akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()

	//2N ≤ Kのとき、操作0回で最小値を得る
	if 2*n < k {
		fmt.Println(n)
	} else {
		//N ≤ K 2Nのとき、1回の操作で最小値を得る
		//K < Nのとき、N/K回またはN/K+1回の操作で最小値を得る
		if n < k {
			fmt.Println(abs(n - k))
		} else {
			fmt.Println(min(n%k, abs(n%k-k)))
		}
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<string,int> mp;
int n,num;
string s;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>s;
    	if(!mp[s]) mp[s]++,num++;
	}
    cout<<num;
return 0;
}

Measured memory_bytes: 19140
N,T = map(int,input().split())

INF = 10**9

min_cost = INF
for _ in range(N):
  c,t = map(int,input().split())
  if t <= T:
    min_cost = min(min_cost,c)

answer = min_cost if min_cost < INF else 'TLE'
print(answer)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

const int N = 1e5 + 10;
double x[N], y[N];

struct x_cmp {
  bool operator() (int i, int j) {
    return x[i] < x[j];
  }
};
struct y_cmp {
  bool operator() (int i, int j) {
    return y[i] < y[j];
  }
};

double dist2(int i, int j) {
  return pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2);
}

double min_brute_force(const std::vector<int> & v) {
  double mi = 1.0 / 0.0;
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) {
	continue;
      }
      mi = min(mi, dist2(v[i], v[j]));
    }
  }
  return mi;
}


double min_strip(const vector<int> &v, double d) {
  double mi = d;
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n && pow(y[v[j]] - y[v[i]], 2) < mi; ++j) {
      mi = min(mi, dist2(v[i], v[j]));
    }
  }
  return mi;
}

/*
 */
double min_pair_util(const vector<int> &vx) {
  int n = vx.size();
  if (n <= 4) {
    return min_brute_force(vx);
  }
  // divide at middle
  int mid = n / 2;
  double mid_x = x[vx[mid]];
  double ml = min_pair_util(vector<int>(vx.begin(), vx.begin() + mid));
  double mr = min_pair_util(vector<int>(vx.begin() + mid, vx.end()));
  double dist = min(ml, mr);
  vector<int> strip;
  for(int i = 0; i < n; ++i) {
    if (pow(x[vx[i]] - mid_x, 2) < dist) {
      strip.push_back(vx[i]);
    }
  }
  sort(strip.begin(), strip.end(), y_cmp());
  double res = min_strip(strip, dist);
  return res;
}

int main(void){
  int n;
  cin >> n;
  REP(i, 0, n) {
    cin >> x[i] >> y[i];
  }
  double mi = 1e10;
  vector<int> v(n);
  REP(i, 0, n) {
    v[i] = i;
  }
  sort(v.begin(), v.end(), x_cmp());
  mi = min_pair_util(v);
  printf("%.9f\n", sqrt(mi));
}

Measured memory_bytes: 3548
import java.util.Scanner;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int a, b, x;
        a = sc.nextInt();
        b = sc.nextInt();
        if(a>=3 && b<=20){
            if(a>b){
               int c = a-1;
               if(c>b){
                   System.out.println(a+c);
               }
               else{
                   System.out.println(a+b);
               }
            }
            else{
                int c = b-1;
                if(c>a){
                    System.out.println(b+c);
                }
                else{
                    System.out.println(a+b);
                }
            }
        }
    }
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int h, w, c[11][11];
long long int ans;

void war(){
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
			}
		}		
	}
}

int main(){
	cin >> h >> w;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin >> c[i][j];
		}	
	}
	war();
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int a;
			cin >> a;
			ans += c[a][1];
		}	
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll T;
	cin >> T;

	repn(i, T) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;

		if (d < b) { cout << "No"; }

		else {

			ll g = gcd(b, d - b);

			ll m = min((a - c - 1) % g + c + 1,a);
			m -= b;

			if (m < 0) { cout << "No"; }
			else { cout << "Yes"; }
		}

		cout << endl;
	}

	system("PAUSE");

}





Measured memory_bytes: 504
a,b = map(int,input().split(" "))
ar = []
for i in range(50):
    l = ["#" for j in range(100)]
    ar.append(l)
for i in range(50):
    l = ["." for j in range(100)]
    ar.append(l)
print(100,100)
count = 0
for i in range(48,-1,-2):
    if count == a-1:
        break
    if i % 2 == 0:
        for j in range(0,100,2):
            ar[i][j] = "."
            count += 1
            if count == a-1:
                break
    else:
        for j in range(1,100,2):
            ar[i][j] = "."
            count += 1
            if count == a-1:
                break
