akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  int N;
  cin >> N;
  vector< int > A(N);
  cin >> A;
  vector< int > cnt(1010101);
  for(auto &p : A) cnt[p]++;
  int ret = 0;
  sort(begin(A), end(A));
  A.erase(unique(begin(A), end(A)), end(A));
  for(int i = 0; i < A.size(); i++) {
    auto d = divisor(A[i]);
    int all = N - 1;
    cnt[A[i]]--;
    for(auto &p : d) {
      all -= cnt[p];
    }
    if(all == N - 1) ++ret;
    cnt[A[i]]++;
  }
  cout << ret << endl;
}


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

int main() {
  int N,M,A,Ans=0;
  cin>>N>>M;
  rep(i,M){cin >> A;
          Ans+=A;}
  Ans=N-Ans;
  if(Ans<0){cout<<-1<<endl;}else{cout<<Ans<<endl;}
}

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

#define ll long long
using namespace std;
bool s[200050] = {};
bool t[200050] = {};
int main()
{
	ll n, m;
	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		ll a, b;
		cin >> a >> b;

		if (a == 1) {
			t[b] = true;
		}

		if (b == n) {
			s[a] = true;
		}
	}

	for (int i = 0; i < 200050; i++)
	{
		if (s[i] && t[i]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;
	return 0;

}

Measured memory_bytes: 640
#include <iostream>
    #include <sstream>
    #include <vector>
    #include <cmath>
    #include <ctime>
    #include <cassert>
    #include <iomanip>
    #include <cstdio>
    #include <float.h>
    #include <queue>
    #include <set>
    #include <map>
    #include <fstream>
    #include <cstdlib>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <numeric>
    #include <stack>
    #include <functional>
           
    using namespace std;
           
    #define endl '\n'
    #define MOD 1000000007
    #define INF 1ll<<30
     
    // #define MAX 100010
     
    #define eps 1e-11
    #define bit_max 1ll<<32
    #define _USE_MATH_DEFINES
     
    long long int fact[3000];
     
    void pre()
    {
        fact[0]=1;
        fact[1]=1;
        for(int i=2;i<2005;i++)
        {
            fact[i]= (fact[i-1]*i)%MOD;
        }
    }
     
    long long int poww(long long int a,long long int b)
    {
        if(b==0)
            return 1;
        long long int x = poww(a,b/2)%MOD;
        if(b%2==0)
        {
            return (x*x)%MOD;
        }
        else
        {
            return (((x*x)%MOD)*a)%MOD;
        }
    }

    map<int,int> m;

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        #ifndef ONLINE_JUDGE
            // freopen("input.txt","r",stdin);
            // freopen("output.txt","w",stdout);
        #endif
        string a;
        cin>>a;
        map<char,int> m;
        for(int i=0;i<a.length();i++)
        {
            m[a[i]]++;
        }
        bool poss = true;
        for(map<char,int>::iterator it = m.begin();it!=m.end();it++)
        {
            if(it->second%2!=0)
                poss=false;
        }
        if(poss)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
        return 0;
    }

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int a[100009];
int main()
{
	int n;
	while(scanf("%d",&n)==1)
	{
		for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
		sort(a,a+n);
		int mid=(int)(a[n-1]/2);
		int xc=0,k=a[n-1],res;
		if(n==2)
			printf("%d %d\n",a[1],a[0]);
			else
			{
				for(int i=0;i<n-1;i++)
				{
					xc=fabs(a[i]-mid);
					if(xc<=k)
					{
						k=xc;
						res=a[i];
					}
				}
				printf("%d %d\n",a[n-1],res);
			}
	}
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
using P=pair<int,int>;
int main() {
    int a,b,h;cin>>a>>b>>h;
    cout<<((a+b)*h)/2<<endl;
}


Measured memory_bytes: 3532
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k, h;
  cin >> n >> k;
  priority_queue<ll> q;
  for(int i = 0; i < n; i++) {
    cin >> h;
    q.push(h);
  }
  for(int i = 0; i < k; i++) {
    if (q.empty()) {
      cout << 0 << "\n";
      return 0;
    }
    q.pop();
  }
  ll sum = 0;
  while(!q.empty()) {
    h = q.top();
    q.pop();
    sum += h;
  }
  cout << sum << "\n";
  return 0;
}



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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int a, b, c, d, e, n, m, k;
string s, t, r;
char c1, c2, c3;

int A[200005];
int B[200005];
int C[200005];

