akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	ll n;
	cin>>n;
	vector<P> p(n);
	rep(i,n)cin>>p[i].first>>p[i].second;

	map<P,P> mp;
	ll zero = 0;
	rep(i,n){
		if(p[i].first==0 && p[i].second==0){
			zero += 1;
			continue;
		}
		ll x;
		if(p[i].first==0 || p[i].second==0){
			p[i].first = abs(p[i].first);
			p[i].second = abs(p[i].second);
			x = max(abs(p[i].first), abs(p[i].second));
		}else if(p[i].second>0) x = gcd(p[i].first, p[i].second);
		else if(p[i].second<0) x = gcd(-p[i].first, -p[i].second);

		p[i].first /= x;
		p[i].second /= x;

		if(p[i].first < 0){
			p[i].first *= -1;
			p[i].second *= -1;
		}
		if(p[i].first==0)p[i].second = 1;
		if(p[i].second==0)p[i].first = 1;

		if(p[i] == P(1,0)) mp[P(1,0)].first += 1;
		else if(p[i] == P(0,1)) mp[P(1,0)].second += 1;
		else if(p[i].second < 0) mp[P(-p[i].second,p[i].first)].second += 1;
		else mp[p[i]].first += 1;
	}


	ll ans = 1;
	for(auto x: mp){
		
		// cout<<"-----"<<endl;
		// cout<<x.first.first << " " << x.first.second<<endl;
		// cout<<x.second.first<<" "<<x.second.second<<endl;

		P q = x.second;
		ans *= (power(2,q.first) + power(2, q.second) - 1) % mod;
		ans %= mod;
	}

	ans += zero-1 + mod;
	ans %= mod;

	// cout<<ans-1LL<<endl;
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 21748
#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

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

	int n, d;
	cin >> n >> d;
	int x, y, count = 0;
	while (n--) {
		cin >> x >> y;
		if (sqrt(x * x + y * y) <= d)
			count++;
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
int n;
char s[100005];
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	int ans=0;
	rep(i,1,n) if(s[i]!=s[i-1]) ++ans;
	rt(ans);
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int H, W;
    cin >> H >> W;
    int h, w;
    cin >> h >> w;
    cout << H * W - h* W - w * H + h * w << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl

int dp[55][55][5005];
int n,k1;

int rec(int i,int j,int k)
{
	if(i>n)
		return (j==0&&k==k1+2500);
	if(dp[i][j][k]!=-1)
		return dp[i][j][k];
	int an=rec(i+1,j,k);
	an=(an+rec(i+1,j+1,k-2*i))%MOD;
	an=(an+(j*2ll*rec(i+1,j,k))%MOD)%MOD;
	an=(an+(j*j*1ll*rec(i+1,j-1,k+2*i))%MOD)%MOD;
	return dp[i][j][k]=an;
}

int main()
{
	SPEED;
	cin>>n>>k1;
	memset(dp,-1,sizeof dp);
	cout<<rec(1,0,2500)<<endl;
	return 0;
}

Measured memory_bytes: 59392
#[allow(unused_macros)]
macro_rules! get_char {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect::<Vec<_>>()
        }
    };
}

