akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
v = list(map(int,input().split()))

if n==2:
    ret = 0
    if v[0]==v[1]:
        ret = 1
    print(ret)
    sys.exit()

max_v = max(v)+1
n_odd = v[0::2]
n_even = v[1::2]
n_half = n//2

odd_bucket = [0] * max_v
even_bucket = [0] * max_v

for i in n_odd:
    odd_bucket[i]+=1
for i in n_even:
    even_bucket[i]+=1

#最大と2番目のindexを取得
odd_max1 = [0,0]#index,value
odd_max2 = [0,0]#index,value
for i,v in enumerate(odd_bucket):
    if v >= odd_max1[1]:
        odd_max2[0],odd_max2[1] = odd_max1[0],odd_max1[1]
        odd_max1 = [i,v]
    elif v > odd_max2[1]:
        odd_max2 = [i,v]

#最大と2番目のindexを取得
even_max1 = [0,0]#index,value
even_max2 = [0,0]#index,value
odd_val = 0
even_val = 0

for i,v in enumerate(even_bucket):
    if v >= even_max1[1]:
        even_max2[0],even_max2[1] = even_max1[0],even_max1[1]
        even_max1 = [i,v]
    elif v > even_max2[1]:
        even_max2 = [i,v]
if odd_max1[0]==even_max1[0] and odd_max1[1]!=odd_max2[1] and even_max1[1]!=even_max2[1]:
    if odd_max1[1] - odd_max2[1] >= even_max1[1] - even_max2[1]:
        odd_val = odd_max1[1]
        even_val = even_max2[1]
    else:
        odd_val = odd_max2[1]
        even_val = even_max1[1]
elif odd_max1[0] != even_max1[0]:
    odd_val = odd_max1[1]
    even_val = even_max1[1]
else:
    if odd_max1[1]==odd_max2[1]:
        odd_val = odd_max2[1]
        even_val = even_max1[1]
    else:
        odd_val = odd_max1[1]
        even_val = even_max2[1]
print(n-odd_val-even_val)

Measured memory_bytes: 14060
module M = Map.Make (struct type t = int let compare = compare end) ;;

Scanf.scanf "%d" (fun n ->
    let add a map = M.add a (1 + try M.find a map with _ -> 0) map in
    let rec loop i map =
        if i = n then map else
            let map = Scanf.scanf " %d" (fun a -> add a map) in
            loop (i + 1) map
    in
    let map = loop 0 M.empty in
    M.fold (fun k v acc ->
        if v < k then acc + v else acc + v - k) map 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 10496
n, q= gets.split(" ").map { |x| x.chomp.to_i }

queue =  n.times.map{ gets.chomp.split(" ") }.map{ |k ,v| [k, v.to_i]}

time = 0
until queue.empty?
  s = queue.shift
  if s[1] <= q
    time += s[1]
    printf "%s %s\n", s[0], time
  else
    time += q
    s[1] -= q
    queue << s
  end
end


Measured memory_bytes: 19916
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long X=sc.nextLong();
        long money=100;
        int year=0;
        while(money<X){
            money*=1.01;
            year++;
        }
        System.out.println(year);
    }
}

