akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

string S,T;
void input()
{
    cin >> S >> T;
}

void solve()
{
    bool ans = true;
    char P[26][1];
    for(int i=0; i<26; ++i){
        P[i][0] = '0';
    }
    for(int i=0; i<S.length(); ++i){
        if(P[S[i]-'a'][0] != '0'){
            if(P[S[i]-'a'][0] == T[i]) continue;
            ans = false; break;
        }
        P[S[i]-'a'][0] = T[i]; 
    }

    for(int i=0; i<26; ++i){
        P[i][0] = '0';
    }
    for(int i=0; i<S.length(); ++i){
        if(P[T[i]-'a'][0] != '0'){
            if(P[T[i]-'a'][0] == S[i]) continue;
            ans = false; break;
        }
        P[T[i]-'a'][0] = S[i]; 
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

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

int main(){
    int A; cin >> A;
    int B; cin >> B;
    int sum = 0;
    for(int i=0;i<2;i++){
        if(A>B){
            sum += A;
            A--;
        }else{
            sum +=B;
            B--;
        }
    }
    cout << sum;
    return 0;
}

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

namespace Program
{
    public class ABC084D
    {
        static public void Main(string[] args)
        {
            var prime = Prime(100000).ToArray();
            var sumary = new int[100001];
            foreach (var item in prime)
            {
                sumary[item] = prime.Contains((item + 1) / 2) ? 1 : 0;
            }
            for (int i = 1; i <= 100000; ++i)
            {
                sumary[i] += sumary[i - 1];
            }

            var Q = NextInt;
            for (int i = 0; i < Q; ++i)
            {
                var l = NextInt;
                var r = NextInt;
                Console.WriteLine(sumary[r] - sumary[l - 1]);
            }
        }

        static class Console_
        {
            private static Queue<string> param = new Queue<string>();
            public static int NextInt() => int.Parse(NextString());
            public static long NextLong() => long.Parse(NextString());
            public static string NextString()
            {
                if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
                return param.Dequeue();
            }
        }
        static int NextInt => Console_.NextInt();
        static long NextLong => Console_.NextLong();
        static string NextString => Console_.NextString();

        static IEnumerable<int> Prime(int x)
        {
            if (x < 2) yield break;
            yield return 2;
            var halfx = x / 2;
            var table = new bool[halfx + 1];
            var max = (int)(Math.Sqrt(x) / 2);
            for (int i = 1; i <= max; ++i)
            {
                if (!table[i])
                {
                    var add = 2 * i + 1;
                    yield return add;
                    for (int j = 2 * i * (i + 1); j <= halfx; j += add)
                    {
                        table[j] = true;
                    }
                }
            }
            for (int i = max + 1; i <= halfx; ++i)
            {
                if (!table[i]) yield return 2 * i + 1;
            }
        }
    }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll a,b,c;
  cin>>a>>b>>c;
  cout << min(a+b+1,c)+b << endl;
  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 998244353

def solve():
    n = I()
    d = LI()
    f = defaultdict(lambda : 0)
    for i in d:
        f[i] += 1
    m = max(d)
    ans = 1
    if f[0] != 1:
        print(0)
        return
    if d[0] != 0:
        print(0)
        return
    for i in range(m):
        ans *= pow(f[i],f[i+1],mod)
        ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 63516
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC168D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NM = Console.ReadLine().Split(' ');
            int N = int.Parse(NM[0]);
            int M = int.Parse(NM[1]);
            var ablist = new List<int>[N];
            for (int i = 0; i < M; i++)
            {
                string[] ABi = Console.ReadLine().Split(' ');
                int A = int.Parse(ABi[0]);
                int B = int.Parse(ABi[1]);
                if (ablist[A - 1] == null)
                {
                    ablist[A - 1] = new List<int>();
                }
                if (ablist[B - 1] == null)
                {
                    ablist[B - 1] = new List<int>();
                }
                ablist[A - 1].Add(B);
                ablist[B - 1].Add(A);
            }
            int[] seen = new int[N];
            Queue<int> next = new Queue<int>();
            next.Enqueue(1);
            while (next.Count != 0)
            {
                int n = next.Dequeue();
                foreach(int j in ablist[n - 1])
                {
                    if (seen[j - 1] == 0)
                    {
                        next.Enqueue(j);
                        seen[j - 1] = n;
                    }
                }
            }
            Console.WriteLine("Yes");
            for (int i = 1; i < N; i++)
            {
                Console.WriteLine(seen[i]);
            }
        }
    }
}


