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

using namespace std;

typedef long long LL;

const int Maxn = 200000, Maxm = 4000, Mod = (int)(1e9 + 7);

int A[Maxn + 10], B[Maxn + 10], Dp[Maxm * 2 + 10][Maxm * 2 + 10], fac[Maxn + 10], inv[Maxn + 10];
int N;

inline int Pow (LL a, int b)
{
	LL ans = 1;
	while (b)
	{
		if (b & 1) (ans *= a) %= Mod;
		(a *= a) %= Mod;
		b >>= 1;
	}
	return ans;
}

inline int C (int n, int m)
{
	return ((LL)fac[n] * inv[m] % Mod * inv[n - m] % Mod);
}

main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	scanf("%d", &N);
	fac[0] = 1;
	inv[0] = 1;
	for (int i = 1; i <= Maxn + 1; ++i) fac[i] = ((LL)fac[i - 1] * i) % Mod, inv[i] = Pow(fac[i], Mod - 2);
	for (int i = 1; i <= N; ++i)
	{
		scanf("%d%d", &A[i], &B[i]);
		Dp[2001 - A[i]][2001 - B[i]] ++;
		//cout<<Maxm + 1 - A[i]<<" "<<Maxm + 1 - B[i]<<endl;
	}
	for (int i = 1; i <= Maxm + 2; ++i)
		for (int j = 1; j <= Maxm + 2; ++j)
			(Dp[i][j] += Dp[i][j - 1] + Dp[i - 1][j]) %= Mod;
	LL ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		ans += Dp[A[i] + 2001][B[i] + 2001];
		ans = ((ans - C(A[i] + A[i] + B[i] + B[i], A[i] + A[i])) % Mod + Mod) % Mod;
	}
	printf("%d\n", ans * inv[2] % Mod);
	return 0;
}

Measured memory_bytes: 128640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
typedef long long ll;
#define min(a, b) ((a) < (b) ? (a) : (b))
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

string getString(char x) {
	string s(1, x);
	return s;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	// cout << std::fixed << std::setprecision(15);
	
	long N, Q; 
	string S; 
	cin >> N >> Q >> S;

	vector<vector<int>> LR(Q ,vector<int>(2));

	for (int i = 0; i < Q; i++) {
		cin >> LR.at(i).at(0) >> LR.at(i).at(1);
	}
	vector<long> res(N);
	res.at(0) = 0;
	long tmp = 0;
	for (int i = 1; i < N; i++) {
		if (S[i - 1] == 'A' && S[i] == 'C') {
			++tmp;
		}
		res.at(i) = tmp;
	}

	for (int i = 0; i < Q; i++) {
		cout << res.at(LR.at(i).at(1) - 1) - res.at(LR.at(i).at(0) - 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 7232
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

// N, E, S, W
const int dx[4] = { 1, 0, -1, 0};
const int dy[4] = { 0, 1, 0, -1};

using LL = long long int;
using LD = long double;

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

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;

//==============================================

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

	int v, e;
	cin >> v >> e;

	vvi G(v);
	vi indeg(v);

	REP(i, e) {
		int s, t;
		cin >> s >> t;

		G[s].push_back(t);
		indeg[t]++;
	}

	vi ans;
	queue<int> q;

	REP(i, v) {
		if (indeg[i] == 0) q.push(i);
	}
	
	while(!q.empty()) {
		int u = q.front(); q.pop();

		ans.push_back(u);

		for (int a : G[u]) {
			indeg[a]--;
			if (indeg[a] == 0) {
				q.push(a);
			}
		}
	}

	for (int i : ans) cout << i << "\n";
	return 0;
}

Measured memory_bytes: 3812
from bisect import bisect_left
n = int(input())
a = [int(input()) for _ in range(n)]

INF = 10**9
dp = [INF for _ in range(n)]
dp[0] = a[0]

for i in range(1, n):
    idx = bisect_left(dp, a[i])
    dp[idx] = a[i]

print(len(list(filter(lambda x: x != INF, dp))))



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

int main(){
  int N, K, Q;
  cin >> N >> K >> Q;
  
  vector<int> A(Q);
  for(int i=0; i<Q; i++){
    cin >> A.at(i);
  }
  
  /*
  Q問終了時の持ち点はK-(Q-{正解数}) 
  */
  vector<int> P(N);
  for(int i=0; i<Q; i++){
    P.at(A.at(i)-1)++;
  }
  for(int j=0; j<N; j++){
    cout << (K-Q+P.at(j) > 0 ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    Tuple!(int, int)[] A;
    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        A ~= tuple(s[0], s[1]);
    }

    int solve() {
        auto B = A.dup;
        Tuple!(int, int)[] C;
        B.sort!"a[0] == b[0] ? a[1] > b[1] : a[0] < b[0]";
        
        int left = 1;
        foreach (b; B) {
            if (b[0] == 0) {
                C ~= b;
            } else if (b[0] >= left) {
                left += 1;
            } else {
                C ~= b;
            }
        }

        int right = M;
        C.sort!"a[1] > b[1]";
        foreach (c; C) {
            if (right < left) {
                break;
            }
            if (c[1] <= right) {
                right -= 1;
            }
        }

        return (left - 1) + (M - right);
    }

    writeln(N - solve);
}


Measured memory_bytes: 8828
N, T = map(int, input().split())
min_c = 1001
flag = 0

for _ in range(N):
  c, t = map(int, input().split())
  if t <= T:
    min_c = min(min_c, c)
    flag = 1

if flag:
  print(min_c)
else:
  print('TLE')

Measured memory_bytes: 3060
n=int(input())
p=list(map(int, input().split()))
ans=0
for i in range(n-2):
    if p[i]<p[i+1] and p[i+1]<p[i+2]:
        ans+=1
    elif p[i]>p[i+1] and p[i+1]>p[i+2]:
        ans+=1
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main() {
	int n,a[100], count=0,count2=0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 2 == 0) {
			count++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 0) {
			if (a[i] % 3 == 0 || a[i] % 5 == 0) {
				count2++;
			}
		}
	}

	if (count == count2) {
		printf("APPROVED");
	}
	else {
		printf("DENIED");
	}
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		int answer = 50;
		for(int i=0;i<n;i++) {
			int kazu=sc.nextInt();
			int amari=kazu%2;
			int kaisuu=0;
			while(amari==0) {
				kazu=kazu/2;
				amari=kazu%2;
				kaisuu++;
			}
			if(answer>kaisuu) {
				answer=kaisuu;
			}
		}
		System.out.print(answer);


	}

}

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

