akhauriyash/Code-Regression huggingface dataset:
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<stw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;
using Graph = vector<vector<int>>;

vector<bool> seen;
vector<int> groupK;
vector<int> groupN;
int g = -1;
void dfs(const Graph &G, int v){
    seen[v] = true;
    groupK[v] = g;
    groupN[g]++; 
    for(auto next_v:G[v]){
        if(seen[next_v]) continue;
        dfs(G,next_v);
    }
}

int main(void){
    int N,M,K;cin>>N>>M>>K;
    Graph G(N),B(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i=0;i<K;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        B[a].push_back(b);
        B[b].push_back(a);
    }
    seen.assign(N,false);
    groupK.assign(N,-1);
    for(int i=0;i<N;i++){
        if(seen[i]==false){
            g++;
            groupN.push_back(0);
            dfs(G,i);
        }
    }
    int count;
    for(int i=0;i<N;i++){
        count = groupN[groupK[i]];
        count -= G[i].size();
        for(auto b:B[i]){
            if(groupK[i]==groupK[b]){
                count--;
            }
        }
        cout << count-1 << " ";
    }
    cout << endl;
}

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

typedef long long ll;

int main()
{
    int l, r, lmod, rmod, ldiv, rdiv;
    cin >> l >> r;

    lmod = l % 2019;
    rmod = r % 2019;
    ldiv = l / 2019;
    rdiv = r / 2019;
    int ans = 2019;
    if (lmod < rmod && ldiv == rdiv){
        for (int i = lmod; i < rmod + 1; i++)
        {
            for (int j = i + 1; j < rmod + 1; j++)
            {
                ans = min(ans, (i * j) % 2019);
            }
        }
    } else {
        ans = 0;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int  a,b,c;
    cin >> a >> b >> c;
    int i=1;
    int ans=0;
    while(1){
        if((a*i)%b==c) break;
        if(i>100){
            ans=1;
            break;
        }
        i++;
    }

    if(ans==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  cout << min(B / A, C) << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

left_gcd = [0]*(n+1)
right_gcd = [0]*(n+1)
left_gcd[1] = a[0]
right_gcd[1] = a[-1]


for i in range(1,n):
    left_gcd[i+1] = gcd(left_gcd[i],a[i])
    right_gcd[i+1] = gcd(right_gcd[i],a[-1-i])

ans = right_gcd[n-1]
for i in range(n):
    ans = max(ans,gcd(left_gcd[i],right_gcd[n-1-i]))

print(ans)


Measured memory_bytes: 14400
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define endl '\n'
using namespace std;

int dp[100007];
int h[100007];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    for(ll i=0; i<n; i++){
        cin>>h[i];
        dp[i] = mod;
    }
    dp[0]=0;
    for(ll i=0; i<n; i++){
        for(ll j=1; j<=k; j++){
            if(n>i+j)
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<dp[n-1]<<endl;



return 0;
}


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

int main(){
  int L,R,d;
  cin >> L >> R >> d;
  int ans = R/d -L/d;
  if(L % d == 0){
    ans++;
  }
  cout << ans << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/07/27  Problem: ABC 135 F / Link: http://abc135.contest.atcoder.jp/tasks/abc135_f  ----- */

struct RHMOD {
	RHMOD() {}RHMOD(const string &S) : S_(S) { int n = (int)S.size(); for (int iter = 0; iter < SZ(mod); ++iter) { hash[iter].assign(n + 1, 0); power[iter].assign(n + 1, 1); for (int i = 0; i < n; ++i) { hash[iter][i + 1] = (hash[iter][i] * base + S[i]) % mod[iter]; power[iter][i + 1] = power[iter][i] * base % mod[iter]; } } }
	inline long long get(int l, int r, int id = 0) const { long long res = hash[id][r] - hash[id][l] * power[id][r - l] % mod[id]; if (res < 0) res += mod[id]; return res; }
	inline int getLongestPrefixSum(int a, int b) const { int len = min((int)S_.size() - a, (int)S_.size() - b); int low = -1, high = len + 1; while (high - low > 1) { int mid = (low + high) / 2; if (get(a, a + mid, 0) != get(b, b + mid, 0)) high = mid; else if (get(a, a + mid, 1) != get(b, b + mid, 1)) high = mid; else low = mid; }return low; }const int base = 9973; const vector<int> mod = { 999999937LL, 1000000007LL }; string S_; vector<long long> hash[2], power[2];
};

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

	string s, t;
	cin >> s >> t;
	int c_s = SZ(s);
	int cur_sz = c_s + 2 + SZ(t);
	string TEXT = s;
	{
		TEXT += "!!"; // 2!
		TEXT += t;
	}
	{
		while (cur_sz < 2 * c_s) {
			cur_sz += SZ(t);
			TEXT += t;
		}
	}
	int tsumlength = -2 - c_s + cur_sz;
	RHMOD superhash(TEXT);

	int ans = 0;
	FOR(spos, 0, c_s) {
		int cur_t = 0;
		int cur_s = spos;
		DD(de(cur_t, "test---"));
		int sumS = 0; {
			while (INF) {
				int tidx = c_s + 2 + cur_t;
				int tlcp = superhash.getLongestPrefixSum(cur_s, tidx);
				if (tlcp == 0)break;
				sumS += tlcp;
				DD(de(cur_t, cur_s, "deg", tlcp));
				cur_t += tlcp;	cur_t %= tsumlength;
				cur_s += tlcp;	cur_s %= c_s;
				DD(de("aft,", cur_t, cur_s))
					if (sumS >= 2 * max(c_s, tsumlength)) {
						DD(de("inf."));
						ans = INF;
						break;
					}
			}
		}
		DD(de("sub end"));
		if (ans == INF)break;
		else {
			int ret = sumS / SZ(t);
			DD(de(ret));
			ans = max(ans, ret);
		}
	}

	if (ans == INF)cout << "-1\n";
	else cout << ans << "\n";

	return 0;
}




Measured memory_bytes: 50120
import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int q=scan.nextInt();
		String eg=scan.next();
		int prefix[]=new int[n];
		for(int i=1;i<n;i++)
		{
			if(eg.charAt(i)=='C'&& eg.charAt(i-1)=='A') {
				prefix[i]=prefix[i-1]+1;
			}else {
				prefix[i]=prefix[i-1];
			}
		}
		for(int i=0;i<q;i++)
		{
			int l=scan.nextInt();
			int r=scan.nextInt();
			r--;
			l--;
			System.out.println(prefix[r]-prefix[l]);
		}
			
		
	}
}


Measured memory_bytes: 64012
#include <iostream>

using namespace std;

int main()
{
	int A, B, C, X;
	int cnt = 0;
	cin >> A >> B >> C >> X;
	for (int a = 0; a <= A; ++a) {
		for (int b = 0; b <= B; ++b) {
			for (int c = 0; c <= C; ++c) {
				if (a * 500 + b * 100 + c * 50 == X) {
					++cnt;
				}
			}
		}
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3144
function main(input) {
    const S = input.split(' ');
    const a = parseInt(S[0], 10);
    const b = parseInt(S[1], 10);
    const c = parseInt(S[2], 10);

    if (a+b+c >= 22) {
      console.log("bust");
    }else {
      console.log("win");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

int main()
{
  int a,b,c,d,l,r;
  cin>>a>>b>>c>>d;
  l=a+b;
  r=c+d;

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


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
using namespace std;
bool match(string s, string t) {
	for (int i = 0; i < 8; i++) {
		if (s[i] != '?' && s[i] != t[i]) return false;
	}
	return true;
}
int n, m; bool x[1111]; string r1[1111], r2[1111], a, b, c;
int main() {
	while (cin >> n >> m, n | m) {
		for (int i = 0; i < n; i++) {
			cin >> a >> r1[i] >> r2[i];
			if (a == "permit") x[i] = true;
			else x[i] = false;
		}
		int ret = 0; vector<string> v1, v2, v3;
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> c;
			bool p1 = false, p2 = false;
			for (int j = n - 1; j >= 0; j--) {
				if (match(r1[j], a) && match(r2[j], b)) {
					if (x[j]) p1 = true;
					else p2 = true;
					break;
				}
			}
			if (p1) {
				v1.push_back(a);
				v2.push_back(b);
				v3.push_back(c);
				ret++;
			}
		}
		cout << ret << endl;
		for (int i = 0; i < ret; i++) {
			cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << endl;
		}
	}
}

Measured memory_bytes: 3200
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5;
ll a[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll x, y;
    cin >> x >> y;
    cout << (x * y) / (__gcd(x, y));
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
  int id;
  int parents;
  int sibling;
  int child1;
  int child2;
}Tree;

int main(void){
  int i,j,k,l,n,id,left,right,depth,height,temp, s_temp, root;
  Tree tree[25];

  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ){
    tree[i].parents = -1;
    tree[i].sibling = -1;
    tree[i].child1 = -1;
    tree[i].child2 = -1;
  }

  for( i = 0 ; i < n ; i++ ){
    scanf("%d %d %d",&id,&left,&right);
    tree[i].id = id;
    tree[i].child1 = left;
    tree[i].child2 = right;
  }

  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ){
      if( tree[i].id == tree[j].child1 ){
	tree[i].parents = tree[j].id;
	tree[i].sibling = tree[j].child2;
      }
      if( tree[i].id == tree[j].child2 ){
	tree[i].parents = tree[j].id;
	tree[i].sibling = tree[j].child1;
      }
    }
  }  
  
  for(i = 0 ; i < n ; i++ ){
    if( tree[i].parents == -1 ){
      root = tree[i].id;
    }
  }
  
  /*bublle sort */
  for( i = 0 ; i < n - 1 ; i++ ){
    for( j = n - 1 ; j > i ; j-- ){
      if( tree[j - 1].id > tree[j].id ){
	s_temp = tree[j].id;
	tree[j].id = tree[j - 1].id;
	tree[j - 1].id = s_temp;
        s_temp = tree[j].parents;
        tree[j].parents = tree[j - 1].parents;
        tree[j - 1].parents = s_temp;
        s_temp = tree[j].sibling;
        tree[j].sibling = tree[j - 1].sibling;
        tree[j - 1].sibling = s_temp;
        s_temp = tree[j].child1;
        tree[j].child1 = tree[j - 1].child1;
        tree[j - 1].child1 = s_temp;
        s_temp = tree[j].child2;
        tree[j].child2 = tree[j - 1].child2;
        tree[j - 1].child2 = s_temp;
      }
    }
  }


  for( i = 0 ; i < n ; i++ ){
    depth = 0;
    printf("node %d: parent = %d, sibling = %d, ",tree[i].id, tree[i].parents, tree[i].sibling);
    for( j = 0 ; j < n ; j++ ){
      if( tree[i].child1 != -1 && tree[i].child2 != -1 ){
	printf("degree = 2, ");
	break;
      }
      else if( tree[i].child1 == -1 && tree[i].child2 == -1 ){
	printf("degree = 0, ");
	break;
      }
      else if( tree[i].child1 != -1 || tree[i].child2 != -1 ){
	printf("degree = 1, ");
	break;
      }
    }

    j = i;
    while(1){
      if( tree[j].id == root ){
	printf("depth = %d, ",depth);
	break;
      }
      else{
	j = tree[j].parents;
	depth++;
      }
    }

    height = 0;
    for( j = 0 ; j < n ; j++ ){
      temp = 0;
      k = j;
      if( tree[i].id == tree[j].id && tree[j].child1 == -1 && tree[j].child2 == -1 ) break;
      while(1){
	if( tree[k].parents == tree[i].id ){
	  temp++;
	  if( height <= temp ){
	    height = temp;
	  }
	  break;
	}
	else if( tree[k].parents == -1 ){
	  break;
	}
	else{
	  k = tree[k].parents;
	  temp++;
	}
      }
    }
    printf("height = %d, ",height);
    if( depth == 0 ) printf("root\n");
    else if( height == 0 ) printf("leaf\n");
    else printf("internal node\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(void) {
  ll X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X, 0), B(Y, 0), C(Z, 0);
  for (int i = 0; i < X; i++) { cin >> A[i]; } 
  for (int i = 0; i < Y; i++) { cin >> B[i]; } 
  for (int i = 0; i < Z; i++) { cin >> C[i]; }
  sort(A.begin(), A.end()); reverse(A.begin(), A.end());
  sort(B.begin(), B.end()); reverse(B.begin(), B.end());
  sort(C.begin(), C.end()); reverse(C.begin(), C.end());

  vector<ll> scores;
  for (int i = 0; i < X; i++) {
      for (int j = 0; j < Y; j++)
          scores.push_back(A[i] + B[j]);
  }
  sort(scores.begin(), scores.end()); reverse(scores.begin(), scores.end());

  vector<ll> scores2;
  auto v = min(K, (ll)scores.size());
  for (int i = 0; i < v; i++) {
      for (int j = 0; j < Z; j++) {
          scores2.push_back(scores[i] + C[j]);
      }
  }
  sort(scores2.begin(), scores2.end()); reverse(scores2.begin(), scores2.end());
  for (int i = 0; i < K; i++)
    cout << scores2[i] << endl;
}


Measured memory_bytes: 43412
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    int N,X;
    cin >> N >> X;
    vector<int> L(N);
    int ct = 1;
    int sum = 0;
    rep(i,N){
        cin >> L[i];
        sum += L[i];
        if(sum <= X) ct++;
    }    
    pr(ct);
}

Measured memory_bytes: 384
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let H = read![[i64]];

    let mut dp = vec![std::i64::MAX; N];
    dp[0] = 0;
    for i in 0..N {
        if i + 1 < N {
            dp[i + 1] = min(dp[i + 1], dp[i] + (H[i] - H[i + 1]).abs())
        }
        if i + 2 < N {
            dp[i + 2] = min(dp[i + 2], dp[i] + (H[i] - H[i + 2]).abs())
        }
    }

    println!("{}", dp[N - 1])
}


Measured memory_bytes: 6396
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    tmp = 1
    tmp2 = 0
    B = A[0]
    if N == 2:
        print(max(A))
    else:
        D = A[0]
        E = A[1]
        for i in range(2,N):
            D = gcd(D,A[i])
            E = gcd(E,A[i])
        for i in range(1,N):
            if B/gcd(B,A[i]) > tmp2 or gcd(A[i],tmp2) < tmp2:
                tmp = i
                tmp2 = B/gcd(B,A[i])
            B = gcd(B,A[i])
        C = A[0]
        for i in range(1,tmp):
            C = gcd(C,A[i])
        for i in range(tmp+1,N):
            C = gcd(C,A[i])
        print(max(C,D,E))
    
    
main()

Measured memory_bytes: 85228
# Queue
class Array
  alias_method :enqueue, :push
  alias_method :dequeue, :shift
end

# u : Index of nodes starting from 1...N
# k : degree of this node
# v : array of vertices connected with this node
# c : :white(=undiscovered), :gray(=frontier), :black(finished searching)
# d : distance when the vertex is first discovered
# pi: predecessor vertex
Node = Struct.new(:u, :k, :v, :c, :d, :pi)

class Graph

  attr :nodes, true

  def initialize(n)
    @nodes = Array.new(n){ Node.new }
  end

  def add_graph_node(u, v)
    @nodes[u-1].u = u
    if not v.nil?
      (@nodes[u-1].v ||= []).push(v)
      @nodes[u-1].k = @nodes[u-1].v.length ||= 0
    else
      @nodes[u-1].v = [] if @nodes[u-1].v.nil?
      @nodes[u-1].k = 0
    end
    @nodes[u-1].c = :white
    @nodes[u-1].d = -1
    @nodes[u-1].pi = nil
  end

  def reset()
    @nodes.each do |node|
      node.c  = :white
      node.d  = -1
      node.pi = nil
    end
  end

  def dist()
    puts "d : #{@nodes.map{|node| node.d}.to_a.to_s}"
    puts "pi: #{@nodes.map{|node| node.pi}.to_a.to_s}"
  end

  def bfs(start, queue)

    start_idx = (start - 1).to_i
    @nodes[start_idx].c  = :gray
    @nodes[start_idx].d  = 0
    @nodes[start_idx].pi = nil
    queue.enqueue(@nodes[start_idx])

    while not queue.empty?

      u = queue.dequeue
      break if u.v.nil?

      u.v.each do |label|
        v = @nodes[label-1]
        if v.c == :white
          v.c  = :gray
          v.d  = u.d.to_i + 1
          v.pi = u
          queue.enqueue(v)
        end
      end
      u.c = :black
    end
  end
end

# start
lines = $stdin.read
array = lines.split("\n")

N     = array[0].to_i
graph = Graph.new(N)

for i in 1...N+1
  seps = array[i].split(" ")
  u    = seps.drop(0)[0].to_i
  k    = seps.drop(1)[0].to_i
  vs   = seps.drop(2).map(&:to_i)
  #puts "add_graph_node(#{u} <--> #{v})"
  for v in vs
    graph.add_graph_node(u, v)
  end
  graph.add_graph_node(u, nil) if vs.length == 0
end

graph.bfs(1, [])

graph.nodes.each_with_index do |elem, idx|
    puts "#{idx+1} #{graph.nodes[idx].d.to_i}"
end

Measured memory_bytes: 8932
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    if(A>=K) printf("%d",K);
    else if(A+B>=K) printf("%d",A);
    else printf("%d",A-(K-A-B));
    return 0;
}


Measured memory_bytes: 3728
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
using namespace std ;

int n, x ;

int main() {
	scanf("%d", &n) ;
	int mn = 1000, sum = 0 ;
	rep(i, 1, n) {
		scanf("%d", &x) ;
		sum += x ;
		if (x % 10) mn = min(mn, x) ;
	}
	if (sum % 10) {
		printf("%d\n", sum) ;
		return 0 ;
	}
	if (mn == 1000) printf("0\n") ;
		else printf("%d\n", sum - mn) ;
	return 0 ;
}

Measured memory_bytes: 256
#include <algorithm>
  #include <bitset>
  #include <complex>
  #include <deque>
  #include <exception>
  #include <fstream>
  #include <functional>
  #include <iomanip>
  #include <ios>
  #include <iosfwd>
  #include <iostream>
  #include <istream>
  #include <iterator>
  #include <limits>
  #include <list>
  #include <locale>
  #include <map>
  #include <memory>
  #include <new>
  #include <numeric>
  #include <ostream>
  #include <queue>
  #include <set>
  #include <sstream>
  #include <stack>
  #include <stdexcept>
  #include <streambuf>
  #include <string>
  #include <typeinfo>
  #include <utility>
  #include <valarray>
  #include <vector>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> number;
    while(N>0)
    {
        number.push_back(N%10);
        N/=10;
    }

    switch (number[0])
    {
    case 2: case 4: case 5: case 7: case 9:
        cout << "hon"<< "\n";
        break;
    case 0: case 1: case 6: case 8:
        cout << "pon"<< "\n";
        break;
    case 3:
        cout << "bon"<< "\n";
        break;
    default:
        break;
    }



}

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

