akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

/////////////         modの計算

int mod = 1000000007;

long long mod_adjust(long long a) {//	余りをとる(0～mod-1に調整する)
	if (a >= mod) {
		return a % mod;
	}
	if (a < 0) {
		a *= -1;
		a %= mod;
		return mod - a;
	}
	return a;
}
int mod_add(int a, int b) {//	足し算
	long long k = mod_adjust((long long)a); k += mod_adjust((long long)b);
	k = mod_adjust(k);
	return (int)k;
}
int mod_sub(int a, int b) {//	引き算
	return mod_add(a, -b);
}
int mod_multi(int a, int b) {//	掛け算
	long long k = mod_adjust((long long)a);
	k *= mod_adjust((long long)b);
	k = mod_adjust(k);
	return (int)k;
}
int mod_inv(int a) {//	逆元
	long k = (int)mod_adjust((long long)a);
	if (k == 0) { return 0; }
	if (k == 1) { return 1; }
	long long p = mod, q = k, m = 0, n = 1, r, c;

	while (q > 1) {
		r = p % q;
		c = p / q;
		c = mod_adjust(m - n * c);
		p = q, m = n, q = r, n = c;
	}
	return (int)mod_adjust(n);
}
int mod_div(int a, int b) {//	割り算
	return mod_multi(a, mod_inv(b));
}

int main() {
	int p; cin >> p;
	mod = p;
	int* b = new int[p];
	for (int i = 0; i < p; i++) {
		b[i] = 0;
	}
	for (int i = 0; i < p; i++) {
		int a; cin >> a;
		if (a == 1) {
			int j = 1;
			for (int k = 0; k < p; k++) {
				b[k] = mod_add(b[k], j);
				j = mod_multi(j, i);
				if (k == p - 1) {
					b[k] = mod_sub(b[k], 1);
				}
			}
		}
	}
	for (int i = p-1; i >= 0; i--) {
		cout << (p - b[i])%p << " ";
	}

	return 0;
}


Measured memory_bytes: 384
arr = []
range = 0..3

for i in range
  arr[i] = 0
end

while line = gets
  a, b = line.chomp.split(",")
  case b
  when "A"
    arr[0] += 1
  when "B"
    arr[1] += 1
  when "AB"
    arr[2] += 1
  when "O"
    arr[3] += 1
  end
end

for i in range
  puts arr[i]
end

Measured memory_bytes: 6112
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< int, int > Pi;
typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const double DINF = 5e14, eps = 1e-10;
const long long MOD = 1e9 + 7, INF = 5e18;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

int n, ret;
double t, a, h, ans = DINF;

