akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"math"
	"strconv"
)

var K, A int
var ans int = 9999999999
var N string
var D []int

func main() {
	fmt.Scan(&N, &K)
	D = make([]int, 10)

	for i := 0; i < K; i++ {
		var t int
		fmt.Scan(&t)
		D[t]--
	}
	dfs(0, [10]int{})
	fmt.Println(ans)
}

func dfs(n int, comb [10]int) {
	if n == len(N)+1 {
		calc(comb)
	} else {
		for i := 0; i < 10; i++ {
			if D[i] == 0 {
				comb[n] = i
				dfs(n+1, comb)
			}
		}
	}
}

func calc(comb [10]int) {

	var res1, res2 int
	n, _ := strconv.Atoi(N)

	for i := 0; i < len(N); i++ {
		res1 *= 10
		res1 += comb[i]
	}
	for i := 0; i <= len(N); i++ {
		res2 *= 10
		res2 += comb[i]
	}

	if n <= res1 {
		ans = min(ans, res1, res2)
	} else if n <= res2 {
		ans = min(ans, res2)
	}

}

/*  ----------------------------------------  */

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] > a[j] }


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict

H, W, N = map(int, input().split())
dic = defaultdict(int)
dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
dy = [1, 1, 1, 0, 0, 0, -1, -1, -1]
for i in range(N):
    y, x = map(int, input().split())
    for j in range(9):
        ny, nx = y+dy[j], x+dx[j]
        if not 1 < ny < H: continue
        if not 1 < nx < W: continue
        dic[str(ny)+":"+str(nx)] += 1
count = [0]*10
tot = (H-3+1)*(W-3+1)
count[0] = tot-len(dic.keys())
for k,v in dic.items():
    count[v] += 1
for c in count:
    print(c)


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

using namespace std;

const int MAX = 2e5+10;

long long a[MAX], l[MAX], r[MAX];

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

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

    l[0] = a[0];
    for(int i=1;i<n;++i)
        l[i] = l[i-1] + a[i];

    r[n-1] = a[n-1];
    for(int i=n-2;i>=0;i--)
        r[i] = r[i+1] + a[i];

    // for(int i=0;i<n;++i){
    //     cout << a[i] << ' ' << l[i] << ' ' << r[i] << '\n';
    // }

    long long sol = abs(l[0]-r[1]);
    for(int i=1;i<n-1;++i)
        sol = min(sol, abs(l[i]-r[i+1]));

    cout << sol << '\n';

    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main() {
	int a, b;
	char c;
	cin >> a;
	while (true) {
		cin >> c;
		if (c == '=') {
			break;
		}
		cin >> b;
		if (c == '+'){
			a += b;
		}
		else if (c == '-') {
			a -= b;
		}
		else if (c == '*') {
			a *= b;
		}
		else if (c == '/') {
			a /= b;
		}
	}
	cout << a << endl;
	cin >> c;
}

Measured memory_bytes: 3108
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;
  int a[1000];
  scanf("%d\n",&n);
  for(int i=0;i<n;i++)scanf("%d",&a[i]);
  sort(a,a+n);
  int v=a[n-1],x=0;
  bool f=0;
  while(!f){
    f=1;
    x+=v;
    for(int i=0;i<n-1;i++){
      if(x%a[i]!=0) f=0;
    }
  }
  printf("%d\n",x);
  return 0;
}

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

#define ll long long
#define pll pair<ll,ll>
#define all(x) x.begin(), x.end()

#define MOD 500005

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

	string s;
	cin >> s;

	if(s.back()!='s') cout << s << "s" << endl;
	else cout << s << "es" << endl;

	return 0;
}

Measured memory_bytes: 3660
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

map<int, int> doubles;

