akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define REEP(i, N) for(ll i = N - 1; i >= 0; --i)
#define FOR(i,m,n) for(ll i = m; i < n; ++i)
#define RFOR(i,m,n) for(ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a を b の倍数値まで増やす
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;} // a / b 以上の最小整数
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	ll N, L;
	cin>>N>>L;
	ll sum = 0;
	vector<ll> a(N);
	REP(i, N) {
		cin>>a[i];
		sum += a[i];
	}
	ll las = -1;
	for(int i = 0; i < N - 1; ++i) {
		if(a[i] + a[i + 1] >= L) {
			las = i + 1;
			break;
		}
	}
	if(las == -1) {
		cout<<"Impossible"<<endl;
		return 0;
	} else {
		cout<<"Possible"<<endl;
		for(ll i = 1; i <= las - 1; ++i) cout<<i<<endl;
		for(ll i = N - 1; i >= las + 1; --i) cout<<i<<endl;
		cout<<las<<endl;
	}
}


Measured memory_bytes: 1664
n= gets.chomp.to_i
ab = []
n.times do
  a, b = gets.split(" ").map(&:to_i)
  ab.push({a: a, b: b})
end

ab.sort_by! { |ab| ab[:a] }
ab.sort_by! { |ab| ab[:b] }

sum_a = 0
answer = "Yes"

n.times do |n|
  sum_a += ab[n][:a] 
  unless sum_a <= ab[n][:b]
    answer = "No"
    break
  end
end

puts answer


Measured memory_bytes: 67848
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <string>
#include <math.h>
using namespace std;

