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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int M, N;
	cin >> M >> N;
	vector<string> C(M);
	vector<vector<pair<int, int>>> pos(26);
	for (int i = 0; i < M; i++) {
		cin >> C[i];
		for (int j = 0; j < N; j++) {
			if (C[i][j] != '.') {
				pos[C[i][j] - 'A'].emplace_back(i, j);
			}
		}
	}
	int res = 0;
	while (true) {
		int val = -1;
		for (int i = 0; i < 26; i++) if (!pos[i].empty()) {
			int x0 = pos[i][0].first, x1 = pos[i][1].first, y0 = pos[i][0].second, y1 = pos[i][1].second;
			if (x0 == x1) {
				if (y0 > y1) swap(y0, y1);
				bool ok = y1 - y0 > 1;
				for (int j = y0 + 1; j < y1; j++) {
					if (C[x0][j] != '.') {
						ok = false;
						break;
					}
				}
				if (ok) {
					val = i;
					break;
				}
			}
			else if (y0 == y1) {
				if (x0 > x1) swap(x0, x1);
				bool ok = x1 - x0 > 1;
				for (int j = x0 + 1; j < x1; j++) {
					if (C[j][y0] != '.') {
						ok = false;
						break;
					}
				}
				if (ok) {
					val = i;
					break;
				}
			}
			else {
				bool ok = true;
				for (int j = min(x0, x1) + 1; j < max(x0, x1); j++) {
					if (C[j][y0] != '.') {
						ok = false;
						break;
					}
				}
				if (C[x1][y0] != '.') ok = false;
				for (int j = min(y0, y1) + 1; j < max(y0, y1); j++) {
					if (C[x1][j] != '.') {
						ok = false;
						break;
					}
				}
				if (ok) {
					val = i;
					break;
				}
				ok = true;
				for (int j = min(y0, y1) + 1; j < max(y0, y1); j++) {
					if (C[x0][j] != '.') {
						ok = false;
						break;
					}
				}
				if (C[x0][y1] != '.') ok = false;
				for (int j = min(x0, x1) + 1; j < max(x0, x1); j++) {
					if (C[j][y1] != '.') {
						ok = false;
						break;
					}
				}
				if (ok) {
					val = i;
					break;
				}
			}
		}
		if (val == -1) break;
		res += 2;
		for (auto p : pos[val]) {
			C[p.first][p.second] = '.';
		}
		pos[val].clear();
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3348
// BCC
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <queue>

// GCC
// #include <bits/stdc++.h>

using namespace std;

#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 each(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define mp make_pair

typedef long long ll;

const int INF = 1 << 28;
const ll INFLL = 1ll << 56;

typedef ll Cost;

struct Edge {
	int src, dst;
	Cost cost;
	bool operator < (const Edge &e) const {
		return cost > e.cost; // ???????????£??????????????¨?????¨???
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

/**
 * ???????§????????????? (Dijkstra ???)
 * ?????????????????¨????????????
 * dijkstra(graph, s) ?§???? s ????????????????????§????????¢?????????
 * buildPath(t) ?????? t ???????§?????????§??????????????????
 */

vector<int> prev_; // ???????????¨????????????

vector<Cost> dijkstra(const Graph &g, int s){
	vector<Cost> dist(g.size(), INFLL);
	prev_.assign(g.size(), -1);
	priority_queue<Edge> pq;
	
	dist[s] = 0;
	pq.push({-1, s, 0});
	while (pq.size()){
		Edge c = pq.top(); pq.pop();
		prev_[c.dst] = c.src;
		each(e, g[c.dst]){
			if (dist[e->dst] > c.cost + e->cost){
				dist[e->dst] = c.cost + e->cost;
				pq.push({e->src, e->dst, dist[e->dst]});
			}
		}
	}
	
	return dist;
}


/**
 * ????????????
 * dijkstra ??????????????????
 */

vector<int> buildPath(int t){
	vector<int> res;
	for (int v = t; v != -1; v = prev_[v]){
		res.pb(v);
	}
	reverse(res.begin(), res.end());
	return res;
}


int main()
{
	int n, m, s;
	scanf("%d %d %d", &n, &m, &s);
	Graph g(n);
	rep(i, m){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		g[a].pb({a, b, c});
	}
	std::vector<ll> res = dijkstra(g, s);
	each(x, res){
		if (*x == INFLL) puts("INF");
		else printf("%lld\n", *x);
	}
}

Measured memory_bytes: 18024
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	char s[301]; scanf("%s",s);
	int hist[128]={};
	for(int i=0;s[i];i++) hist[s[i]]++;
	printf("%d\n",min(min(hist['K'],hist['U']),min(hist['P'],hist['C'])));
	return 0;
}

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

int main(){
	string S;
	int m, h;
	while(1){
		cin >> S;
		if(S == "-") break;
		cin >> m;
		for(int i=0;i<m;i++){
			cin >> h;
			S = S.substr(h) + S.substr(0, h);
		}
		cout << S << endl;
	}
	return 0;
}

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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}

//main------------------------------------------------------------------------------------------
int mod_pow(int x, int n, int m){if(n== 0) return 1;int res = mod_pow(x*x%m,n/2,m);if(n&1) res = res*x%m;return res;}
int factorial(int x){int res = 1;rep(i,2,x+1){res *= i;res %= mod;}return res;}
int inv(int n){return mod_pow(n,mod-2,mod);}

struct binomial_coefficient{
    vector<int> facts;
    vector<int> invs;
    int maxn;

    void init(int n){
        maxn = n;
        facts.push_back(1); invs.push_back(1);
        for(int i = 1; i < maxn; i++){
            facts.push_back(facts[i-1]*i%mod);
            invs.push_back(inv(facts[i]));
        } 
    }

    int nPr(int n, int r){
        if(r > n) return 0;
        return (facts[n]%mod * invs[n-r]% mod)%mod;
    }

    int nCr(int n, int r){
        if(r > n) return 0;
        return facts[n]%mod * invs[n-r]%mod * invs[r] % mod;
    }

    int nHr(int n, int r){
        if(n==0 && r==0) return 1;
        return nCr(n+r-1, r);
    }

};
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    binomial_coefficient bc;
    bc.init(200005);

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

    int t = m;
    int ans = 1;

    int cnt = 0;
    while(t % 2 == 0){
        cnt++;
        t /= 2;
    }
    if(cnt > 0) ans = ans * bc.nHr(n, cnt) % mod;

    for(int i = 3; t > 1; i+=2){
        cnt = 0;
        while(t % i == 0){
            cnt++;
            t /= i;
        }
        if(cnt > 0) ans = ans * bc.nHr(n, cnt) % mod;
    }
    print(ans % mod);

}

