akhauriyash/Code-Regression huggingface dataset:
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.Bool (bool)

main :: IO ()
main = do
  let
    f :: [(Int, Int)] -> UF
    f = foldl step IMS.empty
      where
        step :: UF -> (Int, Int) -> UF
        step = ((fst .) .) . flip . uncurry $ unite
  [n, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    g :: UF -> Int
    g u = foldl step 0 [0 .. (n - 1)]
      where
        step :: Int -> Int -> Int
        step c x | snd (root x u) == x = c + 1
                 | otherwise           = c
  abs <- map (unsafeListToPair . map (pred . unsafeTextToInt) . T.words) . T.lines <$> T.getContents :: IO [(Int, Int)]
  print . pred . g . f $ abs

type UF = IntMap Int

parent :: Int -> UF -> Maybe Int
parent = IMS.lookup

root :: Int -> UF -> (UF, Int)
root i u = maybe (u, i) (\j -> let (u', j') = root j u in (bool (IMS.insert i j' u') u (j' == j), j')) (parent i u)

unite :: Int -> Int -> UF -> (UF, ())
unite i j u | i' == j'  = (u'', ())
            | otherwise = (IMS.insert j' i' u'', ())
  where
    (u', i') = root i u
    (u'', j') = root j u'

isSame :: Int -> Int -> UF -> (UF, Bool)
isSame i j u = (u'', i' == j')
  where
    (u', i') = root i u
    (u'', j') = root j u'

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair = (,) <$> head <*> head . tail
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 23952
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    val a = new Array[Int](n)
    val mp = scala.collection.mutable.Map[Long, Long]()
    for (i <- 0 until n) {
      a(i) = sc.nextInt()
      if (mp.contains(a(i))) mp(a(i)) += 1
      else mp.put(a(i), 1)
    }

    val lengths = mp.filter(_._2 >= 2).keys.toList.sorted
    if (lengths.size == 0) {
      println(0)
    } else {
      val (firstLength, firstNums) = (lengths(lengths.size - 1), mp(lengths(lengths.size - 1)))
      if (firstNums >= 4) {
        println(firstLength * firstLength)
      } else if (lengths.size >= 2) {
        val secondLength = lengths(lengths.size - 2)
        println(firstLength * secondLength)
      } else {
        println(0)
      }
    }

  }
}


Measured memory_bytes: 60548
#include <iostream>
#include <vector>

using namespace std;


int main(){
    string s,t;
    cin >> s >> t;
    int m = (int) s.size();
    int n = (int) t.size();
    vector<vector<int>> dp(m+1,vector<int>(n+1));
    string ans;
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){

            if (s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j]+1;
            }
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1]);
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j]);

        }
    }
    int i = m;
    int j = n;
    while(i>0 && j>0){

        if (dp[i][j] == dp[i][j-1])j--;
        else if (dp[i][j] == dp[i-1][j])i--;
        else {ans = s[i-1] + ans;i--;j--;}
    }
    
    cout << ans;
}

Measured memory_bytes: 35584
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

ll MAX = 1000000;
ll dp[1000001];
ll phi[1000001];
bool is_prime(int n) {
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) return false;
	}
	return n != 1;
}