int main() {
	cin >>a;
  	int sol = 1000*(a/500);
  a%=500;
  		sol+=5*(a/5);
  cout <<sol<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int N, first, second, third;
    scanf("%d", &N);

    if ((first = N % 10) == 7) {
        printf("Yes\n");
        return 0;
    }
    if ((second = ((N = (N-first)/10) % 10) == 7)) {
        printf("Yes\n");
        return 0;
    }
    if ((second = (((N-second)/10) % 10) == 7)) {
        printf("Yes\n");
        return 0;
    }

    printf("No\n");
    return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    ll N , M ;
    cin >> N >> M ;
    ll X[M] ;
    for(ll i = 0 ; i < M ; i++){
        cin >> X[i] ;
    }
    sort(X, X+M) ;
    if(N >= M){
        cout << 0 << endl;
    }else{
    ll dif[M-1] ;
    for(ll j = 0 ; j < M -1 ; j++){
        dif[j] = abs(X[j] - X[j+1]);
    }

    sort(dif, dif+(M-1) ) ;

    ll ans = 0 ;
    for(ll k = 0 ; k < M - (N ); k++){
        ans += dif[k] ;
    }
    cout << ans << endl;
    }

  
    
    return 0 ;
}

 


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

using namespace std;

#define ll long long

int main(){
	long k, n, dist;
	cin >> k >> n;
	long a[n];
	for(int i=0; i<n; i++)
		cin >> a[i];
	dist = a[n-1] - a[0];
	for(int i=0; i<n-1; i++){
		if(a[i]+k-a[i+1] < dist){
			dist = a[i]+k-a[i+1];
		}
	}
	cout << dist;

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;

int main() {
    ll a, b; cin >> a >> b;
    if ((a + b) % 2 == 0) cout << (a + b) / 2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}


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


int main(){
	int num[100005];
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>num[i];
	}
	sort(num,num+N);
	int pre=0;
	int k=0;
	for(int i=1;i<N;i++){
		if(num[pre]!=num[i]){
			if((i-pre)%2!=0){
				k++;
			}
			pre=i;
		}
	}
	if((N-pre)%2!=0){
		k++;
	}
	cout<<k;
	return 0;
} 

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

int main(){
    long a, b, i;
    long count = 1;
    cin >> a >> b;
    long aa = a;
    long bb = b;
    if(a%2 == 0 && b%2 == 0) count++;
    while(a%2 == 0) a = a/2;
    while(b%2 == 0) b = b/2;

    for(i = 3;i <= min(sqrt(aa), sqrt(bb));i+= 2){
        if(a%i == 0 && b%i == 0) count++;
        while(a%i == 0) a = a/i;
        while(b%i == 0) b = b/i;
    }
    if(a != 1 && b != 1 && a == b) count++;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long K,N,max=0;
    cin >> K >>N;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        if(i != N-1){
            if(max<A[i+1]-A[i]){
                max = A[i+1]-A[i];
            }
        }else{
            if(max<K+A[0]-A[i]){
                max=K+A[0]-A[i];
            }
        }
    }
    cout << K - max;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
#define rep(k,i,n) for(ll i=k;i<n;++i)
ll const mod=1e9+7;
ll mpow(ll a,ll b){return b?mpow(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(void){
    ll n;
    cin>>n;
    ll c=0;
    map<p,p>m;
    rep(0,i,n){
        ll a,b;
        cin>>a>>b;
        if(!a&&!b)++c;
        else{
            ll g=gcd(a,b);
            a/=g,b/=g;
            if(b<0)b=-b,a=-a;
            if(a<=0)m[{b,-a}].first++;
            else m[{a,b}].second++;
        }
    }
    ll ans=1;
    for(auto u:m)ans=ans*(mpow(2,u.second.first)+mpow(2,u.second.second)-1+mod)%mod;
    ans+=c;
    cout<<(ans-1+mod)%mod;
}

Measured memory_bytes: 19036
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	int ma = -INF, mi = INF;
	int maPos = 0, miPos = 0;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		
		if (a > ma) {
			ma = a;
			maPos = i;
		}
		if (a < mi) {
			mi = a;
			miPos = i;
		}
	}

	cout << 2 * n - 1 << endl;
	if (abs(ma) >= abs(mi)) {
		for (int i = 0; i < n; i++) {
			cout << maPos + 1 << " " << i + 1 << endl;
		}
		for (int i = 0; i < n - 1; i++) {
			cout << i + 1 << " " << i + 2 << endl;
		}
	} else {
		for (int i = 0; i < n; i++) {
			cout << miPos + 1 << " " << i + 1 << endl;
		}
		for (int i = n - 1; i >= 1; i--) {
			cout << i + 1 << " " << i << endl;
		}
	}
	return 0;
}


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

