akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
  int k;
  scanf("%d", &k);
  cout << a[k - 1] << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] height = new int[n];
    int num = 0;
    for(int i = 0; i < n; i++){
      int t = sc.nextInt();
      if(t>=k){
        num++;
      }
    }
    System.out.println(num);
  }
}

Measured memory_bytes: 49384
#include<bits/stdc++.h>
 using namespace std;
int gcd(int a, int b){
 return __gcd(a,b);
}

int main(){
  int n,r;
  std::cin >> n;
bool b=false;
  while(n!=0){
   r= n%10;
   n/=10;
   if(r==7) {
        b= true; break;
   }
  }
if(b)
  cout << "Yes"  << endl; 
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3592
<?php
$str = trim(fgets(STDIN));
$array = [];
$count = 0;
for($i = 0; $i < strlen($str);$i++){
  if($str[$i] == "S"){
    $array[] = "S";
    $count++;
  }else{
    if($array && $array[count($array) - 1] == "S"){
      array_pop($array);
      $count--;
    }else{
      $array[] = "T";
      $count++;
    }
  }
}
echo $count,"\n";

Measured memory_bytes: 12788
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] S = new String[N];
		int[] P = new int[N];
		int[] index = new int[N];
		TreeMap<String,Integer> shop = new TreeMap<String,Integer>();
		String[] ans = new String[N];
		for (int i=0;i<N;i++) {
			S[i]=sc.next();
			P[i]=sc.nextInt();
			shop.put(S[i],i);
			index[i]=i+1;
			ans[i]=S[i]+"_"+String.valueOf(1900-P[i])+"_"+String.valueOf(index[i]);
		}
		Arrays.sort(ans);
		for (int i=0;i<N;i++) {
			String[] str = ans[i].split("_");
			System.out.println(str[2]);
		}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

vector<int> topologicalSort(vector<vector<int>> &G) {
    int n = G.size();
    vector<int> indegree(n, 0);
    REP(i, 0, n) {
        for (auto g : G[i]) {
            indegree[g]++;
        }
    }

    stack<int> st;
    REP(i, 0, n) if (indegree[i] == 0) st.push(i);

    vector<int> sorted;
    while (!st.empty()) {
        auto v = st.top(); st.pop();
        sorted.push_back(v);
        for (auto g : G[v]) {
            indegree[g]--;
            if (indegree[g] == 0) st.push(g);
        }
    }
    return sorted;
}

int main() {
    int N, M; cin >> N >> M;

    vector<vector<int>> G(N);
    REP(i, 0, N - 1 + M) {
        int u, v; cin >> u >> v;
        G[--u].push_back(--v);
    }

    auto sorted = topologicalSort(G);
    vector<int> idx(N, 0);
    REP(i, 0, sorted.size()) {
        idx[sorted[i]] = i;
    }

    vector<int> ans(N, -1);
    REP(i, 0, N) {
        for (auto g : G[i]) {
            if (ans[g] == -1 || idx[ans[g]] < idx[i]) {
                ans[g] = i;
            }
        } 
    } 

    REP(i, 0, N) cout << ans[i] + 1 << endl;
    return 0;
}

