akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n)
	fmt.Scan(&k)
	mod := 2 * k
	matrix := make([][]int, mod)
	for i := 0; i < mod; i++ {
		matrix[i] = make([]int, mod)
	}
	for i := 0; i < n; i++ {
		var x, y int
		var s string
		fmt.Scan(&x)
		fmt.Scan(&y)
		fmt.Scan(&s)
		if s == "W" {
			y += k
		}
		x %= mod
		y %= mod
		ldl := x - (k - 1)
		ldd := y - k
		rul := x + 1
		rud := y
		if ldl < 0 && ldd < -1 {
			imos(0, -1, x+1, y+1, matrix)
			imos(ldl+mod, -1, -ldl, y+1, matrix)
			imos(0, ldd+mod, x+1, -ldd-1, matrix)
			imos(ldl+mod, ldd+mod, -ldl, -ldd-1, matrix)
		} else if ldl < 0 {
			imos(0, ldd, x+1, k, matrix)
			imos(ldl+mod, ldd, -ldl, k, matrix)
		} else if ldd < -1 {
			imos(ldl, -1, k, y+1, matrix)
			imos(ldl, ldd+mod, k, -ldd-1, matrix)
		} else {
			imos(ldl, ldd, k, k, matrix)
		}
		if rul+k-1 >= mod && rud+k >= mod {
			imos(rul, rud, mod-rul, mod-rud-1, matrix)
			imos(rul, -1, mod-rul, k-mod+rud+1, matrix)
			imos(0, rud, k-mod+rul, mod-rud-1, matrix)
			imos(0, -1, k-mod+rul, k-mod+rud+1, matrix)
		} else if rul+k-1 >= mod {
			imos(rul, rud, mod-rul, k, matrix)
			imos(0, rud, k-mod+rul, k, matrix)
		} else if rud+k >= mod {
			imos(rul, rud, k, mod-rud-1, matrix)
			imos(rul, -1, k, k-mod+rud+1, matrix)
		} else {
			imos(rul, rud, k, k, matrix)
		}
		/*
			for i := 0; i < mod; i++ {
				fmt.Println(matrix[mod-1-i])
			}
			fmt.Println()
		*/
	}
	for i := 0; i < mod; i++ {
		for j := 1; j < mod; j++ {
			matrix[i][j] += matrix[i][j-1]
		}
	}
	for i := mod - 2; i >= 0; i-- {
		for j := 0; j < mod; j++ {
			matrix[i][j] += matrix[i+1][j]
		}
	}
	maximum := 0
	for i := 0; i < mod; i++ {
		for j := 0; j < mod; j++ {
			if matrix[i][j] > maximum {
				maximum = matrix[i][j]
			}
		}
	}
	fmt.Println(maximum)
}

func imos(ldl int, ldd int, wx int, wy int, matrix [][]int) {
	update(ldl, ldd+wy, 1, matrix)
	update(ldl, ldd, -1, matrix)
	update(ldl+wx, ldd+wy, -1, matrix)
	update(ldl+wx, ldd, 1, matrix)
}

func update(x int, y int, d int, matrix [][]int) {
	if x < 0 || x >= len(matrix) || y < 0 || y >= len(matrix) {
		return
	}
	matrix[y][x] += d
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int A, B; cin >> A >> B;
	cout << (A - 1) * (B - 1) << endl;
}


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

using namespace std;

typedef vector <int> vi;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    vi v(n);
    int ans = 0;
    for( auto &x: v ) cin>>x;
    for( int i = 0; i < n ; i++ )
        for( int j = i + 1 ; j < n ; j++ )
            ans += ( v[i] * v[j] );
    cout<<ans<<"\n";

}


Measured memory_bytes: 256
n_s = input()
n_s = n_s[::-1]
#n = int(n_s)

pay = 0
back = 0
flag = 0

dp = [[0,0] for _ in range(len(n_s) + 1)]

dp[0][0] = int(n_s[0])
dp[0][1] = 10 - int(n_s[0])

for i in range(len(n_s)):
  i += 1
  if i == len(n_s):
    n = 0
  else:
    n = int(n_s[i])
  
  dp[i][0] = min(dp[i-1][0] + n, dp[i-1][1] + n+1)
  dp[i][1] = min(dp[i-1][0] + (10-n), dp[i-1][1] + (10-n-1))

print(min(dp[-1]))


Measured memory_bytes: 138780
h,w = map(int,input().split())

grid = list()

for i in range(h):
    grid.append(input())

x = [1,-1,0 ,0]   
y = [0, 0,1,-1]   

count = 0

for i in range(h):
    for j in range(w):
        count = 0
        if grid[i][j] == '#':
            for s,t in zip(x,y):
                if h > i+s >= 0 and w > j+t >= 0 and grid[i+s][j+t] == '#':
                    break
            else:
                print("No")
                exit()
                
