akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int n={},k={};
string integer[11]={};
vector<string>num={};
int chousen[11]={};
string complete_integer[10000]={};
string answer={};
int integer_count=0;


void operation(){
    for(int i=1;i<=n;i++){
        if (chousen[i]==0){
            
            chousen[i]=1;
            num.push_back(integer[i]);
        
            if(num.size()==k){
                for(int i=1;i<=k;i++){
                    answer+=num[i-1];
                }
                for(int i=1;i<=integer_count;i++){
                    if(answer==complete_integer[i]){
                        goto none;
                    }
                }
                integer_count+=1;
                complete_integer[integer_count]=answer;

                none:;
                answer={};
            }else{
                operation();
            }
            num.pop_back();
            chousen[i]=0;
        }
        
    }

}







int main(){
    
    while(true){

    cin >> n >> k;
    if (n==0&&k==0){
        break;
    }
    for(int i=1;i<=n;i++){
        cin >> integer[i];
    }

    operation();

    cout << integer_count << endl;
        
    n={};
    k={};
    for(int i=0;i<=10;i++){
        integer[i]={};
        chousen[i]={};
    }
    num={};
    for(int i=0;i<=9999;i++){
        complete_integer[i]={};
    }
    answer={};
    integer_count=0;
        
    }
    return 0;
}

Measured memory_bytes: 3376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    bool flag = false;
    for (ll i = 0; i <= n; i++) {
        for (ll j = 0; j <= m; j++){
            if ((m - j) * i + (n - i) * j == k) flag = true;
        }
    }
    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
//const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	mint ans=1;
	vector<int> count(N, 0);
	vector<int> check(N, 0);
	while (N--)
	{
		int a;
		cin >> a;
		count.at(a)++;
		check.at(a)++;
		if (a == 0)
		{
			ans *= 4 - count.at(a);
		}
		else{
			ans *= min({4 - count.at(a), count.at(a - 1), check.at(a - 1)});
			check.at(a - 1)--;
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3976
n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [0]*n
 
for i in range(m):
    a,b = map(int, input().split())
    if high[a-1] > high[b-1]:
        if ans[a-1] == 0:
            ans[a-1] = 1
        ans[b-1] = -1
    elif high[a-1] < high[b-1]:
        if ans[b-1] == 0:
            ans[b-1] = 1
        ans[a-1] = -1
    else:
        ans[b-1] = -1
        ans[a-1] = -1
print(ans.count(0) + ans.count(1))

Measured memory_bytes: 86028
#include <bits/stdc++.h>///int * int = int
using namespace std;
int h,w,d,s[300][300],q,a,b;
int x[90001],y[90001];
int dp[90001];
int main()
{
    scanf("%d%d%d",&h,&w,&d);
    for(int i = 0;i < h;i ++)
    {
        for(int j = 0;j < w;j ++)
        {
            scanf("%d",&s[i][j]);
            x[s[i][j]] = i;
            y[s[i][j]] = j;
        }
    }
    for(int i = 1 + d;i <= h * w;i ++)
    {
        dp[i] = dp[i - d] + abs(x[i] - x[i - d]) + abs(y[i] - y[i - d]);
    }
    scanf("%d",&q);
    for(int i = 0;i < q;i ++)
    {
        scanf("%d%d",&a,&b);
        printf("%lld\n",abs(dp[a] - dp[b]));
    }
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  ll N;
  cin >> N;
  vector<int> A(N);
  vector<int> cnt(1010101);
  vector<int> ans(1010101);
rep(i,N){
  cin >> A.at(i);
  cnt.at(A.at(i))++;
}
  vector<int> elem;
  rep(i,1010101){
if(cnt.at(i) == 1)elem.push_back(i);
  }
  sort(all(A));
  A.erase(unique(all(A)),A.end());
  rep(i,SZ(A)){
    for(int m = 2;A.at(i) * m < 1010101;m++){
      ans.at(m * A.at(i)) = 1;
    }
  }
  ll answer =0;
  rep(i,SZ(elem)){
    if(ans.at(elem.at(i)) == 0)answer++;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 12928
animal,leg = [int(x) for x in input().split()]
import numpy as np
X = np.array([
    [1,1],
    [2,4]
])
Y = np.array([
    [animal],
    [leg]
])
X_inverse = np.linalg.inv(X)
answer = X_inverse.dot(Y)
result = 0
for x in answer:
    for y in x:
        if y<0 or not y.is_integer():
            result = True
            break
if result:
    print("No")
else:
    print("Yes")

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 500010;

template<typename T>
class BITree {
    public:
        BITree(int n) : m_N(n + 1) { m_Tree.assign(m_N, 0); }
        // [1, i] の合計値を返す (log m_N)
        // 閉区間であることに注意
        T Sum(int i) {
            assert(i >= 0 && i < m_N);
            T s = 0;
            while(i > 0) { s += m_Tree[i]; i -= i & -i; }
            return s;
        }
        // [i, j] の合計値を返す (log m_N)
        // i < j
        // 閉区間であることに注意
        T Sum(int i, int j) {
            assert(i <= j);
            return Sum(j) - Sum(i-1);
        }
        // i 番目の要素(1-indexed)に x を足して更新 O(log m_N)
        void Add(int i, T x){ while(i < m_N) { m_Tree[i] += x; i += i & -i; } }
    private:
        int m_N;            // 要素数
        vector<T> m_Tree;   // BIT 本体
};

int N, Q;
vector<int> C;

vector< pair<int, int> > LR;
vector< vector<int> > point_st, point_lr;

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

    cin >> N >> Q;
    C.resize(N);
    REP(i, N) {
        cin >> C[i];
    }
    point_st.assign(N + 10, vector<int>());
    point_lr.assign(N + 10, vector<int>());
    REP(i, Q) {
        int l, r;
        cin >> l >> r;
        point_lr[l].push_back(r);
        LR.push_back(make_pair(l, r));
    }

    // C を同じ数字のペア数直線に変換
    vector<int> prev(N + 10, -1);    // 前回の i があった場所
    REP(i, N) {
        if(prev[C[i]] >= 0) {
            point_st[prev[C[i]] + 1].push_back(i + 1);
        }
        prev[C[i]] = i;
    }

    BITree<int> fenwick(N + 1);
    map< pair<int, int>, int> ans;
    for(int x = N; x >= 0; --x) {
        DBG("x = %lld\n", x);
        for(auto y : point_st[x]) {
            fenwick.Add(y + 1, 1);
            DBG("add: y = %lld\n", y);
        }
        for(auto y : point_lr[x]) {
            // これまで出ている (s, t) のうち以下のものの数
            int cnt = fenwick.Sum(1, y + 1);
            ans[make_pair(x, y)] = (y - x + 1) - cnt;
            DBG("xy: (%lld, %lld) cnt: %lld\n", x, y, cnt);
        }
    }

    for(auto lr : LR) {
        printf("%lld\n", ans[lr]);
    }

    return 0;
}


Measured memory_bytes: 102920
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> b(N);
  for (int i = 0; i < N; i++){
    cin >> b[i];
  }
  vector<int> ans(N, -1);
  bool ok = true;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N - i; j++){
      if (b[j] == j + 1){
        ans[i] = j;
      }
    }
    if (ans[i] == -1){
      ok = false;
      break;
    } else {
      b.erase(b.begin() + ans[i]);
    }
  }
  if (!ok){
    cout << -1 << endl;
  } else {
    for (int i = N - 1; i >= 0; i--){
      cout << ans[i] + 1 << endl;
    }
  }
}

