akhauriyash/Code-Regression huggingface dataset:
class Heap
  attr_accessor :nodes
  attr_reader :relational_operator

  def initialize(defalut = [], direction)
    @nodes = defalut
    @relational_operator = direction == :max ? :< : :>
  end

  def pop
    popped = nodes.shift
    return popped if nodes.empty?

    nodes.unshift(nodes.pop)

    tmp_index = 0
    while (tmp_index * 2 + 1) < nodes.size
      left_child_index = tmp_index * 2 + 1
      right_child_index = tmp_index * 2 + 2

      if right_child_index >= nodes.size
        if need_swap?(nodes[tmp_index], nodes[left_child_index])
          swap(tmp_index, left_child_index)
          tmp_index = left_child_index
        else
          break
        end
      else
        max_direction_child_index =
            if need_swap?(nodes[right_child_index], nodes[left_child_index])
              left_child_index
            else
              right_child_index
            end

        if need_swap?(nodes[tmp_index], nodes[max_direction_child_index])
          swap(tmp_index, max_direction_child_index)
          tmp_index = max_direction_child_index
        else
          break
        end
      end
    end

    popped
  end

  def push(node)
    tmp_index = nodes.size
    while tmp_index > 0 do
      parent_index = (tmp_index - 1) / 2

      if nodes[parent_index] && need_swap?(nodes[parent_index], node)
        swap(parent_index, tmp_index)
        tmp_index = parent_index
      else
        break
      end
    end

    @nodes[tmp_index] = node
  end

  private

  def need_swap?(node, other_node)
    node.send(relational_operator, other_node)
  end

  def swap(index, other_index)
    nodes[index], nodes[other_index] = nodes[other_index], nodes[index]
  end
end

class PriorityQueue
  attr_accessor :heap

  def initialize(direction, default = nil)
    case direction
    when :max, :min
      @heap = Heap.new(default, direction)
    else
      ArgumentError
    end
  end

  def dequeue
    heap.pop
  end

  def enqueue(e)
    heap.push(e)
  end
end

N, M = gets.split.map(&:to_i)
array = gets.split.map(&:to_i).sort!.reverse!
priority_queue = PriorityQueue.new(:max, array)

M.times do
  max = priority_queue.dequeue
  priority_queue.enqueue(max / 2)
end

puts priority_queue.heap.nodes.inject(:+)


Measured memory_bytes: 11144
n=int(input())
arr=list(map(int,input().split()))
if n<=3:
  print(max(arr))
  exit()
lim=n%2+2
dp=[[0]*lim for _ in range(n+1)]
for i in range(n):
  dp[i+1][0]=dp[i-1][0]+arr[i]
  dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i])
  if lim==3:
    dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i])
print(max(dp[-1][:lim]))

Measured memory_bytes: 65876
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
struct edge { int to, cost; };
int n, ma, mb;
int a[45], b[45], c[45];
int dp[45][444][444];//i番目までの薬から物質Aをjグラム、物質Bをkグラムとるときの最小費用
signed main() {
	cin >> n >> ma >> mb;
	rep(i, n)cin >> a[i] >> b[i] >> c[i];
	rep(i, n + 1) {
		rep(j, 444) {
			rep(k, 444)dp[i][j][k] = inf;
		}
	}
	dp[0][0][0] = 0;
	rep(i, n) {
		for (int j = 0; j < 444; j++) {
			for (int k = 0; k < 444; k++) {
				if (j < a[i] || k < b[i])dp[i + 1][j][k] = dp[i][j][k];
				else dp[i + 1][j][k] = min(dp[i][j - a[i]][k - b[i]] + c[i], dp[i][j][k]);
			}
		}
	}
	int ans = mod;
	for (int i = ma; i <= 422; i += ma) {
		if (dp[n][i][i / ma * mb] != inf)ans = min(ans, dp[n][i][i / ma * mb]);
	}
	if (ans == mod)puts("-1");
	else cout << ans << endl;
	ggr
}