int solve(const int N) {
    int ans = 0;

    for (int x = 1; x < 100; x++) {
        for (int y = 1; y < 100; y++) {
            const int v = (x + y) * (x + y) - 4 * (x * x + y * y + x * y - N);
            if (v < 0) {
                continue;
            }
            if (doubles.find(v) == doubles.end()) {
                continue;
            }

            const int z2 =  -1 * (x + y) + doubles[v];
            if (z2 <= 0) {
                continue;
            }
            if (z2 % 2 == 0) {
                // printf("x: %d, y: %d, z: %d\n", x, y, z2 / 2);
                ans++;
            }
        }
    }

    return ans;
}

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

    // prepare doubles
    for (int i = 0; i <= 1000; i++) {
        doubles[i * i] = i;
    }

    for (int i = 1; i <= N; i++) {
        // printf("%d: \n", i);
        printf("%d\n", solve(i));
    }

    return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 1000010
#define mod 1000000007
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define out(s) cout<<s
#define outs(s,a) cout<<s<<a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
void solve(){
	ll k,i;
	in(k);
	string str;
	in(str);
	if(str.length()<=k){
		cout<<str<<'\n';
	}else{
		nfl(i,k){
			cout<<str[i];
		}
		cout<<"...\n";
	}
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	clock_t t1=clock();
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
	clock_t t2=clock();
	cerr<<"Time elapsed:- "<<(double)(t2-t1)/CLOCKS_PER_SEC<<'\n';
}	

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
int n,offset,j,pre,ans;
string s,t;
deque<int> q;
int main()
{
	cin>>n>>s>>t;
	q.push_back(n);j=n-1;
	for (int i=n-1;i>=0;i--)
	{
		pre=j;
		while(j>=0 && (j>i || s[j]!=t[i])) j--;
		if (j<0) 
		{
			printf("-1\n");
			return 0;
		}
		if (pre==j)
		{
			while(!q.empty() && q.back()-offset>=i) q.pop_back();
			q.push_back(i+offset); 
 		}
 		else
 		{
 			offset++;
 			if (i!=j)
 			{
 				ans=max(ans,(int)q.size());
 				q.push_front(j+offset); 
			 }
		}
	} 
	cout<<ans<<endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin>>k;
    cout<<(k/2)*((k+1)/2)<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()

white_to_red = 0
red_to_white = s.count('R')

ans = red_to_white
for i in range(n):
    if s[i] == 'W':
        white_to_red += 1
    else:
        red_to_white -= 1
    ans = min(ans, max(white_to_red, red_to_white))

print(ans)

Measured memory_bytes: 9432
//
//  abc169_b.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll INF = 1000000007;
#define PI 3.14159265


int main() {
  ll n;
  std::cin >> n;
  long double a[n];
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      std::cout << 0 << std::endl;
      return 0;
    }
  }

  long double ans = 1;
  for (int i = 0; i < n; i++) {
    long double new_a = ans*a[i];
    if (new_a <= 1000000000000000000) ans = new_a;
    else {ans = -1; break;}
  }


  std::cout << (ll)ans << std::endl;

  return 0;
}

Measured memory_bytes: 5252
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
ans = -max(a)
cnt = 0

if n%2 == 0:
    for i in a:
        ans += i*2
        cnt += 2
        if cnt == n:
            print(ans)
            exit()
else:
    for i in a:
        ans += i*2
        cnt += 2
        if cnt >= n:
            print(ans - i)
            exit()

Measured memory_bytes: 31688
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",(a+b)%24);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

public class AtCoder_151_C
{
    public static void Main()
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int[] line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int n = line1[0];
        int m = line1[1];

        bool[] isAc = new bool[n + 1];
        int[] isWaCount = new int[n + 1];

        for (int i = 0; i < m; i++)
        {
            string[] line = Console.ReadLine().Split(' ').ToArray();
            int num = int.Parse(line[0]);
            if (isAc[num])
            {
                continue;
            }
            if (line[1] == "AC")
            {
                isAc[num] = true;
            }
            else
            {
                isWaCount[num]++;
            }
        }

        int acCount = 0;
        int waCount = 0;

        for (int i = 1; i < n + 1; i++)
        {
            if (isAc[i])
            {
                acCount++;
                waCount += isWaCount[i];
            }
        }

        Console.WriteLine(string.Format("{0} {1}", acCount, waCount));
    }
}


Measured memory_bytes: 17756
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.next()
    val b = sc.next()
    println(problem078a(a, b))
}

fun problem078a(a: String, b: String): String {
    return if (a < b) "<" else if (a > b) ">" else "="
}

