akhauriyash/Code-Regression huggingface dataset:
n, m = list(map(int, input().split()))
a = [[int(j) for j in input().split()] for i in range(n)]
b = [int(input()) for i in range(m)]
c = [[int(0) for j in range(1)] for j in range(n)]

for i in range(n):
    for j in range(m):
        c[i][0] += (a[i][j] * b[j])

for i in c:
    print(i[0])


Measured memory_bytes: 6032
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int l[60];
  for(int i = 0; i < N; i++)
  {
    cin >> l[i];
  }
  sort(l,l+N,greater<int>());
  int total = 0;
  for(int i = 0; i < K; i++)
  {
    /* code */
    total += l[i];
  }
  cout << total << endl;
  
}

Measured memory_bytes: 256
// Created by ...Lusifer
#include<bits/stdc++.h>
using namespace std;
 
#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
	int n;
	cin>>n;
	int visited[n+1]={0};
	int node[n+1];
	for(int i=1;i<=n;i++){
		cin>>node[i];
	}
	int cnt=0;
	int u=1;
	while(u!=2){
		if(visited[u]==0){
			visited[u]=1;		
		}
		else if(visited[u]==1){
			cout<<-1<<endl;
			return;
		}
		u=node[u];
		cnt++;
	}
	cout<<cnt<<endl;
	//cout<<endl<<"Time: "<<(float)clock()/CLOCKS_PER_SEC<<" seconds"<<endl;
	return ;
}
 