Measured memory_bytes: 63744
#include <iostream>
using namespace std;
int main(void){
    int a[3],cnt = 1000;
    for(int i = 0;i < 3;i++)
    cin >> a[i];

    int sum = abs(a[1] - a[0]) + abs(a[2] - a[1]);
    cnt = min(cnt,sum);
    
    sum = abs(a[2] - a[0]) + abs(a[1] - a[2]);
    cnt = min(cnt,sum);
    
    sum = abs(a[0] - a[1]) + abs(a[2] - a[0]);
    cnt = min(cnt,sum);
    
    sum = abs(a[2] - a[1]) + abs(a[0] - a[2]);
    cnt = min(cnt,sum);
    
    sum = abs(a[0] - a[2]) + abs(a[1] - a[0]);
    cnt = min(cnt,sum);
    
    sum = abs(a[1] - a[2]) + abs(a[0] - a[1]);
    cnt = min(cnt,sum);
    
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
<?php

    $N = intval(trim(fgets(STDIN)));
    list($s,$t) = array_map(null,explode(" ",trim(fgets(STDIN))));
    
    $S = str_split($s);
    $T = str_split($t);
    
    $ans="";
    for($i=0;$i<count($S);$i++){
        $ans .= ($S[$i].$T[$i]);
    }
    echo $ans;
?>

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)

int main() {
  int a, b;
  cin >> a >> b;
  if(a < b) {
    cout << 0 << endl;
  }
  else {
    cout << a - b << endl;
  }
}


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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

