akhauriyash/Code-Regression huggingface dataset:
/* # */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
int n, m, q;
vi li;
vvi quad;
ll ans(-1);

void recur(int start, int idx) {
    if (idx == n) {
        ll sum(0);
        for (int i = 0; i < q; i++) {
            if (li[quad[i][1]-1] - li[quad[i][0]-1] == quad[i][2])
                sum += (ll)quad[i][3];
        }
        if (ans < sum) ans = sum;
    }
    else {
        for (int i = start; i <= m; i++) {
            li[idx] = i;
            recur(i, idx + 1);
        }
    }
}

void sol() {
    cin >> n >> m >> q;
    li.resize(n);
    quad.assign(q, vi(4, 0));
    for (int i = 0; i < q; i++)
        for (int j = 0; j < 4; j++)
            cin >> quad[i][j];

    ans = -1;
    recur(1, 0);

    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
    int T(1);
    while (T--)
        sol();


    return 0;
}

Measured memory_bytes: 3172
a,b=list(map(int,input().split()))

sum=0
if a==1 and b == 1:
  sum += 400000
if a == 1:
  sum += 300000
elif a==2:
  sum += 200000
elif a==3:
  sum += 100000

if b == 1:
  sum += 300000
elif b==2:
  sum += 200000
elif b==3:
  sum += 100000

print(sum)

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var n, r int
	fmt.Scan(&n)
	var a []int
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			a = append(a, i)
			if i != n/i {
				a = append(a, n/i)
			}
		}
	}
	sort.Sort(sort.IntSlice(a))

	min := math.MaxInt64
	for i := 0; i < len(a); i++ {
		for j := i; j < len(a); j++ {
			if a[i]*a[j] == n {
				if min > a[j]+a[i] {
					r = (a[i] - 1) + (a[j] - 1)
					min = a[j] + a[i]
				}
			}
		}
	}
	fmt.Println(r)
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
void min_self(ll& x, ll y) {
	x = min(x, y);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, k;
	cin >> n >> k;
	vector<int> a(n + 1);
	a[0] = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i + 1];
	}
	vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(n + 1, vector<ll>(k + 1, inf64)));
	dp[1][1][0] = a[1];
	if (k != 0) {
		dp[1][0][1] = 0;
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < i; ++j) {
			for (int kk = 0; kk <= k; ++kk) {
				if (a[i] != a[j] && kk != k) {
					min_self(dp[i][j][kk + 1], dp[i - 1][j][kk]);
				}
				if (a[i] == a[j]) {
					min_self(dp[i][j][kk], dp[i - 1][j][kk]);
				}
				min_self(dp[i][i][kk], dp[i - 1][j][kk] + max(a[i] - a[j], 0));
			}
		}
	}
	ll answer = inf64;
	for (int j = 0; j <= n; ++j) {
		for (int kk = 0; kk <= k; ++kk) {
			min_self(answer, dp[n][j][kk]);
		}
	}
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 216832
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

signed main(){
    int n,m;
    cin>>n>>m;
    
    int t = 100*n+1800*m;
    
    double ans = 0;
    double pp = 1;
    rep(i,1000){
        ans += pp*1./(1LL<<(m))*((i+1)*t);
        pp -= pp*1./(1LL<<(m));
    }
    
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H-h) * (W-w) << endl;
    return 0;
}




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

using namespace std;

typedef long long ll;

pair<ll,ll> divmod(ll a,ll b)
{
	ll q=a/b,r=a%b;
	if(r<0){
		if(b>0)
			q--,r+=b;
		else
			q++,r-=b;
	}
	return pair<ll,ll>(q,r);
}

int main()
{
	for(ll x;cin>>x,x;){
		stack<int> d;
		while(x){
			auto qr=divmod(x,-10);
			d.push(qr.second);
			x=qr.first;
		}
		for(;!d.empty();d.pop())
			cout<<d.top();
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1200
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			ArrayList<Cake> cakes = new ArrayList<Cake>();
			String input = br.readLine();
			String[] nwd = input.split("[\\s]");
			int n = Integer.parseInt(nwd[0]);
			int w = Integer.parseInt(nwd[1]);
			int d = Integer.parseInt(nwd[2]);
			if (n == 0 && w == 0 && d == 0) {
				break;
			}
			Cake cake = new Cake(1, w, d);
			cakes.add(cake);
			for (int i = 0; i < n; i++) {
				Cake target = null;
				String line = br.readLine();
				String[] ps = line.split("[\\s]");
				int p = Integer.parseInt(ps[0]);
				int s = Integer.parseInt(ps[1]);
				/*
				 * for (Cake tmp : cakes) { if (p == tmp.getId()) { target =
				 * tmp; } }
				 */
				target = cakes.get(p - 1);
				Cake[] pieces = target.cut(s, i + 1);
				cakes.remove(target);
				cakes.add(pieces[0]);
				cakes.add(pieces[1]);
			}
			Collections.sort(cakes);

			System.out.print(cakes.get(0).getArea());
			for (int i = 1; i < cakes.size(); i++) {
				Cake tmp = cakes.get(i);
				System.out.print(" " + tmp.getArea());
			}
			System.out.println();
		}
	}
}

