akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, k;

int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> k;
	int ans = 0;
	for(int i=0; i<n; i++) {
		int x; cin >> x;
		ans += (x>=k);
	}
	cout <<ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int N,Q;
string S;
vector<set<int>> abc(26);

void add(int i, char c){//type1
	if(S[i] == c) return;
	abc[S[i]-'a'].erase(i);
	S[i] = c;
	abc[S[i]-'a'].insert(i);
}

void out(int l, int r){//type2
	int ans = 0;
	// for(auto s:abc){
	// 	if(s.size() <= 0) continue;
	// 	auto it = s.lower_bound(l);
	// 	if(it==s.end()) continue;
	// 	if(*it<=r) ans++;
	// }
	// cout<<ans<<endl;

	rp(i,0,26){
		if(abc[i].size() <= 0) continue;
		auto it = abc[i].lower_bound(l);
		if(it  == abc[i].end()) continue;
		if(*it <= r) ans++;
	}
	printf("%d\n",ans);
}

int main(){
	cin>>N>>S>>Q;
	rp(i,0,N) abc[S[i]-'a'].insert(i);

	rp(i,0,Q){
		int t,a;
		cin>>t;
		if(t-1){//type2
			int b;
			cin>>a>>b;
			out(a-1,b-1);
		}
		else{//type1
			char b;
			cin>>a>>b;
			add(a-1,b);
		}
	}
}


Measured memory_bytes: 24196
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int a;
    string s;
    input(a, s);

    print(a >= 3200 ? s : "red");

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
#include<chrono>
#include <fstream>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
/*ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}*/
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x);

		y = y >> 1;
		x = (x * x);
	}
	return res;
}


/*ll modInverse(ll n, ll p)
{
	return power(n, p - 2, p);
}*/

ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}
ll sum_digit(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
ll gp(ll r, ll n)
{
	return (pow(r,n)-1)/(r-1);
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s,t;
	cin>>s>>t;
	ll ans=INF;
	f(i,0,s.size()-t.size()+1)
	{
		ll temp=0;
		f(j,0,t.size())
		{
			if(s[i+j]!=t[j])
			{
				temp+=1;
			}
		}
		ans=min(ans,temp);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3684
#include<stdio.h>
int main(void)
{
 	int i,j,n,a[1000],r;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(a[i]>a[j]){
				r=a[i];
				a[i]=a[j];
				a[j]=r;
			}
		}
	}
	printf("%d\n",a[n-1]-a[0]);
	return 0;
}

Measured memory_bytes: 128
from collections import deque
H, W = map(int, input().split())
ch, cw = map(int, input().split())
gh, gw = map(int, input().split())
s = [input() for _ in range(H)]

res = [[10**8 for _ in range(W)] for _ in range(H)]
res[ch-1][cw-1] = 0
deq = deque([(ch-1, cw-1)])

DH = [1, 0, -1, 0]
DW = [0, 1, 0, -1]

def inc(h, w):
	if 0 <= h < H and 0 <= w < W:
		return True
	else:
		return False

while deq:
	h, w = deq.pop()
	for dh, dw in zip(DH, DW):
		if inc(h+dh, w+dw) == False or s[h+dh][w+dw] == "#":
			continue
		if res[h+dh][w+dw] > res[h][w]:
			res[h+dh][w+dw] = res[h][w]
			deq.append((h+dh, w+dw))
	for dh in range(-2, 3):
		for dw in range(-2, 3):
			if inc(h+dh, w+dw) == False or s[h+dh][w+dw] == "#":
				continue
			if res[h+dh][w+dw] > res[h][w]+1:
				res[h+dh][w+dw] = res[h][w]+1
				deq.appendleft((h+dh, w+dw))

if res[gh-1][gw-1] > 10**7:
	print(-1)
else:
	print(res[gh-1][gw-1])

Measured memory_bytes: 89604
let cnt = ref 0
let g = ref []

let print_list l =
  List.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) l;
  print_newline ()

let print_array a = Array.iter (fun n -> Printf.printf "%d\n" n) a

let insertion_sort a n g =
  let rec insert j v =
    if j < 0 || a.(j) <= v then a.(j + g) <- v
    else (a.(j + g) <- a.(j); incr cnt; insert (j - g) v)
  in
  let rec doit i =
    if i >= n then ()
    else (insert (i - g) a.(i); doit (i + 1))
  in
  doit g

let generate_g n =
  let rec doit i lst =
    if i > n then lst
    else doit (3*i + 1) (i :: lst)
  in
  doit 1 []

let shell_sort a n =
  cnt := 0;
  g := generate_g n;
  let rec doit = function
    | [] -> ()
    | hd :: tl -> (insertion_sort a n hd; doit tl)
  in
  doit !g

let () =
  let n = read_int () in
  let a = Array.make n 0 in
  let rec doit i =
    if i >= n then ()
    else (a.(i) <- read_int (); doit (i + 1))
  in
  doit 0;
  shell_sort a n;
  Printf.printf "%d\n" (List.length !g);
  print_list !g;
  Printf.printf "%d\n" !cnt;
  print_array a