int main(){

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

    int n;
    cin>>n;
    int l[n];
    int maxi = 0, sum = 0;
    for(int i = 0; i < n; i++){
    	cin>>l[i];
    	sum += l[i];
    	maxi = max(maxi, l[i]);
    }
    if(sum > 2*maxi){
    	cout<<"Yes"<<endl;
    }else{
    	cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>

#define MAX 100
#define ll long long
using namespace std;


int main( )
{
	string s;
	while(cin >> s){
		int len = s.length();
		int win = 15 - len;
		for(int i = 0; i < len; i++){
			if(s[i] == 'o'){
				win++;
			}
		}
		if(win >= 8){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

 

Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();

		String[] square = new String[x];
		for (int i = 0; i < square.length; i++) {
			square[i] = scan.next();
		}

		boolean[] row = new boolean[x];
		boolean[] col = new boolean[y];

		for (int i = 0; i < row.length; i++) {
			for (int j = 0; j < col.length; j++) {
				if (square[i].charAt(j) == '#') {
					row[i] = true;
					col[j] = true;
				}
			}
		}

		for (int i = 0; i < row.length; i++) {
			if (row[i]) {
				for (int j = 0; j < col.length; j++) {
					if (col[j]) {
						System.out.print(square[i].charAt(j));
					}
				}
				System.out.println();
			}
		}
	}
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];
    sort(A,A+N);reverse(A,A+N);


    deque<pint>d;
    d.pb({A[N-1],(A[N-1]-1+N-1)%2==0});
    for(int i=N-2;i>=0;i--){
        if(d.size()>=2){
            d.front().fi--;
            d.back().fi++;
            if(d.front().fi==0)d.pop_front();
        }
        if(A[i]!=A[i+1]){
            int f=(A[i]-1+i)%2==0;
            if(d.back().se==f){
                d.back().fi+=A[i]-A[i+1];
            }
            else{
                if((A[i+1]-1+i)%2==f){
                    d.back().fi--;
                    if(d.front().fi==0)d.pop_front();
                    d.pb({A[i]-A[i+1]+1,f});
                }
                else{
                    d.pb({A[i]-A[i+1],f});
                }
            }
        }
    }

    if(d[0].se)cout<<"Second"<<endl;
    else cout<<"First"<<endl;
    return 0;
}


Measured memory_bytes: 1408
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N;
	cin >> N;
	
	vector< int > V(N), C(N);
	for (int i=0; i<N; ++i) cin >> V[i];
	for (int i=0; i<N; ++i) cin >> C[i];
	
	vector< int > P(N);
	for (int i=0; i<N; ++i) P[i] = V[i] - C[i];
	
	int ans = 0;
	for (int i=0; i<N; ++i) if (P[i] > 0) ans += P[i];
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
#include <iostream> 

using namespace std;


int main() {
    int n, m;
    int a[1000][1000]{{0}};
    int b[1000]={0};
    int c[1000]= {0};

    cin >> n >> m;

    for (int y = 0; y < n; ++y){
        for (int x = 0; x < m; ++x){
            cin >> a[y][x];
            }
    }
    for (int x = 0; x < m; ++x){
        cin >> b[x];
    }

    for (int y = 0; y < n; ++y){
        for (int x = 0; x < m; ++x){
        c[y] += a[y][x] * b[x];
        }
    }
    for (int x = 0; x < n; ++x){
        cout << c[x] << endl;
    }
    return 0;
}



Measured memory_bytes: 7028
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1,mod=1e9+7;
const int inf=(1ull<<31)-1;
ll a,b;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>a>>b;
	cout<<(ll)a/__gcd(a,b)*b;
	return 0;
}

Measured memory_bytes: 256
gets
c=$<.map{|l|a,_,*b=l.split;[a.to_i-1,b]}.sort
m=0
t=[]
d=->n{t[n]||(t[n]=[n+1,m+=1];c[n][1].map{|i|d[i.to_i-1]};t[n]<<m+=1)}
puts c.map{|i,|d[i];t[i]*" "}

Measured memory_bytes: 6384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define N 2002
#define INF 1000000000000LL
using namespace std;
int n;
vector<int> G[100100];
int sg[100100];
int dfs(int o,int fa){
    for(auto &i:G[o]){
        if(i == fa)continue;
        sg[o] ^= (dfs(i,o) + 1);
    }
    return sg[o];
}
int main(){
    scanf("%d",&n);
    for(int i = 1; i < n; ++i){
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    if(dfs(1,-1)){
        printf("Alice");
    }else{
        printf("Bob");
    }
}

Measured memory_bytes: 10752
N,M = map(int, input().split())
from collections import defaultdict
edges = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

first = edges[1]
# print(first)
for fr in first:
    if N in edges[fr]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Measured memory_bytes: 51192
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define pii pair<int, int>
#define ll long long
using namespace std; 

#define MAX 10
#define SIZE 1000
#define INF 1<<30

int H, W, N;
char sec[SIZE][SIZE+1];
int tsec[SIZE][SIZE+1];
int move_cnt = INF;
int all_move_cnt = 0;
int facy[10] = {};
int facx[10] = {};
int gy, gx;

struct state {
	int sy, sx, cnt;
	state() {}
	state(int _sy, int _sx, int _cnt) :
		sy(_sy), sx(_sx), cnt(_cnt) {}
};
queue<state> que;

void bfs()
{
	int dy[4] = {-1, 0, 1, 0};
	int dx[4] = {0, 1, 0, -1};
	rep(i,0,SIZE) rep(j,0,SIZE+1) tsec[i][j] = INF;

	while (!que.empty()) {
		state ts = que.front(); que.pop();
		// printf("sy=%d sx=%d cnt=%d\n",ts.sy,ts.sx,ts.cnt);
		if (ts.sy == gy && ts.sx == gx) {
			move_cnt = min(move_cnt, ts.cnt);
			break;
		}

		int ny, nx;
		rep(i, 0, 4) {
			ny = ts.sy + dy[i];
			nx = ts.sx + dx[i];
			if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
			if (sec[ny][nx] == 'X' || tsec[ny][nx] != INF) continue;
			state ns(ny, nx, ts.cnt + 1);
			tsec[ny][nx] = ts.cnt+1;
			que.push(ns);
		}
	// rep(i,0,H) { rep(j,0,W) tsec[i][j]>99? printf("99"):printf("%2d",tsec[i][j]); cout << endl;}
	}
}

void solve()
{
	// rep(i,0,N+1) printf("%d y=%d x=%d\n",i,facy[i],facx[i]);

	rep(i,0,N) {
		move_cnt = INF;
		while(!que.empty()) que.pop();
		state s(facy[i], facx[i], 0);
		que.push(s);
		gy = facy[i+1];
		gx = facx[i+1];
		// printf("\n bfs start !! \n");
		bfs();
		all_move_cnt += move_cnt;
	}

	cout << all_move_cnt << endl;
}

void input()
{
	cin >> H >> W >> N;
	rep(i,0,H) { 
		rep(j,0,W) {
			cin >> sec[i][j];
			if (sec[i][j] == 'S') { facy[0] = i; facx[0] = j; }
			if (sec[i][j] >= 49 && 57 >= sec[i][j]) {
				facy[sec[i][j]-48] = i;
				facx[sec[i][j]-48] = j;
			}
		}
	}
	solve();
}

int main(void)
{
	input();
	
	return 0;
}

Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double



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


////////////////////////////////////////////////////////////////////i

int n, a[210000], ac[210000];
signed main(){
  cin>>n;rep(i,n)cin>>a[i];
  int ans = INF;
  rep(i,n)ac[i+1] = ac[i]+a[i];
  repd(i,2,n-1){//B->[0, b), C->[b, i), D->[i, d), E->[d, n) 

    int lmin = INF, lmax = -INF, rmin = INF, rmax = -INF;
    auto p = lower_bound(ac, ac+i, ac[i]/2), r = lower_bound(ac+i, ac+n+1, (ac[n]+ac[i])/2);
    repd(k, -1, 2){
      lmin = min(*(p+k), ac[i]-*(p+k));
      lmax = max(*(p+k), ac[i]-*(p+k));
      repd(j,-1,2){
        rmin = min(*(r+j) - ac[i], ac[n]-*(r+j));
        rmax = max(*(r+j) - ac[i], ac[n]-*(r+j));
        chmin(ans, max(lmax, rmax) - min(lmin, rmin));
      }
    }
    
  }
  cout << ans << endl;
}





Measured memory_bytes: 3328
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int D,N,M,m,d,k,i,S[100009],r;

int cmp(const void *a,const void *b)
{
	return *(int*)a-*(int*)b;
}

int sch()
{
	int i=S[N/2]<d?N/2:0;
	int e=i+N/2+1;
	int r=1000000000;
	for(;i<=e;i++)
		r=r>abs(S[i]-d)?abs(S[i]-d):r;
	return r;
}

int main()
{
	for(;scanf("%d",&D),D;)
	{
		r=0;
		scanf("%d%d",&N,&M);
		memset(S,0,sizeof(S));
		for(i=1;i<N;i++)
			scanf("%d",&S[i]);
		S[N]=D;
		qsort(S,N+1,4,cmp);

		for(i=0;i<M;i++)
		{
			scanf("%d",&d);
			r+=sch();
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 1284
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
a,b,x = rl()
if x<=a*a*b/2:

    print(180*math.atan(b**2*a/x/2)/math.pi)
else:
    t = 2*(a*a*b-x)/a/a
    print(180/math.pi*math.atan(t/a))

Measured memory_bytes: 65556
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    string a, b, c;

    cin >> n >> a >> b >> c;

    int res = 0;
    REP(i, n)
    {
        if (a[i] == b[i] && b[i] == c[i])
        {
        }
        else if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i])
        {
            res += 2;
        }
        else
        {

            res += 1;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    int ans = (n*(n-1))/2 + (m*(m-1))/2;
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int card[4][13] = {{}};
	char a;
	int b;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		switch (a) {
		case 'S':
			card[0][b - 1] = 1;
			break;
		case 'H':
			card[1][b - 1] = 1;
			break;
		case 'C':
			card[2][b - 1] = 1;
			break;
		case 'D':
			card[3][b - 1] = 1;
			break;
		}
	}
	for (int i = 0; i < 52; i++) {
		switch (i / 13) {
		case 0:
			if (card[0][i % 13] == 0) cout << "S " << i + 1 << endl;
			break;
		case 1:
			if (card[1][i % 13] == 0) cout << "H " << i % 13 + 1 << endl;
			break;
		case 2:
			if (card[2][i % 13] == 0) cout << "C " << i % 13 + 1 << endl;
			break;
		case 3:
			if (card[3][i % 13] == 0) cout << "D " << i % 13 + 1 << endl;
			break;
		}
	}
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
const int MAX_V = 1e5;


struct edge {
	int to, cost;
};
// O(ElogV)
struct C {
	ll d[MAX_V];
	//bool used[MAX_V];
	int V;
	vector<edge> G[MAX_V];
	void dijkstra(int s) {
		fill(d, d + V, INF);
		d[s] = 0;
		priority_queue<P, vector<P>, greater<P> > q;
		q.push(make_pair(0, s)); // distance, index)

		while(!q.empty()) {
			P p = q.top();
			q.pop();
			int v = p.second;
			if(d[v] < p.first) continue;
			rep(i, 0, G[v].size()) {
				edge e = G[v][i];
				if(d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					q.push(P(d[e.to], e.to));
				}
			}
		}
	}
};

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

	int N;
	cin >> N;
	C c1, c2;
	c1.V = c2.V = N;
	rep(i, 0, N - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		edge e1, e2;
		e1.to = b;
		e1.cost = 1;
		e2.to = a;
		e2.cost = 1;

		c1.G[a].push_back(e1);
		c1.G[b].push_back(e2);

		c2.G[a].push_back(e1);
		c2.G[b].push_back(e2);
	}

	c1.dijkstra(0);
	c2.dijkstra(N - 1);

	int cnt1 = 0, cnt2 = 0;
	rep(i, 0, N) {
		if(c1.d[i] <= c2.d[i]) cnt1++;
		else if(c1.d[i] > c2.d[i]) cnt2++;
	}

	if(cnt1 > cnt2) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int a[4];
int main()
{
    scanf("%d%d%d",&a[1],&a[2],&a[3]);
    int m,n,k;
    m=abs(a[3]-a[1])+abs(a[2]-a[3]);
    n=abs(a[2]-a[1])+abs(a[3]-a[2]);
    m=min(m,n);
    n=abs(a[2]-a[3])+abs(a[1]-a[3]);
    m=min(m,n);
    n=abs(a[2]-a[1])+abs(a[1]-a[3]);
    m=min(m,n);
    n=abs(a[2]-a[3])+abs(a[1]-a[2]);
    m=min(m,n);
    n=abs(a[3]-a[1])+abs(a[1]-a[2]);
    m=min(m,n);
    printf("%d\n",m);
}


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

using namespace std;

typedef long long ll;
#define debug(x) cout << #x << ": " << (x) << endl
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define INF ((1 << 16)-1)
#define MOD (1000000007)
#define print(arr, n) REP(i, n) cout << arr[i] << " ";

struct PreMain {
    PreMain() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} premain;

#define MAX_V 202

struct Dinic {
    struct edge {
        int to;
        ll cap;
        int rev;
    };
    vector<edge> G[MAX_V];
    vector<int> itr, level;

    void add_edge(int from, int to, ll cap) {
        G[from].push_back((edge) {to, cap, (int) G[to].size()});
        G[to].push_back((edge) {from, 0, (int) G[from].size() - 1});
    }

    void bfs(int s) {
        level.assign(MAX_V, -1);
        queue<int> q;
        level[s] = 0;
        q.push(s);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto &e: G[v]) {
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    ll dfs(int v, int t, ll f) {
        if (v == t) return f;
        for (int &i = itr[v]; i < (int) G[v].size(); ++i) {
            edge &e = G[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                ll d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    ll max_flow(int s, int t) {
        ll ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(MAX_V, 0);
            while ((f = dfs(s, t, INF)) > 0) ret += f;
        }
        return ret;
    }
};

int main() {
#ifdef LOCAL
    std::ifstream in("../arg.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N, x, y;
    cin >> N;

    Dinic dinic;
    int s = 0;
    int t = 2 * N + 1;

    vector<pair<int, int>> reds;

    REP(i, N) {
        cin >> x >> y;
        dinic.add_edge(s, i + 1, 1);
        reds.emplace_back(make_pair(x, y));
    }

    REP(j, N) {
        cin >> x >> y;
        dinic.add_edge(N + j + 1, t, 1);
        REP(i, N) {
            auto p = reds[i];
            if (p.first < x && p.second < y) dinic.add_edge(i + 1, N + j + 1, 1);
        }
    }

    ll ans = dinic.max_flow(s, t);
    cout << ans << endl;

    return 0;
}




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

int main(){
    int N,j=0,sum=0;
    cin >> N;
    vector<int> aj(N);

    for(int i=0; i<N; i++)
        cin >> aj[i];

    for(int i=0; i<N; i++){
        for(j; j<N; j++){
            if(i!=j)
            sum+=aj[i]*aj[j];
        }
        j=i+1;
    }
    cout << sum <<endl;
}

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

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

bool check(int i,int j,int k,int l){	
	string ACGT = "ACGT";
	string s = "";
	s += ACGT[i];
	s += ACGT[j];
	s += ACGT[k];
	s += ACGT[l];
	if(s.substr(0,3) == "AGC" || s.substr(1,3) == "AGC")return false;
	if(s.substr(0,3) == "ACG" || s.substr(1,3) == "ACG")return false;
	if(s.substr(0,3) == "GAC" || s.substr(1,3) == "GAC")return false;
	if(s.substr(0,1) == "A" && s.substr(2,3) == "GC")return false;
	if(s.substr(0,2) == "AG" && s.substr(3,1) == "C")return false;
	return true;
}

ll DP[101][4][4][4][4];

signed main(){
	ll N;
	cin >> N;
	if(N == 3){
		cout << 61 << endl;
		return 0;
	}
	FOR(i,0,4)FOR(j,0,4)FOR(k,0,4)FOR(l,0,4){
		DP[4][i][j][k][l] = check(i,j,k,l);
	}
	FOR(n,5,N+1){
		FOR(i,0,4)FOR(j,0,4)FOR(k,0,4)FOR(l,0,4){
			FOR(m,0,4){
				DP[n][i][j][k][l] += DP[n-1][m][i][j][k];
				DP[n][i][j][k][l] %= INF;
			}
			if(!check(i,j,k,l))DP[n][i][j][k][l] = 0;
		}
	}
	ll ans = 0;
	FOR(i,0,4)FOR(j,0,4)FOR(k,0,4)FOR(l,0,4){
		ans += DP[N][i][j][k][l];
		ans %= INF;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    A=[list(map(lambda x:int(x)-1,input().split())) for _ in range(n)]
    ans=INF

    for _ in range(m):
        C=[0]*m # スポーツのカウンター
        for i in range(n):
            for j in range(m):
                if(A[i][j] is not None):
                    C[A[i][j]]+=1
                    break
        M=max(C)
        ans=min(ans,M)
        ind=C.index(M)
        for i in range(n):
            for j in range(m):
                if(A[i][j]==ind):
                    A[i][j]=None

    print(ans)
resolve()

Measured memory_bytes: 48092
s = int(input())
a_i = s
v = set([a_i])
for i in range(2, 1000000):
    if a_i % 2 == 0:
        a_i = int(a_i // 2)
    else:
        a_i = a_i * 3 + 1
    if a_i in v:
        print(i)
        break
    v.add(a_i)
    # print(f"i:{i} a_i:{a_i}", file=sys.stderr)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
string s;
ll ans = 0;
int len_s = 0;
void f(ll a, ll b, int i) {
	if (i == len_s) {
		ans += a + b;
		return;
	}
	f(a + b, s[i] - '0', i + 1);
	f(a, b * 10 + (s[i] - '0'), i + 1);
}
void solve() {
	cin >> s;
	len_s = len(s);
	f(0, s[0] - '0', 1);
	print(ans);
}
int main() {
	solve();
	return 0;
}


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

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll sum = myPow(2, n, mod);
  sum--;
  ll bunsiA=1, bunboA=1;
  rep(i, a){
    bunsiA *= (n-i);
    bunsiA %= mod;
  }
  rep(i, a){
    bunboA *= i+1;
    bunboA %= mod;
  }
  ll A = bunsiA * modinv(bunboA, mod) % mod;
  ll bunsiB=1, bunboB=1;
  rep(i, b){
    bunsiB *= (n-i);
    bunsiB %= mod;
  }
  rep(i, b){
    bunboB *= i+1;
    bunboB %= mod;
  }
  ll B = bunsiB * modinv(bunboB, mod) % mod;
  sum -= A;
  sum %= mod;
  if(sum < 0) sum += mod;
  sum -= B;
  sum %= mod;
  if(sum < 0) sum += mod;
  cout << sum << endl;
  return 0;
}
  
  


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

const int MOD = 1000000007;

int ss[2000+10];
int ts[2000+10];

ll dp[2010][2010];

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  REP(i, n) {
    scanf("%d", &ss[i]);
  }
  REP(i, m) {
    scanf("%d", &ts[i]);
  }

  dp[0][0] = 1;
  REP(i, n+1) REP(j, m+1) {
    if(i > 0) {
      dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
    }
    if(j > 0) {
      dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
    }
    if(i > 0 && j > 0) {
      dp[i][j] = (dp[i][j] + MOD - dp[i-1][j-1]) % MOD;
      if(ss[i-1] == ts[j-1]) {
        dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MOD;
      }
    }
  }
  cout << dp[n][m] << endl;
  
  return 0;
}


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

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

    string s;
    cin >> s;
    string res = "";

    for(int i = 0; i < s.length(); ++i){

        if(s[i] == '0' or s[i] == '1'){
            res += s[i];
        }
        else{

            if(res != ""){
                res.erase(res.length() - 1);
            }
        }
    }
    cout << res << endl;
}

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

int main()
{
    double A, B, C, X, Y;
    int sum = 0, current = 0, diff = 0, max_num;
    cin >> A >> B >> C >> X >> Y;

    diff = min(X, Y);
    current = 2 * C * diff;
    max_num = 2 * C * max(X, Y);

    if ((X - Y) > (Y - X))
    {
        current += (X - Y) * A;
    }
    else
    {
        current += (Y - X) * B;
    }
    sum = min(current, max_num);

    current = A * X + B * Y;

    sum = min(sum, current);

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
# Me
def resolve(k, s):
    c = 0
    for x in range(0, k+1):
        for y in range(0, k+1):
            if 0 <= s - (x + y) <= k:
                c += 1
    return c


k, s = map(int, input().split())
print(resolve(k, s))


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

const int inf = 10000;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int h, w;

int main() {
  cin >> h >> w;

  vector<vector<char>> s(h, vector<char>(w,'-'));
  rep(i,h) rep(j,w) cin >> s[i][j];

  int ans = 0;
  rep(i,h) rep(j,w) {
    if (s[i][j] == '#') continue;
    vector<vector<int>> dist(h,vector<int>(w,inf));
    queue<pair<int, int>> q;
    auto update = [&] (int li, int lj, int k) {
      if (dist[li][lj] != inf) return;
      dist[li][lj] = k;
      q.push(pair<int,int>(li,lj));
    };
    update(i, j, 0);
    while(!q.empty()) {
      int x = q.front().first;
      int y = q.front().second;
      q.pop();    
      rep(dir, 4) {
        int ni = x + di[dir];
        int nj = y + dj[dir];
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        update(ni,nj,dist[x][y]+1);
      }
     }
     rep(x,h) rep(y,w) {
       if (dist[x][y] == inf) continue;
       ans = max(ans, dist[x][y]);
     }
  }
  cout << ans << endl;

}

Measured memory_bytes: 3548
s=list(input())
n=len(s)
a=[]

count=1
for i in range(1,n):
  if s[i]==s[i-1]:
    count+=1
  else:
    a.append(count)
    count=1
a.append(count)

an= len(a)
for i in range(an//2):
  for j in range(a[0+i*2]-1):
    print(0,end=' ')
  half=(a[0+i*2]+a[1+i*2])//2
  if (a[0+i*2]+a[1+i*2])%2==0:
    print(half,end=' ')
    print(half,end=' ')
  else:
    if max(a[0+i*2],a[1+i*2])%2==0:
      if a[0+i*2]>a[1+i*2]:
        print(half,end=' ')
        print(half+1,end=' ')
      else:
        print(half+1,end=' ')
        print(half,end=' ')
    if max(a[0+i*2],a[1+i*2])%2==1:
      if a[0+i*2]>a[1+i*2]:
        print(half+1,end=' ')
        print(half,end=' ')
      else:
        print(half,end=' ')
        print(half+1,end=' ')
  for j in range(a[1+i*2]-1):
    print(0,end=' ')

Measured memory_bytes: 5580
import java.util.Scanner;
  
class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = 0;
  
        for(int i = 1; i <= n; i++ ){
            if(i % 3 == 0){
                System.out.print(" " + i);
            }else{
                a = i;
  
            while(a > 0){
                if (a % 10 == 3){
                    System.out.print(" " + i);
                    break;
                }else{
                    a /= 10;
                }
            }
            }
        }
        System.out.println();
    }
}

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

using LL = long long;
const LL M = 1e9 + 7;

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

  vector<LL> dp, num;
  for(auto i = 1; i * i <= N; ++i) dp.emplace_back(N / i), num.emplace_back(1);
  for(auto i = dp.size() - (dp.size()==dp.back()); 0 < i; --i) dp.emplace_back(i), num.emplace_back((dp[i - 1] - dp[i] + M) % M);

  N = num.size();
  dp = num;
  for(auto k = 1; k < K; ++k) {
    vector<LL> ss{0};
    for(auto i: dp) ss.emplace_back((ss.back() + i) % M);
    for(auto i = 0; i < N; ++i) dp[i] = (ss[N - i] * num[i]) % M;
  }

  LL res = 0;
  for(auto i = 0; i < N; ++i) (res += dp[i]) %= M;
  cout << res << endl;
}


Measured memory_bytes: 2300
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m=0,n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i]-a[j]>m)
			{m=a[i]-a[j];}
		}
	}
	cout<<m;
	return 0;
}

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

int main(void)
{
    int a,b;

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

    if(a<=b){
        for(int i=0;i<b;i++){
            printf("%c",a+'0');
        }
    }else if(a>b){
        for(int i=0;i<a;i++){
            printf("%c",b+'0');
        }
    }

    return 0;
}

Measured memory_bytes: 128
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
H=IL()
m=0
c=0
for i in range(n):
  if H[i]>=m:
    c+=1
  m=max(m,H[i])
print(c)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if (B - A == C - B)cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int a,b;
  cin>>a>>b;
  string ans="Yay!";
  if(a>8||b>8)ans=":(";
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 125568
#include <bits/stdc++.h>
using namespace std;
int r;
int main () {
cin >> r;
if (r<1200) {
	cout << "ABC" << endl;
}
else if (r<2800) {
	cout << "ARC" << endl;
}
else {
	cout << "AGC" << endl;
	}
}




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

void fnInput(llong& rnMaxNum, vector<llong>& rvnCapcty)
{
  cin >> rnMaxNum;
  
  for (llong& rnCapcty : rvnCapcty)
    cin >> rnCapcty;
}

llong fnTransptCnt(llong nMaxNum, vector<llong>& rvnCapcty)
{
  for (int i = 0; i < rvnCapcty.size() - 1; i++)
    if (rvnCapcty[i] < rvnCapcty[i + 1])
      rvnCapcty[i + 1] = rvnCapcty[i];
  
  vector<llong> vnTime(6);

  for (int i = 0; i < vnTime.size() - 1; i++)
  {
    vnTime[i + 1] = (nMaxNum + (rvnCapcty[i] - 1)) / rvnCapcty[i]; 
    vnTime[i + 1] += i;
  }
  llong nTotalTime = 0;

  for (int i = 0; i < vnTime.size() - 1; i++)
    nTotalTime += vnTime[i + 1] - vnTime[i];

  return nTotalTime;
}
 
int main()
{
  llong nMaxNum;
  vector<llong> vnCapcty(5);

  fnInput(nMaxNum, vnCapcty);
  cout << fnTransptCnt(nMaxNum, vnCapcty) << endl;

  return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
  int n ;
  cin >> n ;
  vector<int> v(n+1) ;
  intll ans = 0;
  
  rep(i,n-1) cin >> v.at(i+1) ;
  v.at(0) = INF ;
  v.at(n)= INF ;
  
  rep(i,n){
    ans += min(v.at(i),v.at(i+1)) ;
  }
  
  cout << ans ;
              
              
      
}

Measured memory_bytes: 256
fun main(args:Array<String>?): Unit {
    val direction = arrayOf(Point(0, -1), Point(1, 0), Point(0, 1), Point(-1, 0))
    while(true){
        val (h, w, l) = readLine()!!.trim().split(' ')
        if (h == "0" && w == "0" && l == "0") return
        val height = h.toInt()
        val width = w.toInt()
        val step = l.toLong()
        val state = Array(height){readLine()!!.trim()}
        val start = (0 until height).mapNotNull { y -> (0 until width).find{ x -> state[y][x] != '#' && state[y][x] != '.'}?.let{Point(it, y)} }.first()
        val initialDir = when(state[start.y][start.x]){
            'N' -> 0
            'E' -> 1
            'S' -> 2
            'W' -> 3
            else -> TODO()
        }
        val memo = Array(4){Array(height){IntArray(width){-1}}}
        var count = 0
        var pos = start
        var dir = initialDir
        var lastMoved = start
        var lastDir = initialDir
        while(step > count && memo[dir][pos.y][pos.x] == -1){
            memo[dir][pos.y][pos.x] = count
            val suspect = pos + direction[dir]
            if (suspect.y in state.indices && suspect.x in state[suspect.y].indices && state[suspect.y][suspect.x] != '#') {
                pos = suspect
                ++count
                lastMoved = pos
                lastDir = dir
            }else {
                dir = (dir + 1) % 4
            }
        }
        val rest = (step - count) % (count - memo[dir][pos.y][pos.x])
        pos = lastMoved
        dir = lastDir
        repeat(rest.toInt()){
            var suspect = pos + direction[dir]
            while (suspect.y !in state.indices || suspect.x !in state[suspect.y].indices || state[suspect.y][suspect.x] == '#') {
                dir = (dir + 1) % 4
                suspect = pos + direction[dir]
            }
            pos = suspect
        }
        println("${pos.y + 1} ${pos.x + 1} ${arrayOf('N', 'E', 'S', 'W')[dir]}")
    }
}
data class Point(val x: Int, val y: Int) {
    operator fun plus(that: Point): Point = Point(x + that.x, y + that.y)
}


Measured memory_bytes: 43064
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      k: usize,
      mut s: chars,
    }

    let mut ans = 0;
    let mut cnt = 0;
    for i in 1..n {
        if s[i] == s[i-1] {
            ans += 1;
        } else {
            cnt += 1;
        }
    }
    for i in 0..min(k, cnt) {
        ans += 2;
    }
    ans = min(ans, n-1);
    puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	for(int i=1;i<=100000;i++)
	{
		c-=b;
		if(c<=0)
		{
			cout<<"Yes";
			return 0;
		}
		a-=d;
		if(a<=0)
		{
			cout<<"No";
			return 0;
		}
	}
 } 

Measured memory_bytes: 3640