akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

template<i64 M>
struct modint {
  i64 a;
  constexpr modint(const i64 x = 0) noexcept: a((x % M + M) % M) {}
  constexpr i64 value() const noexcept { return a; }
  constexpr modint pow(i64 r) const noexcept {
    modint ans(1);
    modint aa = *this;
    while(r) {
      if(r & 1) {
        ans *= aa;
      }
      aa *= aa;
      r >>= 1;
    }
    return ans;
  }
  constexpr modint& operator+=(const modint r) noexcept {
    a += r.a;
    if(a >= M) a -= M;
    return *this;
  }
  constexpr modint& operator=(const i64 r) {
    a = (r % M + M) % M;
    return *this;
  }
  constexpr modint& operator-=(const modint r) noexcept {
    a -= r.a;
    if(a < 0) a += M;
    return *this;
  }
  constexpr modint& operator*=(const modint r) noexcept {
    a = a * r.a % M;
    return *this;
  }
  constexpr modint& operator/=(modint r) noexcept {
    i64 ex = M - 2;
    while(ex) {
      if(ex & 1) {
        *this *= r;
      }
      r *= r;
      ex >>= 1;
    }
    return *this;
  }

  constexpr modint operator+(const modint r) const {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint r) const {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint r) const {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint r) const {
    return modint(*this) /= r;
  }
};

template<const i64 M>
std::ostream& operator<<(std::ostream& os, const modint<M>& m) {
  os << m.value();
  return os;
}

const i64 MOD = 1e9 + 7;
using fp = modint<MOD>;

int main() {
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N);
  rep(i,0,N) cin >> A[i];
  sort(all(A));
  vector<fp> fact(N + 1);
  vector<fp> inv(N + 1);
  fact[0] = 1;
  rep(i,1,N + 1) fact[i] = fact[i - 1] * fp(i);
  inv[N] = fp(1) / fact[N];
  for(i64 i = N; i --> 0;) inv[i] = inv[i + 1] * fp(i + 1);

  auto binom = [&](i64 n, i64 r) {
    if(r < 0 || n < r) return fp(0);
    else return fact[n] * inv[r] * inv[n - r];
  };


  fp ans = 0;
  rep(i,0,N) {
    i64 j = N - i - 1;

    ans += fp(A[j]) * binom(N - i - 1, K - 1);
    ans -= fp(A[i]) * binom(N - i - 1, K - 1);
  }
  cout << ans.value() << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

struct UnionFind {
    vector< int > data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};


signed main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    cin >> S;
    vector<vector<int>> index(H, vector<int>(W));
    int count = 1;
    for (int i = 0; i < H; i++) for(int j = 0; j < W; j++) index[i][j] = count++;
    auto uf = UnionFind(count + 5);
    vector<vector<bool>> check(H, vector<bool>(W, false));
    queue<pair<int, int>> q;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        if (check[i][j] || S[i][j] == '.') continue;
        q.emplace(i, j);
        check[i][j] = true;
        while (!q.empty()) {
            auto now = q.front();
            q.pop();
            char c = '.';
            if (S[now.first][now.second] == '.') c = '#';

            for (int a = -1; a <= 1; a++) for (int b = -1; b <= 1; b++) {
                if (abs(a) == abs(b)) continue;
                if (now.first + a >= 0 && now.first + a < H && now.second + b >= 0 && now.second + b < W) {
                    if (S[now.first + a][now.second + b] != c || check[now.first + a][now.second + b]) continue;
                    check[now.first + a][now.second + b] = true;
                    uf.unite(index[now.first][now.second], index[now.first + a][now.second+ b]);
                    q.emplace(now.first + a, now.second + b);
                }
            }
        }
    }
    map<int, int> black;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        if (S[i][j] == '.') continue;
        black[uf.find(index[i][j])]++;
    }
    int ans = 0;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        if (S[i][j] == '.') continue;
        ans += uf.size(index[i][j]) - black[uf.find(index[i][j])];
    }
    cout << ans << endl;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N, A, B;
  cin >> N >> A >> B;

  N %= 12;

  for (int i = 1; i <= N; i++) {
    if (i % 2 == 1) {
      A = A - B;
    } else {
      B = A + B;
    }
  }

  cout << A << " " << B << endl;
  return 0;
}


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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >


int main()
{
    ll x,y;
    cin>>x>>y;
    if(x*500LL >= y){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


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

int main(){
	
	long long n,k;
	cin >> n >> k;
	n = n%k;
	if (n==0) {
		cout << n;
		return 0;
		}
	n = min(n,abs(n-k));
	cout << n;
	
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(s) ((int)((s).size()))

typedef long long ll;

const ll mod = 1000000007;
const double pi = 3.1415926535897932384626;

ll powmod(ll a, ll b) {ll res = 1; ll rem = a % mod; for (; b; b >>= 1) {if (b & 1) res = (res * rem) % mod; rem = (rem * rem) % mod;} return res;}

const int N = 58;

int X[N];
int Y[N];
pair<int, int> A[N];

int main()
{
/*	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif
*/
    
	int n = 0;
	int p = 0;
	scanf("%d %d", &n, &p);

	for (int i = 1; i <= n; ++i) {
		scanf("%d %d", X + i, Y + i);
		A[i] = mp(X[i], Y[i]);
	}

	sort(X + 1, X + 1 + n);
	sort(Y + 1, Y + 1 + n);

	ll ans = 4e18;

	for (int i = 1; i < n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			for (int k = 1; k < n; ++k) {
				for (int l = k + 1; l <= n; ++l) {
					ll lx = (ll) X[i];
					ll rx = (ll) X[j];
					ll ly = (ll) Y[k];
					ll ry = (ll) Y[l];
					ll tmp = 1ll * (rx - lx) * (ry - ly);
					int c = 0;
					for (int m = 1; m <= n; ++m) {
						if (A[m].fi >= lx && A[m].fi <= rx && A[m].se >= ly && A[m].se <= ry) ++c;
					}
					if (c >= p) {
						ans = min(ans, tmp);
					}
				}
			}
		}
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#include "atcoder/all"
using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

struct UF{
	vector<int>par,sz;
	void init(int n){
		par.resize(n);
		sz.resize(n);
		for(int i=0;i<n;i++){
			par[i]=i;
			sz[i]=1;
		}
	}
	int find(int x){
		return x==par[x]?x:par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		sz[x]+=sz[y];
		par[y]=x;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int size(int x){
		return sz[find(x)];
	}
};

signed main(){
	int N;
	cin >> N;
	vector<tuple<int,int,int>>v(N);
	REP(i, N) {
		int x, y;
		cin >> x >> y;
		v[i] = {x, y, i};
	}
	sort(ALL(v));
	UF uf;
	uf.init(N);
	set<pair<int, int>>st;
	REP(i, N) {
		auto[x, y, idx] = v[i];
		int mi = y;
		while(st.size() && st.begin()->first <= y) {
			uf.unite(st.begin()->second, idx);
			CHMIN(mi, st.begin()->first);
			st.erase(st.begin());
		}
		st.insert({mi, idx});
	}
	REP(i, N) out(uf.size(i));
}

Measured memory_bytes: 17652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    string s;cin>>s;
    ll buf=1;
    char tmp=s[0];
    rep(i,n){
        if(tmp!=s[i]){
            buf++;
            tmp=s[i];
        }
    }
    buf-=k*2;
    if(buf<0)buf=0;
    if(buf==0){
        cout<<n-1<<endl;
        return 0;
    }else{
        cout<<n-buf<<endl;
        return 0;
    }
}

Measured memory_bytes: 3776
// https://atcoder.jp/contests/abc143/tasks/abc143_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << max(0LL, a - b * 2) << endl;

    return 0;
}


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

vector<int> adj[100001];
int visited[100001];
void dfs(int u){
	visited[u] = 1;
	for(auto i: adj[u])
		if(!visited[i])
			dfs(i);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	int i, j;
	cin >> n >> m;
	for(i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		adj[u - 1].push_back(v - 1);
		adj[v - 1].push_back(u - 1);
	}
	int cnt = 0;
	for(i = 0; i < n; i++){
		if(!visited[i]){
			dfs(i);
			cnt++;
		}
	}
	cout << cnt - 1;
}

Measured memory_bytes: 10004
n, k = map(int, input().split())
check = [0] * n
for i in range(k):
    D = int(input())
    A = list(map(int, input().split()))
    for d in range(D):
        if check[A[d] - 1] == 0:
             check[A[d] - 1] = 1
print(check.count(0))

Measured memory_bytes: 9140
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    int x;
    cin >> x;
    int res;
    for (int i = 1; ; i++) {
        int u = pow(i, 2);
        if (u > x) {
            cout << res << endl;
            return 0;
        }
        for (int j = 2; ;j++) {
            int y = pow(i, j);
            if (y > x) break;
            if (i == 1) {
                res = 1;
                break;
            } else {
                res = max(res, y);
            }
            
        }
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }

signed main() {
SS(int,a);
ll mo=1000;
for(int i=1;i<=10;i++){
    if(mo*i>=a){
        p(mo*i-a);
        break;
    }
}

//p();
}

Measured memory_bytes: 3648
H, N = map(int,input().split())
M = []
for k in range(N):
    M.append(list(map(int,input().split())))
dp = [10**9]*(10**5)
dp[0] = 0
for A, B in M:
    for k in range(A+1):
        dp[k] = min(dp[k],B)
    for k in range(A+1,H+1):
        dp[k] = min(dp[k],dp[k-A]+B)
print(dp[H])


Measured memory_bytes: 74484
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
	int A,B,M; cin>>A>>B>>M;
	vector<int> a(A);
	vector<int> b(B);
	rep(i,A)cin>>a[i];
	rep(i,B)cin>>b[i];
	int x[M];
	int y[M];
	int c[M];
	vector<int> d(M+1);
	rep(i,M){
		cin>>x[i]>>y[i]>>c[i];
		d[i]=a[x[i]-1]+b[y[i]-1]-c[i];
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	d[M]=a[0]+b[0];
	sort(d.begin(),d.end());
	cout<<d[0]<<endl;
}

Measured memory_bytes: 5636
n =  int(input())
a = list(map(int,input().split()))

for i in range(n):
    if a[i]%2==1:
        pass
    else:
        if a[i]%3 !=0 and a[i]%5 !=0:
            print('DENIED')
            exit(0)
        else:
            pass
print("APPROVED")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define M1 1000000007LL
typedef pair<int,int> ii;
typedef vector<int> vi;
#define MAXN 1010
int h[MAXN];
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int n,t,a;
	cin >> n;
	cin >> t >> a;
	int r = 1;
	for (int i=1; i<=n; i++) {
		cin >> h[i];
	}
	for (int i=1; i<=n; i++) {
		if (abs(t*1000-6*h[i]-a*1000) < abs(t*1000-6*h[r]-a*1000)) {
			r = i;
		}
	}
	printf("%d\n", r);
	return 0;
}

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

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double mxv = 0;
	int mxa = a*100, mxb = 0;
	for(int i=0; i<=30; i++) {
		for(int j=0; j<=30; j++) {
			if(!i && !j) j++;
			int w = i*a*100+j*b*100;
			if(w >= f) continue;
			int suglim = min(e*(w/100), f-w);
			for(int x=0;x*c <= suglim;x++) {
				int sug = x*c;
				sug += ((suglim - sug) / d) * d;
				if(sug <= suglim && w+sug <= f && sug*1.0/(w+sug) > mxv) {
					mxv = sug*1.0/(w+sug);
					mxa = w;
					mxb = sug;
				}
			}
		}
	}
	cout << mxa+mxb << ' ' << mxb;
}


Measured memory_bytes: 256
class card(object):
    def __init__(self, str):
        self.symbol = str[0]
        self.num = int(str[1:])
    
    def __lt__(self,obj):
        if(self.num < obj.num):
            return True
        else:
            return False
    def __gt__(self,obj):
        if(self.num > obj.num):
            return True
        else:
            return False

    def display_card(self):
        print("{0}{1}".format(self.symbol,self.num),end="")

n = int(input())
s = input()
org = list(map(card,s.split()))  

bub = list(org)
sel = list(org)

#####################################
"""
Bubble sort(bub[])
""" '''
for i in range(0,len(bub)):
    for j in range(len(bub)-1,i-1,-1):
        if(bub[j] < bub[j-1]):
            tmp = bub[j]
            bub[j] = bub[j-1]
            bub[j-1] = tmp
'''
flag = True
while(flag==True):
    flag = False
    for i in range(1,len(bub)):
        if(bub[i]<bub[i-1]):
            bub[i],bub[i-1] = bub[i-1],bub[i]
            flag = True


"""
selection sort(sel[])
"""

for i in range(0,len(sel)-1):
    minj = i
    for j in range(i,len(sel)):
        if(sel[j] < sel[minj]):
            minj = j
    sel[i],sel[minj] = sel[minj],sel[i]
       
"""
comp org(org[])
"""


# buble

for i in range(0,len(bub)):
    bub[i].display_card()
    if (i==len(bub)-1):
        print("\n",end="")
    else :
        print(" ",end="")
print("Stable")
# selec
                
for i in range(0,len(sel)):
    sel[i].display_card()
    if (i==len(sel)-1):
        print("\n",end="")
    else :
        print(" ",end="")
if(bub == sel): 
    print("Stable")
else:
    print("Not stable")

Measured memory_bytes: 7768
// Problem : B - Crane and Turtle
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
bool legs(int x,int y)
{
	for(int i=0;i<=x;i++)
	{
		int temp=x-i;
		int sum=temp*2+i*4;
		if(sum==y)
		return true;
	}	
	return false;
}
int main()
{
	int x,y;
	cin>>x>>y;
	bool A=legs(x,y);
	if(A)
	cout<<"Yes";
	else cout<<"No";	
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
signed main() {
	string s;
	cin >> s;
	ll n = s.size();
	ll p, q;
	rep(i, n) {
		if (s[i] == 'A') {
			p = i;
			break;
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			q = i;
			break;
		}
	}
	cout << q - p + 1 << endl;
	ggr
}


Measured memory_bytes: 640
MOD = 10**9+7

n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

x_dif = [b-a for a,b in zip(x,x[1:])]
y_dif = [b-a for a,b in zip(y,y[1:])]

def cumd(dif,line):
    d_sum = 0
    for i,d in enumerate(dif,1):
        d_sum += d * i * (line-i)%MOD
        d_sum %= MOD
    return d_sum

dx_sum = cumd(x_dif,n)
dy_sum = cumd(y_dif,m)

    
print(dx_sum * dy_sum % MOD)

Measured memory_bytes: 20604
from math import sqrt, floor
from collections import defaultdict


N, P = map(int, input().split())

X = defaultdict(int)
cnt = 2
for a in range(2, floor(sqrt(P)) + 1):
    while P % a == 0:
        X[a] += 1
        P = P // a
if P > 1:
    X[P] += 1

ans = 1
for k, v in X.items():
    ans *= k ** (v // N)
print(ans)


Measured memory_bytes: 3436
n=int(input())
A = list(map(int,input().split()))

max_value = max(A)
max_index = A.index(max_value)

c=0

for i in range(max_index,n):
    c+=(max_value-A[i])

for i in range(1,max_index):
    if A[i-1]>A[i]:
        c+=(A[i-1]-A[i])
        A[i]=A[i-1]

print(c)

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;

  long long ans = 0;
  vector<int> a(n);
  vector<vector<pair<int, int>>> seg(m + 5);

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (!i) continue;
    ans += (a[i] - a[i-1] + m) % m;
    if (a[i-1] < a[i]) {
      seg[a[i-1] + 1].push_back({a[i-1], 1});
      seg[a[i]+1].push_back({-a[i-1], -1});
    } else {
      seg[a[i-1] + 1].push_back({a[i-1], 1});
      seg[1].push_back({a[i-1]-m, 1});
      seg[a[i]+1].push_back({m-a[i-1], -1});
    }
  }

  long long cur = 0, fans = ans;
  for (long long i = 1, cnt = 0; i <= m; ++i) {
    for (auto j : seg[i]) {
      cur += j.first;
      cnt += j.second;
    }
    fans = min(fans, ans - (cnt * i - cur - cnt));
  }

  cout << fans << '\n';
}


Measured memory_bytes: 6516
n=int(input())
h=list(map(int,input().split()))
def r_d(x):
  return [x[i] for i in range(len(x)) if i==0 or x[i]!=x[i-1]]
c=0
h=r_d(h)
while len(h)!=1:
  if h[0]>h[1]:
    c+=h[0]-h[1]
    h[0]=h[1]
  if h[len(h)-2]<h[len(h)-1]:
    c+=(h[len(h)-1]-h[len(h)-2])
    h[len(h)-1]=h[len(h)-2]
  for i in range(1,len(h)-1):
    if h[i]>h[i-1] and h[i]>h[i+1]:
      c+=h[i]-max(h[i-1],h[i+1])
      h[i]=max(h[i-1],h[i+1])
  h=r_d(h)
print(c+h[0])

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;

template<class T>
class set2 : public set<T> {
private:
    typename set<T>::iterator back_itr() {
        auto e = this->end();
        e--;
        return e;
    }

public:
    T front() {
        if (this->empty()) throw;
        return *this->begin();
    }

    T back() {
        if (this->empty()) throw;
        return *this->back_itr();
    }

    void erase_front() {
        if (!this->empty()) this->erase(this->begin());
    }

    void erase_back() {
        if (!this->empty()) this->erase(this->back_itr());
    }
};

int main() {
    int n;
    cin >> n;
    char *w[3] = {(char *) "2 5 63", (char *) "2 5 20 63", (char *) "2 5 20 30 63"};
    if (n < 6) {
        cout << w[n - 3] << endl;
        return 0;
    }
    set<int> r;
    int v[4] = {2, 3, 4, 6}, s = 0;
    for (int i = 0; i < n; i++) r.insert((i / 4) * 6 + v[(i % 4)]);
    for (auto &e:r) s += e;
    int t = n / 4;
    if (s % 6 == 2) {
        r.insert((t + 1) * 6);
        r.erase(2);
    }
    if (s % 6 == 3) {
        r.insert((t + 1) * 6);
        r.erase(3);
    }
    if (s % 6 == 5) {
        r.insert(t * 6 + 4);
        r.erase(3);
    }
    for (auto &e:r) cout << e << ' ';
    cout << endl;
}

Measured memory_bytes: 1280
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def z_algorithm(s):
    ma = 0
    prefix = [0]*len(s)
    j = 0
    for i in range(1,len(s)):
        if i+prefix[i-j] < j+prefix[j]:
            prefix[i] = prefix[i-j]
        else:
            k = max(0,j+prefix[j]-i)
            while i+k < len(s) and s[k] == s[i+k]:
                k += 1
            prefix[i] = k
            j = i
    prefix[0] = len(s)
    for i,pi in enumerate(prefix):
        if i < pi:
            prefix[i] = i
    for i in prefix:
        if ma < i:
            ma = i
    return ma

def main():
    n = int(ipt())
    s = input()
    ma = 0
    for i in range(n):
        pf = z_algorithm(s[i::])
        if ma < pf:
            ma = pf

    print(ma)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 74556
anslist=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(anslist[int(input())-1])


Measured memory_bytes: 9168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int[][] l = new int[4][13];

        for(int i = 0; i < a; i++) {
        	String cardType = sc.next();
        	int cardNum = sc.nextInt();

        	switch(cardType) {
        	case "S":
        		l[0][cardNum-1] = 1;
        		break;
        	case "H":
        		l[1][cardNum-1] = 1;
        		break;
        	case "C":
        		l[2][cardNum-1] = 1;
        		break;
        	case "D":
        		l[3][cardNum-1] = 1;
        		break;
        	}
        }

        for(int i = 0; i < 4; i++) {

        	for(int j = 0; j < 13; j++) {

        		if(l[i][j] == 0) {

        			switch(i) {
        			case 0:
        				System.out.println("S " + (j+1) );
        				break;
        			case 1:
        				System.out.println("H " + (j+1) );
        				break;
        			case 2:
        				System.out.println("C " + (j+1) );
        				break;
        			case 3:
        				System.out.println("D " + (j+1) );
        				break;
        			}
        		}
        	}
        }
	}
}



