akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
	int q;

	for (int i = 1; i < 10; i++){
		for (int iq = 1; iq < 10; iq++){
			q = i * iq;

			cout << i << "x" << iq << "=" << q << endl;
		}
	}

	return 0;
}

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

long long n,tmp;
long long visited[200005];

int main()
{
	cin>>n;
	for (long long i=2;i<=n;i++)
	{
		cin>>tmp;
		visited[tmp]++;
	}
	for (long long i=1;i<=n;i++)  cout<<visited[i]<<endl;
	cout<<endl;
	
	return 0;
}

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

int main(){
  string S,T;
  cin>>S;
  cin>>T;
  int count=0;
  int ind=0;
  int i=0;
  while(i<S.size()){
      int subcount=0;
      for(int j=0;j<T.size();++j){
        if(i+j<S.size() && (S.at(i+j)==T.at(j) || S.at(i+j)=='?')){
          ++subcount;
        }
      }
      if(subcount==T.size()){
        ++count;
        ind=i;
      }
      ++i;
    }

  if(count==0){
    cout<<"UNRESTORABLE"<<endl;
  }
  else{
    for(int j=0;j<T.size();++j){
      S.at(ind+j)=T.at(j);
    }
    for(int i=0;i<S.size();++i){
      if(S.at(i)=='?'){
        S.at(i)='a';
      }
    }
    cout<<S<<endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("out.o", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	ll a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll s = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] > a[i + 1]) {
			s += a[i] - a[i + 1];
			a[i + 1] += a[i] - a[i + 1];
		}
	}
	cout << s;
}

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