Measured memory_bytes: 12484
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, K;
  scanf("%d %d", &N, &K);

  // count for each b
  long ans = 0;
  for (int b = K + 1; b <= N; b++) {
    const int num_cycle = N / b;
    const int cnt_full = num_cycle * (b - K);
    const int cnt_part = max(N - num_cycle * b - max(K - 1, 0), 0);
    ans += cnt_full + cnt_part;
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    string s;
    cin >> s;
    vector<int> n(s.size());
    vector<int> rightEnd(s.size(),0);
    for(int i=0; i!= s.size(); i++) n.at(i) = s.at(i) - '0';

    for(int i=0; i<s.size(); ++i){
        int tot = 0;
        for(int j=i; j<s.size(); ++j){
            tot = (tot*10+ n.at(j)) % 2019;
            if(tot == 0){
                if(j<s.size()-1) rightEnd.at(j+1) = rightEnd.at(i)+1;
                else rightEnd.at(0) += rightEnd.at(i) +1;
                break;
            }
        }
    }   
    int out = 0;
    for(const auto r: rightEnd) out +=r;

    cout << out << endl;

    return 0;
}

Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b,c;
cin>>a>>b>>c;
string ans;
if(a*b*c==5*5*7) ans="YES";
else ans="NO";
cout<<ans<<endl;

//system("pause");
return 0;
}

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


int main() {

	int64_t N, K;
	cin >> N >> K;

	int64_t x =abs(N - K*(N/K));
	int64_t y = abs(N - K * (N / K + 1));
	int64_t ans = min(x, y);
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int n, idx = 0;
    int arr[250];
    scanf("%d", &n);
    while(n--){
        scanf("%d", &arr[idx]);
        idx++;
    }
    for(int i = 1; i <= idx; i++){
        printf("node %d: ", i);
        printf("key = %d, ", arr[i-1]);
        if(i != 1){
            printf("parent key = %d, ", arr[i/2-1]);
        }
        if((2*i) <= idx){
            printf("left key = %d, ", arr[2*i-1]);
        }
        if((2*i+1) <= idx){
            printf("right key = %d, ", arr[2*i+1-1]);
        }
        printf("\n");
    }
}



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

int main()
{
    ll n,w;
    cin>>n>>w;
    ll a[n][2];
    for(int i=0;i<n;i++)
        cin>>a[i][0]>>a[i][1];
    ll dp[100005];
    //dp[0]=0;
    for(int i=0;i<100005;i++)
        dp[i]=10000000005;
dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=100000;j>=a[i][1];j--)
        {
            if(j-a[i][1]>=0)
                dp[j]=min(dp[j],dp[j-a[i][1]]+a[i][0]);
        }
    }

    for(int j=100000;j>=0;j--)
    {
        if(dp[j]<=w)
        {
            cout<<j<<endl;
            break;
        }

    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll h, w, n;
  cin >> h >> w >> n;
  
  cout << (n + max(h,w)-1) / max(h,w) << endl;

  return 0;
}


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

int a[3][3];
int b[10];
bool appear[3][3];

int main() {
  rep(i,3){
    rep(j,3){
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  rep(i,n) cin >> b[i];
  rep(i,3){
    rep(j,3){
      appear[i][j] = false;
      rep(k,n){
        if(a[i][j] == b[k]) appear[i][j] = true;
      }
    }
  }
  string ans = "No";
  rep(i,3) {
    if(appear[i][0] && appear[i][1] && appear[i][2]) ans = "Yes";
  }
  rep(i,3) {
    if(appear[0][i] && appear[1][i] && appear[2][i]) ans = "Yes";
  }
  if(appear[0][0] && appear[1][1] && appear[2][2]) ans = "Yes";
  if(appear[0][2] && appear[1][1] && appear[2][0]) ans = "Yes";
  cout << ans << endl;
  return 0;
}


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

int main(){
    int n; cin >> n;
    vector<ll> a(100000);
    int no_cnt=0;
    int two_cnt=0;
    int four_cnt=0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i]%4!=0 && a[i]%2!=0) no_cnt++;
        if(a[i]%4!=0 && a[i]%2==0) two_cnt++;
        if(a[i]%4==0) four_cnt++; 
    }
    if(no_cnt <= four_cnt || (no_cnt<=four_cnt+1 && n == no_cnt+four_cnt)){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    string s;
    for (int i = 0; i < 3; i++) {
        cin >> s;
        cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        
        int N = scanner.nextInt();
        
        if(N%1000==0){
            System.out.println(N%1000);
        }else{
            System.out.println(1000-N%1000);    
        }
    }
}


Measured memory_bytes: 35852
from math import radians, cos, sqrt
A, B, H, M = map(int, input().split())

angle_hour = 360 * ((60 * H + M) / (60 * 12))
angle_minute = 360 * (M / 60)

angle_between = abs(angle_hour - angle_minute)
angle_between = min(angle_between, 360 - angle_between)
angle_between = radians(angle_between)

ans = A ** 2 + B ** 2 - 2 * A * B * cos(angle_between)
print(sqrt(ans))


Measured memory_bytes: 9240
using System;
using static System.Console;
using System.Collections.Generic;
using System.Collections;

