akhauriyash/Code-Regression huggingface dataset:
"""
累積GCD
"""

import sys
sys.setrecursionlimit(10**6)

n = int(input())
A = list(map(int, input().split()))

from math import gcd

L = [0] * n
R = [0] * n

for i in range(n-1):
    L[i+1] = gcd(L[i], A[i])
for i in range(n-1, 0, -1):
    R[i-1] = gcd(R[i], A[i])

ans = 0
for i in range(n):
    ans = max(ans, gcd(L[i], R[i]))

print(ans)


Measured memory_bytes: 20572
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef tuple<int,int,bool> Tb;


int atcoder(){
    //入力
    int n;
    cin >> n;
    int cnt[60][26]={};
    REP(i,n){
        string s;
        cin >> s;
        for(int j=0; j<s.length(); ++j) cnt[i][s[j]-'a']++;
    }
    int ans[26];
    REP(i,26) ans[i]=INT_MAX;
    
    //処理
    REP(i,26){
        REP(j,n){
            ans[i] = min(cnt[j][i],ans[i]);
        }
    }
    
    string ansstr = "";
    REP(i,26){
        int tmp=ans[i];
        REP(j,tmp) ansstr += 'a'+i;
    }
    
    //出力
    cout << ansstr << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using ll = long long;
using P = pair<long long, long long>;
using MATRIX = vector< vector<ll> >;

long long gcd(long long &a, long long &b) {
  if(b == 0) return a;
  long long d;
  a = a % b;
  swap(a, b);
  d = gcd(a, b);
  return d;
}

int main() {
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  long long ans = 0;
  ans += B / C - (A-1) / C;
  ans += B / D - (A-1) / D;
  long long l = C * D / gcd(C, D);
  ans -= B / l - (A-1) / l;
  ans = B - A + 1 - ans;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int MAXN = 102;

int main()
{
    int n;
    cin >> n;
    int x, y;
    cin >> x >> y;
    if (abs(x - y) % 2 == 0)
        cout << "Alice" << endl;
    else
        cout << "Borys" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define INF 10000000000
ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s, t;

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

    while(cin >> h >> w){
        rep(i, h){
            cin >> s;
            cout << s << endl << s << endl;
        }
    }
}



Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=2e5+5;
const long long INF=999999999999999;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
ll sum[MAXN];
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        ll a;
        cin>>a;
        sum[i]=sum[i-1]+a;
    }
    ll ans=INF;
    for(int i=1;i<n;i++)
    {
        ans=min(ans,abs((sum[n]-sum[i])-sum[i]));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)

// 1行読み込み
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

// 読み込みをint型へキャスト
func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if(err != nil) {
		panic(err)
	}
	return num
}

// 読み込みをfloat型へキャスト
func nextFloat() float64 {
	sc.Scan()
	num, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return num
}

func main() {
	// scannerの挙動を改行区切り → 空白区切りに変更
	sc.Split(bufio.ScanWords)
	x := nextInt()
	y := nextInt()

	if y % 2 != 0 {
		fmt.Println("No")
		return
	}

	// 余り
	mod_4 := y % 4
	// 2本の動物の数
	num_2 := mod_4 / 2
	num_4 := y / 4
	if num_2 + num_4 == x {
		fmt.Println("Yes")
	} else {
		if y / 2 == x && y % 2 == 0 {
			fmt.Println("Yes")
			return	
		} else if y / 4 == x && y % 4 == 0 {
			fmt.Println("Yes")
			return	
		}
		for n := num_4 * 4 - 4; n > 0; n = n - 4 {
			num_4 = num_4 - 1
			num_2 = num_2 + 2
			if num_2 + num_4 == x {
				fmt.Println("Yes")
				return
			} else if num_4 < 0 {
				fmt.Println("No")
				return
			}
		}
		fmt.Println("No")
	}
}

Measured memory_bytes: 1760
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define MaxN 1000010
//#define MOD 998244353
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define endl '\n'
#define LL long long
#define PII pair<int,int>
#define rint register int 
#define ULL unsigned long long
const int MOD=1e9+7;
//int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
//int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
template<class T> inline void read(T& x){
    x=0;int f=0;char ch=getchar();
    while( !isdigit(ch) ) f|=( ch == '-' ) , ch=getchar();
    while( isdigit(ch) )  x = ( x<<1 ) + ( x<<3 ) + ( ch^48 ) , ch=getchar();
    x = f ? -x : x;
}
template<class T> inline void print(T x){
	if ( x < 0 ) { putchar('-'); x = -x; }
	if ( x >= 10 ) print( x / 10 );
	putchar(x % 10 + '0');
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int x,S=0;
    cin>>x;
    bool flag=false;
    for(int i=1; i<MaxN; i++){
        S=(S*10+7)%x;
        if( S == 0 ){
            flag=true;
            cout<<i<<endl;
            break;
        }
    }
    if( !flag ) cout<<"-1"<<endl;
	return 0; 
}

