akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i,s.size()) ++mp[s.at(i)];
    for (auto x : mp) {
        if (x.second % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}



Measured memory_bytes: 3620
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

int main() {
	int n;
	LL x, mul = 1;
	LL maxi = 1000000000000000000;
	cin>>n;
	bool zero = false, ov = false;
	for(int i=0;i<n;i++) {
		cin>>x;
		LL m = mul * x;
		if(m < 0 || m > maxi || m < mul) {
			ov=true;
		}
		if(x == 0) zero = true;
		mul = m;
	}
	
	if(zero) cout<<0<<endl;
	else if(ov) cout<<-1<<endl;
	else cout<<mul<<endl;

    return 0;
}



Measured memory_bytes: 3632
import heapq
N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)

ans = 0
for i in range(M):
    most_expensive = -heapq.heappop(A)
    most_expensive //= 2
    heapq.heappush(A, -most_expensive)

print(-sum(A))

Measured memory_bytes: 14184
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;

long double a[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, k;
    cin >> n >> k;
    long double ans = 0, sum = 0;
    queue<long double> q;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < k; i++){
        long double x = (a[i] * (a[i] + 1) / 2);
        x = x / a[i];
        q.push(x);
        sum += x;
        ans += x;
    }
    for(int i = k; i < n; i++){
        long double x = (a[i] * (a[i] + 1) / 2);
        x = x / a[i];
        sum -= q.front();
        sum += x;
        q.pop();
        q.push(x);
        if(ans - sum < 1e-8) ans = sum;
    }
    cout << fixed << setprecision(8) << ans;

    return 0;
}




Measured memory_bytes: 9480
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var n int
	var s string
	con.Scan(&n, &s)
	lev := 0
	minLev := 0
	for _, c := range s {
		switch c {
		case '(':
			lev++
		case ')':
			lev--
			if lev < minLev {
				minLev = lev
			}
		}
	}
	for minLev < 0 {
		s = "(" + s
		lev++
		minLev++
	}
	for lev > 0 {
		s = s + ")"
		lev--
	}
	con.Println(s)
	return nil
}


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

#define int long long

using namespace std;

int gcd(int x, int y){
  if(y > x) return gcd(y, x);
  if(x % y == 0) return y;
  return gcd(y, x % y);
}