Measured memory_bytes: 35760
#include <iostream>
#include <vector>
#include <string>
#include <stack>

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    //スタックに積むのは(のみ
    //)を読み込んだときはスタックの先頭が(の時(を削除する
    //)を読み込んだ時(がない場合その連続数をカウントする
    //その連続数分(を先頭に結合する
    //最後まで読み込んだら残っている要素分)を末尾に結合する
    string result = s;
    stack<char> stack1;
    int count = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '(')
        {
            stack1.push('(');
        }else{
            if(!stack1.empty())
            {
                stack1.pop();
                if(count != 0)
                {
                    for(int j = 0; j < count; j++)
                    {
                        result = "(" + result;
                    }
                    count = 0;
                }
            }else{
                count++;
            }
        }
    }
    for(int i = 0; i < count; i++)
    {
        result = "(" + result;
    }
    for(int i = 0; i < stack1.size(); i++)
    {
        result += ")";
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    unsigned N;
    scanf("%u", &N);
    unsigned L[N];
    for(int i = 0; i < N; ++i){
        scanf("%u", L + i);
    }
    sort(L, L + N);
    unsigned answer = 0u;
    for (size_t i = 0; i < N - 1; i++){
        for (size_t j = i + 1; j < N; j++){
            answer += distance(upper_bound(L, L + N, L[j] - L[i]), lower_bound(L, L + N, L[j] + L[i])) - 1;
            if(L[i]*2 > L[j]) answer--;
        }
    }
    printf("%u\n", answer/3);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

int main() {

	string S;
	bool judge;

	judge = false;

	cin >> S;
	
	for (int i = 0; i < S.size() -1; i++) {
		for (int j = i + 1; j < S.size(); j++) {
			if (S[i] == S[j]) judge = true;
		}
	}

	if (judge) cout << "no";
	else cout << "yes";

	return 0;

}

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

#define rs(a, b) ((a) >> (b))
#define ls(a, b) ((a) << (b))
#define gcd __gcd
#define lcm(a, b) ((a * b) / gcd(a, b))
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define nani(x) cerr << #x << " is " << x << endl;
#define ch(x) (x - 'a' + 1)
#define mp make_pair
#define pb push_back
#define loop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define scan(x, n) loop(i, 0, n) cin >> x[i];
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define print(x, n) loop(i, 0, n) cout << x[i] << " ";
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<long, long> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef um<int, int> umii;
typedef um<char, int> umci;
typedef map<char, int> mci;
typedef map<int, int> mii;

int main()
{
    fast;
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int a[n];
    scan(a, n);
    double ans = 0;

    for (int i = 0; i < n; i++) {
        ans += 1 / (double)a[i];
    }

    cout << setprecision(10) << 1 / (double)ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll M,N,A[100],sum=0,num=0;
    cin >> N >> M;
    REP(i,N){
        cin >> A[i];
        sum += A[i];
    }
    REP(j,N){
        if(A[j]*4*M >= sum){
            num++;
        }
    }
    if(num>=M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;    
}


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

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

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int k, a, b;

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

	cin>>k>>a>>b;
	lint ans=0;
	if(a+1>=b){
		ans = k+1;
	} else{
		lint now = 1, x;
		x = min(a-1, k);
		now += x, k -= x;
		if(k!=0){
			lint cnt = k/2;
			k -= cnt*2, now += cnt * (b-a);
		}
		if(k!=0){
			now += 1;
		}
		ans = now;
	}
	cout<<ans<<'\n';

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  string s,t; cin >> s >> t;
  int ans = 0;
  REP(i,SIZE(s)) {
    if (s[i] == t[i]) continue;
    else ans++;
  }

  cout << ans <<endl;

  return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int N = 2020;

int n;
int res;

int dist(int x, int y) {
	if (x>y) swap(x,y);
	return min(y-x, n+x-y);
}

void update(int x, int y, int p) {
	res = min(res, x + (x+y) + dist(y,p));
	res = min(res, y + (x+y) + dist(n-x, p));
}

int ret;
char a[N], b[N];
int le[N], ri[N];
int main() {
	scanf("%s%s", a, b);
	for (n=0; a[n]; n++) ;
	ret = 2*n+1;
	int fnd = 0;
	FOR(i,n) if (a[i] == '1') {
		fnd = -1;
	}
	FOR(i,n) if (b[i] == '1') {
		fnd = i;
		break;
	}
	if (fnd == -1) {
		printf("-1\n");
		return 0;
	}
	ri[n] = fnd+n;
	int rfnd = -1;
	for (int i = n-1; i >= 0; i--) {
		ri[i] = ri[i+1];
		if (b[i]=='1') {
			ri[i]=i;
			if (rfnd==-1) rfnd=i;
		}
	}
	le[0] = rfnd-n;
	if (b[0]=='1') le[0]=0;
	for (int i=1; i<n; i++) {
		le[i] = le[i-1];
		if (b[i]=='1') le[i]=i;
	}
	//FOR(i,n) printf("%d ", le[i]); printf("\n");
	//FOR(i,n) printf("%d ", ri[i]); printf("\n");
	FOR(p,n) {
		int cur = 0;
		res = 2*n+1;
		vector<pii> v;
		FOR(i,n) if (a[i] != b[(i+p)%n]) {
			cur++;
			if (a[i] == '1') {
				v.pb(mp(i-le[i], ri[i]-i));
			}
		}
		//printf("p=%d\n", p);
		sort(v.begin(), v.end());
		//FOR(i,SZ(v)) printf("%d %d; ", v[i].fi, v[i].se);
		//printf("\n");
		int mxle = 0, mxri = 0;
		for (int i=SZ(v)-1; i>=0; i--) {
			int cle = v[i].fi, cri = v[i].se;
			mxle = cle;
			update(mxle, mxri, p);
			mxri = max(mxri, cri);
		}
		update(0, mxri, p);
		//printf("res=%d\n", res+cur);
		ret = min(ret, res+cur);
	}
	printf("%d\n", ret);
	return 0;
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   int n; cin>>n;
   vector<int> a(n),b(n);
   rep(i,0,n)cin>>a[i];
   rep(i,0,n)cin>>b[i];
   int d=0;
   rep(i,0,n){
      int idx=upper_bound(ALL(b),a[i])-b.begin();
      chmax(d,idx-i);
   }
   rotate(b.begin(),b.begin()+d,b.end());
   rep(i,0,n)if(a[i]==b[i]){
      puts("No"); return 0;
   }
   puts("Yes");
   rep(i,0,n)cout<<b[i]<<(i==n-1?'\n':' ');
   return 0;
}

Measured memory_bytes: 4836
#include<stdio.h>
#include<string.h>
#define N 100000
int main()
{
	char S[N];
	scanf("%s", &S);
	int one=0;
	int zero=0;
	int i = 0;
	for (;i < strlen(S);i++)
	{
		if (S[i] == '0')zero++;
		else one++;
	}
	if(one>=zero)printf("%d\n", 2 * zero);
	else printf("%d\n", 2 * one);
	
	return 0;
}

Measured memory_bytes: 256
use combination::*;
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: usize,
        b: usize,
        mut v: [i64; n],
    };

    v.sort_by_key(|&v_i| -v_i);

    let avg = v[0..a].iter().sum::<i64>() as f64 / a as f64;
    let count = {
        let combin = CombinationTable::new(n);
        let mut x = 0;
        let mut y = 0;
        for (i, &v_i) in v.iter().enumerate() {
            if v_i == v[a - 1] {
                x += 1;
                if i < a {
                    y += 1;
                }
            }
        }
        if y == a {
            (a..=b).map(|y| combin.combination(x, y)).sum::<usize>()
        } else {
            combin.combination(x, y)
        }
    };

    println!("{:.6}", avg);
    println!("{}", count);
}