Measured memory_bytes: 3564
n=int(input())
a=list(map(int, input().split()))
ans=1

if 0 in a:
  print(0)
else:
  for i in range(n):
    ans*=a[i]
    if ans>10**18:
      print(-1)
      break
    elif i==n-1:
      print(ans)

Measured memory_bytes: 21468
#include <iostream>
#include <algorithm>
#include <atomic>
#include <thread>
#include <mutex>
#include <string>
#include <string.h>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <limits.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define P std::pair<int,int> 
#define INF LLONG_MAX/3
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n;
string s[36],t[36];
void bubble() {
	rep(i, n) {
		for (int j = n - 1; j >= i + 1; j--) {
			if (s[j][1] - '0' < s[j - 1][1] - '0')swap(s[j], s[j - 1]);
		}
	}
}
void selection() {
	rep(i, n) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (t[j][1] - '0' < t[minj][1] - '0')minj = j;
		}
		swap(t[i], t[minj]);
	}
}
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> s[i];
		t[i] = s[i];
	}
	bubble();
	rep(i, n - 1)cout << s[i] << " ";
	cout << s[n - 1] << endl << "Stable" << endl;
	selection();
	bool b = true;
	rep(i, n) {
		if (s[i] != t[i])b = false;
	}
	rep(i, n - 1)cout << t[i] << " ";
	cout << t[n - 1] << endl << (b ? "Stable" : "Not stable") << endl;
	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 3164
s = gets.chomp
x = 0
a = -1
z = -1
s.each_char do |c|
  if c == "A" and a == -1
    a = x
  elsif c == "Z"
    z = x
  end
  x += 1
end
puts ((z-a+1) > 0)? z-a+1: 0