count = 0
for i in range(99,50,-2):
    if count == b-1:
        break
    if i % 2 == 0:
        for j in range(0,100,2):
            ar[i][j] = "#"
            count += 1
            if count == b-1:
                break
    else:
        for j in range(1,100,2):
            ar[i][j] = "#"
            count += 1
            if count == b-1:
                break
for r in ar:
    print("".join(r))

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


int main(){
  ll k,a,b; cin >> k >> a >> b;
  if(b-a<=2){
    cout<<k+1<<endl;
    return 0;
  }
  else{
    ll can=max(0ll,(k-(a-1))/2);
    cout<<1+can*(b-a)+k-can*2<<endl;
  }
}


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


void solve(std::vector<long long> A){
  cout << abs(*min_element(A.begin(), A.end()) - *max_element(A.begin(), A.end())) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<long long> A(3);
  for(int i = 0 ; i < 3 ; i++){
    scanf("%lld",&A[i]);
  }
    solve(std::move(A));
    return 0;
}


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

int n, m, k;
long long arr[200010], brr[200010];
long long sum_a[200010], sum_b[200010];

bool check(int x) {
    for(int i = 0;i <= min(x, n);i ++) {
        if(x - i > m) continue;
        if(sum_b[x-i] + sum_a[i] <= k)
            return 1;
    }
    return 0;
}

int main() {
    cin >> n >> m >> k;
    for(int i = 1;i <= n;i ++) {
        scanf("%lld", &arr[i]);
        if(i >= 1)
            sum_a[i] = sum_a[i-1] + arr[i];
        else sum_a[i] = arr[i];
    }
    for(int j = 1;j <= m;j ++) {
        scanf("%lld", &brr[j]);
        if(j >= 1)
            sum_b[j] = sum_b[j-1] + brr[j];
        else sum_b[j] = brr[j];
    }
//    for(int i = 1;i <= 7;i ++) {
//        cout << check(i) << endl;
//    }
    int l = 0, r = n+m, mid = 0, ans = 0;
    do {
        mid = (l + r) >> 1;
        if(check(mid)) l = mid + 1, ans = mid;
        else r = mid - 1;
    } while (l <= r);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10012
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL d[300001];
LL e[300001];
LL a[300001];
int main(){
    LL N;
    cin>>N;
    REP(i,3*N){
        cin>>a[i];
    }
    LL dd=0;
    priority_queue<LL,vector<LL>,greater<LL> >q;
    REP(i,2*N){
        dd+=a[i];
        q.push(a[i]);
        if(i>=N){
           LL aa=q.top();q.pop();
           dd-=aa;
        }
        if(i>=N-1){
           d[i]=dd;
        }
    }
    LL ee=0;
    priority_queue<LL> qq;
    for(int i=3*N-1;i>=N;i--){
        ee+=a[i];
        qq.push(a[i]);
        if(i<2*N){
           LL aa=qq.top();qq.pop();

           ee-=aa;
        }
        if(i<=2*N){
           e[i]=ee;
        }
    }
    LL ans=-10e17;
    for(int i=N-1;i<2*N;i++){
        //cout<<"d"<<d[i]<<"e"<<e[i+1]<<endl;
        ans=max(ans,d[i]-e[i+1]);
    }
    cout<<ans<<endl;
    
    return(0);
}

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

map<ll,ll>l2;

int main()
{
    ll n;
    cin>>n;
    ll s=0;
    for(int i = 1; i<=n;i++){
        ll a,b;
        cin>>a>>b;
        s+=b-a+1;
    }
    cout<<s;

    return 0;
}


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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  int cnt = 0, ans = 0;
  rep(i,n){
    if(a[i] <= x){
      ans++;
      cnt++;
      x -= a[i];
    }else break;
  }
  if(x>0 && ans != 0 && cnt == n) ans--;
  cout << ans << endl;
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using mint = modint998244353;

struct S {
    mint x, w;
    S(mint x = 0, mint w = 1): x(x), w(w){}
};

S op(S a, S b){ return S(a.x * b.w + b.x, a.w * b.w); }

S e() { return S(); }

S mapping(int f, S a){
    if(f == 0) return a;
    return S((a.w - 1)/9 * f, a.w);
}

int composition(int f, int g){
    if(f == 0) return g;
    return f;
}

int id(){ return 0; }

void Main(){
    int n, q; cin >> n >> q;
    lazy_segtree<S, op, e, int, mapping, composition, id> t(n);
    rep(i, n) t.set(i, S(1,10));
    while(q--){
        int l, r, d; cin >> l >> r >> d;
        l--;
        t.apply(l,r,d);
        S ans = t.all_prod();
        cout << ans.x.val() << endl;
    }
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 9832
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> vec(n);
  
  for(int i=0; i<n; i++) {
    cin >> vec.at(i); 
    //cout << vec.at(i) << endl;
  }
  
  int ans = 0;
  
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      for(int k=0; k<n; k++) {
        if(vec.at(i) != vec.at(j) && vec.at(j) != vec.at(k) && vec.at(i) != vec.at(k)) {
          //すべて異なる値
          if(vec.at(i) < vec.at(j) && vec.at(j) < vec.at(k) && vec.at(i) < vec.at(k)) {
            //条件を満たす値
            if((vec.at(i)+vec.at(j)) > vec.at(k) && (vec.at(j)+vec.at(k)) > vec.at(i) && (vec.at(k)+vec.at(i)) > vec.at(j)) {
              //三角形の成立条件に一致
              ans++;
              //cout << vec.at(i) << ":" << vec.at(j) << ":" << vec.at(k) << endl;
            }
          } //条件を満たす値
        } //すべて異なる値
      } // for k
    } // for j
  } // for i
  
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol(const vector<int>& v1, 
               const vector<int>& v2){ 
 return v1[0] < v2[0]; } 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }

void solve()
{
	int A, V;
    cin >> A >> V;
    int B, W;
    cin >> B >> W;
    int T; cin >> T;
    int d = abs(A-B);
    ll d2 = V-W;
    if (d2 <= 0) cout<<"NO";
    else {
        if (d <= d2 * T) cout<<"YES";
        else cout<<"NO";
    }
		return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ss              second
#define ar              array
#define int             long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("ip1.txt", "r", stdin);
  freopen("op1.txt", "w", stdout);
#endif
}

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
  return (a.second < b.second);
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int prime(int n) {
  int flag = 1;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {flag = 0; break;}
  }
  return flag;
}
int power(int x, int y)
{
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
  else
    return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
  return (a * b) / gcd(a, b);
}

int32_t main()
{
  k_007();
  int h;
  cin >> h;
  int i = 0;
  int ans = 0;
  while (h > 1)
  {
    ans += (pow(2, i++));
    h /= 2;
  }

  ans += pow(2, i);

  cout << ans << endl;
}


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

int main( void )
{
    char a,b;
    cin >> a >> b;
    
    int ans = 1;
    if ( a == 'D' )
        ans *= -1;
    if ( b == 'D' )
        ans *= -1;
    
    if ( ans > 0 )
        cout << 'H' << endl;
    else
        cout << 'D' << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


n, w = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]

dp = [0]*(w + 1)
for i in range(n):
    for j in range(w + 1)[::-1]:
        if j - info[i][0] < 0:
            break
        else:
            dp[j] = max(dp[j], dp[j - info[i][0]] + info[i][1])
print(dp[w])

Measured memory_bytes: 41708
M, D = [int(_) for _ in input().split()]

ans = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        d10 = d // 10
        d1 = d % 10
        if d10 < 2 or d1 < 2:
            continue
        if d1 * d10 == m:
            ans += 1
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b)
		cout<<"a < b"<<endl;
	else if(a>b)
		cout<<"a > b"<<endl;
	else
		cout<<"a == b"<<endl;
	return 0;
}

