akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
const int N=2005;
int n,t,s,v,id,a[N],d[N],vis[N];
set<int>S;
vector<int>f[N],e[N];
void dfs(int v){
	vis[v]=1;d[++t]=a[v];
	int i,u;
	for(i=0;i<e[v].size();i++){
		u=e[v][i];
		if(vis[u]==0)dfs(u);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)for(int j=1;j<i;j++)if(gcd(a[i],a[j])!=1){
		e[i].push_back(j);
		e[j].push_back(i);
	}
	for(int i=1;i<=n;i++)sort(e[i].begin(),e[i].end());
	for(int i=1;i<=n;i++)if(vis[i]==0){vis[i]=1;S.insert(i);dfs(i);}
//	for(int i=1;i<=n;i++)printf("%d ",d[i]);printf("\n");
	for(int i=1;i<=n;i++){
		s=sqrt(t=d[i]);
		for(int j=2;j<=s;j++)if(t%j==0){
			while(t%j==0)t/=j;
			f[i].push_back(j);
		}
		if(t!=1)f[i].push_back(t);
	}
	for(int i=1;i<=n;i++)a[i]=i;
	for(int i=1;i<=n;i++){
		s=d[a[i]];id=i;
		S.clear();
		for(int j=i;j<=n;j++){
			t=(d[a[j]]>s);
			for(int l=0;l<f[a[j]].size();l++){
				v=f[a[j]][l];
				if(S.find(v)==S.end())S.insert(v);
				else t=0;
			}
			if(t==1){s=d[a[j]];id=j;}
		}
		for(int j=id-1;j>=i;j--)swap(a[j],a[j+1]);
//		for(int i=1;i<=n;i++)printf("%d ",d[a[i]]);printf("\n");
	}
	for(int i=1;i<=n;i++)printf("%d ",d[a[i]]);
	return 0;
}

Measured memory_bytes: 16768
N = int(input())
X = list(map(int, input().split()))

sumXSq = sum([x*x for x in X])
sumX = sum(X)

# NP^2 - 2*SumX*P + sumXSq の最小値
# 微分して0 -> 2NP -2*SumX = 0
# P = sumX / N

P = int(sumX / N)
P2 = P + 1

