akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr()
	//N := list[0]
	K := list[1]
	p := getStdinIntArr()

	sort.Ints(p)
	sum := 0
	for i := 0; i < K; i++ {
		sum += p[i]
	}

	fmt.Printf("%d\n", sum)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 1812
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, Y, Z, K = MAP()
A = LIST()
B = LIST()
C = LIST()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

V = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1) * (j+1) * (k+1) <= K:
                V.append(A[i]+B[j]+C[k])
            else:
                break

V.sort(reverse=True)

for i in range(K):
    print(V[i])

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

int main() {
	string s,slong,nlong;
	vector<string> S;
	while (cin >> s) {
		S.push_back(s);
	}
	S[0][0] += 32;
	int sizeMAX = 0, ctr2 = 0;
	for (int i = 0; i < S.size(); i++) {
		int ctr1 = 0;
		for (int j = 0; j < S.size(); j++) {
			if (S[i] == S[j])ctr1++;
		}
		if (sizeMAX < S[i].size()) {
			slong = S[i]; sizeMAX = S[i].size();
		}
		if (ctr2 < ctr1) {
			ctr2 = ctr1; nlong = S[i];
		}
	}
	cout << nlong << " " << slong << endl;
	return 0;
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;
int gcd(int a, int b) {
	int c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int a = A[0] / 2;
	for (int i = 1; i < N; i++) {
		a = (a * (A[i] / 2)) / (gcd(a, (A[i] / 2)));
		if (a > M) {
			break;
		}
	}
	if (a > M) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
		if ((a / (A[i] / 2)) % 2 == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	cout << ((M / a) + 1) / 2 << endl;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func getLowerCase(s string) string {
	b := make([]byte, len(s))
	for i := 0; i < len(s); i++ {
		c := s[i]
		if 'A' <= c && c <= 'Z' {
			c += 'a' - 'A'
		}
		b[i] = c
	}

	return string(b)
}

func main() {
	var w string
	fmt.Scan(&w)
	w = getLowerCase(w)

	count := 0
	for {
		var t string
		fmt.Scan(&t)

		if t == "END_OF_TEXT" {
			break
		}

		t = getLowerCase(t)
		if w == t {
			count++
		}
	}
	fmt.Println(count)
}



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

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

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


Measured memory_bytes: 3620
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
A,B = input().split()

d = {"H":0, "D":1}
Ans = ["H", "D"]

print(Ans[d[A]^d[B]])

Measured memory_bytes: 2940
from itertools import *
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

a = [i+1 for i in range(n)]
for i,per in enumerate(list(permutations(a))):
    if per == p:
        x = i
    if per == q:
        y = i
print(abs(x-y))


Measured memory_bytes: 8052
#include<bits/stdc++.h>
#define R(a) int a;cin>>a;
#define deb(x) cout<<#x<<" "<<x<<endl;
#define mod 1000000007
#define f_arr(n) for(int i=0;i<n;i++)
#define r_arr(n) for(int i=n-1;i>=0;i--)
#define pb push_back
#define all(x) x.begin(),x.end()
// #define int long long int
using namespace std;

#ifndef ONLINE_JUDGE
template<typename T>		
void __p(T a) {
  cerr<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cerr<<"[";
  __p(a.first);
  cerr<<",";
  __p(a.second);
  cerr<<"]";
}
template<typename T>
void __p(std::vector<T> a) {
  cerr<<"[";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cerr<<",]"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr<<name<<" : ";
  __p(arg1);
  cerr<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cerr.write(names,comma-names)<<" : ";
  __p(arg1);
  cerr<<" | ";
  __f(comma+1,args...);
}
#define trace(...) cerr<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#endif

void test_case()
{
  R(x);
  if(x>=30){
    cout<<"Yes";
  }
  else
    cout<<"No";
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int t=1;
    // cin>>t;
    while(t--)
    {
        test_case();
    }

    cerr<<endl<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

    return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }



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

    ll N;
    string S;
    cin >> N;

    bool flag = false;

    for (ll i = -200; i < 200; i++) {
        for (ll j = -200; j < 200; j++) {
            ll tmp = i * i * i * i * i - j * j * j * j * j;
            if(tmp==N){
                cout << i << " " << j << endl;
                flag = true;
                break;
            }
        }
        if(flag){
            break;
        }
    }
}


Measured memory_bytes: 3596
import sys

N, M = list(map(int, sys.stdin.readline().strip().split()))

l, r = list(map(int, sys.stdin.readline().strip().split()))

for _ in range(M-1):
    tl, tr = list(map(int, sys.stdin.readline().strip().split()))

    if r > tr:
        r = tr
    if l < tl:
        l = tl

print(max(r-l+1, 0))

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

using namespace std;

int main(){
	int n,k,q;
	scanf("%d%d%d",&n,&k,&q);
	vector<int> ans(n,k-q);
	for(int i=0;i<q;i++){
		int index;
		scanf("%d",&index);
		ans[index-1]++;
	}
	for(int i=0;i<n;i++){
		if(ans[i]>0){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1024
k, n = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
t = 0
id = 0
l = 0
for i in range(n):
    if i < n - 1:
        d = abs(a[i] - a[i + 1])
    else:
        d = k - a[n - 1] + a[0]
    if t < d:
        t = d
        id = i + 1 if i < n - 1 else 0
for i in range(n - 1):
    l += abs(a[(i + id) % n] - a [(i + id + 1) % n]) if i + id != n - 1 else k - a[n - 1] + a[0]
print(l)

Measured memory_bytes: 26444
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------

bool a[4][100];
signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		char s;
		int t;
		cin >> s >> t;
		if (s == 'S') a[0][t] = 1;
		if (s == 'H') a[1][t] = 1;
		if (s == 'C') a[2][t] = 1;
		if (s == 'D') a[3][t] = 1;
	}
	char b[4] = { 'S','H','C','D' };
	for (int i = 0; i < 4; i++) {
		for (int j = 1; j <= 13; j++) {
			if (!a[i][j]) {
				cout << b[i] << " " << j << endl;
			}
		}
	}
}


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

using namespace std;
vector<int> V;
int main(){
    long long n;
    cin >> n;
    while(n){
        int u=n%10;
        n=n/10;
        V.push_back(u);
    }
    reverse(V.begin(),V.end());
    int ans=0;
    for(int i=0;i<V.size();++i){
        if(V[i]){
            int ma=0;
            for(int j=0;j<i;++j) ma+=V[j];
            ma+=(V[i]-1);
            for(int j=i+1;j<V.size();++j) ma+=9;
            ans=max(ans,ma);
        }


    }
    int ma=0;
    for(int j=0;j<V.size();++j) ma+=V[j];
    ans=max(ans,ma);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int data[10];
int sp = 0;
int read;

int top()
{
	return data[sp-1];
}

void pop()
{
	sp--;
}

void push(int v)
{
	data[sp] = v;
	sp++;
}

int main()
{
	while(scanf("%d",&read) != EOF)
	{
		if(read == 0)
		{
			printf("%d\n",top());
			pop();
		}
		else
		{
			push(read);
		}
	}
	return 0;
}

Measured memory_bytes: 600
Infinity = 1.0 / 0.0
class Station
  attr_reader :m, :cost
  def initialize(m)
    @m = m
    @rails = []
    @r = nil
    @cost = Infinity
  end
  def ==(other)
    @m == other
  end
  def start
    @cost = 0
  end
  def setup(r)
    @r = r
    @cost = Infinity
  end
  def set_r(b, cost, time)
    @rails << [b, cost, time]
  end
  def ride
    @rails.each{|rail|
      rail[0].reach(@cost + rail[@r + 1])
    }
  end
  def reach(cost)
    @cost = cost if @cost > cost
  end
end
class Chain
  def initialize(args, r)
    @s = S_ring.new
    @l = L_ring.new
    @s.ne = @l
    args.each{|f|
      f.setup(r)
      @s.push(Ring.new(f))
    }
  end
  def get
    return @s.min.chomp
  end
end
class S_ring
  attr_accessor :ne
  def initialize
    @ne = nil
  end
  def min
    @ne.min(@ne)
  end
  def push(ring)
    ring.ne = @ne
    @ne.pr = ring
    ring.pr = self
    @ne = ring
  end
end
class L_ring
  attr_accessor :pr
  def initialize
    @pr = nil
  end
  def min(minv)
    return minv
  end
end
class Ring
  include Comparable
  attr_accessor :factor, :pr, :ne
  def initialize(factor)
    @factor = factor
    @pr = nil
    @ne = nil
  end
  def <=>(other)
    @factor.cost <=> other.factor.cost
  end
  def min(minv)
    return @ne.min((minv > self)? self : minv)
  end
  def chomp
    @pr.ne = @ne
    @ne.pr = @pr
    return @factor
  end
end
def main(input = STDIN)
  while (n, m = input.gets.split(" ").map(&:to_i)) != [0, 0]
    st = Array.new(m){|i|Station.new(i + 1)}
    n.times do
      rail = input.gets.split(" ").map(&:to_i)
      st[rail[0] - 1].set_r(st[rail[1] - 1], *rail[2,2])
      st[rail[1] - 1].set_r(st[rail[0] - 1], *rail[2,2])
    end
    input.gets.to_i.times do
      request = input.gets.split(" ").map(&:to_i)
      chain = Chain.new(st, request[2])
      st[request[0] - 1].start
      while (min = chain.get) != request[1]
        min.ride
      end
      puts min.cost
    end
  end
end
main

Measured memory_bytes: 6164
#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 ret = 0;
string s;

int main(void){
  ll K;  
  IN(N);
  IN(K);
  vl h(N);
  REP(i, N) IN(h[i]);

  vl dp(N);
  dp[0] = 0;
  FOR(i, 1, N) {
    ll m = INF;
    ll k = 1;
    while(k <= K && i-k >= 0) {
      CHMIN(m, dp[i-k] + abs(h[i] - h[i-k]));
      k++;
    }
    // DEBUG(m);
    dp[i] = m;
  }
  PRINT(dp[N-1]);

}


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

using namespace std;

int b[105];

main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; ++i) cin >> b[i];
    b[n] = 1e6;
    b[0] = 1e6;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += min(b[i], b[i - 1]);
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define f first
#define s second
#define double long double
const int MAX=2e3+5;
const int MAX2=2e5+4;
const int MAAX=1e10;
const int MOD=1e9+7;

int n,x,y;
int cost[MAX],ans[MAX];
vector<int>adj[MAX];
void bfs(int rt)
{
    queue<pair<int,int> >q;
    q.push({rt,0});
    while(q.size())
    {

        pair<int,int>cur=q.front();
        q.pop();
        if(cost[cur.f]==-1)
        cost[cur.f]=cur.s;

        for(int i=0;i<adj[cur.f].size();++i)
        {
            if(cost[adj[cur.f][i]]==-1)
            {
                q.push({adj[cur.f][i],cur.s+1});
            }
        }
    }
    return;
}
in main()
{
  cin>>n>>x>>y;
  for(int i=1;i<n;i++)
  {
      adj[i].pb(i+1);
      adj[i+1].pb(i);
  }
  adj[x].pb(y);
  adj[y].pb(x);


  for(int i=1;i<=n;i++)
  {
 for(int j=1;j<=n;j++)
        cost[j]=-1;
      bfs(i);
   for(int j=i+1;j<=n;j++)
   {
    if(cost[j]!=-1)
   ans[cost[j]]++;
   }
  }
  for(int i=1;i<=n-1;i++)
    cout<<ans[i]<<endl;
 return 0;
}


Measured memory_bytes: 384
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    h,w = map(int,ipt().split())
    dq = deque()
    a = [input()+"#" for i in range(h)] + ["#"*(w+1)]
    d = [[-1]*(w+1) for i in range(h+1)]
    for i in range(h):
        d[i][w] = 0
    for i in range(w):
        d[h][i] = 0

    for i in range(h):
        ai = a[i]
        for j in range(w):
            if ai[j] == "#":
                d[i][j] = 0
                for dx,dy in dir:
                    nx = i+dx
                    ny = j+dy
                    if a[nx][ny] == "." and d[nx][ny] == -1:
                        dq.append((nx,ny))
                        d[nx][ny] = 1

    while dq:
        qx,qy = dq.popleft()
        nd = d[qx][qy]
        for dx,dy in dir:
            nx = qx+dx
            ny = qy+dy
            if a[nx][ny] == "." and d[nx][ny] == -1:
                dq.append((nx,ny))
                d[nx][ny] = nd+1

#    print(d)
    ma = 0
    for i in d:
        for j in i:
            if ma < j:
                ma = j

    print(ma)




    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 112104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=0,a;i<n;++i){
    cin>>a;
    if(a%2==0&&a%3&&a%5)return cout<<"DENIED",0;
  }
  cout<<"APPROVED";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  for (;;){
    int a, b; string op; cin >> a >> op >> b;
    if (op == "?") return 0;
    if (op == "+") cout << a + b << endl;
    if (op == "-") cout << a - b << endl;
    if (op == "*") cout << a * b << endl;
    if (op == "/") cout << a / b << endl;
  }
}


Measured memory_bytes: 3108
l, r = list(map(int,input().split()))
lmod = l % 2019
rmod = r % 2019
if(r-l) >= 2018:
	answer = 0
elif(lmod > rmod):
	answer = 0
else:
	answer = (rmod * lmod)% 2019
	for i in range(rmod - lmod + 1):
		for j in range(rmod - lmod + 1):
			if(i < j):
				if(answer > (lmod + i) * (lmod + j) % 2019):
					answer = (lmod + i) * (lmod + j) % 2019
print(answer)

Measured memory_bytes: 3064
#include<stdio.h>
#include<limits.h>

#define rep(i,n) for(i=0;i<(n);i++)
#define For(i,a,b) for(i=(a);i<(b);i++)
#define size 500000

int count=0;

void merge(int a[],int left,int mid,int right){
  int n1=mid-left,n2=right-mid;
  int l[n1+1],r[n2+1];
  int i,j,k;
  rep(i,n1)
    l[i]=a[left+i];
  rep(i,n2)
    r[i]=a[mid+i];
  l[n1]=INT_MAX;
  r[n2]=INT_MAX;
  i=0;j=0;
  For(k,left,right){
    if(l[i]<=r[j]){
      a[k]=l[i];
      //printf("%d\n",a[k]);
      i++;
    }else{
      a[k]=r[j];
      //printf("%d\n",a[k]);
      j++;
    }
    count++;
  }  
}

void mergesort(int a[],int l,int r){
  int m;
  if(l+1<r){
    m=(l+r)/2;
    mergesort(a,l,m);
    mergesort(a,m,r);
    merge(a,l,m,r);
  }
}

int main(){
  int n,s[size];
  int i,j,k,l;

  scanf("%d",&n);
  rep(i,n)
    scanf("%d",&s[i]);

  mergesort(s,0,n);
  rep(i,n){
    printf("%d",s[i]);
    if(i==n-1){
      printf("\n");
    }else{
      printf(" ");
    }
  }
  printf("%d\n",count);

  return 0;

}

Measured memory_bytes: 6492
h,w=map(int, input().split())
ch,cw=map(lambda x:int(x)-1,input().split())
dh,dw=map(lambda x:int(x)-1,input().split())
s=[list(input()) for _ in range(h)]

dy=[1, 0, -1, 0]
dx=[0, 1, 0 ,-1]
my=[-2, -2, -2, -2, -2, -1, -1, -1, -1, -1,  0,  0, 0, 0,  1,  1, 1, 1, 1,  2,  2,  2,  2,  2]
mx=[-2, -1,  0,  1,  2, -2, -1,  0,  1,  2, -2, -1, 1, 2, -2, -1, 0, 1, 2, -2, -1,  0,  1,  2]

from collections import deque

d=[[float("inf")]*w for _ in range(h)]
queue=deque()
queue.append((ch, cw))
d[ch][cw]=0

while queue:
    y,x=queue.popleft()

    for d_y, d_x in zip(dy, dx):
        new_y=y+d_y
        new_x=x+d_x
        if new_y<0 or h<=new_y or new_x<0 or w<=new_x:
            continue
        if s[new_y][new_x]=='.' and d[new_y][new_x]>d[y][x]:
            d[new_y][new_x]=d[y][x]
            queue.appendleft((new_y, new_x))

    for m_y, m_x in zip(my, mx):
        new_y=y+m_y
        new_x=x+m_x
        if new_y<0 or h<=new_y or new_x<0 or w<=new_x:
            continue
        if s[new_y][new_x]=='.' and d[new_y][new_x]==float("inf"):
            d[new_y][new_x]=d[y][x]+1
            queue.append((new_y, new_x))

print(-1 if d[dh][dw]==float("inf") else d[dh][dw])



Measured memory_bytes: 144932
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])
ans, num = 1, []

