akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
int dp[20][20];
int main(){
	int a,b;
	int n;
	int x[40],y[40];
	while(true){
	cin>>a>>b;
	if(a==0&&b==0)
		break;
	cin>>n;
	for(int i=0;i<20;i++)
		for(int j=0;j<20;j++)
			dp[i][j]=0;
	for(int i=1;i<n+1;i++){
		cin>>x[i]>>y[i];
		dp[y[i]][x[i]]=-1;
	}
	dp[1][1]=1;
	for(int i=1;i<b+1;i++){
		for(int j=1;j<a+1;j++){
			if(dp[i][j]!=-1){
			if(dp[i-1][j]>0)
				dp[i][j]+=dp[i-1][j];
			if(dp[i][j-1]>0)
				dp[i][j]+=dp[i][j-1];
			}
			else
				dp[i][j]=0;
		}
	}
	cout<<dp[b][a]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main(void){
    int N,a,a_,c=0,ans=0,i;
    cin >> N;
    cin >> a_;
    for(i=1;i<N;i++){
        cin >> a;
        if(a==a_){
            c++;
        }else if(c>0){
            ans+=(c+1)/2;
            c=0;
        }
        a_=a;
    }
    ans+=(c+1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
c = []*n
list = [input().split() for l in range(n)]
ans = float('inf')
op_cnt = n
for i in range(2 ** op_cnt):
  flag = 1
  progress =[0]*m
  cost = 0
  op = [0] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
  for j in range(op_cnt):
      if ((i >> j) & 1):
          op[op_cnt - 1 - j] = 1
          cost += int(list[op_cnt - 1 - j][0])
          for k in range(m):
            progress[k] += int(list[op_cnt-1-j][k+1])
   
  for l in range(m):
    if progress[l] < x:
      flag = 0
      break
  if flag == 1:
    ans = min(ans,cost)
if ans == float('inf'):
  print(-1)
else:
  print(int(ans))
  

  

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7
#define LD long double


int main(){
    LL a,b,c;
    cin >> a >> b >> c;
    LL k;
    cin >> k;

    if(k < a){
        cout << k << endl;
    }else if(k < a + b){
        cout << a << endl;
    }else{
        cout << a - (k - (a + b)) << endl;
    }



    return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    M1, D1 = map(int, input().split())
    M2, D2 = map(int, input().split())

    if D2 == 1:
        print(1)
    else:
        print(0)


def main():
    solve()


if __name__ == '__main__':
    main()


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

int main()
{
	int N,minj,change,count;
	int A[100];
	count = 0;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	for (int i = 0; i < N-1; ++i)
	{
		minj = i;
		for (int j = i; j < N; ++j)
		{
			if (A[j] < A[minj])
			{
				minj = j;
			}
		}
		if (minj != i)
		{			
			change = A[i];
			A[i] = A[minj];
			A[minj] = change;
			count += 1;
		}
	}
	for (int i = 0; i < N; ++i)
	{
		if (i != N-1)
		{
			cout << A[i] << " ";
		}
		else
		{
			cout << A[i] << "\n";
		}
	}
	cout << count << "\n";
	return 0;
}


Measured memory_bytes: 3088
import heapq as hp
# heapq.heappush(heap,item)
# heapq.heppop(heap) 最小値　最初のやつの取り出し
t=int(input())
for i in range(t):
    n=int(input())
# 左からkまでなら、+x lef[k]=[3,4,5]
    lef=[[] for i in range(n+1)]
    rig=[[] for i in range(n+1)]
    a=[]
    hp.heapify(a)
    ans=0
    lefcnt=0

    for i in range(n):
        k,l,r=map(int,input().split())
        if(l>=r):
            ans+=r
            lefcnt+=1
            tmp=l-r
            lef[k].append(tmp)
        else:
            ans+=l
            tmp=r-l
            rig[n-k].append(tmp)
    for i in range(n,lefcnt,-1):
        for j in lef[i]:
            hp.heappush(a,-j)           
    for i in range(lefcnt,0,-1):
        for j in lef[i]:
            hp.heappush(a,-j)
        if(a):
            tmp=hp.heappop(a)*(-1)
            ans+=tmp

    a=[]
    hp.heapify(a)
    for i in range(n,n-lefcnt,-1):
        for j in rig[i]:
            hp.heappush(a,-j)    
    for i in range(n-lefcnt,0,-1):
        for j in rig[i]:
            hp.heappush(a,-j)
        if(a):
            tmp=hp.heappop(a)*(-1)
            ans+=tmp
    print(ans)

Measured memory_bytes: 49664
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

vec fact(10001, 1), invfact(10001, 1);
int mod = 998244353;

int extgcd(int a, int b, int &x, int &y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return d;
}

int mod_inverse(int a, int m){
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 20){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

int comb(int n, int r){
    if(r > n || r < 0 || n < 0) return 0;
    int a = fact[n];
    a *= invfact[r];
    a %= mod;
    a *= invfact[n - r];
    a %= mod;
    return a;
}

signed main(){

    int K, N; cin >> K >> N;

    REP(i, 10000){
        fact[i + 1] = (fact[i] * (i + 1)) % mod;
        invfact[i + 1] = mod_inverse(fact[i + 1], mod);
    }

    vec pow2(10001);
    REP(i, 10001){
        pow2[i] = fastpow(2, i, mod);
    }


    FOR(i, 2, 2 * K + 1){
        int ans = 0;
        if(i % 2 == 1){
            int dmax = min(i / 2, (2 * K + 2 - i) / 2);
            int K2 = K - dmax * 2;
            FOR(d, 0, dmax + 1){
                //if(d > N || d == 0 && K2 == 0) continue;
                int tmp = (comb(dmax, d) * comb(N + K2 - 1, N - d)) % mod;
                tmp = (tmp * pow2[d]) % mod;
                ans = (ans + tmp) % mod;
            }
        }

        if(i % 2 == 0){
            int dmax = min(i / 2, (2 * K + 2 - i) / 2) - 1;
            int K2 = K - dmax * 2 - 1;
            FOR(d, 0, dmax + 1){
                //if(d > N || d == 0 && K2 == 0) continue;
                // (i/2,i/2)なし
                int tmp = (comb(dmax, d) * comb(N + K2 - 1, N - d)) % mod;
                tmp = (tmp * pow2[d]) % mod;
                ans = (ans + tmp) % mod;
                // (i/2,i/2)あり
                tmp = (comb(dmax, d) * comb(N + K2 - 2, N - d - 1)) % mod;
                tmp = (tmp * pow2[d]) % mod;
                ans = (ans + tmp) % mod;
            }   
        }

        cout << ans << endl;
        
    }

    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,a,b,A,B;
  cin >> N;
  vector<int> max(N-1);
  for(int i=1;i<N;i++){
    A=0,B=0;
    a=i;
    b=N-i;
    for(int j=0;j<6;j++){
      A += a%10;
      a /=10;
      B += b%10;
      b /=10;
    }
    max.at(i-1)=A+B;
  }
  sort(max.begin(),max.end());
  cout << max.at(0) << endl;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li w, h;
li p[100100];
li q[100100];
PI pq[200200];

int main() {
    cin >> w >> h;
    rep(i, w) {
        cin >> pq[i].F;
        pq[i].S = 0;
    }
    rep(i, h) {
        cin >> pq[i + w].F;
        pq[i + w].S = 1;
    }
    sort(pq, pq + w + h);

    li cols = w + 1;
    li rows = h + 1;
    li res = 0;
    rep(i, w + h) {
        if (pq[i].S == 0) {
            res += pq[i].F * rows;
            cols--;
        } else {
            res += pq[i].F * cols;
            rows--;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4352
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let k: usize = read();
    let ab: Vec<usize> = read_vec();
    let a = ab[0];
    let b = ab[1];

    if a <= b - b % k {
        println!("OK");
    } else {
        println!("NG");
    }
}


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

int main(){
  ll n;
  cin >> n;
  map<ll,ll> a;
  vector<ll> m;
  for(ll i=0;i<n;++i){
    ll num;
    cin >> num;
    a[num]++;
    if( a[num] == 1 ) m.push_back(num);
  }
  sort(m.begin(),m.end());
  reverse(m.begin(),m.end());
  ll cnt = 0;
  ll ans = 1;
  ll ans2 = 0;
  for(ll i=0;i<a.size();++i){
    ll num = m.at(i);
    if( a[num] >= 4 && ans2 == 0 ){
      ans2 = num*num;
    }
    if( a[num] >= 2 && cnt != 2 ){
      cnt++;
      ans *= num;
    }
  }
  if( cnt != 2 && ans2 == 0 ){
    cout << 0 << endl;
  }else{
    cout << max(ans,ans2) << endl;
  }
  return 0;
}

Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin >>n;
    cin >>s;
    unordered_set<int> r;
    unordered_set<int> g;
    unordered_set<int> b;
    for (int i = 0; i < n; ++i)
    {
        if(s[i]=='R')
            r.insert(i+1);
        else if(s[i]=='G')
            g.insert(i+1);
        else
            b.insert(i+1);
    }
    long long int cnt=0;
    for (int x:r)
    {
        for(int y :g)
        {
            if((x+y)%2==0)
            {
                int z = (x+y)/2;
                //printf("%d %d %d\n",x,y,z);
                if (z==x || z==y)
                {
                    cnt++;
                }
                else if (b.count(z))
                    cnt++;
            }
        }
    }
    for (int x:b)
    {
        for(int y :g)
        {
            if((x+y)%2==0)
            {
                int z = (x+y)/2;
                //printf("%d %d %d\n",x,y,z);
                if (z==x || z==y)
                {
                    cnt++;
                }
                else if (r.count(z))
                    cnt++;
            }
        }
    }
    for (int x:r)
    {
        for(int y :b)
        {
            if((x+y)%2==0)
            {
                int z = (x+y)/2;
                //printf("%d %d %d\n",x,y,z);
                if (z==x || z==y)
                {
                    cnt++;
                }
                else if (g.count(z))
                    cnt++;
            }
        }
    }
    cout << r.size()*g.size()*b.size()-cnt;


    return 0;
}

Measured memory_bytes: 3808
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://atcoder.jp/contests/abc112/tasks/abc112_d>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,M; cin >> N >> M;
    if(N == 1) return M;
    for(ll i = 1; i*N <= M;i++){
        if((M-i*(N-1))%i==0) res = i;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int a[100];
	int minv = 10000000;

	int sum = 0;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if (a[i] % 10 == 0) {
			sum += a[i];
		}
		else {
			int num = 10 - (a[i] % 10);
			sum += (num + a[i]);
			minv = min(minv, a[i] % 10);
		}
	}

	if (minv == 10000000) {
		cout << sum << endl;
	}
	else {
		cout << sum - (10 - minv) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


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

    int n; cin >> n;
    int cnt=0;
    rep(i, n+1) if(i%2==1) ++cnt;

    double ans=(double)cnt/n;
    cout << setprecision(15);
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a[5],b[5] = {0,0,0,0,0},max = 0,x = -1,sum = 0;
	for(int i = 0;i < 5;i++){
		scanf("%d",&a[i]);
		if(a[i] % 10 != 0){
			if((a[i]+10) / 10 * 10 - a[i] > max){
				max = (a[i]+10) / 10 * 10 - a[i];
				x = i;
			}
		}
	}
	b[x] = 1;
	for(int i = 0;i < 5;i++){
		if(a[i] % 10 == 0) sum += a[i];
		else{
			if(b[i] != 1) sum += (a[i]+10) / 10 * 10;
			else sum += a[i];
		}
	}
	printf("%d",sum);
	return 0;
}

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

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  sort(a, a + n);
  int ans = 0;
  REP(i, n - 1) {
    ans -= a[i] - a[i + 1];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}
ll cnt[2] = {};

vector<vector<bool>> used;

void dfs(int c, int r, const vector<vector<int>>& to) {
  used[c][r] = true;
  cnt[r]++;
  // cout << c << ":" << r << endl;
  for(const auto next: to[c]) {
    if(used[next][r^1]) continue;
    dfs(next, r^1, to);
  }
}

signed main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  used = vector<vector<bool>>(n, vector<bool>(2, false));
  vector<vector<int>> to(n);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0, 0, to);
  if(used[0][0] && used[0][1]) {
    cout << n * (n - 1) / 2 - m << endl;
  }
  else {
    cout << cnt[0] * cnt[1] - m << endl;
  }
  return 0;
}


Measured memory_bytes: 14592
XN = list(map(int, input().split()))
 
if XN[1] == 0:
  print(XN[0])
else:
  p = list(map(int, input().split()))
  for d in range(XN[1] + 1):
    if not XN[0] - d in p:
      print(XN[0] - d)
      break
    if not XN[0] + d in p:
      print(XN[0] + d)
      break

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<int> sim(N);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--, B--;
        if (A > B) swap(A, B);

        sim[A]++;
        sim[B]--;
    }

    // rep(i, N) cerr << sim[i] << " ";
    // cerr << endl;

    REP(i, 1, N) {
        sim[i] += sim[i-1];
    }

     rep(i, N-1) {
        if (sim[i]&1) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

int main(){
  ll N; cin >> N;
  if(N==1){
    cout << 0 << endl;
    return 0;
  }
  ll n = N;
  ll ans = 0;
  for(ll i=2;i*i<=N;i++){
    ll x = i;
    while(n%x==0){
      ans++;
      n /= x;
      x *= i; 
    }
    while(n%i==0){
      n /= i;
    }
  }
  if(n != 1) ans++;
  cout << ans << endl;
}


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

using namespace std;

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

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

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

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

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, k;
	int v[60];
	cin>>n>>k;
	assert(n<=50 && k<=100);
	REP(i, n){
		cin>>v[i];
	}
	int ans=0;
	REP(i, k+1){
		REP(j, k-i+1){
			if(i+j>n){
				continue;
			}
			int x2[i+j];
			REP(j2, i){
				x2[j2]=v[j2];
			}
			int cnt=i-1;
			FORR(j2, n-j, n){
				x2[++cnt]=v[j2];
			}
			sort(x2, x2+i+j);
			int sum=0;
			REP(a, i+j){
				sum+=x2[a];
			}
			REP(a, min(k-i-j, i+j)){
				if(x2[a]>=0){
					break;
				}
				sum-=x2[a];
			}
			CHMAX(ans, sum);
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
string board[11];
int CUM[11][1010];

int main(){
    
    // 1. 入力情報.
    int H, W, K;
    scanf("%d %d %d", &H, &W, &K);
    rep(i, H){
        char c[1010];
        scanf("%s", c);
        string s(c);
        board[i] = s;
    }
    
    // 2. ホワイトチョコレートについて, 二次元累積和を保存.
    repx(i, 1, H + 1){
        repx(j, 1, W + 1){
            CUM[i][j] = (board[i - 1][j - 1] - '0') + CUM[i - 1][j] + CUM[i][j - 1] - CUM[i - 1][j - 1];
        }
    }
    
    // 3. 分割に必要な操作の回数をチェック.
    int ans = 2020;
    rep(i, 1 << (H - 1)){
        // チェック対象の行数を保存.
        vector<int> row, col;
        row.pb(0);
        row.pb(H);
        rep(j, H - 1) if((i >> j) & 1) row.pb(H - 1 - j);
        sort(all(row));
        // printf("--- row start i=%d ---\n", i);
        // for(auto &p : row) printf("%d ", p);
        // puts("\n--- row end ---");
        
        // 列方向にチェック.
        int s = 0, e = 0;
        priority_queue<int> pq;
        while(e < W){
            bool ok = true;
            int white = 0;
            while(ok && e < W){
                e++;
                rep(j, row.size() - 1){
                    // 各ブロックのホワイトチョコレートの個数を確認.
                    white = CUM[row[j + 1]][e] - CUM[row[j]][e] - CUM[row[j + 1]][s] + CUM[row[j]][s];
                    // printf("i=%d s=%d e=%d white=%d\n", i, s, e, white);
                    if(white > K){
                        ok = false;
                        break;
                    }
                }
            }
            
            // 各ブロックのホワイトチョコレートの個数を詰め直し.
            if(white > K){
                rep(j, row.size() - 1){
                    pq.push(CUM[row[j + 1]][e - 1] - CUM[row[j]][e - 1] - CUM[row[j + 1]][s] + CUM[row[j]][s]);
                }
                col.pb(e - 1), s = e - 1;
            }else{
                rep(j, row.size() - 1){
                    pq.push(CUM[row[j + 1]][e] - CUM[row[j]][e] - CUM[row[j + 1]][s] + CUM[row[j]][s]);
                }
                col.pb(e), s = e;
            }
            // printf("s=%d e=%d white=%d\n", s, e, white);
        }
        // printf("--- col i=%d ---\n", i);
        // for(auto &p : col) printf("%d ", p);
        // puts("\n--- col end ---");
        
        // 必要な操作数を更新.
        int rCount = row.size(), cCount = col.size();
        if(row.front() == 0) rCount--;
        if(row.back()  == H) rCount--;
        if(col.back()  == W) cCount--;
        if(pq.top() <= K) ans = min(ans, rCount + cCount);
    }
    
    // 4. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(int argc, const char * argv[]) {
    ll n;
    scanf("%lld", &n);
    if (n%2==0) {
        printf("%lld\n", n);
    }
    else{
        printf("%lld\n", n*2);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m,s;
  vector<int> kyori;
  cin >> n >> m;
  kyori.resize(n,0);

  for(int i=1;i<n;i++){
    cin >> s;
    kyori[i] = s+kyori[i-1];
  }
  long long now=0,oldnow=0,cnt = 0;
  while(m--){
    cin >> s;
    oldnow = now;
    now += s;
    cnt += max(kyori[now] - kyori[oldnow],kyori[oldnow]-kyori[now]);
  }
  cout << cnt%100000 << endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  
  rep(i,n) cin >> h[i];
  
  rep(i,m){
  int a,b;
    cin >> a >> b;
    a--,b--;
    if (h[a] <= h[b]) ok[a] = false;
    if (h[b] <= h[a]) ok[b] = false;
  }
  
  int ans=0;
  rep(i,n) {
    if (ok[i]) ans++;
  }
  cout << ans << endl;
  return 0;
  
}


Measured memory_bytes: 3716
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin >>a>>b;
    int c=a*b;
    if(c%2==0){
        cout <<"Even"<<endl;
    }else{
        cout <<"Odd"<<endl;
    }
        
    
}


Measured memory_bytes: 256
import sys

class SCC:
  '''
  SCC class with non-recursive DFS.
  '''
  def __init__(self,N):
    self.N = N
    self.G1 = [[] for _ in range(N)]
    self.G2 = [[] for _ in range(N)]
  
  def add_edge(self,a,b):
    self.G1[a].append(b)
    self.G2[b].append(a)
    
  def scc(self):
    self.seen = [0]*self.N
    self.postorder=[-1]*self.N
    self.order = 0
    for i in range(self.N):
      if self.seen[i]:continue
      self._dfs(i)

    self.seen = [0]*self.N
    scclist = []
    for i in self._argsort(self.postorder,reverse=True):
      if self.seen[i]:continue
      cc = self._dfs2(i)
      scclist.append(cc)
    
    return scclist
    
  def _argsort(self,arr,reverse=False):
    shift = self.N.bit_length()+2
    tmp = sorted([arr[i]<<shift | i for i in range(len(arr))],reverse=reverse)
    mask = (1<<shift) - 1
    return [tmp[i] & mask for i in range(len(arr))]
  
  def _dfs(self,v0):
    todo = [~v0, v0]
    while todo:
      v = todo.pop()
      if v >= 0:
        self.seen[v] = 1
        for next_v in self.G1[v]:
          if self.seen[next_v]: continue
          todo.append(~next_v)
          todo.append(next_v)
      else:
        if self.postorder[~v] == -1:
          self.postorder[~v] = self.order
          self.order += 1
    return
  
  def _dfs2(self,v):
    todo = [v]
    self.seen[v] = 1
    cc = [v]
    while todo:
      v = todo.pop()
      for next_v in self.G2[v]:
        if self.seen[next_v]: continue
        self.seen[next_v] = 1
        todo.append(next_v)
        cc.append(next_v)
    return cc

class TwoSAT:
  def __init__(self,N):
    self.N = N
    self.scc = SCC(2*N)
    self.flag=-1
  
  def add_clause(self,i,f,j,g):
    self.scc.add_edge(f*self.N+i,(1^g)*self.N+j)
    self.scc.add_edge(g*self.N+j,(1^f)*self.N+i)
    
  def satisfiable(self):
    if self.flag==-1:
      self.scclist = self.scc.scc()
      self.order = {j:i for i,scc in enumerate(self.scclist) for j in scc}
      self.flag = True
      self.ans = [0]*self.N
      for i in range(self.N):
        if self.order[i] > self.order[self.N+i]:
          self.ans[i] = 1
          continue
        elif self.order[i] == self.order[i+self.N]:
          self.flag = False
          return self.flag
      return self.flag
    else: return self.flag
  
  def answer(self):
    return self.ans
  
def main():
  N,D=map(int,input().split())
  xy = [tuple(map(int,input().split())) for _ in range(N)]
  ts=TwoSAT(N)
  for i in range(N-1):
    for j in range(i+1,N):
      for k1,k2 in [(0,0),(0,1),(1,0),(1,1)]:
        pos1,pos2 = xy[i][k1],xy[j][k2]
        if abs(pos2-pos1)<D:
          ts.add_clause(i,k1^1,j,k2^1)

  if ts.satisfiable():
    print('Yes')
    print(*[xy[i][ts.ans[i]] for i in range(N)],sep="\n")
  else:
    print('No')
    
if __name__=="__main__":
  main()

Measured memory_bytes: 10116
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    int X, A;
    cin >> X >> A;

    if (X < A) {
        cout << 0 << endl;
    } else {
        cout << 10 << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=300069;
template<typename TP>
inline void read(TP &kk)
{
	TP ret=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}
	kk=ret*f;
}
int n,W,X,H;
struct shino
{
	int x,y;
	shino(int x=0,int y=0):x(x),y(y){}
	bool operator < (const shino &a)const{return x==a.x?y<a.y:x<a.x;}
}pt[N],a[N],b[N];
int ans;
int w[N<<2],tag[N<<2];
void fuckup(int px,int pl,int pr)
{
	if(pl==pr) return;
	w[px]=max(w[px<<1],w[px<<1|1])+tag[px];
}
void add(int px,int pl,int pr,int l,int r,int v)
{
	if(l<=pl&&r>=pr){w[px]+=v,tag[px]+=v;return;}
	int pm=(pl+pr)>>1;
	if(l<=pm) add(px<<1,pl,pm,l,r,v);
	if(r>pm) add(px<<1|1,pm+1,pr,l,r,v);
	fuckup(px,pl,pr);
}
void fuck()
{
	memset(w,0,sizeof(w)),memset(tag,0,sizeof(tag));
	sort(pt+1,pt+1+n);
	int l1=0,l2=0,l=0,r=0;
	for(int i=1;i<n;i++)
	{
		if(pt[i].y<=H/2)
		{
			int ne=i-1;
			while(l1&&a[l1].y<pt[i].y)
			{
				l=a[l1].x,r=ne,ne=l-1;
				add(1,1,n,l,r,a[l1].y-pt[i].y);l1--;
			}
			if(ne!=i-1) a[++l1]=shino(ne+1,pt[i].y);
		}else
		{
			int ne=i-1;
			while(l2&&b[l2].y>pt[i].y)
			{
				l=b[l2].x,r=ne,ne=l-1;
				add(1,1,n,l,r,pt[i].y-b[l2].y);l2--;
			}
			if(ne!=i-1) b[++l2]=shino(ne+1,pt[i].y);
		}
		a[++l1]=shino(i,0),b[++l2]=shino(i,H);
		add(1,1,n,i,i,H-pt[i].x);
		ans=max(ans,2*(w[1]+pt[i+1].x));
	}
}

signed main()
{
	read(W),read(H),read(n);
	for(int i=1;i<=n;i++) read(pt[i].x),read(pt[i].y);
	pt[++n]=shino(0,0),pt[++n]=shino(W,H);fuck();
	swap(W,H);for(int i=1;i<=n;i++) swap(pt[i].x,pt[i].y);
	fuck();
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 16512
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

    static long mod = (long) (1e9 + 7);

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int[] wa = new int[n];
        int[] sa = new int[n];
        long[] va = new long[n];
        List<Item> items = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            wa[i] = in.nextInt();
            sa[i] = in.nextInt();
            va[i] = in.nextInt();
            items.add(new Item(wa[i], sa[i], va[i]));
        }
        Collections.sort(items);
        int wsum = 20500;
        long[] dp = new long[wsum + 1];

        for (int i = 0; i < n; i++) {
            Item itm = items.get(i);
            for (int j = Math.min(itm.s, wsum - itm.w); j >= 0; j--) {
                dp[j + itm.w] = Math.max(dp[j + itm.w], itm.val + dp[j]);
            }
        }
        long ans = 0;
        for (int i = 0; i < wsum; i++) {
            ans = Math.max(ans, dp[i]);
        }
        out.println(ans);
        out.close();
    }

    static class Item implements Comparable<Item> {
        int w;
        int s;
        long val;

        public Item(int w, int s, long val) {
            this.w = w;
            this.s = s;
            this.val = val;
        }

        @Override
        public int compareTo(Item o) {
            if ((w + s) == (o.s + o.w)) {
                return (w - o.w);
            } else {
                return Integer.compare((w + s), (o.s + o.w));
            }
        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 23252
extension String: CollectionType {
    func toInts() -> [Int] {
        return self.split(" ").map {Int($0)!}
    }
    
    func toStrings() -> [String] {
        return self.split(" ")
    }
}

let values = readLine()!.toStrings()
let capital = String(values[1].characters.first!)
print("A\(capital)C")


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

int main() {
    int N; cin >> N;
    int cnt = 1;
    int now = 10;
    int n = N;
    int ans = 0;
    while(n / now != 0){
        if(cnt % 2 == 1){
            int x = pow(10,cnt) - pow(10,cnt-1);
            ans += x;
        }
        cnt++;
        now *= 10;
    }
    if(cnt % 2 == 1){
        int x = N - pow(10,cnt-1) + 1;
        ans += x;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3860
#include<stdio.h>
int main(){
  int i;
  char a[5];
  for(i=1;i<=5;i++){
    scanf("%c",&a[i]);
  }
  if(a[1]==a[2]&&a[2]==a[3]){
    printf("Yes");
  }
  else if(a[2]==a[3]&&a[3]==a[4]){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    a,b,c,d = map(int, input().split())

    l = a + b
    r = c + d
    if l > r:
        print('Left')
    elif l < r:
        print('Right')
    else:
        print('Balanced')


if __name__ == '__main__':
    main()


Measured memory_bytes: 62884
// Atcoder Beginner Contest 178
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(ll i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main() 
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cerr.tie(0);
	ll x;
	cin>>x;
	cout<<ll(x^1)<<endl;
	return 0;
}

Measured memory_bytes: 3644
N = int(input())
S = list(str(input()))
from collections import Counter

c = Counter(S)
ans = c['B']*c['G']*c['R']
for i in range(N-1):
    for j in range(i, N):
        if S[i]==S[j]:
            continue
        elif i+(j-i)*2>N-1:
            break
        s = S[i+(j-i)*2]
        if s!=S[i] and s!=S[j]:
            ans -= 1
print(ans)

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	string s; 
	cin>>s;
	for(auto& c:s)
	{
		int x=(c-'A'+n)%26;
		c='A'+x;
	}
	cout<<s;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    int a,b;
    char op;
    cin>>a>>op>>b;
    while(op!='?')
    {
        int c;
        if(op=='+')
            c=a+b;
        else if(op=='-')
            c=a-b;
        else if(op=='*')
            c=a*b;
        else
            c=a/b;
        cout<<c<<endl;

    cin>>a>>op>>b;}
    return 0;
}




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

long long int M, A, R, C, H, I, N, G;
char s[15];

main(){
  cin >> N;
  for(I = 0; I < N; ++I){
    scanf("%s", s);
    switch(*s){
      case 65:
        ++A;
        break;
      case 67:
        ++C;
        break;
      case 72:
        ++H;
        break;
      case 77:
        ++M;
        break;
      case 82:
        ++R;
        break;
    }
  }
  G = M * (A * (R + C + H) + R * (C + H) + C * H) + A * (R * (C + H) + C * H) + R * C * H;
  cout << G << endl;
  return 0;
}

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

ll gcd(ll a, ll b) {
    if (a % b == 0) return b;
    return gcd(b, a % b);
}



ll a, b;

int main() {
    
    while (cin >> a >> b) {
        ll g = gcd(a,b);
        cout << g << " " << a * b / g << "\n";
    }

}


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

signed main(){
  lint N, suma = 0, sumb = 0; cin >> N;
  vector<lint> a(N), b(N);
  for(lint i = 0; i < N; i++) cin >> a[i], suma += a[i];
  for(lint i = 0; i < N; i++) cin >> b[i], sumb += b[i];
  lint counts1 = 0, counts2 = 0;
  for(lint i = 0; i < N; i++){
    if(a[i] < b[i]) counts1 += ceil(double(b[i] - a[i]) / double(2));
    if(a[i] > b[i]) counts2 += (a[i] - b[i]);
  }
  if(max(counts1, counts2) <= (sumb - suma)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main { 
	static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) { 

    	int n = scan.nextInt();
    	String str = "";
    	
    	for(int i=0; i<n; i++) {
    		str += scan.nextInt();	//WARNING
    		if (i != n-1) str += " ";
    	}
    	
    	String str2 = "";
    	List<String> list = new ArrayList<String>();
    	for(int i=1; i<n+1; i++) {
    		str2 += i;
    	}
    	list =permutation(list, str2, "");
    	
    	int a = -1;
    	for(int i=0; i<list.size(); i++) {
    		if(list.get(i).equals(str)) {
    			a = i;
    			break;
    		}
    	}
    	if(a != 0) {
    		System.out.println(list.get(a - 1));
    	}
    	System.out.println(list.get(a));
    	if(a != list.size()-1) System.out.println(list.get(a + 1));
    }
	
    public static List<String> permutation(List<String> list, String q, String ans){
    	if(q.length() <= 1) {
    		list.add(ans + q);
    	}else {
    		for (int i = 0; i < q.length(); i++) {
    			permutation(list, q.substring(0, i) + q.substring(i + 1), ans + q.charAt(i) + " ");
    		}
    	}
    	return list;
    }    	
}


Measured memory_bytes: 175732
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
ll n, m, x;
ll trakm[N], l[N];
int main(){
	scanf("%lld%lld%lld",&n,&x,&m);
	trakm[1]=x;
	ll ans=x;
	ll tmp = x;
	for(ll i=2; i<=n; ++i){
		tmp = tmp*tmp%m;
		ans+=tmp;
		if(l[tmp]){
			trakm[i]=trakm[i-1]+tmp;
			ll period = i - l[tmp];
			ll sum = trakm[i]-trakm[l[tmp]];
			ll tmp1 = (n-i)/period;
			ll rem = (n-i)%period;
			ll sm1 = trakm[l[tmp]+rem]-trakm[l[tmp]];
			ans += sm1+sum*tmp1;
			break;
		}
		l[tmp] = i;
		trakm[i]=trakm[i-1]+tmp;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4824
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = __int64_t;

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

void solve(){
  int N, Q;
  string s;
  int x[100001];
  cin >> N >> Q >> s;

  int c = 0;
  x[0] = 0;
  for(int i = 1; i < N; i++){
    if(s[i-1] == 'A' && s[i] == 'C'){
      c++;
    }
    x[i] = c;
  }

  int l, r;
  for(int i = 0; i < Q; i++){
    cin >> l >> r;
    cout << (x[r-1] - x[l-1]) << endl;
  }
}

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

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <unistd.h>
#include <sstream>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back
const int N=1e6+1;
int prime[N];

void seive()
{
    memset(prime,-1,sizeof(prime));
    for(int i=2;i<=N;i++)
    {
        if(prime[i]==-1)
        {
            prime[i]=i;
            for(int j=i*i;j<=N;j+=i)
                prime[j]=i;
        }
    }
}

void solve()
{
    seive();
    int n;cin>>n;
    int ans=0;
    for(int c=1;c<=n-1;c++)
    {
        map<int,int> mp;
        int t=n-c;
        if(t==1)
        {
            ans++;continue;
        }
        while(prime[t]!=-1)
        {
            int x=prime[t];
            mp[x]++;t/=x;
        }
        int prod=1;
        for(auto it:mp)
            prod*=(it.second+1);
        ans+=prod;
    }
    cout<<ans;
}

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

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 11468
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int d1[26], d2[26];

int main() {
	int n,maxn=0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 26; j++) d1[j] = d2[j] = 0;
		for (int f = 0; f <= i; f++) {
			d1[(int)(s[f] - 97)] = 1;
		}
		for (int f = i+1; f < n; f++) {
			d2[(int)(s[f] - 97)] = 1;
		}
		int c = 0;
		for (int j = 0; j < 26; j++) {
			if (d1[j] && d2[j]) c++;
		}
		maxn = max(maxn, c);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 256
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=2e5+1000;
int a[maxn];
int n,m;
bool check(int l){
    for(int i=l*2+1,j=2*n;i<j;i++,j--){
        if(a[i]+a[j]<m)return 0;
    }
    return 1;
}
int main(){
    ios::sync_with_stdio(0);
   cin>>n>>m;rep(i,1,2*n)cin>>a[i];
    sort(a+1,a+1+2*n);
    int l=0,r=n;
    while(l<r){
        int mid=(l+r)>>1;
        if(check(mid))r=mid;
        else l=mid+1;
    }
    int ans=0;
    for(int i=1,j=l*2;i<=l;i++,j--)ans=max(ans,(a[i]+a[j])%m);
    for(int i=l*2+1,j=2*n;i<j;i++,j--)ans=max(ans,(a[i]+a[j])%m);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4416
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	int odd = 0;
	for( int i = 0; i < N; ++i ) {
		int a;
		cin >> a;
		odd += a & 1;
	}
	cout << (odd%2 == 0 ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int a=read(),b=read(),n=read(),ans=0;
signed main(){
	fz(i,max(min(n,b-1)-100000000,0ll),min(n,b-1)){
		ans=max(ans,(int)(1.0*a*i)/b);
//		cout<<i<<" "<<(int)(1.0*a*i/b)-a*(int)(1.0*i/b)<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3600