Measured memory_bytes: 3624
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		try {
			String line;
			int N;
			
			while((line=r.readLine())!=null){
				N = Integer.parseInt(line);
				int count=0;
				if(N>2){
					ArrayList<Integer> primelist = prime(N);
					for(int i : primelist){
						if(primelist.contains(i) && primelist.contains(N-i+1)){
							count++;
						}
					}
				}
				System.out.println(count);
				
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	//Sieve of Eratosthenes
	public static ArrayList<Integer> primes(int n){
		ArrayList<Integer> numbers = new ArrayList<Integer>();
		ArrayList<Integer> primes = new ArrayList<Integer>();
		
		//initialize number list (add all numbers from 2 to n)
		for(int i=2;i<=n;i++){
			numbers.add(i);
		}
		
		int limit = (int)Math.sqrt(n);
		
		while(true){
			int k = numbers.get(0);
			if(k>limit){
				break;
			}
			primes.add(k);
			numbers.remove(Integer.valueOf(k));
			for(int j=2;k*j<=n;j++){
				numbers.remove(Integer.valueOf(k*j));
			}
		}
		for(int i : numbers){
			primes.add(i);
		}
		
		return primes;
	}
	

	public static ArrayList<Integer> prime(int n){
		ArrayList<Integer> primes = new ArrayList<Integer>();

		int i;
		Boolean[] p = new Boolean[n+1];
		//initialize number list
		for(i=1;i<=n;i++){
			p[i] = true;
		}
		
		
		int limit = (int)Math.sqrt(n);
		
		for(i=2;i<=limit;i++){
			if(p[i]){
				primes.add(i);
				for(int j=2;i*j<=n;j++){
					p[i*j] = false;
				}
				continue;
			}
		}
		
		for(;i<=n;i++){
			if(p[i]){
				primes.add(i);
			}
		}
		
		return primes;
	}
}

Measured memory_bytes: 56600
#include <algorithm>
#include <iostream>
int n, k, m, a[200010], b[200010], ans;
int main() {
    std::cin >> n >> k;
    for (int i = 1; i <= n; i++) std::cin >> a[i];
    std::sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++)
        if (a[i] != a[i - 1])
            b[++m] = 1;
        else
            b[m]++;
    std::sort(b + 1, b + m + 1);
    for (int i = 1; i <= m - k; i++) ans += b[i];
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1792
import itertools
H,W,K=map(int,input().split())
c=[list(input()) for _ in range(H)]
hll=list(itertools.product(range(2),repeat=H))
wll=list(itertools.product(range(2),repeat=W))
ans=0
for hl in hll:
    for wl in wll:
        tc=[]
        for i in c:
            tc.append(i[:])
        for i in range(H):
            if hl[i]==1:
                for j in range(W):
                    tc[i][j]='.'
        for i in range(W):
            if wl[i]==1:
                for j in range(H):
                    tc[j][i]='.'
        t=0
        for i in range(H):
            for j in range(W):
                if tc[i][j]=='#':
                    t+=1
        if t==K:
            ans+=1
print(ans)

Measured memory_bytes: 9180
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int w = scan.nextInt();
		int h = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		if (x - r < 0 || y - r < 0 || x + r > w || y + r > h) {
			System.out.println("No");
		} else System.out.println("Yes");
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

const int M = 1e3;
int v[M], c[M], memo[M * 10 + 1], n;

int solve(int h) {
    if (h < 1)
        return 0;

    int &r = memo[h];

    if (r == -1) {
        r = 2e9;
        for (int i = 0; i < n; i++)
            r = min(r, c[i] + solve(h - v[i]));
    }

    return r;
}

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

    memset(memo, -1, sizeof memo);

    int h;
    cin >> h >> n;
    for (int i = 0; i < n; i++)
        cin >> v[i] >> c[i];

    cout << solve(h) << "\n";

    return 0;
}

Measured memory_bytes: 768
import string
abc = string.ascii_lowercase
s = list(input())
K = int(input())
index = 0
while K > 0:
    if index == len(s) - 1:
        s[index] = abc[(abc.index(s[index]) + K) % 26]
        break
    tmp = 26 - abc.index(s[index])
    if tmp == 26:
        index += 1
        continue
    if K >= tmp:
        s[index] = 'a'
        index += 1
        K -= tmp
    else:
        index += 1

for i in s:
    print(i, end='')

