akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <climits>
#include <functional>
#include <queue>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

#define REP(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

struct edge {
	int to;
	long long cost;
	edge(int to_, long long cost_):to(to_), cost(cost_) {}
};

long long dijkstra(int s, int g, int x, const vector<long long> &h, const vector<vector<edge>> &G) {
	typedef pair<long long, int> P;
	const int n = G.size();
	vector<long long> dist(n, LLONG_MAX);
	priority_queue<P, vector<P>, greater<P>> que;
	dist[s] = 0;
	que.push({0, s});

	while(!que.empty()) {
		const auto d = que.top().first;
		const auto v = que.top().second;
		que.pop();

		if(dist[v] < d) continue;
		if(v == g) return 2 * d + h[g] - x;

		for(const auto &e : G[v]) {
			const long long next_dist = max(d + e.cost, x - h[e.to]);

			if(dist[e.to] > next_dist) {
				dist[e.to] = next_dist;
				que.push({next_dist, e.to});
			}
		}
	}

	return -1;
}

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

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

	vector<long long> h(n);
	for(auto &e : h) cin >> e;

	vector<vector<edge>> G(n);
	rep(i, m) {
		int a, b;
		long long t;
		cin >> a >> b >> t;
		--a; --b;
		if(h[a] >= t) G[a].emplace_back(b, t);
		if(h[b] >= t) G[b].emplace_back(a, t);
	}

	cout <<  dijkstra(0, n - 1, x, h, G) << endl;
  
	return EXIT_SUCCESS;
}

Measured memory_bytes: 18964
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
int main(){
    float N;
    cin >> N;
    int c = floor(N / 1.08);

    if((N != int(c * 1.08)) && (N != int((c+1) * 1.08)) && (N != int((c-1) * 1.08))){
        cout << ":(" << endl;
        return 0;
    }else{
        if((N == int((c+1) * 1.08))){
            c++;
        }
        else if ((N == int((c-1) * 1.08))){
            c--;
        }
        cout << c << endl;
    }
    return 0;
}

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

using namespace std;

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

	int a[100000];

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

	double medium = (double)max / 2.0;
	int mini;
	double min;
	if(a[0] != max){
		min = abs(a[0] - medium);
		mini = 0;
	}else{
		min = abs(a[1] - medium);
		mini = 1;
	}
	

	for(int i = 1; i < n; i++){
		if(a[i] != max){
			double tmp = abs(a[i] - medium);
			if(tmp < min){
				min = tmp;
				mini = i;
			}
		}
	}

	cout<<max<<" "<<a[mini]<<endl;


	return 0;
}


Measured memory_bytes: 640
#include <iostream>