class Cake implements Comparable<Cake> {
	private int id;
	private int w;
	private int d;
	private int area;

	public Cake(int id, int w, int d) {
		this.id = id;
		this.w = w;
		this.d = d;
		this.area = w * d;
	}

	public Cake[] cut(int s, int i) {
		Cake[] pieces = new Cake[2];
		s %= (w + d) * 2;
		int aw = 0, ad = 0;
		int bw = 0, bd = 0;
		if (s < w) {
			aw = s;
			ad = d;
			bw = w - aw;
			bd = d;
		} else if (s < w + d) {
			aw = w;
			ad = s - w;
			bw = w;
			bd = d - ad;
		} else if (s < 2 * w + d) {
			aw = s - w - d;
			ad = d;
			bw = w - aw;
			bd = d;
		} else if (s < (2 * w + 2 * d)) {
			aw = w;
			ad = s - 2 * w - d;
			bw = w;
			bd = d - ad;
		}

		if (aw * ad < bw * bd) {
			pieces[0] = new Cake(i, aw, ad);
			pieces[1] = new Cake(i + 1, bw, bd);
		} else {
			pieces[0] = new Cake(i, bw, bd);
			pieces[1] = new Cake(i + 1, aw, ad);
		}
		return pieces;
	}

	public int getId() {
		return this.id;
	}

	public int getArea() {
		return this.area;
	}

	@Override
	public int compareTo(Cake c) {
		if (area < c.area) {
			return -1;
		} else if (area > c.area) {
			return 1;
		} else {
			return 0;
		}
	}
}

Measured memory_bytes: 45772
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

ss = list(input())
tt = list(input())
ss.sort()
tt.sort(reverse=True)
S = ''
T = ''
for s in ss:
	S = S + s
for t in tt:
	T = T + t

if S < T:
	print('Yes')
else:
	print('No')


Measured memory_bytes: 4204
import java.util.Scanner;
 