if len(pla) == 0 and k % 2 == 1:
    for i in mia[:k]:
        ans = ans * i % mod
    print(ans)
    exit()

for _ in range(k):
    if len(mia) == 0 or (len(pla) > 0 and abs(mia[-1]) <= pla[-1]):
        tmp = pla.pop()
    elif len(pla) == 0 or (len(mia) > 0 and abs(mia[-1]) > pla[-1]):
        tmp = mia.pop()
    num.append(tmp)
    ans = ans * tmp % mod

cnt = sum(i < 0 for i in num)
if cnt % 2 == 1:
    p, q, r, s = 1, 0, -1, 0
    if len(mia) > 0 and cnt != k:
        p, q = min(i for i in num if i >= 0), mia[-1]
    if len(pla) > 0:
        r, s = max(i for i in num if i < 0), pla[-1]
    if len(mia) > 0 or (len(pla) > 0 and cnt != k):
        if q * r >= p * s:
            ans *= q * pow(p, mod - 2, mod)
        if q * r < p * s:
            ans *= s * pow(r, mod - 2, mod)
    ans %= mod
print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i=0; i<N; ++i) {
    cin >> L.at(i);
  }
  
  sort(L.begin(), L.end()); //昇順にソート
  reverse(L.begin(), L.end()); //降順にソート  
  int count=0;
  vector<int> T(3);
 
  for (int i=0; i<N; ++i) {
    for (int j=i+1; j<N; ++j) {
      for (int k=j+1; k<N; ++k) {
        
        if (L.at(i) == L.at(j) || L.at(i) == L.at(k) || L.at(j) == L.at(k)) {
          continue;
        }
            
        else if ( L.at(i) < L.at(j) + L.at(k)) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

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

using namespace std;

long long dp[100001][3];
long long a[100001];
long long b[100001];
long long c[100001];

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

    long long n;
    cin>>n;

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

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i = 1; i < n; i++)
    {
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c[i];
    }

    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);


    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n){
    cin>>a[i];
  }
  vector<int>s=a;
  sort(s.rbegin(),s.rend());
  rep(i,n){
    int ans=s[0];
    if(s[0]==a[i])ans=s[1];
    cout<<ans<<endl;
  }
  return(0);
}


