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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int k, a, b;
	cin >> k >> a >> b;
	bool flag = false;
	for (int i = a; i <= b; i++) {
		if (i % k == 0)
			flag = true;
	}
	if (flag)
		cout << "OK" << endl;
	else
		cout << "NG" << endl;
	return 0;
}

//!

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

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

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
double dp[301][301][301];
double expectation(int  N,int n1,int n2,int n3)
{
if(n1<=0&&n2<=0&&n3<=0)return 0;
if(dp[n1][n2][n3]!=-1)return dp[n1][n2][n3];
double a=0,b=0,c=0,nn=N,np=(n1+n2+n3),c1=0;
if(n1>0){a=expectation(N,n1-1,n2,n3);c1++;}
if(n2>0){b=expectation(N,n1+1,n2-1,n3);c1++;}
if(n3>0){c=expectation(N,n1,n2+1,n3-1);c1++;}
//dp[n1][n2][n3]=(nn/np)+(a*((float)n1/(n1+n2+n3))+b*((float)n2/(n1+n2+n3))+c*((float)n3/(n1+n2+n3)));
dp[n1][n2][n3]=((nn/np) + a)*((double)n1/(n1+n2+n3))+((nn/np) + b)*((double)n2/(n1+n2+n3))+((nn/np) + c)*((double)n3/(n1+n2+n3));


//cout<<dp[n1][n2][n3]<<"  "<<n1<< "  "<< n2<<" "<<n3<<endl;

return dp[n1][n2][n3];
}



main(){
int N;
cin>>N;
int p[N];
for(int i=0;i<N;i++)cin>>p[i];
//double dp[N+1][N+1][N+1];
for(int i=0;i<=N;i++)for(int j=0;j<=N;j++)for(int k=0;k<=N;k++){
dp[i][j][k]=-1;

}
//cout<<"done";
//return 0;


int n1=0,n2=0,n3=0;
for(int i=0;i<N;i++){if(p[i]==1)n1++;
		     if(p[i]==2)n2++;
		     if(p[i]==3)n3++;}




//cout<<n1<<"  "<<n2<<" "<<n3;		     
double out=expectation(N,n1,n2,n3);
printf("%.10lf",out);

}


Measured memory_bytes: 213376
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	ll n, m, k; cin >> n >> m >> k;
	vector<ll> a(n + 1), b(m + 1);
	rep(i, n)cin >> a[i + 1];
	rep(i, m)cin >> b[i + 1];
	rep(i, n)a[i + 1] += a[i];
	rep(i, m)b[i + 1] += b[i];
	ll res = 0;
	rep(i, n + 1)
	{
		if (a[i] > k)continue;
		ll tmp = i;
		tmp += upper_bound(all(b), k - a[i]) - b.begin() - 1;
		chmax(res, tmp);
	}
	rep(i, m + 1)
	{
		if (b[i] > k)continue;
		ll tmp = i;
		tmp += upper_bound(all(a), k - b[i]) - a.begin() - 1;
		chmax(res, tmp);
	}
	cout << res << endl;
}

Measured memory_bytes: 6420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
int f[10];
int n,x[10],y[10];
int p2(int x){
    return x*x;
}
db cal(int i,int j){
    return sqrt(p2(x[i]-x[j])+p2(y[i]-y[j]));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d%d",x+i,y+i);
    db ans=0.0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++)ans+=cal(i,j);
    }
    ans*=2.0/n;
    printf("%.6Lf\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
const string YES = "Yes";
const string NO = "No";

void solve(long long X){
    cout << ((X >= 30)?YES:NO) <<endl;
}
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3684
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	char S[100001];
	while(~scanf("%s", S)) {
		int n = (int)strlen(S);
		const char *strs[4] = { "dream", "dreamer", "erase", "eraser" };
		vector<bool> dp(n + 1);
		dp[0] = true;
		rep(i, n) if(dp[i]) {
			rep(k, 4) {
				int j = 0;
				for(; strs[k][j] != 0 && strs[k][j] == S[i + j]; ++ j);
				if(strs[k][j] == 0)
					dp[i + j] = true;
			}
		}
		bool ans = dp[n];
		puts(ans ? "YES" : "NO");
	}
	return 0;
}


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

const ll LINF = 9223372036854775807;
vector<int> v = {2, 3, 5};

ll n, d;
vector<int> a(3);
map<ll, ll> dp;

