akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;

using namespace std;
//
// Created by karayuu on 2019-3-28.
//

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    double rad = c * M_PI / 180;

    double s = a * b * sin(rad) / 2;
    //余弦定理
    double d = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(rad));
    double l = a + b + d;

    double h = 2 * s / a;

    printf("%.5f\n", s);
    printf("%.5f\n", l);
    printf("%.5f\n", h);
}


Measured memory_bytes: 3400
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
long long int mod = 4294967296;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,f,g,h,i,j,k,w,ok,ng,res,q;
ll x[500005],y[500005],z[500005];
ll moyox[500005],moyoy[500005];
ll dp[5005][5005][3];
char s[500005];
bool flag,dame;

int main(){
    cin >> a >> b >> q;
	for(i=0;i<a;i++)cin >> x[i];
	for(i=0;i<b;i++)cin >> y[i];
	x[a] = INF;
	y[b] = INF;
	num = 0;
	for(i=0;i<a;i++){
		while(y[num+1] <= x[i]){
			num ++;
		}
		moyox[i] = min(abs(y[num] - x[i]),abs(y[num+1] - x[i]));
	}
	num = 0;
	for(i=0;i<b;i++){
		while(x[num+1] <= y[i]){
			num ++;
		}
		moyoy[i] = min(abs(x[num] - y[i]),abs(x[num+1] - y[i]));
	}
	for(i=0;i<q;i++){
		cin >> k;
		ans = INF;
		ll res1,res2;
		if(k <= x[0]){
			res1 = x[0] - k + moyox[0];
		}else if(k >= x[a-1]){
			res1 = k - x[a-1] + moyox[a-1];
		}else{
			d = lb(x,x+a,k) - x;
			res1 = INF;
			for(j=-1;j<=1;j++){
				if(j + d < 0 || j + d>= a)continue;
				res1 = min(res1,abs(x[j + d] - k) + moyox[j + d]);
			}
		}

		if(k <= y[0]){
			res2 = y[0] - k + moyoy[0];
		}else if(k >= y[b-1]){
			res2 = k - y[b-1] + moyoy[b-1];
		}else{
			d = lb(y,y+b,k) - y;
			res2 = INF;
			for(j=-1;j<=1;j++){
				if(j + d < 0 || j + d >= b)continue;
				res2 = min(res2,abs(y[j + d] - k) + moyoy[j + d]);
			}
		}
		z[i] = min(res1,res2);
	}
	for(i=0;i<q;i++)p(z[i]);


	return 0;
}

