akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {
  string s;
  while( cin >> s ){
    int n = s.size();
    string ans = "";
    for(int i=0; i<n; i++){
      if( s[i] == '@' ){
        ans += string(s[i+1]-'0', s[i+2]);
        i += 2;
      }else ans += s[i];
    }
    cout << ans << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 2976
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		String remain = "01234567";
		int over = 0;
		for (int i = 0; i < N; i++) {
			int num = reader.nextInt()/400;
			if (num < 8) {
				remain = remain.replace(Integer.toString(num), "");
			} else {
				over++;
			}
		}
		int min = 8 - remain.length();
		int max = min + over;
		if (min < 1) {
			min = 1;
		}

		reader.close();
		System.out.print(min + " " + max);
	}
}



Measured memory_bytes: 23252
import java.util.Scanner;

class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System. in);
      int a = stdIn.nextInt();
      int b = stdIn.nextInt();
      int c = a*b;
      int d = 2*(a+b);
      System.out.println( c + " " + d );
   }
}

Measured memory_bytes: 26188
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,VI(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)
     
int main() {
  ll n, m, k, x=0, y=0 , z = 0, h,w, sum = 0, Max = -1, Min = 3e9+1;
  string u;
  bool ok=true;
  cin >> n;
  VI a(n);
  rep(i,n) {
    cin >> a[i];
    if(a[i]%4==0)
      x++;
    else if (a[i]%2==0)
      y++;
    else
      z++;
  }
  if(x+1 >= z && y==0){
    pri("Yes");
  }
  else if(x >= z){
    pri("Yes");
  }
  else pri("No");

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;



int main(){
     
    string s;
    int cnt[100000]={};
    
    cin>>s;
    for(int i=0;i<s.size();i++){
        cnt[s[i]]++;
    }
    for(int i=0;i<26;i++){
        if(cnt['a'+i]%2==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
     
    return 0;
}
 

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

int main() {
	int k;
	cin>>k;
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	}
	int y=0;
	for(int i=0;i<n;i++){
	    k=k-arr[i];
	    
	}
	if(k<=0){
	    cout<<"Yes";
	}
	else{
	    cout<<"No";
	}
}

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

int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (k < e - a)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;

    return 0;
}


Measured memory_bytes: 3536
#include <stdio.h>

int main(void)
{
	char joi[1000001];
	int i, len;
	int rj, ro, ri;
	int level;

	scanf("%s%n", joi, &len);
	level = 0;
	for (i = 0; i < len; i++){
		if (joi[i] == 'J'){
			for (rj = 0; joi[i] == 'J'; rj++, i++);
			for (ro = 0; joi[i] == 'O'; ro++, i++);
			for (ri = 0; joi[i] == 'I'; ri++, i++);
			if (ri >= ro && rj >= ro) level = level > ro ? level : ro;
			i--;
		}
	}
	printf("%d\n", level);

	return (0);
}

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

#define max_3(a, b, c) max(a, max(b, c))
using namespace std;

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

    typedef vector <int> v_int;
    v_int swim_happiness(no_of_days + 1);
    v_int bug_happiness(no_of_days + 1);
    v_int homework_happiness(no_of_days + 1);

    for(int i = 1; i <= no_of_days; i++)
        cin >> swim_happiness[i] >> bug_happiness[i] >> homework_happiness[i];

    const int NO_OF_TYPES = 3;
    vector <v_int> maximum_happiness(no_of_days + 1, v_int(NO_OF_TYPES, 0));

    const int SWIM_TODAY = 0, BUG_TODAY = 1, HOMEWORK_TODAY = 2;
    for(int i = 1; i <= no_of_days; i++)
    {
        maximum_happiness[i][SWIM_TODAY] = swim_happiness[i] + max(maximum_happiness[i - 1][BUG_TODAY], maximum_happiness[i - 1][HOMEWORK_TODAY]);

        maximum_happiness[i][BUG_TODAY] = bug_happiness[i] + max(maximum_happiness[i - 1][HOMEWORK_TODAY], maximum_happiness[i - 1][SWIM_TODAY]);

        maximum_happiness[i][HOMEWORK_TODAY] = homework_happiness[i] + max(maximum_happiness[i - 1][SWIM_TODAY], maximum_happiness[i - 1][BUG_TODAY]);
    }

    int overall_happiness = max_3(maximum_happiness[no_of_days][SWIM_TODAY], maximum_happiness[no_of_days][BUG_TODAY], maximum_happiness[no_of_days][HOMEWORK_TODAY]);

    cout << overall_happiness;
    return 0;
}