//Function Macros:
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if (i * j == n)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right

N,K = [int(zz) for zz in input().split()]
A = [int(zz) for zz in input().split()]

B = sorted(A)

C = []
for i in range(N):
    p = bisect_left(B,A[i])
    C.append(p)

q = 0
for i in range(N):
    for j in range(i,N):
        if A[i] > A[j]:
            q += 1

ans = q*K+sum(C)*((K*(K-1))//2)
print(ans%(10**9+7))


Measured memory_bytes: 3188
#include <stdio.h>

int main() {
    int N, T, c, t;
    int cost = 1001;

    scanf("%d %d", &N, &T);
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &c, &t);

        if (t <= T) {
            if (cost > c) {
                cost = c;
            }
        }
    }

    if (cost == 1001) {
        printf("TLE\n");
    } else {
        printf("%d\n", cost);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    
    long long N,M,ans,x=1;

    cin >> N >> M;

    for(int i=1;i<=M;i++){
        x*=2;
    }

    ans = M*1900 + (N-M) * 100;

    ans *= x;

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define FF first
#define SS second
#define pii pair<int,int>
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(x) (int)x.size()
#define mp make_pair
#define Mod 1000000007
typedef long long int ll;
// g++ -DLOCAL -std=c++17 -Wshadow -Wall  "codeforces.c++" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g

// dp[i] -> store result whether present player playing the tuen is able to win or not if i stones left

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// #endif

	int n, k, i, j;
	cin >> n >> k;

	vector<int> a(n);
	for(int &x : a)
		cin >> x;

	vector<vector<int>> dp(n+1, vector<int>(k+1));
	vector<int> prefix(k+1, 0);

	dp[0][0] = 1;
	for(j = 1; j <= k; j++)
		dp[0][j] = 0;

	for(i = 1; i <= n; i++){
		// vector<int> prefix(k+1, 0);
		prefix[0] = dp[i-1][0];
		for(j = 1; j <= k; j++)
			prefix[j] = (prefix[j-1]%Mod + dp[i-1][j])%Mod;

		for(j = 0; j <= k; j++)
			if(j > a[i-1])
				dp[i][j] = (Mod + prefix[j] - prefix[j - a[i-1] - 1])%Mod;
			else
				dp[i][j] = prefix[j];
	}

	cout<<dp[n][k]<<"\n";

}	


Measured memory_bytes: 40192
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

//閉路やばそう
//閉路の総和がPより大きいとヤバそう
//小さい場合は閉路を回る必要がないが

//閉路判定以外やるだけでは？

struct edge {
	int to; ll cost;
};
vector<edge> G[2500];
ll score[2500];
void solve() {
	int a, b; cin >> a >> b;
	cout << max({ a + b,a - b,a*b }) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
	//stop
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<vector<pair<int , int>>> s(n+1);
    for(int i=1 ; i<=n ; i++)
    {
        int aux;
        cin >> aux;
        for(int j=0 ; j<aux ; j++)
        {
            int x , y;
            cin >> x >> y;
            s[i].push_back({x , y});
        }
    }
    int ans=0;
    for(long long i=0 ; i<1LL<<n ; i++)
    {
        int hon=0 , curr = 0 , v[20];
        for(int j=0 ; j<=n ; j++)
            v[j] = 0;
        bool ok = true;
        long long aux = i;
        while(aux)
        {
            curr++;
            v[curr] = aux%2;
            aux /= 2;
            if(v[curr] == 1) hon++;
        }
        if(hon <= ans) continue;
        for(int j=1 ; j<=n ; j++)
            if(v[j])
                for(int l=0 ; l<s[j].size() ; l++)
                    if(s[j][l].second != v[s[j][l].first])
                        ok = false;
        if(ok) ans = max(ans , hon);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
using namespace std;


ll gcd(ll a, ll b)   //Function to find gcd of two numbers
{
    if (a == 0)
    return b;
    return gcd(b % a, a);
}

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

    string str,t;
    cin>>str>>t;

    int ans = t.size();

    for(int start=0;start<=(str.size() - t.size());start++)
    {
        int diff=0;

        for(int i=0;i<t.size();i++)
        {
            if(t[i]!=str[start+i])
            diff++;
        }

        ans = min(ans,diff);
    }

    cout<<ans<<endl;

    
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int k, n;
        cin >> k >> n;
        vector<int> a(2 * n);
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        for(int i = n; i < 2 * n; i++){
            a[i] = a[i - n];
        }
        int ans[n][2];
        for(int i = 0; i < n; i++){
            ans[i][0] = (a[i + n - 1] - a[i] + k) % k;
        }
        reverse(all(a));
        for(int i = 0; i < n; i++){
            ans[i][1] = (a[i] - a[i + n - 1] + k) % k;
        }
        int mn = INF;
        for(int i = 0; i < n; i++){
            mn = min(mn, ans[i][0]);
            mn = min(mn, ans[i][1]);
        }
        cout << mn << '\n';
        /*
        5 10 15 5 10 15
        15 10 5 15 10 5
         */
    }
}