Measured memory_bytes: 4584
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back

using namespace std;
int n,i;
int main(){
    cin >> n >> i;
    cout << n - i + 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    double x1,y1,x2,y2;
    double distance;
    cin>>x1>>y1>>x2>>y2;
    distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%1f\n",distance);
    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<int>& a, vector<int>& b) {
	return a[0] < b[0];
}

int ycomp(vector<int>& a, vector<int>& b) {
	return a[1] < b[1];
}

int zcomp(vector<int>& a, vector<int>& b) {
	return a[2] < b[2];
}
#define XSORT(c) sort((c).begin(),(c).end(),xcomp)
#define YSORT(c) sort((c).begin(),(c).end(),ycomp)
#define ZSORT(c) sort((c).begin(),(c).end(),zcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

int main() {
	LL N, K;
	cin >> N >> K;
	LL sum = 0;
	vector<LL> a(N + 1, 0);
	vector<LL> b(N + 1, 0);
	vector<LL> c(N + 1, 0);
	REP(i, N) {
		cin >> a[i + 1];
		if (a[i + 1] > 0) {
			sum += a[i + 1];
			b[i + 1] = b[i];
			c[i + 1] = c[i] + a[i + 1];
		}
		else {
			b[i + 1] = b[i]+a[i+1];
			c[i + 1] = c[i];
		}

	}
	LL max = b[N];
	REP(i, N - K + 1) {
		LL hoge = b[i + K] - b[i];
		LL fuga = c[i + K] - c[i];
		if (hoge > max) {
			max = hoge;
		}

		if (-fuga > max) {
			max = -fuga;
		}
	}
	cout << sum + max<< endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in insert
#define mp make_pair
#define F first
#define pb push_back
#define pf push_front
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll exp(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x); x=(x*x); y/=2; } return res;}