Measured memory_bytes: 31520
using System;
using System.IO;

class Solve {
    static void Main(string[] args) {
        var arr = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long X = arr[0], Y = arr[1];
        var answer = 0;
        while (X <= Y) {
            X *= 2;
            answer++;
        }
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 27532
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    int r = x%y;
    if (r == 0) {
        return y;
    }
    return gcd(y, r);
}

ll mypow(ll x, ll n) {
    if (n == 0) return 1;
    if (n%2 == 0) return mypow(((x%mod)*(x%mod))%mod, n/2);
    else return ((x%mod) * mypow(((x%mod)*(x%mod))%mod, (n-1)/2))%mod;
}

int main(){
    ll N, K;
    cin >> N >> K;
    map<ll, ll> hist;
    for (ll i=1; i<=K; i++) hist[i] = 0;
    ll sum = 0;
    for (ll i=K; i>=1; i--) {
        hist[i] += mypow(K/i, N)%mod;
        for (ll j=2; i*j<=K; j++) {
            if (hist[i] < hist[i*j]) hist[i] += mod;
            hist[i] -= hist[i*j];
        }
        sum = (sum + i*hist[i])%mod;
    }
    cout << sum << endl;
}

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

int n,x;
ll dp[205][200005];
int s[205];

ll extgcd(ll a,ll b,ll& x,ll& y){
    ll d=a;
    if(b!=0LL){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }else{
        x=1;
        y=0;
    }
    return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

int main(void){
    scanf("%d%d",&n,&x);
    for(int i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    sort(s,s+n);
    for(int i=0;i<=x;i++){
        dp[0][i]=i;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=x;j++){
            dp[i+1][j]=(ll)dp[i][j]*i%MOD;
            dp[i+1][j]+=dp[i][j%s[i]];
            dp[i+1][j]%=MOD;
        }
    }
    printf("%lld\n",dp[n][x]);
    return 0;
}

Measured memory_bytes: 312704
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n" // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n)             \
	for (int i = 0; i < (n); i++) \
		cin >> (c)[i];
#define exit_message(s) return 0 * printf(s)
#define show(c)           \
	for (auto i : (c))      \
		cout << i << " "; \
	cout << "\n";
#define display(c, n)           \
	for (int i = 0; i < (n); i++) \
		cout << (c)[i] << " ";    \
	cout << "\n";
#define forl(i, a, n) for (int (i) = (a); (i) < (n); (i)++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}

const int N = 1e3 + 5;

int h, w;
char a[N][N];
int cache[N][N];

int solve(int x, int y)
{
	if (x > h || y > w)
		return 0;
	if (x == h && y == w)
		return 1;

	int &memo = cache[x][y];
	if (memo != -1)
		return memo;

	memo = ((a[x + 1][y] == '.') * solve(x + 1, y) + (a[x][y + 1] == '.') * solve(x, y + 1)) % mod;
	return memo;
}

int32_t main()
{
#ifdef FASTIO
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif
	// freopen("in.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	memset(cache, -1, sizeof cache);

	cin >> h >> w;
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			cin >> a[i][j];
		}
	}

