akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int A,B,C;cin>>A>>B>>C;
    cout<<((A<=C&&C<=B)||(A>=C&&C>=B)?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define REPR(i, a, n) for (int i = (a); i >= (n); i--)
#define REPIT(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()
#define CO(x) cout << (x) << "\n"
#define COSP(x) cout << (x) << " "
#define mkp make_pair
#define mkt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/******* Variable ***********************************/
const int maxn = 1e6 * 50;
const double inf = 0x3f3f3f3f3f;
/******* Function ***********************************/
void OutIndent(auto &X) {
  REP(i, 0, sizeof(X) - 1) CO(X[i]);
}
void OutSpace(auto &X) {
  REP(i, 0, sizeof(X) - 2) COSP(X[i]);
  cout << X.back() << endl;
}
/*****************************************************/
/******* Main ****************************************/
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  deque<int> que;
  while (n--) {
    string cm;
    int x;
    cin >> cm;
    if (cm == "insert") {
      cin >> x;
      que.puf(x);
    }
    if (cm == "delete") {
      cin >> x;
      auto itr = find(que.begin(), que.end(), x);
      if (itr != que.end()) {
        que.erase(itr);
      }
    }
    if (cm == "deleteFirst") {
      que.pof();
    }
    if (cm == "deleteLast") {
      que.pob();
    }
  }
  n = que.size();
  for (int i = 0; i < n; i++) {
    cout << que[i] << (i + 1 < n ? " " : "\n");
  }

  return 0;
}


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

int main () {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> vt(n);
    string s;
    int x;
    for (int i = 0; i < n; i++) {
        cin >> s >> x;
        vt.at(i) = make_tuple(s,(x * -1),i+1); // ここで2番目の要素に-1を掛けると大きい順になる 大きいと小さくなってい い感じにソートできる。 30 < 50 , -30 > -50 おおおおおおおおおすごい。
    }

    sort(vt.begin(), vt.end());

    int ans;
    rep(i, n) {
        tie(ignore, ignore, ans) = vt.at(i);
        cout <<ans << endl;
    }
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from collections import Counter
MOD = 2019

def main():
    S = list(map(int, list(readline().rstrip())))
    N = len(S)
    T = [0] * (N+1)
    e = 1
    for i in range(N-1, -1, -1):
        T[i] = (T[i+1] + S[i] * e) % MOD
        e = e * 10 % MOD
    
    c = Counter(T)
    ans = 0
    for k, v in c.items():
        ans += (v * (v-1)) // 2
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 18056
import sys
input = sys.stdin.readline
import math
from functools import reduce


# 最大公約数（リスト引数）
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


N, X = [int(a) for a in input().split()]
x = [int(a) for a in input().split()]

# 座標XからDずつ移動してぴったりxkを訪れられる
# ⇄ |X - xk|がDで割り切れる
# ⇄ Dは|X-x1|,|X-x2|,...,|X-xN|の公約数
# つまりDの最大値は、|X-x1|,|X-x2|,...,|X-xN|の最大公約数

nums = [abs(X - xk) for xk in x]
ans = gcd_list(nums)
print(ans)

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

using namespace std;
const long long INF = 1LL << 60;

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() {
  int N;
  cin >> N;
  vector<int> h(N, 0);
  vector<long long> dp(N, INF);

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

  dp[0] = 0;  // 0-indexed

  for (int i = 1; i < N; ++i) {
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }

  cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1408
n=int(input())
l=[0]*n
q=int(n**0.5)
for i in range(1,q+1):
  for j in range(1,q+1):
    for k in range(1,q+1):
      t=((i+j)**2+(j+k)**2+(i+k)**2)//2
      if t<=n:
        l[t-1]+=1
print(*l)

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

int main(){
    int N;
    cin >> N;
    vector<string> ans;
    if(N <= 2) ans.push_back("0");
    for(int i=2; i<=N; i++){
        string S(i, '0');
        S[0] = S.back() = '1';
        ans.push_back(S);
    }
    cout << ans.size() << endl;
    for(auto& s : ans) cout << s << endl;
    return 0;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
#include <ctime>
#include <cstdlib>
#define rep(i, N) for (long i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<long long> a(N), b(2);
    rep(i, N)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    b[0] = 0;
    b[1] = 0;
    long long i = 0, j = 1, count = 1, k = 0;
    while (j <= N && k < 2)
    {
        if (a[i] == a[j])
        {
            count++;
            j++;
        }
        else
        {
            if (count >= 4 && k == 0)
            {
                cout << a[i] * a[i] << endl;
                return 0;
            }
            else if (count >= 2)
            {
                b[k] = a[i];
                k++;
             
            }

            count = 1;
            i = j;
            j = i + 1;
        }
    }
    cout << b[0] * b[1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int cnt[100010];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int l,r;
        cin>>l>>r;
        cnt[l]++;
        cnt[r+1]--;
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cnt[i]+=cnt[i-1];
        ans+=(cnt[i]==m);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
S = input()
X,Y = map(int,input().split())
T0 = 0
XList = []
YList = []
N = len(S)
t = 0
f = 0
for i in range(N):
    c = S[i]
    if c == 'F':
        f += 1
    else:
        if t == 0:
            T0 = f
        else:
            if t % 2 == 0:
                if f > 0:
                    XList.append(f)
            else:
                if f > 0:
                    YList.append(f)
        f = 0
        t += 1
if f > 0:
    if t == 0:
        T0 = f
    else:
        if t % 2 == 0:
            XList.append(f)
        else:
            YList.append(f)

xset = set()
yset = set()
tset = set()

xset.add( T0 )
for f in XList:
    tset.clear()
    for x in xset:
        tset.add(x+f)
        tset.add(x-f)
    xset.clear()
    for x in tset:
        xset.add(x)

yset.add( 0 )
for f in YList:
    tset.clear()
    for y in yset:
        tset.add(y+f)
        tset.add(y-f)
    yset.clear()
    for y in tset:
        yset.add(y)

if X in xset and Y in yset:
    print('Yes')
else:
    print('No')


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

public class Main {
	int N;
	public void solve() {
		N = nextInt();

		if(N / 100 == N % 10){
			out.println("Yes");
		}else{
			out.println("No");
		}
	}

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

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

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

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

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

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

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

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

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

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

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int T = Integer.parseInt(sc.next());
		int ans = 1001;
		for (int i = 0; i < N; i++) {
			int c = Integer.parseInt(sc.next());
			int t = Integer.parseInt(sc.next());
			if (t <= T) {
				ans = Math.min(ans, c);
			}
		}
		System.out.println(ans == 1001 ? "TLE" : ans);
		sc.close();

	}
}


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

int solve(vector<int>&v)
{
    int n=v.size();
    int dp[n+1];
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(int i=2; i<n; i++)
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));

    return dp[n-1];
}


int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0; i<n; i++)
        cin>>v[i];
    cout<<solve(v);
}

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