namespace Grobal
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] str = ReadLine().Split(' ');
			int x = int.Parse(str[0]);
			int a = int.Parse(str[1]);

			if (x < a) WriteLine(0);
			if (x >= a) WriteLine(10);
		}
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int n,k,s;
int main()
{
	scanf("%d%d%d",&n,&k,&s);
	for (int i=1;i<=k;i++) printf("%d ",s);
	for (int i=k+1;i<=n;i++) printf("%d ",(s==1e9)?s-1:s+1);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int n,k;
vector<int> vec;
int dp[100007];
int solve(int index){

    if(index==n-1){
        return 0;
    }
    if(dp[index]!=-1){
        return dp[index];
    }
    
    int ret1 = INT_MAX;
    int ret2 = INT_MAX;
  
  	for(int i=1;i<=k;i++){
  		if(index+i<n)
  		{
    	dp[index] = abs(vec[index] - vec[index+i]) + solve(index+i);
  		}
      	ret1 = min(ret1,dp[index]);
    }

    return dp[index]=ret1;
}

int main(){
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    int num;
    for(int i = 0 ; i<n ; i++){
        cin>>num;
        vec.push_back(num);
    }
    cout<<solve(0)<<endl;
    return 0;
}


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

int main() {
  int N, M; cin >> N >> M;
  vector<int> a(M);
  for (int i = 0; i < M; i++) cin >> a.at(i);
  int hogehoge = 1000000007;
  int j = 0;
  vector<int> f(N+1);
  f.at(0) = 1;
  if (j < M) {
    if (a.at(j) == 1) {
      f.at(1) = 0;
      j++;
    }
    else f.at(1) = 1;
  }
  else f.at(1) = 1;
  for (int i = 2; i < N+1; i++) {
    if (j < M) {
      if (i == a.at(j)) {
        j++;
        f.at(i) = 0;
      }
      else f.at(i) = (f.at(i-1) + f.at(i-2)) % hogehoge;
    }
    else f.at(i) = (f.at(i-1) + f.at(i-2)) % hogehoge;
  }
  // for (int i = 0; i < N+1; i++) cout << f.at(i) << endl;
  cout << f.at(N) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=200005;
int n,A[maxn],f[maxn],B[maxn],mx;
int inline read(){
	int x=0,f=1,ch=getchar();
	while (ch<48||ch>57) f=ch=='-'?-f:f,ch=getchar();
	while (ch>47&&ch<58) x=x*10+ch-48,ch=getchar();
	return x*f;
}
int main()
{
	n=read();for(int i=1;i<=n;i++)A[i]=read(),B[A[i]]=i;
	for(int i=1;i<=n;i++)
	if(B[i]>B[i-1]) f[i]=f[i-1]+1;else f[i]=1;
	for(int i=1;i<=n;i++)mx=max(mx,f[i]);
	printf("%d",n-mx);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  int x=7%k;
  for(int i=1;i<=k;i++){
    if(x==0){
      cout<<i<<endl;
      return 0;
    }
    x=(10*x+7)%k;
  }
  cout<<-1<<endl;
  return 0;
}

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

int main()
{
	int N,Y,x,y,z;
	
	cin>>N>>Y;
		
    for(x=0; x<=Y/10000; x++)
       for(y=0; y<=Y/5000; y++)
       {
       	  z=N-x-y;
       	  if(z>=0 && x*10000+y*5000+z*1000==Y)
       	  {
       	  	 cout<<x<<" "<<y<<" "<<z;
       	  	 return 0;
       	  }
       }
       
    cout<<"-1 -1 -1";
    return 0;
}

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

typedef long long ll;

const int UF_SZ_MX = 1e5+10;
int uf[UF_SZ_MX];
int rnk[UF_SZ_MX];
int diff[UF_SZ_MX];

void uf_init() {
	for(int i = 0; i < UF_SZ_MX; i++) {
		uf[i] = i;
		rnk[i] = 0;
		diff[i] = 0;
	}
}

int uf_find(int n) {
	if(n == uf[n])
		return n;
	return uf_find(uf[n]);
}

bool uf_same(int a, int b) {
	int pa, pb;
	pa = uf_find(a);
	pb = uf_find(b);
	if(pa == pb)
		return true;
	return false;
}

ll uf_cost(int n) {
	if(uf[n] == n)
		return 0ll;
	return (ll)diff[n] + uf_cost(uf[n]);
}

void uf_marge(int a, int b, int d) {
	int pa, pb;
	int ca, cb;
	pa = uf_find(a);
	pb = uf_find(b);
	ca = uf_cost(a);
	cb = uf_cost(b);
	if(pa == pb)
		return;
	if(rnk[pa] > rnk[pb]) {
		uf[pb] = pa;
		diff[pb] = ca - cb + d;
	}
	else {
		uf[pa] = pb;
		diff[pa] = cb - ca -d;
		if(rnk[pa] == rnk[pb])
			rnk[pb]++;
	}
}

int main() {
	int N, M;
	while(cin >> N >> M, N || M) {
		uf_init();
		for(int i = 0; i < M; i++) {
			string s;
			cin >> s;

			if(s == "!") {
				int a, b, w;
				cin >> a >> b >> w;
				if(!uf_same(a,b)) {
					uf_marge(a,b,w);
				}
			}
			else {
				int a, b;
				cin >> a >> b;
				if(uf_same(a,b)) {
					cout << uf_cost(b) - uf_cost(a) << endl;
				}
				else {
					cout << "UNKNOWN" << endl;
				}
			}
		}
	}
}

Measured memory_bytes: 2376
n, m = map(int, input().split())

s = [0] * m
c = [0] * m

for i in range(m):
    s[i], c[i] = map(int, input().split())
    s[i] -= 1
    
num = [10] * n

flag = False
for i in range(m):
    if num[s[i]] != 10 and num[s[i]] != c[i]:
        #print("dif")
        flag = True
    else:
        num[s[i]] = c[i]
        
if 1 < n and num[0] == 0:
    #print("head is 0")
    flag = True
elif 1 < n and num[0] == 10:
    num[0] = 1

for i in range(n):
    if num[i] == 10:
        num[i] = 0

if flag:
    print(-1)
else:
    print(''.join([str(n) for n in num]))

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
		int t = 1;
		t = Integer.parseInt(reader.readLine());
		int i = 1;
		int rem = 7%t;
		int rem1 = 1%t;
		HashSet<Integer> hs = new HashSet<>();
		while(true){
			if(rem==0){
				System.out.println(i);
				return;
			}
			else if(hs.contains(rem)){
				System.out.println(-1);
				return;
			}
			else{
				hs.add(rem);
				rem1 = (10*rem1)%t;
				rem = (rem + (7*(rem1))%t)%t;
				i++;
			}
		}	
	}
}

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

