akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, dead_code, unused_variables, unused_mut)]
use num::abs;
use num::integer::gcd;
use permutohedron::LexicalPermutation;
use proconio::{fastout, input, marker::*};
use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;
use text_io::{read, scan};
const INF: i32 = std::i32::MAX;
const MOD: i32 = 1e9 as i32 + 7;
const Yes: &str = "Yes";
const No: &str = "No";
static dx: [i32; 4] = [1, 0, -1, 0];
static dy: [i32; 4] = [0, -1, 0, 1];

#[derive(Debug)]
struct UnionFind {
    data: Vec<usize>,
    rank: Vec<usize>,
}

// https://pyteyon.hatenablog.com/entry/2019/03/11/200000
impl UnionFind {
    /// return UnionFind  
    /// data was inited by i  
    /// rank was inited by 1
    fn new(n: usize) -> UnionFind {
        UnionFind {
            data: (0..n).map(|i| i).collect::<Vec<usize>>(),
            rank: (0..n).map(|_| 1).collect::<Vec<usize>>(),
        }
    }

    /// return root of x
    fn root(&mut self, x: usize) -> usize {
        if self.data[x] == x {
            return x;
        }
        self.data[x] = self.root(self.data[x]);
        self.data[x]
    }

    /// unite x and y
    fn unite(&mut self, x: usize, y: usize) {
        let mut root_x = self.root(x);
        let mut root_y = self.root(y);

        if root_x == root_y {
            return;
        }

        if self.rank[root_x] < self.rank[root_y] {
            swap(&mut root_x, &mut root_y);
        }
        self.rank[root_x] += self.rank[root_y];
        self.data[root_y] = root_x;
    }

    /// check if x and y belong to same root
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }

    /// check size of tree x belongs to
    fn rank(&mut self, x: usize) -> usize {
        let root_x = self.root(x);
        self.rank[root_x]
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(i32, i32); m],
    }

    let mut uf = UnionFind::new(n);
    for elem in &ab {
        uf.unite(elem.0 as usize - 1, elem.1 as usize - 1);
    }

    let mut ans = 0;
    let mut min = INF as usize;
    for i in 0..n {
        min = cmp::min(min, uf.root(i));
    }

    for i in 0..n {
        if uf.root(i) == min {
            continue;
        }
        if uf.root(i) == i {
            ans += 1;
        }
    }

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


Measured memory_bytes: 5484
#include <bits/stdc++.h>
using LL = long long;

int main() {
  std::ios::sync_with_stdio(0);
  std::vector<LL> stack;
  int n, m;
  std::cin >> n >> m;
  stack.emplace_back(n);
  for (int i = 0; i < m; i++) {
    LL x;
    std::cin >> x;
    while (stack.size() && stack.back() >= x) stack.pop_back();
    stack.emplace_back(x);
  }
  std::map<LL, LL> positions;
  positions.insert({stack.back(), 1});
  while (stack.size()) {
    LL position = stack.back(); stack.pop_back();
    auto pos = positions.upper_bound(position);
    for(auto itr = pos; itr != positions.end(); itr++) {
      LL x, y;
      std::tie(x, y) = *itr;
      LL k = x / position, b = x % position;
      positions[position] += y * k;
      positions[b] += y;
    }
    positions.erase(pos, positions.end());
  }
  LL now = 0;
  std::vector<LL> answer(n, 0);
  for (int i = n; i >= 1; i--) {
    now += positions[i];
    answer[i - 1] = now;
  }
  for (auto x: answer) {
    std::cout << x << std::endl;
  }
  std::cout << std::endl;
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}
int T[2],A[2],B[2];

signed main(){
    rep(i,2)cin>>T[i];
    rep(i,2)cin>>A[i];
    rep(i,2)cin>>B[i];

    if(A[0]<B[0]){
        rep(i,2)swap(A[i],B[i]);
    }

    if(A[0]*T[0]+A[1]*T[1]>B[0]*T[0]+B[1]*T[1]){
        cout<<0<<endl;
        return 0;
    }

    if(A[0]*T[0]+A[1]*T[1]==B[0]*T[0]+B[1]*T[1]){
        cout<<"infinity"<<endl;
        return 0;
    }

    int X=A[0]*T[0]+A[1]*T[1];
    int Y=B[0]*T[0]+B[1]*T[1];

    int ans=((A[0]-B[0])*T[0]+Y-X-1)/(Y-X)-1;
    ans*=2;
    if((A[0]-B[0])*T[0]%(Y-X)==0)ans++;
    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)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void dfs(int i, int n, vector<int> r, vector<vector<int>>* res) {
  if (r[n - 1] > 0) {
    res->push_back(r);
    return;
  }
  for (int j = 1; j <= n; j++) {
    bool con = false;
    for (int k = 0; k <= i; k++) {
      if (r[k] == j) {
        con = true;
        continue;
      }
    }
    if (con) continue;
    r[i] = j;
    dfs(i + 1, n, r, res);
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  int a, b;
  vector<int> r(n, 0);
  vector<vector<int>> res;
  dfs(0, n, r, &res);
  rep(i, res.size()) {
    if (p == res[i]) a = i;
    if (q == res[i]) b = i;
  }
  int ans = a > b ? a - b : b - a;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    string s;
    cin >> s;
    ll cntb = 0, sum_index = 0;
    rep(i, 0, (ll)s.size()) {
        if (s[i] == 'B') cntb++, sum_index += i;
    }
    cout << s.size()*cntb - cntb*(cntb+1)/2 - sum_index << endl;
}

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

int h, w;
char field[110][110];
bool j = true;

int dfs(int p, int q, char c) {
	field[p][q] = 'a';
	int dx[4] = { 0, 0, 1, -1 };
	int dy[4] = { 1, -1, 0, 0 };
	for (int i = 0; i < 4; i++) {
		int nx = p + dx[i];
		int ny = q + dy[i];
		if (0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] == c) {
			dfs(nx, ny, c);
		}
	}
	return 0;
}