print("Yes")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {

        public void Calc()
        {


            var NK = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var Ps = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

            var N = NK[0];
            var K = NK[1];

            var exPs = new double[1000];

            for (var i = 0; i < 1000; i++)
            {
                exPs[i] = (double)Enumerable.Range(1, i + 1).Sum() / (i + 1);
            }


            var sum = Ps.Where((x, i) => i < K).Sum();
            var max = sum;
            var maxIndent = 0;
            for (var i = 0; i < N - K; i++)
            {
                sum = sum - Ps[i] + Ps[i + K];
                if (max < sum)
                {
                    max = sum;
                    maxIndent = i + 1;
                }
            }

            var anser = Ps.Where((x, i) => maxIndent <= i && i < maxIndent + K).Select(x => exPs[x - 1]).Sum();

            Console.WriteLine(anser);



            //Console.WriteLine(As.Distinct().Count() == As.Count() ? "YES" : "NO");

            //var SP = Console.ReadLine().Split();


            //var AB = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

            //var U = Console.ReadLine();

            //var S = Console.ReadLine();

            //Console.WriteLine(new string('x', S.Length));


        }
    }
}

Measured memory_bytes: 30428
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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 ll INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main(){
    string s;
    ll c[3];
    fill(c,c+3,0);
    cin >> s;
    for (ll i=0;i<s.size();i++){
        c[s[i]-'a']++;
    }
    ll a=0,b=INF;
    for (ll i=0;i<3;i++){
        a=max(a,c[i]);
        b=min(b,c[i]);
    }
    if (a-b>1){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

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

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

stack<int> S;
int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N]; //未訪問な次の頂点を保持

//未訪問な次の頂点を返す．全て訪問済みなら-1を返す
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if(M[u][v]) return v;
    }
    return -1;
}

void dfs_visit(int i){
    S.push(i);
    color[i] = GRAY;
    d[i] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = next(u);
        if(v != -1){
            if(color[v] == WHITE){
                S.push(v);
                color[v] = GRAY;
                d[v] = ++tt;
            }
        }else{
            color[u] = BLACK;
            f[u] = ++tt;
            S.pop();
        }
    }
}