Measured memory_bytes: 81540
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int X;
    cin >> X;

    if(X < 100)
    {
        cout << 0 << endl;
        return 0;
    }

    if(X >= 2000)
    {
        cout << 1 << endl;
        return 0;
    }
    vector<int> v_X;
    for(int i=0; i<=X; i++)
    {
      v_X.push_back(0);
    }
    v_X.at(0) = 1;

    for(int i=100; i<=X; i++)
    {
        if(v_X.at(i-100))
        {
            v_X.at(i)=1;
        }
        else if(v_X.at(i-101))
        {
            v_X.at(i)=1;
        }
        else if(v_X.at(i-102))
        {
            v_X.at(i)=1;
        }
        else if(v_X.at(i-103))
        {
            v_X.at(i)=1;
        }
        else if(v_X.at(i-104))
        {
            v_X.at(i)=1;
        }
        else if(v_X.at(i-105))
        {
            v_X.at(i)=1;
        }
   }

    cout << v_X.at(X) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    vector<int> X(N), L(N);
    vector<pair<int, int>> prs;

    rep(i, N) {
        cin >> X[i] >> L[i];
        prs.push_back(mp(X[i] + L[i], X[i] - L[i]));
    }

    sort(all(prs));

    int ret = 0;
    int val = LLONG_MIN;
    rep(i, N) {
        if (prs[i].second < val) continue;
        else {
            ret++;
            val = max(val, prs[i].first);
        }
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3956
#include<iostream>
using namespace std;
int main(){
    int a,b,c,s,t;
    cin>>a>>b>>c;
    for(s=a;s<=b;s++){
        if(c%s==0){
            t++;
        }    
        
    }
    cout<<t<<endl;    
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, p;
string a , b;
int c[100005];
int v[100005];
int rez[100005];
int dfs( int nod){
    if(v[nod]==0){
        v[nod] = 1;
    }
    else{
        return c[nod];
    }
    if(a[nod]=='L' && a[nod-1]=='R'){c[nod] = nod;return nod;}
    if(a[nod]=='R' && a[nod+1]=='L'){c[nod] = nod;return nod;}
    if(a[nod]=='L')c[nod] = dfs(nod-1);
    if(a[nod]=='R')c[nod] = dfs(nod+1);
    return c[nod];
}
int main(){

    cin >> b;
    n = b.size();
    a = '0' + b;
    for(int i = 1 ; i <= n ; i++){
        if(v[i]==0)dfs(i);
    }
    for(int i = 1 ; i <= n ; i++){
        if(a[i]=='R'){
            if((c[i]-i+ 200000)% 2 == 0)rez[c[i]]++;
            if((c[i]-i+ 200000)% 2 == 1)rez[c[i]+1]++;
        }
        if(a[i]=='L'){
            if((i-c[i]+200000)% 2 == 0)rez[c[i]]++;
            if((i-c[i]+200000)% 2 == 1)rez[c[i]-1]++;
        }
    }
    for(int i = 1 ; i <= n ; i++){
        cout << rez[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
#define ll long long
ll tree[4 * N];

void upd(int in, int l, int r, int idx, ll v){
  if(l > idx || r < idx)
    return;
  if(l == r){
    tree[in] = v;
    return;
  }
  int m = (l + r) / 2;
  upd(2 * in, l, m, idx, v);
  upd(2 * in + 1, m + 1, r, idx, v);
  tree[in] = max(tree[2 * in], tree[2 * in + 1]);
}

ll get(int in, int l, int r, int s, int e){
  if(l > e || r < s)
    return 0;
  if(l >= s && r <= e)
    return tree[in];
  int m = (l + r) / 2;
  return max(get(2 * in, l, m, s, e),
             get(2 * in + 1, m + 1, r, s, e));
}
int main() {
  int n;
  cin >> n;
  int h[n], v[n];
  for(int i = 0;i < n;i++)
    cin >> h[i];
  for(int i = 0;i < n;i++)
    cin >> v[i];
  ll dp[n];
  ll res = 0;
  for(int i = 0;i < n;i++){
    dp[i] = get(1, 0, n, 0, h[i] - 1) + v[i];
    upd(1, 0, n, h[i], dp[i]);
    res = max(res, dp[i]);
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 9472
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
using namespace std;
const int maxn = 2e5 + 5;
int n,m;
bool vis[maxn];
map<int,int> MAP;
struct Edge{
    int to,d;
    Edge(int _to,int _d):to(_to),d(_d){}
};
vector<Edge>G[maxn];
void AddEdge(int u,int v,int d){
    G[u].push_back(Edge(v,-d));
    G[v].push_back(Edge(u,d));
}
bool dfs(int x){
    vis[x] = true;
    if(MAP.count(x) == 0)MAP[x] = 0;
    for(int i = 0; i < G[x].size(); i++){
        Edge &e = G[x][i];
        if(MAP.count(e.to) == 0)
            MAP[e.to] = MAP[x] - e.d;
        if(MAP[x] - MAP[e.to] != e.d)return false;
        if(!vis[e.to] && !dfs(e.to))return false;
    }
    return true;
}
void dfs2(int x,int &MIN,int &MAX){
    vis[x] = true;
    for(int i = 0; i < G[x].size();i++){
        int MIN0,MAX0;
        if(!vis[G[x][i].to]){
            dfs2(G[x][i].to,MIN0,MAX0);
            MAX = max(MAX,MAX0);
            MIN = max(MIN,MIN0);
        }
    }
}
int main(){
//    freopen("e:\\in.txt","r",stdin);
    int l,r,d;
    cin>>n>>m;
    memset(vis,0,sizeof(vis));
    for(int i = 0; i < m; i++){
        scanf("%d%d%d",&l,&r,&d);
        AddEdge(l,r,d);
    }
    for(int i = 1; i <= n; i++){
        if(!vis[i] && !dfs(i)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    memset(vis,0,sizeof(vis));
    for(int i = 1; i <= n; i++){
        int MAX = -1e9,MIN = 1e9;
        if(!vis[i]){
            dfs2(i,MIN,MAX);
            if(MAX - MIN > 1000000000){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

int main() {
    ll N; cin >> N;
    vector<ll> A(N); for (ll i = 0; i < N; ++i) cin >> A[i];
    for (ll i = 0; i < N; ++i) A[i] = A[i] - (i + 1);
    sort(A.begin(), A.end());
    vector <ll> candidates;
    ll s_min = 2e18;
    for (ll b = A[N/2]; b < A[N/2] + 1; ++b) {
        ll s = 0;
        for (ll i = 0; i < N; ++i) {
            s += abs(b - A[i]);
        }
        if (s < s_min) {
            s_min = s;
        }
    }
    cout << s_min << endl;
    return 0;
}


Measured memory_bytes: 4764
n, m, x = map(int, input().split())

A = list(map(int, input().split()))

lower_count = 0
larger_count = 0
for a in A:
    if a > x:
        larger_count += 1
    elif a < x:
        lower_count += 1
if lower_count < larger_count:
    print(lower_count)
else:
    print(larger_count)

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

#define mod 1'000'000'007
typedef long long ll;

template <typename T>
void deb(initializer_list<T> l)
{
    for (auto &e : l)
        cout << e << ' ';
    cout << '\n';
}

void solve()
{
    int a, b, c;
    cin >> a >> b >> c;
    if ((a <= c && c <= b) || (b <= c && c <= a))
        cout << "Yes\n";
    else
        cout << "No\n";
}

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

    int t { 1 };
    //cin >> t;
    while (t--)
        solve();

    return 0;
}


Measured memory_bytes: 256
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.regex.Pattern
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.collection.immutable.TreeMap
import scala.math._
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val Array(a, v) = input.split(LINE_SEPARATOR).head.split(" ").map(_.toLong)
    val Array(b, w) = input.split(LINE_SEPARATOR).tail.head.split(" ").map(_.toLong)
    val t = input.split(LINE_SEPARATOR).tail.tail.head.toLong
    if (abs(b - a) <= (abs(v) - abs(w)) * t) "YES" else "NO"
  }

  def medianCalculator(seq: Seq[Int]): Int = {
    //In order if you are not sure that 'seq' is sorted
    val sortedSeq = seq.sortWith(_ < _)

    if (seq.size % 2 == 1) sortedSeq(sortedSeq.size / 2)
    else {
      val (up, down) = sortedSeq.splitAt(seq.size / 2)
      (up.last + down.head) / 2
    }
  }

  def factorize(x: Long): List[Long] = {
    def foo(x: Long, a: Long = 2, list: List[Long] = Nil): List[Long] = a*a > x match {
      case false if x % a == 0 => foo(x / a, a    , a :: list)
      case false               => foo(x    , a + 1, list)
      case true                => x :: list
    }
    foo(x)
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """1 2
      |3 1
      |3""".stripMargin -> """YES
                                   |""".stripMargin,
    """1 2
      |3 2
      |3""".stripMargin -> """NO""".stripMargin,
    """1 2
      |3 3
      |3""".stripMargin -> """NO"""
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 55172
using System;

namespace agc022_b
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			if (n == 3) Console.WriteLine("2 5 63");
			else
			{
				int[] x = new int[] { 2, 3, 4, 6, 8, 9, 10, 12 };
				bool first = true;
				for (int i = 0; i < n / 8; i++)
				{
					foreach (int a in x)
					{
						if (first) first = false;
						else Console.Write(" ");
						Console.Write(i * 12 + a);
					}
				}
				int end = n / 8 * 12;
				if (first) first = false;
				else Console.Write(" ");
				switch (n % 8)
				{
					case (0): break;
					case (1):
					{
						Console.Write((end + 6));
						break;
					}
					case (2):
					{
						Console.Write((end + 2) + " " + (end + 4));
						break;
					}
					case (3):
					{
						Console.Write((end + 4) + " " + (end + 6) + " " + (end + 8));
						break;
					}
					case (4):
					{
						Console.Write((end + 2) + " " + (end + 3) + " " + (end + 4) + " " + (end + 9));
						break;
					}
					case (5):
					{
						Console.Write((end + 2) + " " + (end + 3) + " " + (end + 6) + " " + (end + 9) + " " + (end + 10));
						break;
					}
					case (6):
					{
						Console.Write((end + 2) + " " + (end + 3) + " " + (end + 6) + " " + (end + 9) + " " + (end + 10) + " " + (end + 12));
						break;
					}
					case (7):
					{
						Console.Write((end + 2) + " " + (end + 3) + " " + (end + 4) + " " + (end + 6) + " " + (end + 8) + " " + (end + 9) + " " + (end + 10));
						break;
					}
				}
			}
		}
	}
}

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

int main(){

	int n;
	cin >> n;

	string taro, hanako;
	int taro_p = 0;
	int hanako_p = 0;
	for(int i = 0; i < n; i++){
		cin >> taro >> hanako;
		if(taro > hanako){
			taro_p += 3;
		}else if(taro < hanako){
			hanako_p += 3;
		}else{
			taro_p++;
			hanako_p++;
		}
	}

	cout << taro_p << " " << hanako_p << endl;

	return 0;
}

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


int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if(A==B)cout<<C<<endl;
    else if(A==C)cout<<B<<endl;
    else cout<<A<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int n;
int a[100100];
long double func(int x){
	return ((long double)x-2.0)*logl((long double)x-1.0);
}
long double f(int i,int j){
	if(i<=j)return -2.0;
	if(i==0||j==0)return -0.0;
	return func(i)-func(j)-func(i-j);
}
int main(){
	cin >> n;
	for(int i=0;i<n;i++)cin >> a[i];
	sort(a,a+n);
	int b = -1,c = -1;
	long double mx = -2.0;
	for(int i=0;i<n;i++){
		int k = lower_bound(a,a+n,a[i]/2)-a;
		for(int j=max(0,k-3);j<min(n,k+3);j++){
			long double ret = f(a[i],a[j]);
			//cout << i << ' ' << j << endl;
			if(ret>mx){
				b = i;
				c = j;
				mx = ret;
			}
		}
	}
	cout << a[b] << ' ' << a[c] << endl;
	return 0;
}


Measured memory_bytes: 896
import Control.Monad
import Data.List
-- import qualified Data.Map.Strict as M

main=do
    s <- getLine
--    print.(+) 1.(-) (comb2 $ length s).sum.map (comb2.snd).M.toList $ foldl (\m k->M.insertWith(+)k 1 m) M.empty s
    print.(+) 1.(-) (comb2 $ length s).sum $ map (\c->comb2.length$filter(==c)s) ['a'..'z']

comb2 n = (n*(n-1)) `div` 2

Measured memory_bytes: 13948
line = gets.split(' ').map(&:to_i)

N = line[0]
L = line[1]

taste = []
for i in 1..N do
  taste.push(L+i-1)
end

def abs(x)
  if x > 0 then
    return x
  else
    return -x
  end
end
  
min_id = 0
min_ad = 10000000000000000
for i in 1..N do
  if abs(taste[i-1]) < min_ad then
    min_ad = abs(taste[i-1])
    min_id = i
  end
end
  
ans = 0
for i in 1..N do
  ans += taste[i-1]
end
print ans - taste[min_id-1]

Measured memory_bytes: 1788
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long w = sc.nextLong();
    long h = sc.nextLong();
    long x = sc.nextLong();
    long y = sc.nextLong();
    int l = 0;
    double a = w*h/2.0;
    
    if(x*2 == w && y*2 == h) l = 1;
    
  	System.out.println(a + " " + l);
    
    
  }
}


Measured memory_bytes: 38924
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		new Main().solver();
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();// the number of rabbits
		int m = sc.nextInt();//
		long[][] g = new long[n][n];

		for (int i = 0; i < m; i++) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			long f = sc.nextLong();// the friendliness between u and v.
			g[u][v] = f;
			g[v][u] = f;
		}
		for(int i=0;i<n;i++){
			ArrayList<Integer> used=new ArrayList<>();
			used.add(i);
			dfs(used,g);
		}
		System.out.println(ans);
	}

	static long ans = 0;

	void dfs(ArrayList<Integer> used, long[][] g) {
		int n = g.length;
		if (used.size() > 1) {
			long tmp = 0;
			for (int v : used) {
				long min = 1L << 60;
				for (int u : used) {
					if (u == v)
						continue;
					min=Math.min(min, g[u][v]);
				}
				tmp+=min;
			}
			ans=Math.max(tmp, ans);
		}
		for (int i = used.get(used.size() - 1); i < n; i++) {
			int v = i;
			boolean f = true;
			for (int u : used) {
				if (g[u][v] == 0) {
					f = false;
					break;
				}
			}
			if (f) {
				used.add(v);
				dfs(used, g);
				used.remove(used.size() - 1);
			}
		}
	}

	class Edge {
		int from;
		int to;
		long friendliness;

		Edge(int from, int to, long friendliness) {
			this.from = from;
			this.to = to;
			this.friendliness = friendliness;
		}
	}
}

Measured memory_bytes: 49432
#include<bits/stdc++.h>
using namespace std;
const int POW[11]={0,1,2,4,8,16,32,64,128,256,512};
int main()
{
	int N;
	cin>>N;
	int* *F=new int* [N];
	int* *P=new int* [N];
	for(int i=0;i<N;i++)
	{
		F[i]=new int [11]; 
		P[i]=new int [11]; 
	}
	//INPUT F
	for(int i=0;i<N;i++)
	{
		F[i][0]=0;//F[][0]:10进制数 
		for(int j=1;j<11;j++)
		{
			cin>>F[i][j];//0 or 1
			//F[i][0]+=F[i][j]*POW[j];
			F[i][0]+=F[i][j]*POW[11-j];
		}
	}

	//input P
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<11;j++)
		{
			cin>>P[i][j];
		}
	}

	int c=0; 
	int res=INT_MIN,flag=0;
	string s;
	
	
	for(int k=1;k<1024;k++)
	{
		int cmax=0;
		for(int i=0;i<N;i++)
		{
			c=((F[i][0])&(k));
			s="";
			for(int a=c;a;a/=2)
			{
				s+=(a%2?'1':'0');
			}
			reverse(s.begin(),s.end());
			int cc=0;
			for(int j=0;j<s.length();j++)
			{
				if(s[j]=='1')cc++;
			}
			cmax+=P[i][cc];
			//if(!cc)flag++;
		}
		/*
		if(flag==N)
		{
			int dd=0;
			for(int i=1;i<N;i++)
			{
				if(P[i][1]>P[i-1][1])dd=i;
			}
			cmax=cmax-P[dd][0]+P[dd][1];
		}*/
		res=(res>cmax?res:cmax);
	}
	cout<<res<<endl;
	for(int i=0;i<N;i++)
	{
		delete []F[i];
		delete []P[i];
	}
	delete []F;
	delete []P;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
  int n,k;
  cin >> n >> k;
  int price[n];
  for(int i=0;i<n;i++){
    cin >> price[i];
  }
  sort(price,price + n);
  int sum=0;
  for(int i=0;i<k;i++){
    sum += price[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {

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

        long res = 0;
        for(int i=1; i<=n; i++) {
            long m = n/i;
            res += i * m * (m+1) / 2;
        }

        System.out.println(res);

    }




}

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

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

    int64_t a = 0;
    for (int i = 1; i <= n; i++) {
        //if (i % 3 == 0 && i % 5 == 0) continue;
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;

        a += i;
    }
    cout << a << endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	
      	String str = sc.next();
      	String[] rs = new String[]{str.substring(0, 1), str.substring(1, 2), str.substring(2, 3)}; 
      	int count = 0;
      
      	if(rs[0].equals("R")) {
          	count++;
        }
      
        for(int i = 1; i <= rs.length - 1; i++) {
            if(rs[i].equals("R") && rs[i - 1].equals("R")) {
                count++;                
            }
            if(rs[i].equals("R") && rs[i - 1].equals("S")) {
                count = 1;
            }
         }
      
      	System.out.println(count);
      	sc.close();
    }
}

Measured memory_bytes: 35480
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <cmath>
using namespace std;

vector<char> v;

void solve()
{
	int n;
	cin >> n;

	string s;
	cin >> s;

	for (int i = 0; i < n; i++)
	{
		if (v.size() > 0 && v.back() == s[i])
		{
			continue;
		}

		v.push_back(s[i]);
	}

	cout << v.size();

}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll 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 mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(std::string S, long long K)
{
    ll cnt = 0, cnt_hatena = 1;
    string tmp = S;
    tmp[0] = '?';
    for (int i = 0; i < tmp.size() - 1; i++)
    {
        if (tmp[i] == tmp[i + 1])
        {
            cnt_hatena++;
            tmp[i + 1] = '?';
        }
    }

    for (int i = 0; i < S.size() - 1; i++)
    {
        if (S[i] == S[i + 1])
        {
            cnt++;
            S[i + 1] = '?';
        }
    }
    ll ans = 0;

    if (K == 1)
    {
        cout << cnt << endl;
        return;
    }

    if (S[S.size() - 1] == S[0])
    {
        if (tmp[tmp.size() - 1] == '?')
        {
            if (K % 2 == 0)
            {
                cout << (cnt + cnt_hatena) * (K / 2) << endl;
                return;
            }
            else
            {
                cout << (cnt + cnt_hatena) * (K / 2) + cnt << endl;
                return;
            }
        }
        else
        {
            cout << cnt + cnt_hatena * (K - 1) << endl;
            return;
        }
    }
    else
    {
        cout << cnt * K << endl;
        return;
    }
}

int main()
{
    std::string S;
    std::cin >> S;
    long long K;
    scanf("%lld", &K);
    solve(S, K);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		long ans = 0;
		
		for(int i=1; i<n+1; i++) {
			for(int j=i; j<n+1; j++) {
				for(int k=j; k<n+1; k++) {
					if(i == j && j == k) {
						ans += gcd(i,j,k);
					}else if(i != j && j!= k) {
						ans += 6 * gcd(i,j,k);
					}else {
						ans += 3 * gcd(i,j,k);
					}
				}
			}
		}
		
		System.out.println(ans);

	}
	
	static long gcd(int a, int b, int c) {
		if(a == b && b == c) {
			return a;
		}
		return gcd(gcd(a,b),c);
	}
	
	static long gcd(long a, long b) {
		while(true) {
			if(a==b) {
				return a;
			}
			if(a>b) {
				a %= b;
				if(a==0) return b;
			}else {
				b %= a;
				if(b==0) return a;
			}
		}
	}

}


Measured memory_bytes: 36524
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws java.lang.Exception{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		String ans="";
		for(int i=0; i<n; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int a=Integer.parseInt(st.nextToken()),b=Integer.parseInt(st.nextToken());
			if(a==b) ans+="1";
			else  ans+="0";
		}
		int c=0;
		for(int i=0; i<ans.length(); i++) {
			if(ans.charAt(i)=='0') {
				if(c>=3) {
					System.out.println("Yes");
					return;
				}
				c=0;
				continue;
			}
			++c;
		}
		System.out.println(c>=3?"Yes":"No");
	}

}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;

    // Reward[n] : n日後に報酬が得られるバイトの報酬をVectorにしたやつ
    vector<int> Reward[100001];

    int a, b;
    for (int n = 0; n < N; n++) {
        cin >> a >> b;
        Reward[a].emplace_back(b);
    }

    long answer = 0;
    priority_queue<int> albeit_reward;
    for (int m = 1; m < M + 1; m++) {
        for (int r : Reward[m]) {
            albeit_reward.push(r);
        }
        if (albeit_reward.size() != 0) {
            answer += albeit_reward.top();
            albeit_reward.pop();
        }
    }

    cout << answer << "\n";

    return 0;
}


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