ll dfs(ll x) {
  if (dp.count(x)) return dp[x];
  ll res;
  if (d < LINF / x) res = d * x;
  else res = LINF;
  rep(i, 3) {
    ll tmp1 = dfs(x / v[i]) + a[i] + abs(x - x / v[i] * v[i]) * d;
    ll tmp2 = dfs((x - 1) / v[i] + 1) + a[i] + abs(x - ((x - 1) / v[i] + 1) * v[i]) * d;
    res = min({res, tmp1, tmp2});
  }
  dp[x] = res;
  return res;
}

int main() {
  int t; cin >> t;
  while (t--) {
    cin >> n >> a[0] >> a[1] >> a[2] >> d;
    dp.clear();
    dp[0] = 0;
    dp[1] = d;
    cout << dfs(n) << endl;
  }
  return 0;
}

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

    int main(){
      int x,y;
      cin >> x >>y;
      cout << x+y/2 << endl;
      return 0;}

Measured memory_bytes: 888
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
#define int long long
signed main() {
    /*int n;cin >> n;
    vi a(n);
    int LCM=1;
    rep(i, n) {
        cin >> a[i];
        LCM=lcm(LCM,a[i]);
    }
    // int ma=-1;
    int sum = 0;
    /*rep1(i, LCM) {
        sum=0;
        rep(j, n) {
            sum+=i%a[j];
        }
        chmax(ma,sum);
    }*/
    /*rep(i, n) sum+=(LCM-1)%a[i];
    cout << /*ma*//*sum << endl;*/
    int n;cin >> n;
    int sum=0;
    rep(i, n) {
        int a;cin >> a;
        sum+=a-1;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3600
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
 
ab = [[int(x) for x in input().split()] for _ in range(n)]
 
ab.sort(key=lambda x: x[0])
 
count, cost, index = 0, 0, 0

for x in ab:
  bottle = x[1]
  if count + bottle < m:  
    count += bottle
    cost += ab[index][0] * bottle
    index += 1
  else:
    cost += ab[index][0] * (m - count)
    break

print(cost)

Measured memory_bytes: 22812
n = int(input())

xarr = list(map(int, input().split()))
X = 0

for x in xarr:
  X += x
  
mean = X//n

ans1 = 0
ans2 = 0

for x in xarr:
  ans1 += (x - mean) * (x - mean)
  ans2 += (x - mean - 1) * (x - mean - 1)

print(min(ans1, ans2))

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

const ll INF = 1e18;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    vector<int> pre(N + 1);
    iota(pre.begin(), pre.end(), -1);
    for(int i = 0;i < M;i++){
        int L, R;
        cin >> L >> R;
        pre[R] = min(pre[R], L - 1);
    }
    for(int i = N - 1;i >= 0;i--){
        pre[i] = min(pre[i], pre[i + 1]);
    }
    vector<ll> dp(N + 1, -INF);
    dp[0] = 0;
    for(int i = 0;i < N;i++){
        dp[i + 1] = max(dp[i], dp[pre[i + 1]] + A[i]);
    }
    cout << dp[N] << endl;
    return 0;
}



Measured memory_bytes: 5936
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  vector<int> ns;
  ns.push_back(1);
  for(auto n : {6, 9}) {
    int nn = n;
    while(nn <= N) {
      ns.push_back(nn);
      nn *= n;
    }
  }
  sort(ns.begin(), ns.end());

  vector<int> es(N + 1, INF);
  es[0] = 0;
  for(int i = 0; i < N; ++i) {
    for(auto n : ns) {
      auto next = i + n;
      if(next <= N) {
        es[next] = min(es[i] + 1, es[next]);
      }
    }
  }
  cout << es[N] << endl;

  return 0;
}

Measured memory_bytes: 640
k,s = list(map(int,input().split()))

def fact(n):
  return sum([x for x in range(1,n+1)])

ans = 0
r = 0
for x in range(k+1):
  for y in range(x,k+1):
    if 0 <= s - (x+y) <= k:
      if (x==y):
          ans += 1
      else:
          ans += 2

print(ans)

Measured memory_bytes: 3060
S=input()
T=input()
char_dict={}
target_chatrs=[]
is_valid=True
for i in range(len(S)):
    if S[i] not in char_dict:
        if T[i] in target_chatrs:
            is_valid=False
            break
        char_dict[S[i]]=T[i]
        target_chatrs.append(T[i])
    else:
        if char_dict[S[i]]!=T[i]:
            is_valid=False
            break
if is_valid:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3632
a, b = map(int, input().split())