Measured memory_bytes: 55524
#include <stdio.h>
#include <iostream>

using namespace std;

#define N 3

int main(int argc, char const *argv[])
{
    int a[N];
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    for (int i = 0; i < N-1; ++i)
    {
        int min = a[i];
        for (int j = i+1; j < N; j++)
        {
            if (min > a[j])
            {
                int tmp = min;
                min = a[j];
                a[j] = tmp;
            }
        }
        a[i] = min;
    }

    for (int i = 0; i < N; ++i)
    {
        if (i == N-1)
        {
            printf("%d\n", a[i]);
            break;
        }
        printf("%d ", a[i]);
    }

    return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
int main(void){
    int n , a[105] ;
    int i , j , t , m , l = 0 ;
    
    scanf("%d" , &n) ;
    
    for(i = 0 ; i < n ; i++){
        scanf("%d" , &a[i]) ;
    }
    
    for(i = 0 ; i < n ; i++){
        m = i ;
        for(j = i ; j < n ; j++){
            if(a[j] < a[m]){
                m = j ;
            }
        }
        if(a[m] != a[i]){
            t = a[i] ;
            a[i] = a[m] ;
            a[m] = t ;
            l++ ;
        }
    }
    for(i = 0 ; i < n ; i++){
        printf("%d" , a[i]) ;
        if(i == n - 1)continue ;
        printf(" ") ;
    }
    printf("\n") ;
    printf("%d\n" , l) ;
    return 0 ;
}


Measured memory_bytes: 2076
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

const int MOD = 1e9+7;

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::set<int> states_s;
	for(int i=1;i*i<=n;i++) {
		states_s.emplace(n/(n/i));
		states_s.emplace(n/i);
	}
	std::vector<int> states;
	states.assign(all(states_s));
	int state_count = states.size();
	std::vector<int> a;
	std::vector<int> b;
	a.reserve(state_count);
	b.reserve(state_count);
	for(int i=0;i<state_count;i++) a[i] = states[i];
	for(int i=1;i<k;i++) {
		int last = 0;
		for(int j=0;j<state_count;j++) {
			b[j] = (states[j]-last)*a[state_count-1-j]%MOD;
			if(j!=0) b[j] = (b[j]+b[j-1])%MOD;
			last = states[j];
		}
		std::swap(a,b);
	}
	print(a[state_count-1]);
	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;
using ll = long long;
using ull = unsigned long long;
using vint = std::vector<int>;
using vvint = std::vector<std::vector<int>>;
using namespace std;
ll mod = 1e9 + 7;


int main(){


        int A, B; cin >> A >> B;
        int ans = max(A + B, A - B);
        ans = max(ans, A * B);
        cout << ans;


        return 0;
}

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

 ll MOD = 1000000007;

 int main() {
   int N, M;
   cin >> N >> M;
   vector<vector<int>> root(N, vector<int>(N, 0));
   vector<pair<int, int>> input(M);

   rep(i, 0, M) {
     cin >> input.at(i).first >> input.at(i).second;
     input.at(i).first--;
     input.at(i).second--;
     root.at(input.at(i).first).at(input.at(i).second)++;
     root.at(input.at(i).second).at(input.at(i).first)++;
   }

   int cnt = 0;

   rep(i, 0, M) {
     queue<int> bfs;
     bool isolated = false;
     vector<bool> done(N, false);
     vector<vector<int>> tmp = root;
     tmp.at(input.at(i).first).at(input.at(i).second) = 0;
     tmp.at(input.at(i).second).at(input.at(i).first) = 0;
     bfs.push(0);
     done.at(0) = true;
     while (!bfs.empty()) {
       int f = bfs.front();
       bfs.pop();
       for (int v = 0; v < N; v++) {
         if (!done.at(v) && tmp.at(f).at(v) == 1) {
           bfs.push(v);
           done.at(v) = true;
         }
       }
     }
     rep(j, 0, N) {
       if (!done.at(j)) isolated = true;
     }
     if (isolated) cnt++;
   }

   cout << cnt << endl;
 }


Measured memory_bytes: 256
# ki
from collections import deque

# input

n, q = map(int, input().split())

edge = [[] for i in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

lq = [list(map(int, input().split())) for i in range(q)]

score = [0]*(n+1)
visited = [False]*(n+1)

for q in lq:
    score[q[0]] += q[1]

que = deque()
que.append(1)

while que:
    node = que.popleft()
    if not visited[node]:
        visited[node] = True
        for next in edge[node]:
            if not visited[next]:
                score[next] += score[node]
                que.append(next)

print(" ".join([str(n) for n in score][1:]))

Measured memory_bytes: 115524
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    A, P = map(int, input().split())
    print((A * 3 + P) // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
#include <iostream>
 

int main(){
    using namespace std;
 
    int a, b, c;
    cin >> a >> b >> c;

    int count = 0;
    for( int factor = a; factor <= b; ++factor ){
        if( (c % factor) != 0 ){ 
            continue;
        }
        ++count;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1160
def main():
    M, K = list(map(int, input().split(' ')))
    if K >= 2 ** M:
        print(-1)
        return
    if M == 0:
        print('0 0')
        return
    if M == 1:
        if K == 0:
            print('0 0 1 1')
        else:
            print(-1)
        return
    # M >= 2 and K < 2 ** M
    arr = list(map(str, [i for i in range(2 ** M) if i != K]))
    rev_arr = arr.copy()
    rev_arr.reverse()
    ans = arr + [str(K)] + rev_arr + [str(K)]
    print(' '.join(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 19344
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] A_B = Console.ReadLine().Split(' ');
            int a = int.Parse(A_B[0]);
            int b = int.Parse(A_B[1]);
            Console.WriteLine((a - 1) * (b - 1));
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#define _USE_MATH_DEFINES
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
#include <cstdlib>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int x, y;
    cin>>x>>y;
    if (y&1){
        cout<<"No\n";
        return 0;
    }
    int c = (4*x - y)/2, t = x -  c;

    if ((c>=0) && (t>=0)){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }

    return 0;
}






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

typedef long long ll;
const ll MOD = 1e9 + 7;

const int MAXN = 2010;

ll N, D, X;
ll table[2][MAXN];
ll coeff[2][MAXN];

void solve(){
    memset(table, 0, sizeof(table));
    memset(coeff, 0, sizeof(coeff));
    
    for(int i=0; i<X; i++)
        table[0][i] = 1;
    coeff[0][0] = 1;
    
    int cnt = 0;
    int ccnt = 0;
    while(D){
        if(D%2){
            memset(coeff[ccnt^1], 0, sizeof(coeff[ccnt^1]));
            for(int i=0; i<=N; i++){
                for(int j=0; j<=i; j++){
                    coeff[ccnt^1][i] = (coeff[ccnt^1][i] + coeff[ccnt][j] * table[cnt][i-j]) % MOD;
                }
            }
            ccnt ^= 1;
        }
        
        memset(table[cnt^1], 0, sizeof(table[cnt^1]));
        for(int i=0; i<=N; i++){
            for(int j=0; j<=i; j++){
                table[cnt^1][i] = (table[cnt^1][i] + table[cnt][j] * table[cnt][i-j]) % MOD;
            }
        }
        cnt ^= 1;
        D /= 2;
    }
    cout << coeff[ccnt][N] << endl;
}

int main(){
    while(cin >> N >> D >> X, N|D|X){
        solve();
    }
    return 0;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    string s; cin >> s;

    cout << s[0] << s.length() - 2 << s[s.length()-1];
}


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

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static final int MOD = 1_000_000_007;

	public static void main(String[] args) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		long[] row = new long[W];
		long before = comb(H - A - 1 + B, B);
		for (int i = B; i < W; ++i) {
			row[i] = before;
			before *= H - A + i;
			before %= MOD;
			before *= inv(i + 1);
			before %= MOD;
		}
		long ans = 0;
		long after = 1;
		for (int i = W - 1; i >= B; --i) {
			ans += row[i] * after;
			ans %= MOD;
			after *= A - 1 + (W - i);
			after %= MOD;
			after *= inv(W - i);
			after %= MOD;
		}
		System.out.println(ans);
	}

	static long comb(long a, long b) {
		long ret = 1;
		for (int i = 0; i < b; ++i) {
			ret *= (a - i);
			ret %= MOD;
			ret *= inv(i + 1);
			ret %= MOD;
		}
		return ret;
	}

	static long inv(long v) {
		return pow(v, MOD - 2);
	}

	static long pow(long v, long p) {
		if (p == 0) return 1;
		if (p == 1) return v;
		long ret = pow(v, p / 2);
		ret *= ret;
		ret %= MOD;
		if (p % 2 == 1) {
			ret *= v;
			ret %= MOD;
		}
		return ret;
	}
}


Measured memory_bytes: 10316
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
# gcd
from fractions import gcd
# 切り上げ，切り捨て
from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
from collections import Counter
import math
from functools import reduce
sys.setrecursionlimit(200000)
# input関係の定義
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
# template

H, W = mi()
S = [li() for i in range(H)]
ans = []
for i in range(H):
    for j in range(W):
        if S[i][j] == "B":
            ans.append((i, j))
        
ans.sort(key=lambda x: x[0] + x[1])
debug(ans[-1])
debug(ans[0])
tmp = abs(ans[-1][0] - ans[0][0]) + abs(ans[-1][1] - ans[0][1])
ans.sort(key=lambda x: x[0] + (W - x[1]))
debug(ans[-1])
debug(ans[0])
tmp2 = abs(ans[-1][0] - ans[0][0]) + abs(ans[-1][1] - ans[0][1])
print(max(tmp,tmp2))


Measured memory_bytes: 6984
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

	vector<int> P(N, 0);
	vector<int> Q(N, 0);

	rep(i, N) cin >> P[i];
	rep(i, N) cin >> Q[i];

	vector<int> vec(N);
	vector<vector<int> > pt;
	iota(vec.begin(), vec.end(), 1);

	do {
		pt.push_back(vec);
	} while (next_permutation(vec.begin(), vec.end()));
	sort(pt.begin(), pt.end());

	int pidx, qidx;
	pidx = qidx = -1;

	for (int i = 0; i < pt.size(); ++i)
	{
		if (P == pt[i]) pidx = i;
		if (Q == pt[i]) qidx = i;
	}

	cout << abs(pidx - qidx) << endl;
	return 0;
}

Measured memory_bytes: 6396
f = lambda: list(map(int,input().split()))

n,m = f()
a = f()
b = [0]
for i in range(n):
    b.append((b[-1]+a[i])%m)

ans = 0
from collections import Counter
for v in Counter(b).values():
    ans += v*(v-1)//2
print(ans)

Measured memory_bytes: 16552
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<map>
#define ll long long int
using namespace std;
int main(){
    ll n;
    cin>>n;
    string s;
    ll i;
    map<string ,int> m;
    for(i=0;i<n;i++){
        cin>>s;
        m[s]=1;
    }
    cout<<m.size();
}


Measured memory_bytes: 19256
void main() {
    double[] tmp = readln.split.to!(double[]);
    double t = tmp[0], x = tmp[1];
    writefln("%.10f", t / x);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll N;
  cin >> N;
  vector<string> S(N);
  rep(i, N){
    cin >> S.at(i);
  }
  vector<pair<ll, ll>> d(N);
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> r;
  priority_queue<pair<ll, ll>> q;
  rep(i, N){
    ll c = 0;
    ll m = 0;
    rep(j, sz(S.at(i))){
      if(S.at(i).at(j) == '('){
        c++;
      }
      else{
        c--;
        chmin(m, c);
      }
    }
    d.at(i) = make_pair(m, c);
    if(c > 0){
      q.push(d.at(i));
    }
    else{
      r.push(make_pair(m-c, -c));
    }
  }
  ll now = 0;
  while(!q.empty()){
    pair<ll, ll> p = q.top();
    q.pop();
    if(now + p.first < 0){
      cout << "No" << endl;
      return 0;
    }
    now += p.second;
  }
  while(!r.empty()){
    pair<ll, ll> p = r.top();
    r.pop();
    if(now + p.first-p.second < 0){
      cout << "No" << endl;
      return 0;
    }
    now -= p.second;
  }
  if(now != 0){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 66016
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<long double, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << #i <<" "<<i<< std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
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);}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;
 

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

  ll n,k,q;
  std::cin>>n>>k>>q;

  std::vector<ll> a(n);
  rep(i,0,n)std::cin>>a[i];

  ll ans=LLONG_MAX;

  rep(i,0,n){
    ll min=a[i];

    ll cnt=0;
    std::vector<ll> temp;
    rep(j,0,n){
      if(a[j]<min){
        if(cnt>=k){
          std::vector<ll> temp2;
          rep(l,j-cnt,j){
            temp2.push_back(a[l]);
          }
          std::sort(all(temp2));
          rep(l,0,cnt-k+1)temp.push_back(temp2[l]);
        }
        cnt=0;
      }else{
        cnt++;
      }
    }
    if(cnt>=k){
      std::vector<ll> temp2;
      rep(l,n-cnt,n)temp2.push_back(a[l]);
      std::sort(all(temp2));
      rep(l,0,cnt-k+1)temp.push_back(temp2[l]);
    }

    std::sort(all(temp));

    ll max;
    if(temp.size()<q)max=LLONG_MAX;
    else max=temp[q-1];

    chmin(ans,max-min);
  }

  std::cout<<ans;

  return 0;
}





Measured memory_bytes: 384
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  int s = 0;
  rep(i, n) {
    int x;
    cin >> x;
    s += x;
  }
  cout << s / n << endl;
}