struct Item{
  int num,p,q,r;

};


int main(){
  Item item[1001];
  while(1){
    int n; cin >> n;
    if( n == 0 ) break;
    int i;
    int flag = 0;
    for( i = 0; i < n; i++ ) cin >> item[i].num >> item[i].p >> item[i].q >> item[i].r;
    int P,Q,R,C;
    cin >> P >> Q >> R >> C;
    for( i = 0; i < n; i++ ){
      int karo = 4 * item[i].p + 9 * item[i].q + 4 * item[i].r;
      if( item[i].p <= P && item[i].q <= Q && item[i].r <= R && karo <= C ){
	flag = 1;
	cout << item[i].num << endl;
      }
    }
    if( flag == 0 ) cout << "NA" << endl;
  }


return 0;
}

Measured memory_bytes: 1176
def lower_bound(a, l, r, v)
	m = l
	until m == r
		l, r = a[m] < v ? [m, r] : [l, m]
		m = l + (r-l+1)/2
	end
	return m
end

N  = gets.to_i
probes = []

N.times{
	a = gets.to_i
	i = lower_bound(probes, 0, probes.length, a)
	if i == 0
		probes.unshift(a)
	else
		probes[i-1] = a
	end
}

p probes.length


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

int main(void){
    int n;
    double d;
    cin >>n >>d;
    int cnt=0;
    double p;
    double q;
    for(int i =0;i<n;i++){
        p = 0;
        q=0;
        cin >> p >>q;
      double dwork=((p*p)+(q*q));
        if(sqrt(abs(dwork)) <= d){
            cnt++;
        } 
    }
  cout << cnt;
    

}

