akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        long n = in.nl();
        long ans = 0;
        TreeMap<Long, Integer> fact = PrimeFactorization(n);
        for(Long prime: fact.keySet()){
            int e = fact.get(prime);
            int i = 1;
            while(i*(i+1)<=2*e) i++;
            i--;
            ans += i;
        }
        out.println(ans);
    }
    public static TreeMap<Long, Integer> PrimeFactorization(long n){
        TreeMap<Long, Integer> map = new TreeMap<>();
        long N = n;
        for (long i = 2; i*i <= N; i++) {
            while(n%i==0){
                map.put(i, map.containsKey(i)?map.get(i)+1:1);
                n /= i;
            }
        }
        if(n!=1) map.put(n, 1);
        return map;
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 34332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		int[][] c = new int[10][10];
		for (int i = 0; i < 100; i++) c[i%10][i/10] = 0;
		for (int i = 1; i <= n; i++) {
			String s = String.valueOf(i);
			c[s.charAt(0)-'0'][s.charAt(s.length()-1)-'0']++;
		}
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				ans += c[i][j]*c[j][i];
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 31828
#include <stdio.h>



int main() {
	int debt = 100000;
	int week;

	scanf("%d", &week);

	while (week--) {
		debt *= 1.05;
		if (debt % 1000) {
			debt = (debt / 1000 + 1) * 1000;
		}
	}

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

	return 0;
}

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


int main(){
  int N,K,d,i,a;
  int total = 0;
  cin >> N;
  cin >> K;
  for(i = 0; i < N; i++){
  	cin >> d;
    if(d == 1) break;
  }// iは1の場所
  
  total += i / (K-1);
  if(i % (K-1) != 0){
    total++;
    a = (K-1) - (i % (K-1));
  }
  else{
  	a = 0;
  }
  
  if(N-1-i-a > 0){
    total += (N-1-i-a) / (K-1);
    if((N-1-i-a) % (K-1) != 0) total++;
  }
  
  cout << total << endl;
}

Measured memory_bytes: 256
/*

Author : AllKilled
Date   : 201911166

Contest: AtCoder Beginner Contest 145.
Problem: Task A.
Result :

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

typedef long long LL;

const LL MAXN = 1e6+7;

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



int main()
{
    int a, b;
    cin >> a;
    cout << a * a << endl;
    return 0;
}


Measured memory_bytes: 256
P,S=print,sorted
n,k,*t=map(int,open(i:=0).read().split())
l=S([a<1<exit(P(-1)),a-1,i:=i+1]for a in t)[::-1]
*_,r=zip(*l)
while k:
 *_,b=r;k-=1
 for t in S(l)[::-1]:
  if t[2]-b:t[1]or exit(P(-1));t[1]-=1;r+=t[2],
P(len(r),*r)

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

#[allow(dead_code)]
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 r: i32 = read();
    let g: i32 = read();
    println!("{}", 2 * g - r);
}


Measured memory_bytes: 4352
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N,M;
	int[] A;

	public int gcd(int x,int y){
		return y == 0 ? x : gcd(y,x%y);
	}

	public void solve() {
		N = nextInt();
		M = nextInt();
		A = new int[N];
		for(int i = 0;i < N;i++){
			A[i] = nextInt();
		}
		int lcm = N * M / gcd(N,M);

		int ans = 0;

		int n = 0;

		for(int i = 0;i < lcm / M;i++){
			int min = Integer.MAX_VALUE;
			int max = Integer.MIN_VALUE;
			for(int j = 0;j < M;j++){
				min = Math.min(min, A[n]);
				max = Math.max(max, A[n]);
				n = (n+1)%N;

			}

			ans += max-min;
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	 

const ll mod=1e9+7;
const int INF=INT_MAX/2;

int n;
int a[200020];
ll cnt=0;

int main(){
	cin>>n;
	REP(i,n)cin>>a[i];
	vector<ll> s(n+1);
	s[0]=0;
	for(int i=1;i<n+1;i++){
		s[i]+=s[i-1]+a[i-1];
	}
	sort(s.begin(),s.end());
	ll temp=1;
	REP(i,n){
		if(s[i]==s[i+1])temp++;
		else{
			cnt+=temp*(temp-1)/2;
			temp=1;
		}
	}
	cnt+=temp*(temp-1)/2;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, s, t) for (int i = (int)(s); i <= (int)(t); i++)
#define rep(i, n) Rep(i, 0, (n) - 1)
const int INF = 1 << 26;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int h, w;
int sx, sy;
char grid[22][22];
int sale[10][100];
int dp[101][22][22][1 << 8];
vector<int> salev;
int toid[10];

int main()
{
	while (scanf("%d %d", &w, &h), w){
		fill_n(*sale, 10 * 100, -INF);
		fill_n(*grid, 22 * 22, '\0');
		fill_n(toid, 10, -1);
		salev.clear();
		
		for (int i = 1; i <= h; i++){
			for (int j = 1; j <= w; j++){
				scanf(" %c", &grid[i][j]);
				if (grid[i][j] == 'P'){
					sx = i;
					sy = j;
					grid[i][j] = '.';
				}
			}
		}
		
		int n;
		scanf("%d", &n);
		for (int i = 0; i < n; i++){
			int g, d, s, e;
			scanf("%d %d %d %d", &g, &d, &s, &e);
			for (int j = s; j < e; j++){
				sale[g][j] = max(sale[g][j], d);
			}
			salev.push_back(g);
		}
		
		sort(salev.begin(), salev.end());
		salev.erase(unique(salev.begin(), salev.end()), salev.end());
		
		for (int i = 0; i < salev.size(); i++){
			toid[salev[i]] = i;
		}
		
		fill_n(***dp, 101 * 22 * 22 * (1 << 8), -INF);
		dp[0][sx][sy][0] = 0;
		rep (t, 100) Rep (x, 1, h) Rep (y, 1, w){
			rep (got, 1 << salev.size()){
				if (dp[t][x][y][got] == -INF) continue;
				if (grid[x][y] != '.') continue;
				//if (dp[t][x][y][got] > 0) printf("%d\n", dp[t][x][y][got]);
				//printf("%d %d %d %d\n", t, x, y, got);
				//dp[t + 1][x][y][got] = max(dp[t + 1][x][y][got], dp[t][x][y][got]);
				rep (dir, 4){
					int nx = x + dx[dir];
					int ny = y + dy[dir];
					if (grid[nx][ny] >= '0' && grid[nx][ny] <= '9'){
						int g = grid[nx][ny] - '0';
						int id = toid[g];
						if (id != -1 && !(got & (1 << id))){
							dp[t][x][y][got | (1 << id)] = max(
								dp[t][x][y][got | (1 << id)],
								dp[t][x][y][got] + sale[g][t]
							);
						}
					}
					dp[t + 1][nx][ny][got] = max(
						dp[t + 1][nx][ny][got],
						dp[t][x][y][got]
					);
				}
			}
		}
		
		int res = 0;
		rep (t, 100) Rep (x, 1, h) Rep(y, 1, w) rep(st, 1 << salev.size()){
			res = max(res, dp[t][x][y][st]);
		}
		
		printf("%d\n", res);
	}
}

Measured memory_bytes: 50100
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int result = 0;

		for(int i=1;i<=c;i++) {
			if(i%a==0) {
				result+=b;
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 25300
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut a: Vec<usize> = (0..n).map(|_| read()).collect();

    let mut count = vec![0; (n + 1) / 2];
    for a_i in a {
        count[a_i / 2] += 1;
    }

    let ans = if count.iter().skip(1).all(|&x| x == 2) {
        mod_pow(2, n as u64 / 2)
    } else {
        0
    };

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

const MOD: u64 = 1_000_000_007;

fn mod_pow(b: u64, e: u64) -> u64 {
    if e == 0 {
        1
    } else if e & 1 == 0 {
        let d = mod_pow(b, e / 2);
        (d * d) % MOD
    } else {
        (b * mod_pow(b, e - 1)) % MOD
    }
}


Measured memory_bytes: 4352
N, M , Q = map(int, input().split())

LR = [[0]*(N+2-i) for i in range(N+2)]
for i in range(M):
  L, R = map(int, input().split())
  LR[L][R-L+1] += 1

  
for i in range(2,N+2):
  for j in range(1,N-i+2):
    LR[j][i] += LR[j][i-1] + LR[j+1][i-1] - LR[j+1][i-2]
    
for i in range(Q):
  p, q = map(int, input().split())
  print(LR[p][q-p+1]-LR[q+1][0])


Measured memory_bytes: 10376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

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

int main() {
	ll a;
	double b;
	cin >> a >> b;

	int c = round(b*100);
	cout << a*c/100 << endl;
	
	return 0;
}

















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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

using namespace std;

template<class T>void reg(vector<T> &ary,const T &elem){ary.emplace_back(elem);}

using R=long double; 
const R EPS = 1E-11;
const R INF = 1E40;
constexpr R PI = acos(R(-1));
inline int sgn(const R& r){ return (r > EPS) - (r < -EPS);}
inline int sgn(const R& a, const R &b){ return sgn(a-b); }
inline R sq(R x){return sqrt(max<R>(x,0.0));}

using P=complex<R>;
using VP=vector<P>;
using L=struct{P s,t;};
using VL=vector<L>;

constexpr P O = P(0,0);
istream& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){a-=o,b-=o; return real(conj(a)*b);}
inline R det(P o,P a,P b){a-=o,b-=o; return imag(conj(a)*b);}
inline P vec(L l){return l.t-l.s;}


enum CCW{ LEFT = 1,RIGHT = 2,BACK = 4,FRONT = 8,ON = 16};
inline int ccw(P o,P a, P b) {
	if (sgn(det(o,a,b)) > 0) return LEFT;
	if (sgn(det(o,a,b)) < 0) return RIGHT;
	if (sgn(dot(o,a,b)) < 0) return BACK;
	if (sgn(norm(a-o)-norm(b-o)) < 0) return FRONT;
	return ON;
}

P cross(L a,L b){
	R s1=det(a.s,b.s,b.t);
	R s2=s1+det(a.t,b.t,b.s);
	return a.s+s1/s2*(a.t-a.s);
}

R area(const VP& pol){
	int n=pol.size();
	R sum=0;
	rep(i,n) sum+=det(O,pol[i],pol[(i+1)%n]);
	return abs(sum/2.0);
}

VP convex_cut(const VP& pol,const L& l) {
	VP res;
	int n=pol.size();
	rep(i,n){
		P a = pol[i],b=pol[(i+1)%n];
		if(ccw(l.s,l.t,a)!=RIGHT) reg(res,a);
		if((ccw(l.s,l.t,a)|ccw(l.s,l.t,b))==(LEFT|RIGHT)) reg(res,cross({a,b},l));
	}
	return res;
}

L bisector(P a, P b){P mid=(a+b)/P(2,0);return L{mid, mid+(b-a)*P(0,1)};}
VP voronoi_cell(VP pol,VP v,int s){rep(i,v.size())if(i!=s)pol=convex_cut(pol,bisector(v[s],v[i]));return pol;}

int main(void){
	int n,m;
	while(cin >> n >> m,n){
		VP island(n),lord(m);
		rep(i,n) cin >> island[i];
		rep(i,m) cin >> lord[i];

		cout.precision(20);
		rep(i,m) cout << fixed << area(voronoi_cell(island,lord,i)) << endl;
	}
	return 0;
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
int main()
{
    using namespace std;
    int N, K, d, s, sum(0);
    cin >> N >> K;
    bool A[N] = {false};
    for (int i = 0; i < K; i++)
    {
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            cin >> s;
            A[s - 1] = true;
        }
    }
    for (int i = 0; i < N; i++)
    {
        if (A[i] == false)
        {
            sum++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define INF 3000000000

int main(){
	int N;
	cin >> N;
	long long x[N], y[N];
	long long Mp = 0, mp = INF, Mm = -1 * INF, mm = INF;
	for(int i=0;i<N;i++){
		cin >> x[i] >> y[i];
		Mp = max(Mp, x[i] + y[i]);
		mp = min(mp, x[i] + y[i]);
		Mm = max(Mm, x[i] - y[i]);
		mm = min(mm, x[i] - y[i]);
	}
	long long ans = Mp - mp;
	ans = max(ans, Mm - mm);
	cout << ans << endl;
}

Measured memory_bytes: 6692
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    c = S()

    return chr(ord(c) + 1)


print(main())





Measured memory_bytes: 6740
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,T,L,B,a;
	while(scanf("%d%d%d%d",&n,&T,&L,&B),n){
		bool b[n+1],l[n+1]; double p[2][n+1][2];
		rep(i,n+1){
			b[i]=l[i]=0; rep(j,2)rep(k,2)p[j][i][k]=0;
		}
		rep(i,L)scanf("%d",&a),l[a]=1; rep(i,B)scanf("%d",&a),b[a]=1;
		p[0][0][0]=1;
		rep(t,T){
			rep(i,n+1)rep(j,2)p[t&1^1][i][j]=0;
			rep(i,n)rep(j,6){
				int ni=i+j+1;
				if(ni>n)ni=2*n-ni; if(b[ni])ni=0;
				p[t&1^1][ni][l[ni]]+=p[t&1][i][0]/6;
			}
			rep(i,n)p[t&1^1][i][0]+=p[t&1][i][1];
			p[t&1^1][n][0]+=p[t&1][n][0];
		}
		printf("%.6f\n",p[T&1][n][0]);
	}
	return 0;
}

Measured memory_bytes: 0
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
xy = []

for _ in range(N):
	A = INT()
	xy_A = []
	for _ in range(A):
		xy_A.append(LIST())
	xy.append(xy_A)

ans = 0
for X in product((0, 1), repeat=N):
	honest = [-1]*N
	for j in range(N):
		if X[j] == 0:
			if honest[j] == -1:
				honest[j] = 0
			elif honest[j] == 1:
				break
		elif X[j] == 1:
			if honest[j] == -1:
				honest[j] = 1
			elif honest[j] == 0:
				break

			for x, y in xy[j]:
				if honest[x-1] == -1:
					honest[x-1] = y
				elif honest[x-1] != y:
					break
			else:
				continue
			break
	else:
		ans = max(ans, sum(X))

print(ans)


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


ll gcd(ll x, ll y);
ll lcm(ll x, ll y);
int main()
{
    int a, b; cin >> a >> b;
    cout << lcm(a,b) << endl;
    return 0;
}

ll gcd(ll a, ll b){
    if(a<b){
        a ^= b;
        b ^= a;
        a ^= b;
    }

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

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

ll floor2(ll num){
    ll ret = 1LL;
    while(ret <= num){
        ret *= 2;
    }
    ret /= 2;

    return ret;
}

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

    ll a, b; cin >> a >> b;
    if(a == b){
        cout << 1 << endl;
        return 0;
    }

    ll floorb = floor2(b);
    ll floora = floor2(a);
    while(floorb == floora){
        b &= ~floorb;
        a &= ~floora;
        floorb = floor2(b);
        floora = floor2(a);
    }

    if(floorb != b){
        bool f = false;
        for(ll i = floorb / 2; i >= 1LL; i /= 2){
            if(b & i){
                f = true;
            }
            if(f){
                b |= i;
            }
        }
    }

    ll res = b - a + 1;
    if(floorb <= a){
        cout << res << endl;
        return 0;
    }

    ll unum = b - floorb + 1;
    ll lnum = floorb - a;
    ll diff = lnum;

    if(unum + lnum > floorb){
        diff = diff - (unum + lnum - floorb);
    }
    res += diff;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class DivGame
    {
        static void Main(string[] args)
        {
            ulong n = ulong.Parse(Console.ReadLine());
            ulong i = 2;
            ulong div = n;
            var PrimeList = new List<ulong>();

            while(i*i <= n)
            {
                if (div % i == 0)
                {
                    div /= i;
                    PrimeList.Add(i);

                }
                else
                {
                    i++;
                }
            }
            if (div != 1) PrimeList.Add(div);

            var PrimeListCount = new List<int>();
            ulong before = 0;
            int count = 0;

            foreach(var data in PrimeList)
            {
                if(before == 0)
                {
                    before = data;
                    count=1;
                }
                else if(before == data)
                {
                    count++;
                }
                else
                {
                    before = data;
                    PrimeListCount.Add(count);
                    count = 1;
                }
            }
            if (count > 0)
            {
                PrimeListCount.Add(count);
            }

            int x = 0;
            foreach(var data in PrimeListCount)
            {
                int next = 0;
                for(int j = data;j>next;j -= next)
                {
                    x++;
                    next++;
                }
            }
            Console.WriteLine(x);
        }

    }

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

using namespace std;

#define ll					long long
#define vi					vector<int>
#define vii					vector<vi>
#define ALL(s)			(s).begin(),(s).end()
#define pii					pair<int, int> pii;
#define pll					pair<ll, ll>
#define si					set<int>
#define mp					make_pair
#define F						first
#define S						second
#define pb					push_back
#define tc(t)				int t; cin >> t; while(t--)
#define _						ios_base::sync_with_stdio(false); cin.tie(NULL); 
const ll MOD = 1e9 + 7;
const ll INF = 1<<29;
const ll MAX_N = 1e6 + 7;

int main() {_
	int n,m;
	cin >> n >> m;

	cout << ((m < n) ? "No" : "Yes");

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, int> P;

int main(){
    int N, M; cin >> N >> M;
    P vec[200200];
    for(int i=0; i<N; i++){
        ll a;
        cin >> a;
        vec[i]=P(a,1);
    }
    for(int i=0; i<M; i++){
        int b; ll c; cin >> b >> c;
        vec[i+N]=P(c,b);
    }
    sort(vec,vec+(N+M),greater<P>());
    int cnt=N;
    ll ans=0;
    int j=0;
    while(cnt > 0){
        P mm = vec[j];
        ll c = mm.first;
        int b = mm.second;
        if(cnt >=b){
            ans += (b*c);
            cnt -=b;
        }
        else{
            ans += (cnt *c);
            cnt=0;
        }
        j++;
    }
    cout << ans <<endl;
}

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

int main() {
  int64_t A,B,K;
  cin >> A >> B >> K;
  
  int64_t C=A-K;
  
  if(C>=0)
    cout << C << " " << B << endl;
  
  else if(A+B-K>=0)
    cout << 0 << " " << A+B-K << endl;
  
  else 
    cout << 0 << " " << 0 << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var x1, y1, x2, y2 int
	fmt.Scan(&x1, &y1, &x2, &y2)
	dx, dy := x2-x1, y2-y1
	x3, y3 := x2-dy, y2+dx
	x4, y4 := x1-dy, y1+dx
	fmt.Println(x3, y3, x4, y4)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b;
  cin >> a >> b;
  int k = 50;
  vector<string> grid(2*k);
  REP(i, k) grid[i] = string(2*k, '#');
  REP(i, k) grid[i+k] = string(2*k, '.');

  int dx[] = {0, 0, -1, 1, -1, 1, -1, 1};
  int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1};
  int count = 0;
  REP(i, k-1) REP(j, 2*k){
    if(count == a-1) continue;
    bool ok = true;
    REP(n, 8){
      int jd = j+dx[n];
      int id = i+dy[n];
      if(id < 0 || jd < 0 || jd >= 2*k) continue;
      if(grid[id][jd] == '.') ok = false;
    }
    if(!ok) continue;
    grid[i][j] = '.';
    count++;
  }

  count = 0;
  FOR(i, k+1, 2*k) REP(j, 2*k){
    if(count == b-1) continue;
    bool ok = true;
    REP(n, 8){
      int jd = j+dx[n];
      int id = i+dy[n];
      if(2*k <= id || jd < 0 || jd >= 2*k) continue;
      if(grid[id][jd] == '#') ok = false;
    }
    if(!ok) continue;
    grid[i][j] = '#';
    count++;
  }
  printf("%d %d\n", 2*k, 2*k);
  REP(i, 2*k) cout << grid[i] << endl;

  return 0;
}

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

#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    scanf("%d",&m);
    return m ;
}
inline ll lD()
{
    ll m ;
    scanf("%lld",&m);
    return m ;
}
inline double dD()
{
    double m ;
    scanf("%llf",&m);
    return m ;
}
ll LCM(ll a, ll b)
{
    return a / __gcd(a, b) * b;
}
int main(){
    int a=D(),b=D(),c=D();
    int x=a+b;
    if(x>=c)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


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

int main(void){
  int m, f ,r;
  char t;
  while(1){
    cin >> m >> f >> r;
    if (m==-1&&f==-1&&r==-1) break; 
    if (m==-1||f==-1) {
        t = 'F';
    } else if (m+f>=80) {
        t = 'A';
    } else if ((m+f>=65)&&(m+f<80)) {
        t = 'B';
    } else if ((m+f>=50)&&(m+f<65)) {
        t = 'C';
    } else if ((m+f>=30)&&(m+f<50)) {
        if (r>=50) {
        t = 'C';
        } else {
        t = 'D';
        }
    } else {
        t = 'F';
    }
  cout << t <<endl;
  }
}


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

class Dice{
    public:
    int val[6];

    Dice(int a[]){
        copy(a,a+6,val);
    }

    int side(){
        return val[2];
    }

    bool match(int f, int u){
        return (val[0] == f && val[4] == u); 
    }

    void move(char c){
        if(c == 'N') {
            int tmp = val[0];
            val[0] = val[1];
            val[1] = val[5];
            val[5] = val[4];
            val[4] = tmp;
        }
        if(c == 'W') {
            int tmp = val[1];
            val[1] = val[3];
            val[3] = val[4];
            val[4] = val[2];
            val[2] = tmp;
        }
        if(c == 'E') {
            int tmp = val[1];
            val[1] = val[2];
            val[2] = val[4];
            val[4] = val[3];
            val[3] = tmp;
        }
        if(c == 'S') {   
            int tmp = val[0];
            val[0] = val[4];
            val[4] = val[5];
            val[5] = val[1];
            val[1] = tmp;
        }
    }
};

int main() {
    string str = "WWWWNWWWWWSWWWWSSWWWWNWWWWWSWWWW";
    int a[6],q;
    rep(i,6) cin >> a[i];
    Dice d(a);
    cin >> q;
    rep(i,q){
        int u,f;
        cin >> u >> f;
        for(auto &s : str){
            d.move(s);
            if(d.match(f,u)) {
                cout << d.side() << endl;
                break;
            }
        }
    }
    return 0;
}


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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
typedef long long ll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a<=k){
        cc("Yay!");
    }else{
        cc(":(");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int suma=0,sumb=0;
	for(;suma<c;suma+=a){
		
		sumb+=b;
	}
	if(suma>c) printf("%d\n",sumb-b);
	else if(suma==c) printf("%d\n",sumb);
	return 0;
}

Measured memory_bytes: 384
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let R2 T U = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U)
let R3 T U V = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V)
let R4 T U V W = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W)
let R5 T U V W X = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W),(c.[4]|>X)
let outl s = stdout.WriteLine(s|>string)
let outsep ls = stdout.WriteLine(String.concat " " (ls|>Array.map string))
let outsepl ls = stdout.WriteLine(String.concat "\n" (ls|>Array.map string))
[<EntryPoint>]
let main argv =
    R int
    |>fun c->(1000-(c%1000))%1000
    |>stdout.WriteLine
    0

Measured memory_bytes: 27884
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;
int gcd(int a, int b) {
  if ( b == 0 ) return a;
  return gcd(b,a%b);
}


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

  int A[100010];
  int B[100010];
  int C[100010];
  int D[100010];
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];
  }
  sort(A,A+N);
  B[0] = A[0];
  for ( int i = 1; i < N; i++ ) {
    B[i] = gcd(A[i],B[i-1]);
  }
  int less = -1;
  int index1,index2;
  for ( int i = 1; i < N; i++ ) {
    if ( B[i-1] - B[i] > less ) {
      less = B[i-1]-B[i];
      index1 = i;
      index2 = i-1;
    }
  }

  if ( index2 != 0 ) {
    C[0] = A[0];
    for ( int i = 1;i < N; i++ ) {
      if ( i == index2 ) {
	C[i+1] = gcd(A[i+1],C[i-1]);
	i++;
      } else {
	C[i] = gcd(A[i],C[i-1]);
      }
    }
  } else if ( index2 == 0 ) {
    C[1] = A[1];
    for ( int i = 2;i < N; i++ ) {
      C[i] = gcd(A[i],C[i-1]);
    }
  }
  int ans = B[N-1];
  // cout << ans << endl;
  ans = max(ans,C[N-1]);
  // cout <<"C" << ans << endl;
  if ( index1 == N-1 ) {
    D[0] = A[0];
    for ( int i = 1; i < N-1; i++ ) {
      D[i] = gcd(A[i],D[i-1]);
    }
    D[N-1] = D[N-2];
  } else {
    D[0] = A[0];
    for ( int i = 1; i < N; i++ ) {
      if ( i == index1 ) {
	D[i+1] = gcd(A[i+1],D[i-1]);
	i++;
      } else {
	D[i] = gcd(A[i],D[i-1]);
      }
    }
  }
  // cout << "D" << D[N-1] << endl;
  cout << max(ans,D[N-1]) << endl;
  return 0;
}


Measured memory_bytes: 1792
num=[]
for i in range(int(input())):
	num.append(int(input()))
	if i==0:
		min=num[0]
	elif i==1:
		max=num[1]-num[0]
		if num[1]<min:
			min=num[1]
	else:
		if num[i]-min>max:
			max=num[i]-min
		elif num[i]<min:
			min=num[i]
print(max)
		
	


Measured memory_bytes: 13584
#include<iostream>
#include<algorithm>
int main(){
  uint32_t N;
  std::cin >> N;
  int64_t *a = (int64_t *)malloc(sizeof(int64_t)*N);
  for(uint32_t i = 0; i < N; ++i){
    std::cin >> a[i];
    a[i] -= (i+1);
  }

  std::sort(a, a+N);
  int64_t b = a[N/2];
  uint64_t ans = 0;
  for(uint32_t i = 0; i < N; ++i){
    ans += abs(a[i] - b);
  }
  std::cout << ans << std::endl;
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

vector<int> G[MAX];
int dp[MAX];

void dfs(int v) {
    int res = -1;
    for (int u : G[v]) {
        if (dp[u] < 0) dfs(u);
        chmax(res, dp[u]);
    }
    if (res < 0) dp[v] = 0;
    else dp[v] = res + 1;
}

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

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }

    rep(i, N) dp[i] = -1;
    rep(i, N) {
        if (dp[i] < 0) dfs(i);
    }

    int ans = 0;
    rep(i, N) chmax(ans, dp[i]);
    cout << ans << endl;
}

Measured memory_bytes: 10496
A,B,C,X,Y=map(int,input().split())
ans=10**10
Z=max(X,Y)
for i in range(0, Z+1):
    tmp=C*i*2
    if X-i>=0:
        tmp+=A*(X-i)
    if Y-i>=0:
        tmp+=B*(Y-i)
    ans=min(ans,tmp)
print(ans)


Measured memory_bytes: 39280
public class Main {
	
		
		public static void main(String[] args) {
			java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
			
//			BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
//			String str = br.readLine();
//			int x = Integer.parseInt(str);
//			
		if(1<=x && x<=100){;
		System.out.println(x*x*x);// TODO ?????????????????????????????????????????????
		}
			
			
		}
	
	}
	

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

int main() {

    long n;
    cin >> n;
    long m = 0;
    rep(i, n){
        m += i + 1;
    }
    cout << m - n << endl;


}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    var low = 0
    var high = n / 2 + 1
    while (high - low > 1) {
        val mid = low + (high - low) / 2
        if (solve(s, mid)) {
            low = mid
        } else {
            high = mid
        }
    }
    println(low)
}

fun solve(s: String, divide: Int): Boolean {
    fun String.window(windowSize: Int, step: Int = 1): List<String> {
        val n = (length - windowSize) / step + 1
        return (0 until n).map { substring(step * it, step * it + windowSize) }
    }
    fun <T> Iterable<T>.duplicate(): Set<T> {
        val set = HashSet<T>()
        val duplicateSet = HashSet<T>()
        this.forEach {
            if(set.contains(it)) {
                duplicateSet.add(it)
            } else {
                set.add(it)
            }
        }
        return duplicateSet
    }

    val windowed = s.window(divide).duplicate()
    return windowed.any {
        s.indexOf(it) + it.length <= s.lastIndexOf(it)
    }
}

Measured memory_bytes: 126104
//????????¢????????????

#include<iostream>
using namespace std;
int main()
{
int w,h,x,y,r;
cin>>w>>h>>x>>y>>r;
if(w-x>=r&&x>=r&&h-y>=r&&y>=r)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;

return 0;
}

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

using namespace std;

# define REP(i, a, b) for(int i = a; i <= b; ++ i)
# define REPD(i, a, b) for(int i = a; i >= b; -- i)
# define CLR(i, a) memset(i, a, sizeof(i))
# define REPG(i, h, x) for(int i = h[x]; ~i; i = edge[i].next)

typedef long long LL;
const int N = 2e5 + 3;

char buf[N];
LL suc[N][30];
int n;

int pe, nxt[N];
LL fib(LL len, int c) {
    if(len <= n) return suc[len][c];
    if(len <= n * 2) return suc[n][c] + suc[len - n][c];
    LL g1 = suc[n][c], g2 = suc[n][c] + suc[pe][c], l1 = n, l2 = n + pe;
    while(len > l1 + l2) {
        LL tg = g2; g2 += g1, g1 = tg;
        LL tl = l2; l2 += l1, l1 = tl;
    }
    return g2 + fib(len - l2, c);
}
LL lf, rt;
LL calc(LL len, int c) {
    if(len <= n) return suc[len][c];
    else if(n % pe) return fib(len, c);
    else {
        LL ret = 1ll * (len - n) / pe * suc[pe][c] + suc[n][c];
        len -= n, len %= pe;
        return ret + suc[len][c];
    }
}

inline void get_nxt() {
    int j = 0; nxt[1] = 0;
    REP(i, 2, n) {
        while(j && buf[j + 1] != buf[i]) j = nxt[j];
        if(buf[j + 1] == buf[i]) ++ j;
        nxt[i] = j;
    }

}

int main() {
    scanf("%s%lld%lld", buf + 1, &lf, &rt);
    n = strlen(buf + 1); n >>= 1;
    get_nxt();
    for(int i = 1; i <= n; i ++) {
        for(int j = 0; j < 26; j ++) suc[i][j] = suc[i - 1][j];
        suc[i][buf[i] - 'a'] ++;
    }
    pe = n - nxt[n];
    REP(i, 0, 25) printf("%lld ", calc(rt, i) - calc(lf - 1, i));
    return 0;
}

Measured memory_bytes: 24576
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int n,i,x,flg;
	scanf("%d",&n);
	flg=0;
	for(i=0;i<=n;i+=4)	{
		x=n-i;
		if(x%7==0)	{
			flg=1;
			break;
		}
	}
	if(flg==1)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
   ll k;
   cin>>k;
   ll s=0;
   for(ll i=1;i<=k;i++)
   {
       for(ll j=1;j<=k;j++)
       {
           for(ll l=1;l<=k;l++)
           {
               s+=__gcd(i,__gcd(j,l));
           }
           
       }
   }
   cout<<s;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
int main()
{
    std::string s;
    std::cin >> s;
    const int N = s.size();
    std::vector<std::vector<int>> to(N);
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= 3; j++) {
            const int num = std::stoi(s.substr(i, j));
            if (num > 255) { continue; }
            if (num == 0) {
                if (j > 1) { continue; }
            } else {
                if (s[i] == '0') { continue; }
            }
            to[i].push_back(i + j);
        }
    }
    std::vector<std::vector<int>> memo(N + 1, std::vector<int>(5, -1));
    auto rec = [&, N](auto&& self, const int i, const int j) {
        if (j == 4) { return (i == N ? 1 : 0); }
        if (i >= N) { return 0; }
        if (memo[i][j] != -1) { return memo[i][j]; }
        int ans = 0;
        for (const int n : to[i]) { ans += self(self, n, j + 1); }
        return memo[i][j] = ans;
    };
    const int ans = rec(rec, 0, 0);
    std::cout << ans << std::endl;
    return 0;
}



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

typedef unsigned long long ull;


int main(){
	ull a, b, n;
	cin >> a >> b >> n;
	if(n >= b)
		n = b-1;
	double ans =  (ull)(floor((double)(a*n)/(double)b) - (double)a * floor((double)n/(double)b));
	cout << (ull) ans << endl;
}


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

int main()
{
    int n, x;
    int count = 0;

    while (true)
    {
        cin >> n >> x;
        if ((n == 0) && (x == 0))
            break;
        for (int i = 1; i <= (n - 2); i++)
        {
            for (int j = i + 1; j <= (n - 1); j++)
            {
                for (int k = j + 1; k <= n; k++)
                {
                    if ((i + j + k) == x)
                        count++;
                }
            }
        }
        cout << count << endl;
        count = 0;
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

int main() {
  lli n;
  int mod = 1000000007;
  std::cin >> n;
  std::vector<lli> v;
  lli sum = 0;
  for (lli i = 0; i < n; ++i) {
    int f;
    std::cin >> f;
    v.push_back(f);
    sum += f;
    sum %= mod;
  }
  lli ans = 0;
  for (int i = 0; i < (int)v.size(); ++i) {
    sum -= v[i];
    if (sum < 0) sum += mod;
    ans += v[i]*sum;
    ans %= mod;
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 5284
s = input()
count = 0

if len(s) % 2 == 0:
    for i in range(int(len(s) / 2)):
        if s[i] == s[len(s) - i - 1]:
            pass
        else:
            count += 1
    print(count)

else:
    for i in range(int((len(s) - 1) / 2)):
        if s[i] == s[len(s) - i - 1]:
            pass
        else:
            count += 1
    print(count)



Measured memory_bytes: 3060
#include <iostream>

using namespace std;
int H, A[500001];

void heapfy(int i) {

    int l, r;
    l = i * 2 + 1;
    r = i * 2 + 2;

    int i_ = i;

    if (l < H && A[l] > A[i_]) i_ = l;
    if (r < H && A[r] > A[i_]) i_ = r;

    if (i_ != i) {
        int tmp = A[i];
        A[i] = A[i_];
        A[i_] = tmp;
        heapfy(i_);
    }
}

int main() {

    cin >> H;

    for (int i = 0; i < H; i++) {
        cin >> A[i];
    }

    for (int i = (H - 1) / 2; i >= 0; i--) {
        heapfy(i);
    }

    for (int i = 0; i < H; i++) {
        cout << " " << A[i];
    }
    cout << endl;
}


Measured memory_bytes: 5032
N = gets.to_i
PS = (0...N).map{ gets.split.map &:to_i }
EPS = 1e-8
#p EPS

def contains_all(cx,cy,r2,points)
  r = points.all?{ |x,y| r2 - (cx-x)**2 - (cy-y)**2 >= -EPS }
  #$stderr.puts "(#{cx},#{cy}) x #{r2} -> #{r}"
  r
end

r = 1000000000000000
(0...N).each{ |i|
  xa,ya = PS[i]
  (i+1...N).each{ |j|
    xb,yb = PS[j]
    # check for doublet
    r2 = ((xa-xb) ** 2 + (ya-yb) ** 2) / 4.0
    centx = (xa+xb)/2.0
    centy = (ya+yb)/2.0
    #$stderr.puts(Math.sqrt(r2))
    if r2 < r && contains_all(centx, centy, r2, PS)
      #p [PS[i], PS[j], centx, centy, r2]
      r = [r, r2].min
    end
    
  	c2 = (xa-xb)**2 + (ya-yb)**2
  	c1 = Math.sqrt(c2)
    (j+1...N).each{ |k|
      # check for triplet
      xc,yc = PS[k]
  	  a2 = (xb-xc)**2 + (yb-yc)**2
  	  b2 = (xa-xc)**2 + (ya-yc)**2
	  a1 = Math.sqrt(a2)
  	  b1 = Math.sqrt(b2)
      ae = a2*(b2+c2-a2); be = b2*(a2+c2-b2); ce = c2*(a2+b2-c2)
      d = ae + be + ce
      next if d == 0
      centx = (ae*xa + be*xb + ce*xc) / d.to_f
      centy = (ae*ya + be*yb + ce*yc) / d.to_f
      r2 = (a1*b1*c1) ** 2 / ((a1+b1+c1)*(-a1+b1+c1)*(a1-b1+c1)*(a1+b1-c1))
      #$stderr.puts Math.sqrt(r2)
      if r2 < r && contains_all(centx, centy, r2, PS)
       	#p [PS[i], PS[j], PS[k], centx, centy, a1, b1, c1, r2]
      	r = r2
     end
    }
  }
}
p Math.sqrt(r)

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

int main(){ 
  int64_t k, q;
  vector<int64_t> d(5010);
  cin >> k >> q;
  for(int i=1; i<=k; i++) cin >> d[i];

  for(int query=0; query<q; query++){
    int64_t n, x, m, zeros = 0, ans = 0, sum = 0, kuriagari = 0;
    cin >> n >> x >> m;
    x %= m;

    vector<int64_t> dmod(5010);
    for(int i=1; i<=k; i++){
      dmod[i] = d[i] % m;
      if(dmod[i] == 0) zeros++;
      sum += dmod[i];
    }

    int64_t loops = (n-1) / k, rest = (n-1) % k;

    kuriagari += (sum * loops + x) / m;
    int64_t nokori = (sum * loops + x) % m;
    for(int i=1; i<=rest; i++){
      nokori += dmod[i];
      if(nokori >= m){
        nokori %= m;
        kuriagari++;
      }
    }
  

    ans += loops * (k-zeros);

    for(int i=1; i<=(n-1)%k; i++){
      if(dmod[i] % m != 0) ans++;
    }

    ans -= kuriagari;

    cout << ans << endl;
  }
}

Measured memory_bytes: 512
S=gets.chomp
s=S.delete('x')

if s.reverse != s
    puts -1
    exit 0
end

l = 0
r = S.length-1
ret = 0
while l < r
    if S[l] == 'x' && S[r] == 'x' && l != r
        l += 1
        r -= 1
    elsif S[l] == 'x'
        ret += 1
        l += 1
    elsif S[r] == 'x'
        ret += 1
        r -= 1
    else
        l += 1
        r -= 1
    end
end

puts ret

Measured memory_bytes: 4092
#include "bits/stdc++.h"

using namespace std;
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define FO(i, x, n) for(int i=x; i<n; i++)
#define aLL(x) x.begin(), x.end()
#define pB push_back
#define eB emplace_back
#define tRav(a, x) for(auto& a: x)
#define fI first
#define sE second
#define lB lower_bound
#define uB upper_bound
#define MOD 1000000007


int main(){
	fast_cin();
	int a[3][3];
	FO(i, 0, 3)
	FO(j, 0, 3)
		cin>>a[i][j];
	int n;cin>>n;
	vector<int> v(n);
	FO(i, 0, n)
		cin>>v[i];
	bool b[3][3];
	FO(i, 0, 3)
	FO(j, 0, 3)
		b[i][j]=0;
	FO(i, 0, 3)
	FO(j, 0, 3){
		tRav(x, v)
		if(a[i][j]==x)
			b[i][j]=1;
	}
	int flag = 0;
	for(int i=0;i<3;i++)
	if(b[i][0]==true and b[i][1]==true and b[i][2]==true)
		flag = 1;
	for(int i=0;i<3;i++)
	if(b[0][i]==true and b[1][i]==true and b[2][i]==true)
		flag = 1;
	if(b[0][0]==true and b[1][1]==true and b[2][2]==true)
		flag = 1;
	if(b[0][2]==true and b[1][1]==true and b[2][0]==true)
		flag = 1;
	if(flag)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int S, W; cin >> S >> W;
    if (W >= S) {
        cout << "unsafe\n";
    } else {
        cout << "safe\n";
    }
    return 0;
}


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

int n, sum[100005], cnt[16], dp[1 << 15];

int main() {
	scanf("%d", &n);
	for (int i = 1, u, v, c; i < n; ++i) {
		scanf("%d%d%d", &u, &v, &c);
		sum[u] ^= c, sum[v] ^= c;
	}
	for (int i = 0; i < n; ++i) ++cnt[sum[i]];
	int ans = 0, buc = 0;
	for (int i = 1; i < 16; ++i) ans += cnt[i] >> 1, buc |= (cnt[i] & 1) << i - 1;
	for (int s = 1; s <= buc; ++s) {
		int t = 0;
		for (int i = 0; i < 15; ++i)
			if (s >> i & 1) ++dp[s], t ^= i + 1;
		dp[s] -= !t;
		for (int t = s - 1 & s; t; t = t - 1 & s)
			dp[s] = min(dp[s], dp[t] + dp[s ^ t]);
	}
	printf("%d\n", ans + dp[buc]);
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

int n;
int a[200010],r[200010],l[200010];
ll ans;

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

	cin>>n;
	REP(i,n) cin>>a[i+1];

	stack<int> s;
	s.push(0);
	FOR(i,1,n+2) {
		while(!s.empty()&&a[s.top()]>a[i]) {
			r[s.top()]=i;
			s.pop();
		}
		if(!s.empty()) l[i]=s.top();
		s.push(i);
	}
	FOR(i,1,n+1) {
		ans+=(ll)a[i]*(r[i]-i)*(i-l[i]);
		//cout<<a[i]<<' '<<r[i]<<' '<<l[i]<<endl;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3228