akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int gcd(int a, int b) {
	if (b == 0) { return a; }
	return gcd(b, a%b);
}
int main() {
	long long a, b, c,d,e,A,B,C;
	c = 9;
	d = 9;
	e = 9;
	C = 9;
	while (cin >> a >> b) {
		if (a < b) { swap(a, b); }
		A=gcd(a, b);
		C = a*b / A;
		cout << A << ' ' << C << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
#define PI 3.14159265358979

int main(void)
{
int N;
int c[50];
   cin>>N;
for(int i=0;i<N;i++)
{
    cin>>c[i];
}
int sum;

for(int i=0;i<N;i++)
{
    for(int j=0;j<i;j++)
    {
        if(i==j) continue;

        sum+=c[i]*c[j];
    }
}
cout<<sum<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 文字列の入力
import math

n,k = map(int ,input().split())

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
    
ans = comb(k, n,1000000007)
print(int(ans))


Measured memory_bytes: 5672
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second 
#define ull unsigned long long  
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif

// int dist(vector<int> a , vector<int> b ){
// 	int k = (int)a.size();
// 	int ans = 0 ;
// 	rep(i,k) ans += (a[i]-b[i])*(a[i]-b[i]) ;
// 	int tmp = sqrt(ans) ;
// 	return (tmp*tmp == ans);
// }
void solve()
{
	int L,R ;
	cin >> L >> R ;
	if( R-L > 2019 ) cout << 0 ;
	else{
		int ans = inf ;
		for(int i = L ; i < R ; ++i){
			for(int j = i + 1; j <= R ; ++j)
				ans = min(ans,(i*j)%(2019)) ;
		}
		cout << ans ;
	}
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int G[101][101];
int rG[101][101];
int par[101];
int s, t,V;
bool bfs(){
	queue<int>q;
	q.push(s);
	int vis[101];
	memset(vis, 0 , sizeof(vis));
	vis[s]=1;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v = 0;v<V;v++){
			if(vis[v]==false&&rG[u][v]>0){
				vis[v]=1;
				par[v]=u;
				q.push(v);
			}
		}
	}
	//cout<<vis[t];
	return vis[t];

}
int maxflow(){
	for(int i=0;i<V;i++){
		for(int j =0;j<V;j++){
			rG[i][j]=G[i][j];
	//		cout<<rG[i][j];
		}
	}
	int mx_flow=0;
	memset(par , -1, sizeof(par));
	while(bfs()){
	//	memset(par , -1, sizeof(par));
		int flow = INT_MAX;
		int x =t,y;
		for(x=t;x!=s;x=par[x]){
			y=par[x];
			flow = min(flow , rG[y][x]);
		}
		for(x=t;x!=s;x=par[x]){
			y= par[x];
			rG[y][x]-=flow;
			rG[x][y]+=flow;
		}
		memset(par, -1, sizeof(par));
//		cout<<flow;
		mx_flow = mx_flow + flow;
	}
	return mx_flow;
}
int main(){
	int m;
	cin>>V>>m;
	for(int i=0;i<m;i++){
		int x,y,w;
		cin>>x>>y>>w;
		G[x][y]=w;
	}
	s= 0;
	t= V-1;
	cout<<maxflow()<<"\n";

}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
int main(){
  char s[200];
  cin >> s;
  int n=strlen(s);
  for(int i=0;i<n;i++){
    if(s[i]!=s[n-1-i]){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i=0;i<(n-1)/2;i++){
    if(s[i]!=s[(n-1)/2-1-i]){
      cout << "No" << endl;
      return 0;
    }
  }
  int y=0;
  for(int i=(n+3)/2-1;i<n;i++){
    if(s[i]!=s[n-1-y]){
      cout << "No" << endl;
      return 0;
    }
    y++;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#!usr/bin/env python3
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
    return [LI() for i in range(n)]
class BIT:
    def __init__(self, size):
        self.size = size + 1
        self.dat = [0]*self.size

    def add(self, i, x=1):
        while i < self.size:
            self.dat[i] += x
            i += i&-i

    # sum[l,r)
    # sum[0,l] (r = None)
    def sum(self, l, r=None):
        if r is None:
            res = 0
            while l > 0:
                res += self.dat[l]
                l -= l&-l
            return res

        else:
            rres = 0
            while r > 0:
                rres += self.dat[r]
                r -= r&-r

            l -= 1
            lres = 0
            while l > 0:
                lres += self.dat[l]
                l -= l&-l

            return rres - lres


def solve():
    n,Q = LI()
    c = LI()
    c = [0]+c
    q = LIR(Q)
    q = [[i,q[i]] for i in range(Q)]
    q.sort(key = lambda x:x[1][1])
    bit = BIT(n+1)
    i = 1
    p = [None]*(n+1)
    ans = [0]*Q
    s = 0
    for ind,(l, r) in q:
        l -= 1
        while i <= r:
            ci = c[i]
            j = p[ci]
            if j is not None:
                bit.add(j)
            else:
                s += 1
            p[ci] = i
            i += 1
        ans[ind] = s-l+bit.sum(l)
    for i in ans:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 262996
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N=110, MAX_W=10010;
int dp[MAX_N][MAX_W];

int main(){
	int n, W;
	cin>>n>>W;
	vi v(n+1, 0), w(n+1, 0);
	v[0]=0; w[0]=0;
	for(int i = 1; i <= n; i++){
		cin>>v[i]>>w[i];
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= W; j++){
			if(j<w[i]) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j], dp[i][j-w[i]]+v[i]);
		}
	}
	cout<<dp[n][W]<<endl;

}
 
 

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

using namespace std;

typedef long long ll;

double getTime() { 
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void write() {};

template <typename T, typename... Args>
void write(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  write(args...);
}

int main() {
  string s; read(s);
  write(s.substr(0, 4), s.substr(4));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int R;
 
int main(void){
	
	cin >> R;
	
    if(R < 1200) cout << "ABC" << endl;
    else if(R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef vo

int main() {
	for (int e, m; (e = m = in());) {
		for (int z = cbrt(e) + 0.0001; z >= 0; z--) {
			int te = e - z * z * z;
			int y = (int)sqrt(te);
			int tm = z + y + te - y * y;
			if (z + y > m)
				break;
			m = min(m, tm);
		}
		out(m, '\n');
	}
}


Measured memory_bytes: 2640
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define endl '\n'
#define N 100005
using namespace std;
ll w[N],v[N],n,have;
ll dp[N][105];
ll rec (int can,int i)
{
	if(i==n) return 0;
	if(dp[can][i]!=-1)
	return dp[can][i];
	ll ans = 0;
	if(can >= w[i])
	ans =  max(v[i]+rec(can-w[i],i+1),rec(can,i+1));
	else
	ans =  rec(can,i+1);
	dp[can][i] = ans;
	return dp[can][i];
}
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>have;
    for(int i=0;i<=have;i++){
    	for(int j=0;j<=n;j++)
    	dp[i][j] = -1;
    }
    
    for(int i=0;i<n;i++)
    cin>>w[i]>>v[i];
    cout<<rec(have,0)<<endl;
}


Measured memory_bytes: 85584
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        var sb = new StringBuilder();
        foreach(var c in s) {
            if (c == '0') sb.Append('0');
            if (c == '1') sb.Append('1');
            if (c == 'B' && sb.Length>0) sb.Remove(sb.Length-1,1);
        }

        return sb;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 13140
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	wcnt := make([]int, n)
	for i := 0; i < n; i++ {
		if i == 0 {
			wcnt[i] = 0
		} else {
			wcnt[i] += wcnt[i-1]
		}
		if s[i] == 'W' {
			wcnt[i]++
		}
	}
	min := math.MaxInt32
	for i := 0; i < n; i++ {
		cnt := 0
		if i > 0 {
			cnt += wcnt[i-1]
		}
		if i < n-1 {
			cnt += (n - i - 1) - (wcnt[n-1] - wcnt[i])
		}
		if cnt < min {
			min = cnt
		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 4864
# coding: utf-8

# input高速化のpythonのおまじない
import sys
input = sys.stdin.readline

# Nの取得とint変換
N = int(input())

# Wiを取得
# Wを初期化
W = [None]*N
# N回入力を取得
for i in range(N):
    # 入力を配列に追加（rstripは改行文字の削除）
    W[i] = input().rstrip()
    
# 同じ単語を発言していないかのチェック
#  setを使用した後にリスト変換すると、
#  リスト中の重複要素がなくなるので、
#  重複要素が存在するとサイズが変わる
if not len(W) == len(list(set(W))):
    print('No')
else:
    # 重複してないので、しりとりが成立してるかチェックしていく
    shiritoreteru = True
    for i in range(N-1):
        # pythonは文字列をリストのように扱える
        # インデックス-1は後ろから見て１つ目の要素＝最後の文字
        if not W[i][-1] == W[i+1][0]:
            # 最後の文字と頭の文字が違うのでダメ
            shiritoreteru = False
            # ループを終える
            break
    
    # 結果判定
    if shiritoreteru:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3060
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)

int main() {

	int n, l;
	cin >> n >> l;

	int mini = 200, ans = 0, sign = 0;
	vector<int> x(n);

	rep(i, 0, n) {
		x[i] = l + i;
		ans += x[i];
		if (x[i] >= 0) {
			if (mini > x[i]) {
				mini = x[i];
				sign = 1;
			}
		}
		else {
			if (mini > x[i] * (-1)) {
				mini = x[i] * (-1);
				sign = -1;
			}
		}
	}

	if (sign = 1) {
		if (ans >= 0) ans -= mini;
		else ans += mini;
	}
	else {
		if (ans <= mini) ans += mini;
		else ans -= mini;
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
	int N;
	cin >> N;
	int CMAX = 100 / 4;
	int DMAX = 100 / 7;
	for (int i = 0; i <= CMAX; i++) {
		for (int j = 0; j <= DMAX; j++) {
			if (i * 4 + j * 7 == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
# a = gets.to_i
# b = gets.to_i
s = gets.chomp
# s,t = gets.split.map(&:to_s)
# n= gets.split.map(&:to_i)

# s = gets.chomp.chars.uniq
# puts gets.chomp.chars.uniq.size != 1 ? "Yes" : "No"

ans = "Sunny"
if s == "Sunny"
    ans = "Cloudy"
elsif s == "Cloudy"
    ans = "Rainy"
end

puts(ans)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 3010;
const int MAXM = 1000010;
const int MAXK = 100010;
const int MAXQ = 200010;

int n;
ll a[MAXN];
ll dp[MAXN][MAXN][2];

ll solve(int l, int r, int p) {
    if (dp[l][r][p] != -1e18) return dp[l][r][p];
    if (l == r) {
        if (p == 0) return a[l];
        return -a[l];
    }
    if (p == 0) return dp[l][r][p] = max(a[l] + solve(l+1, r, 1-p), a[r] + solve(l, r-1, 1-p));
    else return dp[l][r][p] = min(-a[l] + solve(l+1, r, 1-p), -a[r] + solve(l, r-1, 1-p));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n)
        FOR(j,1,n)
            FOR(k,0,1) dp[i][j][k] = -1e18;
    cout << solve(1,n,0);
    return 0;
}


Measured memory_bytes: 141696
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int a;
    bool flag=true;
    cin>>a;
    vector<string>vec(a);
    rep(i,a){
        cin>>vec.at(i);
        //cout<<vec.at(i)<<endl;
    }
    rep(i,a){
        for(int j=i+1;j<a;j++){
            if(vec.at(i)==vec.at(j)){
                flag=false;
            }
        }
    }
    rep(i,a-1){
        string s,t;
        s=vec.at(i);
        t=vec.at(i+1);
        if(s.at(s.length()-1)!=t.at(0)){
            flag=false;
            break;
        }
    }
    if(flag==true){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	int n;
	cin>>n;
	string output = "";
	for(int i = 0;i < s.size(); i += n)
	{
		output += s[i];
	}
	cout<<output<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int dp[2100]; // dp[i] 和为 i 的方案数

int main() {
    int S;
    scanf("%d", &S);
    dp[0] = 1;
    for (int i = 3; i <= S; i++) { // sum
        for (int k = 3; k <= i; k++) { // next
            dp[i] = (dp[i] + dp[i - k]) % MOD;
        }
    }
    printf("%d\n", dp[S]);
    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
 
using namespace std;
 
int n, m;
int d[1000];
int c[1000];
 
int memo[1000][1000];
 
int rec(int day, int now)
{
    if (now == n) return 0;
 
    if (day == m) return 1 << 30;
 
    if (memo[day][now] >= 0) return memo[day][now];
 
    return memo[day][now] = min(rec(day + 1, now), rec(day + 1, now + 1) + d[now] * c[day]);
}
 
int main()
{
    cin >> n >> m;
 
    for (int i = 0; i < n; ++i) cin >> d[i];
 
    for (int i = 0; i < m; ++i) cin >> c[i];
 
    memset(memo, -1, sizeof(memo));
 
    printf("%d\n", rec(0, 0));
}

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

using namespace std;

const int N=1010;
int n;

int data[N];

void printP(int v)
{
    if(v<1) return;

    printf("parent key = %d, ",data[v]);
}

void printL(int v)
{
    if(v>n) return;

    printf("left key = %d, ",data[v]);
}

void printR(int v)
{
    if(v>n) return;

    printf("right key = %d, ",data[v]);
}

void print(int v)
{
    printf("node %d: key = %d, ",v,data[v]);
    printP(v/2);
    printL(v*2);
    printR(v*2+1);
    puts("");
}

int main()
{
    scanf("%d",&n);

    for(int i=1;i<=n;i++)
    {
        scanf("%d",&data[i]);
    }

    for(int i=1;i<=n;i++)
    {
        print(i);
    }


    return 0;
}



Measured memory_bytes: 3216
a, b, c = map(int, input().split())

a0, b0, c0 = a, b, c
a1, b1, c1 = 0, 0, 0

cnt = 0
while True:
    if a0%2==1 or b0%2==1 or c0%2==1:
        print(cnt)
        exit()

    a1 = b0//2 + c0//2
    b1 = a0//2 + c0//2
    c1 = a0//2 + c0//2

    a0 = a1
    b0 = b1
    c0 = c1

    cnt += 1

    if a1 == a and b1 == b and c1 == c:
        print(-1)
        exit()



Measured memory_bytes: 38256
#include <stdio.h>
#include <string.h>

//#define DEBUG

#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define MAX_KETA 100

char str1[MAX_KETA],str2[MAX_KETA]; //number string
char num1[MAX_KETA],num2[MAX_KETA],res[MAX_KETA]; //number row data
void add(void)
{
    int i;
    //get length of digits
    int len1=strlen(str1); 
    int len2=strlen(str2);
    int max_digit=MAX(len1,len2);
   
    //check overflow
    if(max_digit>80){
        printf("overflow\n");
        return;
    }
    
    //init with zero
    memset(num1,0,sizeof(char)*MAX_KETA);
    memset(num2,0,sizeof(char)*MAX_KETA);
    memset(res, 0,sizeof(char)*MAX_KETA);

    //convert string into number
    for(i=0;i<len1;i++){
       num1[i]=str1[len1-i-1]-'0';
    }
    for(i=0;i<len2;i++){
       num2[i]=str2[len2-i-1]-'0';
    }

    //add calc
    for(i=0;i<max_digit;i++){
        res[i]=num1[i]+num2[i]+res[i];
        //process carried-up digits
        if(res[i]>=10){
            res[i]-=10; res[i+1]=1;
        }
    }

    //see if max digit had carried-up or not
    max_digit=(res[i]>0)?max_digit+1:max_digit;

    //check result overflow
    if(max_digit>80){
        printf("overflow\n");
        return;
    }

    //print result
    for(i=max_digit-1;i>=0;i--){
        printf("%d",res[i]);
    }
    printf("\n");
}

int main(void)
{
    FILE *fp;
#ifdef DEBUG
    fp=fopen("input.txt","r");
#else
    fp=stdin;
#endif
   
    int i,n;
    fscanf(fp,"%d\n",&n);
    for(i=0;i<n;i++){
        fscanf(fp,"%s\n",str1);
        fscanf(fp,"%s\n",str2);
        add();        
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 21;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
struct Edge{
    ll from,to,cost;
};
class Bellman_Ford{
    private:
        vector<Edge> edges;
        vector<ll> d;
        ll V;
    public:
        Bellman_Ford(vector<Edge>& g,ll v):edges(g),V(v){
            d.resize(v,INF);
        }
        bool bellman_ford(ll s){
            d[s] = 0;
            rep(i,V){
                rep(j,edges.size()){
                    Edge e = edges[j];
                    if(d[e.from] != INF && d[e.to] > d[e.from]+e.cost){
                        d[e.to] = d[e.from]+e.cost;
                        if (i == V-1) return true;
                    }
                }
            }
            return false;
        }
        ll operator[](ll a){
            return d[a];
        }
};
vector<vector<ll>> g(2510);
vector<ll> done(2510,0);
void dfs(ll v){
    done[v] = 1;
    for (ll u:g[v]){
        if (done[u]) continue;
        dfs(u);
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,p,a,b,c;
    cin >> n >> m >> p;
    vector<vector<ll>> edge(m,vector<ll>(3));
    rep(i,m){
        cin >> a >> b >> c;
        c *= -1;
        c += p;
        --a;
        --b;
        g[b].push_back(a);
        edge[i] = {a,b,c};
    }
    dfs(n-1);
    vector<Edge> s;
    rep(i,m){
        if (done[edge[i][0]] && done[edge[i][1]]){
            s.push_back(Edge{edge[i][0],edge[i][1],edge[i][2]});
        }
    }
    Bellman_Ford ng(s,n);
    if (ng.bellman_ford(0)){
        PRINT(-1);
    }
    else{
        PRINT(max(-ng[n-1],0ll));
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
    ll N,M;
    cin >> N >> M;
    vector<PLL> AB;
    REP(i,N){
        ll a,b;
        cin >> a >> b;
        AB.PB(MP(a,b));
    }

    sort(ALL(AB));
    ll ans = 0;

    REP(i,N){
        ll A,B;
        A = AB[i].fst;
        B = AB[i].snd;

        if (M <= B){
            ans += A * M;
            PRINTLLD(ans);
            return 0;
        }

        ans += A*B;
        M = M - B;
    }
}






Measured memory_bytes: 2420
x = int(input())

for a in range(-120, 120):
  f_a = a**5
  r_b = (x-f_a)**(1/5).real
  b = round(r_b.real)
  if f_a - b**5 == x:
    print(a, b)
    break
  b *= -1
  if f_a - b**5 == x:
    print(a, b)
    break


Measured memory_bytes: 9428
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)



int main(){
ll r;
cin>>r;

cout<<r*r<<endl;


  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("apple");
            //apples
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("bus");
            //buses
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("box");
            //boxs
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];

        if (S.EndsWith("s") == false) {
            Console.WriteLine(S + "s");
        }
        else {
            Console.WriteLine(S + "es");
        }
    }
}


Measured memory_bytes: 26400
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	string s, t;
	cin >> s >> t;
	for (int i = n; i > 0; i--)
	{
		if (s.substr(n - i) == t.substr(0, i))
		{
			cout << n + t.substr(i).size() << endl;
			return 0;
		}
	}
	cout << 2 * n << endl;
	return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    lint n; cin >> n;
    lint d = 1, e = 26, f = 26;
    while(1){
        if(n <= f){
            n -= f-e+1;
            break;
        }
        d++; e *= 26; f += e;
    }
    vector<char> res(d);
    repr(i, d){
        res[i] = 'a' + (n % 26);
        n /= 26;
    }
    rep(i, d) cout << res[i];
    cout << endl;
}

Measured memory_bytes: 3624
/**
 *    author:  [itmo] enot.1.10
 *    created: 04.09.2016 15:20:34       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 1e5 + 10;

vi v[N];

int d[N];
int r[N];

void dfs(int x, int dd = 0)
{
    d[x] = dd;
    for (int y : v[x]) dfs(y, dd + 1);
}

int a[N];
pi e[N];

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int n, k;
    scanf("%d%d", &n, &k);    
    forn(i, n) scanf("%d", a + i);
    forn(i, n) a[i]--;
    int res = 0;
    if (a[0] != 0) a[0] = 0, res++;
    for (int i = 1; i < n; ++i) v[a[i]].pb(i);
    dfs(0);
    forn(i, n) e[i] = mp(-d[i], i);
    sort(e, e + n);
    forn(i, n)
    {
        int x = e[i].S;
        if (a[x] == 0) continue;
        if (r[x] == k - 1) res++;
        else r[a[x]] = max(r[a[x]], r[x] + 1);
    }
    printf("%d\n", res);

    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 10752
n , m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
pop = []
counter = 0
for i in range(m):
    pop.append(a[i])

all_vote = 0
for i in a:
    all_vote += i

for n in pop:
    if n*4*m < all_vote:
        print("No")
        break
    else:
        counter += 1

if counter == m:
    print("Yes")


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
using namespace std;
//イントとダブルが入り乱れるときはどちらかに統一しよう。

int max(int x,int y){
  if(x>y) return x;
  return y;
}

int min(int x,int y){
  if(x<y) return x;
  return y;
}

bool findpalindromic(int n){//nは五桁の整数
  int a[10];
  for(int i=0;i<5;i++){
    a[i]= n % 10;
    n /= 10;
  }
  if(a[0]==a[4]&&a[1]==a[3])return true;
  else return false;
}

int main(){
  int a,b,count=0;
  cin >> a >> b;
  for(int i=a;i<=b;i++){
    if(findpalindromic(i)){
      count++;
    //  cout << i << endl;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	X, Y = getlist()
	for i in range(101):
		for j in range(101):
			if i + j == X and (2 * i + 4 * j) == Y:
				print("Yes")
				return

	print("No")

if __name__ == '__main__':
	main()

Measured memory_bytes: 65676
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int mod=1e9+7;
int Add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
int Sub(int a,int b){return a-b<0?a-b+mod:a-b;}
int Mul(int a,int b){return 1LL*a*b%mod;}

const int maxn=100005;
int n;
int a[maxn],sum[maxn],fac[maxn],inv[maxn];

int quickpow(int x,int pow){
	int res=1;
	for(;pow;pow>>=1){
		if(pow&1)res=Mul(res,x);
		x=Mul(x,x);
	}
	return res;
}

int C(int a,int b){
	return Mul(fac[a],Mul(inv[b],inv[a-b]));
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	fac[0]=inv[0]=1;
	REP(i,n){
		fac[i]=Mul(fac[i-1],i);
		inv[i]=quickpow(fac[i],mod-2);
	}
	REP(i,n){
		scanf("%d",&a[i]);
		sum[i]=Add(sum[i-1],a[i]);
	}
	int ans=Mul(fac[n],sum[n]);
	for(int i=2;i<=n;i++){
		int coef=Mul(C(n,i),Mul(fac[n-i],fac[i-1]));
		ans=Add(ans,Mul(coef,sum[n-i+1]));
		ans=Add(ans,Mul(coef,Sub(sum[n],sum[i-1])));
	} 
	printf("%d\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double calc_len(double a, double b, double ceta) {
    double tmp = a*a+b*b-2*a*b*cos(ceta);
    return sqrt(tmp);
}

double deg2rad(double ceta) {
    return ceta*M_PI/180;
}

double hm2deg(double H, double M) {
    double tmp = abs(360*(H*60+M)/(60*12) - 360*M/60);
    if(tmp>180) {
        tmp = 360-tmp;
    }
    return tmp;
}

int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    
    cout << setprecision(20) << calc_len(A, B, deg2rad(hm2deg(H, M))) << endl;

    return 0;
    
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  vector<vector<int>> v;
  rep(i,N){
    int x, y, h;
    cin >> x >> y >> h;
    v.push_back({x,y,h});
  }

  int retX = 0;
  int retY = 0;
  int retH = 0;
  
  rep(cy,101){
    rep(cx,101){
      bool flg = true;
      int H = -1;
      rep(i,v.size()){
        int z = abs(v[i][0]-cx) + abs(v[i][1]-cy);
        if(v[i][2] != 0){
          if(H < 0){
            H = max(0, v[i][2] + z);
          }else{
            if(H != max(0, v[i][2] + z)) flg = false;
          }
        }
      }
      //cout << flg << " " << cy << " " << cx << " " << H << endl;
      rep(i,v.size()){
        int z = max(H - abs(v[i][0]-cx) - abs(v[i][1]-cy), 0);
        //cout << " " << i << " " << v[i][2] << " " << z << endl;
        if(v[i][2] != z) flg = false;
      }
      if(flg){
        retX = cx;
        retY = cy;
        retH = H;
      }
    }
  }

  cout << retX << " " << retY << " " << retH << endl;

  
  return 0;
}


Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;

void solve();

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

void solve() {
    string s;
    cin >> s;
    if(s[0] != 'A') s.insert(0,"A");
    if(s.length() >= 5 && s[4] != 'A') s.insert(4,"A");
    if(s.length() >= 7 && s[6] != 'A') s.insert(6,"A");
    if(s.length() >= 8 && s[8] != 'A') s.insert(8,"A");

    if(s == "AKIHABARA") {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int N;
vpint lis[22];

signed main(){
	cin>>N;
	rep(i,N){
		int n;cin>>n;
		rep(j,n){
			int x,y;
			cin>>x>>y;
			x--;
			lis[i].eb(x,y);
		}
	}
	int ans=0;
	rep(i,1<<N){
		bool ok=true;
		rep(j,N){
			if(!(i>>j&1))continue;
			for(auto &p:lis[j]){
				if((i>>(p.fi)&1)!=p.se)ok=false;
			}
		}
		if(ok)chmax(ans,__builtin_popcount(i));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

dp = [float("inf") for _ in range(100010)]
dp[0] = 0

for i in range(1, N+1):
    power = 1
    while power <= i:
        dp[i] = min(dp[i], dp[i-power]+1)
        power *= 6
    
    power = 1
    while power <= i:
        dp[i] = min(dp[i], dp[i-power]+1)
        power *= 9
print(dp[N])

Measured memory_bytes: 6296
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>

using namespace std;

const int N = 1e5 + 10;

int n, t, a[N];
map<int, int> b, c;

int main() {

	scanf("%d %d", &n, &t);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	int mn = a[1], gap = 1;
	for (int i = 2; i <= n; ++i) {
		gap = max(gap, a[i] - mn);
		mn = min(mn, a[i]);
	}
	mn = a[1];
	int cnt = 1, ans = 0;
	for (int i = 2; i <= n; ++i) {
		if (a[i] - mn == gap) {
			int &B = b[a[i]], &C = c[a[i]];
			ans -= min(B, C);
			B = mn;
			++C;
			ans += min(B, C);
		}
		if (a[i] == mn)
			++cnt;
		if (a[i] < mn) {
			mn = a[i];
			cnt = 1;
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,rec;
vector<pair<int,P>>vec;
P ans[200000];
int main(){
	cin>>n>>m;
	rep(i,m){
		int p,y;
		cin>>p>>y;
		vec.push_back(make_pair(p,make_pair(y,i)));
	}
	sort(vec.begin(),vec.end());
	rep(i,m){
		int p=vec[i].first,num=vec[i].second.second;
		if(i==0||p!=vec[i-1].first)rec=i;
		ans[num]=make_pair(p,i-rec+1);
	}
	rep(i,m){
		int a=ans[i].first,b=ans[i].second;
		int da=0,db=0;
		while(a){
			a/=10;
			da++;
		}
		rep(i,6-da)cout<<"0";
		cout<<ans[i].first;
		while(b){
			b/=10;
			db++;
		}
		rep(i,6-db)cout<<"0";
		cout<<ans[i].second<<endl;
	}
	return 0;
}
		
	


Measured memory_bytes: 3572
/*input
3776
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main() {
	IOS;
	string s;
	cin>>s;
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1]){
			cout << "Bad";
			return 0 ; 
		}
	}
	cout << "Good";
return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<String> set = new HashSet<>();
        String prev = sc.next();
        boolean isOk = true;
        for (int i = 1; i < n; i++) {
            set.add(prev);
            String current = sc.next();
            if (set.contains(current) || prev.charAt(prev.length() - 1) != current.charAt(0)) {
                isOk = false;
                break;
            }
            prev = current;
        }

        if (isOk) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        sc.close();
    }

}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

class Main {
    public static void main(String[] args){

        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String[] ss=br.readLine().split(" ");
            int n=Integer.parseInt(ss[0]);
            int k=Integer.parseInt(ss[1]);
            long w=1000000007;
            long[] pre=new long[n+1];
            for(int i=1;i<=n;i++){
                pre[i]=pre[i-1]+i;
            }
            long[] pos=new long[n+1];
            pos[n]=n;
            for(int i=n-1;i>=0;i--){
                pos[i]=pos[i+1]+i;
            }
            long ans=0;
            for(int i=k-1;i<=n;i++){
                ans+=(pos[n-i]-pre[i]+1);
                ans=ans%w;
            }
            System.out.println(ans);


        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
}


Measured memory_bytes: 35832
N, M = gets.split.map(&:to_i)

n = N
m = M
ans = 0

loop do
  c = 2 * n <= m ? n : m / 2
  break if c == 0

  ans += c
  n -= c
  m -= 2 * c

  a = m / 4
  n += a
  m -= 2 * a
end

puts ans


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = ni();
        int[] a = nia(n - 1);

        G = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            G.add(new ArrayList<>());
        }

        for (int i = 0; i < n - 1; i++) {
            G.get(a[i] - 1).add(i + 1);
        }

        out.println(rec(0));
    }

    ArrayList<ArrayList<Integer>> G;

    int rec(int x) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int y : G.get(x)) {
            list.add(rec(y));
        }
        Collections.sort(list);
        int ret = 0;
        for (int i = 0; i < list.size(); i++) {
            ret = Math.max(ret, list.get(i) + list.size() - i);
        }
        return ret;
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 66028
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int H, W, h, w;
	cin >> H >> W;
	cin >> h >> w;
	cout << (H - h)*(W - w) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	int N;//人数
	int T;//連続でお湯が出る秒数
	cin >> N >> T;
	vector<int>t(N);
	for (int i = 0; i < N; i++) {
		cin >> t[i];
	}
	int ans = 0;
	for (int i = 0; i < N-1; i++) {
		if (t[i + 1] - t[i] <= T) {
			ans += t[i + 1] - t[i];
		}
		else {
			ans += T;
		}
	}
	ans += T;
	cout << ans << endl;

	return 0;

}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

string to_binString(int val)
{
    if( !val )
        return std::string("0");
    string str;
    while( val != 0 ) {
        if( (val & 1) == 0 )  // val は偶数か？
            str.insert(str.begin(), '0');  //  偶数の場合
        else
            str.insert(str.begin(), '1');  //  奇数の場合
        val >>= 1;
    }
    return str;
}

int main()
{
    ll n,k,cnt = 0;
    cin >> n >> k;
    rep(i,n){
        ll h;
        cin >> h;
        if(h >= k)cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]
L = []
R = []

for gate in LR:
    L.append(gate[0])
    R.append(gate[1])

count = min(R)-max(L)
print(count+1 if count > -1 else 0)

Measured memory_bytes: 29088