akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()

map<int, char> p{
    {0, '+'},
    {1, '-'}
};

vector<char> ans(3);


int calc(int op, int a, int b){
    if (op == 1) return a - b;
    else return a + b;
}

bool solve(int op1, int op2, int op3, int a, int b, int c, int d){
    if ((calc(op3, calc(op2, calc(op1, a, b), c), d)) == 7) {
        ans = {p[op1], p[op2], p[op3]};
        return true;
    }
    return false;
}



int main(){
    string S;
    cin >> S;
    int A = S[0] - '0';
    int B = S[1] -'0';
    int C = S[2] - '0';
    int D = S[3] - '0';


    vector<int> Operators = {0, 1};

    for (int op1 : Operators){
        for (int op2 : Operators){
            for (int op3 : Operators){
                if (solve(op1, op2, op3, A, B, C, D)) break;
            }
        }
    }
    cout << A << ans[0] << B << ans[1] << C << ans[2] << D << "=7" << endl;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int>ten(n);
  double su=0;
  for(int i=0;i<n;i++){
    cin >> ten.at(i);
    su+=ten.at(i);
  }
  sort(ten.begin(),ten.end(),greater());
  bool ans=true;
  for(int i=0;i<m;i++){
    if(ten.at(i)<su/4/m)
      ans=false;
  }
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
#define all(a) a.begin(),a.end()
int ans;
unordered_map<int,int>m;
signed main(){
	int n;
	cin>>n;
	int a[n],b[n];
	r(i,n)cin>>a[i],b[i]=a[i];
	r(i,n-1)b[i+1]+=b[i];
	r(i,n)m[b[i]]++;
	int sum=0;
	r(i,n){
		ans+=m[sum];
		m[b[i]]--;
		sum+=a[i];
		//ans+=m[-a[i]];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] a  = new int[N];
		
		for (int i=0; i<N; i++){
			a[i] = sc.nextInt();
		}
		
		int ret = 0;
		for(int i=0; i<N; i++){
			
			int temp;
			
			// 自身の数字が順番と同じ場合
			if (i+1 == a[i]){
				ret++;
				// 先頭の場合
				if (i+1 == 1){
					a[i] = a[i+1];
					a[i+1] = 1;
				}
//				// 前と入れ替え可能か
//				else if (a[i-1] != i-1){
//					temp = a[i-1];
//					a[i-1] = a[i];
//					a[i] = temp;
//				}
				// 最後が同じ場合
				else if (i == N-1){
					temp = a[i-1];
					a[i-1] = a[i];
					a[i] = temp;
				}
				// 後ろと入れ替える
				else {
					temp = a[i+1];
					a[i+1] = a[i];
					a[i] = temp;
				}
				
			}
			
		}
		
		System.out.println(ret);
		
	}

}


Measured memory_bytes: 51164
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int main(){
	
	string s;
	while(cin>>s,s!="0"){
		set<string> seto;
		queue<string> q; 
		int count=0;
		bool f=false;
		q.push(s);
		seto.insert(s);
		while(!q.empty()){
			int k=q.size();
			while(k>0){
			string n=q.front();
					 f=true;
			for(int i=0;i<s.size();i++){
				if(n[0]!=n[i]){
					f=false;
					break;
				}
				
			}
				if(f)
					break;
			for(int i=0;i<s.size()-1;i++){
				string n=q.front();
				if(n[i]=='r'&&n[i+1]=='b'||n[i]=='b'&&n[i+1]=='r'){
						n[i]='g';
						n[i+1]='g';
				}
				else if(n[i]=='b'&&n[i+1]=='g'||n[i]=='g'&&n[i+1]=='b'){
						n[i]='r';
						n[i+1]='r';
				}
				else if(n[i]=='r'&&n[i+1]=='g'||n[i]=='g'&&n[i+1]=='r'){
						n[i]='b';
						n[i+1]='b';
				}
				set<string>::iterator a=seto.find(n);
				if(a==seto.end()){
					q.push(n);
					seto.insert(n);
					
				}
				}
				q.pop();
				k--;
			}
			if(f){
				
				break;
			}
			else{
				count++;
			}
		}
		if(f)
			cout<<count<<endl;
		else
			cout<<"NA"<<endl;
		
			
	}
	
	
}

	

Measured memory_bytes: 2652
#include <iostream>

using namespace std;

int main(){
	while(1){
		int x,y,z;
		
		int ans;
		cin>>x>>y>>z;
		if(x==0 && y==0 && z==0)break;
		
		int maxi=-1;
		int nukia,nukib,komia,komib;
		for(int i=1;i<=z/2;i++){
			for(int j=z-1;j>=1;j--){
				if(j*(100+x)/100==i){
					nukia=j;
					break;
				}
			}
			for(int j=z-1;j>=1;j--){
				if(j*(100+x)/100==z-i){
					nukib=j;
				}
			}
			int a=nukia*(100+x)/100;
			int b=nukib*(100+x)/100;
			if(a+b!=z)goto skip;

			komia=nukia*(100+y)/100;
			komib=nukib*(100+y)/100;
			maxi=max(maxi,komia+komib);
			skip:;
		}
		cout<<maxi<<endl;
	}
	return 0;
}

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

int main()
{
  int n, m;
  cin >> n;
  int a = 0, b = 0;
  int x[n];
  rep(i, n){
    cin >> x[i];
  }
  sort(x, x + n);
  reverse(x, x + n);
  
  for(int i = 0; i < n; i += 2){
    a += x[i];
  }
  for(int i = 1; i < n; i += 2){
    b += x[i];
  }
  cout << a - b << endl;
  return 0;
}

Measured memory_bytes: 3552
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A = LI()

def primes(n):
    if n <= 1:
        return []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,int(n**0.5)+1):
        if is_prime[i]:
            for j in range(2*i,n+1,i):
                is_prime[j] = False
    return [i for i in range(2,n+1) if is_prime[i]]