Measured memory_bytes: 3828
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
  static string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
  static long n = long.Parse(input[0]);
  static long a = long.Parse(input[1]);
  static long b = long.Parse(input[2]);
  static long[] nums = new long[n];

	static void Main()
	{
    for(long i = 0; i < n; i++)
    {
      nums[i] = long.Parse(Console.ReadLine());
    }
    //Array.Sort(nums);
    Console.WriteLine(Search(1, 1000000000));  
	}

  static long Search(long min, long max)//二分探索法で最小値を求める
  {
    while (true)
    {
      long mid = min + (max - min) / 2;
      if(Check(mid)) max = mid;//さらに小さくても成り立つかも
      else min = mid;

      if(max - min <= 1)
      {
        if(Check(min)) 
        {
          return min;//最小値で成り立つかの確認を優先
        }
        else
        {
          return max;
        }
      break;
      }  
    }
  }

  static bool Check(long testNum)
  {
    long attackCount = 0;
    long[] testNums = new long[n];
    for(long i = 0; i < n; i++)
    {
      testNums[i] = nums[i] - b*testNum;
    }
    for(long i = 0; i < n; i++)
    {
      if(testNums[i] > 0)
      {
        attackCount += (testNums[i]+a-b-1)/(a-b);
      }
    }
    //Console.WriteLine(attackCount+" "+ testNum);
    if(attackCount <= testNum) return true;
    return false;
  }
  
}