Measured memory_bytes: 44160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define zrt k << 1
#define yrt k << 1 | 1
const int N = 2e5;
using namespace std;
int n,Q,A,B,x[N + 5];
struct Seg
{
    long long mi1[N * 4 + 5],mi2[N * 4 + 5],tag[N * 4 + 5];
    Seg()
    {
        memset(mi1,0x3f,sizeof(mi1));
        memset(mi2,0x3f,sizeof(mi2));
        memset(tag,0,sizeof(tag));
    }
    void add(int k,int l,int r,long long z)
    {
        mi1[k] += z;
        mi2[k] += z;
        tag[k] += z;
    }
    void pushdown(int k,int l,int r,int mid)
    {
        if (tag[k] != 0)
        {
            add(zrt,l,mid,tag[k]);
            add(yrt,mid + 1,r,tag[k]);
            tag[k] = 0;
        }
    }
    void pushup(int k)
    {
        mi1[k] = min(mi1[zrt],mi1[yrt]);
        mi2[k] = min(mi2[zrt],mi2[yrt]);
    }
    void modify(int k,int l,int r,int x,long long z)
    {
        if (l == r)
        {
            mi1[k] = min(mi1[k],z - l);
            mi2[k] = min(mi2[k],z + l);
            return;
        }
        int mid = l + r >> 1;
        pushdown(k,l,r,mid);
        if (x <= mid)
            modify(zrt,l,mid,x,z);
        else
            modify(yrt,mid + 1,r,x,z);
        pushup(k);
    }
    long long query1(int k,int l,int r,int x,int y)
    {
        if (l >= x && r <= y)
            return mi1[k];
        int mid = l + r >> 1;
        pushdown(k,l,r,mid);
        if (x > mid)
            return query1(yrt,mid + 1,r,x,y);
        else
            if (y <= mid)
                return query1(zrt,l,mid,x,y);
            else
                return min(query1(zrt,l,mid,x,y),query1(yrt,mid + 1,r,x,y));
    }
    long long query2(int k,int l,int r,int x,int y)
    {
        if (l >= x && r <= y)
            return mi2[k];
        int mid = l + r >> 1;
        pushdown(k,l,r,mid);
        if (x > mid)
            return query2(yrt,mid + 1,r,x,y);
        else
            if (y <= mid)
                return query2(zrt,l,mid,x,y);
            else
                return min(query2(zrt,l,mid,x,y),query2(yrt,mid + 1,r,x,y));
    }
    long long query(int k,int l,int r)
    {
        if (l == r)
            return mi1[k] + l;
        int mid = l + r >> 1;
        pushdown(k,l,r,mid);
        return min(query(zrt,l,mid),query(yrt,mid + 1,r));
    }
}tree;
int myabs(int x)
{
    return x < 0 ? -x : x;
}
int main()
{
    scanf("%d%d%d%d",&n,&Q,&A,&B);
    x[0] = A;
    for (int i = 1;i <= Q;i++)
        scanf("%d",&x[i]);
    tree.modify(1,1,n,B,0);
    for (int i = 1;i <= Q;i++)
    {
        long long m1 = tree.query1(1,1,n,1,x[i]),m2 = tree.query2(1,1,n,x[i],n);
        tree.add(1,1,n,1ll * myabs(x[i] - x[i - 1]));
        tree.modify(1,1,n,x[i - 1],min(m1 + x[i],m2 - x[i]));
    }
    printf("%lld\n",tree.query(1,1,n));
    return 0;
}

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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g) {
    for ( int i = g; i < n; i++ ) {
        int v = A[i];
        int j = i - g;
        while ( j >= 0 && A[j] > v ) {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n) {
    for ( int h = 1; ; ) {
        if ( h > n ) break;
        G.push_back(h);
        h = 3 * h + 1;
    }
    
    for ( int i = G.size() - 1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    }
}

int main() {
    cin >> n;
    for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
    cnt = 0;
    
    shellSort(A, n);
    
    cout << G.size() << endl;
    for ( int i = G.size() - 1; i >= 0; i-- ) {
        printf("%d", G[i]);
        if ( i > 0 ) printf(" ");
    }
    printf("\n");
    printf("%d\n", cnt);
    for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);
    
    return 0;
}

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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        char[] c=fsc.next().toCharArray();
        fsc.close();
        System.out.println((char)(c[0]+1));
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int inf = 1e9 + 7;

int main() {
	int a,b;
	cin >> a >> b;
	int height = (b-a)*(b-a+1)/2;
	cout << height - b << endl;
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;


bool is_prime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    
    auto sqrtNum = sqrt(num);
    for(int i = 3; i <= (int)sqrtNum ; i += 2){
      if(num % i == 0){
        return false;
      }
    }

    return true;
}
 
int main(){
  int N;
  cin >> N;
  int ans = 0;
  for(int i = N;  ; ++i){
    if(is_prime(i)){
      ans = i;
      break;
    }
  }

  std::cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;

public class Main {
    static int nextMultiple(int min, int M){
        int ans = (min/M)*M;
        while(ans<min) ans += M;
        return ans;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] C = new int[N];
        int[] S = new int[N];
        int[] F = new int[N];
        for(int n=0; n<N-1; n++){
            C[n] = sc.nextInt();
            S[n] = sc.nextInt();
            F[n] = sc.nextInt();
        }
        for(int start=0; start<=N-1; start++){
            int time = 0;
            for(int n=start; n<N-1; n++){
                time = Math.max(S[n], nextMultiple(time, F[n])) + C[n];
            }
            System.out.println(time);
        }

    }
}


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

int main() {
  int N;
  cin>>N;
  int A=1;
  for (int i = 0; i < N; i++) {
  string color;
   cin >>color ;
    if(color=="Y"){A*=0;}
    else{A*=1;}
    
}
  if(A==1){cout<<"Three"<<endl;}
  else{cout<<"Four"<<endl;}
}

Measured memory_bytes: 256
use std::io;
use std::cmp;

fn main() {
    let mut n = String::new();
    io::stdin().read_line(&mut n);
    let n = n.trim().parse::<u64>().unwrap();

    let mut min = std::u64::MAX;
    for i in 1u64..((n as f64).sqrt() as u64 + 1u64) {
        let a = n / i;
        if a * i != n {
            continue;
        }
        // log10(10) == 1 , log10(100) == 2
        min = cmp::min(min, 
            cmp::max(
                (a as f64).log10().floor() as u64 + 1u64,
                (i as f64).log10().floor() as u64 + 1u64
            )
        );
    }

    println!("{}", min);
}

Measured memory_bytes: 4352
a,b,k = (int(i) for i in input().split())
ans = []
for i in range(k):
  if a+i <=b:
   ans.append(a+i)
  
for j in range(k):
  if b-j >=a: 
   ans.append(b-j)
ans2 = sorted(set(ans))
for i in ans2:
  print(i)
  

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

const int MOD = 1e9 + 7;

int n;
int fullmask;
int cutoff;
int memo[41][1 << 17];

void print (int x) {
	while (x) {
		cout << (x & 1);
		x >>= 1;
	}
}

int solve (int i, int mask) {
	if ((mask & fullmask) == fullmask)
		return 0;
	if (i == n)
		return 1;

	int & p = memo[i][mask];
	if (p + 1) return p;

	p = 0;
	for (int d = 1; d <= 10; ++d) {
		p += solve (i + 1, ( (mask << d) | (1 << (d - 1)) ) & cutoff );
		if (p >= MOD)
			p -= MOD;
	}

	return p;
}

// 3 4 2
// 100100010

int main () {


	int x, y, z;
	cin >> n >> x >> y >> z;

	fullmask = 1 << x;
	fullmask = (fullmask + 1) << y;
	fullmask = (fullmask + 1) << (z - 1);
	cutoff = (1 << 17) - 1;

	memset (memo, -1, sizeof memo);

	long long all = 1;
	for (int i = 0; i < n; ++i)
		all = (all * 10LL) % MOD;

	cout << (all - solve (0, 0) + ((long long) MOD)) % MOD << endl;

	return 0;
}

Measured memory_bytes: 21248
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
char m[666][666];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%s", m[i]);
	for (int i = 0; i < num; i++)for (int j = 0; j < num; j++)m[i + num][j] = m[i][j];
	int ans = 0;
	for (int i = 0; i < num; i++)
	{
		bool f = true;
		for (int j = 0; j < num; j++)for (int k = 0; k < num; k++)f &= m[j + i][k] == m[k + i][j];
		if (f)ans += num;
	}
	printf("%d\n", ans);
}

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

