akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, K;
  cin>>N>>K;
  vector<Int> A(N);
  cin>>A;
  vector<Int> F(N);
  cin>>F;
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<Int>());

  auto calc = [&](Int a, Int b, Int X){
    Int L = 0, R = a;
    while(L + 1 < R){
      Int M = (L + R) / 2;
      (a-M) * b > X? (L=M):(R=M);
    }
    return R;
  };
  auto check=[&](Int X){
    Int k = K;
    for(Int i=0;i<N;i++){
      Int a = A[i];
      Int b = F[i];
      /*
        Int t = (X - a * b) / b;
        pr(a, b, X, "pre", t);
        while((a - t) * b > X) t++;
        pr("last", t);
      */
      Int t = calc(a, b, X);
      if(a * b > X) k -= t;
      if(k < 0) return 0;
      assert((a - t) * b <= X);
    }
    return 1;
  };

  Int L = -1, R = INF / 2;
  while(L + 1< R){
    Int M = (L + R) / 2;
    check(M)? (R = M): (L = M);
  }
  cout<<R<<endl;

  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    char X, Y;
    cin >> X >> Y;
    
    if (X == Y){
        cout << '=' << endl;
    }
    else if (X < Y){
        cout << '<' << endl;
    }
    else {
        cout << '>' << endl;
    }
}

Measured memory_bytes: 256
H,W=map(int, input().split())
A=[]
for i in range(H):
  d=list(input())
  A.append(d)
D=[[0]*W for i in range(H)]

cnt=0
for i in range(H):
  if A[i][0]=='.' and cnt==0:
    D[i][0]=1
  else:
    cnt=1
cnt=0
for i in range(W):
  if A[0][i]=='.' and cnt==0:
    D[0][i]=1
  else:
    cnt=1
mod=10**9+7
for i in range(1,H):
  for j in range(1,W):
    if A[i][j]=='.':
      D[i][j]+=(D[i-1][j]+D[i][j-1])
      D[i][j]%=mod
print(D[-1][-1])