signed main(void){
  int A, B;
  cin >> A >> B;
  cout << (A * B) / gcd(A, B) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;

struct UnionFind {
private:
  vector<ll> child, tree;
  vector<vector<ll>> list;

public:
  //頂点数v
  UnionFind(ll v) {
    tree.resize(v);
    list.resize(v);
    for(ll i = 0; i < v; i++) {
      tree[i] = i;
      list[i].push_back(i);
    }
  }

  //木の根を求める
  ll root(ll x) {
    if(x == tree[x]) {
      for(ll i = 0; i < child.size(); i++) {
        tree[child[i]] = x;
      }
      child.clear();
      return x;
    } else {
      child.push_back(x);
      return x = root(tree[x]);
    }
  }
  //xの所属するグループの大きさ
  ll size(ll x) { return list[root(x)].size(); }

  vector<ll> nodes(ll no) { return list[root(no)]; }

  //xとyの集合を合わせる
  bool unit(ll x, ll y) {
    x = root(x);
    y = root(y);
    if(x == y) {
      return false;
    }
    if(list[x].size() < list[y].size()) {
      swap(x, y);
    }
    for(int no : list[y]) {
      list[x].emplace_back(no);
    }
    tree[y] = x;
    return true;
  }

  //xとyが同じグループに所属するか
  bool isUnit(ll x, ll y) { return root(x) == root(y); }
};
int main(){
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind UF(n);
  vector<int> di(n, 0);
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    di[a]++;
    di[b]++;
    UF.unit(a, b);
  }
  vector<int> ans(n);
  for(int i = 0; i < n; i++){
    ans[i] = UF.size(i) - di[i];
  }
  for(int i = 0; i < k; i++) {
    int c, d;
    cin >> c >> d;
    c--;
    d--;
    if(UF.isUnit(c, d)) {
      ans[c]--;
      ans[d]--;
    }
  }
  for(int i = 0; i < n; i++){
    cout << ans[i] - 1<< ' ';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 9844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
typedef long long ll;
double getDistance(int x1, int x2, int y1, int y2){
  return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main() {
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  rep(i,n){
    cin >> a.at(i).first >> a.at(i).second;
  }
  double sum=0;
  rep(i,n){
    rep(j,n){
      sum+=getDistance(a.at(i).first,a.at(j).first, a.at(i).second, a.at(j).second);
    }
  }
  cout << fixed << setprecision(10) << sum/n << endl;
}



Measured memory_bytes: 256
a,b,c,x = map(int, [input() for i in range(4)])

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            s = 500 * i + 100 * j + 50 * k
            if s == x:
                count +=1
            # print(s)
print(count)

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

struct UnionFind {
    vector<int> d; // 根なら (-サイズ), そうでないなら親の番号
    UnionFind(int N) : d(N, -1){} // 全て根として初期化

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

    bool unite(int x, int y) { // x と y の木を併合. 併合した場合 true
        x = root(x); y = root(y); // x <- x の根, y <- y の根
        if (x == y) return false; 
        // merge technique（データ構造をマージするテク. 小を大にくっつける）
        if (d[x] > d[y]) swap(x, y);    // x の木のサイズ > y の木のサイズにする. d[x], d[y] < 0 に注意.
        d[x] += d[y];   // x の木のサイズ += y の木のサイズ
        d[y] = x;   // y の親は x
        return true;
    }

    bool same(int x, int y) { // 2つのデータ x, y が属する木が同じなら true
        return root(x) == root(y);
    }
    
    int size(int x) { // 素集合のサイズ
        return -d[root(x)]; // d[root(x)] < 0 に注意.
    }
};

void Main(){
	ll n, m; cin >> n >> m;
	vi a(m), b(m);
	rep(i, m) {
	    cin >> a[i] >> b[i];
	    a[i]--; b[i]--;
	}
	reverse(all(a));
	reverse(all(b));
	
    UnionFind UF(n);
    ll tot = n * (n-1) / 2;
    vll ans;
    
    rep(i, m){
        ans.pb(tot);
        if(!UF.same(a[i], b[i])){
            tot -= ll(UF.size(a[i])) * ll(UF.size(b[i]));
        } 
        UF.unite(a[i], b[i]);
    }
        
    reverse(all(ans));    
	for(auto x : ans) cout << x << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 5388
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int a,b;
    cin >> a >> b;
    b-=a;
    int k = 0;
    rep(i,b)k+=i+1;
    cout << k - a-b << endl;
}

Measured memory_bytes: 888
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if( b - ( a*c ) >= 0) {
			System.out.println(c);
		}else {
			System.out.println( b/a );
		}
	}
}

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

int main()
{
    int P,Q,R;
    cin >> P >> Q >> R;
    if (P+Q < P+R && P+Q < Q+R) {
        cout << P+Q << endl;
    }else if(P+R < Q+R){
        cout << P+R << endl;
    }else{
        cout << Q+R << endl;
    }
}

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

static class Program
{
    static void Main(string[] args)
    {
        //入力
        var input = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
        var N = input[0];
        var K = input[1];

        //処理

        //出力
        Console.WriteLine(K * Math.Pow(K - 1, N - 1));
    }
}


Measured memory_bytes: 13268
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

K = ri()
S = rs()

class CombMod:
    def __init__(self, N):
        self.fact = [1]
        self.rfact = [1]
        for i in range(1, N+1):
            self.fact.append(self.fact[i-1]*i % mod)
            self.rfact.append(pow(self.fact[i], mod-2, mod))

    def comb(self, n, k):
        return self.fact[n]*self.rfact[k]*self.rfact[n-k] % mod

class PowMod:
	def __init__(self, N, base=[2]):
		self.mem = {}
		for b in base:
			pows = [1]
			for i in range(1, N+1):
				pows.append(pows[-1]*b % mod)
			self.mem[b] = pows

	def pow(self, b, n):
		return self.mem[b][n]

N = len(S)
cm = CombMod(K+N)
pm = PowMod(K, base=[25, 26])

ans = 0
for i in range(K+1):
	ans += cm.comb(K+N-i-1, N-1) * pm.pow(26, i) * pm.pow(25, K-i)
	ans = ans % mod
print(ans)


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

using namespace std;
template <class W> struct edge {
	int from, to;
	W a, b;
	edge(int from, int to, W a, W b) : from(from), to(to), a(a), b(b) {}
};
template <class W> using node = vector<edge<W>>;
template <class W> using graph = vector<node<W>>;
template <class W> void addedge(graph<W>& g, int from, int to, W a, W b, bool bidirectional = false) {
	g[from].emplace_back(edge<W>(from, to, a, b));
	if (bidirectional) g[to].emplace_back(edge<W>(to, from, a, b));
}

class Solution {
public:
	void solve() {
		int n, m, s;
		cin >> n >> m >> s;
		graph<int> g(n);
		for (int i = 0; i < m; i++) {
			int u, v, a, b;
			cin >> u >> v >> a >> b;
			addedge(g, u - 1, v - 1, a, b, true);
		}
		vector<int> c(n), d(n);
		for (int i = 0; i < n; i++) cin >> c[i] >> d[i];
		vector<vector<long long>> dp(n, vector<long long>(2501, 0x3f3f3f3f3f3f3f3f));
		using state = tuple<long long, int, int>;
		priority_queue<state, vector<state>, greater<state>> q;
		q.push(make_tuple(0, 0, min(s, 2500)));
		while (!q.empty()) {
			long long c_cost;
			int c_u, c_s;
			tie(c_cost, c_u, c_s) = q.top();
			q.pop();
			if (dp[c_u][c_s] <= c_cost) continue;
			dp[c_u][c_s] = c_cost;
			if (c_s < 2500) {
				q.push(make_tuple(c_cost + d[c_u], c_u, min(c_s + c[c_u], 2500)));
			}
			for (auto e : g[c_u]) {
				if (c_s - e.a >= 0) q.push(make_tuple(c_cost + e.b, e.to, c_s - e.a));
			}
		}
		for (int i = 1; i < n; i++) {
			long long ans = 0x3f3f3f3f3f3f3f3f;
			for (int j = 0; j <= 2500; j++) {
				ans = min(ans, dp[i][j]);
			}
			cout << ans << "\n";
		}
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 8416
def main():
    _ = int(input())
    p_list = [int(p) for p in input().split()]

    cnt = 0
    for i in range(len(p_list)):
        if i == 0 and i+1 == p_list[i]:
            cnt += 1
            p_list[i], p_list[i+1] = p_list[i+1], p_list[i]
            continue
        elif i == len(p_list)-1 and i+1 == p_list[i]:
            cnt += 1
        elif i+1 == p_list[i]:
            cnt += 1
            p_list[i], p_list[i+1] = p_list[i+1], p_list[i]
    print(cnt)


if __name__ == "__main__":
    main()

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

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using cd = complex<ld>;

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

  int x, p;
  cin >> x >> p;
  cout.precision(10);
  x += x % 2;
  cout << fixed << x * 100.0 / (2 * p);
  return 0;
}

Measured memory_bytes: 3800
N=int(input())
S=input()
Z='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
List=[]
y=0
for i in range(len(S)):
  for j in range(len(Z)):
    if S[i]==Z[j]:
        y=Z[(j+N)%26]
    else:
        pass

  List.append(y)

a=List[0]
for i in range(1,len(S)):
    a=a+List[i]
    
print(a)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int A[100];
int main()
{
	int i,n;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>A[i];
	for(i=n-1;i>0;i--)
		cout<<A[i]<<" ";
	cout<<A[0]<<endl;
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string s;
int n,k;
int main(){
    cin>>s>>k;
    n = s.size();
    set<string>S;
    for(int i=0;i<n;i++){
        string ss = "";
        for(int j=0;j<6;j++){
            if(i+j >= n) break;
            ss.pb(s[i+j]);
            S.insert(ss);
        }
    }
    for(set<string>::iterator it=S.begin();it!=S.end();++it){
        k--;
        if(k == 0){
            cout<<*it<<endl;
            return 0;
        }
        
    }
}

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

int main() {
	ll n;
	cin >> n;
	if (n % 2) {
		cout << 0 << endl;
		return 0;
	}
	ll k = 5;
	ll ans = 0;
	while (k <= n) {
		ans += n / k / 2;
		k *= 5;
	}
	cout << ans << endl;
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define MOD 1000000007

uint add(uint a, uint b) { return a+b < MOD ? a+b : a+b-MOD; }
uint sub(uint a, uint b) { return a < b ? a+MOD-b : a-b; }
uint mul(uint a, uint b) { return (ull)a*b%MOD; }
uint sqr(uint a) { return mul(a, a); }

uint modpow(uint b, uint e)
{
    uint r = 1;
    for (; e; e >>= 1) {
        if (e&1) r = mul(r, b);
        b = mul(b, b);
    }
    return r;
}

uint modinv(uint n) { return modpow(n, MOD-2); }
uint moddiv(uint n, uint d) { return mul(n, modinv(d)); }

#define N 2048

uint fac[N];
//uint dp[N][N];

uint binom(int n, int k)
{
    return moddiv(fac[n], mul(fac[k], fac[n-k]));
}

int main()
{
    canhazfast();

    int n, k;

    cin >> n >> k;
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; ++i) fac[i] = mul(fac[i-1], i);
    for (int i = 1; i <= k; ++i) {
        if (i-1 > n-k) {
            cout << "0\n";
            continue;
        }
        uint b = binom(k-1, i-1);
        uint r = binom(n-k+1, i);
        //cerr << "i = " << i << " b = " << b << " r = " << r << '\n';
        uint ans = mul(b, r);
        cout << ans << '\n';
    }


    return 0;
}


Measured memory_bytes: 256
import math
a,b,h,m = map(int,input().split())
theta_h = 2 * math.pi * (h * 60 + m)/720
theta_m = 2 * math.pi * m /60
x_h = a *math.cos(theta_h)
y_h = a *math.sin(theta_h)
x_m = b *math.cos(theta_m)
y_m = b *math.sin(theta_m)
length = math.sqrt((x_h - x_m)*(x_h - x_m) + (y_h - y_m)*(y_h - y_m))
#print(theta_h,theta_m)
#print(x_h,y_h,x_m,y_m)
print(length)

Measured memory_bytes: 9524
#include <iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	string sa, sb, sc;
	cin >> sa >> sb >> sc;
	char c = sa[0];
	sa.erase(sa.begin());

	while (true) {
		if (c == 'a') {
			if (sa.size() == 0) {
				cout << "A" << endl;
				break;
			}
			sa.erase(sa.begin());
			c = sa[0];
		}
		else if (c == 'b') {
			if (sb.size() == 0) {
				cout << "B" << endl;
				break;
			}
			sb.erase(sb.begin());
			c = sb[0];
		}
		else {
			if (sc.size() == 0) {
				cout << "C" << endl;
				break;
			}
			sc.erase(sc.begin());
			c = sc[0];
		}
	}

	return 0;
}

Measured memory_bytes: 256
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 100005;
using namespace std;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n,c = 0;
  cin >> n;
  vector <int> v(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  for (int i = 0; i < n; ++i)
  {
    int l =0,r = i-1;
    while(l < r)
    {
      if(v[l] + v[r] > v[i])
      {
        c += r-l;
        r--;
      }
      else
        l++;
    }
  }
  cout << c;
  return 0;
}

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

int main() {

#ifdef LOCAL_DEFINE
	freopen("input.txt", "wt", stdin);
#endif

	int n, k;
	cin >> n >> k;

	cout << (n % k ? 1 : 0) << endl;

#ifdef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif

	return 0;
}

Measured memory_bytes: 256
n=int(input())
import math
res=0
for a in range(1,n+1):
    for b in range(1, n + 1):
        gcd1 = math.gcd(a, b)
        for c in range(1, n + 1):
           gcd2=math.gcd(gcd1,c)
           res+=gcd2
print(res)

Measured memory_bytes: 68548
from heapq import heappop, heappush


class UnionFind(object):

    def __init__(self, N):
        self.tree = [i for i in range(N)]
        self.rank = [0] * (N + 1)
        self.size = [1] * N  # 頂点iの属する連結成分の大きさ

    def find(self, x):
        while self.tree[x] != self.tree[self.tree[x]]:
            self.tree[x] = self.tree[self.tree[x]]  # 経路圧縮
        return self.tree[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        # ランクを考慮しない場合はどちらが親になっても良い
        if self.rank[x] < self.rank[y]:
            self.tree[x] = y
            self.size[y] += self.size[x]
        else:
            self.tree[y] = x
            self.size[x] += self.size[y]

        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def has_same_parent(self, x, y):
        return self.find(x) == self.find(y)


def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


N = I()
X = [None] * N
Y = [None] * N
for i in range(N):
    x, y = MI()
    X[i] = (x, i, x, y)
    Y[i] = (y, i, x, y)
X.sort()
Y.sort()

# ある頂点vから最小全域木に含まれる点をたどった先の頂点は、x軸方向で最も近いかy軸方向で最もvから近いはず
q = list()
for i in range(N - 1):
    for axis in [X, Y]:
        _, t0, x0, y0 = axis[i]
        _, t1, x1, y1 = axis[i + 1]
        cost = min(abs(x1 - x0), abs(y1 - y0))
        heappush(q, (cost, t0, t1))

# Kruskal法 := 最小コストの辺から順に見て、新たな頂点が仲間に入るなら加える
uf = UnionFind(N)
ans = 0
while len(q) > 0:
    cost, t0, t1 = heappop(q)
    if not uf.has_same_parent(t0, t1):
        uf.unite(t0, t1)
        ans += cost
print(ans)


Measured memory_bytes: 60316
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = 100001;
		boolean[] isPrime = new boolean[N];
                isPrime[2] = true;
		boolean useless = true;
		for(int i=3;i<N;++i){
			isPrime[i] = useless;
			useless = !useless;
		}
		for(int i=3;i<=(int)Math.sqrt((double)N);++i){
			if(isPrime[i]){
				for(int j=i*i;j<N;j+=2*i) isPrime[j] = false;
			}
		}		
		int[] ruiseki = new int[N];
		ruiseki[1] = 0;
		for(int i=3;i<N;i+=2){
			if(isPrime[i]&&isPrime[(i+1)/2]) ruiseki[i]++;
			ruiseki[i] += ruiseki[i-2];
		}
		
		int Q = sc.nextInt();
		for(int i=0;i<Q;++i){
			int l = sc.nextInt()-2;
			if(l<0) l=1;
			int r = sc.nextInt();
			System.out.println(ruiseki[r]-ruiseki[l]);
		}
		return;
	}
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int N, M, a, b, I, Ma=0;
    cin >> N >> M;
    vector <int> D[N], DA[N];
    priority_queue <pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> Q;
    int S[N], g[N], Di[N];
    for (int i = 0; i < N; i++)
    {
        g[i] = 1;
        S[i] = 0;
        Di[i] = 0;
    }
    for (int i = 0; i < M; i++)
    {
        cin >> a >> b;
        a--;
        b--;
        D[b].push_back(a);
        DA[a].push_back(b);
        S[a]++;
    }
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 0)
        {
            Q.push({0,i});
        }
    }
    while (Q.size() > 0)
    {
        I = Q.top().second;
        Q.pop();
        g[I] = 0;
        for (int i = 0; i < D[I].size(); i++)
        {
            a = D[I][i];
            if (g[a] == 1)
            {
                Di[a] = max(Di[a],Di[I] + 1);
                S[a]--;
                if (S[a] == 0)
                {
                    Q.push({Di[a],a});
                    Ma = max(Ma,Di[a]);
                }
            }
        }
    }
    cout << Ma;
    return 0;
}