A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]

if (a in A and b in A) or (a in B and b in B) or (a in C and b in C):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)
bool arr[21][21];
int n;
int dp[21][1<<21];

int inline rec(int m,int f)
{
    if(m==-1) return 1;
    if(dp[m][f]!=-1) return dp[m][f];
    else
    {
        int i;
        dp[m][f]=0;
        rep(i,0,n)
        {
            if(arr[m][i] && (f&(1<<i)))
            {
                dp[m][f]+=rec(m-1,f^(1<<i));
                dp[m][f]%=mod;
            }
        }
        return dp[m][f];
    }
}

int main()
{
    int i,j,t;
    //boost;
    scanf("%d",&n);
    char c;
    getchar();
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            c=getchar();
            arr[i][j]=c-'0';
            getchar();
        }
    }
    
    rep(i,0,n)
    {
        rep(j,0,1<<21)
        {
            dp[i][j]=-1;
        }
    }
    int f=1<<n ;
    f--;
    printf("%d",rec(n-1,f));
    

    return 0;
}



Measured memory_bytes: 172288
#include<stdio.h>
#define N 200
int a,A[N];
int judge(int, int);

int main(){
    int b,B[N],i;

    scanf("%d",&a);
    for(i = 0;i < a;i++){
        scanf("%d",&A[i]);
    }

    scanf("%d",&b);
    for(i = 0;i < b;i++){
        scanf("%d",&B[i]);
    }
    for(i = 0;i < b;i++){
        if(judge(0,B[i]) == 1){
            printf("yes\n");
        }else printf("no\n");
    }

    return 0;
}
int judge(int cnt,int c)
{
int sum;
if(c == 0)return 1;
if(cnt >= a)return 0;
sum = judge(cnt+1,c) || judge(cnt+1,c - A[cnt]);
return sum;
}


Measured memory_bytes: 2104
#define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;
int main(){
        int n,u,k,v;
        cin >> n;
        int g[n][n];
        REP(i,n){
                REP(j,n){
                        g[i][j] = 0;
                }
        }
        REP(i,n){
                cin >> u >> k;
                REP(j,k){
                        cin >> v;
                        g[v-1][u-1] = 1;
                }
        }
        REP(i,n){
                REP(j,n){
                        cout << (j?" ":"") << g[j][i];
                }
                cout << endl;
        }
}

Measured memory_bytes: 1200
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        Console.WriteLine(Base26(n));
    }

    public static string Base26(long self)
    {
        if (self <= 0) return "";

        long n = (self % 26 == 0) ? 26 : self % 26;
        if (self == n) return ((char)(n + 96)).ToString();
        return Base26((self - n) / 26) + ((char)(n + 96)).ToString();
    }
}

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

const int INF = 1e9 + 7;

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	vector <int> p(1111, INF);
	for(int i = 2; i < 1111; i++) {
		if(p[i] == INF) {
			for(int j = i; j < 1111; j += i) {
				p[j] = min(p[j], i);
			}
		}
	}

	vector <int> f(1111, 0);
	int n; cin >> n;
	for(int i = 1; i <= n; i++) {
		int j = i;
		while(j > 1) {
			f[p[j]]++;
			j /= p[j];
		}
	}
	long long ans = 1;

	for(int i = 1; i < 1111; i++) {
		ans = (ans * (f[i] + 1)) % INF;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3660
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();
		char tmp=' ';
		int ans=n;
		for(int i=0;i<n;i++) {
			char a=s.charAt(i);
			if(a==tmp) {
				ans--;
			}
			tmp=a;
		}
		System.out.println(ans);
	}
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int d, w;
    int e[10][10];
    while(true){
        cin >> d >> w;
        if(d == 0 && w == 0) break;
        for(int i=0;i<d;i++){
            for(int j=0;j<w;j++) cin >> e[i][j];
        }

        int64_t ans = 0;
        for(int i1=0;i1<d-2;i1++){
            for(int j1=0;j1<w-2;j1++){
                for(int i2=i1+2;i2<d;i2++){
                    for(int j2=j1+2;j2<w;j2++){
                        int min_b = e[i1][j1];
                        int64_t vol = 0;
                        for(int ii=i1;ii<=i2;ii++){
                            min_b = min({min_b, e[ii][j1], e[ii][j2]});
                        }
                        for(int jj=j1;jj<=j2;jj++){
                            min_b = min({min_b, e[i1][jj], e[i2][jj]});
                        }
                        for(int ii=i1+1;ii<i2;ii++){
                            for(int jj=j1+1;jj<j2;jj++){
                                if(min_b - e[ii][jj] <= 0) goto next;
                                vol += min_b - e[ii][jj];
                            }
                        }
                        ans = max(ans, vol);
                        next:;
                    }
                }
            }
        }

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


Measured memory_bytes: 3152
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int[] a = new int[3];
        for (int i = 0; i < 3; i++) a[i] = sc.nextInt();
        // for(int i = 0; i < 3; i++) a[i] = sc.nextInt();
        Arrays.sort(a);
        System.out.println(a[0] + " " + a[1] + " " + a[2]);
    }
}