void dfs(){
    for(int i = 0; i < n; i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    for(int i = 0; i < n; i++){
        if(color[i] == WHITE) dfs_visit(i);
    }

    for(int i = 0; i < n; i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }

}

int main(){
    int u, k, v;
    cin >> n;
    //隣接行列の作製
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            M[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        u--; //0オリジンに変換
        for(int j = 0; j < k; j++){
            cin >> v;
            v--; //0オリジンに変換
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;

}



Measured memory_bytes: 3108
n=int(input())
s=input()
e=[0]
w=[0]
for i, si in enumerate(s):
    if si=='W':
        w.append(w[i]+1)
    else:
        w.append(w[i])
for i, si in enumerate(reversed(s)):
    if si=='E':
        e.append(e[i]+1)        
    else:
        e.append(e[i])

ans=float('inf')
for i in range(n):
    ans=min(ans, w[i]+e[n-i-1])
print(ans)

Measured memory_bytes: 18080
#include<stdio.h>
#include<stdlib.h>

#define min(a,b) ((a)<(b)?(a):(b))

int main(){
	int n,k,i,x,ans=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&x);
		ans+=min(abs(x-k),abs(x))*2;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(11000).
       01 A-REC.
      	02 A-DATA OCCURS 100.
      	 03 A PIC 999.
       01 B PIC 999.
       01 C PIC 999.
       01 D PIC 999.
       01 ALICE PIC 999999.
       01 BOB PIC 999999.
       01 REN PIC 9999999999.
       01 RE PIC ZZZZZZZZZZ9.
       01 temp1 PIC 9999999.
       01 temp2 PIC 9999999.
       01 temp3 PIC 9999999.
       01 NOW PIC 9999999.
       01 N PIC 999.
       01 MAX PIC 999.
       PROCEDURE DIVISION.
       MAIN.
      	PERFORM VARYING N FROM 1 BY 1 UNTIL N = 101
      		MOVE 0 TO A(N)
      	END-PERFORM.
       	ACCEPT B.
      	ADD 1 TO B.
      	PERFORM VARYING N FROM 1 BY 1 UNTIL N = B
      		ACCEPT C
      		ADD 1 TO A(C)
      	END-PERFORM.
      	MOVE 0 TO D.
      	PERFORM VARYING N FROM 1 BY 1 UNTIL N = 101
      		IF A(N) > 000 THEN
      			ADD 1 TO D
      		END-IF
      	END-PERFORM.
      	MOVE D TO RE.
      	DISPLAY RE.
      	STOP RUN.




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 2e9;
int main(){ 
  int n, x, y;
  cin >> n >> x >> y;
  vector<ll> cnt(n+1, 0);

  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int d1 = j - i;
      int d2 = abs(i - x) + abs(y - j) + 1;

      int res = min(d1, d2);
      cnt[res]++;
    }
  }

  for (int i = 1; i <= n-1; i++) cout << cnt[i] << endl;

  return 0;
} 

Measured memory_bytes: 256
A, B, C ,X = 4.times.map{gets.to_i}

ans = 0
(A+1).times do |i|
  (B+1).times do |j|
    (C+1).times do |k|
      ans+=1 if 500*i + 100*j + 50*k == X
    end
  end
end

puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll A, B;
ll K = 0;
ll t;
ll ret = 0;
string s;

void input() {
  IN(N);
  IN(A);
  IN(B);
}

void solve() {
  ll x = N / (A+B);
  ll y = N % (A+B);
  ret += x * A;
  ret += min(y, A);
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256
N=int(input())
c=0;
while N-26**c>=0:
  N-=26**c
  c+=1
d=[0]*(c-1)
i=0
for i in range(c):
  d.insert(c-1,N%26)
  N=(N-d[i])//26
  i+=1
e=[]
s=''
for i in range(2*c-1):
  e.append(chr(97+d[i]))
  s+=e[i]
print(s[c-1:2*c-1])

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

vector<int> create_primelist(int n)
{
    vector<int> list;
    vector<bool> isprime(n+1,1);
    isprime[0] = false;
    isprime[1] = false;
    for(int i = 2;i*i<=n;i++){
        if(isprime[i]){
            for(int j = i + i;j<=n;j+=i){
                isprime[j] = false;
            }
        }
    }

    REP(i,isprime.size()){
        if(isprime[i]){
            list.push_back(i);
        }
    }

    return list;
}

vector<bool> create_is_primelist(ll n)
{
    vector<bool> isprime(n+1,1);
    isprime[0] = false;
    isprime[1] = false;
    for(int i = 2;i*i<=n;i++){
        if(isprime[i]){
            for(int j = i + i;j<=n;j+=i){
                isprime[j] = false;
            }
        }
    }
    return isprime;
}

int main(void)
{
    vector<int> primelist = create_primelist(55555);
    vector<int> oklist;
    int n;
    cin >> n;

    REP(i,primelist.size())
    {
        if(primelist[i] % 5 == 1){
            oklist.push_back(primelist[i]);
        }
    }

    REP(i,n){
        cout << oklist[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
main=print.solve.V.unfoldr(B.readInt.B.dropWhile isSpace)=<<(B.getLine>>B.getLine)
solve=g=<<V.foldr f(0,0,0)
f a(i,j,k)
  |a<0=(i+1,j,k)
  |a>0=(i,j,k+1)
  |otherwise=(i,j+1,k)
g(i,j,k)as
  |even i || j>0=V.sum bs
  |otherwise=V.sum bs-V.minimum bs*2
  where bs=V.map abs as

Measured memory_bytes: 15864
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();
        long n = sc.nextLong();
        long d = 1;
        long a = 0;
        long b = 0;


        for(int i=(int)A; i>=1; i--) {
            if(A%i==0 && B%i==0) {
                a = A/i;
                b = B/i;
                d = i;
                break;
            }
        }

        long res = 0;
        if (n >= B) {
            res = a * (B-1) / b;
        } else {
            res = a * n / b;
        }

        System.out.println(res);


    }



}

Measured memory_bytes: 35708
#ifdef loc
    #include "loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif

typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 100005;
int a[N][3], f[N][3];

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    int n;
    std::cin >> n;
    rep(i, 1, n + 1) {
        rep(j, 0, 3) {
            std::cin >> a[i][j];
        }
        rep(j, 0, 3) {
            rep(k, 0, 3) {
                if(j == k) {
                    continue;
                }
                f[i][j] = std::max(f[i][j], f[i - 1][k] + a[i][j]);
            }
        }
    }
    int ans = 0;
    rep(i, 0, 3) {
        ans = std::max(ans, f[n][i]);
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 2560
def hoge(n):
    return 10 ** n - 10 ** (n - 1)

N = input().strip()
o = len(N)
N = int(N)

ans = 0
for i in range(o):
    if i % 2 == 0:
        continue
    ans += hoge(i)

if o % 2 == 1:
    ans += N - 10 ** (o-1) + 1

print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
using namespace std;
using ll = long long;
int main(){
  string s;
  cin >> s;
  
  int cnt = 0;
  for(int i = 0; i < s.size() - 1; i++){
    if(s[i] != s[i+1]){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
} 


Measured memory_bytes: 512
#include <stdio.h>
int main(){
    int A[100];
    int n;
    int i,j,t;
    int minj,count=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }

    for(i=0;i<n;i++){
        minj=i;
        for(j=i;j<n;j++){
            if(A[j]<A[minj]){
                minj=j;
                
            }
        }
        if(i!=minj)count++;

        t=A[i];
        A[i]=A[minj];
        A[minj]=t;
    }
    for(j=0;j<n;j++){
        printf("%d",A[j]);
        if(j<n-1)printf(" ");
    }
    printf("\n%d\n",count);
    
    return 0;
}


Measured memory_bytes: 1992
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto S = readln.chomp;
    auto T = readln.chomp;
    foreach (i; 0..S.length) {
        if (S[i..$] ~ S[0..i] == T) {
            writeln("Yes");
            return;
        }
    }
    writeln("No");
}



Measured memory_bytes: 256
R = str(input())

if R == "RRR":
    print(3)
    
if R == "SRR":
    print(2)
if R == "RSR":
    print(1)
if R == "RRS":
    print(2)
    
if R == "RSS":
    print(1)
if R == "SSR":
    print(1)
if R == "SRS":
    print(1)
if R == "SSS":
    print(0)

Measured memory_bytes: 9048
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
const int MAXN = 52;
const ll INF = 10000000005;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];

  vector<ll> sl(n + 1);
  rep(i, n) sl[i + 1] = sl[i] + v[i];

  reverse(all(v));
  vector<int> rv(n);
  rep(i, n) rv[i] = v[i];
  reverse(all(v));

  vector<ll> sr(n + 1);
  rep(i, n) sr[i + 1] = sr[i] + rv[i];

  vector<vector<vector<ll>>> retv(
    n + 1, vector<vector<ll>>(n + 1, vector<ll>(n + 1)));
  vector<int> L, R;
  priority_queue<int, vector<int>, greater<int>> H;
  rep(l, n + 1) {
    R.clear();
    rep(r, n + 1) {
      while(H.size()) H.pop();
      for(auto vr : R) H.emplace(vr);
      for(auto vl : L) H.emplace(vl);
      rep(ret, n + 1) {
        if(ret == 0) continue;
        if(l + r < ret) {
          retv[l][r][ret] = INF;
          continue;
        }
        if(l + r > n) {
          retv[l][r][ret] = INF;
          continue;
        }
        int x = H.top();
        H.pop();
        retv[l][r][ret] = retv[l][r][ret - 1] + x;
      }
      if(r < n) R.push_back(rv[r]);
    }
    if(l < n) L.push_back(v[l]);
  }
  ll ans = 0;
  rep(l, n + 1) rep(r, n + 1) rep(h, n + 1) {
    int ret = l + r - h;
    if(l + r + ret > k) continue;
    if(l + r < h) continue;
    if(l + r > n) continue;

    ll now = sl[l] + sr[r] - retv[l][r][ret];
    ans = max(ans, now);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1408
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> N >> K;
	vector<vector<long long int>>dp(K + 1, vector < long long int >(N + 1));
	dp[0][N] = 1;
	vector<long long int>by(N + 1, 1);
	vector<long long int>inv(N + 1, 1);
	for (int i = 2; i <= N; i++) {
		by[i] = by[i - 1] * i%MOD;
		inv[i] = power(by[i], MOD - 2, MOD);
	}
	for (int i = 0; i < K; i++) {
		int num;
		cin >> num;
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= min(num, j); k++) {
				long long int add = by[j] * inv[k] % MOD*inv[j - k] % MOD*by[N - k] % MOD*inv[num - k] % MOD*inv[N - num] % MOD;
				dp[i + 1][j - k] += dp[i][j] * add%MOD;
				dp[i + 1][j - k] %= MOD;
			}
		}
	}
	cout << dp.back().front() << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	int a = 0, b = 0;
	bool turn = true;
	for (int i = 1; i <= n; i++) {
		if (turn) {
			a = a + v[n - i];
			turn = false;
		}
		else {
			b = b + v[n - i];
			turn = true;
		}
	}
	cout << a - b << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	long long int h,w,sum=0;
	scanf("%lld %lld",&h,&w);
	long long int a,b,c,d;
	a = h / 2 ;
	if(h == 1 || w == 1) sum = 1;
	else if(h % 2 == 0)
	{
		sum = a * w ;
	}
	else{
		sum = a * w;
		if(w % 2 == 0)
		{
			sum += (w / 2);
		}
		else{
			sum += (w / 2 + 1);
		}
	}
	printf("%lld",sum);
	return 0;
} 

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long result = (N * (N - 1)) / 2;

            Console.WriteLine(result.ToString());
//            Console.Read();
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
const long long MOD=924844033;
long long C[2005][2005];
long long dp[2005][2005][2];
long long dp2[2005],po[2005];
long long tmp[2005];
int main(){
	for(int i=0;i<=2001;i++){
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++){
			C[i][j]=C[i-1][j-1]+C[i-1][j];
			if(C[i][j]>=MOD) C[i][j]-=MOD;
		}
	}
	po[0]=1;
	for(int i=1;i<=2002;i++) po[i]=po[i-1]*i%MOD;
	dp[0][0][0]=1;
	for(int i=1;i<=2001;i++){
		dp[i][0][0]=1;
		for(int j=1;j<=2001;j++){
			dp[i][j][0]=(dp[i-1][j][1]+dp[i-1][j][0])%MOD;
			dp[i][j][1]=dp[i-1][j-1][0];
		}
	}
	int n,k;
	cin>>n>>k;
	dp2[0]=1;
	for(int i=1;i<=k;i++){
		int times=(n-i)/k;
//		cout<<times<<"md\n";
		for(int j=0;j<=n;j++) tmp[j]=dp2[j],dp2[j]=0;
		for(int j=n;j>=0;j--){
			for(int jj=0;jj<=min(j,times);jj++){
				dp2[j]+=tmp[j-jj]*(dp[times][jj][0]+dp[times][jj][1])%MOD;
//				cout<<j<<","<<jj<<":"<<tmp[j-jj]<<" "<<dp[times][jj][0]+dp[times][jj][1]<<endl;
				dp2[j]%=MOD;
			}
		}
//		cout<<dp2[1]<<" ";
		for(int j=0;j<=n;j++) tmp[j]=dp2[j],dp2[j]=0;
		for(int j=n;j>=0;j--){
			for(int jj=0;jj<=min(j,times);jj++){
				dp2[j]+=tmp[j-jj]*(dp[times][jj][0]+dp[times][jj][1])%MOD;
				dp2[j]%=MOD;
			}
		}
//		cout<<dp2[1]<<" "<<dp[2][1][0]+dp[2][1][1]<<endl;
	}
	int inv=1;
	long long res=0;
	for(int i=0;i<=n;i++,inv*=-1){
		res=(res+inv*dp2[i]*po[n-i])%MOD;
	}
	if(res<0) res+=MOD;
	cout<<res;
}

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