Measured memory_bytes: 12416
n,k=map(int,input().split())
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

mod=10**9+7
for i in range(1,k+1):
  print(cmb(n-k+1,i,mod)*cmb(k-1,i-1,mod)%mod)

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... 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 V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    ll ans = 0;
    ll b_s = 0;
    ll a_e = 0;
    ll both = 0;
    REP(i,N){
        string s;
        cin >> s;

        if(s[0]=='B'){
            if (s[s.size()-1]=='A') both++;
            else b_s++;
        } else if (s[s.size()-1]=='A') a_e++;

        REP(j,s.size()-1){
            if(s[j]=='A' && s[j+1]=='B') ans++;
        }
    }

    if(a_e>0){
        if(both>0){
            ans += both;
            if(b_s>0) ans += 1 + min(a_e-1,b_s-1);
        } else {
            ans += min(a_e,b_s);
        } 
    } else {
        if(both>0){
            ans += both - 1;
            if(b_s>0) ans += 1;
        }
    }

    pl(ans)

    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    X = list(map(int, input().split()))
    Xmin = min(X)
    Xmax = max(X)
    ans = 1000000000000
    for i in range(Xmin-1, Xmax+2):
        tmp = 0
        for p in X:
            tmp += (p-i)*(p-i)
        ans = min(ans, tmp)
    print(ans)

