akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace abc0818
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
            int[] v = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            Array.Sort(v);
            //Array.Reverse(v);
            double ave = v[0];
            for(int i = 1; i < v.Length; i++)
            {
                ave = (ave + v[i]) / 2;
            }
            Console.WriteLine(ave);
        }
    }
}


Measured memory_bytes: 13396
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<int,int>
#define ti3 tuple<int,int,int>

struct BIT
{
    std::vector<int> bit;
    
    BIT(int size) : bit(size, 0){ }
    
    void add(int k, int x) {
        while (k < bit.size()) {
            bit[k] += x;
            k += k &-k;
        }
    }
    int sum(int k) {
        int res = 0;
        while (k > 0) {
            res += bit[k];
            k -= k&-k;
        }
        return res;
    }
};

struct UnionFind {
    vector<int> data;
    
    UnionFind(int size) : data(size, -1) { }
    
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y)
        {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};


int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    string s = (c <= b && c >= a) ? "Yes" : "No";
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
def binary_search(array, key)
    left = 0
    right = array.length
    while left < right
        mid = (left + right) / 2
        if array[mid] == key
            return mid
        elsif key < array[mid]
            right = mid
        else
            left = mid + 1
        end
    end
    return -1
end

line_count = gets.to_i
array = gets.split(" ").map(&:to_i)
search_count = gets.to_i
search_array = gets.split(" ").map(&:to_i)
puts search_array.count{|n| binary_search(array, n) > 0}



Measured memory_bytes: 15348
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();

            if (S == "AAA")
                Console.WriteLine("No");
            else if (S == "BBB")
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 13140
class Point
  attr_accessor :x, :y
  def initialize(x, y)
    @x = x
    @y = y
  end

  def -(p)
    Point.new(x - p.x, y - p.y)
  end
end

def dot(a, b)
  a.x * b.x + a.y * b.y
end

def cross(a, b)
  a.x * b.y - a.y * b.x
end

Segment = Struct.new('Segment', :p1, :p2)

def is_orthogonal?(s1, s2)
  dot(s1.p2 - s1.p1, s2.p2 - s2.p1).zero?
end

def is_parallel?(s1, s2)
  cross(s1.p2 - s1.p1, s2.p2 - s2.p1).zero?
end

n = gets.to_i
n.times do
  x0, y0, x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_i)
  p0 = Point.new(x0, y0)
  p1 = Point.new(x1, y1)
  p2 = Point.new(x2, y2)
  p3 = Point.new(x3, y3)
  s1 = Segment.new(p0, p1)
  s2 = Segment.new(p2, p3)
  if is_orthogonal?(s1, s2)
    puts 1
  elsif is_parallel?(s1, s2)
    puts 2
  else
    puts 0
  end
end