Measured memory_bytes: 26228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;

  ll ans = 0;
  rep3(i, 1, n + 1) {
    // ans に i の倍数が足される
    int l = n / i * i; // 末項
    int n_ = (l - i) / i + 1;
    // cerr << i << " " << l << " " << n_ << endl;
    ans += (i + l) * 1LL * n_ / 2; // 初項 i, 末項 l, 項数 n_ の等差数列の和
  }
  cout << ans << endl;
}


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

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

   rep2(i, a, b+1) {
      if (i % k == 0) {
          cout << "OK" << endl;
          return 0;
      }
   }

   cout << "NG" << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N;cin >> N;
    vector<int> A(N);rep(i,N)cin >> A[i];

    vector<LL> path(N);
    rep(i,N){
        if(i == 0)path[i] = abs(A[0]);
        else path[i] = abs(A[i] - A[i-1]);
    }

    vector<LL> ni(N);
    rep(i,N){
        if(i == 0)ni[i] = abs(A[1]);
        else if(i == N-1)ni[i] = abs(A[N-2]);
        else ni[i] = abs(A[i-1] - A[i+1]);
    }

    LL sum = 0;
    rep(i,N)sum += path[i];
    sum += abs(A[N-1]);

    rep(i,N){
        LL tmp;
        if(i == N-1){
            cout << sum - path[i] - abs(A[N-1])+ abs(A[N-2]) << endl;
        }
        else{
            tmp = sum - path[i] - path[i+1];
            tmp += ni[i];
            cout << tmp << endl;
        }
    }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, x;
  cin>>a>>b>>c;
  if(a>=b){
      x=a;
      a=b;
      b=x;
  }
  if(a>=c){
      x=a;
      a=c;
      c=b;
      b=x;
  }else if(a<c&&c<b){
      x=b;
      b=c;
      c=x;
  }
  cout<<a<<" "<<b<<" "<<c<<endl;
  
  
  return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void)
{	
	int n, t, a;
	cin >> n >> t >> a;
	int h;
	vector<double> b(n);
	for (int i = 0; i < n; i++) {
		cin >> h;
		b[i] = t - h * 0.006;
	}
	double ans = 100000000;
	int s;
	for (int i = 0; i < n; i++) {
		if (ans > abs(a - b[i])) {
			s = i;
			ans = abs(a - b[i]);
		}
	}
	cout << s + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    int n,l ;
    scanf ("%d%d",&n,&l) ;
    char s[n][l+1] ;
    for (int i=0; i<n; i++){
        scanf ("%s",s[i]) ;
    }
    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++){
            char tmp[l];
            if (strcmp(s[i],s[j])>0) {
                strcpy(tmp,s[i]);
                strcpy(s[i],s[j]);
                strcpy(s[j],tmp);
            }
        }    
    }
    for (int i=0; i<n; i++){
        printf("%s",s[i]) ;
    }
    printf ("\n") ;
    return 0 ;   
}