mod combination {
    pub struct CombinationTable {
        // pascal's triangle
        c: Vec<Vec<usize>>,
    }

    impl CombinationTable {
        pub fn new(n: usize) -> Self {
            let mut c = vec![vec![0; n + 1]; n + 1];
            for i in 0..n + 1 {
                for j in 0..i + 1 {
                    if j == 0 || j == i {
                        c[i][j] = 1;
                    } else {
                        c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
                    }
                }
            }
            CombinationTable { c }
        }

        pub fn combination(&self, n: usize, k: usize) -> usize {
            self.c[n][k]
        }
    }
}


Measured memory_bytes: 2220
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
#define double long long
using namespace std;
signed main() {
	int A, B;
	cin >> A >> B;
  int ans = 0;

	for (int i = A; i <= B; i++) {
		string X = to_string(i);
		if (X[0] == X[4] && X[1] == X[3]) {
			ans++;
			
		}
	}
  cout << ans << endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
LL arr[105];
LL cal(LL n, LL k){
	if (k == 1) { arr[1] = n; return n; }
	arr[k] = (n - k + 1)*arr[k - 1] / k;
	return arr[k];
}
int main()
{
	LL l, k;
	scanf("%lld%lld", &l, &k);
	LL h, h_temp, ans = 0;
	if (l & 1) h = l;
	else h = l - 1;//h表示块高为1时的总高度

	while(h > 0){
		h_temp = h;
		ans++;
		LL n = (h + 1) / 2;//n表示黑块的个数
		while (h_temp + k - 1 <= l&&n > 0){
			h_temp += k - 1;
			--n;
			ans += cal((h + 1) / 2, (h + 1) / 2 - n);
		}
		h -= 2;
	}
	printf("%lld\n", ans);

	return 0;
}



Measured memory_bytes: 3228
# frozen_string_literal: true

n = gets.to_i
s = gets.chomp.chars.map(&:to_i)
count = 0
0.upto(999) do |x|
  a = x % 10
  p = 0
  0.upto(n - 1) do |t|
    if s[t] == a
      x /= 10
      a = x % 10
      p += 1
      if p == 3
        count += 1
        flag = true
      end
    end
    break if flag
  end
end
puts count


Measured memory_bytes: 3452
#include <bits/stdc++.h>
    using namespace std;
    int main()
    {
      int n;
      char s[100];
      cin>>n>>s;
      
      if(n%2!=0)
      {
        cout<<"No ";
        return 0;
      }
      for(int i=0;i<n/2;++i)
      {
        if(s[i]!=s[n/2+i])
        {
          cout<<"No" ;
          return 0;
        }
      }
      cout<<"Yes" ;
      return 0;
    }

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

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

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", texto);
 
////////////////////////// Solution starts below. //////////////////////////////

template<typename T> void max_self(T& a, T b){
	a = max(a, b);
}

bool first_row_or_column(pii p){
	return p.fs == 0 || p.sc == 0;
}

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

	string a, b;
	cin >> a >> b;
	vector<vector<pair<int, pii>>> dp(a.length()+1, vector<pair<int, pii>>(b.length()+1, {-INF, {0, 0}}));
	dp[0][0] = {0, {0, 0}}; /// base case

	/// dp[i][j] = maximum possible length so far
	for(int i = 0; i < (int) a.length(); i++){
		for(int j = 0; j < (int) b.length(); j++){
			if(a[i] == b[j]){
				max_self(dp[i+1][j+1], mp(dp[i][j].fs + 1, mp(i, j)));
			}
			max_self(dp[i+1][j], mp(dp[i][j].fs, mp(i, j)));
			max_self(dp[i][j+1], mp(dp[i][j].fs, mp(i, j)));
		}
	}
	pair<int, pii> ans = {0, {0, 0}};
	for(int i = 0; i <= (int) a.length(); i++){
		for(int j = 0; j <= (int) b.length(); j++){
			max_self(ans, mp(dp[i][j].fs, mp(i, j)));
		}
	}

	string s;
	pii cur = ans.sc;
	while(!first_row_or_column(cur)){
		int i = cur.fs;
		int j = cur.sc;
		pii ant = dp[i][j].sc;   /// the cell from which I came
		if(ant == mp(i-1, j-1)){
			assert(a[i-1] == b[j-1]);
			s += a[i-1];
		}
		cur = ant;
	}

	reverse(all(s));
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 105984
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main(){
    ll n,ans=0,x,y;
    cin>>n;
    ll a=-2e9,b=2e9,c=-2e9,d=2e9;
    rep(i,0,n){
        cin>>x>>y;
        a=max(a,x+y);
        b=min(b,x+y);
        c=max(c,x-y);
        d=min(d,x-y);
    }
    cout<<max(a-b,c-d);
}



Measured memory_bytes: 3616
program sample
    implicit none
    character(100)::s
    integer(8) :: i,j,m,n,a,b
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) s
    allocate(x(26))
    n=len_trim(s)
    x(:)=0
    do i=1,n
        a=ichar(s(i:i))-96
        x(a)=x(a)+1
    end do
    if(maxval(x)>1)then
        write(*,*)'no'
    else
        write(*,*)'yes'
    end if
  
    stop