Measured memory_bytes: 3200
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double EPS = 1e-9;
const int INF = 1e9 + 7;
const ll LINF = 1e18;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    START_TIME = clock();
}

void solve() {
    db r;
    cin >> r;
    cout << fixed << setprecision(3) << 2 * PI * r << en;
}

int main() {
    fast_in_out();
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    cerr << en << TIME << " sec." << en;
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
using namespace std;

int main() {
  string s;
  int x, y;
  cin >> s;
  cin >> x >> y;
  int c = 0;
  int i = 0;
  const int slen = s.size();
  while (i < slen && s[i] == 'F') {
    x -= 1;
    i += 1;
  }
  bool dirx = false;
  vector<int> xs, ys;
  xs.push_back(abs(x));
  ys.push_back(abs(y));
  i += 1;
  for (; i < slen; i++) {
    if (s[i] == 'F') {
      c += 1;
    } else {
      if (dirx) {
        xs.push_back(c);
      } else {
        ys.push_back(c);
      }
      c = 0;
      dirx = !dirx;
    }
  }
  if (dirx) {
    xs.push_back(c);
  } else {
    ys.push_back(c);
  }
  sort(xs.begin(), xs.end(), greater<int>());
  sort(ys.begin(), ys.end(), greater<int>());
  x = y = 0;
  for_each(xs.begin(), xs.end(), [&x](const int& xx){
      if (x > 0) {
        x -= xx;
      } else {
        x += xx;
      }
      });
  for_each(ys.begin(), ys.end(), [&y](const int& yy){
      if (y > 0) {
        y -= yy;
      } else {
        y += yy;
      }
      });
  cout << (x == 0 && y == 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 384
import sys

def II(): return str(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    a = II()
    if a.islower() :
        print("a")
    else:
        print("A")

    
if __name__ == "__main__":
	main()

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

using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}

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

    int n;
    cin >> n;

    ll a_sum = 0;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        a_sum += a[i];
    }

    string s;

    ll ans;
    rep(i, n) {
        if (i == 0) {
            ans = a_sum;
            for (int j = 1; j < n; j+=2) {
                ans -= (ll)2 * a[(i+j)%n];
            }
        } else {
            ans = (ll)2 * a[i-1] - ans;
        }
        s.append(to_string(ans));
        if (i != n-1) s.append(" ");
    }

    cout << s << endl;
}


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;

  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    int cnt = 0;
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) cnt++;
    }
    if (cnt == 8) ans++;
  }

  // 解答
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = 10**9 + 7