Measured memory_bytes: 37760
#include <stdio.h>
int main(void){
    // Your code here!
    long long int x, k,kk, dd, d, i, ii, tmp = 0;
    scanf("%lld%lld%lld", &x, &k, &d);
    if (x < 0)
        x *= -1;
    kk = k; dd = d;
    while (kk > 0)
    {
        kk /= 10;
        tmp++;
    }
    while (dd > 0)
    {
        dd /= 10;
        tmp++;
    }
    if (x > k * d && tmp < 18)
        printf("%lld", x - k * d);
    else if ((k - x / d) % 2)
        printf("%lld", d - x % d);
    else
        printf("%lld", x % d);
}


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

using namespace std;

int main(){
	int N,A,B,C,X;
	int cnt,maxFlame,nextFlameNum;
	int Y[10001];
	int R[10001];
	
	while(cin>>N>>A>>B>>C>>X,N||A||B||C||X){
		 
		 cnt=0;
		 maxFlame=0;
		 nextFlameNum=0;
		 
		 fill(Y,Y+10001,0);
		 fill(R,R+10001,0);
		 
		 for(int i=0;i<N;i++){
		 	cin>>Y[i];
		 }
		 
		 //乱数
		 R[0]=X;
		 for(int i=1;i<10001;i++){
		 	R[i]=(A*R[i-1]+B)%C;
		 }
		 
		 
		 for(int i=0;i<N;i++){
			 for(int j=nextFlameNum;j<=10001;j++){
		 		if(Y[i]==R[j]){
						maxFlame=j;
						nextFlameNum=j+1;
		 				cnt++;
						break;
		 		}
		 	}
		 }
		 if(cnt!=N){
		 	cout<<-1<<endl;
		 }
		 else{
		 	cout<<maxFlame<<endl;
		 }
	}
}

Measured memory_bytes: 1236
import sys
input = sys.stdin.readline

N, K = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

for i in range(N):
    p[i] = (1 + p[i]) * p[i] / 2 / p[i]

import itertools
cumsum = list(itertools.accumulate(p))
cumsum = [0] + cumsum
ans = []

for i in range(K, N + 1):
    ans.append(cumsum[i] - cumsum[i - K])
    

print(max(ans))


Measured memory_bytes: 85068
#include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
g=0;
while(g<3){
cin >>a;
cin >>b;
cin >>c;
cin >>d;
cin >>e;
cin >>f;
if(c>f){f=f+60; e=e-1;}
if(b>e){e=e+60; d=d-1;}
h=d-a;
i=e-b;
j=f-c;
cout <<h<<" "<<i<<" "<<j<<endl;
g=g+1;}}

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

long long unsigned int mod = 1000000007;

// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
long long unsigned int PowMod( long long unsigned int base, long long unsigned int index, long long unsigned int modulo = mod ){
    if( index == 0 ) return 1;
    // O( log(index) )
    if( index % 2 ){
        return base * PowMod(base, index - 1, modulo) % modulo;
    }else{
        long long unsigned int Phalf = index / 2;
        long long unsigned int half = PowMod(base, Phalf, modulo);
        return half * half % modulo;
    }
}
// }}}

// Comb( n, r, modulo ) return nCr % modulo {{{
// Comb(ination) = nCr % mod ( natural number )
long long unsigned int Comb( long long unsigned int n, long long unsigned int r, long long unsigned int modulo = mod){
    if( n < r ) return Comb(r,n,modulo);
    long long unsigned int Upper = 1;
    long long unsigned int Lower = 1;
    for(long long unsigned int i = 0; i < r; i++){
        Upper = Upper * (n-i) % modulo;
        Lower = Lower * (i+1) % modulo;
    }
    // Return (Upper / Lower)
    long long unsigned int ret = Upper * PowMod(Lower,modulo-2,modulo) % modulo;
    return ret;
}
// }}}