Measured memory_bytes: 26256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;
		static int gyes = 0;
		static int gno = 0;
int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int d[128][2];
		for (int i = 0; i < n; ++i)
		{
			int t;
			scanf("%d", &t);
			d[i][0] = t / 10;
			d[i][1] = t % 10;
		}
		int c[10];
		memset(c, 0, sizeof(c));
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < 2; ++j)
				++c[d[i][j]];


		int follow = -1;

		bool usedNum[10];
		fill(usedNum, usedNum+10, false);
		bool used[128];
		fill(used, used+n, false);

		{
			int i;
			for (i = 0; follow == -1 && i < n; ++i)
			{
				if (c[d[i][0]] & 1)
					follow = d[i][1];
				else if (c[d[i][1]] & 1)
					follow = d[i][0];

				if (follow != -1)
				{
					used[i] = true;
					usedNum[d[i][1]] = usedNum[d[i][0]] = true;
				}
			}
			if (follow == -1)
			{
				follow = d[0][0];
				used[0] = true;
				usedNum[d[0][0]] = usedNum[d[0][1]] = true;
			}
		}

		int left = n-1;
		for (bool changed = true; changed; )
		{
			changed = false;
			for (int i = 0; !changed && i < n; ++i)
			{
				if (used[i])
					continue;

				if (follow == d[i][0])
				{
					follow = d[i][1];
					changed = true;
				}
				else if (follow == d[i][1])
				{
					follow = d[i][0];
					changed = true;
				}
				if (changed)
				{
					used[i] = true;
					usedNum[d[i][0]] = usedNum[d[i][1]] = true;
					--left;
				}
			}
		}
		
		for (bool changed = true; left && changed; )
		{
			changed = false;
			for (int u = 0; u < 10; ++u)
			{
				if (!usedNum[u])
					continue;

				int _left = left;
				bool _used[128];
				for (int i = 0; i < n; ++i)
					_used[i] = used[i];

				int _follow = -1;
				for (int i = 0; _follow == -1 && i < n; ++i)
				{
					if (_used[i])
						continue;
					
					if (d[i][0] == u)
						_follow = d[i][1];
					else if (d[i][1] == u)
						_follow = d[i][0];
					
					if (_follow != -1)
					{
						_used[i] = true;
						--_left;
					}							
				}
				for (bool _changed = true; _changed; )
				{
					_changed = false;
					for (int i = 0; !_changed && i < n; ++i)
					{
						if (_used[i])
							continue;

						if (_follow == d[i][0])
						{
							_follow = d[i][1];
							_changed = true;
						}
						else if (_follow == d[i][1])
						{
							_follow = d[i][0];
							_changed = true;
						}
						if (_changed)
						{
							_used[i] = true;
							--_left;
						}
					}
				}
				if (_left != left && _follow == u)
				{
					left = _left;
					for (int i = 0; i < n; ++i)
					{
						if (!used[i] && _used[i])
						{
							used[i] = _used[i];
							usedNum[d[i][0]] = usedNum[d[i][1]] = true;
						}
					}
					changed = true;
				}
			}
		}

		if (!left)
			printf("Yes\n");
		else
			printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	if(a==b && b==c) cout << 1 << endl;
	else if(a==b || b==c || c==a) cout << 2 << endl;
	else cout << 3 << endl;
}

Measured memory_bytes: 256
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int main () {
   string s;
   cin >> s;
   vi v = {0};
   string p;
   for (char c : s) {
      if (c == 'x') {
         v.back()++;
      } else {
         p += c;
         v.pb(0);
      }
   }
   string pt = p;
   reverse(ALL(pt));
   if (pt != p) {
      cout << -1;
   } else {
      int res = 0;
      for (int i = 0, j = SZ(v) - 1; i < j; ++i, --j) {
         res += abs(v[i] - v[j]);
      }
      pisz(res);
   }
}

