akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
const ll inf = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const ll N=1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;


ll a[maxn];
ll b[maxn];
int main(){
   // in;
   // out;
   IOS;
   ll n;
   cin>>n;
   for(ll i=1;i<=n;i++){
      cin>>a[i];
   }
   ll sum=0;
   for(ll i=2;i<=n;i++){
      sum=(sum+a[i])%mod;
   }
   // cout<<sum<<endl;
   b[1]=sum;
   for(ll i=2;i<=n;i++){
      sum-=a[i];
      if(sum<0) sum+=mod;
      b[i]=sum;
   }

   ll ans=0;
   for(ll i=1;i<n;i++){
      ans=(ans+(a[i]*b[i])%mod)%mod;
   }
   cout<<ans<<endl;

}

Measured memory_bytes: 6700
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    string S, T;
    cin >> S >> T;
    map<char, char> dictionary1, dictionary2;
    int size = S.size();

    for (int i = 0; i < size; i++) {
        auto itr = dictionary1.find(T[i]);
        if (itr == dictionary1.end()) {
            if (T[i] != S[i]) {
                dictionary1[T[i]] = S[i];
            }         
        } else {
            if (dictionary1[T[i]] != S[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    for (int i = 0; i < size; i++) {
        auto itr = dictionary2.find(S[i]);
        if (itr == dictionary2.end()) {
            if (T[i] != S[i]) {
                dictionary2[S[i]] = T[i];
            }         
        } else {
            if (dictionary2[S[i]] != T[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define REP(i,N) for(int i=0;i<N;i++)

int main()
{
    int n; cin>>n;
    vector<pair<int,int>> c(n,{0,0});

    vector<vector<int>> graph(n,vector<int>());
    vector<int> depth(n,0);

    for(int i=0;i<n;i++){
        c[i] = {i, 0};
    }
    for(int i=0;i<n-1;i++){
        int a,b; cin>>a>>b;
        c[a-1].second++; c[b-1].second++;
        graph[a-1].push_back(b-1);
        graph[b-1].push_back(a-1);
    }

    vector<int> d(n,0);
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    sort(all(d), greater<int>());

    int maxConn = 0;
    int argmax = 0;
    for(int i=0;i<n;i++){
        if(c[i].second>maxConn){
            maxConn = c[i].second;
            argmax = c[i].first;
        }
    }

    queue<int> q;
    bool visited[n];
    for(int i=0;i<n;i++){
        visited[i] = false;
    }
    q.push(argmax);
    int dd = 0;
    while(!q.empty()){
        int t = q.front();
        q.pop();
        visited[t] = true;
        depth[t] = dd;
        for(auto n:graph[t]){
            if(!visited[n]){
                q.push(n);
            }
        }
        dd++;
    }

    sort(all(c), [&](pair<int,int> a, pair<int,int> b){ return depth[a.first]<depth[b.first]; });
    for(int i=0;i<n;i++){
        c[i].second = i;
    }
    sort(all(c), [](pair<int,int> a, pair<int,int> b){ return a.first<b.first; });

    cout<<accumulate(d.begin()+1, d.end(), 0)<<endl;
    for(auto p:c){
        cout<<d[p.second]<<" ";
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 1152
using System;

public class AtCoderC
{
    static void Main()
    {
        int n;
        int k;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            k = int.Parse(words[1]);
        }

        double[] monsters = new double[n];
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n; i++)
            {
                monsters[i] = double.Parse(words[i]);
            }
        }

        Array.Sort(monsters);

        double sum = 0;

        for (int i = 0; i < n - k; i++)
        {
            sum += monsters[i];
        }

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 31452
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll a[300000];
ll sumL[300000], sumR[300000];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < 3 * N; i++) cin >> a[i];
	priority_queue<ll, vector<ll>, greater<ll>> L;
	priority_queue<ll> R;
	ll s = 0;
	for (int i = 0; i < N; i++) {
		s += a[i];
		L.push(a[i]);
	}
	sumL[N - 1] = s;
	for (int i = N; i < 3 * N; i++) {
		s += a[i];
		L.push(a[i]);
		s -= L.top();
		L.pop();
		sumL[i] = s;
	}
	s = 0;
	for (int i = 3 * N - 1; i >= 2 * N; i--) {
		s += a[i];
		R.push(a[i]);
	}
	sumR[2 * N] = s;
	for (int i = 2 * N - 1; i >= 0; i--) {
		s += a[i];
		R.push(a[i]);
		s -= R.top();
		R.pop();
		sumR[i] = s;
	}
	ll ans = -INF;
	for (int i = N; i <= 2 * N; i++) {
		ans = max(ans, sumL[i - 1] - sumR[i]);
	}
	cout << ans << endl;
 }

Measured memory_bytes: 8436
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
# 頻度 counter
S = [_S() for _ in range(N)]
c = collections.Counter(S)

judge = ['AC', 'WA', 'TLE', 'RE']
for j in judge:
    print(j + ' x ' + str(c[j]))

Measured memory_bytes: 34124
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
const int mod = 1e9 + 7;
int main(void) {
    string s;
    cin >> s;

    s += 'x';

    vi ans(s.size() + 1);

    vi rang(s.size(), 0);

    int rcnt = 0, lcnt = 0;
    rep (i, s.size() - 1) {

        if (s[i] == 'R') {
            rcnt++;
            if (s[i + 1] == 'R') {
                continue;
            }
            else {
                rang[i] = rcnt;
                rcnt = 0;
            }
        }
        if (s[i] == 'L') {
            lcnt++;
            if (s[i + 1] == 'L') {
                continue;
            }
            else {
                rang[i - (lcnt - 1)] = lcnt;
                lcnt = 0;
            }
        }

    }
    //rep (i, s.size()) cout << rang[i] << endl;

    rep (i, s.size()) {
        if (rang[i]) {
            if (rang[i] % 2 == rang[i + 1] % 2) {
                rang[i] = rang[i + 1] = (rang[i] + rang[i + 1]) / 2;
            }
            else {
                int tmp = rang[i] + rang[i + 1];
                if (rang[i] % 2 == 1) {
                    
                    rang[i] = (tmp + 1) / 2;
                    rang[i + 1] = tmp / 2;
                }
                else {
                    rang[i] = tmp / 2;
                    rang[i + 1] = (tmp + 1) / 2;
                }
            }
            i++;
        }
    }
    rep (i, s.size() - 1) cout << rang[i] << endl;
    return 0;
}


Measured memory_bytes: 1408
using System;
namespace ABC
{
    public class A
    {
        static void Main()
        {
            string Q = Console.ReadLine();
            char q = Q[0];
            if (char.IsLower(q))
            {
                Console.WriteLine("a");
            } else
            {
                Console.WriteLine("A");
            }
        }
    }
}


Measured memory_bytes: 25872
#include <iostream>

using namespace std;

int main() {
   int n;
   cin >> n;
   int a[n];
   for(int i = 0; i < n; i++) {
       cin >> a[i];
   }
   int cost[n];
   cost[0] = 0;
   cost[1] = abs(a[1] - a[0]);
   for(int i = 2; i < n; i++) {
       cost[i] = min(cost[i - 2] + abs(a[i] - a[i - 2]), cost[i - 1] + abs(a[i] - a[i - 1]));
   }
   cout << cost[n - 1] << endl;
   
   return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    string str_a,str_b;
    for (int i=0; i<b; i++){
        str_a += to_string(a);
    }
    for(int i=0; i<a; i++){
        str_b += to_string(b);
    }
    if(str_a>=str_b) cout << str_b;
    else cout << str_a;
    return 0;
}

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

int main(){
    int a;
    cin >>a;
  int ans = a+a*a+a*a*a;
  
  cout <<ans<<endl;
}


Measured memory_bytes: 3544
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUF_SIZE 15
#define QUERY_MAX 200000

int arr[QUERY_MAX];
int pos = 0;
int is_empty(void) {
  return !pos;
}

void push_back(int num) {
  arr[pos++] = num;
}

void pop_back(void) {
  pos--;
}

int get(int idx) {
  return arr[idx];
}

int main(void) {
  FILE *fp = stdin;
  int queries;
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  sscanf(line, "%d", &queries);

  int i, j;
  for(i = 0; i < queries; i++) {
    if(!fgets(line, BUF_SIZE, fp)) return 0;
    int command, num;
    sscanf(line, "%d %d", &command, &num);
    switch(command) {
      case 0: // pushback
        push_back(num);
        break;
      case 1: // random access
        if(is_empty()) break;
        int res = get(num);
        printf("%d\n", res);
        break;
      case 2: // pop back
        pop_back();
        break;
      default:
        printf("err\n");
        return 0;
    }
  }
  return 0;
}


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

#define int long long

#define rep(i,s,n) for(int i = (s);i<(n);i++)
#define repe(i,s,n) for(int i = (s);i<=(n);i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

int n;
int a[100010],b[100010];

signed main(){
    cin>>n;
    rep(i,0,n){
        cin>>a[i]>>b[i];
    }
    int cnt=0;
    rrep(i,0,n){
        a[i]+=cnt;
        if(a[i]%b[i]==0)continue;
        cnt+=b[i]-(a[i]%b[i]);
    }
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<string> ss(n);
    for(int i = 0; i < n;i++){
        cin >> ss[i];
    }
    
    string ans;
    for(char c ='a';c<='z';c++){
        int num = 100;
        for(int i = 0; i < n;i++){
            int cnt = 0;
            for(auto j : ss[i]){
                if(j == c)cnt++;
            }
            
            num = min(num,cnt);
            
        }
        ans += string(num,c);
    }
    cout << ans << '\n';
    return 0;
    
    
    
    
    
}

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

int main() {
    long long N,A,B;
    cin >> N >> A >> B;
    long long kami = 0;
    if(N%(A+B) >= A) kami = A;
    else kami = N%(A+B);
    cout << N/(A+B)*A+kami <<endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()
	cnt1 := 0

	for _, v := range s {
		if v == '1' {
			cnt1++
		}
	}
	fmt.Println(2 * min(cnt1, len(s)-cnt1))

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

#define int long long
typedef pair<int, int> P;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, l;
  while ( cin >> n >> l, n ) {
    vector<int> datl(l+3, 0);
    vector<int> datr(l+3, 0);
    for ( int i = 1; i <= n; i++ ) {
      char d;
      int p;
      cin >> d >> p;
      if ( d == 'R' ) datr[p] = i;      
      else datl[p] = i;      
    }

    bool flag = true;
    int last_ant = -1;
    int cnt = 0;    
    while ( flag ) {
      cnt++;      
      flag = false;
      int ant = 100000;      
      vector<int> nxtl(l+3, 0);
      vector<int> nxtr(l+3, 0);      
      for ( int i = 1; i < l; i++ ) {
	if ( datr[i] && datl[i+2] ) {
	  flag = true;
	  nxtr[i+1] = datl[i+2];
	  nxtl[i+1] = datr[i];
	  datr[i] = datl[i+2] = 0;	  
	}
	if ( datr[i] ) {
	  flag = true;
	  nxtr[i+1] = datr[i];
	  datr[i] = 0;	  
	}
	if ( datl[i] ) {
	  flag = true;	  	  
	  nxtl[i-1] = datl[i];
	  datl[i] = 0;	  
	}
      }
      
      if ( nxtl[0] ) last_ant = nxtl[0];
      else if ( nxtr[l] ) last_ant = nxtr[l];      
      datl = nxtl;
      datr = nxtr;      
    }

    cout << cnt-1 << " " << last_ant << endl;
  }
  
  return 0;
}



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

int main() {
    string s;
    cin >> s;
    ll ans, n, w;
    ans = 0; w = 0; n = s.size();
    for (ll i = 0; i < n; i++) {
        if (s.at(i) == 'W') {
            ans += i - w;
            w++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3716
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ",i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

class UnionFind {
public:
	vector<int> par;
	UnionFind(int n) {
		par = vector<int>(n, -1);
	}
	int root(int a) {
		if (par[a] < 0) {
			return a;
		}
		else {
			return par[a] = root(par[a]);
		}
	}
	int size(int a) {
		return -par[root(a)];
	}
	bool connect(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) {
			return false;
		}
		if (size(a) < size(b)) {
			swap(a, b);
		}
		par[a] += par[b];
		par[b] = a;
		return true;
	}
};

struct edge { int u,v,cost;  };
bool comp(edge& e1, edge& e2) {
	return e1.cost < e2.cost;
}
#define MAX_E 200010
edge es[MAX_E];
int V, E;
int kruskal(){
	sort(es, es + E, comp);
	UnionFind uni(V);
	int res = 0;
	rep(i, 0, E) {
		edge e = es[i];
		if (uni.root(e.u) != uni.root(e.v)) {
			uni.connect(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

int main() {
	cin >> V; E = 0;
	vector<P> x, y;
	rep(i, 0, V) {
		int p1, p2; cin >> p1 >> p2;
		x.push_back({ p1,i });
		y.push_back({ p2,i });
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	rep(i, 0, V - 1) {
		E++;
		es[i] = { x[i].second,x[i + 1].second,x[i + 1].first - x[i].first };
	}
	rep(i, 0, V - 1) {
		E++;
		es[i+V-1]={ y[i].second,y[i + 1].second,y[i + 1].first - y[i].first };
	}
	printf("%d", kruskal());
	return 0;
}


Measured memory_bytes: 4588
#include <iostream>

using namespace std;

int main()
{
	int N;
	
	cin >> N;
	
	if (N / 10 == 9 || N % 10 == 9){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	
	return 0;
}


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

    g = []
    for _ in range(n):
        g.append(input())

    return g

def yesOrNo(g):
    c = 0
    
    for i in range(len(g)):
        for j in range(i+1, len(g), 1):
            if g[i] == g[j]:
                c += 1
                break
    
    for i in range(1, len(g), 1):
        if(g[i][0] != g[i-1][len(g[i-1])-1]):
            c += 1
            break

    return c
    

g = get()
r = yesOrNo(g)

if r != 0:
    print("No")

else:
    print("Yes")
    


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <iomanip>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <functional>

#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <cstdlib>


using namespace std;

#define tr(x) cout << x << endl;
#define tr2(x, y) cout << x << " " << y << endl;
#define tr3(x, y, z) cout << x << " " << y << " " << z << endl;
#define tr4(w, x, y, z) cout << w << " " << x << " " << y << " " << z << endl;
#define tr6(a, b, w, x, y, z) cout << a << " " << b << " " << w << " " << x << " " << y << " " << z << endl;

#define ll long long
#define fastIO  ios::sync_with_stdio(false); cin.tie(0);
inline int in() { int x; scanf("%d", &x); return x; }
inline ll inL() { ll x; scanf("%lld", &x); return x; }



int main(){
#ifdef __APPLE__
    const clock_t begin_time = clock();
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    ll n = inL(), x = inL();
    
    cout << 3 * ( n - __gcd(n, x)) << endl;
    
#ifdef __APPLE__
    cout << endl;
    cout << "Time : ";
    cout << float( clock () - begin_time ) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <numeric>
#include <utility>
#include <set>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define IPSILON 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
  int a;
  string s;
  cin >> a;
  cin >> s;
  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
  return 0;
}


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

int main(){
    ll MOD=1e9+7;
    int n,m;
    cin>>n>>m;
    vector<int> kowa(n+1,0);
    for(int i=0; i<m; i++){
        int a;
        cin>>a;
        kowa[a]=1;
    }
    vector<ll> dp(n+1,0);
    dp[0]=1;
    if(kowa[1])dp[1]=0;
    else dp[1]=1;
    for(int i=2; i<=n; i++){
        if(!kowa[i])dp[i]=(dp[i-1]+dp[i-2])%MOD;
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 1408
#abc128d
n,k=map(int,raw_input().split())
v=map(int,raw_input().split())
res=[]
for i in range(n+1):
 for j in range(min(n-i,k-i)+1):
  p=v[:i]+v[n-j:]
  p.sort()
  for x in range(k-i-j+1):
   res.append(sum(p[x:]))
print max(res)


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

int main() {
	string s;
	cin >> s;
	vector<string> w={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	for(int i=0; i<7; i++){
		if(w[i]==s){
			cout << 7-i <<endl; return 0;
		}
	}
	return 0;
}

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

#define ll long long

using namespace std;

void fill(vector<vector<char>>& g, int i, int j) {

	for (int x = 0; x < g[i].size(); x++) {
		g[i][x] = 'R';
	}

	for (int y = 0; y < g.size(); y++) {
		g[y][j] = 'R';
	}

}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int H, W, K;

	cin >> H >> W >> K;

	vector<vector<char>>g(H);

	for (int i = 0; i < H; i++) {
		g[i] = vector<char>(W);

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

	int ans = 0;

	for (int maskR = 0; maskR < (1 << H); maskR++) {

		for (int maskC = 0; maskC < (1 << W); maskC++) {

			int black = 0;

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if ((((maskR >> i) & 1) == 0) && (((maskC >> j) & 1) == 0)
						&& (g[i][j] == '#')) {
						black++;
					}
				}
			}

			if (black == K) {
				ans++;
			}
		}
	}

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

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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;

int main(){
        long long n;cin >> n;
        long long a,b,c;
        for(long long i = 0;i<=3500;i++){
                for(long long  j = 0;j<=3500;j++){
                        long long tmp1 = n*i*j;
                        long long tmp2 = 4*i*j-n*(i+j);
                        if(tmp2>0 && (tmp1 % tmp2) == 0){
                                a = i;b = j;c = tmp1/tmp2;
                        }
                }
        }
        cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> table(n+1, 0);

  rep(j, k) {
    rep(i, n+1) table[i] = 0;

    rep(i, n) {
      table[max(0ll, i-a[i])]++;
      table[min(n, i+a[i]+1)]--;
    }

    rep(i, n) {
      if (0 < i) table[i] += table[i-1];
    }

    rep(i, n) a[i] = table[i];

    bool flag = true;
    rep(i, n) {
      if (a[i] != n) {
        flag = false;
        break;
      }
    }
    if (flag) break;
  }

  rep(i, n) cout << a[i] << " ";
  cout << endl;

  return 0;
}


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

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

Measured memory_bytes: 3628
import math
n = int(input())
A = [int(i) for i in input().split()]
cnt, ans = 0, 0
for i in range(n-1):
  if A[i] == A[i+1]:
    cnt += 1
    if i == n-2:
      ans += math.floor((cnt+1)/2)
  else:
    ans += math.floor((cnt+1)/2)
    cnt = 0
print(ans)

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        V[] a = new V[m];
        for (int i = 0; i < m; i++) {
            int p = sc.nextInt();
            int y = sc.nextInt();
            a[i] = new V(p, y, i);
        }

        Arrays.sort(a);

        int[] num = new int[n];
        String[] ans = new String[m];
        for (int i = 0; i < m; i++) {
            int p = a[i].p;
            num[p-1]++;

            String id = String.format("%06d%06d", p, num[p-1]);
            ans[a[i].i] = id;
        }
        
        for (String s : ans)
            System.out.println(s);
    }

    static class V implements Comparable<V> {
        int p, y, i;

        V(int p, int y, int i) {
            this.p = p;
            this.y = y;
            this.i = i;
        }

        public int compareTo(V o) {
            return y - o.y;
        }
    }
}


Measured memory_bytes: 152008
k = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())

print(k[n -1])

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

int main(){
  int n,k;
  while(cin >> n >> k, n){
    vector<string> a(n);
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    sort(a.begin(), a.end());

    set<string> ans;
    for(int bit=1;bit<(1<<n);bit++){
      if(__builtin_popcount(bit) == k){
        vector<string> use;
        for(int i=0;i<n;i++){
          if( (bit>>i)&1 ) use.push_back(a[i]);
        }
        do{
          string con;
          for(int i=0;i<k;i++) con += use[i];
          ans.insert(con);
        }while( next_permutation(use.begin(), use.end()) );
      }
    }
    cout << ans.size() << endl;
  }
}

Measured memory_bytes: 1464
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(){
	int a, b,eq=0;
	scanf("%d %d", &a, &b);
	eq= (a+b)/2;
	if((a+b)%2==0)
		printf("%d", eq);
	else
		printf("IMPOSSIBLE");
	printf("\n");
    return 0;
}

Measured memory_bytes: 128
from math import gcd

def resolve():
    k = int(input())
    l = [None] * k ** 2
    for i in range(k):
        for j in range(k):
            l[i * k + j] = gcd(i + 1, j + 1)
    ans = 0
    for i in l:
        for j in range(k):
            ans += gcd(i, j + 1)
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
std::map<long long, long long> primeFactorization(
    long long n) { /* prime factorization * nを素因数分解する */
  std::map<long long, long long> pf;
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      ++pf[i];
    }
  }
  if (n > 1) {
    ++pf[n];
  }
  return pf;
}

int main() {
  ULL S;
  cin >> S;
  ULL lim = 1e9;
  ULL x2 = (lim-S%lim)%lim;
  ULL x1 = (S+lim-1)/lim;
  printf("%lld %lld %lld %lld %lld %lld\n", 0LL, 0LL, x1, 1LL, x2, (LL)1e9);
  cerr<<x1*lim-x2<<endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int ans1 = 0;
  int ans2 = 0;
  
  for (int i = 0; i < (N + 1) / 2; i++) {
    ans1 += vec.at(2 * i);
  }
  
  for (int i = 0; i < N / 2; i++) {
    ans2 += vec.at(2 * i + 1);
  }
  
  cout << ans1 - ans2 <<endl;
}

Measured memory_bytes: 256
import Data.Char
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

readInt :: BS.ByteString -> Int
readInt s = case BS.readInt s of
              Just (x, _) -> x

main = do
  n <- readInt <$> BS.getLine
  xs <- U.unfoldrN n (fmap (fmap (BS.dropWhile isSpace)) . BS.readInt) <$> BS.getLine
  let ls = U.scanl gcd 0 xs
      rs = U.scanr gcd 0 xs
  print $ U.maximum $ U.zipWith gcd ls (U.tail rs)


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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;

  int cnt_b = 0, cnt_w = 0, i = 0;
  while (i < s.size()) {
    int cur = i;
    while (cur < s.size() && s[i] == s[cur]) {
      cur++;
    }

    if (s[i] == 'B') {
      cnt_b++;
    } else {
      cnt_w++;
    }

    i = cur;
  }

  cout << cnt_b + cnt_w - 1 << '\n';
  return 0;
}

Measured memory_bytes: 3728
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
using ll = long long;
#define max(a,b) ((a)>(b) ? (a):(b))
#define min(a,b) ((a)<=(b) ? (a):(b))
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

int main(){
  ll N,K;
  cin >> N >> K;
  vector<int> H(N);
  rep(i,N) cin >> H[i];
  sort(H.begin(),H.end());
  ll ans = 0;
  ll i;
  rep(i,N-K) ans += H[i];
  cout << ans;  
  return 0;
}


Measured memory_bytes: 1024
import sys
n = int(input())
l = list(map(int, input().split()))
dp = [sys.maxsize] *n
dp[0] = 0
for i in range(n):
    for j in range(i+1,i+3):
        if(j<n):
            dp[j]=min(dp[j],dp[i]+abs(l[i]-l[j]))
print(dp[n-1])

Measured memory_bytes: 52208
use std::io;


fn main() {
    let (a, b) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    println!("{}", (a + b) % 24);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include <cmath>
#include<tuple>
typedef long long int ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const ll INF = 10000000000000;

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

int N;

int main() {
	cin >> N;
	vector<int> h(N);
	vector<int> dp(N);
	rep(i, 0, N) {
		cin >> h[i];
		dp[i] = INF;
	}
	dp[0] = 0;
	rep(i, 1, N) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1)chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
		//cout << dp[i] << endl;
	}

	cout << dp[N - 1] << endl;
	return 0;
}

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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)     for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N);
    vi H(N);VCIN(H);
    flag=true;
    RRepS(i,N-2,0){
        if(H[i]-H[i+1]>1)flag=false;
        if(H[i]-H[i+1]==1)H[i]--;
    }
    Yes(flag);

    return 0;
}


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

# 3辺の長さとその最大値
a = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
b = ((x2 - x3) ** 2 + (y2 - y3) ** 2) ** 0.5
c = ((x3 - x1) ** 2 + (y3 - y1) ** 2) ** 0.5
L = max(a, b, c)

# ヘロンの公式
s = (a + b + c) / 2
S = (s * (s - a) * (s - b) * (s - c)) ** 0.5

# 内接円の半径
r = (2 * S) / (a + b + c)

ans = (L * r) / (2 * r + L)
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

#define ll long long
#define pint pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(VECTOR) (VECTOR).begin(),(VECTOR).end()

int main(){

	int N, A, B, C, l;
	cin >> N >> A >> B >> C;
	vector<int> L;
	for(int i = 0; i < N; i ++){
		cin >> l;
		L.pb(l);
	}
	unsigned int abit = 1, bbit, cbit;
	int minMP = 1000000000;
	while(abit < pow(2, N)){
		bbit = 1;
		while(bbit < pow(2, N)){
			cbit = 1;
			while(cbit < pow(2, N)){
				if((abit & bbit) == 0 && (bbit & cbit) == 0 && (cbit & abit) == 0){
					//cout << abit << SPACE << bbit << SPACE << cbit << endl;
					//return 0;
					int alen = 0, blen = 0, clen = 0, anum = 0, bnum = 0, cnum = 0;
					for(int i = 0; i < N; i ++){
						if(abit & (1<<i)){
							alen += L[i];
							anum ++;
						}
						if(bbit & (1<<i)){
							blen += L[i];
							bnum ++;
						}
						if(cbit & (1<<i)){
							clen += L[i];
							cnum ++;
						}
					}
					minMP = min(minMP, (anum + bnum + cnum - 3) * 10 + abs(alen - A) + abs(blen - B) + abs(clen - C));
					/*if(minMP > (anum + bnum + cnum - 3) * 10 + abs(alen - A) + abs(blen - B) + abs(clen - C)){
						minMP = (anum + bnum + cnum - 3) * 10 + abs(alen - A) + abs(blen - B) + abs(clen - C);
						//cout << "abit, bbit, cbit, anum, bnum, cnum, alen, blen, clen, minMP = " << abit << SPACE << bbit << SPACE << cbit << SPACE << anum << SPACE << bnum << SPACE << cnum << SPACE << alen << SPACE << blen << SPACE << clen << SPACE << minMP << endl;
					}*/
				}
				cbit ++;
			}
			bbit ++;
		}
		abit ++;
	}
	cout << minMP << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int f = min(n, k);
    n -= min(n, k);
    cout << f * x + n * y << endl;
}


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

int main() {
  int k, x;
  cin >> k >> x;

  if (500 * k >= x)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
  
#define M 1000000
#define NIL -1
#define L 14
  
char H[M][L]; /* Hash Table */
  
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}
  
/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
  
int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }
  
int find(char str[]){
  long long key,i,h;
  
  key=getKey(str);
  
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0) return 0;
  
  }
  return 0;
}
  
int insert(char str[]){
  long long key,i,h;
  
  key=getKey(str);
  
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
    
  return 0;
}
  
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
      
    scanf("%d", &n);
      
    for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
      
    if ( com[0] == 'i' ){
        insert(str);
    } else {
        if (find(str)){
        printf("yes\n");
        } else {
        printf("no\n");
        }
    }
    }
  
    return 0;
}



Measured memory_bytes: 15420
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	var n string
	switch s {
	case "Sunny":
		n = "Cloudy"
	case "Cloudy":
		n = "Rainy"
	case "Rainy":
		n = "Sunny"
	}
	fmt.Println(n)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>

int main(void)
{
    long n, d;
    

    scanf("%ld%ld", &n, &d);

    long x[n];
    long y[n];
    double s[n];
    long i;
    long count = 0;

    for (i = 1; i <= n; i++) {
        scanf("%ld%ld", &x[i-1], &y[i-1]);
        s[i-1] = sqrt(pow(x[i-1], 2)+pow(y[i-1], 2));
        if ((double)d >= s[i-1]) {
            count++;
        }
    }
    printf("%ld\n", count);

    return 0;
}

Measured memory_bytes: 6792
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def check(x):
  c = 0
  for y in a:
    ok = N
    ng = -1
    while ok - ng > 1:
      m = (ok + ng) // 2
      if a[m] + y >= x: ok = m
      else: ng = m
    c += N - ok
  return c >= M

ok = 0
ng = 10 ** 6
while ng - ok > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m

l = ok + 1
cs = [0] * (N + 1)
for i in range(N): cs[i + 1] = cs[i] + a[i]

res = 0
c = 0
for x in a:
  ok = N
  ng = -1
  while ok - ng > 1:
    m = (ok + ng) // 2
    if a[m] + x >= l: ok = m
    else: ng = m
  c += N - ok
  res += cs[-1] - cs[ok] + x * (N - ok)

print(res + (l - 1) * (M - c))

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t n,m;
  cin >> n >> m;
  vector<vector<int>> rooms(n);
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    a--;b--;
    rooms[a].push_back(b);
    rooms[b].push_back(a);
  }
 
  vector<int> dist(n, -1);
  vector<int> mark(n, -1);

  dist[0] = 0;
  mark[0] = 0;
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int id = q.front();
    q.pop();
    for(auto v:rooms[id]){
      if(dist[v]>=0) continue;
      dist[v] = dist[id]+1;
      mark[v] = id;
      q.push(v);
    }
  }
  cout << "Yes" << endl;
  for(int i=1;i<n;i++){
    cout << mark[i]+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 10760
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	string S;
	cin >> S;

	int32_t N = S.size();
	int64_t res = 0;
	for (int32_t i = 0; i < (1 << (N - 1)); i++) {
		int64_t sum = 0, value = 0;
		for (int32_t j = 0; j < N; j++) {
			value = value * 10 + (S[j] - '0');
			if (j < N - 1 && ((i & (1 << j)) != 0)) {
				sum += value;
				value = 0;
			}
		}
		sum += value;
		res += sum;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();
		int k = s.nextInt();
		int sum = 0;
		if (k > a) {
			k = k - a;
			sum += a;
			if (k > b) {
				k = k - b;
				if (k > 0) {
					sum -= k;
				}
			}
		} else {
			sum = k;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 35732
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  double a, b, ans;
  double t = 3.305785;

  cin >> a >> b;
  ans = a*b / t;
  printf("%.6lf\n", ans);
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,C;
    cin>>N>>C;
    N+=1;
    int cake[C];
    int cakes=0;
    for(int i;i<C;i++){
        cin>>cake[i];
        cakes+=cake[i];
    } 
    int ans =0;
    ans=cakes/N;
    if(cakes%N>=1){
        ans++;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int A;
    string B;
    cin >> A >> B;
    cout << A*(B[0]-'0')+((B[2]-'0')*10+(B[3]-'0'))*A/100 << endl;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    string s;
    cin >> s;
    int n = (int)s.size();
    s = ' ' + s;

    if (s.at(1) == '0' || s.at(n) == '1') {
        cout << -1 << '\n';
        return;
    }
    for (int i=1; i<n; ++i) {
        if (s.at(i) != s.at(n-i)) {
            cout << -1 << '\n';
            return;
        }
    }

    int par = n;
    for (int i=n-1; i>0; --i) {
        cout << i << ' ' << par << '\n';
        if (s.at(i) == '1') par = i;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

int main() {
   int K,A,B;
   cin >> K >> A >> B;
   for (int i=A; i<=B; i++) {
       if (i%K==0) {
       cout << "OK" << endl;break;
       }
       if (i==B) cout << "NG" << endl;
   }
}

Measured memory_bytes: 3632