// Fact( n, modulo ) return n! % modulo {{{
// Fact(orial) = n! % mod ( natural number )
long long unsigned int Fact( long long unsigned int n, long long unsigned int modulo = mod){
    long long unsigned int Upper = 1;
    for(long long unsigned int i = 0; i < n; i++){
        Upper = Upper * (n-i) % modulo;
    }
    return Upper;
}
// }}}

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {


    int n,m;

    Scd2(n,m);

    ll ans = 0;
    if( n == m ){
        ans = Fact(n) * Fact(m) * 2 % mod;
    }else if( n+1 == m  ||  n == m+1 ){
        ans = Fact(n) * Fact(m) % mod;
    }

    printf ("%llu\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std; 
#define endl "\n"
int main() 
{
//	ios::sync_with_stdio(0);
//	cin.tie(0);
    long long int i,j,l,inc,dec,t,r,mod=1000000007;
   	long long int c,d,q,e,ans=0,n,temp,m,p,w,h,k,x,y;
//	cin>>t;
	t=1;
	while(t--)
	{
		string s,t;
		cin>>s;
		cin>>t;
		n=s.size();
		m=t.size();
		long long int a[n+1][m+1];
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=m;j++)
			{
				if(i==0 || j==0)
				{
					a[i][j]=0;
				}
				else if(s[i-1]==t[j-1])
				{
					a[i][j]=1+a[i-1][j-1];
				}
				else
				{
					a[i][j]=max(a[i-1][j],a[i][j-1]);
				}
			}
		}
		string res="";
		i=n;
		j=m;
		while(i>0 && j>0)
		{
			if(s[i-1]==t[j-1])
			{
				res=res+s[i-1];
				i--;
				j--;
			}
			else if(a[i][j-1]==a[i][j])
			{
				j--;
			}
			else
			{
				i--;
			}
		}
		reverse(res.begin(),res.end());
		cout<<res<<endl;
		
	}

   return 0;
}
/*
1
5
1 1 6 1 6

*/


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

std::vector<std::vector<long>> memo(101, std::vector<long>(4, -1));
long nCr(const int& n, const int& r) {
  if (n <= 0 || r < 0) return 0;
  if (r == 1) return n;
  if (n == r) return 1;
  if (n < r) return 0;
  if (memo[n][r] != -1) return memo[n][r];
  return memo[n][r] = nCr(n-1, r) + nCr(n-1, r-1);
}

unsigned long long answer(const int& num, const std::string& S, const int& K, const int& S_size) {
  if (K == 1) {
      if (S_size - num < 1) return 0;
      if (S[num] == '0') return answer(num+1, S, K, S_size);
      return (S_size - num - 1)*9 + (S[num]-'0');
  } else if (K == 2) {
      if (S_size - num < 2) return 0;
      if (S[num] == '0') return answer(num+1, S, K, S_size);
      return (nCr(S_size - num-1, 2)*81 + (S[num]-'0'-1)*9*nCr(S_size - num - 1, 1) + answer(num+1, S, K-1, S_size));
  } else { // K == 3
      if (S_size - num < 3) return 0;
      return (nCr(S_size - num-1, 3)*729 + (S[num]-'0'-1)*81*nCr(S_size-num-1, 2) + answer(num+1, S, K-1, S_size));
  }
}

int main(int argc, char** argv) {
  std::string N;
  int K;
  std::cin >> N >> K;

  std::cout << answer(0, N, K, N.size()) << '\n';
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll a,b,c,k,sum=0,s=0;
        cin>>a>>b>>c>>k;
        if(k>a)
        {
            sum=a;
            s=k-a;
            if(s>b)
            {
                s=s-b;
                sum=sum-s;
                cout<<(ll)sum;
            }
            else
            {
                cout<<(ll)a;
            }
        }
        else
        {
            cout<<k;
        }
        
    }        
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;

///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/// ⸜( ⌓̈ )⸝ ///

