akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;
    ll W;
    cin>>n>>W;
    vector<ll> v(n),w(n);
    rep(i,n)cin>>w[i]>>v[i];
    ll m=w[0];
    rep(i,n)w[i]-=m;
    ll dp[n+1][4];
    rep(i,n+1)rep(j,4)dp[i][j]=-1;
    dp[0][0]=dp[0][1]=dp[0][2]=dp[0][3]=0;
    rep(i,n){
        for(int j=n-1;j>=0;j--){
            if(dp[j][w[i]]!=-1) chmax(dp[j+1][w[i]],dp[j][w[i]]+v[i]);
        }
    }
    ll res=0;
    for(int i=0;i<=n&&m*i<=W;i++){
        if(dp[i][0]==-1)break;
        for(int j=0;j<=n&&m*i+(m+1)*j<=W;j++){
            if(dp[j][1]==-1)break;
            for(int k=0;k<=n&&m*i+(m+1)*j+(m+2)*k<=W;k++){
                if(dp[k][2]==-1)break;
                for(int l=0;l<=n&&m*i+(m+1)*j+(m+2)*k+(m+3)*l<=W;l++){
                    if(dp[l][3]==-1)break;
                    ll buf=dp[i][0]+dp[j][1]+dp[k][2]+dp[l][3];
                    chmax(res,buf);
                }
            }
        }
    }
    cout<<res<<endl;
}


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

