akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/aising2019/submissions/3972256
#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;
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; }

const int MAX_N = 100000;
const int MAX_Q = 100000;
const ll UB = 1000000000;

int N;
ll A[MAX_N];

ll eSum[MAX_N], oSum[MAX_N], sum[MAX_N];

bool lt(int x, int a, int b){
	if(b < 0 || N <= b) return true;
	if(a < 0 || N <= a) return false;
	ll d1 = abs(x - A[a]);
	ll d2 = abs(x - A[b]);
	if(d1 < d2) return true;
	if(d1 == d2) return a < b;
	return false;
}

ll calc(int r, int d){
	if(r < 0) return 0;
	if(d == 0) return eSum[r];
	if(d == 1) return oSum[r];
	return sum[r];
}

ll calc(int l, int r, int d){
	if(l > r) return 0;
	return calc(r, d) - calc(l-1, d);
}

ll query(int x){
	int lb = 1, ub = N + 1;
	while(ub - lb > 1){
		int mid = (lb + ub) / 2;
		int a = mid / 2;
		int b = mid / 2;
		if(a + b < mid) ++a;
		int l = N - mid;
		int r = N - a - 1;
		if(lt(x, r+1, l)) ub = mid;
		else lb = mid;
	}
	int a = (lb + 1) / 2;
	int d = N % 2;
	ll ans = calc(0, N - lb - 1, d) + calc(N - lb, N - a - 1, -1);
	return sum[N-1] - ans;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int Q;
	cin >> N >> Q;
	rep(i,N) cin >> A[i];
	sum[0] = A[0];
	eSum[0] = A[0];
	oSum[0] = 0;
	for(int i = 1; i < N; ++i){
		sum[i] = sum[i-1] + A[i];
		eSum[i] = eSum[i-1] + (i%2 == 0 ? A[i] : 0);
		oSum[i] = oSum[i-1] + (i%2 == 1 ? A[i] : 0);
	}
	rep(qi,Q){
		ll x;
		cin >> x;
		ll ans = query(x);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 6796
#include <cstdio>

int c[100010];
int main()
{
  int n, k, q; scanf("%d%d%d", &n, &k, &q);
  for (int i = 1; i <= q; ++i)
  {int x; scanf("%d", &x); ++c[x];}
  for (int i = 1; i <= n; ++i)
    if (k - (q - c[i]) <= 0) puts("No");
  	else puts("Yes");
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int n;
int u,v;
vector<int> g[100100];
int d[100100];
int ma[100100];
int ans=0;
int can[100100];

void dfs(int k,int p,int depth,int vv){
	d[k]=depth;
	ma[k]=depth;
	for(int t:g[k]){
		if(t==p)continue;
		if(t==u)vv=1;
		dfs(t,k,depth+1,vv);
		if(can[t]){
			can[k]=1;
		}
	}
	if(can[k]&&d[k]>d[u]-d[k]){
		int dif=d[k]-(d[u]-d[k]);
		
		//cout << ma[k] << " " <<d[k] << endl;
		//cout << k+1 << " "  << d[u]-d[k]+ma[k]-d[k]+dif-1 << endl;
		ans=max(ans,d[u]-d[k]+ma[k]-d[k]+dif-1);
	}
	if(vv){
		can[k]=1;
		int dif=d[u];
		ans=max(ans,d[k]-d[u]+dif-1);
	}
	if(p>=0){
		ma[p]=max(ma[p],ma[k]);
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> u >> v;
	u--; v--;
	for(int i=0;i<n-1;i++){
		int a,b; cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(v,-1,0,0);
	cout << ans << endl;
}


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

#define long long long int
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(6);
    int n, m, x;
    cin >> n >> m >> x;
    vector<bool> a(n + 1);
    for (int i = 0; i < m; ++i) {
        int idx;
        cin >> idx;
        a[idx] = true;
    }
    int sum1 = 0;
    int sum2 = 0;
    for (int i = 0; i <= x; ++i) {
        sum1 += a[i];
    }
    for (int i = x; i <= n; ++i) {
        sum2 += a[i];
    }
    cout << min(sum2, sum1);
    return 0;
}

Measured memory_bytes: 256
import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        list.add(a);
        for (int i = 1;; i++) {
            int x = list.get(i - 1);
            if(x % 2 == 0){
                x = x / 2;
            } else {
                x = 3 * x + 1;
            }
            if (list.contains(x)) {
                System.out.println(i + 1);
                break;
            }
            list.add(x);
       }

    }
}


Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;


int main() {
	//cout << fixed << setprecision(10);
	long long int n, a, b, c, d, e, k;
	cin >> n >> a >> b >> c >> d >> e;
	k = min(a, min(b, min(c, min(d, e))));
	cout << (n-1)/ k + 5;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    deque<int> dq;
    bool f = true;
    for(int i = 0; i < n; ++i) {
        int a;
        cin >> a;

        if(f) {
            dq.push_back(a);
            f = false;
        } else {
            dq.push_front(a);
            f = true;
        }
    }

    while(!dq.empty()) {
        if(n % 2 == 0) {
            cout << dq.front() << " ";
            dq.pop_front();
        } else {
            cout << dq.back() << " ";
            dq.pop_back();
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3072
# AOJ 0586: Palindrome
# Python3 2018.6.30 bal4u

def palindrome(k, c):
	a = 10*k + c;
	while k:
		a = 10*a + (k%10)
		k //= 10
	return a

def isPrime(p):
	if (p & 1) == 0: return False
	for i in range(3, int(p**0.5), 2):
		if (p % i) == 0: return False
	return True

n, c = map(int, input().split())
if c < 0:
	if n == 1: print(11)
	else: print('9'*(2*n))
else:
	k = int('9'*n)+1
	while True:
		k -= 1
		x = palindrome(k, c)
		if isPrime(x):
			print(x)
			break


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

const long double PI=(acos(-1));

int main(){
	long double a,b,x,ans;
	cin>>a>>b>>x;
	if(a*a*b/2.0>=x){
		long double y=x*2/a/b/b;
		ans=PI/2-atan(y);		
	}else{
		long double y=(2*b-2*x/a/a)/a;
		ans=atan(y);
	}
	cout<<setprecision(10)<<ans*180.0/PI<<endl;
	return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  int mx = max(A, max(B, C));
  int ret = mx * 10 + A + B + C - mx;
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;
//fibonacci
int binet(int n)
{
	return (pow((1+sqrt(5)),n-1)-pow((1-sqrt(5)),n-1))/(pow(2,n-1)*sqrt(5));
}


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll a,b,m;
	cin>>a>>b;
	m=a*b;
	a=__gcd(a,b);
	cout<<m/a<<"\n";
	return 0;
}
	

Measured memory_bytes: 3668
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
int n , m , q;
int a[MAXN] , b[MAXN] , C[MAXN] , d[MAXN];
int A[MAXN] , ans;
void dfs( int c ) {
	if( c == n + 1 ) {
		int res = 0;
		for( int i = 1 ; i <= q ; ++ i ) if( A[b[i]] - A[a[i]] == C[i] ) res += d[i];
		ans = max( ans ,res );
		return;
	}
	for( int i = A[c - 1] ; i <= m ; ++ i ) A[c] = i , dfs( c + 1 );
}
void solve() {
	cin >> n >> m >> q;
	rep( i , 1 , q ) scanf("%d%d%d%d",a+i,b+i,C+i,d+i);
	A[0] = 1; dfs( 1 );
	cout << ans << endl;
}

signed main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define ll long long 
#define ff first
#define ss second
#define mp make_pair
#define fastio() ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;
int main() {
	fastio();
	int n,i,j,k;
	cin>>n>>k;
	int h[n];
	for(i=0;i<n;i++)
	{
		cin>>h[i];
	}

	vector <int> dp(n,INT_MAX);
	dp[0]=0;


	for(i=1;i<n;i++)
	{
		for(j=1;j<=k && i-j>=0;j++)
		{
			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[n-1];
	return 0;
}




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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

const int N = 309;

double dp[N][N][N];

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	int a[n];
	for (int& x: a) cin >> x;
	
	vi cnt(4);
	for (int i = 0; i < n; i++) cnt[a[i]]++;

	dp[0][0][0] = 0;
	for (int k = 0; k <= cnt[3]; k++) {
		for (int j = 0; j <= n; j++) {
			for (int i = 0; i <= n; i++) {
				if (i == 0 && j == 0 && k == 0) continue;	
				dp[i][j][k] = 1;
				if (i > 0) dp[i][j][k] += (double)i/(double)n*dp[i-1][j][k];
				if (j > 0) dp[i][j][k] += (double)j/(double)n*dp[i+1][j-1][k];
				if (k > 0) dp[i][j][k] += (double)k/(double)n*dp[i][j+1][k-1];
				dp[i][j][k] *= (double)n/double(i+j+k);
			}
		}
	}
	cout << fixed << setprecision(15) << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 225536
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut a: [i64; 3] = [0; 3];
    for i in 0..3 { a[i] = read(); }
    let b: i64 = a.iter().fold(0, |b, c| b + c);
    println!("{}", if b > 21 { "bust" } else { "win" });
}

Measured memory_bytes: 4352
def main112():
    N, K = (int(x) for x in input().split())
    height = []

    for n in range(N):
        height.append(int(input()))

    height = sorted(height)

    min_h = 10 ** 10

    for h in range(len(height) - K + 1):
        focus = height[h + K -1] - height[h]
        if focus < min_h:
            min_h = focus

    print(min_h)

main112()

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

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

int n, m, ans;
string s;
vector<int> dat;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m >> s;
    s = '1' + s;
    int cnt = 0;
    cont (i, n) {
        if (s[i] != s[i - 1]) {
            dat.push_back(cnt);
            cnt = 1;
        } else {
            ++cnt;
        }
    }
    dat.push_back(cnt);
    if (s.back() == '0') {
        dat.push_back(0);
    }
    int to = min((int) dat.size(), 2 * m + 1), cur = 0;
    loop (i, to) {
        cur += dat[i];
    }
    ans = max(ans, cur);
    for (int l = 0, r = 2 * m + 2; r < dat.size(); l += 2, r += 2) {
        cur -= dat[l];
        cur -= dat[l + 1];
        cur += dat[r - 1];
        cur += dat[r];
        ans = max(ans, cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1020
def POW(x, n, mod):
    ans = 1
    # n が 0 になるまで計算を続ける
    while n > 0:
        if n % 2 == 1:
            ans *= x%mod
        x = (x*x)%mod						#x = x**2
        n >>= 1						#ビットシフト
    return ans

if __name__ == '__main__':
	S = input()
	L = len(S)
	lst = [0] * 2019
	lst[0] = 1
	amari = 0
	ans = 0
	for i in range(1,L+1):
		amari = ( int(S[L-i]) * POW(10,i-1,2019) + amari ) % 2019
		lst[amari] += 1

	for i in range(2019):
		m = lst[i]
		ans += m * (m-1) / 2

	print(int(ans))

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a != b) cout << max(a, b) * 2 - 1 << endl;
  else cout << 2 * a << endl;
}


Measured memory_bytes: 256
int main(){
  int a,b,c,d,e,f;
  float x,y;
  while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=-1){
    x = (float)(c*e-b*f)/(a*e-d*b);
    y = (float)(c*d-a*f)/(b*d-a*e);
    if(-0.0005<x && x<=0)
      x=0;
    if(-0.0005<y && y<=0)
      y=0;
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 636
def binarySearch(key):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if key == A[mid]: return 1
        if key > A[mid]: left = mid + 1
        elif key < A[mid]: right = mid
    return 0

n = int(input())
A = list(map(int,input().split()))
input()
print(sum(binarySearch(e) for e in map(int,input().split())))


Measured memory_bytes: 16720
fun main(args: Array<String>) {
    abc146a()
}

fun abc146a() {
    val s = readLine()!!

    val list = listOf("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT")
    val indexOf = list.indexOf(s)
    val answer = indexOf.let { if (it == 0) 7 else 7 - it }

    println(answer)
}


Measured memory_bytes: 34084
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	int n, x;
	cin >> n >> x;
	vector<int> a;
	int i, count = 0;
	for(i=0; i<n; i++){
		int p;
		cin >> p;
		a.push_back(p);
	}
	sort(a.begin(), a.end());
	for(i=0; i<n; i++){
		if(a[i]>x){
			x = 0;
			break;
		}
		else{
			count++;
			x = x-a[i];
		}
	}
	if(x) count = count - 1;
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

#define max(a, b) (a>b?a:b)
int seg[1 << 21];

void add(int a, int v){
    a += 1 << 20;
    seg[a] += v;
    while(a /= 2){
	seg[a] = max(seg[a * 2], seg[a * 2 + 1]);
    }
}

int solve(){
    int v = 1;
    while(v < (1 << 20)){
	if(seg[v] == seg[v * 2])
	    v = v * 2;
	else
	    v = v * 2 + 1;
    }
    return v - (1 << 20);
}

int main(){
    int i, n, q, a, v;
    scanf("%d%d", &n, &q);
    for(i = 0;i < q;i++){
	scanf("%d%d", &a, &v);
	add(a, v);
	printf("%d %d\n", solve(), seg[1]); 
    }
    return 0;
}

Measured memory_bytes: 8712
#include<iostream>
#define endl '\n'
using namespace std;
int main()
{
	int N,M,C,i,j,total=0,e,sum=0;
	cin>>N>>M>>C;
	int A[N][M],B[M];
	for(i=0;i<M;i++) {
		cin>>B[i];
	}
	for(i=0;i<N;i++) {
		for(j=0;j<M;j++) {
			cin>>A[i][j];
		}
	}
	for(i=0;i<N;i++) {
		for(j=0;j<M;j++) {
			sum=sum+A[i][j]*B[j];
		}
			if(sum+C>0) {
				total+=1;
			}
		sum=0;
	}
	cout<<total;
	return 0;
}

Measured memory_bytes: 256
let pi = 4. *. atan 1.

let d60 = pi /.  3.

let printer (a,b) = Printf.printf "%f %f\n" a b

let f (a,b) (c,d) = (2. *. a +. c) /. 3., (2. *. b +. d) /. 3.

let rec recursive depth p1 p2 =
  if depth=0 then ()
  else
    let ((sx,sy) as s) = f p1 p2 in
    let ((tx,ty) as t) = f p2 p1 in
    let tsx = tx -. sx in
    let tsy = ty -. sy in
    let u = tsx *. cos d60 -. tsy *. sin d60 +. sx,
            tsx *. sin d60 +. tsy *. cos d60 +. sy in
    let d = depth-1 in
    recursive d p1 s;
    printer s;
    recursive d s u;
    printer u;
    recursive d u t;
    printer t;
    recursive d t p2

let () =
  let depth = read_int () in
  let p1 = 0.,0. in
  let p2 = 100., 0. in
  printer p1;
  recursive depth p1 p2;
  printer p2

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

public class Program
{
    static int N;
    static char[] chars;

    public static void Main(string[] args)
    {
        N = Input.NextInt();
        var S = Input.NextString();N = S.Length;
        chars = S.ToCharArray();

        var first_black = S.IndexOf("#");
        if (first_black < 0)
        {
            Console.WriteLine("0");
            return;
        }

        var totalB = chars.Count(n => n == '#');
        var totalW = N - totalB;
        var countB = 0;
        var ans = totalW;
        for (int i = 0; i < N; i++)
        {
            if (chars[i] == '#')
                countB++;
            var remainW = (N - i-1) - (totalB - countB);
            var totalR = countB + remainW;
            ans = Math.Min(ans, totalR);
        }
        Console.WriteLine(ans);
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}



Measured memory_bytes: 15456
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, x, y, b, p;
	cin >> n;
	while (n--) {
		cin >> x >> y >> b >> p;
		int ans = x * b + y * p;
		if (b >= 5 && p >= 2)
			ans = ans * 4 / 5;

		if (b < 5 && p < 2)
			ans = min(ans, (x * 5 + y * 2) * 4 / 5);
		if (b >= 5 && p < 2)
			ans = min(ans, (x * b + y * 2) * 4 / 5);
		if (b < 5 && p >= 2)
			ans = min(ans, (x * 5 + y * p) * 4 / 5);
		cout << ans << endl;
	}

	return 0;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007 , __ = _<<1;
const lint linf = 0x3f3f3f3f3f3f3f3f;

int n,nn,val[__],rk[__],got[__]={0};

int main()
{
	n=ty(),nn=n+n;
	for(int i=1;i<=n;i++)val[i]=ty(),val[n+i]=ty();
	for(int i=1;i<=nn;i++)rk[i]=i;
	sort(rk+1,rk+nn+1,[](int a,int b){return val[a]<val[b];});

	lint ans=linf,temp=0;
	for(int i=1;i<=n;i++)temp+=val[i];
	ans=min(ans,temp),temp=0;
	for(int i=n+1;i<=nn;i++)temp+=val[i];
	ans=min(ans,temp),temp=0;
	for(int i=1,a;i<=n;i++)a=rk[i],temp+=val[a],got[a]=1;
	for(int i=1;i<=n;i++)
	{
		if(got[i] && got[i+n])ans=min(ans,temp);
		else ans=min(ans,temp+val[n*got[i]+i]-val[rk[n-(rk[n]==i || rk[n]==i+n)]]);
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 2560
N, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N - 1)]

MOD = 10 ** 9 + 7

graph = [[] for _ in range(N + 1)]
for A, B in AB:
  graph[A].append(B)
  graph[B].append(A)
#print("graph:", graph)

parent = [-1] * (N + 1)

stack = [1]
parent[1] = 0
while stack:
  s = stack.pop()
  for g in graph[s]:
    if parent[s] != g:
      parent[g] = s
      stack.append(g)
#print("parent:", parent)

cnt = [0] * (N + 1)
for i in range(2, len(parent)):
  cnt[parent[i]] += 1
#print("cnt:", cnt)

P = [1]
for i in range(N + 2):
  P.append((P[-1] * (K - 2 - i)) % MOD)
#print("P:", P)

answer = K
for i in range(1, len(cnt)):

  M = cnt[i]
  if M == 0:
    continue  
  #print("M, answer :", M, answer)

  if i == 1:
    if K - 1 >= M:
      for j in range(cnt[1]):
        answer *= (K - 1 - j)
        answer %= MOD
    else:
      answer = 0
  else:
    if K - 2 >= M:
      answer *= P[M]
      answer %= MOD
    else:
      answer = 0
print(answer)      

Measured memory_bytes: 83672
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int[] b = new int[a];
    double c = 0;
    for(int i = 0;i < b.length;i++){
      b[i] = sc.nextInt();
    }
    for(int j = 0;j < b.length;j++){  
      c += 1 /(double) b[j];  
//      System.out.println(c);
    }
    c = 1 / c;
    System.out.println(c);
  }
}

Measured memory_bytes: 23124
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


a = list(_S())
a = list(map(int,a))
l = len(a)-1

for i in range(1<<l):
    t = a[0]
    sign = ['-','-','-']
    # 符号のループ
    for j in range(l):
        # i を j回右にシフトして1との論理積を取り、0であれば+とする
        if (i >> j) & 1 == 0:
            t += a[j+1]
            sign[j]='+'
        else:
            t -= a[j+1]
    # print(t)
    if t == 7:
        break

ans = str(a[0])
for i in range(l):
    ans += sign[i] + str(a[i+1])
ans += '=7'
print(ans)

Measured memory_bytes: 9288
import math
primes = []
for p in range(2,10001):
    for m in range(2,math.floor(math.sqrt(p)) + 1):
        if p % m == 0:
            break
    else:
        primes.append(p)
targ = int(input())
while targ != 0:
    ans = 0
    for p in range(len(primes)):
        if primes[p] > targ:
            break
        tempsum = 0
        for l in range(p,len(primes)):
            tempsum += primes[l]
            if tempsum > targ:
                break
            elif tempsum == targ:
                ans += 1
                break
    print(ans)
    targ = int(input())

Measured memory_bytes: 7656
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int inf = 1<<30;
typedef pair<int, int> P;

int main() {
  ll n; cin >> n;
  ll ans = n*(n-1)/2;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N=int(input())
gray=0
brown=0
green=0
cyan=0
blue=0
yellow=0
dai=0
red=0
chan=0
A=input().split()
for i in range(N):
    a=int(A[i])
    if a<400:
        gray=1    
    elif a<800:
        brown=1
    elif a<1200:
        green=1   
    elif a<1600:
        cyan=1
    elif a<2000:
        blue=1
    elif a<2400:
        yellow=1
    elif a<2800:
        dai=1
    elif a<3200:
        red=1    
    else:
        chan=chan+1
min=gray+brown+green+cyan+blue+yellow+dai+red
 
 
if chan==0:
   print(str(min)+' '+str(min))
else:
   max=min+chan
   if min==0:
      min=1
   print(str(min)+' '+str(max))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

int N, Q;

int main()
{
    while (cin >> N >> Q)
    {
        if (N == 0 && Q == 0)
            return 0;
        set<int> wan;
        int player = 0;
        vector<set<int>> temoto(N);

        for (int i = 0; i < Q; i++)
        {
            wan.insert(i);
        }

        while (1)
        {
            if (wan.size() == 1 && temoto[player].size() == Q - 1)
            {
                cout << player << "\n";
                break;
            }
            if (wan.empty())
            {
                while (temoto[player].size())
                {
                    wan.insert(*temoto[player].begin());
                    temoto[player].erase(*temoto[player].begin());
                }
            }
            else
            {
                temoto[player].insert(*wan.begin());
                wan.erase(*wan.begin());
            }
            player++;
            player %= N;
        }
    }
}


Measured memory_bytes: 3108
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(B, N *A) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mn=1e5+7;
vector< vector<ll> > dp(mn);

ll dfs(ll a,ll b){
	ll ret=0;
	for(ll p=0;p<dp[a].size();++p){
		if(dp[a][p]==b)continue;
		ret+=dfs(dp[a][p],a);
	}
	if(ret>=2){cout<<"First"<<endl;exit(0);}
	if(ret==0)return 1;
	return 0;
}

int main(){
	ll N;cin>>N;
	for(ll a=0;a<N-1;++a){
		ll b,c;cin>>b>>c;
		--b;--c;
		dp[b].push_back(c);
		dp[c].push_back(b);
	}
	if(dfs(0,0))cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

//void substring_dfs(vector < int, int > substring){
    
//}

int checknext(int i, vector < int > element){
    for(auto itr = element.begin(); itr < element.end(); itr++){
        if(i % *itr == 0) return 0;
        if(i < 2 * *itr) break;
    }
    return i;
}

int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    cin >> n;
    
    vector < int > element;
    element.clear();
    //element.push_back(2);
    int number = 1;
    //cout << "11";
    
    for (int i = 0; i < n; i++){
        //bool hantei = true;
        if (i > 0) cout << " ";
        while(number < 55555){
            number += 2;
            int result = checknext(number, element);
            if (result != 0) {
                element.push_back(result);
            }
            if (result > 0 && result % 5 == 1){
                cout << result;
                break;
            }
        }
        
        
    }
    
    cout << endl;
    return 0;
}

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

int main(){
  ll a,b,k;
  cin >> a >> b >> k;
  
  if(k > a+b){
    b = 0;
    a = 0;
  }else if(k > a){
    b = b+a-k;
    a = 0;
  }else{
    a = a - k;
  }
  
  cout << a << " " << b << endl;
  
  return 0;
}

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

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	int n=s.size();
	if (s[0]=='0'||s[n-1]=='1')
	{
		cout<<"-1\n";
		return 0;
	}
	int f=1;
	for (int i = 0; i < n/2; ++i)
	{
		if (s[i]!=s[n-i-2])
		{
			f=0;
		}
	}
	if (f==0)
	{
		cout<<"-1\n";
		return 0;
	}
	int now=n;
	for (int i = n-1; i > 0; --i)
	{
		cout<<i<<" "<<now<<endl;
		if (s[i-1]=='1')
		{
			now=i;
		}
	}
	return 0;
}


Measured memory_bytes: 1664
import collections as cl

N=int(input())

L = []

for i in range(N):
  S,P_ = input().split()
  P = int(P_)
  
  flg = False
  for j in range(len(L)):
    if L[j][0]>S or (L[j][0]==S and L[j][1]<P):
      L.insert(j,(S,P,i))
      flg = True
      break
  if flg==False:
    L.append((S,P,i))
        
#I = [0]*N
for i in range(N):
  print(L[i][2]+1)
#  I[L[i][2]] = i+1
      






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

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

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

   int b = 0, c = 10000;
   for (int i = 1; i < n; i++) {
       if (a[i] == a[i - 1]) a[i] = c--, b++;
   }

   cout << b << endl;

    return 0;
}


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

int main(){
    int n,a,b; cin >> n >> a >> b;
    int dai = 0, chu = 0, sho=0;
    for(int i = 0; i < n; i++){
        int p; cin >> p;
        if(p <= a) sho++;
        else if(p <= b) chu++;
        else dai++;
    }
    cout << min(dai, min(chu, sho)) << endl;
    return 0;
}

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

template<typename T>
struct FenwickTree
{
    vector<T> tree;
    const int n;
    FenwickTree(int n=0) : tree(n+1), n(n) {}
    void add(int i, T x=1)
    {
        for(i++; i<=n; i += i&-i) tree[i] += x;
    }
    T sum(int i)
    {
        T x = 0;
        for(i++; i; i -= i&-i) x += tree[i];
        return x;
    }
    T sum(int l, int r)
    {
        return sum(r) - sum(l-1);
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    vector<int> C(N);
    for(int i=0; i<N; i++) cin >> C[i];
    vector<int> L(Q), R(Q);
    for(int i=0; i<Q; i++)
    {
        cin >> L[i] >> R[i];
        L[i]--; R[i]--;
    }

    vector<int> arrow(N+1, -1);
    vector<int> S, T;
    for(int i=0; i<N; i++)
    {
        if(arrow[C[i]] != -1)
        {
            S.push_back(arrow[C[i]]);
            T.push_back(i);
        }
        arrow[C[i]] = i;
    }

    vector<vector<pair<int, int>>> LRi(N);
    for(int i=0; i<Q; i++)
    {
        LRi[L[i]].emplace_back(R[i], i);
    }
    vector<vector<int>> ST(N);
    for(int i=0; i<S.size(); i++)
    {
        ST[S[i]].push_back(T[i]);
    }

    // L <= S && T <= R
    FenwickTree<ll> ft(N);
    vector<int> ans(Q);
    for(int i=N-1; i>=0; i--)
    {
        for(auto t : ST[i])
        {
            ft.add(t);
        }
        for(auto p : LRi[i])
        {
            ans[p.second] = p.first - i + 1 - ft.sum(p.first);
        }
    }
    for(auto num : ans)
    {
        cout << num << '\n';
    }

    return 0;
}


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

int main(int argc, char **argv) {
	int h, w;
	cin >> h >> w;
	string s;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cin >> s;
			if(s == "snuke") {
				cout << char(j + 'A') << i + 1 << endl;
			}
		}
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <unordered_set>

using namespace std;

int main() {
    string s;
    cin >> s;
    
    unordered_set<char> check;
    check.insert('A');
    check.insert('T');
    check.insert('G');
    check.insert('C');
    
    int len = s.size();
    
    int maxLen = 0;
    for(int i = 0; i < len; ++i) {
        vector<int> dp(len + 1, 0);
        for(int j = 0; j < len; ++j) {
            if(check.count(s[j]) > 0) {
                dp[j + 1] = dp[j] + 1;
                maxLen = max(maxLen, dp[j + 1]);
            }
        }
    }
    cout << maxLen << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int a,b;
	bool flag = true;
	string s;
	cin >> a >> b >> s;
	for(int i = 0;i < a;i++) if(!(s[i] >= '0' && s[i] <= '9')) flag = false;
	if(s[a] != '-') flag = false;
	for(int i = a + 1;i < a + b + 1;i++) if(!(s[i] >= '0' && s[i] <= '9')) flag = false;
	if(flag) Yes();
	else No();
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
	    long n =s.nextLong();
	    long a =100;
	    int p =1;
	    long count =0;
	    long ii =0;
	    while(a<n){
	        ii = (a*p)/100;
	        a += ii;
	        count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 35700
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#define pii pair<ll,ll>
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int DMAX=500000+5;
const int MOD=998244353;
template<class T> inline void read(T &x){
    x=0; 
    T f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch<='9' && ch>='0'){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    x*=f;
}
ll n;
ll prime[DMAX];
ll cnt=0;
ll ans=0;
ll a[105];
int main(){
    read(n);
    for(ll i=1;i<=100;i++){
        a[i]=a[i-1]+i;
    }
    for(ll i=2;i<=sqrt(n);i++){
        ll res=0;
        if(n%i==0){
            while(n%i==0){
                n/=i;
                res++;
            }
        }
        if(res!=0){
            ll p=lower_bound(a+1,a+101,res)-a;
            if(a[p]!=res){
            	p--;
			}
            ans+=p;
        }
    }
    if(n>1){
        ans++;
    }
    printf("%lld\n",ans);
    return 0;

}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define PB push_back
#define PII pair<int,int>
#define FI first
#define SE second
#define si(a) scanf("%d",&a)
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const int maxn = 1<<17;
const int mod = 1e9+7;
const int N = 2e5+5;
int euler[N];
LL gcd(LL a,LL b){
    return b?gcd(b,a%b):a;
    //高精度 return b?gcd(b,a-b):a;
}
LL lcm(LL a,LL b){
    return a*b/gcd(a,b);
}
LL sum[N];
LL pre[N],pos[N];
map<string,int>mp;
string a[]={"AC","WA","TLE","RE"};
int main(){
	string ans;
	int n;cin>>n;
	while(n--){
		cin>>ans;
		mp[ans]++;
	}
	for(int i=0;i<4;i++){
		cout<<a[i]<<" x "<<mp[a[i]]<<endl;
	}
	return 0;
}

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

using namespace std;

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

  vector<long long> a(N);

  cin >> a[0];
  long long  amax_1 = a[0];
  long long  amax_2 = 0;
  for(long long i =1; i <N; i++){
    cin >> a[i] ;
    if(a[i] > amax_1){
      amax_2 = amax_1;
      amax_1 = a[i];
    }
    if(a[i] > amax_2 && a[i] < amax_1)amax_2 = a[i];
  }

  long long  cnt =0;
  for(long long i =0; i <N; i++){
    if(a[i] == amax_1){
      cnt++;
    }
  }

  for(long long i =0; i <N; i++){
    if(cnt > 1)cout << amax_1 << endl;
    else{
      if(amax_1 == a[i])cout << amax_2 << endl;
      else cout << amax_1 << endl;
    }
  }
}


Measured memory_bytes: 3200
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int A,B; double T;
    while (cin >> A >> B >> T) {
        T += 0.5;
        int t = A, ans = 0;
        while (t < T) {
            ans += B;
            t += A;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define foref(i, a, b) for (int i = b - 1, to = a; i >= to; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  Long x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  Long need = x / d;
  Long move = min(need, k);
  x -= move * d;
  k -= move;
  if (k % 2 == 0)
    cout << x << '\n';
  else
    cout << abs(x - d) << '\n';

  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
ll n,a[5],now[5],ans,minn;
int t;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>a[0];
	minn=a[0];
	for (int i=1;i<5;++i)
	{
		cin>>a[i];
		if (a[i]<minn) minn=a[i],t=i;
	}
	//t+1
	ans+=t;
	if (n%minn==0) ans+=n/minn;
	else ans+=n/minn+1;
	ans+=(4-t);
	cout<<ans;
	return 0;
}

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

int main(){
  string s;
  std::cin >> s;
  reverse(s.begin(),s.end());

  ll ans=0;
  int bcnt=0;
  for (int i = 0; i < s.size() ; i++) {
    if(s[i]=='B'){
      ans+=i-bcnt;
      bcnt++;
    }
  }
  std::cout << ans << '\n';



return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
  int total,n,Y,M,D,y,yy,I,ii,i;
  
  total=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d %d",&Y,&M,&D);
    y=Y/3;
    yy=Y%3;
    if(Y==1){
      for(I=1;I<M;I++){
	if(I%2==0){
	  total+=19;
	}
	else {
	  total+=20;
	}
      }
      total+=D;
    }
   
    if(Y==2){
      total=195;
      for(I=1;I<=M;I++){
	if(I%2==0){
	  total+=19;
	}
	else {
	  total+=20;
	}
      }
      total+=D;
    }
    
    if(Y>=3){
      total=390;
      for(I=1;I<=y;I++){
	if(I>=2) total+=590;
      }
      for(ii=1;ii<=yy;ii++){
	if(ii==1) total+=200;
	  
	if(ii==2) total+=195;
      }
    
      
      if(Y%3==0){
	for(I=1;I<M;I++){
	  total+=20;
	}
      }
      else {
	for(I=1;I<M;I++){
	  if(I%2==1) total+=20;
	  else total+=19;
	}
      }
      total+=D;
    }
    
   
    printf("%d\n",196471-total);
    total=0;
  }
  return 0;
}
	     

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
const long long MOD = 998244353;
long long A[3000];
long long dp_left[3000][3001];
long long dp_right[3000][3001];
int main(){
  int N;
  int S;
  cin >> N >> S;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  dp_left[0][0] = 1;
  dp_left[0][A[0]] = 1;
  for(int i = 1; i < N; i++){
    for(int j = 0; j <= S; j++){
      dp_left[i][j] = (dp_left[i][j] + dp_left[i - 1][j]) % MOD;
      if(j >= A[i]){
        if(j - A[i] == 0){
          dp_left[i][j] = (dp_left[i][j] + (i + 1)) % MOD;
        } else {
          dp_left[i][j] = (dp_left[i][j] + dp_left[i - 1][j - A[i]]) % MOD;
        }
      }
    }
  }

  /*
  dp_right[N - 1][0] = 1;
  dp_right[N - 1][A[0]] = 1;
  for(int i = N - 1; i >= 0; i--){
    for(int j = 0; j <= S; j++){
      dp_right[i][j] = (dp_right[i][j] + dp_right[i + 1][j]) % MOD;
      if(j >= A[i]){
        dp_right[i][j] = (dp_right[i][j] + dp_right[i + 1][j - A[i]]) % MOD;
      }
    }
  }
  */

  

  long long ans = 0;
  for(int i = 0; i < N; i++){
    long long cur_cases;
    if(i == 0){
      cur_cases = dp_left[i][S];
    } else {
      cur_cases = (dp_left[i][S] -  dp_left[i - 1][S] + MOD) % MOD;
    }
    ans = (ans + (cur_cases * (N - i) % MOD)) % MOD;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 71296
# nの遇奇で出現する数字の数は固定されるのでそれから外れるとダメ 奇数んとき真ん中0以外ぜんぶ2 偶数ならぜんぶ2ずつ場所が割り当てられる
# もっとマシな実装できんのか
# たぶん割忘れてて1WA
n = int(input())
a = list(map(int, input().split()))
d = {}
MOD = 10**9 + 7
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1
if n % 2 == 0:
    ans = 1
    for i in range(1, n, 2):
        if i not in d or d[i] != 2:
            print(0)
            exit()
        else:
            ans *= 2
            ans %= MOD
    print(ans)
else:
    if 0 not in d or d[0] != 1:
        print(0)
        exit()
    ans = 1
    for i in range(2, n, 2):
        if i not in d or d[i] != 2:
            print(0)
            exit()
        else:
            ans *= 2
            ans %= MOD
    print(ans)

Measured memory_bytes: 20456
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> num;
    rep(i, n) {
        cin >> a[i];
        num[a[i]]++;
    }
    ll base = 0;
    for(auto number : num){
        base += number.sc * (number.sc - 1) / 2;
    }
    rep(i, n){
        ll tmp = max(0LL, (num[a[i]] - 1));
        ll ans = max(0LL, base - tmp);
        print(ans);
    }
}


Measured memory_bytes: 12032