int main() {
    ll N,X,M; cin >> N >> X >> M;
    vector<ll> index(M + 2);
    vector<ll> XX(M+2);

    REP(i,M+2){index[i] = -1;}
    ll Xs = X;
    ll nsum = 0;
    ll lstart,lend;
    lstart = -1;
    lend = -1;
    REP(i,100000){
        if (i) Xs = (Xs * Xs) % M;
        nsum += Xs;
        XX[i] = Xs;
        //DB2(i,XX[i]);
        //DB2(i,nsum);
        if (index[Xs] != -1){
            lstart = index[Xs];
            lend = i - 1;
            break;
        }
        index[Xs] = i;
    }
    //DB2(lstart,lend);

    ll ans = 0;
    if (lstart != -1){
        ll loopsize = lend - lstart + 1;
        ll loopcount = (N - lstart) / loopsize;
        ll rest = (N - lstart) % loopsize;

        REP(i,lstart){
            ans += XX[i];
        }

        REP(i,rest){
            ans += XX[lstart+i];
        }

        ll loopsum = 0;
        FORq(i,lstart,lend){
            loopsum += XX[i];
        }
        ans += loopsum * loopcount;
    }else{
        REP(i,N){
            ans += XX[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4856
def main():
    h, w = map(int, input().split())
    coord = []
    coord.append([0] * (w + 2))
    for _ in range(h):
        coord.append([0] + list(input()) + [0])
    coord.append([0] * (w + 2))

    dys = [-1, -1, 0, 1, 1, 1, 0, -1]
    dxs = [0, 1, 1, 1, 0, -1, -1, -1]

    for y in range(1, h + 1):
        for x in range(1, w + 1):
            if coord[y][x] == '#':
                continue

            coord[y][x] = 0
            for dy, dx in zip(dys, dxs):
                if coord[y + dy][x + dx] == '#':
                    coord[y][x] += 1

    for row in coord[1:-1]:
        print(''.join(map(str, row[1:-1])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <atcoder/all>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back

using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<ll, ll>;
using mint = modint1000000007;

//RMQ
struct SegmentTree{
    private:
        int n;
        vector<int> node;

    public:
        //元配列vをセグ木で表現する
        SegmentTree(vector<int> v){
            int vsz = v.size();
            n = 1;
            while(n < vsz)n *= 2;
            node.resize(2 * n - 1, 0);
        
            //配列の最下層
            rep(i, vsz) node[i + n - 1] = v[i];
            //上の層の値を下の層からもらってる
            for(int i = n - 2; i >= 0; i--)node[i] = min(node[2 * i + 1], node[2 * i + 2]);
        }
        
        void update(int x, int val){
            //最下層の値にアクセス
            x += (n - 1);
            node[x] = val;
            //上に上がって更新していく
            while(x > 0){
                x = (x - 1) / 2;
                node[x] = max(node[2 * x + 1], node[2 * x + 2]);
            }
        }

        int get(int a, int b, int k = 0, int l = 0, int r = -1){
            if(r < 0)r = n;
            //満たさないケース
            if(r <= a || b <= l)return 0;
            //base-case
            if(a <= l && r <= b)return node[k];

            int vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
            int vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
};


int main(){
    ll n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    SegmentTree seg(vector<int>(300300));
    rep(i, n){
        int ma = seg.get(a[i] - k, a[i] + k + 1);
        seg.update(a[i], ma + 1);
    }
    cout << seg.get(0, 300300) << endl;
}

Measured memory_bytes: 9568
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    return arr


n = int(input())
factors = factorization(n)

ans = 0
for factor, count in factors:
    use = 1
    possible = count
    while possible >= use:
        possible -= use
        use += 1
        ans += 1

print(ans)


Measured memory_bytes: 9440
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    
    let mut m: HashMap<char, u32> = HashMap::new();
    for c in buf.trim().chars() {
        if let Some(x) = m.get_mut(&c) {
            *x += 1;
            continue;
        }
        m.insert(c, 1);
    }
    
    if m.values().all(|c| c % 2 == 0) {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;
int main()
{
	int i, j, m, n, cnt = 0, cnt1 = 0;
	char str[6002];
	for (i = 0; i < 3000; i = i + 2) {
		str[i] = '#';
		str[i + 1] = '.';
	}
	while (1) {
		scanf("%d %d", &m, &n);
		if (m == 0 && n == 0) {
			break;
		}
		for (i = 0; i < m; i++) {
			for (j = 0; j < n; j++) {
				if (i % 2 == 0) {
					printf("%c", str[j]);
				}
				else {
					printf("%c", str[j + 1]);

				}
				if (j == j - 1) {
					printf(" ");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

template<typename T>
void maxi(T &a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T b) {
	a = min(a, b);
}

int main() {
	int ans = 0;
	makei(N);
	makei(K);
	--K;
	rep(N) {
		makei(a);
		if (a == 1) {
			int tmp = 0;
			ans += i / K;
			tmp += i % K;
			ans += (N - i - 1) / K;
			tmp += (N - i - 1) % K;
			if (tmp > 0) {
				if (tmp > K)ans += 2;
				else ++ans;
			}
		}
	}
	say(ans);
}

Measured memory_bytes: 256
@D=map[glob<>],@@=0..$'-<>=~$";map{for$x(split){$k=$j++%3;$$k[$_]+=$D[$x-1][$_]for@@}$j=++$i}<>;$\=1e15;for$i(@@){for$j(@@){$\-=$-=$i-$j&&$i-$_&&$j-$_&&$\-$0[$i]-$1[$j]-$2[$_]for@@}}print

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdint>
#define rep(ident, start, end) for(int ident=start;ident<end;ident++)

using namespace std;

int main(void){
	int N, i;
	cin >> N >> i;
	cout << N - i + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long inf = 1000000000000;
int mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int n, m;
	cin >> n >> m;
	int i;
	bool breaks[110000];
	for (i = 0; i < m; i++) {
		int a;
		cin >> a;
		breaks[a]++;
	}
	int stairs[110000];
	stairs[0] = 1;
	for (i = 0; i <= n; i++) {
		if (breaks[i]) continue;
		if (!breaks[i + 1]) {
			stairs[i + 1] += stairs[i];
			stairs[i + 1] %= mod;
		}
		if (!stairs[i + 2]) {
			stairs[i + 2] += stairs[i];
			stairs[i + 2] %= mod;
		}
	}
	cout << stairs[n];
	return(0);
}

Measured memory_bytes: 768
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++)
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
int n;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		m -= a[i];
	}
	Sort(a);

	int ans = n;
	ans += m / a[0];
	cout << ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def solve():
  n = int(readline())
  num_list = list(map(int, input().split()))

  for a in num_list:
    if a == 0:
      print(0)
      return


  base = 10**18
  ans = 1

  for a in num_list:
    ans *= a
    if ans > base:
      print(-1)
      return

  print(ans)

solve()

Measured memory_bytes: 21668
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> Vec;
void rotatex(Vec &a){
  int tmp;
  tmp=a[0];a[0]=a[1];a[1]=a[2];a[2]=a[3];a[3]=tmp;
  tmp=a[4];a[4]=a[5];a[5]=a[6];a[6]=a[7];a[7]=tmp;
}

void rotatey(Vec &a){
  int tmp;
  tmp=a[0];a[0]=a[1];a[1]=a[5];a[5]=a[4];a[4]=tmp;
  tmp=a[3];a[3]=a[2];a[2]=a[6];a[6]=a[7];a[7]=tmp;
}

void rotatez(Vec &a){
  int tmp;
  tmp=a[0];a[0]=a[4];a[4]=a[7];a[7]=a[3];a[3]=tmp;
  tmp=a[1];a[1]=a[5];a[5]=a[6];a[6]=a[2];a[2]=tmp;
}

int main(){
  string s[8];
  set<Vec> sv;
  map<Vec,bool> mv;
  while(cin>>s[0]){
    int i,j,k,ans=0;
    sv.clear();mv.clear();
    for(i=1;i<8;i++) cin>>s[i];
    sort(s,s+8);
    set<string> ss;
    Vec v;
    for(i=0;i<8;i++) ss.insert(s[i]),v.push_back(ss.size()-1);
    do{
      for(i=0;i<4;i++){
	rotatez(v);
	for(j=0;j<4;j++){
	  rotatey(v);
	  for(k=0;k<4;k++){
	    rotatex(v);
	    sv.insert(v);
	  }
	}
      }
    }while(next_permutation(v.begin(),v.end()));
    for(Vec a:sv){
      if(mv[a]) continue;
      ans++;
      for(i=0;i<4;i++){
	rotatez(a);
	for(j=0;j<4;j++){
	  rotatey(a);
	  for(k=0;k<4;k++){
	    rotatex(a);
	    mv[a]=1;
	  }
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 12552
#include <bits/stdc++.h>
//#include <cstdio>
//#include <cstring>
//#include <iostream>
//#include <algorithm>
using namespace std;
typedef long long ll;
const  int maxx=1e6+100;
const int INF=1e9;
const int MOD=1e9+7;
int a[maxx],b[maxx],c[maxx];
int main()
{
    int n;
    scanf("%d",&n);
    int k;
    for(int i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    for(int i=0; i<n; i++){
        scanf("%d",&b[i]);
    }
    for(int i=0; i<n; i++){
        scanf("%d",&c[i]);
    }
    sort(a,a+n);
    sort(c,c+n);
    ll u,v;
    ll ans=0;
    for(int i=0; i<n; i++){
        u=lower_bound(a,a+n,b[i])-a;
        v=n-(upper_bound(c,c+n,b[i])-c);
        //cout<<"*"<<u<<" "<<v<<endl;

        ans+= u*v;

    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 9340
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> T(N), V(N);
    rep(i, N) cin >> T[i];
    rep(i, N) cin >> V[i];
    vector<int> S(N + 1, 0);
    rep(i, N) S[i + 1] = S[i] + T[i];
    vector<int> dp(S[N] + 1, inf);
    vector<int> vm(S[N]);
    rep(i, N){
        rep(j, S[i], S[i + 1]){
            vm[j] = V[i];
        }
    }
    rep(i, N){
        rep(j, S[N] + 1){
            int now = V[i] + min(abs(S[i] - j), abs(S[i + 1] - j));
            if(S[i] <= j && j <= S[i + 1]) now = V[i];
            dp[j] = min(dp[j], now);
        }
    }
    rep(i, S[N] + 1){
        dp[i] = min(dp[i], i);
        dp[i] = min(dp[i], S[N] - i);
    }
    double ret = 0;
    rep(i, S[N]){
        if(dp[i] == dp[i + 1] && dp[i] < vm[i]){
            ret += (double)dp[i] + 0.25;
        }
        else{
            ret += (double)(dp[i] + dp[i + 1]) / 2.0;
        }

    }
    
    output(ret, 10);
    
    return 0;
}


Measured memory_bytes: 384
from collections import *
n,m = map(int,input().split())
par = [-1 for _ in range(n)]#par<0なら自身が親で要素の個数、>0なら子で親の位置示す

def root(i):
    if par[i] < 0:
        return i
    else:
        return root(par[i])

def size(a):
    return -par[root(a)]

def union(a,b):
    a = root(a)
    b = root(b)
    if a == b:#親が等しい
        return False
    if size(a) < size(b):#サイズが大きい方に繋げる
        a,b = b,a
    par[a] += par[b]
    par[b] = a
    return True

for i in range(m):
    a = [int(j)-1 for j in input().split()]#数字を一つ減らして足を揃える
    if root(a[0]) != root(a[1]):
        union(a[0],a[1])
print(max([ size(i) for i in par]))

Measured memory_bytes: 22640
#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>;

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool ng = false;
  rep(i,n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || MX/ans < a) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

vector<map<int, int> > S;
map<int, int> L;

bool check(int l, int r, int d) {
    int ls = L[l];
    int rs = L[r];
    if(ls==0 && rs==0) {
        S.emplace_back();
        L[l] = S.size();
        L[r] = S.size();
        map<int, int> & s = S.back();
        s[l] = 0;
        s[r] = d;
        return true;
    }
    if(ls==0) {
        L[l] = rs;
        map<int, int> & s = S[rs-1];
        s[l] = s[r] - d;
        return true;
    }
    if(rs==0) {
        L[r] = ls;
        map<int, int> & s = S[ls-1];
        s[r] = s[l] + d;
        return true;
    }
    if(ls==rs) {
        map<int, int> & s = S[ls-1];
        return s[r]==s[l]+d;
    }
    map<int, int> & s = S[ls-1];
    map<int, int> & s2 = S[rs-1];
    if(s2.size()<s.size()) {
        int d2 = s[l] - s2[r] + d;
        for(pair<const int, int> & v : s2) {
            s[v.first] = v.second + d2;
            L[v.first] = ls;
        }
        s2.clear();
    }
    else {
        int d2 = s2[r] - s[l] - d;
        for(pair<const int, int> & v : s) {
            s2[v.first] = v.second + d2;
            L[v.first] = rs;
        }
        s.clear();
    }
    return true;
}

int main() {
    int N, M;
    scanf("%d%d", &N, &M);
    for(int m=0; m<M; ++m) {
        int l, r, d;
        scanf("%d%d%d", &l, &r, &d);--l;--r;
        if(!check(l, r, d)) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 13616
#include <stdio.h>

int main(void) {
  int i;
  int N, M;
  int Lmax,Rmin;
  scanf("%d %d", &N, &M);
  int L[M+1], R[M+1];

  for(i=1;i<=M;i++){
    scanf("%d %d", &L[i], &R[i]);
  }
  Lmax=L[1];
  Rmin=R[1];

  for(i=1;i<=M;i++){
    if(Lmax<L[i]) Lmax=L[i];
    if(Rmin>R[i]) Rmin=R[i];
  }

  if(Lmax>Rmin){
    printf("0\n");
  }else{
    printf("%d\n", Rmin-Lmax+1);
  }
  return 0;
}


Measured memory_bytes: 896
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        S=str(input())
        ls=len(S)

        if S=='keyence':
            return 'YES'
        else:



            for i in range(ls):
                for j in range(i+1,ls):
                    if S[:i]+S[j:]=='keyence':
                        return 'YES'
            return 'NO'
    print(main())



resolve()

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,i,ans;
	cin>>a>>b;
	if (b==1)
	{
		cout<<0<<endl;
		return 0;
	}
	for(i=1;i<=100;i++)
	{
		if (a*i-(i-1)>=b)
		{
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256