int main() {
  int N; cin >> N;
  vector<tuple<string, int, int>> vec;
  for (int i = 0; i < N; i++)
  {
    string S; cin >> S;
    int P; cin >> P;
    vec.emplace_back(S, -P, i);
  }
  sort(vec.begin(), vec.end());

  for (int i = 0; i < N; i++)
  {
    cout << get<2>(vec[i]) + 1 << endl;
  }
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;


fn main() {
    let nkq: Vec<usize> = reads();
    let n = nkq[0];
    let k = nkq[1] as i32;
    let q = nkq[2];

    let mut xs: Vec<i32> = Vec::new();
    xs.resize(n, 0);

    for _ in 0..q {
        let idx: usize = read();
        xs[idx-1] += 1;
    }

    for i in 0..n {
        println!("{}", if k - q as i32 + xs[i] > 0 {"Yes"} else {"No"});
    }
}

#[allow(dead_code)]
fn getline() -> String {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().to_string()
}

#[allow(dead_code)]
fn read<T>() -> T where T : FromStr {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn reads<T>() -> Vec<T> where T : FromStr {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn printv<T>(xs: &[T]) where T : std::fmt::Display {
    xs.iter().fold("", |s, x| {
        print!("{}{}", s, x);
        " "
    });
    println!();
}


Measured memory_bytes: 4732
#include <iostream>

using namespace std;

const int kMaxN = 100;

int selectionSort(int *a, int n) {
    int count = 0;

    for (int i = 0; i < n; i++) {
        int min_i = i;
        for (int j = i + 1; j < n; j++) {
            if (a[j] < a[min_i]) {
                min_i = j;
            }
        }
        
        if (i != min_i) {
            swap(a[i], a[min_i]);
            count++;
        }
    }

    return count;
}

int main() {
    int n;
    int A[kMaxN];
    cin >> n;

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

    int count = selectionSort(A, n);

    for (int i = 0; i < n; i++) {
        cout << A[i];
        if (i != n - 1) {
            cout << " ";
        }
    }

    cout << endl;
    cout << count << endl;

}




Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>

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

    std::cout << ((d <= s * t)? "Yes":"No") << std::endl;

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int k, x;
	cin >> k >> x;
	for (int i = (x - k + 1); i <= x + k - 1; i++) {
		cout << i << ' ';
	}
	cout << endl;
}


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

int a[200010];
long long sum[200010];

long long get_s(int l, int r){
	return sum[r] - sum[l - 1];
}

bool check(int a, int b, int c){
	return abs(get_s(a, b) - get_s(b + 1, c)) > abs(get_s(a, b + 1) - get_s(b + 2, c));
}

int main(){
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		sum[i] = sum[i - 1] + a[i];
	}
	int l = 1, r = 3;
	long long ans = 0x3f3f3f3f3f3f3f3f;
	for (int i = 2; i < n; i++){
		while (l < i - 1 && check(1, l, i)) l++;
		while (r < n - 1 && check(i + 1, r, n)) r++;
		long long minj = min(min(get_s(1, l), get_s(l + 1, i)), min(get_s(i + 1, r), get_s(r + 1, n)));
		long long maxj = max(max(get_s(1, l), get_s(l + 1, i)), max(get_s(i + 1, r), get_s(r + 1, n)));
		ans = min(ans, maxj - minj);
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define int long long
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; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    string s; cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
a,b=input().split()
a=int(a)
b=list(b)
if len(b)==1:
    b=int(b[0])*100
elif len(b)==3:
    b=int(b[0])*100+int(b[2])*10
else:
    b=int(b[0])*100+int(b[2])*10+int(b[3])
print((a*b)//100)

Measured memory_bytes: 9204
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("YES")
no = lambda: print("NO")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
n,m = MI()
a = LI()
c = n-sum(a)
print(c if c>=0 else -1)

Measured memory_bytes: 9992
import java.io.*;
    
class Main
{
     static InputStreamReader isr;
     static BufferedReader br;
     static String output;
     static String[] data = new String[2];
    
     static void initialize ()
     {
          isr = new InputStreamReader(System.in);
          br = new BufferedReader(isr);
          output = null;
          for (String d : data)
          {
               d = null;
          }
     }
    
     public static void main (String[] args)
     {
           initialize();
           try {
                data = (br.readLine()).split(" ");
                if (Integer.parseInt(data[0])-Integer.parseInt(data[1]) == 0) {
                     output = "a == b";
                } else if (Integer.parseInt(data[0])-Integer.parseInt(data[1]) > 0) {
                     output = "a > b";
                } else {
                     output = "a < b";
                }
            System.out.println(output);
           } catch (IOException e) {
           } finally {
                try {
                      br.close();
                } catch (IOException e) {
                }
           }
     }
}

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

int main(int argc, char *argv[])
{
	long a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a){
		cout << k;
	}
	else if (k > a && k <= a+b){
		cout << a;
	}
	else if (k > a + b){
		cout << a - (k - a - b);
	}
}

Measured memory_bytes: 3608
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>
 
namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}
 
using namespace std;
typedef long long int llint;
 
int hantei (int i) {
	if (i == 5) {
		return 2;
	}
	else if (i == 7) {
		return 1;
	}
	return 0;
}
 
int main (void) {
	int a,b,c; cin >> a >> b >> c;
	if (hantei (a) + hantei (b) + hantei (c) == 5) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
 
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    ll m,k,mx,xsum=0;cin>>m>>k;
    mx=mpow(2ll,m);
    if(mx<=k){
        cout<<-1<<endl;
        return 0;
    }

    if(k==0){
        rep(i,0,mx){
            cout<<i<<" "<<i<<" ";
        }
        return 0;
    }

    vector<ll> v(mpow(2ll,m));
    rep(i,0,mx){
        v[i]=i;
        xsum^=v[i];
    }
    xsum^=k;
    swap(v[k],v[mx-1]);
    
    if(xsum==k){
        rep(i,0,mx){
            cout<<v[i]<<" ";
        }
        reverse(v.begin(),--v.end());
        rep(i,0,mx){
            cout<<v[i]<<" ";
        }

    }else{
        cout<<-1<<endl;
        return 0;
    }
}

Measured memory_bytes: 2816
K,T=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
a.reverse()
if T==1:
    print(a[0]-1)
    exit()

b=a[0]
c=a[1]
for i in range(2,T):
    if b>c:
        c+=a[i]
    else:
        b+=a[i]
if b==c:
    print(0)
    exit()
print(abs(b-c)-1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int,int> pint;

int N;
vector<vector<pint> > v;

bool judge(int bit) {
  for (int i = 0; i < N; i++) {
    if (!(bit & (1 << i))) continue;

    for (pint xy : v[i]) {
      int x = xy.first;
      int y = xy.second;

      if (y == 1 && !(bit & (1 << x))) return false;
      if (y == 0 && (bit & (1 << x))) return false;
    }
  }
  return true;
}

int main() {
  cin >> N;
  v.resize(N);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    v[i].resize(A);
    for (int j = 0; j < A; j++) {
      cin >> v[i][j].first >> v[i][j].second;
      v[i][j].first--;
    }
  }

  int res = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    if (judge(bit)) {
      int count = 0;
      for (int i = 0; i < N; i++) {
        if (bit & (1 << i)) count++;
      }
      res = max(res, count);
    }
  }

  cout << res << endl;
}


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

#define ll long long
#define ld long double
#define mod 1000000007LL
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define pb(x) push_back(x)
#define fo(i, a, n) for (i = (a); i < (n); i++)
#define foe(i, a, n) for (i = (a); i <= (n); i++)
// clang-format off
#define vin(a) for (ll i = 0; i < sz(a); i++) { cin >> a[i]; } 
#define vout(a) for (auto x : a) { cout << x << " "; }
#define sws                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
// clang-format on
#define pd(x) cout << x
#define sd(x) cin >> x
#define nl cout << endl
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define foreach(i, a)                                                          \
  for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
// int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};

ll binpow(ll a, ll b, ll m) {
  a %= m;
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  ll ans = (binpow(10, n, mod) + binpow(8, n, mod)) % mod;
  ans = ((ans - 2 * binpow(9, n, mod)) % mod + mod) % mod;

  cout << ans << endl;
}

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

Measured memory_bytes: 3636
#include <stdio.h>
int main (int argc, const char * argv[]) {

    int s,m,h;
    
    scanf("%d",&s);
    if(s<0 || s>86400){
        return -1;
    }
    
    m = s / 60;
    s = s % 60;
    h = m / 60;
    m = m % 60;
    
    printf("%d:%d:%d\n",h,m,s);
    
        return 0;
}

Measured memory_bytes: 592
def kitaichi(a):
    return ((1+a)*a/2)/a

n, k = map(int, input().split())
p = [int(_) for _ in input().split()]
dp = [0] * n
dp[0] = p[0]
cnt = 1

maxi = 0
idx = 0

for i in range(1, n):
    if cnt < k:
        dp[i] = p[i] + dp[i-1]
        cnt += 1
    else:
        dp[i] = p[i] + dp[i-1] - p[i-k]
    if maxi < dp[i]:
        maxi = dp[i]
        idx = i

ans = 0
for i in range(idx-k+1, idx+1):
    ans += kitaichi(p[i])

print(ans)



Measured memory_bytes: 25308
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

char int2char(int x){
}

int main(){
    long N;
    cin >> N;
    string s;
    while(N!=0){
        s = (char)((N-1)%26 + 'a') + s;
        N = (N-1)/26;
    }
    cout << s << endl;
    return 0; 
}

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

const int dx[] = {0, 0, -1, 1};
const int dy[] = {1, -1, 0, 0};
int W, H;
char board[30][30];

int dfs(int y, int x) {
   board[y][x] = '#';
   int ret = 1;
   for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx >= 0 && nx < W && ny >= 0 && ny < H && board[ny][nx] == '.') {
         ret += dfs(ny, nx);
      }
   }
   return ret;
}