end program sample
  



Measured memory_bytes: 2824
using System;
using System.Linq;
using System.Text;

// 長方形の描画

public class ITP1_5_A
{
    public static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        StringBuilder sb = new StringBuilder();
        while (true)
        {
            int[] nums = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int h = nums[0];
            int w = nums[1];
            if (h == 0 && w == 0)
            {
                break;
            }
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    sb.Append("#");
                }
                sb.AppendLine();
            }
            sb.AppendLine();
        }
        Console.Write(sb.ToString());
    }
}



Measured memory_bytes: 16360
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define fr(i,f,t) for(ll i=(f);i<t;i++)
#define fb(i,f,t) for(ll i=(f);i>=t;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int att;
    int ata;
    if(a%d==0){
    	att = a/d;
    }
    else{
    	att = (a/d) + 1;
    }
    if(c%b==0){
    	ata = c/b;
    }
    else{
    	ata = (c/b) + 1;
    }
    // cout<<att<<" "<<ata<<endl;
    if(att>=ata){
    	cout<<"Yes"<<endl;
    }
    else{
    	cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3660
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e9+7;


int main(){
    ll n;
    cin >> n;
    vector<ll> divisors;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            if(i*i==n) divisors.push_back(i);
            else{
                divisors.push_back(i);
                divisors.push_back(n/i);
            }
        }
    }
    ll ans=0;
    for(auto r:divisors){
        if(n%r==0){
            ll m=n/r-1;
            if(r<=m-1) ans+=m;
        }
    }
    cout << ans << endl;
}


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

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

	int n,m,l,r;
	vector <pair<int,int>> v;

	cin >> n >> m;

	for(int i=0;i<m;i++)
	{
		cin >> l >> r;
		v.push_back(make_pair(l,r));
	}

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

	int res = v[0].second - v[0].first + 1;
	int left = v[0].first;
	int right = v[0].second;

	for(int i=1;i<m;i++)
	{
		if(v[i].first > right)
		{
			cout << 0 << '\n';
			return 0;
		}

		if(left < v[i].first)
		{
			res -=(v[i].first - left);
			left = v[i].first;
		}

		if(right > v[i].second)
		{
			res -= (right - v[i].second);
			right = v[i].second;
		}
	}
	cout << res << '\n';
	return 0;

}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
    ll ans=1;
    for(int i=1; i<=n; i++)
        ans*=a;
    return ans;
}
ll divi[1000001];;
void divisorPhi(ll n)
{
    for(ll i=1; i<=n; i++)
    {
        for(ll j=i; j<=n; j+=i)
            divi[j]++;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n,ans=0;
    cin>>n;
    divisorPhi(n);
    for(int i=1; i<=n-1; i++)
    {
        ans+=divi[i];
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 11456
#include<iostream>
#include<vector>

using namespace std;

vector<int> b(100);
vector<int> c(100);
vector<vector<int>> A(100,vector<int>(100));

int main(){
  int n,m;
  cin >> n >> m;
  for(int i=0;i < n;i++){
    for(int j=0;j < m;j++){
      cin >> A.at(i).at(j);
    }
  }

  for(int i=0;i < m;i++){
    cin >> b.at(i);
  }

  for(int i=0;i < n;i++){
    for(int j=0;j < m;j++){
      c.at(i) += A.at(i).at(j)*b.at(j);
    }
  }

  for(int i=0;i < n;i++){
    cout << c.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 3212
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		try (Scanner sc = new Scanner(System.in)) {
			final String s = sc.next();
			
			System.out.println("2018" + s.substring(4));
			
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 22484
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()

    var ans = 1
    for (i in 1..n) {
        if (ans > k) {
            ans += k
        } else {
            ans *= 2
        }
    }
    println(ans)

}


Measured memory_bytes: 29788
#include<cstdio>
#include<cstring>
char str[100015];
int n;
int main(){
    scanf("%d",&n);
    scanf("%s",str);
    int i=0,j=0;
    int ans=1;
    while(j<n){
        if(str[i]!=str[j]){
            i=j;
            ans++;
        }
        j++;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
// ABC067_A.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int g[]{ 0,2,0,1,0,1,0,0,1,0,1,0 }, x, y;
	cin >> x >> y;
	if (g[--x] == g[--y]) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin >> n;
    vector<long long>a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    long long ans=1;
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        if(a[i]==0){
            cout << 0;
            return 0;
        }
        if(ans<=1000000000000000000/a[i]){
            ans*=a[i];
        }
        else{
            cout << -1;
            return 0;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3996
#include <iostream>
using namespace std;
int main(){
    int x,y;
    while(1){
        cin>>x>>y;
        if(x==0&&y==0)break;
        if(x<=y){cout<<x<<" "<<y;}
        else{cout<<y<<" "<<x;}
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3072
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb emplace_back
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()

const int prime = 1e9+7;

int mod(int a, int p = prime)
{
	a %= p;
	return a >= 0 ? a : a+p;
}

const int maxn = 1e5+10;

int dp[maxn][13];

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

	string s;
	cin >> s;

	int n = sz(s);

	for(int i = 0; i < n; ++i)
	{
		if(!i)
		{
			if(s[i] == '?')
			{
				for(int j = 0; j < 10; ++j)
					dp[i][j]++;
			}
			else
			{
				dp[i][s[i]-'0']++;
			}
		}
		else
		{
			if(s[i] == '?')
			{
				for(int j = 0; j < 13; ++j)
				{
					for(int k = 0; k < 10; ++k)
					{
						int num = j*10+k;
						num %= 13;
						dp[i][num] = mod(dp[i][num] + dp[i-1][j]);
					}
				}
			}
			else
			{
				int dig = s[i]-'0';
				for(int j = 0; j < 13; ++j)
				{
					int num = j*10 + dig;
					num %= 13;
					dp[i][num] = mod(dp[i][num] + dp[i-1][j]);
				}
			}
		}
	}

	cout << dp[n-1][5];

	return 0;
}

Measured memory_bytes: 10604
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int N;
	cin >> N;
	int *T = new int[N];
	int Ttotal = 0;
	for (int i = 0; i < N; i++) {
		cin >> T[i];
		Ttotal += T[i];
	}

	int M;
	cin >> M;
	int P, X;
	for (int i = 0; i < M; i++) {
		cin >> P >> X;
		cout << Ttotal - T[P - 1] + X << endl;
	}
}

Measured memory_bytes: 256
//Practice more and more
//learn for better
#define bn begin()
#define en end()
#define mx 5000010
#define pb push_back
#define PI (2.0*acos(0.0))
#define ALL(a) a.begin(),a.end()
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rep(a,b) for(int a=0;a<b;++a)
#define fastio ios::sync_with_stdio(false)
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int>  vi;
typedef vector<ll>   vll;
bool m[200010];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
	ll b,a,n,i,t,tmp;
	double d,e;
	cin>>a>>d;
	n=d*10000;
	b=a*n;
	printf("%lld\n",b/10000);

	return 0;
}

Measured memory_bytes: 3772
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadLine();

            WriteLine(n[0] == n[2] ? "Yes" : "No");
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}



Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const long long INF = 1LL << 60;

int main(){
  map<int, int> mp;
  int n; cin >> n;

  rep(i, n){
    int a; cin >> a;
    mp[a-1]++;
    mp[a]++;
    mp[a+1]++;
  }

  int ans = 0;
  for(auto p : mp){
    chmax(ans, p.second);
  }

  cout << ans << endl;

  return 0;
}


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


int main(){
  string s;
  cin >> s;
  int ans = 0;
  for(int i=0; i<s.size(); i++){
    if((i+1)%2==0){
      if(s.at(i)=='L' || s.at(i)=='U' || s.at(i)=='D'){ans++;}
    }else{
        if(s.at(i)=='R' || s.at(i)=='U' || s.at(i)=='D'){ans++;}
      }
  }
  if(ans==s.size()){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int A,B,C,tot,a,b,c;
int main(){
    scanf("%d%d%d",&A,&B,&C);
    while(!((A&1)||(B&1)||(C&1)))
	{
        if(A==B&&B==C)
		{
            puts("-1");
            return 0;
        }
        tot++,a=(B+C)>>1,b=(A+C)>>1,c=(B+A)>>1;
        A=a,B=b,C=c;
    }
     
    printf("%d\n",tot);
    return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define size(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    for1(i,5){
        int x;
        cin>>x;
        if(x==0){
            cout<<i;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3648
S = input()

def saiki(i,s = S[0]):
    _sum = 0
    if i == len(S) - 1:
        ans = eval(s)
        return ans
    a = saiki(i + 1, s + "+" + S[i+1])
    b = saiki(i + 1, s + S[i+1])
    
    return a + b
    
print(saiki(0))


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;


// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// -------------------------------------------------------------------------------------

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

  cout << string(w+2, '#') << endl;
  rep(i, h) {
    string s;
    cin >> s;
    cout << "#" << s << "#" << endl;
  }
  cout << string(w+2, '#') << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;

int main()
{
  long long int N,M,ans,z=0;
  cin>>N>>M;
  cout<<  min(N,M/2)+max(z,(M-2*N)/4) <<endl;
}



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

typedef struct{
  int parent;
  int right;
  int left;
}BT;

BT bt[26];
int n;

void Preorder(int a){
  if(a == -1) return;

  printf(" %d",a);
  Preorder(bt[a].left);
  Preorder(bt[a].right);

}

void Inorder(int a){
  if(a==-1)return;

  Inorder(bt[a].left);
  printf(" %d",a);
  Inorder(bt[a].right);
}

void Postorder(int a){
  if(a==-1)return;

  Postorder(bt[a].left);
  Postorder(bt[a].right);
  printf(" %d",a);
}

int main(){
  int i,j,num,depth = 0;
 

  
  scanf("%d",&n);

  for(i=0;i<n;++i) bt[i].parent = -1;

  for(i=0;i<n;i++){
    scanf("%d",&num);
    scanf("%d%d",&(bt[num].left),&(bt[num].right));

    if(bt[num].left != -1 &&bt[num].right != -1){
      bt[bt[num].left].parent = num;
      bt[bt[num].right].parent = num;
      
    }
    else if(bt[num].left != -1) bt[bt[num].left].parent = num;
    else if(bt[num].right != -1) bt[bt[num].right].parent = num;
  }

  for(i=0;bt[i].parent != -1;++i);
  
  printf("Preorder\n");
  Preorder(i);
  printf("\n");

  printf("Inorder\n");
  Inorder(i);
  printf("\n");

  printf("Postorder\n");
  Postorder(i);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2076
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long

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

  vector<ll> A(N), B(N);
  for(ll i=0; i<N; ++i) cin >> A[i];
  for(ll i=0; i<N; ++i) cin >> B[i];

  ll ans = 1e10;
  ll pos_0 = 0b101010101010101010;

  vector<ll> C(N);
  vector<ll> P(N);

  ll n_operation;
  
  for(ll color=0; !(color>>N); ++color) {
    ll sum_color = 0;
    ll pos_1 = color ^ pos_0;
    for(ll i=0; i<N; ++i) {
      C[i] = ((color>>i)&1 ? B[i] : A[i]);
      P[i] = (pos_1>>i)&1;
      sum_color += ((color>>i)&1);
    }
    if (sum_color&1) continue;

    vector<ll> C_sorted(C);
    sort(C_sorted.begin(), C_sorted.end());
    
    n_operation = 0;
    bool found;
    for(ll i=0; i<N; ++i) {
      found = false;
      ll j=i;
      for(; j<N; ++j) {
        if(C[j]==C_sorted[i] && P[j]==(i&1)) { found = true; break; }
      }

      if (found) {
        n_operation += j-i;
        for(ll k=j; k>i; --k) {
          ll bC = C[k]; C[k]=C[k-1]; C[k-1]=bC;
          ll bP = P[k]; P[k]=P[k-1]; P[k-1]=bP;
        }
        
      } else { break; }

    }

    if(found) ans = min(ans, n_operation);
    
  }

  cout << (ans<1e10 ? ans : -1) << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int k;
  cin>>k;
  cout<<a[k-1]<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
 
  
    ll n,x,t;
    cin>>n>>x>>t;
    if(n%x==0)
    {
      cout<<t*(n/x)<<endl;
    }
    else
    {
      cout<<t*((n/x)+1)<<endl;
    }
    
   
    
    
    
  }
  

  












Measured memory_bytes: 3588
BLANK = 0
O = 1
X = -1
H = 8
W = 8

def put!(field, y, x, color)
  field[y][x] = color
  dy = [-1, -1, -1, 0, 1, 1, 1, 0]
  dx = [-1, 0, 1, 1, 1, 0, -1, -1]
  8.times do |i|
    ny = y + dy[i]
    nx = x + dx[i]
    count = 0
    while field[ny][nx] == -color do
      count += 1
      ny += dy[i]
      nx += dx[i]
    end
    next if field[ny][nx] != color || count == 0
    ny = y + dy[i]
    nx = x + dx[i]
    while field[ny][nx] == -color do
      field[ny][nx] = color
      ny += dy[i]
      nx += dx[i]
    end
  end
  1
end

def put?(field, y, x, color)
  return 0 if field[y][x] != BLANK
  sum = 0
  dy = [-1, -1, -1, 0, 1, 1, 1, 0]
  dx = [-1, 0, 1, 1, 1, 0, -1, -1]
  8.times do |i|
    ny = y + dy[i]
    nx = x + dx[i]
    count = 0
    while field[ny][nx] == -color do
      count += 1
      ny += dy[i]
      nx += dx[i]
    end
    next if field[ny][nx] != color || count == 0
    sum += count
  end
  sum
end

def mami(field)
  max = y = x = 0
  for i in 1..H do
    for j in 1..W do
      count = put?(field, i, j, O)
      next if max >= count
      max = count
      y = i
      x = j
    end
  end
  max > 0 ? put!(field, y, x, O) : 0
end

def witch(field)
  max = y = x = 0
  H.downto(1) do |i|
    W.downto(1) do |j|
      count = put?(field, i, j, X)
      next if max >= count
      max = count
      y = i
      x = j
    end
  end
  max > 0 ? put!(field, y, x, X) : 0
end

field = Array.new(H+2) {Array.new(W+2, BLANK)}
for i in 1..H do
  field[i][1, W] = gets.chomp.chars.map{|c| c == "o" ? O : (c == "x" ? X : BLANK)}
end

turn = O
pass = 0
while true do
  case turn
    when O
      mami(field) > 0 ? pass = 0 : pass += 1
    when X
      witch(field) > 0 ? pass = 0 : pass += 1
  end
  break if pass == 2
  turn *= -1
end

for i in 1..H do
  field[i][1,W].map{|c| putc c == 0 ? "." : (c == 1 ? "o" : "x")}
  puts
end

Measured memory_bytes: 6244
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

S = sum(A)

idx = dict()
for i in range(len(A)):
	idx.setdefault(A[i], 0)
	idx[A[i]] += 1

for _ in range(Q):
	B, C = map(int, input().split())
	idx.setdefault(B, 0)
	idx.setdefault(C, 0)
	S += (C-B) * idx[B]
	idx[C] += idx[B]
	idx[B] = 0
	print(S)

Measured memory_bytes: 23712
N, M = map(int, input().split())
e = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    e[a].append(b)
ans = 0
minb = float("inf")
for i in range(1, N + 1):
    if i == minb:
        ans += 1
        minb = float("inf")
    if len(e[i]):
        minb = min(minb, min(e[i]))
print(ans)


Measured memory_bytes: 17968
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	static double A, B, X;

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		A = (double) sc.nextInt();
		B = (double) sc.nextInt();
		X = (double) sc.nextInt();
		double theta;

		if (X <= A * A * B / 2)
			theta = keisan();

		else
			theta = keisan2();

		System.out.println(theta);

	}

	public static double keisan() {
		return (Math.PI / 2 - Math.atan(2 * X / (A * B * B))) * 180 / Math.PI;

	}

	public static double keisan2() {
		return Math.atan(2 * B / A - 2 * X / (A * A * A)) * 180 / Math.PI;

	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;



int main(){
	int N,K;
	cin >> N >> K;
	vector<P> a(N);
	vector<ll> f(N + 1,0);
	for(int i = 0; i < N; i++) {
		ll t,d;cin>>t>>d;
		a[i] = mp(d,t);
	}
	sort(RALL(a));
	priority_queue<ll,vector<ll>,greater<ll>> que1;
	vector<bool> used(N + 1,false);//一個使ってるか
	ll sum = 0;
	ll kind = 0;
	ll res = 0;
	for(int i = 0; i < N; i++) {
		if (i < K){
			if (!used[a[i].sc]){
				sum += a[i].fs;
				kind ++;
				used[a[i].sc] = true;
			}
			else{
				sum += a[i].fs;
				que1.push(a[i].fs);
			}
			f[kind] = sum;
			res = max(res,sum + kind * kind);
		}
		else{
			if (que1.empty())break;
			if (!used[a[i].sc]){
				sum -= que1.top();
				sum += a[i].fs;
				kind++;
				used[a[i].sc] = true;
				que1.pop();
				f[kind] = sum;
				res = max(res,sum + kind * kind);
			} 
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define ll long long
#define f(i,l,r) for(int i=l;i<r;i++)
#define debug(x) cout<<#x<<'='<<(x)<<endl
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
    cin>>n>>w;
    ll vmax=1000*n;
    ll dp[n+1][vmax+1],wi,vi;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=vmax;j++)
            dp[i][j]=1000000005;
    for(int i=1;i<=n;i++)
    {
        cin>>wi>>vi;
        for(int j=0;j<vi;j++)
        dp[i][j]=min(dp[i-1][j],wi);
        for(int j=vi;j<=vmax;j++)
        dp[i][j]=min(dp[i-1][j],wi+dp[i-1][j-vi]);

    }
   // cout<<dp[0][3000]<<" ";
    /*
    for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=vmax;j++)
                cout<<dp[i][j]<<" ";
            cout<<"\n";
        }*/
    for(int j=vmax;j>=0;j--)
    {
        for(int i=0;i<=n;i++)
        {
            if(dp[i][j]<=w)
            {   
                cout<<j+1;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 79232
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

M = pow(10, 9) + 7


def main():
    n, k = map(int, input().split())

    ans = 0
    for i in range(n - k + 1 + 1):
        ans += range_sum(i, n) % M - range_sum(0, n - i) % M + 1
        ans %= M
    print(ans)


def range_sum(a, b):
    if a < 1:
        return b * (b + 1) // 2
    else:
        return b * (b + 1) // 2 - a * (a - 1) // 2


if __name__ == '__main__':
    main()


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


int main(){

    int n;
    cin >> n;

    vector<pair<int,int>> ba(n);

    rep(i,n){
        cin >> ba[i].second >> ba[i].first;
    }

    sort(ba.begin(),ba.end());
    ll aa=0;
    ll bb=0;
    rep(i,n){
        bb=ba[i].first;
        aa+=ba[i].second;
        if(aa>bb){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    

    return 0;
}

Measured memory_bytes: 1920
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

pre = a[0] - 1
ans = 0
for i in range(n):
    if a[i] - 1 - pre == 1:
        ans += c[a[i] - 1 - 1]
    ans += b[a[i] - 1]
    pre = a[i] - 1
print(ans)


Measured memory_bytes: 38384