Measured memory_bytes: 6912
#include <cstdio>
#include <stdlib.h>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    long long array[n + 1];
    long long diff[n];
    long long sum = 0;
    for(int i = 1;i <= n;i++){
        scanf("%lld",&array[i]);
        sum += array[i];
        }
    array[0] = array[n];
    if(sum % ((long)n * (n + 1)/2)){
    printf("NO");
    return 0;
    }
    int times = sum * 2 / ((long)n * (n + 1));
    long long cnt = 0;
    for(int i = 0;i < n;i++){
            diff[i] = array[i + 1] - array[i] - times;
            if(diff[i] > 0){
            printf("NO");
            return 0;
            }
            if(diff[i] < 0){
            if(abs(diff[i]) % n){
            printf("NO");
            return 0;
            }
            cnt += abs(diff[i])/n;
            }
        }
     if(cnt > times){
     printf("NO");
     return 0;
     }
     printf("YES");
     return 0;
    }


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int w,h;
    cin>>w>>h;
    string s[w]={};
    for(int i=0;i<w;i++)
        cin>>s[i];
    for(int i=0;i<w;i++)
        {
            cout<<s[i]<<'\n';
            cout<<s[i]<<'\n';
        }
    return 0;
}


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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
    // random_device rnd;
    // mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int ans = 999;
    for(int i = 0;i < S.size()-2;i++){
        ans = min(ans,abs(753-stoi(S.substr(i,3))));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);
#define asc(A) sort(A.begin(),A.end())
#define dsc(A) sort(A.begin(),A.end(),greater<ll>())
#define input(A,N) for(ll i=0;i<N;i++) cin>>A[i];
int main()
{
    fasino
    ll a;
    double b;
    cin>>a>>b;
    ll b2=round(b*100.00);
    // cou<<a<<b;
    auto k = a*b2/100;
    cout<<(long long)k;
    return 0;
}



Measured memory_bytes: 3752
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  private static final long MOD = 1000000007L;

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    String s = sc.next();
    int n = s.length();
    int[] leftAs = new int[n];
    int[] leftQs = new int[n];
    int[] rightCs = new int[n];
    int[] rightQs = new int[n];

    int qCount;

    int aCount = 0;
    qCount = 0;
    for (int i = 0; i < n; i++) {
      leftAs[i] = aCount;
      leftQs[i] = qCount;
      char c = s.charAt(i);
      if (c == 'A') aCount++;
      else if (c == '?') qCount++;
    }

    int cCount = 0;
    qCount = 0;
    for (int i = n - 1; 0 <= i; i--) {
      rightCs[i] = cCount;
      rightQs[i] = qCount;
      char c = s.charAt(i);
      if (c == 'C') cCount++;
      else if (c == '?') qCount++;
    }

    long[] pow3 = new long[qCount + 1];
    pow3[0] = 1;
    for (int i = 1; i <= qCount; i++) {
      pow3[i] = (pow3[i - 1] * 3L) % MOD;
    }

    long sum = 0;
    // fix B
    for (int i = 0 ; i < n; i++) {
      char c = s.charAt(i);
      if (c != 'B' && c != '?') continue;
      long left = leftAs[i] * pow3[leftQs[i]] % MOD;
      if (1 <= leftQs[i]) left += leftQs[i] * pow3[leftQs[i] - 1];
      long right = rightCs[i] * pow3[rightQs[i]] % MOD;
      if (1 <= rightQs[i]) right += rightQs[i] * pow3[rightQs[i] - 1];
      sum += (left % MOD) * (right % MOD);
      sum = sum % MOD;
    }
    os.println(sum);
  }
}

Measured memory_bytes: 28048
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009],cr[500009];
int main()
{
    ll a,b,c,i,j=0,k=0,x,z=0,y,g,h,f=0;
    string s,d;
    cin>>a>>b;
    c=sqrt(a);
    x=sqrt(b);
    for(i=1; i<=c; i++)
    {
       if(a%i==0)
       {
           ar[++j]=i;
           if(i!=(a/i))
           {
               ar[++j]=(a/i);
           }
       }
    }
    for(i=1; i<=x; i++)
    {
        if(b%i==0)
       {
           br[++k]=i;
           if(i!=(b/i))
           {
               br[++k]=(b/i);
           }
       }
    }
    for(i=1;i<=j;i++)
    {
        for(y=1;y<=k;y++)
        {
            if(ar[i]==br[y])
            {
                cr[++z]=ar[i];
                break;
            }
        }
    }
    sort(cr+1,cr+z+1);
    for(i=1;i<=z;i++)
    {
        h=0;
        for(j=1;j<i;j++)
        {
            g=__gcd(cr[i],cr[j]);
            if(g>1)
            {
                h=1;
                break;
            }
        }
        if(h==0)
        {
            f++;
        }
    }
    cout<<f<<endl;
}


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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int testCases = 1;
   // cin >> testCases;
  
    while(testCases--)
    {
        int n,X,T;
        cin >> n >> X >> T;
        int rem = n % X;
        
        if(rem == 0)
            cout << (n / X) * T;
        else
            cout << ((n / X) + 1)*T;

        cout << '\n';
    }
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <set>
#include <cmath>

