akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template<unsigned long long SIZE> class unionFind{
    protected:
        long long uni[SIZE];
        long long diff_weight[SIZE];
    public:
        unionFind(){
            for(int i=0;i<SIZE;i++){
                uni[i]=-1;
                diff_weight[i]=0;
            }
        }
        unsigned long long root(unsigned long long a){
            if(a>=SIZE) throw std::range_error("与えられたインデックスが木の範囲外です");
            if(uni[a]<0) return a;
            else{
                unsigned long long r=root(uni[a]);
                diff_weight[a]+=diff_weight[uni[a]];
                return uni[a]=r;
            }
        }
        long long weight(unsigned long long a){
            root(a);
            return diff_weight[a];
        }
        long long diff(unsigned long long a, unsigned long long b){
            if(isSame(a,b)) return weight(b)-weight(a);
            else return INT64_MAX;
        }
        unsigned long long count(unsigned long long a){
            return -uni[root(a)];
        }
        bool merge(unsigned long long a, unsigned long long b, long long w=1){
            w+=weight(a);  w-=weight(b);
            a=root(a);  b=root(b);
            if(a==b) return false;
            if(uni[a]>uni[b]){
                swap(a, b);
                w=(-w);
            }
            uni[a]+=uni[b];
            uni[b]=a;
            diff_weight[b]=w;
            return true;
        }
        bool isSame(unsigned long long a,unsigned long long b){
            return root(a)==root(b);
        }
};

int main(){
    int n;
    cin >> n;
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    vector<pair<int64_t,int64_t>> pos, cand;
    for(int i=0;i<n;i++){
        int64_t x, y;
        cin >> x >> y;
        pos.emplace_back(x, y);
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j) continue;
            pair<int64_t,int64_t> v = {pos[i].first-pos[j].first, pos[i].second-pos[j].second};
            cand.push_back(v);
        }
    }

    int64_t ans = INT64_MAX;
    for(auto v : cand){
        if(v.first == 0 && v.second == 0) continue;
        unionFind<50> uf;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(pos[j].first-pos[i].first == v.first && pos[j].second-pos[i].second == v.second) uf.merge(i, j);
            }
        }
        int cnt[51];
        for(int i=0;i<=50;i++) cnt[i] = 0;
        for(int i=0;i<n;i++) cnt[uf.count(i)]++;
        int64_t cost = 0;
        for(int i=1;i<=50;i++){
            cost += cnt[i] / i;
        }
        ans = min(ans, cost);
    }

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

Measured memory_bytes: 384
import math