using namespace std;

int main() {
    // freopen("in.txt", "rt", stdin);
    // freopen("out.txt", "w", stdout);
    long long a,b,c;
    scanf("%lld %lld %lld",&a,&b,&c);
    if(c<=a){
        a-=c;
    }
    else {
        c-=a;
        a=0;
        b-=c;
        b=max(b,0ll);
    }
    printf("%lld %lld",a,b);
}


Measured memory_bytes: 256
import java.util.Scanner;


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

	    for (int i = 1; i <= 10; i++) {
	    	z =  x * z - y;
	    	System.out.println(z);
	    }
	}
}

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

const int N = 205;
const int INF = (int) 1e9 + 9;

struct TPoint {
	int x, y;
	TPoint() {}
	TPoint(int x, int y) : x(x), y(y) {}
	bool operator < (const TPoint &op) {
		return x == op.x ? y < op.y : x < op.x;
	}
} p[N];

int n;

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= 2 * n; i++) cin >> p[i].x >> p[i].y;
	sort(p + 1, p + 1 + n);
	sort(p + 1 + n, p + 1 + n + n);
	multiset <pair <int, int> > myset;
	multiset <pair <int, int> > :: iterator it;
	int pos = 1, ans = 0;
	for (int i = n + 1; i <= 2 * n; i++) {
		while (pos <= n && p[pos].x <= p[i].x) {
			myset.insert(make_pair(p[pos].y, p[pos].x));
			pos++;
		}
		it = myset.upper_bound(make_pair(p[i].y, INF));
		if (it == myset.begin()) continue;
		it--;
		if (it -> first <= p[i].y) {
			ans++;
			myset.erase(it);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
	ios::sync_with_stdio(0); cin.tie(0);
	
    int n; cin >> n;
    int mx = 0, ans = 0;
    int s; cin >> s;
    --n;
    while(n--){
		int x; cin >> x;
		if(s >= x) ++ans;
        else{
            mx = max(ans, mx);
            ans = 0;
        }
        s = x;
    }
 
    mx = max(mx, ans);
 
    cout << mx;
	
	
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int get(long long n)
{
	int ans=0;
	while(n>0)
	{
		ans++;
		n/=10;
	}
	return ans;
}
int main() 
{
	long long n;
	cin>>n;
	for(long long i=sqrt(n);i>=1;i--)
	{
		if(n%i==0)
		{
			cout<<max(get(n/i),get(i))<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long DP[3000*3000];
long A[3000];
void Calc(){
	int N = rei();
	for(int i=0;i<N;i++){
		A[i] = rel();
	}
	for(int i=0;i<N;i++){
		DP[i*3000+i] = A[i];
	}
	for(int i=1;i<N;i++){
		for(int j=0;j+i<N;j++){
			DP[j*3000+(j+i)] = max(A[j]-DP[(j+1)*3000+j+i],A[j+i]-DP[j*3000+j+i-1]);
		}
	}
	cout << DP[N-1] << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 70016
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-7;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}


struct edge{
	int to;
	int limitSpeed;
	int dist;
};
vector<edge> G[101];
void add_edge(int x,int y,int d,int c){
	edge e;
	int from=x;
	int to=y;
	e.to=y;
	e.limitSpeed=c;
	e.dist=d;
	G[from].push_back(e);
	e.to=x;
	G[to].push_back(e);
}
const double INF=1e+10;

typedef pair<double,int> pdi;
typedef pair<pdi,pii> Sit;

double d[51][51][51];
double dijkstra(int s,int g,int n){
	for(int i=0;i<51;i++)
		for(int j=0;j<51;j++)
			for(int k=0;k<51;k++)
				d[i][j][k]=INF;
	priority_queue<Sit,vector<Sit>,greater<Sit> > pq;
	pq.push(make_pair(pdi(0,0),pii(s,1)));
	d[0][s][1]=0;
	while(pq.size()){
		Sit p=pq.top();pq.pop();
		double ccost=p.first.first;
		int prvNode=p.first.second;
		int curNode=p.second.first;
		int curSpeed=p.second.second;
		if(!EQ(d[prvNode][curNode][curSpeed],ccost)&&d[prvNode][curNode][curSpeed]<ccost)continue;
		for(int j=0;j<G[curNode].size();j++){
			edge &e=G[curNode][j];
			int toNode=e.to;
			if(toNode==prvNode)
				continue;
			int limitSpeed=e.limitSpeed;
			int dist=e.dist;
			for(int i=-1;i<=1;i++){
				if(prvNode==0&&i!=0)continue;
				int nxtSpeed=curSpeed+i;
				if(nxtSpeed==0||nxtSpeed>limitSpeed)continue;
				double ncost=ccost+1.0*dist/nxtSpeed;
				if(!EQ(ncost,d[curNode][toNode][nxtSpeed])&&ncost<d[curNode][toNode][nxtSpeed]){
					d[curNode][toNode][nxtSpeed]=ncost;
					pq.push(make_pair(pdi(ncost,curNode),pii(toNode,nxtSpeed)));
				}
			}
		}
	}
	double res=INF;
	for(int i=1;i<=n;i++)
		res=min(res,d[i][g][1]);
	return res;
}

void solve(){
	int n,m,s,g;
	while(cin>>n>>m&&(n|m)){
		cin>>s>>g;
		for(int i=0;i<m;i++){
			int x,y,d,c;
			cin>>x>>y>>d>>c;
			add_edge(x,y,d,c);
		}
		double res=dijkstra(s,g,n);
		if(EQ(res,INF))cout<<"unreachable"<<endl;
		else printf("%.10f\n",res);
		for(int i=0;i<101;i++)G[i].clear();
	}
}

int main(){
	solve();
	return 0;
}

Measured memory_bytes: 2528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e8;

struct edge{ll from,to,cost;bool need;};
ll d[100][100];

void warshall_floid(){
    for(int k = 0;k < 100;k ++){
        for(int i = 0;i < 100;i ++){
            for(int j = 0;j < 100;j ++){
                d[i][j] = min(d[i][k]+d[k][j],d[i][j]);
            }
        }
    }
}

int main(){
    int n,m,ans=0;
    cin >> n >> m;
    fill(d[0],d[100],INF);
    vector<edge> G;
    for(int i = 0;i < m;i ++){
        ll a,b,c;
        cin >> a >> b >> c;
        a --;b --;
        d[a][b] = c;
        d[b][a] = c;
        G.push_back({a,b,c,0});
    }
    for(int i = 0;i < n;i ++){
        d[i][i] = 0;
    }
    warshall_floid();
    for(int i = 0;i < n;i ++){
        for(int j = 0;j < n;j ++){
            for(int k = 0;k < m;k ++){
                if(d[i][G[k].from]+G[k].cost+d[G[k].to][j]==d[i][j]) G[k].need=1;
            }
        }
    }
    for(int i = 0;i < m;i ++){
        if(!G[i].need) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
n,m=map(int, input().split())
sc = [list(map(int, input().split())) for x in range(m)]

ans = ['0']*(n+1)
flg = 0
for i in range(m):
    if ans[sc[i][0]] == '0':
        if sc[i][1] != 0:
            ans[sc[i][0]] = str(sc[i][1])
            if sc[i][0] == 1:
                flg = 1
        elif sc[i][0] == 1 and sc[i][1] == 0 and flg == 0:
            ans[sc[i][0]] = str(sc[i][1])
            flg = 1
        else:
            continue
    elif ans[sc[i][0]] == str(sc[i][1]):
        continue
    else:
        print(-1)
        exit()
if flg == 0 and len(ans) != 2:
    ans[1] = '1'
    print(int(''.join(ans)))
elif ans[1] == '0' and len(ans) != 2:
    print(-1)
else:
    print(int(''.join(ans)))


Measured memory_bytes: 3064
#include<stdio.h>
#include<vector>
#include<iostream>
#include <algorithm>
using namespace std;
 
int main() {
 
  int N, K;
  cin >> N >> K;
  vector<int> price(N);
  for(int i=0;i<N;i++) {
    cin >> price[i];
  }
  sort(price.begin(), price.end());
  int sum = 0;
  for(int i=0;i<K;i++) {sum+=price[i];}
  cout << sum << endl;
    
 
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
using ll = long long;
using P = pair<int,int>;

ll n,m,k,h,w,a,b,c;
string s,t;

int main() {
  cin >> a >> b >> c;
  ll d=c-a-b;
  cout << (4*a*b<d*d && d>0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repv(i,a,b) for(ll i=b-1;i>=a;i--)
#define MAXN 300005
#define endl "\n"

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;}

string s;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s;
    for(int i=0;i<3;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

int partition(int A[], int p, int r)
{
  int x,i,j,ch1,ch2;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++){
    if(A[j] <= x){
      i = i+1;
      ch1 = A[i];
      A[i] = A[j];
      A[j] = ch1;
    }
  }
      ch2 = A[i+1];
      A[i+1] = A[r];
      A[r] = ch2;
      return i+1; 
}
int main()
{
  int i,n,A[N],p=0,r,res;

  scanf("%d",&n);
  r=n-1;
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  res = partition(A,p,r);
  for(i=0; i<n; i++){
    
    if(i==res)printf("[");
    printf("%d",A[i]);    
    if(i==res)printf("]");
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
typedef vector<int > vecint;
typedef vector<string > vecstr;
int main()
{
  int n;
  cin >> n;
  map<ll, int> m;
  ll tmp;
  REP(i,n){
    cin >> tmp;
    m[tmp] ++;
  }
  ll rec1, rec2;
  rec1 = rec2 = 0;
  ll sq = 0;
  for(auto itr = m.begin();itr != m.end();itr++){
    if(itr->second >= 2){
      rec2 = rec1;
      rec1 = itr->first;
      // cout << rec1 << " " << rec2 << endl;
    }
    if(itr->second >= 4){
      sq = itr->first;
    }
  }
  cout << max(rec1*rec2,sq*sq) << endl;
}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b;

		a = sc.nextInt();
		b = sc.nextInt();

		if (a % 2 != 0 && b % 2 != 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}


Measured memory_bytes: 20948
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int lli;
typedef vector<vector<lli> > vlli;
lli N, K;
lli MOD = 1e9 +7;
lli dfs(vector<int> &A, int i, int N, vector<int> &M){
	if(i>=N) return INT_MAX;
	if(i==N-1) return 0;
	if(M[i]!=-1) return M[i];
	lli x = dfs(A, i+1, N, M);
	lli y = dfs(A, i+2, N, M);
	if(x==INT_MAX and y==INT_MAX)
		return M[i]=INT_MAX;
	if(x!=INT_MAX and y!=INT_MAX)
		return M[i]=min(x+abs(A[i+1]-A[i]), y+abs(A[i+2]-A[i]));
	if(x!=INT_MAX and y==INT_MAX)
		return M[i]=(x+abs(A[i+1]-A[i]));
	if(x==INT_MAX and y!=INT_MAX)
		return M[i]=(y+abs(A[i+2]-A[i]));
}
int main() 
{ 
    cin>>N;
    vector<int> A(N+5, 0);
    vector<int> M(N+5, -1);
    
    for (int i = 0; i < N; ++i)
    {
    	cin>>A[i];
    }
    cout<<dfs(A, 0, N, M);
    return 0; 
}

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

using namespace std;

int main() {
	int A, B, C, D, E;
	int N = 5;
	cin >> A >> B >> C >> D >> E;
	vector<int>Time{ A,B,C,D,E };
	vector<int>nextTime(N);
	for (int i = 0; i < N; i++)
	{
		if (Time[i] % 10 == 0) {
			nextTime[i] = Time[i];
		}
		else {
			nextTime[i] = Time[i] - Time[i] % 10 + 10;
		}
	}
	int ans = 1e9;
	for (int i = 0; i < N; i++)
	{
		int sum = 0;
		for (int j = 0; j < N; j++)
		{
			if (i == j) {
				sum += Time[j];
			}
			else {
				sum += nextTime[j];
			}
		}
		ans = min(ans, sum);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
d, g = map(int, input().split())
pc = []
a = 9999999
for _ in range(d):
    _p, _c = map(int, input().split())
    pc.append([_p, _c])
for i in range(2 ** d):
    tmp = []
    ans = 0
    n = 0
    for j in range(d):
        if ((i >> j) & 1):
            tmp.append(j)
    for j in tmp:
        ans += (j+1)*100*pc[j][0] + pc[j][1]
        n += pc[j][0]
    if ans >= g:
        if n < a:
            a = n
    else:
        for j in range(len(pc)):
            if not j in tmp:
                plus = 0
                for k in range(pc[j][0]):
                    plus += (j+1)*100
                    if ans + plus >= g:
                        if n + k + 1 < a:
                            ans += plus
                            n += k+1
                            a = n
                            break
print(a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.size(); ++i)
  {
    if (S == T)
    {
      cout << "Yes" << endl;
      return 0;
    }
    S = S.back() + S.substr(0, S.size() - 1);
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int A, B, C, D;

int main(void){
	//IO("test.in", "test.out");
	scanf("%d%d%d%d", &A, &B, &C, &D);
	if((A <= C && B <= C) || (A >= D)) printf("0\n");
	else if(A == C && B == D) printf("%d\n", B - A);
	else if(A <= C && B >= D) printf("%d\n", D - C);
	else if(A >= C && B <= D) printf("%d\n", B - A);
	else if(A < C && B < D) printf("%d\n", B - C);
	else if(A > C && B > D) printf("%d\n", D - A);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  int N = s.length();
  reverse(all(s));
  int carry = 0;
  s.push_back('0');
  s.push_back('0');
  int ans = 0;
  rep(i,N+1){
    int x = s[i] - '0';
    x += carry;
    if(x<=4){
      ans += x;
      carry = 0;
    }else if(x==5){
      if((int)(s[i+1]-'0')<5){
        ans += x;
        carry = 0;
      }else{
        ans += 10-x;
        carry = 1;
      }
    }else{
      ans += 10-x;
      carry = 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1948
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define MOD 1000000007
#define PI acos(-1)
int main()
{
	IOS
	string s,t;
	cin>>s>>t;
	t.erase(t.length()-1,1);
	if(s==t)
	cout<<"Yes";
	else
	cout<<"No";
}

Measured memory_bytes: 3612
n, p = [int(x) for x in input().split(' ')]
dp1 = [0,0]
dp2 = [0,0]
data = [int(x) for x in input().split(' ')]
count = 0
for i in range(n):
    tmp = data[i]
    if(tmp % 2 == 1):
        count += 1
if(count == 0):
    if(p == 0):
        print(2**n)
    else:
        print(0)
    exit()
print(2**(count - 1) *2 ** (n - count))


Measured memory_bytes: 3064
#include<stdio.h>

int main(void){

  int a,b;

  scanf("%d%d",&a,&b);

  if(a > b){
    printf("a > b\n");
  }else if(a < b){
    printf("a < b\n");
  }else{
    printf("a == b\n");
  }

  return 0;
}

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

using namespace std;

int main() {
  int A, B;

  cin >> A >> B;

  int al = (int) ceil((double) A / 0.08);
  int ar = (int) ceil((double) (A + 1) / 0.08);
  int bl = (int) ceil((double) B / 0.1);
  int br = (int) ceil((double) (B + 1) / 0.1);

  int ans = max(al, bl);
  if (ans >= ar || ans >= br) {
    ans = -1;
  }

  cout << ans << endl;

  return 0;
}


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

int inner(vector<int > p,vector<int>q){
int ans=0;
for(int i=0;i<p.size();i++)  ans+=(p[i]-q[i])*(p[i]-q[i]);
return ans;
}

int main(){
int N,D;
cin>>N>>D;
vector<int> a[N];

for(int i=0;i<N;i++){
 for(int j=0;j<D;j++){
int s;
cin>>s;
a[i].push_back(s);
 }
}

int ans=0;

for(int i=0;i<N;i++){
 for(int j=i+1;j<N;j++){
double d=sqrt(inner(a[i],a[j]));
if (d==floor(d)) ans++;
 }
}
cout<<ans;

 return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
  sort(a, a+N);
}
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  int i;
  pair<T1, T2> *arr;
  walloc1d(&arr, N, &mem);
  for(i=(0);i<(N);i++){
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr+N);
  for(i=(0);i<(N);i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int M;
int A[100000];
int B[100000];
int main(){
  wmem = memarr;
  int i;
  int j;
  long long res = 0;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
    }
  }
  sortA_L(N,A,B);
  for(i=(0);i<(N);i++){
    j =min_L(B[i], M);
    M -= j;
    res += (long long)A[i] * j;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190925-1

// --- original code ---
// int N, M, A[1d5], B[1d5];
// {
//   int i, j;
//   ll res = 0;
//   rd(N,M,(A,B)(N));
//   sortA(N,A,B);
//   rep(i,N){
//     j = min(B[i],M);
//     M -= j;
//     res += (ll)A[i] * j;
//   }
//   wt(res);
// }


Measured memory_bytes: 1792
/* kadai3_2
   Saikyo_Kazune
*/
#include <stdio.h>
#include <string.h>
 
 
 
int main(void){
   //本の数を要れる変数num_booksを宣言
   int num_books;
   scanf("%d",&num_books);
   //1の位の数で場合分け
   switch(num_books%10){
       case 2:case 4:case 5:case 7: case 9:printf("hon\n");break;
       case 0:case 1:case 6:case 8:printf("pon\n");break;
       case 3:printf("bon\n");break;
   }
   return 0;
}

Measured memory_bytes: 1616
while true
    n = STDIN.gets.to_i
    exit 0 if n==0
    max = 10000
    data = Array.new(max)
    for i in 0..max-1 do
        data[i] = 0
    end
    num_type = 0
    for i in 0..n-1 do
        type = STDIN.gets.to_i
        data[type] = data[type]+1 
        num_type = type if type > num_type
    end
    for i in 0..num_type do
        if data[i]==0 then
            print "-"
        else
            for j in 0..data[i]-1 do
                print "*"
            end
        end
        print "\n"
    end
end

Measured memory_bytes: 6324
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対グラフ

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

int main(){
    string s;
    cin >>s;
    rep2(i,s.size()-1){
        if(s[i]==s[i-1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    return 0;
}

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

ll h, w, a, b, fat[2*MAXH], inv_fat[2*MAXH];

ll exp(ll a, int p){
	ll resp = 1LL;
	while(p>0){
		if(p%2){
			resp = (resp*a)%MOD;
		}
		a = (a*a)%MOD;
		p/=2;
	}
	return resp;
}

int main(){
	fat[0]=1;
	inv_fat[0]=1;
	for(ll i=1; i<2*MAXH; i++){
		fat[i] = (fat[i-1]*i)%MOD;
		inv_fat[i] = exp(fat[i], MOD-2);
	}
	while(scanf("%lld %lld %lld %lld", &h, &w, &a, &b)!=EOF){
		ll tot = fat[h-1+w-1];
		tot = (tot*inv_fat[h-1])%MOD;
		tot = (tot*inv_fat[w-1])%MOD;
		
		for(ll x = h-a; x<h; x++){
			ll parc1 = fat[x+b-1];
			parc1 = (parc1*inv_fat[x])%MOD;
			parc1 = (parc1*inv_fat[b-1])%MOD;
			
			ll parc2 = fat[h-1-x+w-1-b];
			parc2 = (parc2*inv_fat[h-1-x])%MOD;
			parc2 = (parc2*inv_fat[w-1-b])%MOD;
			
			parc1 = (parc1*parc2)%MOD;
			
			tot = (tot - parc1 + MOD)%MOD;
		}
		printf("%lld\n", tot);
	}
	return 0;
}








Measured memory_bytes: 3328
N = int(input())
A = list(map(int,input().split()))
a = 0
b = 0
mod = 10**9 + 7
for i in range(N):
    a += A[i]
    b += A[i]**2
    a = a 
    b = b 
a = a ** 2 
ans = (a - b) // 2 % mod
if ans < 0:
    ans += mod
print(ans)

Measured memory_bytes: 94256
function main(){
  var i = 0;
  while(true){
    var fieldInfo = input[i].split(' ');
    var width = fieldInfo[0] - 0;//toInt
    var height = fieldInfo[1] - 0;//toInt

    // 0 0が入力された
    if(!width && !height){
      break;
    }

    var start;
    var goal;
    var elem = [[],[],[],[],[]];
    for(var ei = 0;ei < 5; ei++){
      elem[ei].length = 0;
    }
    
    for(var y = 0; y < height; y++){
      i++;//1行進める
      for(var x = 0; x < width; x++){
        var c = input[i][x];

        switch(c){
        case 'S':
          start = new Pos(x, y);
          break;
        case 'G':
          goal = new Pos(x, y);
          break;
        case '.':
          break;
        default : // 入力値が正しいので、絶対に属性
          elem[c - 1].push(new Pos(x, y));
          break;
        }
      }
    }

    
    var bestElement = -1;
    var distance = Infinity;
    
    // 属性ごとにループ
    for (var startElem = 0; startElem < 5; startElem++) {
      // DPの初期化 DP[属性][同じ属性内の連番]
      var dp = [[],[],[],[],[]];
      for(var h = 0; h < 5; h++){
        var hLength = elem[h].length;
        dp[h].length = hLength;
        for(var hidx = 0; hidx < hLength; hidx++){
          dp[h][hidx] = Infinity;
        }
      }
      
      // 最初に選んだパチモンから次に捕まえられる属性番号
      var first = (startElem + 1) % 5;

      var firstLength = elem[first].length;
      for (var j = 0; j < firstLength; j++) {
        // s→e1を計算
        dp[first][j] = dist(start, elem[first][j]);
      }
      
      // s->1->2->3->4->g
      // なので、ループは間の-> * 3分まわす
      for (var e = 0; e < 3; e++) {
        // ex->e(x+1)
        var now = (first + e) % 5;
        var next = (now + 1) % 5;
        var nowLength = elem[now].length;
        var nextLength = elem[next].length;
        for (var j = 0; j < nowLength; j++) {
          for (var k = 0; k < nextLength; k++) {
            dp[next][k] = min(
              dp[next][k],
              dp[now][j] + 
                  dist(elem[now][j], elem[next][k]));
          }
        }
      }
      
      var last = (first + 3) % 5;
      var lastLength = elem[last].length;
      for (var j = 0; j < lastLength; j++) {
        // e4->g
        var d = dp[last][j] + 
                    dist(elem[last][j], goal);
        
        if (d < distance) {
          distance = d;
          bestElement = startElem + 1;
        }
        
      }
      
    }
    
    if (distance == Infinity) {
      console.log("NA");
    } else {
      console.log(bestElement + " " + distance);
    }

    i++;
  }
  

}

function dist(from, to){
  return Math.abs(from.x - to.x) + Math.abs(from.y - to.y)
}

function min(a1, a2){
  return a1 < a2 ? a1 : a2;
}

function Pos(a, b){
  this.x = a;
  this.y = b;
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 63484
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

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

    ll ans = 0;
    for (int i = 1; i < n; i++) {
        if (a[i-1] > x) {
            ans += a[i] + (a[i-1] - x);
            a[i] = 0;
        } else {
            ll d = x - a[i-1];
            ans += max(0LL, a[i] - d);
            a[i] = min(d, a[i]);
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024