akhauriyash/Code-Regression huggingface dataset:
n = int(input())
P = [int(x) for x in input().split()]
count = 0

for i in range(n-2):
  if (P[i] < P[i+1]) and (P[i+1] < P[i+2]):
    count += 1
  elif (P[i] > P[i+1]) and (P[i+1] > P[i+2]):
    count += 1

print(count)

Measured memory_bytes: 9116
#include <stdio.h>

int main(void)
{
	int H, W, h, w;

	if (scanf("%d %d", &H, &W) == EOF) return 0;
	if (scanf("%d %d", &h, &w) == EOF) return 0;

	int ans = (H*W)- ((H*w) + (W * h) - (w*h));

	printf("%d\n",ans);
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n,k,cnt int
	fmt.Scan(&n,&k)
	
	heights := make([]int,n)
	for i:= 0; i < len(heights); i++ {
		fmt.Scanf("%d",&heights[i])
		if heights[i] >= k {
			cnt++
		}
	}
	
	fmt.Printf("%d",cnt)
}

Measured memory_bytes: 5504
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    cout << ceil((sqrt(8 * X + 1) - 1) / 2.0) << "\n";
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

long long gcd(long long a, long long b) {
	if (b == 0) return a;
	 return gcd(b, a%b);
}

long long lcm(long long a, long long b) {
	long long g = gcd(a, b);
	return a / g * b;
}

int main() {
	long long n;
	std::cin >> n;
	long long ans = 1;
	long long a;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		ans = lcm(a, ans);
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <map>
#include <set>
#define SIZE 200005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char A[SIZE];
int cnt[30];

int main()
{
	scanf("%s",&A);
	int n=strlen(A);
	ll ret=(ll) n*(ll) (n+1)/2LL;
	for(int i=0;i<n;i++) cnt[A[i]-'a']++;
	for(int i=0;i<29;i++) ret-=(ll) cnt[i]*(ll) (cnt[i]+1)/2LL;
	printf("%lld\n",ret+1);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
char T[9]; int p;
int main() {
	while (cin >> T[0]) {
		for (int i = 1; i < 9; i++) { cin >> T[i]; }
		for (int i = 0; i < 3; i++) {
			if (T[i]!='s' && T[i] == T[i + 3] && T[i] == T[i + 6]) { p = i; goto E; }
		}
		for (int i = 0; i < 9; i += 3) {
			if (T[i]!='s' && T[i] == T[i + 1] && T[i + 1] == T[i + 2]) { p = i; goto E; }
		}
		if (T[4]!='s' && T[0] == T[4] && T[4] == T[8]) { p = 4; goto E; }
		if (T[4]!='s' && T[2] == T[4] && T[4] == T[6]) {
			p = 4; goto E;
		}
		cout << "d" << endl; goto F;
	E:;
		if (T[p] == 'o') { cout << 'o' << endl; }
		if (T[p] == 'x') { cout << 'x' << endl; }
	F:;
	}
}

Measured memory_bytes: 1132
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<string>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int maxn = (int)(2e5) + 7;
const int maxm = 300;

int n, a[maxn], b[maxn], pre[maxn]; 

int main() {
	
	// freopen("in.in", "r", stdin);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		pre[i] = (pre[i - 1] ^ a[i]);
	}
	for (int i = 1, j = n; i <= n / 2; i++, j--) {
		int t = pre[n] ^ a[i] ^ a[j];
		b[j] = (a[i] ^ t);
		b[i] = (a[j] ^ t);
	}
	for (int i = 1; i <= n; i++) printf("%d%c", b[i], " \n"[i == n]);

	return 0;
}		


Measured memory_bytes: 5388
#include <stdio.h>
#include <string.h>
#define N 1001
int main(){
  char T[N],P[N];
  int i,j,n,m,flag;
   
  scanf("%s",T);
  scanf("%s",P);
   
  n=strlen(T);
  m=strlen(P);
   
  for(i=0;i<n;i++){
    flag=0;
    for(j=0;j<m;j++){
      if(T[i+j]==P[j]) flag++;
   
    }
    if(flag==m) printf("%d\n",i);
  }
 
  return 0;
}

Measured memory_bytes: 540
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int int32_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX)
{return uniform_int_distribution<int>(l,r)(rng);}

template <typename T,typename G>
ostream& operator << (ostream& out, const pair<T,G> &a) 
{return out<<"( "<<a.x<<", "<<a.y<<")";}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &a) 
{out<<"[ ";for(const auto &i:a)out<<i<<", ";return out<<"]"<<endl;}