Measured memory_bytes: 1156
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A1 = sc.nextInt();
    int A2 = sc.nextInt();
    int A3 = sc.nextInt();
    
    if (A1 + A2 + A3 >= 22) {
      System.out.print("bust");
    } else {
      System.out.print("win");
    }
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	V a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	rep(i, n - 1) {
		if (a[i] == i + 1) ans++, swap(a[i], a[i + 1]);
	}
	if (a[n - 1] == n) ans++;
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n; cin >> n;
  
  int ans = 0;
  for(int i = 3; i <= n; i+=2){
    int k = 0;
    for(int j = 1; j <= i; j++){
      if(i%j==0) k++;
    }
    if(k==8) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main() {
    int n; cin>> n;
    vector<int> w(n);
    forin(w);
    vector<int> b(n+1, 0);
    rep(i, n){
        b[i+1] = b[i] + w[i];
    }

    int ans = 1e+9;
    for(int t=1; t<n; t++){
        int s1 = b[t];
        int s2 = b[n] - s1;
        ans = min(ans, abs(s1 - s2));
    }
    cout<< ans << endl;
}


Measured memory_bytes: 3608
#include<stdio.h>

int main ()
{

	int n, d;
	scanf("%d%d", &d, &n);
	if(d == 0) {
		if(n == 100) {
			printf("101\n");
		} else {
			printf("%d\n", n);
		}
		return 0;
	}
	int x = 1;
	for(int i = 0; i < d; i++) {
		x *= 100;
	}
	int cnt = 0;
	for(int i = 1; i <= 5000000; i++) {
		
		int g = i;
		int ture = 0;
		while(g % 100 == 0) {
			g /= 100;
			ture++;
		}
		if(ture == d) {
			cnt++;
		}
		if(cnt == n) {
			printf("%d\n", i);
			return 0;
		}
	} 

}



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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	int n,k;
	int r,s,p;
	string t;
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> t;

	int point[3];
	char myhand[n][3];

	for( int i=0; i<3; i++ )	point[i] = 0;

	for( int i=0; i<n; i++ ){
		for( int j=0; j<3; j++ ){
			if( i-k >= 0 ){

				if( t[i] == 's' && myhand[i-k][j] != 'r' ){
					point[j] += r;
					myhand[i][j] = 'r';
				}else	if( t[i] == 'p' && myhand[i-k][j] != 's' ){
					point[j] += s;
					myhand[i][j] = 's';
				}else	if( t[i] == 'r' && myhand[i-k][j] != 'p' ){
					point[j] += p;
					myhand[i][j] = 'p';
				}else{
					if( i+k < n ){
						if( t[i+k] == 'p' )	myhand[i][j] = 'r';
						else if( t[i+k] == 'r' )	myhand[i][j] = 's';
						else	myhand[i][j] = 'p';
					}
				}
			}else{
				if( t[i] == 's' ){
					point[j] += r;
					myhand[i][j] = 'r';
				}else	if( t[i] == 'p' ){
					point[j] += s;
					myhand[i][j] = 's';
				}else	if( t[i] == 'r' ){
					point[j] += p;
					myhand[i][j] = 'p';
				}else{
					if( i+k < n ){
						if( t[i+k] == 'p' )	myhand[i][j] = 'r';
						else if( t[i+k] == 'r' )	myhand[i][j] = 's';
						else	myhand[i][j] = 'p';
					}
				}
			}
		}
	}

	cout << max( point[0], max( point[1], point[2] ) ) << endl;

	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin >> H >> W;
  char c[51][51] ={'.'};
  for(int i = 1; i<= H; i++){
    for(int j = 1; j<=W; j++){
      cin >> c[i][j];
    }
  }
  char d[51][51];
  for(int i = 1; i<= H; i++){
    for(int j = 1; j<=W; j++){
      if(c[i][j] == '#'){
        d[i][j] = '#';
      }
      else{
        int count = 0;
        for(int k = -1; k <=1; k++){
          for(int l = -1; l<=1; l++){
            if(c[i+k][j+l]=='#'){
              count ++;
            }
          }
        }
        char p = count +'0';
        d[i][j] = p;
      }
    }
  }
  for(int i = 1; i <=H; i++){
    for(int j = 1; j<=W; j++){
      if(j == W){
      cout << d[i][j] <<endl;;
    }
    else{
      cout << d[i][j];
    }
    }
  }
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in); 
        String n = scan.next();
        int N = Integer.parseInt(n);
        int x = N * 800;
        int y = 200 * ( N / 15 );
        int z = x - y;
        System.out.println(z);
    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int k=0;k<n;k++){
    cin >> vec[k];
  }
  int mx = vec[0];
  int mn = vec[0];
  for(int i=1;i<n;i++){
    if(mx < vec[i]) mx = vec[i];
    if(mn > vec[i]) mn = vec[i];
  }
  cout << mx - mn << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int ans = Math.max(a + b, Math.max(a - b, a * b));
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n, t = 0;
	cin >> n;
	t = n % 10;
	if (t == 0 || t == 1 || t == 6 || t == 8)cout << "pon" << endl;
	else if (t == 3)cout << "bon" << endl;
	else cout << "hon" << endl;
	return 0;
}

Measured memory_bytes: 3620
package main

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

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	a, _ := strconv.Atoi(read())
	b, _ := strconv.Atoi(read())

	ret := a + b

	if ret < (a - b) {
		ret = a - b
	}
	if ret < (a * b) {
		ret = a * b
	}

	fmt.Println(ret)
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N, N2;
pll P[1010101];