def powmod(x, y, mod):
    if y == 0:
        return 1
    return (((powmod(x, y >> 1, mod) ** 2) % mod) * x ** (y & 1)) % mod


def cmb(n, r, MOD):
    if n < r:
        return 0
    if n-r < r:
        r = n-r
    comb = 1
    for x in range(n-r+1, n+1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, r+1):
        d = (d * x) % MOD
    comb *= powmod(d, MOD-2, MOD)
    return comb % MOD


a = cmb(n, a, mod)
b = cmb(n, b, mod)
ans = powmod(2, n, mod) - a - b - 1
print(ans % mod)


Measured memory_bytes: 3064
import java.util.Scanner;

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

        int x = scanner.nextInt(16);
        int y = scanner.nextInt(16);

        System.out.println((x == y) ? "=" : (x > y) ? ">" : "<");
    }
}


Measured memory_bytes: 23380
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") 
///#pragma GCC target("avx2")
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <numeric>

using namespace std;
#define open_streams ifstream fin("olympiad.in");ofstream fout("olympiad.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
//const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 4e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 1e6 + 100;






signed main() {
	speed;
	ll n, a, b;
	cin >> n >> a >> b;
	ll x = n / (a + b);
	ll sum = x * a;
	cout << sum + min(n - x*(a+b), a);
	return 0;
}

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