Measured memory_bytes: 31580
#include<bits/stdc++.h>
#define rg register
#define il inline
using namespace std;
typedef long long ll;
const int O=2e5+10;
const ll inf=2e9;
struct Data{
	int x,y;
	il bool operator<(Data A)const{
		return x<A.x;
	}
}a[O];
il void Max(int&x,int y){if(x<y)x=y;}
il void Min(int&x,int y){if(x>y)x=y;}
il int gi(){
    int o=0,fl=1;char ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')fl=-1,ch=getchar();
    while(isdigit(ch))o=o*10+ch-'0',ch=getchar();
    return fl*o;
}
int n,bmax,bmin,rmax,rmin,maxn[O],minl[O],ans2=inf;
ll ans1;
int main(){
	n=gi();
	bmax=rmax=-1;bmin=rmin=inf;
	for(int i=1;i<=n;++i){
		int x=gi(),y=gi();
		if(x>y)swap(x,y);
		a[i]=(Data){x,y};
		Max(bmax,y);Min(bmin,y);
		Max(rmax,x);Min(rmin,x);
	}
	ans1=1ll*(bmax-bmin)*(rmax-rmin);
	sort(a+1,a+n+1);bmin=rmin;
	maxn[1]=minl[1]=a[1].y;
	for(int i=2;i<=n;++i){
		maxn[i]=max(maxn[i-1],a[i].y);
		minl[i]=min(minl[i-1],a[i].y);
		if(i^n)Min(ans2,max(maxn[i],a[n].x)-min(minl[i],a[i+1].x));
	}
	printf("%lld\n",min(ans1,1ll*(bmax-bmin)*ans2));
//	printf("%lld %lld",ans1,1ll*(bmax-bmin)*ans2);
	return 0;
}