ll mk[1000][1000];
ll mk2[1000][1000];
ll gx[] = {1, 0, -1, 0};
ll gy[] = {0, 1, 0, -1};
ll i, j, k;
int main(){
    scanf("%lld", &N);
    N2 = N * N;
    fornum(i,0,N2){
        ll p;
        scanf("%lld", &p);
        --p;
        P[i] = {p % N, p / N};
    }
    fornum(i,0,N){
        fornum(j,0,N){
            mk[i][j] = min(min(i, N - i - 1), min(j, N - j - 1));
        }
    }
    ll ans = 0;
    fornum(i,0,N2){
        //printf("%lld ", P[i]);
        ll px = P[i].first;
        ll py = P[i].second;
        ans += mk[px][py];
        mk2[px][py] = 1;
        queue<pll> q;
        q.push({px, py});
        //printf("\n%lld:\n", P[i]);
        while(q.size()){
            pll qa = q.front();
            q.pop();
            fornum(j,0,4){
                ll x = qa.first + gx[j];
                ll y = qa.second + gy[j];
                if (x < 0 || N <= x || y < 0 || N <= y)
                    continue;
                ll b = mk[qa.first][qa.second] + 1 - mk2[qa.first][qa.second];
                if(b<mk[x][y]){
                    mk[x][y] = b;
                    q.push({x, y});
                }
            }
        }

    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 15448
s="#" + input()
n=len(s)
n-=1
if s[1:n+1]==s[1:n+1][::-1] and s[1:(n-1)//2 + 1]==s[1:(n-1)//2 + 1][::-1] and s[(n+3)//2:]==s[(n+3)//2:][::-1]:
    print("Yes")
else:
    print("No")
    # print("No",s[1:n+1],s[1:n+1][::-1],s[1:(n-1)//2 + 1],s[1:(n-1)//2 + 1][::-1], s[(n+3)//2:],s[(n+1)//2:][::-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
const int N = 200010;
int n, a[N], cntx, cnty, mxx, mxy, mx, cnt[N];
bool premx[N];
int ans[N];

struct SEG {
	int t[N * 4];
	void build(int u, int l, int r) {
		if(l >= r) { t[u] = -1e9; return ; }
		int mid = (l + r) >> 1;
		build(u * 2, l, mid), build(u * 2 + 1, mid + 1, r);
		t[u] = max(t[u * 2], t[u * 2 + 1]);
	}
	void mdy(int u, int l, int r, int x, int w) {
		if(l >= r) { t[u] = w; return ; }
		int mid = (l + r) >> 1;
		x <= mid ? mdy(u * 2, l, mid, x, w) : mdy(u * 2 + 1, mid + 1, r, x, w);
		t[u] = max(t[u * 2], t[u * 2 + 1]);
	}
	int qry(int u, int l, int r, int L, int R) {
		if(R < l || L > r) return -1e9;
		if(L <= l && r <= R) return t[u];
		int mid = (l + r) >> 1;
		return max(qry(u * 2, l, mid, L, R), qry(u * 2 + 1, mid + 1, r, L, R));
	}
}; SEG t1, t2;

bool check(int x, int C) {
	if(C < 0) return 0;
	if(C & 1) return t1.qry(1, 1, n, x, n) >= C;
	return t2.qry(1, 1, n, x, n) >= C;
}
int main() {
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d", &a[i]), premx[i] = (mx < a[i]), mx = max(mx, a[i]);
	t1.build(1, 1, n);
	per(i, n, 1) {
		int mx1 = t1.qry(1, 1, n, a[i], n);
		int mx2 = t2.qry(1, 1, n, a[i], n);
		if(premx[i]) t1.mdy(1, 1, n, a[i], mx1 + 2), t2.mdy(1, 1, n, a[i], mx2 + 2);
		else t1.mdy(1, 1, n, a[i], mx2 + 1), t2.mdy(1, 1, n, a[i], mx1 + 1);
	}
	per(i, n, 1) cnt[i] = cnt[i + 1] + premx[i];
	rep(i, 1, n) {
		t1.mdy(1, 1, n, a[i], -1e9), t2.mdy(1, 1, n, a[i], 0);
		if(check(mxy, cntx + cnt[i + 1] - cnty + (a[i] > mxx))) {
			ans[i] = 0;
			cntx += (a[i] > mxx), mxx = max(mxx, a[i]);
		}
		else if(check(max(mxx, a[i]), cnty + cnt[i + 1] - cntx - (a[i] > mxx))) {
			ans[i] = 0;
			cntx += (a[i] > mxx), mxx = max(mxx, a[i]);
		}
		else {
			ans[i] = 1;
			cnty += (a[i] > mxy), mxy = max(mxy, a[i]);
		}
	}
	if(cntx != cnty) puts("-1");
	else rep(i, 1, n) printf("%d", ans[i]);
	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
struct tri {
    int first,second,third; 
    tri(int first = 0,int second = 0,int third = 0):first(first),second(second),third(third) {}
};

int main() {
    int N; cin >> N;
    vector<tri> phrase(N);
    rep(i,N) cin >> phrase[i].first >> phrase[i].second >> phrase[i].third;
    int M; cin >> M;
    vector<int> W(M);
    rep(i,M) cin >> W[i];

    vector<int> dp(400,0);
    rep(i,N) {
        int l = phrase[i].first,r = phrase[i].second,p = phrase[i].third;
        rep(j,400) {
            for (int k = max(j - r,0); k < min(j - l + 1,400);++k) {
                dp[j] = max(dp[j],dp[k] + p);
            }
        }
    }
    vector<int> ans(M);
    bool flag = true;
    rep(i,M) {
        if (dp[W[i]] > 0) ans[i] = dp[W[i]];
        else {flag = false; break;}
    }
    if (flag) {
        rep(i,M) cout << ans[i] << '\n'; 
    }
    else cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
// #include<iostream>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
    // printf("%d\n", N);
    return 0;
}

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

"""
・ダイクストラ(優先度付きキュー)
"""

from heapq import heappop, heappush

# 今回はダイクストラするので、データの持ち方は隣接リスト
N = int(input())
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, c))
    # 無向グラフなのでこっちも入れる
    nodes[b].append((a, c))

def dijkstra(nodes, start):
    # 最短距離メモ
    memo = [float('inf')] * (len(nodes))
    # スタート位置
    que = [(0, start)]
    memo[start] = 0
    # キューが空になるまで
    while len(que) != 0:
        # startからの距離, 現在のノード
        dist, cur = heappop(que)
        # 出発ノードcurの到着ノードでループ
        for nxt, cost in nodes[cur]:
            # 今回の経路のが短い時
            if memo[cur] + cost < memo[nxt]:
                memo[nxt] = memo[cur] + cost
                # 現在の移動距離をキューの優先度として、早い方から先に処理するようにする
                heappush(que, (memo[nxt], nxt))
    # ノードstartからの最短距離リストを返却
    return memo

Q, K = map(int, input().split())
# 引数：(ノードの隣接リスト, 出発ノード)
memo = dijkstra(nodes, K)

for i in range(Q):
    x, y = map(int, input().split())
    # 今回は全てKを経由するので、Kからの距離さえ分かれば全部出る
    print(memo[x] + memo[y])


Measured memory_bytes: 94172
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    static int MOD = 1000000007;


    public static void main(String[] args) {

        //int ans=Integer.MAX_VALUE;
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
        int n =sc.nextInt();

        int sum=0;
        for(int i=0;i<n;i++)sum+=sc.nextInt();





        System.out.println(sum>=h?"Yes":"No");






    }


}


Measured memory_bytes: 50056
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int N;
  cin >> N;
  lint S[N+1];
  S[0]=0;
  for(int i=1;i<=N;i++){
    int x;
    cin >> x;
    S[i]=S[i-1]+x;
  }
  sort(S,S+N+1);
  lint ans=0;
  lint num=S[0],count=0;
  rep(i,N+1){
    if(S[i]==num) count++;
    else ans+=(count*(count-1))/2,count=1,num=S[i];
  }
  if(count>1) ans+=(count*(count-1))/2;
  cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
sys.setrecursionlimit(10 ** 7)

N = ri()
A = []
B = []

for i in range(N):
    a, b = rl()
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)
diff = A + B
D = []
for i, x in enumerate(diff):
    D.append((x, i))