Rcount = 0
Lcount = 0
ans = [0]*len(S)
for i in range(len(S)-1):
    if (S[i] == "R") and (S[i+1] == "R"):
        Rcount += 1
    elif (S[i] == "R") and (S[i+1] == "L"):
        Rcount += 1
        temp = i
    elif (S[i] == "L") and (S[i+1] == "L"):
        Lcount += 1
    elif (S[i] == "L") and (S[i+1] == "R"):
        Lcount += 1
        count = Rcount + Lcount
        if count % 2 == 0:
            ans[temp] = count/2
            ans[temp+1] = count/2
        elif Rcount % 2 == 0:
            ans[temp] = count//2
            ans[temp+1] = (count//2) + 1
        else:
            ans[temp+1] = count//2
            ans[temp] = (count//2) + 1
        Rcount = 0
        Lcount = 0

    if i == len(S)-2:
        Lcount += 1
        count = Rcount + Lcount
        if count % 2 == 0:
            ans[temp] = count/2
            ans[temp+1] = count/2
        elif Rcount % 2 == 0:
            ans[temp] = count//2
            ans[temp+1] = (count//2) + 1
        else:
            ans[temp+1] = count//2
            ans[temp] = (count//2) + 1

for i in range(len(ans)):
    print(int(ans[i]), end = " ")


Measured memory_bytes: 7844
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

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

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

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

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) {
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

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

int main() {
	ll ans = 0;
	ll cnt = 0;
	ll n, m; cin >> n >> m;
	vector<vector<char>> data(n, vector<char>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> data[i][j];
			if (data[i][j] == '#') cnt++;
		}
	}
	if (cnt == n + m - 1) {
		cout << "Possible" << endl;
	}
	else cout << "Impossible" << endl;
}

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

using namespace std;
using ll = long long;

// 最大公約数を求める (a > b) 非再帰ver
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

int main(void) {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        ans += gcd(k, gcd(i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define LL long long

int main() {
    LL n, T;
    cin >> n >> T;

    vector<long long> vt(n);
    for (int i = 0; i < n; ++i) {
        cin >> vt[i];
    }
    
    LL ans = n * T;
    for (int i = 0; i < n - 1; ++i) {
        ans -= max(vt[i] + T - vt[i + 1], 0LL);
    }

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

Measured memory_bytes: 1792
L,R = map(int,input().split(" "))
remind = 2020
if L + 1 == R:
    print((R * L) % 2019)
else:
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            r = (i * j) % 2019
            if r < remind:
                remind = r
                if remind == 0:
                    print(0)
                    exit(0)
    print(remind)

Measured memory_bytes: 3064
#include <cstdio>
using namespace std;
int main() {
	int a, b;
	int d, r;
	double f;
	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	f = (double)a / b;
	printf("%d %d %lf\n", d, r, f);
}


Measured memory_bytes: 2684
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

const int mul=500000004;
const int mod=1e9+7;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	ll x=0, y=0, A;
	for (int i=0; i<N; i++) {
		cin>>A;
		x=(x+A)%mod;
		y=(y+A*A)%mod;
	}
	cout<<(x*x+mod-y)%mod * mul % mod<<"\n";
	return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  string s;
  ll K;
  cin >> s;
  int N = s.size();
  cin >> K;
  string A = "abcdefghijklmnopqrstuvwxyz";

  int last_index = N-1;
  for(int i = 0; i < N-1; i++){
    // aにするまでの回数
    int num;
    num = 'z' - s[i] + 1;
    num %= 26;

    if(num <= K){
      // aにする
      s[i] = 'a';
      K -= num;
    } else { 
      // aにできない
      continue;
    } 
  }
  
  //後処理
  int tmp = s[N-1] - 'a';
  int next = tmp + K;
  next %= 26;
  s[N-1] = A[next];

  cout << s << endl;
  
}


Measured memory_bytes: 512
#include <stdio.h>
 
int main()
{
  int a,b;    
 
  scanf("%d %d", &a, &b);
 
  if (a < b) {
    printf ("a < b\n");
  } else if (a > b) {
    printf ("a > b\n");
  } else if (a == b) {
    printf ("a == b\n");
  }
 
  return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  REP(i,7){
	int a, b;
	cin >> a >> b;
	cout << a-b << endl;
  }

  return 0;
}



Measured memory_bytes: 3188
use proconio::input;

fn sum(l: usize, r:usize)-> usize {
  (l + r) * (r-l+1) / 2
}

fn main() {
  let Mod = 1_000_000_007;
  input! {
    N: usize,
    K: usize
  }
  
  let mut result = 0;
  
  for i in K..=N+1 {
    let l = sum(0, i-1);
    let r = sum(N-i+1, N);
    result = (result + r - l + 1) % Mod;
  }
  
  println!("{}", result);
}

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

int main() {
  int x = 0;
  string s,t;
  cin >> s >> t;
  for(int i = 0; i < t.size(); i++){
    if(s[i] != t[i]){
      x += 1;
    }
  }
  cout << x << endl;
  return 0;
}



Measured memory_bytes: 3768
def main
  a,v = gets.chomp.split(" ").map(&:to_i)
  b,w = gets.chomp.split(" ").map(&:to_i)
  t = gets.to_i
  if (v-w) * t >= (a-b).abs
    puts 'YES'
  else
    puts 'NO'
  end
end

main



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

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
#define fr first
#define sc second

using namespace std;


int main(){

    ios::sync_with_stdio(0);
    cin.tie(0) , cout.tie(0);
    int a , b , c; cin >> a >> b>> c;
    swap(a , b);
    swap(a , c);
    cout << a << ' ' << b << ' ' << c  << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    char S[5];
    char A, B;
    int cntA, cntB;
    cntA =0;
    cntB =0;
    cin >> S;
    A = S[0];
    for(int i =1; i < 4; i++){
        if (S[i]!=A){
            B = S[i];
        }
        
    }
    for(int i=0; i < 4; i++){
        if (S[i]==A){
            cntA+=1;
        }else if (S[i]==B){
            cntB+=1;
        }
    }
    if (cntA ==2 & cntB==2){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
}

Measured memory_bytes: 256
N=int(input())
L=[]
for i in range(N):
    a=int(input())
    L.append(a)
#print(L)
if L[0]!=0:
    print(-1)
    exit()
for i in range(1,N):
    if L[i]>L[i-1]+1:
        print(-1)
        exit()
L.append(0)
L=L[::-1]
#print(L)
ans=0
for i in range(1,len(L)):
    if L[i]>=L[i-1]:
        ans+=L[i]
print(ans)
    

Measured memory_bytes: 63576
//Property Distribution
#include <iostream>
#include <cstring>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)

int W, H, ans;
char a[101][101];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


int dfs(int x, int y) {
	char cur = a[x][y];
	a[x][y] = 'X';
	fo(i, 4) {
		int xx = x + dx[i], yy = y + dy[i];
		if (xx >= 0 && xx < H && yy >= 0 && yy < W && a[xx][yy] == cur)
			dfs(xx, yy);
	}
}



void solve() {
	ans = 0;
	fo(i, H) cin >> a[i];
	fo(i, H) {
		fo(j, W) {
			if (a[i][j] != 'X') {
				dfs(i, j);
				ans++;
			}
		}
	}
}



int main() {
	//freopen("in.txt", "r", stdin);
	while (cin >> H >> W && W && H) {
		solve();
		cout << ans << endl;
	}
}

Measured memory_bytes: 3480
/*package whatever //do not write package name here */

import java.io.*;
import java.lang.Math; 
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
	    Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[][] act = new int[3][n];
		
		for(int i = 0; i < n; i++){
		    act[0][i] = scan.nextInt();
		    act[1][i] = scan.nextInt();
		    act[2][i] = scan.nextInt();
		}
		
		int[][] dp = new int[3][n];
		dp[0][0] = act[0][0];
		dp[1][0] = act[1][0];
		dp[2][0] = act[2][0];
		
		for(int i = 1; i < n; i++ ){
		    dp[0][i] = act[0][i] + Math.max(dp[1][i-1],dp[2][i-1]);
		    dp[1][i] = act[1][i] + Math.max(dp[0][i-1],dp[2][i-1]);
		    dp[2][i] = act[2][i] + Math.max(dp[0][i-1],dp[1][i-1]);
		}
		int max = Math.max(dp[0][n-1],Math.max(dp[1][n-1],dp[2][n-1]));
		System.out.println(max);
		
	}
}

Measured memory_bytes: 51288
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
tmp = A[0] + sum(B)
ans = tmp
for i in range(N-1):
    tmp = tmp - B[i] + A[i+1]
    if ans < tmp:
        ans = tmp
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N;
  cin >> N;
  vector<int> order(N);
  FOR(i, N) cin >> order[i];
  int ans = 0;
  FOR(i, N) {
    int B;
    cin >> B;
    ans += B;
  }
  vector<int> C(N - 1);
  FOR(i, N - 1) cin >> C[i];
  FOR(i, N - 1) {
    if (order[i] == order[i + 1] - 1) {
      ans += C[order[i] - 1];
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
package main

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

var count int = 0

func main () {
  sc := bufio.NewScanner(os.Stdin)

  var m int = 0
  var G []int

  // Get "length"
  var length int
  if sc.Scan() { length, _ = strconv.Atoi(sc.Text()) }

  // Set "m"
  for i := 1; ; i = 3*i + 1{
    if i > length { break }
    G = append(G, i)
    m++
  }

  // Get input array
  input := make([]int, length)
  for i := 0; i < length; i++ {
    if sc.Scan() { input[i], _ = strconv.Atoi(sc.Text()) }
  }

  for i := m; i > 0; i-- {
    input = insertionSort(input, length, G[i-1])
  }

  // Print
  fmt.Printf("%d\n", m)
  for i := m-1; i > 0; i-- {
    fmt.Printf("%d ",G[i])
  }
  fmt.Printf("%d\n", G[0])
  fmt.Printf("%d\n", count)
  for i := 0; i < length; i++ {
    fmt.Printf("%d\n", input[i])
  }
}

func insertionSort(input []int, length, gap int) []int{
  var v, j int
  for i := gap; i < length; i++ {
    v = input[i]
    j = i - gap
    for ;j >= 0 && input[j] > v; {
      input[j + gap] = input[j]
      j = j-gap
      count++
    }
    input[j+gap] = v
  }

  return input
}



Measured memory_bytes: 17408
import sys,heapq
input = sys.stdin.readline

def main():
    q = int(input())
    
    big = [10**10]
    sma = [10**10]
    sb = 0
    ss = 0

    rr = 0

    for _ in [None]*q:  
        m = tuple(map(int,input().split()))
        
        if m[0] == 1:
            a = m[1]
            rr += m[2]

            if big[0] <= a:
                heapq.heappush(big,a)
                sb += a
            elif -sma[0] >= a:
                heapq.heappush(sma,-a)
                ss += a
            elif len(sma) >= len(big):
                heapq.heappush(sma,-a)
                ss += a
            else:
                heapq.heappush(big,a)
                sb += a
            
            while len(big) > len(sma)+1:
                p = heapq.heappop(big)
                heapq.heappush(sma,-p)
                ss += p
                sb -= p
            
            while len(sma) >  len(big)+1:
                p = -heapq.heappop(sma)
                heapq.heappush(big,p)
                sb += p
                ss -= p
            
        else:
            if len(big) > len(sma):
                mid = big[0]
            else:
                mid = -sma[0]
            
            print(mid,sb-mid*(len(big)-1) + mid*(len(sma)-1) -ss +rr)

if __name__ =="__main__":
    main()
            

Measured memory_bytes: 80732
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll x; cin>>x;
    int a=x/500;
    x-=a*500;
    int b=x/5;
    cout<<1000*a+5*b<<"\n";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
int_list = sorted([int(input()) for i in range(n)],reverse=True)
count = 1
i= 0
while i + 1 < len(int_list) :
    if int_list[i] > int_list[i + 1]:
        count += 1
    i += 1 
print(count)

Measured memory_bytes: 9184