def C(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,P = map(int,input().split())

A = list(map(int,input().split()))[:N]

ans = 0

odd = len(list(filter(lambda x:x%2==1,A)))
even = len(list(filter(lambda x:x%2==0,A)))

i = 0 if P==0 else 1
while(i<=odd):
    ans += C(odd,i)
    i+=2
    
for i in range(even):
    ans *= 2

print(ans)

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

int main() {
  
  int D,N;
  cin >> D >> N;
  
  if (D==0 && N<100) cout << N << endl;
  if (D==0 && N==100) cout << N+1 << endl;
  if (D==1 && N<100) cout << 100*N << endl;
  if (D==1 && N==100) cout << 100*(N+1) << endl;
  if (D==2 && N<100) cout << 100*100*N << endl;
  if (D==2 && N==100) cout << 100*100*(N+1) << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#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 ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){

  int n,w;
  cin >> n >> w;
  vector<vector<ll>> v(4);
  ll w1,v1;
  cin >> w1 >> v1;
  v[0].push_back(v1);
  REP(i,n-1){
    int x,y;cin >> x >> y;
    v[x-w1].push_back(y);
  }
  REP(i,4)sort(ALL(v[i]),greater<ll>());
  vector<vector<ll>> s(4,vector<ll>(n+1,0));
  REP(i,4)REP(j,v[i].size())s[i][j+1] = s[i][j]+v[i][j];
  ll res = 0;
  REP(i,v[0].size()+1){
    REP(j,v[1].size()+1){
      REP(k,v[2].size()+1){
        REP(l,v[3].size()+1){
          if(w1*(i+j+k+l)+j+k*2+l*3 > w)continue;
          ll sum = s[0][i] + s[1][j] + s[2][k] + s[3][l];
          res = max(res,sum);
        }
      }
    }
  }
  cout << res << endl;



  

  return 0;
}


Measured memory_bytes: 256
//#pragma warning(disable:4996)
//#pragma comment(linker, "/STACK:336777216")
//#pragma GCC optimize("Ofast")
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
 
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
 
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N=200005;
 
 
void solve()
{
    int n;
    cin>>n;
    pair<int,int> p[n];
    for(int i=0;i<n;i++)
    {
        cin>>p[i].first>>p[i].second;
        int l=p[i].first-p[i].second;
        int r=p[i].first+p[i].second-1;
        p[i].first=l;p[i].second=r;
    }
    sort(p,p+n);int ans=0;multiset<int>s;multiset<int>::iterator it;
    for(int i=0;i<n;i++)
    {
        while(!s.empty()&&(*s.begin())<p[i].first)
            s.erase(s.begin());
        s.insert(p[i].second);
        if(s.size()>1)
        {
            ans++;
            it=(--s.end());
            s.erase(it);
        }
    }
    cout<<max((int)1,n-ans)<<endl;
}
int32_t main()
{
    IOS;
    int t;
    t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double

int main(void){
  ll a,b;
  cin>>a>>b;
  if(a<=9 && b<=9){
    cout<<a*b<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}

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

int main(){
    string s; cin >> s;
    int ans = 1e9;
    for(int i=0; i<s.size()-3+1; i++){
        int num = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
        ans = min(ans, abs(num - 753));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

#define SQUARE(x) ((x) * (x))

using namespace std;

int main()
{
    int d;
    int area;
    
    while (cin >> d){
        area = 0;
        
        for (int i = 0; i < 600; i += d){
            area += (d * SQUARE(i));
        }
        
        cout << area << std::endl;
    }
}

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

int main() {
        string s; cin >> s;
        vector<long long> cnt(26, 0);
        long long n = s.size();
        for (int i = 0; i < n; i ++) cnt[s[i] - 'a'] ++;
        long long ans = 1 + n * (n - 1) / 2;
        for (int i = 0; i < 26; i ++) if (cnt[i] >= 2) ans -= cnt[i] * (cnt[i] - 1) / 2;
        cout << ans << endl;
        return 0;
}



Measured memory_bytes: 640
import java.util.*;
import java.lang.Math;

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

  		
      	int s = sc.nextInt();
      	int w = sc.nextInt();      	   	
      	
      	if(s > w)System.out.println("safe");
      	else System.out.println("unsafe");
        
	}
}


Measured memory_bytes: 35796
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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; }

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  FORe(i, 1, n) {
    if (i%3 == 0) continue;
    if (i%5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main()
{
    double n,m,d;
    cin>>n>>m>>d;
    double ans=0;
    ans=(m-1)*(2*(n-d))/(n*n);
    ans-=((!d)*ans/2);
    printf("%.9f",ans);
}


Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

isprime = None

def sieve(n):
    global isprime

    if n < 2:
        isprime = [False] * (n + 1)
        return

    isprime = [True if i % 2 != 0 else False for i in range(n + 1)]
    isprime[0] = isprime[1] = False
    isprime[2] = True

    from math import sqrt, ceil

    for i in range(3, int(sqrt(n)) + 1):
        if isprime[i] == True:
            for j in range(i + i, n + 1, i):
                isprime[j] = False

def main():
    global isprime

    sieve(100000)

    _ = sys.stdin.readline()

    csums = [0] * 100001
    for i in range(3, 100001):
        csums[i] += csums[i - 1]
        if isprime[i] == True and isprime[(i + 1) // 2] == True:
            csums[i] += 1

    for l, r in (map(int, line.split()) for line in sys.stdin.readlines()):
        print(csums[r] - csums[l - 1])

if __name__ == '__main__':
    main()


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    sort(all(a), greater<ll>());
    priority_queue<ll> pq;
    ll ans = 0;
    pq.emplace(a.at(0));
    for(i = 1;i < n;++i){
        ans += pq.top();
        pq.pop();
        pq.emplace(a.at(i));
        pq.emplace(a.at(i));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6832
package main

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

var m = map[string]int{
	"SUN": 7,
	"MON": 6,
	"TUE": 5,
	"WED": 4,
	"THU": 3,
	"FRI": 2,
	"SAT": 1,
}

func main() {
	s := readString()

	fmt.Println(m[s])
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdbool.h>

#define MAX 1000000

int main(void)
{
    int i, j;

    bool isPrime[MAX];
    isPrime[0] = isPrime[1] = false;

    for (i = 2; i < MAX; i++) {
        isPrime[i] = true;
    }

    for (i = 2; i < MAX; i++) {
        if (isPrime[i] == true) {
            for (j = i + i; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }

    int n;
    int cnt;
    while (scanf("%d", &n) != EOF) {
        cnt = 0;
        for (i = 2; i <= n; i++) {
            if (isPrime[i] == true) {
                cnt++;
            }
        }
        printf("%d\n", cnt);
    }

    return 0;
}

Measured memory_bytes: 1572
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    int sl=s.length();
    vi dp(n+1,mod);
    vi dp2(n+1,mod*2);
    int nw=0;
    FOR(i,0,sl){
        if(s[i]=='o'){
            nw++;
            dp[nw]=i;
            i+=c;
        }
        
    }
    nw=k+1;
    FORD(i,sl,0){
        if(s[i]=='o'){
            nw--;
            dp2[nw]=i;
            i-=c;
        }
        if(nw==1)break;
    }
    FOR(i,1,k+1){
        //cerr<<dp[i]<<" "<<dp2[i]<<endl;
        if(dp[i]==dp2[i]){
            cout<<dp[i]+1<<endl;
        }
    }


}


Measured memory_bytes: 3332
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define INF (0x3f3f3f3f)
using namespace std;

const int N = 200005;

template <class T> inline void read(T &x) {
	int flag = 1; x = 0;
	register char ch = getchar();
	while(ch <  '0' || ch >  '9') { if(ch == '-')  flag = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') { x = (x<<1)+(x<<3)+ch-'0'; ch = getchar(); }
	x *= flag;
}
int n, m, dis[N], que[N << 1], head[N], top = 0;

struct Node
{
	int y, nxt;
} e[N << 1];

inline void Adde( int x, int y )
{
	e[++top].y = y, e[top].nxt = head[x], head[x] = top;
	e[++top].y = x, e[top].nxt = head[y], head[y] = top;
}

int BFS()
{
	memset(dis, INF, sizeof(dis));
	int h, t, u, v;
	h = t = 0;
	dis[1] = 0;
	que[++t] = 1;
	while(h < t)
	{
		u = que[++h];
		for(int i = head[u]; i; i = e[i].nxt)
		{
			v = e[i].y;
			if(dis[v] != INF) continue;
			dis[v] = dis[u] + 1;
			que[++t] = v;
		}
	}
	return dis[n];
}

int main()
{
	int u, v;
	read(n), read(m);
	for(int i = 1; i <= m; i++)
		read(u), read(v), Adde(u, v);
	if(BFS() > 2) printf( "IMPOSSIBLE\n" );
	else printf( "POSSIBLE\n" );
	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;
class union_find {
public:
	vector<int> dat;
	union_find(int n) {
		dat.assign(n, -1);
	}
	
	bool unite(int a, int b) {
		int da = find(a);
		int db = find(b);
		if (da != db){
			if (dat[da] > dat[db]) swap(da, db);
			dat[da] += dat[db];
			dat[db] = da;
		}
		return (da != db);
	}
	bool check(int a, int b) {
		return (find(a) == find(b));
	}
	int find(int a) {
		return ((dat[a] < 0) ? a : (dat[a] = find(dat[a])));
	}
	int size(int a) {
		return -dat[find(a)];
	}
};

int main() {
	for (string s; cin >> s; ) {
		vector<string> m;
		m.pb(s);
		rep(i, 11) {
			cin >> s;
			m.pb(s);
		}
		union_find uf(12 * 12);
		rep (i, 12) rep (j, 12) if (m[i][j] == '1') {
			if (i > 0) if (m[i - 1][j] == '1') uf.unite(i * 12 + j, (i - 1) * 12 + j);
			if (j > 0) if (m[i][j - 1] == '1') uf.unite(i * 12 + j, i * 12 + j - 1);
		}
		set<int> ans;
		rep (i, 12) rep (j, 12) if (m[i][j] == '1') ans.insert(uf.find(i * 12 + j));
		cout << ans.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
map<ll,ll> memo;
ll cost(ll x,ll a,ll b,ll c,ll d){
    if(x==1) return d;
    if(memo.count(x)) return memo[x];
    ll cand=INF;
    if(x<cand/d) cand=x*d;
    if(x%2ll==0) chmin(cand,a+cost(x/2,a,b,c,d));
    else {
        chmin(cand,d+a+cost(x/2,a,b,c,d));
        chmin(cand,d+a+cost((x+1)/2,a,b,c,d));
    }
    if(x==2) return cand;
    if(x%3ll==0) chmin(cand,b+cost(x/3,a,b,c,d));
    else if(x%3ll==1){
        chmin(cand,d+b+cost(x/3,a,b,c,d));
        chmin(cand,d+d+b+cost((x+2)/3,a,b,c,d));
    }
    else{
        chmin(cand,d+d+b+cost(x/3,a,b,c,d));
        chmin(cand,d+b+cost((x+1)/3,a,b,c,d));
    }
    if(x<5) return cand;
    if(x%5ll==0) chmin(cand,c+cost(x/5,a,b,c,d));
    else if(x%5ll==1){
        chmin(cand,d+c+cost(x/5,a,b,c,d));
        chmin(cand,d*4+c+cost((x+4)/5,a,b,c,d));
    }
    else if(x%5ll==2){
        chmin(cand,d+d+c+cost(x/5,a,b,c,d));
        chmin(cand,d+d+d+c+cost((x+3)/5,a,b,c,d));
    }
    else if(x%5ll==3){
        chmin(cand,d+d+d+c+cost(x/5,a,b,c,d));
        chmin(cand,d+d+c+cost((x+2)/5,a,b,c,d));
    }
    else{
        chmin(cand,d+c+cost((x+1)/5,a,b,c,d));
        chmin(cand,d*4+c+cost(x/5,a,b,c,d));
    }
    memo[x]=cand;
    return cand;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    int t;
    cin >> t;
    
    Vi ans(t);
    rp(i,t){
        memo.clear();
        ll n,a,b,c,d;
        cin >> n >> a >> b >> c >> d;
        ans[i]=cost(n,a,b,c,d);
    }
    for(auto an:ans){
        print(an);
    }
    return 0;
}

Measured memory_bytes: 4364
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};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(b<a){a=b;return 1;}return 0;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()

void solve(long long N, long long M){
    ll ans=N*(N-1)/2+M*(M-1)/2;
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

ll num[10][10];

int digit(int val){
  int res=0;
  while(val>0){
    val/=10;
    res++;
  }
  return res;
}

int updig(int val){
  while(val/10>0){
    val/=10;
  }
  return val;
}

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

  if(N<=9){
    cout<<N<<endl;
    return 0;
  }

  ll ten=1;
  int d=digit(N);
  for(int i=0;i<d-2;i++) ten*=10;

 
  ll ans=0;
  int up=updig(N);
  ll M=N-ten*10*up;
  M/=10;

  //cout<<d<<" "<<M<<" "<<up<<endl;

  for(ll i=1;i<=N;i++){
    int ma=updig(i);
    if(i%10==0) continue;
    ll res=0;

    for(int j=1;j<=d;j++){
      if(j==1&&i%10!=ma) continue;
      else if(j==1){
        res++;
        continue;
      }

      if(j==d){
        if(i%10==up){
          if(N%10<ma) res+=(M);
          else res+=M+1;
        }else if(i%10<up)res+=ten;
      }else res+=pow(10,j-2);
    }

    //cout<<i<<" "<<ma<<" "<<res<<endl;
    ans+=res;
  }

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/heap"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	n, _ := sc.NextInt()
	m, _ := sc.NextInt()
	a, b := []int{}, []int{}
	for i := 0; i < m; i++ {
		ai, _ := sc.NextInt()
		bi, _ := sc.NextInt()
		a = append(a, ai)
		b = append(b, bi)
	}
	ans := solve(n, a, b)
	if ans == nil {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
		for i := range ans {
			fmt.Println(ans[i])
		}

	}
}

func solve(n int, a, b []int) (ans []int) {
	cl := createConcatenatedList(n, a, b)
	dists := dijkstra(n, cl)
	labels := toLabels(cl, dists)
	return labels
}

func createConcatenatedList(n int, a, b []int) [][]int {
	cl := make([][]int, n)
	for i := range a {
		cl[a[i]-1] = append(cl[a[i]-1], b[i])
		cl[b[i]-1] = append(cl[b[i]-1], a[i])
	}
	return cl
}

func dijkstra(n int, cl [][]int) (minDists []int) {
	dists := createDistanceList(n)
	q := PriorityQueue{}
	heap.Push(&q, Pair{Key: 1, Value: 0})
	for len(q) > 0 {
		from := heap.Pop(&q).(Pair)
		dist := from.Value + 1
		for _, key := range cl[from.Key-1] {
			if dist < dists[key-1] {
				dists[key-1] = dist
				to := Pair{Key: key, Value: dist}
				heap.Push(&q, to)
			}
		}
	}
	return dists
}

func createDistanceList(n int) []int {
	dists := make([]int, n)
	for i := range dists {
		dists[i] = math.MaxInt64
	}
	dists[0] = 0
	return dists
}

func toLabels(cl [][]int, minDists []int) []int {
	labels := []int{}
	for i := 1; i < len(cl); i++ {
		var argmin, min int
		for j := range cl[i] {
			if j == 0 || minDists[cl[i][j]-1] < min {
				argmin, min = cl[i][j], minDists[cl[i][j]-1]
			}
		}
		labels = append(labels, argmin)
	}
	return labels
}

// Pair has id and value
type Pair struct {
	Key   int
	Value int
}

// PriorityQueue is heap for Pair

type PriorityQueue []Pair

// Len is used int heap interface
func (q PriorityQueue) Len() int { return len(q) }

// Less is used int heap interface
func (q PriorityQueue) Less(i, j int) bool { return q[i].Value < q[j].Value }

// Swap is used int heap interface
func (q PriorityQueue) Swap(i, j int) { q[i], q[j] = q[j], q[i] }

// Push adds an element to heap
func (q *PriorityQueue) Push(x interface{}) { *q = append(*q, x.(Pair)) }

// Pop returns the minimum element from heap
func (q *PriorityQueue) Pop() interface{} {
	old := *q
	*q = old[:len(old)-1]
	return old[len(old)-1]
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}


Measured memory_bytes: 29428
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
s = [_ for _ in input()]

e = [0]
w = [0]

for si in s:
  if si == 'E':
    e.append(e[-1]+1)
    w.append(w[-1])
  if si == 'W':
    w.append(w[-1]+1)
    e.append(e[-1])

# print(e)
# print(w)

mn = 10**7

for i in range(n):
  cost = w[i] + e[n]-e[i+1]
  mn = min(cost,mn)

print(mn)

Measured memory_bytes: 20248
// Do you knOW what it feels like?

		// To be TorTured by your own MinD?
	
	// I don't wanna feel the PAIN.

// I BeG you to KILL me, pleASE...

#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=5e2+10, lg=17, mod=1e9+7, inf=1e18;

vector<ll>G[1<<lg];
ll n,m,a,b,c,v[1<<lg];
bool dfs(int u,int col){
	v[u]=col;
	bool ans=1;
	for(auto x:G[u]){
		if(!v[x]) ans&=dfs(x,3-col);
		else      ans&=(v[x]==3-col);
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int v,u; cin>>v>>u;
		G[v].pb(u);
		G[u].pb(v);
	}
	for(int i=0;i++<n;)if(!v[i]){
		if(SZ(G[i])==0)   c++;
		else if(dfs(i,1)) a++;
		else              b++;
	}
	cout<<2*c*n-c*c+2*a+b*b+a*(a-1)*2+a*b*2<<endl;

	return 0;
}


















Measured memory_bytes: 12672
## coding: UTF-8

N = int(input())
l = []
for i in range(N):
    l.append(input())

#print(N)
#print(l)

#中にあるABの数を数える
def count_inAB(s):
    counter = 0
    for i in range(len(s)-1):
        if(s[i] == 'A' and s[i+1] == 'B'):
            counter += 1
    return counter
'''
print(count_inAB('ABCA'))
print(count_inAB('ABCAB'))
print(count_inAB('ABABAB'))
print(count_inAB('ACBA'))
'''
#末尾にあるAの数を数える
lastA = []
for i in range(N):
    if(l[i][-1] == 'A'):
        lastA.append(i)
#print('lastA:{}'.format(lastA))

#先頭にあるBの数を数える
firstB = []
for i in range(N):
    if(l[i][0] == 'B'):
        firstB.append(i)
#print('firstB:{}'.format(firstB))






ans = 0
for i in range(N):
    ans += count_inAB(l[i])
    #print(ans)
#print('insert:{}'.format(ans))


connect = min(len(lastA), len(firstB))
if(lastA == firstB):
    connect -= 1
if(lastA == [] and firstB == []):
    connect += 1
#print('connect:{}'.format(connect))


ans += connect

#rint('ans:{}'.format(ans))
print(ans)

Measured memory_bytes: 4468
import collections

n = int(input())

s = [input() for _ in range(n)]

m = int(input())

t = [input() for _ in range(m)]

s_num = collections.Counter(s)
t_num = collections.Counter(t)

ans = 0
for key in s_num:
    if key in t_num:
        ans = max(ans, s_num[key] - t_num[key])
    else:
        ans = max(ans, s_num[key])

print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;

typedef pair<int, int> P; // left, area

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

  string s;
  cin >> s;

  stack<int> t;
  vector<P> pools;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == '\\') {
      t.push(i);
    } else if (s[i] == '/') {
      if (t.empty()) {
        continue;
      }
      int l = t.top();
      t.pop();
      int k = i - l;
      for (auto p = pools.rbegin(); p != pools.rend(); ++p) {
        int a = p->first;
        int b = p->second;
        if (a < l) {
          break;
        }
        k += b;
        pools.pop_back();
      }
      pools.push_back(P(l, k));
    }
  }

  int q = 0;
  for (auto p = pools.begin(); p != pools.end(); ++p) {
    q += p->second;
  }

  cout << q << endl;
  cout << pools.size();
  for (auto p = pools.begin(); p != pools.end(); ++p) {
    cout << " " << p->second;
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3288
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, int> LP;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int mx = 0, mi = 1e9;
	vector<int> a(n);
	map<int, int> mp;
	rep(i,n){
		cin >> a[i];
		chmax(mx, a[i]);
		chmin(mi, a[i]);
		++mp[a[i]];
	}
	if(mx - mi > 1){
		cout << "No" << endl;
		return 0;
	}
	if(mx == mi){
		if(mx == n-1 || 2*mx <= n) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else{
		if(2*mx <= 2*mp[mi] + mp[mx] && mp[mi] < mx) cout << "Yes" << endl;
		else cout << "No" << endl; 
	}
	return 0;
}

Measured memory_bytes: 8252
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double EPS = 1e-8;

int main(){
  int c1,c5,c10,c50,c100,c500;
  while(~scanf("%d %d %d %d %d %d",
               &c1,&c5,&c10,&c50,&c100,&c500)){
    printf("%d\n",
           (c1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500)
           >= 1000 ? 1 : 0);
  }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int q,m[305],x[305];
int p[7]={2,3,5,7,11,13,17};
int main(){
	cin>>q;
	for(int i=0;i<q;i++) cin>>m[i]>>x[i];
	int ret = -INF;
	for(int x2=1;x2<=300;x2*=2)	for(int x3=1;x3<=300;x3*=3)	for(int x5=1;x5<=300;x5*=5)	for(int x7=1;x7<=300;x7*=7)	for(int x11=1;x11<=300;x11*=11)	for(int x13=1;x13<=300;x13*=13)	for(int x17=1;x17<=300;x17*=17){
		int ans = 0;
		map<int,int>MM;
		for(int i=0;i<q;i++){
			int M = m[i];
			int m2 = 1,m3 = 1,m5 = 1,m7 = 1,m11 = 1,m13 = 1,m17 = 1;
			while(M%2 == 0){ M/=2; m2*=2; }
			while(M%3 == 0){ M/=3; m3*=3; }
			while(M%5 == 0){ M/=5; m5*=5; }
			while(M%7 == 0){ M/=7; m7*=7; }
			while(M%11 == 0){ M/=11; m11*=11; }
			while(M%13 == 0){ M/=13; m13*=13; }
			while(M%17 == 0){ M/=17; m17*=17; }
			
			if(x2<m2 || x3<m3 || x5<m5 || x7<m7 || x11<m11 || x13<m13 || x17<m17) continue;
			if(M == 1) ans += x[i];
			else MM[M] += x[i];
		}
		for(map<int,int>::iterator it=MM.begin();it!=MM.end();++it) ans += max(0,it->sc);
		ret = max(ret,ans);
	}
	cout << ret << endl;
}

Measured memory_bytes: 384
N = int(input())
H = [int(i) for i in input().split()]

ans = 0
c = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        c += 1
    else:
        ans = max(ans, c)
        c = 0
ans = max(ans, c)
print(ans)


Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
 
#define mod             1000000007
#define w(x)            int x; cin>>x; while(x--)
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll              long long
 
 
int main() {
    fast
    string s;
    cin >> s;
    if(s == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

Measured memory_bytes: 3548
#include "bits/stdc++.h"
using namespace std; 
#define LIM 3003

#define M 1000000007
#define inf 99999999999999999LL	//long long inf
typedef long long ll;

#define sc(x) scanf("%d",&x);
#define sc2(x,y) scanf("%d%d",&x,&y);
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z);
#define scl(x) scanf("%lld",&x);
#define scl2(x,y) scanf("%lld%lld",&x,&y);
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z);

#define pb push_back
#define mp make_pair
#define fi first
#define se second 
ll power(ll x,ll y,ll z) {	ll ret = 1;	while(y > 0) {	if(y & 1) ret = (ret*x)%z;x = (x*x)%z;y >>= 1;}return ret;}


#define debug(x) cerr<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define debug4(x,y,z,a) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#a<<" :: "<<a<< " -> ";




char a[LIM], b[LIM] ;
int n, m ;
int dp[LIM][LIM], par[LIM][LIM][2] ;
int doit(int x, int y, int parx, int pary) {
	if ( x == 0 || y == 0 )
		return 0;
	int &xy = dp[x][y] ;
	if( xy != -1)
		return xy ;
	if (a[x] == b[y]) {
		par[x][y][0] = x-1 ;
		par[x][y][1] = y-1 ;
		return xy =1 + doit(x-1, y-1, x, y) ;
	}
	int temp = doit(x, y-1, x, y) ;
	int temp1 = doit(x-1, y, x, y) ;
	if(temp > temp1) {
		par[x][y][0] = x ;
		par[x][y][1] = y-1 ;
	}
	else {
		par[x][y][0] = x-1 ;
		par[x][y][1] = y ;
	}
	
	return xy = max(temp, temp1)  ;
}
int main() {
	int i, j, t;
	memset(dp , -1, sizeof dp ) ;
	scanf("%s", 1+a) ;	scanf("%s", 1+b) ;
	n = strlen(1+a) ;	m = strlen(1+b) ;
	int answer = doit(n, m, -1, -1) ;
	for(i=1; i<=n; i++)	for(j=1; j<=m; j++)	int tt = doit(i, j, -1, -1) ; 
	int nn = n , mm = m ;
	stack< char > ss; 
	while( nn > 0 && mm > 0 ) {
		int xx = par[nn][mm][0], yy = par[nn][mm][1] ;
		if( abs(xx-nn) + abs(mm-yy) == 2 )	ss.push(a[nn]) ;
		nn = xx ;	mm = yy ;
		if(nn == 0 && mm == 0)	break ;
	}
	while(!ss.empty()) {
		cout << ss.top() ;
		ss.pop() ;
	}
	cout << endl ;
	return 0;
}




Measured memory_bytes: 106368
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int a;

	bool flg = true;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 == 0 || a % 5 == 0) {
				flg = flg;
			}
			else {
				flg = false;
			}
		}
	}

	if (flg==true) {
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    W, A, B = map(int, input().split())
    if abs(W + A - B) < abs(W + B - A):
        print(max(B - W - A, 0))
    else:
        print(max(A - W - B, 0))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;
 
#define REP(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)(a); i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007
#define _SPLIT " "
 
template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T,class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << setprecision(24) << a << endl;}
template<class T,class ...Args> void write(T a, Args... args){cout << setprecision(24) << a << _SPLIT; write(args...);}
template<class T> void warr(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int main(void)
{
    int a,b,h;
    read(a,b,h);
    write((a+b)*h/2);
    return 0;
}

Measured memory_bytes: 764
A = list(map(int,input().split()))
X,K,D = A[0], A[1], A[2]

if abs(X) >= K*D:
    print(abs(X)-K*D)
elif X == 0:
    if K % 2 == 0:
        print(0)
    else:
        print(D)
else:
    d = abs(X) // D
    
    amari = abs(X) % D
    
    hantai = D - amari
    
    
    if (K - d) % 2 == 0:
        print(amari)
    else:
        print(hantai)  

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  string s;
  cin >> s;

  if (s == "A") {
    cout << "T" << endl;
  }
  if (s == "T") {
    cout << "A" << endl;
  }
  if (s == "C") {
    cout << "G" << endl;
  }
  if (s == "G") {
    cout << "C" << endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

S = [0] * N # S[i]は社員iの直属の部下数

for i in range(N-1):
  S[A[i]-1] += 1

for i in range(N):
  print(S[i])

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

int main() {
  int n;
  cin >> n;
  
  int ans = n;
  
  vector<string> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  for (int j = 0; j < n - 1; j++) {
    if (vec.at(j) ==  vec.at(j+1)) ans--;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 9600
#define _USE_MATH_DEFINES
#include "iostream"
#include "cmath"
#include "iomanip"

int main() {
	int a, b, x;
	std::cin >> a;
	std::cin >> b;
	std::cin >> x;

	long double ans;
	if (x <= std::pow(a, 2) * b / 2) {
		ans = std::atan((long double)(a * std::pow(b, 2)) / (long double)(((double)x * 2)));
	}
	else
		ans = std::atan((long double)((std::pow(a, 2) * b - x) * 2) / (long double)std::pow(a, 3));

	std::cout << std::setprecision(10) <<std::fixed << ans * 180 / M_PI << std::endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;


int main(){
  int K;
  string S;

  cin>>K>>S;
  string tmp="";

  int i=0;
  while(i<K){
    tmp += S[i];
    i++;
  }


  if(S.size() > K){

    cout<<tmp<<"..."<<endl;
  }else{
    cout<<S<<endl;
  }
  return 0;
}


Measured memory_bytes: 3136
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, s, k=-1, sum, a[1000000];
bool f;
struct Edge { LL to, cost; };
vector<LL>ans;
string str;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> a[i];
		if (i)
			if (a[i] + a[i - 1] >= m) {
				k = i;
			}

	}
	if (k == -1) {
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
	for (LL i = 1; i < k; i++)
		cout << i << endl;
	for (LL i = n - 1; i >= k; i--) {
		cout << i << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int s=0;
    if(n<10){
        printf("0\n");
        return 0;
    }
    for(int i=10;i<=n;i++){
        int d=0,j;
        if(i%2!=0){
            
            for( j=1;j<=i;j++){
                if(i%j==0){
                    d++;
                    //printf("%d %d %d\n",i,j,d);
                }
            }
            
        }
        if(d==8){
                s++;
                //printf("%d %d\n",i,d);
            }
    }
    printf("%d\n",s);
}


Measured memory_bytes: 128
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b
mod = 7 + 10 ** 9
  
def solve():
    N = int(single_input())
    A = [int(a) for a in line_input()]
    factorial_N = 1
    accumulated_sum_nrev = [0] * (N + 1)
    for i in range(1, N+1):
        accumulated_sum_nrev[i] = accumulated_sum_nrev[i-1] + pow(i, mod - 2, mod)
        factorial_N *= i
        factorial_N %= mod
    ans = 0
    for i in range(N):
        ans += A[i] * factorial_N * (accumulated_sum_nrev[i+1] + accumulated_sum_nrev[N- i] - 1) % mod
        ans %= mod
    return ans
    

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

Measured memory_bytes: 14636
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N;cin >> N;
vector<ll> C(N);
vector<ll> S(N);
vector<ll> F(N);
vector<ll> Ans(N, 0);

rep(i, 1, N)cin >> C[i] >> S[i] >> F[i];

rep(i, 1, N + 1){

    if(i == N){cout << 0;break;}

    rep(j, i, N){

        if(S[j] >= Ans[i])Ans[i] = S[j] + C[j];

        else{

            if(Ans[i]%F[j] != 0)Ans[i] = F[j]*(Ans[i]/F[j] + 1) + C[j];

            else Ans[i] += C[j];

        }
    }

    cout << Ans[i] << endl;
    
}
}

Measured memory_bytes: 3636