int main(){
	fastio();

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

Measured memory_bytes: 4432
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, k;

    cin >> n >> k;

    ll a = n % k;

    cout << min(abs(a), abs(a - k)) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

struct Combination{
    vector<long long> _fac,_finv,_inv;
    const int m = MOD;

    Combination(int sz) : _fac(sz),_finv(sz),_inv(sz){
        _fac[0] = _fac[1] = 1;
        _finv[0] = _finv[1] = 1;
        _inv[1] = 1;
        for(int i = 2; i <= sz; i++){
            _fac[i] = _fac[i-1]*i%m;
            _inv[i] = m-_inv[m%i]*(m/i)%m;
            _finv[i] = _finv[i-1]*_inv[i]%m;
        }
    }

    inline long long fac(int n){return _fac[n];}
    inline long long inv(int n){return _inv[n];}
    inline long long finv(int n){return _finv[n];}

    long long comb(int n,int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return _fac[n]*(_finv[k]*_finv[n-k]%m)%m;
    }
};

int main(){
    int N,A,B; cin >> N >> A >> B;
    ll K; cin >> K;
    Combination C(1000000);
    ll ans = 0;
    rep(i,N+1){
        ll now = (ll)A*i;
        if(K < now) continue;
        if((K-now)%B==0){
            ll d = (K-now)/B;
            ans += C.comb(N,i)*C.comb(N,d)%MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;

}

    



Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    int cnt_kazu;
    for(int i=0;i<n;i++){
        if(i%2==0){
            int cnt_yaku=0;
            for(int j=0;j<sqrt(i+1)-1;j++){
                if((i+1)%(j+1)==0){
                    cnt_yaku++;
                }
            }
            if(cnt_yaku==4){
                cnt_kazu++;
            }
        }
    }
    cout << cnt_kazu <<endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    
    if (N % 2 == 1) {
    
    int min = 1;
    int max = N;
    
    for (int i = 0; i<M; i++) {
        cout << min;
        cout << " ";
        cout << max << endl;
        min++;
        max--;
    }
    }else{
    
    int min1 = N/4;
    int max1 = N/4 + 1;
    int MIN = min1;
    
    int min2 = N*3/4;
    int max2 = N*3/4 + 2;
    
    if (MIN > M ) {
        for (int i = 0; i < M; i++) {
            cout << min1;
            cout << " ";
            cout << max1 << endl;
            min1--;
            max1++;
        }
    }else {
        for (int i = 0; i < MIN; i++){
            cout << min1;
            cout << " ";
            cout << max1 << endl;
            min1--;
            max1++;
        }
        for (int i = 0; i < M - MIN; i++) {
            cout << min2;
            cout << " ";
            cout << max2 << endl;
            min2--;
            max2++;
        }
    }
    
    
    
    
    
    }  
}

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 hh, ww, nn, aa, pp = 0;
	cin >> hh >> ww >> nn;
	int64 memo[hh][ww];
	for(int64 ii = 1;ii <= nn;ii++)
	{
		cin >> aa;
		for(int64 jj = 0;jj < aa;jj++)
		{
			memo[pp / ww][pp % ww] = ii;
			pp++;
		}
	}
	for(int64 ii = 0;ii < hh;ii++)
	{
		if(ii % 2 == 0)
		{
			for(int64 jj = 0;jj < ww;jj++)
			{
				cout << memo[ii][jj];
				if(jj != ww - 1)
				{
					cout << ' ';
				}
			}
			cout << '\n';
		}
		else
		{
			for(int64 jj = ww - 1;jj >= 0;jj--)
			{
				cout << memo[ii][jj];
				if(jj != 0)
				{
					cout << ' ';
				}
			}
			cout << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, ans=0;
    unsigned int min = -1;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];

    for (int i = 0; i < n;i++) {
        if (p[i] <= min) {
            min = p[i];
            ans++;
        }
    }
    cout << ans << endl;
}

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

const int N = 2 * 1e5 + 5;

int a[N];

void print(int n) {

	int t = n;

	if (n & 1) {

		while (t >= 1) {

			cout << a[t] << " ";

			t -= 2;

		}

		t = 2;

		while (t <= n) {

			cout << a[t] << " ";

			t += 2;


		}


	}

	else {


		while (t >= 2) {

			cout << a[t] << " ";

			t -= 2;

		}

		t = 1;

		while (t <= n) {

			cout << a[t] << " ";

			t += 2;


		}







	}







}

int main() {

	int n;

	cin >> n;

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

	print(n);

	cout << "\n";

}

Measured memory_bytes: 2944
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<iterator>
#include <stack>
#define ll long long
typedef long double ld;
#define all(v) ((v).begin()),((v).end())
#define vec2(n,m) vector<vector<ll>>vv(n + 10, vector<ll>(m + 10, 0));
#define p_q1   priority_queue<int,vector<int>,greater<int>>pq1;
#define format(n) fixed<<setprecision(n)
#define ll_min LLONG_MIN;
#define ll_max LLONG_MIN;
#define endl "\n"
#define F first 
#define S second
#define mkpr(x,y)  make_pair(x,y)
using namespace std;
void weza()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
    weza();
    ll n,k;
    cin >>k>> n;
    vector<int>v(n + 10);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    int m = 10000000;
    int l = 0, r = 0;
    for (int i = 0; i < n; i++)
    {
       
           
        if (i == 0)
            r = (v[n - 1] - v[i]);
        else
            r = (v[n - 1] - v[i]) + (k - v[n - 1]) + v[i - 1];
            
        m = min(m, r);
        if (i != n - 1)
            l = v[i] + k - v[n - 1] + (v[n - 1] - v[i + 1]);
        else
            l = v[n - 1] - v[0];
        m = min(m, l);
       // cout << r << " " << l << endl;
    }
    cout << m << endl;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    rep(i, N) {
        if (A[i] > i) {
            cout << -1 << endl;
            return 0;
        }

        if (i < N - 1 && A[i] + 1 < A[i + 1]) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = 0;
    for (int i = 1; i < N; ++i) {
        if (A[i - 1] + 1 != A[i]) {
            ans += A[i - 1];
        }
    }

    ans += A[N - 1];
    
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <typename First> void Exit(First first){cout << first << endl;exit(0); };

int main(){
    iosetup;
    int N; cin >> N;
    modint ans = 1;
    rep(i, 1, N+1) ans *= i;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
sa = input()
sb = input()
sc = input()
p = "a"
for i in range(1024):
  if p == "a":
    if len(sa) == 0: 
      print("A")
      break
    p = sa[0]
    sa = sa[1:]
  elif p == "b":
    if len(sb) == 0: 
      print("B")
      break
    p = sb[0]
    sb = sb[1:]
  elif p == "c":
    if len(sc) == 0:
      print("C")
      break
    p = sc[0]
    sc = sc[1:]

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

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

  vector< int > p(n);

  for(auto &&s : p) {
    cin >> s;
  }

  int count = 0;

  for(int i = 0; i < n; i++) {
    if(p.at(i) != i+1) {
      count++;
    }
  }

  if(count == 0 || count == 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
p = input()
s = input()

words = list(s)
x = 0
max_x = 0
n = int(p)

for num in range(len(words)):
    if words[num] == 'I':
        x += 1
        if x > max_x:
            max_x = x
    else:
        x -= 1

print(max_x)



Measured memory_bytes: 9168
#include <iostream>
#include <vector>

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        std::cin >> a[i];
    }
    int l = 0, r = (int) 1e9 + 7;
    while (r - l > 1)
    {
        int mid = (l + r) / 2;
        int count = 0;
        for (int i = 0; i < n; ++i)
        {
            count += (a[i] + mid - 1) / mid - 1;
        }
        if (count <= k)
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    std::cout << r << '\n';
    return 0;
}

Measured memory_bytes: 3936
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793)
#define mod 1000000007



int main() {
	int a, b;
	cin >> a >> b;
	int C = 0;
	for (int i = a; i <= b; i++) {
		string s = to_string(i);
		string s1 = s;
		reverse(s.begin(), s.end());
		if (s1== s)C++;
	}
	cout << C << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

knock_down = [0] * (n + 1)

for i in range(n):
    power = b[i]

    # まずはi番目の街のモンスターをできる限り倒す
    if(power >= a[i] - knock_down[i]):
        power -= (a[i] - knock_down[i])
        knock_down[i] = a[i]
    else:
        knock_down[i] += power
        continue

    if(power == 0):
        continue

    # 次に、残った力でi+1番目のモンスターをできる限り倒す
    if(power >= a[i+1]):
        knock_down[i+1] = a[i+1]
    else:
        knock_down[i+1] = power

print(sum(knock_down))

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 2147483647
#include <math.h> /* M_PI */
int main()
{

    ll n;
    cin >> n;
    //vector<ll> A(n);
    map<ll, ll> data;
    rep(i, n)
    {
        ll a = 0;
        cin >> a; //3組同じものがないかを調べたい
        data[a] += 1;
    }
    ll o = 0; //奇数
    ll e = 0; //偶数個
    for (auto x : data)
    {
        if (x.second % 2 == 0)
        {
            e += 1;
        }
        else
        {
            o += 1;
        }
    }
    if (e % 2 == 0)
    {
        cout << o + e;
    }
    else
    {
        cout << o + e - 1;
    }
}


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

using namespace std;

int main()
{
  int n, ans = 1000000;
  double sum;

  scanf("%d", &n);

  vector<double> x(n);

  for (int i = 0; i < n; i++)
  {
    scanf("%lf", &x[i]);
  }

  sort(x.begin(), x.end());

  for (double i = x[0]; i <= x[n - 1]; i++)
  {
    sum = 0;
    for (int j = 0; j < n; j++)
    {
      sum += pow(x[j] - i, 2);
    }
    if (sum < ans)
      ans = sum;
  }

  printf("%d", int(ans));
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,k,d,a=0,b=1;
    vector<lli> vec;
    lli i,j;
    cin>>n>>k;
    rep(i,0,k){
        cin>>d;
        while(d>a){
            vec.push_back(a);
            a++;
        }
        a++;
    }
    while(10>a){
        vec.push_back(a);
        a++;
    }
    lli h=n;
    while(h>=10){
        h/=10;
        b++;
    }
    lli sinsu=vec.size();
//    cout<<"入力した"<<b<<"桁の数字を、"<<sinsu<<"進数で考える"<<endl;
    vector<lli> syoki(b,0),keta;
    rep(i,0,pow(sinsu,b)){
//        cout<<i<<"の時　";
        keta=syoki;
        lli c=i;
        d=0;
        while(c>=sinsu){
            keta[d]=c%sinsu;
            c/=sinsu;
            d++;
        }
        keta[d]=c;
        lli sum=0;
//        rep(j,0,b){
//            cout<<keta[j];
//        }
//        cout<<endl;
        rep(j,0,b){
            sum+=pow(10,j)*vec[keta[j]];
        }
        if(sum>=n){
            cout<<sum<<endl;
            exit(0);
        }
    }
    if(vec[0]==0){
        cout<<vec[1];
        rep(i,0,b){
            cout<<vec[0];
        }
        cout<<endl;
    }
    else{
        rep(i,0,b+1){
            cout<<vec[0];
        }
        cout<<endl;
    }
}


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

typedef long long ll;

int main(void) {
    ll x;
    scanf("%lld",&x);
    for(ll i=-500;i<=500;i++) {
        for(ll j=-500;j<=500;j++) {
            ll a=i*i*i*i*i;
            ll b=j*j*j*j*j;
            if (a-b==x) {
                printf("%lld %lld",i,j);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3836
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque

H,W=map(int, sys.stdin.readline().split())
CH,CW=map(int, sys.stdin.readline().split())
CH-=1
CW-=1
DH,DW=map(int, sys.stdin.readline().split())
DH-=1
DW-=1
S=[ sys.stdin.readline().strip() for _ in range(H) ]

D=[(0,1),(0,-1),(1,0),(-1,0)]
WARP=[]
for dh in range(-2,3):
    for dw in range(-2,3):
        if abs(dh)+abs(dw)<=1: continue
        WARP.append((dh,dw))

d=defaultdict(lambda: float("inf")) #スタート地点から各マスまでの距離

q=deque()
q.append((0,CH,CW))
d[(CH,CW)]=0

while q:
    kyori, fro_h, fro_w=q.popleft()
    if d[(fro_h, fro_w)]<kyori: continue
    #歩いて移動
    for dh,dw in D:
        to_h, to_w=fro_h+dh, fro_w+dw
        if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]==".":
            if kyori < d[(to_h, to_w)]:
                d[(to_h, to_w)]=kyori
                q.appendleft((kyori, to_h, to_w))
    #ワープ
    for dh,dw in WARP:
        to_h, to_w=fro_h+dh, fro_w+dw
        if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]==".":
            if kyori+1 < d[(to_h, to_w)]:
                d[(to_h, to_w)]=kyori+1
                q.append((kyori+1, to_h, to_w))

if d[(DH,DW)]==float("inf"):
    print -1
else:
    print d[(DH,DW)]


Measured memory_bytes: 215608
#define N 40
#include <stdio.h>
struct poker {
    char suit;
    int value;
};

void showArray(struct poker a[], int n) {
    for (int i = 0; i < n; i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%c%d", a[i].suit, a[i].value);
    }
    printf("\n");
}

void bubbleSort(struct poker a[], int n) {
    int flag = 1;
    while (flag) {
        flag = 0;
        int i = 0;
        for (int j = 0; j < n - i - 1; j++) {
            if (a[j].value > a[j + 1].value) {
                struct poker tmp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = tmp;
                flag = 1;
            }
        }
        i++;
    }
}

void selectionSort(struct poker a[], int n) {
    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i + 1; j < n; j++) {
            if (a[j].value < a[minj].value) {
                minj = j;
            }
        }
        if (minj != i) {
            struct poker tmp = a[minj];
            a[minj] = a[i];
            a[i] = tmp;
        }
    }
}

int isStable(struct poker a[], struct poker b[], int n) {
    for (int i = 0; i < n; i++) {
        if (a[i].suit != b[i].suit) {
            return 0;
        }
    }
    return 1;
}

int main() {
    struct poker p1[N], p2[N];
    int n = 0;
    scanf("%d\n", &n);
    for (int i = 0; i < n; i++) {
        if (i > 0) {
            getchar();
        }
        scanf("%C%d", &p1[i].suit, &p1[i].value);
        p2[i] = p1[i];
    }
    bubbleSort(p1, n);
    selectionSort(p2, n);
    showArray(p1, n);
    printf("Stable\n");
    showArray(p2, n);
    if (isStable(p1, p2, n)) {
        printf("Stable\n");
    }
    else {
        printf("Not stable\n");
    }
    return 0;
}


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

using namespace std;

long long dp[101][100001];

int main()
{
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  for (int i = 0; i < N; i++)
    cin >> w[i] >> v[i];
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 100001; j++)
      dp[i][j] = 1e18;
  dp[0][0] = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 100001; j++)
    {
      if (j - v[i] >= 0)
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    }
  long long ans = 0;
  for (int i = 0; i < 100001; i++)
    if (dp[N][i] <= W)
      ans = i;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
// #define DEBUG 10
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const ll mod = 1e9 + 7, maxn = 155, maxm = 15;
const double PI = acos(-1);
 
 
int main (){
    ios_base::sync_with_stdio(false);
    int n, k, c, last = -oo;
    string s;
    cin >> n >> k >> c >> s;
 
    vector<int> l(n), r(n);
 
    for (int i=0; i<n-1; i++){
        l[i+1] = l[i];
        if (s[i] == 'o' and last + c < i){
            last = i;
            l[i+1]++;
        }
    }
    last = oo;
    for (int i=n-1; i>0; i--){
        r[i-1] = r[i];
        if (s[i] == 'o' and last - c > i){
            last = i;
            r[i-1]++;
        }
    }
 
    for (int i=0; i<n; i++){
        if (l[i] + r[i] < k){
            cout << i+1 << endl;
        }
    }
    return 0;
}

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

int main() {
    int a, b, c, d, s, t;
    cin >> a >> b >> c >> d;
    s = max(a, c);
    t = min(b, d);

    if(b < c || d < a) cout << 0 << endl;
    else cout << t-s << endl;
}

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll Q; cin >> Q;
    priority_queue<ll> L;
    priority_queue<ll, vector<ll>, greater<ll>> R;
    
    ll LSum = 0, RSum = 0, bsum = 0;
    REP(i, Q){
        ll t, a, b; cin >> t;
        if(t == 1){
            cin >> a >> b; bsum += b;
            if(L.empty()){
                L.push(a); LSum += a;
            }
            else if(L.top() < a){
                R.push(a); RSum += a;
            }
            else{
                L.push(a); LSum += a;
            }
            
            while(L.size() >= R.size()+2){
                ll tmp = L.top(); L.pop(); LSum -= tmp;
                R.push(tmp); RSum += tmp;
            }
            while(L.size()+1 <= R.size()){
                ll tmp = R.top(); R.pop(); RSum -= tmp;
                L.push(tmp); LSum += tmp;
            }
        }
        else{
            ll x = L.top();
            ll ans = bsum;
            ans += x*L.size() - LSum;
            ans += RSum - x*R.size();
            cout << x << " " << ans << endstr;
        }
    }
    return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

int main(){
    int n,t;cin >> n >> t;
    int c[n],time[n];
    rep(i,n)cin >> c[i] >> time[i];

    int ans = INF;
    bool ok = false;

    for(int i=0;i<n;i++){
        if(time[i]<=t){
            ans = min(ans,c[i]);
            ok =true;
        }
    }

    if(ok)cout << ans << endl;
    else cout << "TLE" << endl;

    return 0;

}


Measured memory_bytes: 3512
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
k,s=map(int,input().split())
cnt=0

for i in range(k+1):
	a=i
	for j in range(k+1):
		b=j
		if a+b<=s and a+b+k>=s:
			cnt+=1
			
print(cnt)

Measured memory_bytes: 3060
from collections import deque

def solve():
    H, W = map(int, input().split())
    Ass = ['#'*(W+2)] + ['#'+input()+'#' for _ in range(H)] + ['#'*(W+2)]

    distss = [[-1]*(W) for _ in range(H)]
    Q = deque([])
    for i in range(1, H+1):
        for j in range(1, W+1):
            if Ass[i][j] == '#':
                Q.append((i, j))
                distss[i-1][j-1] = 0

    while Q:
        i, j = Q.popleft()
        for di, dj in [(-1,0), (1,0), (0,-1), (0,1)]:
            i2, j2 = i+di, j+dj
            if Ass[i2][j2] == '.' and distss[i2-1][j2-1] == -1:
                Q.append((i2, j2))
                distss[i2-1][j2-1] = distss[i-1][j-1] + 1

    return max(map(max, distss))

print(solve())


Measured memory_bytes: 86748
#include<cstdio>
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int max(int a,int b,int c)
{
if(a>b)
{
	return a>c ? a : c;
}
else
	return b>c ? b : c;
}

int main()
{
	int a,b,c,k;
	int ans=0;
	cin>> a >> b >> c >> k;
	ans=a+b+c;
	for(int i=1;i<=k;i++)
	{
		ans+=max(a,b,c);
		if(max(a,b,c)==a)a*=2;
		else if(max(a,b,c)==b)b*=2;
		else c*=2;
	}
	cout<<ans;
	
	return 0;
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
// vll x(n); x[i]=a;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define INF 1e+12
#define EPS 1e-12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    vc s(3);
    cin >> s;
    if(s[0] != s[1] || s[1] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import exit

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

B = B[::-1]

#Find match
need_swap = [i for i in range(n) if A[i] == B[i]]

if len(need_swap) == 0:
    print("Yes")
    print(" ".join(map(str,B)))
    exit()

val = A[need_swap[0]]
for i in range(n):
    if len(need_swap) == 0:
        break
    if A[i] != val and B[i] != val:
        j = need_swap.pop()
        B[i],B[j] = B[j],B[i]
if len(need_swap) == 0:
    print("Yes")
    print(" ".join(map(str,B)))
else:
    print("No")

Measured memory_bytes: 121384
#include<bits/stdc++.h>
const long long INF = INT_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ll long long int
#define ALL(x) x.begin(),x.end()
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
vector<ll> vi;

/*--------------------template--------------------*/


int main() {
	cin >> s;
	REP(i, s.size()) {
		if (s[i] == '0') {
			k = 0;
			v.push_back(k);
		}
		else if (s[i] == '1') {
			k = 1;
			v.push_back(k);
		}
		else if (s[i] == 'B' && v.size() != 0) {
			v.pop_back();
		}
	}
	REP(i, v.size()) {
		cout << v[i];
	}
	cout << endl;
}

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

int main(){

  string s;

  while(cin>>s&&s!="#"){
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    bool mp[9][9]={};
    int x=0,y=0;
    for(int i=0;i<s.size();i++){
      if(s[i]=='/')y++,x=0;
      else if(s[i]=='b')mp[y][x]=1,x++;
      else x+=s[i]-'0';
    }
    
    swap(mp[a-1][b-1],mp[c-1][d-1]);
    
    for(int i=0;i<=y;i++){
      int t=0;
      for(int j=0;j<x;j++){
	if(mp[i][j]){
	  if(t)cout<<t,t=0;
	  cout<<'b';
	}
	else t++;
      }

      if(t)cout<<t;
      if(i!=y)cout<<'/';
    }
    
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

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

  int cnt =0;

  for(int i=0; i<t.size(); ++i){
    if(s[i] == t[i]) cnt++;
  }
  if(cnt != s.size()) cout << "No";
  else cout << "Yes";

  
  return 0;
}

Measured memory_bytes: 3624
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if s[i+j]=="?":
      continue
    if s[i+j]!=t[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    strs.append(posstr.replace("?","a",50))
strs.sort()
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])


Measured memory_bytes: 38308
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(sorted(Y)));L=len(t);h=dict(zip(s.values(),s.keys()));w=dict(zip(t.values(),t.keys()));V=[[0]*-~K for i in r(L+1)];U=[i[:]for i in V];v=[i[:]for i in V]
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]+=-1
for i in r(L+1):
 for j in r(K):U[i][j+1]+=U[i][j]
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]+=-1
for j in r(K+1):
 for i in r(L):V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];v[w[0]][h[0]]=1;a=0
while q:
 x,y=q.pop();a+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in[(-1,0),(1,0),(0,1),(0,-1)]:
  c=x+e;d=y+f
  if(0<=c<K)*(0<=d<L)*v[d][c]==0:
   if U[-~f//2+y][x]==e==0 or V[y][-~e//2+x]==0==f:q+=[(c,d)];v[d][c]=1
if a>F:a='INF'
print(a)

Measured memory_bytes: 551604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int MAX_N=105;
set<string> seen;
string words[MAX_N];
int N;

void solve()
{
	bool ok = true;
	seen.emplace(words[0]);
	for(int i=1;i<N;++i){
		if(seen.count(words[i]) || words[i][0] != words[i-1].back()){
			ok = false;
			break;
		}
		seen.emplace(words[i]);
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d,x,y;
  cin>>a>>b>>d>>c;
  if(a <= b){x = a;}
  else if(b < a){x = b;}
  
  if(c <= b){y = c;}
  else if(d < c){y = d;}
  
  cout<<x+y<<endl;
  
  return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 2e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;
int A[MAXN];
int cnt[MAXN];
vector<int> vec;

int main()
{
	int i, j;
	scanf("%d", &N);
	ll tot = 0ll;
	for (i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
		cnt[A[i]]++;
		vec.push_back(A[i]);
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	for (i = 0; i < vec.size(); ++i) {
		ll x = cnt[vec[i]];
		tot += x*(x - 1LL) / 2LL;
	}
	for (i = 1; i <= N; ++i) {
		ll x = cnt[A[i]];
		printf("%lld\n", tot - x + 1LL);
	}
	return 0;
}

Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int n, p;
    std::string s;
    std::cin >> n >> p >> s;

    long long ans = 0;
    if (p == 2)
    {
        for (int i = 0; i < n; ++i)
        {
            if (s[i] == '0' || s[i] == '2' || s[i] == '4' || s[i] == '6' || s[i] == '8')
            {
                ans += i + 1;
            }
        }
    }
    else if (p == 5)
    {
        for (int i = 0; i < n; ++i)
        {
            if (s[i] == '0' || s[i] == '5')
            {
                ans += i + 1;
            }
        }
    }
    else
    {
        int rem10 = 10 % p;
        int rem10pow = 1;
        std::vector<int> rem;
        rem.resize(n + 1);
        rem[n] = 0;
        for (int i = n - 1; i >= 0; --i)
        {
            rem[i] = (rem[i + 1] + ((s[i] - '0') % p) * rem10pow) % p;
            rem10pow = (rem10pow * rem10) % p;
        }

        std::vector<long long> count;
        count.resize(p);
        std::fill(count.begin(), count.end(), 0);
        for (int i = 0; i <= n; ++i)
        {
            ++count[rem[i]];
        }

        for (int i = 0; i < p; ++i)
        {
            ans += count[i] * (count[i] - 1);
        }
        ans /= 2;
    }
    std::cout << ans << std::endl;

    return 0;
}

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

bool test = true;
int tt = 1;
#define ll long long
#define all(x) x.begin(), x.end()
#define sz(s) (int)(s.size())

struct fio
{
    fio()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(10);
    }
} fio;

const ll mod = (ll)(1e9 + 7);

int main() 
{
    int n;
    cin >> n;
    vector<ll> ways(n+1, 0);

    for(int i=3; i<=n; i++) {
    	ways[i] = 1 + ways[i-3];
    	ways[i] = (ways[i] + ways[i-1]) % mod;
    }
    cout << (ways[n] - ways[n-1] + mod) % mod;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
using namespace std;

signed main(){
    int n; cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a.at(i);
    int ans=0;
    a.push_back(0);
    rep(i,n){
        if(a.at(i)==0) continue;
        if(a.at(i+1)==0){
            ans+=a.at(i)/2;
            a.at(i)=a.at(i)%2;
        }else{
            if((a.at(i)+a.at(i+1))%2==0){
                ans+=(a.at(i)+a.at(i+1))/2;
                a.at(i)=0;
                a.at(i+1)=0;
            }else{
                ans+=(a.at(i)+a.at(i+1))/2;
                a.at(i)=0;
                a.at(i+1)=1;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
from math import ceil, floor
X, K, D = map(int, input().split())
ans = abs(X + K*D)
fapp = (K*D - X)/(2*D)

if fapp <= 0:
    list = [0]
elif fapp >= K:
    list = [K]

else:
    list = [ceil(fapp), floor(fapp)]
for f in list:
    abso = abs(X + f*D - (K-f)*D)
    if abso < ans:
        ans = abso

print(ans)

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;

vector<pair<ll, int>> factorize(ll num){
    vector<pair<ll, int>> res;
    for(ll i=2; i*i<=num; i++){
         if(num%i) continue;

        res.emplace_back(i, 0);
        while(num%i==0){
            res.back().second++;
            num /= i;
        }
    }
    if(num != 1){
        res.emplace_back(num, 1);
    }
    return res;
}

int main() {

    ll n;
    cin >> n;

    vector<ll> v(n+1, 0);
    while(n > 1){
        auto f = factorize(n--);
        rep(i, f.size()){
            v[f[i].first] +=  f[i].second; 
        }
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    ll ans = 1;
    for(int i=0; v[i]!=0; i++){
        ans *= (v[i]+1);
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
num = sorted(list(map(int, input().split())))

if (num[1] - num[0]) % 2 == 0:
    print(num[2] - num[1] + (num[1]-num[0])//2)
else:
    print(num[2] - num[1] + (num[1]-num[0])//2 + 2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define endl '\n'
#define F first
#define S second
typedef pair<int, int> pii;
typedef long long ll;

void C(){
	/**int pass(int m, int k){
		int cnt=0;
		while(m<k){
			m*=2;
			cnt++;
		}
		return cnt;
	}
	int n,k; cin>>n>>k;
	double ans=0;
	for(int i=1; i<=n; i++){
		int x = 1<<pass(i, k);
		double prob = 1.0/(x*1.0);
		ans+=((1.0/n*1.0)*prob);
	}
	cout<<fixed<<setprecision(12)<<ans<<endl;*/
}
const int MAX = 1e5+1;
vector<pii> g[MAX];
bool vis[MAX];
int color[MAX];

void D(){
/*void bfs(pii u){
	memset(color, -1, sizeof(color));
	queue<pii> q;
	q.push(u);
	while(!q.empty()){
		pii v = q.front();
		q.pop();
		vis[v.F]=true;
		for(auto&x: g[v.F]){
			if(!vis[x.F]){
				vis[x.F]=true;
				if(x.S%2==0){
					if(color[v.F]!=-1)color[x.F]=color[v.F];
					else color[v.F]=color[x.F]=0;
				}
				else{
					if(color[v.F]!=-1)color[x.F]=!color[v.F];
					else {color[v.F]=1; color[x.F]=0;}
				}
				q.push(x);
			}
		}
	}
}*/
}
void dfs(pii u){
	vis[u.F] = 1;
	for(auto&x: g[u.F]){
		if(!vis[x.F]){
			if(x.S%2==0){
				if(color[u.F]!=-1)color[x.F]=color[u.F];
				else color[x.F]=color[u.F]=0;
			}
			else{
				color[x.F]=!color[u.F];
				//if(color[x.F]!=-1)color[x.F]=!color[u.F];
				//else {color[x.F]=0; color[u.F]=1;}
			}
			dfs(x);
		}
	}
}

int main(){
	int n; cin>>n;
	int u, v, w;
	for(int i=0; i<n-1; i++){
		cin>>u>>v>>w;
		u--; v--;
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	dfs({0,0});
	for(int i=0; i<n; i++){
		cout<<color[i]<<endl;
	}
	return 0;   
}


Measured memory_bytes: 11612
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	string s;
	cin >> s;
	rep(i,s.length()) {
		s[i] = 'x';
	}
	cout << s << endl;

  return 0;
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i = 0; i < H; i++) {
        cin >> S[i];
    }
    bool isok = true;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(S[i][j] == '.')
                continue;
            bool ok = false;
            ok |= i > 0 && S[i - 1][j] == '#';
            ok |= i + 1 < H && S[i + 1][j] == '#';
            ok |= j > 0 && S[i][j - 1] == '#';
            ok |= j + 1 < W && S[i][j + 1] == '#';
            isok &= ok;
        }
    }
    cout << (isok ? "Yes" : "No") << endl;
    return 0;
}

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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    printf("%d %d %d\n", z, x, y);
    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD


ll N,L[101010];
ll i, j, k,ans;



int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld",&L[i]);
    }
    sort(L,L+N);
    fornum(i,2,N){
        j=i-1;
        fornum(k,0,i){
            while(k<j&&L[i]<L[j]+L[k]){
                j--;
            }
            ans+=(i-1-j);
            if(k>=j){
                ans+=(i-1-j)*(i-2-j)/2;
                break;
            }
            
        }
        //printf("%lld %lld\n",i,j);
    }
    printf("%lld",ans);
    
    return 0;
}

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

int main(){
  int N,K,S;
  cin >> N >> K >> S;

  vector<int> ans(N);

  if(S==1e9){
    for(int i=0;i<K;i++)  ans.at(i)=S;
    for(int i=K;i<N;i++)  ans.at(i)=1;
  }
  else{
    for(int i=0;i<K;i++)  ans.at(i)=S;
    for(int i=K;i<N;i++)  ans.at(i)=S+1;
  }

  for(int i=0;i<N-1;i++)  cout << ans.at(i) << " ";
  cout << ans.at(N-1) << endl;

	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s;cin>>s;
    while(true){
        s.pop_back();
        if(s.size()&1) continue;
        bool ok = true;
        for(int i=0;i<s.size()/2;++i){
            if(s[i]!=s[i+s.size()/2]) ok = false;
        }
        if(ok){
            cout << s.size() << endl;
            return 0;
        }
    }
        
    return 0;
}

Measured memory_bytes: 256
n, y = gets.chomp.split(' ').map(&:to_i)

o_i, o_j, o_k = -1, -1, -1

(0..n).each do |i|
  (0..n-i).each do |j|
    if i * 10000 + j * 5000 + (n - i - j) * 1000 == y
      o_i, o_j, o_k = i, j, (n - i - j)
    end
  end
end

puts "#{o_i} #{o_j} #{o_k}"

Measured memory_bytes: 1788
s = input()
t = input()

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dpp = dp[i][j] + 1
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dpp)
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])

u = ''
i = len(s)
j = len(t)
while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        u = s[i - 1] + u
        i -= 1
        j -= 1

print(u)

Measured memory_bytes: 113884
#include <iostream>
#include <string>

using namespace std;
int main() {
	long long a, b, c, k;
	cin >> a >> b >> c >> k;
	long long sum = 0;
	if(k >= a) {
		sum += a;
		k -= a;
	} else {
		cout << k << "\n";
		return 0;
	}
	if(k >= b) {
		k -= b;
	} else {
		cout << sum << "\n";
		return 0;
	}
	if(k >= c) {
		sum -= c;
		cout << sum << "\n";
		return 0;
	}
	cout << sum - k << "\n";
	return 0;
}

Measured memory_bytes: 3636