akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e;
  string s,ss,sss,ssss;
  cin>>a>>b;
  vi A(a);
  for(auto &aa:A)cin>>aa;
  ll now=0;
  ll ans=1;
  for(int i=0;i<a;i++){
    now+=A[i];
    if(now<=b)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
<?php

$sc = new Scanner();

$n = $sc->nextInt();
$k = $sc->nextInt();

$h = [];
for($i = 0; $i < $n; $i++) {
    $h[] = $sc->nextInt();
}
sort($h);

$min = pow(10, 10);
$index = -1;
for($i = $k - 1; $i < $n; $i++) {
    $min = min($min, $h[$i] - $h[$i - $k + 1]);
}
echo $min . PHP_EOL;

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}


Measured memory_bytes: 10744
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s, ans;
    const string alphabet = "abcdefghijklmnopqrstuvwxyz";
    cin >> s;
    if(s.length() == 26){
        if(s == "zyxwvutsrqponmlkjihgfedcba"){
            ans = "-1";
        }
        else {
            int d;
            vector<char> l(26);
            for (int i=0; i<26; ++i){
                l[i] = s[i];
            }
            next_permutation(ALL(l));
            for (int i=0; i<26; ++i){
                ans = ans + l[i];
                if(l[i] != s[i]){
                    break;
                }
            }
        }
    }
    else {
        set<int> letter;
        for (int i=0; i<(int)s.length(); ++i){
            letter.insert(s[i]);
        }
        ans = s;
        for (int i=0; i<26; ++i){
            if(letter.count(alphabet[i]) == 0){
                ans = ans + alphabet[i];
                break;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
	int n[5];
	int x[5];
	int ans = 0, may = 0;
	
	for(int i = 0; i<5; i++)
		cin >> n[i];
		
	for(int i = 0; i<5; i++){
		x[i] = 0;
		int aux = n[i];
		while(aux%10 != 0){
			aux++;
			x[i]++;
		}
		may = max(may,x[i]);
	}
	
	for(int i = 0; i<5; i++){
		if(x[i] == may){
			ans += n[i];
			may = -1;
		}
		else
			ans += n[i] + x[i];
	}
	cout << ans << endl;
	return 0;
}

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

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>

using namespace std;

typedef struct NODE {
	int le, ri;
} Node;

const int N = 100010;

int n;
int X[N], L[N];
Node node[N];

bool cmp(Node a, Node b)
{
	return a.ri < b.ri;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> X[i] >> L[i];
		node[i].le = X[i] - L[i], node[i].ri = X[i] + L[i];
	}
	
	sort(node, node + n, cmp);
	
	int la = node[0].ri, ans = 1;
	for (int i = 1; i < n; ++i)
	{
		if (node[i].le >= la) 
		{
			ans ++;
			la = node[i].ri;
		}
	}
	
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 1792
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE1=1e6+1000;
const int SIZE2=2010;
const int SIZE3=400;
const int SIZE=SIZE1;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string s;
ut N,M,K,X,L,Y,D;
int A[SIZE],B[SIZE];
signed main(){
	cin >> N;
	int diff=0,sum=0,minium=INF;
	REP(i,N){
		cin >> A[i] >> B[i];
		if(A[i]>B[i]){
			minium=min(minium,B[i]);
			
		}sum+=A[i];
	}
	if(minium==INF) cout << 0 <<endl;
	else cout << sum-minium << endl;
	return 0;
}

Measured memory_bytes: 2432
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

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

    usize n;
    std::cin >> n;
    vec<usize> a(n);
    for (usize& x: a) std::cin >> x, x--;

    usize ans = 0;
    for (usize i=0; i!=1 && ans<n; i=a.at(i), ans++);
    std::cout << (ans==n ? -1 : (i64)ans) << '\n';
}


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

int main() {
  int N;
  cin >> N;
  int a=N/100;
  int b=N%100/10;
  int c=N%100%10;
  
  if (a==7 || b==7 || c==7 )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3576
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
	if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
lint a;
std::string b;
int main() {
	std::cin>>a>>b;
	b.erase(b.begin()+1);
	std::cout<<a*std::stoi(b)/100<<std::endl;
	return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int k, q;
  cin >> k >> q;
  
  vector<int> d(k);
  for(int i = 0; i < k; i++) cin >> d.at(i);
  
  for(int i = 0; i < q; i++){
    int n, x, m;
    cin >> n >> x >> m;
    
    vector<int> v(k);
    for(int j = 0; j < k; j++) v.at(j) = d.at(j) % m;
    
    int keep = 0;
    for(int j = 0; j < k; j++){
      if(v.at(j) == 0) keep++;
    }
    int num = n - 1, ans = n - 1;
    ans -= (num / k) * keep;
    num %= k;
    for(int j = 0; j < num; j++){
      if(v.at(j) == 0) ans--;
    }
    
    ll sum = 0;
    for(int j = 0; j < k; j++){
      sum += v.at(j);
    }
    num = n - 1;
    sum *= num / k;
    num %= k;
    for(int j = 0; j < num; j++){
      sum += v.at(j);
    }
    sum += x;
    ans -= (sum / m) - (x / m);
    
    cout << ans << '\n';
  }
}

Measured memory_bytes: 384
//35
#include<iostream>
#include<queue>
#include<algorithm>

#define E(X,Y,Z,W) ((X)*52*52*52+(Y)*52*52+(Z)*52+(W))

using namespace std;

struct S{
  int x,y,xx,yy,t;
};

int main(){
  for(int x,y;cin>>x>>y,x|y;){
    S i;
    cin>>i.x>>i.y>>i.xx>>i.yy;
    int g[52][52];
    fill_n(g[0],52*52,1);
    for(int i=1;i<=y;i++){
      for(int j=1;j<=x;j++){
	cin>>g[i][j];
      }
    }
    i.t=0;
    static bool u[52*52*52*52];
    fill_n(u,sizeof(u)/sizeof(u[0]),false);
    queue<S> que;
    que.push(i);
    while(!que.empty()&&que.front().t<100){
      S c=que.front();
      if(c.x==c.xx&&c.y==c.yy)break;
      que.pop();
      if(u[E(c.x,c.y,c.xx,c.yy)]++)continue;
      for(int i=0;i<4;i++){
	int d[]={0,1,0,-1,0};
	S n=c;
	n.x+=d[i];
	n.y+=d[i+1];
	n.xx-=d[i];
	n.yy-=d[i+1];
	n.t++;
	if(g[n.y][n.x]){
	  n.x=c.x;
	  n.y=c.y;
	}
	if(g[n.yy][n.xx]){
	  n.xx=c.xx;
	  n.yy=c.yy;
	}
	que.push(n);
      }
    }
    if(!que.empty()&&que.front().t<100){
      cout<<que.front().t<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
  return 0;
}
	

Measured memory_bytes: 9544
import sys
sys.setrecursionlimit(10 ** 6)

from itertools import product

def mat2_mul(X, Y):
    Z = [ [0, 0], 
          [0, 0] ]
    for (i,j,k) in product(range(2),range(2),range(2)):
        Z[i][j] += X[i][k] * Y[k][j]
    return Z

def mat2_pow(X, n):
    if n == 0:
        return [ [1, 0],
                 [0, 1] ]
    elif n % 2:
        return mat2_mul(X, mat2_pow(X, n-1))  
    else:
        half_pow = mat2_pow(X, n/2)
        return mat2_mul(half_pow, half_pow)

def Fib(n):
    if n == 0:
        return 0
    else:
        F = [ [0, 1],
              [1, 1] ]
        return mat2_pow(F, n-1)[1][1]
    
    
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]

x=0
L=[]
for i in range(M):
    L += [A[i] - 1 - x]
    x = A[i] + 1
L += [N - x]
L = [Fib(i+1)%1000000007 for  i in L]

X=1
for i in range(len(L)):
    X *= L[i]
    X %= 1000000007 
print(X)

Measured memory_bytes: 8640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N,K;
    cin >> N >> K;
    vector <int> H(N);
    loop(i,0,N) cin >> H[i];
    vector <int> dp(N);
    dp[0]=0;
    loop(i,1,N) 
    {
        int min=2e9;
        loop(j, 1, std::min(i+1, K+1)) // jmax=K, i-jmax>=0 ->  jmax<=i
        if ((dp[i-j]+abs(H[i]-H[i-j]))<min) min=dp[i-j]+abs(H[i]-H[i-j]);
        dp[i]=min;
        // cout << i << " " << dp[i] << "\n";
    }
    cout << dp[N-1] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long ll;
int main () {
  int H, W, K;
  cin >> H >> W >> K;
  int si, sj, gi, gj;
  cin >> si >> sj >> gi >> gj;
  vector<vector<char>>pond(H + 2, vector<char>(W + 2));
  for (int i = 1; i <= H; i ++) {
    for (int j = 1; j <= W; j ++) {
      cin >> pond[i][j];
    }
  }
  for (int i = 1; i <= H; i ++) pond[i][0] = pond[i][W + 1] = '@';
  for (int i = 1; i <= W; i ++) pond[0][i] = pond[H + 1][i] = '@';
  queue<int>qi;
  queue<int>qj;
  ll INF = 1e17;
  vector<vector<ll>>ans(H + 1, vector<ll>(W + 1, INF));
  vector<vector<ll>>vis(H + 1, vector<ll>(W + 1, 0));
  int bi[] = {1, 2, 4, 8};
  ans[si][sj] = 0ll;
  qi.push(si);
  qj.push(sj);
  int mi[] = {0, 0, 1, -1};
  int mj[] = {1, -1, 0, 0};
  ll on = 1ll;
  while (!qi.empty()) {
    int ui = qi.front();
    int uj = qj.front();
    //cout << "t " << ui << ' ' << uj << endl;
    qi.pop();
    qj.pop();
    for (int i = 0; i < 4; i ++) {
      if (((vis[ui][uj] / bi[i]) % 2) == 1) continue;
      int kj_ = 1;
      while (kj_ <= K && pond[ui + (mi[i] * kj_)][uj + (mj[i] * kj_)] == '.') {
        kj_ ++;
      }
      for (int kj = kj_ - 1; kj >= 1; kj --) {
        //cout << i << ' ' <<  kj << endl;
        int vi = ui + (mi[i] * kj);
        int vj = uj + (mj[i] * kj);
        if (ans[vi][vj] >= ans[ui][uj]) {
          if (i == 0) {
            vis[vi][vj] += bi[1];
            if (kj < kj_ - 1) vis[vi][vj] += bi[0];
          }
          if (i == 1) {
            vis[vi][vj] += bi[0];
            if (kj < kj_ - 1) vis[vi][vj] += bi[1];
          }
          if (i == 2) {
            vis[vi][vj] += bi[3];
            if (kj < kj_ - 1) vis[vi][vj] += bi[2];
          }
          if (i == 3) {
            vis[vi][vj] += bi[2];
            if (kj < kj_ - 1) vis[vi][vj] += bi[3];
          }
          if (ans[vi][vj] != INF) continue;
          ans[vi][vj] = ans[ui][uj] + on;
          qi.push(vi);
          qj.push(vj);
        }
      }
    }
  }
  if (ans[gi][gj] == INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans[gi][gj] << endl;
}



Measured memory_bytes: 45220
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll frac[100005];

ll comb(ll a, ll b) {
  if(a<b) return 0;
  ll ans = frac[a];
  ll sh1, sh2;
  ll two;
  ll h = mod-2;
  while(h>0) {
    two = 1;
    sh1 = frac[b];
    sh2 = frac[a-b];
    while(2*two<h) {
      two *= 2;
      sh1 *= sh1;
      sh1 %= mod;
      sh2 *= sh2;
      sh2 %= mod;
    }
    ans *= sh1*sh2%mod;
    ans %= mod;
    h -= two;
  }
  return ans;
}

int main() {
  frac[0] = 1;
  for(ll i=1;i<100005;++i) frac[i] = frac[i-1]*i%mod;
  int N;
  cin>>N;
  int A[N+1];
  int tmp;
  map<int, int> amap;
  for(int i=0;i<=N;++i) {
    cin>>A[i];
    if(amap[A[i]]>0) tmp = A[i];
    amap[A[i]]++;
  }
  int anum=0, bnum=0;
  int tmpnum = 0;
  for(int i=0;i<=N;++i) {
    if(A[i]==tmp) {
      tmpnum++;
      continue;
    }
    if(tmpnum==0) anum++;
    if(tmpnum==2) bnum++;
  }
  for(int i=1;i<=N+1;++i) {
    cout<<(comb(N+1, i)-comb(anum+bnum, i-1)+mod)%mod<<endl;
  }
}



Measured memory_bytes: 9428
# https://atcoder.jp/contests/abc090/tasks/arc091_a
# C - Flip,Flip, and Flip......

N, M = list(map(int, input().split()))

if N == 1 and M == 1:
    c = 1
elif N == 1 or M == 1:
    c = max(N, M) - 2
else:
    c = (M - 2) * (N - 2)

print(c)


Measured memory_bytes: 2940
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<String, Integer> dic = new HashMap<String, Integer>();
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			if (dic.get(s) == null) {
				dic.put(s, 1);
			} else {
				dic.put(s, dic.get(s) + 1);
			}
		}
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			String s = sc.next();
			if (dic.get(s) != null) {
				dic.put(s, dic.get(s) - 1);
				if (dic.get(s) == 0) {
					dic.remove(s);
				}
			}
		}
		int ans = 0;
		for (String k: dic.keySet()) {
			ans = Math.max(ans, dic.get(k));
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int n,m;
char ch[188][188];
int sum[188][188];
int dp[2][188][188][188];
bool eq(int x1,int y1,int x2,int y2){
	int siz=(x2-x1+1)*(y2-y1+1);
	int c1=sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];
	return c1==siz||c1==0;
}
void init(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			sum[i][j]+=sum[i][j-1];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			sum[i][j]+=sum[i-1][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			for(int l=1,r;l<=m;l=r){
				r=l;
				while(eq(i,l,j,r)&&r<=m){
					r++;
				}
				for(int p=l;p<r;p++){
					dp[0][i][j][p]=r-1;
				}
				if(l==r){
					dp[0][i][j][l]=l-1;
					r++;
				}
			}
		}
	}
}
int find(int c,int u,int d,int L){
	int l=u,r=d-1,mid;
	int res=0;
	int v1,v2;
	while(l<=r){
		mid=(l+r)/2;
		v1=dp[c][u][mid][L];
		v2=dp[c][mid+1][d][L];
		res=max(res,min(v1,v2));
		if(v1<v2){
			r=mid-1;
		}
		else{
			l=mid+1;
		}
	}
	return res;
}
void DP(int c){
	int nv,lv;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			for(int l=1;l<=m;l++){
				lv=dp[c^1][i][j][l];
				if(lv!=m){
					nv=dp[c^1][i][j][lv+1];
					nv=max(nv,find(c^1,i,j,l));
				}
				else{
					nv=m;
				}
				dp[c][i][j][l]=nv;
			}
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",ch[i]+1);
		for(int j=1;j<=m;j++){
			if(ch[i][j]=='#'){
				sum[i][j]=1;
			}
		}
	}
	init();
	int ans=0;
	for(int i=1;dp[(i&1)^1][1][n][1]<m;i++){
		DP(i&1);
		ans=i;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 30716
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int N=105;
int n;
int t[N];
int mx=0;
int main()
{
	scanf("%d",&n);
	for (int u=1;u<=n;u++)
	{
		int x;
		scanf("%d",&x);
		mx=max(mx,x);
		t[x]++;
	}
	if (t[mx]<2) 
	{
		printf("Impossible\n");
		return 0;
	}
	int x=(mx+1)/2;
	for (int u=1;u<x;u++) 
		if (t[u]!=0) 
		{
			printf("Impossible\n");
			return 0;
		}
	if (t[x]!=(mx&1)+1)
	{
		printf("Impossible\n");
		return 0;
	}
	for (int i=x;i<=mx;i++)
	{
		if (t[i]==0)
		{
			printf("Impossible\n");
			return 0;
		}
		t[i]--;
	}
	int now=mx/2;
	for (int i=now+1;i<=mx;i++)
		if (t[i]==0)
		{
			printf("Impossible\n");
			return 0;
		}
	printf("Possible\n");
	return 0;
}

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

//最大公約数
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 main() {
  ll a, b, c, d; cin >> a >> b >> c >> d;
  ll l = lcm(c, d);
  ll n_c, n_d, n_l;
  n_c = b/c - (a+c-1)/c + 1;
  n_d = b/d - (a+d-1)/d + 1;
  n_l = b/l - (a+l-1)/l + 1;
  ll ans = (b-a+1) - (n_c + n_d - n_l);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int((x).size()))
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
template<typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); }
template<typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); }
typedef long long ll;