main()


Measured memory_bytes: 3060
import math
def prime_number(num):
    if num == 1 :
        return 0
    for i in range(2,int(math.sqrt(num))+1):
        if (num % i) == 0:
            return 0
    return 1

N =int(input())
count = 0
for i in range(0,N):
    num = int(input())
    count += int(prime_number(num))
print(count)


Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S, key = "keyence";
  cin >> S;
  for(int i = 0; i < S.size(); i++){
    for(int j = 0; j <= S.size() - i; j++){
      if((S.substr(0, i) + S.substr(i + j, S.size() - j)) == key){
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

continum = 0
prev_num = 0

a.append(-1)
ans = 0
for a_i in a:
    if prev_num == a_i:
        continum += 1
    else:
        ans += max(0, (continum)//2)
        continum = 1
        prev_num = a_i

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Market
{
    ll a,b;
    bool operator<(const Market &o)const
    {
        if(o.a || a)
            return o.a*b < a*o.b;
        else
            return b < o.b;
    }
};
void solve(ll T, vector<Market> m)
{
    vector<Market>m1,m0;
    for(auto x:m)
    {
        if(x.a==0)m0.push_back(x);
        else m1.push_back(x);
    }
    sort(m1.begin(),m1.end());
    sort(m0.begin(),m0.end());
    vector<ll> dp(34,INT_MAX);
    dp[0] = 0;
    for(int i=0;i<m1.size();++i)
    {
        int j = 32;
        while(j >= 0 && dp[j] >= T) j--;
        for(;j>=0;--j)
        {
            if(dp[j] * m1[i].a + m1[i].b + dp[j] < dp[j+1])
                dp[j+1] = dp[j] * m1[i].a + m1[i].b + dp[j];
        }
    }
    int ans = 0;
    int j = 0;
    for(int i=0;i<=32;++i)
        if(dp[i] <= T)
        {    
            ans = i;
            j = i;
        }
    ll sum = 0;
    for(int i=0;i<m0.size();++i)
    {
        sum += m0[i].b;
        if(sum > T) break;
        while(j>=0 && dp[j] + sum > T)
        {
            j--;
        }
        ans = max(ans,j + i + 1);
    }
    cout<<ans<<endl;
}

int main()
{
    ll N;
    cin>>N;
    ll T;
    cin>>T;
    vector<Market> dat(N);
    for(int i = 0 ; i < N ; i++)
    {
        cin>>dat[i].a>>dat[i].b;
        dat[i].b += dat[i].a + 1;
    }
    solve(T, move(dat));
    return 0;
}


Measured memory_bytes: 8944
#include<bits/stdc++.h>
#define INF 2147483647
#define  ll long long
using namespace std;
const int Max=1e6+20;
const int Maxn=1e7+20;
//const int mod=1e9+7;
inline int read()
{
    int f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')f=-1;
    }
    while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    while(ch>='0'&&ch<='9');
    return x*f;
}

int main()
{

   double d,t,s;
   cin>>d>>t>>s;
   double n=d/s;
   if(n<=t) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

}




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

using namespace std;

vector<queue<int> > que;

void f0()
{
    int p1,p2;
    cin>>p1>>p2;

    que[p1].push(p2);
}

void f1()
{
    int p;
    cin>>p;

    if(!que[p].empty())
        cout<<que[p].front()<<endl;
}

void f2()
{
    int p;
    cin>>p;

    if(!que[p].empty()) que[p].pop();
}

int main()
{
    
    int n,q;

    cin>>n>>q;

    que.resize(n);

    while(q--)
    {
        int op;
        cin>>op;

        switch(op)
        {
            case 0:f0();break;
            case 1:f1();break;
            case 2:f2();break;
        }
    }


    return 0;
}



Measured memory_bytes: 4380
#include<iostream>
#include<stack>
#include<string>
#include<iomanip>
#include<vector>
#include<map>

using namespace std;

map<int, int> countSame(vector<int> input) {
    map<int, int> _map;
    for (auto it = input.begin(); it < input.end(); it++) {
        ++_map[*it];
    }
    return _map;
}

int main() {
    vector<int> input;
    int n=0, temp=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        input.push_back(temp);
    }
    long long result = 0;
    auto _map = countSame(input);
    for (auto& elem : _map) {
        if (elem.second >= 2) {
            result += ((long long)(elem.second) * (long long)(elem.second-1)) / 2;
            //cout << elem.first << "," << elem.second << endl;
        }
    }
    for (auto& elem : input) {
        int temp = _map[elem];
        cout << result - temp + 1 << endl;
    }
    
}


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

Measured memory_bytes: 1760
#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,c,d,i,j;
    char x[1001],y[10],z[1001];
    scanf("%s",&x);
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%s",&y);
        if(strcmp(y,"print")==0){
        scanf("%d%d",&b,&c);
            for(j=b;j<c+1;j++){
                putchar(x[j]);
            }
            puts("");
        }
        else if(strcmp(y,"reverse")==0){
        scanf("%d%d",&b,&c);
            for(j=0;j<c-b+1;j++){
                z[j]=x[c-j];
            }
            for(j=0;j<c-b+1;j++){
                x[b+j]=z[j];
            }
        }
        else if(strcmp(y,"replace")==0){
        scanf("%d%d%s",&b,&c,&z);
            for(j=0;j<c-b+1;j++){
                x[b+j]=z[j];
            }
        }
    }
    return 0;
}