Measured memory_bytes: 2976
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define mod 1000000007 //1e9+7
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  i,j,n,k,x,cnt=0;
    cin>>n>>k;
    ll cpk=k;
    vector<ll> v(n);
    for(i=0; i<n; i++)
    {
        cin>>v[i];
    }
    for(i=0; i<n-k; i++)
    {
        if(v.at(i)<v.at(i+k))
            yes
            else
                no
    }
    return 0;
}


Measured memory_bytes: 4744
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int a, b, c;

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

    if(a == b && b == c){
        printf("1\n");
    }else if((a == b && a != c) || (b == c && c != a) || (c == a && a != b)){
        printf("2\n");
    }else{
        printf("3\n");
    }

    return 0;
}

Measured memory_bytes: 1636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll A,B;
  cin >> A >> B;
  ll cnt=0;
  if(abs(A-B)%2==0){
    cnt = abs(A-B)/2;
  }
  else{
    ll a_lengh,b_lengh;
    a_lengh = min(abs(N-A),abs(A-1));
    b_lengh = min(abs(N-B),abs(B-1));
    ll lengh = min(a_lengh,b_lengh);
    cnt = (abs(A-B)+1)/2 + lengh;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3600
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    A1, A2, A3 = map(int, input().split())
    if A1+A2+A3 >= 22:
        print('bust')
    else:
        print('win')

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc147","a",main)

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD 998244353
typedef long long int lli;

int main(){
    int a, b;
    cin >> a >> b;
    if(a + b == 3) puts("3");
    else if(a + b == 4) puts("2");
    else puts("1");
    return 0;
}

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

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
print( num2alpha(n).lower() )

Measured memory_bytes: 61672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String str = br.readLine();
			String[] w_h = str.split(" ", 0);
			int h = Integer.parseInt(w_h[0]);
			int w = Integer.parseInt(w_h[1]);
			if (w == 0 && h == 0) {
				break;
			}
			for (int j = 0; j < h; j++) {
				if (j % 2 == 0) {
					for (int i = 0; i < w; i++) {
						if (i % 2 == 0) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					}
				} else {
					for (int i = 0; i < w; i++) {
						if (i % 2 == 0) {
							System.out.print(".");
						} else {
							System.out.print("#");
						}
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 30456
import java.util.*;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    // long[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
    static long[] L;
    static long[] P;
    static void solve(Scanner scanner) {
        long[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
        int N = (int) n[0];
        long X = n[1];
        L = new long[N + 1];
        P = new long[N + 1];
        L[0] = 1;
        P[0] = 1;
        for (int i = 1; i < N + 1; i++) {
            L[i] = 2 * L[i - 1] + 3;
            P[i] = 2 * P[i - 1] + 1;
        }

        System.out.println(dfs(N, X));
    }

    static long dfs(int n, long x) {
        if (n == 0) {
            return (x > 0) ? 1 : 0;
        }
        if (x <= L[n - 1] + 1) {
            return dfs(n - 1, x - 1);
        }
        return P[n - 1] + 1 + dfs(n - 1, x - 2 - L[n - 1]);
    }

}


Measured memory_bytes: 28884
from itertools import accumulate
from collections import defaultdict


def main():
    n = int(input())
    prime_counter = defaultdict(int)  # key ^ value
    acc = tuple(accumulate(range(1, 42)))  # because 10^12 < 2^39

    def facs(n):
        yield 2
        max_x = int(n ** 0.5)
        for x in range(3, max_x+1, 2):
            yield x

    for fac in facs(n):
        while n % fac == 0:
            n //= fac
            prime_counter[fac] += 1
            # ここで if fac * fac > n: braek を入れると，
            # 計算量の少ないケースでは早く，多いケースでは遅くなる。
    if n != 1:
        prime_counter[n] += 1

    ans = 0
    for c in prime_counter.values():
        for i, x in enumerate(acc):
            if c < x:
                tmp = i
                break
        ans += tmp
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9652
#include <stdio.h>
int main(){

	int a,b,c,d,p,lx,ly,ans;

	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&p);
	
	lx = p*a;
	
	if ( p > c){
		ly = b + d*(p-c);
	}else{
		ly = b;
	}

	if ( lx < ly){
		ans = lx;
	}else{
		ans=ly;
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 596
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<long long,long long>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a);}
                a=(a*a);
                b>>=1;
        }
    return ans;
        
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(0));
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int x=__gcd(i,j);
            if(x==1){
                ans+=n;
                continue;
            }
            for(int k=1;k<=n;k++){
                ans+=__gcd(x,k);
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3648
n = gets.chomp.to_i
d, x = gets.chomp.split(" ").map(&:to_i)

a = Array.new
STDIN.each_line do |line|
    a.push(line.to_i)
end

a.each do |m|
  x += (1 + (d - 1) / m)    
end

puts x

Measured memory_bytes: 1788
#include <cstdio>

#define ll long long
#define maxn 100000

int v[maxn + 1];

int main() {
    int n, rez = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &v[i]);
    }
    for (int i = 1; i <= n; i++) {
        if (i == v[i]) {
            int aux = v[i];
            v[i] = v[i + 1];
            v[i + 1] = aux;
            rez++;
        }
    }
    printf("%d", rez);
    return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

bool check(const vector<int> &v, int hf)
{
    // 0 dp初期値
    // 要素数分(1 indexed)
    // 要素を -1 で初期化
    vector<int> dp(hf + 1, -1);

    dp[0] = 0;

    for (int i = 0; i < (signed)v.size(); i++)
    {
        for (int j = 0; j <= hf; j++)
        {
            // 最大で「1」 「0」→「1」 「1」→「1」
            if (0 <= dp[j]) dp[j] = 1;
            // 組合せで構築できない「-1」
            else if (j < v[i] || dp[j - v[i]] <= 0) dp[j] = -1;
            // 組合せで構築できる「0」
            else dp[j] = 0;
        }
    }

    return 0 <= dp[hf];
}

int main()
{
    const char *Yes = "Yes";
    const char *No = "No";

    char tmp[8001];
    if (scanf("%s", tmp) < 1) return 0;

    string s = tmp;

    int x, y;
    if (scanf("%d%d", &x, &y) < 2) return 0;

    // 要素数 2 (x と y)
    vector<int> ar[2];

    int xy = 0, cnt = 0;

    for (int i = 0; i < (signed)s.length(); i++)
    {
        if (s[i] == 'F')
        {
            cnt++;
        }
        else
        {
            ar[xy].push_back(cnt);
            cnt = 0;
            xy ^= 1;    // ビット排他的論理和 反転(0 ⇔ 1)
        }
    }

    // 最後が T でない場合の考慮
    ar[xy].push_back(cnt); 

    // x の先頭を参照
    // 最初だけ 右確定 目標地点を左にずらす
    x -= ar[0][0];

    // x の先頭を削除
    ar[0].erase(ar[0].begin());

    // 正負を意識する必要はない
    // 先に左にずらしている為
    x = abs(x);
    // y は 0 始点の為
    y = abs(y);

    // x 合計
    int xs = accumulate(ar[0].begin(), ar[0].end(), 0);
    // y 合計
    int ys = accumulate(ar[1].begin(), ar[1].end(), 0);

    // 不足
    if (xs < x || ys < y) return !printf("%s\n", No);

    // 全力 Just
    if (xs == x && ys == y) return !printf("%s\n", Yes);

    // 奇数 行って帰れず
    if ((xs - x) % 2 || (ys - y) % 2) return !printf("%s\n", No);

    // 行き過ぎ 確定
    // ソート 昇順
    sort(ar[0].begin(), ar[0].end());   // x
    sort(ar[1].begin(), ar[1].end());   // y

    if (check(ar[0], (xs - x) / 2) && check(ar[1], (ys - y) / 2))
    {
        // 行き過ぎた距離の半分を
        // 組合せで構築できる
        return !printf("%s\n", Yes);
    }
    else
    {
        // 行き過ぎた距離の半分を
        // 組合せで構築できない
        return !printf("%s\n", No);
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#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 repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
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;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	set<int>tmp;
	rep(i, n) {
		int a; cin >> a;
		tmp.insert(a);
	}
	cout << tmp.size() << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll a,b;
    cin>>a>>b;
    if(a-b*2 <=0) cout<<0<<endl;
    else cout<<a-b*2<<endl;
    return 0;
}

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

using namespace std;

#define f first
#define s second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <int> vi;
typedef vector <string> vs;
typedef vector <vector <llong> > matrix;

typedef pair <llong, llong> pll;

typedef map <int, int> mii;

typedef set <llong> sl;

const int MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const int INF = 1e9;
const llong LINF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;}

int n;

int sum (string s) {
    int sum = 0;
    for (char it : s) {
        sum += (it - '0');
    }
    return sum;
}

int main () {
    android;
    //freopen ("input.txt", "r", stdin);
    cin >> n;
    int mn = INF;
    for (int a = 1; a <= n / 2; a ++) {
        mn = min (mn, sum(to_string(a)) + sum(to_string(n - a)));
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, L = sc.nextInt()

    val min = (1 to N). map { i =>
      L + i - 1
    }. minBy(v => Math.abs(v))

    val sum = (1 to N). map { i =>
      L + i - 1
    }. sum

    println(sum - min)
  }

}

Measured memory_bytes: 25552
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int x;
  cin >> x;
  vector<int> dp(100001, -1);
  dp.at(0) = 0;
  for (int i = 0; i < 6; ++i) {
    for (int j = 0; j <= x; ++j) {
      if (dp.at(j) >= 0) {
        dp.at(j) = 1000000;
      } else if (j < 100+i || dp.at(j - 100 - i) <= 0) {
        dp.at(j) = -1;
      } else {
        dp.at(j) = dp.at(j - 100 - i) - 1;
      }
    }
  }
  if (dp.at(x) >= 0) puts("1");
  else puts("0");
  return 0;
}