Measured memory_bytes: 9908
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e5 + 5 ;
int n , r ;
char s[maxn] ;
int main()
{
	scanf("%d%d" , &n , &r) ;
	if(n >= 10)  printf("%d\n" , r) ;
	else  printf("%d\n" , r + 100 * (10 - n)) ;
    return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
//#include <math.h>
using namespace std;
typedef long long LL;

int main()
{
	int g[3][3];
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			cin >> g[i][j];

	bool res = true;
	int difs[] = { 0,1,0,2,1,2 };
	for (int i = 0; res &&  i < 6; i += 2) {
		int a = difs[i], b = difs[i + 1];
		int dif = g[a][0] - g[b][0];
		if ((dif != g[a][1] - g[b][1]) || (dif != g[a][2] - g[b][2])) {
			res = false;
		}
		else {
			dif = g[0][a] - g[0][b];
			if ((dif != g[1][a] - g[1][b]) || (dif != g[2][a] - g[2][b])) {
				res = false;
			}
		}

	}

	cout << (res ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define max 100000
int A[max],n;

int partition(int p,int r){
    int x,i,j,t;
    x=A[r];
    i=p-1;
    for(j=p;j<=r-1;j++){
        if(A[j]<=x){
            i++;
            t=A[i];
            A[i]=A[j];
            A[j]=t;
        }
    }
    t=A[i+1];
    A[i+1]=A[r];
    A[r]=t;
    return i+1;
}

int main(){
    scanf("%d",&n);
    int i;
    for(i=0;i<=n-1;i++)scanf("%d",&A[i]);
    int q;
    q=partition(0,n-1);
    for(i=0;i<=n-1;i++){
        if(i)printf(" ");
        if(i==q)printf("[");
        printf("%d",A[i]);
        if(i==q)printf("]");
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 992
#include <stdio.h>

int main(void) {
	int a, b;
	char ope;
	
	while(1) {
		scanf("%d %c %d", &a, &ope, &b);
		
		if(ope == '?') {
			break;
		}
		
		if(ope == '+') {
			printf("%d\n", a + b);
		} else if(ope == '-') {
			printf("%d\n", a - b);
		} else if(ope == '*') {
			printf("%d\n", a * b);
		} else if(ope == '/') {
			printf("%d\n", a / b);
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
from collections import deque
# import sys
# input = sys.stdin.readline
n, x, y = map(int, input().split())
g = dict()
for i in range(n):
    if i == 0:
        g[i] = [i+1]
    elif i == n-1:
        g[i] = [i-1]
    else:
        g[i] = [i-1, i+1]
g[x-1].append(y-1)
g[y-1].append(x-1)
# print(g)
distance = [0]*(n-1)
# 1番ノードから各ノードへの最短距離を求めていく.
for i in range(n):
    queue = deque()
    visited = [0]*n
    # まず処理される予定のノードが格納されているqueueに最初のノードを格納する
    queue.append(i)
    while queue:
        target = queue.popleft()
        for j in g[target]:
                if visited[j] == 0 or visited[j] > visited[target] + 1:
                    visited[j] = visited[target] + 1
                    queue.append(j)
    for k, a in enumerate(visited):
        if k > i:
            if a >= 1:
                distance[a-1] += 1
    # print(f"{i}番ノードからの各ノードへの最短距離は{visited}である")
for l in distance:
    print(l)

Measured memory_bytes: 48476
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int n;
	int d[100000];
	
	cin >> n;
	for(int i=0;i<n;i++) cin >> d[i];

	sort(d,d+n);

	cout << d[n/2] - d[n/2-1] << endl;

	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

long long MOD = 1000000007;
vector<long long> F;

long long Calc(long long A, long long B) {
	if (B == 0) return 1;
	if (B % 2 == 0) {
		long long C = Calc(A, B / 2);
		return (C * C) % MOD;
	}
	return (A * Calc(A, B - 1)) % MOD;
}

void init(long long N) {
	F.resize(N + 1);
	F[0] = F[1] = 1;
	for (long long i = 2; i <= N; i++) {
		F[i] = (F[i - 1] * i) % MOD;
	}
	return;
}

int main() {
	long long N, ANS = 0, Cur = 0;
	vector<long long> X;
	cin >> N;
	X.resize(N);
	init(N);
	for (int i = 0; i < N; i++) cin >> X[i];
	for (int i = 1; i < N; i++) {
		long long COUNT = (F[N - 1] * Calc(i, MOD - 2)) % MOD;
		Cur = (Cur + COUNT) % MOD;
		ANS = (ANS + Cur * (X[i] - X[i - 1])) % MOD;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; 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 REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll solve(ll a, ll b){
    return (a + b - 1) / b;
}
int main() {
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    if (v > w and solve(abs(a - b), (v - w)) <= t) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n, m;
	cin >> n >> m;
	vector <int> A(n);
	ll sumx = 0, resx = 0;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		resx += (i * x - sumx);
		sumx += x;
	}
	ll sumy = 0, resy = 0;
	for (int i = 0; i < m; i++) {
		ll y;
		cin >> y;
		resy += (i * y - sumy);
		sumy += y;
	}
	resx %= MOD;
	resy %= MOD;
	cout << (resx * resy) % MOD;
}


Measured memory_bytes: 640
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

void test() {
    ll L = 1;
    for(int i=1; i<=40; i++) L = lcm(L, i);
    cout << L << endl;
}

int main() {
    // test();

    int N; cin >> N;    
    vector<ll> P(N);
    for(int i=0; i<N; i++) {
        cin >> P[i];
    }

    int ans = 0;
    for(int bit=1; bit<(1<<N); bit++) {
        ll L = 1;
        for(int i=0; i<N; i++) if(bit >> i & 1) L = lcm(L, P[i]);
        bool ok = true;
        for(int i=0; i<N; i++) ok &= (bit >> i & 1) or L % P[i] != 0;
        if(ok) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3116
#include<cstdio>
#include<algorithm>
using namespace std;
int dp[200][200],a[200],b[200],c[200],m,w[200];
int main(void)
{
	int d,n,i,j,k,x;
	scanf("%d %d",&d,&n);
	for(i=0;i<d;i++){
		scanf("%d",&w[i]);
	}
	for(i=0;i<d;i++){
		for(j=0;j<n;j++){
			dp[i][j]=-1;
		}
	}
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		if(a[i]<=w[0]&&w[0]<=b[i]){
			dp[0][i]=0;
		}
	}
	for(i=0;i<d-1;i++){
		for(j=0;j<n;j++){
			if(dp[i][j]!=-1){
				for(k=0;k<n;k++){
					if(a[k]<=w[i+1]&&w[i+1]<=b[k]){
						x=c[j]-c[k];
						if(x<0)	x=-x;
						dp[i+1][k]=max(dp[i+1][k],dp[i][j]+x);
					}
				}
			}
		}
	}
	m=0;
	for(i=0;i<n;i++){
		m=max(m,dp[d-1][i]);
	}
	printf("%d\n",m);
	return 0;
}


Measured memory_bytes: 2892
N,M=gets.split.map &:to_i
value=N.times.map{gets.split.map(&:to_i)}
ans=0
if M==0
    puts 0
    exit 0
end

for i in 0..7
    value_abs=value.map{|e|e.map.with_index{|c,j|c*((-1)**i[j])}.inject(:+)}.sort.reverse
    judge=value_abs[0...M].inject(:+)
    ans = ans < judge ? judge : ans
end
puts ans


Measured memory_bytes: 4344
fun main(args: Array<String>) {
    val s = readLine()!!.toString()
    var ans = true
    s.withIndex().forEach {
        if (it.index % 2 == 0) {
            if (!(it.value == 'R' || it.value == 'U' || it.value == 'D')) {
                ans = false
            }
        }
        if (it.index % 2 != 0) {
            if (!(it.value == 'L' || it.value == 'U' || it.value == 'D')) {
                ans = false
            }
        }
    }

    println(if(ans) "Yes" else "No")
}


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

#ifdef DEBUG
#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))

#define LOGM(msg) (cerr << (msg))

#define LOGV(vec, sep) {                                        \
    cerr << #vec << " =";                                       \
    for (const auto& v : (vec)) cerr << " " << v;               \
    cerr << (sep); }

#define LOGA(arr, N, sep) {                                     \
        cerr << #arr << " =";                                   \
        for (int i = 0; i < N; ++i) cerr << " " << (arr)[i];    \
        cerr << (sep); }

#define LOGA2(arr, N, M, sep) {                                 \
        cerr << #arr << " =\n";                                 \
        for (int i = 0; i < N; ++i) {                           \
            for (int j = 0; j < M; ++j)                         \
                cerr << (arr)[i][j] << " ";                     \
            cerr << endl;                                       \
        } cerr << (sep); }
#else
#define LOG(var, sep)
#define LOGM(msg)
#define LOGV(vec, sep)
#define LOGA(arr, N, sep)
#define LOGA2(arr, N, M, sep)
#endif

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, X, T;
    cin >> N >> X >> T;

    auto ans = (N + X - 1)/X;

    cout << T*ans << '\n';

    return 0;
}


Measured memory_bytes: 3636
def selsort(array):
    counter = 0
    for i in range(len(array)):
        minnum = i
        for c in range(i,len(array)):
            if array[c] < array[minnum]:
                minnum = c
        if minnum != i:
            x = array[i]
            array[i] = array[minnum]
            array[minnum] = x
            counter = counter + 1
    array.append(counter)

N = int(input())
arr = [int(i) for i in input().split()]

selsort(arr)
print(' '.join([str(i) for i in arr[:-1]]))
print(arr[-1])

Measured memory_bytes: 7708
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

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

	int ans = 0;
	for(int i=1;i<=n;i++){
		if(1<=i && i<10) ans++;
		if(100<=i && i<1000) ans++;
		if(10000<=i && i<100000) ans++;
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX = 100001;

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	int N, X[MAX];
	cin >> N;
	for (int i = 0;i <= N;++ i) cin >> X[i];
	sort(X, X+N+1);
	int ans = X[1] - X[0];
	for (int i = 0;i < N;++ i) ans = gcd(ans, X[i + 1] - X[i]);
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

結局、移動を要約すると整数nに対しX+nDにしか移動できない
つまり、全ての距離の最大公約数がDになる
*/

Measured memory_bytes: 640
import sys
#input = sys.stdin.buffer.readline


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

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

#import numpy as np
from collections import defaultdict

def main():
	n=II()
	d=defaultdict(int)
	for _ in range(n):
		d[input()]+=1


	print("AC x "+str(d["AC"]))
	print("WA x "+str(d["WA"]))
	print("TLE x "+str(d["TLE"]))
	print("RE x "+str(d["RE"]))






if __name__ == "__main__":
	main()


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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int mod = 1e9 + 7;
const int MAX = 1e5 + 1;

int main()
{
	IOS
	int t = 1;
	//cin >> t;
	while(t--)
	{
		string s;
		cin >> s;
		int ct = 0;
		for(int i = 0; i < s.length(); ++i)
			if(s[i] == 'R') ct += 1;

		if(ct == 0) cout << 0;
		else if(ct == 3) cout << 3;
		else if(ct == 1) cout << 1;
		else
		{
			if(s[0] == 'R' && s[1] == 'R' || s[1] == 'R' && s[2] == 'R') cout << 2;
			else cout << 1;
		}
	}
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define MAX 100000

using namespace std;

typedef long long ll;


ll arr[MAX];

int main()
{

    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif



    int n;
    cin>>n;
    for( int i = 0; i < n; ++i )
    {
        cin>>arr[i];
    }
    ll v1 = 0;
    ll v2 = 0;
    ll bef1 = 0, bef2 = 0;
    for( int i = 0; i < n; i++ )
    {
        bef1 += arr[i];
        bef2 += arr[i];
        if ( i%2 == 0 )
        {
            if ( bef1 <= 0ll )
            {
                  v1 += abs(bef1)+1ll;
                  bef1 = 1;
            }
            if ( bef2 >= 0ll )
            {
                  v2 += abs(bef2)+1ll;
                  bef2 = -1;
            }
        }
        else
        {
            if ( bef2 <= 0ll )
            {
                v2 += abs(bef2)+1ll;
                bef2 = 1;
            }
            if ( bef1 >= 0ll )
            {
                v1 += abs(bef1)+1ll;
                bef1 = -1;
            }
        }
    }
    cout<<min(v1, v2)<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];

  int res =0;
  rep(i,n){
    rep(j,n){
      if(i>=j) continue;
      res+=d[i]*d[j];
    }
  }

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let s: Vec<Vec<char>> = (0..n).map(|_| read::<String>().chars().collect()).collect();

    let mut ans = 0;
    for i in 0..n {
        let mut ok = true;
        for j in 0..n {
            for k in 0..n {
                let x = (j + n - i) % n;
                let y = (k + i) % n;
                if s[j][k] != s[y][x] {
                    ok = false;
                }
            }
        }
        if ok {
            ans += n;
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=200005;
int a[N];
int main() {
    int n,k,i,j;
    scanf("%d %d",&n,&k);
    memset(a,0,sizeof(a));
    int x;
    for(i=0;i<n;i++){
        scanf("%d",&x);
        a[x]++;
    }
    sort(a,a+N+1);
    int ans=0;
    for(i=N-k;i>=1;i--){
        ans+=a[i];
        if(a[i]==0)break;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int get() { int r; cin >> r; return r; }
int n, d, a;
pair<int, int>xh[234567];
int x[234567], k[234567];
signed main() {
	cin >> n >> d >> a;
	for1(i, n)cin >> xh[i].first >> xh[i].second;
	sort(xh + 1, xh + n + 1); x[0] = -1;
	for1(i, n) {
		if (i > 1) {
			int r = 0, l = i - 1;
			if (x[l] < xh[i].first);
			else {
				while (l - r > 1) {
					int mid = (r + l) / 2;
					if (x[mid] < xh[i].first)r = mid;
					else l = mid;
				}
				xh[i].second -= a * (k[i - 1] - k[r]);
			}
		}
		xh[i].second = max(xh[i].second, (int)0);
		int p = (xh[i].second + a - 1) / a;
		x[i] = xh[i].first + 2 * d;
		k[i] = k[i - 1] + p;
	}
	cout << k[n] << endl;
}

Measured memory_bytes: 6784
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int N;
    int X[8],Y[8];

    scanf("%d",&N);
    for(int i=0; i<N; i++)
        scanf("%d %d",&X[i],&Y[i]);
  
    int array[] = {0,1,2,3,4,5,6,7};

    double sum = 0;
    do{
        for(int i=0; i<N-1; i++){
            int tmp1 = array[i];
            int tmp2 = array[i+1];
            sum += hypot(X[tmp1]-X[tmp2],Y[tmp1]-Y[tmp2]);
        }
    }while(next_permutation(array,array+N));

    long long C=1;
    for(int i=1; i<=N; i++)
        C*=i;
    cout << fixed << setprecision(6) << sum / C << '\n';

    return 0;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[3030][3030];

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

    ll a[3030];
    for(int i=1; i<=N; i++){
        cin >> a[i];
    }

    for(int i=1; i<=N; i++){
        dp[i][i-1]=0;
    }
    for(int k=0; k<=N-1; k++){
        for(int i=1; i<=N-k; i++){
            if( (N-k)%2 ){ //太郎
                dp[i][i+k] = max (dp[i][i+k-1]+a[i+k], dp[i+1][i+k]+a[i]);
            }
            if( (N-k)%2==0 ){ //次郎
                dp[i][i+k] = min (dp[i][i+k-1]-a[i+k] ,dp[i+1][i+k]-a[i] );
            }
        }
    }
//    cout << dp[1][1] <<" " << dp[1][2] << " " << dp[2][2] << endl;
    cout << dp[1][N] << endl;
}

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

int main() {
  int N, K; cin >> N >> K;
  ll ans {};
  for (int i = K + 1; i <= N; i++) {
    ans += max(0, i - K) * (N / i);
    ans += max(0, N % i - K + 1);
  }
  cout << ans - (!K * N) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>

using namespace std;

typedef long long ll;


int N, K;
int x[3000], y[3000];
vector<P> c;

int gcb(int a, int b) {
	if (b == 0) return a;
	return gcb(b, a%b);
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}


	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) continue;

			int dx = x[i] - x[j];
			int dy = y[i] - y[j];

			int g = gcb(dx, dy);
			dx /= g; dy /= g;

			if (dx < 0) {
				dx = -dx; dy = -dy;
			}
			if (dx == 0) dy = abs(dy);

			c.emplace_back(dx, dy);
		}

		sort(c.begin(), c.end());
		P last = c[0];
		int cnt = 1, res = 1;
		for (int j = 1; j < c.size(); j++) {
			if (c[j] == last) {
				cnt++;
			}
			else {
				cnt = 1;
			}
			res = max(res, cnt);
			last = c[j];
		}
		if (res >= K - 1) {
			cout << 1 << endl;
			return 0;
		}
		c.clear();
	}

	cout << 0 << endl;


	return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
int H, W, D, A;
int Q, L, R;
int px[90001], py[90001];
int d[90001];
int main()
{
    scanf("%d%d%d", &H, &W, &D);
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
        {
            scanf("%d", &A);
            px[A] = i, py[A] = j;
        }
    for (int i = D + 1; i <= H * W; i++)
        d[i] = d[i - D] + abs(px[i] - px[i - D]) + abs(py[i] - py[i - D]);
    scanf("%d", &Q);
    while (Q--)
    {
        scanf("%d%d", &L, &R);
        printf("%d\n", d[R] - d[L]);
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n_=1<<19;

class segtree{
public:
	int dp[1<<20];
	segtree(){
		memset(dp,0,sizeof(dp));
	}
	void update(int k,int v){
		k+=n_-1;
		dp[k]=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=min(dp[k*2+1],dp[k*2+2]);
		}
	}

	int query(int a,int b,int k=0,int l=0,int r=n_){
		if(b<=l || r<=a)return 2e9;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		return min(vl,vr);
	}
};

segtree seg[2];

int n,q;
int a[200005],b[200005];
set<int> s;

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		seg[0].update(i,a[i]);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
		seg[1].update(i,b[i]);
	}
	scanf("%d",&q);
	bool flag=false;
	for(int i=0;i<q;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		y--;
		if(x==1){
			s.insert(y);
			seg[0].update(y,z);
		}
		if(x==2){
			s.insert(y);
			seg[1].update(y,z);
		}
		if(x==3){
			printf("%d\n",seg[0].query(y,z));
		}
		if(x==4){
			printf("%d\n",seg[1].query(y,z));
		}
		if(x==5 || x==6){
			int side=x-5;
			if(!flag){
				for(int i=0;i<n;i++){
					seg[side].update(i,seg[1-side].query(i,i+1));
				}
				flag=true;
			}else{
				for(set<int>::iterator it=s.begin();it!=s.end();it++){
					seg[side].update(*it,seg[1-side].query(*it,(*it)+1));
				}
			}
			s.clear();
		}
	}
	return 0;
}

Measured memory_bytes: 12948
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main()
{   long long a,b,c;
    cin>>a>>b>>c;

    long long x=a/b;

    if(a%b==0)
    	cout<<c*x<<endl;
    else
    	cout<<((c)*(x+1))<<endl;
 
    }
 

Measured memory_bytes: 3632
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  const A = Number.parseInt(inputStr[0]);
  const B = Number.parseInt(inputStr[1]);
  //結果
  console.log((A-B*2) < 0? 0 : (A-B*2));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int solve();

int main(int argc, char const *argv[])
{
	int result{solve()};
	if (result > 0) printf("LESS\n");
	else if (result == 0) printf("EQUAL\n");
	else printf("GREATER\n");

	return 0;
}

int solve()
{
	std::string a, b;
	std::cin >> a >> b;
	if (a.size() < b.size()) return 1;
	if (a.size() > b.size()) return -1;

	if (a < b) return 1;
	if (a == b) return 0;
	if (a > b) return -1;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
def count_8(i,j):
    global h,w,s
    cnt=0
    if i-1>=0 and j-1>=0:
        if s[i-1][j-1]=="#":
            cnt+=1
    if i-1>=0 and j+1<=w-1:
        if s[i-1][j+1]=="#":
            cnt+=1
    if i+1<=h-1 and j-1>=0:
        if s[i+1][j-1]=="#":
            cnt+=1
    if i+1<=h-1 and j+1<=w-1:
        if s[i+1][j+1]=="#":
            cnt+=1
    if i-1>=0:
        if s[i-1][j]=="#":
            cnt+=1
    if j-1>=0:
        if s[i][j-1]=="#":
            cnt+=1
    if i+1<=h-1:
        if s[i+1][j]=="#":
            cnt+=1
    if j+1<=w-1:
        if s[i][j+1]=="#":
            cnt+=1
    return str(cnt)
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            print("#",end="")
        else:
            print(count_8(i,j),end="")
    print()


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



int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    char s[10];
    scanf("%s", s + 1);
    if (s[1] != s[2] && s[2] != s[3] && s[3] != s[4]) puts("Good");
    else puts("Bad");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll n,ans = 0;
    string s;
    cin >> n >> s;
    rep0(i, 1000){
        string t;
        if(i < 10){
            t += "00";
            t += to_string(i);
        }else if(i < 100){
            t += "0";
            t += to_string(i);
        }else{
            t += to_string(i);
        }
        t += 'a';
        ll cnt = 0;
        rep0(j, n){
            if(s[j] == t[cnt])++cnt;
        }
        if(cnt == 3)++ans;
    }
    pf(ans);
    return 0;
}


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



int insertionSort(int a[],int n){
    int v,j;
	for(int i=1;i<=n-1;i++){
		for(int ii=0;ii<n;ii++){
			if(ii!=n-1){
				cout<<a[ii]<<" ";
			}
			else{cout<<a[ii]<<endl;}
		}
		v=a[i];
		j=i-1;
		while(j>=0 && a[j]>v){
			a[j+1]=a[j];
			j--;
			a[j+1]=v;
		}
		/*
		for(int ii=0;ii<n;ii++){
			if(ii!=n-1){
				cout<<a[ii]<<" ";
			}
			else{cout<<a[ii]<<endl;}
		}
		*/
	}
	for(int i=0;i<n;i++){
		if(i!=n-1){
			cout<<a[i]<<" ";
		}else{
			cout<<a[i]<<endl;
		}
	}
		return 0;
}
int main(){
	int N,A[1001];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
    insertionSort(A,N);
	int aa;cin>>aa;
	
	return 0;
}

Measured memory_bytes: 3100
x1,y1,x2,y2 = map(int,input().split())

x3 = x2 + y1 - y2
y3 = y2 - x1 + x2
x4 = x3 + x1 - x2
y4 = y3 - y2 + y1
print(x3,y3,x4,y4)

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

int main() {
  ll n, d;
  cin >> n >> d;
  ll ans = 0;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) ans++;
  }

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

Measured memory_bytes: 3592
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace
import           Text.Printf

data Ans = Ans Int Int Int deriving Show


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

ansToGCD :: Ans -> Int
ansToGCD (Ans a b c) = foldl1' gcd [a,b,c]

solve :: [Ans] -> Int
solve anss = foldl' (\n m -> n + (ansToGCD m)) 0 anss

main = do
  -- let k = 200
  k <- readLn :: IO Int
  print $ solve $ Ans <$> [1..k] <*> [1..k] <*> [1..k]


Measured memory_bytes: 5032
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll a[1005];
int main()
{
    ll n;
    double ans = 0;
    cin >> n;
    for(ll i = 0; i < n; i ++)
    {
        cin >> a[i];
    }
    for(ll i = 0; i < n; i ++)
    {
        ans += 1 / (double)a[i];
    }
    cout << 1 / ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,int> pii;
const int N = 1e5+5;
const int M = 5e5+5;
#define pi acos(-1)
#define INF 1e18
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
int main()
{
	double r;
	cin >> r;
	printf("%.10f\n",2*pi*r);
	//system("pause");
	return 0;
}

Measured memory_bytes: 3784
package main

import (
	"fmt"
)

func main() {
	var a, b, k int
	for a > b || a < 1 || b > 1e9 || k < 1 || k > 100 {
		fmt.Scanf("%d %d %d", &a, &b, &k)
	}
	for i := 0; i < k; i++ {
		if a+i <= b {
			fmt.Println(a + i)
		}
	}
	for i := k - 1; i >= 0; i-- {
		if b-i >= a+k {
			fmt.Println(b - i)
		}
	}
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

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

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

    int N;
    cin >> N;

    string S, T;
    cin >> S >> T;

    string ans;

    for (int i = 0; i < N; ++i) {
        ans.push_back(S[i]);
        ans.push_back(T[i]);
    }

    cout << ans << endl;

    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),A=in(),B=in(),C=in(),D=in();
	vector<int> S(N);
	REP(i,N){
		char c=in<char>();
		S[i] = c=='.' ? 0 : 1;
	}

	// BtoD
	bool find_one=false;
	for(int i=B-1;i<D;i++){
		if(!find_one && S[i]==1) find_one = true;
		else if(find_one){
			if(S[i]==0) find_one = false;
			else{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	// AtoC
	find_one=false;
	for(int i=A-1;i<C;i++){
		if(!find_one && S[i]==1) find_one = true;
		else if(find_one){
			if(S[i]==0) find_one = false;
			else{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	
	if(D<C){
		bool find_zero=false;
		int zero_count = 0,max_zero_count=-1;
		for(int i=max(B-2,0),ei=min(D+1,N);i<ei;i++){
			if(!find_zero){
				if(S[i]==0){
					find_zero = true;
					zero_count=1;
				}
				else{
					zero_count = 0;
				}
			}
			else if(find_zero){
				if(S[i]==0){
					zero_count++;
				}
				else{
					find_zero = false;
					zero_count = 0;
				}
				max_zero_count = max(zero_count,max_zero_count);
			}
		}
		if(max_zero_count<3){
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 152076289;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;//100000
const int MAX_N = (1 << 17);
int nn;ll dat[2 * MAX_N - 1];
void init(int n_) {
	nn = 1;
	while (nn < n_)nn *= 2;
}
void update(int k, ll a) {
	k += nn - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}
ll query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l)return 0;
	if (a <= l && r <= b)return dat[k];
	else {
		ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
}
int main(){
	int n; cin >> n; init(n + 1);
	ll sum = (ll)n*(n + 1) / 2;
	ll ma = 0;
	rep(i, n) {
		ll a; cin >> a;
		ll csum = query(1, a, 0, 0, nn) + a;
		ma = max(ma, csum);
		update(a, csum);
	}
	cout << sum - ma << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define X first;
#define Y second;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 1e5 + 10;
const int maxK = 1e4+10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 998244353;

int main()
{
	ll n,x,t;
	cin>>n>>x>>t;
	
	int cnt = n/x + (n%x != 0);
	cout<<cnt*t<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mod 1000000007
using namespace std;

int n;
long long dp1[300010],dp2[300010],a[300010],sum1,sum2;

priority_queue<long long,vector<long long>,greater<long long> > q;
priority_queue<long long> q2;

int main()
{
	scanf("%d",&n);
	memset(dp1,0,sizeof(dp1));
	memset(dp2,0x3f,sizeof(dp2));
	for(int i=1;i<=3*n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		q.push(a[i]);
		sum1+=a[i];
	}
	dp1[n]=sum1;
	for(int i=n+1;i<=3*n;i++)
	{
		if(q.top()<a[i])
		{
			sum1-=q.top();
			sum1+=a[i];
			q.pop();
			q.push(a[i]);
		}
		dp1[i]=sum1;
	}
	for(int i=3*n;i>2*n;i--)
	{
		q2.push(a[i]);
		sum2+=a[i];
	}
	dp2[2*n+1]=sum2;
	for(int i=2*n;i>=1;i--)
	{
		if(q2.top()>a[i])
		{
			sum2-=q2.top();
			sum2+=a[i];
			q2.pop();
			q2.push(a[i]);
		}
		dp2[i]=sum2;
	}
	long long ans=-0x3f3f3f3f3f3f3f3f;
	for(int i=n;i<=2*n;i++)
	{
//		printf("%d %lld %lld\n",i,dp1[i],dp2[i]);
		ans=max(ans,dp1[i]-dp2[i+1]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 9588
# B - ROT N

abc = [s for s in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
N = int(input())
S = str(input())

def f(ch, n):
    if len(abc) - 1 < abc.index(ch) + n:
        return abc[(abc.index(ch) + n) - len(abc)]
    else:
        return abc[abc.index(ch) + n]

ans = ''
for s in S:
    ans += f(s, N)

print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    imfor(i, n) {
        ans += i + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 998244353
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 300005
#define MAXB 3

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,cnt[1<<MAXB];
ll res = 1;
char s[MAXN];
vector<int> v;

int main(){
	scanf("%d %s",&len,s+1);
	for(int s=2; s>=1; s--){
		for(int i=0; i<(1<<3); i++)
			if(__builtin_popcount(i) == s)
				v.pb(i);
	}
	for(int i=1; i<=3*len; i++){
		int curr = (s[i]=='R'?0:s[i]=='G'?1:2);
		bool found = false;
		for(int k=0; k<v.size(); k++){
			if(cnt[v[k]] == 0) continue;
			if(v[k]&(1<<curr)) continue;
			found = true;
			res = (res*cnt[v[k]])%MOD;
			cnt[v[k]]--;
			if(__builtin_popcount(v[k]) <= 1)
				cnt[v[k]^(1<<curr)]++;
			break;
		}
		if(!found) cnt[1<<curr]++;
	}
	for(int i=2; i<=len; i++)
		res = (res*i)%MOD;
	printf("%lld\n",res);
}

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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int water,ans;
  water = b+c;
  if (water > a) ans=water-a;
  else ans=0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
int n,m,arr[101];
const int mod=1000000007;
int dp[101][100010];
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>arr[i];
	for(int i=0;i<=arr[0];i++)dp[0][i]=1LL+dp[0][i-1];
	for(int i=1+arr[0];i<=m;i++)dp[0][i]=dp[0][i-1];
	for(int j=1;j<n;j++){
		for(int i=0;i<=m;i++){
			dp[j][i]=dp[j-1][i]-dp[j-1][max(0LL,i-arr[j])-1]+dp[j][i-1];
			// if(dp[j][i]>=mod)dp[j][i]-=mod;
			dp[j][i]%=mod;
		}
	}
	int ans=dp[n-1][m]-dp[n-1][m-1];
	ans%=mod;
	if(ans<0)ans+=mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 78336
n,m=map(int,input().split())
arr = []
q = 2
while q*q <= m:
  e = 0
  while m % q == 0:
    e += 1
    m //= q
  if e > 0: arr.append(e)
  q += 1
if m > 1: arr.append(1)
ans = 1
for e in arr:
  comb = 1
  for i in range(e):
    comb = comb * (n+i) // (1+i)
  ans = ans * comb % 1000000007
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
     int n, a, b;
     scanf("%d", &n);
     if(n == 1){
            printf("Hello World\n");
     }
     if(n == 2){
             scanf("%d %d", &a, &b);
             printf("%d\n", a+b);
     }

      return  0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

using namespace std;


using int64 = long long;
const int mod = (1e9 + 7);

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int64 X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  int64 ret = infll;

  {
    int64 d = X / D;
    chmin(d, K);
    int64 k = K - d;
    d *= D;
    if(k % 2 == 0) {
      chmin(ret, X - d);
    } else {
      chmin(ret, X - d + D);
      chmin(ret, abs(X - d - D));
    };
  }

  {
    int64 d = X / D + 1;
    chmin(d, K);
    int64 k = K - d;
    d *= D;
    if(k % 2 == 0) {
      chmin(ret, abs(X - d));
    } else {
      chmin(ret, abs(X - d + D));
      chmin(ret, abs(X - d - D));
    }
  }

  cout << ret << "\n";
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <string.h>

using namespace std;

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

int main(){
	int T;
	cin >> T;
	REP(t,T){
		int iM,ret=0,y,k;
		cin >> iM >> y >> k;
		REP(i,k){
			int r, R, M=iM, t;
			double ratio;
			R=0;
			cin >> r >> ratio >> t;
			if(r==1)REP(j, y)M += M*ratio - t;
			if(r==0){
				REP(j, y){
					R += M*ratio;
					M -= t;
				}
				M+=R;
			}
			ret = max(ret, M);
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
import fractions
#import math

def lcm(x, y):
    #return (x * y) // math.gcd(x, y)
    return (x * y) // fractions.gcd(x, y)

x, y = map(int,input().split())

if y < 2*x: #長さが1になる場合
    print(1)
    exit()

li = [x, 2*x]
i = 0

while True:
    x = lcm(li[i], li[i+1])*2
    if x <= y:
        li.append(x)
        i += 1
    else:
        print(len(li))
        exit()

Measured memory_bytes: 64364
import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

n,m = map(int,input().split())
h = list(map(int,input().split()))

v=[[] for _ in range(n)]

for _ in range(m):
  a,b = map(int,input().split())
  a-=1
  b-=1
  v[a].append(b)
  v[b].append(a)

ans =0
for i in range(n):
  if not v[i]:
        ans+=1;continue
  f=0
  for j in v[i]:
    if h[j] >= h[i]:f=1 ;break

  if not f:
    ans+=1

print(ans)

Measured memory_bytes: 29452