fn main() {
    let s = get_char!();

    let mut ans = 0u64;
    for bit in 0..(1 << (s.len() - 1)) {
        let mut buf = 0;
        for (i, c) in s.iter().enumerate() {
            buf *= 10;
            buf += c.to_digit(10).unwrap() as u64;

            if bit & (1 << i) != 0 {
                ans += buf;
                buf = 0;
            }
        }
        ans += buf;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<string,bool>mm;
vector<string>v;
int ans[200005];
int main()
{
    string a,b,h;
    cin>>a>>b;
    int aa,bb;
    scanf("%d%d",&aa,&bb);
    cin>>h;
    if(h==a)printf("%d %d\n",aa-1,bb);
    else printf("%d %d\n",aa,bb-1);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;

int main(void) {
	string s;
	int N[10], i, bet = 999,num;
	cin >> s;
	for (i = 0; i < s.length(); i++) {
		N[i] = (int)(s[i] - '0');
	}
	for (i = 0; i < (s.length()-2); i++) {
		num = N[i]*100 + N[i + 1]*10 + N[i + 2];
		if (abs(num - 753) < bet) bet = abs(num - 753);
		else bet = bet;
	}
	cout << bet << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define INF (int) 2e9
#define MOD (int) 1e9 + 7

int main(){
    int n;
    cin >> n;
    if(n%2==0){
        cout << (double)1/2 << endl;
    }else{
        int a = (n+1)/2;
        cout << (double)a/n << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pa pair<int,int>
#define ld long double
#define BOOST ios_base::sync_with_stdio(false)
#define pb push_back
#define st first
#define nd second
using namespace std;
const int MAX=1e5+5;
vector<int>polaczenia[MAX];
bool odwiedzony[MAX];
vector<int>toposort;
int dp[MAX];
void dfs(int n)
{
  for (int i=0;i<polaczenia[n].size();i++)
  {
    int l=polaczenia[n][i];
    if (!odwiedzony[l])
    {
      odwiedzony[l]=true;
      dfs(l);
    }
  }
  toposort.pb(n);
}

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=0;i<m;i++)
    {
      int a,b;
      scanf("%d%d",&a,&b);
      polaczenia[a].pb(b);
    }

    for (int i=1;i<=n;i++)
    {
      if (!odwiedzony[i])
      {
        odwiedzony[i]=true;
        dfs(i);
      }
    }

    for (int i=0;i<toposort.size();i++)
    {
      int k=toposort[i];
     // cout<<k<<" ";
      int maximum=0;
      for (int j=0;j<polaczenia[k].size();j++)
      {
        int l=polaczenia[k][j];
        maximum=max(maximum,dp[l]);
      }
    dp[k]=maximum+1;
    }
    int maxymalny=0;
    for (int i=1;i<=n;i++)
    {
      maxymalny=max(maxymalny,dp[i]);
    }
    printf("%d",maxymalny-1);
    return 0;
}



Measured memory_bytes: 8056
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=0,m,k,i=0,s=1;
    cin>>n>>k;
    int a[100005]={0};
    for(i=0;i<n;i++)
        cin>>a[i];
    n-=k;
    k--;
    //cout<<n<<endl;
    while(n>0)
    {
        n-=k;
        s++;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

template<class T> class segtree {
	int n = 1;
	vector<T> dat;
	T def = INF; //Default value

public:
	segtree(int _n) {
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, def);
	}
	segtree(vector<T> a) {
		int _n = a.size();
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, def);
		rep(i, 0, _n)dat[i + n - 1] = a[i];
		rREP(i, 0, n - 1)dat[i] = fun(dat[2 * i + 1], dat[2 * i + 2]);
	}


	//sum,min,max,etc...
	T fun(T x, T y) { return min(x, y); }

	//assignment,chmin,chmax,etc...
	void update(int i, T a) {
		i += n - 1;
		dat[i] = a;
		while (i > 0) {
			--i /= 2;
			dat[i] = fun(dat[2 * i + 1], dat[2 * i + 2]);
		}
	}


	T value(int a, int b, int k, int l, int r) {
		if (b <= l || r <= a)return def;
		if (a <= l && r <= b)return dat[k];
		T s = value(a, b, 2 * k + 1, l, (l + r) / 2);
		T t = value(a, b, 2 * k + 2, (l + r) / 2, r);
		return fun(s, t);
	}
	T value(int a, int b) { return value(a, b, 0, 0, n); }

	T operator[](int k) { return dat[k + n - 1]; }
};


int main() {
	init();

	int N; cin >> N;
	map<int, int>mp;
	ll sum = 0;
	rep(i, 0, N) {
		int a; cin >> a;
		mp[a]++;
		sum += a;
	}
	int Q; cin >> Q;
	rep(i, 0, Q) {
		int a, b; cin >> a >> b;
		if (!mp.count(a)) {
			cout << sum << "\n";
			continue;
		}
		sum -= a * (ll)mp[a];
		ll cnt = mp[a];
		mp[a] = 0;
		mp[b] += cnt;
		sum += cnt * b;
		cout << sum << "\n";
	}


	return 0;
}

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

class Progaram
{
    static void Main(string[] args)
    {
        var line = Console.ReadLine().Split(' ')
            .Select(x => int.Parse(x)).ToList();
        var a = line[0];
        var b = line[1];
        var m = line[2];

        var reprice = Console.ReadLine().Split(' ')
            .Select(x => int.Parse(x)).ToList();
        var deprice = Console.ReadLine().Split(' ')
            .Select(x => int.Parse(x)).ToList();
        var waril = new List<WariSet>();

        //割引券不使用のパターン
        var arl = reprice.OrderBy(x => x).ToList()[0];
        var brl = deprice.OrderBy(x => x).ToList()[0];
        var wil = new WariSet()
        {
            Repricex = arl,
            Depricey = brl,
            Nesagec = 0
        };
        waril.Add(wil);

        //割引券使用のパターン
        for (var i = 0; m > i; i++)
        {
            var waris = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToList();
            var warise = new WariSet() 
            { 
                Repricex = reprice[waris[0] - 1], 
                Depricey = deprice[waris[1] - 1], 
                Nesagec = waris[2] 
            };
            waril.Add(warise);
        }

        var al = waril.OrderBy(x => x.Allprice).ToList();
        Console.WriteLine(al[0].Allprice);
    }
}

class WariSet
{
    public int Repricex { get; set; }
    public int Depricey { get; set; }
    public int Nesagec { get; set; }
    public int Allprice 
    {
        get { return (this.Repricex + this.Depricey) - Nesagec; }
    }
}


Measured memory_bytes: 39032
public class Main {

	public static void main(String[] args) {
		java.util.Scanner in = new java.util.Scanner(System.in);
		while(in.hasNext()) {
			Double weight = in.nextDouble();
			if(weight <= 48) System.out.println("light fly");
			else if(48 < weight && weight <= 51) System.out.println("fly");
			else if(51 < weight && weight <= 54) System.out.println("bantam");
			else if(54 < weight && weight <= 57) System.out.println("feather");
			else if(57 < weight && weight <= 60) System.out.println("light");
			else if(60 < weight && weight <= 64) System.out.println("light welter");
			else if(64 < weight && weight <= 69) System.out.println("welter");
			else if(69 < weight && weight <= 75) System.out.println("light middle");
			else if(75 < weight && weight <= 81) System.out.println("middle");
			else if(81 < weight && weight <= 91) System.out.println("light heavy");
			else if(91 < weight) System.out.println("heavy");
		}
	}
}

Measured memory_bytes: 19304
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  cout << (s < t ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int h,w,k;
  cin >> h>>w>>k;
  char c[h][w];
  int ans=0;
  rep(i,h){
    rep(j,w){
      cin >> c[i][j];
    }
  }
  for(int bit=0;bit<(1<<h);bit++){
    for(int bit1=0;bit1<(1<<w);bit1++){
      int ct=0;
      rep(i,h){
        rep(j,w){
          if(bit>>i&1){
            continue;
          }
          if(bit1>>j&1){
            continue;
          }
          if(c[i][j]=='#'){
            ct++;
          }
        }
      }
      if(ct==k){
        ans++;
      }
    }
  }  
  cout << ans;
}

Measured memory_bytes: 3572
N,M = map(int, input().split())
H = [0] + list(map(int, input().split()))
P = [0] + [1]*N
for i in range(M):
  A,B = map(int, input().split())
  if H[A]<=H[B]:
    P[A]=0
  if H[A]>=H[B]:
    P[B]=0
print(sum(P))

Measured memory_bytes: 20016
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=1e9,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int n;
long long ans;
vector<int> p;
map<int,int> mp;
bool prime(int x)
{
	if(x==2||x==3)
		return true;
	for(int i=2;i*i<=x;i++)
		if(!x%i)
			return false;
	return true;
}
void getprime(void)
{
	for(int i=2;i<=997;i++)
		if(prime(i))
		{
			p.push_back(i); 
			mp[i]=1;
		}
}
void add(int x)
{
	int i=0;
	while(p[i]<=x)
	{
		if(x%p[i])
		{
			i++;
			continue;
		}
		mp[p[i]]++;
		x/=p[i];	
	}
}
int main(){
	ans=1;
	cin>>n;
	getprime();
	for(int i=1;i<=n;i++)
		add(i);
	for(int i=0;i<p.size();i++)
		ans=(ans*mp[p[i]])%1000000007;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

N, M = [int(_) for _ in input().split()]
A = [int(input()) for i in range(M)]
isBroken = [False] * (N + 1)
for i in A:
    isBroken[i] = True


def solve():

    # It's impossible
    if M >= 1:
        temp = A[0]
        for a in A[1:]:
            if a - 1 == temp:
                return 0
            temp = a

    # We can
    memo = [0] * (N + 2)

    def rec(i):
        if i == 0:
            return 1
        if i < 0:
            return 0
        if isBroken[i]:
            return 0

        if memo[i] == 0:
            count1 = rec(i - 1)
            count2 = rec(i - 2)
            memo[i] = (count1 + count2) % 1000000007
        return memo[i]
    return rec(N)


print(solve())


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

def _index(l, c):
    if c in l:
        return l.index(c)
    else:
        return -1

chars = list(input())

a = _index(chars, "A")
z = _index(list(reversed(chars)), "Z")
# print("{}, {}".format(a, z))

if a == -1 or z == -1:
    print("0")
    exit(0)

if a + z < len(chars) - 1:
    print(len(chars) - a - z)
else:
    print("0")

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


int main()
{
	int a, b, c, m1 = 0, m2 = 0, m3 = 0;
	cin >> a >> b >> c;
	if (a >= b && a >= c) {
		cout << a * 10 + b + c;
	}
	else if (b >= a && b >= c) {
		cout << b * 10 + a + c;
	}
	else if (c >= b && c >= a) {
		cout << c * 10 + b + a;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (998244353ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	ll a,b;
	cin >> a >> b;
	cout << (((b-a)*(b-a+1)/2)-b) << endl;
	return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int b[n];
	for(int i=1; i<=n-1; i++) cin >> b[i];

	int ans=b[1]+b[n-1];
	for(int i=2; i<=n-1; i++) ans+=min(b[i-1], b[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
int n;
string s;
map<string, long long> mp[19];
int main(){
  prep();
  
  cin >> n;
  cin >> s;
  int cnts[26] = {0};
  int cnts2[26] = {0};
  for (int i=0; i<n; i++){
      cnts[s[i]-'a']++;
  }
  for (int i=n; i<2*n; i++){
      cnts2[s[i]-'a']++;
  }
  for (int i=0; i<26; i++){
      if (cnts[i] != cnts2[i]){
          cout << 0;
          return 0;
      }
  }
  int poww = pow(2, n);
  long long res = 0;
  for (int i=0; i<poww; i++){
      bitset<18> bs(i);
      string front = "";
      string endd = "";
      for (int j=0; j<n; j++){
          if (bs[j]){
              front += s[j];
          }else{
              endd += s[j];
          }
      }
      //cout << front << " " << endd << endl;
      reverse(endd.begin(), endd.end());
      for (int i=0; i<endd.size(); i++){
          front += endd[i];
      }
      reverse(front.begin(), front.end());
      mp[bs.count()][front]++;
  }
  for (int i=0; i<poww; i++){
      bitset<18> bs(i);
      string front = "";
      string endd = "";
      for (int j=n; j<2*n; j++){
          if (bs[j-n]){
              front += s[j];
          }else{
              endd += s[j];
          }
      }
      //cout << front << " " << endd << endl;
      reverse(endd.begin(), endd.end());
      for (int i=0; i<front.size(); i++){
          endd += front[i];
      }
      auto val = mp[bs.count()].find(endd);
      if (val != mp[bs.count()].end()){
          res += val->second;
      }
      
  }
  cout << res;
  return 0; 
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N,M;
	cin >> N >> M;

	vector<int> A(M);

	for(int i = 0; i<M; i++){
		cin >> A[i];
		N = N - A[i];
	}

	if(N<0)
		cout << "\n-1";
	else
		cout << "\n" << N;

	return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>


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

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll nmax=50;


int main(){
    ll H,W,a,b,c;
    ll ans=inf;
    cin>>H>>W;
    for(ll h0=0;h0<=H;h0++){
        a=h0*W;
        b=((H-h0)/2)*W;
        c=(H-(h0+((H-h0)/2)))*W;
        ans=min(ans,max(max(a,b),c)-min(min(a,b),c));
    }
    for(ll h0=0;h0<=H;h0++){
        a=h0*W;
        b=(H-h0)*(W/2);
        c=(H-h0)*(W-(W/2));
        ans=min(ans,max(max(a,b),c)-min(min(a,b),c));
    }
    for(ll h0=0;h0<=W;h0++){
        a=h0*H;
        b=((W-h0)/2)*H;
        c=(W-(h0+((W-h0)/2)))*H;
        ans=min(ans,max(max(a,b),c)-min(min(a,b),c));
    }
    for(ll h0=0;h0<=W;h0++){
        a=h0*H;
        b=(W-h0)*(H/2);
        c=(W-h0)*(H-(H/2));
        ans=min(ans,max(max(a,b),c)-min(min(a,b),c));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = [0,0,0]
for i in range(n):
    a, b, c = map(int, input().split())
    l[0],l[1],l[2] = (max(l[1],l[2])+a, max(l[0],l[2])+b, max(l[0],l[1])+c)
print(max(l))

Measured memory_bytes: 9072
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  vector<int> cop(N);
  for(int i=0;i<N;i++){
    cin >> X.at(i);
    cop.at(i)=X.at(i);
  }

  sort(cop.begin(),cop.end());
  int l=cop.at(N/2-1);
  int r=cop.at(N/2);
  for(int i=0;i<N;i++){
    int x=X.at(i);
    if(x<=l)  cout << r << endl;
    else if(x>=r) cout << l << endl;
  }

  return 0;
}


Measured memory_bytes: 3712
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};



// 入れ子のコンテナの表示関数.
void print_list(const vector<vector<llong> >& v_list)
{
    for (vector<vector<llong> >::const_iterator p = v_list.begin(); p != v_list.end(); ++p) {
        for (vector<llong>::const_iterator q = p->begin(); q != p->end(); ++q)
            cout << *q << " ";
        cout << endl;
    }
}

// 和の比較関数.
template<class T>
bool less_summation(const vector<T>& a, const vector<T>& b)
{
    return a[0] < b[0];
}

int main()
{
    vector< vector<llong> > source;
    llong n, m;
    
    llong ans = 0;

    
    scanf("%lld %lld", &n, &m);

    source.resize(n);
    for(llong i=0;i<n;i++){
        source[i].resize(2);
    }


    for(llong k=0;k<n;k++){
        
        for(llong s = 0;s<2;s++){
            llong temp;
            scanf("%lld",&temp);
            source[k][s] = temp;
        
            
        }


        
    }



    
    sort(source.begin(), source.end(), less_summation<llong>);

   llong num = 0;
    for(llong i = 0; i<n;i++){
        llong tn = 0;
        tn = min(m - num, source[i][1]);
        ans += tn  * source[i][0];
        num += tn;

    }
    
    cout<<ans<<endl;
        
  
    
}





Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
void Main(){
    int n;cin>>n;
    vector<double> a(n);
    For(i,0,n) cin>>a[i];
    sort(ALL(a));
    For(i,0,n-1) a[i+1]=(a[i]+a[i+1])/2;
    cout<<fixed<<setprecision(8)<<a[n-1]<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

int main(){
   int a,b;
   cin >> a >> b;
   if(a == b){
     cout << a*2 << endl;
   }else if(b > a){
     cout << b+(b-1) << endl;
   }else{
     cout << a+(a-1) << endl;
  }
   
}

Measured memory_bytes: 256
from functools import reduce
n_,x_=map(int,input().split())
a=[1]
p=[1]
for i in range(n_):
    a.append(2*a[-1]+3)
    p.append(2*p[-1]+1)

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

print(f(n_,x_))

Measured memory_bytes: 3572
#include<stdio.h>
#include<string.h>
int main()
{
    char s[102], t[102];
    scanf("%s%s", s, t);
    int i, j;
    char x;
    int n = strlen(s);
    for (i = 0; i < n; i++)
    {
        x = s[n - 1];
        for (j = n - 1; j > 0; j--)
            s[j] = s[j - 1];
        s[0] = x;
        if (strcmp(s, t) == 0)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>

int main() {
	double x1, x2, y1, y2;
	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
	printf("%.8lf\n", (double)sqrt((x2 - x1) * (x2 -  x1) + (y2 - y1) * (y2 - y1)));
	return 0;
}


Measured memory_bytes: 2736
#include<stdio.h>

int main(void)
{
    int a, b;
    
    scanf("%d %d", &a, &b);
    
    if(a>b){
        printf("a > b");
    }else if(a<b){
        printf("a < b");
    }else{
        printf("a == b");
    }
    
    putchar('\n');
    
    return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#include <sstream> 
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define pi 2*acos(0.0)
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repe(i,a,b) for(ll i=a;i<=b;++i)
#define CPrint(c)  for(auto i:(c)) { cout<<i<<" "; } nl 
#define eb   emplace_back
#define ef   emplace_front
#define pb   push_back
#define pf   push_front
#define popb pop_back
#define popf pop_front
#define mp   make_pair
#define sz(a) int((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
//Allows to traverse any type of macro
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
//debuggers
#define trace2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define trace3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define trace4(w,x,y,z) cout<<#w<<"="<<w<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
typedef long long ll;
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<ll,ll> pll;
const int INF=1e9+5;
int main()
{
	FAST_IO;
ll n,k;
cin >>n >> k;
vector<ll>dp(n,INF);
dp[0] = 0;//base case
vector<ll>h(n);
rep(i,0,n)
{
	cin >> h[i];
}
/* i+1.. i+k abs(h[i]-h[j])
*/
for(int i= 0 ;i<n;i++)
{
	for(int j = i+1;j<=i+k && j<n;j++)
	{
		dp[j] = min(dp[j],dp[i]+abs(h[j]-h[i]));
	}
}
cout << dp[n-1] << endl;
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
bool is_prime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return n!=1;
}
int main(){
	int n,p;
	while(1){
		cin>>n>>p;
		if(n==-1&&p==-1)break;
		vector<int> prime,sum;
		int cnt=0;
		while(cnt<p){
			n++;
			if(is_prime(n)){
				prime.push_back(n);
				cnt++;
			}
		}
		for(int i=0;i<prime.size();i++){
			for(int j=i;j<prime.size();j++){
				sum.push_back(prime[i]+prime[j]);
			}
		}
		sort(sum.begin(),sum.end());
		cout<<sum[p-1]<<endl;
	}
}
			

Measured memory_bytes: 1276
IDENTIFICATION  DIVISION.
PROGRAM-ID.     MAIN.
ENVIRONMENT     DIVISION.
DATA            DIVISION.
WORKING-STORAGE  SECTION.
01 R        PIC XXX.
      
PROCEDURE DIVISION.

ACCEPT R.
IF R(1:1) = R(3:1) THEN
	DISPLAY "Yes"
ELSE
	DISPLAY "No"
END-IF.
STOP RUN.


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 300005
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

int i,j,m,n,p,k,r,c,R[N];

vector<int>v[N];

long long ans,cnt;
int main()
{
		scanf("%d%d%d",&r,&c,&n);
		for (i=1;i<=n;++i)
		{
				int x,y;
				scanf("%d%d",&x,&y);
				v[y].pb(x);
		}
		for (i=1;i<=c;++i) v[i].pb(r+1),sort(v[i].begin(),v[i].end());
		R[1]=1;
		for (i=2;i<=c;++i)
		{
				for (j=min(r+1,R[i-1]+1);j<=r;++j)
				{
						int p=lower_bound(v[i].begin(),v[i].end(),j)-v[i].begin();
						if (p<(int)v[i].size()&&v[i][p]==j) continue;
						break; 
				}
				R[i]=j;
		}
		int ans=(int)1e9;
		for (i=1;i<=c;++i) 
		{
				int p=lower_bound(v[i].begin(),v[i].end(),R[i])-v[i].begin();
				ans=min(ans,v[i][p]);
		}
		printf("%d\n",ans-1);
}

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

int a[505][505];

void solve(long long H, long long W, long long h, long long w){
	memset(a,0,sizeof(a));
	int hp = H/h, hn = H/h, wp = W/w, wn = W/w;
	if(H%h!=0)hp++;
	if(W%w!=0)wp++;
	int pos = hp*wp, neg = hn*wn;
	if(pos==neg){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
		int alpha, beta;
		beta = (-pos)/(pos-neg)-1;
		alpha = -1 - beta;
		for(int i=0;i<H;i+=h)for(int j=0;j<W;j+=w){
			a[i][j] = alpha;
			if(i+h-1<H and j+w-1<W){
				a[i+h-1][j+w-1] = beta;
			}
		}
		REP(i,H){
			REP(j,W){
				printf("%d",a[i][j]);
				if(j!=W-1)printf(" ");
			}
			printf("\n");
		}
	}
}

int main(){	
	long long h;
	long long w;
	long long H;
	long long W;
	scanf("%lld",&H);
	scanf("%lld",&W);
	scanf("%lld",&h);
	scanf("%lld",&w);
	solve(H, W, h, w);
	return 0;
}


Measured memory_bytes: 2304
#include <iostream>

void insertionSort(int A[], int N)
{
    for (int k = 0; k < N; k++)
    {
        std::cout << A[k];

        if (k < N-1) std::cout << " ";
        else         std::cout << std::endl;
    }
    
    for (int i = 1; i < N; i++)
    {
        int v = A[i];
        int j = i - 1;

        while (j >= 0 && A[j] > v)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;

        for (int k = 0; k < N; k++)
        {
            std::cout << A[k];

            if (k < N-1) std::cout << " ";
            else         std::cout << std::endl;
        }
    }
}

int main()
{
    int num;
    std::cin >> num;

    int *element = new int[num];

    for (int i = 0; i < num; i++) std::cin >> element[i];

    insertionSort(element, num);
}


Measured memory_bytes: 3096
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  if (a <= 5) cout << 0 << '\n';
  else if (a <= 12) cout << b / 2 << '\n';
  else cout << b << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N;
    cin >> N;
    vector<ll> f(N, 0);
    rep2(i, 1, N+1){
        rep2(j, 1, min(100, (int)(sqrt(i)+1))){
            rep2(k, j, min(100, (int)(sqrt(i)+1))){
                rep2(l, k, min(100, (int)(sqrt(i)+1))){
                    if(j*j + k*k + l*l + j*k + k*l + l*j == i){
                        if(j == k && k == l){
                            f.at(i-1)++;
                        }
                        else if(j == k && k < l){
                            f.at(i-1) += 3;
                        }
                        else if(j < k && k == l){
                            f.at(i-1) += 3;
                        }
                        else{
                            f.at(i-1) += 6;
                        }
                    }
                }
            }
        }
    }
    rep(i, N){
        cout << f.at(i) << endl;
    }
}

Measured memory_bytes: 3620
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,k;
int arr[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k;
	rep(x,0,n) cin>>arr[x];
	
	rep(x,k,n){
		if (arr[x-k]<arr[x]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}


Measured memory_bytes: 4440
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


void solve() {
	int N, A, B; cin >> N >> A >> B;
	vector<int>H(N);
	REP(i, N)cin >> H[i];
	int ok = 1e9, ng = 0;
	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		vector<int>h = H;
		REP(i, N)h[i] -= B * mid;
		int rem = mid;
		bool can = true;
		REP(i, N) {
			if (h[i] > 0) {
				int need = (h[i] + A-B - 1) / (A - B);
				if (rem < need)can = false;
				else {
					rem -= need;
				}
			}
		}
		if (can)ok = mid;
		else ng = mid;
	}
	print(ok);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 1792
using System;
using System.IO;

public class Program
{
    static void Main(string[] args)
    {
        char[] s = Console.ReadLine().ToCharArray();
        Array.Sort(s);

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

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

void print(int n, int *a)
{
    for (int i = 0; i < n; i++)
        cout << a[i] << ((i == n - 1) ? '\n' : ' ');
}

int main(int argc, char const *argv[])
{
    int n;
    int a[100];

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    print(n, a);

    for (int i = 1; i < n; i++)
    {
        int v = a[i];
        int j;
        for (j = i - 1; j >= 0 && a[j] > v; j--)
            a[j + 1] = a[j];

        a[j + 1] = v;

        print(n, a);
    }
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

// returns gcd(a, b)
// x, y will contain the answer for ax + by = gcd(a, b) after the execution
// if answer for ax + by = c is needed,
// check if c % gcd(a, b) == 0
// get (c / gcd(a, b)) * (x, y)

long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a%b, y, x);
  y -= a/b * x;
  return d;
}

// factorize
vector<pair<ll, ll> > prime_factorize(ll n) {
  vector<pair<ll, ll> > res;
  for (ll p = 2; p * p <= n; p++) {
    if (n %p != 0) continue;
    int num = 0;
    while (n % p == 0) {
      num++;
      n /= p;
    }
    res.push_back(make_pair(p,num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

// enumerate divisors
vector<int> enum_div(int n) {
  vector<int> res;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i * i != n) {
        res.push_back(n/i);
      }
    } 
  }
  sort(res.begin(), res.end());
  return res;
}

signed main() {
  int A, B; cin >> A >> B;
  ll x, y;
  int d = extGCD(A, B, x, y);
  vector<pair<int, int>> F = prime_factorize(d);
  cout << F.size() + 1 << endl;

}


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

int main(){
    int n;
    int a[100];
    cin >> n;
    for (int i = 0; i < n; i++ ) cin >> a[i];
    for (int i = n -1; i >= 0; i--){
		cout << a[i];
		if (i != 0) cout << " ";
	}
	cout << endl;
}


Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
using namespace std;
int N,R,L,T[100001],S[100001],maxt=1,pret=0,P[100001];
pair<int,int>H[100001];
void swap(int x,int y){
    P[-H[y].second]=x;
    P[-H[x].second]=y;
    pair<int,int>i;
    i=H[x];
    H[x]=H[y];
    H[y]=i;
}
void upheap(int i){
    while(i>0&&H[i]>H[i/2]){
        swap(i,i/2);
        i/=2;
    }
}
void downheap(int i){
    int l=i*2+1,r=l+1;
    if(r<N&&H[r]>H[l])l=r;
    
    if(l<N&&H[l]>H[i]){
        swap(i,l);
        downheap(l);
    }
}
int main(void){
  cin>>N>>R>>L;
  for(int i=0;i<N;i++){
      P[i+1]=i;
      H[i].second=-i-1;
  }
  for(int i=0;i<R;i++){
      int d,t,x;
      cin>>d>>t>>x;
      int maxp=-H[0].second;
      T[maxp]+=t-pret;
      pret=t;
      if(T[maxp]==T[maxt])maxt=min(maxp,maxt);
      
      if(T[maxp]>T[maxt])maxt=maxp;
      
      H[P[d]].first+=x;
      if(x>0)upheap(P[d]);
      else downheap(P[d]);
      
      
      
  }
  int maxp=-H[0].second;
      T[maxp]+=L-pret;
      if(T[maxp]==T[maxt])cout<<min(maxp,maxt)<<endl;
      else if(T[maxp]>T[maxt])cout<<maxp<<endl;
      else cout<<maxt<<endl;
  
    
}

Measured memory_bytes: 4640
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

XY = np.array(read().split(), np.int64)[1:]
X, Y = XY[::2], XY[1::2]

A = (X == Y)
A = A[:-1] & A[1:]
A = A[:-1] & A[1:]

print('Yes' if np.any(A) else 'No')

Measured memory_bytes: 27248
#include <iostream>
#include <string>
#include <sstream>  // istringstream
#include <vector>
#include <stack>

using namespace std;

class Line {
public:
	Line()
		: a_(0)
		, b_(0)
		, inspected_(false)
	{};
	Line(int a, int b)
		: a_(a)
		, b_(b)
		, inspected_(false)
	{};

public:
	int a_;
	int b_;
	bool inspected_;
};

bool IsBridge(int index, const std::vector<Line>& vctLine, int N)
{
	std::vector<Line> tmpVctLine(vctLine);
	tmpVctLine.erase(tmpVctLine.begin() + index);
	std::vector<bool> vctNode(N, false);

	std::stack<int> next;

	next.push(tmpVctLine[0].a_);//@@@ 19 ★ tmpVctLine.size() == 0 のとき、落ちる。
	for (int i = 0; (next.size() != 0) /* && (i < N)*/ ; ++i) { // 最大のサーチ個数 //@@@ 19これか?
		int currentNode = next.top();
		next.pop();
		vctNode[currentNode] = true;
		for (auto& elem : tmpVctLine){
			if (elem.inspected_ == false){
				if (elem.a_ == currentNode){
					elem.inspected_ = true;
					next.push(elem.b_);
				}
				else if (elem.b_ == currentNode){
					elem.inspected_ = true;
					next.push(elem.a_);
				}
			}
		}
	}

	bool isExistNotConnected = false;
	for (const auto& elem : vctNode){
		if (elem == false){
			isExistNotConnected = true;
			break;
		}
	}

	return isExistNotConnected;
}

int  main()
{
	int N = 0, M = 0;

	cin >> N >> M;

	std::vector<Line> vctLine(M);

	for (auto& elem : vctLine){
		int a = 0, b = 0;
		cin >> a >> b;
		elem = Line(a - 1, b - 1);
	}

	if (M == 1){
		cout << 1;
		return 0;
	}
	int count = 0;
	for (int i = 0; i < M; ++i){
		if (IsBridge(i, vctLine, N)){
			++count;
		}
	}

	cout << count;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main(){
    int n;
    string s, t;
    cin >> n;
    cin >> s >> t;

    for(int i = 0; i < n; i++){
        cout << s[i] << t[i];
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#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 N,K;

int G[101][101];

void solve(void) {
    int ans = 0;
    int m = N-1;
    int temp = ((N-1)*(N-2))/2;

    for(int i = 2;i <= N;i++) {
        G[i][1] = 1;
        G[1][i] = 1;
    }

    int s = 2;
    int e = 3;
    while(temp > K) {
        G[s][e] = 1;
        G[e][s] = 1;
        m++;
        temp--;
        e++;
        if(e > N) {
            s++;
            e = s+1;
        }
    }

    cout<<m<<endl;
    for(int i = 1;i <= N-1;i++) {
        for(int j = i+1;j <= N;j++) {
            if(G[i][j] == 1) {
                cout<<i<<" "<<j<<endl;
            }
        }
    }

    return;
}

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

    if(K > ((N-1)*(N-2))/2) {
        cout<<-1<<endl;
    } else {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	int a;
	string s;

	cin >> a;
	cin >> s;
	if (a >= 3200) {
		cout << s;
	} else {
		cout << "red";
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<string>
#include<set>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<cmath>
#include<cstdlib>
#include<cassert>

int main() {
	int A, B;
	std::cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
		std::printf("Possible\n");
	else
		std::printf("Impossible\n");
}


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

using namespace std;

int main(){

    int N, K;
    string S;

    cin >> N;
    cin >> S;
    cin >> K;

    char c = S.at(K-1);

    for(int i = 0;i < N; i++){
	if(c != S.at(i)){
	    S.at(i) = '*';
	}
    }
    cout << S << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int>b(n-1);
  rep(i,n-1) cin >> b[i];
  vector<int>a(n);
  a[0]=b[0];
  for(int i=1;i<=n-2;i++) {
    a[i]=min(b[i],b[i-1]);
  }
  a[n-1]=b[n-2];
  int ans=0;
  rep(i,n) ans+=a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
/*
    vec1.size();
    str1.length();
    vec1.pop_back;
*/
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef vector<pll> vplll;
#define rep(i,l,r) for (ll i = l; i < r; ++i)
#define reprev(i,l,r) for (ll i = r; i >= l; --i)
ll mod = 1e9+7;
ll expo_mod(ll x, ll y, ll p) 
{ 
    ll res = 1;
    x = x % p; 
    if (x == 0) 
        return 0; 
    while (y > 0) 
    {
        if (y%2==1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    // ll arr[n+1],brr[n+1],crr[n+1];
    ll arr[n+1][3];
    rep(i,0,n)
    {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    ll dp[n+1][3];
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    rep(i,1,n)
    {
        rep(j,0,3)
        {
            dp[i][j]=max(dp[i-1][(j+1)%3]+arr[i][j], dp[i-1][(j+2)%3]+arr[i][j]);    
        }
    }
    ll ans=max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4992
S=input().split('/')
S_to_int = [int(n) for n in S]
if S_to_int[0]==2019:
  if S_to_int[1]>=5:
    print('TBD')
  if S_to_int[1]==4 and S_to_int[2]<=30:
    print('Heisei')
  if S_to_int[1]<=3:
    print('Heisei')  


Measured memory_bytes: 2940