Measured memory_bytes: 1148
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)


typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;

#define ARRAY_MAX 100005

int main() {

	
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int width = tx - sx;
	int height = ty - sy;

	string s;

	//1周目
	for (int i = 0; i < height; i++)
	{
		s.push_back('U');
	}
	for (int i = 0; i < width; i++)
	{
		s.push_back('R');
	}
	for (int i = 0; i < height; i++)
	{
		s.push_back('D');
	}
	for (int i = 0; i < width; i++)
	{
		s.push_back('L');
	}

	//2周目
	s.push_back('L');
	width++;
	height++;
	for (int i = 0; i < height; i++)
	{
		s.push_back('U');
	}
	for (int i = 0; i < width; i++)
	{
		s.push_back('R');
	}
	s.push_back('D');
	s.push_back('R');
	for (int i = 0; i < height; i++)
	{
		s.push_back('D');
	}
	for (int i = 0; i < width; i++)
	{
		s.push_back('L');
	}
	s.push_back('U');
	cout << s << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    long long dp1[3001][3001] = {}, dp2[3001][3001] = {};;
    for (int w = 0; w < n; w++) {
        for (int i = 0; i + w < n; i++) {
            if (w == 0) { dp1[i][i] = a[i]; dp2[i][i] = -a[i]; }
            else {
                dp1[i][i+w] = max(a[i] + dp2[i+1][i+w], a[i+w] + dp2[i][i+w-1]);
                dp2[i][i+w] = min(- a[i] + dp1[i+1][i+w], - a[i+w] + dp1[i][i+w-1]);
            }
        }
    }
    cout << dp1[0][n-1] << endl;
}


Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, m, d[maxn], fa[maxn];

int find(int x) {
	return x == fa[x]? x : fa[x] = find(fa[x]);
}

int fir[maxn], nxt[maxn], to[maxn], e = 0;
void add(int x, int y) {
	to[++e] = y; nxt[e] = fir[x]; fir[x] = e;
	to[++e] = x; nxt[e] = fir[y]; fir[y] = e;
}

int num[maxn];
void dfs(int pos, int f) {
	int y, z;
	for (y = fir[pos]; y; y = nxt[y]) {
		if((z = to[y]) == f) continue;
		dfs(z, pos);
		num[pos] ^= num[z];
	}
	if(pos > 1) {
		if(num[pos]) printf("%d %d\n", f, pos);
		else printf("%d %d\n", pos, f);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	if(m & 1) {
		printf("-1\n");
		return 0;
	}
	for (int i = 1; i <= n; ++i) fa[i] = i;
	int x, y;
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", &x, &y);
		if(find(x) == find(y)) {
			printf("%d %d\n", x, y);
			d[x] ^= 1;
		}
		else {
			fa[find(x)] = find(y);
			add(x, y);
		}
	}
	if(d[1]) num[1] = 1;
	for (int i = 2; i <= n; ++i) {
		d[i] ^= 1;
		if(d[i]) {
			num[i] = 1;
		}
	}
	dfs(1, 0);
	return 0;
}

Measured memory_bytes: 12064
use std::iter;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let _ = scan!(usize);
    let s = scan!();

    let mut num: usize = 0;
    for c in s.chars().rev() {
        if c == ')' {
            num += 1
        } else if num > 0 {
            num -= 1
        }
    }

    let mut t = String::new();
    if num > 0 {
        t.push_str(&iter::repeat("(").take(num).collect::<String>())
    }
    t.push_str(&s);

    num = 0;
    for c in t.chars() {
        if c == '(' {
            num += 1
        } else if num > 0 {
            num -= 1
        }
    }

    if num > 0 {
        t.push_str(&iter::repeat(")").take(num).collect::<String>())
    }

    println!("{}", t)
}


Measured memory_bytes: 4352
use input::Input;