	int ans = solve(1, 1);
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
int main()
{ int a,b;
 long long sum,mul,sub=0;
 cin>>a;
 cin>>b;
 sum=a+b;
 sub=a-b;
 mul=a*b;
 int res=max(sum,max(sub,mul));
 cout<<res;
return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ll t, a, T{1}, A{1}, k;
  cin >> k;
  while(cin >> t >> a) {
    k = ((ld)T/A < (ld)t/a ? (A-1)/a+1 : (T-1)/t+1);
    A = k * a, T = k * t;
  }
  cout << T + A << endl;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9+7
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
 
 
int main(){
    int n;
    cin>>n;
    set<int> s;
    rep(i,n){
        int a;
        cin>>a;
        s.insert(a);
    }
    if(s.size()==n) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define l long 
#define ll long long 
#define ld long double 
#define MOD 1000000007
#define MAX_N 1000006
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
vector<vector<l>> adj(MAX_N);
vector<ll> dp(MAX_N,-1);
ll long_path(l pos)
{
    if(dp[pos]!=-1)
    {
        return dp[pos];
    }
    dp[pos]=0;
    for(l i=0;i<adj[pos].size();i++)
    {
        dp[pos]=max(dp[pos],1+long_path(adj[pos][i]));
    }
    return dp[pos];
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    l n,m,u,v;
    cin>>n>>m;
    for(l i=0;i<m;i++)
    {
        cin>>u>>v;
        u--;
        v--;
        adj[u].push_back(v);
    }
    ll ans=0;
    for(l i=0;i<n;i++)
    {
        ans=max(ans,long_path(i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 39536
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int d, t, s;
	cin >> d >> t >> s;

	if (s * t >= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
signed main(){
	string s,p;
	cin>>s>>p;
	s=s+s;
	for(int i=0;i<=s.size()-p.size();i++){
		if(s.substr(i,p.size())==p){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 3172
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  char s[14];
  scanf("%s",s);
  int n,i;
  int min=1000,tmp,diff=0;
  n=strlen(s);
  for(i=0;i<n-2;i++){
    tmp=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    diff=abs(753-tmp);
    if(diff<min){
      min=diff;
    } 
  }
  printf("%d\n",min);
  return 0;
}



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

int main() {
    string s;
    cin >> s;

    if (s == "keyence") {
        cout << "YES" << endl;
        return 0;
    }

    int n = s.length() - 7;

    for (int i = 0; i < 7; i++) {
        string ss = s.substr(0, i) + s.substr(i + n, s.length() - i);
        if (ss == "keyence") {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll pos[200010];
ll a[200010];

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

    rep(i, n){
        ll p;
        cin >> p;
        p--;
        pos[p] = i;
    }

    multiset<ll> st = {-1, n};
    ll ans = 0;
    rep(i, n){
        st.insert(pos[i]);
        auto it = st.lower_bound(pos[i]);
        auto l = prev(it);
        auto r = next(it);
        ans += (i+1) * (*it - *l) * (*r - *it);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14520
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1 << 29;
const int maxn = 200 + 10;
int g[maxn][maxn];
struct edge{
  int u, v, cost;
} e[1000 + 11];
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  int n, m; cin >> n >> m;
  for (int i = 1; i <= n; i++){
    for (int j = 1; j <= n; j++){
      if (i == j) g[i][j] = 0;
      else g[i][j] = inf;
    }
  }
  for (int i = 0; i < m; i++){
    cin >> e[i].u >> e[i].v >> e[i].cost;
    g[e[i].u][e[i].v] = e[i].cost;
    g[e[i].v][e[i].u] = e[i].cost;
  }
  for (int k = 1; k <= n; k++){
    for (int i = 1; i <= n; i++){
      for (int j = 1; j <= n; j++){
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  int ret = m;
  for (int i = 0; i < m; i++){
    bool ok = false;
    for (int j = 1; j <= n; j++){
      if (g[j][e[i].u] + e[i].cost == g[j][e[i].v]) 
        ok = true;
    }
    if (ok) ret--; // edge is a part of shortest path
  }
  cout << ret << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
using namespace std;

int main(){
  int N,D,ans=0;
  cin>>N>>D;
  int X[N][D];
  for(int i=0; i<N; ++i){
    for(int j=0; j<D; ++j){
      cin>>X[i][j];
    }
  }
  
  for(int i=0; i<N-1; ++i){
    for(int j=i+1; j<N; ++j){
      int cnt=0;
      for(int k=0; k<D; ++k){
        cnt+=abs(X[i][k]-X[j][k])*abs(X[i][k]-X[j][k]);
      }
      for(int l=0; l<10000; ++l){
        if(cnt==(l*l)){
          ans++;
        }
      }
    }
  }
  
  cout<<ans<<endl;
}


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

using namespace std;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const  long long  INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int n;
double x[100010], r[100010], low = 0, high = 1e9, mid;

bool check(double dist) {
	double L = -1e9, R =1e9;
	for (int i = 0;i < n;i++) {
		L = max(L, x[i] - sqrt(r[i] * r[i] - dist * dist));
		R = min(R, x[i] + sqrt(r[i] * r[i] - dist * dist));
	}
	return L < R;
}

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> x[i] >> r[i];
		high = min(high, r[i]);
	}
	for (int i = 0;i < 100;i++) {
		mid = (low + high) / 2;
		if (check(mid))low = mid;
		else high = mid;
	}
	cout << setprecision(15) << low << endl;
	return 0;
}




Measured memory_bytes: 4860
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<60)
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll h, w;
    cin >> h >> w;
    multiset<ll> m;
    set<pair<ll, ll>> s;
    rep(i, w){
        s.insert({i, i});
        m.insert(0);
    }
    m.insert(INFLL);
    s.insert({-1, -2000000});
    s.insert({w, w});

    // k番目のクエリを処理する場合、現在位置が[a[i], b[i]]の場合はb[i]+1まで右に移動する必要がある。
    // ただし、b[i]+1 >= wの場合は枠外として例外処理する。
    vi a(h), b(h);
    rep(i, h){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        while(1){
            auto it = s.lower_bound({a[i], 0});
            if(it->first > b[i]) break;
            if(next(it)->first <= (b[i]+1)){
                m.erase(m.find(it->first - it->second));
                s.erase(it);
            }
            else{
                ll r = it->second;
                m.erase(m.find(it->first - it->second));
                s.erase(it);
                s.insert({b[i]+1, r});
                m.insert({b[i]+1-r});
            }
        }
        ll tmp = *(m.begin()) + (i+1);
        if(tmp >= h+w) tmp = -1;
        cout << tmp << endl;
    }
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll n, ans = 0;
  string s;
  cin >> n >> s;
  rep(i, n - 2) {
    auto p = s.substr(i, 3);
    if (p == "ABC")
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    String x=sc.next();
    String y=sc.next();
    x+=y.charAt(y.length()-1);
    if(x.equals(y))
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
using vi = vector<int>;
using vvi = vector<vi>;

signed main(){
  int n,m;
  while(cin >> n >> m, n){
    vi a(n); rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n) rep(j,n){
      if(i == j) continue;
      if(a[i] + a[j] <= m) ans = max(ans, a[i]+a[j]);
    }
    if(ans)
      cout << ans << endl;
    else
      cout << "NONE\n";
  }
}



Measured memory_bytes: 3104
#include <stdio.h>

int main(void){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a<=b){
        if(c<=d){
            printf("%d\n",a+c);
        }else{
            printf("%d\n",a+d);
        }
    }else{
        if(c<=d){
            printf("%d\n",b+c);
        }else{
            printf("%d\n",b+d);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 200
 
struct Point{
    int x, y;
 
    bool operator < (const Point p)const{
	if(x != p.x){
	    return x < p.x;
	}else{
	    return y < p.y;
	}
    }
};
 
int n, m;
Point star[MAX], pict[MAX*5];
 
Point search(){
    Point res;
    vector<Point> v;
 
    for(int i = 0 ; i < m ; i++){
	for(int j = 0 ; j < n ; j++){
	    Point P;
	    P.x = pict[j].x - star[i].x;
	    P.y = pict[j].y - star[i].y;
	    v.push_back(P);
	}
    }
    sort(v.begin(),v.end());
 
    int cnt = 1;
    Point p = v[0];
    for(int i = 1 ; i < (int)v.size() ; i++){
	if(cnt == m){
	    res = p;
	    break;
	}
 
	if(p.x != v[i].x || p.y != v[i].y){
	    p = v[i];
	    cnt = 1;
	}else{
	    cnt++;
	}
    }
 
    return res;
}
 
int main(){
    while(cin >> m, m){
	for(int i = 0 ; i < m ; i++){
	    cin >> star[i].x >> star[i].y;
	}
 
	cin >> n;
	for(int i = 0 ; i < n ; i++){
	    cin >> pict[i].x >> pict[i].y;
	}
 
	Point p = search();
	cout << p.x << " " << p.y << endl;
    }
    return 0;
}

Measured memory_bytes: 6580
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int a, b;

    cin >> a >> b;

    if ( a <= 8 && b <= 8)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
t0=x0=y0=0
for _ in range(n):
    t,x,y = map(int,input().split())
    if abs(x-x0)+abs(y-y0)>abs(t-t0) or (abs(t-t0)-abs(x-x0)-abs(y-y0))%2!=0:
        print("No")
        exit()
    x0=x
    y0=y
    t0=t
print("Yes")



Measured memory_bytes: 47080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

import static java.lang.Integer.parseInt;

/**
 * Princess's Marriage - Accepted
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int N, M;
			N = parseInt(line.substring(0, line.indexOf(' ')));
			M = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((N | M) == 0) break;

			int[] ps = new int[11];
			int expected = 0;

			for (int i = 0; i < N; i++) {
				line = br.readLine();
				int D, P;
				D = parseInt(line.substring(0, line.indexOf(' ')));
				P = parseInt(line.substring(line.indexOf(' ') + 1));
				ps[P] += D;
				expected += D * P;
			}

			for (int i = 10; i >= 0; i--) {
				if (ps[i] > 0) {
					if (ps[i] <= M) {
						expected -= i * ps[i];
						M -= ps[i];
					} else {
						expected -= i * M;
						M = 0;
					}
				}
			}
			System.out.println(expected);

		} //end while
	} //end main
}

Measured memory_bytes: 43672
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

ans = 1
for i in range(1, N+1):
	ans = (ans*i)%mod

print(ans)


Measured memory_bytes: 5148
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
#include <limits>
using namespace std;
int gcd(int a, int b)//最大公約数
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}
vector<int> divisor(int n) {//約数発見
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}
long nc2(long n){
    return n*(n-1)/2;
}
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
	static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string ret;
	static numeric_limits<TypeInt> t;
	TypeInt n = v;
	if (t.is_signed) {
		if (v < 0) n *= -1;
	}

	while (n >= base) {
		ret += table[n%base];
		n /= base;
	}
	ret += table[n];
	if (t.is_signed) {
		if (v < 0 && base == 10) ret += '-';
	}
	// 文字列の順番を逆にする
	std::reverse(ret.begin(), ret.end());

	return ret;
}
int main(){
    //std::stack<int> stack;
    long n;
    cin >> n;
    
    cout << n+n*n+n*n*n << endl;
    return 0;
}






Measured memory_bytes: 3624
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        //String[] array = scanner.nextLine().split(" ");
        int N = Integer.parseInt(scanner.nextLine());
        String S = scanner.nextLine();
        char[] array = S.toCharArray();
        int[] line = new int[N];

        for (int i = 0; i < N; ++i) {
            char start = array[i];
            if (start != '\n') {
                int endIndex = i;
                array[i] = '\n';
                for (int j = i + 1; j < N; ++j) {
                    if (array[j] == start) {
                        array[j] = '\n';
                        endIndex = j;
                    }
                }
                if (i != endIndex) {
                    line[i] = 1;
                    line[endIndex] = -1;
                }
            }
        }

        int max = 0;
        int current = 0;
        for (int i = 0; i < N; ++i) {
            current += line[i];
            if (max < current) {
                max = current;
            }
        }

        System.out.println(max);
    }
}

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

int main() {
	int N; cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		char c; cin >> c;
		v[i] = c - '0';
	}
	int res = 0;
	for (int pin = 0; pin < 1000; pin++) {
		vector<int> p(4, 10);
		p[0] = pin / 100;
		p[1] = pin / 10 % 10;
		p[2] = pin % 10;
		int i = 0;
		for (int j = 0; j < N; j++) {
			if (v[j] == p[i]) i++;
		}
		if (i == 3) res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;

int main() {
	long long a, b, x, m, n, ans;
	cin >> a >> b >> x;
	if (a%x == 0) {
		m = a;
	} else if (((a/x) + 1)*x > b){
		m = -1;
	} else {
		m = ((a / x) + 1)*x;
	}
	if (m >= 0) {
		n = (b / x)*x;
		ans = (n - m)/x + 1;
	} else {
		ans = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
'''
Created on 2020/08/22

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=pin()[:-1]
  N=list(map(int,N))
  if sum(N)%9==0:
    print("Yes")
  else:
    print("No")
  return 
main()

Measured memory_bytes: 10772
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int p[] = new int[n];

		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		Arrays.sort(p);

		int ans = 0;
		for(int i= 0; i < k; i++) {
			ans += p[i];
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 39032
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
a = int(n**0.5)
print(a**2)












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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> X(M);
  rep(i,M) cin>>X[i];
  if(N>=M){
    cout<<0<<endl;
    return 0;
  }
  sort(X.begin(),X.end());
  vector<int> L(M-1);
  rep(i,M-1) L[i]=X[i+1]-X[i];//LはXの間の距離
  //Lの大きい順にN-1回Lを消し、残りを足し合わせたものが答え
  //すなわち、sortしたLをL[0]~L[M-N-1]たせばよい
  sort(L.begin(),L.end());
  int ans=0;
  rep(i,M-N) ans += L[i];
  cout<<ans<<endl;
  return 0;
}


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

@OptIn(ExperimentalStdlibApi::class)
fun abc171a() {
    val a = readLine()!!

    val answer = if (a[0] in 'a'..'z') 'a' else 'A'

    println(answer)
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000000 + 7
#define PI 3.14159265359

const long long INF = 100000;
typedef pair<int,int> P;
typedef long long ll;

using Graph = vector<vector<int>>;

//全点間距離を求める
vector<int> d(2000 + 5, -1);// d[i]は始点からiまでの距離
vector<int> d2(2000 + 5, -1);
vector<int> num(2000 + 5);// num[i]には頂点間距離がiの頂点の組の個数が入る

void bfs(const Graph &G, int v) {
	d[v] = 0;
	queue<int> que;
	que.push(v);

	while (que.size()) {
		int iTop = que.front();
		que.pop();

		for (auto next : G[iTop]) {
			if (d[next] != -1) continue;// 既に訪れている
			d[next] = d[iTop] + 1;
			que.push(next);
		}
	}
}

int main() {
    int N, X, Y;
	cin >> N >> X >> Y;

	Graph G(N + 1);
	G[1].push_back(2);
	G[N].push_back(N - 1);
  	G[X].push_back(Y);
	G[Y].push_back(X);

	for (int i = 2; i<= N - 1; i++) {
		G[i].push_back(i - 1);
		G[i].push_back(i + 1);
	}
    /*for (int i = 0; i < G[2].size(); i++) {
		cout << G[2][i] << endl;
	}*/
  
	for (int v = 1; v <= N; v++) {
		bfs(G, v);
		for (int i = 1; i <= N; i++) {
			if (d[i] >= 1) num[d[i]]++;
		}
		d = d2;
	}

	for (int k = 1; k <= N -1; k++) {
		cout << num[k] / 2 << endl;
	}
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int x, y;
int gcd(int n, int m) {
	if (n == 0) return m;
	else return gcd(m%n,n);
}


int main()
{
	cin >> x >> y;
	cout << gcd(x, y) << endl;
}

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

template<class I, class BiOp = I (*) (I, I)>
class SegTree {
private:
  int n;
  std::vector<I> dat, lazy;
  BiOp op;
  I e;

public:
  SegTree(int n_, BiOp op, I e) : op(op), e(e) {
    n = 1;
    while (n < n_) n *= 2;
    dat.resize(2 * n - 1, e);
    lazy.resize(2 * n - 1, -1);
  }

  void eval(int k, int l, int r) {
    if (lazy[k] == -1) return;
    // cerr << "eval: k = " << k << ", l = " << l << ", r = " << r << endl;
    dat[k] = lazy[k];
    if (k < n - 1) {
      lazy[2 * k + 1] = lazy[k];
      lazy[2 * k + 2] = lazy[k];
    }
    lazy[k] = -1;
  }

  void update(int a, int b, I x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    // cerr << "update: a = " << a << ", b = " << b << ", x = " << x << ", k = " << k << ", l = " << l << ", r = " << r << endl;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      // cerr << "hey!" << endl;
      lazy[k] = x;
      eval(k, l, r);
    }
    else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }

  I query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    // cerr << "query: a = " << a << ", b = " << b << ", k = " << k << ", l = " << l << ", r = " << r << endl;
    eval(k, l, r);
    if (b <= l || r <= a) return e;
    if (a <= l && r <= b) return dat[k];
    I vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    I vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return op(vl, vr);
  }

  void print() {
    int j = 2;
    for (int i = 0; i < 2 * n - 1; i++) {
      cerr << "(" << dat[i] << ", " << lazy[i] << ")";
      if (i == j - 2) {
        cerr << endl;
        j *= 2;
      }
      else {
        cerr << " ";
      }
    }
  }
};

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

  int n, q;
  cin >> n >> q;
  SegTree<int> seg(n, [](int a, int b){return min(a, b);}, INT_MAX);

  // seg.print();

  rep(i, q) {
    // cerr << "i = " << i << endl;

    int t;
    cin >> t;
    if (t == 0) {
      int a, b, x;
      cin >> a >> b >> x;
      seg.update(a, b + 1, x);
    }
    else {
      int a, b;
      cin >> a >> b;
      cout << seg.query(a, b + 1) << endl;
    }

    // seg.print();
    // cerr << endl;
  }

  return 0;
}



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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define mul(a, b) (((a) % MOD * (b) % MOD) % MOD)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define insert ins
#define ers erase
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a)                   t a; cin >> a;
#define rd2(t, a, b)                rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c)             rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d)          rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e)       rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f)    rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)             t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
    #define deb(v) cout << endl << #v << ": " << v << endl
    #define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
    #define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
    #define dbl cout << "-------------------------------" << endl
#else
    #define deb(v)
    #define db1(v)
    #define db2(v)
    #define dbl
#endif

const int msz = 1e6;
bool primes[msz + 1];
vi pr;
void sieve() {
    memset(primes, true, sizeof(primes));
    for(ll p = 2; p * p <= msz; p++) {
        if(primes[p] == true) {
            for(ll i = p * p; i <= msz; i += p)
                primes[i] = false;
        }
    }
    FOR(i, 2, msz) {
        if(primes[i] == true)
            pr.pb(i);
    }
}

int main() {
    
    fastio;

    rd1(ll, n);

    sieve();
    FOR(i, 0, pr.size()) {
        if(pr[i] >= n) {
            cout << pr[i];
            break;
            return 0;
        }
    }

    return 0;
}

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

using namespace std;

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

	vector<int> h;
	int max = -1;
	int result = 0;
	for (int i = 0; i < n; i++) {
		cin >> temp;

		if (max <= temp) {
			result++;
		}

		if (max < temp) {
			max = temp;
		}
	}

	cout << result;
}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        a: i32,
        b: i32,
    }
    let max = std::cmp::max;
    let ans = max(a + b, max(a - b, a * b));
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int[] a =nextInts();

		boolean flg=true;
		HashMap<Integer,Integer> map = new HashMap<>();
		for(int i=0;i<N;i++){
			map.put(a[i], map.getOrDefault(a[i], 0)+1);
		}

		Iterator<Integer> itor = map.keySet().iterator();
		if(map.size()==1){

			if(itor.next()==0){
				System.out.println("Yes");
				return;
			}
		}else if(map.size()==2){
			int[] key =new int[]{itor.next(),itor.next()};
			Arrays.sort(key);
			if(key[0]==0&&map.get(key[0])==N/3){
				System.out.println("Yes");
				return;

			}
		}else if(map.size()==3){
			int[] key =new int[]{itor.next(),itor.next(),itor.next()};
			if((key[0]^key[1]^key[2])==0&&map.get(key[0])==N/3&&map.get(key[1])==N/3){
				System.out.println("Yes");
				return;
			}
		}

		System.out.println("No");


	}

	public static long[] disassemblyAlph(String s) {
		long[] alph = new long['z' - 'a' + 1];
		Arrays.fill(alph, 0);
		for (int i = 0; i < s.length(); i++) {
			alph[s.charAt(i) - 'a']++;
		}
		return alph;
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

Measured memory_bytes: 46088
// https://atcoder.jp/contests/abc077/tasks/abc077_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  string a, b, c = "", d = "", r;

  cin >> a >> b;

  c += b[2];
  c += b[1];
  c += b[0];
  d += a[2];
  d += a[1];
  d += a[0];

  r = a == c && b == d ? "YES" : "NO";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256