from functools import reduce
def calc_gcd(A):
    return reduce(math.gcd, A)

def trial_division(n):
    d = defaultdict(int)
    while n%2 == 0:
        d[2] += 1
        n = n//2
    p = 3
    while p**2 <= n:
        while n%p == 0:
            d[p] += 1
            n = n//p
        p += 2
    if n != 1:
        d[n] += 1
    return d

x = primes(10**6+1)
a = calc_gcd(A)
d_prime = dict()
for x0 in x:
    d_prime[x0] = 0

if a != 1:
    print('not coprime')
else:
    flag = False
    for i in range(N):
        d = trial_division(A[i])
        for k in d.keys():
            if d_prime[k]:
                flag = True
                break
            else:
                d_prime[k] += 1
        if flag:
            break
    if not flag:
        print('pairwise coprime')
    else:
        print('setwise coprime')

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

int main(){
    int a, b;
    cin >> a >> b;
    if (a + b < 10) cout << a + b << endl;
    else cout << "error" << 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 sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  
  // 1kaime ouro
  rep(i,tx-sx){
  	cout << "R";
  }
  rep(i,ty-sy){
  	cout << "U";
  }
  
  //1kaime fukuro
  rep(i,tx-sx){
  	cout << "L";
  }
  rep(i,ty-sy){
  	cout << "D";
  }
  
  
  //2kaime ouro
  cout << "D";
  rep(i,tx-sx){
  	cout << "R";
  }
  cout << "R";
  cout << "U";
  rep(i,ty-sy){
  	cout << "U";
  }
  cout << "L";
  
  //2kaime fukuro
  cout << "U";
  rep(i,tx-sx){
  	cout << "L";
  }
  cout << "L";
  cout << "D";
  rep(i,ty-sy){
  	cout << "D";
  }
  cout << "R";  

  
  
  
  cout << endl;
  return 0;
}

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

using namespace std;


typedef long long ll;
#define loop(i, init, val) for(i = init; i < val; i++)
#define srt(v) sort(v.begin(), v.end())