const ll INF = 1001001001;

int main(){
    double w, h; cin >> w >> h;
    int x, y; cin >> x >> y;
    cout << h * w / 2 << " " << (x * 2 == w && y * 2 == h ? 1 : 0) << endl;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B>C+D){
    cout << "Left" << endl;
  }else if(A+B==C+D){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

//#define solvsh
//#define multi
#ifdef solvsh


#else

void solve() {

    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;

    for (int i = a; i <= b;++i){
        if (i % k == 0){
            cout << "OK";
            return;
        }
    }
    cout << "NG";
}

#endif

void multisolve() {

    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Case #" << (i++) << ": ";
        solve();
//        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);



#ifdef multi
    multisolve();
#else
    solve();
//    gen();
#endif

}

Measured memory_bytes: 3656
#include <stdio.h>

int main(void)
{
	int x,y,z;
	char a[4];
	scanf("%s",a);
	for(x=0;x<3;x++)
	{
		if (a[x] == '9') a[x] = '1';
		else a[x] ='9';
	}
	printf("%s",a);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF 1e9+7
#define LLINF 1e18
// #define int ll
using namespace std;
const int MOD = 1e9 +7;


struct WeightedUnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> diff_weight;

    WeightedUnionFind(int n){
        init(n);
    }
    void init(int n){
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        rep(i,n){
            par[i]=i;
            rank[i]=0;
            diff_weight[i]=0;
        }
    }

    int find(int x){
        if(par[x]==x){
            return x;
        }
        else{
            int r=find(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] =r;
        }
    }
    int weight(int x) {
        find(x);
        return diff_weight[x];
    }

    int diff(int x, int y) {
        return weight(y) - weight(x);
    }

    
    

    bool unite(int x, int y, int w) {
        w += weight(x); w -= weight(y);
        x = find(x); y = find(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    bool same(int x,int y){
        return find(x) ==find(y);
    }
    


    
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    WeightedUnionFind uf(n);
    rep(i,m){
        int l,r,d;
        cin>>l>>r>>d;
        r--;l--;
        if(uf.same(l,r)){
            int diff=uf.diff(l,r);
            if(diff !=d){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else uf.unite(l,r,d);
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PP = pair<P,P>;

long double d(P p1, P p2){
  long double dx=p1.first-p2.first,dy=p1.second-p2.second;
  return sqrt( dx*dx + dy*dy ); 
}

int main() {
  int n;
  cin >> n;
  vector<P> pos(n);
  rep(i,n) cin >> pos[i].first >> pos[i].second;
  sort(pos.begin(),pos.end());

  map<pair<P,P>,long double> dmap;
  rep(i,n)rep(j,n)if(i<j){
    dmap[PP(pos[i],pos[j])] = dmap[PP(pos[j],pos[i])] = d(pos[i],pos[j]);
  }

  long double sum = 0;
  do {
    rep(i,n-1){
      sum += dmap[PP(pos[i],pos[i+1])];
    }
  } while (next_permutation(pos.begin(),pos.end()));
  
  while(n>1){
    sum /= n;
    --n;
  }
  printf("%.10Lf\n",sum);
}


Measured memory_bytes: 256
/*
 Read problem and understand it 100%
 Make observation
 SOLVE THE PROBLEM
*/
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pii pair<int, int>
#define int long long
#define szof(s) (int)s.size()
#define all(s) (int)s.begin(), s.end()
using namespace std;
 
const int N = (int)1e6 + 5;
const int INF = (int)1e9 + 9;
const int MOD = (int)1e9 + 7;
 
main() {
	int a, b;
	cin >> a >> b;
	if (b == 1) {
		cout << 0;
		return 0;
	}
	
	int pref = 0;
	for (int i = 1; i <= 20; i++) {
		if (i * a - pref >= b) {
			cout << i << endl;
			return 0;
		}
		pref++;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;

int h[N], dp[N];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	dp[0] = 0; dp[1] = abs(h[0] - h[1]) + dp[0];
	for (int i = 2; i < n; i++)
	{
		dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i] - h[i-2]) + dp[i-2]);
	}
	cout << dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

a = l()
a = list(set(a))

if len(a) == 2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9952
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.Attoparsec.ByteString.Lazy as AL
import qualified Data.Attoparsec.ByteString.Char8 as AC
import Data.Bits

type Input  = (Int, Int)
type Output = Int

inputParser :: AC.Parser Input
inputParser = do
  (_A, _B) <- decimalPair
  return (_A, _B)

decimalPair :: AC.Parser (Int, Int)
decimalPair = (,)
  <$> AC.decimal <* AC.char ' '
  <*> AC.decimal <* AC.endOfLine

main :: IO ()
main = do
  contents <- B.getContents
  case AL.parse inputParser contents of
    AL.Done _ input -> print $ solve input
    _               -> error "parse failed"

solve :: Input -> Output
solve (_A, _B) = f _A _B
  where
    f 0 b = g b
    f a b = g b `xor` g (a - 1)

    g x = case x `mod` 4 of
      0 -> x
      1 -> 1
      2 -> x `xor` 1
      3 -> 0

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

#define int long long
#define MAXN 405
int p[MAXN];
int dp[MAXN][MAXN];
int a[MAXN];
int n;

int dfs(int l, int r){
	if(dp[l][r]!=-1) return dp[l][r];
	if(l==r) return 0;
	int v = p[r]-p[l-1];
	int mn = 1e15;
	for(int i=l; i<r; i++){
		mn = min(mn, dfs(l,i) + dfs(i+1,r) + v);
	}
	return dp[l][r]=mn;
}

int32_t main(){
	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];
	p[0]=0;
	for(int i=1; i<=n; i++) p[i]=p[i-1]+a[i];
	memset(dp,-1,sizeof(dp));
	cout<<dfs(1,n);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
//#include "util.h"

#define ll long long
using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  constexpr char nl = '\n';
  const int mod = 1e9 + 7;

  int N = 0;
  int K = 0;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  vector<bool> dp(K + 1, true);
  dp[0] = false;

  for (int i = 1; i <= K; ++i) {
    for (int j = 0; j < N; ++j) {
      if (i >= a[j]) {
        dp[i] = dp[i] && dp[i - a[j]];
        if (!dp[i]) {
          break;
        }
      }
    }
    dp[i] = !dp[i];
  }

  cout << (dp[K] ? "First" : "Second") << nl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a,b,c,d,i,j,m;
    cin >> a >> b >> c >> d;
    i=max(a*c,a*d);
    j=max(b*c,b*d);
    m=max(i,j);
    {
        cout << m << endl;
    }
     
    return 0;

}


Measured memory_bytes: 3632
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int ans = 0;
        rep(i,n){
            int x, y, h, w;
            int size = 100, hevy = 100;
            cin >> x >> y >> h >> w;
            rep(i,6){
                int cm = 60 + 20 * i;
                if(x + y + h <= cm){
                    size = i;
                    break;
                }
            }
            rep(i,6){
                if(w <= 2){
                    hevy = 0;
                    break;
                }else if(w <= i * 5){
                    hevy = i;
                    break;
                }
            }
            int money = max(size, hevy) ;
            rep(i,6){
                if(money == 100) break;
                if(money == i){
                    ans+= 600 + 200 * i;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
n, q = map(int, input().split())
s = input()
t = [0]*(n+1)

for i in range(n):
	t[i+1] = t[i] + (1 if s[i:i+2]=='AC' else 0)

for i in range(q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])

Measured memory_bytes: 7748
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q, t;
ll mi = LINF;
U_MAP mp;

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

  cin >> n >> t;
  rep(i, n) {
    cin >> a;
    mi = min(mi, a);
    mp[a - mi]++;
    if (a - mi >= tmp) {
      tmp = a - mi;
    }
  }
  Cout(mp[tmp]);
  return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int m,d;
    cin>>m>>d;
    int ans=0;
    for(int i=4; i<=m; ++i){
        for(int j=22; j<=d; ++j){
            if(j%10<=1)continue;
            if(i==(j/10)*(j%10))ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
ll MOD = 1000000007;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}


ll modpow(ll a,ll n,ll m){//modpow(a,n,m) := a ^ n (mod m)
  ll res = 1;
  while(n > 0){
    if(n & 1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a,ll p){//modinv(a,p) := pを法とするaの逆元(※pは素数でなければならない)
    ll res = modpow(a,p-2,p);
    return res;
}

int main(){
  int N,M;
  cin >> N >> M;
  double sum = 0;
  sum += (N-M) * 100 + M * 1900;
  cout << sum * pow(2,M) << endl;
}

Measured memory_bytes: 256
# http://drken1215.hatenablog.com/entry/2020/01/12/011700

# 本質的な速度改善の方法は分からない
# dpを二次元配列にするとTLEするので、
# 配列2本で処理した

# 修正点:
# [1]
# enumerate(a) -> a
# 不要なenumerateを消した
# [2]
# counted in range(n + 1) -> enumerate(dp)
# enumerateの方がわずかに速いはず
# [3]
# cmbのif文を消した

def main():
    MOD = 10 ** 9 + 7

    N, K = map(int, input().split())
    *a, = map(int, input().split())

    # -+-+-+-prepare combination-+-+-+-
    # -+-+-+-START-+-+-+-
    fact = [0] * (N + 1)
    fact[0] = 1
    fact[1] = 1
    for x in range(2, N + 1):
        fact[x] = x * fact[x - 1] % MOD

    invs = [1] * (N + 1)
    invs[N] = pow(fact[N], MOD - 2, MOD)
    for x in range(N - 1, 0, -1):
        invs[x] = invs[x + 1] * (x + 1) % MOD

    def cmb(n, r):
        return (((invs[r] * invs[n - r]) % MOD) * fact[n]) % MOD

    # -+-+-+-END-+-+-+-

    dp = [0] * (N + 1)
    dp[0] = 1

    for ai in a:
        ndp = [0] * (N + 1)
        for counted, dp_counted in enumerate(dp):
            for to_count in range(min(N - counted, ai) + 1):
                ndp[counted + to_count] = (
                                                  ndp[counted + to_count]
                                                  + dp_counted
                                                  * cmb(N - counted, to_count)
                                                  * cmb(N - to_count, ai - to_count)
                                          ) % MOD
        dp = ndp

    print(dp[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 56088
#include <bits/stdc++.h>
using namespace std;
#define TR(i,v)       for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x)      cout<<#x<<" = "<<x<<endl
#define SIZE(p)       (int)(p).size()
#define MP(a,b)       make_pair((a),(b))
#define ALL(p)        (p).begin(),(p).end()
#define rep(i,n)      for(int i=0;i<(int)(n);++i)
#define REP(i,a,n)    for(int i=(a);i<(int)(n); ++i)
#define FOR(i,a,b)    for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,b,a)   for(int i=(int)(b);i>=(int)(a);--i)
#define CLR(x,y)      memset((x),(y),sizeof((x)))
typedef long long LL;
typedef pair<int,int> pii;

int main(){
  char s[55][55];
  int n,m;scanf("%d%d",&n,&m);
  rep(i,n)scanf("%s",s[i]);
  rep(i,n)
  rep(j,m){
    if(s[i][j]=='.'){
      int c=0;
      FOR(dx,-1,1)
      FOR(dy,-1,1)if(dx || dy){
        int xx=i+dx,yy=j+dy;
        if(xx>=0&&xx<n&&yy>=0&&yy<m)
          c+=s[xx][yy]=='#';
      }
      putchar('0'+c);
    }else putchar('#');
    if(j+1==m)puts("");
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K,A,B ;
  cin>>K>>A>>B ;
  int x=A/K;
  int y=B/K;
    if (x==y&& A%K!=0&&B%K!=0){
    cout<<"NG"<<endl;
    }
      
      else {
      cout<<"OK"<<endl;
      }
    }

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

using namespace std;
using lint = long long;

const int MAX = 1009 * 1009 / 2;

vector<int> adj[MAX];
bool cyc = false;
bool term[MAX];
bool vis[MAX];
int f[1009][1009];
int dp[1009];
int N;

void dfs0(int here) {
	vis[here] = true;
	for (auto there : adj[here]) {
		if (!vis[there])
			dfs0(there);
		if (!term[there])
			cyc = true;
	}
	term[here] = true;
}

int dfs1(int here) {
	vis[here] = true;
	int ret = 0;
	for (auto there : adj[here]) {
		if (vis[there])
			ret = max(ret, dp[there]);
		else
			ret = max(ret, dfs1(there));
	}
	return dp[here] = ret + 1;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N;
	int f0 = 0;
	for (int i = 0; i < N; ++i)
		for (int j = i + 1; j < N; ++j)
			f[i][j] = f0++;
	for (int i = 0; i < N; ++i) {
		vector<pair<int, int>> tmp;
		for (int j = 0; j < N - 1; ++j) {
			int A;
			cin >> A;
			pair<int, int> p = {i, A - 1};
			if (p.first > p.second)
				swap(p.first, p.second);
			tmp.push_back(p);
		}
		for (int j = 1; j < N - 1; ++j) {
			int u = f[tmp[j - 1].first][tmp[j - 1].second];
			int v = f[tmp[j].first][tmp[j].second];
			adj[u].push_back(v);
		}
	}
	int MAXV = f0;
	for (int i = 0; i < MAXV; ++i)
		if (!vis[i])
			dfs0(i);
	if (cyc)
		cout << "-1\n";
	else {
		memset(vis, false, sizeof(vis));
		int ans = 0;
		for (int i = 0; i < MAXV; ++i)
			if (!vis[i])
				ans = max(ans, dfs1(i));
		cout << ans << '\n';
	}
}



Measured memory_bytes: 32896
from collections import Counter

h, w = (int(x) for x in input().split())
A = []
for _ in range(h):
    A += list(input())

B = [0, 0, 0]
if h % 2 == 0 and w % 2 == 0:
    B[2] += h * w
elif h % 2 == 0 and w % 2 == 1:
    B[2] += h * (w - 1)
    B[1] += h
elif h % 2 == 1 and w % 2 == 0:
    B[2] += w * (h - 1)
    B[1] += w
else:
    B[2] += (w - 1) * (h - 1)
    B[1] += w + h - 2
    B[0] += 1

i = 0
for key, value in Counter(A).most_common():
    while value >= 4 and B[2] > 0:
        B[2] -= 4
        value -= 4
    while value >= 2 and B[1] > 0:
        B[1] -= 2
        value -= 2
    while value >= 1 and B[0] > 0:
        B[0] -= 1
        value -= 1
    if value != 0:
        print("No")
        exit()
else:
    print("Yes")
    exit()


Measured memory_bytes: 69520
n = gets.to_i
a = gets.split.map(&:to_i)
h = Hash.new(0)
n.times do |i|
  h[a[i]] += 1
end
sum = 0
h.each do |k, v|
  sum += v * (v - 1) / 2
end
n.times do |i|
  puts sum - h[a[i]] * (h[a[i]] - 1) / 2 + (h[a[i]] - 1) * (h[a[i]] - 2) / 2
end

Measured memory_bytes: 28804
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair



int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	string s;
	cin >> s;
	string w = "AKIHABARA";
	for (int mask = 0; mask < (1 << 9); mask++) {
		string p = "";
		bool ok = true;
		for (int i = 0; i < 9; i++) {
			if ((mask >> i) & 1) {
				p += w[i];
			} else {
				ok &= w[i] == 'A';
			}
		}
		if (!ok) continue;
		if (s == p) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 764
n = int(input())
ary = list(map(int,input().split()))
sorted_ary = sorted(ary)
for i in range(n):
    a = n//2-1
    if sorted_ary[a] >= ary[i]:
        print(sorted_ary[a+1])
    else:
        print(sorted_ary[a])


Measured memory_bytes: 93780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
ll pow_mod(ll fi,ll se,ll mod){
  if(se==0){
    return 1;
  }
  if(se%2){
    return pow_mod(fi,se-1,mod)*fi%mod;
  }
  ll t=pow_mod(fi,se/2,mod);
  return t*t%mod;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}

vector<pair<int,int>> Dir={{-1,0},{1,0},{0,1},{0,-1}};
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/


int main(){
  int n;
	cin>>n;
	vector<string> s(n);
	vector<int> p(n);
 
	vector<pair<string,pair<int,int>>> v(n);
	for(int i=0;i<n;i++){
		cin>>s[i]>>p[i];
		v[i]=make_pair(s[i],make_pair(-p[i],i+1));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		cout<<v[i].second.second<<endl;
	}
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int n,T;cin >> n>>T;
    int ans = 10000;
    REP(i, n) {
        int c, t;
        cin >> c>>t;
        if(t<=T)
            ans = min(ans, c);
        }
    
    if(ans==10000){
        cout << "TLE" << "\n";
    }else cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    K = int(input())
    if N <= 1000:
        count = 0
        for i in range(1, N + 1):
            d = 0
            ci = i
            while ci > 0:
                d += (1 if ci % 10 > 0 else 0)
                ci //= 10
            if d == K: count += 1
        print(count)
    else:
        strN = str(N)
        dig = len(strN)
        DPsmall = [[0 for j in range(K + 1)] for i in range(dig)]
        DPsmall[0][0] = 1
        DPsmall[0][1] = int(strN[0]) - 1
        for i in range(1, dig):
            DPsmall[i][0] = 1
            for j in range(1, K + 1):
                DPsmall[i][j] += DPsmall[i-1][j-1] * 9 + DPsmall[i-1][j]
            
        DPlarge = [[0 for j in range(K + 1)] for i in range(dig)] #最初の桁がNの最初と一致
        DPlarge[0][0] = 1
        for i in range(1, dig):
            if strN[i] == "0": DPlarge[i][0] = DPlarge[i-1][0]
            else: DPlarge[i][0] = DPlarge[i-1][0] + 1
            for j in range(1, K + 1):
                if DPlarge[i-1][0] == j - 1: DPlarge[i][j] += (int(strN[i]) - 1 if strN[i] != "0" else 0)
                if DPlarge[i-1][0] == j: DPlarge[i][j] += (1 if strN[i] != "0" else 0)

                DPlarge[i][j] += DPlarge[i-1][j] #i桁目が0
                if j > 1: DPlarge[i][j] += DPlarge[i-1][j-1] * 9 #i桁目は0以上

        ans = DPsmall[dig-1][K] + DPlarge[dig-1][K]
        if DPlarge[dig-1][0] == K: ans += 1
        print(ans)   
        #print(DPsmall)
        #print(DPlarge)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3192
# 基本的に問題はここで解く。

num_temp = gets.chomp.split(" ").map{|x| x.to_i}

num_1 = num_temp[0]
num_2 = num_temp[1]

# 階乗はn*(n+1)/2より、

n = num_2 - num_1 
puts n*(n+1)/2 - num_2


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define N 107
#define inf 1e9+7
using namespace std;
vector <int> a(N, inf);
vector <int> b(N, inf);

int main(){
    int x, y;
    cin >> x >> y;
    if (y % 2){
        cout << "No";
        return 0;
    }
    a[0] = 0;
    b[0] = 0;
    for (int i = 0; i <= y; i++){
        a[i + 2] = min(a[i] + 1, a[i + 2]);
        a[i + 4] = min(a[i] + 1, a[i + 4]);
        b[i + 2] = b[i] + 1;
    }
    if ((x >= a[y]) && (x <= b[y])){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


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

using namespace std;

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

	vector<int> a;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		if (tmp % 2 == 0)
		{
			a.push_back(tmp);
		}
	}

	if (a.size() == 0)
	{
		cout << 0 << endl;
	}
	else
	{
		sort(a.begin(), a.end());
		int i = 0;
		int ans = 0;
		while (true)
		{
			if (a.at(i) % 2 == 0 && a.at(i) != 0)
			{
				a.at(i) /= 2;
				ans++;
			}
			else
			{
				i++;
			}
			if (i == a.size())
			{
				break;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 384
N, C = map(int, input().split())

weight = []
color = []
colorCount = [[0 for _ in range(C)] for _ in range(3)]

for _ in range(C) :
    line = list(map(int, input().split()))
    weight.append(line)

for i in range(N) :
    line = list(map(int, input().split()))
    color.append(line)
    for j, c in enumerate(line) :
        colorCount[(i + j + 2) % 3][c - 1] += 1

ans = float('inf')

for firstColor in range(C) :
    for secondColor in range(C) :
        for thirdColor in range(C) :
            if firstColor == secondColor or secondColor == thirdColor or thirdColor == firstColor :
                continue
            cost = 0
            for i, newColor in enumerate([firstColor, secondColor, thirdColor]) :
                for oldColor in range(C) :
                    cost += colorCount[i][oldColor] * weight[oldColor][newColor]
            ans = min(ans, cost)

print(ans)


Measured memory_bytes: 5620
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Curtain
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%d\n", max(0, a - 2 * b));
  return 0;
}


Measured memory_bytes: 256
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

#define MAXN 300000
#define kcz 998244353
LL f[MAXN+10];
LL qpow(LL x,LL n=kcz-2)
{
	if (n==1) return x;
	LL t=qpow(x,n/2);
	t=t*t%kcz;
	if (n%2==1) t=t*x%kcz;
	return t;
}
LL calcC(LL n,LL k)
{
	return f[n]*qpow(f[k])%kcz*qpow(f[n-k])%kcz;
}
void solve(long long N, long long A, long long B, long long K){
	f[0]=1;
	for(int i=1; i<=N; ++i) {
		f[i]=f[i-1]*i%kcz;
	}
	LL ans=0;
	for(int a=0; a<=N; ++a) {
		LL t=K-a*A;
		if (t%B!=0) continue;
		LL b=t/B;
		if (b<0 || b>N) continue;
		ans+=calcC(N,a)*calcC(N,b);
		ans%=kcz;
	}	
	cout<<ans<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	long long K;
	long long A;
	long long N;
	long long B;
	scanf("%lld",&N);
	scanf("%lld",&A);
	scanf("%lld",&B);
	scanf("%lld",&K);
	solve(N, A, B, K);
	return 0;
}



Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#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 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

typedef vector<vector<int>> graph;
struct LowLink{
    graph v;
    vector<int> art,low,ord;
    vector <pint> bridge;

    LowLink(int n):v(n),ord(n,-1),low(n){};

    void addedge(int x,int y){
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    void dfs(int& count,int from,int x){
        ord[x]=count++;
        low[x]=ord[x];
        bool isart=false;
        int cnt=0;
        for(auto to:v[x]){
            if(to==from)continue;
            if(ord[to]==-1){
                cnt++;
                dfs(count,x,to);
                if(ord[x]<low[to])bridge.push_back({min(x,to),max(to,x)});
                if(from!=-1&&ord[x]<=low[to])isart=true;
                low[x]=min(low[x],low[to]);
            }
            else low[x]=min(low[x],ord[to]);
        }
        if(from==-1&&cnt>1)isart=true;
        if(isart)art.push_back(x);
    }
    void dfs(){
        int count=0;
        dfs(count,-1,0);
    }
};


int main(){
    int n,m;
    cin>>n>>m;
    LowLink ll(n);
    rep(i,m){
        int x,y;
        cin>>x>>y;
        ll.addedge(x,y);
    }
    ll.dfs();
    sort(ll.bridge.begin(),ll.bridge.end());
    for(auto x:ll.bridge)cout<<x.first<<" "<<x.second<<endl;
   return 0;
}


Measured memory_bytes: 4648
using System;
using System.Linq;

namespace ABC067_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long ans = long.MaxValue;
            long x = a.First();
            long y = a.Skip(1).Sum();
            for (int i = 1; i < N; i++)
            {
                ans = Math.Min(ans, Math.Abs(x - y));
                x += a[i];
                y -= a[i];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 34500
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef float f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b, int mod) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int a[200005];


void solve()
{
  int n;
  cin>>n;
  int c=0;
  fr(i,1,n)
  {
  cin>>a[i];
  if(a[i]!=i)
        c++;
  }
  if(c>2)
    cout<<"NO";
  else
    cout<<"YES";


}



signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
 	//cin>>t;
	fr(i,1,t) {
		solve();
	}
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}
/// template by rahuldugar





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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<pair<int,string>> v(n);
  rep(i,n){
    cin >> v[i].se;
    v[i].fi = v[i].se.size();
  }
  sort(all(v));
  vector<int> ans ;
  ll M = 0;
  if(n > 1000){
    v.resize(v.size()/2);
  }
  rep(i,v.size()){
    rep(j,v.size()){
      if(i != j){
        auto s = v[i].se + v[j].se;
        ll k = ston(s,0);
        if( k < M || ans.size() < 4){
          M = max(M,k);
          ans.push_back(ston(s,0));
        }
      }
    }
  }
  sort(all(ans));
  cout << ans[2] << endl;
  return 0;
}

Measured memory_bytes: 3292
N = int(input())
A = list(map(int, input().split()))
maru = len([a for a in A if a % 4 == 0])
batu = len([a for a in A if a % 2 == 1])
sankaku = N - maru - batu

if sankaku:
    if batu <= maru:
        print('Yes')
    else:
        print('No')
else:
    if batu <= maru + 1:
        print('Yes')
    else:
        print('No')


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

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  	int n;
    cin >> n;
    long long int ans=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0)ans+=i;
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> wc(n);
  vector<int> ec(n);
  if (s[0] == 'W') wc[0]++;
  if (s[n - 1] == 'E') ec[n - 1]++;
  for (int i = 1; i < n; i++) {
    wc[i] = wc[i - 1];
    if (s[i] == 'W') wc[i]++;
  }
  for (int i = n - 2; i >= 0; i--) {
    ec[i] = ec[i + 1];
    if (s[i] == 'E') ec[i]++;
  }
  int ans = inf;
  rep(i, n) {
    int tmp = ec[i] + wc[i] - 1;
    if (ans > tmp) ans = tmp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6072
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  unsigned long long H, W;

  cin >> H >> W;

  if(H == 1 || W == 1){
    cout << 1 << endl;
    return 0;
  }

  unsigned long long dot = H*W;

  if(dot%2 == 0){
    cout << dot/2 << endl;
  }
  else{
    cout << dot/2 + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * C - Replacing Integer
 * 青木君は任意の整数 x に対し、以下の操作を行うことができます。
 * 操作: x を x と K の差の絶対値で置き換える。
 * 整数 N の初期値が与えられます。
 * この整数に上記の操作を 0 回以上好きな回数行った時にとりうる N の最小値を求めてください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 初期値
        long n = sc.nextLong();
        // x を x と K の差の絶対値
        long k = sc.nextLong();

        long remainder = n % k;

        if( k - remainder > remainder ) {
            System.out.println( remainder );
        }
        else {
            System.out.println( k - remainder );
        }

        sc.close();
    }
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i, 3) {
        ans += (S[i] == T[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s; cin>>s;
    if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main()
{
	int p[3];
	for(int i=0;i<3;i++)
	cin >> p[i];
	sort(p,p+3);
	cout<<p[0]+p[1];
}


Measured memory_bytes: 256
#include "stdio.h"

int main(int argc, char const *argv[])
{
	int W,H,x,y,r;
	scanf("%d",&W);
	scanf("%d",&H);
	scanf("%d",&x);
	scanf("%d",&y);
	scanf("%d",&r);

	if(x-r<0||x+r>W||y+r>H||y-r<0) printf("No\n");
	else printf("Yes\n");

	return 0;
}

Measured memory_bytes: 584
package main

import (
  "fmt"
)

func check(s string) bool {
  if len(s) == 0 {
    return true
  }
  words := [4]string{"dream", "dreamer", "erase", "eraser"}
  for _, w := range words {
    if len(s)-len(w) >= 0 && s[len(s)-len(w):] == w {
      return check(s[:len(s)-len(w)])
    }
  }
  return false
}

func main() {
  var S string
  fmt.Scan(&S)
  if check(S) {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

Measured memory_bytes: 16512