akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#include <cstdint>

using std::int64_t;

template <int64_t MOD>
class Modint {
  using Self = Modint<MOD>;

  int64_t m_value;

 public:
  Modint() : m_value(0) {}
  Modint(int64_t value) : m_value((value % MOD + MOD) % MOD) {}
  Self pow(int64_t e) const {
    if (e == 0) {
      return (Self)1;
    } else if (e % 2 == 0) {
      return ((*this) * (*this)).pow(e / 2);
    } else {
      return (*this).pow(e - 1) * (*this);
    }
  }
  Self inv() const { return pow(MOD - 2); }
  Self& operator=(const Self& rh) {
    m_value = rh.m_value;
    return *this;
  }
  Self operator-() const { return Self(-m_value); }
  Self operator+(const Self& other) const {
    return Self(m_value + other.m_value);
  }
  Self operator-(const Self& other) const {
    return Self(m_value - other.m_value);
  }
  Self operator*(const Self& other) const {
    return Self(m_value * other.m_value);
  }
  Self operator/(const Self& other) const { return (*this) * other.inv(); }
  Self& operator+=(const Self& rh) { return (*this) = (*this) + rh; }
  Self& operator-=(const Self& rh) { return (*this) = (*this) - rh; }
  Self& operator*=(const Self& rh) { return (*this) = (*this) * rh; }
  Self& operator/=(const Self& rh) { return (*this) = (*this) / rh; }
  int64_t value() const { return m_value; }
};

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

  using Mint = Modint<1'000'000'007>;
  Mint result = 0;
  for (int64_t i = K; i <= N + 1; i++) {
    int64_t x = i * (i - 1) / 2;
    int64_t y = N * i - i * (i - 1) / 2;

    result += y - x + 1;
  }
  cout << result.value() << endl;
  return 0;
}

Measured memory_bytes: 3188
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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 int dy[4] = {0, -1, 0, 1};
const int dx[4] = {-1, 0, 1, 0};

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

    vector<vector<int>> dist;
    vector<string> wall;

    int w, h;
    while(1) {
        cin >> w >> h;cin.ignore();
        if(w == 0 && h == 0) break;

        dist.assign(h, vector<int>(w, 0));
        wall.resize(h * 2 - 1);

        rep(i, h * 2 - 1) { getline(cin, wall[i]); }

        queue<pair<int, int>> que;
        dist[0][0] = 1;
        que.push({0, 0});

        while(!que.empty()) {
            pair<int, int> next = que.front();
            que.pop();
            int y = next.first, x = next.second;
            if(y == h - 1 && x == w - 1) break;
            rep(i, 4) {
                int ny = y + dy[i], nx = x + dx[i];
                if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
                if(dist[ny][nx] != 0) continue;
                if(wall[y + ny][x + nx] != '0') continue;
                dist[ny][nx] = dist[y][x] + 1;
                que.push({ny, nx});
            }
        }
        COUT(dist[h - 1][w - 1]);
    }
}



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

#define iii pair<pair<int,int>,int> 
#define FIR first.first
#define SEC first.second
#define THI second

int N,M;
vector<int> e[100010];
int Q;
iii q[100010];

int g[100010];

void input()
{
	scanf("%d%d",&N,&M);
	for(int i=1,tmp1,tmp2;i<=M;i++)
	{
		scanf("%d%d",&tmp1,&tmp2);
		e[tmp1].push_back(tmp2);
		e[tmp2].push_back(tmp1);
	}
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++)
	{
		scanf("%d%d%d",&q[i].FIR,&q[i].SEC,&q[i].THI);
	}
}

bool done[100010][15];
void f(int v,int d,int c)
{
	if(done[v][d]) return;
	done[v][d]=true;
	
	if(g[v]==0) g[v]=c;
	if(d==0)
	{
		return;
	}
	for(int i=0;i<e[v].size();i++)
	{
		f(e[v][i],d-1,c);
	}
}

void work()
{
	for(int i=Q;i>=1;i--)
	{
		f(q[i].FIR,q[i].SEC,q[i].THI);
	}
}

void output()
{
	for(int i=1;i<=N;i++)
	{
		printf("%d\n",g[i]);
	}
}

int main()
{
	input();
	work();
	output();
	return 0;
}


Measured memory_bytes: 9464
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

// Union find
struct uf {
  vi d;
  uf(){}
  uf(int mx):d(mx,-1){}
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y]; d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
  int operator[](int x) { return root(x);}
  int operator()(int x) { return size(x);}
};
//