Measured memory_bytes: 592
string = input()

c1 = True
c2 = True
c3 = True

if ("W" in string and not("E" in string)) or "E" in string and not("W" in string): c1 = False
    
if ("N" in string and not("S" in string)) or "S" in string and not("N" in string): c2 = False

if "N" in string and "S" in string and "E" in string and "W" in string:
    N = string.count("N")
    S = string.count("S")
    W = string.count("W")
    E = string.count("E")
    if not(N/S == W/E or N/S == E/W): c3 = False
    
if c1 and c2 and c3: print("Yes")
else: print("No")

Measured memory_bytes: 9056
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;


long long pgcd(long long a,long long b)
{
    return a==0?b:pgcd(b%a,a);
}

long long ppcm(long long a,long long b)
{
    return a*b/pgcd(a,b);
}

int main()
{
    long long a,b;
    while(cin>>a>>b)
    {
        cout<<pgcd(a,b)<<" "<<ppcm(a,b)<<endl;
    }
}

Measured memory_bytes: 1152
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$k = (int)$input[1];

if ($n % $k === 0) {
	$ret = 0;
} elseif ($n < $k) {
	$ret = min($n, $k - $n);
} else {
	$n = $n % $k;
	$ret = min($n, $k - $n);
}
echo $ret;

Measured memory_bytes: 4728
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
//ll const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