typedef long long ll;
const int N = 54, M = 216, mod = 1000000007;
const int phi[N] = {0, 1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8, 16, 6, 18, 8, 12, 10, 22, 8, 20, 12, 18, 12, 28, 8, 30, 16, 20, 16, 24, 12, 36, 18, 24, 16, 40, 12, 42, 20, 24, 22, 46, 16, 42, 20, 32, 24, 52};

struct edge {
	int u, v;
	edge (int u0 = 0, int v0 = 0) : u(u0), v(v0) {}
} e[M];

int V, E, C, Es = 0, Br;
int first[N], next[M];
int cnt = 0, id[N], low[N];
int top = 0, stack[N], size[N];
int bcc_cnt = 0, p[M], vi[M], ei[M];
int fact[M], finv[M], polya[M];

inline void down(int &x, const int y) {x > y ? x = y : 0;}
ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

void init(int m) {
	int i, j, ij, mm = m;
	for (*fact = i = 1; i < M; ++i) fact[i] = (ll)fact[i - 1] * i % mod;
	--i, finv[i] = PowerMod(fact[i], mod - 2);
	for (; i; --i) finv[i - 1] = (ll)finv[i] * i % mod;
	for (i = 1; i < N; ++i, mm = (ll)mm * m % mod)
		for (j = 1, ij = i; ij < N; ++j, ij += i)
			polya[ij] = (polya[ij] + (ll)mm * phi[j]) % mod;
	for (i = 1; i < N; ++i) polya[i] = (ll)fact[i - 1] * finv[i] % mod * polya[i] % mod;
}