template <typename T>
ostream& operator << (ostream& out, const set<T> &a) 
{out<<"{ ";for(const auto &i:a)out<<i<<", ";return out<<"}"<<endl;}

template <typename T,typename G>
ostream& operator << (ostream& out, const map<T,G> &a) 
{out<<"< ";for(const auto &i:a)out<<i<<", ";return out<<">"<<endl;}

template<typename T, size_t N>
typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,
ostream&>::type operator<<(ostream& out, T(&a)[N])
{out<<"[ ";for(size_t i=0;i<N;++i)out<<a[i]<<", ";out <<"]"<<endl;return out;}

void debug_out(){cerr<<endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr<<(H)<<" ";debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr<<"#"<<#__VA_ARGS__<<":\n",debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n,i,x;
	cin>>n;
	set<int> a;
	for(i=0;i<n;i++){
		cin>>x;
		a.insert(x);
	}
	if(int(a.size())==n)
		cout<<"YES\n";
	else
		cout<<"NO\n";
	return 0;
}


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

//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4"

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)4e3;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

int n,dp[maxn][maxn],s[maxn][maxn];
char c[maxn];
main () {
  cin>>n;
  forn(i,1,n-1)
    cin>>c[i];
  forn(i,1,n){
    forn(j,1,i){
      if(i==1){
        dp[i][j]=1;
      }else{
        if(c[i-1]=='>')
          dp[i][j]=(s[i-1][i-1]-s[i-1][j-1]+mod)%mod;
        else
          dp[i][j]=s[i-1][j-1];
      }
      s[i][j]=(s[i][j-1]+dp[i][j])%mod;
    }
  }
  int ans=0;
  forn(i,1,n)
    ans=(ans+dp[n][i])%mod;
  cout<<ans;
}

Measured memory_bytes: 187008
#include <iostream>

int diagonal[151][151];

using namespace std;