D.sort(reverse=True)
A = list(A)
B = list(B)
ta = 0
ao = 0
for x, i in D[::2]:
    ta += A[i]
for x, i in D[1::2]:
    ao += B[i]

print(ta-ao)


Measured memory_bytes: 34776
from collections import deque
infty = 10 ** 9

def BFS(graph, parent, u):
    queue = deque()
    queue.append(u)
    visited = [False for k in range(len(parent))] #探索が始まったか否か
    visited[u] = True
    while queue:
        v = queue.popleft()
        for j in graph[v]:
            if not visited[j]:
                queue.append(j)
                visited[j] = True
                parent[j] = v

n, m = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
parent = [-1 for i in range(n)]
BFS(graph, parent, 0)
if -1 in parent[1:]:
    print("No")
else:
    print("Yes")
    for p in parent[1:]:
        print(p+1)

Measured memory_bytes: 34768
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    List<int[]>[] enter = new List[N + 2];
    List<int[]>[] exit = new List[N + 2];
    for (int i = 0; i <= N + 1; i++) {
      enter[i] = new ArrayList<>();
      exit[i] = new ArrayList<>();
    }

    for (int i = 0; i < M; i++) {
      int left = scanner.nextInt();
      int right = scanner.nextInt();
      int a = scanner.nextInt();
      enter[left].add(new int[]{left, right, a});
      exit[right + 1].add(new int[]{left, right, a});
    }

    SegmentTree st = new SegmentTree(N);
    long max = 0;
    for (int i = 1; i <= N; i++) {
      for (int[] e : enter[i]) st.add(0, e[0], e[2]);
      for (int[] e : exit[i]) st.add(0, e[0], -e[2]);
      long dp = st.query(0, i);
      st.add(i, i + 1, dp);
      max = Math.max(max, dp);
    }
    System.out.println(max);
  }

  private static class SegmentTree {
    private static final long INF = -1_000_000_000_000_000L;
    private final int n;
    long[] max;
    long[] add;
    public SegmentTree(int n) {
      int tmpn = 1;
      while (tmpn < n) tmpn <<= 1;
      this.n = tmpn;
      max = new long[this.n * 2 - 1];
      add = new long[this.n * 2 - 1];
    }

    public long query(int a, int b) {
      return query(a, b, 0, 0, n);
    }

    private long query(int a, int b, int k, int l, int r) {
      if (b <= l || a >= r) return INF;
      if (a <= l && r <= b) return max[k];
      long lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return Math.max(lv, rv) + add[k];
    }

    public void add(int a, int b, long v) {
      add(a, b, v, 0, 0, n);
    }

    private void add(int a, int b, long v, int k, int l, int r) {
      if (a <= l && r <= b) {
        add[k] += v;
        max[k] += v;
        return;
      }
      if (b <= l || a >= r) return;
      add(a, b, v, k * 2 + 1, l, (l + r) / 2);
      add(a, b, v, k * 2 + 2, (l + r) / 2, r);
      max[k] = Math.max(max[k * 2 + 1], max[k * 2 + 2]) + add[k];
    }
  }
}