fn main() {
    let mut input = Input::default();

    let n = input.parse();
    let mut a = (0..n).map(|_| input.parse()).collect::<Vec<usize>>();
    a.sort();

    if a.len() == 1 {
        println!("1");
        return;
    }

    let mut b = vec![true; 1000001];
    let mut c = vec![0u32; 1000001];
    let mut ans = 0;
    for i in 0..n {
        if b[a[i]] || c[a[i]] > 0 {
            c[a[i]] += 1;
        }

        if b[a[i]] {
            let mut j = 1;
            while a[i] * j <= 1000000 {
                b[a[i] * j] = false;
                j += 1;
            }
            ans += 1;
        }
    }
    ans -= c.iter().filter(|x| **x > 1).count();
    println!("{}", ans);
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 15548
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

struct QueueItem
{
  uint64_t key, val;
  QueueItem(uint64_t key, uint64_t val) : key(key), val(val) {}
  bool operator<(const QueueItem &rhs) const { return val < rhs.val; }
};

int main()
{
  uint64_t X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<uint64_t> p(A), q(B), r(C);
  N_TIMES(a, A) { cin >> p[a]; }
  N_TIMES(b, B) { cin >> q[b]; }
  N_TIMES(c, C) { cin >> r[c]; }

  uint64_t S = 0, x = 0, y = 0, z = 0;
  priority_queue<QueueItem> Q;
  N_TIMES(a, A) { Q.emplace(1, p[a]); }
  N_TIMES(b, B) { Q.emplace(2, q[b]); }
  N_TIMES(c, C) { Q.emplace(0, r[c]); }
  while (!Q.empty()) {
    QueueItem item = Q.top(); Q.pop();
    if (x + y + z == X + Y) { break; }

    switch(item.key) {
    case 0:
      S += item.val;
      ++z;
      break;
    case 1:
      if (x >= X) { break; }
      S += item.val;
      ++x;
      break;
    case 2:
      if (y >= Y) { break; }
      S += item.val;
      ++y;
      break;
    }
  }
  cout << S << endl;

  return 0;
}

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

int main(){
  int N;
  cin >> N;
  int t = 1;
  long long C[10][10] = {};
  for(int i = 1; i <= N; ++i){
    int a = i%10, b = to_string(i)[0]-'0';
    ++C[a][b];
  }
  long long ans = 0;
  for(int i = 1; i < 10; ++i){
    for(int j = 1; j < 10; ++j){
      ans += C[i][j]*C[j][i];
    }
  }
  cout << ans << endl;
}


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

int main(void){
    int h,w;
    cin>>h>>w;
    rep(i,h){
        string s;
        cin>>s;
        cout<<s<<endl<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n, a[N];
int main (){
    scanf ("%d", &n);
    int mx1 = 0, pos1 = 0;
    for (int i = 1; i <= n; ++i){
        scanf ("%d", a + i);
        if (mx1 < a[i]){
            mx1 = a[i];
            pos1 = i;
        }
    }
    int mx2 = 0;
    for (int i = 1; i <= n; ++i){
        if (i != pos1){
            mx2 = max(mx2, a[i]);
        }
    }
    for (int i = 1; i <= n; ++i){
        if (a[i] == mx1) printf ("%d ", mx2);
        else printf ("%d ", mx1);
    }
}

Measured memory_bytes: 2432
S = input()
N = len(S)


if S==S[::-1]:
    s = S[:int((N-1)/2)]
    if s==s[::-1]:
        s = S[int((N+1)/2):]
        if s==s[::-1]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 3060
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N, x;
    std::cin >> N >> x;

    std::vector<int64_t> A;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    int64_t ans = 0;
    for (int64_t i = 1; i < N; ++i) {
        auto must_eat = std::max(A[i-1] + A[i] - x, (int64_t)0);
        auto eat = std::min(A[i], must_eat);
        ans += must_eat;
        A[i] -= eat;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1400
n,a,b,c=map(int,input().split())
ll=[int(input()) for _ in range(n)]

e=[0]*n
def dfs(i):
    if i==n:
        return solve()
    r=10**10
    for k in range(4):
        e[i]=k
        r=min(r,dfs(i+1))
    return r

def solve():
    ta=tb=tc=0
    ca=cb=cc=0
    for i in range(n):
        if e[i]==1:
            ta+=ll[i]
            ca+=1
        if e[i]==2:
            tb+=ll[i]
            cb+=1
        if e[i]==3:
            tc+=ll[i]
            cc+=1
    if not ca or not cb or not cc:
        return 10**10
    return (ca+cb+cc-3)*10+abs(a-ta)+abs(b-tb)+abs(c-tc)

print(dfs(0))

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

int main(){
    int N,K;
    cin >> N >> K;
    int l[55];
    int ans = 0;
    for (int i=1; i<N+1; i++) cin >> l[i];
    sort(l+1, l+N+1, greater<int>());
    for (int i=1; i<K+1; i++){
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
    int a,i,j,ZEROcount;
    int count=0;
    int A[10000];
    scanf("%d",&a);
    for(i = 0;i <= a-1;i++){
        scanf("%d",&A[i]);
    } 
    count = a;
    for(i = 0;i <= a-1;i++){
        if(A[i] == 2){
        }
        else if(A[i] % 2 == 0){
            count--;
        }
        else{
      int t = sqrt(A[i]);
      for(j = 3;j <= t;j = j+2){
        if(A[i] % j == 0){
          count--;
          break;
          }
          }
          }
    }
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2056
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int, input().split()))

i = 1
b = 0

for ai in an:
    if ai == i:
        i += 1
    else:
        b += 1

if b == n:
    print(-1)
else:
    print(b)

    

Measured memory_bytes: 26140
#include<stdio.h>
#define INF 1000000000
int dp[2][2][5001];
int min(int a,int b){return a<b?a:b;}
int main(){
	int n;
	int i,j;
	scanf("%d",&n);
	for(i=0;i<2;i++)for(j=0;j<=n/2;j++)dp[1][i][j]=INF;
	dp[1][0][0]=0;
	for(i=0;i<n-1;i++){
		int x;
		scanf("%d",&x);
		for(j=0;j<=n/2;j++){
			dp[i%2][0][j]=INF;
			dp[i%2][1][j]=INF;
			if(j>=1&&dp[(i+1)%2][0][j-1]!=INF){
				dp[i%2][1][j]=min(dp[i%2][1][j],dp[(i+1)%2][0][j-1]+x);
				dp[i%2][0][j]=min(dp[i%2][0][j],dp[(i+1)%2][0][j-1]);
			}
			if(dp[(i+1)%2][1][j]!=INF){
				dp[i%2][0][j]=min(dp[i%2][0][j],dp[(i+1)%2][1][j]+x);
				dp[i%2][1][j]=min(dp[i%2][1][j],dp[(i+1)%2][1][j]);
			}
		}
	}
	for(j=1;j<=n/2;j++)dp[(n-1)%2][0][j]=dp[n%2][0][j-1];
	printf("%d\n",min(dp[(n-1)%2][0][n/2],dp[(n-1)%2][1][n/2]));
	return 0;
}

Measured memory_bytes: 1100
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int maxi = 1e6+10;
string s;
vector<int> v[maxi];
int n;
ll a[maxi];

int main () {
  cin >> n;
  std::vector<ll> h(n);
  rep(i,n) {
    cin >> h[i];
  }
  ll result = 0,r= 0;
  for (size_t i = 1; i < n; i++) {
    if(h[i] <= h[i-1]) r++;
    else {
      result = max(result, r);
      r = 0;
    }
  }
  result = max(result, r);
  cout << result << endl;
}


Measured memory_bytes: 26112
#include "bits/stdc++.h"
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define display(v) for (auto x : v) cout << x << ", "
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define ceel(x, y) ((x) / (y) + !((x) % (y) == 0))
#define ss second
#define ff first
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

void __print(int x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifdef INCLUDEWHENOFFLINE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int maxN = 3001;
ll dp[maxN][maxN]; // stores X - Y
ll arr[maxN];

ll compute (int i, int j, int cnt)
{
    ll ans = 0;
    if (i > j) return 0;
    if (dp[i][j] != -1) return dp[i][j];
    if (cnt % 2 == 0)
    {
        ans = arr[i] + compute(i + 1, j, cnt + 1);
        ans = max(ans, arr[j] + compute(i, j - 1, cnt + 1));
    }
    else
    {
        ans = -arr[i] + compute(i + 1, j, cnt + 1);
        ans = min(ans, -arr[j] + compute(i, j - 1, cnt + 1));
    }
    dp[i][j] = ans;
    return ans;
}

void solve()
{
    for (int i = 0; i < maxN; i++)
        for (int j = 0; j < maxN; j++)
            dp[i][j] = -1;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> arr[i];
    ll ans = compute(0, n - 1, 0);
    cout << ans << endl;
}

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

Measured memory_bytes: 74268
#include<bits/stdc++.h>
using namespace std;
int h[501],fac[10001],a[501],n,k;
bool check(int d){
	int t=0,sum=0,s=0;
	for(int i=1;i<=n;i++){
		h[i]=a[i]%d;	
		t+=(d-h[i])%d;
	}
	sort(h+1,h+n+1);
	for(int i=1;i<=n;i++){
		sum+=h[i];t-=(d-h[i])%d;
		if(sum>k)return false;
		if(t==sum)return true;
	}
}
int main(){
	int sum=0,cnt=0,ans;
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i],sum+=a[i];
	for(int i=1;i*i<=sum;i++)if(sum%i==0){
		if(check(sum/i)){printf("%d",sum/i);return 0;}
		if(check(i))ans=i;
	}
	printf("%d",ans);
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void) {
	long long int a, b, x, ans;
	scanf("%lld %lld %lld", &a, &b, &x);
	ans = (b / x + 1) ;
	if (a != 0)ans -= (a - 1) / x + 1;
	printf("%lld\n", ans);
	return 0;
}

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

#define rep(X, Y) for( int (X) = 0; (X) < (Y); ++(X) )

int main(){
	int i, cnt;
	std::vector<long long> vec;

	while( std::cin >> cnt, cnt ){
		vec.push_back(0);

		while(cnt--)
			std::cin >> i, vec.push_back(i);

		std::sort( vec.begin(), vec.end() );

		rep( i, 2 )
			rep( l, (int)vec.size() - 2 )	
				vec[l + 1] += vec[l];

		std::cout << vec[(int)vec.size() - 2] << std::endl;
		
		vec.clear();
	}
	return 0;
}

Measured memory_bytes: 1340
n=int(input());l=[list(map(int,input().split()))for i in[0]*n];a=[0 for i in[0]*n];d=1;k=n*(n-1)
while sum(a)<k and 0<d<9999:
 L=[];y=0;d+=1
 for i in range(n):
  if a[i]<n-1:
   x=l[i][a[i]]-1
   if l[x][a[x]]-1==i and not(x in L or i in L):
    a[i]+=1;a[x]+=1;L+=[i,x];y=1
 d*=y
print([k//2,d-1][d<9999])

Measured memory_bytes: 54236
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,M;
int k[20],s[20][20];
int p[20];
int main(){
  cin>>N>>M;
  rep(i,M){
    cin>>k[i];
    rep(j,k[i]){
      cin>>s[i][j];
    }
  }
  rep(i,M) cin>>p[i];
  vi vec[20];
  rep(i,M){
    rep(j,k[i]){
      vec[s[i][j]].push_back(i+1);
    }
  }
 
  int lig[20];
  int res=0;
  //{0,1,...,n-1}に含まれるサイズkの部分集合の列挙
  for(int comb=0;comb<(1<<N);comb++){
    //ここで組み合わせに対して処理をする
    bool f=true;
    rep1(i,M){
      lig[i]=0;
    }
    rep(i,N){
      if(comb>>i&1){
	rep(j,vec[i+1].size()){
	  lig[vec[i+1][j]]++;
	}
      }
    }

    rep1(i,M){
      if(lig[i]%2!=p[i-1]){
	f=false;
	break;
      }
    }
    if(f) res++;
    
  }

  prin(res);
  
  return 0;
}


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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  umap<int,int> count;

  int n;
  cin >> n;
  int a[n];
  REP(i,n){
    cin >> a[i];
    count[a[i]]++;
  }
  int res = 0;
  for(auto i=count.begin() ;i!=count.end() ;++i){
    int val = i->first;
    int cnt = i->second;
    if(cnt >= val){
      res += (cnt-val);
    }else{
      res += cnt;
    }
  }

  cout << res << endl;

  return 0;
}


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

int main(void)
{
    int n, w;
    cin >> n >> w;

    vector<int> wi(n,0);
    vector<int> vi(n,0);

    for(int i = 0; i < n; ++i)
    {
        int w_tmp, v_tmp;
        cin >> w_tmp >> v_tmp;
        wi.at(i) = w_tmp;
        vi.at(i) = v_tmp;
    }
    
    vector<vector<long long int>> vt(n+1,vector<long long int>(n*1000+1, 1000000001));
    vt.at(0).at(0) = 0;

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j <= n*1000; ++j)
        {
            if(j-vi.at(i) >= 0)
            {
                vt.at(i+1).at(j) = min(vt.at(i+1).at(j), vt.at(i).at(j-vi.at(i))+wi.at(i));
            }

            vt.at(i+1).at(j) = min(vt.at(i).at(j), vt.at(i+1).at(j));                
        } 
    }
    
    int ans = 0;

    for(int j = 0; j <= n*1000; ++j)
    {
        if(vt.at(n).at(j) <= w)
        {
            if(ans <= j) ans = j;
        }
    
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 80256