akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a, b, c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x, y)                 in>>x>>y
#define s3(x, y, z)               in>>x>>y>>z
#define s4(x, y, z, w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x, y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x, y)                out<<x<<" "<<y
#define p1d(a, n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a, n, m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2
int dp[10005];
int best(vi &a, vi& b, int& n, int start){
    if(start <= 0) return 0;
    if(dp[start] != -1) return dp[start];
    int mini = 1e9;
    f(i,0,n){
        mini = min(mini,b[i]+best(a,b,n,start-a[i]));
    }
    return dp[start] = mini;
}

class ECrestedIbisVsMonster {
public:
    void solve(std::istream &in, std::ostream &out) {
        int h, n;
        s2(h, n);
        rst(dp);
        vi a(n), b(n);
        f(i, 0, n) {
            s2(a[i], b[i]);
        }
        out<<best(a,b,n,h)<<endl;
    }
};


integer main() {
	ECrestedIbisVsMonster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 1152
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

bool[10^^5] PS;
int[10^^5] BS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    PS[0] = true;
    foreach (i; 0..N) BS[i] = 1;
    foreach (_; 0..M) {
        auto xy = readln.split.to!(int[]);
        auto x = xy[0]-1;
        auto y = xy[1]-1;
        --BS[x];
        ++BS[y];
        if (PS[x]) PS[y] = true;
        if (BS[x] == 0) PS[x] = false;
    }
    int r;
    foreach (i; 0..N) if (BS[i] > 0 && PS[i]) ++r;
    writeln(r);
}

Measured memory_bytes: 1788
#include<stdio.h>
#include<set>
std::set<int> s;
int main(){
	int _,n;
	for(scanf("%d",&_); _--;){
		scanf("%d",&n);
		if(s.count(n))s.erase(n);else
			s.insert(n);
	}
	printf("%d\n",s.size());
	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);

    int A[N], i, max, min;
    for(i=0; i<N; i++) {
        scanf("%d", &A[i]);
        if(i==1) {
            max = A[1] - A[0];
            min = A[1] - A[0]; 
        } else if(i>1) {
            if(A[i]-A[0]>max) {
                max = A[i] - A[0];
            }
            if(A[i]-A[0]<min) {
                min = A[i] - A[0];
            }
        }
    }

    if(max<0) {
        printf("%d\n", -min);
    } else {
        if(min>=0) {
            printf("%d\n", max);
        } else {
            printf("%d\n", max-min);
        }
    }

    return 0;
}

Measured memory_bytes: 128
import itertools
n,c=map(int,input().split())
ld=[list(map(int,input().split())) for i in range(c)]
lc=[list(map(int,input().split())) for i in range(n)]
ct=[[0 for i in range(c)] for i in range(3)]
for i in range(n):
  for j in range(n):
    ct[(i+j+2)%3][lc[i][j]-1]+=1
L=list(itertools.permutations([i for i in range(c)],3))
ans=[]
for i in range(len(L)):
  ct2=0
  for j in range(3):
    for k in range(c):
      ct2+=ld[k][L[i][j]]*ct[j][k]
  ans.append(ct2)
print(min(ans))

Measured memory_bytes: 8656
b=int(input())
a=input()
c=[]
for i in range(b):
    c.append(a[i])
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))

if b==1:
    print("No")
elif c[:int(b/2)]==c[int(b/2):]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 8992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair


int main(){
    ll n,m;
    cin >> n >> m;
    ll a[n],b[n];
    vector<ll> t[100005];
    for(ll i=0;i<n;i++){
        cin >> a[i] >> b[i];
        t[a[i]].push_back(b[i]);
    }
    priority_queue<ll> pq;
    ll res=0;
    for(ll i=1;i<=m;i++){
        for(auto p:t[i]){
            pq.push(p);
        }
        if(!pq.empty()){
            res+=pq.top();
            pq.pop();
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 10428
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

ll n,ans;
int maxv,num;
vector<int> a(1000100);

int main(){
    cin>>n;
    rep(i,0,n) cin>>a[i];
    rep(i,1,n){
        if(a[i-1]>a[i]){
            ans+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<ans<<"\n";
    return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;
#define VQ vector<priority_queue<pair<ll,vector<int>>>>
#define VQQ vector<vector<pair<ll,vector<int>>>>


int main() {

	
	int n;
	cin >> n;
	string s;
	cin >> s;
	string t = "";
	if (n % 2) {
		cout << "No" << endl;
	}
	else {
		REP(i, n / 2)t += s[i];
		t += t;
		if (s == t) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

}


Measured memory_bytes: 256
import sys

stdin = sys.stdin
 
ni = lambda:int(ns())
na = lambda:list(map(int,stdin.readline().split()))
ns = lambda:stdin.readline().rstrip()  # ignore trailing spaces

S = ns()
start = 0
end = 0
S2 = 'keyence'
for i in range(7):
    if S[i] == S2[i]:
        start += 1
    else:
        break
for i in range(-1, -8, -1):
    if S[i] == S2[i]:
        end += 1
    else:
        break
print('YES' if start + end >= 7 else 'NO')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}



int32_t main(){
  fastio;
  int n,k;
  cin>>n>>k;
  int best = 0;
  int tot=0;
  vector<int> p(n+1,0);
  for(int i=1;i<=n;i++)cin>>p[i];
  for(int i=1;i<=k-1;i++){
    tot+=p[i];
  }
  for(int i=k;i<=n;i++){
    tot-=p[i-k];
    tot+=p[i];
    best = max(best,tot + k); 
  }
  double ans = best/2.0;
  cout << setprecision(10)<<fixed;
  cout << ans << endl;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,W; cin>>n>>W;
    vector<ll> v(n), w(n);
    rep(i,n) cin>>v[i]>>w[i];
    vector<vector<ll>> dp(W+1, vector<ll>(n+1, -1));
    rep(i, W+1) dp[i][0]=0;
    rep(j,n){
        rep(i,W+1) dp[i][j+1]=dp[i][j];
        for(ll i=w[j]; i<=W; i++){
            if(dp[i-w[j]][j]>=0){
                chmax(dp[i][j+1], dp[i-w[j]][j]+v[j]);
            }
        }
    }
    ll res=0;
    rep(i,W+1) chmax(res, dp[i][n]);
    cout<<dp[W][n]<<endl;
    return 0;
}


Measured memory_bytes: 11048
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll dp[2][110][110];  /* dp[id][i+1][j] : 先頭からi桁目までで0でない数がj個現れるs以下の数の個数。
                                         ただし、id = 0 のとき現時点でsと等しい。
                                         id = 1 のとき現時点でsより小さいことが確定。 */
int main() {
    string s;
    ll k;
    cin >> s >> k;
    ll m = s.size();
    
    dp[0][0][0] = 1;
    rep(id, 2) {
        rep(i, m) {
            rep(j, m) {
                ll lim = s[i] - '0';  //  先頭からi桁目にはlim以下の数を置ける
                if(id) {
                    lim = 9;
                }
                exrep(x, 0, lim) {  // 先頭からi桁目にxを置くとする
                    dp[id || x < lim][i+1][j + (x != 0)] += dp[id][i][j];
                }
            }
        }
    }
    
    ll ans = 0;
    rep(id, 2) {
        ans += dp[id][m][k];
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 384
;; #!/usr/bin/env sbcl --script

(declaim (optimize (speed 3) (safety 0) (debug 0)))

(defun main ()
  (let* ((n (read))
         (k (read))
         (a (make-array n :element-type 'fixnum))
         (dp (make-array n :element-type 'fixnum :initial-element (floor most-positive-fixnum 2))))
    (let ((stream (make-string-input-stream (read-line))))
      (loop for i from 0
         for j = (read stream nil) until (null j)
         do (setf (aref a i) j)))
    (flet ((relax (from to)
             (let* ((from-val (aref dp from))
                    (to-val (aref dp to))
                    (diff (abs (- (aref a to) (aref a from)))))
               (setf (aref dp to) (min to-val (+ from-val diff))))))
      (setf (aref dp 0) 0)
      (dotimes (i n)
        (dotimes (j k)
          (when (< (+ i (1+ j)) n) (relax i (+ i (1+ j)))))))
    (format t "~a~%" (aref dp (- n 1)))))

(main)


Measured memory_bytes: 57704
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e3 + 5;
char lst[Max][Max];

int main()
{
	int x, y;
	cin >> x >> y;
	for (int i = 1; i <= x; i++)
	{
		for (int j = 1; j <= y; j++)
		{
			char c;
			scanf(" %c", &lst[i][j]);
		}
	}
	for (int i = 1; i <= 2 * x; i++)
	{
		int xx;
		if (double(i + 1) / 2 > (double)(i + 1) / 2 + 0.5)xx = ceil((i + 1) / 2);
		else xx = (i + 1) / 2;
		for (int j = 1; j <= y; j++)
		{
			printf("%c", lst[xx][j]);
		}
		cout << endl;
	}
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double  
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((ll)x.size())

class Name{
  public:
    void solve(){
      ll l,r,d;
      cin>>l>>r>>d;
      ll cnt=r/d-l/d;
      if(l%d==0) cnt++;
      cout<<cnt;LOL
    }
};

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  Name T;
  ll _=1; //cin>>_;
  while(_--) T.solve(); 
  return 0;
}

Measured memory_bytes: 3608
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int a,b;
  cin >> a >> b;
  for(int i = 1; i < 4; i++){
    if(a*b*i % 2 == 1){cout << "Yes" << endl; return 0;}
  }
  cout << "No" << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <vector>

#ifdef GONGKUNPENG
#include <cassert>

#define _GG 1
#else
#define _GG 0
#endif

#define uint unsigned
#define vector std::vector
#define max(a, b) std::max(a, b)
#define min(a, b) std::min(a, b)
#define swap(a, b) std::swap(a, b)
#define sort(...) std::sort(__VA_ARGS__)
#define ms(a, v) memset(a, v, sizeof(a))
#define sfor(i, n) for (int i = 1; i <= n; ++i)
#define tfor(i, n) for (int i = 0; i < n; ++i)

#if __cplusplus >= 201103L
using ll = long long;
using ull = unsigned long long;
#else
typedef long long ll;
typedef unsigned long long ull;
#endif

#define _GIO 1

#if _GIO
struct _gio {
#define BFSZ 1 << 18
#define blank(x) (x == ' ' || x == '\t' || x == '\n' || x == '\r')

  char rcha;
  bool rneg;
#if _GG
#else
  char ruf[BFSZ], wuf[BFSZ], *r1, *r2, *w1;
#endif

  _gio() {
    rcha = ' ';
#if _GG
#else
    r1 = r2 = ruf, w1 = wuf;
#endif
  }

  ~_gio() {
#if _GG
#else
    fwrite(wuf, 1, w1 - wuf, stdout);
#endif
  }

  inline void flush() {
#ifdef _GG
#else
    fwrite(wuf, 1, w1 - wuf, stdout), w1 = wuf;
#endif
  }

  inline int readc() {
#if _GG
    return getchar();
#else
    return (r1 == r2 && (r2 = (r1 = ruf) + fread(ruf, 1, BFSZ, stdin), r1 == r2)
                ? -1
                : *r1++);
#endif
  }

  template <typename T, typename... Args>
  void read(T &x, Args &... args) {
    read(x), read(args...);
  }

  inline void read() {}

  inline void read(char *s) {
    while (blank(rcha)) rcha = readc();
    while (!blank(rcha) && rcha > 0) *s++ = rcha, rcha = readc();
    *s = '\0';
  }

  inline void readl(char *s) {
    while (blank(rcha)) rcha = readc();
    while (rcha != '\n' && rcha > 0) *s++ = rcha, rcha = readc();
    *s = '\0';
  }

  template <typename T>
  inline void read(T &x) {
    x = rcha = rneg = 0;
    while (!isdigit(rcha) && rcha != '-') rcha = readc();
    rcha == '-' && (rneg = true, rcha = readc());
    while (isdigit(rcha)) x = (x << 3) + (x << 1) - 48 + rcha, rcha = readc();
    rneg && (x = -x);
  }

  inline void writec(const char &c) {
#if _GG
    putchar(c);
#else
    (w1 - wuf == BFSZ) && (fwrite(wuf, 1, BFSZ, stdout), w1 = wuf);
    *w1++ = c;
#endif
  }

  template <typename T, typename... Args>
  void write(const T &x, const Args &... args) {
    write(x), write(args...);
  }

  template <typename T, typename... Args>
  void writel(const T &x, const Args &... args) {
    write(x), write(args...);
    writec('\n');
  }

  inline void write() {}

  inline void write(const char &c) { writec(c); }

  template <typename T>
  void write(T x) {
    if (x < 0) {
      writec('-');
      write(-ll(x));
      return;
    }
    if (x > 9) write(x / 10);
    writec(x % 10 ^ 48);
  }

  inline void write(const char *s) {
    while (*s) writec(*s++);
  }
#undef BFSZ
} io;
#endif

const ll INF = 0x3f3f3f3f;
const uint MAXN =
#ifdef GONGKUNPENG
    15
#else
    1000005
#endif
    ;

int main() {
  ll a, b, n, t, r;
  io.read(n, a, b);
  t = a + b;
  r = n / t * a;
  r += min(n % t, a);
  io.writel(r);
  return 0;
}

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

using ll = long long;

constexpr ll inf = 1e18;

ll solve(vector<ll> a) {
    const int n = a.size();
    vector<vector<ll>> dp(n + 1, vector<ll>(5, inf));
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i) {
        dp[i + 1][0] = dp[i][0] + a[i];
        dp[i + 1][1] = min(dp[i][0], dp[i][1]) + (a[i] == 0 ? 2 : (a[i] & 1));
        dp[i + 1][2] = min({dp[i][0], dp[i][1], dp[i][2]}) + (a[i] % 2 == 0);
        dp[i + 1][3] = min({dp[i][0], dp[i][1], dp[i][2], dp[i][3]}) + (a[i] == 0 ? 2 : (a[i] & 1));
        dp[i + 1][4] = min({dp[i][0], dp[i][1], dp[i][2], dp[i][3], dp[i][4]}) + a[i];
        //cout << "I: " << i << endl;
        //cout << dp[i + 1][0] << ' ' << dp[i + 1][1] << ' ' << dp[i + 1][2] << ' ' << dp[i + 1][3] << endl;
    }

    return *min_element(begin(dp[n]), end(dp[n]));
}

int main() {
    int l; cin >> l;
    vector<ll> a(l);
    for(int i = 0; i < l; ++i) {
        cin >> a[i];
    }

    ll ans = solve(a);
    reverse(begin(a), end(a));
    ans = min(ans, solve(a));

    cout << ans << endl;
}


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

int main( void )
{
	string input;
	while ( cin >> input )
	{
		int ioi = 0, joi = 0;
		for ( int i = 0; i < input.size() - 2; i++ )
		{
			if ( input.substr( i, 3 ) == "IOI" ) ioi++;
			else if ( input.substr( i, 3 ) == "JOI" ) joi++;
		}
		cout << joi << endl;
		cout << ioi << endl;
	}
	return 0;
}

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

void solve(long long A, long long B, long long N){
ll mae,ato;
ll x,ans;
if(N>=B)x=B-1;
else{
    x=N;
}
    mae=(A*x)/B;
    ato=A*ll(x/B);
    ans=ll(mae)-ll(ato);    

cout<< ans <<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long N;
    scanf("%lld",&N);
    solve(A, B, N);
    return 0;
}


Measured memory_bytes: 3720
# ABC107C - Candles (ARC101C)
def main():
    n, k = tuple(map(int, input().rstrip().split()))
    x = tuple(map(int, input().rstrip().split()))
    ans = float("inf")
    for l, r in zip(x, x[k - 1 :]):
        ans = min(ans, r - l + min(abs(l), abs(r)))
    print(ans)


if __name__ == "__main__":
    main()

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

void solve(long long N){
    ll res;
    for (ll i=1;i<=N;i++){
        if (i%3 != 0 &&  i %5 != 0){
            res+=i;
        }
    }
    printf("%lld\n",res);

}

// 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)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}

Measured memory_bytes: 3816
from collections import deque

n = int(input())
a = list(map(int, input().split()))

d = deque()
for i in range(n):
    if i % 2 != 0:
        d.append(a[i])
    else:
        d.appendleft(a[i])

if n % 2 == 0:
    print(*list(reversed(d)))
else:
    print(*d)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int n;

int main(){
  ll mod = 1e9+7;
  vector<int> x;
  cin >> n;
  for(int i = 0; i < n; i++){
      int zzz; cin >> zzz;
      x.push_back(zzz);
  }

  int condition = 1;
  int count = 0;
  ll result = 1;
  while(count < n){
    if(x[count] >= 2*condition - 1){
      condition++;
      count++;
    }
    else{
      result = (result * condition) % mod;
      count++;
    }
  }

  condition--;
  while(condition > 0){
    result = (result * condition) % mod;
    condition--;
  }

  cout << result << endl;

}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int MAXN = 300005;
const int MOD = 1000000007;

ll arr[MAXN],pre[MAXN],suf[MAXN];
multiset<ll> s;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	for(int i=1;i<=3*n;i++) cin >> arr[i];
	ll sum = 0;
	for(int i=1;i<=n;i++) s.insert(arr[i]) , sum += arr[i];
	pre[n] = sum;
	for(int i=n+1;i<=2*n;i++){
		ll t = *s.begin();
		pre[i] = pre[i-1];
		if(arr[i] > t){
			sum += arr[i] - t;
			s.erase(s.begin());
			s.insert(arr[i]);
			pre[i] = sum;
		}
	}
	s.clear();
	sum = 0;
	for(int i=2*n+1;i<=3*n;i++) s.insert(-arr[i]) , sum += arr[i];
	suf[2*n+1] = sum;
	for(int i=2*n;i>=n+1;i--){
		ll t = -*s.begin();
		suf[i] = suf[i+1];
		if(arr[i] < t){
			sum += arr[i] - t;
			s.erase(s.begin());
			s.insert(-arr[i]);
			suf[i] = sum;
		}
	}
	sum = -1e16;
	for(int i=n;i<=2*n;i++){
		sum = max(sum,pre[i]-suf[i+1]);
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define MAX_V 100000
#define INF 1e9
#define N 105
using namespace std;

/*????°??????¨???(???????????£????????????????????¨) O(F|V||E|)*/

//????????¨????§???????(???????????????????????????????????????)
struct edge{int to, cap,cost,rev;};
int V;                         //????????°
vector<edge> G[MAX_V];         //??°???????????£??\???????????¨???
int dist[MAX_V];               //???????????¢
int prevv[MAX_V],preve[MAX_V]; //??´??????????????¨???

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

//s??????t????????????f???????°??????¨???????±???????
//??????????????´???-1?????????
int min_cost_flow(int s,int t,int f){
  int res=0;
  while(f>0){
    //????????????????????????????????????,s-t????????????????±???????
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update = true;
    while(update){
      update = false;
      for(int v=0; v<V ;v++){
	if(dist[v]==INF) continue;
	for(int i=0; i<G[v].size(); i++){
	  edge &e = G[v][i];
	  if(e.cap > 0 && dist[e.to] > dist[v]+e.cost) {
	    dist[e.to] = dist[v] + e.cost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    update = true;
	  }
	}
      }
    }
    if(dist[t]==INF) return -1; //????????\??????????????????
    
    //s???t?????????????????£??????????????????
    int d = f;
    for(int v=t; v!=s; v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d*dist[t];
    for(int v=t; v!=s; v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int wcost[N][N],ecost[N][N];
string s[N];
int n,cost[N][N];

int make_cost(int y,int x){
  int res=0,cnt=0;
  for(int i=0;i<n;i++)
    if(i!=x&&s[y][i]=='o')res+=ecost[y][i],cnt++;
  if(s[y][x]=='.')res+=wcost[y][x],cnt++;
  cost[y][x]=cnt;
  return res;
}

int main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>wcost[i][j];

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>ecost[i][j];

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

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      add_edge(i,j+n,1,make_cost(i,j));

  int S=n*2,T=S+1;
  for(int i=0;i<n;i++){
    add_edge(S,i,1,0);
    add_edge(i+n,T,1,0);
  }

  V=n*2+2;
  cout<<min_cost_flow(S,T,n)<<endl;

  int cnt=0;
  
  for(int i=0;i<n;i++)
    for(int j=0;j<G[i].size();j++)
      if(!G[i][j].cap)cnt+=cost[i][G[i][j].to-n];
  
  cout<<cnt<<endl;
  
  for(int i=0;i<n;i++)
    for(int j=0;j<G[i].size();j++)
      if(!G[i][j].cap){
	if(s[i][G[i][j].to-n]=='.')
	  cout<<i+1<<' '<<G[i][j].to-n+1<<' '<<"write"<<endl;
	for(int k=0;k<n;k++)
	  if(G[i][j].to-n!=k&&s[i][k]=='o')
	    cout<<i+1<<' '<<k+1<<' '<<"erase"<<endl;
      }
  
  return 0;
}

Measured memory_bytes: 6024
// ------------------------------------
// Date:2018/ 3/17
// Problem:ARC 067 FactorsOfFactorial c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1010;

bool prime[MAX_N];

void init()
{
  FOR(i, 2, MAX_N) {
    for (int j = 0; i * (j + 2) < MAX_N; ++j) {
      prime[i * (j + 2)] = true;
    }
  }
}

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

  memset(prime, false, sizeof(prime));
  CIN(N);
  init();
  ll ans = 1ll;
  FOR(i, 2, MAX_N) {
    if (prime[i]) continue;
    ll cnt = 0;
    FOR(j, 2, N + 1) {
      ll tmp = j;
      while(tmp % i == 0) {
	cnt++;
	tmp /= i;
      }
    }
    ans = (ans % MOD) * ((cnt + 1) % MOD);
    ans %= MOD;
    // debug(i);
    // debug(ans);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

extendedEu :: Integer -> Integer -> (Integer, Integer)
extendedEu a 0 = (1, 0)
extendedEu a b = (t, s - q * t)
  where
    (q, r) = quotRem a b
    (s, t) = extendedEu b r

lt::(Integer, Integer)->(Integer,Integer)->Bool
lt (x1,y1) (x2,y2) =
  let v1=abs x1 + abs y1
      v2=abs x2 + abs y2 in
      if v1==v2 then x1 <= y1 else v1 < v2

min'::(Integer, Integer)->(Integer,Integer)->(Integer,Integer)
min' a b
  | lt a b = a
  | otherwise = b

main = do
  [n,m]<- map (read::String->Integer) . words <$> getLine
  let (x0,y0) = extendedEu n m
  let d = n*x0 + m*y0
  -- k = -3 .. 3
  -- x = x0 + k*m / d, y = y0- k*n/d
  let (x1,y1) = foldl min' (x0,y0) [(x0 + k*m `div` d, y0 - k* n `div` d)| k<-[(-3)..3]]
  putStrLn $ show x1 ++ " " ++ show y1


Measured memory_bytes: 3688
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************


int main(){

    int S, W;
    cin >> S >> W;
    if (S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
signed main() {
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> L(2 * N);
  REP(i,2*N) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  REP(i,N) {
    ans += min(L[2*i], L[2*i+1]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b;
    cin >> a >> b;
    if (a == 1){
        if (b == 2){
            cout << "3" << endl;
        }
        else{
            cout << "2" << endl;
        }
    }
    else if (a == 2){
        if (b == 1){
            cout << "3" << endl;
        }
        else{
            cout << "1" << endl;
        }
    }
    else if (a == 3){
        if (b == 1){
            cout << "2" << endl;
        }
        else{
            cout << "1" << endl;
        }
    }
}

Measured memory_bytes: 256
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

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

const int N = 1e5 + 4;

ll n, m, k, r[N], c[N];
vector<pll> g[2][N];

void read() {
    cin >> n >> m >> k;
    for (int i = 0; i < k; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        g[0][u].em_back(v, w);
        g[1][v].em_back(u, w);
    }
}

int used[2][N];
ll color[2][N];

ll up, down;

void dfs(int s, int u, ll add, int stat) {
    used[s][u] = stat;
    color[s][u] = add;

    if (s) { /// add - x >= 0
        up = min(up, add);
    } else { /// x + add >= 0
        down = max(down, -add);
    }

    for (pll p : g[s][u]) if (stat != used[s ^ 1][p.first]) {
        dfs(s ^ 1, p.first, p.second - add, stat);
    }
}

bool check() {
    for (int u = 1; u <= n; ++u) {
        for (pll p : g[0][u]) {
            if (color[0][u] + color[1][p.first] != p.second) {
                return false;
            }
        }
    }
    return true;
}

void solve() {
    read();

    for (int i = 1; i <= n; ++i) if (!used[0][i]) {
        up = 8e18;
        down = -up;
        dfs(0, i, 0, 1);
        if (up < down) {
            cout << "No\n";
            return;
        }
        dfs(0, i, down, 2);
    }

    if (check()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 23700
def show(nums):
    for i in range(len(nums)):
        if i !=len(nums)-1:
            print(nums[i],end=' ')
        else:
            print(nums[i])

n=int(input())
nums=list(map(int,input().split()))
show(nums)
for i in range(1,n):
    v=nums[i]
    j=i-1
    while (j>=0 and nums[j]>v):
        nums[j+1]=nums[j]
        j -= 1
    nums[j+1] = v
    show(nums)



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

int k, ev, od;
long long sww, C[105][105];

void init () {
	C[0][0] = 1;
	for (int i = 1; i <= 101; i++)
		for (int j = 0; j <= i; j++) {
			if (j == 0 || j == i) C[i][j] = 1;
			else C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
}

int main () {
	scanf ("%d", &k);
	init ();
	ev = k / 2; od = k - ev;
	sww = C[ev][1] * C[od][1];
	return !printf ("%lld\n", sww);
}

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

using namespace std;

using ll = long long;

const long long MOD = 1e9 + 7;
const int INF = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s[3] = {"Sunny", "Cloudy", "Rainy"};
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < 3; ++i) if (s[i] == S) ans = i;
    ans = (ans + 1) % 3;
    cout << s[ans] << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <functional>
#include <array>
#include <algorithm>

using namespace std;

int main() {

	string S, T;
	
	int total = 0;

	cin >> S >> T;
	char* Sa = new char[S.size() + 1];
	char* Ta = new char[T.size() + 1];

	S.copy(Sa, S.length());
	T.copy(Ta, T.length());
	
	for (int i = 0; i < S.length(); i++)
	{
		if (Sa[i] != Ta[i])
		{
			total++;
		}
	}
	
	cout << total;

}

Measured memory_bytes: 4124
#include <bits/stdc++.h>
#define pb push_back

typedef long long ll;
using namespace std;

const ll MAXN = +100500;
const ll INF = 1e18;

map <ll, ll> mp;

int main() {
    ll n;
    cin >> n;
    ll sum = 0;
    mp[0] = 1;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ll x;
        cin >> x;
        sum += x;
        ans += mp[sum];
        mp[sum]++;
    }
    cout << ans;
}


Measured memory_bytes: 12800
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.insert(0,0)
hist = [0 for _ in range(N+1)]
hist[1] = 1
cur = A[1]
while True:
    cur = A[cur]
    if hist[cur]==0:
        hist[cur]=1
    else:break
s = cur
cur = A[s]
T = 1
while cur!=s:
    cur = A[cur]
    T += 1
T1 = 0
cur = 1
while cur!=s:
    cur = A[cur]
    T1 += 1
if K<=T1:
    cur = 1
    cnt = 0
    while cnt<K:
        cur = A[cur]
        cnt += 1
    print(cur)
else:
    K = (K-T1)%T
    cur = s
    cnt = 0
    while cnt<K:
        cur = A[cur]
        cnt += 1
    print(cur)

Measured memory_bytes: 102252
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
int main() {
	cin >> n;
	int cont = 0;
	int Acont = 0;
	while (cont<n) {
		string s;
		cin >> s;
		if (s == "A") {
			Acont++;
		}
		else if (s == "Un") {
			Acont--;
		}
		if (Acont < 0) {
			cout << "NO" << endl;
			return 0;
		}
		if (cont == n - 1) {
			if (Acont == 0)cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		cont++;
	}
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
typedef long long ll;
const int MAXN = 3e3+2;
int N;
double p[MAXN], dp[MAXN][MAXN], ans;
int main() {
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> N;
	for(int i = 1;i<=N;i++)cin >> p[i];
	dp[0][0] = 1.0;
	for(int i = 1;i<=N;i++)dp[0][i] = dp[0][i-1]*(1.0-p[i]);
	for(int i = 1;i<=N;i++){
		for(int j = i;j<=N;j++){
			dp[i][j]+=(dp[i-1][j-1]*p[j]);
			dp[i][j]+=(dp[i][j-1]*(1.0-p[j]));
		}
	}
	for(int i = N;i>=0;i--){
		if(i>N-i)ans+=dp[i][N];
		else break;
	}
	cout << fixed << setprecision(9) << ans << el;
	return 0;
}

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

using namespace std;

int f(int n) {
    return n * (n + 1) / 2;
}

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

    int n = b - a;
    cout << f(n - 1) - a << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  int[] num = new int[in.nextInt()];
  for (int i = 0; i < num.length; i++) {
	num[i] = i + 1;
  }
  int count = in.nextInt();
  Pattern pt = Pattern.compile("(\\d+),(\\d+)");
  int line[] = new int[2];
  for (int i = 0; i < count; i++) {
	String next = in.next(pt);
	for (int j = 0; j < line.length; j++) {
	  Matcher matcher = pt.matcher(next);
	  matcher.matches();
	  line[j] = Integer.parseInt(matcher.group(j + 1)) - 1;
	}
	int change = num[line[0]];
	num[line[0]] = num[line[1]];
	num[line[1]] = change;
  }
  for (int i = 0; i < num.length; i++) {
	System.out.println(num[i]);
  }
}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t; const ll MOD = 1e9+7;
int main(){
    ll N;
    cin >> N;
    ll keta = 0;
    while(pow(2, keta) <= N) keta++;
    ll dp[keta][3];
    dp[keta - 1][0] = 1;
    dp[keta - 1][1] = 1;
    dp[keta - 1][2] = 0;
    for(ll i = keta - 2; 0 <= i; i--){
        if((N >> i) & 1){
            dp[i][0] = dp[i + 1][0] * 1;
            dp[i][1] = dp[i + 1][0] + dp[i + 1][1];
            dp[i][2] = dp[i + 1][2] * 3 + dp[i + 1][1] * 2;
        }else{
            dp[i][0] = dp[i + 1][0] + dp[i + 1][1];
            dp[i][1] = dp[i + 1][1] * 1;
            dp[i][2] = dp[i + 1][2] * 3 + dp[i + 1][1];
        }
        for(int j = 0; j < 3; j++) dp[i][j] %= MOD;
    }
    cout << (dp[0][0] + dp[0][1] + dp[0][2]) % MOD << endl;
    return 0;
}

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


     signed main(){
         cout << std::fixed << std::setprecision(15);
int n;
cin>>n;
int a[n],ans1=0;
for(int i=0;i<n;i++)cin>>a[i];
int b[n],ans2=0;
for(int i=0;i<n;i++)b[i]=a[i];
ans1+=max(0ll,1-a[0]);a[0]=max(1ll,a[0]);
for(int i=1;i<n;i++){
     a[i]+=a[i-1];
   //  cerr<<a[i-1]<<' '<<a[i]<<endl;
     if(a[i]*a[i-1]>=0){
          if(a[i-1]>0){ans1+=a[i]+1;a[i]=-1;}
          else {ans1+=1-a[i];a[i]=1;}
     }
}//cerr<<a[n-1]<<' '<<ans1;
ans2+=max(0ll,1+b[0]);b[0]=min(-1ll,b[0]);
for(int i=1;i<n;i++){
     b[i]+=b[i-1];
     if(b[i]*b[i-1]>=0){
          if(b[i-1]>0){ans2+=b[i]+1;b[i]=-1;}
          else {ans2+=1-b[i];b[i]=1;}
     }
}
cout<<min(ans1,ans2)<<endl;


 }

 


 






    





      

        


Measured memory_bytes: 1792
use proconio::marker::*;
use proconio::*;

#[derive(Debug)]
#[allow(non_snake_case)]
struct Input {
    D: usize,
    c: Vec<i64>,
    s: Vec<Vec<i64>>,
    t: Vec<usize>,
    lasts: Vec<usize>,
    d: usize,
}

#[allow(non_snake_case)]
impl Input {
    fn new(D: usize, c: Vec<i64>, s: Vec<Vec<i64>>) -> Input {
        Input {
            D,
            c,
            s,
            t: vec![0; D],
            lasts: vec![0; 26],
            d: 0,
        }
    }

    fn calc(&mut self) -> i64 {
        let mut score = self.s[self.d][self.t[self.d]];

        self.lasts[self.t[self.d]] = self.d + 1;
        for i in 0..26 {
            score -= (self.d + 1 - self.lasts[i]) as i64 * self.c[i];
        }

        self.d += 1;
        score
    }
}

#[allow(non_snake_case)]
fn main() {
    input! {
        D: usize,
        c: [i64; 26],
        s: [[i64; 26]; D],
    };

    input! {
        t: [Usize1; D],
    };
    let mut obj = Input::new(D, c, s);
    obj.t = t;
    let mut score = 0;

    for _ in 0..D {
        score += obj.calc();
        println!("{}", score);
    }
}


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


using namespace std;

using ll = long long;


void prime_factorization(vector<pair<ll, ll>> &res, ll x) {
    for (ll p = 2; p * p <= x; p++) {
        if (x % p != 0) {
            continue;
        }

        ll num = 0;
        while (x % p == 0) {
            ++num;
            x /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (x != 1) {
        res.push_back(make_pair(x, 1));
    }
}


int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<bool> used(1000000, false);
    bool flag = false;
    for (auto e : A) {
        vector<pair<ll, ll>> res;
        prime_factorization(res, e);
        for (auto p : res) {
            ll prime = p.first;
            if (used[prime]) {
                flag = true;
                break;
            }
            used[prime] = true;
        }
        if (flag)
            break;
    }
    if (!flag) {
        cout << "pairwise coprime" << endl;
        return 0;
    }

    ll g = gcd(A[0], A[1]);
    for (ll i = 1; i < N; i++) {
        g = gcd(A[i], g);
    }
    if (g == 1) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int L = -1;
    int R = 100000 + 1;
    rep(i, m)
    {
        int l, r;
        cin >> l >> r;
        L = max(l, L);
        R = min(r, R);
    }

    int ans = (R - L >= 0) ? R - L + 1 : 0;

    cout << ans << endl;
}


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

using namespace std;

int main()
{
    string ch;
    cin >> ch;
    if(ch == "SAT")cout <<"1\n";
    else if(ch == "FRI")cout <<"2\n";
    else if(ch == "THU")cout <<"3\n";
    else if(ch == "WED")cout <<"4\n";
    else if(ch == "TUE")cout <<"5\n";
    else if(ch == "MON")cout <<"6\n";
    else if(ch == "SUN")cout <<"7\n";
	return 0;
}



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

#define llint long long int

int main(void){

  int n;
  std::cin >> n;


  int count =0;
  for(int i=1; i<=n; i++){
    int a;
    std::cin >> a;
    if(a != i) count++;
  }

  if(count <=2) std::cout << "YES" << std::endl;
  else          std::cout << "NO"  << std::endl;

  return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	string s;
	int k;
	cin >> s >> k;
	if(s.size()==1 && k==1)
	{
		cout << "0" << endl;
		return 0;
	}
	if(s.size()==1 && k>1)
	{
		cout << k/2 << endl;
		return 0;
	}
	int flagg=0;
	rep(i,0,s.size()-2)
	{
		if(s[i]!=s[i+1])
		{
			flagg=1;
			break;
		}
	}
	if(flagg==0)
	{
		int x= s.size()*k;
		int ans= x/2;
		cout << ans << endl;
		return 0;
	}
	int l=0;
	int r= s.size()-1;
	int ans=0;
	if(s[l]==s[r])
	{
		int x=0;
		int y=0;
		while(s[l]==s[l+1])
		{
			l++;
			x++;
		}
		l++;
		x++;
		while(s[r]==s[r-1])
		{
			r--;
			y++;
		}
		r--;
		y++;
		ans += (x/2) + (y/2) + ((x+y)/2)*(k-1);
	}
	int tot=0;
	for(int i=l;i<r;)
	{
		if(s[i]==s[i+1])
		{
			tot++;
			i+=2;
		}
		else
		{
			i++;
		}
	}
	ans += tot*k;
	cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    long long N, K, K2, ans=1;

    cin >> N >> K;

    K2 = K;

    if(N < K){
        cout << 1 << endl;
    }

    else{
        while(N >= K){
            K *= K2;
            ans++;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int N;
  	cin>>N;
  	int a[4]={0,0,0,0};
  	while(N--)
    {
      string s;
      cin>>s;
      if(s=="AC") ++a[0];
      else if(s=="WA") ++a[1];
  	  else if("TLE"==s) ++a[2];
      else ++a[3];
    }
  	cout<<"AC x "<<a[0];
  	cout<<"\nWA x "<<a[1];
  	cout<<"\nTLE x "<<a[2];
  	cout<<"\nRE x \n"<<a[3];
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define int long long
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

signed main(void){
    int x[3];
    int n; cin >> n >> x[0] >> x[1] >> x[2];

    int xyz = x[0] + x[1] + x[2];
    int mask = (1 << (xyz + 1)) - 1;

    vector<vi> dp(n + 1, vi(mask + 1));
    dp[0][1] = 1;

    int nmask = 0;
    {
        int sum = 0;
        rrep(i, 3){
            sum += x[i];
            nmask |= (1 << sum);
        }
    }

    rep(i, n){
        rep(j, mask + 1){
            if(dp[i][j] == 0) continue;

            rep(k, 1, 11){
                int nj = (((j << k) + 1) & mask);
                if((nj & nmask) == nmask) continue;

                dp[i + 1][nj] = ADD(dp[i + 1][nj], dp[i][j], mod);
            }
        }
    }
    
    int res = 1;
    rep(i, n){
        res = MUL(res, 10, mod);
    }
    for(auto & e : dp[n]){
        res = SUB(res, e, mod);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 86400