Measured memory_bytes: 2300
#include<iostream>
using namespace std;
int main(){
    int r, g, b;
    cin >> r >> g >> b;
    int sum = r*100+g*10+b;
    if(sum%4==0)
        cout << "YES\n" << endl;
    else
        cout << "NO\n" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {

	var N int

	fmt.Scan(&N)

	var num []int

	for i:=0;i<N;i++{
		num = append(num,i)
	}

	x:=SliceInt(N)
	y:=SliceInt(N)

	for i:=0;i<N;i++{

		fmt.Scan(&x[i],&y[i])
	}

	sum :=0.0

	for _,v:= range Permute(num){

		for i:=0;i<N-1;i++{
			sum += math.Sqrt(math.Pow(float64(x[v[i+1]]-x[v[i]]),2) + math.Pow(float64(y[v[i+1]]-y[v[i]]),2))
		
		}
	} 

	cnt:=1

	for i:=N;i>0;i--{

		cnt = cnt*i

	}

	result :=   sum / float64(cnt)

	fmt.Println(result)

}

//Permute 順列
func Permute(nums []int) [][]int {
	n := factorial(len(nums))
	ret := make([][]int, 0, n)
	permute(nums, &ret)
	return ret
}

//permute @ 
func permute(nums []int, ret *[][]int) {
	*ret = append(*ret, makeCopy(nums))

	n := len(nums)
	p := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		p[i] = i
	}
	for i := 1; i < n; {
		p[i]--
		j := 0
		if i%2 == 1 {
			j = p[i]
		}

		nums[i], nums[j] = nums[j], nums[i]
		*ret = append(*ret, makeCopy(nums))
		for i = 1; p[i] == 0; i++ {
			p[i] = i
		}
	}
}

//factorial int
func factorial(n int) int {
	ret := 1
	for i := 2; i <= n; i++ {
		ret *= i
	}
	return ret
}

//makeCopy []int
func makeCopy(nums []int) []int {
	return append([]int{}, nums...)
}


//SliceInt 引数サイズのSliceを返す
func SliceInt(a int) []int {

	IntSample := make([]int, a)

	return IntSample

}


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

int main()
{
    int nums;
    cin >> nums;
    set<long long> Set;
    for(int i = 0; i < nums; i++)
    {
        long long tmp;
        cin >> tmp;
        Set.insert(tmp);
    }
    
    cout << Set.size() << endl;
    return 0;
}


Measured memory_bytes: 7688
taka, aoki, num = map(int, input().split())
if taka <= num:
  num -= taka
  taka = 0
  if aoki <= num:
    aoki = 0
    print(taka, aoki)
  elif aoki > num:
    aoki -= num
    print(taka, aoki)  
if taka > num:
  taka -= num
  print(taka, aoki)


Measured memory_bytes: 9060
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
#define ll long long
#define mod 998244353

using namespace std;

int n, k, arr[110], dp[100005];

string solve()
{
	for (int i = 1; i <= k; i++)
		for (int j = 0; j < n; j++)
			if (i >= arr[j] && !dp[i - arr[j]])
				dp[i] = 1;
	if (dp[k] == 1)return "First";
	return "Second";
}

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	cout << solve() << '\n';
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define N 1001
int main()
{
  int q,i,j;
  char S1[N],S2[N];
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s",S1);
    scanf("%s",S2);
    printf("%d\n",LCS(S1,S2));
  }
  return 0;
}

int LCS(char *S1,char *S2)
{
  int c[N][N],i,j,x,y;
  x=strlen(S1)+1;
  y=strlen(S2)+1;
  for(i=1;i<x;i++)c[0][i]=0;
  for(i=0;i<y;i++)c[i][0]=0;
  
  for(i=1;i<x;i++){
    for(j=1;j<y;j++){
      if(S1[i-1]==S2[j-1])c[i][j]=c[i-1][j-1]+1;
      else if(c[i-1][j]>=c[i][j-1])c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
    }
  }
  return c[x-1][y-1];
}