Measured memory_bytes: 51444
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto s = sort(readln.chomp.split).array;
  if (s == ["1", "4", "7", "9"]) {
    writeln("YES");
  } else {
    writeln("NO");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int c[13] = { 1 };
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;

        c[d]++;
    }

    int r = 12;
    int k = 0;
    int x[24] = {};
    for (int i = 0; i <= 12; i++) {
        if (c[i] > 2 || (i % 12 == 0 && c[i] > 1)) {
            r = 0;
            break;
        }
        for (int j = 0; j < c[i]; j++) {
            x[j == k ? i : 24 - i]++;
        }
        if (c[i] == 1) k ^= 1;
    }

    int j = -r;
    for (int i = 0; i <= 24; i++) {
        if (i == 24 || x[i]) {
            r = min(r, i - j);
            j = i;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    int ans = INF;
    rep(i, 1, N) {
        if (i * i > N) {
            break;
        }
        if (N % i == 0) {
            int a = i;
            int b = N / i;
            chmin(ans, abs(a - 1) + abs(b - 1));
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int val[200005],vis[200005];
vector<int> edge[200005];
void dfs(int u,int k){
    val[u]+=k;vis[u]=1;
    for(int i=0;i<edge[u].size();i++){
        int v=edge[u][i];
        if(vis[v]) continue;
        dfs(v,val[u]);
    }
}
int main(){
    int n,q;
    cin>>n>>q;
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    for(int i=1;i<=q;i++){
        int x,y;
        cin>>x>>y;
        val[x]+=y;
    }
    dfs(1,0);
    for(int i=1;i<=n;i++){
        cout<<val[i]<<" ";
    }
    cout<<endl;
}


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

//最大公倍数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
long long lcm(int x, int y){
  return (long long) x / gcd(x,y) * y;
}

int main() {
    int a,b; cin >> a >> b;
    cout << lcm(a,b) << endl;
}

Measured memory_bytes: 3608
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

N,C,*H = map(int,read().split())

class CHT:
    """
    f_i = a_ix + b_i とする。f_i の追加および、min_i f(x) の取得ができるデータ構造。
    ただし、傾き a_i は昇順に追加されなければならない。
    また、クエリ x も昇順に実行されなければならない。
    """
    def __init__(self):
        self.funcs = deque()

    def add(self,a,b):
        funcs = self.funcs
        while len(funcs) >= 2:
            a1,b1 = funcs[-2]
            a2,b2 = funcs[-1]
            if (a2-a1)*(b-b2) < (b2-b1)*(a-a2):
                break
            funcs.pop()
        funcs.append((a,b))

    def query(self,x):
        funcs = self.funcs
        a,b = funcs[0]
        y = a*x+b
        while len(funcs) >= 2:
            a2,b2 = self.funcs[1]
            y2 = a2*x+b2
            if y < y2:
                break
            y = y2
            self.funcs.popleft()
        return y

dp = [0] * N
cht = CHT()

h = H[0]
cht.add(-2*h, h*h)
for i,h in enumerate(H[1:],1):
    x = cht.query(h) + h*h + C
    dp[i] = x
    cht.add(-2*h, h*h + x)

answer = dp[-1]
print(answer)

Measured memory_bytes: 41540
function Main(input) {
    input = input.split("\n");
    
    var n = input[0].trim();
    for(var i=n; true; i++){
        if(isSosu(i)){
            break;
        }
    }
    
    if(i<2){
        i = 2;
    }
    console.log(i);
}

function isSosu(num) {
    if(num == 2){
        return true;
    }
    
    for(i=2; i<num; i++){
        if(num % i == 0){
            return false;
            break;
        }
    }
    
    return true;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
	int n;
	cin >> n;
	int a[n-1];
	int ans[n] = {};
	for (int i = 0; i < n-1; i++) {
		cin >> a[i];
		ans[a[i]-1]++;
	}

	for (int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5216
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <bitset>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 200005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << min((int) (b / a), c);
}


Measured memory_bytes: 256
h = -1
w = -1

while True:
  input = map(int, raw_input().split(" "))
  h = input[0]
  w = input[1]
  if (h == 0 and w == 0):
    break

  odd_line = ""
  even_line = ""

  j = 0
  while j < w:
    if j % 2 == 0:
      odd_line += "."
      even_line += "#"
    else:
      odd_line += "#"
      even_line += "."
    j += 1

  i = 0
  while i < h:
    if i % 2 == 0:
      print even_line
    else:
      print odd_line
    i += 1

  print ""

Measured memory_bytes: 4232
#include <stdio.h>

int gcd(int a, int b)
{
	if (b == 0){
		return (a);
	}
	return gcd(b, a % b);
}
int main(void)
{
	int a, b;
	
	while (scanf("%d%d", &a, &b) != EOF){
		if (b > a){
			a ^= b;
			b ^= a;
			a ^= b;
		}
		printf("%d %d\n", gcd(a, b), a / gcd(a, b) * b);
	}
	
	return (0);
}

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

#define fi first
#define se second

typedef pair<int, int> pii;

const int MAXN = 85, MAXM = 1e5 + 5;

int main() {
	int k; cin >> k;
	long long sum = 0;

	for (int i = 1; i <= k; i++) for (int j = 1; j <= k; j++) for (int z = 1; z <= k; z++) {
		int g = __gcd(j, z);
		sum += __gcd(i, g);
	}
	cout << sum << endl;
}

Measured memory_bytes: 3624
N,X,Y=map(int,input().split())

def dist(a,b):
    return min(abs(b-a),abs(a-X)+1+abs(b-Y),abs(a-Y)+1+abs(b-X))

data=[0]*N
for i in range(1,N+1):
    for j in range(i+1,N+1):
        data[dist(i,j)]+=1
for d in data[1:]:
    print(d)


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

const int mod = 1000000007;

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

    vector<ll> s(n+1);
    s[0] = 0;
    for(int i=0;i<n;i++){
        s[i+1] = s[i]+a[i];
        s[i+1] %= mod;
    }

    ll ans = 0;
    for(int i=1;i<n;i++){
        ans += a[i]*s[i];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6432
#include<bits/stdc++.h>
using namespace std;
const int Max_N=1e5;
int N,A[Max_N+10]={},B[Max_N+10]={},C[Max_N+10]={},P[Max_N*3+10]={};
inline int lowbit(int x){
	return x & -x ;
}
inline void Add(int x,int k){
	for(;x<=Max_N*3;x+=lowbit(x)) P[x]+=k;
}
inline long long Ask(int x){
	long long Sum=0;
	for(;x>0;x-=lowbit(x)) Sum+=P[x];
	return Sum;
}
inline bool chck(int x){
	long long Cnt=1;
	for(int i=1;i<=N;i++)
	 if(A[i]<=x) B[i]=0;
	 else B[i]=1;
	for(int i=1;i<=N;i++) B[i]+=B[i-1];
	for(int i=1;i<=N;i++) Add(B[i]*2-i+N+1,1);
	for(int i=1;i<=N;i++){
		Cnt+=(N-i+1)-Ask(B[i-1]*2-(i-1)-1+N+1);
		Add(B[i]*2-i+N+1,-1);
	}
	return Cnt*2<N*1LL*(N+1)/2;
}
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++) scanf("%d",&A[i]),C[i]=A[i];
	sort(C+1,C+N+1);
	int l=1,r=N;
	for(;l+1<r;){
		int Mid=(l+r)>>1;
		if(chck(C[Mid])) r=Mid;
		else l=Mid;
	}
	if(chck(C[l])) printf("%d\n",C[l]);
	else printf("%d\n",C[r]);
	return 0; 
} 

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
    int w = s.nextInt();
    int h = s.nextInt();
    int x = s.nextInt();
    int y = s.nextInt();
    int r = s.nextInt();
    if (x + r > w)
      System.out.println("No");
    else if (x - r < 0)
      System.out.println("No");
    else if (y + r > h)
      System.out.println("No");
    else if (y - r < 0)
      System.out.println("No");
    else
      System.out.println("Yes");
	}
}



Measured memory_bytes: 26328
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int d = scanner.nextInt();
 
        if (Math.abs(a - c) <= d){
            System.out.print("Yes");
        } else if (Math.abs(a-b) <=d && Math.abs(b-c) <= d) {
            System.out.print("Yes");
        } else{
            System.out.print("No");
        }
    }
}

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