ans = min(N*P*P - 2*sumX*P + sumXSq, N*P2*P2 - 2*sumX*P2 + sumXSq)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  char s;
  cin >> s;
  if (s == 'a' || s == 'i' || s == 'u' || s == 'e' ||  s == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T&a,T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,T&b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
/**/

int main(){
    ll hoge;
    for(int i=0;i<5;i++){
        cin>>hoge;
        if(hoge==0){
            cout<<i+1<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3588
<?php

function input() {
    return trim(fgets(STDIN));
}
function input_array() {
    return explode(' ', input());
}

list($A, $B, $K) = input_array();

for ($i = 0; $i < $K; $i++) {
    if ($i % 2 === 0) { // takahashi's turn
        if ($A % 2 === 1) {
            $A--;
        }
        $B = $B + floor($A / 2);
        $A = floor($A / 2);
    } else { // aoki's turn
        if ($B % 2 === 1) {
            $B--;
        }
        $A = $A + floor($B / 2);
        $B = floor($B / 2);
    }
}

echo "{$A} {$B}\n";

Measured memory_bytes: 4728
#include<iostream>
using namespace std;
typedef long long ll;

const int MNUM[] = {12,12};
const int ML[][12] = { {31,28,31,30,31,30,31,31,30,31,30,31},      //day/month in usual year
		      {31,29,31,30,31,30,31,31,30,31,30,31} };  //day/month in leap year
const string DAY[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

struct date{
  int y,m,d;

  date(void):y(0),m(1),d(1){}
  date(int a,int b,int c):y(a),m(b),d(c){}

  int Leap(void){
    if(y%400==0)return 1;
    if(y%100==0)return 0;
    if(y%4==0)return 1;
    return 0;
  }

  date next(void){
    int l = Leap();
    if(ML[l][m-1]<++d){ d=1; m++; }
    if(MNUM[l]<m){ m=1; y++; }
    return *this;
  }

  ll dayCount(void)const{
    date tmp;
    for(ll res=0;;res++){
      if(tmp==*this)return res;
      tmp.next();
    }
  }

  //calculate days from Julian Day(-4713/01/01) using Fliegel's formula.
  ll Fliegel(void){
    int a = (14-m)/12, Y = y+4800-a, M = m+12*a-3;
    return (ll)d + (153*M+2)/5 + 365*Y + Y/4 - Y/100 + Y/400 - 32045;
  }

  //calculate day of week using Zeller congruence.
  int Zeller(void){
    int Y = y, M = m;
    if(M<3){Y--; M+=12;}
    return (Y + Y/4 - Y/100 + Y/400 + (13*M+8)/5 + d)%7;
  }

  bool operator==(const date x)const{return (y==x.y && m==x.m && d==x.d);}
  
  bool operator<(const date x)const{
    if(y!=x.y)return y<x.y;
    if(m!=x.m)return m<x.m;
    return d<x.d;
  }
  
  bool operator<=(const date x)const{return (*this<x || *this==x); }
  bool operator>(const date x)const{return !(*this<=x);}
  bool operator>=(const date x)const{return !(*this<x);}
  
  ll operator-(const date x)const{
    return dayCount() - x.dayCount();
  }
};

int main(){
  int y1,m1,d1,y2,m2,d2;
  while(cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2,y1>=0){
    cout << date(y2,m2,d2)-date(y1,m1,d1) << endl;
  }
}

Measured memory_bytes: 1200
#include<iostream>
using namespace std;
int n,k,s;
int dfs(int now,int less,int u)
{
	if(!less)return now==0;
	else
	{
		int cnt=0;
		for(int i=u+1;i<=n&&i<=now;i++)
		{
			cnt+=dfs(now-i,less-1,i);
		}
		return cnt;
	}
}
main()
{
	while(cin>>n>>k>>s,n)
	{
		cout<<dfs(s,k,0)<<endl;
	}
}



Measured memory_bytes: 3092
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    printf("%d\n",(x+y)%24);
    return 0;
}


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

int main() {
  int r, d, x;
  cin >> r >> d >> x;
  rep(i,10) {
    x = r*x - d;
    cout << x << endl;
  }
  return 0;
}

// https://github.com/atcoder/live_library

Measured memory_bytes: 3616
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    let alphabet = [
        'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
        'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
    ];

    input! {
       mut N: usize,
    }
    //let mut N = 1000000000000001_usize;
    //let mut N = 52_usize;
    //let mut N = 702_usize;

    let mut tmp = vec![];
    while N > 0 {
        let mut x = N % 26;
        if x == 0 {
            x = 26;
        }
        N = (N - x) / 26;
        tmp.push(x);
    }
    mydbg!(tmp);
    tmp.reverse();

    let ans = tmp.iter().map(|&x| alphabet[x]).toVec().joinToString("");

    echo!(ans);
}


Measured memory_bytes: 2172
val = ["S", "H", "C", "D"]
cards = []
for i in val:
    cards.extend([str(i) + " " + str(j) for j in range(1, 14)])

n = int(input())
curr_cards = [input() for i in range(n)]

diff_cards = [x for x in cards if x not in curr_cards]

if diff_cards != []:
    print("\r\n".join(diff_cards))



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

int main() { 
    int x, l, n, ans, h_ans = 0;
    cin >> n;
    ans = n;
    vector<pair<int, int>> v;
    for(int i = 0; i < n; ++i) {
        cin >> x >> l;
        v.push_back(make_pair(x+l, x-l));
    }
    sort(v.begin(), v.end());
    l = 0;
    int r = 1;
    while(r < n) {
        if(v[l].first > v[r].second) {
            r++;
            ans--;
        } else {
            l = r;
            r++;
        }
    }
    cout << ans << '\n';
}


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

int main() {

	int n,a;
	int tmp500,tmp1,pay;

	cin >> n;
	cin >> a;

	tmp500	= (n / 500);
	tmp1	= (n % 500);

	pay = tmp500 * 500 + tmp1;

	if(pay == n && a >= tmp1){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
function main()
	lines=readlines()
	N,M=map(x->parse(Int,x),split(shift!(lines)))
	X=Array{Int}(0)
	Y=Array{Int}(0)
	Z=Array{Int}(0)
	for s=lines
		x,y,z=map(x->parse(Int,x),split(s))
		push!(X,x)
		push!(Y,y)
		push!(Z,z)
	end
	ans=0
	for i=0:7
		if i%2==1
			Z=-Z
		end
		if i%4==2
			Y=-Y
		end
		if i==4
			X=-X
		end
		now=Array{Int}(0)
		for j=1:N
			push!(now,X[j]+Y[j]+Z[j])
		end
		sort!(now)
		ret=0
		for j=1:M
			ret+=now[N-j+1]
		end
		ans=max(ans,ret)
	end
	println(ans)
end
main()


Measured memory_bytes: 114776
fn main() {
    let abc = read_vec::<u64>();
    let a = abc[0];
    let b = abc[1];
    let c = abc[2];

    if c < a + b {
        println!("No");
        return
    }

    let d = c - a - b;
    if 4 * a * b < d * d {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

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

using namespace std;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;

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

    double y = (double) sum / (4.0 * m);
    int cnt = 0;

    for(int i = 0; i < n; i++) {
        if(a[i] >= y) {
            ++cnt;
        }
    }
    
    cout << ((cnt >= m) ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//String S = sc.next();
		//int N = Integer.parseInt(sc.next());
		//out.println();
		// ArrayList<String> list = new ArrayList<String>();
		// list.stream().sorted().distinct();
		int A = Integer.parseInt(sc.next());
      int B = Integer.parseInt(sc.next());
      int C = Integer.parseInt(sc.next());
      out.println((A+B)*C/2);
		out.flush();	
	}
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define fst first
#define snd second

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

#define MAX 500010
int BIT[MAX+1], N;

int sum(int i) {
  int s = 0;
  while( i > 0 ) {
    s += BIT[i];
    i -= i & -i;
  }
  return s;
}

int sum(int L,int R) {
  ++L, ++R;
  int v = sum(R);
  if( L - 1 >= 0 ) v -= sum(L-1);
  return v;
}

void add(int i, int x) {
  ++i;
  while( i <= N ) {
    BIT[i] += x;
    i += i & -i;
  }
}

struct Data {
  int L,R,idx;
  bool operator < (Data &d) const {
    if( R != d.R ) return R < d.R;
    return idx < d.idx;
  }
};

int last[MAX];
bool debug = 0;

int main() {
  int Q;
  cin >> N >> Q;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  vector<Data> q(Q);
  rep(i,Q) {
    cin >> q[i].L >> q[i].R;
    --q[i].L, --q[i].R;
    q[i].idx = i;
  }
  sort(ALL(q));
  vector<int> ans(Q,-1);

  memset(last,-1,sizeof last);
  int cur_R = 0;
  rep(i,Q) {
    int L = q[i].L, R = q[i].R;
    int idx = q[i].idx;
    while( cur_R <= R ) {
      if( last[a[cur_R]] != -1 ) {
	add(last[a[cur_R]], -1);
      }
      last[a[cur_R]] = max(last[a[cur_R]],cur_R);
      add(last[a[cur_R]],+1);
      ++cur_R;
    }
    if( debug ) {
      rep(i,10) {
	cout << "(" << i << ": last = " << last[i] << ")" << " ";
      } puts("");
      puts("BIT--");
      rep(i,N) {
	cout << i << " : " << sum(i,i+1) << endl;
      }
    }
    ans[idx] = sum(L,R);
  }

  rep(i,Q) {
    cout << ans[i] << endl;
  }

  return 0;
}


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

const int N = 105;
int dp[N][N];
string s[N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin>>n>>m;

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

    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            if (i == 0 && j == 0) {
                dp[i][j] = (s[i][j] == '#');
                continue;
            }
            dp[i][j] = 1e9;
            if (i) {
                bool b = (s[i][j]=='#')&&(s[i-1][j]=='.');
                dp[i][j] = min(dp[i][j], dp[i-1][j]+b);
            }
            if (j) {
                bool b = (s[i][j]=='#')&&(s[i][j-1]=='.');
                dp[i][j] = min(dp[i][j], dp[i][j-1]+b);
            }
        }
    }
    cout<<dp[n-1][m-1]<<endl;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

double EPS = 1e-10;
double add(double a, double b){
  if(abs(a+b) < EPS* (abs(a) + abs(b))) return 0;
  return a+b;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  double xa,ya,xb,yb,ra,rb;
  cin >> N;
  rep(i,N){
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    double d = sqrt(add(xa,-xb)*add(xa,-xb) + add(ya,-yb)*add(ya,-yb));
    if(d>ra+rb){
      cout << 0 << endl;
    }
    else if(d<max(ra,rb)-min(ra,rb)){
      if(ra>rb){
        cout << 2 << endl;
      }
      else{
        cout << -2 << endl;
      }
    }
    else if(d<=ra+rb)cout<<1<<endl;
  }
  return 0;
}

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

struct drink {
    long A;
    long B;

    bool operator<( const drink& right ) const {
        return A == right.A ? B < right.B : A < right.A;
    };
};

int main(){
  long N,M;cin >> N >> M ;
  vector<drink>D(N);
  for (auto& d : D)cin>> d.A >> d.B;
  sort(D.begin(),D.end());
  long m=0;
  long ans=0;
  for (auto d : D){
    if (m+d.B <M){
      ans += d.A * d.B;
      m += d.B;
    }
    else{
      ans += d.A * ( M-m);
      m = M;
    }
    if (m==M)break;
  } 
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split();
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);

            var path = new List<List<int>>();

            for (int i = 0; i < n; i++) 
            {
                path.Add(new List<int>());
            }

            for (int i = 0; i < m; i++)
            {
                var ab = Console.ReadLine().Split();
                var a = int.Parse(ab[0]) - 1;
                var b = int.Parse(ab[1]) - 1;

                path[a].Add(b);
                path[b].Add(a);
            }

            var ans = new int[n];
            var visited = new bool[n];
            visited[0] = true;

            var que = new Queue<int>();
            que.Enqueue(0);

            while (que.Any())
            {
                var x = que.Dequeue();
                foreach(var nx in path[x])
                {
                    if (visited[nx])
                    {
                        continue;
                    }
                    else
                    {
                        ans[nx] = x + 1;
                        visited[nx] = true;
                        que.Enqueue(nx);
                    }
                }
            }

            Console.WriteLine("Yes");
            for(int i = 1; i < n; i++)
            {
                Console.WriteLine(ans[i]);
            }
        }
    }
}

Measured memory_bytes: 56852
#include<stdio.h>
int main()
{
  int a,b,c,d,s,a1,b1,c1,d1,t;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  scanf("%d%d%d%d",&a1,&b1,&c1,&d1);
  s=a+b+c+d;
  t=a1+b1+c1+d1;
  if(s>t){printf("%d\n",s);}
  else if(s<=t){printf("%d\n",t);}
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

struct Seg {
    int L, R, C;

    bool operator<(const Seg s) const {
        if (L == s.L) {
            if (R == s.R) return C < s.C;
            return R < s.R;
        }
        return L < s.L;
    }
};

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, M; cin >> N >> M;
    Seg s[M];
    FOR(i,0,M-1){
        int L, R, C; cin >> L >> R >> C;
        s[i] = { L, R, C };
    }

    sort(s,s+M);
    set<pair<int, ll> > ans;
    int idx = 0;
    for(; idx < M && s[idx].L == 1; ++idx) {
        auto cur = mp(s[idx].R, (ll)s[idx].C);
        while (!ans.empty() && prev(ans.end())->fi >= cur.fi && prev(ans.end())->sc >= cur.sc)
            ans.erase(prev(ans.end()));
        if (ans.empty() || prev(ans.end())->fi < cur.fi)
            ans.insert(cur);
    }

    for(; idx < M; ++idx) {
        auto it = ans.lower_bound({ s[idx].L, 0 });
        if (it == ans.end()) continue;

        auto cur = mp(s[idx].R, it->sc + s[idx].C);

        auto y = ans.insert(cur).fi;
        if (y != ans.begin() && prev(y)->fi == y->fi) ans.erase(y);
        else if (next(y) != ans.end() && y->sc >= next(y)->sc) ans.erase(y);
        else {
            if (next(y) != ans.end() && y->fi == next(y)->fi) ans.erase(next(y));
            while (y != ans.begin() && prev(y)->sc >= y->sc) ans.erase(prev(y));
        }

        //for(auto x : ans) { cout << x.fi << "," << x.sc << "  "; } cout << endl;
    }

    if (ans.empty() || prev(ans.end())->fi != N) cout << -1;
    else cout << prev(ans.end())->sc;
}



Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
void sol() {
  int h, w, n;
  cin >> h >> w >> n;
  int tot = 0;
  int c1 = 0, c2 = 0;
  while(tot < n) {
    tot += h;
    c1++;
  }
  tot = 0;
  while(tot < n) {
    tot += w;
    c2++;
  }
  int ans = min(c1, c2);
  cout << ans;
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


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

int main()
{
    int c=0;
    string s;
    cin>>s;
    for(int i=0;i<6;i++)
    {
        if(s[2]==s[3] && s[4]==s[5])
            c=1;

    }
    if(c==1)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

int main()
{
	int h, w, i, j ,k;
	string s ;
	cin>>h>>w;
	for(i=0; i<w+2 ; i++)
	{
		cout<<"#";
	}
	cout<<endl;
	for(j=0; j<h; j++)
	{
		cin>>s;
		cout << "#" << s << "#"<<endl;
	}
	for(k=0; k<w+2 ; k++)
	{
		cout<<"#";
	}
	
	return 0;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#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> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> inline void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T> inline T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int h,w,n;cin>>h>>w>>n;
  V<int> l(h+1,INF);
  l[h]=0;
  rep(i,0,n){
    int g,r;cin>>g>>r;
    g--;r--;
    chmin(l[g],r);
  }

  int now=0;
  rep(i,1,h+1){
    if(l[i]<=now){
      cout<<i<<endl;
      return 0;
    }else if(l[i]!=now+1){
      now++;
    }
  }
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <random>

#define ff first
#define ss second

using namespace std;

using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;

pii operator+(pii a, pii b)
{
    return {a.ff+b.ff,a.ss+b.ss};
}

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

    int n;
    cin>>n;
    vector<bool> v(n);
    for(int i=0; i<n; i++){
        int a,b;
        cin>>a>>b;
        v[i]=(a==b);
    }
    bool answer=false;
    for(int i=0; i<=n-3; i++){
        if(v[i]&&v[i+1]&&v[i+2]) answer=true;
    }
    if(answer) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	string s;
	cin>>s;
	string s1 = "ATGC";
	ll mx = 0;
	rep(i,0,s.sz){
		rep(j,i,s.sz){
			ll flag = 1;
			string s2;
			rep(k,i,j+1){
				s2 += s[k];
				ll flag1 = 0;
				rep(l,0,s1.sz){
					if(s[k]==s1[l])flag1 = 1;
				}
				if(flag1==0)flag = 0;
			}
			if(flag==1){
				mx = max(mx,(ll)s2.sz);
			}
		}
	}
	cout << mx << endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n; cin>>n;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    sort(v.begin(),v.end());
    double tmp=v[0];
    for(int i=1;i<n;i++){
        tmp+=v[i];
        tmp/=2;
    }
    cout<<tmp<<endl;
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

void solve() {
	int X, N;
	cin >> X >> N;
	set<int> S;
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		S.insert(p);
	}
	int abs_diff = 10000;
	int ans = -1;
	for (int i = 0; i <= 200; i++) {
		if (S.find(i) != S.end()) continue;
		if (abs_diff > abs(X - i)) {
			ans = i;
			abs_diff = abs(X - i);
		}
	}
	cout << ans << endl;
}

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



Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;
int main(void){
int n;
cin>>n;
string s,t;
cin>>s>>t;
for(int i=0;i<n;i++){
    cout<<s.at(i)<<t.at(i);
}
}



Measured memory_bytes: 256
h,w,k = gets.split.map(&:to_i)

g =[]

h.times do
  g << gets.strip.split('')
end

rpatterns = (0..(h-1)).to_a.map {|i| (0..(h-1)).to_a.combination(i).to_a }.flatten(1)
cpatterns = (0..(w-1)).to_a.map {|i| (0..(w-1)).to_a.combination(i).to_a }.flatten(1)

count = 0

rpatterns.each do |rowp|
  cpatterns.each do |colp|
    d = g.map{|row| row.dup}
    rowp.each do |i|
      d[i] = ['r'] * w
    end
    colp.each do |i|
      0.upto(h-1) do |j|
        d[j][i] = 'r'
      end
    end
    if d.flatten.count("#") == k
      count += 1
    end
  end
end

puts count



Measured memory_bytes: 14432
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line.trim().split_whitespace();
    let a = it.next().unwrap();
    let b = it.next().unwrap();
    if a == "H" {
        println!("{}", b);
    } else {
        if b == "H" {
            println!("D");
        } else {
            println!("H");
        }
    }
}


Measured memory_bytes: 4352
program main
implicit None
	integer(8)::n,h,w,i,c
	integer(8),allocatable::a(:),b(:)
	
	read *,n,h,w
	allocate(a(n),b(n))
	
	do i = 1,n
		read *,a(i),b(i)
	enddo
	
	c = 0
	
	do i = 1,n
		if(a(i) >= h .and. b(i)>= w) c = c + 1
	enddo
	
	print 101,c
101 format(i0)
end program main

Measured memory_bytes: 768
K = int(raw_input())
nakaji = isono = 0
for I, N in zip([raw_input() for i in xrange(K)], [raw_input() for i in xrange(K)]):
    lose1 = lose2 = False
    if I == "kougekida" and isono == 0: lose1 = True
    if N == "kougekida" and nakaji == 0: lose2 = True
    if lose1 and lose2: continue
    elif lose1:
        print "Nakajima-kun"
        break
    elif lose2:
        print "Isono-kun"
        break

    if I == "tameru": isono = min(5, isono + 1)
    if N == "tameru": nakaji = min(5, nakaji + 1)

    if I == "kougekida":
        if N == "mamoru":
            if isono == 5:
                print "Isono-kun"
                break
            isono = 0
        if N == "tameru":
            print "Isono-kun"
            break
        if N == "kougekida":
            if nakaji < isono:
                print "Isono-kun"
                break
            elif nakaji == isono:
                nakaji = isono = 0
            elif nakaji > isono:
                print "Nakajima-kun"
                break
    if N == "kougekida":
        if I == "mamoru":
            if nakaji == 5:
                print "Nakajima-kun"
                break
            nakaji = 0
        if I == "tameru":
            print "Nakajima-kun"
            break
else:
    print "Hikiwake-kun"

Measured memory_bytes: 6464
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
	int x,h;
	double S;
	while (cin>>x>>h,x!=0&&h!=0) {
		S=x*x+2*x*sqrt(h*h+x*x/4.0);
		printf("%.6lf\n",S);
	}
}

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

int main() {
    long n, x, y;
    cin >> n >> x >> y;
    vector<long> ans(n - 1, 0l);
    for(int i = 1; i < n; i++) {
        for(int j = i + 1; j <= n; j++) {
            ans.at(min((long)(j - i), min(abs(x - i) + abs(y - j) + 1, abs(x - j) + abs(y - i) + 1)) - 1)++;
        }
    }
    rep(i, n - 1) cout << ans.at(i) << endl;
}

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

A = [[] for i in range(n)]

for i in range(n):
    A[i] = list(map(int, input().split()))
    
b = [[0]*1 for i in range(m)]

for i in range(m):
    b[i] = int(input())

for i in range(n):
    ans = 0
    for j in range(m):
        ans += A[i][j] * b[j]
    print(ans)


Measured memory_bytes: 6020
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

class UF
{
private:
    int         num;
    vector<int> par;
    vector<int> siz;
public:
    vector<int> val;
public:
    UF(int n): num(n) {
        par.resize(n);
        siz.resize(n);
        val.resize(n);
        int i;
        for(i=0; i<n; i++) {
            par[i]=i; siz[i]=1;
            val[i]=0;
        }
    }
	
    int find(int x) {
        if(x==par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(siz[x]<siz[y]) {
            par[x]=y;
            siz[y]=siz[x]+siz[y];
            val[y]=val[x]+val[y];
        }
        else {
            par[y]=x;
            siz[x]=siz[x]+siz[y];
            val[x]=val[x]+val[y];
        }
    }

    bool same(int x, int y) {
        return find(x)==find(y);
    }

    int size(int x) {
        return siz[find(x)];
    }

    int ngroup() {
    //int ngroup( int& ans ) {
        int count=0;
        int i;
        for(i=0; i<num; i++) {
            if(par[i]==i) {
                count++;
                //ans += (val[i]? siz[i]: siz[i]-1);
            }
        }
        return count;
    }
};


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    map<int,int> z;
    map<int,vector<int> > aa;
    int i;
    for(i=0; i<n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        z[x]=0;
        aa[y].push_back(x);
    }
    
    int cnt=0;
    {        
        auto it=z.begin();
        for(; it!=z.end(); ++it) {
            it->second=cnt;
            cnt++;
        }
    }
    UF uf(cnt);

    int cnt2=0;
    {
        auto it=aa.begin();
        for(; it!=aa.end(); ++it) {
            vector<int>& v = it->second;
            int siz=v.size();
            if(siz>1) {
                for(i=1; i<siz; i++) {
                    uf.unite(z[v[0]], z[v[i]]);
                }
            }
            cnt2++;
            int par = uf.find(z[v[0]]);
            uf.val[par]++;
        }        
    }

    ll sum=0;
    for(i=0; i<cnt; i++) {
        if(uf.find(i)==i) {
            //printf("%d %d\n", uf.val[i], uf.size(i));
            sum += (ll)uf.val[i] * uf.size(i);
        }
    }
    printf("%lld\n", sum-n);

    return 0;
}


Measured memory_bytes: 8704
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vunique(v) unique(v.begin(), v.end());

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

	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int l, r;
	l = A + B;
	r = C + D;

	if(l > r) cout << "Left" << endl;
	else if(l < r) cout << "Right" << endl;
	else cout << "Balanced" << endl;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def f(x):
    global e
    return len(list(filter(lambda y:y>=x-1,e)))

def main():
    n = inp()
    global e
    e = [0 for _ in range(n+1)]
    for i in range(2,n+1):
        x = i
        for j in range(2,i+1):
            while x % j == 0:
                e[j] += 1
                x //= j
    print( f(75) + f(25)*(f(3)-1) + f(15)*(f(5)-1) + f(5)*(f(5)-1)*(f(3)-2)//2)

if __name__ == "__main__":
    main()

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

int main() {
	int num,num2,num3;
	std::cin >> num;
	std::cin >> num2;
	std::cin >> num3;
	
	if(num < num2) {
		if(num2 < num3) {
			std::cout << "Yes" <<std::endl;
		}else {
		std::cout << "No" << std::endl;
		}
	}else {
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1156
// https://atcoder.jp/contests/arc085/tasks/arc085_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, M;
  cin >> N >> M;

  double p = 1 / pow(2, M);
  ll t = 1900 * M + 100 * (N - M);
  ll res = t / p;
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

string S;
int memo[510][510];

int dfs(int l,int r){
    if(l==r)return 1;
    int &ret=memo[l][r];
    if(ret!=-1)return ret;
    ret=0;
    if(S[l]!='m'||S[r-1]!='w')return 0;
    for(int i=l+1;i<r-1;i++){
        if(S[i]!='e')continue;
        ret|=dfs(l+1,i)&&dfs(i+1,r-1);
    }
    return ret;
}

int main(){
    memset(memo,-1,sizeof(memo));
    cin>>S;
    if(dfs(0,S.size()))cout<<"Cat"<<endl;
    else cout<<"Rabbit"<<endl;
    return 0;
}

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

#define ll long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18

void testCase()
{
     
   // ll t; cin>>t; while(t--)
    
    {
        ll n;
        cin>>n;
        string s,a;
        cin>>s;
        a=s;
        sort(a.begin(),a.end());
       // reverse(a.begin(),a.end());

        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]!=s[i])
            cnt++;
        }
        cout<<cnt/2<<endl;
        
    }
    
        
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
//#define cin fin
//#define cout fout
using namespace std;


const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;

int n,k;
string s;

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
    cin >> n >> k >> s;
    for(int i=0;i<n;i++){
        if(i+1==k) cout<<char(s[i]+32);
        else cout<<s[i];
    }
}


Measured memory_bytes: 256
n,k=map(int,input().split())
guest=[]
interval=[]
flag=0
for i in range(n):
    guest.append(int(input()))
    if flag==1:
        interval.append(guest[-1]-guest[-2]-1)
    flag=1
interval.sort()
ans=n
if n>k:
    for i in range(n-k):
        ans+=interval[i]
print(ans)


Measured memory_bytes: 13796
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>

using namespace std;

typedef unsigned long long ull;

int main()
{

  ios::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);

  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
  
  int a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b));
  
  return 0;
  
}


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