using namespace std;

bool comp(pair<int, int> a, pair<int, int> b)
{
	if( a.first > b.first or (a.first == b.first and a.second < b.second) )
	{
		return true;
	}
	
	return false;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	bool flag;
	long long int totalVal;
	int n, k, i, weight, value, j, ans;
	vector<pair<int, int>> w;
	
	cin >> n >> k;

	for(i=totalVal=0; i<n; i++)
	{
		cin >> weight >> value;
		
		totalVal += value;
		
		w.push_back(make_pair(weight, value));
	}
	
	vector<long long int> dp(totalVal+1, 1000000000001);
	
	dp[0] = 0;
	
	for(i=0; i<n; i++)
	{
		for(j=totalVal; j>=w[i].second; j--)
		{
		 	dp[j] = min(dp[j], dp[j-w[i].second]+w[i].first);
		}	
	}
	
	for(j=1,ans=INT_MIN; j<=totalVal; j++)
	{	
		if( ans < j and dp[j] <= k )
		{
			ans = j;
		}
		
//		cout << dp[j] << ' ';
	}

//	cout << '\n';
	
	cout << ans ;

	return 0;
}


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

int main(){
	int a, b;
	cin >> a >> b;
	if(a * b % 2 == 0) cout << "Even" << endl;
	else cout << "Odd" << endl;
	return 0;
}




Measured memory_bytes: 256
N, M = map(int, input().split())
X = [int(s) for s in input().split()]
X.sort()
dist = [X[i] - X[i-1] for i in range(1, M)]
dist.sort(reverse=True)
if N >= M:
    print(0)
else:
    print(sum(dist[N - 1:]))


Measured memory_bytes: 13840
using System;