Measured memory_bytes: 5776
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    long long N, K;
    cin >> N >> K;
    vector<long long> V(N);
    REP(i, N) { cin >> V[i]; }
    // print(V);
    ll ans = 0;
    REP(i, min(K + 1, N + 1)) {
        //左からi-1番目まで穫る
        REP(j, min(N + 1 - i, K + 1 - i)) {
            //右からj-1番目まで穫る
            vector<long long> tmp(i + j);
            REP(k, i) { tmp[k] = V[k]; }
            REP(l, j) { tmp[i + l] = V[N - 1 - l]; }
            int resop = K - i - j;
            if(resop > 0) {
                sort(tmp.begin(), tmp.end());
                REP(m, min(resop, (int)tmp.size())) {
                    if(tmp[m] < 0) {
                        tmp[m] = 0;
                    }
                }
            }
            ans = max(ans, (long long)accumulate(tmp.begin(), tmp.end(), 0));
            /*
            cout << "********" << endl;
            REP(i, tmp.size()) { cout << tmp[i]; }
            cout << endl;
            cout << "********" << endl;
            */
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,0,n)cin>>h[i];
    int res=0,cnt=0;
    int dir=0;
    rep(i,0,n-1){
        dir=h[i];
        if(dir >= h[i+1]){
            cnt++;
            res = max(res,cnt);
        }else{
            cnt=0;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 640
N = int(input())
abc = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * 3 for _ in range(N)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]

for i in range(1, N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dpp = dp[i - 1][j] + abc[i][k]
            dp[i][k] = max(dp[i][k], dpp)

print(max(dp[-1]))

Measured memory_bytes: 74200
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    if(a < 10 && b < 10) {
        out(a*b);
    }
    else {
        out(-1);
    }
    
    re0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class Program {
    public static void Main() {
        Dictionary <char, int> roman = new Dictionary<char, int>();
        roman['I'] = 1;
        roman['V'] = 5;
        roman['X'] = 10;
        roman['L'] = 50;
        roman['C'] = 100;
        roman['D'] = 500;
        roman['M'] = 1000;
        while (true) {
            string line = Console.ReadLine();
            if (string.IsNullOrEmpty(line)) return;
            int num = 0;
            for (int i = 0; i < line.Length-1; i++) {
                if (roman[line[i]] < roman[line[i+1]]) {
                    num -= roman[line[i]];
                } else {
                    num += roman[line[i]];
                }
            }
            num += roman[line[line.Length-1]];
            Console.WriteLine(num);
        }
    }
}

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

ll gcd(ll a, ll b) {
  ll smaller = min(a, b);
  ll bigger = max(a, b);
  ll surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  surplus = gcd(smaller, surplus);
  return surplus;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll all_gcd = a[0];
  rep(i,n){
    all_gcd = gcd(all_gcd, a[i]);
  }
  cout << all_gcd << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>


int main() {
	long long a, b;

	std::cin >> a >> b;

	std::vector<std::string> v(a);

	for (long long i = 0; i < a; i++)
	{
		std::cin >> v[i];
	}

	long long x[] = { 1, 0, -1, 0 };
	long long y[] = { 0, 1, 0 , -1};

	for (long long i = 0; i < a; i++)
	{
		for (long long j = 0; j < b; j++)
		{
			bool flag = false;
			if (v[i][j] == '#') {
				for (long long k = 0; k < 4; k++)
				{
					long long xx = i + x[k];
					long long yy = j + y[k];

					if (xx >= 0 && yy >= 0 && xx < a && yy < b) {
						if (v[xx][yy] == '#') {
							flag = true;
							break;
						}
					}
				}
				if (flag == false) {
					std::cout << "No" << std::endl;
					return 0;
				}

			}
		}
	}

	std::cout << "Yes" << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#define MAX_N 1000000000
typedef long long ll;
using namespace std;
bool cmp(const pair<ll,ll> &a, const pair<ll,ll>&b){
  if(a.first !=b.first) return a.first>b.first;
  else return a.second<b.second;
}
bool cmp2(const pair<ll,ll> &a, const pair<ll,ll>&b){
  return a.second>b.second;
}

int main(){
  long long N, H,ans=0,ind;
  vector<pair<ll, ll> > vc;
  cin>>N>>H;
  for(ll i=0; i<N;i++){
    ll a,b;
    cin>>a>>b;
    vc.push_back(pair<ll,ll>(a,b));
  }
  sort(vc.begin(), vc.end(), cmp);
  if(N>1)sort(vc.begin()+1,vc.end(),cmp2 );
  ind=1;
  while(H>0){
    ans++;
    if(H>vc[0].second){
      if(ind<N && vc[0].first<vc[ind].second){
        H-=vc[ind].second;
        ind++;
      }else{
        ans+=(H-vc[0].second-1)/vc[0].first;
        H=vc[0].second;
      }
    }else{
      H=0;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
typedef array<int, 26> arr;

void print(arr a) {
    return;
    for(auto tmp : a) cerr << tmp << " ";
    cerr << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S1, S2;
    cin >> S1 >> S2;
    for(int len = min(S1.size(), S2.size()); len >= 1; len--) {
        set<arr> st;
        arr tmp;
        for(int i = 0; i < 26; i++) tmp[i] = 0;
        for(int i = 0; i < len; i++) {
            tmp[(int)(S1[i] - 'a')]++;
        }
        st.insert(tmp);
        print(tmp);
        for(int i = len; i < S1.size(); i++) {
            tmp[(int)(S1[i] - 'a')]++;
            tmp[(int)(S1[i-len] - 'a')]--;
            st.insert(tmp);
            print(tmp);
        }
        for(int i = 0; i < 26; i++) tmp[i] = 0;
        for(int i = 0; i < len; i++) {
            tmp[(int)(S2[i] - 'a')]++;
        }
        print(tmp);
        if(st.find(tmp) != st.end()) {
            cout << len << endl;
            return 0;
        }
        for(int i = len; i < S2.size(); i++) {
            tmp[(int)(S2[i] - 'a')]++;
            tmp[(int)(S2[i-len] - 'a')]--;
            print(tmp);
            if(st.find(tmp) != st.end()) {
                cout << len << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int INF=0x3f3f3f3f;
int mode=1e9+7;
int main()
{
	int n;
	cin>>n;
	int a[200020];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	{
		if(a[i]==a[i+1])
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

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

int field[21][21];
int w, h, res;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

void dfs(int x, int y, int n) {
    if (n >= res) return;
    for (int i = 0; i < 4; i++) {
        int tx = x + dir[i][0];
        int ty = y + dir[i][1];
        
        if (tx < 0 || tx >= w || ty < 0 || ty >= h) continue;
        if (field[ty][tx] == 1) continue;
        if (field[ty][tx] == 3) { res = n; return; }
        
        while (true) {
            tx += dir[i][0];
            ty += dir[i][1];
            if (tx < 0 || tx >= w || ty < 0 || ty >= h) break;
            if (field[ty][tx] == 3) { res = n; return; }
            if (field[ty][tx] == 1) {
                field[ty][tx] = 0;
                dfs(tx - dir[i][0], ty - dir[i][1], n + 1);
                field[ty][tx] = 1;
                break;
            }
        }
    }
}

int main()
{
    int x, y;
    while (cin >> w >> h, w | h) {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> field[i][j];
                if (field[i][j] == 2) {
                    x = j;
                    y = i;
                }
            }
        }
        res = 11;
        dfs(x ,y, 1);
        cout << (res > 10 ? -1 : res) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(void)
{
	long long count = 0;
	long long max = 0;
	long long N;

	cin >> N;

	vector<long long> H(N);

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

	for (int i = 0; i < N; i++)
	{
		count = 0;
		for (int j = 1; j < N - i; j++)
		{
			if (H[i + j - 1] >= H[i + j])
			{
				count++;
			}
			else
			{
				break;
			}
		}

		if (count > max)
		{
			max = count;
		}
		if (N - i < max)
		{
			break;
		}
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
#define pb push_back

typedef long long ll;
using namespace std;
int MOD = 1000000007;
int N, C, K, l = 0, bc = 0, mc = 0, t;
int T[100000];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> C >> K;
  FOR(i, 0, N){
    cin >> T[i];
  }
  sort(T, T + N);
  FOR(i, 0, N){
    t = T[i];
    if((t > l) || (mc == C)){
      bc++;
      l = t + K;
      mc = 0;
    }
    mc++;
  }
  cout << bc << endl;
}


Measured memory_bytes: 640
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7
import heapq

def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
ab = []
for i in range(n):
    a,b = inm()
    ab.append((a,b))
ab.sort(reverse=True)
h = []
sm = 0
for d in range(m-1,-1,-1):
    while len(ab)>0 and ab[-1][0]<=m-d:
        ab2 = ab.pop()
        heapq.heappush(h, -ab2[1])
    if len(h)>0:
        sm -= heapq.heappop(h)
print(sm)


Measured memory_bytes: 69848
package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n+1)
	b := make([]int, n)
	for i := 0; i < n+1; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&b[i])
	}
	ans := 0
	for i := 0; i < n; i++ {
		l := min(a[i], b[i])
		ans += l
		a[i] -= l
		b[i] -= l
		r := min(b[i], a[i+1])
		ans += r
		b[i] -= r
		a[i+1] -= r
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7464
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

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

int main()
{
    string s;
    cin >> s;

    if (s == "SUN") {
        cout << 7 << endl;
    } else if (s == "MON") {
        cout << 6 << endl;
    } else if (s == "TUE") {
        cout << 5 << endl;
    } else if (s == "WED") {
        cout << 4 << endl;
    } else if (s == "THU") {
        cout << 3 << endl;
    } else if (s == "FRI") {
        cout << 2 << endl;
    } else {
        cout << 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def popcount(num):
    cnt = 0
    while num > 0:
        num %= bin(num).count('1')
        cnt += 1
    return cnt

def Main():
    n = read_int()
    x = read_str()
    x_int = int(x, 2)

    cnt = x.count('1')
    minus_cnt = cnt - 1
    plus_cnt = cnt + 1
    
    minus_mod = x_int % minus_cnt if minus_cnt != 0 else 0
    plus_mod = x_int % plus_cnt

    for i in range(n):
        if x[i] == '0':
            print(popcount((plus_mod + pow(2, n - 1 - i, plus_cnt)) % plus_cnt) + 1)
        elif minus_cnt != 0:
            print(popcount((minus_mod - pow(2, n - 1 - i, minus_cnt)) % minus_cnt) + 1)
        else:
            print(0)

if __name__ == '__main__':
    Main()

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

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h, vector<char>(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char inp;
            cin >> inp;
            c[i][j] = inp;
        }
    }

    int rtn = 0;

    for (int biti = 0; biti < (1 << h); ++biti) {
        for (int bitj = 0; bitj < (1 << w); ++bitj) {
            int cnt = 0;

            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    if (biti & 1 << i) continue;
                    if (bitj & 1 << j) continue;
                    if (c[i][j] == '#') cnt++;
                }
            }
            if (cnt == k) rtn++;
        }
    }
    cout << rtn << endl;
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N=26;
	int D;
	cin >>D;
	vector<int> c(N+1, 0);
	Rep1(i, N)
		cin >>c.at(i);
	vector<vector<int>> s(D+1, vector<int> (N+1, 0));
	Rep1(i, D)
		Rep1(j, N)
			cin >>s.at(i).at(j);
	vector<int> t(D+1);
	Rep1(i, D)
		cin >>t.at(i);
	//
	vector<vector<int>> LAST(D+1, vector<int> (N+1, 0));
	int S=0;
	vector<vector<int>> SS(D+1, vector<int> (N+1, 0));
	Rep1(i, D) {
		Rep1(j, N) {
			if (j==t.at(i)) {
				LAST.at(i).at(j)=0;
				SS.at(i).at(j)=SS.at(i-1).at(j)+s.at(i).at(j);
				S +=s.at(i).at(j);
			} else {
				LAST.at(i).at(j) =LAST.at(i-1).at(j)+c.at(j);
				SS.at(i).at(j)=SS.at(i-1).at(j)-LAST.at(i).at(j);
			}
			S -=LAST.at(i).at(j);
		}
		//cout <<S <<endl;
	}
	//
	int M;
	cin >>M;
	Rep1(i, M) {
		int d, q;
		cin >>d >>q;
		int q0=t.at(d);
		S -=SS.at(D).at(q0)+SS.at(D).at(q);
		t.at(d)=q;
		for (auto j=d; j<=D; j++) {
			int SSS=0;
			if (q0==t.at(j)) {
				LAST.at(j).at(q0)=0;
				SSS=SS.at(j-1).at(q0)+s.at(j).at(q0);
			} else {
				LAST.at(j).at(q0)=LAST.at(j-1).at(q0)+c.at(q0);
				SSS=SS.at(j-1).at(q0)-LAST.at(j).at(q0);
			}
			if (SSS==SS.at(j).at(q0))
				break;
			else
				SS.at(j).at(q0)=SSS;
		}
		for (auto j=d; j<=D; j++) {
			int SSS=0;
			if (q==t.at(j)) {
				LAST.at(j).at(q)=0;
				SSS=SS.at(j-1).at(q)+s.at(j).at(q);
			} else {
				LAST.at(j).at(q)=LAST.at(j-1).at(q)+c.at(q);
				SSS=SS.at(j-1).at(q)-LAST.at(j).at(q);
			}
			if (SSS==SS.at(j).at(q))
				break;
			else
				SS.at(j).at(q)=SSS;
		}
		S +=SS.at(D).at(q0)+SS.at(D).at(q);
		cout <<S <<endl;
	}
	return 0;
}



Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	int N;
	cin >> N;
	vector<pll> XL(N);
	rep(i, N) {
		cin >> XL[i].first >> XL[i].second;
		XL[i].first -= XL[i].second;
	}
	int ans = 0;
	sort(XL.begin(), XL.end(), less<pll>());
	int Rnext = -Inf;
	rep(i, N) {
		int Ltmp = XL[i].first;
		int Rtmp = XL[i].first + XL[i].second * 2;
		if (Ltmp >= Rnext) {
			ans++;
			Rnext = Rtmp;
		}
		Rnext = min(Rnext, Rtmp);

	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
n, k = map(int, input().split())
res = 0
cnt = [0] * (k + 1)
M = int(1e9) + 7

def pow(b, e, m):
    res = 1
    while e:
        if e & 1: res = res * b % m
        e >>= 1
        b = b * b % m
    return res

for i in reversed(range(1, k + 1)):
    t = k // i
    cnt[i] = pow(t, n, M)
    for j in range(i + i, k + 1, i):
        cnt[i] -= cnt[j]

    res = (res + cnt[i] * i) % M

print(res)

Measured memory_bytes: 69512
#!/usr/bin/env python3

M, N = map(int, input().split())

ans=0

if M<=1:
    if N<=1:
        ans = 0
    else:
        ans = N*(N-1)/2
elif N<=1:
    ans = M*(M-1)/2

if M>1 and N>1:
    ans = M*(M-1)/2 + N * (N-1)/2

print(int(ans))


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

int main() {
	int k, even, odd;
	cin >> k;
	even = k/2;
	if(k % 2 == 1){
		odd = (k+1)/2;
	}
	else{
		odd = k/2;
	}
	
	cout << even*odd << endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
set_list = [input().split() for _ in range(N)]
X = input()
ans = 0
flg = False

for i in range(N):
  if flg == True:
    ans += int(set_list[i][1])
  if set_list[i][0] == X:
    flg = True
    
print(ans)

Measured memory_bytes: 3060
import sys
import math
from collections import defaultdict

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))

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

def fact(a,M=mod):
    ans = 1
    for i in range(2,a+1):
        ans = (ans*i)%M
    return ans

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

def mod_inv(a,M=mod):
    x = extgcd(a,M)[0]
    return (M+x%M)%M

N = I()
x = LI()

nfact = fact(N-1)
pn = nfact
cumpn = nfact
ans = nfact*(x[1]-x[0])
for i in range(1,N-1):
    pn -= nfact*mod_inv(i)*mod_inv(i+1)
    pn %= mod
    cumpn += pn
    ans += cumpn*(x[i+1]-x[i])
    ans %= mod

print(ans)

Measured memory_bytes: 62704
import sys

sys.setrecursionlimit(100000000)


def dfs(g: {}, v: int, seen: [], current_color: int):
    seen[v] = current_color
    for next_v in g[v]:
        # next_v が探索済だったらスルー
        if seen[next_v] != -1:
            if current_color == seen[next_v]:
                return False
            continue
        seen[next_v] = 1-current_color
        # 再帰的に探索
        if not dfs(g, next_v, seen, 1 - current_color):
            return False
    return True


def main():
    n, m = map(int, input().split())

    g = {}
    for i in range(m):
        a, b = map(int, input().split())
        dic_a = g.setdefault(a-1, [])
        dic_a.append(b-1)
        dic_b = g.setdefault(b-1, [])
        dic_b.append(a-1)
    # -1:not clear, 0:white, 1:black
    seen = [-1] * n

    is_bipartite = True
    for i in range(n):
        if seen[i] != -1:
            continue
        if not dfs(g, 0, seen, 0):
            is_bipartite = False
            break

    if is_bipartite:
        white = len([x for x in seen if x == 0])
        black = n - white

        print(black*white - m)
    else:
        print(int((n-1)*n / 2) - m)

main()


Measured memory_bytes: 37148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,Mh=0;
    ll Mx,My;
    cin >> N;
    vector<ll> x(N),y(N),h(N);
    rep(i,N){
        cin >> x[i] >> y[i] >> h[i];
        cmax(Mh,h[i]);
        if(h[i] == Mh){
            Mx = x[i];
            My = y[i];
        }
    }
    rep(X,101){
        rep(Y,101){
            ll H = Mh + abs(X-Mx) + abs(Y-My);
            bool flag = true;
            rep(i,N){
                if(h[i] != max(H-abs(X-x[i])-abs(Y-y[i]), 0LL)){
                    flag = false;
                    break;
                }
            }
            if(flag){
                cout << X << " " << Y << " " << H << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include<vector>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <climits>
#define ll long long
#define ull unsigned long long
#define mod 1000000007

using namespace std;

vector<int> sieve(ll n)
{
	vector<int> a(n+1,0);
	for(ll i=3;i<=n;i+=2)
	a[i]=1;
	for(ll i=3;i<=n;i+=2)
	{
       if(a[i]==1)
	   {
		   for(ll j=i*2;j<=n;j+=i)
		   a[j]=0;
	   }
	}
	a[2]=1;
	a[1]=a[0]=0;
	return a;
}
ll reverse(ll n)
{
	ll s=0;
	while(n>0)
	{
       ll t=n%10;
	   s=s*10+t;
	   n/=10;
	}
	return s;
}
int count_setbits(int N)

{ int cnt=0;

while(N>0)

{

cnt+=(N&1);

N=N>>1;

}

return cnt;

}
ll power(ll x, ll y)  
{  
    int res = 1;     // Initialize result  
  
    x = x % mod; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % mod;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % mod;  
    }  
    return res;  
}  

void BellmanFord(vector< vector<ll> > &graph, int V, int E, int src) 
{ 
    // Initialize distance of all vertices as infinite. 
    int dis[V]; 
    for (int i = 0; i < V; i++) 
        dis[i] = INT_MAX; 
  
    // initialize distance of source as 0 
    dis[src] = 0; 
  
    // Relax all edges |V| - 1 times. A simple 
    // shortest path from src to any other 
    // vertex can have at-most |V| - 1 edges 
    for (int i = 0; i < V - 1; i++) { 
  
        for (int j = 0; j < E; j++) { 
            if (dis[graph[j][0]] + graph[j][2] < 
                               dis[graph[j][1]]) 
                dis[graph[j][1]] =  
                  dis[graph[j][0]] + graph[j][2]; 
        } 
    } 
  
    // check for negative-weight cycles. 
    // The above step guarantees shortest 
    // distances if graph doesn't contain 
    // negative weight cycle.  If we get a 
    // shorter path, then there is a cycle. 
    for (int i = 0; i < E; i++) { 
        int x = graph[i][0]; 
        int y = graph[i][1]; 
        int weight = graph[i][2]; 
        if (dis[x] != INT_MAX && 
                   dis[x] + weight < dis[y]) 
            cout << "Graph contains negative"
                    " weight cycle"
                 << endl; 
    } 
  
    
} 

ll find_binary_rotated(vector<ll> &a,ll key)
{
 ll start=0;ll end=a.size()-1;
 while(start<=end)
 {
	 ll mid=(start+end)/2;
	 if(key==a[mid])
	 return mid;
	 else if(a[start]<=a[mid])
	 {
		 if(key>=a[start] && key<=a[mid])
		 end=mid-1;
		 else
		 {
			 start=mid+1;
		 }
		 
	 }
	 else
	 {
		 if(key>=a[mid] && key<=a[end])
		 start=mid+1;
		 else
		 {
			 end=mid-1;
		 }
		 
	 }
	 
 }
 return -1;
}



int main()
{
	
		ll a,b;
		cin>>a>>b;
		cout<<a*b<<"\n";

		

	


		

		
		
		

		
		
	
	
	


	
	
}

Measured memory_bytes: 3628
import qualified Data.Vector as V
import Data.List
import Data.Maybe
import qualified Data.ByteString.Lazy.Char8 as B

data RecItem = RecItem {
    riStart :: Int
  , riEnd :: Int
  , riChannel :: Int
  } deriving (Show)

data EventType = ETStart | ETEnd deriving (Eq, Ord)

data Event = Event {
    evTime :: Int
  , evType :: EventType
} deriving (Eq, Ord)

calc :: [RecItem] -> Int -> Int
calc ris numC =
  countPara $ sort $ concat [eventList ris c | c <- [1 .. numC]]

eventList :: [RecItem] -> Int -> [Event]
eventList ris c = 
  concat [[Event s ETStart, Event e ETEnd] |
          RecItem s e _ <- paste $ sortOn riStart $ filter ffilt ris]
  where 
    ffilt (RecItem s e c') = c == c'
    paste ris = foldr bin [] ris
    bin ri [] = [ri]
    bin ri1 (ri2:ris)
      | riEnd ri1 == riStart ri2 = RecItem (riStart ri1) (riEnd ri2) (riChannel ri2) : ris
      | otherwise                = ri1 : ri2 : ris

countPara :: [Event] -> Int
countPara evs = f 0 0 evs
  where f cur vMax [] = vMax
        f cur vMax ((Event t ETStart) : evs) = f (cur + 1) vMax' evs
          where vMax' = if cur == vMax then vMax + 1 else vMax
        f cur vMax ((Event t ETEnd)   : evs) = f (cur - 1) vMax evs

myReadInt :: B.ByteString -> Int
myReadInt = fst . fromJust . B.readInt

line2RecItem :: B.ByteString -> RecItem
line2RecItem aLine = let [s, e, c] = map myReadInt (B.words aLine)
                     in RecItem s e c

main :: IO ()
main = do
  all <- B.getContents
  let (h:rest) = B.lines all
      [_, numC] = [myReadInt w | w <- B.words h]
      ris = map line2RecItem rest
  putStrLn $ show $ calc ris numC



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

ll fact(ll n){
  if(n<=1) return 1;
  else return n*fact(n-1)%mod;
}

int main(){
  int n,m;
  ll ans;
  cin>>n>>m;
  if(abs(n-m)==0)
    ans=fact(n)*fact(m)*2;
  else if(abs(n-m)<=1)
    ans=fact(n)*fact(m);
  else
    ans=0;
  cout<<(ans%mod)<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "queue"

using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  string a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    char x = a.at(i);
    char y = b.at(i);
    char z = c.at(i);
    if (x != y && y != z && z != x)
    {
      ans += 2;
    }
    else
    if ((x == y && x != z) || (y == z && y != x) || (z == x && z != y))
    {
      ans++;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X, N, ans = 0;
    cin >> X >> N;
    vector<int> pi(N);
    for (int i=0; i<N; i++){
        cin >> pi.at(i);
    }
    sort(pi.begin(), pi.end());
    for (int j=0; j<100; j++){
        int count1 = 0, count2 = 0;
        for (int i=0; i<N; i++){
            if (pi.at(i) != X - j){
                count1 += 1;
            }
            if (pi.at(i) != X + j){
                count2 += 1;
            }
        }if (count1 == N) {
            ans = X-j;
            break;
        }else if (count2 == N){
            ans = X + j;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;

    REP(i, 1, N + 1)
    {
        int tmpSum = 0;

        for(auto c : to_string(i))
        {
            tmpSum += c - '0';    
        }

        ans += (A <= tmpSum && tmpSum <= B ? i : 0);
    }

    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 256