vector<int> divisor(int n) {
	vector<int> res;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

map<int, int> prime_factor(int n) {
	map<int, int> res;
	for(int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int eratosthenes(int n) {
	bool is_prime[n + 1];
	memset(is_prime, true, sizeof(is_prime));
	// prime[n];

	is_prime[0] = is_prime[1] = false;
	int ans = 0;
	rep(i, 2, n + 1) {
		if(is_prime[i]) {
			// prime[ans++] = i;
			ans++;
			for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return ans;
}

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

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

	rep(i, 0, MAX + 1) phi[i] = i;
	rep(i, 2, MAX + 1) {
		if(phi[i] == i) {
			for(int j = i; j <= MAX; j += i) phi[j] = phi[j] / i * (i - 1);
		}
	}
	//memset(dp, 0, sizeof(dp));
	dp[0] = 1;
	dp[1] = 2;
	rep(i, 2, MAX + 1) dp[i] = dp[i - 1] + phi[i];

	int t;
	cin >> t;
	rep(i, 0, t) {
		int n;
		cin >> n;
		cout << dp[n] << endl;
	}


}



Measured memory_bytes: 18740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  int cnt = 0;
  for(int i = 0; i < S.size() / 2; i++){
    if(S.at(i) != S.at(S.size() - 1 - i)){
      cnt++;
    }
  }
  
  cout << cnt << endl;
}

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

int main()
{
  int n, maxi, mini;
  std::cin >> n;
  int R[n] = {0};
  for(int i = 0; i < n; i++) {
    std::cin >> R[i];
  }

  maxi = R[1] - R[0];
  mini = R[0];
  
  for(int i = 1; i < n; i++) {
    if(R[i] - mini > maxi) {
      maxi = R[i] - mini;
    }
    if(R[i] < mini) {
      mini = R[i];
    }
  }


  std::cout << maxi << "\n";


  return 0;
}



Measured memory_bytes: 3880
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int a,b,c;
 cin>>a>>b>>c;
 int d;
 cin>>d;
 if(abs(a-c)<=d)
 cout << "Yes" << endl;
 else{
 if(abs(a-b)<=d && abs(c-b)<=d)
 cout << "Yes" << endl;
 else
 cout << "No" << endl;
 }
 system("pause");
 return 0; 
}

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

void solv() {
    int N;
    string S;
    cin >> N >> S;
    if(N%2 != 0){
        cout << "No" << endl;
        return;
    }
    rep(i,N/2){
        if(S[i] != S[N/2+i] ){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    solv();
    return 0;
}

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

int main() {
  int a,b,c; cin >>a >>b >>c;
  int ans;
  if (a==b) ans = c;
  else if (b==c) ans = a;
  else ans = b;
  
  cout <<ans <<endl;
  /*
  if (ans) cout <<"Yes" <<endl;
  else cout <<"No" <<endl;
  */
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> coin(m);
    for(int i = 0;i < m;i++) cin >> coin[i];
    
    int dp[100000];
    dp[0] = 0;
    
    for(int i = 1;i <= n;i++){
        int tmp = 1e9;
        for(int j = 0; j < m;j++){
            if(i-coin[j] >= 0 && dp[i-coin[j]] < tmp){
                tmp = dp[i-coin[j]];
            }
        }
        
        dp[i] = tmp + 1;
    }
   
   cout << dp[n] << endl;
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define INF 10000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
int n,a[114514],b[114514],d[114514];
bool used[114514];
int now=0;
int ans[114514];
vector<int>v[114514];
void dfs(int x){
	used[x]=true;
	ans[x]=d[now];
	now++;
	for(int i:v[x]){
		if(!used[i]){
			dfs(i);
		}
	}
}
signed main(){
	cin>>n;
	rep(i,n-1){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
		v[a[i]].push_back(b[i]);
		v[b[i]].push_back(a[i]);
	}
	rep(i,n)cin>>d[i];
	
	sort(d,d+n,greater<int>());
	int sum=0;
	rep(i,n)if(i)sum+=d[i];
	cout<<sum<<endl;
	dfs(0);
	
	
	rep(i,n){
		cout<<ans[i];
		if(i==n-1)cout<<endl;
		else cout<<" ";
	}
	return 0;
}


Measured memory_bytes: 7040
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N;
	long ans = 0;
	cin >> N;

	vector<int> A(N);

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		A[i]--;
	}

	for (int i = 0; i < N; i++)
	{
		if (i == A[A[i]])
			ans++;
	}

	cout << ans / 2 << endl;

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string a;
	cin>>a;
	for(int i=0;i<a.length();i++)
	{
		for(int o=i+1;o<a.length();o++)
		{
			if(a[i]=='C'&&a[o]=='F')
			{
				cout<<"Yes"<<endl;
				return 0; 
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 256
using System;

namespace AOJ.Volume0
{
    public class IntersectionOfRectangles
    {
        public static void Main()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                var line = input.Split(' ');
                var ax_from = Math.Min(decimal.Parse(line[0]), decimal.Parse(line[2]));
                var ax_to = Math.Max(decimal.Parse(line[0]), decimal.Parse(line[2]));
                var ay_from = Math.Min(decimal.Parse(line[1]), decimal.Parse(line[3]));
                var ay_to = Math.Max(decimal.Parse(line[1]), decimal.Parse(line[3]));
                var bx_from = Math.Min(decimal.Parse(line[4]), decimal.Parse(line[6]));
                var bx_to = Math.Max(decimal.Parse(line[4]), decimal.Parse(line[6]));
                var by_from = Math.Min(decimal.Parse(line[5]), decimal.Parse(line[7]));
                var by_to = Math.Max(decimal.Parse(line[5]), decimal.Parse(line[7]));

                string answer = "NO";
                // X軸方向の重なり
                if ((ax_from > bx_to) || (ax_to < bx_from)) { }
                else
                {
                    // Y軸方向の重なり
                    if ((ay_from > by_to) || (ay_to < by_from)) { }
                    else { answer = "YES"; }
                }
                Console.WriteLine(answer);
            }
        }
    }
}

Measured memory_bytes: 9320
import java.util.*;
public class Main {
	private static Scanner sc;	 
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		Long a = sc.nextLong();
		Long b = sc.nextLong();
		Long x = sc.nextLong();
		Long count ;
		Long sum1 = a/x;
		long sum2 = b/x;
		if(a%x==0)sum1=sum1-1;
		count = sum2-sum1;
		System.out.println(count);
		
	}

}


Measured memory_bytes: 21972
#include <iostream>

using namespace std;
int a[100001];
int xi;
int part (int p, int r){
    xi = p;
    for (int i = 0; i < r; i++){
        if (a[i] <= a[r]){
            swap(a[i], a[xi]);
            xi++;
        }
    }
    swap(a[xi], a[r]);
}
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    part(0, n-1);
    for (int i = 0; i < n; i++){
        if (i != 0)
            cout << " ";
        if (i == xi){
            cout << "[" << a[i] << "]";
        }
        else
            cout << a[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3468
#include <iostream>
#include <vector>
 
using namespace std;
 
int main()
{
    int N, M;
    cin >> N >> M;
     
    vector<bool> used(N + 1);
    vector<int> v(M);
    for (int i = 0; i < M; i++) {
        cin >> v[i];
    }
     
    for (int i = M - 1; i >= 0; i--) {
        if (used[v[i]]) continue;
        used[v[i]] = 1;
        cout << v[i] << endl;
    }
 
    for (int i = 1; i <= N; i++) {
        if (!used[i]) {
            cout << i << endl;
        }
    }
    return 0;
}

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

int main() {
  ll a,b,x;
  cin >>a>>b>>x;
  
  ll numa=a/x, numb = b/x;
  ll sum = numb - numa;
  if (a%x == 0){
    sum++;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
# coding: utf-8

n = int(input())

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

a,b = 0,0

for i in range(n):
    if i%2==0:
        a += max(card)
        card.pop(card.index(max(card)))
    else:
        b += max(card)
        card.pop(card.index(max(card)))
        
    
print(a-b)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to) 
void dfs(stack<int> s, stack<int> r, stack<int> l, bool &f) {
	if(s.empty()) {
		f = 1;
		return;
	}
	int x = s.top();
	if(r.empty() || r.top() < x) {
		s.pop();
		r.push(x);
		dfs(s,r,l,f);
		r.pop();
		s.push(x);
	}
	if(l.empty() || l.top() < x) {
		s.pop();
		l.push(x);
		dfs(s,r,l,f);
		l.pop();
		s.push(x);
	}
}
int main() {
	int n;
	cin >> n;
	while(n--) {
		int a[10];
		stack<int> s;
		rep(i,10) {
			cin >> a[i];
		}
		rep(i,10) {
			s.push(a[10-i-1]);
		}
		stack<int> r;
		stack<int> l;
		bool f = 0;
		dfs(s,r,l,f);
		if(f) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define int long long 
using namespace std;

int a[200002];


int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, x = 0; cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		x ^= a[i];
	}

	for(int i = 1; i <= n; i++) {
		cout << (x ^ a[i]) << " ";
	} cout << endl;
}

Measured memory_bytes: 5148
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    cin>>n;
    if(n>=24){
        cout<<0<<endl;
        return 0;
    }
    int d[n];
    rep(i,n)cin>>d[i];
    int ans=0;
    rep(s,1<<n){
        int cnt[24]={1};
        bool flag=true;
        rep(i,n){
            if(s&(1<<i)){
                if(cnt[d[i]]){
                    flag=false;
                    break;
                }
                ++cnt[d[i]];
            }
            else{
                if(d[i]==0||cnt[24-d[i]]){
                    flag=false;
                    break;
                }
                ++cnt[24-d[i]];
            }
        }
        if(!flag)continue;
        int mn=inf;
        int mx=0;
        for(int i=1;i<=23;++i){
            if(cnt[i]){
                mn=min(mn,i-mx);
                mx=i;
            }
        }
        mn=min(mn,24-mx);
        ans=max(ans,mn);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <numeric>
#include <cassert>
#include "bits/stdc++.h"

class SuffixArray {
    int n;
    std::string str;
    std::vector<int> sa, rank;

    template <typename Compare>
    int binarySearch(const std::string &t) {
        int m = t.size();
        int lb = -1, ub = n + 1;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            if (Compare()(strncmp(str.c_str() + sa[mid], t.c_str(), m), 0)) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }

  public:
    // 構築 O(n (logn)^2)
    SuffixArray(const std::string _s) : n(_s.size()), str(_s), sa(n + 1), rank(n + 1) {
        for (int i = 0; i <= n; i++) {
            sa[i] = i;
            rank[i] = i < n ? str[i] : -1;
        }
        std::vector<int> tmp(n + 1);
        for (int k = 1; k <= n; k *= 2) {
            // (rank[i], rank[i+k]), (rank[j], rank[j+k]) を比較
            auto compare_sa = [=](int i, int j) {
                if (rank[i] != rank[j])
                    return rank[i] < rank[j];
                else {
                    int ri = i + k <= n ? rank[i + k] : -1;
                    int rj = j + k <= n ? rank[j + k] : -1;
                    return ri < rj;
                }
            };
            std::sort(sa.begin(), sa.end(), compare_sa);
            tmp[sa[0]] = 0;
            for (int i = 1; i <= n; i++) {
                tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
            }
            for (int i = 0; i <= n; i++) {
                rank[i] = tmp[i];
            }
        }
    }
    // O(|t|logn)
    bool contain(const std::string &t) {
        int lb = 0, ub = n;
        while (ub - lb > 1) {
            int mid = (lb + ub) / 2;
            if (str.compare(sa[mid], t.size(), t) < 0)
                lb = mid;
            else
                ub = mid;
        }
        return str.compare(sa[ub], t.size(), t) == 0;
    }
    // 高さ配列 := 接尾辞配列における隣接要素で先頭何文字が共通しているか
    // つまり, lcp[i] = str[sa[i]..] と str[sa[i+1]..] の先頭共通文字数
    // O(n)
    std::vector<int> getLcp() {
        for (int i = 0; i <= n; i++)
            rank[sa[i]] = i;
        int h = 0;
        std::vector<int> lcp(n + 1);
        for (int i = 0; i < n; i++) {
            int j = sa[rank[i] - 1];
            if (h > 0)
                h--;
            for (; j + h < n && i + h < n; h++) {
                if (str[j + h] != str[i + h])
                    break;
            }
            lcp[rank[i] - 1] = h;
        }
        return lcp;
    }
    std::vector<int> getSa() {
        return sa;
    }
    int lowerBound(const std::string &t) {
        return binarySearch<std::less<int>>(t);
    }
    int upperBound(const std::string &t) {
        return binarySearch<std::less_equal<int>>(t);
    }
};

char t[1 << 18];

int main() {
  scanf("%s", t);
  int n = strlen(t);
  SuffixArray sa(t);
  auto lcp = sa.getLcp();
  printf("%d\n", n - *std::max_element(lcp.begin(), lcp.end()));
}


Measured memory_bytes: 1664
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]

#cnt = 0
#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
#print(cnt)

S = str(input())
A = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U","V","W","X","Y","Z"]

if S in A:
    print('A')
else:
    print('a')

Measured memory_bytes: 9116
n = int(input())
s = [int(input()) for _ in range(n)]

if sum(s) % 10 == 0:
  not_10_times = [i for i in s if i % 10 != 0]
  if len(not_10_times) > 0:
    min = min(not_10_times)
    print(sum(s) - min)
  else:
    print(0)
else: 
  print(sum(s))


Measured memory_bytes: 3060
class AC:
    @staticmethod
    def inputStr(char):
        return input().split(char)
    
    @staticmethod
    def inputInt(char):
        a = input().split(char)
        for i in range(len(a)):
            a[i] = int(a[i])
        return a

inp = AC.inputStr(" ")
print(inp[1]+inp[0])

Measured memory_bytes: 2940
#line 1 "main.cpp"

/**
 * @title Template
 */

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>
#include <cassert>

#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/chmin_chmax.cpp"

template <class T, class U>
constexpr bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
constexpr bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

/**
 * @title Chmin/Chmax
 */
#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

#line 4 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

class range {
public:
  class iterator {
  private:
    int64_t M_position;

  public:
    constexpr iterator(int64_t position) noexcept: M_position(position) { }
    constexpr void operator ++ () noexcept { ++M_position; }
    constexpr bool operator != (iterator other) const noexcept { return M_position != other.M_position; }
    constexpr int64_t operator * () const noexcept { return M_position; }
  };

  class reverse_iterator {
  private:
    int64_t M_position;
  
  public:
    constexpr reverse_iterator(int64_t position) noexcept: M_position(position) { }
    constexpr void operator ++ () noexcept { --M_position; }
    constexpr bool operator != (reverse_iterator other) const noexcept { return M_position != other.M_position; }
    constexpr int64_t operator * () const noexcept { return M_position; }
  };
  
private:
  const iterator M_first, M_last;

public:
  constexpr range(int64_t first, int64_t last) noexcept: M_first(first), M_last(std::max(first, last)) { }
  constexpr iterator begin() const noexcept { return M_first; }
  constexpr iterator end() const noexcept { return M_last; }
  constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(*M_last - 1); } 
  constexpr reverse_iterator rend() const noexcept { return reverse_iterator(*M_first - 1); } 
};

/**
 * @title Range
 */
#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/rev.cpp"

#include <type_traits>
#include <iterator>
#line 6 "/Users/kodamankod/Desktop/cpp_programming/Library/other/rev.cpp"

template <class T>
class rev_impl {
public:
  using iterator = decltype(std::rbegin(std::declval<T>()));

private:
  const iterator M_begin;
  const iterator M_end;

public:
  constexpr rev_impl(T &&cont) noexcept: M_begin(std::rbegin(cont)), M_end(std::rend(cont)) { }
  constexpr iterator begin() const noexcept { return M_begin; }
  constexpr iterator end() const noexcept { return M_end; }
};

template <class T>
constexpr decltype(auto) rev(T &&cont) {
  return rev_impl<T>(std::forward<T>(cont));
}

/**
 * @title Reverser
 */
#line 17 "main.cpp"

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  i32 K;
  std::cin >> K;
  std::string ans;
  while (K--) {
    ans += "ACL";
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <algorithm>

#define rep(i,n) for(int i=0; i < n; i++)
using namespace std;

int main()
{
    int n;
    int64_t cnt = 0;
    cin >> n;
    
    rep(i, n)
    {
        if ((i + 1) % 3 != 0 && (i + 1) % 5 != 0)
        {
            cnt += i+1;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3580
MOD = 10**9 + 7

N, K = map(int, input().split())
As = list(map(int, input().split()))

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N, MOD)
def getCombKs(n, k, invs, MOD):
    combKs = [0] * (n+1)
    combKs[k] = 1
    for x in range(k+1, n+1):
        combKs[x] = (combKs[x-1] * x * invs[x-k]) % MOD
    return combKs
combKs = getCombKs(N, K-1, invs, MOD)

As.sort()

ans = 0
for i, A in enumerate(As):
    if i >= K-1:
        ans += combKs[i] * A
    if N-1-i >= K-1:
        ans -= combKs[N-1-i] * A
    ans %= MOD

print(ans)


Measured memory_bytes: 19912
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef struct taikai{
	int bango;
	int get;
}taikai;


int comp(const void *p1,const void *p2){
struct taikai* A = (struct taikai *)p1;
struct taikai* B = (struct taikai *)p2;

if((B->get)>(A->get)){return 1;}
else if((A->get)==(B->get)){
	return (A->bango)>(B->bango);
}
return (B->get)-(A->get);
}

int main(void){
int N;

	scanf("%d",&N);

	taikai* sanka=(taikai*)calloc(N,sizeof(taikai));

	for(int i=0;i<N;i++)scanf("%d %d",&sanka[i].bango,&sanka[i].get);
	qsort(sanka,N,sizeof(sanka[0]),comp);

	
	int maxv=0,maxw=0;


		printf("%d %d\n",sanka[0].bango,sanka[0].get);
		free(sanka);
	

return 0;
}




Measured memory_bytes: 2056
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e3+7;
const ll mod = 1e9+7;
int main()
{
    for(int i=0;i<3;i++){
        char c=getchar();
        if(c=='1')putchar('9');
        else if(c=='9')putchar('1');
        else putchar(c);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define printv(a) {\
    for (auto i : a) cout << i << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define ld long double
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define X first
#define Y second
#define oset tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update>
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);

// AC automaton will help me get AC!
struct AC {
    vector <vector <int>> ch;
    vector <int> cnt, f;
    AC () {extend();}
    void extend() {
        ch.pb(vector <int>(26, 0));
        cnt.pb(0);
    }
    int next(int u, int v) {
        if (!ch[u][v]) {
            ch[u][v] = ch.size();
            extend();
        }
        return ch[u][v];
    }
    void insert(string &s) {
        int now = 0;
        for (char c : s) {
            now = next(now, c - 'a');
        }
        cnt[now]++;
    }
    void build_fail() {
        f.assign(ch.size(), 0);
        queue <int> q;
        for (int i = 0; i < 26; ++i) if (ch[0][i]) q.push(ch[0][i]);
        while (q.size()) {
            int v = q.front(); q.pop();
            for (int i = 0; i < 26; ++i) if (ch[v][i]) {
                    int k = f[v];
                    while (k && !ch[k][i]) k = f[k];
                    if (ch[k][i]) k = ch[k][i];
                    f[ch[v][i]] = k;
                    cnt[ch[v][i]] += cnt[k];
                    q.push(ch[v][i]);
                }
        }
    }
    int match(string &s) {
        int k = 0, ans = 0;
        for (char c : s) {
            while (k && !ch[k][c - 'a']) k = f[k];
            if (ch[k][c - 'a']) k = ch[k][c - 'a'];
            ans += cnt[k];
        }
        return ans;
    }
};

const int mod = 1e9 + 7, x = 864197532, N = 1000087, logN = 17;

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a <= b * c ? "Yes\n" : "No\n");
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 2005

char a[N][N];int up[N][N], down[N][N], ri[N][N], le[N][N];

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

	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; ++i)
	{
		cin >> a[i] + 1;
	}

	for (int i = 1; i <= h; ++i)
	{
		for (int j = 1; j <= w; ++j)
		{
			up[i][j] = (up[i-1][j] + 1) * (a[i][j] == '.');
			le[i][j] = (le[i][j-1] + 1) * (a[i][j] == '.');
		}
	}

	for(int i = h; i > 0; --i)
	{
		for(int j = w; j > 0; --j )
		{
			down[i][j] = (down[i+ 1][j] + 1) * (a[i][j] == '.');
			ri[i][j] = (ri[i][j+1] + 1) * (a[i][j] == '.');
		}
	}

	ll max = 0;

	for(int i = 1; i <= h; ++i)
	{
		for(int j = 1; j <= w; ++j)
		{
			ll k = up[i][j] + down[i][j] + ri[i][j] + le[i][j] - 3;
			if(k > max)
			{
				// cout << k << " ";
				// cout << i << " " << j << "\n";
				max = k;
			}
		}
	}
	cout << max << "\n";
	return 0;
}

Measured memory_bytes: 66944
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, n, m) for (ll i = (n); i < (m); i++)

const int MOD = 998244353;
const int MAX = 2e4+10;

ll K, N;

int mem[MAX];

ll fac[MAX];  /// fac[n] = n!
ll finv[MAX]; /// (fac[n] * finv[n]) % MOD = 1
ll inv[MAX];  /// (n * inv[n]) % MOD = 1

void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR (i, 2, MAX) {
    fac[i] = fac[i-1]*i % MOD;
    inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
    finv[i] = finv[i-1]*inv[i] % MOD;
  }
}

ll nCk (int n, int k) {
  if (n < k || k < 0 || n < 0) return 0;
  return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

ll nHk (int n, int k) {
  if (n <=0 || k < 0) return 0;
  return nCk(n-1+k, n-1);
}

ll pow(ll x, ll n) {
  if (n == 0) return 1;
  if (n == 1) return x;
  if (n%2 == 1) return x*pow((x*x)%MOD, n/2)%MOD;
  return pow((x*x)%MOD, n/2)%MOD;
}

int main() {

  cin >> K >> N;
  init();

  REP(tt, 2*K-1) {
    ll t = min(tt+2, 2*K-tt);
    ll ans = 0;
    if (t != tt+2) ans = mem[t];
    else {
      ll a, b, c;
      b = (t%2 == 0) ? 1 : 0;
      c = K+1-t;
      a = (K-c-b)/2;
      if (b)
        REP (i, a+1) (ans += nCk(a,i) * pow(2,i) % MOD * (nHk(c+i, N-i)+nHk(c+i, N-i-1))) %= MOD;
      else
        REP (i, a+1) (ans += nCk(a,i) * pow(2,i) % MOD * nHk(c+i, N-i)) %= MOD;

      mem[t] = ans;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 768
function Main(input){
    // inp = input.split('\n').map(x => x.split(' ')).map(y => parseInt(y, 10))
    inp = input.split('\n').map(function(x){return x.split(' ').map(function(y){return parseInt(y, 10)})})

    inp.pop()
    var N = inp[0][0]
    var M = inp[0][1]
    var X = inp[0][2]
    var Y = inp[0][3]

    var x = inp[1]
    var y = inp[2]
    var flag = false

    for (var i = X+1; i <= Y; ++i) {
        if(Math.max(...x) < i && Math.min(...y) >= i){
            flag = true
        }
    }

    if(flag){
        console.log("No War")
    }else{
        console.log("War")
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

int main(){
  int A;
  int B;
  int K;
  cin >> A;
  cin >> B;
  if((A - B) % 2 == 0){
      K = (A + B) / 2;
    if(K < 0){
      K *= -1;
    }
    cout << K;
  }else{
    cout << "IMPOSSIBLE\n";
  }
}

Measured memory_bytes: 256
#include <iostream>

int main(void)
{
	using namespace std;
	
	int n,m;
	cin >> n;
	cin >> m;

	int matA[n][m];
	int vecB[m];
	for(int i = 0; i<n; i++){
		for(int j = 0; j<m; j++){
			cin >> matA[i][j];
		}
	}

	for(int i = 0; i<m; i++){
		cin >> vecB[i];
	}

	int tempans;
	for(int i = 0; i<n; i++){
		tempans = 0;
		for(int j = 0; j<m; j++){
			tempans += matA[i][j] * vecB[j];
		}
		cout << tempans << endl;
	}

	return 0;
}

Measured memory_bytes: 3120
n = gets.to_i
s = gets.chomp
ans = 'Yes'
if n.odd?
  ans = 'No'
else
  n2 = n / 2
  n2.times do |i|
    if s[i] != s[n2 + i]
      ans = 'No'
    end
  end
end
puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define int long long
using namespace std;


 main()
{
    int a[6];
    int ans;
    for(int i =1; i<=5; i++){
        cin>>a[i];
        if(a[i] == 0)ans = i;
    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    var N = sc.nextInt

    while (N.toString.distinct.length != 1) {
      N += 1
    }
    N.toString
  }
}


Measured memory_bytes: 27196
N = int(input())
S = input()

L = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
ans = []
for i in range(len(S)):
    idx = L.index(S[i])
    idx += N
    idx %= 26
    ans.append(L[idx])
    
print("".join(ans))

Measured memory_bytes: 3188
n, m = map(int, input().split())
ps = list(map(int, input().split()))
s = sum(ps)
ls = []
for p in ps:
    prev = p
    while p > 0:
        p //= 2
        ls.append(prev - p)
        prev = p
ls.sort(reverse=True)
print(s - sum(ls[:m]))

Measured memory_bytes: 145064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i,h) cin >> s[i];

    vector<string> t(h,string(w,'.'));

    int x = 0, y = 0;
    while(true) {
        t[y][x] ='#';
        if (x < w-1 && s[y][x+1] == '#') x++;
        else if (y < h-1 && s[y+1][x] == '#') y++;
        else break;
    }

    bool ans = true;
    REP(i,h) if (s[i] != t[i]) ans = false;
    if (ans) OUT("Possible")
    else OUT("Impossible")

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

typedef long long ll;

int main() {
  int N; cin >> N;
  ll a[100000];

  for ( int i = 0; i < N; i++ ) cin >> a[i];
  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    int cnt = 0;    
    if ( a[i] % 2 == 0 ) {
      while(a[i]%2 == 0) {
	a[i]/=2;
	ans++;
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] cmd=br.readLine().split(" ");
		int n=Integer.valueOf(cmd[0]);
		ArrayList<int[]> ar1=new ArrayList<>();
		ArrayList<int[]> ar2=new ArrayList<>();
		for(int i=0;i<n;i++)
		{
			StringBuilder s=new StringBuilder(br.readLine());
			Stack<Character> st=new Stack<>();
			int cnt=0;
			for(int j=0;j<s.length();j++)
			{
				if(s.charAt(j)=='(')
					st.push('(');
				else
				{
					if(st.empty())
						cnt++;
					else
						st.pop();
				}
			}
			if(st.size()>=cnt)
				ar1.add(new int[] {cnt,st.size()});
			else
				ar2.add(new int[] {cnt,st.size()});
		}
		StringBuilder f=new StringBuilder("");
		ar1.sort(new Comparator<int[]>() {
			public int compare(int[]a,int[]b)
			{
				if(a[0]>b[0])
					return 1;
				else if(a[0]<b[0])
					return -1;
				else
				{
					return b[1]-a[1];
				}
			}
		});
		ar2.sort(new Comparator<int[]>() {
			public int compare(int[]a,int[]b)
			{
				if(a[1]>b[1])
					return -1;
				else if(a[1]<b[1])
					return 1;
				else
				{
					return a[0]-b[0];
				}
			}
		});
		for(int i=0;i<ar1.size();i++)
		{
			for(int j=0;j<ar1.get(i)[0];j++)
			{
				f=f.append(")");
			}
			for(int j=0;j<ar1.get(i)[1];j++)
			{
				f=f.append("(");
			}
		}
		for(int i=0;i<ar2.size();i++)
		{
			for(int j=0;j<ar2.get(i)[0];j++)
			{
				f=f.append(")");
			}
			for(int j=0;j<ar2.get(i)[1];j++)
			{
				f=f.append("(");
			}
		}
		Stack<Character> st=new Stack<>();
		int b=0;
		for(int i=0;i<f.length();i++)
		{
			if(f.charAt(i)=='(')
				st.push('(');
			else
			{
				if(st.empty())
				{
					b=1;
					break;
				}
				else
					st.pop();
			}
		}
		if(b==1 || st.size()!=0)
			System.out.println("No");
		else
			System.out.println("Yes");
	}
}


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

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

    int ans = 0;

    for(int i = 105; i <= n; i+=2){
        int tmp = 0;
        for(int j = 1; j <= i; j++){
            if(i % j == 0)  tmp++;
        }
        if(tmp == 8)    ans++;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
ll a, b, c, i, j, k;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	cout << s[0] << s[1] << s[2];
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;

int main(){
	int n,c=0;
	string s;
	cin>>n>>s;
	vector<char>slimes(n);
	rep(i,n){
		slimes[i]=s[i];
	}
	for(int i=n-1; i>0; i--){
		if(slimes[i]==slimes[i-1]){
			c++;
		}
	}
	cout<<n-c<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  int n,m,d=0;
  cin>>n>>m;
  pair<char,bool> c[n][m];
  rep(i,0,n){
    rep(j,0,m){
      cin>>c[i][j].first;
      c[i][j].second=false;
    }
  }
  rep(i,0,n){
    rep(j,0,m){
      if(i>0 && c[i][j].first=='#') c[i-1][j].second=true;
      if(i<n-1 && c[i][j].first=='#') c[i+1][j].second=true;
      if(j>0 && c[i][j].first=='#') c[i][j-1].second=true;
      if(j<m-1 && c[i][j].first=='#') c[i][j+1].second=true;
    }
  }
  rep(i,0,n) rep(j,0,m) if(c[i][j].first=='#' && c[i][j].second==false) d++;
  if(d==0) co("Yes");
  else co("No");
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
k = [1]
for i in range(1, 7):
    k.append(6**i)
for i in range(1, 6):
    k.append(9**i)
k.sort()

m = len(k)

dp = [[0 for j in range(N+1)] for i in range(m+1)]
dp[1] = [int(i) for i in range(N+1)]
for i in range(2, m+1):
    for j in range(N+1):
        if j - k[i-1] > -1:
            dp[i][j] = min(dp[i-1][j], dp[i][j-k[i-1]]+1)
        else:
            dp[i][j] = dp[i-1][j]
print(dp[m][N])


Measured memory_bytes: 29576
import java.util.*;

public class Main{
  
  public static void main (String []args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    
    if(Math.abs(c-a) <= d || Math.abs(b-a) <= d && Math.abs(c-b) <=d){
      System.out.println("Yes");
    } else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    int dp[n+1][m+1];
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= m; j++) {
    		if (s[i-1] == t[j-1])
    			dp[i][j] = dp[i-1][j-1] + 1;
    		else
    			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    	}
    }
    string subseq = "";
    int i = n, j = m;
    while (i != 0 && j != 0) {
    	if (s[i-1] == t[j-1]) {
    		subseq += s[i-1];
    		i -= 1;
    		j -= 1;
    	} else if (dp[i][j] == dp[i-1][j]) {
    		i -= 1;
    	} else {
    		j -= 1;
    	}
    }
    reverse(all(subseq));
    cout << subseq;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 73964
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

long sqr(long x)
{
	long kir = 0, kan = 2e9;
	while(kir < kan)
	{
		long mid = (kir+kan+1)/2;
		if(mid*mid > x) kan = mid-1;
		else kir = mid;
	}
	return kir;
}

int main()
{
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	int q; scanf("%d", &q);
	while(q--)
	{
		long a, b;
		scanf("%lld %lld", &a, &b);
		if(a == 1 && b == 1)
		{
			printf("0\n");
			continue;
		}
		long x = a*b-1;
		long sq = sqr(x);
		long res = 2*sq - ((long)(sq == x/sq));
		if(a == b) printf("%lld\n", res);
		else printf("%lld\n", res-1);
	}
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int,int>
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first 
#define s second 
using namespace std;
const int mod=1e9+7;
int logi(int n){int p=0;while(n/2){n=n/2;p++;}return p;}
int poww(int x,int y){int pro=1;while(y){if(y&1)pro=((pro%mod)*(x%mod)%mod);y=y>>1;x=((x%mod)*(x%mod)%mod);}return pro;}
int poww2(int x,int y){int pro=1;while(y){if(y&1)pro=pro*x;y=y>>1;x=x*x;}return pro;}
bool isprime(int n){ if(n==1) return false; for(int i=2;i<=sqrt(n);i++)	if(n%i==0) return false; return true;}

/*

*/



void solve()
{
	int n,k;
	cin>>n>>k;
	vi v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	int sum=0;
	for(int i=0;i<k;i++)
	{
		sum+=v[i];
	}
	cout<<sum;
}

int32_t main()																																	
{
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007

int main(){

    int n,m;

    cin >> n;

    int d[n];

    map<int,int> count;

    REP(i,n){
        cin >> d[i];

        count[d[i]]++;
    }

    cin >> m;
    int t[m];
    REP(i,m){
        cin >> t[i];

        if(count[t[i]]>0){
            count[t[i]]--;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 14348
object Main {

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

    // 互いに割り切ることができる時, 1は作れない。
    def gcd(a: Int, b: Int): Int =
      if (a % b == 0) b
      else gcd(b, a % b)

    val N = sc.nextInt()
    val A = Array.fill(N)(sc.nextInt())
    println(A.reduce((b,n) => gcd(b, n)))
  }

}

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

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}

bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

int ans, n;
int s[100];
bool flag = false;

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        if(s[i] % 10 != 0)  flag = true;
    }
    sort(s,s+n);
    for(int i = 0; i < n; i++){
        ans += s[i];
    }
    if(!flag){
        cout << "0\n";
        return 0;
    }
    int cou = 0;
    if(ans % 10 != 0){
        cout << ans << endl;
        return 0;
    }
    while((ans - s[cou]) % 10 == 0)++cou;
    ans -= s[cou];
    cout << ans << endl;
}

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

namespace ABC141
{
    class Program2
    {
        static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse);
            var N = input.First();
            var M = input.Skip(1).First();
            var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var pq = new PriorityQueue<int>(N, (a, b) => b - a);
            for (int i = 0; i < N; i++)
                pq.Enqueue(A[i]);

            for (int i = 0; i < M; i++)
                pq.Enqueue((int)Math.Floor((double)pq.Dequeue() / 2));

            var sum = 0L;
            for (int i = 0; i < N; i++)
                sum += pq.Dequeue();

            Console.WriteLine(sum);
        }
    }

    public class PriorityQueue<T>
    {
        private readonly List<T> m_list;
        private readonly Func<T, T, int> m_compare;
        private int _mCount;
        public int Count => _mCount;

        public PriorityQueue(Func<T, T, int> compare)
        {
            m_list = new List<T>();
            m_compare = compare;
            _mCount = 0;
        }

        public PriorityQueue(int capacity, Func<T, T, int> compare)
        {
            m_list = new List<T>(capacity);
            m_compare = compare;
            _mCount = 0;
        }

        private int Add(T value)
        {
            if (_mCount == m_list.Count)
            {
                m_list.Add(value);
            }
            else
            {
                m_list[_mCount] = value;
            }
            return _mCount++;
        }

        private void Swap(int a, int b)
        {
            T tmp = m_list[a];
            m_list[a] = m_list[b];
            m_list[b] = tmp;
        }

        public void Enqueue(T value)
        {
            int c = Add(value);
            while (c > 0)
            {
                int p = (c - 1) / 2;
                if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
                c = p;
            }
        }

        public T Dequeue()
        {
            T value = m_list[0];
            m_list[0] = m_list[--_mCount];
            int p = 0;
            while (true)
            {
                int c1 = p * 2 + 1;
                int c2 = p * 2 + 2;
                if (c1 >= _mCount) { break; }
                int c = (c2 >= _mCount || m_compare(m_list[c1], m_list[c2]) < 0) ? c1 : c2;
                if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
                p = c;
            }
            return value;
        }

        public T Peek()
        {
            return m_list[0];
        }

        public bool Contains(T obj)
        {
            foreach (var item in m_list)
                if (obj.Equals(item)) return true;
            return false;
        }
    }
}


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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;

	int ans = min(a,b) + min(c,d);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int v[n];
    for(int i=0;i<n;i++){
        scanf("%d",&v[i]);
    }
    int m=100005;
    int x1,x2,x3,x4;
    int a[m];
    for(int i=0;i<m;i++){
        a[i]=0;
    }
    for(int i=0;i<n;i++){
        if(i%2)a[v[i]]++;
    }
    int max=0,max2=0;
    for(int i=0;i<m;i++){
        if(a[i]>a[max])max=i;
    }
    x1=a[max];
    a[max]=0;
    for(int i=0;i<m;i++){
        if(a[i]>a[max2])max2=i;
    }
    x2=a[max2];
    for(int i=0;i<m;i++){
        a[i]=0;
    }
    for(int i=0;i<n;i++){
        if(!(i%2))a[v[i]]++;
    }
    int max3=0,max4=0;
    for(int i=0;i<m;i++){
        if(a[i]>a[max3])max3=i;
    }
    x3=a[max3];
    a[max3]=0;
    for(int i=0;i<m;i++){
        if(a[i]>a[max4])max4=i;
    }
    x4=a[max4];
    if(max!=max3)printf("%d\n",n-x1-x3);
    if(max==max3){
        if(x1+x4<x2+x3)printf("%d\n",n-x2-x3);
        else printf("%d\n",n-x1-x4);
    }
}

Measured memory_bytes: 896