int main(){
	int i, j, k;
	int n;
	cin >> n;
	vector<int> p(n);
	loop(i, 0, n)	cin >> p[i];

	int ans = 1;
	int tmp = p[0];
	loop(i, 1, n){
		if(tmp > p[i]){
			ans++;
			tmp = p[i];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(n, -1);
	rep(i, m){
		int s, c;
		cin >> s >> c;
		if(s > n){
			cout << -1 << endl;
			return 0;
		}
		if(a[s-1] != -1 && a[s-1] != c){
			cout << -1 << endl;
			return 0;
		}
		a[s-1] = c;
	}
	v1 answer(n);
	if((a[0] == 0 && n == 1 && a.size() == 1)|| a[0] == -1 && n==1 &&a.size() == 1){
		cout << 0 << endl;
		return 0;
	}
	if(a[0] == 0){
		cout << -1 << endl;
		return 0;
	}else if(a[0] == -1){
		answer[0] = 1;
	}else{
		answer[0] = a[0];
	}
	for(int i = 1; i< n; i++){
		if(a[i] == -1){
			answer[i] = 0;
		}else{
			answer[i] = a[i];
		}
	}
	rep(i, n){
		cout << answer[i];
	}
	cout << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    cout << fixed << setprecision(14);
    double a,b,x;
    cin >> a >> b >> x;
    if(x >= a*a*b/2){
        double c = 2*x/(a*a) - b;
        double d = b - c;
        cout << atan(d/a) * 180 / 3.14159265358979323846 << endl;
    }
    else{
        double c = 2*x/a/b;
        cout << atan(b/c) * 180 / 3.14159265358979323846 << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

constexpr double INIT = -1000.;
std::vector<std::vector<double>> dp;
std::vector<double> p; 

double sol(int i, int j) {
  if ( i == 0 && j == 0 ) return 1.;
  if ( i <= 0 ) return 0.;
  if ( i < j ) return 0.;
  if ( dp[i][j] != INIT ) return dp[i][j];
  return dp[i][j] = sol(i-1, j-1)*p[i-1] + sol(i-1,j)*(1.-p[i-1]);
}

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  p.resize(N); rep(i,N) std::cin >> p[i];
  dp.resize(N+1); rep(i,N+1) dp[i].assign(N+1, INIT);

  double ans = 0.;
  for(int i=(N+1)/2; i<=N; i++) ans += sol(N,i);
  std::cout << std::fixed << std::setprecision(10) << ans << std::endl;
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define For(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define sz(x) ((int)(x).size())
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef long long ll;

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

  int n,W; cin>>n>>W;
  vi w(n+1),v(n+1);
  rep(i,n) cin>>w[i+1]>>v[i+1];
  vector<vector<ll>> dp(W+1,vector<ll>(n+1,0));
  For(i,1,W) {
    For(j,1,n) {
      dp[i][j] = dp[i][j-1];
      if(i-w[j]>=0)
        dp[i][j] = max(dp[i][j], dp[i-w[j]][j-1]+v[j]);
    }
  }
  cout<<dp[W][n]<<endl;
}


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

int main(void){
    int x,y;
    cin >> x >> y;

    while(x || y){
        if(x > y){
            swap(x,y);
        }
        printf("%d %d\n",x,y);
        cin >> x >> y;
    }
}


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

int main(){
    string s;
    int k;
    cin >> s >> k;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'&&i<k-1) continue;
        else{
            cout << s[i]-'0' << endl;
            return 0;
        }
    }
}

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

using namespace std;

#define ll long long
#define MOD 1000000007

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

    double t;
    int a,b;

    cin>>a>>b>>t;

    t += 0.5;

    int x = 0,ans = 0;
    while(true){
        x += a;
        if(x<=t)
         ans += b;
        else 
            break;
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 384
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))


N = int(input())
a = list(map(int, input().split()))

print(sum([ai - 1 for ai in a]))

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll k, s, ans = 0;
  cin >> k >> s;
  
  rep(i, 0, k+1) {
    rep(j, 0, k+1) {
      ll diff = s -(i+j);
      if(0 <= diff and diff <= k) ans++;
    }
  }  
  cout << ans << "\n";
}

Measured memory_bytes: 256
S = gets.chomp.chars
K = gets.chomp.to_i

n = S.length

# DP [i][j][k]
# i桁目まで見たときに、j個の非0があって、k 0-> Nと一致 1-> N以下

dp = Array.new(n+1).map{Array.new(K+1).map{Array.new(2,0)}}

# 0桁目まで見たときはNと一致してるので最後は0
dp[0][0][0] = 1

n.times do |i|
  num = S[i].to_i

  (K+1).times do |j|
    2.times do |k|
      10.times do |d|
        # iは次の桁
        ni = i + 1
        nj = j
        nk = k

        # 非ゼロなら+1
        nj += 1 unless d == 0

        # K個を超えてしまったらnext
        next if nj > K

        # 一致してるとき
        if k == 0
          next if d > num
          nk = 1 if d < num
        end

        dp[ni][nj][nk] += dp[i][j][k]
      end
    end
  end
end

p dp[n][K][0] + dp[n][K][1]



Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] t = new int[n+1];
		for(int i=0;i<n*(n-1)/2;i++){
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			int c = stdIn.nextInt();
			int d = stdIn.nextInt();
			if(c>d){
				t[a]+=3;
			}
			else if(c<d){
				t[b]+=3;
			}
			else{
				t[a]+=1;
				t[b]+=1;
			}
		}
		int[] r = new int[n];
		for(int i=1;i<=n;i++){
			r[i-1] = t[i];
		}
		Arrays.sort(r);
		int[] r2 = new int[n+1];
		int cnt = 1;
		int z;
		for(int i=n-1;i>=0;){
			z=0;
			for(int j=1;j<=n;j++){
				if(r[i]==t[j]){
					r2[j] = cnt;
					z++;
				}
			}
			cnt+=z;
			i-=z;
		}
		for(int i=1;i<=n;i++){
			System.out.println(r2[i]);
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int x, y;
    cin >> x >> y;
    int money[206];
    rep(i, 206) {
        if ( i == 1 )      money[i] = 300000;
        else if ( i == 2 ) money[i] = 200000;
        else if ( i == 3 ) money[i] = 100000; 
        else               money[i] = 0;
    }
    if ( x == 1 && y == 1 ) cout << 300000 + 300000 + 400000 << endl;
    else                    cout << money[x] + money[y] << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0029
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> BTS = new List<int>();
            BTS.Add(int.Parse(Console.ReadLine()));
            BTS.Add(int.Parse(Console.ReadLine()));
            BTS.Add(int.Parse(Console.ReadLine()));
            BTS.Add(int.Parse(Console.ReadLine()));
            BTS.Add(int.Parse(Console.ReadLine()));

            List<int[]> Nums = GetAllPermutation(5);

            int result = int.MaxValue;

            for (int i = 0; i < Nums.Count(); i++)
            {
                int tmp = 0;

                for (int j = 0; j < Nums[i].Count(); j++)
                {
                    tmp += BTS[Nums[i][j]];

                    if (j != Nums[i].Count() - 1 && tmp % 10 != 0)
                    {
                        tmp += 10 - (tmp % 10);
                    }
                }

                if (tmp < result)
                {
                    result = tmp;
                }
            }

            Console.WriteLine(result);
        }

        static List<int[]> GetAllPermutation(int N)
        {
            var res = new List<int[]>();
            var array = Enumerable.Range(0, N).ToArray();

            do
            {
                var copy = new int[N];
                array.CopyTo(copy, 0);
                res.Add(copy);
            } while (NextPermutation(array));

            return res;
        }


        static bool NextPermutation(int[] array)
        {
            var size = array.Length;
            var ok = false;

            int i = size - 2;
            for (; 0 <= i; i--)
            {
                if (array[i] < array[i + 1])
                {
                    ok = true;
                    break;
                }
            }

            if (ok == false)
            {
                return false;
            }

            int j = size - 1;
            for (; ; j--)
            {
                if (array[i] < array[j])
                {
                    break;
                }
            }

            var tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;

            Array.Reverse(array, i + 1, size - (i + 1));

            return true;
        }
    }
}