int main() {
   while (cin >> W >> H, W) {
      for (int i = 0; i < H; i++) {
         cin >> board[i];
      }
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            if (board[i][j] == '@') {
               cout << dfs(i, j) << endl;
            }
         }
      }
   }

   return 0;
}


Measured memory_bytes: 2988
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int n;
    int max_height = 0;
    int sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int h = 0;
        cin >> h;
        if (h >= max_height) {
            max_height = h;
            sum++;
        }
    }
    cout << sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int n,m,k;cin>>n>>m>>k;
    
    set<int> st;
    
    rep(i,n+1){
        rep(j,m+1){
            st.insert(i*(m-j)+j*(n-i));
        }
    }
    
    if(st.count(k)==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}




Measured memory_bytes: 13056
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allg(v) v.begin(), v.end(), greater<int>()



signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  int n, m, x, y;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, 0, m) {
    cin >> x >> y;
    a[x-1]++;
    a[y-1]++;
  }
  
  rep(i, 0, n)
    cout << a[i] << "\n";
  
  //cout << (  ?"Yes" :"No") << "\n";
  
  //cout << fixed << setprecision(15) << n << "\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;
 
int main(int argc, char *argv[])
{
    int N, A, B;
    std::cin >> N >> A >> B;

    int max = 0;
    int min = 0;
    max = std::min(A, B);
    if (N < A+B) {
        min = A+B-N;
    } else {
        min = 0;
    }

    std::cout << max << " " << min << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

	Scanner sc = new Scanner(System.in);

	int A = sc.nextInt();

	int B = sc.nextInt();

	if(A>=13){

	System.out.println(B);

   }

	else if(6<=A&& A<=12){

	System.out.println(B/2);	

   }


	else if(A<=5){

	System.out.println("0");
 
   }

  }
 }

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
int N = 0, M = 0;
int main(void){
    while(std::cin >> N >> M){
        if(N==0 && M==0) return 0;
        std::vector<int> mas(N, 0);
        for(int i=0; i<N; ++i){
            std::cin >> mas[i];
        }

        std::vector<int> me(M, 0);
        for(int i=0; i<M; ++i){
            std::cin >> me[i];
        }

        int point = 0;
        int cnt = 0;
        for(int i=0; i<M; ++i){
            cnt++;
            point += me[i];
            point += mas[point];
            if(point >= N) break;
        }
        std::cout << cnt << std::endl;
    }
}

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