int main() {
	cin >> n >> t >> a;
	for (int i = 0;i < n;i++) {
		cin >> h;
		if (ans > abs(a - (t - h * 0.006))) {
			ans = abs(a - (t - h * 0.006));
			ret = i + 1;
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

int m,n;
int p[11111],c[555],e[555];
int sum[11111];
pair<int,int> ce[555];

int main(void)
{
  scanf("%d%d",&m,&n);
  for( int i = 0; i < m; i++ ) scanf("%d",p+i);
  sort(p,p+m,greater<int>());
  for( int i = 0; i < m; i++ ) {
    sum[i+1] = sum[i]+p[i];
  }
  for( int i = 0; i < n; i++ ) {
    scanf("%d%d",c+i,e+i);
  }
  int dp[11111];
  for( int i = 0; i <= m; i++ ) dp[i] = 0;
  for( int i = 0; i < n; i++ ) {
    for( int j = m-1; j >= 0; j-- ) {
      dp[min(m,j+c[i])] = max(dp[min(m,j+c[i])],dp[j]+sum[min(m,j+c[i])]-sum[j]-e[i]);
    }
  }
  printf("%d\n",*max_element(dp,dp+m+1));
  return 0;
}

Measured memory_bytes: 1176
#include<stdio.h>
 
int main(void)
{
   int n, m, a[10000], s=0, i;
 
   scanf("%d%d",&n,&m);
   for(i=0;i<m;i++){
      scanf("%d",&a[i]);
      s=s+a[i];
   }
 
   if(n<s) printf("-1\n");
   else printf("%d\n",(n-s));
   return 0;
}

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

using namespace std;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front


typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;


const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

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



int main(){
  string a,b,c;
  cin>>a>>b>>c;
  
  cout<<'A'<<b[0]<<'C'<<endl;
  

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int n; ll d;
  cin >> n >> d;
  int cnt = 0;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    double now = sqrt(x*x + y*y);
    if (now <= d) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
vector<int>g[maxn];
int c[maxn];
vector<int>v[2];
int ans[maxn];
void dfs(int now,int x){
    //cout << now <<' '<<x<<endl;
    c[now] = x;
    int ret = 0;
    v[x].pb(now);
    for(auto i:g[now]){
        if(~c[i])continue;
        dfs(i,x^1);
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    while(cin >> n){
        ms1(c);
        int a = n/3 + (n % 3 >= 1);
        int b = n/3 + (n % 3 >= 2);
        int c = n/3;
        f(n-1){
            int add1, add2;
            cin >> add1 >> add2;
            g[add1].pb(add2);
            g[add2].pb(add1);
        }
        dfs(1,0);
        if(v[0].size() < v[1].size()) {
            swap(v[0],v[1]);
        }
        //cout << v[0].size() <<' '<<v[1].size() <<' '<<a<<' '<<b<<endl;
        if (v[0].size() >= a + b) {
            //cout << "here1"<<endl;;
            for (int i = 0 ; i < a ; i++) {
                ans[v[0][i]] = i * 3 + 1;
            }
            for (int i = 0 ; i < b ; i++) {
                ans[v[0][a+i]] = i * 3 + 2;
            }
            int ptr = 3;
            for (int i = 1 ; i <= n ; i++) {
                if (ans[i])continue;
                ans[i] = ptr;
                ptr += 3;
            }
        }
        else {
            //cout << "HERE20"<<endl;
            for (int i = 0 ; i < a ; i++) {
                ans[v[0][i]] = i * 3 + 1;
            }
            for (int i = 0 ; i < b ; i++) {
                ans[v[1][i]] = i * 3 + 2;
            }
            int ptr = 3;
            for (int i = 1 ; i <= n ; i++) {
                if (ans[i])continue;
                ans[i] = ptr;
                ptr += 3;
            }
        }
        f1(n) {
            cout << ans[i] <<' ';
        }
        cout << '\n';
    }
}

Measured memory_bytes: 22772
import java.util.*;

public class Main {
    static long n;
    static long x;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        x = sc.nextLong();
        long ret = solve(n, x);
        System.out.println(ret);
    }


    static long solve(long n, long x) {
        if (n == 3 * x) {
            return n;
        }
        if(2*x > n) {
            x = n - x;
        }
        long y = n - x;
        long tmp = (y / x) * 3 * x;
        long tmp1 = (y % x != 0) ? solve(x + y % x, x) : 0;
        return tmp + tmp1;
    }
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if(a >= -1000 && a <= 1000 && b >= -1000 && b <= 1000){
		if (a > b) {
			cout << "a > b" << endl;
		}
		else if (a < b) {
			cout << "a < b" << endl;
		}
		else {
			cout << "a == b" << endl;
		}
	}
	else {
		cout << "error" << endl;
	}
}


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

int main() {
  int N,M;
  cin>>N>>M;
  vector<vector<long>> a(N,vector<long>(3));
  for(int i=0;i<N;i++) for(int j=0;j<3;j++){
    cin>>a[i][j];
}
  long ans=0;
  for(int bit=0;bit<(1<<3);bit++){
    vector<long> b;
    for(int i=0;i<N;i++){
      long tmp=0;
      for(int j=0;j<3;j++){
        if(bit&(1<<j)) tmp+=a[i][j];
        else tmp -= a[i][j];
      }
      b.push_back(tmp);
    }
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    long sum=0;
    for(int i=0;i<M;i++) sum+=b[i];
    ans =max(ans,sum);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

LL MOD = 1000000007;


int main() {
	int n, k;
	cin >> n >> k;
	if (k == 1)printf("0\n");
	else printf("%d\n", n-k);
	return 0;
}

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

int main(){
  int N;
  int numR=0,numG=0,numB=0;
  string S;
  uint64_t ans=0;
  cin >> N;
  cin >> S;
  for(int i=0; i<N; i++){
    if(S[i]=='R') numR++;
    if(S[i]=='G') numG++;
    if(S[i]=='B') numB++;
  }
  ans = numR * numG;
  ans *= numB;
  for(int i=0; i<N; i++){
    for(int j=1; i+j+j<N; j++){
      if(S[i]!=S[i+j] && S[i+j]!=S[i+j+j] && S[i+j+j]!=S[i]) ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
N, T = gets.split.map(&:to_i)
c, t = N.times.map{gets.split.map(&:to_i)}.transpose
INF = 9999999999
cost = INF
for i in 0..(N-1)
  if t[i] <= T
    cost = c[i] if cost > c[i]
  end
end
if cost == INF
  puts "TLE"
else
  puts cost
end

Measured memory_bytes: 1788
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int arr[101][101] = {0};

int main()
{
	for(int i=0; i<3; i++)
	{
		for(int j=0; j<3; j++)
		{
			cin >> arr[i][j];
		}
	}
	int a;
	cin >> a;
	for(int n=0; n<a; n++)
	{
		int o;
		cin >> o;
		for(int i=0; i<3; i++)
		{
			for(int j=0; j<3; j++)
			{
				if(o == arr[i][j])
				{
					arr[i][j] = 0;
				}
			}
		}
	}
	if(arr[0][0]==0 && arr[0][1]==0 && arr[0][2]==0)
	{
		cout << "Yes";
	}
	else if(arr[1][0]==0 && arr[1][1]==0 && arr[1][2]==0)
	{
		cout << "Yes";
	}
	else if(arr[2][0]==0 && arr[2][1]==0 && arr[2][2]==0)
	{
		cout << "Yes";
	}
	else if(arr[0][0]==0 && arr[1][0]==0 && arr[2][0]==0)
	{
		cout << "Yes";
	}
	else if(arr[0][1]==0 && arr[1][1]==0 && arr[2][1]==0)
	{
		cout << "Yes";
	}
	else if(arr[0][2]==0 && arr[1][2]==0 && arr[2][2]==0)
	{
		cout << "Yes";
	}
	else if(arr[0][0]==0 && arr[1][1]==0 && arr[2][2]==0)
	{
		cout << "Yes";
	}
	else if(arr[0][2]==0 && arr[1][1]==0 && arr[2][0]==0)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    rp(i, 0, n)
    {
        if ((i + 1) % 3 != 0 && (i + 1) % 5 != 0)
        {
            ans += i + 1;
        }
    }
    ce(ans);
}

Measured memory_bytes: 3624
import sys
def main():
    s=list(sys.stdin.readline().strip())
    t=list(sys.stdin.readline().strip())
    S,T=len(s),len(t)
    dp=[[0 for _ in range(T+1)] for _ in range(S+1)]
    for i in range(S):
        for j in range(T):
            if s[i]==t[j]:dp[i+1][j+1]=dp[i][j]+1
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j],dp[i][j+1])
    res=''
    i,j=S,T
    while i>0 and j>0:
        if dp[i][j]==dp[i-1][j]:i-=1
        elif dp[i][j]==dp[i][j-1]:j-=1
        else:
            res=s[i-1]+res
            i,j=i-1,j-1
    print(res)
if __name__=='__main__':main()

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

using namespace std;
 
int main(){
    unordered_map<long long, int> count;
	int n; cin >> n;
	++count[0];
	long long result{}, current{};
	for(int i = 0 ; i < n ; i++){
		int x; cin >> x;
		current += x;
		result += count[current];
		++count[current];
	}
	cout << result << endl;
}


Measured memory_bytes: 8520
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int a[maxn];
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	a[1]=1;a[3]=1;a[5]=1;a[7]=1;a[8]=1;a[10]=1;a[12]=1;
	a[4]=2;a[6]=2;a[9]=2;a[11]=2;
	a[2]=3;
	int x,y;
	cin>>x>>y;
	if(a[x]==a[y])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,w;
    cin>>n>>w;
    long long int dp[w+1];
    int tempw,tempv;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        cin>>tempw>>tempv;
      	for(int j=w;j>=tempw;j--){
          dp[j]=max(dp[j],dp[j-tempw]+tempv);
        }
    }
    cout<<dp[w]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
struct UnionFind {
  vector<int> parent,s;
  UnionFind(int n): parent(n), s(n){
    rep(i,n) {
      parent[i] = i;
      s[i] = 1;
    }
  }
  int root(int x) { return parent[x]==x ? x : parent[x] = root(parent[x]); }
  bool same(int x, int y) { return root(x)==root(y); }
  int size(int x){ return s[root(x)]; }
  void unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return;
    if (s[x] < s[y]) {
      parent[x] = y;
      s[y] += s[x];
    } else {
      parent[y] = x;
      s[x] += s[y];
    }   
  }
};

const ll inf = 1e18L;
int main() {
  int n,k;
  cin >> n >> k;
  vector<int> p(n),c(n);
  rep(i,n) cin >> p[i], --p[i];
  rep(i,n) cin >> c[i];

  UnionFind u(n);
  rep(i,n) u.unite(i,p[i]);
  vector<ll> s(n);
  rep(i,n) s[u.root(i)] += c[i];
  rep(i,n) s[i] = s[u.root(i)];

  ll ans = -inf;
  rep(i,n){
    ll res = -inf, t = 0;
    int m = k/u.size(i);
    if(m>=2 && s[i]>0) t += s[i]*(m-1);
    int v=i;
    m = min(k,k%u.size(i)+u.size(i));
    rep(_,m){
      t += c[v=p[v]];
      res = max(res,t);
    }
    ans = max({ans,res,t});
  }
  cout << ans << endl;
}

Measured memory_bytes: 3704
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7; 
const int N=1e2 + 5,M=1e5 + 5;
ll arr[N];
ll pre[N];
ll dp[N][M];
ll OO=1e13; 
 
ll n,m,k,cnt,SU,idx,len,MN,MX;
ll l,r,mid;
ll a,b,c,d,s;
vector<ll> vec;
 
ll Solve(int idx,int rem){
	
	if(idx == n)
		return (rem < 0) ? -OO : 0;
	if(rem < 0)
		return -OO;
		
		
	ll &ret=dp[idx][rem];
	
	if(~ret)
		return ret;
	
	
	return ret = max(Solve(idx+1,rem) , pre[idx] + Solve(idx+1,rem-arr[idx]));

}

 
 
 
int main(){

	memset(dp,-1,sizeof dp);
	
	cin>>n>>m;
	for(int i=0;i<n;++i)
		cin>>arr[i]>>pre[i];
	
	
	
	cout<<Solve(0,m)<<endl;

	
		
}
 
 


Measured memory_bytes: 82304
/*
    TOP GUN: MAVERICK!!
                                */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7.;   
lli INF=1e17;
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,q,z,y,k,m;
const double pi1=3.14159265358979323846;
//unordered_map<pair<ll,lli>,lli> mp;
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
//lli tot=0;
vector<lli> pf(string s) {
    int n = (int)s.length();
    vector<lli> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}

int main()
{
    ios_base::sync_with_stdio(0);
    //cin.tie(0);
    string s;
    cin>>s;
    n=s.length();
    set<lli> l,r;
    for(int i=0;i<n;i++)
    {
    	if(s[i]=='L')
    	l.insert(i);
    	else
    	r.insert(n-i-1);
    }
    set<lli> laux,raux;
    laux=l;
    raux=r;
    map<lli,lli> ans;
    for(int i=0;i<n;i++)
    {
    	
    	if(s[i]=='L')
    	{
    		laux.erase(i);
    	}
    	else
    	{
    	     if(laux.lower_bound(i)!=laux.end())
    	     {
    	     	lli dd=*laux.lower_bound(i);
    	     	lli jj=dd-1;
    	     	dd-=i-1;
    	     	lli kk=me(10ll,100ll,2ll);
    	     	dd=(kk%2-dd%2+2)%2;
    	     	if(dd)
    	     	ans[jj+1]++;
    	     	else
    	     	ans[jj]++;
    	     }
    	}
    }
    for(int i=n-1;i>=0;i--)
    {
    	if(s[i]=='R')
    	{
    		raux.erase(n-i-1);
    	}
    	else
    	{
    		if(raux.lower_bound(n-i-1)!=raux.end())
    	     {
    	     	lli dd=*raux.lower_bound(n-i-1);
    	     	
    	     	lli jj=dd-1;
    	     	dd=dd-(n-i-1)-1;
    	     	lli kk=me(10ll,100ll,2ll);
    	     	
    	     	dd=(kk%2-dd%2+2)%2;
    	     	if(dd)
    	     	ans[n-jj-2]++;
    	     	else
    	     	ans[n-jj-1]++;
    	     	
    	     }
    	}
    }
    for(int i=0;i<n;i++)
    cout<<ans[i]<<" ";
}

Measured memory_bytes: 11472
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int N;

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

int main () {
  cin >> N;

  for (int k=2;k<=500;++k) {
    if (f(k) == N) {
      cout << "Yes\n";

      vector<vector<int>> v(k+1);

      int ct = 1;
      for (int i=1;i<=k;++i) {
        for (int j=i+1;j<=k;++j) {
          v[i].push_back(ct);
          v[j].push_back(ct);
          ++ct;
        }
      }

      cout << k << "\n";

      rep(i, k) {
        cout << k-1 << " ";
        Rep(j, k-1) {
          cout << v[i][j] << " ";
        }
        cout << "\n";
      }

      return 0;
    }
  }

  cout << "No\n";
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    int n;
    cin >> n;
    vector<int> as(n);
    for (int i = 0; i < n; i++){
        cin >> as[i];
    }
    for (int i = n - 1; i >= 0; i--){
        cout << as[i];
        if(i != 0)
        cout << " ";
    }
    cout << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

ll N;
ll res = 0;

bool judge(ll x){
	bool b3 = false, b5 = false, b7 = false;
	ll y = x;
	while(y>0){
		if(y%10==3) b3 = true;
		if(y%10==5) b5 = true;
		if(y%10==7) b7 = true;
		y /= 10;
	}
	return x<=N && b3 && b5 && b7;
}

void rec(ll x){
	ll a = 10*x + 3;
	ll b = 10*x + 5;
	ll c = 10*x + 7;
	if(a<1010101010) rec(a);
	if(b<1010101010) rec(b);
	if(c<1010101010) rec(c);
	res += judge(x);
	//if (judge(x)) dump(x)
}

int main(){
	cin >> N;
	rec(0);
	cout << res << endl;
    return 0;
}

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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

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

	deque<ll> qu;
	qu.push_front(0);
	char cs[q+5];
	ll cnt = 1;
	bool flag = true; //進行方向通り
	while(q--){
		ll t;
		cin >> t;
		if(t == 1){
			flag = !flag;
		}else{//t == 2
			ll f;
			cin >> f >> &cs[cnt];
			f--;//0:先頭, 1：末尾
			if(flag ^ (f == 0)){
				qu.push_back(cnt);
			}else{
				qu.push_front(cnt);
			}
			cnt++;
		}
	}
	if(!flag){
		reverse(s.begin(), s.end());
		while(!qu.empty()){
			ll ind = qu.back(); qu.pop_back();
			if(ind != 0) printf("%c", cs[ind]);
			else cout << s;
		}
		printf("\n");
	}else{
		while(!qu.empty()){
			ll ind = qu.front(); qu.pop_front();
			if(ind != 0) printf("%c", cs[ind]);
			else cout << s;
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2432
N = int(input())
def sumof(N):
  sum = 0
  while(N>0):
    sum += N % 10
    N //= 10
  return sum

minsum = 9*10
for i in range(1,N//2+1):
  minsum = min(minsum,sumof(i) + sumof(N-i))
print(minsum)


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int N;
  cin >> N;

  vector<int> Nums(N);
  rep(i,N) cin >> Nums.at(i);

  int all = 0;
  rep(i,N) all ^= Nums.at(i);
  rep(i,N) Nums.at(i) ^= all;

  rep(i,N) cout << Nums.at(i) << endl;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a = 1, t = 1;
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		long long x, y; cin >> x >> y;
		long long f = max((a + x - 1) / x, (t + y - 1) / y);
		a = f * x;
		t = f * y;
	}
	cout << a+t << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#define LL long long
using namespace std;
const LL Maxn = 100010;
LL n, a[Maxn];
LL siz[Maxn];
struct lnode {
	LL x, y;
}lis[Maxn]; LL ll;
queue <LL> q[2];
LL dis[Maxn];
vector <LL> vec[Maxn];
void dfs(LL x) {
	dis[x] = 0; siz[x] = 1;
	for(LL i = 0; i < vec[x].size(); i++){
		LL y = vec[x][i];
		dfs(y);
		dis[x] += dis[y]+siz[y];
		siz[x] += siz[y];
	}
}
struct pnode {
	LL num, x;
	bool operator<(const pnode &A) const { return x < A.x; }
}po[Maxn];
int main() {
	LL i, j, k;
	scanf("%lld", &n);
	for(i = 1; i <= n; i++) scanf("%lld", &po[i].x), po[i].num = i;
	sort(po+1, po+n+1);
	for(i = 1; i <= n; i++) a[i] = po[i].x;
	for(i = 1; i <= n; i++) siz[i] = 1;
	for(i = n; i >= 2; i--){
		int x = lower_bound(a+1, a+n+1, a[i]-n+2*siz[i]) - a;
		if(a[x] != a[i]-n+2*siz[i]){ printf("-1\n"); return 0; }
		ll++;
		lis[ll].x = x; lis[ll].y = i;
		siz[x] += siz[i];
	}
	for(i = 1; i <= ll; i++) vec[lis[i].x].push_back(lis[i].y);
	dfs(1);
	if(dis[1] != a[1]){ printf("-1\n"); return 0; }
	for(i = 1; i <= ll; i++) printf("%lld %lld\n", po[lis[i].x].num, po[lis[i].y].num);
	return 0;
}

Measured memory_bytes: 14720
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n = II()
    A = LI()

    memo = {}
    ans = 0
    for j in range(n):
        sa = j - A[j]
        ans += memo.get(sa, 0)
        wa = j + A[j]
        memo[wa] = memo.get(wa, 0) + 1
        # print(memo)
    print(ans)


if __name__ == '__main__':
    solve()


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

using namespace std;

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

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

  cout << n*(n+1)/2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,time,ans=0,flag=0;
    cin>>n>>time;
    int s,e;
    cin>>s;
    e=s+time;
    for(int i =1;i <n;i++){
        int inter;
        cin>>inter;


        if(inter <=e){
            e = inter + time;
           // cout<<"in between "<<e<<endl;
            flag=0;
        }
        else{
            ans = ans + (e-s);
            //cout<<"broken"<<" "<<ans<<endl;
            flag=1;
            s = inter;
            e = inter  + time;
        }

    }
    ans = ans + e-s ;
    cout<<ans<<endl;















}




















Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

flag = True
t = []

for i in range(n):
    if (i+1) != p[i]:
        t.append(i)


if len(t) == 0 or len(t) == 2:
    ans = "YES"

else:
    ans = "NO"

print(ans)

Measured memory_bytes: 3064
#include <map>
#include <algorithm>
#include <iostream>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

bool one(double x){
  return x + 1e-9 > 1.0;
}

int main(){
  const int n = getInt();
  const int m = getInt();

  vector<vector<int> > v(n);
  vector<vector<int> > r(n);
  vector<int> intmp;
  vector<int> in(n);
  vector<int> out(n);
  vector<pair<int, int> > e(m);
  map<int, map<int, int> > memo;

  REP(i,m){
    const int a = e[i].first  = getInt() - 1;
    const int b = e[i].second = getInt() - 1;

    v[a].push_back(b);
    in[b]++;

    r[b].push_back(a);
    out[a]++;

    memo[a][b] = memo[b][a] = i;
  }
  intmp = in;

  vector<int> dist(n);
  queue<int> q;

  REP(i,n) if(in[i] == 0){
    q.push(i);
  }

  while(q.size()){
    const int pos = q.front(); q.pop();

    for(const int next : v[pos]){
      dist[next] = max(dist[next], dist[pos] + 1);
      --in[next];
      if(in[next] == 0) q.push(next);
    }
  }

  const int mx = *max_element(dist.begin(), dist.end());
  vector<int> chain(m);
  vector<int> valid(n);

  REP(i,n) if(dist[i] == mx){
    valid[i] = 1;
  }

  REP(i,n) if(out[i] == 0){
    q.push(i);
  }

  while(q.size()){
    const int pos = q.front(); q.pop();

    for(const int next : r[pos]){
      if(dist[pos] == dist[next] + 1){
        if(valid[pos]){
          valid[next] = 1;
          chain[memo[pos][next]] = 1;
        }
      }

      --out[next];
      if(out[next] == 0) q.push(next);
    }
  }

  vector<double> wp(n);
  vector<double> w(m);
  in = intmp;

  int cnt = 0;
  REP(i,n) if(in[i] == 0 && valid[i]){
    cnt++;
  }

  REP(i,n) if(in[i] == 0 && valid[i]){
    wp[i] = 1.0 / cnt;
  }

  REP(i,n) if(in[i] == 0){
    q.push(i);
  }

  while(q.size()){
    const int pos = q.front(); q.pop();

    int cnt = 0;
    for(const int next : v[pos])
      if(chain[memo[pos][next]]) cnt++;

    for(const int next : v[pos]){
      if(chain[memo[pos][next]]){
        wp[next] += wp[pos] / cnt;
        w[memo[pos][next]] += wp[pos] / cnt;
      }
      --in[next];
      if(in[next] == 0) q.push(next);
    }
  }

  bool b = false;
  REP(i,m){
    if(one(w[i])){
      printf("%d\n", i + 1);
      b = true;
    }
  }

  if(!b) puts("-1");

  return 0;
}

Measured memory_bytes: 44772
#include<iostream>
#include<string>

using namespace std;

int main(void)
{
  string s;
  
  cin>>s;
  
  int size=(int)(s.size());
  int right=size;
  int ans=0;
  
  for(int i=0;i<(size/2);i++)
  {
    if(i==right-1)
        break;
    
    if(s[i] != s[right-1])
      ans++;
    
    
    right--;
    
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep2(i,start,end) for(ll i = start; i < end; ++i)
#define dwn(i,n) for(int i = n; i >= 0; --i)
#define dwn2(i,start,end) for(ll i = start; i >= end; --i)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll mode = 1e9 + 7;


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


	return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  char e;
  cin>>e;
  cout<<++e;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
//   cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    if(sx+1==tx||sy+1==ty) {
        for (int i = sy; i < ty; i++)cout << 'U';
        for (int i = sx; i < tx; i++)cout << 'R';
        for (int i = sy; i < ty; i++)cout << 'D';
        for (int i = sx; i < tx; i++)cout << 'L';
        cout << 'L';
        for (int i = sy; i < ty; i++)cout << 'U';
        cout << 'U';
        for (int i = sx; i < tx; i++)cout << 'R';
        cout << "RDR";
        for (int i = sy; i < ty; i++)cout << 'D';
        cout << 'D';
        for (int i = sx; i < tx; i++)cout << 'L';
        cout << "LU";
    }
    else{
        cout<<"UU";
        for(int i=sx;i<tx-1;i++)cout<<'R';
        for(int i=sy;i<ty-2;i++)cout<<'U';
        cout<<"RR";
        for(int i=sy;i<ty;i++)cout<<'D';
        for(int i=sx;i<tx-1;i++)cout<<'L';
        cout<<"DLLULUUU";
        for(int i=sx;i<tx-1;i++)cout<<'R';
        for(int i=sy;i<ty-2;i++)cout<<'U';
        cout<<"RR";
        for(int i=sy;i<ty;i++)cout<<'D';
        for(int i=sx;i<tx-1;i++)cout<<'L';
        cout<<"DL";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int X,Y;
	cin>>X>>Y;
	int result = 0;
	if(X==1 && Y==1)
	{
		result = 400000;
	}
	
	
		result += max(4-X,0) * 100000 + max(4-Y,0) * 100000;
	
	cout<<result<<endl;
}

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

typedef long long LL;
typedef pair<int,int> pii;

LL h,w;
int n;

map<pii,int> ada;

LL ans[10];

int main(){
	scanf("%lld%lld%d",&h,&w,&n);
	for(int i=1;i<=n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		for(int j=-1;j<=1;j++){
			for(int k=-1;k<=1;k++){
				int nx = a+j;
				int ny = b+k;
				if(nx < 2 || nx > h-1 || ny < 2 || ny > w-1) continue;
				ada[make_pair(nx,ny)]++;
			}
		}
	}
	LL tot = (h-2)*(w-2);
	for(auto x : ada){
		tot--;
		ans[x.second]++;
	}
	ans[0] = tot;
	for(int i=0;i<=9;i++){
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 56448
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
B = list(map(int,input().split()))

A = [0]*N
A[0] = B[0]
for i in range(N-1):
    A[i+1] = B[i]
    if A[i] > B[i]:
        A[i] = B[i]

print(sum(A))


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int p=1e9+7;

int main()
{
	long long n;
	cin>>n;
	long long ans=10;
	long long s=9;
	long long k=8;
	for(int i=1;i<n;++i)
	  {
	  	  ans=(ans*10)%p;
	  	  s=(s*9)%p;
	  	  k=(k*8)%p;
	  }
	ans=(ans-2*s+k+p+p)%p;
	cout<<ans<<endl;  
	    
}


Measured memory_bytes: 3632
D, G = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(D)]

comp = [pc[i][0]*(i+1)*100+pc[i][1] for i in range(D)]

ans = 1000
for bit in range(2**D):
  solved = []
  for j in range(D):
    if 1&(bit>>j):
      solved.append(j)
  now = 0
  ps = 0
  for i in solved:
    now += comp[i]
    ps += pc[i][0]
  if now >= G:
    ans = min(ans, ps)
  else:
    for k in range(D):
      if D-k-1 in solved:
        continue
      if now + (D-k)*100*(pc[k][0]-1) >= G:
        ps += (G-now-100)//((D-k)*100) + 1
        ans = min(ans, ps)
      else:
        break
        
print(ans)


Measured memory_bytes: 3064
import numpy as np
N = int(input())

A,B = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]

b = 0 
c = 0 
d = 0

for i in range(N):
    if a[i] <= A:
        b = b + 1
    elif a[i] <= B:
        c = c + 1
    else:
        d = d + 1

if b < c:
    if b < d:
        print(b)
    else:
        print(d)
elif c < d:
    print(c)
else:
    print(d)

Measured memory_bytes: 21636
// review
#include <iostream>

using namespace std;

string s;

void solve() {
  int cnt0 = 0, cnt1 = 0;
  for (int i=0;i<s.size();i++) {
    if (s[i] == '0') {
      cnt0++;
    } else {
      cnt1++;
    }
  }
  cout << 2 * min(cnt0, cnt1) << endl;
}

int main() {
  cin >> s;
  solve();
}


Measured memory_bytes: 512
import numpy as np

D=int(input())
C=np.array(list(map(int,input().split())))
S=[]
for _ in range(D):
    S.append(list(map(int,input().split())))
T=[int(input()) for _ in range(D)]

def last(d):
    l=np.zeros(26,int)
    for i in range(d):
        l[T[i]-1]=i+1
    return l

def decrease(d):
    return np.dot(C,(d-last(d)))



manzoku=0
res=[]
for i in range(D):
    manzoku+=S[i][T[i]-1]
    manzoku-=decrease(i+1)
    res.append(manzoku)

for x in res:
    print(x)

Measured memory_bytes: 27196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
	ll s=0;
	bool f=0;
	char ch=' ';
	while(!isdigit(ch))
	{
		f|=(ch=='-'); ch=getchar();
	}
	while(isdigit(ch))
	{
		s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
	}
	return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
	if(x<0)
	{
		putchar('-'); x=-x;
	}
	if(x<10)
	{
		putchar(x+'0');	return;
	}
	write(x/10);
	putchar((x%10)+'0');
	return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const ll Mod=1000000007;
const int N=200005;
int n,A,B;
ll Jiec[N];
int Father[N];
int Min[N],CMin[N];
int Cnt[N];
struct Record
{
	int Cor,W,Id;
}Xins[N];
inline int Get_Father(int x)
{
	return (Father[x]==x)?(x):(Father[x]=Get_Father(Father[x]));
}
inline void Merge(int x,int y)
{
	Father[Get_Father(x)]=Get_Father(y);
}
vector<int>Liantong[N];
inline ll Ksm(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y&1) ans=ans*x%Mod;
		x=x*x%Mod;
		y>>=1;
	}
	return ans;
}
int main()
{
	int i,j;
	R(n); R(A); R(B);
	Jiec[0]=1; for(i=1;i<=n;i++) Jiec[i]=1ll*Jiec[i-1]*i%Mod;
	Xins[0].W=0x3f3f3f3f;
	for(i=1;i<=n;i++)
	{
		Father[i]=i;
		R(Xins[i].Cor); R(Xins[i].W); Xins[i].Id=i;
		if(Xins[i].W<=Xins[Min[Xins[i].Cor]].W)
		{
			CMin[Xins[i].Cor]=Min[Xins[i].Cor];
			Min[Xins[i].Cor]=i;
		}
		else if(Xins[i].W<Xins[CMin[Xins[i].Cor]].W)
		{
			CMin[Xins[i].Cor]=i;
		}
	}
	int Fir=0,Sec=0;
	for(i=1;i<=n;i++)
	{
		if(Fir==0||Xins[i].W<Xins[Min[Fir]].W) {Sec=Fir; Fir=Xins[i].Cor;}
		else if(Sec==0||Xins[i].W<Xins[Min[Sec]].W) Sec=Xins[i].Cor;
	}
	for(i=1;i<=n;i++)
	{
		if(Xins[i].W+Xins[Min[Xins[i].Cor]].W<=A)
		{
			if(i!=Min[Xins[i].Cor]) Merge(i,Min[Xins[i].Cor]);
		}
		if(Xins[i].Cor==Fir)
		{
			if(Xins[i].W+Xins[Min[Sec]].W<=B) Merge(i,Min[Sec]);
		}
		else
		{
			if(Xins[i].W+Xins[Min[Fir]].W<=B) Merge(i,Min[Fir]);
		}
	}
	for(i=1;i<=n;i++) Liantong[Get_Father(i)].push_back(i);
//	for(i=1;i<=n;i++) if(Liantong[i].size())
//	{
//		for(j=0;j<Liantong[i].size();j++) W(Liantong[i][j]);
//		puts("");
//	}
	ll ans=1;
	for(i=1;i<=n;i++) if(Liantong[i].size())
	{
		for(j=0;j<Liantong[i].size();j++)
		{
			Cnt[Xins[Liantong[i][j]].Cor]++;
		}
		ll tmp=Jiec[Liantong[i].size()];
		for(j=0;j<Liantong[i].size();j++) if(Cnt[Xins[Liantong[i][j]].Cor])
		{
			tmp=1ll*tmp*Ksm(Jiec[Cnt[Xins[Liantong[i][j]].Cor]],Mod-2)%Mod;
			Cnt[Xins[Liantong[i][j]].Cor]=0;
		}
		ans=1ll*ans*tmp%Mod;
	}
	Wl(ans);
	return 0;
}
/*
input
4 7 3
3 2
4 3
2 1
4 4
output
2

input
5 99 100
5 91
2 42
3 63
3 35
4 21
output
12

input
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
output
129729600
*/

Measured memory_bytes: 17792
S = input()
T = input()

tToS = {}
sToT = {}
for s, t in zip(S, T):
    if not t in tToS:
        tToS[t] = s
    if not s in sToT:
        sToT[s] = t

    if tToS[t] != s or sToT[s] != t:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 3632
n, m = [int(i) for i in input().split()]
p = [0 for i in range(m)]
y = [0 for i in range(m)]

out = [[0, 0] for i in range(m)]
hash = [[] for i in range(10**5+1)]
for i in range(m):
    p[i], y[i] = [int(i) for i in input().split()]
    hash[p[i]].append([y[i], i])

for i in range(len(hash)):
    hash[i] = sorted(hash[i])
    for j in range(len(hash[i])):
        out[hash[i][j][1]] = i, j+1
for i in range(len(out)):
    print("{}{}".format(str(out[i][0]).zfill(6), str(out[i][1]).zfill(6)))

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

const int N = 1e5;

vector<int> g[N];
int leaves[N];
int dp[N];
int ans;
int root;

pair<int, int> max2(pair<int, int> a, int b) {
    if (a.first < b) {
        swap(a.first, b);
    }
    if (a.second < b) {
        swap(a.second, b);
    }
    return a;
}

void dfs(int u, int p) {
    bool is_leaf = true;
    for (int v : g[u]) {
        if (v == p) {
            continue;
        }
        dfs(v, u);
        is_leaf = false;
        leaves[u] += leaves[v];
    }
    if (is_leaf) {
        leaves[u]++;
        dp[u] = 1;
    }
}

void dfs2(int u, int p) {
    pair<int, int> take;
    pair<int, int> not_take;
    for (int v : g[u]) {
        if (v == p) {
            continue;
        }
        dfs2(v, u);
        dp[u] = max(dp[u], dp[v] + leaves[u] - leaves[v]);
        dp[u] = max(dp[u], dp[v] + 1);
        take = max2(take, dp[v]);
        not_take = max2(not_take, dp[v] - leaves[v]);
    }
    ans = max(ans, dp[u]);
    ans = max(ans, take.first + take.second + 1);
    ans = max(ans, not_take.first + not_take.second + leaves[root]);
    //for (int x : g[u]) {
    //    for (int y : g[u]) {
    //        if (x == y) {
    //            continue;
    //        }
    //        ans = max(ans, dp[x] + dp[y] + 1);
    //        // ans = max(ans, dp[x] + dp[y] + leaves[u] - leaves[x] - leaves[y] + (leaves[0] - leaves[u]));
    //        ans = max(ans, dp[x] + dp[y] - leaves[x] - leaves[y] + leaves[0]);
    //    }
    //}
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    if (n <= 2) {
        cout << n << endl;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (g[i].size() >= 2) {
            root = i;
            dfs(i, -1);
            dfs2(i, -1);
            cout << ans << endl;
            break;
        }
    }
}


Measured memory_bytes: 6656
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int ma=1e5+10;
int h[ma],l[ma];
main()
{
    int n;
    cin>>n;
    rep(i,n)cin>>h[i];
    rep(i,n)l[i]=0;
    rep(i,n+1)
    {
        if(h[i]>=h[i+1])l[i+1]=l[i]+1;
        else l[i+1]=0;
    }
    int ans=0;
    rep(i,n)
    {
        ans=max(ans,l[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


const int MAX = 510000;
const int mod = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

int main(){
  string s;cin>>s;
  int alp[26]={};
  rep(i,4){
    alp[(int)s[i]-'A']++;
  }
  rep(i,26){
    if(alp[i]!=2&&alp[i]!=0){
      cout<<"No"<<endl;
      exit(0);
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
n, *li = map(int, input().split())
L = list(map(int, (int(input()) for _ in range(n))))
ans = int(1e9)
def f(A, num, cnt):
    if num == n:
        if 0 in A:
            return
        global ans
        ans = min(ans, abs(A[0] - li[0]) + abs(A[1] - li[1]) + abs(A[2] - li[2]) + cnt)
        return
    for i in range(3):
        p = 0 if A[i] == 0 else 10
        B = A[::]
        B[i] += L[num]
        f(B, num + 1, cnt + p)
    f(A, num + 1, cnt)
f([0, 0, 0], 0, 0)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int N, K;

int main(int argc, const char * argv[]) {
    cin >> N >> K;
    vi A(N);
    for (int n=0; n<N; ++n) {
        cin >> A[n];
    }
    
    cout << (N+K-3) / (K-1) << endl;

    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
int main(){
int w[10],k[10],i,j,tmp,ksum,wsum;
for(i=0;i<10;i++){
scanf("%d\n",&w[i]);
}
for(i=0;i<10;i++){
scanf("%d\n",&k[i]);
}
for (i = 0; i < 9; i++) {
for (j = 9; j > i; j--) {
if (w[j - 1] < w[j]) { 
tmp = w[j];      
w[j] = w[j - 1];
w[j - 1]= tmp;
}
if (k[j - 1] < k[j]) {  
tmp = k[j];      
k[j] = k[j - 1];
k[j - 1]= tmp;
}
}
}
wsum=w[0]+w[1]+w[2];
ksum=k[0]+k[1]+k[2];
printf("%d %d\n",wsum,ksum);
return 0;
}

Measured memory_bytes: 600
N = int(input())
a = [int(i) for i in input().split()]
big = sorted(a)[N // 2]
sma = sorted(a)[N // 2 - 1]
if big == sma:
    for i in range(N):
        print(big)
else:
    for i in a:
        if i < big:
            print(big)
        else:
            print(sma)

Measured memory_bytes: 25224
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,a[100005],b[100005],ans;
main(){
cin>>n;
for(int k=1;k<=n+1;k++)
    cin>>a[k];
for(int k=1;k<=n;k++)
    cin>>b[k];
for(int k=1;k<=n;k++){
    if(a[k]>b[k]){
        ans+=b[k];
    }
    else{
        ans+=a[k];
        b[k]-=a[k];
    int c=min(b[k],a[k+1]);
    a[k+1]-=c;
    ans+=c;
    }
}
cout<<ans;
return 0;
}


Measured memory_bytes: 1792