akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.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 Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};
int dx[6] = {1, 0, -1, 1, -1, 0}, dy[6] = {1, 1, 1, 0, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, C;
  cin >> N >> C;
  vector<vector<int>> D(C, vector<int>(C));
  for (int i = 0; i < C; i++)
  {
    for (int j = 0; j < C; j++)
    {
      cin >> D[i][j];
    }
  }
  vector<vector<int>> t(3, vector<int>(C));
  vector<vector<int>> c(N, vector<int>(N));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      cin >> c[i][j];
      t[(i + j) % 3][c[i][j] - 1]++; // 前処理として(i + j) % 3となる位置に各色が何色あるか先に計算しておく
    }
  }
  ll ans = INF;
  // 使う色を全列挙
  for (int x = 1; x <= C; x++)
  {
    for (int y = 1; y <= C; y++)
    {
      if (x == y)
        continue;
      for (int z = 1; z <= C; z++)
      {
        if (x == z || y == z)
          continue;
        ll tmp = 0;
        for (int i = 0; i < C; i++)
          tmp += D[i][x - 1] * t[0][i]; // mod 3 == 0のときに色をx-1に変えるためのコストが何回分かかるかを計算する
        for (int i = 0; i < C; i++)
          tmp += D[i][y - 1] * t[1][i]; // mod 3 == 1
        for (int i = 0; i < C; i++)
          tmp += D[i][z - 1] * t[2][i]; // mod 3 == 2
        ans = min(ans, tmp);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

// どの色で最初に塗られているマスがいくつあるかを予め計算しておくとこの部分がO(C)となり，時間内に正解を得ることが出来る．


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  int maxan = max(a, max(b, max(c, max(d, e))));
  int minan = min(a, min(b, min(c, min(d, e))));
  string ans;
  if (maxan- minan>k)  ans = ":(";
  else ans = "Yay!";

  cout << ans << endl;
  return 0;
}


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


    ll n,m,k;
    cin>>n>>m>>k;
    ll arr[m+5]={0};
    ll vis[105]={0};
    for(int i=0;i<m;i++)
    {
        cin>>arr[i];
        vis[arr[i]]=1;
    }
    ll cnt=0;
    ll arek=0;
    for(int i=k;i<=n;i++)
    {
        if(vis[i]==1)
        {
            cnt++;
        }

    }
    for(int i=k;i>=0;i--)
    {
        if(vis[i]==1)
        {
            arek++;
        }
    }
    cout<<min(cnt,arek)<<endl;


}


Measured memory_bytes: 3572
(stdin => {
  // Define Function
  const lessThen = (a,b) => a<b
  const range = f => (a,b,c) => f(a,b) && f(b,c)
  // Declare Variable
  const inputs = stdin.toString().trim().split('\n')
  const [a,b,c] = Array.from (inputs[0].split(' '),Number)
  console.log(range(lessThen)(a,b,c)?'Yes' : 'No')
})(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 15136
#include <stdio.h>

int main(void){
  int a,b,state=0;
  int i;
  scanf("%d %d",&a,&b);
  if(a==0&&b==0) state=-1;
  else{
    state=0;
    for(i=a;i<=b;i++){
      if(i%400==0){
	printf("%d\n",i);
	state++;
      }else if(i%4==0 && i%100!=0){
	printf("%d\n",i);
	  state++;
      }
      }
    if(state==0) printf("NA\n");
  }
  if(state!=-1){
    while(scanf("%d %d",&a,&b)!=EOF){
      if(a==0&&b==0) break;
      else{
	state=0;
	printf("\n");
	for(i=a;i<=b;i++){
	  if(i%400==0){
	  printf("%d\n",i);
	  state++;
	  }else if(i%4==0 && i%100!=0){
	    printf("%d\n",i);
	    state++;
	  }
	}
	if(state==0) printf("NA\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 616
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int main(){
	int N;
	cin>>N;
	string str,str2;
	cin>>str;
	str2=str;
	reverse(all(str2));
	str=str.substr(0,N);
	str2=str2.substr(0,N);
	ll ans=0;
	for(int i=0;i<(1<<N);i++){
		int temp = i;
		string hoge="",fuga="";
		rep(j,N){
			if(temp%2)hoge+=str[j];
			else fuga+=str[j];
			temp = temp>>1;
		}
		//cout<<hoge<<" "<<fuga<<endl;
		ll dp[30][30]={0};
		dp[0][0]=(ll)1;
		for(int j=1;j<=N;j++){
			for(int k=0;k<=j;k++){
				if(str2[j-1]==hoge[j-1-k])dp[j][k]+=dp[j-1][k];
				if(k>0&&str2[j-1]==fuga[k-1])dp[j][k]+=dp[j-1][k-1];
			}
		}
		ans+=dp[N][fuga.size()];
	}
	/*vector<char>X,Y;
	rep(i,N)X.pb(str[i]),Y.pb(str2[i]);
	sort(all(X));
	sort(all(Y));
	bool check=true;
	rep(i,N)if(X[i]!=Y[i])check=false;*/
	cout<<ans<<endl;
	/*if(check)cout<<"Y"<<endl;
	else cout<<"N"<<endl;*/
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);
int N=gi();
	    String S=gs();
	    String T=gs();
	    StringBuilder sb=new StringBuilder();
	    for (int i=0; i<S.length();i++) {
	    	sb.append(S.charAt(i));
	    	sb.append(T.charAt(i));
	    }
	   
        System.out.print(sb.toString());

//        if (2*X<=Y&& Y<=4*X && Y%2==0) {
//        	System.out.println("Yes");
//        }else{
//        	System.out.println("No");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35596
#include <stdio.h>

int main( void )
{

	unsigned int time, h = 0, m = 0, s = 0;
	
	scanf( "%u", &time );
	
	h = time / 3600;
	m = ( time / 60 ) % 60;
	s = time % 60;
	
	printf( "%u:%u:%u\n", h, m, s );
	
	return 0;
}

Measured memory_bytes: 604
n = int(input())
Ss = [input() for i in range(n)]

num = [[0] * 26 for i in range(n)]
for i, S in enumerate(Ss):
    for c in S:
        num[i][ord(c) - ord('a')] += 1

minNs = list(map(min, zip(*num)))

ans = ''
for c, minN in zip('abcdefghijklmnopqrstuvwxyz', minNs):
    ans += c * minN

print(ans)


Measured memory_bytes: 3060
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	string s;
	cin>>s;
	int i,j,k,l;
	l=s.size();
	int o,e;
	e=l/2;o=l-e;
	int o0=0,o1=0,e0=0,e1=0;
	for(i=0;i<l;i++)
	{
		if(i%2==0)
		{
			if(s[i]=='0')
				o0++;
			else
				o1++;
		}
		else
		{
			if(s[i]=='0')
				e0++;
			else
				e1++;
		}
	}
	cout<<min(o0+e1,o1+e0);


	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#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 all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);


int main()
{
	int n,k;
	cin >> n >> k;
	vi h(n+10,INF);
	for(int i = 1; i <= n; i++) cin >> h[i];
	vi dp(100010,INF);
	dp[1] = 0;
	for(int i = 1; i < n; i++){
		for(int j = 1; j <= k; j++){
			if(i+j > n) break;
			dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
		}
	}
	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
 

int main(){
    int k,n; cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans=INF;
    rep(i,n){
        int left,right;
        if(i==0) left=k-(a[0]+k-a[n-1]);
        else if(i==n-1) right=k-(a[0]+k-a[n-1]);
        else{
            left=k-(a[i]-a[i-1]);
            right=k-(a[i+1]-a[i]);
        }
        ans=min(ans,left);
        ans=min(ans,right);
    }
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
using ll=long long;
using ld=long double; 
using namespace std;
//const int INF = 7+(1e+9);
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll MOD=1e9+7;

int main(){
    ll n,m;cin>>n>>m;
    vector<pair<ll,ll>> vec(m);
    for(int i=0;i<m;i++){
        int x,y;cin>>x>>y;x--;y--;
        vec[i]=make_pair(x,y);
       // cout<<x<<" "<<y<<endl;
    }
 //   cout<<endl;
    ll c=0;
   // cout<<vec[0].second<<endl;
    for(int i=0;i<m;i++){
        UnionFind tree(n+1);
        for(int j=0;j<m;j++){
            if(i==j){
                
            }else{
                tree.unite(vec[j].first,vec[j].second);
             //   cout<<j<<" "<<vec[j].first<<" "<<vec[j].second<<endl;
            }
          //  cout<<vec[i].first<<" "<<vec
        }
     //   cout<<endl;
       // cout<<endl;
        bool h=true;
        for(int j=1;j<n;j++){
            if(!tree.same(0,j)){
            //    cout<<i<<" "<<j<<endl;
                h=false;
                break;
            }
        }
        if(!h){
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b): return (a + b - 1) // b


def ok(n, A, B):
    ans = 0
    for c in str(n):
        ans += int(c)
    return A <= ans <= B


def main():
    N, A, B = map(int, input().split())
    ans = 0
    for n in range(1, N + 1):
        if ok(n, A, B):
            ans += n
    print(ans)


if __name__ == '__main__':
    main()


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

const int N = 100005;
const int inf = 1e6;

int n, k;
vector<int> G[N];
int L[N], R[N], a[N];
int parity[N];

void dfs(int u, int p) {
	L[u] = -inf, R[u] = inf;
	if (a[u] != -1) L[u] = R[u] = a[u], parity[u] = (a[u] & 1);
	for (int v : G[u]) if (v != p) {
		dfs(v, u);
		if (parity[v] != -1) {
			if (parity[u] == -1) parity[u] = parity[v] ^ 1;
			else if (parity[u] != parity[v] ^ 1) { printf("No\n"); exit(0); }
		}
		L[u] = max(L[u], L[v] - 1);
		R[u] = min(R[u], R[v] + 1);
	}
	if (L[u] > R[u]) { printf("No\n"); exit(0); }
}

void fill(int u, int p) {
	for (int v : G[u]) if (v != p) {
		int val = a[u] + 1;
		if (!(val >= L[v] && val <= R[v])) val = a[u] - 1;
		if (!(val >= L[v] && val <= R[v])) { printf("No\n"); exit(0); }
		a[v] = val;
		fill(v, u);
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	memset(parity, -1, sizeof parity);
	memset(a, -1, sizeof a);
	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		G[u].push_back(v); G[v].push_back(u);
	}
	cin >> k;
	while(k--) {
		int v, p; cin >> v >> p; a[v] = p;
	}

	dfs(1,-1);
	a[1] = L[1];
	fill(1,-1);

	printf("Yes\n");
	for (int i = 1; i <= n; ++i) printf("%d\n", a[i]);
}

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

int main(){
	int n,m;cin >> n >> m;
	int maxl = INT_MIN;
	int minr = INT_MAX;
	for(int i = 0;i < m;i++){
		int l,r;cin >> l >> r;
		if(l > maxl)maxl = l;
		if(r < minr)minr = r;
	}
	cout << max(0, minr - maxl + 1);
}
// make pair, tuple
// make pair, tuple
// 
// __gcd(int, int);
// lcm = a * b / __gcd(a, b);
// 
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }
// 
// #Count leading & trailing zero of an integer bits
// __builtin_clz(n);
// __builtin_clzll(n);
//
// #Count 1s bits of an integer
// __builtin_popcount(n);
// __builtin_popcountll(n);
//
// #Error checking
// assert(n == 3);
// 
// #Error Printing
// cerr << "Some thing";

// #binary exponentiation
// long long binpow(long long a, long long b) {
//     long long res = 1;
//     while (b > 0) {
//         if (b & 1)
//             res = res * a;
//         a = a * a;
//         b >>= 1;
//     }
//     return res;
// }


Measured memory_bytes: 256
//============================================================================
// 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

//============================================================================
#define PI 3.14159265359
#define succ(x) ((x)+1)
#define pred(x) ((x)-1)
//============================================================================
void enter()
{
    long N,i,min,max,sum, *ary;

    scanf("%ld", &N);
    ary=malloc(N*sizeof(long));
    for (i=sum=0,min=1000000000,max=-min; i<N; i++){
        scanf("%ld", &ary[i]);
        sum+=ary[i];
        if (max<ary[i])
            max=ary[i];
        if (min>ary[i])
            min=ary[i];
    }
    printf("%ld %ld %ld\n", min, max, sum);
    free(ary);
}
//============================================================================
int main(void)
{
    enter();
    return 0;
}
//============================================================================

Measured memory_bytes: 676
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;

ll n, q, a, b, c, freq[nax];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> n;
	ll sum = 0;
	for(ll i = 1; i <= n; i++){
		cin >> a;
		freq[a]++;
		sum += a;
	}
	cin >> q;
	while(q--){
		cin >> b >> c;
		ll dif = c - b;
		sum += dif * freq[b];
		freq[c] += freq[b];
		freq[b] = 0;
		cout << sum << '\n';
	}
}


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

#define ld long double
#define f(i,g,n) for(int i=g;i<=n;i++)

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

	int n;
	cin>>n;
	ld A[n],sum=0;
	f(i,0,n-1)
	{
		cin>>A[i];
		sum += 1/A[i];
	}
	cout<<setprecision(30)<<1/sum<<"\n";


	return 0;
}

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 <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 DSORT(c, type) sort(ALL(c), greater<type>())

using namespace std;


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

  int x; cin >> x;
  int y[3] = {3, 5, 7};

  for(int i=0; i<3; ++i)
    if(x == y[i]){ cout << "YES\n"; return 0; }

  cout << "NO\n";

  return 0;
}


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

int main(void){
    int k;
    cin >> k;
    istringstream ss("1 1 1 2 1 2 1 5 2 2 1 5 1 2 1 14 1 5 1 5 2 2 1 15 2 2 5 4 1 4 1 51");
    string s;
    for (int i = 0; i < k; i++){
        ss >> s;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

#define LIM_S 200002
#define LIM_N 100001

char str[LIM_S];

int N, K;
char S[LIM_S];

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &N);
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%s", S);
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &K);
}

void initialize() {
}

void solve() {
	char c = S[K-1];

	for (size_t i = 0; i < N; i++) {
		printf("%c", (c == S[i]) ? c : '*');
	}
}

int main(void) {
	receive_input();
	initialize();

	solve();

	return 0;
}


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

template <int Mod, bool IsPrime = false>
class mod_int {
    using ll = long long;

public:
    constexpr mod_int() : n(0) {}
    constexpr mod_int(int n_) : n(n_) {
        if(n >= Mod)     n %= Mod;
        else if(n < 0) n = (n % Mod + Mod) % Mod;
    }
    constexpr mod_int(ll n_) : n(n_) { n = (n + Mod) % Mod; }

    constexpr operator int() const { return n; }
    constexpr operator ll() const  { return n; }

    constexpr bool operator==(mod_int const& other) const { return n == other.n; }
    constexpr mod_int& operator+=(mod_int const& other) {
        if((n += other.n) >= Mod) n -= Mod;
        return *this;
    }
    constexpr mod_int& operator-=(mod_int const& other) {
        if((n += Mod - other.n) >= Mod) n -= Mod;
        return *this;
    }
    constexpr mod_int& operator*=(mod_int const& other) {
        n = (unsigned long long)n * other.n % Mod;
        return *this;
    }
    constexpr typename std::enable_if<IsPrime, mod_int>::type& operator/=(mod_int const& other) {
        return *this *= other.inverse();
    }
    constexpr mod_int operator+(mod_int other) const { return mod_int(*this) += other; }
    constexpr mod_int operator-(mod_int other) const { return mod_int(*this) -= other; }
    constexpr mod_int operator*(mod_int other) const { return mod_int(*this) *= other; }
    constexpr mod_int operator/(mod_int other) const { return mod_int(*this) /= other; }

    constexpr typename std::enable_if<IsPrime, mod_int>::type inverse() const {
        ll a = n, b = Mod, u = 1, v = 0;
        while(b) {
            ll t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        return mod_int(u);
    }

private:
    ll n;
};

template <int Mod, bool IsPrime>
std::ostream& operator<<(std::ostream& os, mod_int<Mod, IsPrime> const& n) {
    os << (int)n;
    return os;
}

constexpr int default_mod = 1000000007;

template <int Mod = default_mod>
mod_int<Mod, true> fact(int n) {
    static std::vector<mod_int<Mod, true>> v = {1};
    if(n >= static_cast<int>(v.size())) {
        const int from = v.size(), to = n + 1024;
        v.reserve(to);
        for(int i = from; i < to; ++i) {
            v.push_back(v.back() * mod_int<Mod, true>(i));
        }
    }
    return v[n];
}

template <int Mod = default_mod>
mod_int<Mod, true> comb(int n, int r) { // nCr
    if(r < 0 || r > n) return 0;
    return fact<Mod>(n) / fact<Mod>(r) / fact<Mod>(n - r);
}

using mint = mod_int<default_mod, true>; // default

int main() {
    int n, m; cin >> n >> m;
    mint ans = 1;
    for(int i = 2; i * i <= m; ++i) {
        if(m % i == 0) {
            int c = 0;
            while(m % i == 0) {
                c += 1;
                m /= i;
            }
            ans *= comb(n + c - 1, n - 1);
        }
    }
    if(m > 1) {
        ans *= mint(n);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
int_n, int_m = map(int, input().split())

roads = dict()

for i in range(int_m):
    road = tuple(map(int, input().split()))

    for r in road:
        if r in roads:
            roads[r] += 1
        else:
            roads[r] = 1


for i in range(1, int_n + 1):
    print("0" if i not in roads else roads[i])



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

int main (){
    cin.tie(0);
    int A,B,C;
    cin >> A >> B >> C ;
    if(A==B){cout << C << endl;}
    if(A==C){cout << B << endl;}
    if(B==C){cout << A << endl;}
    return 0;
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbg=2e18;
//My own input/output stream
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putsp()
#define putii(x,y) puti(x),putnum(y),putsp()
#define putiii(x,y,z) putii(x,y),putnum(z),putsp()
#define putsi(x) putnum(x),putendl()
#define putsii(x,y) puti(x),putnum(y),putendl()
#define putsiii(x,y,z) putii(x,y),putnum(z),putendl()
inline ll getnum()
{
	register ll r=0;register bool ng=0;register char c;c=getchar();
	while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	if(c=='-')ng=1,c=getchar();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=getchar();
	if(ng)r=-r;return r;
}
template <class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline void putsp(){putchar(' ');}
inline void putendl(){putchar('\n');}
inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
int n,m,d[100111];
int main()
{
	getii(n,m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		getii(x,y);
		d[x]++;
		d[y]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(d[i]&1)
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

int main() {
    double x1, x2, y1, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    printf("%.4lf\n", sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
}


Measured memory_bytes: 2112
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

vector <int> G[maxN];
int comp[maxN], cmp = 0;

void DFS(int v){
	comp[v] = cmp;
	for (auto u : G[v]){
		if (comp[u]) continue;
		DFS(u);
	}
	return;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m, u, v, z;
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		cin >> u >> v >> z;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for (int i = 1; i <= n; i++){
		if (comp[i]) continue;
		cmp += 1;
		DFS(i);
	}
	cout << cmp << endl;
	return 0;
}



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

int main() {
    int K,X;
    cin >> K >> X;
    cout << (K*500 >= X ? "Yes" : "No") << endl;

    return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    int sum = 0;
    for (int i = 0; i < m; i++)
    {
        cin >> a.at(i);
        sum += a.at(i);
    }
    if (n - sum >= 0)
    {
        cout << n - sum << endl;
    }
    else
    {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3604
h, w = map(int, raw_input().split())
S = [raw_input().split() for i in xrange(h)]
for i in xrange(h):
    for j in xrange(w):
        if S[i][j] == "snuke":
            print "%s%d" % ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"[j], i+1)


Measured memory_bytes: 2700
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

ll result[200005] = {0};
void fact(ll n) {
   if (n >= 0) {
      result[0] = 1;
      for (ll i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
   }
}

void solution(){
  int k, a, b;
  cin >> k >> a >> b;

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

  cout << "NG" << endl;
}     



Measured memory_bytes: 3132
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

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

	int N;
	string a, b, c;
	cin >> N >> a >> b >> c;

	int ans = 0;
	for( int i = 0; i < N; ++i ) {
		set<char> x { a[i], b[i], c[i] };
		ans += x.size() - 1;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  ll N,A,B; cin >> N >> A >> B;
  vector<ll> X(N);
  for (int i = 0; i < N; i++) cin >> X[i];
  
  ll sum = 0;
  for (int i = 1; i < N; i++) sum += min(A*(X[i] - X[i-1]),B);
  
  cout << sum << endl;                                       
}

Measured memory_bytes: 1024
// 2020-08-02 10:54:47
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const int MAX_N = 100010;
int visited[MAX_N];
vector<int> used;
vector<P> G[MAX_N]; // to, i
vector<P> p; // Ai, perils
void dfs(int u) {
  if(visited[u]) return;
  visited[u] = 1;
  for(auto& e : G[u]) {
    if(visited[e.first]) continue;
    dfs(e.first);
    if(p[e.first].second) {
      used.push_back(e.second);
      p[e.first].second = 0;
      p[u].second = !p[u].second;
    }
  }
}
void answer() {
  int n, m;
  cin >> n >> m;
  p.resize(n+1);
  {
    vector<P> ab(n+2);
    rep(i, n) cin >> ab[i].first >> ab[i].second;
    ab[n] = P(0, 0);
    ab[n+1] = P(1e9+5, 0);
    sort(ALL(ab));
    rep(i, n+1) {
      p[i].first = ab[i].first;
      p[i].second = ab[i].second ^ ab[i+1].second;
    }
  }
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    int li = lower_bound(ALL(p), P(l, 0)) - p.begin() - 1;
    int ri = upper_bound(ALL(p), P(r, 1)) - p.begin() - 1;
    if(li == ri) continue;
    G[li].emplace_back(ri, i+1);
    G[ri].emplace_back(li, i+1);
  }
  rep(i, n+1) dfs(i);
  bool ok = true;
  rep(i, n+1) ok &= (p[i].second == 0);
  if(!ok) {
    cout << -1 << '\n';
    return;
  }
  sort(ALL(used));
  cout << used.size() << '\n';
  bool first = 1;
  for(int i : used) {
    if(first) first = false;
    else cout << ' ';
    cout << i;
  }
  cout << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 16696
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	VL a(3 * n);
	rep(i, 3 * n) {
		cin >> a[i];
	}
	sort(all(a),greater<ll>());
	ll ans = 0;
	for (int i = 1; i < 2 * n; i += 2) ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5548
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

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

    int64_t ans = (X/500) * 1000;
    X %= 500;
    ans += (X/5)*5;

    cout << ans << endl;
    return 0;
}


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

int main(){
  string S ;
  cin >> S ;
  string A = S.substr(0,2), B = S.substr(2);
  if(A >= "01" && A <= "12" && (B == "00" || B >= "13")) cout << "MMYY" << endl;
  else if(B >= "01" && B <= "12" && (A == "00" || A >= "13")) cout << "YYMM" << endl;
  else if(A >= "01" && A <= "12" && B >= "01" && B <= "12") cout << "AMBIGUOUS" << endl;
  else cout << "NA" << endl;
}


Measured memory_bytes: 3628
import sys

K = int(input())

NLUNLUN = [[-1 for _ in range(11)] for _ in range(10)]
def num_lunlun(n, digit):
    if digit == 1:
        NLUNLUN[n][digit] = 1
        return NLUNLUN[n][digit]

    if digit == 2:
        if 0 < n < 9:
            NLUNLUN[n][digit] = 3
        else:
            NLUNLUN[n][digit] = 2
        return NLUNLUN[n][digit]

    n2 = 0
    if n - 1 >= 0:
        n2 += NLUNLUN[n-1][digit-1]
    n2 += NLUNLUN[n][digit-1]
    if n + 1 <= 9:
        n2 += NLUNLUN[n+1][digit-1]
    NLUNLUN[n][digit] = n2
    return NLUNLUN[n][digit]


if K < 10:
    print(K)
    sys.exit(0)

k = 0
for digit in range(1, 11):
    for n in range(10):
        tmp = num_lunlun(n, digit)
        if n > 0:
            if k + tmp >= K:
                ans = str(n)
                n2 = n
                for digit2 in range(digit-1, 1, -1):
                    if n2 - 1 >= 0:
                        tmp = NLUNLUN[n2 - 1][digit2]
                        if k + tmp >= K:
                            ans += str(n2 - 1)
                            n2 -= 1
                            continue
                        k += tmp

                    tmp = NLUNLUN[n2][digit2]
                    if k + tmp >= K:
                        ans += str(n2)
                        continue
                    k += tmp

                    if n2 + 1 <= 9:
                        tmp = NLUNLUN[n2 + 1][digit2]
                        if k + tmp >= K:
                            ans += str(n2 + 1)
                            n2 += 1
                            continue
                        k += tmp

                if ans[-1] == '0':
                    ans = int(ans + str(n2 + K - k - 1))
                else:
                    ans = int(ans + str(n2 + K - k - 2))
                print(ans)

                sys.exit(0)
            k += tmp


Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cctype>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long LL;
int inv[46000];
char ch[256];
int term(int p);
int primary_expression(int p);

int pow_2(int a,int n,int p) {
	int x=1;
	while(n>0) {
		if(n&1) x=(x*a)%p;
		a=(a*a)%p;
		n>>=1;
	}
	return x;
}
enum TokenType {
	INT=1,ADD,SUB,MUL,DIV,LP,RP,END
};
struct Token{
	TokenType type;
	int value;
};
vector<Token> V;
bool get_token(void) {
	char ch;
	while((ch=getchar())==' ') {}
	Token tkn;
	if(ch=='\n'||ch=='\0') {
		tkn.type=END;
	}else if(ch=='+') {
		tkn.type=ADD;
	}else if(ch=='-') {
		tkn.type=SUB;
	}else if(ch=='*') {
		tkn.type=MUL;
	}else if(ch=='/') {
		tkn.type=DIV;
	}else if(ch=='(') {
		tkn.type=LP;
	}else if(ch==')') {
		tkn.type=RP;
	}else {
		tkn.type=INT;
		int value=0;
		do {
			value*=10;
			value+=(ch-'0');
		}while(isdigit(ch=getchar()));
		ungetc(ch,stdin);
		tkn.value=value;
	}
	V.push_back(tkn);
	return(tkn.type!=END);
}
int pos=0;
int expression(int p) {
	int val1=term(p),val2;
	while(V[pos].type==ADD||V[pos].type==SUB) {
		TokenType type=V[pos].type;
		pos++;
		val2=term(p);
		if(val1==-1||val2==-1) return -1;
		if(type==ADD) {
			val1=(val1+val2)%p;
		}else {
			val1=(val1-val2+p)%p;
		}
	}
	return val1;
}
int term(int p) {
	int val1=primary_expression(p),val2;
	while(V[pos].type==MUL||V[pos].type==DIV) {
		TokenType type=V[pos].type;
		pos++;
		val2=primary_expression(p);
		if(val1==-1||val2==-1) return -1;
		if(type==MUL) {
			val1=(val1*val2)%p;
		}else {
			if(val2==0) return -1;
			val1=(val1*inv[val2])%p;
		}
	}
	return val1;
}
int primary_expression(int p) {
	int value;
	if(V[pos].type==INT) {
		value=V[pos].value;
	}else if(V[pos].type==LP) {
		pos++;
		value=expression(p);
	}
	pos++;
	return value;
}
int main() {
	int p;
	ch[ADD]='+';
	ch[SUB]='-';
	ch[MUL]='*';
	ch[DIV]='/';
	ch[LP]='(';
	ch[RP]=')';
	while(scanf("%d:",&p),p) {
		for(int i=1;i<p;i++) inv[i]=pow_2(i,p-2,p);
		V.clear();
		while(get_token()) {}
		pos=0;
		int val=expression(p);
		if(val==-1) {printf("NG\n"); continue;}
		for(int i=0;i+1<V.size();i++) {
			if(V[i].type==INT) {
				printf("%d",V[i].value);
			}else {
				putchar(ch[V[i].type]);
			}
		}
		printf(" = %d (mod %d)\n",val,p);
	}
}

Measured memory_bytes: 1532
N = int(input())
D = [None] * N
for i in range(N):
    D[i] = list(map(int, input().split()))
for i in range(N-2):
    for j in range(3):
        if D[i+j][0] != D[i+j][1]:
            break
    else:
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 62328
import sys
import math
from itertools import accumulate as acc
input=sys.stdin.readline
N=int(input())
a=[[0,0,0]]+[list(map(int,input().split())) for i in range(N)]

for i in range(N):
    dt,dx,dy=[a[i+1][j]-a[i][j] for j in range(3)]
    if abs(dx)+abs(dy)>dt or (abs(dx)+abs(dy)-dt)%2!=0: print("No"),sys.exit()
print("Yes")

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

using UM = unordered_multimap<ll, ll>;

void f(ll node, ll current_score, vector<ll>& counter, const UM& tree, const vector<ll>& scores)
{
    if (counter[node - 1] != -1) {
        return;
    }

    current_score += scores[node - 1];
    counter[node - 1] = current_score;

    auto range_it = tree.equal_range(node);
    while (range_it.first != range_it.second) {
        f(range_it.first->second, current_score, counter, tree, scores);
        range_it.first++;
    }
}

// 再帰の代わりにキューを使用するバージョン
vector<ll> g(int N, const UM& tree, const vector<ll>& scores)
{
    vector<ll> counter(N, -1);

    queue<pair<ll, ll>> que;
    que.emplace(1, 0); // 初期ノード

    while (!que.empty()) {
        auto q = que.front();
        que.pop();
        auto node = q.first;
        auto score = q.second;
        score += scores[node - 1];
        counter[node - 1] = score;

        auto range_it = tree.equal_range(node);
        while (range_it.first != range_it.second) {
            auto next_node = range_it.first->second;
            if (counter[next_node - 1] == -1)  {
                que.emplace(next_node, score);
            }
            range_it.first++;
        }
    }

    replace(begin(counter), end(counter), -1, 0);
    return counter;
}

void solve(long long N, long long Q, std::vector<long long>&& a, std::vector<long long>&& b, std::vector<long long>&& p, std::vector<long long>&& x)
{
    UM tree;
    for (ll i = 0; i < N - 1; ++i) {
        tree.emplace(a[i], b[i]);
        tree.emplace(b[i], a[i]);
    }

    vector<ll> scores(N);
    for (ll i = 0; i < Q; ++i) {
        scores[p[i] - 1] += x[i];
    }

    //vector<ll> counter(N, -1);
    //f(1, 0, counter, tree, scores);
    // replace(begin(counter), end(counter), -1, 0);
    auto counter = g(N, tree, scores);
    copy(begin(counter), end(counter), ostream_iterator<ll>(cout, " "));
    cout << "\n";
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    std::vector<long long> p(Q);
    std::vector<long long> x(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&p[i]);
        scanf("%lld",&x[i]);
    }
    solve(N, Q, std::move(a), std::move(b), std::move(p), std::move(x));
    return 0;
}


Measured memory_bytes: 31476
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
pre = -1

for target in A:
  ans += B[target-1]
  if(pre == -1):
    pre = target
    continue
  if(pre + 1 == target):
    ans += C[pre - 1]
  pre = target
print(ans)

Measured memory_bytes: 38384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();

    int cou = 0;
    ll ans = 0;
    for(int i = n-1; i >= 0; i--) {
        if(s[i] == 'B') {
            ans += cou;
        } else {
            cou++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3732
#include <iostream>

#define A 0
#define B 1
#define AB 2
#define O 3
using namespace std;

int main(){
	string str;

	int num;
	int data[4];
	for(int i=0;i<4;i++){
		data[i]=0;
	}
	while(cin>>num){
		if(num==0){
			break;
		}
		cin.ignore();
		cin>>str;
		if(str == "A"){
			data[A]++;
		}
		else if(str == "B"){
			data[B]++;
		}
		else if(str == "O"){
			data[O]++;
		}
		else{
			data[AB]++;
		}
	}

	for(int i=0;i<4;i++){
		cout<<data[i]<<endl;
	}
	return 0;

}

/*
Sample Input
1,B
2,A
3,B
4,AB
5,B
6,O
7,A
8,O
9,AB
10,A
11,A
12,B
13,AB
14,A
Output for the Sample Input
5
4
3
2
*/

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i) >> B.at(i);
  }
  int64_t ans = 0;
  for (int i = N - 1; i >= 0; i--) {
    if ((A.at(i) + ans) % B.at(i) != 0) {
      ans += B.at(i) - (A.at(i) + ans) % B.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
#include<unordered_map>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(int i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
/* Coding Space*/
map<char,int> m;
int main(){
  int w,h; cin >> w >> h;
  vector<tii> v;
  rep(i,w){
    int p; cin >> p;
    v.pb(tii{p,0});
  }
  rep(i,h){
    int q; cin >> q;
    v.pb(tii{q,1});
  }
  ll ans = 0;
  sort(ALL(v));
  rep(i,(int)v.size()){
    ll c,type; tie(c,type) = v[i];
    if(type == 0){
      ans += 1LL*(h+1)*c;
      w--;
    }else{
      ans += 1LL*(w+1)*c;
      h--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
int n, m, x;
vector<int> a;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

void solve() {
    cin >> n >> m >> x;
    a.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    int large_cnt = 0;
    int small_cnt = 0;
    for (int i = 0; i < m; ++i) {
        if (x <= a[i]) {
            small_cnt++;
        } else {
            large_cnt++;
        }
    }
    cout << min(small_cnt, large_cnt) << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int64;
const int64 INF = 1LL << 58;
 
typedef tuple< int64, int, int, bool > Pi;
 
#define rep(i, n) for(int i = 0; i < n; i++)
 
struct edge
{
  int to, cost;
};
 
int64 v[500][51][2];
int N, M, V, A, B, C;
vector< edge > g[500];
 
int main()
{
 
 
  cin >> N >> M;
  rep(i, M) {
    int x, y, t;
    cin >> x >> y >> t;
    --x, --y;
    g[x].push_back((edge) {y, t});
    g[y].push_back((edge) {x, t});
  }
  cin >> V;
  cin >> A >> B >> C;
 
  fill_n(**v, 500 * 51 * 2, INF);
  v[0][V][0] = 0;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.emplace(0, 0, V, false);
 
  while(!que.empty()) {
    int64 cost;
    int now, vv;
    bool flag;
    tie(cost, now, vv, flag) = que.top();
    que.pop();
 
    if(flag && now == 0) {
      cout << cost << endl;
      return (0);
    }
 
    for(auto &e : g[now]) {
 
      int64 nxtcost = cost + 1LL * vv * e.cost;
      int nxtvv = (A * vv + B) % C;
      bool nxtfg = flag | (e.to == N - 1);
 
      if(nxtcost < v[e.to][nxtvv][nxtfg]) {
        v[e.to][nxtvv][nxtfg] = nxtcost;
        que.emplace(nxtcost, e.to, nxtvv, nxtfg);
      }
 
    }
  }
}

Measured memory_bytes: 9696