using namespace std;

int main()
{
    int n,m;
    cin >> n >> m; 
    vector<int> like(m);

    for(int i=0; i<n; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int a;
            cin >> a;
            like.at(a-1)++; 
        }
    }

    int cnt=0;
    for(int j=0; j<m; j++){
        if(like.at(j) == n)
        cnt++;
    }
    cout<< cnt << endl;


    return 0;
}

Measured memory_bytes: 3628
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;


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

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3620
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class ModInt:
    MOD = 10 ** 9 + 7

    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    def __repr__(self):
        return str(self.x)

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

    def set_mod_divisor(self, divisor):
        ModInt.MOD = divisor


def main():
    s = input()
    n = len(s)
    dp_t = [ModInt(0)] * (n + 1)
    dp_a = [ModInt(0)] * (n + 1)
    dp_ab = [ModInt(0)] * (n + 1)
    dp_abc = [ModInt(0)] * (n + 1)

    dp_t[0] = ModInt(1)
    dp_a[0] = ModInt(0)
    dp_ab[0] = ModInt(0)
    dp_abc[0] = ModInt(0)

    for i, char in enumerate(s, 1):
        if char == "?":
            dp_t[i] = 3 * dp_t[i - 1]
            dp_a[i] = 3 * dp_a[i - 1] + dp_t[i - 1]
            dp_ab[i] += 3 * dp_ab[i - 1] + dp_a[i - 1]
            dp_abc[i] += 3 * dp_abc[i - 1] + dp_ab[i - 1]
        else:
            dp_t[i] = dp_t[i - 1]
            dp_a[i] += dp_a[i - 1]
            dp_ab[i] += dp_ab[i - 1]
            dp_abc[i] += dp_abc[i - 1]
            if char == "A":
                dp_a[i] += dp_t[i - 1]
            if char == "B":
                dp_ab[i] += dp_a[i - 1]
            if char == "C":
                dp_abc[i] += dp_ab[i - 1]

    print(dp_abc[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 71128
L, R = list(map(int, input().split()))
L_mod = L%2019
R_mod = R%2019
L_shou = L//2019
R_shou = R//2019
ans = 2020
if L_shou == R_shou:
    for l in range(L_mod, R_mod):
        for r in range(l+1, R_mod+1):
            if (l*r)%2019 < ans:
                ans = (l*r)%2019
    print(ans)
else:
    print(0)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
ll n;
ll a[105];
ll ans=1e18;
signed main(){
	ios_base::sync_with_stdio(0); 
	cin>>n;
	for(ll i=0;i<n;i++) cin>>a[i];
	for(ll x=-100;x<=100;x++){
		ll cur=0;
		for(ll i=0;i<n;i++) cur+=(x-a[i])*(x-a[i]);
		ans=min(ans,cur);
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,n,m,p;
    cin>>k>>n;
    int i,a[n],sum=0,ans,d;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    m=k-a[n-1]+a[0];
    p=-1;
    //cout<<m<<endl<<p<<endl;
    for(i=1; i<n; i++)
    {
        d=a[i]-a[i-1];
        if(d>m)
        {
            m=d;
            p=i-1;
        }
    }
    //cout<<m<<endl<<p<<endl;
    if(p==-1)
        cout<<a[n-1]-a[0]<<endl;
    else
        cout<<k-a[p+1]+a[p]<<endl;
    //cout<<ans<<endl;
    return 0;



}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();


  bool all = true;

  int pt = 0;
  int px = 0;
  int py = 0;
  REP(i, N) {
    int t = nextInt();
    int x = nextInt();
    int y = nextInt();
    int dt = t - pt;
    int dx = abs(x - px);
    int dy = abs(y - py);
    bool ok = true;
    if (dx + dy > dt) { ok = false; }
    if ((dt - (dx + dy)) & 1) { ok = false; }

    all = all && ok;
    pt = t;
    px = x;
    py = y;
  }

  cout << (all ? "Yes":"No") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
/* 
 * Author: aps
 * Time: 20-06-2019 02:16:27
**/
#include<bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

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

const ll inf = 1e18;
const ll mod = 1e9+7;

inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    vector<tuple<int,int,int,int>> evs;

    int n,q; cin >> n >> q;
    for(int i=0;i<n;i++){
        int s,t,x; cin >> s >> t >> x;
        evs.emplace_back(s-x,0,x,i);
        evs.emplace_back(t-x,1,x,i);
    }
    for(int i=0;i<q;i++){
        int d; cin >> d;
        evs.emplace_back(d,2,0,i);
    }

    sort(all(evs));

    set<pii> st;
    for(auto ev : evs){
        int t,x,type,id;
        tie(t,type,x,id) = ev;
        if(type == 0) st.insert({x,id});
        else if (type == 1) st.erase({x,id});
        else{
            if(st.empty()) cout << -1 << endl;
            else cout << (*st.begin()).fi << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 21092
import java.util.Scanner;

public class Main{
  static int n, m;
  static boolean[][] a, b;

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

    n = sc.nextInt();
    m = sc.nextInt();

    a = new boolean[n][n];
    for(int i = 0; i < n; i++){
      String line = sc.next();
      for(int j = 0; j < n; j++){
        if(line.charAt(j) == '#'){
          a[i][j] = true;
        }
      }
    }

    b = new boolean[m][m];
    for(int i = 0; i < m; i++){
      String line = sc.next();
      for(int j = 0; j < m; j++){
        if(line.charAt(j) == '#'){
          b[i][j] = true;
        }
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(i + m - 1 >= n || j + m - 1 >= n){
          continue;
        }
        boolean match = true;
        for(int k = 0; k < m; k++){
          for(int l = 0; l < m; l++){
            if(a[i + k][j + l] != b[k][l]){
              match = false;
              break;
            }
          }
        }
        if(match){
          System.out.println("Yes");
          return;
        }
      }
    }

    System.out.println("No");
  }
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int M = 100000;
int n, m;

vector<pair<int, LL>> v[M];
bool f[M];
LL x[M];

bool dfs(int no, LL val) {
	if(f[no]) { return (val == x[no]); }
	
	f[no] = true;
	x[no] = val;
	
	bool ans = true;
	inc(i, v[no].size()) {
		ans &= dfs(v[no][i].FI, val + v[no][i].SE);
	}
	
	return ans;
}

int main() {
	cin >> n >> m;
	inc(i, m) {
		LL l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		v[l].EB(r,  d);
		v[r].EB(l, -d);
	}
	
	bool ans = true;
	inc(i, n) { ans &= dfs(i, x[i]); }
	
	cout << (ans ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 16512
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
x = nl()

mn = 100100100
for p in range(101):
  cnt = 0
  for xi in x:
    cnt += (p-xi)**2
  mn = min(mn, cnt)
print(mn)

Measured memory_bytes: 3064
s=list(input())
sl=len(s)
c_cnt=0
for i in range(2,sl-1):
    if s[i]=="C":
        c_cnt+=1
if s[0]=="A":
    if c_cnt==1:
        s.remove("A")
        s.remove("C")
        temp="".join(s)
        if temp.islower():
            print("AC")
            exit()
print("WA")


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

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

    long long x;
    cin >> x;
    long long p = 100, step = 0;
    while(p < x) {
        p += p / 100;
        step++;
    }
    cout << step << "\n";
    return 0;

}


Measured memory_bytes: 3640