int main() {
	while (j) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			return 0;
			j = false;
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> field[i][j];
			}
		}
		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (field[i][j] != 'a') {
					dfs(i, j, field[i][j]);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 4196
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main(){
    int n;
    cin >> n;
    set<int> st;
    rep(i, n){
        int a;
        cin >> a;
        st.insert(a);
    }
    int ans;
    if((n - st.size()) % 2 == 1)
        ans = st.size() - 1;
    else
        ans = st.size();
    cout << ans << ln;  
}


Measured memory_bytes: 4992
from bisect import bisect_left

n = int(input())

l_list = [int(x) for x in input().split()]
l_list.sort()
# print(l_list)

ans = 0
for i in range(n - 2):
    continue_flag = False
    for j in range(i + 1, n - 1):
        ans += bisect_left(l_list, l_list[j] + l_list[i]) - (j + 1)
print(ans)

Measured memory_bytes: 3188
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength

#素因数分解
def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a

#重複を検出
def has_duplicates(seq):
  return len(seq) != len(set(seq))



#X = str(input()).split()
#a = [int(x) for x in input().split()]


NK = str(input()).split()
N = int(NK[0])
K = int(NK[1])
p = [int(x) for x in input().split()]

M = 0
ans = 0

for i in range(K):
  M+= p[i]

ans = M
ans2 = 0
ans3 = 0
ans4 = 0

for i in range(K, N):
  M = M-p[i-K]+p[i]
  if(ans < M):
    ans2 = i-K+1
    ans = M

for i in range(ans2,ans2+K):
  for j in range(p[i]+1):
    ans3 += j
    #print(ans3)
  ans4 += float(ans3/p[i])
  ans3 = 0


print(ans4)



Measured memory_bytes: 71500
#include <stdio.h>
#include <math.h>
typedef long long ll;
double pita(int a,int b,int c,int d)
{
    int x=a-c;
    int y=b-d;
    return sqrt(x*x+y*y);
}

int main()
{
    int n;
    scanf("%d",&n);
    int x[n];
    int y[n];
    double sum;
    for(int i=0;i<n;i++){
        scanf("%d %d",&x[i],&y[i]);
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            sum += pita(x[i],y[i],x[j],y[j]);
        }
    }
    int c = n*(n-1);
    c/=2;
    printf("%.10f",(sum*(n-1))/c);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() { 
    
    int a, b, c;
    cin >> a >> b >> c;
    int abc = a + b + c;
    int max_abc = max(a, max(b, c)) * 3;
    if ((max_abc - abc) % 2 == 0) {
        cout << (max_abc - abc) / 2 << endl;
    } else {
        cout << (max_abc - abc + 3) / 2 << endl;
    }
}




Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define int long long
#define m_k make_pair
using namespace std;
const int N=2*1e5+100;
int n,a[N],b[N],vi[N],ans;
priority_queue <pair<int,int> > q;
inline int pre(int x){return((x==1)?n:x-1);}
inline int suc(int x){return((x==n)?1:x+1);}
inline bool check(int x){return(b[x]>=b[pre(x)]+b[suc(x)]&&b[x]>a[x]);}
signed main()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++) scanf("%lld",&b[i]);
	bool bl=1;
	for (int i=1;i<=n;i++) if (b[i]<a[i]) bl=0;
	if (!bl)
	{
		printf("-1\n");
		return 0;
	}
	for (int i=1;i<=n;i++)
	{
		if (check(i))
		{
			vi[i]=1;
			q.push(m_k(b[i],i));
		}
	}
	bl=1;
	while (!q.empty())
	{
		int x=q.top().second;
		q.pop();
		vi[x]=0;
		int delta=b[x]-a[x];
		delta/=b[pre(x)]+b[suc(x)];
		ans+=delta;
		b[x]-=(b[pre(x)]+b[suc(x)])*delta;
		if (delta==0)
		{
			bl=0;
			break;
		}
		if (check(pre(x)) && !vi[pre(x)]) vi[pre(x)]=1,q.push(m_k(b[pre(x)],pre(x)));
		if (check(suc(x)) && !vi[suc(x)]) vi[suc(x)]=1,q.push(m_k(b[suc(x)],suc(x)));
	}
	if (!bl)
	{
		printf("-1\n");
		return 0;
	}
	for (int i=1;i<=n;i++) if (a[i]!=b[i]) bl=0;
	if (!bl)
	{
		printf("-1\n");
		return 0;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 10056
#include <iostream>
using namespace std;
 
int main(){
  int K,S;
   cin >> K;
   cin >> S;
  int ans = 0;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      if(S-i-j<=K && (S-i-j>=0))
	   ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const long double pi = acosl(-1.0);
int main() {
    long double A, B, H, M; cin >> A >> B >> H >> M;
    long double h = 30 * H + M / 2.0;
    long double m = M * 6;
    long double diff = min(abs(h - m), 360 - abs(h - m));
    diff *= pi / 180;
    cout << fixed << setprecision(20) << sqrt(A * A + B * B - 2 * A * B * cos(diff)) << '\n';
}

Measured memory_bytes: 4156
#include<bits/stdc++.h>
using namespace std;
int put_number(int number,int add, int times,int dp);
int n,th=0,fi=0,se=0,depth,x;

int main(void){
    int count=0;
    int top;
    cin >> n;
    depth=0;
    x=n;
    while(n!=0){
        depth++;
        n/=10;
    }
    for(int i=1;i<depth;i++){
        th=1;
        count+=put_number(0,3,1,i);
        th=0;
        fi=1;
        count+=put_number(0,5,1,i);
        fi=0;
        se=1;
        count+=put_number(0,7,1,i);
        se=0;
    }
//    cout << "end" << endl;
    top=x/(pow(10,depth-1));
//    cout << top << endl;
    if(top>=7){
        th=1;
        count+=put_number(0,3,1,depth);
        th=0;
        fi=1;
        count+=put_number(0,5,1,depth);
        fi=0;
        se=1;
        count+=put_number(0,7,1,depth);
        se=0;
    }else if(top>=5){
        th=1;
        count+=put_number(0,3,1,depth);
        th=0;
        fi=1;
        count+=put_number(0,5,1,depth);
        fi=0;
    }else if(top>=3){
        th=1;
        count+=put_number(0,3,1,depth);
        th=0;
    }
    cout << count << endl;

    return 0;
}

int put_number(int number,int add, int times,int dp){
    int c=0;
    int tmp;
    //cout << "th fi se dp" << th << fi << se <<  dp <<endl;
        number=number*10+add;
    if(times==dp){
        if(th==1 && fi==1 && se==1 && number <=x){
//            cout << "number is " << number << endl;
            return 1;
        }else{
//            cout << "return " << endl;
            return 0;
        }
    }
        tmp=th;
        th=1;
        c+=put_number(number,3,times+1,dp);
        th=tmp;
        tmp=fi;
        fi=1;
        c+=put_number(number,5,times+1,dp);
        fi=tmp;
        tmp=se;
        se=1;
        c+=put_number(number,7,times+1,dp);
        se=tmp;
    return c; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[100],b[100];
int main(){
    cin>>a>>b;
    for(int i=0;i<max(strlen(a),strlen(b));i++){
        if(a[i]!='\0')cout<<a[i];
        if(b[i]!='\0')cout<<b[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class Program {
    static void Main( string[] args )
    {
        while ( true ) {
            string[] input = Console.ReadLine().Split();

            int h = int.Parse( input[ 0 ] );
            int w = int.Parse( input[ 1 ] );

            if ( 0 == h + w ) {
                break;
            }

            string s = new string( '#', w );

            for ( int i = 0; i < h; ++i ) {
                Console.WriteLine( s );
            }

            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 8812
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int m;
int ans = 0;

int main(){
	ii a[100005];
	cin>> n >> m;
	form(i,m) {
		int k, l;
		cin >> k >> l;
		if (k-->l--)swap(k,l);
		a[i].first = k; a[i].second = l;
	}
	sort(a,a+m);
	int l, r;
	l = 0;
	r = m;
	for (int i = 0; i < m; i++) {
		int f, s;
		f = a[i].first;
		s = a[i].second;
		if (f >= r) {
			ans++;
			l = f;
			r = s;
		}
		else {
			l = f;
			if (s < r)r = s;
		}
	}
	ans++;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
t = S()
if s == t[:-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 68400
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b)
    {
        for(int i=1;i<a;i++)
        {
            printf("%d",b);
        }
        printf("%d\n",b);
    }
    else if(a<b)
    {
        for(int i=1;i<b;i++)
        {
            printf("%d",a);
        }
        printf("%d\n",a);
    }
    else
    {
        for(int i=1;i<b;i++)
        {
            printf("%d",a);
        }
        printf("%d\n",a);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
const ll M = 1e9+7;
const ll inf = 1e18+5;
using namespace std;
#define debug() for(ll l=0;l<50;l++){}
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
double power(ll x,ll y,ll p){
	ll res = 1;
	x = x % p;
	if(x == 0) return 0;
	while (y > 0){
		if (y & 1) res = (res*x) % p;
		y = y>>1;
		x = (x*x) % p;
		}
	return res;
}

void solve(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max({b*d,a*c,a*d,b*c})<<"\n";
	//else if(a<=0 && c<=0 && b<=0 && d<=0) cout<<a*c<<"\n";
	//else cout<<max(a*d,b*c)<<"\n";
}

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


Measured memory_bytes: 3656
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int [] input = new int[n];
		for (int i = 0; i < n; i++) {
			input[i] = sc.nextInt();
		}
		sc.close();
		
		selectionSort(input, n);

	}

	private static void selectionSort(int[] A, int n) {

		int count = 0;
		for (int i = 0; i < n; i++) {
			int minj = i;
			for (int j = i; j < n; j++) {
				if(A[j] < A[minj]) minj = j;
			}
			
			if(minj != i) {
				int wk = A[i];
				A[i] = A[minj];
				A[minj] = wk;
				count++;
			}
		}

		show(A, " ");
		System.out.println(count);
		
	}

	private static void show(int[] a, String joiner) {

		String line = Arrays.stream(a)
				.mapToObj(String::valueOf)
				.collect(Collectors.joining(joiner));
		
		System.out.println(line);
		
	}
}

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

const int MAXN = 2222;

int n;
int ans[MAXN][MAXN];
int num[2*MAXN], col[2*MAXN];
int positionw[MAXN], positionb[MAXN];

struct Fen{
    int n;
    vector<int> v;
    Fen(int m){
        n = m;
        v.resize(n+1);
        reset();
    }
    void reset(){
        for(int i=0; i<=n; i++) v[i] = 0;
    }
    int getSum(int x){
        if(x == 0) return 0;
        //~ cerr << "gwt " << x << endl;
        int ans = 0;
        for(; x > 0; x -= x & -x) ans += v[x];
        //~ cerr << " -> " << ans << endl;
        return ans;
    }
    void upd(int x){
        //~ cerr << "upd " << x << endl;
        for(; x <= n; x += x & -x) v[x]++;
    }
};

int main(){
    cin >> n;
    for(int i=1; i<=2*n; i++){
        char c; cin >> c;
        if(c == 'B') col[i] = 1;
        else col[i] = 0;
        cin >> num[i];
        
        if(c == 'B') positionb[num[i]] = i;
        else positionw[num[i]] = i;
    }
    
    Fen fw(2*n);
    Fen fb(2*n);
    
    ans[n][n] = 0;
    for(int w=n; w>=0; w--){
        
        fb.reset();
        for(int b=n; b>=0; b--){
            if(w < n or b < n){
                int ans1 = MAXN*MAXN, ans2 = MAXN*MAXN;
                if(w < n) ans1 = fw.getSum(positionw[w+1]-1) + fb.getSum(positionw[w+1]-1) + ans[w+1][b];
                if(b < n) ans2 = fw.getSum(positionb[b+1]-1) + fb.getSum(positionb[b+1]-1) + ans[w][b+1];
                //~ cerr << w << ' ' << b << "  --> " << ans1 << ' ' << ans2 << endl;
                ans[w][b] = min(ans1, ans2);
            }
            if(b > 0) fb.upd(positionb[b]);
        }
        if(w > 0) fw.upd(positionw[w]);
    }
    
    cout << ans[0][0] << '\n';
    return 0;
}


Measured memory_bytes: 18688
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<int, int> ki;
	int cnt = 0;
	rep(i,n){
		int a;
		cin >> a;
		a /= 400;
		if(a >= 8) cnt++;
		else ki[a]++;
	}
	int ans = ki.size();
	if(ans == 0 && cnt > 0) cout << 1 << " " << cnt << endl;
	else cout << ans << " " << ans + cnt << endl;
	return 0;
}

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

#define ll long long
#define ar array

void solve(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll res = n / (a + b) * a;
    ll rem = n % (a + b);
    res += rem < a ? rem : a;
    cout << res << endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int testCases;
    testCases = 1;
    while(testCases --){
        solve();
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=1; i<=(n); i++)
typedef long long ll;
using namespace std;
int H;
int A[2000000];

//iは１～Hのインデックス番号
void maxHeapify(int i){
    int left,right,big;//最初はbig=最初のインデックス番号、最終的にbig=自分、左の子、右の子の中で最も大きい値をもつインデックス番号に変わる
    //つまり、最終的なbigにはより小さい値に変化する、故にさらにmaxHeapifyをする再帰型にする必要がある！
    left=2*i;
    right=2*i+1;
    
    if(left<=H && A[left]>A[i]) big=left;
    else big=i;
    if(right<=H && A[right]>A[big]) big=right;
    
    if(big!=i){
        swap(A[big],A[i]);
        maxHeapify(big);
    }
}


int main(){
    cin >> H;
    rep(i,H) cin >> A[i];
    
    for (int i=H/2; i>=1; i--) maxHeapify(i);
    rep(i,H) cout << " " << A[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 4944
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long ans=0;
  cin>>N;
  vector<int>S(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  for(int i=0;i<N-1;i++){
    if(S[i]>S[i+1]){
      ans+=S[i]-S[i+1];
      S[i+1]=S[i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4036
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  int ans=1;
  for(int i=0;i<N;i++){
    if(ans<K) ans*=2;
    else if(ans>=K) ans+=K;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
## クソみたいな漸化式をクソみたいなコードで書いてしまった

def ABC122D_sum():
  return ACT_A[-1]+G_A[-1]+A_G[-1]+GCT_G_G[-1]+A_G_G[-1]+C_G[-1]+A_T_G[-1]+GCT_T_G[-1]+A_C[-1]+GCT_C[-1]+A_T[-1]+A_G_T[-1]+GCT_G_T[-1]+CT_T[-1]

N = int(input())

mod = int(1e9+7)

## N=3の場合で初項を作る
ACT_A = [4*3*1]
G_A = [4*1*1]
A_G = [4*1*1]
GCT_G_G = [3*1*1]
A_G_G = [1*1*1]
C_G = [3*1*1]
A_T_G = [1*1*1]
GCT_T_G = [3*1*1]
A_C = [3*1*1]
GCT_C = [4*2*1+3*1*1]
A_T = [4*1*1]
A_G_T = [1*1*1]
GCT_G_T = [3*1*1]
CT_T = [4*2*1]
#print(ABC122D_sum())

if N == 3:
  print(ABC122D_sum())
  exit()

for i in range(N-3):
  new_ACT_A = ACT_A[-1]+G_A[-1]+A_C[-1]+GCT_C[-1]+A_T[-1]+A_G_T[-1]+GCT_G_T[-1]+CT_T[-1]
  new_G_A = A_G[-1]+GCT_G_G[-1]+A_G_G[-1]+C_G[-1]+A_T_G[-1]+GCT_T_G[-1]
  new_A_G = ACT_A[-1]+G_A[-1]
  new_GCT_G_G = GCT_G_G[-1]+A_G_G[-1]+C_G[-1]+A_T_G[-1]+GCT_T_G[-1]
  new_A_G_G = A_G[-1]
  new_C_G = GCT_C[-1]
  new_A_T_G = A_T[-1]
  new_GCT_T_G = A_G_T[-1]+GCT_G_T[-1]+CT_T[-1]
  new_A_C = ACT_A[-1]
  new_GCT_C = GCT_G_G[-1]+C_G[-1]+GCT_T_G[-1]+A_C[-1]+GCT_C[-1]+A_T[-1]+GCT_G_T[-1]+CT_T[-1]
  new_A_T = ACT_A[-1]+G_A[-1]
  new_A_G_T = A_G[-1]
  new_GCT_G_T = GCT_G_G[-1]+A_G_G[-1]+C_G[-1]+A_T_G[-1]+GCT_T_G[-1]
  new_CT_T = A_C[-1]+GCT_C[-1]+A_T[-1]+A_G_T[-1]+GCT_G_T[-1]+CT_T[-1]
  ACT_A.append(new_ACT_A)
  G_A.append(new_G_A)
  A_G.append(new_A_G)
  GCT_G_G.append(new_GCT_G_G)
  A_G_G.append(new_A_G_G)
  C_G.append(new_C_G)
  A_T_G.append(new_A_T_G)
  GCT_T_G.append(new_GCT_T_G)
  A_C.append(new_A_C)
  GCT_C.append(new_GCT_C)
  A_T.append(new_A_T)
  A_G_T.append(new_A_G_T)
  GCT_G_T.append(new_GCT_G_T)
  CT_T.append(new_CT_T)
  
ans = ABC122D_sum() % mod
print(ans)




Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<functional>
using namespace std;
int p[110], a, b, c, d;
int main() {
	cin >> a >> b >> c >> d;
	for (int i = a; i < b; i++)p[i] = 1;
	for (int i = c; i < d; i++)p[i] ++;
	int cnt = 0;
	for (int i = 0; i < 110; i++) {
		if (p[i] >= 2)cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


//
string s, t;

bool func(string a, string b)
{
	char memo['z' + 1] = {0};

	rep (i, a.length())
	{
		if ( memo[a[i]] != 0 )
		{
			if ( memo[a[i]] != b[i] ) return false;
		}
		else
		{
			memo[a[i]] = b[i];
		}
	}
}

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

	if ( func(s, t) && func(t, s) )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 1544
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int r=sc.nextInt();
		out.println(3*r*r);
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

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

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

}

Measured memory_bytes: 21076
n = int(raw_input())
q = []
bottom = 0
for i in range(n):
    cmd = raw_input()
    if cmd[0] == 'i':
        q.append(cmd[7:])
    elif cmd[6] == ' ':
        try:
            q.pop(~q[::-1].index(cmd[7:]))
        except:
            pass
    elif cmd[6] == 'F':
        q.pop()
    else:
        bottom += 1

print(' '.join(q[bottom:][::-1]))

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

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


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

using namespace std;

int main(){
	long long int N;
	cin >> N;
	vector<string>S(3);
	for( size_t i = 0; i < 3; i++ ){
		cin >> S[i];
	}

	long long int ans = 0;
	for( size_t i = 0; i < N; i++ ){
		if( S[0][i] == S[1][i] && S[0][i] == S[2][i] ){

		} else{
			if( S[0][i] == S[1][i] || S[0][i] == S[2][i] || S[2][i] == S[1][i] ){
				ans += 1;
			} else{
				ans += 2;
			}
		}
	}
	cout << ans << endl;
}


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

int main() {
	int A,B;
	cin >> A >> B;
	int a,b,c;
	a =A+ B;
	b = A-B;
	c=A*B;

	if(a>=b&&a>=c){
		cout <<a << endl;
	}
	else if(b >=a&&b>=c){
		cout << b << endl;
	}
	else{
		cout << c << endl;
	}
}

Measured memory_bytes: 256
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
//const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 3e2 + 5;

int MOD;
int C[N][N], DP[N][N], PS[N][N];

void Add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; }

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	int n, k; cin >> n >> k >> MOD;
	C[0][0] = 1;
	for (int i = 1; i < N; i++) {
		C[i][0] = C[i][i] = 1;
		for (int j = 1; j < i; j++) Add(C[i][j], C[i - 1][j - 1] + C[i - 1][j]);
	}
	for (int i = 0; i <= k; i++) DP[1][i] = 1;
	for (int i = k - 1; i >= 0; i--) Add(PS[1][i], PS[1][i + 1] + DP[1][i + 1]);
	for (int i = 2; i <= n + 1; i++) {
		for (int j = 0; j <= k; j++) for (int s = 1; s < i; s++) Add(DP[i][j], 1LL * DP[i - s][j] * PS[s][j] % MOD * C[i - 2][s - 1] % MOD);
		for (int j = k - 1; j >= 0; j--) Add(PS[i][j], PS[i][j + 1] + DP[i][j + 1]);
	}
	cout << DP[n + 1][0] << endl;

	return 0;
}


Measured memory_bytes: 4740
import math
a,b,h,m=map(int,input().split())
t=h*60+m
short=float(t/2%360)
longer=float(t*6%360)
#print(short)
#print(longer)
angle=(abs(short-longer))
#print(angle)
if angle >=float(180):
  angles =float(360)-angle
  #print(angles)
  length=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(angles)))

else:
  length=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(angle)))

print('{:.10f}'.format(length))

Measured memory_bytes: 9468
A,B = list(map(int,input().split()))
X = []
mA = int(100/8*A)
MA = int(100/8*(A+1))+1
mB = int(10*B)
MB = int(10*(B+1))+1
 

for i in range(max(mA,mB),min(MA,MB)):
    X.append(i)
#print(X)

f = True
for i in X:
    if int(i*0.08)==A and int(i*0.1)==B:
        print(i)
        f = False
        break
if f:
    print(-1)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	double v, y, N, t;
	while (cin >> v) {
		t = v / 9.8;
		y = 4.9 * t * t;
		N = (y + 5) / 5;
		printf("%.0lf\n", ceil(N));
	}
	return 0;
}

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

int main()
{
  int a, b = 8;
  cin >> a;
  for (int i = 0; i < 8; i++) {
    int min = 400 + 200*i;
    int max = 599 + 200*i;
    if (min <= a && a <= max) {
      b -= i;
      break;
    }
  }
  cout << b << endl;
}


Measured memory_bytes: 3636
n,m=map(int,input().split())
i=0
x=[]
while i!=n:
    a=list(map(int,input().split()))
    x.append(a)
    i=i+1
x.sort()
m_now=0
n_now=0
while m!=m_now:
    a=x[0]
    del x[0]
    if m>=m_now+a[1]:
        m_now=m_now+a[1]
        n_now=n_now+a[0]*a[1]
    else:
        n_now=n_now+a[0]*(m-m_now)
        m_now=m
print(n_now)

Measured memory_bytes: 27760
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, K;
    cin >> N >> K;
    long long sum[200010];
    sum[0] = 0;
    for (int i = 1; i <= N; i++)
    {
        sum[i] = sum[i - 1] + i;
    }
    
    long long cnt = 0;
    for (int i = K; i < N + 1; i++)
    {
        cnt += ((sum[N] - sum[N - i] - sum[i - 1]) + 1) % 1000000007;
    }
    
    cout << (cnt + 1) % 1000000007 << endl;

    return 0;
}

Measured memory_bytes: 4716
from sys import stdin
def main():
    n, k = map(int, stdin.readline().split())
    a = map(int, stdin.readline().split())
    s = [0] * (n + 1)
    t = [0] * (n + 1)
    for i, x in enumerate(a):
        s[i+1] = s[i] + x
        t[i+1] = t[i] + (x if x > 0 else 0)
    ans = 0
    for i in xrange(n - k + 1):
        v = s[i+k] - s[i]
        if v < 0:
            v = 0
        v += t[i] + t[n] - t[i+k]
        if ans < v:
            ans = v
    print ans
main()


Measured memory_bytes: 12236
n, m = map(int, input().split())
ans = [0] * n
a = [0] * m
b = [0] * m
for i in range(m):
    a[i], b[i] = map(int, input().split())
    ans[a[i]-1] += 1
    ans[b[i]-1] += 1
for i in range(n):
    print(ans[i])




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

signed main(){
    int n,a=1e9,c[2][20];
    cin>>n;
    R(i,n)cin>>c[0][i];
    R(i,n)cin>>c[1][i];
    vector<vector<int>> dp(1<<n,vector<int>(51,1e9));
    dp[0][0]=0;
    R(B,1<<n){
        int o=0,d[n];
        R(i,n)if(!(B&1<<i))d[i]=o++;
        R(i,n){
            int k=abs(i-n+o);
            R(j,c[k%2][i]+1) dp[B|1<<i][c[k%2][i]]=min(dp[B|1<<i][c[k%2][i]],dp[B][j]+d[i]);
        }
    }
    R(i,51)a=min(a,dp[(1<<n)-1][i]);
    cout<<(a==1e9?-1:a);
}

Measured memory_bytes: 65792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll A , B , x , y , cnt[] = {0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31};
string s;

int main() {
    fast_io;

    cin >> s;
    A = (s[0] - 48) * 10 + s[1] - 48;
    B = (s[2] - 48) * 10 + s[3] - 48;

    if(A >= 1 && A <= 12)   x = 1;
    if(B >= 1 && B <= 12)   y = 1;

    if(x && !y) return cout << "MMYY" << endl , 0;
    if(!x && y) return cout << "YYMM" << endl , 0;
    if(x && y)  return cout << "AMBIGUOUS" << endl , 0;
    cout << "NA" << endl;

    return 0;
}
/*
todo :
    1- set constants
    2- check TimeLimit and MemoryLimit
    3- check special test cases
    4- don't forget BS can help you that is good idea(use for loop for floats)
    5- don't forget printf and scanf can help you in your code speed
*/


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e17;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

signed main(){
	int h, w;
	cin >> h >> w;
	vector <vector <char>> a(h, vector <char> (w));
	int cnt = 0;
	rep(i, h)rep(j, w){
		cin >> a[i][j];
		cnt += a[i][j] == '#';
	}

	cout << (cnt == h + w - 1 ? "Possible" : "Impossible") << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll X;
  cin >> X;
  long M = 100;
  ll ans = 0;
  while (M < X) {
    M = M * 1.01;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int k=in.nextInt();
		int q=in.nextInt();
		int [] ans=new int[n];
		for(int i=0;i<q;i++)
		{
			int ind=in.nextInt();
			ans[ind-1]++;
		}
		for(int i=0;i<n;i++)
		{
			if(ans[i]+k-q>0)
			{
				System.out.println("Yes");
			}
			else
			{
				System.out.println("No");
			}
		}
	}
}
	

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

typedef long long ll;
using namespace std;

class Prime{
public:
	vector<int> prime;
	vector<bool> is_prime;
	Prime(int n){
		prime = vector<int>(n);
		is_prime = vector<bool>(n+1,true);
		is_prime[0] = is_prime[1] = false;
		int p = 0;
		for (int i = 2;i <= n;i++){
			if(is_prime[i]){
				prime[p++] = i;
				for (int j = 2*i;j <= n;j += i)is_prime[j] = false;
			}
		}
	}
};

class Mod{
public:
	ll mod;
	Mod(ll m){
		mod = m;
	}
	//a^p
	ll modpow(ll a, ll p){
		if(p == 0) return 1;
		if(p%2 == 0){
			ll half = modpow(a, p/2);
			return half * half % mod;
		}
		else return a * modpow(a,p-1) % mod;
	}

	//nCr
	ll comb(ll n, ll r){
		if(r > n-r) return comb(n,n-r);
		ll mul = 1;
		ll div = 1;
		for (int i = 0;i < r;i++){
			mul *= n-i;
			mul %= mod;
			div *= i+1;
			div %= mod;
		}
		return mul * modpow(div,mod-2) % mod;
	}
};

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

	int n,m; cin >> n >> m;

	ll ans = 1;
		
	Prime p(sqrt(m));
	Mod mod(1e9+7);

	int now = 0;

	while(m != 1 && p.prime[now] != 0){
		int cnt = 0;
		while(m%p.prime[now] == 0){
			cnt++;
			m /= p.prime[now];
		}
		ans = ans * mod.comb(cnt+n-1,n-1) % mod.mod;
		now++;
	}
	if(m != 1){
		ans = ans * mod.comb(n,n-1) % mod.mod;
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 384
N=int(input())
a=[int(x) for x in input().split()]
ans=0
for i in range(1,N-1):
  if (a[i]>a[i-1] and a[i]<a[i+1]) or (a[i]<a[i-1] and a[i]>a[i+1]):
    ans+=1

print(ans)

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

using namespace std; 

#define endl "\n"



long long int divisors[1000006]={0};
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   
   string s;
   cin>>s;
   if(s[s.length()-1]=='s')
      {
          s+="es";
      }
      
    else
      s+="s";
      
    cout<<s;  
   
  
     return 0;
}

Measured memory_bytes: 3644
from itertools import accumulate
from collections import defaultdict


def solve(s):
    n, m, *a = map(int, s.split())
    ac_a = [_a % m for _a in accumulate(a)]
    d = defaultdict(list)
    for i, _a in enumerate(ac_a):
        d[_a].append(i)
    ans = len(d[0])
    for v in d.values():
        if len(v) > 1:
            ans += len(v) * (len(v) - 1) // 2
    return ans


print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 24872
s = gets.chomp
a = s[0..1].to_i
b = s[2..3].to_i

# AMBIGOUS
if 1 <= a && a <= 12 && 1 <= b && b <= 12
  puts "AMBIGUOUS"
# YYMM
elsif 1 <= b && b <= 12
  puts "YYMM"
elsif 1 <= a && a <= 12
  puts "MMYY"
else
  puts "NA"
end


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

using namespace std;

#define pb push_back
#define fio ios::sync_with_stdio(false);

typedef long long ll;
typedef pair <ll, ll> pi;

const ll maxn =  55556;
const ll N = 277775;
const ll mod = 1e9 + 7;

ll cnt, ans, n;

ll __pow(ll a, ll b) {
    if (b == 0)
        return 1LL;
    ll tmp = __pow(a, b / 2);
    ll res = (tmp * tmp) % mod;
    if (b & 1)
        res = (res * a) % mod;
    return res;
}


ll add(ll a, ll b) {
    a += b;
    if (a < 0)
        a += mod;
    if (a >= mod)
        a -= mod;
    return a;
}


string s;

int main() {
    fio;
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++) {
        if (s[i] == '1') {
            ans = add(ans, (__pow(2LL, cnt) * __pow(3LL, n - i - 1)) % mod);
            cnt++;
        }
    }
    ans = add(ans, __pow(2LL, cnt));
    cout << ans << endl;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int K, A, B;
    cin >> K >> A >> B;
    int Ki = K;
    while(Ki<=B){
        if(A<=Ki){
            cout << "OK" << endl;

            return 0;
        }
        Ki += K;
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(void){
	int x[10000],y[10000],i=0,sum=0,vol=0,ave;
	while(scanf("%d,%d",&x[i],&y[i])!=EOF){
		sum+=x[i]*y[i];
		vol+=y[i];
		i++;
	}
	if((vol*10/i)%10>=5)ave=vol/i+1;
	else ave=vol/i;
	printf("%d\n%d\n",sum,ave);
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
using namespace std;
int int_sort(const void*a,const void *b) {
    return *(  int *) b - *(int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}
int main() {
    int D,div=2,x;
    
    cin >> D ;
    //for(int i=0;i<n;i++) {
    if(D==25)
        cout<<"Christmas";
    else if(D==24)
         cout<<"Christmas Eve";
    else if(D==23)
        cout<<"Christmas Eve Eve";
    else
        cout<<"Christmas Eve Eve Eve";
    return 0;
    
    
    
}



Measured memory_bytes: 256
def ABC_79_A():
    N = input()
    
    if N.count(N[0]) == 4:
        print('Yes')
    elif (N[0] == N[1] and N[1] == N[2]) or (N[1] == N[2] and N[2] == N[3]):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':

    ABC_79_A()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int 
#define pb push_back
#define xx first
#define yy second
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ull t;
	t=1;
	while(t--)
	{
		string s;
		cin>>s;
		
		ll n=s.size();
		
		if(s[n-1]=='s')
			s+="es";
		else
			s+="s";
			
		cout<<s;
	}
}

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

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++) 2
#define mn -
#define pls +
#define mod %
#define E =
#define EE ==
#define le <=
#define ge >=

inline void SUM(ll &x,ll y)
{
    x=x+y;
}
inline void DIFF(ll &x,ll y)
{
    x=x-y;
}
inline void yes(int counter){
    if(counter EE 0)
    cout<<"yes\n";
    else if(counter EE 1)
    cout<<"Yes\n";
    else cout<<"YES\n";
    return;
}
inline void no(int counter){
    if(counter EE 0)
    cout<<"no\n";
    else if(counter EE 1)
    cout<<"No\n";
    else cout<<"NO\n";
    return;
}
ll c E 0;
int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin>>n;

    int a[n mn 1];
    int b[n] E {0};

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

    ll sum E 0;
    b[0] E a[0];
    for (int i = 0; i < n mn 1; ++i)
    {
        if(a[i] ge b[i]){
            b[i pls 1] E a[i];
        }
        else
        {
            b[i] E a[i];
            b[i pls 1] E a[i];
        }
    }
    for (int i = 0; i < n; ++i)
    {
        //cout<<b[i];ps();
        SUM(sum,b[i]);
    }
    //cout<<endl;
    cout<<sum<<endl;
    return 0;
}


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

using namespace std;

int main() {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    long long ans = 0;
    if(y >= 2 * x) {
        ans = x + (y - 2 * x) / 4;
    }
    else ans = y / 2;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read( ){
	int x=0,y=1;char ch=' ';
	for(;(ch!='-' && (ch>'9' || ch<'0'));ch=getchar( ));
	if(ch=='-')y=-1,ch=getchar( );
	for(;ch>='0' && ch<='9';ch=getchar( ))x=x*10+ch-48;
	return x*y;
}
const int N=1e5+10;
int n,m,q;
int a[N];
int main( ){
	int x,y,z,k;
	n=read( );m=read( );q=read( );
	for(register int i=1;i<=q;++i){
		x=read( );++a[x];
	}
	for(register int i=1;i<=n;++i){
		if(q-a[i]<m)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

public class AtCoderD
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        int[,] calcResults = new int[10, 10];
        for (int i = 0; i <= 9; i++)
        {
            for (int j = 0; j <= 9; j++)
            {
                calcResults[i, j] = -1;
            }
        }

        int answer = 0;
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                int calcA;
                if (calcResults[i, j] != -1)
                {
                    calcA = calcResults[i, j];
                }
                else
                {
                    calcA = calc(i, j, n);
                }
                int calcB;
                if (calcResults[j, i] != -1)
                {
                    calcB = calcResults[j, i];
                }
                else
                {
                    calcB = calc(j, i, n);
                }
                answer += calcA * calcB;
            }
        }
        Console.WriteLine(answer);
    }

    static int calc(int start, int end, int n)
    {
        int ret = 0;
        int order = 1;
        for (int i = 1; i <= n; i++)
        {
            if (i >= order * 10)
            {
                order = order * 10;
            }
            if (i / order != start)
            {
                continue;
            }
            if (i % 10 != end)
            {
                continue;
            }
            ret++;
        }
        return ret;
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    ll mod = pow(10, 9) + 7;

    ll N, K;
    cin >> N >> K;

    ll ans = 0;

    for(ll i = K; i <= N + 1; i++) {
        ll max = (N + 1 - i + N) * i / 2;
        ll min = (i - 1) * i / 2;

        ans += (max - min) + 1LL;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3640