Measured memory_bytes: 28260
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;



int main()
{
	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;
	cout << (e - a > k ? ":(" : "Yay!") << endl;
}


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

int main(){
	int a;
	int b;

	cin >> a >> b;

	if(a < b){
		cout << "a < b" << endl;
	}
	if(a > b){
		cout << "a > b" << endl;
	}
	if(a == b){
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
int gcd(int x,int y){
    if(x<y)swap(x,y);
    int r=1;
    while (r) {
        r=x%y;
        x=y;
        y=r;
    }
    return x;
    
}
int main() {
    int a,b;
    while (cin >> a >> b) {
        cout << gcd(a,b)<< " "<< (long long) a*b/gcd(a, b)<<endl;
    }
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d;
    cin>>n>>d;
    int x[20][20];
    FOR(i,1,n+1)FOR(j,1,d+1) cin>>x[i][j];
    int ans=0;
    FOR(i,1,n+1)FOR(j,1,n+1){
      if(i>=j) continue;
      int now=0;
      FOR(k,1,d+1){
        now+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        //cout<<now<<endl;
      }
      rep(i,100000){
        if(i*i==now){
          ans++;
          //cout<<now<<endl;
        }
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
typedef vector<long long> vll;

// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	return a/ gcd(a,b)*b;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N,a[100010],c1=0,c2= 0, c4 = 0;
	scanf("%d", &N);
	vll T(N);
	REP(i, N) {
		cin >> T[i];
	}
	ll ans = 1;
	REP(i, N) {
		ans = lcm(ans, T[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;

int main(){
    itn n;
    std::cin >> n;
    VEC(int,a,n);
    int c=0;
    int ans=0;
    rep(i,n-1){
        if(a[i]>=a[i+1])c++;
        else{
            ans=max(ans,c);
            c=0;
        }
    }
    ans=max(ans,c);
    std::cout << ans << std::endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int n, i, cut,cost, sum=0, a[200000],t,d1,d2,ans;
    scanf("%d", &n);
    a[0] = 0;
    a[n+1] = 0;
    for (i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (i = 1; i <= n + 1; i++)
    {
        t = a[i] - a[i - 1];
        if (t < 0)
            t = -t;
        sum += t;
    }
    for (i = 1; i <= n; i++)
    {
        d1 = a[i] - a[i - 1];
        if (d1 < 0)
            d1 = -d1;
        d2 = a[i + 1] - a[i];
        if (d2 < 0)
            d2 = -d2;
        cut = d1 + d2;
        cost = a[i + 1] - a[i - 1];
        if (cost < 0)
            cost = -cost;
        ans = sum + cost - cut;
        printf("%d\n", ans);
    }
    return 0;
}

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

int main() {

  long long H;
  cin >> H;

  long long answer = 0;

  long long count = 0;
  while (1 < H) {
    H = H / 2;
    count++;
  }

  while (0 < count) {
    answer += pow(2, count);
    count--;
  }
  
  cout << answer + 1 << endl;

}

Measured memory_bytes: 256
module app;

import std.stdio;
import std.algorithm;
import std.range;
import std.array;
import std.string;
import std.conv;

void main(string[] args) {
    auto five_hund = readln.chop.to!int;
    auto one_hund = readln.chop.to!int;
    auto fifty = readln.chop.to!int;
    immutable auto target_yen = readln.chop.to!int;
    int answer;
    foreach(fh; iota(0, five_hund+1)) {
        foreach(oh; iota(0, one_hund+1)) {
            foreach(f; iota(0, fifty+1)) {
                if(fh*500 + oh*100 + f*50 == target_yen){
                    answer++;
                }
            }
        }
    }
    writeln(answer);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef vector<vector<double> > vvd;

int main(){


    int N;
    cin >> N;

    vector<vector<int>> plans;
    for(int i=0; i<N; ++i){
        int t, x, y;
        cin >> t >> x >> y;
        plans.push_back(vector<int>{t, x, y});
    }

    int x = 0;
    int y = 0;
    int t = 0;

    for( auto plan : plans ) {

        int dt = plan[0] - t;
        int dx = abs(plan[1] - x);
        int dy = abs(plan[2] - y);

        if( dt < (dx+dy) or (dt-dx-dy)%2 != 0 ){
            cout << "No" << endl;
            return 0;
        }

    }

    cout << "Yes" << endl;

    return 0;
}

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

int main() {
  int N, ans;
  cin >> N;
  ans = N;
  string S;
  cin >> S;
  rep(i, N-1) if (S[i] == S[i+1]) {
    --ans;
  }
  cout << ans <<endl;
  return 0;
}

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

int main(){
  int N,M;  cin >> N >> M;
  vector<int>num(N,-1);
  for(int i=0;i<M;i++){
    int s,c;  cin >> s >> c;
    if(num.at(s-1) == -1 || num.at(s-1) == c) num.at(s-1) = c;
    else{
      cout << "-1" << endl;
      return 0;
    }
  }
  if(num.at(0) == 0 && N != 1){
    cout << "-1" << endl;
    return 0;
  }
  else if(num.at(0) == -1 && N != 1)  num.at(0) = 1;

  for(int i=0;i<num.size();i++){
    if(num.at(i) == -1) num.at(i) = 0;
    cout << num.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#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++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const ll longinf=1LL<<60;
const int mod=1000000007;    
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

ll pow(ll n,int k){
  if(k<0)k+=mod-1;
  ll ret=1;
  while(k>0){
    if(k&1)ret=ret*n %mod;
    n=n*n %mod;
    k>>=1;
    }
  return ret;
  }

int main(){
  ll n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  ll fact[n+1];
  fact[0]=1;
  rep(i,n)fact[i+1]=(i+1)*fact[i]%mod;
  ll invfact[n+1];
  rep(i,n+1)invfact[i]=pow(fact[i],-1);
  ll dp[1001][1001];
  rep(i,n+1){
    dp[a-1][i]=0;
    }
  dp[a-1][0]=fact[n];
  REP(i,a,b+1){
    rep(j,n+1){
      dp[i][j]=dp[i-1][j];
      if(i*c<=j){
        int m=min(d-c+1,1+(j-i*c)/i);
        rep(k,m){
          ll res=dp[i-1][j-i*(c+k)]*pow(invfact[i],c+k)%mod;
          dp[i][j]+=res*invfact[c+k]%mod;
          }
        dp[i][j]%=mod;
        }
      }
    }
  cout<<dp[b][n]<<endl;
  return 0;
  }

Measured memory_bytes: 8064
#include <bits/stdc++.h>
	using namespace std;
	
	typedef long long ll;
	#define pi 3.14159265 
	#define EPS 1e-8
	
	#define mod 1000000007
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define endl "\n"

	const ll INF=(ll)3e17;
	
	
	
	int main()
	{
		 ios_base::sync_with_stdio(false);
		 cin.tie(NULL);
		 
		 ll n,k;
		 cin>>n>>k;
		 
		 vector<ll> pref(n+2,0);
		 for(ll i=2;i<=(n+1);i++)
		 {
			 pref[i]=pref[i-1]+(i-1);
		 }
		 ll prev=-1,ans=0;
		 for(ll i=k;i<=(1+n);i++)
		 {
			
			 prev=pref[i];
			 ll next=pref[n+1]-pref[n+1-i];
			 ans+=(next-prev+1);
			 prev=next;
			// cout<<prev<<" "<<next<<endl;
			 ans%=mod;
		 }
		 cout<<ans;
	}


Measured memory_bytes: 4776
#include <iostream>
#include <cstring>
#include <stdio.h>

int find(const std::string &str){
	return (str.find("this",0)!=std::string::npos) + (str.find("that",0)!=std::string::npos) + (str.find("the",0)!=std::string::npos);
}

std::string rot(const std::string &prm, int n)
{
	std::string str=prm;

	for(int i=0; i < str.size(); i++){
		if(('a'<=str[i]) && (str[i]<='z'))
			str[i] = (str[i]+n > 'z')?(str[i]+n-'z'+'a'-1):(str[i]+n);
	}
return str;
}
	
int main(void)
{
	char s[81]="";
	while(std::cin.getline(s,sizeof(s)))
	{
		std::string in=s;
		for(int i=0;i < ('z'-'a')+1;i++)
		{
			if(find(rot(in, i))){
				std::cout << rot(in, i) << std::endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1180
from collections import deque
from heapq import heapify, heappop, heappush
N = int(input())
tmp = list(map(int, input().split(' ')))
former_A = deque(tmp)
latter_A = deque(tmp.copy())
former_heap = list()
latter_heap = list()
for _ in range(N):
    former_heap.append(former_A.popleft())
    latter_heap.append(- latter_A.pop())
heapify(former_heap)
heapify(latter_heap)

former_sum = sum(former_heap)
former_sum_list = [former_sum]
for k in range(N):
    new_a = former_A.popleft()
    heappush(former_heap, new_a)
    min_a = heappop(former_heap)
    former_sum += new_a - min_a
    former_sum_list.append(former_sum)

latter_sum = sum(latter_heap)
latter_sum_list = [latter_sum]
for k in range(N):
    new_a = - latter_A.pop()
    heappush(latter_heap, new_a)
    min_a = heappop(latter_heap)
    latter_sum += new_a - min_a
    latter_sum_list.append(latter_sum)
latter_sum_list.reverse()

answer = max([former + latter for former, latter in zip(former_sum_list, latter_sum_list)])
print(answer)

Measured memory_bytes: 37468
#include<bits/stdc++.h>
    #define FOR(i,n) for(int i=0;i<n;i++)
    #define SFOR(i,a,b) for(int i=a;i<b;i++)
    #define elif(a) else if(a)
    #define INF INT_MAX
    #define F first
    #define S second
    #define endl '\n'
    using namespace std;
    typedef long long ll;
    typedef pair<int,int>P;
    int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,X,Y,x,y,mx=-1,my=INF;
    cin>>n>>m>>X>>Y;
    FOR(i,n){
    cin>>x;
    mx=max(mx,x);
    }
    FOR(i,m){
    cin>>y;
    my=min(my,y);
    }
    mx=max(X,mx);
    my=min(Y,my);
    if(my-mx>0) cout<<"No War"<<endl;
    else cout<<"War"<<endl;
    return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 103, mod = 998244353;
inline void qmo(int &x){x += (x >> 31) & mod;}
map<string, int> F, G;
string S;
int f(string s);
int g(string s){
	if(G.count(s)) return G[s];
	if(s.size() == 1) return G[s] = s[0] - '0' + 1;
	int &ans = G[s];
	for(Rint i = 1;i < s.size();++ i) if(!(s.size() % i)){
		string t; int tmp = s.size() / i;
		for(Rint j = 0;j < i;++ j){
			bool flag = true;
			for(Rint k = 0;k < tmp && flag;++ k) flag &= s[i * k + j] == '1';
			t += (char)(flag + '0');
		}
		qmo(ans += f(t) - mod);
	}
	return ans;
}
int f(string s){
	if(F.count(s)) return F[s];
	int &ans = F[s];
	for(Rint i = 1;i <= s.size();++ i)
		qmo(ans += (LL) g(s.substr(0, i)) * f(s.substr(i)) % mod - mod);
	return ans;
}
int main(){
	cin >> S; F[""] = 1; cout << f(S);
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,M;
int k[13];
vector<int> s[13];
int p[13];
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> k[i];
		s[i].resize(k[i]);
		for(int j=0;j<k[i];j++){
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	for(int i=0;i<M;i++)cin >> p[i];
	int ans = 0;
	for(int i=0;i<(1<<N);i++){
		bool flag = true;
		for(int j=0;j<M;j++){
			int cnt = 0;
			for(int l=0;l<k[j];l++){
				if((i>>s[j][l])&1)cnt++;
			}
			if(cnt%2!=p[j]){
				flag = false;
				break;
			}
		}
		if(flag)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

vector<P> v;

bool pairgreater(const P& a, const P&b){
  return a.first > b.first;
}

int main(){
  int N,A,B,X;
  cin >> N;
  REP(i,N){
    cin >> A >> B;
    v.push_back(make_pair(B,A));
  }
  sort(v.begin(),v.end(),pairgreater);
  X = v[0].first;
  REP(i,N-1){
    X = min(v[i+1].first, X - v[i].second);
  }
  X -= v[N-1].second;
  if(X >= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
map<string ,int >mp;
map<string ,int >::iterator it;
string an[200000+7];
int main()
{
    int n;
    cin>>n;
    string s;
    int ans=0;
    for(int i=1;i<=n;i++){
        cin>>s;
        mp[s]++;
        ans=max(ans,mp[s]);
    }
    int pos=0;
    for(it=mp.begin();it!=mp.end();it++){
        if(it->second==ans) an[pos++]=it->first;
    }
    sort(an,an+pos);
    for(int i=0;i<pos;i++) cout<<an[i]<<endl;
 
    return 0;
}

Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define Liny "Yes\n"
#define Linn "No\n"

int A,B,M,ans,x,y,c,t;
int a[100001],b[100001];

int main(){
  cin>>A>>B>>M;
  REP(i,A){ cin>>a[i];}
  REP(i,B){ cin>>b[i];}
  ans = (int)*min_element(a,a+A) + (int)*min_element(b,b+B);
  REP(i,M){
    cin>>x>>y>>c;
    t = a[x-1]+b[y-1]-c;
    if(t<ans){ans=t;}
  }
  cout << ans <<"\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int unsigned long long
#define rep(i,m,n) for(int i=m;i<n;i++)
#define repr(i,n,m) for(int i=n;i>=m ;i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define mp make_pair
#define pp pop_back
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 
bool sortbysec(const pair<int,int> &a,
             const pair<int,int> &b)
{
   return (a.second < b.second);
}
bool sortinrev(const pair<int,int> &a,  
              const pair<int,int> &b)
{
      return (a.first > b.first);
}
int ispal(string s)
{
	int x=s.length();
	for(int i=0,j=x-1;i<x/2,j>=x-x/2;i++,j--)
		if(s[i]!=s[j])
			return 0;
	return 1;
}
void solve()
{
	int n,total=0;
	cin>>n;
	rep(i,1,n+1)
	{
		if(i%3!=0&&i%5!=0)
			total+=i;
	}cout<<total;
}	
signed main()
{
           	   // #ifndef ONLINE_JUDGE
               // freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
               // #endif 
  int t=1;
 //cin>>t;
  while(t--){
  solve();
  cout<<"\n";
}
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
 return 0;
}  


Measured memory_bytes: 3788
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
sum = 0
max = 0
(n-1).times do |i|
	if arr[i] >= arr[i + 1]
		sum += 1
	else
		sum = 0
	end
	max = sum if max < sum
end
puts max



Measured memory_bytes: 21980
#include <stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a*b>c*d) printf("%d\n",a*b);
	else printf("%d\n",c*d);
	return 0;
	
}

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

struct qu{
	int l, r, id;
    bool operator<(qu & f) const {return r < f.r;}
}b[500010];

int n, m;
int a[500010], c[500010],vis[1000010];
int ans[500010];

int lowbit(int x){
	return x & (-x);
}
void update(int i,int k) {
	while(i <= n){
		c[i] += k;
		i += lowbit(i);
	}
}
int getsum(int i){
	int res = 0;
	while(i){
		res += c[i];
		i -= lowbit(i);
	}
	return res;
}

inline void solve(int T) {
    cin >> n >> m;
	rep(i, 1, n) cin >> a[i];
	rep(i, 1, m){
		b[i].id = i;
		cin >> b[i].l >> b[i].r;
	}
	sort(b + 1, b + m + 1);
	int ind = 1;
	int cnt = 1;
	while(cnt <= m){
		for(; ind <= b[cnt].r; ind++){
			if(vis[a[ind]])
				update(vis[a[ind]], -1);
			update(ind, 1);
			vis[a[ind]] = ind;
		}
		ans[b[cnt].id] = getsum(b[cnt].r) - getsum(b[cnt].l - 1);
		cnt++;
	}
	rep(i, 1, m) cout << ans[i] << endl;	

}   
int main()
{
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
 
    int T = 1;
    // cin >> T;
    rep(i, 1, T) solve(i);
    system("pause");
}

Measured memory_bytes: 17620
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a<b) System.out.println("a < b");
        else if(a>b) System.out.println("a > b");
        else System.out.println("a == b");
    }
}


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

"""042-d"""


import sys

def factorialMod(x, mod):
    """Calculate modulo of funcotial 'x'."""
    assert isinstance(x, int)
    assert x >= 0
    assert isinstance(mod, int)
    assert mod >= 0

    if x == 0:
        return 1
    return (x % mod) * factorialMod(x - 1, mod)

def binpow(p, e):
    """Bisection exponentiation."""
    assert isinstance(e, int)
    assert e >= 0

    a = 1
    while e:
        if e % 2 == 0:
            p = p * p
            e /= 2
        else:
            a = a * p
            e = e - 1
    return a


def main():
    """Main function."""
    mod = 1000000007
    H, W, A, B = map(int, sys.stdin.readline().split())

    fact_table = [1, 1]
    [fact_table.append((fact_table[-1] * i) % mod) for i in range(2, H + W - 1)]
    inv_fact_table = [pow(fact_table[i], 1000000005, 1000000007) for i in range(H + W - 1)]

    # print(inv_fact_table)

    def comb(n, r):
        """Calculate combination."""
        assert n >= r and n >= 0 and r >= 0

        return fact_table[n] * inv_fact_table[r] * inv_fact_table[n - r] % mod

    result = sum([comb(H - A + i - 1, H - A -1) * comb(W + A - i - 2, A - 1) for i in range(B, W)]) % mod

    print(result)

if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 22816
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 1e6 + 5;

int n;
char s[N];

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	boolean flag2 = true;
	for (int i = 1; i < n; i++) {
		if (s[i + 1] >= s[i]) {
			s[i] = s[i + 1] - s[i];
		} else {
			s[i] = s[i] - s[i + 1];	
		}
		if (s[i] == 1) {
			flag2 = false;
		}
	}
	if (flag2) {
		for (int i = 1; i < n; i++) {
			if (s[i] == 2) {
				s[i] = 1;
			}
		}
	} else {
		for (int i = 1; i < n; i++) {
			if (s[i] == 2) {
				s[i] = 0;
			}
		}
	}
	int ans = 0;
	--n;
	for (int i = 0; i < n; i++) {
		if ((i & (n - 1)) == i) {
			ans += s[i + 1];
		}
	}
	ans = (ans & 1) * (1 + flag2);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
int main(void){
    int a, b, c, d;
    scanf("%d %d %d", &a, &b, &c);
    if(a>=b&&a>c){
        d=b+c;
    }else if(b>=c&&b>=a){
        d=a+c;
    }else{
        d=a+b;
    }
    printf("%d", d);
    return 0;
}

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

int main(){
	int n, m;
	cin >> n >> m;

	int maxL = 0;
	int minR = n;
	rep(i, m){
		int l, r;
		cin >> l >> r;
		maxL = max(maxL, l);
		minR = min(minR, r);
	}

	int ans = max(minR-maxL+1, 0);

	cout << ans << endl;

	return 0;
}

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	int x = 800*N;
	int y = (N/15)*200;

	cout << x-y << endl;


	return 0;

}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

ll n, a, b;

int main() {
    cin >> n >> a >> b;
    ll rem = n % (a + b);

    cout << (n / (a + b)) * a + min(rem, a) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const ll INF = 1ll << 60;
const int N = 5010;
int n, A, B, per[N], mx[N], num[N], pla[N];
ll dp[N][N], ans;
int main() {
  read(n), read(A), read(B);
  rep (i, 1, n) read(per[i]), pla[per[i]] = i;
  memset(dp, 0x3f, sizeof dp);
  dp[n][n] = 0;
  ans = INF;
  rrp (i, n, 1) {
    rep (j, 1, n) {
      num[j] = 0;
      mx[j] = 0;
      if (per[j] <= i) num[j] = 1, mx[j] = per[j];
    }
    rep (j, 2, n) mx[j] = max(mx[j], mx[j-1]);
    rep (j, 2, n) num[j] += num[j-1];
    rep (j, 1, n) {
      int p = pla[mx[j]];
      if (!p) {
	ckmn(ans, dp[i][j]);
	continue;
      }
      if (mx[j] < i) ckmn(dp[i-1][j], dp[i][j]);
      ckmn(dp[i-1][j], dp[i][j] + A);
      ckmn(dp[i-1][p-1], dp[i][j] + 1ll * B * (num[j] - num[p]));
    }
  }
  rep (i, 0, n) ckmn(ans, dp[i][0]), ckmn(ans, dp[0][i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 196480
#include<stdio.h>
int main(){
	int h;
	int m;
	int s;
	int S;
	
	scanf("%d",&S);
	h = S / 3600;
	m = S / 60 - ( h * 60 );
	s = S - ( h * 3600 + m * 60 );
	printf("%d:%d:%d\n",h,m,s);
	
 	return 0;
 }

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef priority_queue<int> Pr; typedef vector<int> V; typedef vector<P> Vp; typedef map<int,int> MP;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    string s; cin>>s; Int ans=1; int n=s.size(); MP al;
    al[s[0]-'a']=1;
    for (int i = 1; i < n; i++){
        int c=s[i]-'a';
        for(auto p:al){
            if(p.first!=c)ans+=p.second;
        }
        al[c]++;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 720
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String A=sc.next();
        String B=sc.next();
        String C=sc.next();
        char[] a=A.toCharArray();
        char[] b=B.toCharArray();
        char[] c=C.toCharArray();
        if(a[A.length()-1]==b[0]&&b[B.length()-1]==c[0]){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,c,k; cin>>a>>b>>c>>k;
	int ans=min(a,k); k=max(0,k-a);
	if(k!=0)k=max(0,k-b);
	if(k!=0)ans-=k;
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 3648
#n = int(input())
n, q = map(int, input().split())
#bl = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
s = input()
acnum = [0]*(n+1)
for i in range(2, n+1):
    if s[i-2:i] == 'AC':
        acnum[i] += acnum[i-1]+1
    else:
        acnum[i] += acnum[i-1]

for i in range(q):
    l, r = map(int, input().split())
    print(acnum[r]-acnum[l])


Measured memory_bytes: 77484
//nupt2017team08
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <cstring>
#include <algorithm>
using namespace std;
int N,a;
const int mod = 1e9+7;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(scanf("%d",&N)!=EOF)
    {
        long long ans = 1;
        int k=0;
        for(int i=1;i<=N;i++)
        {
            scanf("%d",&a);
            k++;
            if(a<2*k-1)
            {
                ans*=k;
                ans%=mod;
                k--;
            }
        }
        for(int i=1;i<=k;i++)
        {
            ans*=i;
            ans%=mod;
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256