Measured memory_bytes: 640
n=int(input())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Measured memory_bytes: 13928
/*
 ____________________________________________________________
|                                                            |
|                   Author: ay2306                           |
|____________________________________________________________|

*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define MAXN 25
using namespace std;

string getString(int f, int s){
    string ans = "";
    for(int i = 0; i < 12; ++i)ans+="0";
    int i = 5;
    while(f){
        ans[i--]=(char((f%10) + '0'));
        f/=10;
    }
    i = 11;
    while(s){
        ans[i--]=(char((s%10) + '0'));
        s/=10;
    }
    return ans;
}

int main(){
    int n,k;
    cin >> n >> k;
    map<int,vector<pair<ll,int> > > m;
    for(int i = 0; i < k; ++i){
        ll a,b;
        cin >> a >> b;
        if(m.find(a) == m.end())m[a] = vector<pair<ll,int> > ();
        m[a].pb(mp(b,i));
    } 
    // for(auto i: m){
    // }
    vector<string> ans(k,"");
    for(auto i: m){
        int l = 1;
        sort(i.second.begin(),i.second.end());
        for(auto j: i.second){
            // cout << j.first << " " << j.second << "\n";
            ans[j.second] = getString(i.first,l++);
        }
    }
    for(auto i: ans){
        cout << i << "\n";
    }
    return 0;
}

Measured memory_bytes: 19456
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define pb push_back;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<char, char> c_c;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
const int INF = 1e9;
const ll LLINF = 1e16;

ll gcd(ll x, ll y){
	if(x>y) swap(x, y);
	while(1){
		y %= x;
		swap(x, y);
		if(x==0) return y;
	}
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    ll m;
    cin >> n >> m;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    set<int> s;
    vector<ll> b(n);
    b = a;
    for(int i=0; i<n; i++){
        int cnt = 0;
        while(a[i]%2 == 0){
            a[i] /= 2;
            cnt++;
        }
        s.insert(cnt);
        //b[i] = a[i];
    }
    ll sum = a[0];
    if (s.size() != 1){
        cout << 0 << endl;
        return 0;
    }
    else{
        //cout << LC << endl;
        for(int i=1; i<n; i++){
            sum = (sum*a[i])/(gcd(sum, a[i]));
            if(sum>m){
                cout << 0 << endl;
                return 0;
            }
        }

        for(int i=0; i<*begin(s)-1; i++){
            sum *= 2;
            if(sum>m){
                cout << 0 << endl;
                return 0;
            }
        }
            //LCM求め終わり
    }
    
    int ans = 0;
    //cout << sum << endl;
    ll tot = sum;
    while(tot <= m){
        ans++;
        tot += sum*2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
int main(){
    int a,n,i, number[100];
    std::cin >> n;
    for (i = 0; i <= (n - 1); i++){
        std::cin >> number[i];
    }
    for (a=(n-1); a>-1;a--){
        std::cout << number[a];
        if (a != 0){
            std::cout << " ";
        }
    }
    std::cout<<"\n";
    return 0;
}

Measured memory_bytes: 3092