akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define f first
#define s second
#define pb push_back
pair<int, int> t[400010];
int arr[100005];
void build(int a[], int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = {a[tl], tl};
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        if(t[2*v].f>t[2*v+1].f){
        	t[v]=t[2*v+1];
        }
        else{
        	t[v]=t[2*v];
        }
    }
}

pair<int, int> mini(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return {2, 0};
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    auto u1=mini(v*2, tl, tm, l, min(r, tm));
    auto u2=mini(v*2+1, tm+1, tr, max(l, tm+1), r);
    if(u1.f>u2.f){
    	return u2;
    }
    else{
    	return u1;
    }
}


main() {
	int n, m;
	cin>>n>>m;
	string s;
	cin>>s;
	int arr[n+1];
	for(int i=0; i<=n; i++){
		arr[i]=(s[i]-'0');
	}
	build(arr, 1, 0, n);
	int pos=n;
	vector<int>ans;
	ans.pb(n);
	while(1){
		int fir=max(0LL, pos-m);
		int sec=max(0LL, pos-1);
		auto u=mini(1, 0, n, fir, sec);
		if(u.f==1){
			cout<<-1;
			return 0;
		}
		int node=u.s;
		ans.pb(node);
		pos=node;
		if(node==0){
			break;
		}
	}
	reverse(ans.begin(), ans.end());
	for(int i=0; i<ans.size()-1; i++){
		cout<<ans[i+1]-ans[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 9176
def main():
    N = int(input())
    S = input()
    
    ans = S.count('R') * S.count('G') * S.count('B')

    for i in range(N-2):
        for j in range(i+1, i+1+(N-1-i)//2):
            k = j + (j - i)
            if len(set([S[i], S[j], S[k]])) == 3:
                ans -= 1
            
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 68096
// -*- coding:utf-8-unix -*-

use proconio::input;
use std::str::FromStr;

#[derive(Debug)]
enum Contest {
    ABC,
    ARC,
}

impl Contest {
    fn next(&self) -> Contest {
        match self {
            Contest::ABC => Contest::ARC,
            Contest::ARC => Contest::ABC,
        }
    }
}

impl FromStr for Contest {
    type Err = ();
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "ABC" => Ok(Contest::ABC),
            "ARC" => Ok(Contest::ARC),
            _ => Err(())
        }
    }
}

fn main() {
    input! {
        mut s: String,
    }
    let s = Contest::from_str(&s).unwrap();
    println!("{:?}", s.next());
}


Measured memory_bytes: 2176
n = gets.chomp.to_i
inputs = []
ans = ""

n.times do
    inputs << gets.chomp.split("").sort
end

("a".."z").each do |alphabet|
    res = 1 << 40
    inputs.each do |s|
        tmp = s.count(alphabet)
        res = tmp > res ? res : tmp
    end
    ans += alphabet * res
end

puts ans

Measured memory_bytes: 1916
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        WeightedUnionFind wuf = new WeightedUnionFind(n);
        for(int i = 0; i < m; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            long w = sc.nextLong();
            if(!wuf.union(l,r,w)){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

class WeightedUnionFind{
    int[] parent;
    int[] rank;
    long[] weight;

    public WeightedUnionFind(int size) {
		this.parent = new int[size];
		this.rank = new int[size];
        this.weight = new long[size];
		
		for (int i = 0; i < size; i++) {
			makeSet(i);
		}
	}
	
	public void makeSet(int i) {
		parent[i] = i;
		rank[i] = 0;
	}

    public boolean union(int x, int y, long w) {
        w += getWeight(x);
        w -= getWeight(y);
        x = find(x);
        y = find(y);
        if (x == y) {
            return getDistance(x, y) == w;
        } else if (rank[x] < rank[y]) {
            parent[x] = y;
            weight[x] = -w;
        } else if (rank[x] == rank[y]) {
            rank[x]++;
            parent[y] = x;
            weight[y] = w;
        } else {
            parent[y] = x;
            weight[y] = w;
        }
        return true;
	}
	
	public int find(int i) {
        int p = parent[i];
        if(p == i){
            return i;
        }else{
            int root = find(p);
            weight[i] += weight[p];
            return parent[i] = root;
        }
	}

    public long getWeight(int i){
        find(i);
        return weight[i];
    }

    public long getDistance(int x, int y) {
        return getWeight(y) - getWeight(x);
    }
	
	public boolean same(int x, int y) {
		return find(x) == find(y);
	}
}


Measured memory_bytes: 151676
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	int m;
	cin >> m;

	for (int i = 0; i < m; i++)
	{
		int c, b, e;
		cin >> c >> b >> e;

		if (c == 0)
		{
			println(*min_element(a.begin() + b, a.begin() + e));
		}
		else
		{
			println(*max_element(a.begin() + b, a.begin() + e));
		}
	}
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mx 10000000000008
#define mod 1000000007
ll n,m,i,j,k,l,t,arr[sz],brr[sz],crr[sz];
vector<ll>v;
char c[sz],d[sz];
int main()
{
     t=1;
  //  scanf("%lld",&t);
    while(t--)
    {
    scanf("%s %s",&c,&d);
    n=strlen(c);
    m=strlen(d);
    k=m;
    for(i=0;i<=n-m;i++)
    {
        l=0;
        for(j=0;j<m;j++)
        {
            if(c[i+j]!=d[j])
                l++;
        }
        k=min(k,l);
    }
    printf("%lld\n",k);
    }
    return 0;
}


Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, q;
const int maxn = 1e5 + 10;
int a[maxn], cnt[maxn];
ll ans;
int main()
{
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		cnt[a[i]]++;
		ans += a[i];
	}
	cin >> q;
	for(int i = 1; i <= q; ++i)
	{
		int b, c;
		cin >> b >> c;
		ans += (c - b) * cnt[b];
		cnt[c] += cnt[b];
		cnt[b] = 0;
		printf("%lld\n", ans);
	}
	return 0;
}
	 

Measured memory_bytes: 4528
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i){ return accumulate(f, l, i); }


int N, K;
string S;


signed main(){
    cin >> N >> K;
    cin >> S;

    string s;
    rep(i, 0, N){
        s.pb(S[i]);
        while(i != N-1 && S[i] == S[i+1]) i++;
    }

    int ans = 0;
    rep(i, 1, N)
        if(S[i-1] == S[i]) ans++;

    ans += min(K, (SZ(s)-1)/2)*2;
    if(SZ(s)%2 == 0 && (SZ(s)-1)/2 < K) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
/* attention to overflow */
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <queue>
#include <sstream>
#include <set>
#include <map>
#define dump(x) cerr<< #x << " = " << x <<endl

using namespace std;
const int INF=1<<25;
void io(){ cin.tie(0);ios::sync_with_stdio(false);}
/*printf("%.9Lf\n",cf);*/
const int MOD=1000000007;

#define P pair<int,int>
const int V=1010;

struct edge{int to,cost;};
vector <edge> G[V];

int d[V];

void dijkstra(int src){
	priority_queue <P,vector <P>,greater <P> > q;
	for(int i=0;i<V;i++){
		d[i]=INF;
	}
	d[src]=0;
	q.push(P(0,src));

	while(!q.empty()){
		P s=q.top();
		q.pop();
		int v=s.second;
		if(s.first>d[v]) continue;
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				q.push(P(d[e.to],e.to));
			}
		}
	}
}

int dp[1<<14][14];

int main(){
	io();
	int n,m,k,p;
	cin>>n>>m>>k>>p;
	p--;
	for(int i=0;i<m;i++){
		int x,y,w;
		cin>>x>>y>>w;
		x--;y--;
		G[x].push_back((edge){y,w});
		G[y].push_back((edge){x,w});
	}
	int a[15];
	int dist[20][20];

	for(int i=0;i<k;i++){
		int s,t;
		cin>>s>>t;
		s--,t--;
		a[2*i]=s;
		a[2*i+1]=t;
	}
	for(int i=0;i<2*k;i++){
		for(int j=i;j<2*k;j++){
			if(i==j){
				dist[i][j]=0;
			}else{
				dijkstra(a[i]);
				dist[i][j]=d[a[j]];
				dist[j][i]=dist[i][j];
			}
		}
	}

	for(int i=0;i<(1<<14);i++){
		fill_n(dp[i],14,INF);
	}
	dijkstra(p);
	for(int i=0;i<k;i++){
		dp[1<<2*i][2*i]=d[a[2*i]];
	}
	for(int i=2;i<=2*k;i++){
		for(int j=0;j<(1<<2*k);j++){
			for(int u=0;u<2*k;u++){
				if((j&(1<<u))==0) continue;
				for(int v=0;v<k;v++){
					int s=2*v;
					int t=s+1;
					if((j&(1<<s))==0){
						dp[j|(1<<s)][s]=min(dp[j|(1<<s)][s],dp[j][u]+dist[u][s]);
					}else if((j&(1<<t))==0){
						dp[j|(1<<t)][t]=min(dp[j|(1<<t)][t],dp[j][u]+dist[u][t]);
					}
				}
			}
		}
	}

	int ret=INF;
	for(int i=0;i<2*k;i++){
		ret=min(ret,dp[(1<<(2*k))-1][i]);
	}
	if(ret==INF){
		cout<<"Cannot deliver"<<endl;
	}else{
		cout<<ret<<endl;
	}


	return 0;
}

Measured memory_bytes: 2232
def make_divisor_list(num): # 約数を求める
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        i = 1
        while i*i <= num:
            if num%i == 0:
                divisor_list.append(i)
                divisor_list.append(num//i)

            i += 1
        divisor_list.append(num)

        return sorted(set(divisor_list))

def factorial(n): # 階乗を求める
    if n == 0 or n == 1:
        return 1
    else:
        ans = n*factorial(n-1)

        return ans
def usage(n):

    fct = factorize(n)
    return fct

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

N = int(input())

NN = factorial(N)
usa = usage(NN)

ans = 0
div_75 = [3, 5, 15, 25, 75]


nums = [0 for _ in range(75+1)]

for i in usa:
    for divs in div_75:
        if i[1] >= divs-1:
            nums[divs] = nums[divs] + 1

ans = 0

if nums[5] >= 2:
    num_tmp = nums[5]
    tmp = factorial(num_tmp)//(2*factorial(num_tmp-2))
    ans += (nums[3] - 2) * tmp

if nums[15] >= 1:
    num_tmp = nums[15]
    tmp = num_tmp
    ans += (nums[5] - 1) * tmp

if nums[25] >= 1:
    tmp = nums[25]
    ans += (nums[3] - 1) * tmp

if nums[75] >= 1:
    ans += nums[75]


print(ans)


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

#define rep(i, x, n) for(int i=(x);i<(n);i++)
#define reps(i, x, n) for(int i=(x);i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;
//八方向を見るのに使うと便利(楽)
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

//最大公約数
lol gcd(lol x, lol y){ return (y != 0 ? gcd(y, x % y) : x); }
//最小公倍数
lol lcm(lol x, lol y){ return ((x * y) / gcd(max(x, y), min(x, y))); }

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int x;
  cin >> x;
  cout << 1 - x << '\n';
  return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
      Double A = in.nextDouble();  
      Double B = in.nextDouble();  
      Double H = in.nextDouble();  
      double M = in.nextDouble();  
      double x = Math.abs(30*H+M/2-6*M);
      double X = Math.cos(Math.toRadians(x));
      double C = Math.sqrt(A*A+B*B-2*A*B*X);
      System.out.println(C);
        }
    }