ll N;
ll a[300000];

int main(){
    cin>>N;
    rep(i,3*N) cin>>a[i];

    sort(a,a+3*N,greater<>());

    ll ans=0;
    rep(i,2*N){
        if(i&1) ans+=a[i];
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 5908
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    string mozi;
    for (int i = 0; i < n; ++i)
    {
        mozi = s[i];
    	if(a+b>0){
    		if(mozi=="a"){
                cout << "Yes" << endl;
                a--;
            }else if (mozi=="b" && b>0){
                cout << "Yes" << endl;
                b--;
            }else{
                cout << "No" << endl;   
            }
    	}else{
            cout << "No" << endl;
        }
    }
    // 出力
    return 0;
}

Measured memory_bytes: 896
use std::io;

fn main() {
    let _ = read_vec::<i32>();
    let mut a = read_vec::<i32>();
    let len = a.len();

    let count = merge_sort(&mut a, 0, len);
    print_vec(a);
    println!("{}", count);
}

pub fn merge(a: &mut [i32], left: usize, mid: usize, right: usize) -> usize {
    let mut count = 0;
    let mut l = a[left..mid].to_vec();
    let mut r = a[mid..right].to_vec();
    // 番兵の挿入
    l.push(std::i32::MAX);
    r.push(std::i32::MAX);
    let mut i = 0;
    let mut j = 0;
    for k in left..right {
        if l[i] <= r[j] {
            a[k] = l[i];
            i += 1;
        } else {
            a[k] = r[j];
            j += 1;
        }
        count += 1;
    }
    count
}

pub fn merge_sort(a: &mut [i32], left: usize, right: usize) -> usize {
    let mut count = 0;
    if left + 1 < right {
        let mid = (left + right) / 2;
        count += merge_sort(a, left, mid);
        count += merge_sort(a, mid, right);
        count += merge(a, left, mid, right);
    }
    count
}

/// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

fn print_vec<T: std::fmt::Display>(v: Vec<T>) {
    for a in &v[0..v.len() - 1] {
        print!("{} ", a);
    }
    println!("{}", v[v.len() - 1]);
}


Measured memory_bytes: 14220
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>

using namespace std;

int main() {
    int N,M; cin >> N >> M;
    vector<tuple<long, long>> data;
    long data_a,data_b;
    for (int i=0; i<N; i++) {
        cin >> data_a >> data_b;
        data.emplace_back( data_a, data_b );
    }
    sort( begin(data), end(data) );

    long result = 0;
    int pos = 0;
    while (M != 0) {
        if (M > get<1>(data[pos])) {
            result += get<0>(data[pos]) * get<1>(data[pos]);
            M -= get<1>(data[pos]);
        } else {
            result += get<0>(data[pos]) * M;
            M = 0;
        }
        pos++;
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
#include <queue>
#include <stack>
#include <cassert>
 

using namespace std;

char nth_letter(long long n)
{
    assert(n >= 1 && n <= 26);
    return "abcdefghijklmnopqrstuvwxyz"[n-1];
}

int main() {
    
    long long n;
    cin >> n;
    
    stack<char> s;
    long long ans=0;
    while(n>0){
        ans=n%26;
        if(ans==0){
            ans=+26;
        }
        s.push(nth_letter(ans));
        if(n%26==0){
            n=n/26;
            n=n-1;
        }
        else{
            n=n/26;
        }
    }
    while(!s.empty()){
        cout << s.top();
        s.pop();
    }
    return 0;
 }


Measured memory_bytes: 3644
import heapq
class Dijkstra:
    INF = 10**13
    threshold = 10**6+1

    def __init__(self, N):
        self.MAX_V = N + 1
        self.dist = [self.INF] * self.MAX_V
        self.G = [[] for _ in range(self.MAX_V)]

    def insert(self, X, Y, cost): self.G[X].append(cost * self.threshold + Y)

    def dijkstra(self, st):
        q = []
        heapq.heappush(q, st)
        self.dist[st] = 0

        while len(q):
            p = heapq.heappop(q)
            cost = p // self.threshold
            node = p - cost * self.threshold
            if cost > self.dist[node]: continue
            for to in self.G[node]:
                to_cost = to // self.threshold
                to_node = to - to_cost * self.threshold
                to_cost += self.dist[node]
                if self.dist[to_node] > to_cost:
                    self.dist[to_node] = to_cost
                    heapq.heappush(q, to_cost * self.threshold + to_node)

def main():
    h, w = map(int, input().split())
    sh, sw = map(int, input().split())
    eh, ew = map(int, input().split())

    sh -= 1
    sw -= 1
    eh -= 1
    ew -= 1

    S = [input() for _ in range(h)]

    di = Dijkstra(h*w)
    for x in range(h):
        for y in range(w):
            if S[x][y] == '#': continue
            for i in range(-2, 3):
                for j in range(-2, 3):
                    X = x + i
                    Y = y + j
                    if X < 0 or Y < 0 or X >= h or Y >= w or S[X][Y] == '#': continue
                    D = abs(i) + abs(j)

                    if D == 1: di.insert(x * w + y, X * w + Y, 0)
                    if D >= 2: di.insert(x * w + y, X * w + Y, 1)

    di.dijkstra(sh * w + sw)
    ans = di.dist[eh * w + ew]
    if ans == 10**13: print(-1)
    else: print(ans)

main()

Measured memory_bytes: 207444
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Reconciled solver = new Reconciled();
        solver.solve(1, in, out);
        out.close();
    }

    static class Reconciled {
        public static int MOD = 1_000_000_007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            boolean is_double = n == m;

            if (1 < Math.abs(n - m)) {
                out.println(0);
                return;
            }

            long result = 1;
            while (0 < n) {
                result *= n;
                result %= MOD;
                n--;
            }
            while (0 < m) {
                result *= m;
                result %= MOD;
                m--;
            }
            if (is_double) {
                result *= 2;
                result %= MOD;
            }
            out.println(result % MOD);
        }

    }
}