int main()
{
    string s,ans="",t;
    cin>>s>>t;
    int l1=s.length();
    int l2=t.length();
    int dp[l1+1][l2+1];
   
    for(int i=0;i<=l1;i++)
        dp[i][0]=0;
    for(int i=0;i<=l2;i++)
        dp[0][i]=0;
    for(int i=1;i<=l1;i++)
    {
        for(int j=1;j<=l2;j++)
        {
            if(s[i-1]==t[j-1]){
               // ans=ans+t[j-1];
            
                dp[i][j]=1+dp[i-1][j-1];}
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=l1,j=l2;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans=s[i-1]+ans;
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        {
            i--;
        }
        else
        j--;
        
    }
   
   
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 38832
from collections import defaultdict


def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    counter = defaultdict(int)
    for ai in A:
        counter[ai] += 1
    
    sorted_c = sorted(counter.values())
    ans = 0
    for i in range(len(counter) - K):
        ans += sorted_c[i]
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 32564
#include<stdio.h>
int main(){
int N,a;
scanf("%d",&N);
a=1;
if(64<=N){
printf("64\n");
}
if(32<=N&&N<64){
printf("32\n");
}
if(16<=N&&N<32){
printf("16\n");
}
if(8<=N&&N<16){
printf("8\n");
}
if(4<=N&&N<8){
printf("4\n");
}
if(2<=N&&N<4){
printf("2\n");
}
if(N==1){
printf("1\n");
}
return 0;
}

Measured memory_bytes: 128
n = int(input())
x,*a = list(map(int, input().split()))
y,*b = list(map(int, input().split()))
z,*c = list(map(int, input().split()))

u = set(range(1,n+1))
a = set(a)
b = set(b)
c = set(c)

s1 = (u - a) & c
s2 = b & c
s3 = s1 & s2

print(len(s1) + len(s2) -len(s3))


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

int main(){
	int n;
	cin >> n;
	
	for(int i = 0; i <= n; i+= 4){
		for(int j = 0; j <= n-i; j += 7){
			if(i+j == n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int m = sc.nextInt();
		int[] whereH = new int[m];//爆弾の位置
		int[] whereW = new int[m];//爆弾の位置
		int[] countHeight = new int[h+1];//爆弾の個数
      	int[] countWide = new int[w+1];//爆弾の個数
		for(int i = 0; i < m; i++){
			int hi = sc.nextInt();
			int wi = sc.nextInt();
			whereH[i] = hi;
			whereW[i] = wi;
			countHeight[hi]++;
          	countWide[wi]++;
		}
		sc.close();
      
		//countHeightとcountWideの最大値計算
		int maxH = 0;
		int maxW = 0;
		for(int i = 0; i <= h; i++){
			if(countHeight[i] > maxH){
				maxH = countHeight[i];
			}
		}
		for(int i = 0; i <= w; i++){
			if(countWide[i] > maxW){
				maxW = countWide[i];
			}
		}
		//maxになる場所の個数
      	int countMaxW = 0;
      	int countMaxH = 0;
      	for(int i = 0; i <= h; i++){
			if(countHeight[i] == maxH){
				countMaxH++;
			}
		}
		for(int i = 0; i <= w; i++){
			if(countWide[i] == maxW){
				countMaxW++;
			}
		}
      
      	long maxCount = countMaxH*countMaxW;
      	
      	for(int i = 0; i < m; i++){
        	if(countWide[whereW[i]] == maxW && countHeight[whereH[i]] == maxH){
            	maxCount--;
            }
        }
      
		if(maxCount!=0) System.out.println(maxH+maxW);
		else  System.out.println(maxH+maxW-1);
	}
}

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

using namespace std;

string s;
vector <char> v;
int t;
bool a[250];

int main()
{
	cin >> s;
	for(int i = 0 ; i < s.size() ; i++)
		a[(int)s[i]] = 1;
	for(int i = (int)'a' ; i < (int)'z' ; i++)
		if(!a[i])
		{
			cout << s << (char) i;
			return 0;
		}
	t = s.size();
	for(int i = s.size() - 1 ; i >= 0 ; i--)
	{
		t--;
		for(int j = 0 ; j < v.size() ; j++)
		{
			if(v[j] > s[i])
			{
				for(int k = 0 ; k < t ; k++)
					cout << s[k];
				cout << v[j];
				return 0;
			}
		}
		v.push_back(s[i]);
		sort(v.begin() , v.end());
	}
	cout << -1;
}
	/*
	if(s.size() == 26)
	{
		for(int i = 25 ; i >= 0 ; i--)
		{
			if(i != 0 && s[i] - s[i - 1] != -1)
			{
				x = i;
			//	cout << "##### " << i << endl;
				for(int j = 0 ; j < x - 1 ; j++)
					cout << s[j];

				cout << "////// " << s[x] << endl;
				for(int j = 0 ; j < 26 ; j++)
					if(a[j] == 0 && j > (char)s[25] - 'a')
					{
						cout << "**** " << s[x]  << " " << j << endl;
						h = (char)j + 'a';
						break;
					}
				cout << s[25];
				return 0;
			}
			if(i == 0 && s[0] == 'z')
				cout << -1;
			else if(i == 0)
				cout << (char)(s[0] + 1);
		}
	}
	else
	{
		for(int i = 0 ; i < 26 ; i++)
			if(a[i] == 0)
			{
				x = i;
				break;
			}
		cout << s << (char)(x + 'a');
	}
	*/

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

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

  int d, g;
  cin >> d >> g;
  vector<vector<int>> vvi(d, vector<int>(2));
  int ans = 10000;
  for (int i = 0; i < d; i++)
  {
    int a1, a2;
    cin >> a1 >> a2;
    vvi.at(i).at(0) = a1;
    vvi.at(i).at(1) = a1*(i+1)*100 + a2;
  }
  for (int tmp = 0; tmp < (1 << d); tmp++)
  {
    bitset<10> bs(tmp);
    int score_sum = 0;
    int problem_sum = 0;
    for (int i = 0; i < d; i++)
    {
      if(bs.test(i))
      {
        score_sum += vvi.at(i).at(1);
        problem_sum += vvi.at(i).at(0);
      }
    }
    if(score_sum >= g) ans = min(ans, problem_sum);
    else
    {
      int digit = 0;
      for (int i = 0; i < d; i++)
      {
        if(bs.test(i));
        else digit = i;
      }
      for (int j = 0; j < vvi.at(digit).at(0); j++)
      {
        score_sum += (digit+1) * 100;
        problem_sum++;
        if(score_sum >= g)
        {
          ans = min(ans, problem_sum);
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <inttypes.h>

#define INF 22222222

#define KI_MAX (1 << 18) /* 262144 */

int ki[KI_MAX * 2 - 1];

void ki_koutiku(void) {
	int i;
	for (i = (KI_MAX - 1) - 1; i >= 0; i--) {
		int l = ki[i * 2 + 1], r = ki[i * 2 + 2];
		ki[i] = l <= r ? l : r;
	}
}

int ki_get_i(int idx, int smin, int smax, int qmin, int qmax) {
	if (smax <= qmin || qmax <= smin) { /* クエリとセグメントが全く重ならない */
		return INF;
	} else if (qmin <= smin && smax <= qmax) { /* セグメントがクエリに完全に含まれる */
		return ki[idx];
	} else {
		int smid = smin + (smax - smin) / 2;
		int l = ki_get_i(idx * 2 + 1, smin, smid, qmin, qmax);
		int r = ki_get_i(idx * 2 + 2, smid, smax, qmin, qmax);
		return l <= r ? l : r;
	}
}

int ki_get(int qmin, int qmax) {
	return qmin < qmax ? ki_get_i(0, 0, KI_MAX, qmin, qmax) : INF;
}

int N;
int* a = ki + (KI_MAX - 1);

int basyo[222222];

int main(void) {
	int i, j;
	uint64_t kotae = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
		basyo[a[i]] = i;
	}
	a[0] = 0;
	a[N + 1] = 0;
	ki_koutiku();
	for (i = 1; i <= N; i++) {
		int yes, no;
		int hidari, migi;

		no = 0; yes = basyo[i];
		while (no + 1 < yes) {
			int mid = no + (yes - no) / 2;
			if (ki_get(mid, basyo[i] + 1) >= i) yes = mid; else no = mid;
		}
		hidari = yes;

		yes = basyo[i]; no = N + 1;
		while (yes + 1 < no) {
			int mid = yes + (no - yes) / 2;
			if (ki_get(basyo[i], mid + 1) >= i) yes = mid; else no = mid;
		}
		migi = yes;

		kotae += (uint64_t)i * (uint64_t)(basyo[i] - hidari + 1) * (uint64_t)(migi - basyo[i] + 1);
	}
	printf("%" PRIu64 "\n", kotae);
	return 0;
}


Measured memory_bytes: 2688