Measured memory_bytes: 3456
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll mod=1000000007;



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

   
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    
    ll sum=0;
    
    sort(a,a+n);
    for(int i=0;i<k;i++)
    sum+=a[i];
    
    cout<<sum;
    
    


    

    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int
main(int argc, char *argv[])
{
  int a, b;
  scanf("%d %d", &a, &b);
  int ans = 1;
  int k = a;
  while (k < b) {
    k += a - 1;
    ans++;
  }

  if (b == 1) printf("0\n");
  else printf("%d\n", ans);

  return 0;
}
      


Measured memory_bytes: 128
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        List<Data> d = new ArrayList<Data>();
        int n = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            long x = sc.nextLong();
            long y = sc.nextLong();
            d.add(new Data(x,y));
        }
        Collections.sort(d);
        Iterator<Data> it = d.iterator();
        while(it.hasNext()){
            Data a = it.next();
            a.print();
        }
    }
}
class Data implements Comparable<Data>{
    long x;
    long y;
    Data(long x, long y){
        this.x = x;
        this.y = y;
    }
    public int compareTo(Data d){
        if(x < d.x)
            return -1;
        else if(x == d.x){
            if(y < d.y)
                return -1;
            else
                return 1;
        }
        else
            return 1;
    }
    public void print(){
        System.out.println(x + " " + y);
    }
}


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