Measured memory_bytes: 35544
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://beta.atcoder.jp/contests/abc103/tasks/abc103_c>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll solve(){
    ll res = 0;
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    res = accumulate(a.begin(),a.end(),0LL) - N;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


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

const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
 
int main(){
	int H, W;
  	cin >> H >> W;
  
  	vector<string> s(H);
  	rep(i, H) cin >> s[i];
  	int ans = 0;
  
  	rep(si, H) rep(sj, W){
    	if(s[si][sj] == '#') continue;
      	vector<vector<int>> dist(H, vector<int>(W, INF));
      	queue<P> q;
      
      	auto update = [&](int i, int j, int x){
			if(dist[i][j] != INF) return;
          	dist[i][j] = x;
          	q.push(P(i, j));
        };
      
      	update(si, sj, 0);
      
      	while(!q.empty()){
        	int i = q.front().first;
          	int j = q.front().second;
          	q.pop();
          
          	rep(dir, 4){
            	int ni = i + di[dir], nj = j + dj[dir];
              	if(ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
              	if(s[ni][nj] == '#') continue;
              	update(ni, nj, dist[i][j] + 1);
            }
        }
      
      	rep(i, H) rep(j, W){
        	if(dist[i][j] == INF) continue;
          	ans = max(ans, dist[i][j]);
        }
    }
        
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AtCoder solver = new AtCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class AtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            for (int i = 0; ; i++) {
                if (i * i > n) {
                    out.println((i - 1) * (i - 1));
                    break;
                } else if (i * i == n) {
                    out.println(i * i);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 21844