int n;
long long a[100*1000+5], ans;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%lld", a+i);
    for (int i = 0; i < n; i++) {
        ans += a[i]/2;
        if (a[i]%2 && a[i+1]) {
            a[i+1]--;
            ans++;
        }
    }
    printf("%lld\n", ans);
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1e9
#define MAX_V 1001
#define MAX_N 510
using namespace std;

/*?????§?????¢?????´?????????(Ford_Fulerson????????¨)???O(F|E|)*/

//????????¨????§???????(???????????????????????????)
struct edge{int to, cap, rev;};

vector<edge> G[MAX_V]; //??°???????????£??\?????????
bool used[MAX_V];      //DFS??§?????§??????????????????????????°

//from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});  
}


//?¢?????????????DFS??§??¢???
int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to ,t , min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

//s??????t???????????§???????±???????
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}

int N,K;
bool can[MAX_N][MAX_N]; //can[i][j]:=???????????\??????i?????????j??????????????????
int Biparite_Matching(){
  //0??????N-1: ???????????\???????????????????????????
  //N??????N+K-1: ???????????????????????????
  int s = N+K, t = s+1;
  
  //s??¨???????????\??????????????¶
  for(int i=0; i<N; i++) add_edge(s,i,1);
  
  //????????¨t?????????
  for(int i=0; i<K; i++) add_edge(N+i,t,1);
  
  //???????????\????????¨??????????????¶
  for(int i=0;i<N;i++)
    for(int j=0;j<K;j++)
      if(can[i][j]) add_edge(i, N+j , 1);

  return max_flow(s,t);
}