#define rep(a, b) for (int (a) = 0; (a) < (b); (a)++)

using namespace std;

long long solve(multiset<pair<int, int>> st1, multiset<pair<int, int>> st2, bool flag) {
    long long ret = 0;

    int pt = 0;
    while (true) {
        if (!flag) {
            if (st1.empty()) break;
            pair<int, int> pr = *st1.rbegin();
            ret += max(0, pr.first - pt);
            if (pr.first < pt) break;
            pt = pr.first;
            st1.erase(st1.find(pr));
            st2.erase(st2.find(make_pair(pr.second, pr.first)));
        } else flag = false;

        if (st2.empty()) break;
        pair<int, int> pr = *st2.begin();
        ret += max(0, pt - pr.first);
        if (pr.first > pt) break;
        pt = pr.first;
        st1.erase(st1.find(make_pair(pr.second, pr.first)));
        st2.erase(st2.find(pr));
    }
    
    ret += abs(pt);
    
    return ret;
}

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

    multiset<pair<int, int>> st1, st2;
    rep(i, N) {
        int L, R;
        cin >> L >> R;

        st1.insert(make_pair(L, R));
        st2.insert(make_pair(R, L));
    }

    long long ret = solve(st1, st2, false);
    ret = max(ret, solve(st1, st2, true));

    cout << ret << endl;

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 0; i < n + 1; i++) cin >> a[i];
  vector<int> b(n);
  for (int i = 0; i < n; i++) cin >> b[i];

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int tmp = min(a[i], b[i]);
    b[i] -= tmp;
    a[i] -= tmp;
    ans += tmp;
    tmp = min(a[i + 1], b[i]);
    b[i] -= tmp;
    a[i + 1] -= tmp;
    ans += tmp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
<?php

$input = explode(' ', trim(fgets(STDIN)));
$n = (int)$input[0];
$m = (int)$input[1];

$input = explode(' ', trim(fgets(STDIN)));
$x = [];
foreach ($input as $str) {
	$x[] = (int)$str;
}

if ($n >= $m) {
	echo 0;
	exit();
}

sort($x);
$dist = [];
for ($i=0; $i < $m-1; $i++) { 
	$dist[] = $x[$i+1] - $x[$i];
}

sort($dist);
$max = $m -$n;
$sum = 0;
for ($j=0; $j < $max; $j++) { 
	$sum += $dist[$j];
}
echo $sum;

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

int lcs(string a,string b){
  int c[1001][1001];
  for(int i=0;i<1001;i++){
      for(int j=0;j<1001;j++){
          c[i][j]=0;    
      } 
  }
  int m=a.size(),n=b.size();
  int mx=0;
  a=' '+a;
  b=' '+b;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(a[i]==b[j]){
	c[i][j]=c[i-1][j-1]+1;
      }else{
	c[i][j]=max(c[i-1][j],c[i][j-1]);
      }
      mx=max(mx,c[i][j]);
    }
  }
  return mx;
}


int main(){
  int q;
  string s1,s2;
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<endl;
  }
  return 0;
}



Measured memory_bytes: 7120
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#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); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n;
  string a,b,c;
  cin>>n>>a>>b>>c;
  int ans = 0;
  rep(i,n) {
    if(a[i] == b[i] && b[i] == c[i]) {
      ans += 0;
    } else if(a[i] != b[i] && b[i] != c[i] && c[i] !=  a[i]) {
      ans += 2;
    } else {
      ans += 1;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int N;
int E[200001], n[200001], H[100001];
int k[100001];
int D[100001];
int kyori, kotae;
int dfs(int p, int mae, int d) {
	D[p] = d;
	int kazu = 1;
	if (p == N) {
		kazu += 1 << 20;
		kyori = (D[N] + 1) / 2;
	}
	for (int i = H[p]; i; i = n[i]) if (E[i] != mae) kazu += dfs(E[i], p, d + 1);
	if (kazu > (1 << 20) && D[p] == kyori + 1) kotae = kazu - (1 << 20);
	return k[p] = kazu;
}

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


	N = getint();
	int kari = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();
		E[kari] = b;
		n[kari] = H[a];
		H[a] = kari++;
		E[kari] = a;
		n[kari] = H[b];
		H[b] = kari++;
	}

	dfs(1, 0, 1);

	if (N - kotae > kotae) printf("Fennec");
	else printf("Snuke");

	Would you please return 0;
}