int main()
{
  int a, b;
  std::cin >> a >> b;

  if ((a + b) % 2 == 0) std::cout << (a + b) / 2 << std::endl;
  else std::cout << ( a + b ) / 2 + 1 << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll count = 0;
	for (int i = 0; i < 1000; i++) {
		int c[3] = { (i / 100) % 10,(i / 10) % 10,i % 10 };
		int f = 0;
		for (int j = 0; j < s.size(); j++) {
			if ((s[j]-'0') == c[f]) {
				f++;
				if (f == 3) {
					break;
				}
			}
		}
		if (f == 3) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d)
    cout << "Left" << endl;
  else if(a + b == c + d)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
int arr[2050][2050];
void fill(int s,int e,int n,int m)
{
    if(n==0)
    {
        arr[s][e+(1<<m)-1]=1;
        return;
    }
    if(m==0)
    {
        arr[s+(1<<n)-1][e]=1;
        return;
    }
    arr[s+(1<<n)-1][e+(1<<m)-1]=1;
    fill(s,e,n-1,m-1);
    fill(s+(1<<n),e,n-1,m-1);
    fill(s,e+(1<<m),n-1,m-1);
    fill(s+(1<<n),e+(1<<m),n-1,m-1);
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    fill(1,1,n-1,m-1);
    for(int i=1;i<1<<n;cout<<'\n',i++)
        for(int j=1;j<1<<m;j++)
            cout<<arr[i][j];
    cout.flush();
    return 0;
}

Measured memory_bytes: 11520
#include<cstdio>
int x;
int main() {
	scanf("%d",&x);
	if (x>=1800) printf("1");
	else if (x>=1600) printf("2");
	else if (x>=1400) printf("3");
	else if (x>=1200) printf("4");
	else if (x>=1000) printf("5");
	else if (x>=800) printf("6");
	else if (x>=600) printf("7");
	else if (x>=400) printf("8");
	
	return 0;
} 

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define N 100005
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

bool check(int mid){

  return false;
}

ll serch(ll ok,ll ng) {
	while (abs(ok-ng) > 1) {
		ll mid = (ok + ng) / 2;
		if (check(mid))ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(){
  cout<<fixed<<setprecision(20);
  cin.tie(0);ios::sync_with_stdio(false);
  ll n,l,t;
  cin>>n>>l>>t;
  ll a[n],x[n];
  rep(i,n){
    cin>>a[i]>>x[i];
  }
  ll pos1=0,pos2=0,tmp=0;
  if(x[0]==1){
    rep(i,n){
      if(x[i]!=x[0]){
        ll dist=a[i]-a[0],col=0;
        if(2*t-dist>=0){
          col=(2*t-dist)/l+1;
          pos1=((pos1+col)%n+n)%n;
        }
      }
    }
  }else{
    rep(i,n){
      if(x[i]!=x[0]){
        ll dist=a[0]+l-a[i],col=0;
        if(2*t-dist>=0){
          col=(2*t-dist)/l+1;
          pos1=((pos1-col)%n+n)%n;
        }
      }
    }
  }
  rep(i,n){
    if(x[i]==1){
      a[i]=(a[i]+t)%l;
    }else{
      a[i]=((a[i]-t)%l+l)%l;
    }
  }
  tmp=a[0];
  sort(a,a+n);
  if(x[0]==1){
    repr(i,n){
      if(a[i]==tmp){
        pos2=i;
        break;
      }
    }
  }else{
    rep(i,n){
      if(a[i]==tmp){
        pos2=i;
        break;
      }
    }
  }
  rep(i,n){
    cout<<a[(i+pos2-pos1+n)%n]<<endl;
  }
  return 0;
}



Measured memory_bytes: 2816
class PriorityQueue
  
  def initialize
    @heap = Array.new
    @sz = 0
  end
  
  def push x
    i = @sz
    @sz += 1
    while i > 0 do
      p = ( i - 1 ) / 2
      break if @heap[p] <= x
      @heap[i] = @heap[p]
      i = p
    end
    @heap[i] = x
  end
  
  def pop
    
    ret = @heap[0]
    x = @heap[@sz-=1]
    
    i = 0
    while i * 2 + 1 < @sz do
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < @sz && @heap[b] < @heap[a]
      break if @heap[a] >= x
      @heap[i] = @heap[a]
      i = a
    end
    
    @heap[i] = x
    @heap.delete_at(-1)
    ret
  end
  
  def top
    @heap[0]
  end
  
  def empty?
    @sz == 0
  end
  
  def all
    @heap
  end
end
 
n, m = gets.to_s.split.map{|t| t.to_i }
dr   = Array.new(n){ gets.to_s.split.map{|t| t.to_i } }.sort
 
pq = PriorityQueue.new
 
ans = 0
cur = 0
(1..m).each do |i|
  
  while dr[cur] && dr[cur][0] == i do
    pq.push -dr[cur][1]
    cur += 1
  end
  pq.empty? || ans += -pq.pop
end
 
puts ans

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<ll> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    sort(h.rbegin(),h.rend());
    ll ans=0;
    for(int i=k;i<n;i++){
        ans+=h[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
n, x = gets.chomp.split(" ").map(&:to_i)

(n+1).times do |y|
    (n+1).times do |i|
        h = n-y-i
        if y * 10000 + i * 5000 + h * 1000 == x && h >= 0
            puts "#{y} #{i} #{h}"
            exit
        end
    end
end

puts "-1 -1 -1"

Measured memory_bytes: 1788
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,x,y) for(int i=x;i<y;i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    string s;
    cin>>s;
    s='$'+s;
    int n=s.size();
    int a=0,b=0;
    bool fl=0;
    for(int i=1;i<=n;i++){
        if(s[i]=='A' && !fl){a=i;fl=1;}
        if(s[i]=='Z')b=i;
    }
    cout<<b-a+1<<endl;

    return 0;
}


Measured memory_bytes: 3732
/*
AizuOnline A0074
Title videotape
*/
#include <stdio.h>
int hour,min,sec;
//
main()
{
  int rest,rh,rm,rs;

  while(EOF!=scanf("%d %d %d",&hour,&min,&sec) && 
	(hour!=-1 && min != -1 && sec != -1))
    {
      rest = 7200 - hour*3600 - min*60 -sec;
      printf("%02d:%02d:%02d\n",rest/3600,(rest % 3600)/60,rest % 60);
      rest*=3;
      printf("%02d:%02d:%02d\n",rest/3600,(rest % 3600)/60,rest % 60);
    }
return(0);
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int &x : a) {
        cin >> x;
        x--;
        x %= k;
    }
    vector<int> pref(n);
    pref[0] = a[0];
    map<int, int> cnt;
    for (int i = 1; i < n; i++) {
        pref[i] = (a[i] + pref[i - 1]) % k;
    }
    ll res = 0;
    for (int i = 0; i < n; i++) {
        if (pref[i] == 0 && i < k - 1) {
            res++;
        }
        if (i >= k) {
            cnt[pref[i - k]]--;
        }
        res += cnt[pref[i]];
        cnt[pref[i]]++;
    }
    cout << res << "\n";
}


Measured memory_bytes: 11264
n = int(input())
x = 100/108*n
x1 = int(x//1)
x2 = int(x1*1.08//1)
if x2 == n:
  print(x1)
elif int((x1+1)*1.08//1) == n:
  print(x1+1)
elif int((x1-1)*1.08//1) == n:
  print(x1-1)
else:
  print(":(")
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
#define rep(i,n) for(int i = 0;i<n;i++)

int main(){
	string s;
	int k;
	cin >> k >> s;
	if(s.length() <= k) cout << s;
	else{
		string sc = s.substr(0,k);
		cout << sc << "...\n";	
	} 

	return 0;
}

Measured memory_bytes: 3628
#pragma GCC optimize("O3")
char buf[16000];sz;
inline int rd(){
	int ret=0;
	for(;;){
		char k=buf[sz++];
		if(k<'0')break;
		ret=ret*10+k-'0';
	}
	return ret;
}
int a,ans,v[3001];
const int mod=998244353;
int main(){
  read(0,buf,16000);
  int N=rd();
  int S=rd();
  for(int j=0;j<N;j++){
    a=rd();
    ++v[0];
    for(int i=S;i>=a;--i){
      v[i]+=v[i-a];
      v[i]-=(v[i]>=mod)*mod;
    }
    ans+=v[S];
    ans-=(ans>=mod)*mod;
  }
  printf("%d",ans);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int):
    print(-(-N // 111) * 111)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<cassert>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<unordered_set>
#include<iomanip>
#include<numeric>

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    vint a(n); vin(a);
    int f = 0, d = 0;
    rfor(x, a) {
        if(x % 4 == 0) f++;
        else if(x % 2 == 0) d++;
    }
    n -= d;
    if(d == 0 && n / 2 <= f){
        cout << "Yes" << endl;
    } else if(n % 2 == 1 && n / 2 < f || n % 2 == 0 && n / 2 <= f) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(1000000)
readline = sys.stdin.readline

N = int(readline())

adj = [[] for i in range(N)]
for i in range(N - 1):
    A, B = map(int, readline().split())
    A -= 1
    B -= 1
    adj[A].append(B)
    adj[B].append(A)

mod = 10 ** 9 + 7
pow2 = [1] * (N + 1)
for i, j in zip(range(N), range(1, N + 1)):
    pow2[j] = pow2[i] * 2 % mod

ans = 0


def dfs(node, parent):
    global ans
    cnt = 1
    
    for child in adj[node]:
        if child != parent:
            cnt += dfs(child, node)
    
    ans += (pow2[cnt] - 1) * (pow2[N-cnt] - 1)
    ans %= mod
    
    return cnt

dfs(0, None)

ans = (ans - N * pow2[N-1] + pow2[N] - 1) % mod
ans = ans * pow(pow2[N], mod - 2, mod) % mod

print(ans)


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    ll n;
    cin>>n;

    ll ans=0;

    for(ll i=1;i<=n;i++)
    {
    	ll k=n/i;
    	ans+=i*((k*(k+1))/2);
    }

    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3620
n, h = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
a = max([l[0] for l in ls])
bs = [l[1] for l in ls if l[1] > a]
bs.sort()
res = 0
while h > 0 and len(bs) > 0:
    h -= bs.pop()
    res += 1
if h > 0:
    res += (h + a - 1) // a
print(res)

Measured memory_bytes: 28396
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

a = [int(i) for i in STR()]

op = ['+', '-']
ops = ['', '', '']
for ops[0] in op:
    for ops[1] in op:
        for ops[2] in op:
            tmp = a[0]
            for i in range(3):
                if ops[i] == '+':
                    tmp += a[i + 1]
                else:
                    tmp -= a[i + 1]
            if tmp == 7:
                ans = str(a[0])
                for i in range(3):
                    ans += ops[i] + str(a[i + 1])
                ans += '=7'
                print(ans)
                exit()

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


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

  int num = n;
  int a = 0;

  while(num > 0)
  {
    a += num % 10;
    num /= 10;
  }
  cout << (n % a == 0 ? "Yes" : "No");
  */
    int n; cin >> n;
    int a = n;
    int sum = 0;
    while(n > 0){
      sum += n%10;
      n = n/10;
    }
    if(a%sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3584
#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 405;
const int MM = 1000000007;

int D[MX][MX];
int a, b, N, M;

pii E[100005];
int die[MX];

int main()
{
	int N;
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= M; i++){
		scanf("%d%d", &E[i].first, &E[i].second);
	}
	for(int i = 1; i <= N; i++){
		D[i][i] = N+1;
		for(int j = M; j >= 1; j--){
			int a = E[j].first, b = E[j].second;
			if( D[i][a] && D[i][b] ) die[i] = 1;
			else if( D[i][a] ) D[i][b] = i;
			else if( D[i][b] ) D[i][a] = i;
		}
	}
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if( die[i] ) continue;
		for(int j = i+1; j <= N; j++){
			if( die[j] ) continue;
			int ch = 1;
			for(int k = 1; k <= N; k++){
				if( D[i][k] && D[j][k] && D[i][k] != D[j][k] ) ch = 0; 
			}
			ans += ch;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int a[110000],b[110000],c[110000];
long long dp[110000][3];//dp[i][j]:= 最後にjをした時のi日目までの幸福度の最大値
int main()
{
    int n;
    cin >> n;
    rep(i,n){
        cin >> a[i] >> b[i] >> c[i];

    }
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    rep(i,n){
        dp[i+1][0] =max(dp[i][1]+b[i], dp[i][2]+c[i]);
        dp[i+1][1] =max(dp[i][0]+a[i], dp[i][2]+c[i]);
        dp[i+1][2] =max(dp[i][1]+b[i], dp[i][0]+a[i]);
    }
    long long ans = -100000000000;
    rep(i,3){
        ans = max(ans,dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3840
#include<stdio.h>
int main(){
  int a,sum,b,i;
  while(1){
  scanf("%d",&a);
  if(a==0)break;
  for(i=0,sum=0;i<9;i++,sum+=b)scanf("%d",&b);
  printf("%d\n",a-sum);
  }
  return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<queue>
#include<iostream>
#include<algorithm>
#include<list>
#include<vector>
using namespace std;
int a[2000] = { 0 }, b[2000] = {0};
int main() {
	int t;
	scanf("%d", &t);
	for (int i = 0; i <t; i++)
	{
		scanf("%d", &a[i]);
	}
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &b[i]);
	}
	if (t > n)
	{
		for (int i = n; i < t; i++)
		{
			b[i] = -1;
		}
	}
	if (t < n)
	{
		for (int i = t; i < n; i++)
		{
			a[i] = -1;
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (b[i] > a[i])
		{
			cout << 1 << endl;
			return 0;
		}
		if (b[i] < a[i])
		{
			cout << 0 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
}




Measured memory_bytes: 3240
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		int n;
		cin >> n;
		int x = ceil(n/1.08);
		//cout << x << endl;
		if(floor(x*1.08)==n) cout << x << endl;
		else cout << ":(" << endl;
		return 0;  
}  


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
typedef pair<int, int>P;


int main()
{
    ll a, b;
    cin >> a >> b;
  
    ll x;
    bool ok = true;
    x = max(a,b);

    ll ans = 0;

    while (ok)
    {
        
        ans += x;


        if (ans % a == 0 && ans % b == 0)
        {
            ok = false;
            break;
        }


    }

    cout <<ans<< endl;

    return 0;
    
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
  ll H,W;cin>>H>>W;ll q;
  if(H==1||W==1)q=1;
  else q=(H*W+1)/2;
  cout<<q;
  return 0;
}


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

int main()
{
    int n, ans = 0;
    cin >> n;
    
    vector<int> v, c;
    for (int i = 0; i < n; i++) {
        int in;
        cin >> in;
        v.push_back(in);
    }
    for (int i = 0; i < n; i++) {
        int in;
        cin >> in;
        c.push_back(in);
    }
    
    for (int i = 0; i < n; i++) {
        if (v[i] > c[i]) ans += v[i] - c[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<math.h>
using namespace std;
int main()
{
	long int n,d;
	cin>>n>>d;
	int count=0;
	for(long int i=0;i<n;i++)
	{
		long int x,y;
		cin>>x>>y;
		if(sqrt(pow(x,2)+pow(y,2))<=d)
		{
			count=count+1;
		}
	}
	cout<<count<<endl;
}

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

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

  int a[200010];

  set<int> values;
  for(int i=0; i<n; ++i){
    cin >> a[i];
    values.insert(a[i]);
  }
  
  if(n == values.size()){
    cout << "YES" << endl;
  } else {
  	cout << "NO" << endl;
  }
    
  return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }

template<class T>
struct SegmentTree {
private:
    int n;
    vector<T> node;
    T def;
    function<T(T,T)> lop;
    function<T(T,T)> out;
    
public:
    SegmentTree() {}
    SegmentTree(const vector<T> &v, T _def, function<T(T,T)> _lop, function<T(T,T)> _out) {
        int vl = (int)v.size();
        n = 1;
        while(n < vl) n *= 2;
        def = _def; lop = _lop; out = _out;
        node = vector<T>(2 * n - 1, def);
        for(int i = 0; i < vl; i++) node[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--) node[i] = out(node[i * 2 + 1], node[i * 2 + 2]);
    }
    
    void update(int idx, T val) {
        idx += (n - 1);
        node[idx] = lop(node[idx], val);
        while(idx > 0) {
            idx = (idx - 1) / 2;
            node[idx] = out(node[idx * 2 + 1], node[idx * 2 + 2]);
        }
    }
    
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if ((r <= a) || (b <= l)) return def;
        if ((a <= l) && (r <= b)) return node[k];
        return out(query(a, b, 2 * k + 1, l, (l + r) / 2), query(a, b, 2 * k + 2, (l + r) / 2, r));
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h, w, m;
    cin >> h >> w >> m;
    vector<ll> hcnt(h, 0), wcnt(w, 0);
    vector<ll> th(m), tw(m);
    vector<vector<ll>> wset(w);
    rep(i, m) {
        cin >> th[i] >> tw[i];
        th[i]--; tw[i]--;
        hcnt[th[i]]++;
        wcnt[tw[i]]++;
        wset[tw[i]].push_back(th[i]);
    }
    auto lop = [](ll a, ll b){ return a + b; };
    auto out = [](ll a, ll b){ return max(a, b); };
    SegmentTree<ll> st(hcnt, 0, lop, out);
    ll ans = 0;
    rep(i, w) {
        rep(j, sz(wset[i])) st.update(wset[i][j], -1);
        ll tmp = wcnt[i] + st.query(0, h);
        chmax(ans, tmp);
        rep(j, sz(wset[i])) st.update(wset[i][j], 1);
        // printf("w=%lld, tmp=(%lld+%lld)=%lld\n", i, wcnt[i], tmp - wcnt[i], tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 37188
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b[220000],cnt=2020202021,cnta=0,cntb=0;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>b[i];
		cnta+=b[i];
	}
	rep(i,a){
		cntb+=b[i];
		cnt=min(abs((cnta-cntb)-cntb),cnt);
	}
	cout<<cnt;
}

Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;
use  std::collections::BTreeSet;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let a: Vec<u64> = (0..n).into_iter().map(|_| read()).collect();
    let s: BTreeSet<&u64> = (&a).into_iter().collect();
    if s.len() == a.len() {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 8444
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Pol;
struct C{P p;D r;};
Pol ps;
vector<int> qs;
vector<L> ls;
D eps=1e-9;
D cro(P a,P b){return imag(conj(a)*b);}
int ccw(P a,P b,P c){
	if(cro(b-a,c-a)>eps) return 1;
	if(cro(b-a,c-a)<-eps) return -1;
	if(abs(abs(a-c)+abs(c-b)-abs(a-b))<eps) return 0;
	if(abs(abs(a-b)+abs(c-b)-abs(a-c))<eps) return -2;
	return 2;
}
bool iSS(L a,L b){
	return ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0&&ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0;
}
Pol intCC(C a,C b){
	D d=abs(a.p-b.p);
	D theta=acos((a.r*a.r+d*d-b.r*b.r)/(2.0*a.r*d));
	Pol ret;
	ret.pb(a.p+(b.p-a.p)/d*polar(a.r,theta));
	ret.pb(a.p+(b.p-a.p)/d*polar(a.r,-theta));
	return ret;
}
D d[200][200],inf=1e9;
C c[100];
int main(){
	while(true){
		int N;
		cin>>N;
		if(N==0) break;
		ps.clear();
		qs.clear();
		ls.clear();
		rep(i,N){
			int x,y,r;
			cin>>x>>y>>r;
			c[i].p=P(x,y),c[i].r=r;
		}
		ps.pb(c[0].p);
		qs.pb(0);
		rep(i,N-1){
			Pol h=intCC(c[i],c[i+1]);
			rep(j,2) ps.pb(h[j]);
			rep(j,2) qs.pb(i+1);
			ls.pb(L(h[0],h[1]));
		}
		ps.pb(c[N-1].p);
		qs.pb(N-1);
		int M=ps.size();
		rep(i,M) for(int j=i+1;j<M;j++){
			d[i][j]=d[j][i]=inf;
			L l=L(ps[i],ps[j]);
			bool can=true;
			for(int k=qs[i];k<qs[j];k++){
				if(!iSS(l,ls[k])) can=0;
			}
			if(can){
				d[i][j]=d[j][i]=abs(ps[i]-ps[j]);
//				printf("d[%d][%d]=%.5f\n",i,j,d[i][j]);
			}
		}
		rep(i,M) rep(j,M) rep(k,M) d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
		printf("%.12f\n",d[0][M-1]);
	}
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  string s;
  cin >> n >> s;
  int par = 0, op = 0;
  rep(i, n) {
    if(s[i] == '(') par++;
    else par--;
    if(par < 0) op++, par = 0;
  }
  rep(i, op) cout << "(";
  cout << s;
  rep(i, par) cout << ")";
  cout << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
/*575専用スペース A place only for 575*/
/*人人人人人人人人人人*/
using namespace std;
/*Y^Y^Y^Y^Y^Y^Y^Y^Y*/
typedef pair<ll, ll> P;
typedef pair<ll, P> TP;

struct UnionFind {
  int n;
  vector<int> r, p;
  UnionFind() {}
  UnionFind(int sz) : n(sz), r(sz, 1), p(sz, 0) { iota(p.begin(), p.end(), 0); }
  int find(int x) { return (x == p[x] ? x : p[x] = find(p[x])); }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (r[x] < r[y])
      swap(x, y);
    r[x] += r[y];
    p[y] = x;
  }
};
//親を知りたいときは必ずfind()を使う！

map<ll, vector<ll>> group;
set<ll> parent;
int main() {
  ll n, m;

  vector<ll> p;
  cin >> n >> m;
  UnionFind uf(n);
  REP(i, n) {
    ll h;
    cin >> h;
    h--;
    p.pb(h);
  }
  REP(i, m) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    uf.unite(a, b);
  }
  REP(i, n) {
    parent.insert(uf.find(i));
    group[uf.find(i)].pb(i);
  }
  ll ans = 0;
  for (auto &parentNum : parent) {
    sort(group[parentNum].begin(), group[parentNum].end());
    for (auto &groupUnique : group[parentNum]) {
      if (lb(group[parentNum], p[groupUnique]) != group[parentNum].end() &&
          *lb(group[parentNum], p[groupUnique]) == p[groupUnique]) {
        ans++;
        // cout << p[k - 1] << endl;
      }
    }
  }
  cout << ans << endl;
}
/*
p[i]個目
groupかつi+1




*/


Measured memory_bytes: 17396
import math
import collections
h,w = map(int,input().split())
c = [[0]*10]*10
for i in range(10):
	c[i] = list(map(int,input().split()))
a = [[0]*w]*h
for i in range(h):
	a[i] = list(map(int,input().split()))


def bellman_ford(s):
	d = [float('inf')]*10 # 各頂点への最小コスト
	d[s] = 0 # 自身への距離は0
	for i in range(10):
		update = False # 更新が行われたか
		for x, y, z in g:
			if d[y] > d[x] + z:
				d[y] = d[x] + z
				update = True
		if not update:
 			break
		# 負閉路が存在
		if i == 9:
			return -1
	return d

g = []
for i in range(10):
	for j in range(10):
		x,y,z = j,i,c[i][j]
		g.append([x,y,z])

MINCOST = bellman_ford(1)

sum = 0
for j in range(h):
	for i in range(0,10):
		sum += MINCOST[i]*collections.Counter(a[j])[i]
print(sum)

Measured memory_bytes: 9824
#include <bits/stdc++.h>
 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=200010;
const int P=1000000007;
using ll = long long;
vector<ll> prime;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/


/*
	string s;
	s.size()
*/

/*
	char s[N];
	strlen(s)
*/
/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/


int main(){
    ll n;
    cin>>n;
    vector<ll> a(n+2);
    ll m;
    rep(i, n-1){
        cin>>m;
        a.at(m)++;
    }
    rep(i, n){
        cout<<a.at(i+1)<<endl;
    }
}


Measured memory_bytes: 5108
#include<iostream>
#include<cmath>

using namespace std;

int main(int argc, char* argv[]){
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if(abs(a-c) <= d) {
    cout << "Yes" << endl;
    return 0;
  }

  if(abs(a-b)<=d and abs(b-c)<=d) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod (long long)(1e9+7)
#define endl "\n"
using namespace std;


void solve(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	stack<ll> st;
	ll prev[n];
	ll ans=0;
	ll maxi=LLONG_MIN;
	for(ll i=0;i<n;i++){
		maxi=max(maxi,a[i]);
		ans+=(maxi-a[i]);
	}
	cout<<ans<<endl;
}


int main(){
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >>N;
    vector<int> A(N);
    
    for (int i =0;i<N;i++){
        cin >>A[i];
    }
    
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    
    int cnt = 0;
    int K;
    for (int i=0;i<N;i++){
        
        if (i%2==0){
            K=A[i];
            cnt+=K;
            
        }
        
        if (i%2!=0){
            K=A[i];
            cnt-=K;
        }
    }
    
    cout << cnt <<endl;
}

Measured memory_bytes: 256
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
    b,f,r,v = map(int,input().split())
    count[b-1][f-1][r-1] += v
x = 0
for k in range(4):
    if x != 0:
        print("#"*20)
    x += 1
    for j in range(3):
        for i in range(10):
            print("",count[k][j][i],end="")
        print()
    


Measured memory_bytes: 5636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
	int N; cin >> N;
	vector<int> H(N);
	rep(i,N) cin >> H[i];
	H[0]--;
	bool ok = true;
	repr(i,1,N){
		if(H[i] < H[i-1]) ok = false;
		if(H[i] > H[i-1]) H[i]--;
	}
	cout << (ok?"Yes":"No") << endl;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

long long main() {
    long long N, A, B, r;
    scanf("%ld %ld %ld", &N, &A, &B);
    
    if ((B-A)%2==0) {
        r = (B-A)/2;
    } else {
        if (A-1 <= N-B) { // A is closer to the left end
            long long d1 = (B-1); // Both only win
            long long d2 = A + (B-A-1)/2; // A wins until distance is even, then meet inbetween
            r = (d1 <= d2) ? d1 : d2;
        } else { // B is closer to the right end
            long long d1 = (N-A); // Both only lose
            long long d2 = (N-B+1) + (N-((N-B+1)+A))/2; // B loses until distance is even, then meet inbetween
            r = (d1 <= d2) ? d1 : d2;
        }
    }
    printf("%ld\n", r);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,i,j,rn,gn,bn,ma,mi,d;
  int64_t c;
  string s;
  cin>>n>>s;
  vector<int> r(n),g(n),b(n);
  rn=0; gn=0; bn=0;
  for(i=0;i<n;i++){
    if(s.at(i)=='R') {r.at(rn)=i; rn++;}
    else if(s.at(i)=='G') {g.at(gn)=i; gn++;}
    else if(s.at(i)=='B') {b.at(bn)=i; bn++;}
  }
  c=(int64_t)rn*gn*bn;
  for(i=0;i<rn;i++){
    for(j=0;j<gn;j++){
      ma=max(r.at(i),g.at(j));
      mi=min(r.at(i),g.at(j));
      d=ma-mi;
      if (mi-d>=0 && s.at(mi-d)=='B') c--;
      if (ma+d<n && s.at(ma+d)=='B') c--;
      if (d%2==0 && s.at((ma+mi)/2)=='B') c--;
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 3652
import math
import fractions
from collections import Counter as ct

def gcd_list(l):
    for n,i in enumerate(l):
        if n==0:cur=i
        cur=fractions.gcd(cur,i)
    return cur

def yakusulist(n):
    ans=[]
    for i in range(1,int(math.sqrt(n+1))+1):
        if n%i==0:
            ans.append(i)
            ans.append(n//i)
    return(set(ans))
    
def warennnokaomaera(n):
    warenai=0
    for k,i in enumerate(A):
        if i%n and warenai==0:
            warenai+=1
            continue
        if i%n and warenai:return(False)
    return(True)

N=int(input())
data=[int(i) for i in input().split()]
datagcd=gcd_list(data)
A=[i//datagcd for i in data]
if N>2:
    co=ct(A)
    alpha=sorted(co.keys())
    if len(alpha)>=3:
        min3=[alpha[0],alpha[1],alpha[2]]
        p,q,r=[yakusulist(n) for n in min3]
        pq=p&q
        qr=q&r
        rp=r&p
        overtwo=pq|qr|rp
        overtwo=sorted(list(overtwo),reverse=True)
        for i in overtwo:
            if warennnokaomaera(i):
                print(datagcd*i)
                break
    elif len(alpha)==2:#Aの数の種類が2種類以下->1個書き換えで違う数ってどっちかが一個じゃないと無理、それ以外はそのまま
        if co[alpha[0]]==1:
            print(datagcd*alpha[1])
        elif co[alpha[1]]==1:
            print(datagcd*alpha[0])
        else:print(datagcd)
    else:print(datagcd)
else:print(max(data))

Measured memory_bytes: 16600
import java.util.Scanner;

public class Main {

    private static long totalSum = 0;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String number = scan.next();
        helper(0,number,"");
        System.out.println(totalSum);
    }

    private static void helper(int index, String orig, String formatted){

        if(index == orig.length()){
            String[] numbers = formatted.split("\\+");
            long sum = 0;
            for(String num : numbers){
                sum += Long.parseLong(num);
            }
            totalSum += sum;
            return;
        }

        if(index < orig.length()-1)
           helper(index+1, orig, formatted + orig.charAt(index) + "+");
        helper(index+1, orig, formatted + orig.charAt(index));
    }
}

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

int main() {
	int n;
	while (cin >> n, n) {
		int p[1000];
		for (int i = 0;i < n;i++) {
			cin >> p[i];
		}
		sort(p, p + n);
		int s = 0;
		for (int i = 1;i < n - 1;i++) {
			s += p[i];
		}
		cout << s / (n - 2) << endl;
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  for(int i = 1; i <= n; i++){
     cin >> a.at(i);
  }

  for(int i = 1; i <= n; i++){
    cout << "node " << i << ": key = " << a.at(i) << ", ";
    if(i != 1){
      cout << "parent key = " << a.at(i/2) << ", ";
    }
    if(2*i <= n){
      cout << "left key = " << a.at(2*i) << ", ";
    }
    if(2*i+1 <= n){
      cout << "right key = " << a.at(2*i+1) << ", ";
    }
    cout << endl;
  }
  
}


Measured memory_bytes: 3108
#include <string>
#include <iostream>
#define DICE_FACE_SIZE 6
using namespace std;

int main() {
  int dice[DICE_FACE_SIZE + 1];
  string commands;

  for(int i = 0; i < DICE_FACE_SIZE; i++) {
    cin >> dice[i + 1];
  }
  cin >> commands;

  int east_label = 3;
  int west_label = 4;
  int north_label = 5;
  int south_label = 2;
  int top_label = 1;
  int bottom_label = 6;

  for(int i = 0; i < commands.size(); i++) {
     double before_bottom_label;

    switch(commands[i]) {
      case 'N':
        before_bottom_label = 7 - top_label;

        bottom_label = north_label;
        north_label = top_label;
        top_label = south_label;
        south_label = before_bottom_label;

        break;
      case 'E':
        before_bottom_label = 7 - top_label;

        bottom_label = east_label;
        east_label = top_label;
        top_label = west_label;
        west_label = before_bottom_label;
        break;
      case 'S':
        before_bottom_label = 7 - top_label;

        bottom_label = south_label;
        south_label = top_label;
        top_label = north_label;
        north_label = before_bottom_label;
        break;
      case 'W':
        before_bottom_label = 7 - top_label;

        bottom_label = west_label;
        west_label = top_label;
        top_label = east_label;
        east_label = before_bottom_label;
        break;
    }
  }

  cout << dice[top_label] << endl;
}



Measured memory_bytes: 3208
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <iostream>
using namespace std;

constexpr long long mod = 1000000007;

long long expr(string::const_reverse_iterator &it);
long long term(string::const_reverse_iterator &it);
long long number(string::const_reverse_iterator &it);

long long expr(string::const_reverse_iterator &it) {
	long long res = term(it);
	if(*it == '>') {
		++it;
		assert(*it == '>');
		++it;
		res = (expr(it) >> min(32ll, res));
	}
	return res;
}

long long term(string::const_reverse_iterator &it) {
	if(isdigit(*it)) return number(it);

	assert(*it == '>');
	++it;
	long long res = expr(it);
	assert(*it == '<');
	++it;
	assert(*it == 'S');
	++it;
	return (res * res) % mod;
}

long long number(string::const_reverse_iterator &it) {
	long long res = 0;
	for(int d = 1; isdigit(*it); d *= 10, ++it) {
		res += d * (*it - '0');
	}
	return res;
}

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

	for(string expression; getline(cin, expression) && expression != "#";) {
		expression.erase(remove(expression.begin(), expression.end(), ' '), expression.end());
		auto it = expression.crbegin();
		cout << expr(it) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2876
K = gets.to_i
lunluns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
K.times do |i|
  break if lunluns.length > K
  if lunluns[i] % 10 == 0
    lunluns << lunluns[i] * 10
    lunluns << lunluns[i] * 10 + 1
  elsif lunluns[i] % 10 == 9
    lunluns << lunluns[i] * 10 + 8
    lunluns << lunluns[i] * 10 + 9
  else
    lunluns << lunluns[i] * 10 + lunluns[i] % 10 - 1
    lunluns << lunluns[i] * 10 + lunluns[i] % 10
    lunluns << lunluns[i] * 10 + lunluns[i] % 10 + 1
  end
end
puts lunluns[K - 1]

Measured memory_bytes: 2684
#include <stdio.h>

int main()
{
	int a, b;
	int temp, min, max;
	int gcd = 1;

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

	if (a > b)
	{
		max = a;
		min = b;
	}
	else
	{
		max = b;
		min = a;
	}

	while (1)
	{
		if (max % min == 0)
		{
			gcd = min;
			break;
		}
		temp = min;
		min = max % min;
		max = temp;
	}

	printf("%d\n", gcd);

	return 0;

}


Measured memory_bytes: 2080
N = int(input())

ans = [0] * N
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            n = x * x + y * y + z * z + x * y + y * z + z * x
            if n <= N:
                ans[n-1] += 1

for i in ans:
    print(i)


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

#define PI 3.141592653589793

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  priority_queue <int> pq;
  double r;
  cin >> r;
  double ans = r * (double)PI * (double)2;
  printf("%.20f\n", ans);
  return 0;
}

Measured memory_bytes: 3760