int main(){
  while(1){
  int b,r,B[501],R[501];
  cin>>b>>r;
  if(!b&&!r)break;
  for(int i=0;i<b;i++) cin>>B[i];
  for(int i=0;i<r;i++) cin>>R[i];

  memset(can,0,sizeof(can));
  for(int i=0;i<MAX_V;i++) G[i].clear();
  N=b,K=r;
  for(int i=0;i<b;i++)
    for(int j=0;j<r;j++)
      if(__gcd(B[i],R[j])>1) can[i][j]=1;

  cout<<Biparite_Matching()<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 9976
#include <cstdio>
#include <functional>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;

int main() {
    // input
    int n; scanf("%d", &n);
    vector<int> a(n); repeat (i, n) scanf("%d", &a[i]);
    vector<vector<int> > g(n);
    repeat (i, n - 1) {
        int x, y; scanf("%d%d", &x, &y); -- x; -- y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    // solve
    function<bool (int)> go = [&](int i) {
        for (int j : g[i]) if (a[i] > a[j]) {
            if (not go(j)) {
                return true;
            }
        }
        return false;
    };
    vector<int> result;
    repeat (i, n) if (a[i]) {
        if (go(i)) {
            result.push_back(i);
        }
    }
    // output
    repeat (i, result.size()) {
        printf("%d%c", result[i] + 1, i + 1 == result.size() ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 512
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

a = set()
for i in range(1,10):
    for j in range(1, 10):
        a.add(i*j)

n = ni()
if n in a:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
n = int(input())
pre = list(map(int,input().split()))
ino = list(map(int,input().split()))
pos = []

def reconstruction(l, r):
    if l >= r :
        return
    c = pre.pop(0)
    m = ino.index(c)
#     print("c", c, l, r, m)
    reconstruction(l, m)
    reconstruction(m+1, r)
    
    global pos
    pos += [c]

reconstruction(0, len(ino))
print(" ".join([str(ss) for ss in pos]))


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n,k;
int a[100010];

int main(){
  cin>>n>>k;
  rep(i,n)cin>>a[i];
  cout<<(n+k-3)/(k-1)<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>p(n+2);
    rep(i,n)cin>>p[i];
    int ans=0;
    int __max=0;
    double x=0;
    vector<int> s(n+2, 0); // s[0] = 0 になる
for (int i = 0; i < n+1; ++i) s[i+1] = s[i] + p[i];
    rep(i,n-k+1){
        __max=max(s[i+k]-s[i],__max);
        if(max(s[i+k]-s[i],__max)==s[i+k]-s[i])ans=i;
    }
    int aaa=ans;
while(ans<aaa+k){
    x+=(double)(1+p[ans])/2.0;
    ans++;
}
cout<<fixed<<setprecision(8)<<x;
return 0;
}

Measured memory_bytes: 4396
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
const char nl = '\n';
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
//The following debugging code was taken from Benjamin Qi's template :) 
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }

#ifdef LOCAL 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif
//CODE STARTS HERE-----------------------------------------------------------------------------------------// 
const int N = 3e3 + 10;
int n; double a[N], dp[N][N];
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    dp[1][1] = a[1];
    dp[1][0] = 1-a[1];
    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= i; j++){
            if(j){
                dp[i][j]+=dp[i-1][j-1] * a[i];
            }
            dp[i][j] += dp[i-1][j] * (1-a[i]);
            dbg(dp[i][j], i, j);
        }
    }     
    int m = (n+2)/2;
    double ans = 0;
    for(int i = m; i <= n; i++){
        ans+=dp[n][i];
    }
    cout << fixed << setprecision(9) << ans << nl;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

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

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

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

    if (!(a % 3 && b % 3 && (a + b) % 3))
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
}


Measured memory_bytes: 256
# 所持している鍵の集合をbitで表現する
#　鍵の集合を表す2進数が少なくなる方向に遷移することはないから，for文for文でかける

N, M = map(int, input().split())
status_money = [float('inf')] * (1 << N)

# 初期状態からの遷移を記録
for _ in range(M) :
    a, b = map(int, input().split())
    C = 0
    for c in input().split() :
        C |= (1 << (int(c) - 1))
    status_money[C] = min(status_money[C], a)
    
# ある状態とある状態の組合せを全部取る
for c in range(1 << N):
    # どんな鍵の組合せでも到達できない宝箱の組合せがあるかもしれない
    if status_money[c] == float('inf'):
        continue
    for d in range(1 << N):
        # c と d の論理和をとって新しく生成される状態 e を考える
        e = c | d
        # eにあらかじめ格納されている最小コストと，今生成したコストとのminをとる
        status_money[e] = min(status_money[c] + status_money[d], status_money[e])

# そもそも到達できない場合の処理を記述       
if status_money[-1] == float('inf'):
    print(-1)
else:
    print(status_money[-1])

Measured memory_bytes: 47192
#include<stdio.h>

int main () {
	char c1, c2, c3, c4, c5, c6;
	scanf("%c%c%c%c%c%c", &c1, &c2, &c3, &c4, &c5, &c6);
	
	c3 == c4 && c5 == c6 ? puts("Yes") : puts("No");
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> x(n), y(n), h(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> h[i];
  int cx, cy, H;
  for (int i = 0; i < 101; i++) for (int j = 0; j < 101; j++) {
    set<int> s;
    for (int k = 0; k < n; k++) if (h[k] > 0) {
      s.insert(h[k] + max(x[k] - i, i - x[k]) + max(y[k] - j, j - y[k]));
    }
    if (s.size() == 1) {
      H = *s.begin();
      cx = i, cy = j;
      bool ok = true;
      for (int k = 0; k < n; k++) if (max(H - abs(x[k] - cx) - abs(y[k] - cy), 0) != h[k]) ok = false;
      if (ok) return cout << cx << ' ' << cy << ' ' << H << '\n', 0;
    }
  }

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

ll f(ll H) {
    if(H == 1LL) return 1LL;
    return 2LL*f(H/2)+1LL;
}

int main()
{
    ll H;
    cin >> H;
    cout << f(H) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#define ll long long int
#define cases int t; cin >> t; while (t--)
#define pb push_back
using namespace std;

int main()
{
    ll l, r; cin >> l >> r;
    bool temp = false;
    for (ll i = l; i <= r; i++) 
    {
        if (i%2019==0)
        {
            cout << 0 << endl;
            temp = true;
            break;
        }
    }
    ll mi = INT_MAX;
    if (!temp)
    {
        for (ll i = l; i <=r ; i++)
        {
            for (ll j = i+1; j <=r; j++)
            {
                mi = min(mi, (i*j)%2019);
            }
        }
        cout << mi << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<cmath>

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> dp(n+1, INT_MAX);
    dp[0] = 0;
    for (int i=0; i<n; ++i) {
        dp[i+1] = min(dp[i+1], dp[i]+1);
        for (int j=6; i+j<n+1; j*=6) {
            dp[i+j] = min(dp[i+j], dp[i]+1);
        }
        for (int k=9; i+k<n+1; k*=9) {
            dp[i+k] = min(dp[i+k], dp[i]+1);
        }
    }
    cout << dp.back() << endl;
}


Measured memory_bytes: 640
fn main() {
    let (n, v) = read();
    let ans = solve(n, vec![0; n as usize], v);
    write(ans);
}

fn read() -> (i32, Vec<i32>) {
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let n = l1.trim().parse::<i32>().unwrap();
    
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let iter = l1.trim().split_whitespace();
    let mut v = Vec::<i32>::new();
    v.push(0);
   for i in iter {
        v.push(i.parse().unwrap());
    }

    (n, v)
}

fn write(v: Vec<i32>) {
    for i in v.iter() {
        println!("{}", *i);
    }
}

fn solve(n: i32, mut u: Vec<i32>, v: Vec<i32>) -> Vec<i32> {
    for (i, e) in v.iter().enumerate() {
        if i == 0 {
            continue;
        }

        u[(*e - 1) as usize] += 1;
    }

    u
}


Measured memory_bytes: 4272
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,a,b;cin>>n>>a>>b;
long long ans=0;
if((n==1&&a!=b)||(b<a))
ans=0;
else
ans=(b*(n-1)+a)-(a*(n-1)+b)+1;
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define endl "\n"
#ifdef LOCAL
#define lout cerr
#else
ostream devnull(0);
#define lout devnull
#endif
#define AMULET cin.tie(0);ios::sync_with_stdio(false);
// https://github.com/kurokoji/.cpp-Template/blob/master/template/template2.cpp
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1) (__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, d) rep5(i, a, n, d, <)
#define rep5(i, a, n, d, o) for (auto i = decltype(n)(a), _n = (n); i o _n; i += (d))

#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, -1)
#define rrep4(i, a, n, d) rep5(i, (a) - 1, n, d, >=)

#define dump(x) lout << #x << " = " << x << endl;
// alias
typedef long long ll;
typedef long long lint;
typedef pair<int,int> pii;
typedef pair<lint,lint> pll;
// func
template <class C> inline void vcin(C &c);
template <class C,class D> inline void vcin(C &c,D &d);
template <class C> inline void vcout(const C &c,const string separate="\n");
template <class T=int> inline T in();

void solve()
{
  int n = in();
  vector<int> p(n);
  vcin(p);

  int cnt = 0;
  rep(i, n)
  {
    if(p[i]!=i+1)
      cnt++;
  }
  cout << (cnt<=2?"YES":"NO") << endl;
}

signed main(){
  AMULET
  solve();
  return 0;
}

template <class C>inline void vcin(C &c){for(auto &a:c){cin>>a;}}
template <class C,class D> inline void vcin(C &c,D &d){for(auto it1=c.begin(),it2=d.begin();it1!=c.end()&&it2!=d.end();it1++,it2++){cin>>*it1>>*it2;}}
template <class C> inline void vcout(const C &c,const string separate){for(auto it=c.begin();it!=c.end();it++){if(it!=c.begin())cout<<separate;cout<<*it;}}
template <class T=int> inline T in(){T x;cin>>x;return (x);}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e5+5;
const ll INF = 1e18+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;
}		

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int n;
	string s;
	string d="Hoshina";
	cin>>n;
	cin.ignore();
	while(n--){
		getline(cin,s);
		for(int i=6;i<s.size();i++){
		if(s.substr(i-6,7)=="Hoshino")
		s.at(i)='a';
		}
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

   
struct Unionfind{
  vi size, par;
  Unionfind(){}
  Unionfind( int n ) :  size(n,1), par(n){
    REP( i , n ) par[i] = i;
  }
  void init( int n ){
    size = vi( n , 1 );
    par.resize( n );
    REP( i , n ) par[i] = i;
  }
  int find( int x ){
    if( par[x] == x ) return x;
    return par[x] = find( par[x] );
  }
  bool unite( int x , int y ){
    x = find(x);
    y = find(y);
    if( x == y ) return false;
    if( size[y] < size[x] ) swap( x , y );
    par[x] = y;
    size[y] += size[x];
    return true;
  }
  bool same( int x , int y ){
    return find(x) == find(y);
  }
};

Unionfind uf;

int n;
ll a[100010];
ll sum[100010];

int main(){

  n = in();
  REP( i , n ){
    a[i] = in();
  }
  sort( a , a + n );

  REP( i , n ){
    sum[i+1] = sum[i] + a[i];
  }

  uf.init( n );
  REP( i , n-1 ){
    if( sum[i+1] * 2 >= a[i+1] ){
      uf.unite( i , i+1 );
    }
  }

  printf( "%d\n" , uf.size[uf.find(n-1)] );
  
  return 0;
}


Measured memory_bytes: 2560
n, k = map(int, input().split())

if n > k:
  count = n // k
  res1 = n - (k * count)
  res2 = res1 - k
  res2 = max(res2, -res2)
  res = min(res1, res2)
  print(res)
  
else:
  res1 = n
  res2 = res1 - k
  res2 = max(res2, -res2)
  res = min(res1, res2)
  print(res)

Measured memory_bytes: 3064
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    ans = set()
    for i in range(1,N+1):
        if i<=N:
            ans.add(i)
            N -= i
        elif N:
            ans.add(i)
            ans.remove(i-N)
            break
    print(*ans,sep="\n")

if __name__ == '__main__':
    main()

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

int n;
int w[110];
long long v[110];

long long memo[110][100010];

long long dp(int i, int W){
  if(i == n) return 0;
  if(memo[i][W] != -1) return memo[i][W];

  long long ans = 0;
  if(W-w[i] >= 0) ans = dp(i+1, W-w[i]) + v[i];

  return memo[i][W] = max(ans, dp(i+1, W));
}

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

  for(int i = 0;i < n;i++) cin >> w[i] >> v[i];

  memset(memo, -1, sizeof(memo));

  cout << dp(0, W) << endl;

  return 0;
}

Measured memory_bytes: 86144
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <functional>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
        int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22)cout<<"bust"<<endl;
	else cout<<"win"<<endl;
	return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,ans=0;
    cin >> n;
    if(log10(n)==(int)log10(n)) ans = 10;
    else while(n!=0){
        ans += n%10;
        n /= 10;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s,t,ans="Yes"; cin>>s>>t;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans="No";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
signed main () {
	int a, b;
  	cin >> a >> b;
  	if (a < 6)
      	cout << 0 << '\n';
 	else if (a < 13)
      	cout << b / 2 << '\n';
  	else
      	cout << b << '\n';
}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long a = lread();
    auto s = sread();
    writeln(3200 <= a ? s : "red");
}


Measured memory_bytes: 3632