akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch  = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e3+5, P = 1e9+7;
struct Matrix
{
    int __[2][2];
    Matrix() { memset(__, 0, sizeof(__)); }
    int* operator [] (const int i) { return __[i]; }
    Matrix operator * (Matrix &_) const
    {
        Matrix ret;
        for(int i = 0; i < 2; ++i)
            for(int j = 0; j < 2; ++j)
                for(int k = 0; k < 2; ++k)
                    ret[i][j] = (ret[i][j]+1ll*__[i][k]*_[k][j]%P)%P;
        return ret;
    }  
    void set() { for(int i = 0; i < 2; ++i) __[i][i] = 1; }
}f;
Matrix qpow(Matrix a, int64 b)
{
    Matrix ret; ret.set();
    for( ; b; b >>= 1, a = a*a) if(b&1) ret = ret*a;
    return ret;
}
int n, m;
int64 k;
char s[N][N];
int p, q, a, b, c;
int main()
{
    n = read(), m = read(); scanf("%lld", &k);
    for(int i = 1; i <= n; ++i) scanf("%s", s[i]+1);
    for(int i = 1; i <= n; ++i) p += s[i][1]=='#'&&s[i][m]=='#';
    for(int i = 1; i <= m; ++i) q += s[1][i]=='#'&&s[n][i]=='#';
    if((p&&q)||k < 2) return puts("1"), 0; b = p|q;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
        {
            c += s[i][j] == '#';
            a += s[i][j] == '#'&&s[i][j+1] == '#'&&p;
            a += s[i][j] == '#'&&s[i+1][j] == '#'&&q;
        }
    f[0][0] = c, f[1][0] = a, f[1][1] = b; f = qpow(f, k-1);
    printf("%d\n", (f[0][0]-f[1][0]+P)%P);
    return 0;
}
/* 
3 3 2
.#.
###
#.#
*/

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

int d[110][110] = {};
int n, m, inf = 1e9 + 7, a[1010], b[1010], c[1010], ans;
bool used[1010];

void warshall_floyd(int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k < n; k++)
            {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i != j)
                d[i][j] = inf;
        }
    }
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }
    warshall_floyd(n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i == j)
                continue;
            for (int k = 0; k < m; k++)
            {
                if (d[i][a[k]] + c[k] + d[b[k]][j] == d[i][j] || d[i][b[k]] + c[k] + d[a[k]][j] == d[i][j])
                    used[k] = true;
            }
        }
    }
    for (int i = 0; i < m; i++)
    {
        ans += !used[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.Stream;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			String[] S = new String[N];
			for (int i = 0;i < N;++ i) S[i] = sc.next();
			for (String judge : new String[]{"AC", "WA", "TLE", "RE"}) {
				System.out.printf("%s x %d\n", judge, Arrays.stream(S).filter(judge::equals).count());
			}
		}
	}
}

Measured memory_bytes: 64632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const ll mod = 1e9 + 7;
const int n_max = 3030303;

ll fac[n_max];  /// fac[n] = n!
ll finv[n_max]; /// (fac[n] * finv[n]) % MOD = 1
ll inv[n_max];  /// (n * inv[n]) % MOD = 1