int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  uf t(n);
  rep(i,m) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    t.unite(a,b);
  }
  int ans = 1;
  rep(i,n) maxs(ans,t(i));
  cout<<ans<<endl;
  return 0;
}






















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

using namespace std;

int v[200005];

int main(){
    int n,i,ok=1;
    
    cin>>n;
    
    for(i=1;i<=n;i++)
        cin>>v[i];
        
    sort(v+1,v+n+1);
    
    for(i=1;i<n;i++)
        if(v[i]==v[i+1])
            ok=0;
            
    if(ok)
        cout<<"YES";
    else
        cout<<"NO";
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN=200050;
int a[MAXN];
int at[MAXN];

int main() {
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;i++) scanf("%d",a+i);
	for(int i=1;i<=N;i++) at[a[i]]=i;
	ll ans=0;
	set<int> S;
	S.insert(0);
	S.insert(N+1);
	for(int i=1;i<=N;i++) {
		auto p1=S.lower_bound(at[i]);
		auto p2=p1;
		p1--;
		ans+=1ll*i*(at[i]-*p1)*(*p2-at[i]);
		S.insert(at[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

#define mx 550005
#define mx2 1003

int a[mx];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int i=0,j=1;
    while(i<n){
        a[j]+=1;
        i+=1;
        j+=1;
        if(j>k){
            j=1;
        }
    }
    int big=0,small=mx;
    for(int v=1;v<=k;v++){
        if(a[v]>big){
            big=a[v];
        }
        if(a[v]<small){
            small=a[v];
        }
    }
    printf("%d",big-small);
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;

int main(){
    int n,m;
    cin>>n>>m;
    ll fct[100010];
    fct[1]=1;
    for(int i=2;i<=max(n,m);i++){
        fct[i]=(fct[i-1]*i)%MOD;
    }
    if(n==m){
        cout<<(2*fct[n]*fct[m])%MOD<<endl;
    }else if(n+1==m||n==m+1){
        cout<<(fct[n]*fct[m])%MOD<<endl;
    }else{
        cout<<0<<endl;
    }
}


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

#define int long long

auto main() -> signed {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; ++i) cin >> v[i];
    int c = 0;
    bool ans = false;
    int cur = 1;
    while(true) {
        if(c>n) break;
        cur = v[cur-1];
        c++;
        if(cur==2) {
            ans = true;
            break;
        }
    }
    if(ans==true) cout << c << endl;
    else cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#define Max 2000001
#define AMax 10001
int main() {
  /* code */
  short *A,*B;
  int C[AMax];

  int n,i,j;
  for (i=0;i<=AMax;i++) C[i]=0;
  scanf("%d\n",&n);

  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for (i=0;i<n;i++) {
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1;i<AMax;i++){
    C[i]=C[i]+C[i-1];
  }
  for(i=1;i<=n;i++){
    B[C[A[i]]]=A[i];
    C[A[i]]--;
  }
  for(i=1;i<=n;i++){
    if(i==n) printf("%d\n",B[i]);
    else printf("%d ",B[i]);
  }
  return 0;
}

Measured memory_bytes: 8456
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,x,c,d,res;
    cin>>a>>b>>x;
    if(a>b){
        swap(a,b);
    }
    c=a/x;
    d=b/x;
    if(a%x==0){
        res=(d-c)+1;
    }
    else{
        res=d-c;
    }
    cout<<res<<endl;
    return 0;
}


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



int main(){

	string s;
	cin>>s;
	
	if(s.back()=='s')s += "es";
	else s += "s";
	
	cout<<s<<endl;

	return 0;
}



Measured memory_bytes: 3624
let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let M = input[1]

let A = readLine()!.split(separator: " ").map { Int($0)! }.sorted()
var B: [[Int]] = []

for i in 0..<M {
  B.append(readLine()!.split(separator: " ").map { Int($0)! })
}

B = B.sorted { $0[1] > $1[1] }

var j = 0
var sum = 0

for i in 0..<A.count {
  if j < B.count && B[j][0] == 0 {
    j += 1
  }
  if j >= B.count || B[j][1] <= A[i] {
    sum += A[i]
  } else {
    B[j][0] -= 1
    sum += B[j][1]
  }
}
print(sum)

Measured memory_bytes: 17372
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
if k == 1:
  print(0)
else:
  mod = 10 ** 9 + 7
  use = 1
  def inv(x):
    y = 1
    while x != 1:
      y *= mod // x + 1
      y %= mod
      x -= mod % x
    return y
  b = [0 for _ in range(n)]
  c = [1]
  for i in range(n-k):
    tmp = c[-1]
    tmp *= inv(i+1)
    tmp %= mod
    tmp *= i+k
    c.append(tmp)
  c.reverse()
  #print(c)
  for i in range(n-k+1):
    b[i] -= c[i]
    b[-i-1] += c[i]
  #print(b)
  ans = 0
  for i in range(n):
    ans += b[i] * a[i]
    ans %= mod
  print(ans)

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

int main(){
  int n;
  cin >> n;
  int mat[n + 1][n + 1];

  for(auto i = 0; i < n + 1; i++){
    for(auto j = 0; j < n + 1; j++){
      mat[i][j] = 0;
    }
  }

  for(auto i = 1; i <= n; i++){
    int vertex, dimout;
    cin >> vertex >> dimout;

    vector<int> adjvertices(dimout);
    for(auto j = 0; j < dimout; j++){
      cin >> adjvertices[j];
      mat[vertex][adjvertices[j]] = 1;
    }
  }

  for(auto i = 1; i <= n; i++){
    for(auto j = 1; j <= n; j++){
      cout << mat[i][j];
      if(j != n) cout << " ";
    }
    cout << endl;
  }
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;

ll a, b, c, x, y;

int main() {
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y);
	ll p1 = 2 * c * max(x,y);
	ll p2 = (a * x) + (b * y);
	ll p3 = (2 * c * min(x, y));
	if (x > y) {
		p3 += (x-y) * a;
	} else if(x<y) p3 += (y - x) * b;
	printf("%lld",min(p1,min(p2,p3)));
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a,b;
	
	cin >> a >> b;
	
	if(a > b)
		cout << "a > b" << endl;
	if(a < b)
		cout << "a < b" << endl;
	if(a == b)
		cout << "a == b" << endl;
}

Measured memory_bytes: 1160
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		String s = sc.next();
		Deque<String> deq = new ArrayDeque<>();
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if (c == '0') {
				deq.addLast("0");
			} else if (c == '1') {
				deq.addLast("1");
			} else {
				deq.pollLast();
			}
		}
		StringBuilder sb = new StringBuilder();
		while (deq.size() != 0) {
			sb.append(deq.pollFirst());
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 21716
import math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd1 = math.gcd(i, j)
        for l in range(1, k + 1):
            gcd2 = math.gcd(gcd1, l)
            ans += gcd2
print(ans)

Measured memory_bytes: 9124
#include <iostream>

int main(int argc, char const *argv[]) {
  int A, B, C, K;
  int count = 0;

  std::cin >> A >> B >> C;
  std::cin >> K;

  while (B <= A) {
    B *= 2;
    count++;
  }
  while (C <= B) {
    C *= 2;
    count++;
  }

  if (count <= K) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N = 2e5+5;
const int mod = 998244353;
int n,m,k;
ll Pow(int a,int b)
{
	if(a==0)return 1;
	ll res=Pow(a/2,b);
	res=res*res%mod;
	if(a%2==1)res=res*b%mod;
	return res;
}
ll fac[N];
void init()
{
	fac[0]=1;
	for(int i=1;i<=2e5;i++)fac[i]=fac[i-1]*i%mod;
}
ll ny(int x)
{
	return Pow(mod-2,x);
}
ll C(int a,int b)
{
	return ny(fac[b])*fac[a]%mod*ny(fac[a-b])%mod;
}
int main()
{
	init();
	ll ans=0;
	cin>>n>>m>>k;
	for(int i=0;i<=k;i++)
	{
		ans+=m*Pow(n-i-1,m-1)%mod*C(n-1,i)%mod;
		ans%=mod;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5200
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    D = []
    for i in range(N):
        D.append(int(input()))
    D.sort()
    
    pre_d = D[0]
    ans = 1
    for i in range(1, N):
        if pre_d < D[i]:
            pre_d = D[i]
            ans += 1
    print(ans)
    

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
n, m = gets.split.map(&:to_i)
hi = gets.split.map(&:to_i)

su = Array.new(n, true)

$<.read.split.map(&:to_i).each_slice(2) do |a, b|
    #puts "#{a} #{b} #{hi[a-1]} #{hi[b-1]}"
    su[a-1] = false if hi[a-1] <= hi[b-1]
    su[b-1] = false if hi[b-1] <= hi[a-1]
    #p su
end

puts su.count(true)

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

int gcd(int x, int y)
{
	int t = 1;
	while(t != 0)
	{
		t = x % y;
		x = y;
		y = t;
	}
	return x;
}

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	vector<int> L(N+1), R(N+1);
	L[0] = 0, R[N] = 0;
	L[1] = A[0], R[N - 1] = A[N - 1];
	for(int i = 2; i < N + 1; i++)
	{
		L[i] = gcd(A[i - 1], L[i - 1]);	
	}
	for(int i = N - 2; i >= 0; i--)
	{
		R[i] = gcd(A[i], R[i + 1]);
	}
	int maxGCD = max(L[N - 1], R[1]);
	for(int i = 1; i < N - 1; i++)
	{
		maxGCD = max(maxGCD, gcd(L[i], R[i + 1]));
	}
	cout << maxGCD << endl;
	return 0;
}

Measured memory_bytes: 1408
n = int(input())
sum=0
point=[]
for i in range(n):
    now= int(input())
    point.append(now)
    sum+=now
#point = list(map(int, input()))
if sum%10!=0:
    print(sum)
else:
    point.sort()
    judge = False
    for i in point:
        if i%10!=0:
            point.remove(i)
            sum-=i
            judge = True
            break
    if judge:
        print(sum)
    else:
        print(0)


Measured memory_bytes: 9096
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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

#define forn(i, a, n) for (int i = (a); i < (int)n; i++)
#define trav(x, arr) for (auto &x : arr)
#define sz(x) (int)x.size()
#define Matrix(m, h, w) = std::vector<vector<int>> m(h, vector<int> (w)); 
using ll = long long;

#define vi vector<int>
#define vl vector<long>
#define vll vector<ll>

// benq
const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;


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


    int a, b; cin >> a >> b;

    if (b % 2 != 0) {
    	cout << "No";
    	return 0;
    }


    int x2 = b, x4 = b;

    while (a >= 0) {
    	// cout << "a " << a << endl;
    	if ((x2 % 2 == 0  && x2 / 2 == a * 2) ||  (x2 % 4 == 0 && x2 / 4 == a * 4)) {
    		cout << "Yes";
    		return 0;
    	} else if ((x4 % 2 == 0  && x4 / 2 == a * 2) ||  (x4 % 4 == 0 && x4 / 4 == a * 4)) {
    		cout << "Yes";
    		return 0;
    	}

    	x2 -= 2;
    	x4 -= 4;

    	a--;


    }
    cout << "No";

    return 0;
}

Measured memory_bytes: 3660
import Control.Applicative

main = do
    [n,x] <- map read . words <$> getLine
    xlist <- map read . words <$> getLine
    print $ solve x xlist

solve :: Integer -> [Integer] -> Integer
solve x list = foldl (\acc elem -> gcd acc (elem - x)) (abs (head list - x)) (tail list)

Measured memory_bytes: 36220
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
using namespace std;
vector<int> b[20];
int p[20];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i = 1;i <= m; i++){
	   int k; cin>>k; 
	   for(int j = 1;j <= k; j++){
	     int t; cin>>t; 
	     b[i].push_back(t);
       }
	}
	for(int i = 1;i <= m; i++) cin>>p[i];
	int ans = 0;
	for(int i = 0;i <= pow(2,n) - 1; i++){
	  int t = i;
	  int a[20],len = 0;
	  for(int i = 0;i <= 10; i++) a[i] = 0;
	  while(t){
	     len++;
		 a[len] = t&1;
		 t = t>>1;	
	  } 
	  int cnt = 0;
	  for(int j = 1;j <= m; j++){
	  	int cnt1 = 0;
	    for(int k = 0;k < b[j].size(); k++) 	
	  	  if(a[b[j][k]]) cnt1++;
	  	if(cnt1%2 == p[j]) cnt++;
	  }
	  if(cnt == m) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'

using namespace std ;

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main()
{

    lli r,g,b,n;
    cin>>r>>g>>b>>n;

    lli ans=0;

    loopl(i,0,(n/r) + 1)
    {
        loopl(j,0,(n/g) + 1)
        {
            if(n - j*g - r*i >=0 && (n - j*g - r*i)%b == 0)
                ans++;

        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
def f():
 from heapq import heappop, heappush
 N=int(input())
 r=[0]*N
 for _ in[0]*(N*~-N//2):
  a,b,c,d=map(int,input().split())
  r[a-1]+=3*(c>d)+(c==d)
  r[b-1]+=3*(d>c)+(d==c)
 b=[[]for _ in[0]*N*3]
 for i in range(N):b[r[i]]+=[i]
 pq = []
 for i, s in enumerate(r):heappush(pq,[-s,i])
 rank=1
 display_rank=1
 prev_score=float('inf')
 while pq:
  s,i=heappop(pq)
  if s!=prev_score:rank=display_rank
  r[i]=rank
  display_rank+=1
  prev_score=s
 print(*r,sep='\n')
f()




########################################################################################################################
##################################################v
################################################################################
##########v####################v##############################v##########v


Measured memory_bytes: 5720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main
{
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		ArrayList<Integer> lstInt = new ArrayList<Integer>();
		String line = "";
		String[] strArray;
		int result = 0;
		int cnt = 0;

		while (cnt < 200 && (line = br.readLine()) != null)
		{
			strArray = line.split(" ", 0);
			result = Integer.parseInt(strArray[0]) + Integer.parseInt(strArray[1]);
			lstInt.add(Integer.toString(result).length());
			++cnt;
		}

		for (int digit : lstInt)
		{
			System.out.println(digit);
		}

	}
}

Measured memory_bytes: 24336
using System;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());

            Console.WriteLine(a/2*(a-a/2));
               


        }

    }
}


Measured memory_bytes: 27464
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999LL
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

queue<PI> order;
int cost[1002][1002], H, W, ans = 0;
char A[1002][1002];

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
			cost[i][j] = 3000;
			if (A[i][j] == '#') {
				cost[i][j] = 0;
				order.push(make_pair(i, j));
			}
		}
	}

	while (!order.empty()) {
		int x = order.front().first;
		int y = order.front().second;
		int c = cost[x][y];
		order.pop();
		if (y - 1 >= 0 && cost[x][y - 1] > c + 1) {
			cost[x][y - 1] = c + 1;
			order.push(make_pair(x, y - 1));
		}
		if (y + 1 <= W - 1 && cost[x][y + 1] > c + 1) {
			cost[x][y + 1] = c + 1;
			order.push(make_pair(x, y + 1));
		}
		if (x - 1 >= 0 && cost[x - 1][y] > c + 1) {
			cost[x - 1][y] = c + 1;
			order.push(make_pair(x - 1, y));
		}
		if (x + 1 <= H - 1 && cost[x + 1][y] > c + 1) {
			cost[x + 1][y] = c + 1;
			order.push(make_pair(x + 1, y));
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)
			ans = max(ans,cost[i][j]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13328
import java.util.Map.Entry;
import java.lang.reflect.Method;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.ArrayList;

//import org.w3c.dom.css.Counter;


public class Main {
	public static void main(String[] args)throws Exception{
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
        String T = sc.next();
        int ans =999999;
		for(int i=0;i<S.length()-T.length()+1;i++){
			int tmp=0;
			for(int i2=0;i2<T.length();i2++){
				if(T.charAt(i2)!=S.charAt(i2+i)){
                    tmp++;
                }
			}
			if(ans>tmp){ans=tmp;}
		}
        System.out.println(ans);
    }
}

Measured memory_bytes: 35616
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vector<int>>;

int main(){
    int n;
    int d[110];
    cin >> n;
    for(int i=0; i<n; ++i) cin>>d[i];

    int num[110] = {0};
    for(int i=0; i<n; ++i){
        num[d[i]]++;
    }   

    int res = 0;
    for(int i=1; i<=100; ++i){
        if(num[i]) {
            ++res;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {
	ll g = gcd(a,b);
	ll res = a/g*b;
	if (res/b != a/g) return 1ll<<60;
	return res;
}

int n, m, a[22], x[22];
double res;

signed main() {
	cin >> n >> m;
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> x[i];
	reps(b,1,1<<n) {
		double p = 1;
		int lc = 1;
		rep(i,n) if (b>>i&1) {
			p *= 1.*x[i]/100;
			lc = lcm(lc,a[i]);
		}
		p *= m/lc;
		if (__builtin_parity(b)) res += p;
		else res -= p;
	}
	printf("%.14lf\n",res);
}


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

int main() {
  string s,t;
  cin >> s;
  cin >> t;
  if (t.length() -1 == s.length()) {
    for (int i = 0; i < s.length(); i++) {
      if (s[i] != t[i]) { 
        cout << "No" <<endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;

  string ans = "";
  rep(i, 0, s.size()) {
    if (s[i] == 'B') {
      if (ans != "") {
        ans = ans.substr(0, ans.size() - 1);
      }
    } else
      ans += s[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a = 0,b = 0,c = 0;

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

  if (a < b){
    if(b < c){
      puts("Yes");
    }else{
      puts("No");
    }
  } else {
    puts("No");
  }

return 0;
}

Measured memory_bytes: 580
#coding:utf-8
from __future__ import division,print_function
try:
    input = raw_input
    range = xrange
except NameError:
    pass
# 上記のコードはPython2とPython3の違いを一部吸収するためのもの

# def solve(n):
# n : 段数(整数)
# 出力: 一郎君がすべての上り方を実行するのに必要な年数をprintする。
a=[0]*100
def solve(n):
    # ここに問題を解くプログラムをかく。s(4)==s(1)*4+s(2)*2+s(3)*1
    if n==1:
        a[1]=1
        return 1
    elif n==2:
        a[2]=2
        return 2
    elif n==3:
        a[3]=4
        return 4
    elif a[n]!=0:
        return a[n]
    else:
        a[n]=solve(n-3)+solve(n-2)+solve(n-1)
        return a[n]
    

def main():
    while True:
        inp=int(input())
        if inp==0:
            break
        print(solve(inp)//3650+1)

main()


Measured memory_bytes: 6796
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long a,b,c;
   cin>>a>>b>>c;
   if(c-b<=0) std::cout << "delicious" << '\n';
   else  if(c-b<=a) std::cout << "safe" << '\n';
   else std::cout << "dangerous" << '\n';
  return 0;
}


Measured memory_bytes: 3608
import java.util.*;
public class Main { 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			ArrayList<Data> list = new ArrayList<Data>();
			int n = stdIn.nextInt();
			int l = stdIn.nextInt();
			if(n == 0 && l == 0) break;
			for(int i = 0; i < n; i++) {
				String a = stdIn.next();
				int b = stdIn.nextInt();
				if(a.equals("R")) {
					list.add(new Data(true,b,i+1));
				}
				else {
					list.add(new Data(false,b,i+1));
				}
			}
			int t = 0;
			MyComp comp = new MyComp();
			int lastremid = 0;
			while(true) {
				if(list.size() == 0) break;
				Collections.sort(list,comp);
				int lastp = -1;
				boolean isLR = false;
				for(int i = 0; i < list.size(); i++) {
					Data tmp = list.get(i);
					if(tmp.p == l) {
						if(!isLR) {
							lastremid = tmp.id;
						}
						list.remove(i);
						i--;
						continue;
					}
					if(tmp.p == 0) {
							lastremid = tmp.id;
							list.remove(i);
							i--;
							isLR = true;
							continue;
					}
					if(tmp.p == lastp) {
						if(tmp.isR) {
							tmp.isR = false;
						}
						else {
							tmp.isR = true;
						}
						list.set(i, tmp);
						tmp = list.get(i-1);
						if(tmp.isR) {
							tmp.isR = false;
						}
						else {
							tmp.isR = true;
						}
						list.set(i-1, tmp);
					}
					lastp = tmp.p;
				}
				for(int i = 0; i < list.size(); i++) {
					Data tmp = list.get(i);
					if(tmp.isR) {
						tmp.p++;
					}
					else {
						tmp.p--;
					}
					list.set(i, tmp);
				}
				t++;
			}
			System.out.println(t-1 +" " + lastremid);
		}
	}
}
class Data {
	boolean isR;
	int p;
	int id;
	Data(boolean a, int b,int c) {
		isR = a;
		p = b;
		id = c;
	}
}

class MyComp implements Comparator<Data> {

	@Override
	public int compare(Data o1, Data o2) {
		if(o1.p < o2.p) {
			return -1;
		}
		if(o1.p > o2.p) {
			return 1;
		}
		return 0;
	}
	
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  int res;
  for (int i=0;i<=n;i++) {
    int x;
    x = i/10000%10 + i/1000%10 + i/100%10 + i/10%10 + i%10;
    if(a<=x && x<=b) {
      res += i;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
from collections import deque
A=[deque(list(input())) for _ in range(3)]

num=0
while 1:
    if len(A[num])==0:
        if num==0:print("A")
        elif num==1:print("B")
        else:print("C")
        exit()
    else:
        word=A[num].popleft()
        if word=="a":num=0
        elif word=="b":num=1
        else:num=2

Measured memory_bytes: 65112
import java.util.Scanner;

public class Main {
	
	static int dp(String x, String y) {
		int[][] dp=new int[1010][1010];
		if(x.charAt(0)==y.charAt(0)) {
			dp[0][0]=1;
		}
		else if(x.charAt(0)!=y.charAt(0)) {
			dp[0][0]=0;
		}
		for(int i=1; i<x.length(); i++) {
			if(x.charAt(i)==y.charAt(0)) {
				dp[i][0]=1;
			}
			else {
				dp[i][0]=dp[i-1][0];
			}
		}
		for(int i=1; i<y.length(); i++) {
			if(y.charAt(i)==x.charAt(0)) {
				dp[0][i]=1;
			}
			else {
				dp[0][i]=dp[0][i-1];
			}
		}
		
		for(int i=1; i<x.length(); i++) {
			for(int j=1; j<y.length(); j++) {
				if(x.charAt(i)==y.charAt(j)) {
					dp[i][j]=dp[i-1][j-1]+1;
				}
				else {
					dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]);
				}
			}
		}
		return dp[x.length()-1][y.length()-1];
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int q=sc.nextInt();
			String x, y;
			for(int k=0; k<q; k++) {
				x=sc.next();
				y=sc.next();
				System.out.println(dp(x, y));
			}
			

		}
	}
}


Measured memory_bytes: 163004
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	 int sum=0;
	if (n<10)
	   sum+=n;
	else if (n>=10&&n<=99)
	    sum+=9;
    else if (n<1000&&n>=100)
        sum=sum+9+(n-100)+1;
    else if (n>=1000&&n<10000)
         sum=sum+9+900;
    else if (n>=10000&&n<100000)
         sum=sum+9+900+(n-10000)+1;
    else if (n==100000)
         sum=90909;
    cout<<sum<<endl;
//    for (int i=1;i<=n;i++)
//     if (i/10==0||i/1000==0||i/100000==0) 
//     sum++;
//     cout<<sum;
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


void trace(int A[],int N) {
	int i;
	for(i=0;i<N;i++) {

		if(i>0) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
}


void insertionSort(int A[], int N) {
	int i,j,v;
	for(i=1;i<N;i++) {
		v=A[i];
		j=i-1;
		while(j>=0 && A[j] > v) {
			A[j+1] = A[j];
			j--;
		}
		A[j+1]=v;
		trace(A,N);
	}
}

int main(void)
{
	int N, i, j;
	int A[100];
	scanf("%d",&N);
	for(i=0;i<N;i++) scanf("%d",&A[i]);
	
	trace(A,N);
	insertionSort(A,N);
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,X,count=0;

  cin>>A>>B>>C>>X;

  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        int total=500*i+100*j+50*k;
        if(X==total)
          count++;
      }
    }
  }

  cout << count<< endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	ll a,b,c;
	cin >> a >> b >> c;
	if (a <=c) {
		c -=a;
		a = 0;
	} else {
		a -= c;
		cout << a << " " << b << endl;
		return 0;
	}

	if (b <=c) {
		b = 0;
		cout << a << " " << b << endl;
		return 0;
	} else {
		b -=c;
		cout << a << " " << b << endl;
		return 0;
	}
}



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

#define nl '\n';

using namespace std;

int a, b, c, d;

int main(){

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

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

    cout << "No";





}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

// char** arr = new char*[r];
// for(long long i = 0; i < r; i++) arr[i] = new char[c];

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
 
using namespace std;
 
vector<string> list(5000*5);
 
int main() {
    string str;
    int K, n = 0, m = 0, m_addr;
    cin >> str;
    cin >> K;
    for (int i = 0; i < str.length(); i++) {
        for (int j = 1; j <= 5 && i + j - 1 < str.length(); j++) {
            list[n++] = str.substr(i, j);
        }
    }
    sort(list.begin(), list.begin()+n);
    list.erase(std::unique(list.begin(), list.begin()+n), list.begin()+n);
    cout << list[K-1] << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;

int get(int n, int m){
	if(n % 3 == 0) return 0;
	int res = m;
	for(int i=1;i<n;i++) {
		ll t[3] = {(ll)i * m, (ll)(n-i) * (m/2), (ll)(n-i) * ((m+1)/2)};
		sort(t, t+3);
		if(t[2] - t[0] < res) res = t[2] - t[0];
	}
	return res;
}

void solve(){
	int n, m; cin >> n >> m;
	printf("%d\n", min(get(n, m), get(m, n)));
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
};


Measured memory_bytes: 256
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    x,y = input().split()
    if x==y:
        print('=')
    elif x>y:
        print('>')
    else:
        print('<')
    return

if __name__=='__main__':
    main()


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

using namespace std;

int main(){
   int s; cin>>s;
  int a[4];
  bool ans=true;
  a[0]=s/1000; int tmp=s%1000;
  a[1]=tmp/100; tmp=tmp%100;
  a[2]=tmp/10; tmp=tmp%10;
  a[3]=tmp/1;
  tmp=a[0];
for(int i=1;i<4;i++){
	if(a[i]==tmp) ans=false;
  else tmp=a[i];
}
  
    if(ans) printf("Good");
  else printf("Bad");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int test[12345678], ok[12345678];
signed main() {
	int n, a, cnt = 0, sum = 0, ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a; test[h] = a; cnt += a; sum += h + 1;
		if (h == 0) { test[n] = a; }
	}
	if (cnt % sum != 0) { cout << "NO" << endl; return 0; }
	cnt /= sum;
	for (int h = 0; h < n; h++) {
		if (test[h + 1] - test[h] != cnt) {
			int ok = test[h] + cnt;
			while (true) {
				ok -= n; ans++;
				if (ok == test[h + 1]) { break; }
				if (ok < test[h + 1]) { cout << "NO" << endl; return 0; }
			}
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 2304
N = int(input())
itv = []
for i in range(N):
  itv.append(list(map(int, input().split())))
itv.sort(key=lambda x: x[1])
ans = 0
t = 0
for i in range(N):
  if (t <= itv[i][1]-itv[i][0]):
    ans += 1
    t += itv[i][0]
if ans == N:
  print ("Yes")
else:
  print ("No")

Measured memory_bytes: 53720
#include<iostream>
#include<algorithm>
#include<string>
#include<numeric>
#include<vector>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i=0;i<n;i++) cin >> h[i];
  int count = h[0];
  for (int i=0;i<n-1;i++){
    if (h[i+1] > h[i]) count += h[i+1] - h[i];
  }

  cout << count << endl;

  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()
typedef long long ll;

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 101001;//ここを問題の制約を見ながらいじる．配列の確保に使う．
//int A[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．

// Main program
void solve(){
  ll K,X;
  cin >> K ;
  cin >> X ;

  
  if(500*K>=X){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  
  return;

}

int main() {
    solve();
    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
 
using namespace std;
 
#define INF (1LL<<60)
 
typedef long long ll;

ll calc(ll b, ll n) {
  ll res = 0;
  if (b == 1) return n;
  while (n) {
    res += n % b;
    n /= b;
  }
  return res;
}
 
int main() {
  ll n, s;
  cin >> n >> s;

  ll ans = INF;
  if (n > s) {
    for (int i = sqrt(n); i >= 2; i--) {
      if (calc(i, n) == s)
	ans = min(ans, (ll)i);
    }
    for (int i = sqrt(n); i >= 1; i--) {
      ll b = (n - s) / i + 1;
      if (calc(b, n) == s)
	ans = min(ans, b);
    }
  }
  else {
    if (n == s) ans = n + 1;
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


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

YES = "YES"  # type: str
NO = "NO"  # type: str
K = 15

def solve(S: str):
    count =  S.count("o")
    if count >= 8:
        print("YES")
    else:
        rest = K - len(S)
        if count + rest >= 8:
            print("YES")
        else:
            print("NO")
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}


int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n*n+1);
    for(int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        a[x] = i;
    }
    queue<int> opt;
    for(int i = 1; i <= n*n; i++) {
        if(!a[i]) opt.push(i);
        else {
            int lftCnt = a[i]-1;
            if(opt.size() < lftCnt) {
                cout << "No" << endl;
                return 0;
            }
            while(lftCnt--) {
                int idx = opt.front();
                opt.pop();
                a[idx] = a[i];
            }
        }
    }
    while(opt.size() > 0) opt.pop();
    vector<bool> done(n+1);
    for(int i = n*n; i >= 1; i--) {
        if(!a[i]) {
            opt.push(i);
        }
        else {
            if(done[a[i]]) continue;
            done[a[i]] = true;
            int rightCnt = n-a[i];
            if(opt.size() < rightCnt) {
                cout << "No" << endl;
                return 0;
            }
            while(rightCnt--) {
                int idx = opt.front();
                opt.pop();
                a[idx] = a[i];
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i <= n*n; i++) cout << a[i] << " ";
}





Measured memory_bytes: 5432
H, W = map(int, input().split())
string = list()
for i in range(H):
    string.append(input())

for i in range(W+2):
    print("#", end="")

print("")

for i in range(H):
    print("#", end="")
    print(string[i], end="")
    print("#")

for i in range(W+2):
    print("#", end="")


Measured memory_bytes: 3064