int main()
{
	int x, n, p;
	cin >> x >> n;
	if (n == 0)  
	{
		cout << x << endl;	
		return 0;
	}
	set<int> P;
	for (int i = 0; i < n; ++i)
	{
		cin >> p;
		P.insert(p);
	}
	int ans = 0, min = 1e9;
	for (int i = -1001; i < 1001; ++i)
	{
		if (P.count(i))
			continue;
		if (abs(i - x) < min)
		{
			min = abs(i - x);
			ans = i;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3624
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var input = new int[5].Select(_ => int.Parse(Console.ReadLine())).ToArray();

            var index = 0;
            var value = input[0] % 10;
            for (int i = 0; i < 5; i++)
            {
                if (0 < input[i] % 10 && input[i] % 10 < value)
                {
                    value = input[i] % 10;
                    index = i;
                }
            }

            var result = 0;
            for (int i = 0; i < 5; i++)
            {
                if (i != index)
                {
                    result += (int)Math.Ceiling(input[i] / 10.0) * 10;
                }
                else
                {
                    result += input[i];
                }
            }
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int x[200000],y[200000];
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
int k(int z) {
	int x = 0;
	while (z) {
		x++;
		z /= 10;
	}
	return x;
}
signed main() {
	int a, b, c, cnt = 0;
	string s;
	cin >> a >> b >> c >> s;
	f(i, a) {
		if (s[i] == 'o') {
			x[cnt] = i;
			cnt++;
			i += c;
			if (cnt == b)break;
		}
	}
	cnt = 1;
	for (int i = a - 1; i >= 0; i--) {
		if (s[i] == 'o') {
			y[b - cnt] = i;
			cnt++;
			i -= c;
			if (cnt == b+1)break;
		}
	}
	f(i, b) {
		if (x[i] == y[i])cout << x[i] + 1 << endl;
	}
}

Measured memory_bytes: 4996
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll num[62][2] = {};
  rep(i, n) rep(j, 62)
    num[j][a[i]>>j&1]++;
  vector<vector<ll>> dp(63, vector<ll>(2, -1));
  dp[62][0] = 0;
  for (int i = 62; i > 0; i--) {
    for (int j = 0; j <= 1; j++) {
      if (dp[i][j] < 0)
        continue;
      int l = k>>i-1&1;
      if (j) {
        for (int m = 0; m <= 1; m++)
          chmax(dp[i-1][j||m<l], dp[i][j]+(num[i-1][m^1]<<i-1));
      } else {
        for (int m = 0; m <= l; m++)
          chmax(dp[i-1][j||m<l], dp[i][j]+(num[i-1][m^1]<<i-1));
      }
    }
  }
  cout << max(dp[0][0], dp[0][1]) << endl;
  return 0;
}

Measured memory_bytes: 1024
# abc115_a.py
# https://atcoder.jp/contests/abc115/tasks/abc115_a

# A - Christmas Eve Eve Eve /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# とある世界では、今日は 12月 D日です。
# D=25なら Christmas, D=24 なら Christmas Eve, D=23 なら Christmas Eve Eve, D=22なら Christmas Eve Eve Eve と出力するプログラムを作ってください。

# 制約
#     22≤D≤25
#     Dは整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# D

# 出力
# 指定された文字列を出力せよ (大文字と小文字は区別される)。

# 入力例 1
# 25

# 出力例 1
# Christmas

# 入力例 2
# 22

# 出力例 2
# Christmas Eve Eve Eve

# 単語と単語の間のスペースも出力してください。


def calculation(lines):
    # X = lines[0]
    D = int(lines[0])
    # N, M = list(map(int, lines[0].split()))

    if D == 22:
        result = 'Christmas Eve Eve Eve'
    elif D == 23:
        result = 'Christmas Eve Eve'
    elif D == 24:
        result = 'Christmas Eve'
    elif D == 25:
        result = 'Christmas'

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['25']
        lines_export = ['Christmas']
    if pattern == 2:
        lines_input = ['22']
        lines_export = ['Christmas Eve Eve Eve']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
def partition(A, p, r):
    x = A[r][1]
    i = p - 1

    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]

    return i + 1


def quick_sort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quick_sort(A, p, q - 1)
        quick_sort(A, q + 1, r)


def main():
    n = int(input())
    A = []

    for i in range(n):
        mark, num = input().split()
        A.append([mark, int(num), i])

    quick_sort(A, 0, n - 1)

    flag = False
    for i in range(1, n):
        if A[i - 1][1] == A[i][1]:
            if A[i - 1][2] > A[i][2]:
                flag = True
                break

    if flag:
        print("Not stable")
    else:
        print("Stable")

    for i in range(n):
        print(A[i][0], A[i][1])


if __name__ == "__main__":
    main()



Measured memory_bytes: 21996
function main(input) {
  input=input.trim();
  const x = parseInt(input.split(" ")[0], 10);
  const y = parseInt(input.split(" ")[1], 10);
  var wake=function(n){
    if(n==1||n==3||n==5||n==7||n==8||n==10||n==12){
      return "a"
    }else if(n==4||n==6||n==9||n==11){
      return "b"
    }else{
      return "c"
    }
  }
  if(wake(x)==wake(y)){
    console.log("Yes");
  }else{
    console.log("No");
  }
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] L = new int[n];
    for(int i = 0; i < n; i++) {
      L[i] = sc.nextInt();
    }
    Arrays.sort(L);
    int ans = 0;
    for(int i = 2; i < n; i++) {
      for(int j = 1; j < i; j++) {
        int d = L[i] - L[j];
        int left = 0;
        int right = j;
        int t = j;
        while(left < right) {
          int med = (left + right) / 2;
          if(L[med] > d) {
            t = med;
            right = med;
          } else {
            left = med + 1;
          }
        }
        ans += (j - t);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 27308
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    
    if(n % k)
        cout << 1;
    else
        cout << 0;
    
    return 0;
}


Measured memory_bytes: 256
### main

loop do
  n = gets.strip.to_i
  break if n == 0

  m = gets.strip.to_i
  s = gets.strip

  status = 0
  prvch = ''
  total = 0
  sublen = 0

  for i in (0...m)
    case s[i]
    when 'I'
      if status == 0
        status = 1
        sublen = 0
      elsif prvch == 'I'
        if sublen >= n
          total += sublen - n + 1
        end
        sublen = 0
      else
        sublen += 1
      end
    when 'O'
      if status == 1 && prvch == 'O'
        if sublen >= n
          total += sublen - n + 1
        end
        status = 0
      end
    end

    prvch = s[i]
  end

  puts total
end

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int na, nb, m;
    cin >> na >> nb >> m;
    vector<int> a(na);
    rep(i, na) {
        cin >> a[i];
    }
    vector<int> b(nb);
    rep(i, nb) {
        cin >> b[i];
    }
    int ans = INF;
    rep(i, m) {
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        ans = min(ans, a[x] + b[y] - c);
    }

    sort(all(a));
    sort(all(b));
    ans = min(ans, a[0] + b[0]);
    cout << ans << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
using namespace std;
#define ep 0.00001

int main()
{
	int a, b, temp;
	int a0, b0;
	int a1, b1;
	int gcd, lcm;
	
	while (cin >> a >> b) {
		if (a > b) {
			temp = a;
			a = b;
			b = temp;
		}
		a0 = a;
		b0 = b;
		while (a0) {
			temp = b0 % a0;
			b0 = a0;
			a0 = temp;
		}
		gcd = b0;
		a1 = a;
		b1 = b;
		while (a1 != b1) {
			if (a1 < b1)
				a1 += a;
			else if (a1 > b1)
				b1 += b;
		}
		lcm = a1;
		cout << gcd << " " << lcm << "\n";
	}
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	double a, b, h, m;
	cin >> a >>b >> h >> m;

	double angle_a = 0.0;
	double angle_b = 0.0;

	angle_a = h * 30.0 + m / 2.0;
	angle_b = m * 6.0;

	double rad_a = angle_a * PI / 180.0;
	double rad_b = angle_b * PI / 180.0;

	double a_x, a_y;
	double b_x, b_y;

	a_x = a * cos(rad_a);
	a_y = a * sin(rad_a);

	b_x = b * cos(rad_b);
	b_y = b * sin(rad_b);

	double ans = pow( pow(a_x - b_x, 2.0) + pow(a_y - b_y, 2.0), 0.5);
	printf("%.10lf\n", ans);
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 4308
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    int count=0;
    for(int i=1; i<n-1; i++){
        if(p[i-1]<p[i] && p[i]<p[i+1])count++;
        if(p[i+1]<p[i] && p[i]<p[i-1])count++;
    }
    cout << count<< endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    set<char> s;
    
    char a;
    cin >> a;
    s.insert(a);
    cin >> a;
    s.insert(a);
    cin >> a;
    s.insert(a);
    cin >> a;
    s.insert(a);

    if(s.size() == 2){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0; 
}


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

namespace ConsoleApplication1{
    class Program{
        static void Main(string[] args){

            int a, b;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);  
            b = int.Parse(str[1]);

            if (b % a == 0) Console.WriteLine(a + b);
            else Console.WriteLine(b - a);

        }
    }
}


Measured memory_bytes: 11092
maxw, maxh, N = list(map(int, input().split(' ')))
minw, minh = 0, 0

for n in range(N):
    x, y, a = list(map(int, input().split(' ')))
    if a == 1:
        minw = max(minw, x)
    elif a == 2:
        maxw = min(maxw, x)
    elif a == 3:
        minh = max(minh, y)
    elif a == 4:
        maxh = min(maxh, y)

if maxw-minw < 0 or maxh-minh < 0:
    res = 0
else:
    res = (maxw-minw)*(maxh-minh)
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	ll a;cin >> a;
	ll ans=a;
	for(int i=1;i<n;i++){
		cin >> a;
		ans=ans/GCD(ans,a)*a;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

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

    int n;
    cin >> n;
    vector<int> c(n-1), s(n-1), f(n-1);
    REP(i, n-1) cin >> c[i] >> s[i] >> f[i];

    REP(i, n){
        int cur = i;
        int time = 0;
        while(cur != n-1){
            time = max(time, s[cur]);
            time += (time % f[cur] != 0 ? f[cur] - (time + f[cur]) % f[cur] : 0) + c[cur];
            cur++;
        }
        cout << time << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    short i,x,y;
    for(i=0;i<=3000;i++)
    {
        scanf("%d%d",&x,&y);
        if(x==0 && y==0)
        {
            break;
        }
        else
        {
            printf("%d %d\n",x<y?x:y,x<y?y:x);
        }
    }
}


Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
int i,j,k,n,m;
string s;

int main() {
  int d,g;cin>>d>>g;
  vector<pair<int, int>> v;
  n=0;
  for (i=0;i<d;++i){
    int p,c;cin>>p>>c;
    n+=p;
    v.push_back(make_pair(p,c));
  }
  int min_cnt=n;
  for (int bit=0;bit < (1<<d); ++bit) {
    int score = 0;
    int cnt_t = 0;
    int max_i = 0;
    for (i=0;i<v.size();++i){
      if (bit & (1<<i)) {
        score += 100*(i+1)*v[i].first + v[i].second;
        cnt_t += v[i].first;
      } else {
         max_i = i;
      }
    }
    if (score < g) {
    	int s1 = 100*(max_i+1);
      int rest = (g - score)/s1;
      if ((g - score)%s1 > 0) ++rest;
      if (rest < v[max_i].first) {
      	cnt_t += rest;
      } else {
      	continue;
      }
    }
    min_cnt = min(min_cnt,cnt_t);
  }
  cout << min_cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>

int main(void) {
    int x, a, b;
    scanf("%d %d %d", &x, &a, &b);
    if (abs(x - a) < abs(x - b)) {
        puts("A");
    }
    else {
        puts("B");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree = 
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;

int n, m, k;
int a[11];

void solve(int test)
{
  string s = "keyence";
  string t; cin >> t;
  n = (int)t.size();
  for (int i = 0; i < 7; ++i) {
    if (t.substr(0, i) == s.substr(0, i) && t.substr(n - 7 + i) == s.substr(i)) {
      cout << "YES\n";
      return;
    }
  }
  cout << "NO\n";
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
void solve(void)
{
	char s[256];
	int len;
	scanf("%s", s);
	len=strlen(s);
if(len&1)
return;	//
	for(len-=2; len>0; len-=2){
		if(strncmp(s, s+len/2, len/2)==0){
			break;
		}
	}
	if(len>0){
		printf("%d\n", len);
	}
}
int main(int argc, char **argv)
{
	solve();
	return 0;
}


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

int main() {
 string s;
  cin >> s;
  bool ok = true;
  for(int n = s.size()-2; n>=2; n-=2) {
    ok = true;
    for(int i = 0; i < n/2;i++) {
      if(s[i] != s[i+n/2]) {
        ok = false;
        break;
      }
    }
    if(ok) {
       cout << n<<endl;
       return 0;
    }
  }
  
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  ll res = 0;
  rep(i, n) {
    ll tmp1 = 0, tmp2 = 0;
    rep(j, n) {
      if (v.at(i) > v.at(j)) {
        tmp1++;
        if (i < j) tmp2++;
      }
    }
    res += ((k*(k-1)/2)%mod)*tmp1;
    res %= mod;
    res += k*tmp2;
    res %= mod;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
fun main(s: Array<String>) {
  val (a, b) = readLine()!!.split(' ').map { it.toLong() }
  println(a * b / gcd(a, b))
}
 
fun gcd(a: Long, b: Long): Long {
    if(a < b) return gcd(b, a)
    if(b == 0L) return a
    return gcd(b, a % b)
}

Measured memory_bytes: 38472
import Data.Functor((<$>))
import Text.Printf(printf)

main :: IO ()
main = do 
        q  <- (read :: String -> Int).last.words <$> getLine
        xs <- map ((\[n, t] -> (n, (read :: String -> Int) t)).words).lines <$> getContents
        solve xs [] q 0

solve                     :: [(String, Int)] -> [(String, Int)] -> Int -> Int -> IO ()
solve []            []  _ _  = return ()
solve []            ys q cnt = solve (reverse ys) [] q cnt 
solve ((n, t) : xs) ys q cnt = let t'   = t - q
                                   cnt' = cnt + q
                                   m    = cnt' + t'
                               in if t' > 0 then solve xs ((n, t') : ys) q cnt'
                                            else printf"%s %d\n" n m >> solve xs ys q m

Measured memory_bytes: 13420
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AMealDelivery {
public:
	void solve(istream& in, ostream& out) {
        int x, a, b; in >> x >> a >> b;
        if(abs(x - a) > abs(x - b)) out << "B" << endl;
        else out << "A" <<  endl;
	}
};

int main() {
	AMealDelivery solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

mt19937_64 llrand((int) chrono::steady_clock::now().time_since_epoch().count());

#define st first
#define nd second
#define pb push_back

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;
const ld pi = acos(-1.0);

ld a, b, h, m;

ld dist(ld xa, ld ya, ld xb, ld yb) {
  ld dx = xa - xb;
  ld dy = ya - yb;
  return sqrt(dx * dx + dy * dy);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> a >> b >> h >> m;

  ld theta_h = -(pi/6) * (h + m/60);
  ld theta_m = -(pi/30) * (m + 60*h);

  cout << fixed << setprecision(12) << dist(a * sin(theta_h), a * cos(theta_h), b * sin(theta_m), b * cos(theta_m)) << "\n";
}


Measured memory_bytes: 4164
include Math

def dist(x, y, p)
    if p == "inf"
        return chebyshev(x, y)
    else
        dist = 0
        x.zip(y) do |xi, yi|
            dist += (xi - yi).abs ** p
        end
        return dist ** (1.0 / p)
    end
end

def chebyshev(x, y)
    dist = -1
    x.zip(y) do |xi, yi|
        dist = [dist, (xi - yi).abs].max
    end
    return dist
end

dim = gets.chomp.to_i

x = gets.chomp.split.map(&:to_i)
y = gets.chomp.split.map(&:to_i)

for i in 1..3
    puts dist(x, y, i)
end
puts dist(x, y, "inf")

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

int main() {
  int n;
  cin >> n;
  map<char, int> name;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    char c = s.at(0);
    name[c]++;
  }
  
  long long ans = 0;
  vector<long long> cnt(5);
  for(auto now : name){
    char c = now.first;
    long long k = (long long) now.second;
    if(c == 'M') cnt.at(0) = k;
    if(c == 'A') cnt.at(1) = k;
    if(c == 'R') cnt.at(2) = k;
    if(c == 'C') cnt.at(3) = k;
    if(c == 'H') cnt.at(4) = k;
  }
  for(int i = 0; i < 5; i++){
    for(int j = i+1; j < 5; j++){
      for(int k = j+1; k < 5; k++){
        ans += cnt.at(i) * cnt.at(j) * cnt.at(k);
      }
    }
  }
  
  cout << ans << endl;
}

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

int main(void){
    string S;cin>>S;
    int A,Z,ans;A=200001;Z=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='A'){
            A=i;
            break;
        }
    }
    for(int i=S.size()-1;i>=0;i--){
        if(S[i]=='Z'){
            Z=i;
            break;
        }
    }
    cout<<Z-A+1<<endl;
    return 0;
}

Measured memory_bytes: 3732
import heapq

def dijkstra(graph, node, start):
    dist = [float("inf") for _ in range(node)]

    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))

    while q:
        cost, cur_node = heapq.heappop(q)

        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heapq.heappush(q, (dist[nex_node], nex_node))

    return dist

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append((c, b))
    adj[b].append((c, a))
shortest = []
for i in range(n):
     shortest.append(dijkstra(adj, n, i))
ans = 0
for i in range(n):
    for cost, j in adj[i]:
        if cost > shortest[i][j]:
            ans += 1
print(ans // 2)


Measured memory_bytes: 3572
#include<stdio.h>
#include<stdlib.h>

int max(int,int);
void ink1(int,int);
void ink2(int,int);
void ink3(int,int);

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

int main(void){

  int x,y,size,i,j,count=0,ans=0;

  memset(grid,0,sizeof(grid));

  while(~scanf("%d,%d,%d",&x,&y,&size)){
    if(size==1)ink1(y+2,x+2);
    else if(size==2)ink2(y+2,x+2);
    else if(size==3)ink3(y+2,x+2);

  }

  for(i=2;i<12;i++){
    for(j=2;j<12;j++){
      ans=max(ans,grid[i][j]);
      if(grid[i][j]==0)count++;
    }
  }

  printf("%d\n%d\n",count,ans);

  return 0;
}

int max(int a,int b){
  return a>b?a:b;
}

void ink1(int y,int x){
  int i;
  for(i=0;i<4;i++)
    grid[y+dy[i]][x+dx[i]]++;
  grid[y][x]++;
}

void ink2(int y,int x){
  int i,j;
  for(i=-1;i<2;i++)
    for(j=-1;j<2;j++)
      grid[y+i][x+j]++;

}

void ink3(int y,int x){
  int i,j;
  for(i=0;i<4;i++)
    grid[y+2*dy[i]][x+2*dx[i]]++;

  for(i=-1;i<2;i++)
    for(j=-1;j<2;j++)
      grid[y+i][x+j]++;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    if (b % a == 0) {
        cout << a + b << endl;
    } else {
        cout << b - a << endl;
    }
}

Measured memory_bytes: 256
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int main()
{
  _int64 ans;
  int i,j,m,n;
  scanf("%d%d",&n,&m);
  if ((n==1)&&(m==1)) printf("1\n");
  else if (n==1) printf("%d\n",m-2);
  else if (m==1) printf("%d\n",n-2);
  else
  {
    ans=(_int64)(n-2)*(m-2);
    printf("%lld\n",ans);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        int main(){
          long long int n;
          cin >> n;
          long long int a;
          for(long long int i=1; i<sqrt(n)+1; i++){
            if(n%i){}
            else{a=i;}
          }
          long long int ans;
          //cout << a << endl;
          //cout << n/a << endl;
          ans = a + (n/a) -2;
          cout << ans << endl;
          return 0;
        }

Measured memory_bytes: 256
A, B, C = gets.split.map(&:to_i)

a, b, c = [A, B, C].sort
cnt = 0
n = (c - a) / 2
a += 2*n
cnt += n
m = (c - b) / 2
b += 2*m
cnt += m
a, b = [a, b].minmax
case [0, b - a, c - a]
when [0, 0, 1]; cnt += 1
when [0, 1, 1]; cnt += 2
end
puts cnt

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
  cerr << ' ' << head;
  debug_cerr(tail...);
}
void chmax(lint &a, lint b) { if (a < b) a = b; }
void chmin(lint &a, lint b) { if (a > b) a = b; }
struct IoSetup{
    IoSetup(){
      cin.tie(nullptr);
      ios::sync_with_stdio(false);
      cout << fixed << setprecision(20);
      cerr << fixed << setprecision(20);
    }
} iosetup;
const int mod = 1e9 + 7;

int main() {
  int n; cin >> n;
  vector<lint> vec(n);
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  lint ans = 0;
  for (int bit = 0; bit < 60; ++bit) {
    lint num[2] = {0, 0};
    for (int i = 0; i < n; ++i) {
      if ((1LL << bit) & vec[i]) ++num[0];
      else ++num[1];
    }
    ans += (num[0] * num[1] % mod) * ((1LL << bit) % mod);
    ans %= mod;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 110;
/*=================================================================================*/

ll dp[N][M][2];
string str;
int a[N], d, len;

int dfs(int k, int now, int lim) {
   if(dp[k][now][lim] >= 0) return dp[k][now][lim];
   if(k == len) return dp[k][now][lim] = (now == 0);
   ll sum = 0;
   int up = lim ? a[k] : 9;
   for0(i, up+1) {
      sum += dfs(k+1, (now+i) % d, lim && i==up);
      sum %= mod;
   }
   return dp[k][now][lim] = sum;
}

int main() {
   ms(dp, -1);
   cin>>str>>d;
   len = str.size();
   for0(i, len) a[i] = str[i] - '0';
   ll ans = (dfs(0, 0, 1) - 1 + mod) % mod;
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 176356
#include <stdio.h>
 
int main() {
 
  char map[101][101],a[102];
  int i,j,w,h,x,y,flag;
 
  while(1) {
    scanf("%d %d",&h,&w);
    if(w==0 && h ==0) break;
 
    for(i=0;i<h;i++) {
      scanf("%s",a);
      for(j=0;j<w;j++) {
    map[i][j] = a[j];
      }
 
    }
 
    flag = 0;
    x  = y = 0;
 
    while(1) {
      flag++;
      if(map[y][x] == '^')y--;
      else if(map[y][x] == '>')x++;
      else if(map[y][x] == 'v')y++;
      else if(map[y][x] == '<')x--;
      else if(map[y][x] == '.'){
    //  printf("break\n");
    break;
      }
       
      // printf("flag = %d\n",flag);
      if(flag >=25000) break;
    }
 
 
    if(flag >= 24000) printf("LOOP\n");
    else printf("%d %d\n",x,y);
 
  }
 
  return 0;
 }

Measured memory_bytes: 1052
#include <vector>
#include <iostream>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
int a[26];

int main() {
  int H, W; cin >> H >> W;
  rep(y, H) rep(x, W) {
    char c; cin >> c;
    a[c-'a']++;
  }

  int A = (H/2) * (W/2) * 4, B, C = (H%2)*(W%2); B = (H*W) - A - C; A /= 4, B /= 2;
  rep(i, 26) {
    while(a[i] >= 4 && A >= 1) {A--, a[i] -= 4;}
  }
  rep(i, 26) {
    while(a[i] >= 2 && B >= 1) {B--, a[i] -= 2;}
  }
  rep(i, 26) {
    while(a[i] >= 1 && C >= 1) {C--, a[i] -= 1;}
  }

  if(A+B+C >= 1) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctime>
#include <stack>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lowbit(x) (x&-x)
#define mem(x,a) memset(x,a,sizeof(x))

const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int read(){
	int ret = 0, sgn = 1;
	char c = getchar();
	while (c != '-' && (c<'0' || c>'9')) c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (c = getchar(), c >= '0'&&c <= '9')
	{
		ret = ret * 10 + c - '0';
	}
	return ret*sgn;
}

LL dp[104][2];

int main()
{
	int a, b, c;
	while (scanf("%d%d%d", &a, &b, &c) != EOF)
	{
		if (b == c)
			cout << a << endl;
		else if (a == b)
			cout << c << endl;
		else if (a == c)
			cout << b << endl;
	}
	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 a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		
		if(a >= k) {
			System.out.println(k);
		}
		else if(a + b >= k) {
			System.out.println(a);
		}
		else {
			int temp = k - a - b;
			System.out.println(a - temp);
		}
	}


}


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

int main() {
	int a, b;
	while(cin >> a >> b) {
		int c = a + b;
		
		if (c < 10) {
			cout << 1 << endl;
		} else if (c < 100) {
			cout << 2 << endl;
		} else if (c < 1000) {
			cout << 3 << endl;
		} else if (c < 10000) {
			cout << 4 << endl;
		} else if (c < 100000) {
			cout << 5 << endl;
		} else if (c < 1000000) {
			cout << 6 << endl;
		} else {
			cout << 7 << endl;
		}
	}
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll n, k, x, y;
	cin >> n >> k >> x >> y;
	cout << (min(k,n)*x+max(0LL,n-k)*y) << "\n";

}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int k;
	cin >> k;
	string s;
	cin >> s;
	if(s.size() > k){
		cout << s.substr(0, k);
		cout << "..." << endl;
		return 0;
	}
	cout << s << endl;			
}

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

int main(){
    int n, k;
    cin >> n >> k;
    set<int> s;
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            s.insert(a);
        }
    }
    cout << n - s.size() << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	lint M;
	cin >> N >> M;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());

	auto judge = [&](auto idx) {

		lint cnt = 0;
		for (int i = 0; i < N; i++) {
			cnt += A.end() - upper_bound(A.begin(), A.end(), idx - A[i] - 1);
		}
		DMP(idx, cnt);
		return cnt >= M;
	};

	auto binary_search = [&](auto f) {

		auto ng = LINF;
		auto ok = 0LL;

		while (abs(ok - ng) > 1) {
			auto mid = (ok + ng) / 2;

			if (f(mid)) ok = mid;
			else ng = mid;
		}

		return ok;
	};

	int border = binary_search(judge);
	vector<lint> culA(N + 1);
	for (int i = 0; i < N; i++) culA[i + 1] = culA[i] + A[i];
	DMP(culA);

	lint ans = 0, cnt = 0;
	for (int i = 0; i < N; i++) {
		lint tmp = A.end() - upper_bound(A.begin(), A.end(), border - A[i]);
		cnt += tmp;
		ans += culA.back() - culA[N - tmp];
		ans += A[i] * tmp;
	}

	ans += border * (M - cnt);

	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 1408
import sys
N = int(input())
G = [{} for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, sys.stdin.readline().split())
    u -= 1
    v -= 1
    G[u][v] = w
    G[v][u] = w

ans = [0] * N
todo = [(0, 0)]
done = set()
while todo:
    p, d = todo.pop()
    for np, dd in G[p].items():
        if not np in done:
            nd = d + dd
            ans[np] = nd % 2
            todo.append((np, nd))
    done.add(p)

for x in ans:
    print(x)

Measured memory_bytes: 50000
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const double EPS  = 1e-10;
const bool debug = 0;
//-----------------------------------//

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

	int ds = 0;
	int tmp = N;
	while (tmp > 0) {
		ds += tmp % 10;
		tmp /= 10;
	}

	if (N % ds == 0) puts("Yes");
	else puts("No");
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

const long double PI = acos(-1);

struct point {
    long double x;
    long double y;
    point (long double x_, long double y_) {
        x = x_;
        y = y_;
    }
};

long double dist (point A, point B) {
    long double res = sqrt(pow(A.x - B.x,2) + pow(A.y - B.y,2));
    return res;
}

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

ld a,b,h,m;
cin >> a >> b >> h >> m;

h += m/60;
h /= 12, m/= 60;
h *= 2*PI, m *= 2*PI;
point A(a*cos(h), a*sin(h));
point B(b*cos(m), b*sin(m));
cout << fixed << setprecision(12) << dist(A,B) << endl;
return 0;
}

Measured memory_bytes: 4188
arr = [0, 0, 0]
while true
    edge = gets.chomp.split.map(&:to_i).sort
    break if edge.max >= edge.inject(:+) - edge.max
    c2 = edge.max ** 2
    edge.pop
    a2b2 = edge.map{|e| e ** 2}.inject(:+)
    type = 2
    if a2b2 == c2
        type = 0
    elsif a2b2 > c2
        type = 1
    end
    arr[type] += 1
end
puts arr.inject(:+).to_s + " " + arr.join(" ")



Measured memory_bytes: 6872
def sharp(u,cnt)
  u.times{
    if cnt.even?
      print (".")
    else
      print ("#")
    end
    cnt += 1
  }
end

def f()
  h,w = gets.split.map(&:to_i)
  cnt=0
  return if h==0 && w==0
  h.times{
    if cnt.even?
      sharp(w,1)
    else
      sharp(w,0)
    end
    cnt+=1
    puts

  }
  puts
  f()
end

f()







Measured memory_bytes: 6880
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int k=-10010;
	if (k<a+b)
	{
		k=a+b;
	}
	else
	{
		k=k;
	}
	if (k<a-b)
	{
		k=a-b;
	}
	else
	{
		k=k;
	}
	if (k<a*b)
	{
		k=a*b;
	}
	cout<<k<<endl;
	return 0;
 } 

Measured memory_bytes: 256
/* author:hellojim */
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=-1e18-10;
	ans=max(ans,a*c);
	ans=max(ans,a*d);
	ans=max(ans,b*c);
	ans=max(ans,b*d);
	cout<<ans<<endl;
	return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<long> lucasNumber;
  lucasNumber.push_back(2);
  lucasNumber.push_back(1);
  
  for(int i = 1;i < N;i++)
  {
    lucasNumber.push_back(lucasNumber[i] + lucasNumber[i-1]);
  }
  
  cout << lucasNumber[N];
}

Measured memory_bytes: 256