using namespace std;

int w, h, x, y;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> w >> h >> x >> y;
    long long ans = 1LL * w * h;
    cout << ans / 2 << "." << 5 * (ans % 2) << " ";
    if (2 * x == w && 2 * y == h) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A, B = [], []
    for n in range(N):
        a, b = il()
        A.append(a)
        B.append(b)

    ret = 0
    for n in reversed(range(N)):
        if (A[n] + ret) % B[n] == 0: continue
        else:
            ret += B[n] - ((A[n] + ret) % B[n])
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18004
#include <bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<int,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

int main(){
  ll N,K,a;cin>>N>>K;
  vector<ll> neg_v{0},pos_v{0};
  REP(i,0,N){
    cin>>a;
    if(a<0){neg_v.emplace_back(-a);}
    else {pos_v.emplace_back(a);}
  }
  sort(all(neg_v));sort(all(pos_v));

  ll i=min(K,(ll)neg_v.size()-1),j=K-i;
  ll ans=1000000007;
  // if(i==K){
  //   ans=min(ans,neg_v[K]);
  // }
  // if(i==1){
  //   ans=min(ans,pos_v[K]);
  // }
  while((0<=i)&&(j<=min(K,(ll)pos_v.size()-1))){
    ans=min(ans,2*min(neg_v[i],pos_v[j])+max(neg_v[i],pos_v[j]));
    i--;j++;
  }
  print(ans)

}