int main(void){

  for(int i = 0 ; i < 151 ; i++){
    for(int j = 0 ; j < 151 ; j++){
      diagonal[i][j] = i * i + j * j;
    }
  }

  while(1){
    int h, w;
    cin >> h;
    cin >> w;
    if(h == 0 && w == 0) {return 0;}

    int tmp = h * h + w * w;
    bool find = false;

    for(int i = h ; i < 151 && !find ; i++){
      for(int j = 1 ; j < 151 && !find ; j++){
        if(diagonal[i][j] == tmp && i < j && !(i == h && j == w)){
          find = true;
          cout << i << " " << j << endl;
        }
      }
    }

    for(int step = 1 ; !find ; step++){
      for(int i = 1 ; i < 151 && !find ; i++){
        for(int j = 1 ; j < 151 && !find ; j++){
          if(diagonal[i][j] == tmp + step && i < j && !(i == h && j == w)){
            find = true;
            cout << i << " " << j << endl;
          }
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<string>
using namespace std;
long long gcd(long long a, long long b)
{
	return b == 0 ? a : (gcd(b, a % b));
}
int main()
{
	long long a = 0, b = 0;
	cin >> a >> b;
	long long numgcd = gcd(a, b);
	long long numlcd = a / numgcd * b;
	cout << numlcd;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>

using namespace std;

std::vector<int> solve(const std::vector<int>& as) {
  int const n = as.size();
  if (n == 1) {
    return as;
  }

  std::vector<int> ret(n);
  int i = 0;
  int j = n - 1;
  bool flag = true;
  for (auto const a : boost::adaptors::reverse(as)) {
    if (flag) {
      ret[i++] = a;
    } else {
      ret[j--] = a;
    }
    flag = !flag;
  }
  return ret;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> as(n);
  for (auto& a : as) {
    std::cin >> a;
  }
  bool doneFirst = false;
  for (auto const b : solve(as)) {
    if (doneFirst) {
      std::cout << " ";
    }
    std::cout << b;
    doneFirst = true;
  }
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int N = 100001;
int main(){
  int ans[N]; 

  for(int i=0;i<N;i++) ans[i] = 100000;

  ans[0] = 0;

  for(int i=1;i<N;i++){
    ans[i] = ans[i-1]+1;
    int k = 9;
    while(k<=i){
      ans[i] = min(ans[i], ans[i-k]+1);
      k *= 9;
    }
    k = 6;
    while(k<=i){
      ans[i] = min(ans[i], ans[i-k]+1);
      k *= 6;
    }
  }

  int n;
  cin >> n;
  cout << ans[n] <<endl;

  return 0;
}

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

int pp[8]={1,2,3,4,5,6,7,8};

int main() {
    int N,i,a,b,c=0;
    cin >> N;
    vector<int> P(N),Q(N);

    for(i=0; i<N; i++)
        cin >> P.at(i);
    for(i=0; i<N; i++)
        cin >> Q.at(i);
    
    do {
        c++;
        for(i=0; i<N; i++)
            if(P.at(i) != pp[i])
                break;
        if(i == N)
            a = c;
        for(i=0; i<N; i++)
            if(Q.at(i) != pp[i])
                break;
        if(i == N)
            b = c;
    } while(next_permutation(pp, pp+N));

    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
process.stdin.setEncoding( 'utf8' );

process.stdin.on( 'readable', function() {
    var chunk = process.stdin.read();
    var inputLineArr;

    if ( chunk !== null ) {
        inputLineArr = chunk.split('\n');

        if( inputLineArr[inputLineArr.length-1] == '' )
            inputLineArr.pop();

        var num = inputLineArr[0].split(' ').map( function( elem ) {
            return elem;
        } );

        var s = num[0]

        console.log( handle( s.slice( 0, s.length-1 ) ) )
    }
} );

function handle ( s ) {
    if ( s.length % 2 === 0 ) {
        var delta = s.length / 2
        for ( var i = 0; i < s.length / 2; i++ ) {
            if ( s[i] !== s[i+delta] ) {
                return handle( s.slice( 0, s.length-2 ) )
            }
        }

        return s.length
    } else {
        return handle ( s.slice( 0, s.length-1 ) )
    }
}


Measured memory_bytes: 7500
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);
function main(){
  var n = next(1);
  var k = next();
  var m = n.length;
  var dp = xArray(0,m,10,k+1,2);
  for(var i = 1; i < +n[0]; i++){
    dp[0][i][1][0] = 1;
  }
  dp[0][+n[0]][1][1] = 1;
  dp[0][0][0][0] = 1;
  for(var i = 1; i < m; i++){
    var t = +n[i];
    for(var j = 0; j <= k; j++){
      for(var x = 0; x <= 9; x++){
        if(t === 0){
          dp[i][0][j][1] += dp[i-1][x][j][1];
          dp[i][0][j][0] += dp[i-1][x][j][0];
        }else{
          dp[i][0][j][0] += dp[i-1][x][j][1] + dp[i-1][x][j][0];
        }
        if(j)for(var y = 1; y <= 9; y++){
          if(t < y){
            dp[i][y][j][0] += dp[i-1][x][j-1][0];
          }else if(t === y){
            dp[i][y][j][0] += dp[i-1][x][j-1][0];
            dp[i][y][j][1] += dp[i-1][x][j-1][1];
          }else{
            dp[i][y][j][0] += dp[i-1][x][j-1][0]+dp[i-1][x][j-1][1];
          }
        }
      }
    }
  }
  var ans = 0;
  for(var i = 0; i <= 9; i++)for(var j = 0; j < 2; j++)ans += dp[m-1][i][k][j];
  return ans;
}

Measured memory_bytes: 10288
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	string s;
	cin>>s;
	if(s.size()==3)reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


signed main(){
    int a,b,x;
    cin>>a>>b>>x;
    int ans=b/x;
    if(a)ans-=(a-1)/x;
    else ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
/*input
20
1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=200005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;

ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
ll sub(ll x,ll y){
    return (x % MOD - y % MOD + MOD) % MOD;
}
ll mult(ll a,ll b) 
{ 
    return ((a%MOD)*(b%MOD))%MOD;
} 
#define int ll
int arr[maxn];
int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int ans=0;
    REP(i,n){
        cin>>arr[i];
        ans^=arr[i];
    }
    REP(i,n) arr[i]=(arr[i]|ans)^ans;
    vector<int> v;
    sort(arr,arr+n);
    for(int i=n-1;i>=0;i--){
        for(auto x:v) arr[i]=min(arr[i],arr[i]^x);
        if(arr[i]) v.pb(arr[i]);
    }
    int z=0;
    for(auto x:v) z=max(z,x^z);
    cout<<2*z+ans;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if (s == u) a--;
  else b--;
  printf("%d %d\n", a, b);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

int a[1000005], b[1000005], c[1000005];

signed main(void)
{
	int n; cin >> n;
	rep (i, n) cin >> a[i], b[a[i]]++;
	rep (i, n)
	{
		if (c[a[i]] == 2) continue;
		if (b[a[i]] > 1) c[a[i]] = 2;
		for (int j = 2 * a[i]; j <= 1000000; j += a[i])
		{
			if (b[j]) c[j] = 1;
		}
	}
	int ans = 0;
	rep (i, n) if (!c[a[i]]) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 20776
from collections import Counter

n, *a = map(int, open(0).read().split())
n += 1


def cmb(n, r, mod=10 ** 9 + 7):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


def make_table(n, mod=10 ** 9 + 7):
    N = n
    # 元テーブル
    g1 = [0] * (N + 1)
    g1[0] = 1
    g1[1] = 1

    # 逆元テーブル
    g2 = [0] * (N + 1)
    g2[0] = 1
    g2[1] = 1

    # 逆元テーブル計算用テーブル
    inverse = [0] * (N + 1)
    inverse[0] = 0
    inverse[1] = 1

    for i in range(2, N + 1):
        g1[i] = (g1[i - 1] * i) % mod
        inverse[i] = (-inverse[mod % i] * (mod // i)) % mod
        g2[i] = (g2[i - 1] * inverse[i]) % mod

    return tuple(g1), tuple(g2), tuple(inverse)


d = Counter(a).most_common(1)[0][0]
lr = [i for i, e in enumerate(a) if e == d]
l = lr[1] - lr[0] + 1
g1, g2, inverse = make_table(n)
MOD = 10 ** 9 + 7

answer = [(cmb(n, i, MOD) - cmb(n - l, i - 1, MOD)) % MOD for i in range(1, n + 1)]
print('\n'.join(map(str, answer)))


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


int main()
{string S;
 cin >> S;
 if(S=="Sunny"){cout<<"Cloudy"<< endl;}
 if(S=="Cloudy"){cout<<"Rainy" << endl;}
 if(S=="Rainy"){cout << "Sunny" << endl;}
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using llong = long long;
using ullong = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()
#define loop(i, times) for (llong i = 0; i < times; i++)
#define rloop(i, times) for (llong i = times -1; 0 <= i; i--)

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif

class AGC004B
{
public:
	AGC004B()
	{
		cin >> n_;
		cin >> x_;

		a_.resize(n_);
		loop(i, n_)
			cin >> a_[i];
	}
	void Run(void)
	{
		vector<llong> ax_(n_);
		vector<llong> ans(n_);

		// 初期化
		loop(i, n_)
			ax_[i] = a_[i];
		for (const auto& e : ax_)
			ans[0] += e;
		for(llong k = 1; k < n_; k++)
		{	// 累積和の要領で計算
			loop(i, n_)
			{
				if (0 <= i - k)
					ax_[i] = min(ax_[i], a_[i - k]);
				else
					ax_[i] = min(ax_[i], a_[n_ + (i - k)]);
			}

			for (const auto& e : ax_)
				ans[k] += e;
			ans[k] += x_ * k;
		}

		sort(all(ans));
		cout << ans[0];
	}
private:
	llong n_;
	llong x_;
	vector<llong> a_;
};

int main(void)
{
	AGC004B agc004b;
	agc004b.Run();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




long long D, N;
int main() {
    while (cin >> D >> N) {
        long long res = N;
        if (N == 100) res = 101;
        for (int i = 0; i < D; ++i) res *= 100;
        cout << res << endl;
    }
}



























Measured memory_bytes: 256
d = {"1": [".", ",", "!", "?", " "], "2": ["a", "b", "c"], "3": ["d", "e", "f"],
     "4": ["g", "h", "i"], "5": ["j", "k", "l"], "6": ["m", "n", "o"],
     "7": ["p", "q", "r", "s"], "8": ["t", "u", "v"], "9": ["w", "x", "y", "z"]}

n = int(input())
m = [input() for _ in range(n)]
ans = [[d[cs[0]][len(cs) % len(d[cs[0]]) - 1] for cs in line.split("0") if cs != ""] for line in m]
for a in ans:
    print(*a, sep="")
    

Measured memory_bytes: 8692
local A = {}
for i = 1, 3 do
   A[i] = {}
   for j = 1, 3 do        
        A[i][j] = io.read("*n")
   end
end
local A_bool = {}
for i = 1, 3 do
    A_bool[i] = {}
    for j = 1, 3 do        
        A_bool[i][j] = false
    end
end
local N = io.read("*n")
local b = {}
for i = 1, N do
    b[i] = io.read("*n")
end
for i = 1, N do
    for j = 1, 3 do
        for k = 1, 3 do
            if A[j][k] == b[i] then
                A_bool[j][k] = true
            end
        end
    end
end

local result = "No"
for i = 1, 3 do
    if A_bool[1][i] and A_bool[2][i] and A_bool[3][i] then
        result = "Yes"
    end
end
for i = 1, 3 do
    if A_bool[i][1] and A_bool[i][2] and A_bool[i][3] then
        result = "Yes"
    end
end
if A_bool[1][1] and A_bool[2][2] and A_bool[3][3] then 
    result = "Yes"
end
if A_bool[1][3] and A_bool[2][2] and A_bool[3][1] then 
    result = "Yes"
end

print(result)

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;
  bool ok=false;
  if(s[2]==s[3] && s[4]==s[5]) ok=true;

  prtok(ok);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
//隣り合う文字列の関係は変わらない
int main(){
    string s;
    int q;
    cin>>s>>q;
    string t;
    rep(qi,q){
        int  ty;
        cin>>ty;
        if(ty==1){
            swap(s,t);
        }else{
             int f;
             char c;
             cin >> f >> c;
             if(f == 1){
                t += c;
             }else{
                 s += c;
             }
        }
    }
    reverse(t.begin(),t.end());
    t+=s;
    cout<< t <<endl;
    return 0;
}

Measured memory_bytes: 1128
def z_algolithm(S, x):
    length = len(S) - x
    A = [0]*length
    B = [0]
    i = 1; j = 0
    while i < length:
        while i+j < length and S[x+j] == S[x+i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        B.append(min(j, i))
        k = 1
        while k < length - i  and k + A[k] < j :
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    ans = max(B)
    return ans


n = int(input())
S = input()

candidates = []
for i in range(n):
    candidates.append(z_algolithm(S, i))

print(max(candidates))

Measured memory_bytes: 53980
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i].second >> v[i].first;
    }
    sort(v.begin(), v.end());

    int ans = 0;
    int end = 0;
    for (int i = 0; i < n; i++)
    {
        if (end < v[i].second)
        {
            end = v[i].first;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int h,a[2000000];

void maxHeapify(int);
int main(){

  int i;

  scanf("%d",&h);

  for( i=1;i<=h; i++ ) scanf("%d",&a[i]);

  for( i=h/2;i>=1; i-- ) maxHeapify(i);

  for( i=1;i<=h; i++ ){
    printf(" %d",a[i]);
  }
  
  printf("\n");

  return 0;

}


void maxHeapify(int i){
  int l,r,largest,temp;
 
  l = 2 * i ;
  r = 2 * i + 1;

  if( l<=h && a[l] >a[i] )largest=l;

  else largest = i;

  if( r <=h && a[r] > a[largest] ) largest = r;

  if( largest != i ){
    temp = a[i];
    a[i] = a[largest];
    a[largest] = temp;
    maxHeapify(largest);
  }
}



Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int h, w;
    string s[55];

    cin >> h >> w;
    REP(i, h)
    {
        string str = "";
        REP(j, w + 2)
        str += ".";
        s[0] = str;
        s[h + 1] = str;
    }
    REP(i, h)
    {
        cin >> s[i + 1];
        s[i + 1] = "." + s[i + 1] + ".";
    }

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            if (s[i][j] == '#')
            {
                cout << "#";
                continue;
            }

            int cnt = 0;
            for (int k = -1; k <= 1; k++)
            {
                for (int l = -1; l <= 1; l++)
                {
                    cnt += s[i + k][l + j] == '#';
                }
            }

            cout << cnt;
        }

        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  string s;
  cin >> s;

  regex re(R"(C.*F.*)");

  smatch m;

  bool ok = regex_search(s, m, re);

  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a+b>=24)cout<<a+b-24<<endl;
    else cout<<a+b<<endl;
    
}

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

using namespace std;

int dp[10024];

int main()
{

    for(int i = 0; i < 10000; i++)
    {
        dp[i] = -10;
    }

    dp[0] = 0;


    int N, W;
    cin >> N >> W;

    for(int i = 0; i < N; i++)
    {
        int v, w;
        cin >> v >> w;

        for(int j = W - w; j >= 0; j--)
        {
            if(dp[j] != -10 && j + w <= W)
            {
                dp[j + w] = max(dp[j + w], dp[j] + v);
            }
        }

        /*
        for(int j = 0; j <= W; j++)
        {
            cout << dp[j] << " ";
        }
        cout << endl;
        //*/
    }


    int ans = 0;
    for(int i = 0; i <= W; i++)
    {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    


    return 0;
}

Measured memory_bytes: 3156
#include <cstdio>
#include <cstring>
int q,n;
bool data[1000001];
int main(void){
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d",&n);
		memset(data,false,sizeof(data));
		int x=n,next,cnt=0;
		while(1){
			if(data[x]){
				printf("-1\n");
				break;
			}
			if(x<=9){
				printf("%d\n",cnt);
				break;
			}
			data[x]=true;
			next=-1;
			int a=x,b=0,c=1;
			while(a>0){
				b=b+(a%10)*c;
				a/=10;
				if(a*b>next)next=a*b;
				c*=10;
			}
			x=next;
			cnt++;
		}
	}
	return 0;
}

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

int main() {
	// your code goes here
	int n, x;
	cin >> n;
	int v[n];
	for (int i = 1; i <= n; i++) {
		cin >> x;
		v[x] = i;
	}
	for (int i = 1; i <=n; i++) {
		cout << v[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 1152
package main

import (
	"fmt"
)

func main() {
	var n, l int
	fmt.Scan(&n, &l)
	var taste = make([]int, n)

	min := 10000000000000000
	ind := 0
	for i := range taste {
		taste[i] = l + (i + 1) - 1

		if taste[i]*taste[i] < min {
			min = taste[i] * taste[i]
			ind = i
		}
	}
	sum := 0
	for i, v := range taste {
		if i != ind {
			sum += v
		}
	}
	fmt.Println(sum)

}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 100000000
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
  scanf("%d", &n);
  vector<int> v[100000];
  for(int i=0; i<n-1; i++){
    int a, b;
    scanf("%d %d", &a, &b);
    a--; b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int d[100000];
  fill(d, d+n, -1);
  d[0]=0;
  queue<int> que;
  que.push(0);
  while(!que.empty()){
    int x=que.front();
    que.pop();
    for(int i=0; i<v[x].size(); i++){
      if(d[v[x][i]]<0){
        d[v[x][i]]=d[x]+1;
        que.push(v[x][i]);
      }
    }
  }
  vector<P> dist;
  for(int i=0; i<n; i++){
    dist.push_back(P(d[i], i));
  }
  sort(dist.begin(), dist.end(), greater<P>());
  int l[100000], r[100000];
  fill(l, l+n, -INF);
  fill(r, r+n, INF);
  int k;
  scanf("%d", &k);
  int par;
  for(int i=0; i<k; i++){
    int v0, p;
    scanf("%d %d", &v0, &p);
    v0--;
    if(i==0){
      if(d[v0]%2==p%2){
        par=0;
      }else{
        par=1;
      }
    }else{
      if((d[v0]+p)%2!=par){
        printf("No\n");
        return 0;
      }
    }
    l[v0]=p, r[v0]=p;
  }
  for(int i=0; i<n; i++){
    int x=dist[i].second;
    for(int j=0; j<v[x].size(); j++){
      if(d[v[x][j]]<d[x]) continue;
      l[x]=max(l[v[x][j]]-1, l[x]);
      r[x]=min(r[v[x][j]]+1, r[x]);
    }
    if(l[x]>r[x]){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  int num[100000];
  num[0]=l[0];
  vector<int> v1;
  for(int i=0; i<n; i++){
    v1.push_back(dist[n-1-i].second);
  }
  for(int i=0; i<n; i++){
    int x=v1[i];
    for(int j=0; j<v[x].size(); j++){
      if(d[v[x][j]]<d[x]) continue;
      if(l[v[x][j]]<=num[x]+1 && r[v[x][j]]>=num[x]+1){
        num[v[x][j]]=num[x]+1;
      }else{
        num[v[x][j]]=num[x]-1;
      }
    }
  }
  for(int i=0; i<n; i++){
    printf("%d\n", num[i]);
  }
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

int N;
int C[555],S[555],F[555];

signed main(){
    cin>>N;
    rep(i,N-1)cin>>C[i]>>S[i]>>F[i];


    rep(i,N){
        int t=0;
        for(int j=i;j<N-1;j++){
            chmax(t,S[j]);
            t=(t+F[j]-1)/F[j]*F[j];
            t+=C[j];
        }
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<vector<int>,int>P;
vector<int>v[13],s(13),t(13);
map<vector<int>,int>m;
 
int has[14];
 
 
void init(){
 
    v[0].push_back(2);
 
    v[1].push_back(2);
    v[1].push_back(5);
 
    v[2].push_back(0);
    v[2].push_back(1);
    v[2].push_back(3);
    v[2].push_back(6);
 
    v[3].push_back(2);
    v[3].push_back(7);
 
    v[4].push_back(5);
 
    v[5].push_back(1);
    v[5].push_back(4);
    v[5].push_back(6);
    v[5].push_back(9);
 
    v[6].push_back(2);
    v[6].push_back(5);
    v[6].push_back(7);
    v[6].push_back(10);
 
    v[7].push_back(3);
    v[7].push_back(6);
    v[7].push_back(8);
    v[7].push_back(11);
 
    v[8].push_back(7);
 
    v[9].push_back(5);
    v[9].push_back(10);
 
    v[10].push_back(6);
    v[10].push_back(9);
    v[10].push_back(11);
    v[10].push_back(12);
 
    v[11].push_back(7);
    v[11].push_back(10);
 
    v[12].push_back(10);
 
    int a=20;
    int p=1;
 
    r(i,13){
        has[i]=p;
        p*=a;
    }
}
 
int ha(vector<int> &x){
 
    int re=0;
 
    r(i,13){
        re+=x[i]*has[i];
    }
 
    return re;
}
 
vector<int> ah(int x){
    vector<int>y(13);
    r(i,13){
        y[i]=x%20;
        x/=20;
    }
    return y;
}
 
void BFS1(){
    s[0]=0;
    s[12]=0;
    r(i,11)s[i+1]=i+1;
    set<vector<int> >st;
    st.insert(s);
    m[s]=0;
    queue<P>q;
    q.push(P(s,0));
    while(1){
        vector<int> now=q.front().first;
        int cost=q.front().second;
        q.pop();
        if(cost==11)break;
        //cout<<m.size()<<' '<<cost<<endl;
        r(i,13)if(now[i]==0){
            r(j,v[i].size()){
                swap(now[i],now[v[i][j]]);
                if(!st.count(now)){
                    st.insert(now);
                    m[now]=cost+1;
                    q.push(P(now,cost+1));
                }
                swap(now[i],now[v[i][j]]);
            }
        }
    }
}
 
void BFS2(){
    set<vector<int> >st;
    st.insert(t);
    queue<P>q;
    q.push(P(t,0));
    while(1){
        vector<int>now=q.front().first;
        int cost=q.front().second;
        q.pop();
        if(m.count(now)){
            cout<<m[now]+cost<<endl;
            return ;
        }
        if(cost==9)break;
        r(i,13)if(now[i]==0){
            r(j,v[i].size()){
                swap(now[i],now[v[i][j]]);
                if(!st.count(now)){
                    st.insert(now);
                    if(m.count(now)){
                        cout<<m[now]+cost+1<<endl;
                        return ;
                    }
                    q.push(P(now,cost+1));
                }
                swap(now[i],now[v[i][j]]);
            }
        }
    }
    cout<<"NA"<<endl;
}
 
 
signed main(){
    init();
    BFS1();
    while(cin>>t[0],t[0]!=-1){
        r(i,12)cin>>t[i+1];
        BFS2();
    }
}


Measured memory_bytes: 8612
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll a, b, n;
    cin >> a >> b >> n;

    ll max_b = ((n + b - 1) / b) * b;
    ll x = min(n, max_b - 1);
    ll y = max(0LL, max_b - b - 1);
    ll ansx = (a * x / b) - a * (x / b);
    ll ansy = (a * y / b) - a * (y / b);
    ll ans = max(ansx, ansy);
    cout << ans << endl;
}

Measured memory_bytes: 3612
import java.util.*;
public class Main {
	
	static int N, M, R, r[], graph[][];	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		R = sc.nextInt();
		r = new int[R];
		for(int i=0;i<R;i++)r[i]= sc.nextInt()-1;
		
		int max = Integer.MAX_VALUE/2;
		graph = new int[N][N];
		for(int t[]:graph)Arrays.fill(t,max);
		for(int i=0;i<M;i++) {
			int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt();		
			graph[--A][--B] = graph[B][A] = C;
		}
		sc.close();

		
		for(int k=0;k<N;k++) {
			for(int i=0;i<N;i++) {
				for(int j=0;j<N;j++) {
					graph[i][j]=Math.min(graph[i][j], graph[i][k]+graph[k][j]);
				}
			}
		}
		
		//順列的にR個の回り方全通りを探索する。
		int visited[]=new int[N];
		Arrays.fill(visited, -1);
		
		int min = max;
		for(int t:r) {
			min = Math.min(min, dfs(t, 0, visited));
		}
		
		System.out.println(min);
		
	}
	
	static int dfs(int vertex, int subDist , int visited[]) {
		int subVisited[] = visited.clone();
		subVisited[vertex]=1;
		boolean stop = true;
		for(int t:r) {
			if(subVisited[t]==-1) {
				stop = false;
				break;
			}
		}
		
		if(stop) {
			return subDist;
		}
		
		int min = Integer.MAX_VALUE/2;
		for(int t:r) {
			if (subVisited[t]==1)continue;
			min = Math.min(min, dfs(t, subDist+graph[vertex][t] , subVisited));
		}
		
		return min;
	}
	
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli a,b,c;
	cin>>a>>b>>c;

	if(a+b+c>=22)cout<<"bust"<<endl;
	else cout<<"win"<<endl;

	return 0;
}

Measured memory_bytes: 764
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    a,b,c,d=map(int,input().split())
    YesNo(abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
function main(input) {
  const args = input.split(' ')
  var N = Number(args[0])
  var L = Number(args[1])
  var azi_sum = 0
  var min_abs = 1000000
  for (var i = 1; i <= N; i++) {
    var azi = L + i - 1
    if (min_abs * min_abs > azi * azi) {
      min_abs = azi
    }
    azi_sum += azi
  }
  azi_sum -= min_abs
  console.log(azi_sum)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int begin = max(A, C);
    int end = min(B, D);
    cout << max(end - begin, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#白昼夢
s = input()
words = ['dream','dreamer','erase','eraser']
#evaluate
while True:
  for i in range(4):
    if s.endswith(words[i]):
      s = s[:-len(words[i])]
      break #inner loop
  else:
    print('NO')
    break #outerloop
  if not s: 
    print('YES')
    break #outerloop
    

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

int main() {
	ll x;
	cin >> x;
	ll fx = 0;
	ll y = x;
	while (y > 0) {
		fx += y % 10;
		y -= y % 10;
		y /= 10;
	}
	if (x % fx == 0)cout << "Yes" << endl;
	else cout << "No" << endl;

}

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

constexpr int inf = 1001001001;

int to_vertex(char c, int idx) {
  return 26 * idx + (c - 'a');
}

char to_char(int v) {
  return (char)(v % 26 + 'a');
}

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

  A += '*';
  reverse(A.begin(), A.end());

  int g = 26 * A.size();
  vector<vector<int>> G(g + 1);

  vector<int> pre(26);
  for (int i = 1; i < A.size(); ++i) {
    int v = to_vertex(A[i], i);
    for (char c = 'a'; c <= 'z'; ++c) {
      int u = to_vertex(c, pre[c - 'a']);
      G[u].push_back(v);
      // cerr << "(" << c << ", " << pre[c - 'a'] << ") -> (" << A[i] << ", " << i << ")" << endl;
    }
    pre[A[i] - 'a'] = i;
  }

  for (int c = 'a'; c <= 'z'; ++c) {
    int u = to_vertex(c, pre[c - 'a']);
    G[u].push_back(g);
  }

  queue<int> q;
  vector<int> d(g + 1, inf), p(g + 1, -1);
  for (int i = 0; i < 26; ++i) {
    q.push(i);
    d[i] = 0;
  }

  while (!q.empty()) {
    int from = q.front();
    q.pop();

    for (auto &to : G[from]) {
      if (d[to] < d[from] + 1) continue;

      if (d[to] > d[from] + 1) {
        d[to] = d[from] + 1;
        q.push(to);
      }
      if (p[to] == -1 || p[to] % 26 > from % 26) p[to] = from;
    }
  }

  string ans;
  for (int v = p[g]; v != -1; v = p[v]) {
    ans += to_char(v);
  }

  cout << ans << endl;
}


Measured memory_bytes: 195716
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  string key="keyence";
  if(s==key){
    cout<<"YES"<<'\n';
    return(0);
  }
  int si=s.size();
  rep(i,si){
    rep(j,si){
      string cp;
      rep(k,i){
        cp+=s[k];
      }
      REP(k,j,si){
        cp+=s[k];
      }
      if(cp==key){
        cout<<"YES"<<'\n';
        return(0);
      }
    }
  }
  cout<<"NO"<<'\n';
  return(0);
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n = int(input())
    s = str(input())

    counter = [0 for _ in range(n+1)]
    for i in range(n):
        if s[i] == "I":
            counter[i+1] = counter[i] + 1
        else:
            counter[i+1] = counter[i] - 1

    print(max(counter))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060