public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] in1 = br.readLine().split(" ");
    int N = Integer.parseInt(in1[0]);
    
    in1 = br.readLine().split(" ");
    int[] P = Stream.of(in1).mapToInt(Integer::parseInt).toArray();
    br.close();


    int[] posInP = new int[N];
    
    for(int i = 0; i < N; i++){
      P[i]--;
      posInP[P[i]] = i;
    }

    TreeSet<Integer> largeNumPos = new TreeSet<>();
    largeNumPos.add(-1);
    largeNumPos.add(N);
    largeNumPos.add(posInP[N-1]);
    long ans = 0;

    for(int i = N-2; i >= 0; i--){
      int j = posInP[i];
      int rLim1 = largeNumPos.higher(j);
      int lLim1 = largeNumPos.lower(j);

      int rLim2 = (rLim1 == N ? N : largeNumPos.higher(rLim1));
      int lLim2 = (lLim1 == -1 ? -1 : largeNumPos.lower(lLim1));
      if(rLim1 != N){
        ans += (long)(i + 1) * (long)(j - lLim1) * (long)(rLim2 - rLim1);
      }
      if(lLim1 != -1){
        ans += (long)(i + 1) * (long)(lLim1 - lLim2) * (long)(rLim1 - j);
      }

      largeNumPos.add(j);
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 50944
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
using namespace std;

int main()
{
  int n, h, w;
  cin >> n >> h >> w;
  int a[1010], b[1010];
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i];
    if (h <= a[i] && w <= b[i])
    {
      ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define OK puts("OK");
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define rep(i,n) for (i=0;i<(n);++i)
#define rep1(i,n) for (i=1;i<=(n);++i)
#define ret return
#define int long long
#define scan1(a) scanf("%lld",&(a));
#define scan2(a,b) scanf("%lld %lld",&(a),&(b));
#define scan3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c));
#define nemeshay ios::sync_with_stdio(0),cin.tie(0);
const int INF=1e9+7,N=1e6+12;
int dp[N],v[N],w[N];
main(){
    int n,i,j,k;
    scan2(n,k)
    for (i=1e5;i>=0;--i){
        dp[i]=INF;
    }
    rep1(i,n)
        scan2(w[i],v[i])
    dp[0] = 0;
    rep1(j,n){
        for (i = 1e5;i>=0;--i){
            if (dp[i]!=INF){
                dp[i+v[j]] = min(dp[i+v[j]],dp[i]+w[j]);
            }
        }
    }
    int ans=0;
    for (i=1e5;i>=0;--i){
        if (dp[i]<=k)break;
    }
    cout <<i;
}










Measured memory_bytes: 6400
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;

int main(){
	unordered_set<int> m;
	string s;
	cin >> s;
	for(auto c: s){
		if(m.count(c)){
			m.erase(c);
		} else{
			m.insert(c);
		}
	}
	if(m.empty()){
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void swap(int& a, int& b)
{
	int t;
	t = a;	a = b;	b = t;
}

int main()
{
	int a, b, c, t;
	cin >> a >> b >> c;

	if (a > b) {
		swap(a, b);
	}
	if (b > c) {
		swap(b, c);
	}
	if (a > b) {
		swap(a, b);
	}
	cout << a << " " << b << " " << c << endl;
	
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
using namespace std;
#define INF 1 << 29

#define elif else if
#define read cin >>
#define echo cout <<
#define fin << '\n'
#define endl '\n'

int main(){
   	string a, b;
   	read a >> b;
   	a += a;
   	echo ( a.find(b) == string::npos ? "No\n" : "Yes\n" );
	return 0;
}


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

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int keta(int _val) {
    int ans = 0;
    while (_val > 0) {
        _val /= 10;
        ans++;
    }
    return ans;
}

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a >= k) {
        cout << k << endl;
    } else {
        if (a + b >= k) {
            cout << a << endl;
        } else {
            int val = k - (a + b);
            cout << a - val << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

long long int ps(long long int x , long long int n){
    if(n==0) return 1;
    if(n==1) return x ;
    if(n%2) return ((x* ps(x,n-1)));
    else {
        long long int z=ps(x,n/2);
        return (z*z) ;
    }
}

bool ssort(const pair<int,int> &a,
              const pair<int,int>  &b)
{
    return (a.second > b.second);
}
bool ssort3(const pair<int,int> &a,
              const pair<int,int>  &b)
{
    if(a.first == b.first) return (a.second < b.second);
    return (a.first < b.first);
}


string s="";
#define md 1000000007



int main()
{
    IOS;
    long long int n,m,a;
    map  < int , int > mp;
    cin >> n >> m;
    for (int i=0 ;i < m ;i++) {
        cin >> a;
        mp[a]+=1;
    }
    long long int res[n+1];
    memset(res ,0 ,sizeof res);
    int deb=-1;
    res[0]=1;
    if(mp[1]==0) {deb=1;}
    else if(mp[2]==0){
            deb=2;
    }
    if(deb==-1) cout <<0;
    else {
        for(int i =deb ;i <=n ;i++){
                if(mp[i]==0 && i>=2) res[i]=(res[i-1]+res[i-2])%md ;
                else if(mp[i]==0 ) res[i]=(res[i-1])%md ;

        }
        cout << res[n];
    }


}


Measured memory_bytes: 5760
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

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

  ll a, b;
  cin >> a >> b;
  
  if(a*b <= 0) cout << "Zero" << endl;
  else if(a > 0 && b > 0) cout << "Positive" << endl;
  else cout << (abs(b-a)%2 == 0 ? "Negative" : "Positive") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <queue>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
    string a, b;
    cin >> a >> b;

    if (a.size() > b.size())
    {
        cout << "GREATER" << endl;
        return 0;
    }
    else if (a.size() < b.size())
    {
        cout << "LESS" << endl;
        return 0;
    }
    
    for (int i = 0; i < a.size(); i++)
    {
        if ((a[i]) > (b[i]))
        {
            cout << "GREATER" << endl;
            return 0;
        }
        else if ((a[i]) < (b[i]))
        {
            cout << "LESS" << endl;
            return 0;
        }
    }
    
    cout << "EQUAL" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
4 3 2 3
1 4 1 100
1 2 1 10
1 3 20 1

0123年後まで
Nを使う場合
N-1を使う場合･･･でDPかな
円でi-Nまでの最安値、Nからtまでスの最安値

*/
ll n,m,s,t; 
vector<ll> U(100010,0), V(100010,0), ans(100010,0);
map<pair<ll,ll>,pair<ll,ll>> M;
vector<ll> yDP(100010,1e15), sDP(100010,1e15);
vector<vector<ll>> G(100010,vector<ll>(0,0));
queue<pair<ll,ll>> Q;
void y_bfs(){
  while(!Q.empty()){
    ll v=Q.front().first, y=Q.front().second;
    Q.pop();
    for(auto next_v: G[v]){
      ll now_y=y+M[make_pair(v,next_v)].first;
      if(yDP[next_v]<=now_y) continue;
      yDP[next_v]=now_y;
      Q.push(make_pair(next_v, now_y));
    }
  }
}

void s_bfs(){
  while(!Q.empty()){
    ll v=Q.front().first, y=Q.front().second;
    Q.pop();
    for(auto next_v: G[v]){
      ll now_y=y+M[make_pair(v,next_v)].second;
      if(sDP[next_v]<=now_y) continue;
      sDP[next_v]=now_y;
      Q.push(make_pair(next_v, now_y));
    }
  }
}

int main(){
  ll def=1e15;
  cin>>n>>m>>s>>t;
  for(ll i=0; i<m; i++){
    ll u,v,a,b; cin>>u>>v>>a>>b;
    M[make_pair(u,v)]=make_pair(a,b);
    M[make_pair(v,u)]=make_pair(a,b);
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }
  //最安値いれる
  yDP[s]=0;
  Q.push(make_pair(s,0));
  y_bfs();//開始とおかね
  sDP[t]=0;
  Q.push(make_pair(t,0));  
  s_bfs();//ゴールとおかね、逆算して求めるかんじ
  //換金したあとゴールにいくまでにいくらかかるか。DPする。
  for(int i=1; i<=n; i++) ans[i]=yDP[i]+sDP[i];
  //最安値で上書きしてく
  for(int i=n-1; i; i--) ans[i]=min(ans[i],ans[i+1]);
  for(ll i=1; i<=n; i++) cout<<def-ans[i]<<endl;
}

Measured memory_bytes: 29696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] dts = new int[3];
        String[] str = br.readLine().split(" ");
        for (int i = 0; i < 3; i++) {
            dts[i] = Integer.parseInt(str[i]);
        }
        System.out.println(dts[0] - dts[1] * dts[2] <= 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 32728
import java.util.*;
import java.math.*;
class Main{
    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        for(int i=0;i<a;i++){
            BigInteger b=s.nextBigInteger();
            BigInteger c=s.nextBigInteger();
            BigInteger d=b.add(c);
            if(d.compareTo(new BigInteger("99999999999999999999999999999999999999999999999999999999999999999999999999999999"))==1)System.out.println("overflow");
            else System.out.println(d.toString());
        }
    }
}

Measured memory_bytes: 26484
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


ll n, h, w, a, b;

int main(){
	cin >> n >> h >> w;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> a >> b;
		if(h <= a && w <= b) cnt++;
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
small=list('abcdefghijklmnopqrstuvwxyz')
A=[0]*26
B=[0]*26
s=input()
t=input()
for i in range(26):
  A[i]=s.count(small[i])
  B[i]=t.count(small[i])
for i in range(len(s)):
  if A[small.index(s[i])]!=B[small.index(t[i])]:
    print('No')
    exit()
  else:
    A[small.index(s[i])]=-i-1
    B[small.index(t[i])]=-i-1
print('Yes')

Measured memory_bytes: 3632
var input: string = require('fs').readFileSync('/dev/stdin', 'utf8');
var inputLines: string[] = input.trim().split("\n");
var parts = inputLines[0].split(" ");

var A = parseInt(parts[0]);
var B = parseInt(parts[1]);

var ans = A >= B ? "Alice" : "Bob";
if (A == B) {
    ans = "Draw";
} else if (A == 1) {
    ans = "Alice";
} else if (B == 1) {
    ans = "Bob";
}

console.log(ans);

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

int main(void){
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    vector<int> index(N);
    for(int i{0}; i<N; ++i){
        index.at(i) = i+1;
        cin >> P.at(i);
    }
    for(int i{0}; i<N; ++i){
        cin >> Q.at(i);
    }

    int num{1};
    int p_n{0};
    int q_n{0};
    do{
        bool p_c{true};
        bool q_c{true};

        for(int i{0}; i<N; ++i){
            if(P.at(i)!=index.at(i)){
                p_c = false;
            }
            if(Q.at(i)!=index.at(i)){
                q_c = false;
            }
        }
        if(p_c){
            p_n = num;
        }
        if(q_c){
            q_n = num;
        }
        if(p_n != 0 and q_n != 0){
            break;
        }
        ++num;
    } while(next_permutation(index.begin(), index.end()));

    cout << abs(p_n-q_n) << endl;
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

int main()
{
  int n;
  cin>>n;
  cout<<(n*(n+1))/2<<endl;
  return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 



 
signed main(){
    int n;
    cin>>n;
   int a[n];
   for(int i=0;i<n;i++)cin>>a[i];
    int m=0,k[n]={};
    for(int i=n-1;i>=0;i--){
        k[i]=a[i];
        for(int j=2*(i+1)-1;j<n;j+=i+1){
            k[i]=(k[i]+k[j])%2;
                    }
        m+=k[i];
    }
    cout<<m<<endl;
    for(int i=0;i<n;i++){
        if(k[i]!=0)cout<<i+1<<' ';
    }
    return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  vector<int> c(n-1);
  vector<int> s(n-1);
  vector<int> f(n-1);
  rep(i,n-1){
    cin>>c[i]>>s[i]>>f[i];
  }

  rep(i,n-1){
    int ans=0;
    // cout<<"i "<<i<<endl;
    for(int j=i;j<n-1;j++){
      if(s[j]>=ans){
        ans=s[j]+c[j];
      }else{
        int d=ans-s[j];
        if(ans%f[j]==0){
          ans+=c[j];
        }else{
          ans=s[j]+(d/f[j])*f[j]+f[j]+c[j];
        }
      }
      // cout<<"ans "<<ans<<endl;
    }
    cout<<ans<<endl;
  }
  cout<<0<<endl;

  return 0;
}


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

void f(int r,int d, int x, int k = 1){
    if(k > 10){
        return ;
    }else{
        cout << r*x-d << endl;
        f(r,d,r*x-d,k+1);
    }
}

int main() {
    int r,d,x;
    cin >> r >> d >> x;

    f(r,d,x);
}


Measured memory_bytes: 764
#include<stdio.h>
#define A 100
 
int main(){
 
  int b,c,d=0,e,f;
  int a[A];
 
  scanf("%d",&e);
 
  for(b=0;b<e;b++){
    scanf("%d",&a[b]);
  }
 
  for(b=0;b<e;b++){
    for(c=e-1;c>b;c--){
      if(a[c]<a[c-1]){
    f=a[c];
    a[c]=a[c-1];
    a[c-1]=f;
    d++;
      }
    }
  }
 
  for(c=0;c<e;c++){
    if(c==e-1)
      printf("%d",a[c]);
    else
      printf("%d ",a[c]);
  }
  printf("\n%d\n",d);
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd
#include <limits> // std::numeric_limits<long int>::max()

template<typename T>
T powint (const T& x, const T& y) {
  T ret = 1;
  for(int i=0; i<y; ++i) ret *= x;
  return ret;
}

template<typename T>
T factorial (const T& n) {
  if (n == 0 || n == 1) return 1;
  else return n * factorial(n - 1);
}

template<typename T>
T combination (const T& n, const T& r) {
  if(n<r) return 0;
  return factorial(n) / (factorial(r) * factorial(n-r));
}

template<typename T>
T permutation (const T& n, const T& r) {
  if(n<r) return 0;
  return factorial(n) / factorial(n-r);
}

int main() {
  long int N;
  std::cin >> N;
  std::vector<long int> A(N);
  for(int i=0; i<N; ++i) std::cin >> A[i];
  std::vector<long int> bin(N, 0);
  for(int i=0; i<N; ++i) bin[A[i]-1]++;
  
  long int sum = 0;
  for(int j=0; j<N; ++j) {
    sum += bin[j] * (bin[j] - 1) / 2;
  }

  for(int i=0; i<N; ++i) {
    long int tmp = sum;
    tmp -= bin[A[i]-1]-1;
    std::cout << tmp << std::endl;
  }

  return 0;
}



Measured memory_bytes: 5760
/*input
bus
*/
#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<pair<int,int>, null_type, less<pair<int,int>>, 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 double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    string s;
    cin>>s;
    if(s.back()=='s'){
        s+="es";
    }
    else{
        s+="s";
    }
    cout<<s;
}  


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

bool b[80000000]={};

void f(int m,int n){

  for(int i=0;i<80000000;i++){
    b[i]=false;
  }

  int c=0;
  int i=m;
  while(c<n){
    if(b[i]){
      i++;
      continue;
    }
    for(int j=i;j<8000000;j+=i){
      b[j]=true;
    }
    i++;
    c++;
  }
  i=m;
  while(true){
    if(!b[i]){
      cout<<i<<endl;
      return;
    }
    i++;
  }

  return ;
}


main(){
  int n,m;
  while(true){
    cin>>m>>n;
    if(n==0) break;
    f(m,n);
  }
}



Measured memory_bytes: 81224
def find(A,K):
    ANS = []
    for i in range(K,len(A)):
        # check grade[i] > grade[i-1]
        # gr[i] = A[i]*...*A[i-K+1]
        # gr[i-1] = A[i-1]*...*A[i-K]
        # check A[i] > A[i-K]
        if A[i] > A[i-K]:
            ANS += ["Yes"]
        else:
            ANS += ["No"]
    print("\n".join(ANS))

n,k = list(map(int,input().strip().split()))
A = list(map(int,input().strip().split()))
find(A,k)

Measured memory_bytes: 107776
N = int(input())
A = list(input())

ans = 0
l, r = 0, N - 1
while l < r:
    if A[l] == 'W' and A[r] == 'R':
        l += 1
        r -= 1
        ans += 1
    else:
        if A[l] == 'R':
            l += 1
        if A[r] == 'W':
            r -= 1
print(ans)


Measured memory_bytes: 10796
//============================================================================
// Name        : Test4.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

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



Measured memory_bytes: 3096
#include<iostream>

using namespace std;

int i, j, ans, now, a, b, total, Anna[5000], Blue[5000];

int main(){

	cin >> a >> b;
	for(i=0;i<a;i++){
		cin >> Anna[i];
	}
	for(i=0;i<b;i++){
		cin >> Blue[i];
	}


	for(i=0;i<b-ans;i++){
		now = i;
		for(j=0;j<a;j++){
			if(Blue[now] == Anna[j]){
				total++;
				now++;
			}
		}
		ans = max(ans, total);
		total = 0;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}
 
int main() {
    int n;
    cin >> n;
    vector<int> a(n - 1);
    int ans[210000];
    rep(i, n - 1) {
        cin >> a[i];
        ans[a[i]]++;
    }
    rep1(i, n) cout << ans[i] << "\n";
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
int main()
{
    int N, K; cin >> N >> K;
    vector<int> V(N); cin >> V;

    int ans = INT_MIN;
    int lr_lim = min(N, K);
    for (int l = 0; l <= lr_lim; l++) {
        for (int r = 0; r <= lr_lim - l; r++) {
            vector<int> onhand;
            if (l) onhand.insert(onhand.end(), V.begin(), V.begin() + l);
            if (r) onhand.insert(onhand.end(), V.end() - r, V.end());
            int s  = accumulate(onhand.begin(), onhand.end(), 0);
            int k = min(max(0, K - l - r), (int)onhand.size());
            if (k) {
                sort(onhand.begin(), onhand.end());
                rep(i, k) {
                    if (onhand[i] < 0) s -= onhand[i];
                    else break;
                }
            }
            chmax(ans, s);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

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

	if(s[2] != s[3] or s[4] != s[5]) printf("No\n");
	else printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

int main(void) {
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = n - 1; i >= 0; i -= 2) {
        printf("%d ", a[i]);
    }
    for (int i = n & 1; i < n; i += 2) {
        printf("%d ", a[i]);
    }
}

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

int	main()
{
  int	N;
  int	i;
  cin >> N;
  
  i = 0;
  while (N-- > 0)
  {
    int	l;
    int	r;
    cin >> l >> r;
    
    i += (r - l + 1);
  }
  cout << i << endl;
  return (0);
}


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

using namespace std;

int main() {
	int anum = 0;
	char ans[20] = {};
	string s; cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '0') ans[anum++] = s[i];
		else if (s[i] == '1') ans[anum++] = s[i];
		else if (anum) ans[--anum] = '\0';
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define pi 3.1415926536
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bs binary_search
#define int long long
#define float double

typedef map<int,int> mii;
typedef map<char,int> mci;
typedef map<string,int> msi;
typedef map<string,string> mss;
typedef map<char,char> mcc;
typedef map<pair<int,int>,int> mpi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef set<int> si;
typedef set<string> ss;
typedef set<char> sc;
int const max1= 1e5+5;
int const mod = 1e9+7;


int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
while(t--){
    string s;
    cin>>s;
    int len=0;
    int max1=0;
    for(int i=0;i<3;i++){
        if(s[i]=='R'){
            len++;
        }
        else{
          max1=max(max1,len);
          len=0;
        }
    }
    max1=max(max1,len);
    cout<<max1;
}
}


Measured memory_bytes: 3652
K = int(input())
data = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(data[K-1])

Measured memory_bytes: 3060
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};
struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}



int main(){
    IOS;
    make(ll,n);
    makevec(ll,vec,n);
    ll s=0;
    fr(i,n) s^=vec[i];
    fr(i,n) {
        ll x=s^vec[i];
        cout<<x<<" ";
    }
    return 0;
}


Measured memory_bytes: 4748
#include<bits/stdc++.h>
using namespace std;
int main(){
	vector<int>A;
	long long int n,ai,sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>ai;
		A.push_back(ai);
		sum+=ai;
	}
	int x=sum/n;
	int y=ceil(sum*1.000/n);
	long long int c=0,d=0;
	for(int i=0;i<n;i++){
		c+=pow(A[i]-x,2);
		d+=pow(A[i]-y,2);
	}
	cout<<min(c,d)<<endl;
	
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

int arr[100005 << 2], value[100005], n, q;

void update(int a, int b, int x, int k = 0, int l = 0, int r = (1 << 17)) {
	if (b <= l || r <= a)return;
	if (a <= l && r <= b) {
		arr[k] = max(arr[k], x);
		return;
	}
	int m = (l + r) / 2;
	update(a, b, x, k * 2 + 1, l, m);
	update(a, b, x, k * 2 + 2, m, r);
}

int query(int x) {
	x += (1 << 17) - 1;
	int res = arr[x];
	while (x) {
		x = (x - 1) / 2;
		res = max(res, arr[x]);
	}
	return res;
}

int main()
{
	queue<int> r;
	value[0] = 2147483647;
	cin >> n >> q;
	for (int i = 1; i <= q; ++i) {
		int ch, a, b;
		cin >> ch;
		if (ch) {
			cin >> a;
			r.push(value[query(a)]);
		}
		else {
			cin >> a >> b >> value[i];
			++b;
			update(a, b, i);
		}
	}
	while (!r.empty())
	{
		cout << r.front() << endl;
		r.pop();
	}
	return 0;
}



Measured memory_bytes: 4444
/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout); 
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

void solve(){
	string s;cin>>s;
	ll i;
	rep(i,s.length())
	{
		if((i+1)&1)
		{
			if(s[i]=='U' || s[i]=='D' || s[i]=='R')
				continue;
			else {
				cout<<"No";
				return;
			}
		}
		else
		{
			if(s[i]=='U' || s[i]=='D' || s[i]=='L')
				continue;
			else {
				cout<<"No";
				return;
			}
		}
	}
	cout<<"Yes";
}

int main(){
	//fio();
	fast

	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int n;
    cin >> n;
    int a[3 * n];
    rep (i, 0, 3 * n) cin >> a[i];
    sort (a, a + 3 * n, greater<int>());
    int ans = 0;
    for (int i = 1; i < 2 * n; i += 2) ans += a[i];
    cout << ans << "\n";
}

Measured memory_bytes: 5972
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
X = 0
Y = 0
for i in range(N):
  if ans < (X + V[i]) - (Y + C[i]):
      X += V[i]
      Y += C[i]
      ans = X - Y

print(ans)

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

int main() {
  int h,w;
  cin>>h>>w; vector<string> strings(h);
  for(int i=0; i<h; i++){
    cin>>strings.at(i);
  }
  for(int i=0; i<w+2; i++){
    cout<<"#";
  }
  cout<<endl;
  for(int i=0; i<h; i++){
    cout<<"#"<<strings.at(i)<<"#"<<endl; 
  }
  for(int i=0; i<w+2; i++){
    cout<<"#";
  }
  cout<<endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
using namespace std;
int main(){
  long long N,K;
  cin>> N >>K;
  int i;
  long long ans=0;
  if(K==0){
    ans=N*N;
  }else{
  for(i=K+1;i<=N;i++){
    ans+=(N/i)*(i-K);
    if(N%i>=K){
      ans+=N%i-K+1;
    }
  }
  }
  cout<<ans;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

///////////////////////////////////////////////////////////////////////////

int main(){
    ll n,x = 0, y = 0,ans =0;
    cin >> n;
    rep(i,0,n){
        ll t,a;
        cin >> t >> a;

        if ( i == 0){
            x = t;
            y = a;
            ans += x + y;
        }else{

            if( t == a){
                if(x > y){
                    ans += x - y;
                    y = x;
                }else if( x < y){
                    ans += y - x;
                    x = y;
                }
            }else{
                ll o,xx,yy;
                if(t > a)o = (y+a-1) / a;
                else o = (x+t-1) / t;
                
                xx = t * o;
                yy = a * o;
                if(xx < x || yy < y){
                    o += max(((x-xx)+t-1)/t, ((y-yy)+a-1)/a);  
                    xx = t * o;
                    yy = a * o;
                }

               
                ans += xx-x + yy-y;
                x = xx;
                y = yy;
            }
        }

       // cout << x << " " << y << " " << ans << endl;
    }

    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
#define MAX 500000
#define SENTINEL 2000000000

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
struct Node
{
    ll key;
    Node *right,*left,*parent;
};
Node *root, *NIL;
void insert(ll k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    //メモリの確保
    z = (Node *)malloc(sizeof(Node));
    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;

    while( x!=NIL ){
        y = x;
        if(z -> key < x ->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z -> parent = y;
    if(y ==NIL){
        root = z;
    }else{
        if(z ->key < y->key){
            y ->left = z;
        }else{
            y ->right = z;
        }
    }
}
void PreorderWalk(Node *u){
    if(u == NIL)return;
    cout << " "<< u->key; 
    PreorderWalk(u->left);
    PreorderWalk(u->right);
}

void InorderWalk(Node *u){
    if(u == NIL)return; 
    InorderWalk(u -> left);
    cout << " "<< u->key;
    InorderWalk(u -> right);
}

int main(){
    ll n,i,x;
    string com;
    cin >> n;
    REP(i,n){
        cin >> com;
        if(com == "insert"){
            cin >> x;
            insert(x);
        }else if(com =="print"){
            InorderWalk(root);
            cout << endl;
            PreorderWalk(root);
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 26548
n=int(input())
ps=[0 for j in range(n+1)]

for i in range(n):
    p,d,*vs=[int(j) for j in input().split()]
    ps[p]=vs
    
dist=[-1 for i in range(n+1)]    
    
d=0
queue=[1]

while queue:
    pos=queue.pop(0)
    if dist[pos] == -1:
        dist[pos]=d
    for i in ps[pos]:
        if dist[i]==-1:
            queue.append(i)
            dist[i]=dist[pos]+1

for i in range(1,n+1):
    print(i,dist[i])
    


Measured memory_bytes: 5628
// p(素数)を法とした時 nCkを計算 1〜max n の逆元も求める。 
// 参考ページ  http://drken1215.hatenablog.com/entry/2018/06/08/210000
// O(N)


#include<iostream>

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

using namespace std;

typedef long long ll;

ll factorial[MAX_N + 1];//factorial[n] := n! mod p
ll factorial_inverse[MAX_N+1];//factorial_inverse[n] = (n!)^-1 mod p
ll inverse[MAX_N + 1];

void precompute_for_combination(ll n,ll p) {//前計算 階乗や階乗の逆限を求めておく
    factorial[0] = factorial[1] = 1;
    factorial_inverse[0] = factorial_inverse[1] = 1;
    inverse[1] = 1;
    for(int i = 2;i <= n;i++) {
        factorial[i] = factorial[i - 1] * i % p;
        inverse[i] = p - inverse[p % i] * (p / i) % p;
        factorial_inverse[i] = factorial_inverse[i - 1] * inverse[i] % p;
    }
}

ll combination(ll n,ll k,ll p) {
    if(n < k || n < 0 || k < 0) return 0;//不正な値
    return factorial[n] % p * factorial_inverse[k] % p * factorial_inverse[n - k] % p;
}

ll N,A,B,K;
int main() {
    cin >> N >> A >> B >> K;
    ll p = 998244353;

    precompute_for_combination(N,p);

    ll ret = 0;
    rep(i,N+1) {
        ll a = i;
        ll b = K - a * A;
        if(b % B)continue;
        b  /= B;
        (ret += combination(N,a,p) * combination(N,b,p) % p) %= p;
    }

    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 10496
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,k,a[nmax],x,nr[nmax],v,mn[nmax],mx[nmax],i,rs;
set<int>s;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<k;i++)s.in(a[i]);
	for(i=k;i<=n;i++)
	{
		s.in(a[i]);
		x=*s.begin();
		if(x==a[i-k+1])mn[i-k+1]=1;
		x=*s.rbegin();
		if(x==a[i])mx[i]=1;
		s.er(s.fd(a[i-k+1]));
	}
	rs=n-k+1;
	for(i=1;i<=n-k;i++)
	{
		if(mn[i] && mx[i+k])
		{
			nr[i+1]=1;
		}
	}
	x=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]>=a[i-1])x++;
		else x=1;
		if(x>=k)nr[i-k+1]=1,v=1;
	}
	for(i=1;i<=n;i++)rs-=nr[i];
	rs+=v;
	cout<<rs<<endl;
	return 0;
}


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

int main() {
  int cnt = 1;
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    int jpeg[n][n];

    jpeg[0][0] = 1;
    int vx, vy;
    int x, y;
    int num = 2;
    x = 0, y = 0;
    vx = 1, vy = 0;
    bool flag = false;
    while(1) {
      if(x == n-1 && y == n-1) break;

      if(x == n-1 && y == 0 && vx == 1 && vy == -1) {
	vx = 0;
	vy = 1;
	flag = true;
      }
      if(x == 0 && y == n-1 && vx == -1 && vy == 1) {
	vx = 1;
	vy = 0;
	flag = true;
      }

      x += vx;
      y += vy;
      if(x < 0 || x >= n) {
	x -= vx;
	y -= vy;
	vx = 0;
	vy = 1;
	continue;
      } else if(y < 0 || y >= n) {
	x -= vx;
	y -= vy;
	vx = 1;
	vy = 0;
	continue;
      }

      if((!flag && vy == 0) || (flag && vx == 0)) {
	vx = -1;
	vy = 1;
      } else if((!flag && vx == 0) || (flag && vy == 0)) {
	vx = 1;
	vy = -1;
      }
      jpeg[y][x] = num++;
    }

    cout << "Case " << cnt++ << ':' << endl;
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	printf("%3d", jpeg[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
h = list(map(int, input().split()))


def water(h):
    if len(h) == 0:
        return 0
    if len(set(h)) == 1:
        return h[0]
    elif not h.count(0):
        h2 = list(map(lambda x: x - 1, h))
        return water(h2) + 1
    else:
        ans = 0
        zeros = [i for i, x in enumerate(h) if x == 0]
        zeros.insert(0, -1)
        zeros.append(len(h))
        for i in range(len(zeros) - 1):
            ans += water(h[zeros[i]+1:zeros[i + 1]])
        return ans

print(water(h))


Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
    int d,s,x;
    int i;

    while (scanf("%d", &d) != EOF){
        s = 0;
        x = d;
        for (x = d; x < 600; x += d){
            s += d * x * x;
        }
        printf("%d\n", s);
    }

    return (0);
}


Measured memory_bytes: 1968
n, k = gets.split.map(&:to_i)

ws = $stdin.readlines.map(&:to_i)

check = lambda do |p|
  i = 0
  0.upto(k - 1) do |j|
    s = 0
    while s + ws[i] <= p
      s += ws[i]
      i += 1
      return n if i == n
    end
  end
  return i
end

left = 0
right = 100000 * 10000

while right - left > 1
  mid = (left + right) / 2
  v = check.call(mid)
  if v >= n
    right = mid
  else
    left = mid
  end
end

puts right

Measured memory_bytes: 13744
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

ll a,b,c,d,n;
map<ll,ll> f;

ll calc(ll n)
{
    if (!n) return 0;
    if (f[n]) return f[n];
    ll ans=4e18;
    if (n<ans/d) ans=n*d;
    rep(i,-2,2)
    {
        if ((n+i>=0) && ((n+i)%2==0) && ((n+i)/2!=n))
        {
            ll tmp=calc((n+i)/2)+a+d*abs(i);
            ans=min(ans,tmp);
        }
    }
    rep(i,-3,3)
    {
        if ((n+i>=0) && ((n+i)%3==0) && ((n+i)/3!=n))
        {
            ll tmp=calc((n+i)/3)+b+d*abs(i);
            ans=min(ans,tmp);
        }
    }
    rep(i,-5,5)
    {
        if ((n+i>=0) && ((n+i)%5==0) && ((n+i)/5!=n))
        {
            ll tmp=calc((n+i)/5)+c+d*abs(i);
            ans=min(ans,tmp);
        }
    }
    f[n]=ans;
    return ans;
}

int main()
{
    int T=read();
    while (T--)
    {
        ll n=readll();
        a=read();b=read();c=read();d=read();
        f.clear();f[1]=d;
        printf("%lld\n",calc(n));
    }
    return 0;
}

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

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

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

inline ll popcnt(ll x){return __builtin_popcount((unsigned int)x);};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vl P(N); rep(i, N) cin >> P[i];
    ll ans = 0;
    rep(i, N-2){
        vl tmp;
        rep(j, 3) tmp.pb(P[i+j]);
        sort(tmp.begin(), tmp.end());
        if(tmp[1] == P[i+1]) ans++;
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#include <climits>
#include <cstring>
#include <functional>

using namespace std;

using ll = long long;

#define rep(i, N) for(int i = 0;i < N;i++)
#define LARGE INT_MAX / 2


int a[100][2];
int l[100];
int r[100];

int main() {
	int N;
	cin >> N;
	rep(j, 2) {
		rep(i, N) {
			cin >> a[i][j];
		}
	}
	l[0] = a[0][0];
	r[N - 1] = a[N - 1][1];
	for (int i = 1; i < N; i++) {
		l[i] += a[i][0] + l[i - 1];
		r[N - i - 1] += a[N - i - 1][1] + r[N - i];
	}
	int ans = 0;
	rep(i, N) {
		ans = max(ans, l[i] + r[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256