Measured memory_bytes: 9216
//B
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;
string itos(int n){
stringstream ss;
ss<<n;
return ss.str();
}
int main(){
	int Q;
	cin>>Q;
for(int i=0;i<Q;i++){
	vector<string>x(0);
	string n;
	cin>>n;
	string tn=n;
	int next=0;
	int ans=0;
	while(true){
	if(tn.size()==1)break;
	int f=0;
	for(int j=0;j<x.size();j++)if(x[j]==tn)f=1;
	if(f){
	ans=-1;
	break;
	}
	x.push_back(tn);
	next=0;
	for(int j=0;j<tn.size()-1;j++){//jで分割
		int a1=0,a2=0;
		int cnt=0;
		for(int k=j;k>=0;k--){
		a1+=(tn[k]-'0')*pow(10,cnt);
		cnt++;
		}
		cnt=0;
		for(int k=tn.size()-1;k>j;k--){
		a2+=(tn[k]-'0')*pow(10,cnt);
		cnt++;
		}
		//cout<<a1<<" "<<a2<<endl;
		next=max(a1*a2,next);
	}
	tn=itos(next);

	ans++;
	}
	cout<<ans<<endl;
}

	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    int n,t;cin>>n>>t;int ans=t;
    int a[n];REP(i,n)cin>>a[i];
    REP(i,n-1){
        ans+=min(a[i+1]-a[i],t);
    }cout<<ans<<endl;

}

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

Measured memory_bytes: 1024
#include<iostream>
#include<set>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin>>n;
  int cnt=0;
  for(int i=1;i<=n;i++){
    ll a;
    cin>>a;
    if(i!=a) cnt++;
  }
  if(cnt<3) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


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