Measured memory_bytes: 128
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

cnt = 0
for i in 1...(n-1)
    if a[i-1] < a[i] and a[i] < a[i+1]
        cnt += 1
    elsif a[i-1] > a[i] and a[i] > a[i+1]
        cnt += 1
    end
end
puts cnt

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int H,N;
    cin>>H>>N;
    int A[N],B[N];
    const int inf = 1e9;
    vector<int> dp(H+1,inf);
    dp[0]=0;
    for(int i = 0 ; i < N ; i++){
         cin>>A[i]>>B[i];
         for(int j = 0 ; j <= H ; j++){
             dp[min(j+A[i],H)] = min(dp[min(j+A[i],H)],dp[j]+B[i]);
         }
    }
   cout<<dp[H];
}

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

ll f(ll x) {
  ll res = x, y = x;
  if (x % 2 == 0) {
    y -= 1;
  } else {
    res = 0;
  }
  res ^= y / 2 % 2 == 0 ? 1 : 0;
  return x <= 0 ? 0 : res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll ans = f(a - 1) ^ f(b);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int abs(int a, int b){
    if(a < b){
        return b - a;
    }
    return a - b;
}

int main(){
    int N, X;
    cin >> N >> X;
    int x[N];
    int sub[N];
    for(int i = 0; i < N; i++){
        cin >> x[i];
        sub[i] = abs(x[i], X);
    }

    for(int i = 1; i < N; i++){
        sub[i] = gcd(sub[i - 1], sub[i]);
    }

    cout << sub[N-1];

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int N;
long long a[301010];
long long L[301010];
long long R[301010];
int main()
{
    scanf("%d", &N);
    for(int i=0; i<3*N; ++i)
        scanf("%lld", a+i);
    priority_queue<long long, vector<long long>, greater<long long> > Lpq;
    priority_queue<long long> Rpq;
    long long lans = 0;
    for(int i=0; i<N; ++i)
    {
        lans += a[i];
        Lpq.push(a[i]);
        if(Lpq.size() == N) L[i] = lans;
    }
    for(int i=N; i<3*N; ++i)
    {
        lans += a[i];
        Lpq.push(a[i]);
        lans -= Lpq.top(); Lpq.pop();
        L[i] = lans;
    }
    
    long long rans = 0;
    for(int i=3*N-1; i>=2*N; --i)
    {
        rans += a[i];
        Rpq.push(a[i]);
        if(Rpq.size() == N) R[i] = rans;
    }
    for(int i=2*N-1; i>=0; --i)
    {
        rans += a[i];
        Rpq.push(a[i]);
        rans -= Rpq.top(); Rpq.pop();
        R[i] = rans;
    }
    
    long long ans = -0x3f3f3f3f3f3f3f3fLL;
    for(int i=N-1; i<2*N; ++i)
    {
        ans = max(ans, L[i]-R[i+1]);
    }
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 8564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
ll n,i,ans;
vector<ll> a;
int main(void){
  cin>>n;
  a.resize(n);
  for(i=0;i<n;i++)cin>>a[i];
  ans=a[0];
  for(i=0;i<n;i++)ans=__gcd(ans,a[i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int a[2000],b[2000],i;
	int q;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+3);
		
	for(i=0;i<2;i++){
		scanf("%d",&b[i]);
	}
	sort(b,b+2);

	q=a[0]+b[0]-50;
	printf("%d\n",q);
	return 0;
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
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<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vl a(n+1,0);
    rep(i,n-1){
        if(s[i]=='A' and s[i+1]=='C'){
            a[i+1]=1;
        }
    }
    partial_sum(all(a),a.begin());
    rep(i,q){
        ll l,r; cin>>l>>r;
        ll v=a[r]-a[l-1];
        if(r<n and s[r-1]=='A' and s[r]=='C')v--;
        puta(v);
    }
    return 0;
}

Measured memory_bytes: 1872
#include<bits/stdc++.h>
using namespace std;
const int inf = 1012345678;
int main()
{
    int finall=inf;
    vector<int>v(5);
    for(int i=0;i<5;i++)
        cin>>v[i];
    vector<int>p={0,1,2,3,4};
    do{
    int ans=0;
    for(int i=0;i<5;i++)
    {
        while(ans%10!=0)ans++;
        ans+=v[p[i]];
    }
    finall=min(ans,finall);
    }while(next_permutation(p.begin(),p.end()));
    cout<<finall<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

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

long long int rev_mod(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

long long int frac[110000];

int main(){
    int N;
    cin >> N;
    long long int FN = 1;
    frac[1] = 1;
    for(int i = 2; i <= N; i++){
        FN = FN * i;
        FN %= MOD;
        frac[i] = rev_mod(i);
        frac[i] += frac[i - 1];
        frac[i] %= MOD;
    }
    long long int ans = 0;
    for(int i = 1; i <= N; i++){
        long long int A;
        cin >> A;
        ans += A * FN % MOD * (frac[i] + frac[N - i + 1] - frac[1]);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;


P f(int x) {
    int a = x % 10;
    int b = 0;
    while(x) {
        b = x % 10;
        x /= 10;
    }
    return P(a,b);
}
int main(void) {
    int n;
    cin >> n;
    map<P, int> freq;
    for(int i = 1; i <=n; i++) {
        P p = f(i);
        freq[p]++;
    }

    ll ans  = 0;
    for(int i = 1; i <=9; ++i) {
        for(int j = 1; j<=9; ++j) {
            P a = make_pair(i,j);
            P b = make_pair(j,i);
            ans += freq[a] * freq[b];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d; cin >> a >> b >> c >> d;
    if(b < c || d < a) cout << 0;
    else cout << min(min(min(b-a, d-c), abs(b-c)), abs(a-d));
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 

 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	bool hasNext(){
		return !cin.eof();
	}
};
Input in;

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

bool isOutofRange(int x, int y, int b){
	return x < 0 || x >= 3 || y < 0 || y >= 3 || y*3+x==b;
}

int dp[20][3][3];

int main(){
	while(in.hasNext()){
		int n = in.nextInt();
		if(n == 0) break;
		rep(i, 20) rep(j, 3) rep(k, 3) dp[i][j][k] = 0;
		int s = in.next()[0]-'A', t = in.next()[0]-'A', b = in.next()[0]-'A';
		//cout<<s<<" "<<t<<" "<<b<<endl;
		//int x = s % 3, y = s / 3;
		dp[0][s / 3][s % 3] = 1;

		rep(i, n){
			rep(x, 3) rep(y, 3)
				rep(j, 4){
					int nx = x + dx[j], ny = y + dy[j];
					if(isOutofRange(nx, ny, b)) dp[i+1][y][x] += dp[i][y][x];
					else dp[i+1][ny][nx] += dp[i][y][x];
				}
		}

		ll ans = 0LL;
		rep(i, 3) rep(j, 3) ans += dp[n][i][j];

		printf("%.15lf\n", (double)dp[n][t/3][t%3]/ans);
	}
}

Measured memory_bytes: 1240
n,w = map(int,input().split())
v = [0]*(n+1)
for i in range(1,n+1):
    v[i] = list(map(int,input().split()))

dp = [[0 for j in range(w+1)] for i in range(n+1)]

for i,[W,V] in enumerate(v[1:],1):
    for j in range(w):
        dp[i][w-1-j] = dp[i-1][w-1-j]
        if w-1-j + W <= w:
            dp[i][w-1-j+W] = max(dp[i][w-1-j]+V, dp[i][w-1-j+W])

ans = 0
for i in range(n+1):
    ans = max(ans, max(dp[i]))
print(ans)

Measured memory_bytes: 217912
N = int(input())
S = input()
S_list=list(S)
ans=""
str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(len(S_list)):
    for j in range(len(str)):
        if S_list[i]==str[j]:
            ans+=str[(j+N)%26]
            break

print(ans)

Measured memory_bytes: 42348
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}


int main()
{
    int n;
    cin >> n;
    string p, q, tmp;
    p = q = "";
    for(int i = 0; i < n; i++) {
        cin >> tmp;
        p += tmp;
    }
    for(int i = 0; i < n; i++) {
        cin >> tmp;
        q += tmp;
    }

    string s = "";
    int ip, iq, i;
    ip = iq = -1;
    for(i = 1; i <= n; i++) {
        s += char(i + '0');
    }

    i = 0;
    do {
        if (s == p)
            ip = i; //cout << s << "p " << endl;
        if (s == q)
            iq = i; //cout << s << "q " << endl;
        bool val = next_permutation(s.begin(), s.end());
        i++;
    } while(ip < 0 || iq < 0);

    cout << abs(ip - iq) << endl;
    return 0;
}


Measured memory_bytes: 256