Measured memory_bytes: 229704
K,N = map(int,input().split())
A = list(map(int,input().split()))

dist_max = 0
for i in range(N-1):
    dist_max = max(dist_max,A[i+1]-A[i])
dist_max = max(dist_max,K-A[N-1]+A[0])

print(K-dist_max)


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> Vector;
typedef vector<vector<ll>> DVector;

#define fi          first
#define se          second
#define pb          push_back
#define INF         INT_MAX
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define dbg(x)      cout<<#x"="<<x<<endl
#define ub(x,y)     upper_bound(all(x),y)-x.begin()
#define lb(x,y)     lower_bound(all(x),y)-x.begin()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define rep(i,n)    repl(i,0,n-1)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<int>())
#define mkp(x,y)    make_pair(x,y)
int n;
DVector f,p;

ll dfs(Vector a){
  ll ans;
  if(a.size() == 10){
    bool flag = false;
    rep(i,10)if(a[i] != 0)flag = true;
    if(!flag)ans = -INF;
    else{
      Vector c(n,0);
      ll sum = 0;
      rep(i,n)rep(j,10)if(a[j] && f[i][j])c[i]++;
      rep(i,n) sum += p[i][c[i]];
      ans = sum;
    }
  }else{
    Vector tmp1 = a;
    Vector tmp2 = a;
    tmp1.pb(1);
    tmp2.pb(0);
    ans = mmax(dfs(tmp1),dfs(tmp2));
  }
  return ans;
}

int main(){
  cin.sync_with_stdio(false);
  cin >> n;
  f.resize(n,Vector(10));
  p.resize(n,Vector(11));
  rep(i,n)rep(j,10)cin >> f[i][j];
  rep(i,n)rep(j,11)cin >> p[i][j];
  Vector a;
  cout << dfs(a) << endl;
}


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

template<typename T>
class PQueue {
private:
	vector<T> data;
public:
	PQueue() { data.push_back(0); }
	T insert(T k);
	T extractMax();
};