Measured memory_bytes: 37484
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long LL;
typedef long double LD;

int main(int argc, char* argv[]) {
	int n, k, x;
	cin >> n >> k;
	vector<LD> a(n), sum(n + 1, 0);
	for (int i = 0; i < n; ++i) {
		cin >> x;
		a[i] = logl(x * 10.0);
		sum[i + 1] = sum[i] + a[i];
	}
	for (int i = k + 1; i <= n; ++i) {
		LD a = sum[i - 1] - sum[i - 1 - k];
		LD b = sum[i] - sum[i - k];
		string ans = b > (a + 1e-10) ? "Yes" : "No";
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 9672
r,c = [int(i) for i in input().split()]
mat = [0 for i in range(r+1)]
for i in range(r):
    mat[i] = [int(i) for i in input().split()]
for i in range(r):
    mat[i].append(sum(mat[i]))
for j in range(c):
    mat[r] = [sum([mat[i][j] for i in range(r)]) for j in range(c+1)]
for i in range(r+1):
    print(*mat[i],sep=" ")


Measured memory_bytes: 6252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int n, k = 0;
vvi e;
map<P, int> color;

void dfs(int v, int pre = -1) {

	int no = color[P(v, pre)];
	int ec = 1;

	for (auto vv : e[v]) {
		if (vv == pre)continue;
		if (ec == no)ec++;
		color[P(v, vv)] = color[P(vv, v)] = ec;
		k = max(k, ec);
		dfs(vv, v);
		ec++;
	}
}

int main() {

	cin >> n;
	e.resize(n);
	V<P> ee(n - 1);
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--;b--;
		e[a].push_back(b);
		e[b].push_back(a);
		ee[i] = P(a, b);
	}

	dfs(0);

	cout << k << endl;
	for (auto p : ee)cout << color[p] << endl;
}

Measured memory_bytes: 20352
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    while (true) {
        int n ,x;
        cin >> n >> x;

        if (n == 0 && x == 0) break;

        int ans = 0;
        RREP(i, 1, n+1) {
            RREP(j, 1, n+1) {
                if (j == i) break;
                RREP(k, 1, n+1) {
                    if (k == i || k == j) break;
                    if (i + j + k == x) ans++;
                }
            }
        }

        cout << ans << endl;
        
    }
        


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


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

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

using namespace std;

string s;
int p;

bool check()
{
	bool ret = true;
	while (s[p] != '.' && s[p] != ')' && s[p] != ']')
	{
		char c = s[p++];
		if (c == '(' || c == '[')
		{
			char end = c == '(' ? ')' : ']';
			ret = check();
			if (s[p] == end) p++;
			else ret = false;
		}
		if (!ret) break;
	}
	return ret;
}

bool checkall()
{
	p = 0;
	bool ret = check();
	ret = ret && s[p] == '.';
	return ret;
}

int main()
{
	while(getline(cin, s), s[0] != '.')
	{
		cout << (checkall() ? "yes" : "no") << endl;
	}
}

Measured memory_bytes: 900
#include <stdio.h>

int main(void){
	int i;
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);

	for(i = 1; i <= b; i++){
		if(a*i%b == c){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");

	printf("\n");
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int main(){
	int n;
	ll x;
	cin >> n >> x;
	vector<ll> a(n);
	ll ans=0;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=1;i<n;i++){
		ll tmp;
		if(a[i]+a[i-1]>x){
			tmp=min(a[i]+a[i-1]-x,a[i]);
			a[i]-=tmp;
			ans+=tmp;
		}
		if(a[i-1]>x){
			tmp=a[i-1]-x;
			a[i-1]-=tmp;
			ans+=tmp;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;
int main(){
  int N,M,K;
  cin>>N>>M;
  int like[M]={};
  for(int i=0;i<N;i++){
    cin>>K;
    for(int j=0;j<K;j++){
      int A;
      cin>>A;
      like[A-1]++;
    }
  }
  int ans=0;
  for(int i=0;i<M;i++){
    if(like[i]==N)ans++;
  }
  cout<<ans<<endl;
}


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

int main(){
    int n;cin>>n;
    
    vv xyh(n, vi (3));
    rep(i,n)rep(j,3)cin>>xyh[i][j];
    
    for(int cx=0; cx<=100; cx++){
        for(int cy=0; cy<=100; cy++){
            int ch;
            rep(i,n){
                if(xyh[i][2]==0)continue;
                ch = xyh[i][2] + abs(xyh[i][0]-cx) + abs(xyh[i][1]-cy);
                break;
            }
            
            bool ok = true;
            rep(i,n){
                int h = max(0, ch - abs(xyh[i][0]-cx) - abs(xyh[i][1]-cy));
                if(xyh[i][2]==h)continue;
                ok = false;
                break;
            }
            if(ok){
                cout << cx <<" "<< cy <<" "<< ch << endl;
                return 0;
            }
        }
    }
}

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

int main(void){
  int p;
  double t;
  double t7,t8;
  t7=100000000;
  t8=100000000;
  int p7,p8;
  for(int i=0;i<3;i++){
    int p1,p2,p3,p4;
    double t1,t2,t3,t4;
    t1=100000000;
    t2=100000000;
    t3=100000000;
    t4=100000000;
    for(int j=0;j<8;j++){
      cin>>p>>t;
      if(t<t1){
        t4=t3;
        t3=t2;
        t2=t1;
        t1=t;
        p4=p3;
        p3=p2;
        p2=p1;
        p1=p;
      }
      else if(t<t2){
        t4=t3;
        t3=t2;
        t2=t;
        p4=p3;
        p3=p2;
        p2=p;
      }
      else if(t<t3){
        t4=t3;
        t3=t;
        p4=p3;
        p3=p;
      }
      else if(t<t4){
        t4=t;
        p4=p;
      }
    }
    cout<<p1<<" "<<t1<<endl;
    cout<<p2<<" "<<t2<<endl;
    if(t4<t7){
      t7=t3;
      p7=p3;
      t8=t4;
      p8=p4;
    }
    else if(t4<t8){
      if(t3<t7){
        t7=t3;
        p7=p3;
        t8=t4;
        p8=p4;
      }
      else{
        t8=t4;
        p8=p4;
      }
    }
    else if(t3<t7){
      t8=t7;
      p8=p7;
      t7=t3;
      p7=p3;
    }
    else if(t3<t8){
      t8=t3;
      p8=p3;
    }
  }
  cout<<p7<<" "<<t7<<endl;
  cout<<p8<<" "<<t8<<endl;
}



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

using namespace std;

template <typename T, int MAX_N>
struct Hash {
    T p,x,n;    
    vector<T> h,h1,vpow;
    Hash(const vector<int> &v, T dx, T dp) {
        h.resize(MAX_N);
        h1.resize(MAX_N);
        vpow.resize(MAX_N);
        n = v.size();
        x = dx, p = dp;
        vpow[0] = 1;
        for (int i = 1; i <= n; ++i)
            vpow[i] = ((T) mul(vpow[i - 1], (T) x)) % p;

        T hash = 0;
        for (int i = n - 1; i >= 0; i--) {
            hash = ((((T) mul(hash, x) + v[i]) % p) + p) % p;
            h[i] = hash % p;
        }
        hash = 0;
        for (int i = 0; i < n; ++i) {
            hash = ((((T) mul(hash, x) + v[i]) % p) + p) % p;
            h1[i] = hash % p;
        }
    }

    T mul(T a, T b) {
        return (a * b)%p;
        T ans = 0;
        a %= p;
        while(b) {
            if(b & 1) ans = (ans + a) % p;
            a = (2 * a) % p;
            b >>= 1;
        }
        return ans % p;
    }

    T getH(int i, int j) {
        int sz = j - i + 1;
        return ((h[i] - mul(h[j + 1], vpow[sz]) % p) + p) % p;
    }

    T getRh(int i, int j) {
        int sz = j - i + 1;
        return ((h1[j] - mul(h1[i - 1], vpow[sz] % p)) + p) % p;
    }
};

int n;
int main() {
    string s;
    cin >> n >> s;
    vector<int> v;
    for (int i = 0; i < n; ++i) 
        v.push_back((s[i] - 'a') + 1);
    Hash<long long, 100010> h1(v, 33, INT_MAX);
    Hash<long long, 100010> h2(v, 33, 1e9+7);
    
    int a = 0, b = n + 1;
    while(b - a > 1) {
        int mid = (a + b) / 2;
        map<pair<long long, long long>, vector<int> > mp;
        int k = mid;
        for (int i = 0; i < n - k + 1; ++i) 
            mp[make_pair(h1.getH(i, i + k - 1), h2.getH(i, i + k - 1))].push_back(i);

        bool flag = 0;
        for (int i = 0; i < n - k + 1; ++i) {
            pair<long long, long long> cur = make_pair(h1.getH(i, i + k - 1), h2.getH(i, i + k - 1));
            int left = 0;
            if(i - k >= 0) lower_bound(mp[cur].begin(), mp[cur].end(), i - k) - mp[cur].begin();
            int right = lower_bound(mp[cur].begin(), mp[cur].end(), i + k) - mp[cur].begin();
            long long total = left + (mp[cur].size() - right);
            if(total + 1 >= 2) {
                flag = 1;
                break;
            }
        }
        if(flag) a = mid;
        else b = mid;
        
    }
    cout << a << "\n";
    return 0;
}


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

int main() {
	long long n,i,j,sum=0,ans=0,count=0,x,y,l,r;
	cin>>l>>r>>n;
	for(i=l;i<=r;i++)
	{
	    if(i%n==0)
	    count++;
	}
	cout<<count;
	
}

Measured memory_bytes: 3644
from sys import stdin
S = stdin.readline().rstrip()
front = int(S[:2])
back = int(S[2:])
def bool_mm(input):
    if 0 < input <= 12:
        return True
    else:
        return False 
bool_f = bool_mm(front)
bool_b = bool_mm(back)
if bool_f and bool_b:
    print("AMBIGUOUS")
elif bool_f and ~bool_b:
    print("MMYY")
elif ~bool_f and bool_b:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std; 
int main() {
    struct localfunc{
        static char asciitolower(char in) {
            if (in <= 'Z' && in >= 'A')
                return in - ('Z' - 'z');
            return in;
        }
    };
    string w; cin >> w;
    string t;
    std::transform(w.begin(), w.end(), w.begin(), localfunc::asciitolower);
    int count=0;
    while(1){
        cin >> t;
        if(t == "END_OF_TEXT") break;
        std::transform(t.begin(), t.end(), t.begin(), localfunc::asciitolower);
        if(t == w){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3196
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
ll high_order_bit(ll n){
    ll tmp=1,i=-1;
    while(tmp<=n){
        tmp*=2;
        i++;
    }
    if(n==0) return 0;
    else return i;
}
vector<ll> binary_expansion(ll n){
    vector<ll> B(high_order_bit(n)+1);
    ll tmp=n;
    for(ll i=high_order_bit(n);i>=0;i--){
        B[i]=tmp/pw2[i];
        tmp%=pw2[i];
    }
    return B;
}
vector<ll> divisor(ll x){
    vector<ll> div;
    for(int i=1;i*i<=x;i++){
        if(i*i!=x && x%i==0){
            div.pb(i);
            div.pb(x/i);
        }
        else if(x%i==0) div.pb(i);
    }
    sort(all(div));
    return div;
}
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}
int main(){
    ll N; cin>>N;
    ll ans=0;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    
    rep(i,N) cin>>A[i];
    rep(i,N) cin>>B[i];
    rep(i,N) cin>>C[i];
    
    sort(all(A));
    // sort(all(B));
    sort(all(C));
    
    rep(i,N){
        ll tmp=B[i]; //真ん中さいず
        ll a_size,c_size;
        
        ll l=0,r=N-1;
        while(r-l>=1){
            ll i=(l+r)/2;
            if(A[i]<tmp) l=i+1;
            else r=i;
        }
        if(A[l]<tmp) a_size = N;
        else a_size = l;
        
        l=0,r=N-1;
        while(r-l>=1){
            ll i=(l+r)/2;
            if(C[i]<=tmp) l=i+1; //A[i]が探したい条件の否定を満たす
            else r=i;
        }
        if(C[l]<=tmp) c_size = 0; //A[l]が探したい条件の否定を満たす
        else c_size = N - l;
        
        ans+=a_size*c_size;
    }
    cout<<ans;
}


Measured memory_bytes: 5608
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


def lcm(a, b):
	return a * b // gcd(a, b)


n, m = map(int, input().split())
s = input()
t = input()
GCD = gcd(n, m)
n_ = n // GCD
m_ = m // GCD

ans = lcm(n, m)
for i in range(GCD):
    if s[i * n_] != t[i * m_]:
        ans = -1
        break
print(ans)

Measured memory_bytes: 3316
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String ans = "";
		
		for (int i=6;i < 555555; i+=5) {
			boolean prime = true;
			for (int j=2;j < i;j++) {
				if (i % j == 0) {
					prime = false;
					break;
				}
			}
			if (prime) {
				ans += i + " ";
				n--;
			}
			if (n == 0) break;
		}
		System.out.println(ans.substring(0, ans.length()-1));
	}
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<pint> e(M);
    for (int i = 0; i < M; ++i) {
        cin >> e[i].first >> e[i].second;
        --e[i].first, --e[i].second;
    }
    int ans = 0;
    for (int i = 0; i < M; ++i) {
        UnionFind uf(N);

        for (int j = 0; j < M; ++j) {
            if (i != j) uf.unite(e[j].first, e[j].second);
        }
        set<int> s;
        for (int j = 0; j < N; ++j) {
            if (uf.par[j] == j) s.insert(uf.par[j]);
        }
        if (s.size() > 1) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void)
{
	int a;
	int b;
	int c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b && b<c){
		printf("%d %d %d\n",a,b,c);
	} else if(b<=a && a<=c){
		printf("%d %d %d\n",b,a,c);
	} else if(b<=c && c<=a){
		printf("%d %d %d\n",b,c,a);
	} else if(c<=a && a<=b){
		printf("%d %d %d\n",c,a,b);
	} else if(a<=c && c<=b){
		printf("%d %d %d\n",a,c,b);
	} else if(c<=b && b<=a){
		printf("%d %d %d\n",c,b,a);
	}
	return 0;
}

Measured memory_bytes: 596
import sys
input = sys.stdin.readline

import numpy as np

MOD = 10**9 + 7

N = int(input())

def cumprod(arr):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

U = 10**6+100
x = np.arange(U,dtype=np.int64)
x[0] = 1
fact = cumprod(x)
x = np.arange(U,0,-1,dtype=np.int64)
x[0] = pow(int(fact[-1]),MOD-2,MOD)
fact_inv = cumprod(x)[::-1]

# 1,N-1の間のn台で完成させる方法
n = np.arange((N-3)//2,N-2)

# +1,+2をn+1個でN-2を作る方法
# +0,+1をn+1個でN-3-nを作る方法
# comb[n+1][N-3-n] * (n+2)! * (N-n-3)!
x = fact[n+1] * fact[n+2] % MOD * fact_inv[4-N+2*n] % MOD
answer = (x[-1] * (N-1) - x[:-1].sum()) % MOD
print(answer)

Measured memory_bytes: 67104
#include<iostream>
using namespace std;
int main() {
	long a[6], b[6], c[6],a2[3],b2[3],c2[3];
	for (int i = 0; i < 6; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 6; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < 6; i++) {
		cin >> c[i];
	}
	a2[0]= a[0] * 3600 + a[1] * 60 + a[2];
	b2[0] = b[0] * 3600 + b[1] * 60 + b[2];
	c2[0] = c[0] * 3600 + c[1] * 60 + c[2];
	a2[1] = a[3] * 3600 + a[4] * 60 + a[5];
	b2[1] = b[3] * 3600 + b[4] * 60 + b[5];
	c2[1] = c[3] * 3600 + c[4] * 60 + c[5];
	a2[2] = a2[1] - a2[0];
	b2[2] = b2[1] - b2[0];
	c2[2] = c2[1] - c2[0];
	a[0] = a2[2] / 3600; a2[2] = a2[2] % 3600;
	a[1] = a2[2] / 60; a2[2] = a2[2] % 60;
	a[2] = a2[2];
	b[0] = b2[2] / 3600; b2[2] = b2[2] % 3600;
	b[1] = b2[2] / 60; b2[2] = b2[2] % 60;
	b[2] = b2[2];
	c[0] = c2[2] / 3600; c2[2] = c2[2] % 3600;
	c[1] = c2[2] / 60; c2[2] = c2[2] % 60;
	c[2] = c2[2];
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	cout << b[0] << " " << b[1] << " " << b[2] << endl;
	cout << c[0] << " " << c[1] << " " << c[2] << endl;


}

Measured memory_bytes: 3028
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define FR first
#define SE second
#define MOD 1000000007
#define inf (ll)(1e18)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pr;

ll f[310];
int mk;

pr a[310][310];
int num[310];

void build(int k) {
  for(int i=1;i<=num[k-1];i++) {
  	ll x=a[k-1][i].SE,y=a[k-1][i].FR;
  	y+=x;
  	for(;y<=f[k+2];y+=x) a[k][++num[k]]=pr(x,y);
  }
}

void pre() {
  f[0]=f[1]=1;
  for(mk=1;f[mk]<=inf;mk++) f[mk+1]=f[mk-1]+f[mk];
  mk--;
  num[1]=3;a[1][1]=pr(1,2);a[1][2]=pr(1,3);a[1][3]=pr(1,4);
  for(int i=2;i<=mk;i++) build(i);
}

inline ll solve(ll n,ll m,ll k) {
  return (m>n)?0:((n-m)/k+1)%MOD;
}

ll calc(ll n,ll m,int k) {
  ll ans=0;
  if (k==1) {
  	for(int i=1;i<=n;i++) ans=(ans+m)%MOD;
  }
  else {
  	for(int i=1;i<=num[k-1];i++) {
  		ll x=a[k-1][i].SE,y=a[k-1][i].FR;
  		if (x<=n) ans=(ans+solve(m,x+y,x))%MOD;
  		if (x<=m) ans=(ans+solve(n,x+y,x))%MOD;
	  }
  }
  return ans;
}

int main() {
  pre();
  int cases;
  scanf("%d",&cases);
  for(;cases;cases--) {
  	ll n=0,m=0;
  	scanf("%lld%lld",&n,&m);
  	if (n>m) swap(n,m);
  	int ans=1;
  	for(;n>=f[ans+1]&&m>=f[ans+2];ans++);
  	printf("%d %lld\n",ans,calc(n,m,ans));
  }
  return 0;
}

Measured memory_bytes: 4352
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
	String s=sc.next();
  		int c=0;

   for(int b=0;b<n-2;b++){
 	if(s.substring(b,b+1).equals("A")&&s.substring(b+1,b+2).equals("B")&&s.substring(b+2,b+3).equals("C")){
    		c++;
   	 }

        }
    	System.out.println(c);
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000010;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(10));
	rep(i, n) rep(j, 10) cin >> a[i][j];
	vector<vector<int>> cnt(n, vector<int>(11));
	rep(i, n) rep(j, 11) cin >> cnt[i][j];
	int ans = -inf;
	for (int i = 1; i < 1024; i++) {
		int res = 0;
		rep(j, n) {
			int c = 0;
			rep(k, 10) {
				if (((i >> k) & 1) && a[j][k]) c++;
			}
			res += cnt[j][c];
		}
		chmax(ans, res);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
cou=0
for i in range(n):
    a=list(map(int,input().split()))
    x=c
    for j in range(m):
        x+=a[j]*b[j]
    if x>0:
        cou+=1
print(cou)



Measured memory_bytes: 38484
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
 
inter_A = (A//10)*10 if A%10 == 0 else (A//10)*10 + 10
inter_B = (B//10)*10 if B%10 == 0 else (B//10)*10 + 10
inter_C = (C//10)*10 if C%10 == 0 else (C//10)*10 + 10
inter_D = (D//10)*10 if D%10 == 0 else (D//10)*10 + 10
inter_E = (E//10)*10 if E%10 == 0 else (E//10)*10 + 10
 
first_A = A + inter_B + inter_C + inter_D + inter_E
first_B = inter_A + B + inter_C + inter_D + inter_E
first_C = inter_A + inter_B + C + inter_D + inter_E
first_D = inter_A + inter_B + inter_C + D + inter_E
first_E = inter_A + inter_B + inter_C + inter_D + E
print(min([first_A, first_B, first_C, first_D, first_E]))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int N; cin >> N;
  vector<long long>A(N);
  for(int i = 0 ; i < N; i++){
    cin >> A[i];}
  
  sort(A.begin(),A.end());
  int n = 0; int ans = 0;
  while( n < N){
    long long cc = A[n]; int cnt = 0;
    while( n < N && A[n] == cc){cnt++; n++;}
    if( cnt % 2 == 0){continue;}
    else{ans ++;}}
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define mod 1000000007
#define inf 9999999999999999ll
bool possible(ll m,vi &a,ll hand)
{
    //first choose all handshakes with total_value > m
    ll n=a.size();
    ll handshakes=0;
    for(ll i=n-1;i>=0;i--)
    {
        ll curr=a[i];
        if(curr*2<=m)
            break;
        ll reqd=max(m+1-curr,0ll);
        ll ind=lower_bound(a.begin(),a.end(),reqd)-a.begin();
        ll num=max(0ll,i-ind);
        handshakes+=2*num+1;
    }
    if(handshakes>=hand)
    {
        return true;
    }
    ll extra=0;
    map <ll,ll> count;
    for(ll i=0;i<n;i++)
    {
        count[a[i]]++;
    }
    for(auto &i:count)
    {
        ll ele=i.F;
        ll fq=i.S;
        ll x=count[m-ele];
        if(x)
        {
            extra+=x*fq;
        }   
    }
    if(handshakes+extra>=hand)
        return true;
    return false;
}
ll sum(vi &s,ll i,ll j)
{
    if(i>=s.size())
        return 0;
    ll ans=s[j];
    if(i)
        ans-=s[i-1];
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vi a(n);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    ll low=2*a.back();
    ll high=2*a[0];
    swap(low,high);
    while(low<high)
    {
        ll mid=(low+high)/2;
        if(possible(mid,a,m))
        {
            if(possible(mid+1,a,m))
            {
                low=mid+1;
            }
            else
                low=high=mid;
        }
        else
        {
            high=mid-1;
        }
    }
    // tr1(low);
    //count all points from low+1
    vi su(a);
    for(ll i=1;i<n;i++)
        su[i]+=su[i-1];

    ll points=0;
    ll handshakes=0;
    for(ll i=n-1;i>=0;i--)
    {
        ll curr=a[i];
        if(curr*2<=low)
            break;
        ll reqd=max(low+1-curr,0ll);
        ll ind=lower_bound(a.begin(),a.end(),reqd)-a.begin();
        //[ind,i-1]
        ll num=max(0ll,i-ind);
        handshakes+=2*num+1;
        if(ind<=i-1)
        {
            points+=2*curr*(num);
            points+=2*sum(su,ind,i-1);
            // points+=2*curr*sum(su,ind,i-1);
        }
        points+=2*curr;
        // tr3(points,handshakes,ind);
    }
    // tr2(points,handshakes);
    ll left=m-handshakes;
    points+=low*left;
    cout<<points<<endl;
}


Measured memory_bytes: 9024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    cout << a-b+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>

using namespace std;

typedef long long ll;

#ifdef ONPC
    mt19937 rnd(228);
#else
    mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = 3000 + 7;
const int MOD = 1e9 + 7;

int dp[N][N];

struct event
{
    int x, y, val;
};

int add(int a, int b)
{
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

int mul(int a, int b)
{
    return (a * (ll) b) % MOD;
}

int bin(int a, int n)
{
    int res = 1;
    while (n)
    {
        if (n % 2 == 0)
        {
            a = mul(a, a);
            n /= 2;
        }
        else
        {
            res = mul(res, a);
            n--;
        }
    }
    return res;
}

int inv(int x)
{
    return bin(x, MOD - 2);
}

int pw[N];
int rev_pw[N];

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (a[i] > a[j])
            {
                dp[i][j]++;
            }
        }
    }
    pw[0] = 1;
    rev_pw[0] = 1;
    for (int i = 1; i <= q; i++)
    {
        pw[i] = mul(pw[i - 1], 2);
        rev_pw[i] = inv(pw[i]);
    }
    for (int i = 0; i < q; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        vector <event> e;
        e.push_back({y, x, dp[x][y]});
        e.push_back({x, y, dp[y][x]});
        for (int i = 0; i < n; i++)
        {
            if (i != x && i != y)
            {
                e.push_back({y, i, dp[x][i]});
                e.push_back({x, i, dp[y][i]});
                e.push_back({i, y, dp[i][x]});
                e.push_back({i, x, dp[i][y]});
            }
        }
        set <pair <int, int> > q;
        for (auto c : e)
        {
            dp[c.x][c.y] = mul(add(mul(dp[c.x][c.y], pw[i]), mul(c.val, pw[i])), rev_pw[i + 1]);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            ans = add(ans, dp[i][j]);
        }
    }
    cout << mul(ans, pw[q]) << '\n';
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  string s; cin >> s;
  int n = s.size();
  map<char, int> mp;
  rep(i, n) {
    mp[s[i]-'a']++;
  }
  if (n == 1) {
    cout << "YES\n";
  }
  else if (n == 2) {
    cout << (mp.size() == 2 ? "YES\n" : "NO\n");
  }
  else {
    int limit = n / 3;
    if (!(mp[0] >= limit && mp[1] >= limit && mp[2] >= limit)) {
      cout << "NO\n";
    }
    else if (mp[0] - limit <= 1 && mp[1] - limit <= 1 && mp[2] - limit <= 1) {
      cout << "YES\n";
    }
    else {
      cout << "NO\n";
    }
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
signed main(){
  int H,W; cin>>H>>W;
  vector<string> S(H);
  rep(i,0,H) cin>>S[i];
  queue<pii> Q;
  Q.push(mp(0,0));
  vi P={0,1},R={1,0};
  string ans="Impossible";
  int count=0;
  int sum=0;
  rep(i,0,H){
    rep(j,0,W){
      if(S[i][j]=='#')
        sum++;
    }
  }
  Q.push(mp(-1,-1));
  while(Q.size()>1){
    int X=Q.front().first,Y=Q.front().second;
    Q.pop();
    if(X==H-1&&Y==W-1&&count==sum-1){
      ans="Possible";
      break;
    }
    if(X==-1){
      count++;
      Q.push(mp(-1,-1));
    }
    else{
    rep(i,0,2){
      int A=X+P[i],B=Y+R[i];
      if(A<H&&B<W){
        if(S[A][B]=='#')
          Q.push(mp(A,B));
      }
    }
    }
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	ok := true
	var x0, y0 int
	for i := 0; i < n; i++ {
		var t, x, y int
		fmt.Scan(&t, &x, &y)

		xa := int(math.Abs(float64(x - x0)))
		ya := int(math.Abs(float64(y - y0)))

		ok = (t-xa-ya)%2 == 0 && t >= xa+ya
		if !ok {
			break
		}
	}

	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 5504
# coding: utf-8
# Your code here!

# x,y,zは高々10^2まで

N = int(input())

A = [0]*10001

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            index = x*x + y*y + z*z + x*y + y*z + z*x
            if index <= 10000:
                A[index] += 1

for i in range(1,N+1):
    print(A[i])

Measured memory_bytes: 69296
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;


int main() {
	string s;cin>>s;
	if (s[0] == 'a') {
		cout<<"square1001";
	}
	else {
		cout<<"e869120";
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {
    public static int MAX = 100001;
    public static class Task{
        String name;
        int t;
    }
    public static class MyQueue {
        int head, tail = 0;
        Task[] a = new Task[MAX];
        public boolean isFull(){
            return head == (tail + 1) % MAX;
        }
        public boolean isEmpty(){
            return head == tail;
        }
        public boolean enqueue(Task s){
            if (isFull()) {
                throw new NullPointerException("queue is full");
            }
            a[tail] = s;
            if (++tail == MAX) tail = 0;
            return true;
        }
        public Task dequeue(){
            if (isEmpty()){
                throw new NullPointerException("queue is empty");
            }
            Task s = a[head];
            if (++head == MAX) head = 0;
            return s;
        }
    }
    public static void startSchedule(MyQueue myQueue, int q, Task[] tasks){
        int countTime = 0;
        while (!myQueue.isEmpty()) {
            Task task = myQueue.dequeue();
            int value = task.t;
            if (!(value - q <= 0)){
                myQueue.enqueue(task);
                task.t = value - q;
                countTime += q;
                continue;
            }
            else {
                System.out.printf("%s %d\n",task.name, countTime + value);
                countTime += value;
            }

        }
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n,q;
        MyQueue myQueue = new MyQueue();
        n = scanner.nextInt();
        Task[] tasks = new Task[n];
        q = scanner.nextInt();
        for (int i = 0; i < n; i++){
            tasks[i] = new Task();
            tasks[i].name = scanner.next();
            tasks[i].t = scanner.nextInt();
            myQueue.enqueue(tasks[i]);
        }
        startSchedule(myQueue, q, tasks);
    }
}



Measured memory_bytes: 115236