class Program
{
    static void Main(string[] args)
    {
        var HW = Console.ReadLine().Split();
        var H = int.Parse(HW[0]);
        var W = int.Parse(HW[1]);

        var S = new string[H];
        for (int i = 0; i < H; i++)
        {
            S[i] = Console.ReadLine();
        }

        var h1 = new int[W, H + 2];
        for (int j = 0; j < W; j++)
        {
            for (int i = 1; i <= H; i++)
            {
                if (S[i - 1][j] == '.')
                {
                    h1[j, i] = h1[j, i - 1] + 1;
                }
            }
        }

        var h2 = new int[W, H + 2];
        for (int j = 0; j < W; j++)
        {
            for (int i = H; 0 < i; i--)
            {
                if (S[i - 1][j] == '.')
                {
                    h2[j, i] = h2[j, i + 1] + 1;
                }
            }
        }

        var w1 = new int[H, W + 2];
        for (int i = 0; i < H; i++)
        {
            for (int j = 1; j <= W; j++)
            {
                if (S[i][j - 1] == '.')
                {
                    w1[i, j] = w1[i, j - 1] + 1;
                }
            }
        }

        var w2 = new int[H, W + 2];
        for (int i = 0; i < H; i++)
        {
            for (int j = W; 0 < j; j--)
            {
                if (S[i][j - 1] == '.')
                {
                    w2[i, j] = w2[i, j + 1] + 1;
                }
            }
        }

        var max = int.MinValue;
        for (int i = 1; i <= H; i++)
        {
            for (int j = 1; j <= W; j++)
            {
                var hh = h1[j - 1, i] + h2[j - 1, i + 1];
                var ww = w1[i - 1, j] + w2[i - 1, j + 1];

                max = Math.Max(max, hh + ww);
            }
        }

        Console.WriteLine(max - 1);
    }
}


Measured memory_bytes: 90176
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll H, N, A[1123], B[1123];
ll mC[11234];
ll fh[11234];

ll f(ll h) {
	if (fh[h]) return fh[h];
	ll ret = 1123456789012;
	rep(i, h) {
		if (!i) ret = mC[h];
		else ret = min(ret, f(i) + f(h - i));
	}
	return fh[h] = ret;
}

int main() {

	cin >> H >> N;
	rep(i, N) cin >> A[i] >> B[i];

	rep(i, H + 1) {
		mC[i] = 1123456789012;
		rep(j, N) {
			mC[i] = min(mC[i], (i / A[j] + !!(i % A[j])) * B[j]);
		}
	}

	cout << f(H) << endl;

	return 0;
}


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

using namespace std;