public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String S = scanner.next();
    long K = scanner.nextLong();
    char ans = '1';
    for(int i = 0; i < Math.min(S.length(), K); i++){
      if(S.charAt(i)!='1'){
        ans = S.charAt(i);
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
 
int main()
{
  int n,y;
  int ansi=-1,ansj=-1,ansk=-1;
  cin >> n >> y;
  for(int i=0; i<n+1; i++){
    for(int j=0; j<n+1-i; j++){
      if (10000*i+5000*j+1000*(n-i-j)==y){
	ansi=i;
	ansj=j;
	ansk=n-i-j;
      }
    }
  }
  cout<< ansi << " "<< ansj << " " << ansk <<endl;
}

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

#define MAXW 10010
using namespace std;
typedef long long int ll;

ll dp[MAXW];
int N, W, m, w, v, k, c;

inline void iterate(ll v, ll w) {
    for (int j = W; j >= w; --j) {
        dp[j] = max(dp[j - w] + v, dp[j]);
    }
}

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

    cin >> N >> W;

    for (int i = 0; i < N; ++i) {
        cin >> v >> w >> m;
        c = m >> 1;
        for (k = 0; (1 << k) <= c; ++k) {
            iterate(v * (1 << k), w * (1 << k));
        }
        c = m - ((1 << k) - 1);
        iterate(v * c, w * c);
    }

    cout << dp[W] << "\n";
    return 0;
}


Measured memory_bytes: 3268
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 土  6/23 21:24:06 2018

# Usage
#
"""
import math
import sys

def get_input():
    input_data = sys.stdin.readlines()
    N, K = input_data[0].split(" ")
    N = int(N)
    K = int(K)
    SEQ = [int(i) for i in input_data[1].split(" ")]

    assert len(SEQ) == N

    return N, K, SEQ

def get_minimum_distance(K, SEQ):
    """
    >>> get_minimum_distance(3, [2,3,1,4])  # doctest: +SKIP
    2
    >>> get_minimum_distance(3, [1,2,3])  # doctest: +SKIP
    1
    >>> get_minimum_distance(3, [7,3,1,8,4,6,2,5])

    """
    init_minimum_pos = SEQ.index(1)
    print("init:", init_minimum_pos)
    # 最小数値よりまずは右側をやっつける
    right_len = len(SEQ) - init_minimum_pos - 1 # because real num is -1 from index.
    operation_num_right = math.ceil(right_len / K)
    print("右に実施する回数", operation_num_right)
    right_adj = right_len % K

    left_len = SEQ.index(1)
    residual = left_len - right_adj
    operation_num_left = math.ceil(residual / K)

    print(operation_num_right+operation_num_left)


if __name__ == '__main__':
    N, K, SEQ = get_input()
    print(math.ceil((N-1)/(K-1)))


Measured memory_bytes: 13992
S = input()
n = len(S)
lcnt = 0
rcnt = 0
group = []
for i in range(n-1):
    #print(i,group)
    if S[i:i+2] == 'RL':
        if lcnt > 0:
            group[-1][2] = lcnt
            lcnt = 0
        rcnt += 1
        group.append([i,rcnt,0])
        rcnt = 0

    elif S[i] == 'R':
        rcnt += 1
        if lcnt > 0:
            group[-1][2] = lcnt
            lcnt = 0
    else:
        lcnt += 1
        
lcnt += 1
group[-1][2] = lcnt

#print(group)
        
ans = [0] * n
for item in group:
    i = item[0]
    ans[i] = (item[1]+1)//2 + item[2]//2
    ans[i+1] = item[1]//2 + (item[2]+1)//2
    
sout = ''
for num in ans:
    sout += str(num) + ' '
print(sout)

Measured memory_bytes: 11204
#include"bits/stdc++.h"
#include<valarray>

using namespace std;

#define MAX 210

int n;

vector<int> v[MAX];

bool vis[MAX];
vector<int> ret[MAX];
int ans;
bool ff[MAX];
inline int dfs(int b,int pr=-1,bool flag=false){
	vis[b]=true;
	ff[b]=flag;
	ret[b].push_back(0);
	ret[b].push_back(0);
	for(int go:v[b]){
		if(go==pr)continue;
		if(vis[go]){
			if(ff[go]==flag){
				puts("-1");
				exit(0);
			}
			continue;
		}
		ret[b].push_back(dfs(go,b,flag^true));
	}
	sort(ret[b].begin(),ret[b].end(),greater<int>() );
	ans=max(ans,ret[b][0]+ret[b][1]+1);
	return ret[b][0]+1;
}
int dist[MAX];

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		for(int j=0;j<n;j++){
			if(s[j]=='1'){
				v[i].push_back(j);
			}
		}
	}
	for(int i=0;i<n;i++){
		if(vis[i]==false){
			dfs(i);
		}
	}
	memset(vis,false,sizeof(vis));
	ans=0;
	for(int i=0;i<n;i++){
		memset(vis,false,sizeof(vis));
		queue<int> q;
		q.push(i);
		memset(dist,0,sizeof(dist));
		dist[i]=1;
		q.push(i);
		while(!q.empty()){
			int b=q.front();
			q.pop();
			for(int go:v[b]){
				if(dist[go]==0){
					dist[go]=dist[b]+1;
					q.push(go);
				}
			}
			ans=max(ans,dist[b]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>

using namespace std;

int main()
{
	int n, p[100000] = {}, i, tmp, c = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	for (;;) {
		for (i = 0; i < n; i++) {
			if (p[i] == i + 1) {
				if (i != n - 1) {
					tmp = p[i];
					p[i] = p[i + 1];
					p[i + 1] = tmp;
					c++;
					break;
				}
				else {
					tmp = p[i];
					p[i] = p[i - 1];
					p[i - 1] = tmp;
					c++;
					break;
				}
			}
		}
		if (i == n) {
			break;
		}
	}

	printf("%d\n", c);

	return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

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

    int n;
    string s;
    cin >> n >> s;

    REP(i, s.size()) {
        int x = (s[i] - 'A' + n) % 26 + 'A';
        cout << (char) x;
    }
    cout << endl;

    return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

int euclid(int a, int b)
{
    if (a < b)
        euclid(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    cin >> n;
    cout << n / 3 << endl;
}


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

int main(){
  string s;
  cin >> s;
  
  if(s[0] == 'A') cout << "T" << endl;
  else if(s[0] == 'T') cout << "A" << endl;
  else if(s[0] == 'G') cout << "C" << endl;
  else if(s[0] == 'C') cout << "G" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
using namespace std;
int main() {
	string arinasi;
	int price=700;
	cin >> arinasi;
	for (int i = 0; i < 3; i++) {
		if (arinasi[i] == 'o') {
			price += 100;
		}
	}
	cout << price<<endl;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// #include "segtree_push.h"

// del

struct less_key {
    bool operator() (const pair<i64, i64>& p1, const pair<i64, i64>& p2) {
        return p1.second < p2.second || (p1.second == p2.second && p1.first < p2.first);
    }
};

const i64 MAXN = 200005;

i64 n;
pair<i64, i64> a[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;
    for (i64 i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }

    sort(a, a + n, less_key());

    bool f = true;
    i64 ps = 0;
    for (i64 i = 0; i < n; i++) {
        ps += a[i].first;
        if (ps > a[i].second) {
            f = false;
            break;
        }
    }

    if (f) {
        cout << "Yes" << endl;
    }
    else { 
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3328
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for C - Half and Half
	var A, B, C int
	var X, Y int
	fmt.Scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y)

	var min = 1000000000
	for i := 0; i <= 100000; i++ {
		a := int(math.Max(0, float64(X-i)))
		b := int(math.Max(0, float64(Y-i)))
		cost := i*2*C + a*A + b*B
		if min > cost {
			min = cost
		}
	}

	fmt.Println(min)
}


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

F = [1] * (N//2 + 2)
for i in range(1, len(F)):
    F[i] = F[i] * 26

def check(l):
    D = set()
    for i in range(N - 2 * l + 1):
        D.add(S[i:i+l])
        if S[i+l:i+2*l] in D:
            return True

OK = 0
NG = N // 2 + 1

while abs(OK - NG) > 1:
    mid = (OK + NG) // 2
    if check(mid):
        OK = mid
    else:
        NG = mid

print(OK)

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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;
ll k;
ll a[210000];
ll b[210000];

int main() {
	scanf("%d%lld", &n, &k);
	++k;
	for (int i = 0; i < n; ++i)
		scanf("%lld%lld", a + i, b + i);
	ll ans = 0;
	for (int i = 0; i <= 30; ++i) {
		if (!((k >> i) & 1))
			continue;
		ll sum = 0;
		for (int j = 0; j < n; ++j) {
			ll x = (a[j] >> i);
			ll y = k >> i;
			if ((x & y) != x)
				continue;
			if ((a[j] >> i) & 1)
				continue;
			sum += b[j];
		}
		ans = max(ans, sum);
	}
	cout << ans << "\n";
	return 0;
}




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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	int n;
	cin >> n;
	long long res = 0;
	for (long long a = 1; a <= (int) 1e6; a++) {
		long long b = 1;
		while (a * b < n) {
			long long c = n - (a * b);
			if (c < 0) break;
			if ((a * b) + c == n) res++;
			b++;
		}
	}
	cout << res << "\n";
	return 0;
}


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

int main(){
  int n,q;ll k;cin >> n >> k >> q;
  vector<int> a(q),b(n,k-q);
  for(int i=0;i<q;i++)cin >> a[i];
  for(int i=0;i<q;i++){
    b[a[i]-1]++;
  }
  for(int i=0;i<n;i++){
    if(b[i]<=0){
      cout << "No" << endl;
    }else{
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(){
	char ch;
	while((ch = getchar()) != EOF){
			if(ch >= 97 && ch <= 122)
				printf("%c",ch-32);
			else if(ch >= 65 && ch <= 90)
				printf("%c",ch+32);
			else
				printf("%c",ch);
	}
}

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

int main(void) {
	char input_str[512];
	int rating, rank;

	fgets(input_str, sizeof(input_str), stdin);
	rating = atoi(input_str);

	if (1800 <= rating) {
		rank = 1;
	}
	else if (1600 <= rating) {
		rank = 2;
	}
	else if (1400 <= rating) {
		rank = 3;
	}
	else if (1200 <= rating) {
		rank = 4;
	}
	else if (1000 <= rating) {
		rank = 5;
	}
	else if (800 <= rating) {
		rank = 6;
	}
	else if (600 <= rating) {
		rank = 7;
	}
	else if (400 <= rating) {
		rank = 8;
	}

	printf("%d\n", rank);

	return 0;
}


Measured memory_bytes: 1664
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    n.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn print_vec_split_whitespace<T: std::fmt::Display>(a: &Vec<T>) {
    let len = (*a).len();
    for i in 0..len-1 {
        print!("{} ", (*a)[i]);
    }
    print!("{}\n", (*a)[len-1]);
}

fn bubble_sort(a: &mut Vec<u32>, n: usize) -> u32 {
    let mut flag = true;
    let mut counter = 0;
    while flag {
        flag = false;
        for j in (1..n).rev() {
            if (*a)[j] < (*a)[j - 1] {
                let tmp = a[j];
                (*a)[j] = (*a)[j - 1];
                (*a)[j - 1] = tmp;
                flag = true;
                counter += 1;
            }
        }
    }
    counter
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<u32>();

    let counter = bubble_sort(&mut a, n);
    print_vec_split_whitespace(&a);
    println!("{}", counter);
}


Measured memory_bytes: 5040
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 200010;
const int INF = INT_MAX/2;
const int mod = 1e9 + 7;

int n;
int nodes, edges;

int32_t main(){
	FAST
	cin >> n;
	
	for (int i =1; i<= n;i++) {
		nodes += i * (n - i + 1);
	}
	
	for (int i =0; i < n-1;i++) {
		int a,b; cin >> a >> b;
		if (a > b) swap(a,b);
		edges += a * (n - b + 1);
	}
	
	cout << nodes - edges;
	
}









Measured memory_bytes: 3676
#include <cstdio>

int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while (A[i] != key) i++;
  return i != n;
}

int main() {
  int i,n,A[10000+1],q,key,sum=0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++) scanf("%d", &A[i]);

  scanf("%d", &q);
  for ( i = 0; i < q; i++) {
    scanf("%d", &key);
    if (search(A, n, key) ) sum++;
  }
  printf("%d\n", sum);

  return 0;
}



Measured memory_bytes: 2744
N, M = map(int, input().split())
P = [1] * N
C = [''] * M
PY = [[] for i in range(M)]
for i in range(M):
  p, y = map(int, input().split())
  PY[i] = [y, p, i]
PY.sort()
for y, p, i in PY:
  C[i] = ('0' * 6 + str(p))[-6:] + ('0' * 6 + str(P[p - 1]))[-6:]
  P[p - 1] += 1
for c in C:
  print(c)

Measured memory_bytes: 32096
fn main() {
    let a = read::<String>().chars().collect::<Vec<_>>();
    let b = read::<String>().chars().collect::<Vec<_>>();
    if a.len() > b.len() {
        println!("GREATER");
        return;
    } else if a.len() < b.len() {
        println!("LESS");
        return;
    } else {
        for i in 0..a.len() {
            if a[i] > b[i] {
                println!("GREATER");
                return;
            } else if a[i] < b[i] {
                println!("LESS");
                return;
            } else {
                continue;
            }
        }
    }
    println!("EQUAL");
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
a = [int(input()) for i in range(5)]
k = int(input())
b = []

for i in range(5):
  for j in range(5):
    ans = abs(a[i] - a[j])
    b.append(ans)

c = 0
for i in b:
  if i > k:
    c += 1

if c == 0:
  print('Yay!')
else:
  print(':(')
  

Measured memory_bytes: 3060
def selmin(a, b); a <= b ? a : b; end

q, h, s, d = gets.split.map(&:to_i)
n = gets.to_i

h = [2 * q, h].min
s = [2 * h, s].min

if n == 1
  puts s
else
  d = 2 * s <= d ? 2 * s : d

  div, mod = n.divmod(2)
  puts d * div + s * mod
end


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

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  char s1[4], s2[4];
  scanf("%s %s", s1, s2);
  
  if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0])
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}



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

#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a.back() == b.front() && b.back() == c.front()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}



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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for (int i = 0; i < N; i++) {
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += l.at(N - 1 - i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<double> VD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void bad()
{
	cout << -1;
	exit(0);
}

const int N = 1 << 18;
int n;
int a[N];
int b[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	cin >> n;
	FOR(i, 0, n)
		cin >> a[i];
	FOR(i, 0, n)
		cin >> b[i];
	
	FOR(i, 0, n)
		if (a[i] > b[i])
			bad();
	
	int cnt_ok = 0;
	set<PII> s;	
	FOR(i, 0, n)
		if (a[i] == b[i])
			cnt_ok++;
		else
			s.insert({b[i], i});
	
	LL ans = 0;
	while(cnt_ok < n)
	{
		PII bg = *s.rbegin();
		s.erase(bg);
		
		int i = bg.Y;
		int l = (i - 1 + n) % n;
		int r = (i + 1) % n;
		
		if (SZ(s) == 0)
		{
			int sum = b[l] + b[r];
			int treba = b[i] - a[i];
			if (treba % sum == 0)
			{
				ans += treba / sum;
				break;
			}
			
			bad();
		}
		
		int sum = b[l] + b[r];
		if (b[i] - sum < a[i])
			bad();
			
		int k = INF;
		if (b[l] < b[i])
			k = min(k, (b[i] - b[l] + sum) / sum);
		if (b[r] < b[i])
			k = min(k, (b[i] - b[r] + sum) / sum);
			
		k = min(k, (b[i] - a[i]) / sum);
		
		ans += k;
		b[i] -= sum * k;
		
		if (a[i] < b[i])
			s.insert({b[i], i});
		else
			cnt_ok++;
	}
		
	cout << ans << endl;
		
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 11264
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,x,y,z;
	while(scanf("%d %d",&a,&b)!=EOF) {
		if(a>=b) {
			x=a;
			y=b;
		}
		else {
			x=b;
			y=a;
		}
		while(y!=0) {
			z=x%y;
			x=y;
			y=z;
		}
		c=a/x;
		d=b/x;
		e=c*d*x;
		printf("%d %d\n",x,e);
	}
	return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, m, n, valid, opt[50][500][500], a[50], b[50], c[50];

int main(){
  FAST_IO
  cin >> N >> m >> n;
  for(int rep = 1; rep <= N; ++rep) cin >> a[rep] >> b[rep] >> c[rep];

  for(int idx = 0; idx <= N; ++idx){
    for(int ca = 0; ca <= 400; ++ca){
      for(int cb = 0; cb <= 400; ++cb){
        opt[idx][ca][cb] = INF;
      }
    }
  }
  opt[0][0][0] = 0;

  for(int idx = 1; idx <= N; ++idx){
    for(int ca = 0; ca <= 400; ++ca){
      for(int cb = 0; cb <= 400; ++cb){
        int &util = opt[idx][ca][cb];
        util = opt[idx - 1][ca][cb];
        if(ca < a[idx] || cb < b[idx]) continue;
        min_self(util, opt[idx - 1][ca -a[idx]][cb - b[idx]] + c[idx]);
      }
    }
  }

  valid = INF;
  for(int ca = 1; ca <= 400; ++ca){
    for(int cb = 1; cb <= 400; ++cb){
      if(ca * n != cb * m) continue;
      min_self(valid, opt[N][ca][cb]);
    }
  }
      
  if(valid < INF) cout << valid << '\n';
  else cout << "-1\n";
  return 0;
}


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

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

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

using namespace std;

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

	long long int n,a,b;

	cin >> n >> a >> b;
	long long int hi = (n-1)*b + a;
	long long int lo = (n-1)*a + b;
	
	cout << max(0LL,hi-lo+1) << '\n';

	return 0;
}

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

//#define DEBUG

long long dist(long long M, long long N) {
	long long D;
	if (M<N) {
		D = M;
		M = N;
		N = D;
	}
	if (N==0) return 0;
	D = (M/N)*2*N;
	if (M%N==0) D -= N;
	return D+dist(N,M%N);
}

int main() {
	long long L, N, P, X;
	scanf("%lld%lld", &N, &X);
	if (2*X == N) L = 3*X;
	else L = N + dist(X,N-X);
/*	if (2*X < N) {
		L = X + (N-X) + X;
		P = N-2*X;
		L += X+dist(P,X);
	} else if (2*X == N) {
		L = 3 * X;
	} else {
		L = X;
		L += (N-X) + dist(X,N-X);
	}*/

	printf("%lld\n", L);
	return 0;
}


Measured memory_bytes: 128
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

s=input().rstrip()
q=deque()
for i in s:
    if i=="S":
        q.append(i)
    else:
        if len(q)==0:
            q.append(i)
        elif q[-1]=="T":
            q.append(i)
        else:
            q.pop()
   # print(q)
print(len(q))

Measured memory_bytes: 5092
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d;
  	cin >> a >> b >> c >> d;
  	if((a + b) > (c + d)){
      	cout << "Left" << endl;
    }else if((a + b) == (c + d)){
      	cout << "Balanced" << endl;
    }else{
      	cout << "Right" << endl;
    }
  	return 0;
}

Measured memory_bytes: 256
import collections

n=int(input())

a_list = list(map(int, input().split()))
#print(a_list)
c = collections.Counter(a_list)
#print(c)

values=list(c.values())
values.sort()
#print(values)

keys=list(c.keys())
keys.sort()
#print(keys)

ans="No"
if len(values)==3:
  if values[0]==values[1] and values[1]==values[2]:
    if keys[0] ^ keys[1]==keys[2]:
      ans="Yes"
  
if len(values)==2:
  if keys[0] == 0:
    if values[0]*2==values[1]:
      ans="Yes"

if len(values)==1:
  if keys[0] == 0:
      ans="Yes"

print(ans)



Measured memory_bytes: 60784
# GCD
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

# lのGCD
def gcdlist(l):
    res = l[0]
    for i in range(1,len(l)):
        res = gcd(res, l[i])
    return res

n = int(input())
res = 0

for i in range(1,n+1):
    for j in range(1,n+1):
        g = gcd(i,j)
        for k in range(1,n+1):
            res += gcd(g,k)
print(res)

Measured memory_bytes: 68092
#include <stdio.h>

int main(void)
{
	char s1[201];
	char s2[201];
	int check = 0;
	int i = 0 , j = 0;
	int count = 0;
	int count2;


	while (1) {
		scanf("%s", s1);
		if (s1[0]== '.')
			break;
		else {
			scanf("%s", s2);
			while (1) {
				if (check == 1) {	/* ""?????? */
					count2 = count;
					i++;
					j++;
					/*printf("1 %c %c\n\n", s1[i], s2[j]);
					getchar();*/

					for (; s1[i] != '"' || s2[j] != '"'; ){
						if (s1[i] == s2[j]) {}
						else {
							count++;
						}
						if (s1[i] != '"')
							i++;
						if (s2[j] != '"')
							j++;
						/*printf("3 %c %c\n", s1[i], s2[j]);
						printf("4 %d\n", count);*/
					}
					/*printf("5 %d %d\n", i, j);
					printf("6 %c %c\n\n", s1[i], s2[j]);
					printf("7 %d\n", count); */
					i++;
					j++;
					check = 0;
					if (count2 < count)
						count = count2 + 1;
					if (count > 2)
						break;
				}
				else {	/* ""?????? */
					for (; s1[i] != '\0' || s2[j] != '\0'; i++, j++) {
						if (s1[i] != s2[j]) {
							count += 2;
							break;
						}
						else {
							if (s1[i] == '"' && s2[j] == '"') {
								check = 1;
								break;
							}
							else {}
						}
					}
					if (s1[i] != s2[j])
						break;
					if (s1[i] == '\0' && s2[j] == '\0')
						break;
				}
			}

			/* ?????? */
			if (count == 0)
				printf("IDENTICAL\n");
			else if (count == 1)
				printf("CLOSE\n");
			else
				printf("DIFFERENT\n");

			/* ????????? */
			count = 0;
			for (i = 0; s1[i] != '\0'; i++)
				s1[i] = '\0';
			for (i = 0; s1[i] != '\0'; i++)
				s1[i] = '\0';
			check = 0;
			i = 0;
			j = 0;

		}
	}

	return 0;
}

Measured memory_bytes: 524
package main

import (
        "fmt"
)

func main () {
        var str string
        fmt.Scanf("%s", &str)
        show(len(str)-1, str)
}

func show(n int, str string) {
        if n == 0 {
                fmt.Printf("%s\n", string(str[n]))
        } else {
                fmt.Printf("%s", string(str[n]))
                show(n-1, str)
        }
}



Measured memory_bytes: 1088
import sys
from collections import Counter


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _ = _i()
    a = Counter(_ia())
    k = sorted(a.keys())
    m = max(k) + 1
    c = [False for i in range(m)]
    cnt = 0
    for ki in k:
        if c[ki]:
            continue
        if a[ki] == 1:
            cnt += 1
        for j in range(ki+ki, m, ki):
            c[j] = True

    return cnt


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 166920
n,q = map(int,input().split())
s = input()
word = list(s)
li = [list(input().split()) for _ in range(q)]
memo = {}

def dfs(m):
    k = m
    if m in memo:
        return memo[m]
    for t,d in li:
        if word[m] == t:
            if d == 'R':
                m += 1
            else:
                m -= 1
        if m < 0:
            memo[k] = 'Left'
            return 'Left'
        elif m > n-1:
            memo[k] = 'Right'
            return  'Right'
    memo[k] = True
    return True

def left(a,b):
    m = int((a+b)/2)
    if a == m:
        return b
    if dfs(m) == 'Left':
        return left(m,b)
    else:
        return left(a,m)

def right(a,b):
    m = int((a+b)/2)
    if a == m:
        return a
    if dfs(m) == 'Right':
        return right(a,m)
    else:
        return right(m,b)

if dfs(0) == 'Right':
    print(0)
elif dfs(0) == 'Left':
    if dfs(n-1) == 'Right':
        print(right(0,n-1) - left(0,n-1) + 1)
    elif dfs(n-1) == 'Left':
        print(0)
    else:
        print(n - left(0,n-1))
else:
    if dfs(b) == 'Right':
        print(right(0,n-1) + 1)
    elif dfs(b) == 'Left':
        print(0)
    else:
        print(n)


Measured memory_bytes: 28464
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n, m, x, minA = 10000000000000000;
    cin >> n >> m >> x;
    ll M[n][m + 1];
    for(int i = 0; i < n; i++)
        for(int j = 0; j <= m; j++)
            cin >> M[i][j];
    for(int i = 0; i < (1<<n); i++){
        ll s = 0, ans[m + 1], aux = 0;
        memset(ans, 0, sizeof ans);
        for(int j = 0; j < n; j++){
            if(i&(1<<j)){
                for(int k = 1; k <= m; k++)
                    ans[k] += M[j][k];
                aux += M[j][0];
            }
        }
        bool sw = true;
        for(int j = 1; j <= m; j++)
            if(ans[j] < x)
                sw = false;
        if(sw)
            minA = min(minA, aux);
    }
    if(minA == 10000000000000000)
        cout << "-1\n";
    else
        cout << minA << "\n";
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int sumDigits(int n)
{
	int sum = 0;
	while (n > 0)
	{
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main()
{
	int ansCount = 0;
	int N;
	int Alice = 0, Bob = 0;
	bool flag = true;

	cin >> N;
	
	vector<int> InVec;
	InVec.resize(N);

	for (auto &itr : InVec)
	{
		cin >> itr;
	}

	sort(InVec.begin(), InVec.end(), greater<int>());

	for (auto itr : InVec)
	{
		if (flag)
			Alice += itr;
		else
			Bob += itr;
		flag = !flag;
	}
	
	ansCount = Alice - Bob;
	
	cout << ansCount << endl;


	return 0;
}

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

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;

int main(){
    double x;
    while(scanf("%lf",&x), x != -1.0){
        double dp[100000]={0.0};
        dp[0] = x*0.5;
        int cnt = 0;
        while(abs(dp[cnt]*dp[cnt]*dp[cnt]) - x >= 0.00001*x){
            cnt++;
            dp[cnt] = dp[cnt-1] - (((dp[cnt-1])*(dp[cnt-1])*(dp[cnt-1])-x)/(3*(dp[cnt-1])*(dp[cnt-1])));
        }
        printf("%lf\n",dp[cnt]);
    }
	return 0;
}

Measured memory_bytes: 1232
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n; ll ans = 0;
    map<ll,ll>mp;
    for(i=1; i<=n; i++){
        cin>>v; ans+=v;
        mp[v]++;
    }
    cin>>q;

    while(q--)
    {
        cin>>x>>y;
        ans-=x*mp[x];
        ans+=y*mp[x];
        mp[y]+=mp[x];
        mp[x] = 0;

        cout<<ans<<endl;
    }

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 9448
#include<iostream>
using namespace std;
int main() {

	long long int sum = 0;
	string s;
	cin >> s;
	int i;
	int bin[10] = { 1,2,4,8,16,32,64,128,256,512 };
	int j;
	long long int k;
	for (i = 0; i < bin[s.size() - 1]; i++) {
		k = (s[0] - '0');
		for (j = 0; j < s.size() - 1; j++) {
			if ((i ^ bin[j]) == (i + bin[j])) {
				sum = sum + k;
				//cout << k << endl;
				k = (s[j + 1] - '0');
			}
			else {
				k = k * 10;
				k = k + (s[j + 1] - '0');
			}
		}
		sum = sum + k;
		//cout << k << endl;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3608
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b = instrm()

c = a+b

for i in range(1000):
    if i**2 == int(c):
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 62040
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    ifdef __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

vector<int> a, b, c, d;

int calc_ans(int q, vector<int> &A) {
    int ret = 0;

    for (int i = 0; i < q; i++) {
        if (c[i] == (A[b[i] - 1] - A[a[i] - 1])) {
            ret += d[i];
        }
    }

    return ret;
}

void rec(int n, int m, int q, int val, vector<int> A, int &ans) {
    A.push_back(val);

    if (A.size() == n) {
        // calc ans
        ans = max(ans, calc_ans(q, A));
        return;
    } else {
        for (int i = A[A.size() - 1]; i <= m; i++) {
            rec(n, m, q, i, A, ans);
        }
    }
}

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

    int n, m, q;
    cin >> n >> m >> q;
    int aa, bb, cc, dd;
    for (int i = 0; i < q; i++) {
        cin >> aa >> bb >> cc >> dd;
        a.push_back(aa);
        b.push_back(bb);
        c.push_back(cc);
        d.push_back(dd);
    }

    int ans = 0;
    for (int i = 1; i <= m; i++) {
        vector<int> A;
        rec(n, m, q, i, A, ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int[] count = new int[26];
		Scanner scan = new Scanner(System.in);
		do { //not false
			String str = scan.nextLine();
			for(int i=0;i < str.length(); i++) {
				if(str.charAt(i) - 'a' >= 0 && str.charAt(i) - 'a' < 26) {
					count[str.charAt(i) - 'a']++;
				}else if(str.charAt(i) - 'A' >= 0 && str.charAt(i) - 'A' < 26) {
					count[str.charAt(i) - 'A']++;
				}if(str.length() == 0) {
					break;
				}
			}
		}while(scan.hasNextLine());
		scan.close();
		String str2 = "abcdefghijklmnopqrstuvwxyz";
		for(int j=0; j<26; j++) {
			System.out.println(str2.charAt(j)+" : "+count[j]);
		}
	}
}


Measured memory_bytes: 26188
from collections import defaultdict
from math import sqrt

n, p = map(int, input().split())
h = defaultdict(int)
def factorization(arg):
    while arg % 2 == 0:
        h[2] += 1
        arg /= 2
    for i in range(3, int(sqrt(arg)) + 1, 2):
        while arg % i == 0:
            h[i] += 1
            arg /= i
    if arg > 1:
        h[arg] += 1
if p == 1:
    print(1)
elif n == 1:
    print(p)
else:
    factorization(p)
    ans = 1
    for k, v in h.items():
        while v >= n:
            ans *= k
            v -= n
    print(ans)

Measured memory_bytes: 3316
#include <iomanip>
#include <iostream>

int main() {
  int N, K;
  std::cin >> N >> K;

  double over_K = 0.0;

  double sum = 0.0;
  for (int i = 1; i <= N; ++i) {
    int v = i;
    double prov = 1.0;
    while (v < K) {
      prov *= 0.5;
      v *= 2;
    }
    sum += prov;
  }

  double result = sum / N;

  std::cout << std::setprecision(20) << result << std::endl;

  return 0;
}

Measured memory_bytes: 256