int main(){
  int A,B,T;
  cin >>A>>B>>T;
  
  int sum;
  int time = (T+0.5)/A;
  sum = B*time;
  cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int n,x;
    std::cin >> n>>x;
    std::vector<int> a(n);
    rep(i,n)std::cin >> a[i];
    int l=0,ans=1;
    rep(i,n){
        l+=a[i];
        if(x<l)break;
        ans++;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def get_yakusu(n):
    ans = set()
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                ans.add(i)
            if n // i != i:
                ans.add(n // i)
    return ans

def main():
    N = I()
    cnt = 0
    if N == 2:
        print(1)
        return
    yakusu = get_yakusu(N)
    n1yakusu = get_yakusu(N-1)
    for n in yakusu:
        cpN = N
        while True:
            if cpN % n == 0:
                cpN = cpN // n
            else:
                break
        if cpN % n == 1:
            cnt += 1
    cnt += len(n1yakusu)
    print(cnt)
main()



Measured memory_bytes: 66412
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
    ll N,K;
    cin >> N >> K;
    N %= K;
    ll Min = N;
    while(Min != abs(N - K))
    {
        N = abs(N - K);
        Min = min(Min,N);
    }

    cout << Min << endl;
}

Measured memory_bytes: 3164
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long H = scanner.nextInt();
    long W = scanner.nextInt();

    if (H == 1 || W == 1) {
      System.out.println(1);
      return;
    }
    long ws = W / 2;
    long wl = W - ws;
    long res = W * (H / 2);
    if (H % 2 != 0) {
      res += wl;
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 22996
num, target = [int(i) for i in input().split()]
Flag = False

for i in range(num, -1, -1):
    for j in range(num-i, -1, -1):
        k = num - i - j 
        if (10000 * i) + (5000 * j) + (1000 * k) == target:
            print(str(i) + " " + str(j) + " " + str(k))
            Flag = True
            break
    if Flag == True:
        break

if Flag == False:
    print("-1 -1 -1")

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		long m=1000000007;
		
		int n=s.nextInt();
		
		long ans=power(10,n,m);
		ans=(ans+power(8,n,m))%m;
		
		long val=(2*power(9,n,m))%m;
		
		ans=(ans-val+m)%m;
		
		System.out.println(ans);
	}
	
	public static long power(long a,long b,long m)
	{
		long res=1;
		
		while(b>0)
		{
			if(b%2!=0)
			{
				res=(res%m*a%m)%m;
			}
			
			b=b/2;
			a=(a%m*a%m)%m;
		}
		
		return res;
		
	}
	
}

Measured memory_bytes: 35728
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int s,w;
  cin >> s >> w;
  if(s > w){
    cout << "safe\n";
  }else{
    cout << "unsafe\n";
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}


int main()
{
    int n;
    cin >> n;
    bool flag = false;
    FOR(i, 1, 10)
    {
        if (n % i == 0){
            int m = n / i;
            if (1 <= m && m <= 9){
                flag = true;
                break;
            }
        }
    }
    if (flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int x ,y;

void process(int n){
	if(n == 5) ++x;
  	if(n == 7) ++y;
}

int main(){
	int a; 
  	for(int i = 0;i < 3 ; ++i){
		cin >> a;
      	process(a);
    }
  	if(x == 2 && y == 1) cout << "YES" << endl;
  	else cout << "NO" << endl;
  return 0;
}

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

using namespace std;

int main(void){
    int n, q;
    cin >> n >> q;
    queue<pair<string, int> > m;
    for(int i = 0; i < n; i++){
        string name;
        int time;
        cin >> name >> time;
        m.push(make_pair(name, time));
    }
    int time = 0;
    while(!m.empty()){
        pair<string, int> now = m.front();
        m.pop();
        if(now.second <= q){
            time += now.second;
            cout << now.first << " " << time << endl;
        }else{
            time += q;
            now.second -= q;
            m.push(now);
        }
    }
    return 0;
}


Measured memory_bytes: 6232
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  while(1){
    int n;
    cin >> n;
    if(n == 0)break;
    vector<pair<double,string> > ans(n); 
    for(int i = 0;i < n;i++){
      string name;
      cin >> name;
      int p,a,b,c,d,e,f,s,m;
      cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      int cost_time = a + b + c +( d + e)*m;
      int buy = f*s*m;
      ans[i] = pair<double,string>(-1*(double)(buy-p)/(double)(cost_time),name);
      
    }
    sort(ans.begin(),ans.end());
    for(int i = 0;i < n;i++){
      cout << ans[i].second << endl;
    }
    cout << "#" << endl;

  }
  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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


int dp[2100][2];
int main()
{
  int N, Z, W;
  cin >> N >> Z >> W;
  vector<int> a(N);
  REP(i, N) cin >> a[i];

  for (int i = N - 1; i >= 0; i--) {
    for (int p = 0; p <= 1; p++) {
      if (p == 0) {
        int ma = -1;
        for (int j = i + 1; j < N; j++) {
          ma = max(ma, dp[j][1 - p]);
        }
        if (i >= 1)
          ma = max(ma, abs(a[N - 1] - a[i - 1]));
        else
          ma = max(ma, abs(a[N - 1] - W));
        dp[i][p] = ma;
      } else {
        int mi = INF;
        for (int j = i + 1; j < N; j++) {
          mi = min(mi, dp[j][1 - p]);
        }
        if (i >= 1)
          mi = min(mi, abs(a[N - 1] - a[i - 1]));
        dp[i][p] = mi;
      }
    }
  }
  cout << dp[0][0] << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static Scanner sc;
    static PrintWriter out;

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        out = new PrintWriter(System.out);
        new Main().solve();
        out.flush();
    }

    public void solve() {
        int n = sc.nextInt();
        long mod = 1000000007;
        long m10 = 1;
        long m9 = 1;
        long m8 = 1;

        for(int i=0; i<n; i++) {
            m10 *= 10;
            m9 *= 9;
            m8 *= 8;
            m10 %= mod;
            m9 %= mod;
            m8 %= mod;
        }

        long res = m10 - m9 * 2 + m8;
        res += mod * 10;
        res %= mod;
        out.println(res);

    }


}

Measured memory_bytes: 35844
import math
from functools import reduce
  
k = int(input())
k+=1

sum = 0
for a in range(1,k):
  for b in range(a,k):
    for c in range(b,k):
      t = len(set([a,b,c]))
      if t==1:
        sum+= reduce(math.gcd, [a,b,c])
      elif t==2:
        sum+= 3*reduce(math.gcd, [a,b,c])
      else:
        sum+= 6*reduce(math.gcd, [a,b,c])

print(sum)

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

int main() {
    string S, T;
    cin >> S >> T;

    // Bの個数の数え上げ
    vector<int> S_cumsum(S.size(), 0),
                T_cumsum(T.size(), 0);
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'B') S_cumsum[i]++;
        if (i > 0) S_cumsum[i] += S_cumsum[i - 1];
    }
    for (int i = 0; i < T.size(); i++) {
        if (T[i] == 'B') T_cumsum[i]++;
        if (i > 0) T_cumsum[i] += T_cumsum[i - 1];
    }
    
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--; c--; d--;

        int sb = S_cumsum[b] - (a > 0 ? S_cumsum[a - 1] : 0),
            tb = T_cumsum[d] - (c > 0 ? T_cumsum[c - 1] : 0),
            sa = b - a + 1 - sb,
            ta = d - c + 1 - tb;
        if ((sa + sb * 2) % 3 == (ta + tb * 2) % 3) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

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

int main() {
  long H;
  cin >> H;
  
  long N = 1;
  long count = 1;
  if (H == 1) {
    cout << 1 << endl;
  }
  else {
    while (H > 1) {
      H /= 2;
      N *= 2;
      count += N;
    }
    cout << count << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  ll x; cin >> x;
  vector<ll> a(n); rep(i, n) cin >> a[i];

  ll ans = 0;
  rep(i, n-1){
    if(i == 0 && a[i] > x){
      ans += a[i] - x;
      a[i] = x;
    }
    if(a[i]+a[i+1] > x){
      ans += a[i]+a[i+1]-x;
      a[i+1] = x-a[i];
    }
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int n,a[100005];
int main(){
	//freopen("b.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	int sta,ans=0;
	for(int i=1;i<=n;++i){
		if((i==1 && a[i]==i) || (a[i]==i && a[i-1]!=i-1)){
			sta=i;
		}
		if((i==n && a[i]==i) || (a[i]==i && a[i+1]!=i+1)){
			ans+=(i-sta+2)/2;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
/******* MY EVERY AC WILL BE A TRIBUTE TO SSR ********/
#define vi vector
#define lli long long int
#define vli vi<lli>
#define pb push_back
#define pll pair<lli,lli>
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(),greater<lli>()
#define clear(x) x.clear()
#define rep(i,n) for(lli i=0;i<(lli)n;i++)
#define rep1(i,n) for(lli i=1;i<=(lli)n;i++)
#define rep2(i,n) for(lli i=1;i<(lli)n;i++)
#define refor(i,n) for(lli i=(lli)n;i>=0;i--)
#define range(i,l,r) for(lli i=(lli)l;i<=(lli)r;i++)
#define big(x,y) (x>y)?x:y
#define small(x,y) (x<y)?x:y
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
using namespace std;
lli gcd(lli a,lli b) {return b==0?a:gcd(b,a%b);}
lli lcm(lli a,lli b) {return (a*b)/gcd(a,b);}
bool isprime(lli x) {for(lli i=2;i<=sqrt(x);i++) { if(x%i == 0) return false;} return true;}
lli modpow(lli x,lli y) {x%=mod;lli res=1;while(y>0){if(y&1) res*=x%mod; y=y>>1; x=x*x%mod;} return res%mod;}
lli ncr(lli n,lli k) {lli res=1; if(k>n-k) k=n-k; rep(i,k){res*=(n-i);res/=(i + 1);} return res;}
lli bintodec(lli n) {lli decimal=0,i=0,rem;while (n!=0){rem = n%10;n/=10;decimal += rem*pow(2,i);++i;}return decimal;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    lli n,k,aa,s=0,i,j;
    vli a;
    cin>>n>>k;
    rep(i,n)
    { cin>>aa;
    a.pb(aa);
	}
	sort(all(a));
	
	rep(i,k)
	{ s+=a[i];
	  
	}
	cout<<s<<'\n';
  
    return 0;
}











Measured memory_bytes: 3688
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
    char s[100] ,t[100];
    cin>>s>>t;
    int N=strlen(s);
    char v;
    int ans=0;
    for(int i=0;i<N;i++){
        v=s[0];
        for(int j=0;j<N-1;j++){
            s[j]=s[j+1];
        }
        s[N-1]=v;
        int cmp;
        cmp=strcmp(s,t);
        if(cmp==0) ans=1;
    }
    if(ans==1) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <map>
#include <string>

#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cinttypes>


using namespace std;

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

	static int hearth[101];

	for (int i = 0; i < n; ++i)
	{
		int x;
		cin >> x;

		for (int p = 1; p <= 100; ++p)
		{
			hearth[p] += (x - p) * (x - p);
		}
	}

	cout << *min_element(&hearth[1], &hearth[101]) << endl;

	return 0;
}


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

const int N_MAX=500;
const int C_MAX=30;
int N,C;
vector<vector<int>> D(C_MAX,vector<int>(C_MAX,0));
vector<vector<int>> c(N_MAX,vector<int>(N_MAX,0));
vector<vector<int>> d(3,vector<int>(C_MAX,0));

int wro(int i,int j,int k){
  vector<int> dc={i,j,k};
  int res=0;
  for(int l=0;l<3;++l){
    for(int m=0;m<C;++m){
      res += d[l][m]*D[m][dc[l]];
    }
  }
  return res;
}

int main(){
  cin>>N>>C;
  for(int i=0;i<C;++i){
    for(int j=0;j<C;++j){
      cin>>D[i][j];
    }
  }
  for(int i=0;i<N;++i){
    for(int j=0;j<N;++j){
      cin>>c[i][j];
      --c[i][j];
      ++d[(i+j)%3][c[i][j]];
    }
  }

  int ans=INT_MAX;

  for(int i=0;i<C;++i){
    for(int j=0;j<C;++j){
      for(int k=0;k<C;++k){
        if(i!=j && j!=k && k!=i){
        ans=min(ans,wro(i,j,k));
        }
      }
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 1280
def e_flatten(MOD=10**9 + 7):
    from fractions import gcd
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

    lcm = reduce(lambda x, y: x * y // gcd(x, y), A) % MOD
    coefficient = sum(pow(a, MOD - 2, MOD) for a in A)
    return (lcm * coefficient) % MOD

print(e_flatten())

Measured memory_bytes: 6100
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    int n;
    scanf("%d",&n);
    char s[n][11];
    
    for(int i = 0; i < n; i++) {
        scanf("%s",s[i]);
    }
    qsort(s, n, sizeof(char) * 11, strcmp);
    int count = 1;
    
    for(int i = 0; i < n - 1; i++) {
        if(strcmp(s[i], s[i + 1]) != 0)
            count++;
    }
    printf("%d",count);
    return 0;
}

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

int N,X;
int main(void){
  cin>>N>>X;
  int cnt=1;
  for(int i=0;i<N;i++){
    int L;
    cin>>L;
    X-=L;
    if(X>=0) cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    vector<unsigned long> p(N);
    for(auto&& i : p)cin >> i;
    nth_element(begin(p), begin(p) + K, end(p));
    cout << accumulate(begin(p), begin(p) + K, 0UL) << endl;
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	auto lucas = vector<long long int>(n + 1);
	lucas[0] = 2;
	lucas[1] = 1;
	for(auto i = 2; i <= n; ++i){
		lucas[i] = lucas[i - 1] + lucas[i - 2];
	}
	cout << lucas[n] << endl;
	return 0;
}

Measured memory_bytes: 256
use std::fmt;


#[derive(Debug)]
enum ANS {
    WAR,
    NOWAR,
}
impl fmt::Display for ANS {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let text = match *self {
            ANS::WAR => "War",
            ANS::NOWAR => "No War",
        };
        write!(f, "{}", text)
    }
}

fn main() {
    let (_n, _m, x, y) = read_tuple::<i32>();
    let x_points = read_vec::<i32>();
    let y_points = read_vec::<i32>();

    let mut ans = ANS::WAR;
    for z in (x+1)..(y+1) {
        if x_points.iter().all(|&x| x < z) && y_points.iter().all(|&y| z <= y) {
            ans = ANS::NOWAR;
            break;
        }
    }
    println!("{}", ans);
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T, T, T) {
    let temp = read_vec();
    (temp[0], temp[1], temp[2], temp[3])
}



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

int main(){
    int N, A, B, C, D;
    int ls[10];
    long minmp = 1e9;
    cin >> N >> A >> B >> C;
    for(int i=0;i<N;i++) cin >> ls[i];

    for(int bit=0;bit < (1<<2*N); bit++){
        vector<int> forA, forB, forC;
        for(int i=0;i<N;i++){
            if(bit & (1<<2*i)){
                if(bit & (1<<2*i+1)){
                    forC.push_back(ls[i]);
                }
                else{
                    forA.push_back(ls[i]);
                }
            }
            else{
                if(bit & (1<<2*i+1)){
                    forB.push_back(ls[i]);
                }
            }
        }
        if(forA.size() > 0 && forB.size() >> 0 && forC.size() >> 0){
            long mp = 10*(forA.size() + forB.size() + forC.size() - 3);
            mp += abs(accumulate(forA.begin(), forA.end(), 0) - A);
            mp += abs(accumulate(forB.begin(), forB.end(), 0) - B);
            mp += abs(accumulate(forC.begin(), forC.end(), 0) - C);
            minmp = min(minmp, mp);
        }
    }
    cout << minmp << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

template <typename T, class F=function<T(const T&, const T&)> >
class SparseTable {
    public:
        int n;
        vector<vector<T> > mat;
        F func;

    SparseTable(const vector<T>&a, const F& f): func(f) {
        n = static_cast<int>(a.size());
        int max_log = 32-__builtin_clz(n);
        mat.resize(max_log);
        mat[0] = a;
        for (int j=1; j<max_log; j++) {
            mat[j].resize(n-(1<<j)+1);
            for (int i=0; i<=n-(1<<j); i++) {
                mat[j][i] = func(mat[j-1][i], mat[j-1][i+(1<<(j-1))]);
            }
        }
    }

    T get(int from, int to) const {
        assert(0<=from && from<=to && to<=n-1);
        int lg = 32-__builtin_clz(to-from+1)-1;
        return func(mat[lg][from], mat[lg][to-(1<<lg)+1]);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    vector<int> p(n); REP(i, n) cin >> p[i];
    SparseTable<int> smin(p, [&](int i, int j) {return min(i, j); });
    SparseTable<int> smax(p, [&](int i, int j) {return max(i, j); });
    vector<int> bad(n-1), pref(n, 0);
    for (int i=0; i<n-1; i++) bad[i] = (p[i]>p[i+1]);
    for (int i=0; i<n-1; i++) pref[i+1] = pref[i] + bad[i];
    int ans=0, nosort=0;
    for (int i=0; i<=n-k; i++) {
        if (pref[i+k-1] - pref[i] == 0) {
            nosort = 1;  // kの範囲がすでに昇順なら
            continue;
        }
        if (i>0 && smin.get(i-1, i+k-2)==p[i-1] && smax.get(i, i+k-1)==p[i+k-1]) continue;
        else ans++;
    }
    cout << ans + nosort << '\n';
    return 0;
}


Measured memory_bytes: 28800
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] s = in.nextString().toCharArray();
			String[] t = new String[4];
			t[0] = ("dream");
			t[1] = ("dreamer");
			t[2] = ("erase");
			t[3] = ("eraser");

			int slen = s.length;
			while (slen > 0) {
				boolean isMatch = false;
				for (int k = 0; k < 4; k++) {
					int tlen = t[k].length();
					char[] tar = t[k].toCharArray();
					boolean isSame = true;
					for (int i = slen - tlen; i < slen; i++) {
						if (i < 0) {
							isSame = false;
							break;
						}
						if (s[i] == tar[i - slen + tlen]) {
							continue;
						} else {
							isSame = false;
							break;
						}
					}
					if (isSame) {
						slen -= tlen;
						isMatch = true;
						break;
					}
				}
				if (!isMatch) {
					out.println("NO");
					return;
				}
			}
			out.println("YES");

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 25172
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main(void){
  char s[110];
  scanf("%s",s);
  int i,j,k=strlen(s),csum=0;
  if(s[0]!='A'||s[1]<'a') {printf("WA");return 0;}
  for(i=2;i<k-1;i++){
    if(s[i]=='C') csum++;
    else if(s[i]<'a'||s[i]<='B'||s[i]<='D') {printf("WA");return 0;}
  }
  if(csum!=1) {printf("WA");return 0;}
  if(s[k-1]<'a'){printf("WA");return 0;}
  printf("AC");
  return 0;
}

Measured memory_bytes: 128
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define mp make_pair

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const ll MOD = 998244353, sz = 5e5;

int n, k;
vector<pii> sec;
ll dp[sz];
void mult(ll &a, ll b) {
	a = ((a % MOD) * (b % MOD)) % MOD;
}
void add(ll &a, ll b) {
	a = ((a % MOD) + (b % MOD)) % MOD;
}
void subtract(ll &a, ll b) {
	if (a >= b)a = (a - b) % MOD;
	else a = (a - b) % MOD + MOD;
}

void input() {
	cin >> n >> k;
	int a, b;
	foru(i, 0, k) {
		cin >> a >> b;
		sec.pb({ a,b });
	}
	sort(sec.begin(), sec.end());
	dp[n] = 1;
}

int main() {
	fast;
	input();
	ll nsm = 0;
	ford(i, n - 1, 1) {
		for (auto x : sec) {
			subtract(nsm, dp[i + x.second + 1]);
			add(nsm, dp[i + x.first]);
		}
		dp[i] = nsm;
	}
	cout << dp[1] << endl;
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main()
{
    ll n;
    cin >> n;
    vector<vector<ll>> cnt(10,vector<ll>(10,0));
    rep1(i, n){
        string s = to_string(i);
        if(i <= n)++cnt[i / pow(10,s.size() - 1)][i % 10];
    }
    ll ans = 0;
    rep1(i, 9)rep1(j, 9){
        ans += cnt[i][j] * cnt[j][i];
    }
    pf(ans)
    return 0;
}


Measured memory_bytes: 256