void solve_test() {
	LL n;
	cin >> n;

	int ops = 0;
	for (LL i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			int cnt = 0;
			while (n % i == 0) {
				cnt++;
				n /= i;
			}

			int j = 1;
			while (cnt >= j) {
				cnt -= j;
				j++;
				ops++;
			}
		}
	}
	if (n > 1)
		ops++;

	cout << ops << '\n';
}

int main() {
	int T;
	T = 1;
	for (int t = 1; t <= T; t++)
		solve_test();

	return 0;
}


Measured memory_bytes: 3620
import itertools
n=int(input())
a=list(map(int,input().split()))
b=[0]+[i for i in itertools.accumulate(a)]
dic={}
for i in b:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
ans=0
for i in dic.values():
    ans+=i*(i-1)//2
print(ans)

Measured memory_bytes: 41488
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Diagnostics;

static class Program
{
    static long Solve(int N, long[] A)
    {
        if (N == 0)
        {
            return (A[0] > 1) ? -1 : A[0];
        }
        var ranges = new Tuple<long, long>[N + 1];
        ranges[N] = Tuple.Create(A[N], A[N]);
        for (int i = N - 1; i >= 0; --i)
        {
            long min = (ranges[i + 1].Item1 + 1) / 2 + A[i];
            long max = ranges[i + 1].Item2 + A[i];
            ranges[i] = Tuple.Create(min, max);
        }
        if (ranges[0].Item1 > 1 || ranges[0].Item2 < 1) { return -1; }

        long n = 1;
        long sum = 1;
        for (int i = 1; i <= N; ++i)
        {
            n = Math.Min((n - A[i - 1]) * 2, ranges[i].Item2);
            sum += n;
        }
        return sum;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var A = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        Console.WriteLine(Solve(N, A));
    }
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  vi a;
  REP(i, n) { a.PB(read()); }
  sort(ALL(a), greater<int>());
  int ans = 0;
  REP(i, n) {
    if (i & 1)
      ans -= a[i];
    else
      ans += a[i];
  }
  print(ans);
}


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

bool has3(int x) {
	while (x) {
		if (x % 10 == 3)return true;
		x /= 10;
	}
	return false;
}

void call(int n) {
	for (int x = 1; x <= n; x++) {
		if (x % 3 == 0 || has3(x)) {
			cout << " " << x;
		}
	}
	cout << endl;
}

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

	return 0;
}

Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        COrdinaryBeauty solver = new COrdinaryBeauty();
        solver.solve(1, in, out);
        out.close();
    }

    static class COrdinaryBeauty {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong(), m = in.nextLong(), d = in.nextLong();
            if (d == 0) {
                out.printf("%.10f", (m - 1) / (double) n);
            } else {
                out.printf("%.10f", 2 * (n - d) * (m - 1) / (double) (n * n));
            }
        }

    }
}



Measured memory_bytes: 23764
s = input()
t = input()
s_len = len(s)
t_len = len(t)
ans = 1000
for i in range(s_len-t_len+1):
    cnt = 0
    for j in range(t_len):
        if s[i+j] != t[j]:
            cnt += 1
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 9112
import java.util.Scanner


import scala.io.StdIn._

object Main extends App {

  val k = readInt()

  def solve() = {
    var ans = 0L
    for {
      a <- 1 to k
      b <- 1 to k
      c <- 1 to k
    } {
      ans += gcd(a,b,c)
    }
    ans
  }

  def gcd(x: Int, y: Int, z: Int): Int = {
    calcGCD(x, calcGCD(y, z))
  }

  def calcGCD(x: Int, y: Int): Int = {
    if(y == 0) x
    else calcGCD(y, x % y)
  }

  println(solve())

}



Measured memory_bytes: 54796
#include <stdio.h>

int main(void){
    // Your code here!
    int N;
    int a[100000];
    long long sum = 0;
    long long cnt[2] = {};
    
    scanf("%d",&N);
    
    for(int i = 0; i < N; i++){
        scanf("%d",&a[i]);
    }
    
    for(int j = 0; j < 2; j++){
        int flag = j; //even or odd integers
        sum = 0;
        for(int i = 0; i < N; i++){
            sum += a[i];
            if(i % 2 == j){
                if(sum <= 0){
                    cnt[j] += -sum + 1;
                    sum = 1;
                }
            }
            else{
                if(sum >= 0){
                    cnt[j] += sum + 1;
                    sum = -1;
                }
            }
        }
    }
    
    if(cnt[0] > cnt[1]){
        printf("%lld\n",cnt[1]);
    }
    else{
        printf("%lld\n",cnt[0]);
    }
}


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