int main(){
    long long int n,b=10000000000,ans=0;
    cin>>n;
    vector<long long int>a(1000000);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),greater<>());
    cout<<a[0]<<' '<<flush;
    for(int i=1;i<n;i++){
        if(a[0]%2==0){
            if(abs(a[0]/2-a[i])<b){
                b=abs(a[0]/2-a[i]);
                ans=a[i];
            }

        }
        else{
            if(abs(a[0]/2-a[i])<b||abs((a[0]+1)/2-a[i])<b){
                b=min(abs(a[0]/2-a[i]),abs((a[0]+1)/2-a[i]));
                ans=a[i];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
 while(1){
 string s;
 cin>>s;
 if(s=="-"){
 break;
 }
 int m;
 cin>>m;
 for(int i=0;i<m;i++){
 string tmp=s;
 s="";
 int h;
 cin>>h;
 for(int j=h;j<(int)tmp.size();j++){
 s+=tmp[j];
 }
 for(int j=0;j<h;j++){
 s+=tmp[j];
 }
}
 cout<<s<<endl;
}
}


Measured memory_bytes: 3140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int d = Integer.parseInt(str[0]);
		int g = Integer.parseInt(str[1]);

		int p[] = new int[d];
		int c[] = new int[d];

		for (int i = 0; i < d; i++) {
			str = br.readLine().split(" ");

			p[i] = Integer.parseInt(str[0]);
			c[i] = Integer.parseInt(str[1]);
		}

		int ans = Integer.MAX_VALUE;
		for (int bit = 0; bit < (1 << d); bit++) {
			int problem = 0;
			int point = 0;

			for (int i = 0; i < d; i++) {
				if ((bit & (1 << i)) != 0) {
					problem += p[i];
					point += (1 + i) * 100 * p[i] + c[i];
				}
			}
			if (point >= g) {
				ans = Math.min(ans, problem);
				continue;
			}
			for (int i = 0; i < d; i++) {
				if ((bit & (1 << i)) != 0)
					continue;
				if ((g - point) / ((i + 1) * 100) <= p[i]) {
					problem += (g - point) / ((i + 1) * 100);
					ans = Math.min(ans, problem);
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
#include<algorithm>
#include<iostream>
#include<map>
#include<math.h>
#include<iomanip>
#include<vector>
using namespace std;

long double calculate_distance(vector<pair<int, int>> towns){
    long double distance_sum = 0.0;
    for (int i=0;i<towns.size()-1;i++){
        distance_sum += sqrt(pow((towns[i].first - towns[i+1].first), 2.0) + pow((towns[i].second - towns[i+1].second), 2.0));
    }
    return distance_sum;
}

int main(){
    int n;cin>>n;
    vector<pair<int, int>> towns(n);
    int x, y;
    for (int i=0;i<n;i++){
        cin >> x >> y;
        towns[i] = make_pair(x, y);
        }
    sort(towns.begin(), towns.end());
    long double distance_sum = 0;
    long double count = 0.0;
    do{
        distance_sum += calculate_distance(towns);
        count += 1.0;
    } while(next_permutation(towns.begin(), towns.end()));
    cout <<setprecision(10) << distance_sum / count << endl;
    return 0;
    
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N, Ma, Mb;
	
	cin >> N >> Ma >> Mb;
	
	const int nmax=40,abmax=10,INF = 1000000;

	int a[N], b[N], c[N];

	rep(i, N)
	{
		cin >> a[i] >> b[i] >> c[i];
	}

	int dist[N+1][nmax * abmax + 1][nmax * abmax + 1];
	
	for(int i = 0; i <= N; i++)
	{
		for (int j = 0; j <= nmax * abmax; j++)
		{
			for (int k = 0; k <= nmax * abmax; k++)
			{
				dist[i][j][k] = INF;
			}
		}
	}

	dist[0][0][0] = 0;

	for(int i = 0; i < N; i++)
	{
		for (int j = 0; j <= nmax * abmax; j++)
		{
			for (int k = 0; k <= nmax * abmax; k++)
			{
				if (dist[i][j][k] == INF)continue;

				dist[i+1][j][k] = min(dist[i+1][j][k], dist[i][j][k]);
				dist[i+1][j+a[i]][k+b[i]] = min(dist[i+1][j+a[i]][k+b[i]], dist[i+1][j][k] + c[i]);
			}
		}
	}

	int ans = INF;

	for (int j = 1; j <= nmax * abmax; j++)
	{
		for (int k = 1; k <= nmax * abmax; k++)
		{
			if (j * Mb == k * Ma)
			{
				ans = min(ans, dist[N][j][k]);
			}
		}
	}

	if (ans == INF)
	{
		cout << "-1" << endl;
	}
	else
	{
		cout << ans << endl;
	}
	

	return 0;
}
#endif

const int INF=INT_MAX/2;
 
int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
 
    int N,A,B;
    cin >> N >> A >> B;
 
	vector<vector<int>> dp(401,vector<int>(401,INF));    
	dp[0][0]=0;
 
    while (N--) {
		int a, b, c;
		cin >> a >> b >> c;
		for (int x = 400; x >= a; x--){
			for (int y = 400; y >= b; y--)
				dp[x][y] = min(dp[x][y], dp[x - a][y - b] + c);
		}
	}
	int ans = INF;
	for (int x = 1; x <= 400; x++){
		for (int y = 1; y <= 400; y++){
			if (x * B == y * A)
				ans = min(ans, dp[x][y]);
		}
	}
	if (ans == INF) 
		ans = -1;
	cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 896
import bisect
x,b=map(int,input().split())
arr=list(map(int,input().split()))
if x not in arr:
    print(x)
    quit()
for i in range(x+1,102):
    if i not in arr:
        ma=i
        break
for i in range(x-1,-2,-1):
    if i not in arr:
        mi=i
        break
if x-mi<=ma-x:
    print(mi)
else:
    print(ma)


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

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

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

int main() {
	int n; scanf("%d", &n);
	std::string s, t; cin >> s >> t;

	for(int i = 0; i < s.size(); i++) printf("%c%c", s[i], t[i]);
	printf("\n");
	return 0;
}


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

#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define endl "\n"
#define sz(x) ((ll)((x).size()))
const ll N=1e2+5,inf=1e9;

ll mx=0;
ll q;
ll a[N],b[N],c[N],d[N];

ll cc=0;
ll solve(ll n,ll m,ll i,ll p,vll v)
{
	// cout<<i<<" ";
	if(i>=n)
	{
		ll ans=0;
		cc+=sz(v);
		lp(j,0,q)
		{
			if(v[b[j]-1]-v[a[j]-1]==c[j])
			{
				ans+=d[j];
			}
		}
		mx=max(ans,mx);
		return 0;
	}
	lp(j,p,m+1)
	{
		// cout<<j<<" ";
		v.pb(j);
		solve(n,m,i+1,j,v);
		v.pop_back();
	}
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll n;
	cin >> n;
	vll v;
	ll m;
	cin >> m;
	cin >> q;
	vpll v2;
	lp(i,0,q)
	{
		cin >> a[i]>> b[i]>> c[i]>> d[i];
		v2.pb(mp(a[i],c[i]));
	}
	solve(n,m,0,1,v);
	// cout<<cc<<endl;
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 3624
main(){//先に入手
long long L[87] = { 2,1,3,4,7,11,18,29,47,76,123,199,322,521,843,1364,2207,3571,5778,9349,15127,24476,39603,64079,103682,167761,271443,439204,710647,1149851,1860498,3010349,4870847,7881196,12752043,20633239,33385282,54018521,87403803,141422324,228826127,370248451,599074578,969323029,1568397607,2537720636,4106118243,6643838879,10749957122,17393796001,28143753123,45537549124,73681302247,119218851371,192900153618,312119004989,505019158607,817138163596,1322157322203,2139295485799,3461452808002,5600748293801,9062201101803,14662949395604,23725150497407,38388099893011,62113250390418,100501350283429,162614600673847,263115950957276,425730551631123,688846502588399,1114577054219522,1803423556807921,2918000611027443,4721424167835364,7639424778862807,12360848946698171,20000273725560978,32361122672259149,52361396397820127,84722519070079276,137083915467899403,221806434537978679,358890350005878082,580696784543856761,939587134549734843 };
int i;scanf("%d",&i);printf("%lld",L[i]);
}

Measured memory_bytes: 128
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int n;
string s[50];

void init()
{
}

void solve()
{
    vector<char> v[50];
    REP(i, n){
        vector<char> vv;
        for(char c: s[i]) vv.pb(c);
        sort(ALL(vv));
        if(i == 0){
            v[i] = vv;
        }else{
            set_intersection(ALL(v[i-1]), ALL(vv), back_inserter(v[i]));
        }
    }
    for(char c: v[n-1]) cout << c;
    cout << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    REP(i, n) cin >> s[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define fix  cout<<std::fixed;
#define mk make_pair
#define N 100005
#define mod 1000000007
#define time  cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
  ll n,k;cin>>n>>k;
  ll a[n+5];
  ll dp[n+5]={0};
  for(int i=0;i<n+5;i++)dp[i]=1e18;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
  }
  
  dp[1]=0;
  for(int i=2;i<=n;i++)
  {
    for(int j=1;j<=min((ll)i,k);j++)
    {
      dp[i]=min(dp[i],abs(a[i]-a[i-j])+dp[i-j]);
    }
  }
  cout<<dp[n];

}

Measured memory_bytes: 1792
let last_i = ref 0

let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let extract (t : int array) =
  let rec max_heapify i =
    let l = left i in
    let r = right i in
    let m = if l <= !last_i && t.(l) > t.(i) then l else i in
    let m = if r <= !last_i && t.(r) > t.(m) then r else m in
    if i = m then ()
    else begin
      let tmp = t.(i) in
      t.(i) <- t.(m);
      t.(m) <- tmp;
      max_heapify m
    end in
  let ret = t.(1) in
  t.(1) <- t.(!last_i);
  decr last_i;
  max_heapify 1;
  ret

let insert x (t : int array) =
  let rec doit i =
    let p = parent i in
    if i <= 1 || t.(p) >= t.(i) then ()
    else begin
      let tmp = t.(i) in
      t.(i) <- t.(p);
      t.(p) <- tmp;
      doit p
    end in
  incr last_i;
  t.(!last_i) <- x;
  doit !last_i

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let t = Array.make 2000001 0 in
  while true do
    match read_line () |> split_on_char ' ' with
    | ["extract"] -> print_int (extract t); print_newline ()
    | ["insert"; n] -> insert (int_of_string n) t
    | _ -> exit 0
  done

Measured memory_bytes: 20200
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define printv(val) std::for_each(val.begin(),val.end(),[](auto x){cout<<x<<"\n";});
#define ALL(f,x,...) ([&](decltype((x)) xxxx) { return (f)(begin(xxxx), end(xxxx), ## __VA_ARGS__); })(x)
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}

template<class T,class U>
void msg_with_compare(T A,T B,U A_greater_B,U A_eq_B,U A_less_B){
    if(A==B){cout<<A_eq_B<<"\n";}else if(A>B){cout<<A_greater_B<<"\n";}else{cout<<A_less_B<<"\n";}}

string str1,str2;
void input(){
    cin>>str1>>str2;
}
void src(){
    if(str1.length()>str2.length()){
        cout<<"GREATER";
    }else if(str1.length()<str2.length()){
        cout<<"LESS";
    }else{
        msg_with_compare(str1,str2,"GREATER","EQUAL","LESS");
    }
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

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

#define ll long long
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define fill(a,b) memset(a,b,sizeof(a))
#define f first
#define s second

#define inf 1e15
#define ninf -1*1e15
#define mod 1000000007
#define N 500005
#define Ns 5005

string s;
ll n,m,x,y,d,k;
ll a[N],p[N],c[N],cost[N];

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--){
	    
	    
	    cin>>n>>k;
	    for(int i=0;i<n;i++){
	        cin>>p[i];
	        p[i]--;
	    }
	     for(int i=0;i<n;i++){
	        cin>>c[i];
	        
	    }
	    ll ans=ninf;
	    
	    for(int i=0;i<n;i++){
	        
	        ll len=0,total=0;
	        
	        int j=p[i];
	        
	        while(j!=i){
	            total+=c[j];
	            cost[len++]=total;
	            j=p[j];
	        }
	        
	        total+=c[i];
	        cost[len++]=total;
	        
	        
	        if(k<=len){
	            
	            ll cnt=ninf;
	            
	            for(int j=0;j<k;j++){
	               
	                cnt=max(cnt,cost[j]);
	            }
	          
	            ans=max(ans,cnt);
	        }
	        else
	        {
	            ll mx=ninf,mx2=ninf;
	            
	            for(int j=0;j<len;j++){
	                mx=max(mx,cost[j]);
	            }
	           
	             for(int j=0;j<k%len;j++){
	                 mx2=max(mx2,cost[j]);
	             }
	            
	            
	            ll h=k/len;
	            
	            ans=max(ans,mx);
	            ans=max(ans,mx+total*(h-1));
	            ans=max(ans,mx2+total*(h));
	        }
	    }
	    
	    
	    
	    
	    cout<<ans<<"\n";
	    
	    
	}
	return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <algorithm>
using uint = unsigned int;
constexpr uint MOD = 2019;

int main (void) {
  uint L, R;
  std::cin >> L >> R;

  if (R - L >= MOD) {
    // 区間の幅がMOD以上ならどこかにMODの倍数が存在する
    std::cout << 0 << std::endl;
  } else {
    // 区間の幅がMOD未満のときは全探索する
    uint ans = MOD;
    for (uint i = L; i < R; i++) {
      for (uint j = i + 1; j <= R; j++) {
        ans = std::min(ans, ((i % MOD) * (j % MOD)) % MOD);
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}


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

using namespace std;

using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
 
template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}
 
template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

ll n, x, ok=1;

int main()
{
	ios_base::sync_with_stdio(false);

	cin>>n;
	for (int i=1; i<=n; i++)
	{
		cin>>x;
		if (x%2 == 0)
		{
			if (x%5 != 0 && x%3 != 0)
			{
				ok = false;
				break;
			}
		}
	}
	if (ok)
		cout<<"APPROVED\n";
	else
		cout<<"DENIED\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

using mint = modint998244353;

void solve() {
    ll n;
    cin >> n;
    map<ll, ll> mp;
    rep(i, 2 * n) {
        ll h;
        cin >> h;
        mp[h]++;
    }
    vector<vector<mint>> vvm;
    vvm.push_back({1});
    for(auto i = mp.begin(); i != mp.end(); ++i) {
        if(i->second == 1) continue;
        vector<mint> vm = {1};
        for(int j = 2; j <= i->second; j += 2) {
            mint k = i->second - j + 2;
            vm.push_back(vm.back() * k * (k - 1) / j);
        }
        vvm.push_back(vm);
    }
    set<pll> st;
    for(int i = 0; i < vvm.size(); ++i) {
        st.emplace(vvm.size(), i);
    }
    while(st.size() > 1) {
        int i1 = st.begin()->second;
        st.erase(st.begin());
        int i2 = st.begin()->second;
        st.erase(st.begin());
        vvm[i1] = convolution(vvm[i1], vvm[i2]);
        st.emplace(vvm[i1].size(), i1);
    }
    vector<mint> d = {1};
    for(ll i = 1; i <= n; ++i) {
        d.push_back(d.back() * (2 * i - 1));
    }
    mint ans = 0;
    mint pn = 1;
    vector<mint> &vm = vvm[st.begin()->second]; 
    for(ll i = 0; i < vm.size(); ++i) {
        ans += pn * d[n - i] * vm[i];
        pn *= -1;
    }
    cout << ans.val() << endl;
    return;
}

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

Measured memory_bytes: 10064
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    count = 0
    while True:
        N = N // K
        if N >= 1:
            count += 1
        else:
            break
    print (count+1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
static const int MAX = 100;
int N;
int A[2][MAX+1];

int main(int argc, const char * argv[]) {
    cin >> N;
    int i, j;
    for (i = 0; i < 2; i++) {
        for (j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }
    
    int ans = 0;
    for (i = 0; i < N; i++) {
        int tmp = 0;
        for (j = 0; j < N; j++) {
            if (j < i) {
                tmp += A[0][j];
                if (i == j) tmp += A[1][j];
            } else {
                tmp += A[1][j];
                if (i == j) tmp += A[0][j];
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#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

// #incluede<bits/stdc+
using namespace std;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b == c or b + c == a or a + c == b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3596
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n,m;
	int c = -1;
	while(cin>>n>>m,n||m){
		bool flag =false;
		if(c!=-1)cout <<endl;
		for(int i=n;i <=m;i++){
			c++;
			if((i%4==0&&i%100!=0)||(i%400==0)){
				flag =true;
				cout <<i<<endl;
				continue;
			}
		}
		if(!flag){
			cout <<"NA"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            var X = Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
            var A = X[0];
            var B = X[1];
            var H = X[2];
            var M = X[3];
            var angle = 360 * Math.Abs(H / 12 - M / 60 + (M / 60) / 12);

            var Ans = A * A + B * B - 2 * A * B * Math.Cos(angle * (Math.PI / 180));
            Console.Write(Math.Sqrt(Ans));
        }
    }
}

Measured memory_bytes: 28628
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>


using namespace std;

const int N_MAX = 1000000;

int binarysearch(int target, int* arr, int arr_size){
  int l_ix = 0;
  int r_ix = arr_size;
  int mid_ix = l_ix + (r_ix - l_ix)/2;
  while(l_ix < r_ix){
    mid_ix = l_ix + (r_ix - l_ix)/2;

    if(l_ix == r_ix - 1){
      if(arr[l_ix] == target || arr[r_ix] == target ) return 1;
      else break;
    }
    
    if(arr[mid_ix] == target) return 1;
    if(arr[mid_ix] < target) l_ix = mid_ix;
    if(arr[mid_ix] > target) r_ix = mid_ix;
  }
  return 0;
}


int main(){
  int n;
  cin >> n;
  int* S = new int[n];
  
  for(int i=0;i<n;i++){
    cin >> S[i];
  }
  
  int q;
  cin >> q;

  int ans = 0;
  
  int* T = new int[n];
  for(int i=0; i<q; i++){
    cin >> T[i];
    ans += binarysearch(T[i], S, n-1);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 1e4 + 10 ;
int a[maxn] , n , w , h , mat[110][100];
int main()
{
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
	cin >>h >> w >>  n ;
	for ( int i = 1 ; i<= n ; i++) 
		cin >> a[i] ;
	int x = 1 ;
	for ( int i =1 ; i<=h ; i++)
	{
		if ( i%2 == 1 ) 
			for ( int j = 1 ; j<= w ; j++)
			{
				//cout << x <<" " << a[x] << endl;
				if ( a[x] ) 
					mat[i][j] = x, a[x]-- ;
				else x++ , mat[i][j] = x , a[x] -- ;

			}
		else
		{
			for (int j = w ; j>=1 ; j--)
			{
				//cout << x << " " << a[x] << endl;
				if (a[x] )
					mat[i][j] = x , a[x]--;
				else
					x++ , mat[i][j] = x , a[x] -- ;
			}
		}
	}
	//cout << " **** " << endl;
	for ( int i=1 ; i<= h ; i++) 
	{
		for ( int j = 1 ; j<= w ; j++)
			cout << mat[i][j] << " " ; 
		cout << "\n" ;
	}	

}


Measured memory_bytes: 384
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   int n;
  
 
   cin >> n;
  
   int a = n/500;
   int b = n%500;
   int c = b/5;
  

   cout << a*1000+c*5 << endl;
  
   
   
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int a, b;
    cin >> a >> b;
    int count = 0;

    rem(i, a, b + 1)
    {
        string s = to_string(i);
        bool kaibun = true;
        rep(j, s.size() / 2)
        {
            if (s[j] != s[s.size() - 1 - j])
            {
                kaibun = false;
                break;
            }
        }
        if (kaibun)
            count++;
    }
    cout << count << "\n";

    return 0;
}


Measured memory_bytes: 256
n=gets.to_i
a=gets.split.map &:to_i
h=Hash.new 0
a.map{|x|h[x]+=1}

if h.values.all?{|v|v*3==n||v*3==n*2}
h=h.map{|k,v|[k,v/(n/3)]}
a,x=h[0]
b,y=h[1]||[0,1]
c,z=h[2]||[0,1]
puts ([a]*x+[b]*y+[c]*z).reduce(:^)==0 ? "Yes":"No"
else
puts (h.keys-[0]==[]) ? "Yes" : "No"
end


Measured memory_bytes: 14472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<ul, ul> puu;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define ls (i << 1)
#define rs (i << 1 | 1)
#define mid (l + r >> 1)
#define enum(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i <  (k); i ++)
#define dec(i, j, k)  for(int i = j; i >= (k); i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define mfil(x, k) memset(x, k, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y, true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y, true) : false; }
struct __init { __init()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cout.precision(16); cout << fixed;
    srand(time(0) ^ ui(ul(new char)));
} } static __init__;
/* default code ends here */

const int maxn = 1010;
int n, m;
bool vis[maxn][maxn];
int dep[maxn][maxn];

const int mov[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

bool inr(int l, int x, int r)
{
    return l <= x && x <= r;
}
bool leg(pii p)
{
    return inr(1, p.fi, n) && inr(1, p.se, m);
}

void bfs()
{
    static queue<pii> que;
    enum(i, 1, n)
        enum(j, 1, m)
            if(vis[i][j])
                que.push(pii(i, j));
    while(!que.empty())
    {
        pii p = que.front();
        que.pop();
        enum(i, 0, 3)
        {
            pii q = pii(p.fi + mov[i][0], p.se + mov[i][1]);
            if(leg(q) && !vis[q.fi][q.se])
            {
                vis[q.fi][q.se] = true;
                dep[q.fi][q.se] = dep[p.fi][p.se] + 1;
                que.push(q);
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    string foo;
    enum(i, 1, n)
    {
        cin >> foo;
        enum(j, 1, m)
            vis[i][j] = foo[j - 1] == '#';
    }
    bfs();
    int ans = 0;
    enum(i, 1, n)
        enum(j, 1, m)
            chkmax(ans, dep[i][j]);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 11408
/* ex7_3
    sak_Citrue  */

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int height,width;
    char **ptr;
    scanf("%d %d",&height,&width);
    //行に出力があったか判定するフラグ
    char flag = 0;
    char *ptrrow = (char*)calloc(height,sizeof(char));
    char *ptrcol = (char*)calloc(width,sizeof(char));


    ptr = (char**)calloc(height,sizeof(char*));

    for(int i = 0;i<height;i++){
        ptr[i] = (char*)calloc(width,sizeof(char));
    }
    
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            scanf(" %c",ptr[i]+j);
        }
    }
    
    //どの行を出力すべき列か走査
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            if(*(ptr[i]+j)=='#'){
                *(ptrrow+i) = 1;
                break;
            }
        }
    }
    
    //どの列を出力すぺきか走査
    for(int i=0;i<width;i++){
        for(int j=0;j<height;j++){
            if(*(ptr[j] + i)=='#'){
                *(ptrcol+i) = 1;
                break;
            }
        }
    }
    
    
    //出力
    for(int i=0;i<height;i++){
        flag = 0;
        for(int j=0;j<width;j++){
            //出力すべき行、列にどちらも該当しているときのみ書き込む
            if(*(ptrrow+i)==1 && *(ptrcol+j)==1){
                printf("%c",*(ptr[i]+j));
                flag = 1;
            }
            //出力が存在した行末尾で改行
            if(j==width -1 && flag == 1){
                printf("\n");
            }
        }
    }

    free(ptrrow);
    free(ptrcol);
    for(int i=0;i<height;i++){
        free(ptr[i]);
    }
    free(ptr);

    return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    vector<double> cube(N + 1);
    for (int i = 0; i < N; i++)
    {
        cin >> cube.at(i);
        cube.at(i) = (cube.at(i) + 1) / 2;
    }
    double exp = 0;
    for (int i = 0; i < K; i++)
    {
        exp += cube.at(i);
    }

    double max_exp = exp;
    for (int i = K; i < N + 1; i++)
    {
        
        max_exp = max(max_exp, exp);
        exp += cube.at(i);
        exp -= cube.at(i - K);
        //cout << i << " " << max_exp << " vs " << exp << endl;
    }	
  cout<<fixed<<setprecision(12)<<max_exp<<endl;
    // for (exp : cube)
    // {
    //     cout << exp << " ";
    // }
    // cout << endl;

    return 0;
}

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

using namespace std;

const int N = 1e5 + 2;

int n, k, h[N], dp[N];

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

    for(int i = 1; i <= n; i ++)
        cin >> h[i];

    for(int i = 2; i <= n; i ++){
        dp[i] = 2e9;
    }

    for(int i = 2; i <= n; i ++){
        for(int j = 1; j <= k; j ++){
            if(i - j >= 1){
                dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            }
        }
    }

    cout << dp[n] << endl;
}


Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))

A.sort(reverse=True)
#print(A)

setbar=[]
known=set()

for a in A:
    if a in known:
        setbar.append(a)
        known.remove(a)
    else:
        known.add(a)
    if len(setbar) >= 2:
        break

if len(setbar) >= 2:
    print(setbar[0]*setbar[1])
else:
    print(0)


Measured memory_bytes: 14244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int n, k, c;

vector<int> solve(string s){
    int pos = 0, cnt = 0;
    vector<int> res;
    while(pos < n){
        if(s[pos] == 'o' && cnt < k){
            res.push_back(pos);
            cnt++, pos += c;
        }
        pos++;
    }
    if(cnt != k) res.clear();
    return res;
}

int main(){
    
    cin >> n >> k >> c;
    string s; cin >> s;
    
    vector<int> r1 = solve(s);
    reverse(s.begin(), s.end());
    vector<int> r2 = solve(s);
    reverse(r2.begin(), r2.end());

    for(int i = 0; i < r2.size(); i++)
        r2[i] = n-r2[i]-1;

    for(int i = 0; i < k; i++)
        if(r1[i] == r2[i])
            cout << r1[i]+1 << endl;
    
    return 0;
}


Measured memory_bytes: 3636
s = Array.new(3){}
3.times do |i|
    s[i] = gets.split("").map(&:to_s)
end

idx = Array.new(3){0}

turn = 0
loop {
    break if idx[turn] == s[turn].length

    idx[turn] += 1
    if s[turn][idx[turn] - 1] == "a"
       turn = 0
    elsif s[turn][idx[turn] - 1] == "b"
        turn = 1
    elsif s[turn][idx[turn] - 1] == "c"
        turn = 2
    end
}

case turn
when 0
    puts "A"
when 1
    puts "B"
when 2
    puts "C"
end

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

int main() {
  int N;
  cin>>N;
  vector<int> as(N);
  for(int i=0;i<N;i++){cin>>as.at(i);}
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=as.at(i)-1;
  }
  cout<<sum<<endl;
}

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define MOD 998244353

using namespace std;

using ll = long long;

template <class T, T M>
class modulo {
public:
    T data;

    modulo(T data = 0) : data(data % M) {
    }

    modulo operator+(const modulo &x) const {
        return modulo(data + x.data);
    }

    modulo operator-(const modulo &x) const {
        return modulo(data + (M - x.data));
    }

    modulo operator*(const modulo &x) const {
        return modulo(data * x.data);
    }

    modulo operator/(const modulo &x) const {
        return modulo(data * x.inv().data);
    }

    modulo operator+=(const modulo &x) {
        return data = (data + x.data) % M;
    }

    modulo operator-=(const modulo &x) {
        return data = (data + (M - x.data)) % M;
    }

    modulo operator*=(const modulo &x) {
        return data = (data * x.data) % M;
    }

    modulo operator/=(const modulo &x) {
        return data = (data * x.inv().data) % M;
    }

    modulo inv() const {
        return _pow(M - 2);
    }

    template <class Integer>
    modulo operator^(Integer n) const {
        if (n >= 0) {
            return _pow(n);
        } else {
            return _pow(M - 1 - (-n) % (M - 1));
        }
    }

    friend std::ostream& operator<<(std::ostream &os, const modulo &x) {
        os << x.data;
        return os;
    }

private:
    template <class NonNegativeInteger>
    modulo _pow(NonNegativeInteger n) const {
        modulo result(1);
        modulo x(*this);
        while (n) {
            if (n & 1) {
                result *= x;
            }
            x *= x;
            n >>= 1;
        }
        return result;
    }
};

template <class T, T M>
struct combinatorics {

    using Mod = modulo<T, M>;

    T N;
    std::vector<Mod> factorial;
    std::vector<Mod> inv_factorial;

    combinatorics(T N) : N(N), factorial(N + 1), inv_factorial(N + 1) {
        factorial[0] = 1;
        for (T i = 1; i <= N; ++i) {
            factorial[i] = factorial[i - 1] * i;
        }
        inv_factorial[N] = factorial[N].inv();
        for (T i = N; i >= 1; --i) {
            inv_factorial[i - 1] = inv_factorial[i] * i;
        }
    }

    Mod P(T n, T k) {
        if (0 <= k && k <= n) {
            return factorial[n] * inv_factorial[k];
        } else {
            return 0;
        }
    }

    Mod C(T n, T k) {
        if (0 <= k && k <= n) {
            return factorial[n] * inv_factorial[k] * inv_factorial[n - k];
        } else {
            return 0;
        }
    }

    Mod H(T n, T k) {
        if (n == 0 && k == 0) {
            return 1;
        } else {
            return C(n + k - 1, k);
        }
    }
};

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

    int N, M, K;
    cin >> N >> M >> K;

    using Mod = modulo<ll, MOD>;

    Mod result = 0;

    combinatorics<ll, MOD> combi(N - 1);

    REP(k, K + 1) {
        int n_blocks = N - k;
        result += combi.C(N - 1, k) * M * (Mod(M - 1) ^ (n_blocks - 1));
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 6348
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define s(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
int main(){
  int n,m;
  cin >> n>>m;
  ll a[n];
  rep(i,n)cin>>a[i];
  ll ans =100000000000;
  for(int bit =0;bit<(1<<n);bit++){
    int count =0;
    ll nowprice =0;
    ll nowhigh=0;
    rep(i,n){
      
      if(bit&(1<<i)){
        if(nowhigh>=a[i]){
          nowprice+=nowhigh-a[i]+1;
          nowhigh++;
        }
        else nowhigh=a[i];
        count++;
      }
      else{ if(nowhigh<a[i]){
        nowhigh=max(nowhigh,a[i]);
        count++;}
    }
    if(count>=m)ans=min(ans,nowprice);

  }
  
}cout<<ans<<endl;
}

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

const long long mod = 1000000007;

long long powMod(long long n,long long k,const long long p){
    long long res = 1;
    while(k > 0){
        if(k&1) res = res*n%p;
        k >>= 1;
        n = n*n%p;
    }
    return res;
}

int main(){
    long long n;
    std::cin >> n;
    std::vector<long long> delta(n-1,0);
    long long last;
    long long mother = 1;
    std::cin >> last;
    for(long long i=0; i<n-1; i++){
        long long x;
        std::cin >> x;
        delta.at(i) = x - last;
        last = x;
        mother = mother*(i+1)%mod;
    }
    long long total = 0, ans = 0;
    for(long long i=0; i<n-1; i++){
        long long now = (total*powMod(i+1,mod-2,mod)+1)%mod;
        ans += now*delta[i]%mod;
        ans %= mod;
        total += now;
        total %= mod;
    }
    std::cout << ans*mother%mod << "\n";
}


Measured memory_bytes: 3900
S = input().strip()[::-1]
div = [i[::-1] for i in ["dream", "dreamer", "erase", "eraser"]]

idx = 0
ok = False
while True:
    sub_ok = False
    for d in div:
        if S[idx:idx+len(d)] == d:
            idx += len(d)
            sub_ok = True
            break
    if sub_ok != True:
        break
    if idx == len(S):
        ok = True
        break

if ok:
    print("YES")
else:
    print("NO")

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
    int a, b, c, d = 0;
    cin >> a >> b >> c >> d;

    int m_sec_start = max(a, c);
    int m_sec_end   = min(b, d);
    int ans = m_sec_end - m_sec_start;
    if (ans <= 0)
    {
        COUT(0);
    }
    else
    {
        COUT(ans);
    }

    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   ll ans;
   ll a,b;cin >>a>>b;
   ans=max({a+b,a*b,a-b});
   cout <<ans <<endl;
   return 0;
}

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

template<typename T> struct Graph {
  struct Edge { int to; T cost; };
  vector<int> prev;
  vector<vector<Edge>> g;
  Graph(int n) : prev(n, -1), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
    //g[v].push_back({u, w});
  }
  vector<T> dijkstra(int s) {
    vector<T> dist(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

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

  int n, m, r; cin >> n >> m >> r;
  Graph<int> g(n);
  for (int i = 0; i < m; ++i) {
    int s, t, d; cin >> s >> t >> d;
    g.addEdge(s, t, d);
  }
  vector<int> d = g.dijkstra(r);
  for (int i = 0; i < n; ++i) cout << ( (d[i] < 0) ? "INF" : to_string(d[i]) ) << endl;
  return 0;
}



Measured memory_bytes: 13392
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#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;
// template <typename T>
// using o_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) find_by_order(i)
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
#define int ll
vector<ll> ft(1, 1LL);


/*======================================================================*/
void solve(){
    int n, ans = 0;
    cin >> n;
    rep(i, 0, n){
        int a, b;
        cin >> a;
        if(i%2 == 0 and a%2 == 1)ans++;
    }
    cout << ans;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
VLL ans;
const ll lim = 3234566667;
map<ll, bool> mp;
void make_num(ll n) {
  ll e = n % 10;
  n *= 10ll;
  if(e - 1 >= 0) {
    ll num = n + e - 1;
    if(num <= lim && mp[num] == false) {
      ans.push_back(num);
      mp[num] = true;
      make_num(num);
    }
  }

  ll num = n + e + 1ll;
  if(e + 1 <= 9 && num <= lim && mp[num] == false) {
    ans.push_back(num);
    mp[num] = true;
    make_num(num);
  }

  num = n + e;
  if(num <= lim && mp[num] == false) {
    ans.push_back(num);
    mp[num] = true;
    make_num(num);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  FOR(i, 1, 10) {
    ans.push_back(i);
    make_num(i);
  }
  sort(ans.begin(), ans.end(), greater<int>());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  sort(all(ans));
  // cout << ans.size() << endl;
  ll x;
  cin >> x;
  cout << ans[x - 1] << endl;
  return 0;
}


Measured memory_bytes: 7284
#include<iostream>
using namespace std;
int main()
{
	int j,ans=0,i,n,t[60];
	string s[60],x;
	cin >>n;
	for (i=0;i<n;i++){
		cin >>s[i]>>t[i];
	}
	cin >>x;
	for (i=0;i<n;i++){
		if (s[i] == x){
			j=i+1;
 			break;
		}
	}
	for (i=j;i<n;i++){
		ans+=t[i];
	}
		
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256