inline ll binom(int n, int r) {return (ll)fact[n] * finv[r] % mod * finv[n - r] % mod;}

inline void addedge(int u, int v) {
	e[++Es] = edge(u, v), next[Es] = first[u], first[u] = Es;
	e[++Es] = edge(v, u), next[Es] = first[v], first[v] = Es;
}

void dfs(int x, int px = 0) {
	int i, y, z;
	id[x] = low[x] = ++cnt, stack[top++] = x;
	for (i = first[x]; i; i = next[i])
		if (!id[y = e[i].v]) {
			dfs(y, i), down(low[x], low[y]);
			if (id[x] == low[y])
				for (p[++bcc_cnt + V] = x, vi[bcc_cnt] = 1, z = 0; z != y; )
					p[z = stack[--top]] = bcc_cnt + V, ++vi[bcc_cnt];
			else if (id[x] < low[y]) ++Br, --top;
		} else if (px - 1 ^ i - 1 ^ 1)
			down(low[x], id[y]);
}

int main() {
	int i, u, v, b, ans = 1;
	scanf("%d%d%d", &V, &E, &C), init(C);
	for (i = 0; i < E; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	for (i = 1; i <= V; ++i) if (!id[i]) dfs(i);
	for (i = 1; i <= Es; i += 2) {
		u = e[i].u, v = e[i].v;
		if ((p[u] && p[u] == p[v]) || p[p[u]] == v || p[p[v]] == u)
			b = p[p[p[v]] == u ? v : u] - V, ++ei[b];
	}
	for (i = 1; i <= bcc_cnt; ++i)
		if (vi[i] < ei[i]) ans = ans * binom(ei[i] + C - 1, ei[i]) % mod;
		else assert(vi[i] == ei[i]), ans = (ll)ans * polya[ei[i]] % mod;
	printf("%d\n", (int)PowerMod(C, Br, ans));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int R[200000];
int num;
int main()
{
	//cout << "????????\???????????¶??´??????" << endl;
	cin >> num;
	for (int i = 0; i < num; i++)
	{
		cin >> R[i];
	}
	int maxv = -2000000000;
	int minv = R[0];
	for (int j = 1; j < num; j++)
	{
		if (maxv < R[j] - minv)
		{
			maxv = R[j] - minv;
		}
		if (minv > R[j])
		{
			minv = R[j];
		}
	/*	for (int i = 0; i < j; i++)
		{
			if (maxv < R[j] - R[i])
			{
				maxv = R[j] - R[i];
			}
		}*/
	}
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3860
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int X = sc.nextInt();
		int Y = sc.nextInt();
		
		
		
		
		
		
		
		
		
		System.out.println(X + (Y /2));
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main(int,char**){
    int i,j,d,c[26],*s,*r;
    cin>>d;
    s = new int[26*d];
    r = new int[d];
    for(i=0;i<26;i++){
        cin>>c[i];
    }
    for(i=0;i<d;i++){
        for(j=0;j<26;j++){
            cin>>s[i*26+j];
        }
    }
    vector<int> v;
    for(i=0;i<26;i++){
        if(i==0){
            v.push_back(c[i]);
        }
        else{
            v.push_back(v.back()+c[i]);
        }
    }
    random_device rd;
    mt19937_64 mt(rd());
    for(i=0;i<d;i++){
        int select = mt()%(v.back()+1);
        for(j=0;j<26;j++){
            if(v[j]>select){
                r[i] = j;
                break;
            }
        }
    }
    for(i=0;i<d;i++){
        cout<<r[i]+1<<endl;
    }
}

Measured memory_bytes: 3672
# https://atcoder.jp/contests/agc031/tasks/agc031_a

from collections import Counter
n = int(input())
s = input()
mod = 10 ** 9 + 7

ans = 1
c = Counter(s)
for v in c.values():
    ans = ans * (v + 1) % mod

print(ans - 1)

Measured memory_bytes: 73728
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int		main(void)
{
	int		K;
	cin >> K;
	int		ans = 0;
	int		tmp;
	for (int i = 1; i <= K; i++)
	{
		for (int j = 1; j <= K; j++)
		{
			for (int k = 1; k <= K; k++)
			{
				for (int l = 0; l < 2; l++)
				{
					if (l == 0)
						tmp = gcd(i, j);
					else
						tmp = gcd(tmp, k);
				}
				ans+=tmp;
			}
		}
	}
	cout << ans << endl;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  char c[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> c[i][j];
    }
  }
  for(int i=0;i<W+2;i++){
    cout << '#';
  }
  cout << endl;
  for(int i=0;i<H;i++){
    cout << '#';
    for(int j=0;j<W;j++){
      cout << c[i][j];
    }
    cout << '#' << endl;
  }
  for(int i=0;i<W+2;i++){
    cout << '#';
  }
  
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}




int main() {
  string a,b;
  cin >> a >> b;
  int na=a.size(),nb=b.size();
  if(na>nb) cout << "GREATER" << endl;
  else if(na<nb) cout << "LESS" << endl;
  else {
    REP(i,na) {
      if(a[i]>b[i]) {
        cout << "GREATER" << endl;
        return 0;
      } else if(a[i]<b[i]) {
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
    return 0;
  }
  return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  ll mid = n/2;
  if(n%2==0) mid--;
  sort(ALL(a));
  vector<ll> v(n);
  v[mid] = a[0];
  for(int i=mid+2, j=1; i<n; i+=2, j+=2) {
    v[i] = a[j];
  }
  for(int i=mid+1, j=n-1; i<n; i+=2, j-=2) {
    v[i] = a[j];
  }
  // cout << v << endl;
  for(int i=mid-2, j=2; i>=0; i-=2, j+=2) {
    v[i] = a[j];
  }
  // cout << v << endl;
  for(int i=mid-1, j=n-2; i>=0; i-=2, j-=2) {
    v[i] = a[j];
  }
  // cout << v << endl;
  ll ret = 0;
  FOR(i, 1, n) ret += abs(v[i]-v[i-1]);
  ll ans = ret;

  reverse(ALL(a));
  v[mid] = a[0];
  for(int i=mid+2; i<n; i+=2) {
    v[i] = a[i-mid-1];
  }
  for(int i=mid+1, j=n-1; i<n; i+=2, j-=2) {
    v[i] = a[j];
  }
  for(int i=mid-2, j=2; i>=0; i-=2, j+=2) {
    v[i] = a[j];
  }
  for(int i=mid-1, j=n-2; i>=0; i-=2, j-=2) {
    v[i] = a[j];
  }
  // cout << v << endl;
  ret = 0;
  FOR(i, 1, n) ret += abs(v[i]-v[i-1]);
  chmax(ans, ret);

  cout << ans << endl;

  return 0;
}


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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n; cin >> n; int a[3*n];
    for(int &i : a) cin >> i;

    LL l = 0, r = 0;
    priority_queue<int> R;
    priority_queue<int, vector<int>, greater<int>> L;

    for(int i = 0; i < n; i++) l += a[i], L.push(a[i]);
    for(int i = 2*n; i < 3*n; i++) r += a[i], R.push(a[i]);

    LL left[n+1], right[n+1];
    for(int i = 0; i <= n; i++) {
        left[i] = l;
        L.push(a[n+i]);
        l += a[n+i]; l -= L.top(); L.pop();

        right[n-i] = r;
        R.push(a[2*n-i-1]);
        r += a[2*n-i-1]; r -= R.top(); R.pop();            
    }

    LL ans = -1e18;
    for(int i = 0; i <= n; i++) ans = max(ans, left[i] - right[i]);
    cout << ans;
}

Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int a[100000], b[100000];
int main() {
	int A, B, M;
	int min = 1000000007, min1 = 1000000007, min2;
	int co, co1;
	int x, y, c;
	cin >> A >> B >> M;
	for (int i = 0; i < A; i++) {
		cin >> a[i];
		if (min > a[i]) {
			min = a[i];
			co = i;
		}
	}
	for (int j = 0; j < B; j++) {
		cin >> b[j];
		if (min1 > b[j]) {
			min1 = b[j];
			co1 = j;
		}
	}
	min2 = min + min1;
	for (int k = 0; k < M; k++) {
		cin >> x >> y >> c;
		if (a[x - 1] + b[y - 1] - c < min2) {
			min2 = a[x - 1] + b[y - 1] - c;
		}
	}
	cout << min2 << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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 (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,a,b;cin >> x >> a >> b;
    if(abs(x-a)<abs(x-b)){
        cout << 'A' << endl;
    }
    else{
        cout << 'B' << endl;
    }
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	string S, T; cin >> S >> T;
	int ans = 0;
	for (int i = 0; i < 3; i++) if (S[i] == T[i]) ans++;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{  int bounce,x,count=1,i;
scanf("%d %d",&bounce,&x);
if((1<=bounce<=100)&&(1<=x<=10000)){
    int a[bounce],b[bounce+1];
    b[0]=0;
    for( i=0;i<bounce;i++){
        scanf("%d",&a[i]);
        if(1<=a[i]<=100){b[i+1]=b[i]+a[i];if(b[i+1]<=x)count++;}
    }printf("%d",count);
}
    return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (1<<(4*4-1))
#define MOD 1000000007

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

   int N,K;
   cin>>N>>K;
   vector<int>A(N);
   for(int i=0;i<N;i++)cin>>A[i];

   ll ans = 0;
   while(N>K){
      N-=K;
      N++;
      ans++;
   }
   ans++;
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {

  int n;
	scanf("%d", &n);
	int withdraw9, withdraw6, withdraw;
	int bit[10];
	int min = -1;
	for (int i = 0; i*9 <= n; i++) {
		withdraw = 0;
		withdraw9 = i*9;
		for (int i = 0; i < 10; i++) {
			bit[i] = 0;
		}
		bit[0] = withdraw9;
		for (int i = 1; i < 10; i++) {
			bit[i] += bit[i-1]/9;
			bit[i-1] %= 9;
		}
		for (int i = 0; i < 10; i++) {
			withdraw += bit[i];
		}
		withdraw6 = n-withdraw9;
		for (int i = 0; i < 10; i++) {
			bit[i] = 0;
		}
		bit[0] = withdraw6;
		for (int i = 1; i < 10; i++) {
			bit[i] += bit[i-1]/6;
			bit[i-1] %= 6;
		}
		for (int i = 0; i < 10; i++) {
			withdraw += bit[i];
		}
		if (min == -1 || withdraw < min) {
			min = withdraw;
		}
	}
	printf("%d\n", min);

  return 0;
}

Measured memory_bytes: 128
//
// main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

map<ll, ll> prime_decomp(ll n) {
    map<ll, ll> ans;
    for (ll p = 2; p * p <= n; p++) {
        while (n % p == 0) {
            ans[p]++;
            n = n / p;
        }
    }
    if (n > 1) {
        ans[n]++;
    }
    return ans;
}


void prime_decomp(ll n, map<ll, ll>& ans) {
    for (ll p = 2; p * p <= n; p++) {
        while (n % p == 0) {
            ans[p]++;
            n = n / p;
        }
    }
    if (n > 1) {
        ans[n]++;
    }
}

int main() {
    ll N;
    cin >> N;
    map<ll, ll> decomp;
    rep(i,2,N+1) {
        prime_decomp(i, decomp);
    }
    vector<ll> exps;
    for (auto& kv : decomp) {
        exps.push_back(kv.second);
    }
    ll ans = 0;
    // 75
    rep(i,0,exps.size()) {
        if (exps[i] >= 74) {
            ans++;
        }
    }
    // 3x25
    rep(i,0,exps.size()) {
        rep(j,0,exps.size()) {
            if (i != j) {
                if (exps[i] >= 2 && exps[j] >= 24) {
                    ans++;
                }
            }
        }
    }
    // 5x15
    rep(i,0,exps.size()) {
        rep(j,0,exps.size()) {
            if (i != j) {
                if (exps[i] >= 4 && exps[j] >= 14) {
                    ans++;
                }
            }
        }
    }
    // 3x5x5
    rep(i,0,exps.size()) {
        rep(j,0,exps.size()) {
            rep(k,0,exps.size()) {
                if (i != j && j != k && k != i && j < k) {
                    if (exps[i] >= 2 && exps[j] >= 4 && exps[k] >= 4) {
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


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

int main() {
	int n;
	cin >> n;
	int num = 1;
	int count;
	int sosu[1010];
	long long mod = 1e9 + 7, ans = 1ll;
	for (int i = 0; i < 1010; i++) {
		sosu[i] = 0;
	}
	for (int i = 2; i <= n; i++) {
		num = i;
		for (int j = 2; j <= num; j++) {
			while (num%j == 0) {
				num /= j;
				sosu[j]++;
			}
		}
	}
	for (int i = 0; i < 1010; i++) {
		if (sosu[i] > 0) {
			ans = (ans%mod)* ((sosu[i] + 1) % mod)%mod;
		}
	}
	cout << ans << endl;
	return 0;
}

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

void solve() {
	int n, XOR; cin >> n;
	vi arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		if (i == 0) XOR = arr[i];
		else XOR ^= arr[i];
	}
	for (int i = 0; i < n; i++)
		cout << (arr[i]^XOR) << ' ';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
int main(){
    int n;
    cin >> n;
    n *= 2;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
    sort(arr.rbegin(),arr.rend());
    int ans = 0;
    for(int i = 1; i < n; i += 2)
        ans += arr[i];
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
ll INF = 1000000007;
using Graph = vector<vector<ll>>;

// 0 false, 1 true 


int main() {
    ll n;
    string s;

    cin >> n;
    cin >> s;

    //最高1000
    vector<int> vec_1(10);
    vector<int> vec_2(100);
    vector<int> vec_3(1000);


    
    for(ll i = 0; i < s.size(); i++){

        
        for(ll j = 0; j < 100; j++){
            if(vec_2.at(j) > 0){
                vec_3.at( (j*10) + int(s.at(i)) -48) ++;
            }
        }

        for(ll j = 0; j < 10; j++){
            if(vec_1.at(j) > 0){
                vec_2.at( (j*10) + int(s.at(i)) -48) ++;
            }
        }
        
        vec_1.at(int(s.at(i))-48)++;

        
    }
    
    int count = 0;
    for(ll i = 0; i < vec_3.size(); i++){
        if(vec_3.at(i) > 0){
            count ++;
        }
    }

    cout << count << endl;


}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; 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--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1000000000;

int main(){
   int n;cin>>n;
   string s[n];
   rep(i,n)cin>>s[i];
   rep(i,n-1){
      if(s[i][s[i].size()-1] == s[i+1][0]){
      }else{
         cout << "No";
         return 0;
      }
   }
   sort(s,s+n);
   rep(i,n-1){
      if(s[i] == s[i+1]){
         cout << "No";
         return 0;
      }
   }
   cout << "Yes";
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll K,N,i;
    cin >> K >> N;
    ll A[N+1];
    for(i=0;i<N;i++){
        cin >> A[i];
    }
    A[N]=A[0]+K;
    ll mx=0;
    for(i=0;i<N;i++){
        mx=max(mx,A[i+1]-A[i]);
    }
    cout << K-mx;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define  N 8
#define Free -1
#define Not_Free 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int H[N][N];

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(H[i][j]){
        if(row[i]!=j) return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      printf("%c",(row[i]==j)?'Q':'.');
    }
    printf("\n");
  }
}

void Put(int i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(Not_Free==col[j] || Not_Free == dpos[i+j]
      || Not_Free == dneg[i-j+N-1])
      continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=Not_Free;
    Put(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=Free;
  }
}

int main(int argc, char const *argv[]) {
  int i,j,k,c,d;
  for (i =0; i < N; i++) {
    row[i]=Free;
    col[i]=Free;
  }
  for ( j = 0; j < 2*N; j++) {
      dpos[j]=Free;
      dneg[j]=Free;
  }
  for ( i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      H[i][j]=0;
    }
  }
  scanf("%d",&k);
  for (i = 0; i < k; i++) {
    scanf("%d %d",&c,&d);
    H[c][d]=1;
  }
  Put(0);
  return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	int A, B;
	int ans = INF;
	int sum = 0;
	rep(i, 0, N)
	{
		cin >> A >> B;
		sum += A;
		if (A > B)chmin(ans, B);
	}

	if (ans == INF)cout << 0 << endl;
	else cout << sum - ans << endl;
	
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int a,b,c;
  c=n%10;
  b=n/10%10;
  a=n/100;
  if(a==1)a=9;else if(a==9)a=1;
  if(b==1)b=9;else if(b==9)b=1;
  if(c==1)c=9;else if(c==9)c=1;
  cout<<a<<b<<c<<endl;
}

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

int gcd(int a, int b) {
  int tmp;
  while ( a%b != 0 ) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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

  int ans = 0;
  for ( int a = 1; a <= k; a++ ) {
    for ( int b = 1; b <= k; b++ ) {
      for ( int c = 1; c <= k; c++ ) {
        ans += gcd(gcd(a, b), c);
      }
    }
  }

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


Measured memory_bytes: 3592