Measured memory_bytes: 6888
#include<bits/stdc++.h>
using namespace std;
int cnt[10000001];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=n;j+=i )
            cnt[j]++;
    }
   // for(int i=1;i<=n;i++)cout<<cnt[i]<< " ";
    long long ans=0;
    for(long long int i=1;i<=n;i++)
        ans+=(i*cnt[i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 42628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=305,INF=1<<30;
struct edge{int to,cap,rev,id,check;};

vector<edge> G[MAX];
int level[MAX];
int iter[MAX];

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

void BFS(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s] =0;
    que.push(s);
    while(!que.empty()){
        int v=que.front();que.pop();
        for(int i=0;i<G[v].size();i++){
            edge &e =G[v][i];
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

int DFS(int v,int t,int f){
    if(v==t) return f;
    for(int &i=iter[v];i<G[v].size();i++){
        edge &e =G[v][i];
        if(e.cap>0&&level[v]<level[e.to]){
            int 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;
}

int max_flow(int s,int t){
    int flow=0;
    for(;;){
        BFS(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=DFS(s,t,INF))>0){
            flow+=f;
        }
    }
}


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<pair<int,int>> E(M);
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        add_edge(a,b,1,-1);
        add_edge(b,a,1,i);
        E[i]=mp(a,b);
    }
    int s,t;cin>>s>>t;
    s--;t--;
    cout<<max_flow(s,t)<<endl;
    
    set<int> ans;
    for(int i=0;i<N;i++){
        for(auto x:G[i]){
            if(x.check==1){
                if(x.cap==0&&x.id>=0) ans.insert(x.id);
            }
        }
    }
    
    cout<<si(ans)<<endl;
    for(int a:ans) cout<<a+1<<endl;
}




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

int main(){

    int N; cin >> N;
    int count = 0;
    vector<int> a(N);

    for(int i=0; i<N; i++){
        cin >> a.at(i);
        if(1 == a.at(i)%2 && 0 == i%2){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;++i) cin>>A[i];
  sort(A.begin(), A.end());
  int minnum = A[0];
  int maxnum = A[N-1];
  pair<int, int> ans[N-1];
  for(int i=1;i<N-1;++i) {
    if(A[i]>=0) {
      ans[i-1] = mp(minnum, A[i]);
      minnum -= A[i];
    }
    else {
      ans[i-1] = mp(maxnum, A[i]);
      maxnum -= A[i];
    }
  }
  cout<<maxnum-minnum<<endl;
  for(int i=0;i<N-2;++i) cout<<ans[i].fi<<" "<<ans[i].se<<endl;
  cout<<maxnum<<" "<<minnum<<endl;
}



Measured memory_bytes: 4344
#include <atcoder/dsu>
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
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 = 1e18;


int main(){
    //input
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,q;
    cin >> n >> q;
    dsu d(n);
    rep(i,q){
        ll t,u,v;
        cin >> t >> u >> v;
        if(t==0){
            d.merge(u,v);
        }
        else{
            if(d.same(u,v))cout<<1<<endl;
            else cout << 0 << endl;
        }
    }

    
    return 0;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll sum = 0, ans = n;
  for (int i = n-1; i >= 0; i--) {
    if (sum + a[i] < k)
      sum += a[i];
    else {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
const int N = 1e6+100;
typedef long long ll;
ll a[N];
int main(){
	int n;
	cin>>n;ll sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];sum+=a[i];
	}
	ll ans=9999999999;
	ll ans1=0; 
	for(int i=1;i<=n;i++){
		ans1+=a[i];
		ans=min(ans,abs(ans1-(sum-ans1)));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
N,K = gets.split.map(&:to_i)
val = gets.split.map(&:to_i)
T = [K, N].min
res = 0

(T+1).times do |left|
  (0..(T-left)).each do |right|
    a = val[0...left]+val[(N-right)...N]    
    a.sort!
    sum = a.inject(&:+) || 0
    [K-left-right, a.length].min.times do |i|
      break if a[i] >= 0
      sum -= a[i]
    end
    res = sum if sum > res
  end
end

puts res


Measured memory_bytes: 1916
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;

  vll cnt(3, 0);
  REP(i, 0, S.size()) {
    cnt[S[i] - 'a']++;
  }

  if (1 < max({cnt[0], cnt[1], cnt[2]}) - min({cnt[0], cnt[1], cnt[2]})) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}


Measured memory_bytes: 512
A,B,C,D = map(int,input().split())
c,d = C,D
count = 0

# CとDの最大公約数をユークリッドの互除法より求め、最小公倍数を導出
while c!=0 and d!=0:
    if c > d:
        c %= d
    else:
        d %= c

gcd = max(c,d)
# B以下の整数からCの倍数とDの倍数の数を引いた数を求める
# A-1に関しても同様の処理を行い、その差が答えとなる
A_prime = A-1
print((B-(B//C+B//D)+(B//(C*D//gcd)))-
     (A_prime-(A_prime//C+A_prime//D)+(A_prime//(C*D//gcd))))

Measured memory_bytes: 61816
n, k= map(int, input().split())

import math 

def findNumberOfDigits(n, base): 
       
    dig = (math.floor(math.log(n) /
                 math.log(base)) + 1) 
      
    print(dig)
  
  
# calling the method 
findNumberOfDigits(n, k) 

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n, w, d;
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0){
      break;
    }
    vector<pair<int, int>> C(1);
    C[0] = make_pair(w, d);
    for (int i = 0; i < n; i++){
      int p, s;
      cin >> p >> s;
      p--;
      int a = C[p].first;
      int b = C[p].second;
      C.erase(C.begin() + p);
      s %= (a + b) * 2;
      if (s >= a + b + a){
        s = a * 3 + b * 2 - s;
      }
      if (s >= a + b){
        s = a * 2 + b - s;
      }
      if (s < a){
        if (s > a / 2){
          s = a - s;
        }
        C.push_back(make_pair(s, b));
        C.push_back(make_pair(a - s, b));
      } else {
        s -= a;
        if (s > b / 2){
          s = b - s;
        }
        C.push_back(make_pair(a, s));
        C.push_back(make_pair(a, b - s));
      }
    }
    vector<int> ans(n + 1);
    for (int i = 0; i <= n; i++){
      ans[i] = C[i].first * C[i].second;
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i <= n; i++){
      cout << ans[i];
      if (i < n){
        cout << ' ';
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3144
from collections import deque

sX, sY, eX, eY = map(int, input().split())

N = int(input())
circles = [(sX, sY, 0)]
for _ in range(N):
    x, y, r = map(int, input().split())
    circles.append((x, y, r))
circles.append((eX, eY, 0))

edges = [[float('inf')] * (N + 2) for _ in range(N + 2)]

for i, (x, y, r) in enumerate(circles):
    for j, (u, v, s) in enumerate(circles):
        d = max(0, ((x - u)**2 + (y - v)**2)**0.5 - (r + s))
        edges[i][j] = d

minDist = [float('inf')] * (N + 2)
confilm = [False] * (N + 2)
minDist[0] = 0
for _ in range(N + 2):
    minNode = (-1, float('inf'))
    for to in range(N + 2):
        if not confilm[to] and minDist[to] < minNode[1]:
            minNode = (to, minDist[to])
    confilm[minNode[0]] = True
    for to in range(N + 2):
        minDist[to] = min(minDist[to], minDist[minNode[0]] + edges[minNode[0]][to])

print(minDist[-1])



Measured memory_bytes: 78772
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";

signed main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	/************************************/
	
	int n; cin>>n;
	int h[n+1];
	for(int i=1; i<=n; i++)
		cin>>h[i];
	
	int dp[n+1];
	fill(dp, dp+n+1, 1e9+8);
	dp[1] = 0;
	
	for(int i=1; i<=n; i++)
	{
		for(int j=i+1; j<=i+2 && j<=n; j++)
			dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
	}
	cout<<dp[n]<<"\n";
	
	
return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    int n, a, b; cin >> n >> a >> b;
    cout << min(a*n, b);
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+500;
int w[N],n;
int cmp(const int &a,const int &b){return a>b;}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",w+i);
    sort(w,w+n,cmp);
    int i=0;
    for(;i<n;i++)if(w[i+1]<=i+1)break;
    int j=i+1;
    for(;j<n;j++)if(w[j]<=i)break;
    if(((w[i]-i)&1)&&((j-i)&1)){puts("Second");}
    else puts("First");
}

Measured memory_bytes: 2036
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define endl "\n"

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

const int N = 1e5 + 7;
vvi adj(N);
vi visited(N), dist(N), par(N);

void bfs(int x, int n) {
	visited[x] = true;
	dist[x] = 0;

	queue<int> q;
	q.push(x);

	while (!q.empty()) {
		int x = q.front();
		q.pop();

		for (auto u : adj[x]) {
			if (!visited[u]) {
				q.push(u);
				visited[u] = true;
				dist[u] = dist[x] + 1;
				par[u] = x;
			}
		}
	}
}

signed main() {
	crap;

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

	while (m--) {
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	bfs(1, n);

	for (int i = 2; i <= n; i++) {
		if (!visited[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	for (int i = 2; i <= n; i++) {
		cout << par[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 14424
n = int(input())
h = list(map(int, input().split()))
ans = 'Yes'
for i in range(len(h)):
  if i > 0:
    if h[-i-1] > prev:
      if h[-i-1] - 1 == prev:
      	h[-i-1] -= 1
      else:
        ans = 'No'
        break
  prev = h[-i-1]
print(ans)

Measured memory_bytes: 14224
#include<iostream>
#include<map>
#include<cstring>
using namespace std;
int main(){
    map<string,int>M;
    pair<string,int>m_len,a;
    a.second=m_len.second=0;
    while(true){
        char str[33];
        if(!(cin>>str))break;
        M[str]++;
        if(strlen(str)>m_len.second){
            m_len.first=str;
            m_len.second=strlen(str);
        }
    }

    for(map<string,int>::iterator ite=M.begin();ite!=M.end();ite++){
        if(ite->second>a.second){
            a.first=ite->first;
            a.second=ite->second;
        }
    }
    cout<<a.first<<" "<<m_len.first<<endl;


    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)

#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long ll;
const int N = 2e5+1 , M = 5e5+1, OO = 0x3f3f3f3f,MOD = 1e9+7;
map<int,pair<ll,ll>> ans;
int arr[N];
ll tot=0;
int main()
{
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;++i) 
  {
    scanf("%d",arr+i);
    ans[arr[i]].first++;
    ans[arr[i]].second= (ans[arr[i]].first)*(ans[arr[i]].first-1)>>1;
  }
  for(auto it =ans.begin();it!=ans.end();it++) tot+=it->second.second;  
  
  for(int i=0;i<n;++i)
  {
    ll val = ans[arr[i]].second;
    ll freq = ans[arr[i]].first;
    printf("%lld\n",tot-(val-(((freq-1)*(freq-2))>>1) ));
  }
  
  
  #ifdef _LOCAL_DEFINE  
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 10240
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N=0;
  int W[1000]={0};
  int T=200;
  int sum=0;
  int a=0;
  int fire=0;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>W[i];
    sum+=W[i];
  }
  for(int i=0;i<N;i++){
    sum-=W[i];
    a+=W[i];
    fire=sum-a;
    if(fire<0){
      fire*=-1;
    }
    if(T>fire){
      T=fire;
    }
  }
  cout<<T;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
const int maxn=4e5+5;
ll pacnt;
int n,m,tot,flag,cnt;
int a1,a2,a3;
int head[maxn],des[maxn],nxt[maxn];
int col[maxn];
void adde(int x,int y){
	des[++tot]=y;nxt[tot]=head[x];head[x]=tot;
}
void dfs(int x,int c){
	cnt++;
	col[x]=c;
	Rep(p,x){
		if(col[des[p]]==-1)dfs(des[p],!c);
		else if(col[des[p]]==c)flag=1;
	}
}
ll P(int x){
	return 1ll*x*x;
}
int main(){
	memset(col,-1,sizeof col);
	read(n);read(m);
	pacnt=1ll*n*n;
	rep(i,1,m){
		int x,y;read(x);read(y);
		adde(x,y);adde(y,x);
	}
	rep(i,1,n)if(col[i]==-1){
		if(!head[i])a3++;
		else{
			cnt=0;
			flag=0;
			dfs(i,0);
			if(flag)a2++;
			else a1++;
		}
	}
	ll ans=P(a1+a2+a3)+P(a1)+1ll*a3*(2*n-2*(a1+a2+a3));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define int long long 

using namespace std;

const int maxn = 1e5 + 7;

vector<array<int, 3>> edge;
int l;
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    cin >> l;
    int n = 0, val = 0;
    while((1 << n) - 1 <= l - 1) n++;
    for(int i = 2; i <= n; i++)
    {
        edge.push_back({i - 1, i, (1 << n - i)});
        edge.push_back({i - 1, i, 0});
    }
    val = 0;
    for(int i = 1; i <= n; i++)
    {
        int total = (1 << n - i) - 1;
        if(total + val <= l - 1)
        {
            if(i != 1)
            edge.push_back({1, i, val});
            val += total + 1;
        }
    }
    cout << n << ' ' << edge.size() << '\n';
    for(auto i: edge) cout << i[0] << ' ' << i[1] << ' ' << i[2] << '\n';
}

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

int main() {
	int n; cin >> n;
	vector<int> F(50, 0);

	F[0] = 1;
	for (int i = 0; i < n; ++i) {
		F[i + 1] += F[i];
		F[i + 2] += F[i];
	}

	cout << F[n] << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int( 1e5 +5)

int main(){
    int n;
    cin >> n;
    llong A[MAX],B[MAX];
    REP(i,n) scanf("%lld",&A[i]);
    REP(i,n) scanf("%lld",&B[i]);    
    llong sa[MAX];
    llong su;
    REP(i,n){
        sa[i] = A[i] - B[i];
        su += sa[i];
    }
    if(su < 0){
        cout << -1 << endl;
        return 0;
    }
    sort(sa,sa+n);
    int cnt = 0;
    int ind = n-1,now = sa[n-1];
    llong mai = 0;
    REP(i,n){
        if(sa[i] >= 0) break;
        cnt ++;
        mai += sa[i];
    }

    REPR(i,n-1){
        if(mai>=0) break;
        cnt ++;
        mai += sa[i];
    }
    cout << cnt << endl;

    
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll min_num = N;
    for (ll i = N; i >= 1; i--) {
        if (N <= i * (i + 1) / 2) {
            min_num = min(min_num, i);
        }
    }
    ll sum = min_num * (min_num + 1) / 2;
    for (ll i = 0; i < min_num; i++) {
        if (sum - i == N) {
            for (ll j = 1; j <= min_num; j++) {
                if (j == i) continue;
                cout << j << endl;
            }
            return 0;
        }
    }
    return 0;
}

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

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

const double EPS = 1e-10;

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

void WarshallFloyd(int N,vector<vector<ll>> &dist){
	rep(k,N)rep(i,N){
		if(dist[i][k] == LINF) continue;
		rep(j,N){
			if(dist[k][j] == LINF) continue;
			dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
		}
	}
}

int main(){
    int H,W; cin >> H >> W;
    vector<string> S(H);
    vector<vector<ll>> dist(H*W,vector<ll>(H*W,LINF));
    rep(i,H){
        cin >> S[i];
    }
    int dh[] = {0,1,-1,0};
    int dw[] = {1,0,0,-1};
    rep(i,H)rep(j,W){
        rep(k,4){
            if(i+dh[k] >= 0 && i+dh[k] < H && j+dw[k] >= 0 && j+dw[k] < W){
                if(S[i][j] == '.' && S[i+dh[k]][j+dw[k]] == '.'){
                    dist[W*i+j][W*(i+dh[k])+j+dw[k]] = 1;
                    dist[W*(i+dh[k])+j+dw[k]][W*i+j] = 1;
                }
            }
        }
    }
    rep(i,H*W)rep(j,H*W) if(i == j) dist[i][j] = 0;
    WarshallFloyd(H*W,dist);
    ll ans = 0;
    rep(i,H*W)rep(j,H*W){
        if(dist[i][j] != LINF) ans = max(ans,dist[i][j]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = INF;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int arr[n];
  fi(0, n) cin>>arr[i];
  sort(arr, arr+n);
  fi(arr[0], arr[n-1]+1) {
    ll s=0;
    fj(0, n){
      s+=(i-arr[j])*(i-arr[j]);
    }
    if(s<ans)ans=s;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second

const int max_n = 1e5+10;

int n;

priority_queue<ll> ql;
priority_queue<ll,vector<ll>,greater<ll>> qr;

ll xs[200010];

int main()
{
	read(n);
    ll g0 = 0;
    ll miny = 0;
    ll befl=0;
    ll dl=0, dr=0;
    for(;n--;){
		ll l, r; read(l, r);
		ll curl = r-l;
		dl += curl; dr += befl;
		if(ql.size()) miny += abs(ql.top()-dl - l);
		ll gx=(ql.empty()?0:ql.top()-dl);
		for(int i=0; i<2; ++i) ql.push(l + dl);
		qr.push(ql.top()-dl-dr); ql.pop();
		while(ql.top()-dl>qr.top()+dr){
			qr.push(ql.top()-dl-dr);
			ql.push(qr.top()+dl+dr);
			ql.pop(); qr.pop();
		}
		++g0; befl=curl;
		if(g0>1){
			if(qr.top()+dr < gx) miny -= (gx-(qr.top()+dr));
			else if(gx < ql.top()-dl) miny -= ((ql.top()-dl) - gx);
		}
    }
    printf("%lld\n", miny);
    return 0;
}


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

int v[200], dp[1000001], dp2[1000001];
vector<int> v2;

int main()
{
  v[0] = 1;
  v2.push_back(1);
  for(int i = 1; i < 200; i++)
  {
    v[i] = v[i - 1];
    for(int j = 0; j <= i; j++)
      v[i] += j + 1;
    if(v[i] % 2)
      v2.push_back(v[i]);
  }
  fill(dp, dp + 1000001, 1000000000);
  fill(dp2, dp2 + 1000001, 1000000000);
  dp[0] = dp2[0] = 0;
  for(int i = 0; i <= 1000000; i++)
  {
    for(int j = 0; j < 200; j++)
    {
      if(v[j] <= i)
        dp[i] = min(dp[i], dp[i - v[j]] + 1);
      if(j < v2.size() && v2[j] <= i)
        dp2[i] = min(dp2[i], dp2[i - v2[j]] + 1);
    }
  }
  while(true)
  {
    int n;
    cin >> n;
    if(!n)
      break;
    cout << dp[n] << " " << dp2[n] << endl; 
  }
}

Measured memory_bytes: 9028
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    H,W = map(int, input().split())
    S = [list(input().rstrip()) for _ in range(H)]
    tate = [[0]*W for _ in range(H)]
    yoko = [[0]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                yoko[i][j] = 0
            else:
                if j==0:
                    yoko[i][j] = 1
                else:
                    yoko[i][j] = yoko[i][j-1] + 1
        for j in range(W-1, 0, -1):
            if yoko[i][j-1]==0 or yoko[i][j]==0:
                continue
            yoko[i][j-1] = yoko[i][j]
    
    for i in range(W):
        for j in range(H):
            if S[j][i] == '#':
                tate[j][i] = 0
            else:
                if j==0:
                    tate[j][i] = 1
                else:
                    tate[j][i] = tate[j-1][i] + 1
        for j in range(H-1, 0, -1):
            if tate[j-1][i]==0 or tate[j][i]==0:
                continue
            tate[j-1][i] = tate[j][i]
    res = 0
    for i in range(H):
        for j in range(W):
            res = max(res, tate[i][j]+yoko[i][j])
    print(res-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 245256
#include <iostream>
using namespace std;
int main(){
  int x;
  int min = 300000,count =0;
  int N[200010];
  cin >> x;
  for(int i=0;i<x;i++){
    cin >> N[i];
  }
  for(int i=0;i<x;i++){
    if(N[i]<min){
      min = N[i];
      count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main()
    {
        int[] a = new int[51];
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    for (int l = 0; l < 10; l++)
                    {
                        a[i + j + k + l]++;
                    }
                }
            }
        }
        string s;
        while ((s = Console.ReadLine()) != null)
        {
            Console.WriteLine(a[int.Parse(s)]);
        }
    }
}

Measured memory_bytes: 9100
def main():
    MOD = 10 ** 9 + 7

    S = int(input())
    dp = [0] * (S + 1)
    dp[0] = 1

    for x in range(3, S + 1):
        # dp[x-3] + dp[x-4] + dp[x-5] + ... + dp[0]
        # dp[x-3] + dp[x-1]
        dp[x] = (dp[x - 3] + dp[x - 1]) % MOD

    print(dp[S])


if __name__ == '__main__':
    main()


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

/* 「警告　W8060 おそらく不正な代入」は、if文などの条件式の中が==ではなく=とな

っている場合にでるエラー */

/* 「エラー E2134 複合文に}がない。」→そのまま */
/* 「エラー E2451 未定義のシンボル」→宣言がされていない。*/


/* 配列（とくに二次元配列以上）の初期化は array[4][13] = {0} というような書き方もある*/

int  mark_num(char c){
 if(c=='S')
	return 0 ;
 else if(c =='H')
	return 1 ;
 else if(c =='C')
	return 2 ;
 else if(c =='D')
	return 3 ;
}

char num_mark(int j){
 if(j==0)
   return 'S' ;
 else if(j==1)
   return 'H' ;
 else if(j==2)
   return 'C' ;
 else if(j==3) 
   return 'D' ;
}


int main(){
int n , m, fc ;
char c ;
int card[4][13] ;
/* 配列の初期化 */
for(int i=0;i<4;i++){
 for(int j=0;j<13;j++){
  card[i][j] = 0 ;
 }
}

cin >> n ;

for(int i=0;i<n;i++){
cin >> c >> m ;
fc = mark_num(c) ;
card[fc][m-1] = 1 ;
}


for(int i=0;i<4;i++){
 for(int k=0;k<13;k++){
  if(card[i][k] == 0){
    cout << num_mark(i) << " " << k+1 << endl;
  }
}
}

return 0 ;

}

Measured memory_bytes: 1164
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

Int A,B,N;

int main(void) {
    cin>>A>>B>>N;
    Int ans = 0;

    Int x = min(N,B-1);
    cout<<(A*x)/B<<endl;

    return 0;
}




Measured memory_bytes: 3132
from collections import deque

N, M = map(int, input().split())
S = input()[::-1] +'1'*M

if M >= N:
  print(N)
  exit()
  
q = deque([])

i = 0
j = 0
while i < N:
  f = 0
  for k in range(i+M,j,-1):
    if S[k] == '0':
      f = 1
      break
  j = i + M
  q.appendleft(k-i)
  i = k
  if f == 0:
    print(-1)
    exit()

print(' '.join(map(str, q)))

Measured memory_bytes: 83892
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
int A[10];
int ans = 0;
int N;
void dfs(int k, bool even) {
	if (k == N) {
		ans += even;
		return;
	}
	if (A[k] % 2 == 0) {
		dfs(k + 1, 1);
		dfs(k + 1, even);
		dfs(k + 1, even);
	}
	else {
		dfs(k + 1, even);
		dfs(k + 1, 1);
		dfs(k + 1, 1);
	}
}
int main() {
	cin >> N;
	rep(i, N) cin >> A[i];
	dfs(0, 0);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,a[3],MAX=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
    MAX = max(MAX,a[i]);
  }
  for(int i=1;i<=MAX;i++){
    bool dotti=true;
    for(int j=0;j<n;j++){
      if(a[j] % i != 0) dotti = false;
    }
    if(dotti == true) cout << i << endl;
  }
}

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

ll x, k ,d;

bool f(ll a) {
    ld ret = (ld)x/(ld)d;
    return ret<=(k-2*a);
}

int main() {
    cin>>x>>k>>d;
    ll lo=0, hi=k,ans = 0, mid;
    while(lo<=hi) {
       mid=(lo+hi)/2;
       if(f(mid)) ans=mid, lo=mid+1;
       else hi=mid-1;
    }
    // cout<<ans<<endl;
    if(ans+1<=k) cout<<min(abs(x+2*(ans)*d-k*d), abs(x+2*(ans+1)*d-k*d))<<endl;
    else if(ans-1>=0) cout<<min(abs(x+2*(ans)*d-k*d), abs(x+2*(ans-1)*d-k*d))<<endl;
    else cout<<abs(x+2*(ans)*d-k*d)<<endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    //入力
    int N;
    cin >> N;
    vector<int> Values(N);
    vector<int> Costs(N);
    for (int i = 0; i < N; i++) cin >> Values[i];
    for (int i = 0; i < N; i++) cin >> Costs[i];
    
    //価値-コストの結果を配列に入れる
    vector<int> True_Values(N);
    for (int i = 0; i < N; i++){
        True_Values[i] = Values[i] - Costs[i];
    }
    
    //価値 - コストが１以上の整数の場合のみ答えに足していく
    int ans = 0;
    for (int i = 0; i < N; i++){
        if (True_Values[i] >= 1) ans += True_Values[i];
    }
    
    //出力
    cout << ans << endl;
}

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

using namespace std; 

int main(){
	string s;
	cin >> s;
	int cnt=0;

	int x=s[0];

	for(int i=1; i<s.size(); i++){
		if(x=='0'){
			if(s[i]=='1'){
				// flag=1;
			}else{
				s[i]='1';
				cnt++;
			}
		}else{
			if(s[i]=='0'){
				// flag==2;
			}else{
				s[i]='0';
				cnt++;
			}
		}
		x=s[i];
	}

	cout << cnt;

return 0;

}










// int main()
// {		
// 	float a,b,c;
// 	cin >> a >> b >> c;

// 	float n = ((b-a)/c)+1;


// 	if(c==0 && a==b)
// 		cout << "YES";
// 	else if(c==0 && a!=b)
// 		cout << "NO";
// 	else if((b<0 && c>=0) || (b>=0 && c<0))
// 		cout << "NO";
// 	else{
// 		if(floor(n)==ceil(n))
// 		cout << "YES";
// 	else
// 		cout << "NO";
// 	}

// }


Measured memory_bytes: 512
N,X=map(int,input().split())

a,p=[1],[1]

for i in range(N):
  a.append(2*a[i]+3)
  p.append(2*p[i]+1)

def f(n,x):
  if n==0:return 0 if x<=0 else 1
  elif x<=1+a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1]+1+f(n-1,x-2-a[n-1])

print(f(N,X))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;

int toInt(string s) {
    stringstream ss(s);
    int ret;
    ss >> ret;
    return ret;
}

string toStr(int n) {
    stringstream ss;
    ss << n;
    return ss.str();
}

string next(string N) {
    sort(N.begin(), N.end());
    int S = toInt(N);
    reverse(N.begin(), N.end());
    int L = toInt(N);
    string ret = "0000" + toStr(L-S);
    return ret.substr((int)ret.size()-4);
}

int main() {
    string N;
    while (cin >> N, N != "0000") {
        if (N[0] == N[1] && N[1] == N[2] && N[2] == N[3]) {
            cout << "NA" << endl;
            continue;
        }
        int cnt = 0;
        while (N != "6174") {
            N = next(N);
            ++ cnt;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class BBattle {
public:
    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);

        int a,b,c,d;

        cin >> a >> b >> c >> d;


        while (c > 0 && a > 0) {
            c -= b;
            if (c <= 0) {
                cout << "Yes" << endl;
                return;
            }

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

	}
};


int main() {
	BBattle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;
int dp[2][2019];

int main(){
    string s; cin >> s;
    rep(i,2019) dp[1][i]=0;
    ll ans=0;
    bool f=true;
    int now;
    rep(i,s.length()){
        if(f) now=0;
        else now=1;
        f=f^1;
        rep(j,2019) dp[now][(j*10+(s[i]-'0'))%2019]=dp[now^1][j];
        dp[now][s[i]-'0']++;
        ans+=dp[now][0];
    }
    cout << ans << endl;
return 0;
}



Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <string.h>
using namespace std;

typedef pair<int,int> P;//y,x

const int dx[] = {1,0,-1,0,0};//東、南、西、北、無
const int dy[] = {0,1,0,-1,0};

int gdx[10];
int gdy[10];
int field[22][22];

int cost[22][22][22][22][10];

struct S
{
	P m;
	P g;
	int gp;
	S(P m_,P g_,int gp_):m(m_),g(g_),gp(gp_){}
};

int main(void)
{
	gdx[5]=0;gdx[8]=0;gdx[6]=1;gdx[4]=-1;gdx[2]=0;
	gdy[5]=0;gdy[8]=-1;gdy[6]=0;gdy[4]=0;gdy[2]=1;
	while(1){
		memset(cost,-1,sizeof(cost));
		memset(field,0,sizeof(field));
		P ms,gs;
		vector<int> gp;
		int W,H;
		cin >> H >> W;
		if(H==0 && W==0)
			return 0;
		for(int y=1;y<=H;++y){
			string in;
			cin >> in;
			for(int x=1;x<=W;++x){
				field[y][x] = in[x-1];
				if(field[y][x] == 'A'){
					field[y][x] = '.';
					ms.first = y;
					ms.second = x;
				}
				if(field[y][x] == 'B'){
					field[y][x] = '.';
					gs.first = y;
					gs.second = x;
				}
			}
		}
		string in;
		cin >> in;
		for(int i=0;i<in.size();++i){
			gp.push_back(in[i]-'0');
		}
		////////////////////////////////////////
		queue<S> q;
		q.push(S(ms,gs,0));
		int turn=0;
		P g(-1,-1);
		int gt=-1;
		bool isGoal=false;
		cost[ms.first][ms.second][gs.first][gs.second][gp.size()-1] = 0;
		while(!q.empty()){
			int size=q.size();
			for(int aaa=0;aaa<size;++aaa){
				S s = q.front(); q.pop();
				P gn = P(s.g.first+gdy[gp[turn]],s.g.second+gdx[gp[turn]]);
				if(field[gn.first][gn.second] == 0)
					gn = s.g;
				for(int i=0;i<5;++i){
					P mn = P(s.m.first+dy[i],s.m.second+dx[i]);
					if(cost[mn.first][mn.second][gn.first][gn.second][turn] == -1 && field[mn.first][mn.second] == '.'){
						cost[mn.first][mn.second][gn.first][gn.second][turn] = cost[s.m.first][s.m.second][s.g.first][s.g.second][(turn+gp.size()-1)%gp.size()]+1;
						if(mn == gn){
							g = mn;
							gt =  turn;
						}
						q.push(S(mn,gn,gp[turn]));
					}
				}
				if(g.first != -1)
					break;
			}
			if(g.first != -1)
				break;
			++turn;
			turn%=gp.size();
		}
		if(g.first != -1)
			cout << cost[g.first][g.second][g.first][g.second][gt] << ' ' << g.first-1  << ' '<< g.second-1 << endl;
		else
			cout << "impossible" << endl;
	}
}

Measured memory_bytes: 10396
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        Dictionary<char, int> dic = new Dictionary<char, int>();
        dic['N'] = 0;
        dic['S'] = 1;
        dic['E'] = 2;
        dic['W'] = 3;
        bool[] exist = new bool[4];
        string S = cin.next();
        foreach (var c in S)
        {
            exist[dic[c]] = true;
        }

        if (exist[0] == exist[1] && exist[2] == exist[3]) Console.WriteLine("Yes");
        else Console.WriteLine("No");

    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13152
#include<stdio.h>
int main()
{
    int N,temp,i,j,k,count=0,a,b;
    scanf("%d",&N);
    int p[N];
    for(i=1; i<=N; i++)
    {
        scanf("%d",&p[i]);
    }
    for(i=1; i<=N; i++)
    {
        if(p[i]!=i)
        {
            a=p[i];
            break;
        }
    }
        for(j=i+1; j<=N; j++)
        {
            if(p[j]!=j)
            {
                b=p[j];
                break;
            }
        }

                temp=p[i];
                p[i]=p[j];
                p[j]=temp;

    for(k=1; k<=N; k++)
    {
        if(p[k]==k)
        {
            count++;
        }

    }
    if(count==N)
    {
        printf("YES");
    }
    else
        printf("NO");
    return 0;
}



Measured memory_bytes: 1736
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string s,t,u,v;
    cin >> s >> t >> u;
    v.push_back(s[0]);
    v.push_back(t[0]);
    v.push_back(u[0]);

    cout << v << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   int a[n+10],i,j=1,k;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
   }
   sort(a,a+n);
   for(i=1;i<n;i++)
   {
       if(a[i]==a[i-1])
       {
           j=0;
       }
   }
   if(j==1)printf("YES\n");
   else printf("NO\n");
    return 0;

}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if((x-r)>=0&&(x+r)<=W&&(y-r)>=0&&(y+r)<=H)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n;
  cin>>n;
  ll ans=0;
  for (ll i = 1; i < n; ++i)
  {
    ans+=n/i;
    if (n%i==0) ans--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
N,X=map(int,input().split(" "))
A=input()
A=A.rstrip().split(" ")
listA=[]
cnt=0
for i in range(N):
    listA.append(int(A[i]))
    if i==0:
        if listA[0]>X:
            cnt+=listA[0]-X
            listA[0]=X
    else:
        if listA[i-1]+listA[i]>X:
            cnt+=(listA[i-1]+listA[i]-X)
            listA[i]=X-listA[i-1]
print(cnt)

Measured memory_bytes: 14128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>

using namespace std;

#define INF 		2000000007
#define MOD			1000003

#define MAX 		105

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

typedef unsigned int 			uint;
typedef unsigned long long int	ull;

int table[55][55];
bool t[55][55];

int main(){
	int H,W;
	cin >>H >>W;
	char a;

	REP(i,H)
		REP(j,W){
			cin>>a;
			table[i+1][j+1] = (a=='#' ? 1 : 0);
		}
	
	REPS(i,1,H+1){
		REPS(j,1,W+1){
			if(table[i][j]==0){
				t[i][j] = true;
				continue;
			}
			int suml = table[i][j-1] + table[i][j+1] + table[i-1][j] + table[i+1][j];
			if(suml > 0){
				t[i][j] = true;
			}
		}
	}

	REPS(i,1,H+1)
		REPS(j,1,W+1)
			if(!t[i][j]){
				cout << "No\n";
				return 0;
			}
	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 256