template<typename T> T PQueue<T>::insert(T k) {
	data.push_back(k);
	int n = data.size() - 1;
	while (1) {
		if (n == 1)
			break;
		else if (data[n] <= data[n / 2])
			break;
		else {
			T temp = data[n / 2];
			data[n / 2] = data[n];
			data[n] = temp;
			n /= 2;
		}
	}
	return k;
}

template<typename T> T PQueue<T>::extractMax() {
	assert(data.size() >= 2);
	T top = data[1];
	data[1] = data.back();
	data.pop_back();
	int i = 1;
	while (1) {
		if (i * 2 >= data.size())
			break;
		else if (i * 2 + 1 >= data.size()) {
			if (data[i] >= data[i * 2])
				break;
			else {
				T temp = data[i];
				data[i] = data[i * 2];
				data[i * 2] = temp;
			}
		}
		else {
			if (data[i] >= max(data[i * 2], data[i * 2 + 1]))
				break;
			else if (data[i * 2] >= data[i * 2 + 1]) {
				T temp = data[i];
				data[i] = data[i * 2];
				data[i * 2] = temp;
				i *= 2;
			}
			else {
				T temp = data[i];
				data[i] = data[i * 2 + 1];
				data[i * 2 + 1] = temp;
				i = i * 2 + 1;
			}
		}
	}
	return top;
}

int main() {
	PQueue<int> pq;
	string command;
	int n;
	while (cin >> command && command != "end") {
		if (command == "insert") {
			cin >> n;
			pq.insert(n);
		}
		else if (command == "extract")
			cout << pq.extractMax() << endl;
	}
}



Measured memory_bytes: 7072
import java.util.Scanner;

public class Main {
    public static int min(int a, int b){
        if(a>b){
            return b;
        }
        return a;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        int[] B = new int[N-1];
        for(int i = 0; i < N-1; i++){
            B[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0; i < N; i++){
            if(i == 0){A[i] = B[i];}
            else if(i == N-1){A[i] = B[i-1];}
            else{
                A[i] = min(B[i],B[i-1]);
            }
        }
        int total = 0;
        for(int i = 0; i < N; i++){
            total += A[i];
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 22612
#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 n;
  cin >> n;
  vector<int> a(n), b(n), c(n-1);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i]--;
  rep(i, n) cin >> b[i];
  rep(i, n-1) cin >> c[i];
  int ans = 0;
  rep(i, n) ans += b[a[i]];
  rep(i, n-1) if (a[i] + 1 == a[i+1]) ans += c[a[i]];
  cout << ans << endl; 
  return 0;
}

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

int main(){
    long double a, b;
    int h, m;
    cin >> a >> b >> h >> m;

    long double p = (60*h + m) % 720;
    long double q = m;

    long double prad = p * PI / 360;
    long double qrad = q * PI / 30;

    long double diff = abs(prad - qrad);
    diff = min(2*PI - diff, diff);

    long double ans = a*a + b*b - 2*a*b*cos(diff);

    cout << fixed << setprecision(15) << pow(ans, 0.5) << endl;

    return 0;
}


Measured memory_bytes: 4164
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int max = 0;
            int gcd = 0;
            for (int i = 0; i < n; ++i) {
                int a = in.nextInt();
                max = Math.max(max, a);
                gcd = findGcd(gcd, a);
            }
            if (k <= max && k % gcd == 0) {
                out.println("POSSIBLE");
            } else {
                out.println("IMPOSSIBLE");
            }
        }

        private int findGcd(int a, int b) {
            while (b > 0) {
                int t = a % b;
                a = b;
                b = t;
            }
            return a;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

int main(){
    string a, b;
    int sum;
    bool tf;

    cin >> a;
    cin >> b;
    sum = stoi(a + b);
    for(int i = 1; i <= 1000; i++){
        if(i * i == sum){
            tf = true;
            break;
        }
        else {
            tf = false;
        }
    }
    if(tf == true){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int r; cin>>r;
	cout << r*r << endl;


  return 0;
}


Measured memory_bytes: 256
/*
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#define M 1010
#define ll long long
using namespace std;

int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}

int n, note[M], a, b;

int main() {
	//freopen(".in", "r", stdin), freopen(".out", "w", stdout);
	n = read();
	a = read(), b = read();
	for(int i = 1; i <= n; i++) note[i] = read();
	int aa = 0, bb = 0, cc = 0;
	for(int i = 1; i <= n; i++)
	{
		if(note[i] <= a) aa++;
		else if(note[i] > b) cc++;
		else bb++;
	}
	cout << min(aa, min(bb, cc)) << "\n";
	
	return 0;
}


Measured memory_bytes: 256