int main() {
	int H1,M1,H2,M2,K,t1,t2,t;
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	t1 = H1*60+M1;
	t2 = H2*60+M2;

	if(t2 >= t1)
		t = t2-t1;
	else
		t = (1440-t1)+t2;

	cout << t-K << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#define SM 30
using namespace std;
long long n,a[SM][SM],F[SM][3000000];
long long Try(long long i,long long Free)
    {
        long long j;
        if (i>n) return 1;
        if (F[i][Free]!=-1) return(F[i][Free]);
        F[i][Free]=0;
        for (j=1;j<=n;++j)
            if ((Free>>(j-1)&1)==0 && a[i][j]==1)
                F[i][Free]=(F[i][Free]+Try(i+1,Free|(1<<(j-1))))%((long long)1e9+7);
        return F[i][Free];
    }
int main()
    {
        //freopen("MATCHING.INP","r",stdin);
        //freopen("MATCHING.OUT","w",stdout);
        long long i,j;
        cin>>n;
        for (i=1;i<=n;++i)
            for (j=1;j<=n;++j) cin>>a[i][j];
        for (i=1;i<=n+1;++i)
            for (j=0;j<=3000000;++j) F[i][j]=-1;
        cout<<Try(1,0);
        return 0;
    }


Measured memory_bytes: 518792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  set<int> s;
  REP(i,3){
    int x;
    cin >> x;
    s.insert(x);
  }
  cout << s.size() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define DEBUG(x) cerr << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main()
{
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int p = N / 2;
    vl A(N);
    ll total = 0LL;

    REP(i, N) {
        cin >> A[i];
        total += A[i];
    }

    ll core_even = 0LL;
    for (int i = 0; i <= 2 * p; i += 2) core_even += A[i];
    ll core_odd = 0LL;
    for (int i = 1; i <= 2 * p + 1; i += 2) core_odd += A[i % N];
    
    vl ans(N);
    REP(i, N) {
        int new_idx = (2 * p + i) % N;
        if (i >= 2 and i % 2 == 0) core_even += A[new_idx] - A[i - 2];
        if (i >= 3 and i % 2 == 1) core_odd += A[new_idx] - A[i - 2];
        
        if (i % 2 == 0) ans[i] = 2 * core_even - total;
        if (i % 2 == 1) ans[i] = 2 * core_odd - total;
    }
    
    REP(i, N) cout << ans[i] << " ";
    cout << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
#define mp(a, b) make_pair(a, b)

int m, n;
bool prime[1000010];

void init(){
    fill(prime, prime+1000010, true);
    prime[0] = prime[1] = false;
    rep(i, 1000010)if(prime[i]){
        for(int j=i*2; j<1000010; j+=i)prime[j] = false;
    }
}

void makeCave(vector<vector<int> > &cave, int &sx, int &sy){
    int k = 1;
    for(; k*k<m; k+=2);
    cave.assign(k, vector<int>(k, 0));
    const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
    int x = k / 2, y = k/ 2, dir = 0, mask = 1;
    for(int i=1; i<=m; ++i){
        cave[x][y] = i;
        if(i == n)sx = x, sy = y;
        if(i == (2 * mask + 1) * (2 * mask + 1))mask++;
        int nx = x + dx[dir], ny = y + dy[dir];
        if(mask < max(abs(nx - k/2), abs(ny - k/2)))(dir += 1) %= 4;
        x += dx[dir]; y += dy[dir];
    }
}

pair<int, int> proc(pair<int, int> p, int x){
    return mp(p.first + prime[x], prime[x]? x: p.second);
}

pair<int, int> solve(){
    vector<vector<int> > cave;
    int sx, sy;
    makeCave(cave, sx, sy);
    vector<vector<pair<int, int> > > dp(cave.size(), vector<pair<int, int> >(cave.size(), mp(0, 0)));
    if(prime[cave[sx][sy]])dp[sx][sy] = mp(1, cave[sx][sy]);
    int l = sy, r = sy + 1;
    for(int x=sx+1; x<(int)cave.size(); ++x){
        l = max(0, l-1); r = min(r+1, (int)cave.size());
        for(int y=l; y<r; ++y){
            for(int dy=-1; dy<=1; ++dy){
                if(y + dy < 0 || (int)cave.size() <= y + dy)continue;
                dp[x][y] = max(dp[x][y], proc(dp[x-1][y+dy], cave[x][y]));
            }
        }
    }
    return *max_element(all(dp.back()));
}

int main(){
    init();
    while(cin >> m >> n, m|n){
        pair<int, int> ans(solve());
        cout << ans.first << ' ' << ans.second << '\n';
    }
    return 0;
}

Measured memory_bytes: 13940
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = None
    for x in xn:
        div = abs(X - x)
        if ans is None:
            ans = div
        elif div % ans:
            ans = gcd(ans, div)
    print(ans)
    return


main()


Measured memory_bytes: 14052
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int c[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++)scanf("%d", &c[i][j]);
    }
    int a[3][3];
    int b[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = i+1; j+i < 3; j++){
            int a1 = c[i][0] - c[i+j][0];
            int a2 = c[i][1] - c[i+j][1];
            int a3 = c[i][2] - c[i+j][2];
            //cout << a1 << " " << a2 << " " <<a3 <<endl;
            if(a1 != a2 || a1 != a3 || a2 != a3){
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
    
}

Measured memory_bytes: 256
S = list(map(int,list(input())))
K = int(input())

def func():
    if len(S) < K:
        for s in S:
            if s != 1:
                return s
    else:
        for i,s in enumerate(S):
            if s != 1:
                return s
            if i == K-1:
                return s

print(func())

Measured memory_bytes: 38384
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,T = (int(_) for _ in input().split())
    t = list(int(_) for _ in input().split())
    sum = T
    for i in range(1,N):
        if(t[i]-t[i-1] > T):
            sum += T
        else:
            sum += t[i]-t[i-1]
    print(sum)
if __name__ == '__main__':
    main()


Measured memory_bytes: 25692
#include <stdio.h>

int main()
{
  int n,i,j,num[100],tmp,cnt=0;
  int flag=1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
  }
  while(flag){
    flag=0;
  for(j=n-1;j>=1;j--)
    {
      if(num[j]<num[j-1])
	{
	  tmp=num[j];
	  num[j]=num[j-1];
	  num[j-1]=tmp;
	  cnt++;
	  flag=1;
	}
    }
  }
  for(i=0;i<n;i++){
    if(i==0) printf("%d",num[i]);
    else printf(" %d",num[i]);
  }
  printf("\n");
  printf("%d\n",cnt);
 

  return 0;
}



Measured memory_bytes: 2072
#define _USE_MATH_DEFINES
#include <stdio.h>
#include<math.h>
int main(void)
{
	double r;
	double c,d;

	scanf("%lf", &r);

	c = r * r * M_PI;
	d = 2 * M_PI*r;

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

	return 0;
}

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

int main() {
  string A, B;
  cin >> A >> B;
  if(A.size() == B.size()) {
    for(int i = 0; i < A.size(); ++i) {
      auto a = A[i] - '0';
      auto b = B[i] - '0';
      if(a > b) {
        cout << "GREATER" << endl;
        return 0;
      } else if(a < b) {
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
    return 0;
  } else if(A.size() > B.size()) {
    cout << "GREATER" << endl;
    return 0;
  } else {
    cout << "LESS" << endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		double[] point = new double[8];
		while(scan.hasNext()){
			for(int i = 0;i < 8;i++){
				point[i] = scan.nextDouble();
			}
			if(s(point[0],point[1],point[2],point[3],point[6],point[7])+
					s(point[2],point[3],point[4],point[5],point[6],point[7])+
					s(point[0],point[1],point[4],point[5],point[6],point[7])-
					s(point[0],point[1],point[2],point[3],point[4],point[5]) < 0.0001){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
	public static double len(double x1,double y1,double x2,double y2){
		return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	}
	public static double s(double x1,double y1,double x2,double y2,double x3,double y3){
		double a = len(x1,y1,x2,y2);
		double b = len(x2,y2,x3,y3);
		double c = len(x3,y3,x1,y1);
		double s = (a + b + c)/2.0;
		return Math.sqrt(s*(s-a)*(s-b)*(s-c));
	}
}

Measured memory_bytes: 23096
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,maxWeight;
    cin >> n >> maxWeight;
    vector <int> w(n);
    vector <long> v(n);
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }
    vector <vector<long>> dpvv(n);
    //return 0;
    for(int i = 0; i < n; i++){
        //cout <<"i:" << i << endl;
        if(i==0){
            dpvv[i]=vector<long>(maxWeight+1,0);
            //cout << dpvv[i].size() << endl;
            for(int j = w[i]; j <= maxWeight; j++){
                dpvv[i][j]=v[i];
            }
            //cout << "alpah" << endl;
            if(n!=1){
                dpvv[i+1]=vector<long>(maxWeight+1,0);
                dpvv[i+1]=dpvv[i];
                //cout << dpvv[i+1].size() << endl;
            }
            //cout << "beta" << endl;
            //return 0;
        }else{
            //cout << w[i] << endl;
            for(int j = w[i]; j <= maxWeight; j++){
                // cout << j << endl;
                // cout << dpvv[i].size();
                // cout << dpvv[i][j] << endl;
                if(j==w[i]){
                    dpvv[i][j]=max(v[i],dpvv[i-1][j]);
                }else{
                    dpvv[i][j]=max(v[i]+dpvv[i-1][j-w[i]],dpvv[i-1][j]);
                }
            }
            if(i!=(n-1)){
                dpvv[i+1]=vector<long>(maxWeight+1,0);
                dpvv[i+1]=dpvv[i];
                //cout << dpvv[i+1].size() << endl;
            }
            //return 0;
        }
    }
    //cout << "test" << endl;
    long ans = 0;
    for(int i = 0; i < n; i++){
        //cout << i << endl;
        long tmp = dpvv[i].back();
        if(ans == 0){
            ans = tmp;
        }else{
            ans = max(ans,tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81452
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	int ans = 0;
	vi d1 = {n}, d2 = {n - 1};
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) {
			d1.pb(i);
			if(i * i != n) {
				d1.pb(n / i);
			}
		}
	}
	for(int i = 2; i * i <= (n - 1); i++) {
		if((n - 1) % i == 0) {
			d2.pb(i);
			if(i * i != (n - 1)) {
				d2.pb((n - 1) / i);
			}
		}
	}
	set<int> s;
	for(auto it : d2) {
		if(it >= 2 && it <= n) {
			s.insert(it);
		}
	}
	for(auto it : d1) {
		if(it >= 2 && it <= n) {
			int tmp = n;
			while(tmp % it == 0) {
				tmp /= it;
			}
			if(tmp % it == 1) {
				s.insert(it);
			}
		}
	}
	cout << s.size();

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
typedef long long LL;
int val[maxn],First[maxn],cnt,N,M;
int tot,pre[maxn];
LL ans = 0;
struct node{
    int to,Next;
}Tree[maxn*2];
void init(){
    memset(First,-1,sizeof(First));
    cnt = 0;
}
void addedge(int from,int to){
    Tree[cnt].to = to;
    Tree[cnt].Next = First[from];
    First[from] = cnt++;
}
priority_queue<int,vector<int>,greater<int> > Q[maxn];
void dfs(int u,int fa){
    pre[u] = 1;
    Q[tot].push(val[u]);
    for(int i = First[u];i!=-1;i=Tree[i].Next){
        int to = Tree[i].to;
        if(to==fa)continue;
        dfs(to,u);
    }
}
vector<int> ac,bc;
int main(){
    init();
    scanf("%d%d",&N,&M);
    for(int i = 0;i<=N-1;i++)scanf("%d",&val[i]);
    for(int i = 0;i<M;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        addedge(a,b);
        addedge(b,a);
    }
    for(int i = 0;i<=N-1;i++){
        if(!pre[i]){
            tot++;
            dfs(i,-1);
            ac.push_back(tot);
        }
    }
    if(tot==1){
        printf("%d\n",0);
        return 0;
    }
    bool flag = 0;
    priority_queue<int,vector<int>,greater<int> >QQ;
    for(int i = 1;i<=tot;i++){
       ans+=Q[i].top();
       Q[i].pop();
       while(!Q[i].empty()){
        QQ.push(Q[i].top());
        Q[i].pop();
       }
    }
    int my =tot-2;
    if(QQ.size()<my){
        printf("Impossible\n");
        return 0;
    }
    for(int i = 0;i<my;i++){
        ans+=QQ.top();
        QQ.pop();
    }
    printf("%lld\n",ans);
    return 0;
}
/*
7 4
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
0 1
1 2
3 4
5 6
6 3
1 1 1 3 7 8
0 4
1 5
2 3
*/


Measured memory_bytes: 9080
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
	int n;
	int score[1000];
	while(true)
	{
		double average = 0;
		cin >> n;
		if(n == 0)
			break;
		for (int i = 0; i < n; i++)
		{
			cin >> score[i];
			average += score[i];
		}
		average /= n;
		double a2 = 0;
		for(int i = 0;i < n;i++)
		{
			a2 += (average - score[i]) * (average - score[i]);
		}
		a2 /= n;
		cout << fixed << setprecision(8) << sqrt(a2) << endl;
	}
	return 0;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vector<string> w(n);
    rep(i, n) cin >> w[i];

    set<string> ws;
    rep(i, n) ws.insert(w[i]);

    bool f = (ws.size() == n);

    rep(i, n-1) {
        if (w[i][w[i].size()-1] != w[i+1][0]) f = false;
    }

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

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>>C(H, vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> C.at(i).at(j);
    }
  }
  
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
        cout << C.at(i).at(j);
      }
      cout << endl;
      
            for(int j=0; j<W; j++){
        cout << C.at(i).at(j);
      }
      cout << endl;
    }
  
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <math.h>
int main(void){
	int A,B,C,X;
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&X);
	int ans = 0,c;
	int i,j,k;
	for(i=0;i<=A;i++){
		for(j=0;j<=B;j++){
			for(k=0;k<=C;k++){
				c = 500*i + 100*j + 50*k;
				if(c==X) ans++;
			}
		}
	}
	
	printf("%d",ans);
	return 0;}

Measured memory_bytes: 128
fun main() = Thread(null, ::abc169b, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc169b() {
    readLine()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    if (0L in aList) return println(0)

    val cap = pow(10L, 18)

    val answer = runCatching {
        aList.fold(1L) { acc, l -> Math.multiplyExact(acc, l) }
    }.fold({ it }, { Long.MAX_VALUE }).takeIf { it <= cap } ?: -1

    println(answer)
}

private fun pow(n: Long, p: Long): Long {
    var x = n
    var y = p
    var result = 1L
    while (y > 0) {
        if (y % 2 == 1L)
            result = (result * x)
        y = y shr 1
        x = (x * x)
    }
    return result
}


Measured memory_bytes: 63196
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
template<class T>
void input(vector<T>& vec,int n){
	vec.resize(n);
	for(int i=0;i<n;i++){
		cin >> vec[i];
	}
}
// verifyed EDPC Z
// https://atcoder.jp/contests/dp/tasks/dp_z
// Comptype true : min, false : max
template<class T,bool Comptype = true>
struct LiChaoTree{
	using Line = pair<T,T>;	
	int sz = 1;
	vector<Line> seg;
	vector<T> xs;
	LiChaoTree(){}
	void init(vector<T>& x,T id){
		xs = x;
		int n = x.size();
		while(sz<n)sz<<=1;
		xs.resize(sz,x.back());
		seg.resize(sz*2,Line(T(0),id));
	}
	void dump_tree(){
		for(int i=0;i<seg.size();i++){
			cout << i << ':' << seg[i].fi << ' ' << seg[i].sec << endl;
		}
		// dump(xs);
	}
	static inline T f(Line l,ll x){
		return l.fi*x+l.sec;
	}	
	void add(Line line,int k,int l ,int r){
		int mid = (l+r)/2;
		T lx = xs[l];
		T mx = xs[mid];
		T rx = xs[r-1];
		bool lb = (f(line,lx)<f(seg[k],lx));
		bool mb = (f(line,mx)<f(seg[k],mx));
		bool rb = (f(line,rx)<f(seg[k],rx));
		if((lb==Comptype)&&(rb==Comptype)){
			seg[k] = line;
			return;
		}else if((lb!=Comptype)&&(rb!=Comptype)){
			return;
		}else{
			if(mb==Comptype)swap(seg[k],line);
			if(lb!=mb){
				add(line,2*k+1,l,mid);
			}else{
				add(line,2*k+2,mid,r);
			}
		}
	}
	void add(Line line){
		add(line,0,0,sz);
	}
	T query(int k){
		T x = xs[k];
		k += sz-1;
		T ret = f(seg[k],x);
		while(k>0){
			k = (k-1)/2;
			T tmp = f(seg[k],x);
			if((tmp<ret)==Comptype)ret = tmp;
		}
		return ret;
	}
};
int main(){
	int N;
	ll C;
	vector<ll> h;
	LiChaoTree<ll> seg;
	vector<ll> dp;
	cin >> N >> C;
	input(h,N);
	dp.resize(N,0ll);
	seg.init(h,LLINF);
	seg.add(make_pair(-2*h[0],dp[0]+h[0]*h[0]));
	for(int i=1;i<N;i++){
		// seg.dump_tree();
		dp[i] = h[i]*h[i]+C+seg.query(i);
		// cout << i << ' ' << dp[i] << endl;
		seg.add(make_pair(-2ll*h[i],h[i]*h[i]+dp[i]));
	}
	cout << dp[N-1] << endl;
	return 0;
}


Measured memory_bytes: 14576
N = int(input())
march = 'MARCH'
l = [0] * len(march)
for i in range(N):
    S = input()
    for j in range(len(march)):
        if S[0] == march[j]:
            l[j] += 1

# print(l)
tmp = []
lenl = len(l)
for i in range(lenl):
    for j in range(i + 1, lenl):
        for k in range(j + 1, lenl):
           tmp.append(l[i]*l[j]*l[k])
# print('tmp',tmp)
print(sum(tmp))


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}


int main()
{
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x = x2 - x1;
    int y = y2 - y1;
    int xx = -y,yy = x;
    int x3 = xx + x2,y3 = yy + y2;
    x = x3 - x2;y = y3 - y2;
    xx = -y;yy = x;
    int x4 = xx + x3,y4 = yy + y3;
    printf("%d %d %d %d\n",x3,y3,x4,y4);
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#define rep(X,Y) for(int (X)=0;(X)<(Y);++(X))
#define pb push_back
#define X first
#define Y second

using namespace std;

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

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

template<typename T> ostream& operator<<(ostream& os, vector<T> &v){
  cout<<"{";
  rep(i,v.size())os<<v[i]<<","<<endl;cout<<"}"<<endl;
  return os;
}
template<typename T,typename S> ostream& operator<<(ostream& os, pair<T,S> &v){
  os<<"("<<v.X<<","<<v.Y<<")";
  return os;
}

int main(){
  int w,h;
  while(cin>>w>>h){
    if(!w)break;
  vector<string> ml(h+2),mr(h+2);
  ml[0]=mr[0]=ml[h+1]=mr[h+1]=string(w+2,'#');
  string tmp;
  pii sl,dl,sr,dr;
  rep(i,h){
    cin>>tmp;
    ml[i+1]=("#"+tmp+"#");
    cin>>tmp;
    mr[i+1]=("#"+tmp+"#");
  }
  rep(i,h+2)rep(j,w+2){
    if(ml[i][j]=='L') sl=pii(j,i);
    if(mr[i][j]=='R') sr=pii(j,i);
    if(ml[i][j]=='%') dl=pii(j,i);
    if(mr[i][j]=='%') dr=pii(j,i);
  }
  //cout<<ml<<mr<<sl<<sr<<dl<<dr<<endl;
  int INF=1e9;
  queue<pi4> que;
  fill(dist[0][0][0],dist[0][0][0]+55*55*55*55,INF);
  rep(i,h+2)rep(j,w+2)
    dist[dl.Y][dl.X][i][j]=dist[i][j][dr.Y][dr.X]=-1;
  dist[dl.Y][dl.X][dr.Y][dr.X]=INF;
  dist[sl.Y][sl.X][sr.Y][sr.X]=0;
  que.emplace(sl,sr);
  while(!que.empty()){
    pii cl=que.front().X, cr=que.front().Y;
    que.pop();
    //cout<<cl<<cr<<dist[cl.Y][cl.X][cr.Y][cr.X]<<endl;
    if(cl==dl && cr==dr)break;
    int nd=dist[cl.Y][cl.X][cr.Y][cr.X]+1;
    rep(i,4){
      pii nl=cl,nr=cr;
      nl.X+=dx[i]; nl.Y+=dy[i];
      nr.X-=dx[i]; nr.Y+=dy[i];
      //cout<<i<<":"<<nl<<nr;
      if(ml[nl.Y][nl.X]=='#') nl=cl;
      if(mr[nr.Y][nr.X]=='#') nr=cr;
      //cout<<i<<":"<<nl<<nr<<dist[nl.Y][nl.X][nr.Y][nr.X]<<endl;
      if(dist[nl.Y][nl.X][nr.Y][nr.X]>nd){
	dist[nl.Y][nl.X][nr.Y][nr.X]=nd;
	que.emplace(nl,nr);
      }
    }
  }
  cout<<(dist[dl.Y][dl.X][dr.Y][dr.X]==INF?"No":"Yes")<<endl;
  }
}

Measured memory_bytes: 37900
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

set<string> ss;
string s;
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k;
	cin >> s >> k;
	int n = min((int)s.size(), 5);
	for(int i = 0; i < (int)s.size(); i++){
		string t;
		for(int j = i; j < min(i+n, (int)s.size()); j++){
			t.push_back(s[j]);
			ss.insert(t);
			// cout << t << endl;
		}
	}
	int cnt = 0;
	for(auto i : ss){
		cnt++;
		if(cnt == k){
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1664
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    t = f()

    m = f()[0]
    drinks = [f() for i in range(m)]

    tt = sum(t)
    for some in drinks:
        print(tt - (t[some[0]-1] - some[1]))

solve()


Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))

a.sort()
tmp = a[0]
f = True
for i in range(1, n):
    tmp *= a[i]

    if tmp > 10 ** 18:
        f = False
        break

if f:
    print(tmp)
else:
    print(-1)


Measured memory_bytes: 84512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#define MAXN 200005
#define MAXM 400005
using namespace std;
struct edge{int u,v;}e[MAXM];
int head[MAXN],nxt[MAXM],cnt;
void addnode(int u,int v)
{
	e[++cnt]=(edge){u,v};
	nxt[cnt]=head[u];
	head[u]=cnt;
}
int col[MAXN],tot[2],p[MAXN],n; 
void dfs(int u)
{
	++tot[col[u]];
	for (int i=head[u];i;i=nxt[i])
		if (col[e[i].v]==-1)
			col[e[i].v]=col[u]^1,dfs(e[i].v);
}
inline void putp(int r,int c)//freedomly put r+3k into color c
{
	int cur=r;
	for (int i=1;i<=n;i++)
		if (col[i]==c&&!p[i])
		{
			p[i]=cur,cur+=3;
			if (cur>n) return;
		}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		addnode(u,v),addnode(v,u);
	}
	memset(col,-1,sizeof(col));
	for (int i=1;i<=n;i++) if (col[i]==-1) col[i]=0,dfs(i);
	int k=(n+1)/3;
	if (k<=min(tot[0],tot[1])) putp(2,tot[1]<=tot[0]);
	else putp(2,tot[1]>tot[0]);
	putp(1,tot[1]>tot[0]);
	int cur=3;
	for (int i=1;i<=n;i++)
		if (!p[i])
			p[i]=cur,cur+=3;
	for (int i=1;i<=n;i++) printf("%d%c",p[i]," \n"[i==n]);
	return 0;
}

Measured memory_bytes: 12032