Measured memory_bytes: 1656
#include "iostream"
using namespace std;

const int N = 100;

int a[100];

int main()
{
    for (int i = 1; i <= 9;i++)
    {
        for (int j = 1; j <= 9;j++)
            a[i * j] = 1;
    }
    int n;
    cin >> n;
    if(a[n])
        cout << "Yes";
    else
        cout << "No";
}   

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int W, H; cin >> W >> H;
  ll p[W+1]; FOR(i,0,W) cin >> p[i];
  ll q[H+1]; FOR(i,0,H) cin >> q[i];
  p[W] = q[H] = 1e9;
  sort(p, p + W);
  sort(q, q + H);
  int x = 0, y = 0;
  ll cost = 0;
  while(x < W || y < H) {
    if(p[x] < q[y]) {
      cost += p[x] * (H + 1 - y);
      x++;
    } else {
      cost += q[y] * (W + 1 - x);
      y++;
    }
  }
  cout << cost << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 1000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MAX_INT = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    string s;
    cin >> s;
    int curr = 0, ans = 0;
    for (char c : s)
    {
        if (c == 'I')
            curr++;
        else
            curr--;
        ans = max(ans, curr);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
nums = [str(e) for e in range(10)]
a, b = map(int, input().split())
S = input()
flag = True
for idx in range(len(S)):
  if idx == a:
    if S[idx] != '-':
      flag = False
      break
  else:
    if S[idx] not in nums:
      flag = False
      break

print('Yes' if flag else 'No')

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

int main(){
    vector<ll> start(100000,1e+9);
    ll n,q;
    string s;
    cin>>n>>q>>s;
    ll count=0;
    for(ll i=0;i<n;i++)
    {
        if(s[i] == 'A' && s[i+1] == 'C')
        {
            start[count] = i;
            count++;
        }
    }

    
    //count:AC総数

    for(ll i=0;i<q;i++)
    {
        ll l,r;
        cin>>l>>r;
        l--;r--;
        auto it1 = lower_bound(start.begin(),start.end(),l);
        auto it2 = lower_bound(start.begin(),start.end(),r);
        ll j = distance(it1,start.begin());
        ll k = distance(it2,start.begin());

        cout<<j-k<<endl;

    }
}

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

inline bool ok(int x, int y, int h, int w) {
    return 0 <= x && x < h && 0 <= y && y < w;
}

bool adjust(int i, int &x, int &y, int h, int w) {
    // cerr << i << ' ' << x << ' ' << y << ' ';
    if (i == -1 && (x + y < 0 || x + y >= h + w - 1)) return false;
    if (i == 1 && (x - y <= -w || x - y >= h)) return false;
    if (x < 0) { y -= i * x; x = 0; }
    if (x >= h) { y -= i * (x - h + 1); x = h-1; }
    if (y < 0) { x -= i * y; y = 0; }
    if (y >= w) { x -= i * (y - w + 1); y = w-1; }
    // cerr << x << ' ' << y << endl;
    return true;
}

int main(int argc, char** argv) {
    int h, w; cin >> h >> w;
    string s[301]; for (int i = 0; i < h; i++) cin >> s[i];
    int sum[2][301][301] = {}; // 0: left downward, 1: right downward
    for (int x = 0; x < h; x++)
        for (int y = 0; y < w; y++) {
            sum[0][x][y] = (s[x][y] == '#');
            sum[1][x][y] = (s[x][y] == '#');
            if (x > 0 && y < w-1) sum[0][x][y] += sum[0][x-1][y+1];
            if (x > 0 && y > 0) sum[1][x][y] += sum[1][x-1][y-1];
        }

    long long ans = 0;
    for (int x = 0; x < h; x++)
        for (int y = 0; y < w; y++) {
            if (s[x][y] == '.') continue;
            for (int d = 1; d <= min(h, w); d++) {
                for (int i : {1, -1}) {
                    int x1 = x + d, y1 = y + d * i;
                    if (!ok(x1, y1, h, w) || s[x1][y1] == '.') continue;
                    int x2 = x + d, y2 = y - d * i,
                        x3 = x2 + d, y3 = y2 + d * i,
                        dir = (i > 0 ? 1 : 0);
                    if (i == 1 && ok(x2, y2, h, w) && s[x2][y2] == '#') ans--;
                    if (i == 1 && ok(x3, y3, h, w) && s[x3][y3] == '#') ans--;
                    if (adjust(i, x2, y2, h, w) && adjust(i, x3, y3, h, w)) {
                        ans += sum[dir][x3][y3];
                        if (dir == 0 && x2 > 0 && y2 < w-1) ans -= sum[dir][x2-1][y2+1];
                        if (dir == 1 && x2 > 0 && y2 > 0) ans -= sum[dir][x2-1][y2-1];
                    }
                                        x2 = x - d;  y2 = y + d * i;
                    x3 = x2 + d; y3 = y2 + d * i;
                    if (i == 1 && ok(x2, y2, h, w) && s[x2][y2] == '#') ans--;
                    if (i == 1 && ok(x3, y3, h, w) && s[x3][y3] == '#') ans--;
                                        if (adjust(i, x2, y2, h, w) && adjust(i, x3, y3, h, w)) {
                        ans += sum[dir][x3][y3];
                        if (dir == 0 && x2 > 0 && y2 < w-1) ans -= sum[dir][x2-1][y2+1];
                        if (dir == 1 && x2 > 0 && y2 > 0) ans -= sum[dir][x2-1][y2-1];
                    }
                }
            }
        }
    cout << ans << endl;
}


Measured memory_bytes: 1152
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int a,b,c,d,e,f,k,l,m,n,x,y,z;
	int ans;
	String[] S;

	Main(){
		// 整数の入力
		n = sc.nextInt();
		k = sc.nextInt();

		for(int i=0;i<n;i++){
			ans+=sc.nextInt()<k?0:1;
		}

		// 出力
		System.out.println(ans);
	}

	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 47092
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n;
    double x[max], ans=0;
    char u[max][4];
    
    scanf("%d", &n);
    rep(i, n){
        scanf("%lf%s", &x[i], u[i]);
    }
    
    rep(i, n){
        if (!strcmp(u[i], "JPY")) {
            ans+=x[i];
        } else if (!strcmp(u[i], "BTC")) {
            ans+=x[i]*380000;
        }
    }
    
    printf("%lf", ans);
    
    return 0;
}