int main(){
    ll x; cin>>x;
    ll c=0;
    while(x){
        if(x>=500){
            x-=500;
            c+=1000;
        }
       else if(x>=5){
            x-=5;
            c+=5;
        }
        if(x<5)
            break;
    }
    cout<<c;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main(){
    ll n; cin >> n;
    ll ans = 0;
    vector<ll> a(n);

    rep(i,n) cin >> a[i];

    for(int i = 1; i < n; i ++){
        if(a[i-1] > a[i]){
            ans += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }

    cout << ans;

}

Measured memory_bytes: 4756
#!/usr/bin/env python3

def compare(a, b):
    return a == '?' or b == '?' or a == b

def solve(A, B, C):
    n, m, l = len(A), len(B), len(C)
    AB, AC, BC = [True]*(n+1), [True]*(n+1), []
    for i in range(n):
        for j in range(m):
            if i + j >= n:
                continue
            if not compare(A[i + j], B[j]):
                AB[i] = False
                break
    
    for i in range(n):
        for j in range(l):
            if i + j >= n:
                continue
            if not compare(A[i + j], C[j]):
                AC[i] = False
                break

    for i in range(n):
        for j in range(l):
            if i + j >= m:
                continue
            if compare(B[i + j], C[j]):
                continue
            break
        else:
            BC.append(i)
    for i in range(max(0,n-m)):
        BC.append(m+i)

    res = n + m + l
    for i in range(n+1):
        if AB[i]:
            for j in BC:
                if i + j >= n:
                    res = min(res, max(i + m, i + j + l))
                elif AC[i + j]:
                    res = min(res, max(n, i + m, i + j + l))
    return res

def main():
    a = input()
    b = input()
    c = input()
    ans = min(solve(a,b,c),solve(a,c,b),solve(b,a,c),solve(b,c,a),solve(c,a,b),solve(c,b,a))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49884
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,p3[13]={1};
    fr(i,12) p3[i+1]=p3[i]*3;
    string t;
    cin>>n>>t;
    int m=t.length();
    vector<int> a(m),v={0,1,2};
    fr(i,m){
        if(t[i]=='S'){
            swap(v[1],v[2]);
        }
        else{
            a[i]=v[2];
            v[2]=v[1];
            v[1]=v[0];
            v[0]=a[i];
        }
    }
    vector<int> ans(3);
    fr(i,3) ans[v[i]]=i;
    //for(auto&K:a) cout<<K<<" ";cout<<endl;
    Fr(l,n-1){
        vector<int> nv={0,1,2};
        auto e=vector(p3[l],array<int,3>());
        for(auto&A:e) A[0]=0,A[1]=1,A[2]=2;
        fr(i,m){
            //cout<<i<<endl;
            if(t[i]=='S'){
                swap(nv[1],nv[2]);
            }
            else{
                int T=a[i];
                auto&A=e[T];
                array<int,3> iv={},AA={},tmp={};
                fr(I,3) iv[nv[I]]=I;
                fr(I,3) AA[iv[A[I]]]=I;
                /*cout<<"iv:";for(auto&K:iv) cout<<K<<"!";cout<<endl;
                cout<<"AA:";for(auto&K:AA) cout<<K<<"!";cout<<endl;
                cout<<"iA:";for(auto&K:A) cout<<iv[K]<<"!";cout<<endl;*/
                tmp[AA[2]]=0;tmp[AA[0]]=1;tmp[AA[1]]=2;
                fr(I,3) A[I]=nv[tmp[I]];
                /*cout<<"A :";for(auto&K:A) cout<<K<<"!";cout<<endl;
                cout<<"tm:";for(auto&K:tmp) cout<<K<<"!";cout<<endl;*/
                a[i]+=AA[2]*p3[l];
            }
        }
        vector<int> nans(p3[l+1]);
        array<int,3> iv={};
        fr(I,3) iv[nv[I]]=I;
        fr(i,p3[l]){
            nans[i]=iv[e[i][0]]*p3[l]+ans[i];
            nans[i+p3[l]]=iv[e[i][1]]*p3[l]+ans[i];
            nans[i+2*p3[l]]=iv[e[i][2]]*p3[l]+ans[i];
        }
        ans.swap(nans);
        //for(auto&K:a) cout<<K<<" ";cout<<endl;
    }
    for(auto&i:ans) cout<<i<<" ";
    cout<<'\n';
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    double average = (double)accumulate(a.begin(), a.end(), 0)/n;
    int ans = 0;
    double minv=100100100;
    rep(i, n) {
        if (abs(average-(double)a[i])< minv) {
            ans = i;
            minv = abs(average-(double)a[i]);
        }
    }
    cout << ans << endl;
    //cout << a[ans] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define inf (int)1e9

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n;
		cin >> n;
		ll arr[n];
		for (ll i = 0; i < n; i++) cin >> arr[i];
		ll dp[n];
		dp[0] = {0};
		dp[1] = abs(arr[1] - arr[0]);
		for (ll i = 2; i < n; i++)
		{
			dp[i] = min(abs(arr[i] - arr[i - 1]) + dp[i - 1], abs(arr[i] - arr[i - 2]) + dp[i - 2]);
		}
		cout << dp[n - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = -10**9
for i in range(n):
    scores = [0]
    seen = set([i])
    now = i
    loop = False
    for _ in range(k):
        now = p[now]-1
        scores.append(c[now])
        if now in seen:
            loop = True
            break
        seen.add(now)
    for i in range(len(scores)-1):
        scores[i+1] += scores[i]
    tmp = max(scores[1:])
    ans = max(ans, tmp)
    if (not loop) or scores[-1]<=0:
        continue
    tmp = scores[-1]*(k//(len(scores)-1))
    rem = k%(len(scores)-1)
    tmp += max(scores[:rem+1])
    ans = max(ans, tmp)
    tmp = scores[-1]*(k//(len(scores)-1)-1)
    tmp += max(scores)
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 168748
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.size()<=k)cout << s << endl;
    else {
        rep(i,k)cout << s[i];
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
constexpr i64 MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    int D;
    cin >> D;
    vector<vvi> dp(s.size() + 1, vvi(2, vi(D)));
    dp[0][0][0] = 1;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < D; k++) {
                for (int d = 0; d <= (j ? 9 : s[i] - '0'); d++) {
                    dp[i + 1][j | (d < s[i] - '0')][(k + d) % D] += dp[i][j][k];
                    dp[i + 1][j | (d < s[i] - '0')][(k + d) % D] %= MOD;
                }
            }
        }
    }
    cout << (dp[s.size()][0][0] + dp[s.size()][1][0] - 1 + MOD) % MOD << endl;
}


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


using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int d;
  cin >> d;
  vector<int> c(26);
  rep(i,26)cin >> c[i];
  rep(i,d){
    int p = 0,v = 0;
    rep(j,26){
      int x;cin >> x;
      if(v < x)p = j+1;
    }
    cout << p << endl;
  }
  
  


  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define INF (1e18)
const ll max_N = 100000;
ll fac[max_N + 10], facinv[max_N + 10];

ll power(ll x, ll n){ // xのn乗 % MOD
    if(n == 0) return 1LL;
    ll res = power(x * x % MOD, n/2);
    if(n % 2 == 1) res = res * x % MOD;
    return res;
}

ll nck(ll n, ll k){
    if(k == 0 || n == k) return 1;
    return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD;
}

ll npk(ll n, ll k){
    if(k == 0 || n == k) return 1;
    return fac[n] * facinv[n-k] % MOD;
}

void comb_setup(){
    fac[0] = 1; fac[1] = 1;
    rep(i,2,max_N+1) fac[i] = (fac[i-1] * i) % MOD;
    rep(i,0,max_N+1) facinv[i] = power(fac[i], MOD - 2);
}

int main(){   
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[100010];
    rep(i,0,N) cin >> A[i];
    ll ans = 0;
    comb_setup();
    ll sum[100010] = {};
    sum[0] = 1;
    sum[1] = 1;
    rep(i,2,N+1){
        sum[i] = ((sum[i-1] * i + 1) % MOD) * power(i, MOD-2) % MOD;
    }
    rep(i,0,N){
        ans += ((fac[N] * A[i]) % MOD) * (sum[N-i] + sum[i+1] - 1) % MOD;
        ans %= MOD;
    }
    print(ans);



}


Measured memory_bytes: 3328
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

int count(int n) {
	if(n < 10) return 0;
	auto s = n.to!string;
	return 1 + count(reduce!(max)(0, iota(1, s.length).map!(i => s[0..i].to!int * s[i..$].to!int)));
}

void main(){
	auto q = readInt();
	for(int i; i < q; ++i) {
		writeln(count(readInt()));
	}
}

Measured memory_bytes: 2536
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-26 14:13:52
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

template <class T>
class CumulativeSum {
 public:
  CumulativeSum(const std::vector<T>& vec) : vec_(vec) { Build(); }

  // return sum of [left, right]
  T Get(int left, int right) {
    return sum_[right + 1] - sum_[left];    
  }

 private:
  std::vector<T> vec_;
  std::vector<T> sum_;

  void Build() {
    sum_.assign(vec_.size() + 1, static_cast<T>(0));
    for (size_t i = 0; i < vec_.size(); ++i) {
      sum_[i + 1] = sum_[i] + vec_[i];
    }
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  string s; cin >> s;

  vector<int> cntW(n + 1, 0), cntB(n + 1, 0);

  for (int i = 0; i < n; ++i) {
    cntW[i + 1] += s[i] == '.';
    cntB[i + 1] += s[i] == '#';
  }

  CumulativeSum<int> csW(cntW);
  CumulativeSum<int> csB(cntB);

  int ans = min(csW.Get(1, n), csB.Get(1, n));

  for (int i = 0; i < n; ++i) {
    ans = min(ans, csB.Get(1, i + 1) + csW.Get(i + 2, n));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5268
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
 
typedef long long ll;
const int mod = 1e9 + 7;
typedef pair<ll, ll> P;
 
ll N, D, A;
vector<ll> X, H;
 
int main() {
    cin >> N >> D >> A;
    X.resize(N);
    H.resize(N);
    rep(i, N) cin >> X[i] >> H[i];

    queue<P> q;
    vector<P> p;
    ll given = 0;
    rep(i, N) {
        p.push_back(P(X[i], H[i]));
    }

    sort(p.begin(), p.end());
    ll ans = 0;
    D = D * 2;
    rep(i, N) {
        ll x = p[i].first;
        ll h = p[i].second;

        // printf("i: %d h: %lld x: %lld\n", i, h, x);
        // 以前の爆弾で受けたダメージ
        while (q.size() && q.front().first < x) {
            given -= q.front().second;
            q.pop();
        }
        h -= given;

        // 該当の座標に来た時
        if (h > 0) {
            // 切り上げ
            ll num = ceil((double)h / A);
            ans += num;
            ll damage = num * A;
            given += damage;
            q.push(P(x + D, damage));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 9200
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int mod7=1e9+7;
const int mod=1e9+7;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int a[N];
bool cmp(int x,int y) {return x>y;}
int main()
{
    int n,m;
    read(n),read(m);
    int sum=0;
    for(re int i=1;i<=n;i++) read(a[i]),sum+=a[i]; 
    sort(a+1,a+1+n,cmp);
    for(re int i=1;i<=m;i++) if(a[i]*4*m<sum) return puts("No"),0;
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	static int[]heap;
    static int MAXHEAP=2000000;
    static int n=0;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
	    int i;
	    String hz;
		heap=new int[MAXHEAP+1];
       Scanner sca= new Scanner(System.in);
       while(true){
	   hz=sca.next();
	   if(hz.equals("insert")){
	    maxHeapInsert(sca.nextInt());
	   }else if(hz.equals("extract")){
	       System.out.println(extract());
	   }else if(hz.equals("end")){
	    break;
	   }
       }
	}
	public static void maxHeapify(int i){
		int l,r,largest,hz;
		l=i*2;
		r=i*2+1;
		if(l<=n&&heap[l]>heap[i]){
			largest=l;
		}else{
			largest=i;
		}
		if(r<=n&&heap[r]>heap[largest])largest=r;
		if(largest!=i){
			hz=heap[largest];
			heap[largest]=heap[i];
			heap[i]=hz;
			maxHeapify(largest);
		}
	}
    public static void maxHeapInsert(int key){
	n++;
	heap[n]=Integer.MIN_VALUE;
	heapIncreaseKey(n,key);
    }
    public static void heapIncreaseKey(int i,int key){
	int hz;
       	if (key<heap[i])return;
	heap[i]=key;
	while(i>1&&heap[i/2]<heap[i]){
	    hz=heap[i/2];
	    heap[i/2]=heap[i];
	    heap[i]=hz;
	    i/=2;
	}
    }
    public static int extract(){
	int i,max;
	if(n<1)return Integer.MIN_VALUE;
	max=heap[1];
	heap[1]=heap[n];
	n--;
	maxHeapify(1);
	return max;
    }

}



Measured memory_bytes: 555692
n,k=map(int, input().split())
p=list(map(int, input().split()))
numset=[]
sexp=[]
tmp=0
ans=0
for i in range(max(p)+1):
  tmp=tmp+i
  numset.append(tmp)
exp=[]
for i in p:
  exp.append(numset[i]/i)
sexp.append(0)
s=0
for i in exp:
  s=s+i
  sexp.append(s)
for i in range(n-k+1):
  ans=max(ans, sexp[k+i]-sexp[i])
print(ans)

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

#define ll long long int
#define ff first
#define ss second
#define int long long int
#define pb push_back

#define N 100010
#define MOD 1000000007

int isprime(int n)
{
	for(int i = 2; i <= sqrt(n); ++i)
		if(n % i == 0)
			return 0;
	return 1;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

	string s, t;
  cin >> s >> t;;
  cout << t << s;
 	return 0;
}


Measured memory_bytes: 384
a=int(input())
i=1
li=[a]
import copy
while True:
    if li[i-1]%2==0:
        b=li[i-1]//2
    else:
        b=3*li[i-1]+1
    if b in li:
        print(i+1)
        exit()
    li.append(b)
    i+=1
        


Measured memory_bytes: 9272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1'010'000'000'000'000'017LL
#define mod 1000000007LL
#define eps 0.0001
#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define SZ(x) ((ll)(x).size())
#define sum(x) accumulate(ALL(x), 0LL)//?
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; }
ll N, A, B, C;
vector<ll> h;
bool D(ll x){
        ll ans = x;
        rep(i, N){
            ll r = h.at(i)-B*x;
            if (r > 0) ans-=r/C + (r%C != 0);
        }
        if(ans>=0) return true;
        else return false;
    }
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> A >> B;
    C = A-B;
    h.resize(N);
    rep(i, N){
        cin >> h.at(i);
    }
    ll ok = 1000000001, ng = 0;
    ll mid;
    while (ok-ng>1){
        mid = (ok+ng)/2;
        if(D(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

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

using namespace std;

int main(){
  string s;
  cin >> s;

  for (int i=0; i<s.size(); i++){
    if( s.at(i) == '9') s.at(i) = '1';
    else if( s.at(i) == '1') s.at(i) = '9';
  }
    cout << s << endl;
    
  

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  int a[ 4 ], b[ 4 ];
  int i;

  while (
    scanf ( "%d%d%d%d%d%d%d%d",
      a, a + 1, a + 2, a + 3,
      b, b + 1, b + 2, b + 3 ) == 8 )
  {
    int hash[ 10 ] = { 0 };
    int res;

    res = 0;
    for ( i = 0; i < 4; ++i )
    {
      hash[ a[ i ] ] = 1;
      res += !! ( a[ i ] == b [ i ] );
    }
    printf ( "%d ", res );

    res = -res;
    for ( i = 0; i < 4; ++i )
    {
      res += hash[ b[ i ] ];
    }
    printf ( "%d\n", res );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

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

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

//
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;
}
//

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

  int n;
  cin >> n;
  vector<pair<lint, lint>> ab(n);
  rep(i, n) {
    lint a, b;
    cin >> a >> b;
    ab[i].first = b;
    ab[i].second = a;
  }
  sort(all(ab));
  lint time = 0;
  rep(i, n) {
    if (time + ab[i].second > ab[i].first) {
      cout << "No" << endl;
      return 0;
    }
    time = time + ab[i].second;
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 3456
//g++ -std=c++11 -Wall test.cpp -o test -lm -g -O2
#include <bits/stdc++.h>
using namespace std;
#define sws                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define qi queue<int>
#define si stack<int>
#define s string
#define ll long long;

int main()
{sws;
    int age;
    cin >> age;
    if (age == 3 or age == 5 or age == 7)
        cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }

    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

int main(){
  ll n; cin >> n;
  cout << n*(n+1)/2 << endl;
}



Measured memory_bytes: 256
n=int(input())
an=list(map(int,input().split()[:n]))
bn=list(map(int,input().split()[:n]))
cn=list(map(int,input().split()[:n-1]))

ret=sum(bn)

for i in range(n-1):
    if an[i] +1 ==an[i+1]:
        ret+=cn[an[i]-1]

print(ret)

Measured memory_bytes: 3064
N, M, Q = map(int, input().split())
L, R = [], []
for _ in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

p, q = [], []
for _ in range(Q):
    tmp = list(map(int, input().split()))
    p.append(tmp[0])
    q.append(tmp[1])

cum_sum = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
    cum_sum[L[i]][R[i]] += 1

for i in range(1, N+1):
    for j in range(1, N+1):
        cum_sum[i][j] += cum_sum[i][j-1]
        cum_sum[i][j] += cum_sum[i-1][j]
        cum_sum[i][j] -= cum_sum[i-1][j-1]

def get_sum_range(L, R):
    ans = cum_sum[R][R] - cum_sum[R][L-1] - cum_sum[L-1][R] + cum_sum[L-1][L-1]
    return ans

for i in range(Q):
    ans = get_sum_range(p[i], q[i])
    print(ans)

Measured memory_bytes: 27800
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ cin >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

inline void init(vector<int>& uf) {
    iota(all(uf), 0);
}

int root(vector<int>& uf, int x) {
    if (uf[x] == x) {
        return x;
    } else {
        return uf[x] = root(uf, uf[x]);
    }
}
bool same(vector<int>& uf, int x, int y) {
    return root(uf, x) == root(uf, y);
}
void unite(vector<int>& uf, int x, int y)
{
    x = root(uf, x);
    y = root(uf, y);
    if (x == y) return;
    uf[x] = y;
}


int main()
{
    int H, W; cin >>H>>W;
    vs grid(H); cin >> grid;

    vector<int> uf(H*W);
    init(uf);

    rep(i, H) {
        rep(j, W) {
            if (j != W-1) {
                if (grid[i][j] != grid[i][j+1])
                    unite(uf, W*i+j, W*i+j+1);
            }
            if (i != H-1) {
                if (grid[i][j] != grid[i+1][j])
                    unite(uf, W*i+j, W*(i+1)+j);
            }
        }
    }

    unordered_map<int, pii> m;
    rep(i, H) {
        rep(j, W) {
            int r = root(uf, W*i+j);
            pii& p = m[r];
            p.first++;
            if (grid[i][j]=='#')
                p.second++;
        }
    }

    ll ans = 0;

    for (auto i = m.begin(); i != m.end(); i++) {
        pii& p = i->second; 
        int s = p.first;
        int b = p.second;
        ans += (ll)(s-b) * b;
    }

    cout << ans << endl;
}


Measured memory_bytes: 7844
#include <cmath>
#include <iostream>
using namespace std;

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

  uint64_t sIdx = 1;
  for (int i = sqrt(n); i >= 1; i--)
  {
    if (n % i == 0)
    {
      sIdx = i;
      break;
    }
  }

  uint64_t a = n / sIdx;
  uint64_t b = n / a;

  cout << a + b - 2 << endl;

  return 0;
}

Measured memory_bytes: 3692
#%%
a = input()
b = input()

#%%
N =  int(a.split()[0])
K = int(a.split()[1])
h = [int(x) for x in b.split()]

available_num = 0
for hight in h:
    if hight >= K:
        available_num += 1

print(available_num)
#%%


Measured memory_bytes: 12288
//インクルード
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

//型宣言
typedef long long ll;
typedef unsigned long long ull;
typedef std::string string;
typedef string answerType;

//変数宣言
ull A;
ull B;
ull C;
answerType answer;

//関数のプロトタイプ宣言
//入力の取得
void getInput();
//答えを求める
answerType calcAnswer();

//メイン関数
int main() {
	//入力の取得
	getInput();

	//答え
	answerType answer = calcAnswer();

	//答えの出力
	std::cout << answer << std::endl;

	//正常終了
	return EXIT_SUCCESS;
}

//入力の取得
void getInput() {
	std::cin >> A >> B >> C;
}

//答えを求める
answerType calcAnswer() {
	if(A + B >= C) {
		return "Yes";
	}
	return "No";
}


Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),k=sc.nextInt();
        long ans = k;
        for(int i = 1;i<n;i++){
            ans *= k-1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int R;
    cin >> R;
    if (R < 1200)
        cout << "ABC" << endl;
    else if (R < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
    return 0;
}



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

int main() {
	int n;
	cin >> n;
	int* R = new int[n];
	for (int i = 0; i < n; i++)
		cin >> R[i];
	int maxProfit(int*, int);
	cout << maxProfit(R, n) << endl;
	return 0;
}

//时间复杂度：O(n)
int maxProfit(int* R, int n) {
	int min, max, p, r;
	min = R[0];
	max = R[1] - R[0];
	for (int i = 1; i < n; i++) {
		if (max < R[i] - min)
			max = R[i] - min;
		if (min > R[i])
			min = R[i];
	}
	return max;
}


Measured memory_bytes: 3880
#include<cstdio>
using ll = long long;
using ull = unsigned long long;
const static int MAX_D = 365;
int c[26], s[MAX_D][26], S, last[26];

int main(){
    int D;
    scanf("%d", &D);
    for (int i = 0; i < 26; i++){
        scanf("%d", c + i);
    }
    for (int i = 0; i < D; i++){
        for (int j = 0; j < 26; j++){
            scanf("%d", &s[i][j]);
        }
    }
    for (int i = 1; i <= D; i++){
        int t;
        scanf("%d", &t);
        t--;
        last[t] = i;
        S += s[i-1][t];
        for (int j = 0; j < 26; j++){
            S -= c[j]*(i - last[j]);
        }
        printf("%d\n", S);
    }
	return 0;
}

Measured memory_bytes: 1720
#include <iostream>
#include <vector>
#include <string>



using namespace std;

int H, W, K;

vector<vector<bool>>maze;

int main()
{
	cin >> H;
	cin >> W;
	cin >> K;



	maze = vector<vector<bool>>(H, vector<bool>(W, false));



	for (int i = 0;i<H;i++) {
		string s;
		cin >> s;
		for (int j = 0;j<W;j++) {
			if (s[j] == '#') {
				maze[i][j]=true;
			}
		}
	}

	

	int ans = 0;
	int loop = 1 << H << W;

	for (int k = 0; k < loop; k++) {
		int s = 0;


		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (
					maze[i][j]
					&& !(k & (1 << i << W))
					&& !(k & (1 << j))) {
					s++;

				}
			}
		}

		if (s==K) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3132
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
const int MAXN = 2e5 + 5;
int a[MAXN],b[MAXN];
map<long long,int>vis;
int main()
{
	int n;
	scanf("%d",&n);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		vis[a[i]]++;
	}
	int t = 1;
	sort(a+1,a+n+1);
	b[1] = a[1];
	for(int i = 1; i < n; i++){
		if(a[i] != a[i+1]) b[++t] = a[i+1];
	}
	for(int i = 1; i <= t; i++){
		if(vis[b[i]] % 2 == 1){
			ans++;
		}

	}
	printf("%d\n",ans);
}

Measured memory_bytes: 7296
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

//#include "set/union_find.h"

struct ufs {
	int n;
	vector<int> f, c;

	ufs(int n=0) {
		resize(n);
	}

	void resize(int sz) {
		n = sz;
		f.resize(n);
		c.resize(n);
		for (int i=0; i<n; i++)
			f[i] = i, c[i] = 1;
	}

	int find(int v) {
		int r, u;
		for(r=v; f[r]!=r; r=f[r]);
		for(u=v; u!=r; ) {
			int t = f[u];
			f[u] = r;
			u = t;
		}
		return r;
	}

	int merge(int a, int b) {
		a = find(a);
		b = find(b);
		if (a!=b) {
			f[a] = b;
			c[b] += c[a];
		}
		return b;
	}

	int count(int v){
		return c[find(v)];
	}
};


#define MAXN 100000

int n, m;
int a[MAXN];

int input() {
	if (scanf("%d %d", &n, &m) < 0) return 0;
	for (int i=0; i<n; i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	return 1;
}

void init() {
}

long solve() {
	ufs u(n);
	for (int i=0; i<m; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		x--, y--;
		u.merge(x, y);
	}
	int r = 0;
	for (int i=0; i<n; i++)
		if (u.find(i) == u.find(a[i])) r++;
	return r;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 1408
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
 
        int n = stdIn.nextInt();
        int k = stdIn.nextInt();
        int[] w = new int[n];
        long max = 0;
        long acc = 0;
 
        for (int i=0; i<n; i++) {
            w[i] = stdIn.nextInt();
            acc += w[i];
            max = Math.max(max,w[i]);
        }
 
        long left = max;
        long right = acc;
 
        while (left < right) {
            long p = (left+right)/2;
            int id = 0;
            long sum = 0;
            for (int i=0; i<n; i++) {
                if (sum+w[i] > p) {
                    sum = w[i];
                    id++;
                }else {
                    sum += w[i];
                }
                if (id == k)
                    break;
            }
            if (id == k)
                left = p+1;
            else
                right = p;
        }
        System.out.println(left);
 
        stdIn.close();
    }
}



Measured memory_bytes: 70568
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

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

    double x = min(b-1, n);
    double temp0 = (x / b) * a;
    int c = temp0;
    double temp1 = x/b;
    int temp2 = temp1;
    int d = a * temp2;
    print (c-d);

    return 0;
}


Measured memory_bytes: 3616
import java.util.*;
  
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int a[] = new int[M];
		int b[] = new int[M];
		int c[] = new int[N];
  
		for(int i=0; i<M; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}

		for(int i=1; i<=N; i++){
			for(int j=0; j<M; j++){
			if(a[j]==i||b[j]==i)
			c[i-1]++;
			}
		}

		for(int y :c)
		System.out.println(y);
		
		
	}
}





Measured memory_bytes: 21844
using System;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            long count = 0;
            for(int i=0; i<s.Length;i++)
            {
                if(s.Substring(i,1)!=t.Substring(i,1))
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 36768
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int main() {
	int N;
	cin>>N;
	vector<double> x(N);
	vector<string> u(N);
	rep(i,N)cin>>x[i]>>u[i];
	double ans;
	rep(i,N){
		if(u[i]=="JPY")ans+=x[i];
		else ans+=x[i]*380000;
	}
	cout<<ans<<endl;
}

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

const int maxn=2e5+10;

int n;
int a[maxn];
int ma,ma2;

int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]>ma){
			ma2=ma;
			ma=a[i];
		}
		else
			if(a[i]>ma2)
				ma2=a[i];
	}
	for(register int i=1;i<=n;i++)
		if(a[i]==ma)
			printf("%d\n",ma2);
		else
			printf("%d\n",ma);
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> road(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        road[a]++;
        road[b]++;
    }
    int ans=0;
    for(int i=0;i<n;i++){
        cout << road[i] << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        Set<Integer> moti = new HashSet<>();
        for (int i = 0; i < n; i++) {
            int d = sc.nextInt();
            if(!moti.contains(d)){
                moti.add(d);
            }
        }

        System.out.println(moti.size());   
    }
}

Measured memory_bytes: 22612