#define int long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second


signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<int,int> mp;
    ffor(i,s.length()){
        mp[s[i]]++;
    }
    int tot = mp['R']*mp['G']*mp['B'];
    // cout << tot << ' ';
    for(int jump = 1;jump < n;++jump){
        if(2*jump >= n)break;
        for(int i = 0;i < n; ++i){
            if(i + 2*jump >= n) break;
            if((s[i] != s[i + jump]) && (s[i + jump] != s[i + 2*jump]) && (s[i] != s[i + 2*jump])){
                // cout << s[i] << ' ' << s[i + jump] << ' ' << s[i + 2*jump] << '\n';
                // cout << jump << ' ';
                tot--;
            }
        }
    }
    cout << tot;
}		

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

int main(void) {
	vector<int> c(4, 0);
	for (int i = 0; i < 3; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		c[a]++; c[b]++;
	}
	sort(c.begin(), c.end());
	if (c[0] == 1 && c[1] == 1 && c[2] == 2 && c[3] == 2) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		string p = "I";
		for (int i = 0; i < n; i++) {
			p += "OI";
		}
		int c;
		string b;
		cin >> c >> b;
		int counter = 0;
		int i = 0;
		while (b.find(p, i) != string::npos) {
			counter++;
			i = b.find(p, i) + 1;
		}
		cout << counter << endl;
	}
	return 0;
}

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

using namespace std;

bool check(int x)
{
    bool res = true;
    string s = to_string(x);
    for (int i = 0; i < (int)s.length() - 1; i++)
    {
        if (s[i] - '0' + 1 != s[i + 1] - '0')
            res = false;
    }
    return res;
}

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

    int n;
    cin >> n;
    std::vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    int ma = -1;
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            int tmp = v[i] * v[j];
            if (check(tmp))
                ma = max(ma, tmp);
        }
    }
    cout << ma << endl;
}


Measured memory_bytes: 3300
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#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=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll l, r; cin >> l >> r;
    if (r - l > 3000) {
        cout << 0 << endl;
    } else {
        ll res = 2018;
        FOR(i, l, r-1) {
            FOR(j, i+1, r) {
                res = min(res, (i*j) % 2019);
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();

		int a = 0;
		int z = 0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i) == 'A') {
				a = i;
				break;
			}
		}

		for(int i=s.length()-1;i>=0;i--) {
			if(s.charAt(i) == 'Z') {
				z = i;
				break;
			}
		}

		System.out.println(z-a+1);
	}

}


Measured memory_bytes: 28476
#include <stdio.h>

#define STR_SIZE 51U
#define OFFSET 32U

int main(void) {
    int k, n;
    int i;
    char s_in[STR_SIZE];
    char c_tmp;

    scanf("%d %d", &n, &k);
    scanf("%s", s_in);

    s_in[k-1] += OFFSET;

    printf("%s\n", s_in);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
using namespace std;
int isPrime(int n){
    int i;
    if(n == 2)  return true;
    else if(n < 2 || n % 2 == 0)    return false;
    else{
        i = 3;
        while(i <= sqrt(n)){
            if(n % i == 0)  return false;
            i += 2;
        }
    }
    return true;
}

int main(void){
    int n, i, x, count;
    cin >> n;
    count = 0;
    for(i = 0; i < n; i++){
        cin >> x;
        if(isPrime(x))  count++;
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3080
n,k,c = (int(num) for num in input().split())
s = input()
earliest = [0] * k
idx = 0
for i in range(n):
    if s[i] == "o" and (idx == 0 or i - earliest[idx-1] > c):
        earliest[idx] = i
        idx += 1
    if idx >= k:
        break
        
latest = [0] * k
idx = k - 1
for i in range(n-1,0,-1):
    if s[i] == "o" and (idx == k-1 or latest[idx+1] - i > c):
        latest[idx] = i
        idx -= 1
    if idx < 0:
        break
        
#print(earliest)
#print(latest)
        
for i in range(k):
    if earliest[i] == latest[i]:
        print(earliest[i] + 1)

Measured memory_bytes: 20604