Measured memory_bytes: 1760
#include<stdio.h>
int main()
{
	double l,r;
	int al=0,bl=0,cl=0,dl=0,ar=0,br=0,cr=0,dr=0;
	while(scanf("%lf%lf",&l,&r)!=EOF){
		if(l>=1.1){
			al++;
		}else if(l>=0.6){
			bl++;
		}else if(l>=0.2){
			cl++;
		}else{
			dl++;
		}
		if(r>=1.1){
			ar++;
		}else if(r>=0.6){
			br++;
		}else if(r>=0.2){
			cr++;
		}else{
			dr++;
		}
	}
	printf("%d %d\n%d %d\n%d %d\n%d %d\n",al,ar,bl,br,cl,cr,dl,dr);
	return 0;
}

Measured memory_bytes: 2580
#include<iostream>
using namespace std;
typedef long long LL;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	LL n, m; cin >> n >> m;
	LL ans = 0;

	LL make1 = min(n,m/2);
	ans += make1;
	n -= make1;
	m -= 2*make1;

	if(m >= 2)
		ans += m/4;

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

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

int main(){
  int n,a,d;
  cin>>n>>a>>d;
  
  map<int,int> mp;
  int m;
  
  cin>>m;
  for(int i=0;i<m;i++){
    int x,y,z;
    cin>>x>>y>>z;
    
    if(mp[y]==0){
      mp[y]=y;
    }
    
    if(mp[z]==0){
      mp[z]=z;
    }
    
    if(x==0){
      swap(mp[y],mp[z]);
    }else{
      mp[y]=mp[z];
    }
  }
  
  int k;
  cin>>k;
  
  if(mp[k]==0){
    mp[k]=k;
  }
  cout<<a+(mp[k]-1)*d<<endl;
  return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    long long n, m;
    cin >> n >> m;
    vector<int> as(m);
    vector<int> bs(m);
    map<int, int> cnt;
    for (int i = 0; i < m; i++) {
        cin >> as[i];
        cin >> bs[i];
        cnt[as[i]]++;
        cnt[bs[i]]++;
    }
    REP(i, n) { cout << cnt[i + 1] << endl; }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
// #define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int k;
    string s;
    cin >> k >> s;
    if (sz(s) <= k)
        cout << s << endl;
    else
        cout << s.substr(0, k) + "..." << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

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

int main(){
  string s,t;	cin >> s >> t;
  
  int m=0;
  for(int i=0;i<=s.size()-t.size();i++){
    int c=0;
    for(int j=0;j<t.size();j++){
      if(s[i+j]==t[j])	c++;
    }
    m=max(m,c);
  }
  cout << t.size()-m;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	int ns[50],e=0;
	scanf("%lld",&n);
	if(n == 0)
	{
		printf("0");
		return 0;
	}
	while(n != 0)
	{
		if(n%-2 == 0)
		{
			ns[e++] = 0;
			n /= -2;
		}
		else
		{
			ns[e++] = 1;
			n = (n-1)/-2;
		}
	}
	while(e--)
		printf("%d",ns[e]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
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;}

int main(){
  ll n, k;
  cin >> n >> k;

  ll ans = 0;
  ll wareru = n / k;
  ans += pow(wareru, 3);

  if(k % 2 == 0){
    ll cnt = (n + k/2) / k;
    ans += pow(cnt, 3);
  }

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

Measured memory_bytes: 256
//NOOOOO

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

int main(){
	string s;
	cin >> s;
	while (!s.empty()){
		if (s.substr(0, 7)=="dreamer"){
			if (s.substr(5, 5)=="erase") s.erase(0, 5);
			else s.erase(0, 7);
		}
		else if (s.substr(0, 6)=="eraser") s.erase(0, 6);
		else if (s.substr(0, 5)=="erase" || s.substr(0, 5)=="dream") s.erase(0, 5);
		else{
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int a[256];

int main(){
	int n, l; scanf("%d%d", &n, &l);
	REP(i, n) a[i]=l+i;
	int mi = 114514;
	REP(i, n) if(abs(mi)>abs(a[i])) mi=a[i];
	int sm = 0;
	REP(i, n) sm += a[i];
	printf("%d\n", sm-mi);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.

int main() {
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	int n;
	cin>>n;
	VI arr(n);
	int zero = 0;
	rep(i,0,n){
		cin>>arr[i];
		if(arr[i] == 0)
			zero++;
	}
	int ans = 0;
	while(zero < n){
		int mi = INT_MAX;
		int seen = 0;
		rep(i,0,n){
			if(arr[i]){
				if(i == 0)
					seen = 1;
				mi = min(mi, arr[i]);
			}
			else{
				if(seen && arr[i-1] != 0)
					break;
				else
					seen = 1;
			}
		}
		seen = 0;
		VI temp = arr;
		rep(i,0,n){
			if(arr[i]){
				if(i == 0)
					seen = 1;
				arr[i] -= mi;
				if((arr[i]) == 0)
					zero++;
			}
			else{
				if(seen && temp[i-1] != 0)
					break;
				else
					seen = 1;
			}
		}
		// cout<<"mi : "<<mi<<"\n";
		// cout<<"zero : "<<zero<<"\n";
		ans += mi;
	}
	cout<<ans;
  	return 0;
}

Measured memory_bytes: 3632
// B - Exponential

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

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

  vector<bool> beki(X + 1, false);

  for (int i = 1; i < X + 1; i++) {
    for (int j = 2; j <= X + 1; j++) {
      // cout << "i : " << i << "j : " << j << endl;
      long long a = pow(i, j);
      // cout << "a : " << a << endl;
      if (a < X + 1) {
        beki[a] = true;
      }
      if(a>X){
        break;
      }
    }
  }

  int ans = 0;
  for (int i = 1; i < X + 1; i++) {
    // cout << "i : " << i << endl;
    if (beki[i]) {
      ans = max(ans, i);
    }
  }

  cout << ans << endl;
}


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

int main() {
  int x, y;
  scanf("%d %d", &x, &y);
  for(int i = 0; i <= x; i++) {
    if(y == 2 * i + 4 * (x - i)) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
}

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

using namespace std;

void dfs(int pos, int bit, vector<int> &p, int n, vector<vector<bool>> &g, int &cnt){
  if(pos == n){
    if(p[0] != 0) return;
    for(int i = 0; i < n - 1; ++i){
      if(!g[p[i]][p[i + 1]]) return;
    }
    ++cnt;
  }
  for(int i = 0; i < n; ++i){
    if((bit >> i) & 1) continue;
    p[pos] = i;
    dfs(pos + 1, bit | (1 << i), p, n, g, cnt);
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> g(n, vector<bool>(n));
  for(int i = 0; i < m; ++i){
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a][b] = g[b][a] = true;
  }
  int cnt = 0;
  vector<int> p(n);
  dfs(0, 0, p, n, g, cnt);
  cout << cnt << endl;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
stp = 0
for i in range(N-1):
    if H[i] == H[i+1]+1:#そのままforループ。次が１だけ低ければ１足して、
        H[i+1] += 1
    elif H[i+1] >= H[i]:#同じ高さ以上なら無問題、
         pass
    else:#２以上低ければアウト
        stp += 1
        print("No")
        break
if stp == 0:
    print("Yes")

Measured memory_bytes: 63856
n = int(input())
s = input().split()
q = int(input())
t = input().split()
c = 0
s = list(map(int,s))
t = list(map(int,t))

for i in t:
    l = 0
    r = n-1
    cen = int((l+r) / 2)
    while r >= l :
#        print("0:",i,l,r,cen,s[cen])
        if i > s[cen]:
            l = cen
            cen = int((l+r) / 2)
#            print("1:",l,r,cen,s[cen])
        elif i < s[cen]:
            r = cen
            cen = int((l+r) / 2)
#            print("2:",l,r,cen,s[cen])
        if i == s[cen] or i == s[l] or i == s[r]:
            c += 1
#            print("!")
            break
        if l+1 > r-1:
#            print("!!",i)
            break
print(c)



Measured memory_bytes: 19620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=205,up=60;
int n;
ll a[N],p[2][N];
char s[N];
void add(int opt,ll x)
{
    for(int i=up;i>=0;i--)
        if(x>>i&1)
        {
            if(!p[opt][i]) {p[opt][i]=x;break;}
            else x=x^p[opt][i];
        }
}
bool query(ll x)
{
    for(int i=up;i>=0;i--)
        if(x>>i&1)
    {
        if(!p[0][i]) return true;
        else x=x^p[0][i];
    }
    return false;
}
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
        scanf("%s",s+1);
        if(s[n]=='1')
        {
            printf("1\n");continue;
        }
        memset(p,0,sizeof(p));
        int ans=0;
        for(int i=n;i>=1;i--)
        if(s[i]=='0') add(0,a[i]),memset(p[1],0,sizeof(p[1]));
        else
        {
            add(1,a[i]);
            for(int i=0;i<=60;i++)
                if(p[1][i]&&query(p[1][i]))
                    ans=1;
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 3812
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
char s[110][110];
int dp[110][110];

int main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	bool flag = true;
	int e = max(c, d);
	for (int i = a + 1;i < e - 1;++i) {
		if (s[i] == s[i + 1] && s[i] == '#') {
			flag = false;
		}
	}
	if (c > d) {
		bool flag2 = false;
		for (int i = b - 1;i < d;++i) {
			if (s[i - 1] == s[i] && s[i] == s[i + 1] && s[i] == '.') {
				flag2 = true;
			}
		}
		if (flag2 == false)flag = false;
	}
	if (flag)puts("Yes");
	else {
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

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

	map<string, vector<pair<int, int>>> m;
	for (auto i = 0; i < N; ++i)
	{
		string S;
		int P;
		cin >> S >> P;
		auto& list = m[S];
		list.push_back(make_pair(P, i + 1));
	}

	vector<string> city;
	for (auto it : m)
	{
		city.push_back(it.first);
	}

	sort(city.begin(), city.end());

	for (auto i = 0; i < city.size(); ++i)
	{
		auto& s = city[i];
		auto& list = m[s];
		sort(list.begin(), list.end(), greater<pair<int, int>>());

		for (auto j = 0; j < list.size(); ++j)
		{
			cout << list[j].second << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256