const int md = 1e9 + 7;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 1;
    for (int i = 2; i <= n; i++){
        ans = (ans * 1LL * i) % md;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

// UnionFind 構造体 for tree
type UnionFind struct {
	par []int
}

/*コンストラクタ*/
func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}
func (u UnionFind) root(x int) int {
	if u.par[x] < 0 {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}
func (u UnionFind) unite(x int, y int) {
	xr := u.root(x)
	yr := u.root(y)
	if xr == yr {
		return
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}
func (u UnionFind) same(x, y int) bool {
	if u.root(x) == u.root(y) {
		return true
	}
	return false
}
func (u UnionFind) size(x int) int {
	return -u.par[u.root(x)]
}

var mod int = 1000000007

type pair struct {
	fi int
	se int
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	a := iScan()
	b := iScan()
	c := iScan()

	if b-a == c-b {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 1772
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
const int MAX_N = 100025;
int dp[MAX_N];
void add(int& a,int b)
{
    a+=b;
    if(a>=mod)
    {
        a-=mod;
    }
}
void sub(int& a,int b)
{
    a-=b;
    if(a<0)
    {
        a+=mod;
    }
}
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,k;
    scanf("%d%d",&n,&k);
    dp[0] = 1;
    for(int i = 1;i<=n;++i)
    {
        int up_to;
        scanf("%d",&up_to);
        vector<int > sum(k+1);
        for(int j = k;j>=0;--j)
        {
            int tmp = dp[j];
            int L = j + 1;
            int R = j + min(k-j,up_to);
            if(L<=R)
            {
                add(sum[L],tmp);
                if(R+1<=k)
                {
                    sub(sum[R+1],tmp);
                }
            }
        }
        int presum = 0;
        for(int i = 0;i <= k;++i)
        {
            add(presum,sum[i]);
            add(dp[i],presum);
        }
    }
    printf("%d\n",dp[k]);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string S;
    cin >> S;
    bool flg = true;
    int len = S.size();
    for(int i=0;i<=(len-1)/2;i++){
        if(S[i]!=S[len-i-1])flg=false;
    }

    len = (S.size()-1)/2;
    for(int i=0;i<=(len-1)/2;i++){
        if(S[i]!=S[len-i-1])flg=false;
    }

    int ix=0;
    for(int i=(S.size()+3)/2-1;i<S.size();i++){
        if(S[i]!=S[S.size()-1-ix])flg=false;
        ix++;
    }
    if(flg)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int A = Integer.parseInt(in.next());
            int B = Integer.parseInt(in.next());
            String S = in.next();

            for (int i = 0; i < A; i++) {
                char c = S.charAt(i);
                if (c >= '0' && c <= '9') {
                } else {
                    System.out.println("No");
                    return;
                }
            }
            for (int i = A; i < A + 1; i++) {
                char c = S.charAt(i);
                if (c != '-') {
                    System.out.println("No");
                    return;
                }
            }
            for (int i = A + 1; i < A + 1 + B; i++) {
                char c = S.charAt(i);
                if (c >= '0' && c <= '9') {
                } else {
                    System.out.println("No");
                    return;
                }
            }
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse -> greater<long long>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int main(){
   int h,w,k;cin>>h>>w>>k;
   char S[310][310];
   int ans[310][310];
   memset(ans,0,sizeof(ans));
   bool all_not_line[310];
   rep(i,310)all_not_line[i]=true;
   rep(i,h){
      rep(j,w){
      cin>>S[i][j];
      if(S[i][j]=='#')all_not_line[i]=false;
   }
   }
   int cnt=1;
   bool next=false;
   rep(i,h){
      next=false;
      rep(j,w){
         if(S[i][j]=='.'){
         }
         else if(next==true){
            cnt++;
         }
         else{
            next=true;
         }
         if(all_not_line[i]==false)ans[i][j]=cnt;
      }
      if(all_not_line[i]==false)cnt++;
   }
   rep(h_i,h){
      if(all_not_line[h_i]==false){
         rep(i,h_i){
            if(ans[i][0]==0){
               rep(j,w){
               ans[i][j]=ans[h_i][j];
               }
            }
         }
      }
   }
   for(int h_i=h-1;h_i>=0;h_i--){
      if(ans[h_i][0]!=0){
         for(int i=h-1;i>h_i;i--){
            if(ans[i][0]==0){
               rep(j,w)ans[i][j]=ans[h_i][j];
            }
         }
      }
   }
   rep(i,h){
      rep(j,w){
         cout<<ans[i][j]<<' ';
      }
      cout<<Endl;
   }
}

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

int main() {
	long long S;
	long long s;
	int x;
	int X=1000;
	cin >> S;
	s = S;

	for (int i = 0; i < 9; i++) {

		if (753 - s % 1000 >= 0) 
			x = 753 - s % 1000;
		else 
			x = -(753 - s % 1000);
		if (x < X)
			X = x;
		s = s / 10;
	}
	cout << X;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
//#include <atcoder/all>
 
using namespace std;
//using namespace atcoder;
 
/* template */
 
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=acos(-1);

vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int flag = 0;
    int ans = 0;
    rep(i,0,n){
        int d1,d2; cin >> d1 >> d2;
        if(d1==d2){
            flag++;
        }
        else{
            chmax(ans,flag);
            flag = 0;
        }
    }
    chmax(ans,flag);
    if(ans>=3){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3640
# -*- coding: utf-8 -*-

X=int(input())

for i in range(X, 2*X, 1):
    c=0
    for j in range(2, i+1, 1):
        if i % j == 0:
            c = c + 1
    if c == 1:
        X = i
        break
        
print(X)

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

int main(){
  int cnt = 0;
  string s;
  
  cin >> s;
  
  if(s[0] != 'A'){
    cout << "WA" << endl;
    return 0;
  }
  if('A' <= s[1] && s[1] <= 'Z'){
    cout << "WA" << endl;
    return 0;
  }
  for(int i = 2;i < s.size() - 1;i++){
    if(s[i] == 'C') cnt++;
    if(cnt > 1){
      cout << "WA" << endl;
      return 0;
    }
    if(s[i] != 'C' && 'A' <= s[i] && s[i] <= 'Z'){
      cout << "WA" << endl;
      return 0;
    }
  }
  if('A' <= s[s.size() - 1] && s[s.size() - 1] <= 'Z'){
    cout << "WA" << endl;
    return 0;
  }
  
  if(cnt) cout << "AC" << endl;
  else cout << "WA" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <cmath>
 
inline void fastscan(int &num) {
    bool neg = false;
    int c;
    num = 0;
    c = getchar_unlocked();
    if (c == '-') {
        neg = true;
        c = getchar_unlocked();
    }
    for (; (c > 47 && c < 58); c = getchar_unlocked()) num = num * 10 + c - 48;
    if (neg) num *= -1;
}
 
inline void fastout(int n) {
    int N = n, rev, count = 0;
    rev = N;
    if (N == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return ;}
    while ((rev % 10) == 0) { ++count; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10;}
    while (count--) putchar_unlocked('0');
}
 
int main(){
    
    int N; fastscan(N);
    int v[N];
    for (int i = 0; i < N; ++i) fastscan(v[i]);
    int sum = 0;
 
    for (int i = 1; i < N; ++i) sum += abs(v[i - 1] - v[i]);
    sum = sum + abs(0 - v[0]) + abs(v[N - 1] - 0);
    int diff[N];
    diff[0] = abs(0 - v[0]) + abs(v[0] - v[1]) - abs(0 - v[1]);
    for (int i = 1; i < N - 1; ++i){
        diff[i] = abs(v[i - 1] - v[i]) + abs(v[i] - v[i + 1]) - abs(v[i - 1] - v[i + 1]);
    }
    diff[N - 1] = abs(v[N - 2] - v[N - 1]) + abs(v[N - 1] - 0) - abs(v[N - 2] - 0);
 
    for (int i = 0; i < N; ++i){
        fastout(sum - diff[i]); putchar_unlocked('\n');
    }
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main(){

 
    int n, k;
    cin >> n >> k;
 
    int ans = k;
    for(int i = 0; i < n - 1; i++){
        ans *= (k - 1);
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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() {
  int X, Y, Z;
  cin >> X >> Y >> Z;

  int K;
  cin >> K;

  vector<ll> A(X);
  rep(i, X) cin >> A[i];
  vector<ll> B(Y);
  rep(i, Y) cin >> B[i];
  vector<ll> C(Z);
  rep(i, Z) cin >> C[i];

  vector<ll> AB(X * Y);
  rep(x, X) {
    rep(y, Y) { AB[x * Y + y] = A[x] + B[y]; }
  }
  sort(all(AB), greater<ll>());

  int XY = min(3000, X * Y);

  vector<ll> ABC(XY * Z);
  rep(xy, XY) {
    rep(z, Z) { ABC[xy * Z + z] = AB[xy] + C[z]; }
  }

  sort(all(ABC), greater<ll>());

  rep(k, K) { cout << ABC[k] << endl; }
}

Measured memory_bytes: 31616
#include<stdio.h>
int main(){
int w,h,x,y,r;
scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

if(x-r >= 0 && y-r >= 0&& x+r <= w && y+r <= h){
printf("Yes\n");
}
else{
printf("No\n");
}

return 0;
}


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

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    x = I()
    k = I()
    r = LI()
    q = I()
    t = [LI() for _ in range(q)]
    a = [[0,0,0,x,0,0]]
    d = 0
    for i in range(k):
        c = a[-1][:]
        rr = r[i] - d
        d = r[i]
        if i % 2 == 0:
            c[1] -= rr
            c[3] -= rr
            c[4] -= rr
            if c[0] > c[1]:
                c[0] = c[1]
        else:
            c[1] += rr
            c[3] += rr
            c[4] += rr
            if c[2] < c[1]:
                c[2] = c[1]
        if c[3] > x:
            c[3] = x
        if c[3] < 0:
            c[3] = 0
        if c[4] > x:
            c[4] = x
        if c[4] < 0:
            c[4] = 0

        c[5] = r[i]

        a.append(c)
    def bs(i):
        ma = k
        mi = 0
        mm = 0
        while ma > mi and (ma+mi) // 2 != mm:
            mm = (ma+mi) // 2
            if a[mm][5] < i:
                mi = mm
            else:
                ma = mm - 1
        if a[mm][5] > i:
            return mm-1
        if mm == k:
            return k
        if a[mm+1][5] <= i:
            return mm+1
        return mm

    #print(a)
    rr = []
    for c,d in t:
        ti = bs(c)
        ai = a[ti]
        e = x-d
        #print(c,d,e,ti,ai)
        if d + ai[0] <= 0:
            tt = ai[4]
        elif e - ai[2] <= 0:
            tt = ai[3]
        else:
            tt = d + ai[1]
        #print('tt',tt)
        if ti % 2 == 0:
            tt -= c - ai[5]
        else:
            tt += c - ai[5]
        #print('tt2',tt)
        if tt < 0:
            tt = 0
        elif tt > x:
            tt = x
        rr.append(tt)

    return '\n'.join(map(str,rr))


print(main())



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

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

    int r = n % 10;
    if (r == 2 ||r == 4 ||r == 5 ||r == 7 || r == 9) cout << "hon" << endl;
    else if(r == 0 ||r == 1 ||r == 6 ||r == 8) cout << "pon" << endl;
    else cout << "bon" << endl;
     
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using vi = vector <int> ;
using vii = vector <long long> ;

#define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define endl "\n"
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define trace(x)  for (auto itr : x)
#define rep(i, n) for (auto i = 0; i < n; ++i)
#define repi(i, x, n) for (auto i = x; i <= n; ++i)

ll solve(ll W, vii wt, vii val, ll n ) {
	int i, w;
	ll dp[n+1][W+1];
	repi(i,0,n){
		repi(w,0,W){
			if (i==0 || w==0)
				dp[i][w] = 0;
			else if (wt[i-1] <= w) 
                dp[i][w] = max(val[i-1] + dp[i-1][w-wt[i-1]],  dp[i-1][w]); 
            else
                dp[i][w] = dp[i-1][w]; 
		}
	}

	return dp[n][W];
}

const int N=1e5+5;

int32_t main()
{
	IOS;
	ll n,W;
	ll x,y;
	cin>>n>>W;
	vii val(n), wt(n);
	rep(i,n){
		cin>>x>>y;
		wt[i] = x;
		val[i] = y;
	}

	cout<<solve(W,wt,val,n)<<endl;


	return 0;
}

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

using namespace std;

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

	int r, d, x, aux;

	cin >> r >> d >> x;

	for (int i = 0; i < 10; i++) {
		aux = r*x - d;
		cout << aux << '\n';
		x = aux;
	}	

	return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	double sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum = sum + a[i];
	}

	sum = (double)sum / (double)n;
	//cout << sum << endl;
	int ansl = (int)(sum);
	int ansh = ansl + 1;

	int el = 0;
	int eh = 0;

	for (int i = 0; i < n; i++) {
		el = el + (a[i] - ansl)*(a[i] - ansl);
		eh = eh + (a[i] - ansh)*(a[i] - ansh);
	}
	int cost = 0;
	if (el > eh) { //anshのが優秀
		cout << eh << endl;
	}
	else cout << el << endl;



	return 0;
}




Measured memory_bytes: 256
H, W = list(map(int, input().split()))
ans = 10**10

for w1 in range(1, W//2+1):
    s1 = H*w1

    w2 = (W-w1)//2
    w3 = W-w1-w2
    s2 = H*w2
    s3 = H*w3
    ans = min(ans, max(s1, s2, s3)-min(s1,s2,s3))

    h2 = H//2
    h3 = H-h2
    s2 = (W-w1)*h2
    s3 = (W-w1)*h3
    ans = min(ans, max(s1, s2, s3)-min(s1,s2,s3))

H, W = W, H

for w1 in range(1, W//2+1):
    s1 = H*w1

    w2 = (W-w1)//2
    w3 = W-w1-w2
    s2 = H*w2
    s3 = H*w3

    ans = min(ans, max(s1, s2, s3)-min(s1,s2,s3))

    h2 = H//2
    h3 = H-h2
    s2 = (W-w1)*h2
    s3 = (W-w1)*h3
    ans = min(ans, max(s1, s2, s3)-min(s1,s2,s3))

print(ans)

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

int id,n,q,a,b,p;
vector<int> graph[200005];
int masuk[200005],keluar[200005];
long long arr[200005],tmp,x,ans[200005];
void dfs(int now, int par){
	id++;
	masuk[now] = id;
	for(int i =0;i<graph[now].size();i++){
		int nex = graph[now][i];
		if(nex == par) continue;
		dfs(nex,now);
	}
	keluar[now] = id;
}

int main(){
	scanf("%d%d",&n,&q);
	for(int i =0;i<n-1;i++){
		scanf("%d%d",&a,&b);
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	id = 0;
	dfs(1,-1);
//	for(int i =1;i<=n;i++){
//		printf("node %d(%d) = %d - %d\n",i,masuk[i],masuk[i],keluar[i]);
//	}
	while(q--){
		scanf("%d%lld",&p,&x);
		arr[masuk[p]]+=x;
		arr[keluar[p]+1]-=x;
	}
	tmp  =0;
	for(int i =1;i<=n;i++){
		tmp+=arr[i];
		ans[i] = tmp;
	}
	for(int i = 1;i<=n;i++){
		if(i!=1) printf(" ");
		printf("%lld",ans[masuk[i]]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 30336
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long

signed main() {
  int n, x;
  cin >> n >> x;
  int a = max(x, n - x), b = min(x, n - x);
  int ans = a + b;
  while (a % b != 0) {
    ans += (a / b) * 2 * b;
    int res = a % b;
    a = b;
    b = res;
  }
  ans += (a / b) * 2 * b - b;
  cout << ans << endl;
  return 0;
}


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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  if(n == 1) {
    ll ans = k / 2;
    cout << ans << endl;
    return 0;
  }


  if(s[0] != s[n-1]) {
    ll dup = 0;
    ll tmp_dup = 1;
    REP(i,n-1) {
      if(s[i] == s[i+1]) {
        ++tmp_dup;
      } else {
        dup += tmp_dup / 2;
        tmp_dup = 1;
      }
    }
    dup += tmp_dup / 2;
    cout << dup*k << endl;
    return 0;
  }

  ll left_dup = 1;
  REP(i,n-1) {
    if(s[i] != s[i+1]) break;
    ++left_dup;
  }
  if(left_dup == n) {
    cout << n*k/2 << endl;
    return 0;
  }
  ll right_dup = 1;
  REPRS(i, 1, n-1) {
    if(s[i] != s[i-1]) break;
    ++right_dup;
  }

  ll half_cent_dup = 0;
  ll tmp_dup = 1;
  REPS(i,left_dup,n-right_dup) {
    if(s[i] == s[i+1]) {
      ++tmp_dup;
    } else {
      half_cent_dup += tmp_dup / 2;
      tmp_dup = 1;
    }
  }
  half_cent_dup += tmp_dup / 2;

  ll ans = 0;
  ll half_left_dup = left_dup / 2;
  ll half_right_dup = right_dup / 2;
  
  ans += half_cent_dup * k;
  ans += (k-1) * ((left_dup+right_dup)/2) + half_left_dup + half_right_dup;
  // LOG(half_left_dup);
  // LOG(half_cent_dup);
  // LOG(half_right_dup);
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	vector<string> a = {"Sunny", "Cloudy", "Rainy", "Sunny"};
	string s;
	cin >> s;
	for(int i=0; i<3; i++) {
		if(a[i] == s) {
			cout << a[i+1];
			break;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll n, k;
vector<ll> a, f, v;

bool check(ll m){
    ll cnt = 0;
    rep(i, n){
        ll v = a[i]*f[i];
        if(v > m){
            cnt += (v-m)/f[i] + ((v-m)%f[i] != 0);
        }
    }
    return cnt <= k;
}

ll binary_search(){
    ll ng = -1;
    ll ok = INF;

    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }

    return ok;
}


int main(){
    cin >> n >> k;
    rep(i, n){
        ll t;
        cin >> t;
        a.push_back(t);
    }
    rep(i, n){
        ll t;
        cin >> t;
        f.push_back(t);
    }

    sort(all(a));
    sort(rall(f));

    cout << binary_search() << endl;
}

Measured memory_bytes: 4976
// D - Triangles
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define all(x) (x).begin(),(x).end()

int solve(int N, vi &L){
	sort(all(L));
	int ans = 0;
	rp(ia, 0, N-2){
		int minL = L[ia];
		rp(ib, ia+1, N-1){
			int midL = L[ib];
			irp(ic, N-1, ib){
				int maxL = L[ic];
				if(maxL < minL + midL){
					int d = ic - ib;
					ans += d;
					break;
				}
			}
		}
	}
	return ans;
}

int main(){
	int N; cin>>N;
	vi L(N);
	rp(i, 0, N) cin>>L[i];
	cout<< solve(N, L) <<endl;
}

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

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= int(b); --i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

int main() {
	int n;
	cin >> n;
	pair<int, int> ans;
	ans.first = 1;
	FOR(i, 1, n+1) {
		int cnt = 0;
		int num = i;
		while (num > 1 && num % 2 == 0) {
			num /= 2;
			cnt++;
		}
		if (ans.second < cnt) {
			ans.second = cnt;
			ans.first = i;
		}
	}
	cout << ans.first << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int tate, yoko, menseki, syuu;

	scanf("%d %d",&tate, &yoko);

	if((1 <= tate) && (yoko <= 100))
	{
		menseki = tate * yoko;
		syuu = (2*tate) + (2*yoko);

		printf("%d %d\n",menseki, syuu);
	}

	return 0;
}

Measured memory_bytes: 596
import sys
from fractions import gcd
A,B,C,D=map(int, sys.stdin.readline().split())
C_cnt=B/C-(A-1)/C
D_cnt=B/D-(A-1)/D
CD_gcd=gcd(C,D)
CD_lcm=C/CD_gcd*D/CD_gcd*CD_gcd
CD_lcm_cnt=B/CD_lcm-(A-1)/CD_lcm
print B-(A-1)-C_cnt-D_cnt+CD_lcm_cnt

Measured memory_bytes: 34536
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi(), m = gi();
	if (n % m == 0) cout << n / m;
	else cout << n / m + 1; 
	return 0;
}



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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  for (int i = 0; cin >> x[i]; i++) {}
  sort(x.begin(), x.end());
  vector<int> l(m - 1);
  for (int i = 0; i < m - 1; i++)
  {
    l[i] = abs(x[i] - x[i + 1]);
  }
  sort(l.begin(), l.end());
  long ans = 0;
  for (int i = 0; i < m - n; i++)
  {
    ans += l[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x, y;
	scanf("%d %d", &x, &y);

	int nums[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2 ,1};
	printf("%s\n", (nums[x] == nums[y] ? "Yes" : "No"));

	return 0;
}

Measured memory_bytes: 764
program evergrowing_tree
  implicit none
  integer :: n, q, v, w, nv, nw, i
  read(*,*) n, q
  if (n == 1) then
    do i = 1, q
      read(*,*) v, w
      write(*,'(i0)') v
    end do
    stop
  end if
  do i = 1, q
    read(*,*) v, w
    v = v-1
    w = w-1
    nv = depth(v,n)
    nw = depth(w,n)
    do while (nw > nv)
      w = (w-1)/n
      nw = nw-1
    end do
    do while (v /= w)
      v = (v-1)/n
      w = (w-1)/n
    end do
    write(*,'(i0)') v+1
  end do
contains
  integer function depth(v,n)
    integer, intent(in) :: v, n
    integer :: x
    depth = 0
    x = v
    do while (x > 1)
      x = (x-1)/n
      depth = depth+1
    end do
  end
end program evergrowing_tree

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  for (int r = 0; R * r <= N; r++) {
    for (int g = 0; R * r + G * g <= N; g++) {
      if ((N - R * r - G * g) % B == 0) {
        ans++;
      }
    }
  }

  cout << ans << endl;
}

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

int main()
{
  int x,y;

  for(int i =1 ; ; i++)
    {
      cin >> x >> y;
      if( x == 0 && y == 0){break;}

      if( x > y )
	{swap(x,y);}

      cout << x << " " << y << endl;
    }

  return 0;
}
      



Measured memory_bytes: 3008
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int n, k; cin >> n >> k;
	int a[60]; for (int i = 0; i < n; i++)cin >> a[i]; sort(a, a + n);
	ll sum = 0;
	for (int i = 0; i < k; i++){
		sum += a[n - 1 - i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int main(){
   int n,m;
   cin>>n;
   cout<<24+(24-n); 
    return 0;
}


Measured memory_bytes: 256
# Aizu Problem ALDS_1_14_A: Naive Search
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


string = input().strip()
pattern = input().strip()
pos = string.find(pattern)
while pos >= 0:
    print(pos)
    pos = string.find(pattern, pos + 1)

Measured memory_bytes: 7456
def examC():
    N = I(); A = [I() for _ in range(N)]
    cur = -1; ans = -1
    for i in range(N):
        if A[i]>cur+1:
            ans = -1
            break
        elif A[i]==cur+1:
            cur +=1
            ans +=1
        else:
            ans += A[i]
            cur = A[i]
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


Measured memory_bytes: 51932
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n, m; cin >> n >> m;
    vector<deque<int>> a(n, deque<int>(m));
    FOR(i, 0, n)FOR(j, 0, m){
        cin >> a[i][j];
        a[i][j]--;
    }

    vector<bool> no(m, false);
    int ans = INF;
    FOR(i, 0, m) {
        VI cnt(m, 0);
        FOR(i, 0, n)cnt[a[i].front()]++;
        chmin(ans, *max_element(all(cnt)));
        no[max_element(all(cnt)) - cnt.begin()] = true;
        FOR(i, 0, n)while (!a[i].empty() && no[a[i].front()])a[i].pop_front();
    }
    cout << ans << "\n";
}


Measured memory_bytes: 768