void init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR(i, 2, n_max)
    {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll nCk(int n, int k)
{
    if (n < k || k < 0 || n < 0)
        return 0;
    return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

int main()
{

    ll X, Y;
    cin >> X >> Y;

    if ((X+Y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    init();
    ll n = (X+Y)/3;
    if (X < Y) swap(X,Y);
    ll k = 1 + abs(Y - n);

    if ((n - (X - Y)) % 2 != 0)
    {
        cout << 0 << endl;
        return 0;
    }

    int b = (n - (X - Y)) / 2;
    int a = n - b;

    cout << nCk(a+b, a) << endl;
    return 0;
}


Measured memory_bytes: 71296
from itertools import product


def solve(string):
    n, *xyh = map(int, string.split())
    xyh = sorted([(x, y, h) for x, y, h in zip(xyh[::3], xyh[1::3], xyh[2::3])],
                 key=lambda x: x[-1], reverse=True)
    for i, j in product(range(101), range(101)):
        h = abs(xyh[0][0] - i) + abs(xyh[0][1] - j) + xyh[0][2]
        check = [_h == max(h - abs(_x - i) - abs(_y - j), 0) for _x, _y, _h in xyh[1:]]
        if all(check):
            return "{} {} {}".format(i, j, h)


if __name__ == '__main__':
    n = int(input())
    print(solve("{}\n".format(n) + '\n'.join([input() for _ in range(n)])))


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

int main() {
    int a, b;
    cin >> a >> b;

    int ans;
    if (a + b >= 24) {
        ans = a + b - 24;
    }
    else {
        ans = a + b;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#pragma 03
using namespace std;
ll mod = 998244353;
ll d[100005];
ll cnt[100005];
ll modpow(ll a, ll b){
	if (b == 0) return 1;
	else{
		ll x = modpow(a, b/2);
		if (b % 2 == 1) return (((x * x) % mod) * a) % mod;
		else return (x * x) % mod;
	} 
}
int main(){
	int n;
	cin >> n;
	ll maxdis = 0;
	for (int i = 0; i<n; i++){
		cin >> d[i];
		maxdis = max(maxdis, d[i]);
		cnt[d[i]]++;
	}
	if (d[0] != 0 || cnt[0] != 1){
		cout << 0;
		return 0;
	}
	if (n == 1){
		cout << 1;
		return 0;
	}
	ll mul = 1;
	for (int i = 1; i<=maxdis; i++){
		if (cnt[d[i]] == 0){
			cout << 0;
			return 0;
		}
		(mul *= modpow(cnt[i-1], cnt[i])) %= mod;
	}	
	cout << mul << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] freq = new int[26];
        for(int i = 0; i < s.length(); i++) {
        	char ch = s.charAt(i);
        	freq[ch - 'a']++;
        }

        for(int i = 0; i < freq.length; i++) {
            if(freq[i] % 2 != 0) {
                System.out.println("No");
                return;
            }
        }
		
        System.out.println("Yes");
    }
}

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

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s<t) cout << "Yes\n";
    else cout << "No\n";
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

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

int main() {
    ll N;
    cin >> N;
    unordered_set<char> hashSet;
    char c;
    for (int i = 0; i < N; ++i) {
        cin >> c;
        hashSet.insert(c);
    }
    if (hashSet.size() == 3) {
        cout << "Three" << endl;
    } else {
        cout << "Four" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
プロットする
*/

ll a,b,n;

int main(void){
	cin>>a>>b>>n;
	if(n>=b-1){
		cout<<(b-1)*a/b<<endl;
	}else{
		cout<<n*a/b<<endl;
	}
	return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<cassert>
#include<numeric>
typedef long long ll;
using namespace std;

int main(){
    ll A, B;   cin >> A >> B;
    ll aa = A;
    ll bb = B;
    int C;
    while(A%B>0){
        C = A%B;
        A = B;
        B = C;
    }
    cout << aa*bb/B;
}

Measured memory_bytes: 3556
N = int(input())
Q = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*3 for i in range(N)]
dp[0][0] = Q[0][0]
dp[0][1] = Q[0][1]
dp[0][2] = Q[0][2]

for i in range(1, N):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + Q[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + Q[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + Q[i][2]
print(max(dp[-1]))

Measured memory_bytes: 74712
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*(n+1)
        self.rnk=[0]*(n+1)

    def Find_Root(self,x):
        if self.root[x]<0:
            return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)
        if x==y:
            return
        elif self.rnk[x]>self.rnk[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y
            if self.rnk[x]==self.rnk[y]:
                self.rnk[y]+=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

h,w=map(int,input().split())
g=[list(input()) for _ in range(h)]
uf=UnionFind(h*w)
dyx=[(1,0),(-1,0),(0,1),(0,-1)]
for i in range(h):
    for j in range(w):
        if g[i][j]==".":
            continue
        p=i*w+j
        for dy,dx in dyx:
            y=i+dy
            x=j+dx
            if 0<=y<h and 0<=x<w:
                if g[y][x]==".":
                    np=y*w+x
                    uf.Unite(p,np)

rt=[0]*(h*w)
for i in range(h*w):
    rt[i]=uf.Find_Root(i)

m=min(rt)
rt=list(map(lambda x:x-m, rt))
m=max(rt)
a=[[0,0] for _ in range(m+1)]
for i in range(h*w):
    y=i//w
    x=i%w
    if g[y][x]=="#":
        a[rt[i]][0]+=1
    else:
        a[rt[i]][1]+=1
ans=0
for i,j in a:
    ans+=i*j

print(ans)


Measured memory_bytes: 33084
# coding: utf-8
import os
import time
import re
import math


N = int(input())
SP=[]
for a in range(N):
    temp=input().split()
    SP.append([temp[0],int(temp[1]),(a+1)])
#SP=list(map(lambda x: x[0], SP))
SP=sorted(SP, key=lambda x: (x[0],-x[1]))
for a in range(N):
    print(SP[a][2])

Measured memory_bytes: 3184
/*
https://muttan1203.hatenablog.com/entry/ALDS_1_4_D
*/
#include<iostream>

using ull = unsigned long long;
using ui = unsigned int;

int main() {
	ui n, k;
	int w[100'001];

	std::cin >> n >> k;
	for (ui i{}; i < n; ++i)
		std::cin >> w[i];

	auto check = [&](auto p) -> bool{
		ull sum{};
		ui index{};

		//k台分調べる
		for (ui i{}; i < k; ++i) {
			sum = 0;
			while (w[index] + sum <= p) {//もう一個積めるなら
				sum += w[index];//積んでいく
				index++;

				if (index == n)
					return true;//積み切った
			}
		}

		return false;//積み切れない=> pが足りない
	};


	ull left{}, right{10'000*100'000+1};
	while (right - left > 1) {
		ull mid = (right + left)/2;
		if (check(mid))
			right = mid;
		else
			left = mid;
	}

	std::cout << right << "\n";

	return 0;
}



Measured memory_bytes: 3476
#include <cstdio>

using namespace std;

int a[500000];
int b[500000];
int c[500000];

int main() {
    int n, d, q, i;
    
    scanf("%d %d", &n, &d);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    b[0] = d;
    
    for (i = 0; i < n - 1; i++) {
        if (a[i] < d * 2) {
            d -= a[i];
            if (d < 0) d = -d;
        }
        
        b[i + 1] = d;
    }
    
    for (i = n - 2; i >= 0; i--) {
        if (a[i + 1] > c[i + 1] * 2 + 1) {
            c[i] = c[i + 1];
        } else {
            c[i] = c[i + 1] + a[i + 1];
            if (c[i] > 1e9) c[i] = 1e9;
        }
    }
    
    scanf("%d", &q);
    
    for (i = 0; i < q; i++) {
        int x;
        
        scanf("%d", &x);
        
        x--;
        
        if (b[x] <= c[x]) {
            puts("NO");
        } else {
            puts("YES");
        }
    }
    
    return 0;
}


Measured memory_bytes: 7680
#include<cstdio>
#include<cstdlib>
#include<cstring>
int n;
char s[100010];

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	if (s[n]=='1' || s[1]=='0')
	{
		printf("-1\n");
		return 0;
	}
	for (int i=2;i<=n/2;i++)
		if (s[i]!=s[n-i])
		{
			printf("-1\n");
			return 0;
		}
	int x=1;
	printf("1 2\n");
	for (int i=2;i<n;i++)
	{
		printf("%d %d\n",x,i+1);
		if (s[i]=='1') x=i+1;
	}
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    long long n;
    cin >> n;
    
    string s = "";
    while(n) {
        n--;
        s += 'a' + (n%26);
        n /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
}


Measured memory_bytes: 3656
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	d := map[int]bool{}
	for i := 0; i < N; i++ {
		d[nextInt()] = true
	}
	fmt.Println(len(d))
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

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

	int len = (int) S.size();
	int l = (len - 1) / 2;
	int r = l + (len%2 == 0);
	int b = S[l];
	while(l>=0 and r<len and S[l]==b and b== S[r]){
		l -= 1;
		r += 1;
	}

	cout << len - l - 1 << '\n';

	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
// 2020-08-22 16:51:59
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const int MX = 1010;
int n, m, nxt[MX];
vector<int> G[MX];

int build_cycle(int u) {
  if(nxt[u] >= 0) return u;
  for(const int v : G[u]) {
    nxt[u] = v;
    int res = build_cycle(v);
    if(res >= 0) return res;
  }
  nxt[u] = -1;
  return -1;
}

int update(int s) {
  int u = s;
  do {
    for(const int v : G[u]) {
      if(nxt[u] != v && nxt[v] >= 0) {
        nxt[nxt[u]] = -1;
        nxt[u] = v;
        return v;
      }
    }
    u = nxt[u];
  } while(u != s);
  return -1;
}

void answer() {
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
  }
  int s = -1;
  rep(i, n) {
    memset(nxt, -1, sizeof nxt);
    s = build_cycle(i);
    if(s >= 0) break;
  }
  if(s == -1) {
    cout << -1 << '\n';
    return;
  }
  int t = s;
  while((t = update(t)) != -1) s = t;
  vector<int> ans;
  int u = s;
  do {
    ans.push_back(u);
    u = nxt[u];
  } while(u != s);
  cout << ans.size() << '\n';
  for(const auto i : ans) cout << i+1 << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3744
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  int a,b,c,ans=0;
  scanf("%d %d %d",&a,&b,&c);
  for(int i=0;i<c;i+=a){
    ans++;
    if(ans%7<1)i+=b;
  }
  PRN(ans);
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>

using namespace std;

int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    int x = (N + A - 1) / A * B;
    int y = (N + C - 1) / C * D;

    cout << min(x, y) << endl;
}


Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		boolean plus = true;
		int first = 0;
		for (int i = 0; i < input.length; i++) {
			input[i] = sc.nextInt();
			if (plus) {
				first += input[i];
			} else {
				first -= input[i];
			}	
			plus = !plus;
		}
		System.out.print(first + " ");
		for (int i = 0; i < input.length - 1; i++) {
			System.out.print((input[i] - first / 2) * 2 + " ");
			first = (input[i] - first / 2) * 2;
		}
	}
}

Measured memory_bytes: 63504
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
double pi = 3.14159265358979;

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

    double a, b, h, m;
    cin >> a >> b >> h >> m;
    h += m / 60.0;
    h *= 5.0;

    double theta = 2.0 * pi * abs(h - m) / 60.0;
    double ans = a * a + b * b - 2.0 * a * b * cos(theta);

    cout << fixed << setprecision(12) << sqrt(ans) << "\n";
    return 0;
}

Measured memory_bytes: 4260
Q,H,S,D=map(int,raw_input().split())
N=input()
a=min([Q*4,H*2,S])
b=float(D)/2

ans=0
if b<a:
	ans+=N/2*D
	amari=N%2
	ans+=amari*a
else:
	ans=N*a
print ans


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define print(x) cout << x;
#define println(x) cout << x << endl;
#define printd(x, f) cout << fixed << setprecision(f) << x << endl;

#define PB push_back
#define MP make_pair
#define F first
#define S second

#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PI acos(-1.0)

int main()
{
  int x, y, z; cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;;
  return 0;
}


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

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

    vector<bool> is_prime(n + 1, true);
    vector<int> primes;
    auto init = [&](){
        is_prime[0] = is_prime[1] = false;
        for (long long int i = 2; i <= n; i++){
            if (is_prime[i]){
                for (long long j = i * i; j <= n; j += i){
                    is_prime[j] = false;
                }
                
                primes.push_back(i);
            }
        }
    };

    init();

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

    int gcd = 0;
    for (auto g: a)
        gcd = __gcd(gcd, g);

    if (gcd != 1){
        cout << "not coprime\n";
        return 0;
    }

    unordered_set<int> s;
    
    auto factorization = [&](int x, vector<int> &fact){
        for (auto p: primes){
            if (p * p > x)
                break;

            if (x % p == 0){
                while (x % p == 0){
                    x /= p;
                }
                fact.push_back(p);
            }
        }

        if (x != 1)
            fact.push_back(x);
    };

    for (auto i: a){
        vector<int> fac;
        
        factorization(i, fac);
        for (auto f: fac){
            if (s.find(f) != s.end()){
                cout << "setwise coprime\n";
                return 0;
            }
            s.insert(f);
        }
    }

    cout << "pairwise coprime\n";

    return 0;
}


Measured memory_bytes: 7800
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if(A==B && A!=C)
        printf("Yes\n");
    else if(A==C && A!=B)
        printf("Yes\n");
    else if(B==C && B!=A)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


void solve(LL N, vector<LL> a){
	LL ans = 0;
	LL prev = 0;
	REP(i, N) {
		if (i == 0) {
			prev = a[i];
		} else {
			if (a[i] == prev) {
				ans += 1;
				prev = 0;
			} else {
				prev = a[i];
			}
		}
	}
	cout << ans << endl;
}


int main(){	
	LL N;
	scanf("%lld",&N);
	vector<LL> a(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, a);
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int cnt[26];
int main()
{
	int N;
	string S;
	cin >> N >> S;
	for (int i = 0; i < N; i++) {
		cnt[S[i] - 'a']++;
	}
	ll ans = 1;
	for (int i = 0; i < 26; i++) {
		ans = (ans * (cnt[i] + 1)) % mod;
	}
	cout << ans - 1 << endl;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
using llong = long long;

void fnInput(llong& rnNum)
{
  cin >> rnNum;
}

void fnNumToName(llong nNum)
{
  const int cnnDivisor = 26;
  vector<int> vnRemain;
  llong nDividend = nNum;

  while ( nDividend )
  {
    llong nQuotent = nDividend / cnnDivisor;
    int nRemain = nDividend % cnnDivisor;
    if (!nRemain)
    {
      vnRemain.push_back( cnnDivisor );
      nQuotent--;
    }
    else
      vnRemain.push_back( nRemain );

    nDividend = nQuotent;
  }
  reverse(begin(vnRemain), end(vnRemain));

  for (int nRemain : vnRemain)
    cout << (char)('a' + nRemain - 1);

  cout << endl;
}
  
int main()
{
  llong nNum;
  fnInput(nNum);
  fnNumToName(nNum);

  return 0;
}

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

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

bool solve() {
	ll A, B, C, D; cin >> A >> B >> C >> D;
	if (A < B) return false;
	if (B > D) return false;
	if (B <= C+1) return true;
	ll G = gcd(B, D);
	ll AM = A % G;
	ll ma = B - G + AM;
	return ma <= C;
}

int main() {
	int Q; cin >> Q;
	while (Q--) {
		if (solve()) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, a, b;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
    int n,k;
    cin>>n>>k;
    VI h(n);
    int cnt=0;
    rep(i,n){
        cin>>h[i];
        if(h[i]>=k){
            cnt++;
        }
    }
    cout<<cnt<<endl;


 }



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

using namespace std;

typedef long long ll;
typedef long double ld;

struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

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

    int n;
    int q;
    cin >> n >> q;
    dsu d(n);
    while (q--)
    {
        int tp, x, y;
        cin >> tp >> x >> y;
        if (tp == 0)
        {
            d.merge(x, y);
        }
        else
        {
            cout << (d.leader(x) == d.leader(y)) << "\n";
        }
    }
}


Measured memory_bytes: 3928
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int x, a, b; cin >> x >> a >> b;
    x -= a;
    while(x - b >= 0) x -= b;
    cout << x << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdexcept>
using namespace std;


#define abs(N) ((N>0)?N:-1*N)
#define lt(A,B) ((A>B)?B:A)
#define gt(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)


struct Node{
	Node *prev,*next;
	long long key;
};

Node *nil;


void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next=nil;
	nil->prev=nil;
	nil->key=-1;
}

Node *linearSearch(long long key){
	Node *cur = nil->next;
	while(cur != nil && cur->key != key){
		cur = cur->next;
	}

	return cur;
}

void insert(long long key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
//	if(nil->next==nil){
//		nil->next = x;
//		nil->prev = x;
//		x->next = nil;
//		x->prev = nil;
//	}else{
		x->next = nil->next;
		nil->next->prev=x;
		nil->next = x;
		x->prev = nil;
//	}
		return;
}

void del(Node *x){
	if(x==nil) return;
	x->prev->next = x->next;
	x->next->prev = x->prev;
	free(x);
}

void delByKey(long long key){
	del(linearSearch(key));
}

void delFirst(){
	del(nil->next);
}

void delLast(){
	del(nil->prev);
}

void printList(){
	Node *cur = nil->next;
	while(cur != nil){
		if(cur->prev != nil)
			printf(" ");
		printf("%d",cur->key);
		cur = cur->next;
	}
	printf("\n");
	return;
}

int main(){
	int n ;

	cin >> n;
	init();
	char cmd[1000];
	long long arg;
	for (int i = 0; i < n; ++i) {
		scanf("%s%d",cmd,&arg);
		if(cmd[0]=='i'){
			insert(arg);
		}else if(strlen(cmd)==6){
			delByKey(arg);
		}else if(cmd[6]=='F'){
			delFirst();
		}else if(cmd[6]=='L'){
			delLast();
		}
//		printList();
	}
	printList();

	return 0;
}



Measured memory_bytes: 34376
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sa = [0]
for i in range(n):
    sa.append(sa[-1] + a[i])
sb = [0]
for i in range(m):
    sb.append(sb[-1] + b[i])

ans = []
for i in range(n+1):
    if k < sa[i]:
        break
    goal = k - sa[i]

    # Binary Search
    start = 0
    stop = m
    while start < stop:
        center = (start + stop + 1) // 2
        if sb[center] == goal:
            start = center
            stop = center
        elif sb[center] < goal:
            start = center
        else:
            stop = center - 1
    
    ans.append(i + start)

print(max(ans))

Measured memory_bytes: 50652
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main { 
	public static void main(String[] args) throws Exception { 
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;
		/*while((line = in.readLine()) != null){
			int i = Integer.parseInt(line.split(" ",0)[0]);
			int j = Integer.parseInt(line.split(" ",0)[1]);
			System.out.println(i+j/2);
		}}*/
	
		line = in.readLine();
			int i = Integer.parseInt(line.split(" ",0)[0]);
			int j = Integer.parseInt(line.split(" ",0)[1]);
			System.out.println(i+j/2);
		}
	}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
vector<string> G;
vector<vector<int>> R;
vector<vector<int>> A;
int num = 0;

void dfs(int x, int y, int h, int w, int keep) {
    if (keep == 1) {
        num++;
        rep(i,h) rep(j,w) R[y+i][x+j] = num;
        return;
    }

    //int berry = A[y+h][x+w] - A[y][x+w] - A[y+h][x] + A[y][x];

    int ph = 0, pw = 0;
    int berry;
    int vertical = true;

    int h1 = 0, h2 = 0, w1 = 0, w2 = 0;
    do {
        pw++;
        w1 = A[y+h][x+pw] - A[y][x+pw] - A[y+h][x] + A[y][x];
        w2 = keep - w1;
    } while (pw < w && (w1 == 0 || w2 == 0));
    do {
        ph++;
        h1 = A[y+ph][x+w] - A[y][x+w] - A[y+ph][x] + A[y][x];
        h2 = keep - h1;
    } while (ph < h && (h1 == 0 || h2 == 0));
    if (h1 > 0 && h2 > 0 && w1 > 0 && w2 > 0) {
        vertical = (h > w);
    } else if (h1 > 0 && h2 > 0) vertical = true;
    else if (w1 > 0 && w2 > 0) vertical = false;

    if (vertical) {
        berry = h1;
        assert(berry != 0);
        dfs(x, y, ph, w, berry);
        assert(berry != 0);
        dfs(x, y + ph, h-ph, w, abs(keep - berry));
    } else {
        berry = w1;
        assert(berry != 0);
        dfs(x, y, h, pw, berry);
        assert(berry != 0);
        dfs(x + pw, y, h, w-pw, abs(keep - berry));
    }
}

int main() {
    int H, W, K; cin >> H >> W >> K;
    int num = 0;
    if (H*W == K) {
        rep(i,H) {
            rep(j,W) {
                cout << ++num; 
                if (j != W-1) cout << " ";
            }
            cout << endl;
        }
        return 0;
    }
    G.assign(H, "");
    rep(i,H) cin >> G.at(i);
    R.assign(H, vector<int>(W,0));
    A.assign(H+1, vector<int>(W+1,0));

    rep(i,H) {
        int cnt = 0;
        rep(j,W) {
           if (G[i][j] == '#') cnt++;
           A[i+1][j+1] = cnt;
        }
    }

    //     ↓ 二度目(縦方向)では0からWまで回す必要がある！！
    rep(i,W+1) rep(j,H) A[j+1][i] += A[j][i];

    dfs(0, 0, H, W, K);
    rep(i,H) {
        rep(j,W) {
            cout << R[i][j];
            if (j != W-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 4520
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;

int  ar[ms]={0};


int main()
{
    idfc;
    string s;
    cin>>s;
    int n=s.length();
    int i;
    int a=0;
    int b=0;
    int m;

    for(i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            if(b)
            {
                a=0; b=0;
                a++;
            }
            else{
                a++;
            }
        }
        else{
            b++;
            m=a+b;
            if(m%2)
            {
                ar[i-b]=m/2;
                ar[i+1-b]=m/2;
                if(a%2)ar[i-b]++;
                else ar[i+1-b]++;
            }
            else{
             ar[i-b]=m/2;
             ar[i+1-b]=m/2;
            }
        }
    }
    for(i=0;i<n;i++)cout<<ar[i]<<" ";
    return 0;
}

Measured memory_bytes: 4144
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	vector<vector<int> > imos(5010, vector<int>(5010, 0));
	REP(i, m){
		int a, b, x;
		scanf("%d%d%d", &a, &b, &x);
		a--; b--;
		
		imos[a][b]+=1;
		imos[a][b+1]-=1;
		imos[a+x+1][b]-=1;
		imos[a+x+1][b+x+2]+=1;
		imos[a+x+2][b+1]+=1;
		imos[a+x+2][b+x+2]-=1;
	}
	
	REP(i, n+5){
		REP(j, n+5){
			if(j>0) imos[i][j]+=imos[i][j-1];
		}
	}
	
	REP(i, n+5){
		REP(j, n+5){
			if(i>0) imos[i][j]+=imos[i-1][j];
		}
	}
	
	REP(i, n+5){
		REP(j, n+5){
			if(i>0 && j>0) imos[i][j]+=imos[i-1][j-1];
		}
	}
	
	int ans=0;
	REP(i, n+5){
		REP(j, n+5){
			if(imos[i][j]>0) ans++;
		}
	}
	
	printf("%d\n", ans);
}

Measured memory_bytes: 99208
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	using data=pair<ll,int>;
	int X,Y;
	cin>>X>>Y;
	vector<data> p;
	rep(i,X){
	    ll t;
	    cin>>t;
	    p.emplace_back(t,0);
	}
	rep(i,Y){
	    ll t;
	    cin>>t;
	    p.emplace_back(t,1);
	}
	sort(all(p));
	int usex=0,usey=0;
	ll ans=0;
	for(auto&d:p){
	    ll cost; int xy;
	    tie(cost,xy)=d;
	    if(xy==0){
    	    ans+=cost*(Y+1-usey);
    	    usex++;
	    }else{
    	    ans+=cost*(X+1-usex);
    	    usey++;
	    }
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6512
#include<iostream>
#include<math.h>
#include <stdlib.h>

void listen_nums(int &a,int &b);

int calc_digit(const int num);

int main()
{
	int a,b;
	
	for(;1;)
	{
		listen_nums(a,b);
		int sum=a+b;
		std::cout<<calc_digit(sum)<<std::endl;
	}
	
	return 0;
}

void listen_nums(int &a,int &b)
{
	using namespace std;
	cin>>a>>b;
	
	if(cin.eof())
	{
		exit(0);
	}
}

int calc_digit(const int num)
{
	return (int)log10((double)num)+1;
}
	

Measured memory_bytes: 1204
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int N = 1e5 + 7;

int p[N], r[N];

int get(int v) {
    if (v == p[v])
        return v;
    return p[v] = get(p[v]);
}

void unite(int u, int v) {
    u = get(u);
    v = get(v);
    if (u == v)
        return;
    if (r[u] < r[v])
        swap(u, v);
    p[v] = u;
    r[u] += r[v];
}

void solve() {
    loop1(i, N - 1) {
        p[i] = i;
        r[i] = 1;
    }
    int n, m; 
    cin >> n >> m;
    loop(i, m) {
        int u, v, usls;
        cin >> u >> v >> usls;
        unite(u, v);
    }
    set <int> s;
    loop1(i, n)
        s.insert(get(i));
    cout << s.size();
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 8972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,end) for(ll i = 0; i < end ; i++ )
#define print(ans) cout << fixed << setprecision(15) << ans << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N,K,Q, ans = 0;
string S;
bool flag = true;


int main() {
  cin >> N >> K >> Q;
  vector<ll> B(N);
  ll a;
  rep(i, Q){
    cin >> a;
    B[a-1] ++;
  }
  rep(i,N){
    if (B[i] - Q + K > 0){
      yes;
    }
    else{
      no;
    }
  }
}




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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

ll f(ll n, ll p) {
  ll ret = 0;
  if (n == 0) return 0;
  ll t = n%p;
  ret += f(t, __builtin_popcountll(t));
  return ret + 1;
}

int main()
{
  ll n; cin >> n;
  string s; cin >> s;

  ll d = 0;
  for (int i=0; i<n; i++) {
    if (s[i] == '1') d++;
  }

  ll a = d-1;
  ll b = d+1;

  vector<ll> x(n, 1);
  vector<ll> y(n, 1);
  rep(i, n-1) {
    if (a > 0) x[n-i-2] = (x[n-i-1]*2) % a;
    if (b > 0) y[n-i-2] = (y[n-i-1]*2) % b;
  }

  ll xx = 0;
  ll yy = 0;
  rep(i, n) {
    if (s[i] == '1') {
      xx += x[i]; yy += y[i];
    }
  }

  for (int i=0; i<n; i++) {
    if (s[i] == '1') {
      if (a <= 0) {
        cout << 0 << endl;
        continue;
      }
      ll t = (xx + a - x[i]) % a;
      ll ans = f(t, __builtin_popcountll(t)) + 1;
      cout << ans << endl;
    } else {
      ll t = (yy + y[i]) % b;
      ll ans = f(t, __builtin_popcountll(t)) + 1;
      cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 6808
var stdin = require("fs").readFileSync("/dev/stdin", "utf8");
stdin = stdin.trim().split("\n").reverse();
function input(){return stdin.pop()}
var stdout = [];


var tmp = input().split(" ").map(n=>parseInt(n));
var t = tmp[0];
var x = tmp[1];
stdout.push(t / x);


stdout = stdout.join(" ");
console.log(stdout);

Measured memory_bytes: 22084
def main():
    s = input()

    i = 0
    is_ok = True
    while i < len(s):
        if i <= len(s) < i + 7:
            if i <= len(s) < i + 4:
                is_ok = False
                break

        next_word = s[i:i+5]
        if next_word == 'dream':
            if s[i+5:i+7] == 'er':
                if s[i+7:i+8] == 'a':
                    # dream
                    i += 5
                else:
                    # dreamer
                    i += 7
            else:
                # dream
                i += 5
        elif next_word == 'erase':
            if s[i+5:i+6] == 'r':
                # eraser
                i += 6
            else:
                # erase
                i += 5
        else:
            is_ok = False
            break

    if is_ok:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;


int main()
{
    int n; 
    cin >> n;
    int a[n];
    int f = 0, t = 0;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        if(tmp % 4 == 0){
            f++;
        }else if(tmp % 2 == 0){
            t++;
        }
    }
    if(t > 1){
        n -= (t-1);
    }
    if((n/2) <= f){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var d = Console.ReadLine().Split(' ').Select(int.Parse);
            var sd = d.OrderBy(x => x).ToArray();
            Console.WriteLine(sd[n / 2] - sd[n / 2 - 1]);
        }
    }
}


Measured memory_bytes: 20064
#include <cstdio>

#define N	5

int main()
{
	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		int pts;

		::scanf("%i", &pts);

		sum += (pts < 40 ? 40 : pts);
	}

	::printf("%i\n", sum / N);
}

Measured memory_bytes: 1028