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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll dp[85][85][14000];

int main()
{
    cout << fixed << setprecision(15);
    ll H, W;
    cin >> H >> W;

    vector<vector<ll>> A(H+1, vector<ll>(W+1, 0));
    vector<vector<ll>> B(H+1, vector<ll>(W+1, 0));

    for(ll i=1; i<=H; i++){
        for(ll j=1; j<=W; j++){
            cin >> A[i][j];
        }
    }

    for(ll i=1; i<=H; i++){
        for(ll j=1; j<=W; j++){
            cin >> B[i][j];
        }
    }

    Fill(dp, 0);

    ll a = A[1][1];
    ll b = B[1][1];

    dp[1][1][abs(a-b)] = 1;

    for(ll i=1; i<=H; i++){
        for(ll j=1; j<=W; j++){
            REP(k, 13000){
                a = A[i][j];
                b = B[i][j];
                
                dp[i][j][abs(k+abs(a-b))] = max(dp[i][j][abs(k+abs(a-b))], dp[i-1][j][k]);
                dp[i][j][abs(k-abs(a-b))] = max(dp[i][j][abs(k-abs(a-b))], dp[i-1][j][k]);

                dp[i][j][abs(k+abs(a-b))] = max(dp[i][j][abs(k+abs(a-b))], dp[i][j-1][k]);
                dp[i][j][abs(k-abs(a-b))] = max(dp[i][j][abs(k-abs(a-b))], dp[i][j-1][k]);        
            }
        }
    }

    // REP(i, H+1){
    //     REP(j, W+1){
    //         cout << dp[i][j][0];
    //     }
    //     cout << endl;
    // }
    REP(k, 13000){
        // cout << dp[H][W][k] << endl;
        if(dp[H][W][k]){
            cout << k << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 793964
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int i, n;
    short a[101];
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    if (n >= 1) printf("%d", a[n - 1]);
    for (i = n - 2; i >= 0; i--) printf(" %d", a[i]);
    putchar('\n');
    return 0;
}




Measured memory_bytes: 2144
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;

int main(){
  int A, B; cin >> A >> B;
  int ans = 0;
  for(int i = A; i <= B; i++){
    string s = to_string(i);
    string tmp = s;
    reverse(s.begin(), s.end());
    if(tmp == s) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


const int MAX_N=200010;
int n,dat[4*MAX_N-1];
int Seg_init(int n_){
    n=1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;++i)dat[i]=0;
    return n;
}
int Seg_calc(int a,int b){
    return (a+b)%3;
}
void Seg_update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=Seg_calc(dat[2*k+1],dat[2*k+2]);
    }
}
/*
int Seg_query(int a,int b,int k,int l,int r){
    cout << a MM b MM k MM l MM r << endl;
    //外からはSeg_query(a,b,0,0,n)で呼ぶ
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b)return dat[k];
    int vl=Seg_query(a,b,2*k+1,l,(l+r)/2);
    int vr=Seg_query(a,b,2*k+2,(l+r)/2,r);
    return Seg_calc(vl,vr);
}*/
/*
int Seg_query(int a,int b){
    vector<pair<pair<int,int>,int>> G;
    G.push_back({{0,n},0});
    int R=0;
    
    while(!G.empty()){
        int l=G.back().first.first;
        int r=G.back().first.second;
        int k=G.back().second;
        //cout << l MM r MM k;
        G.pop_back();
        if(r<=a||b<=l)continue;
        if(a<=l&&r<=b){R=Seg_calc(R,dat[k]);continue;}
        G.push_back({{l,(l+r)/2},2*k+1});
        G.push_back({{(l+r)/2,r},2*k+2});
    }
    
    return R;
}*/

int Seg_query(int a,int b){
    a += n;
    b += n;
    int R = 0;
    while(a < b){
        if(a % 2 == 1){
            R = Seg_calc(R, dat[a - 1]);
            a += 1;
        }
        a /= 2;
        if(b % 2 == 1){
            b -= 1;
            R = Seg_calc(R, dat[b - 1]);
        }
        b /= 2;
    }
    return R;
}

signed main(void){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    string S,T;
    int Q;
    int A[114514],B[114514],C[114514],D[114514];
    int G[114514],H[114514];
    
    cin >> S >> T;
    cin >> Q;
    REP(i,Q){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;B[i]--;C[i]--;D[i]--;
    }
    
    //Aを1、Bを2、O(=AB)を0と扱う
    
    //Sをセグる
    Seg_init(S.size());
    REP(i,S.size()){
        Seg_update(i,(S[i]=='A'?1:2));
    }
    REP(i,Q){
        G[i]=Seg_query(A[i],B[i]+1);
    }
    //Tをセグる
    Seg_init(T.size());
    REP(i,T.size()){
        Seg_update(i,(T[i]=='A'?1:2));
    }
    REP(i,Q){
        H[i]=Seg_query(C[i],D[i]+1);
    }
    
    //REP(i,Q){cout << G[i] MM H[i] << endl;}
    
    REP(i,Q){
        if(G[i]==H[i]){
            cout << "YES" << '\n';
        }else{
            cout << "NO" << '\n';
        }
    }
    
    return 0;
}



Measured memory_bytes: 10192
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#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 _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

signed main() {
  int h,a;cin>>h>>a;
  cout << divceil(h, a) << endl;
  return 0;
}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
ll h, w, d[55][55];
char s[55][55];
ll dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
void bfs() {
  rep(i, 55) rep(j, 55) d[i][j] = -1;
  d[0][0] = 0;
  queue<P> q;
  q.push(P(0, 0));
  while(!q.empty()) {
    P p = q.front(); q.pop();
    rep(i, 4) {
      ll nx = p.first + dx[i], ny = p.second + dy[i];
      if(0 <= nx && nx < h && 0 <= ny && ny < w && d[nx][ny] == -1 && s[nx][ny] == '.') {
        d[nx][ny] = d[p.first][p.second] + 1;
        q.push(P(nx, ny));
      }
    }
  }
}

signed main() {
	ll cnt = 0;
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> s[i][j];
  bfs();
  rep(i, h) rep(j, w) if(s[i][j] == '#') cnt++;
  h--, w--;
  if(d[h][w] == -1) {
    cout << "-1" << endl;
    return 0;
  }
  cout << (h + 1) * (w + 1) - d[h][w] - cnt - 1 << endl;
	return 0;
}

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

using ll = long long;
using pint = pair<int, int>;

const ll INF = 1e12;
const ll MOD = 1e9 + 7;

ll N, Q;
string S;
vector<pint> q;

int main()
{
    cin >> N >> Q;
    q.resize(Q);
    cin >> S;
    for (int i = 0; i < Q; ++i)
    {
        cin >> q[i].first >> q[i].second;
        q[i].first;
        q[i].second;
    }

    vector<int> sum(N + 1);
    for (int i = 2; i <= N; ++i)
    {
        sum[i] = sum[i - 1];
        if (S[i - 2] == 'A' && S[i - 1] == 'C')
        {
            sum[i]++;
        }
    }

    for (auto p : q)
    {
        cout << sum[p.second] - sum[p.first] << endl;
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 int x,y,z;
 cin >> x >> y >> z;
 int cnt;
 cnt=(x-z)/(y+z);
cout << cnt << endl;
 
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  
	char c;
  	cin >> c;
  	c++;
  	cout << c << endl;
  	return 0;
}

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

int main () {
  int N, K; cin >> N >> K;
  
  int a[N];
  for (int i=0; i<N; i++)	cin >> a[i];
  sort(a, a+N, greater<int>());
  
  int ans =0;
  for (int i=0; i<K; i++) {
    ans += a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void query1(const int &p, const char &c, vector<set<int>> &a) {
	for (int i = 0; i < 26; i++) {
		auto itr = a[i].find(p);
		if (itr != a[i].end()) {
			a[i].erase(itr);
			break;
		}
	}
	a[c - 'a'].insert(p);
}
void query2(const int &l, const int &r, const vector<set<int>> &a) {
	int cnt = 0;
	for (int i = 0; i < 26; i++) {
		auto itr = a[i].lower_bound(l);
		if (itr != a[i].end()) {
			if (itr != a[i].end()) {
				if (*itr <= r) cnt++;
			}
		}
	}
	printf("%d\n", cnt);
}
int main() {
	int n;
	scanf("%d", &n);
	char s[n];
	scanf("%s", s);
	vector<set<int>> a(26);
	for (int i = 0; i < n; i++) a[s[i] - 'a'].insert(i);
	int q;
	scanf("%d", &q);
	while (q--) {
		int p;
		scanf("%d", &p);
		if (p == 1) {
			int i;
			char c;
			scanf("%d %c", &i, &c);
			query1(i - 1, c, a);
		} else {
			int l, r;
			scanf("%d%d", &l, &r);
			query2(l - 1, r - 1, a);
		}
	}
	return 0;
}

Measured memory_bytes: 24192
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define size 5005
const long MOD = 1e9+7;
bool dp[size];
int A[size];
pair<int,int>pos[size];
signed main()
{
    long test;
    test=1;
    // cin>>test;
    while(test--){
    long i,j,b,n,x,k,ans,most,index,c,maxi=0,temp,aw,bw,w,count,sum;
    cin>>n>>k;
    for(i=0;i<n;i++)cin>>A[i];
    sort(A,A+n);
    sum=0;
    for(i=0;i<n;i++)sum+=A[i];
    memset(dp,false,sizeof(dp));
    dp[0]=true;
    int ret=0;
    for(i=n-1;i>=0;i--)
    {
        bool up=false;
        for(j=0;j<k;j++)
        {
            if(dp[j] && j+sum>=k)up=true;
        }
        if(!up)ret++;
        sum-=A[i];
        for(j=k-1;j>=A[i];j--)
        {
            dp[j]|=dp[j-A[i]];
        }
    }
    cout<<ret;
    
    
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

int main() {


	int H, W, D; cin >> H >> W >> D;

	int max_d = 1500;
	vector<vector<char>>field(9 * max_d, vector<char>(9 * max_d, 'K'));

	if (D % 2) {
		int k = D / 2 + 1;
		int c = 0;

		int sx = max_d;
		int sy = 7 * max_d;

		while (sx <= 8 * max_d&&sx >= max_d && sy <= 8 * max_d&&sy >= max_d) {
			sx += k - 1;
			sy -= k;

			c = c ^ 2;

			int nx = sx;
			int ny = sy;

			int nc = c;
			while (nx <= 8 * max_d&&nx >= max_d && ny <= 8 * max_d&&ny >= max_d) {
				c = c ^ 1;
				nx += k;
				ny += k - 1;
				//cout << "x:" << nx << "y:" << ny << endl;
				int w = -1;
				for (int h = -k + 1; h <= k - 1; ++h) {
					if (h <= 0)w += 1;
					else w -= 1;
					for (int x = -w; x <= w; ++x) {

						assert(field[ny + h][nx + x] == 'K');
						field[ny + h][nx + x] = c;
					}
				}
			}
			c = nc;
		}
	}
	else {
		int k = D / 2;
		int c = 0;

		int sx = max_d;
		int sy = 7 * max_d;

		while (sx <= 8 * max_d&&sx >= max_d && sy <= 8 * max_d&&sy >= max_d) {
			sx += k;
			sy -= k;

			c = c ^ 2;

			int nx = sx;
			int ny = sy;
			int nc = c;
			while (nx <= 8 * max_d&&nx >= max_d && ny <= 8 * max_d&&ny >= max_d) {
				c = c ^ 1;
				nx += k;
				ny += k;
				//cout << "x:" << nx << "y:" << ny << endl;
				int w = -1;
				for (int h = -k + 1; h <= k - 1; ++h) {
					if (h <= 0)w += 1;
					else w -= 1;
					for (int x = -w; x <= w; ++x) {
						if ((h + x+1000000) % 2!=k%2) {

							assert(field[ny + h][nx + x] == 'K');
							field[ny + h][nx + x] = c;
						}
						
					}
				}
			}
			c = nc;
		}
		sx = max_d;
		sy = 7 * max_d - 1;
		while (sx <= 8 * max_d&&sx >= max_d && sy <= 8 * max_d&&sy >= max_d) {
			sx += k;
			sy -= k;

			c = c ^ 2;

			int nx = sx;
			int ny = sy;

			int nc = c;
			while (nx <= 8 * max_d&&nx >= max_d && ny <= 8 * max_d&&ny >= max_d) {
				c = c ^ 1;
				nx += k;
				ny += k;
				//cout << "x:" << nx << "y:" << ny << endl;
				int w = -1;
				for (int h = -k + 1; h <= k - 1; ++h) {
					if (h <= 0)w += 1;
					else w -= 1;
					for (int x = -w; x <= w; ++x) {
						if ((h + x+1000000) % 2!=k%2) {

							assert(field[ny + h][nx + x] == 'K');
							field[ny + h][nx + x] = c;
						}
					}
				}
			}
			c = nc;
		}
	}

	string c_mp("RYGB");
	int ay = 4 * max_d + max_d / 2-H/2;
	int ax = 4 * max_d + max_d / 2 - W / 2;
	for (int y = ay; y <ay+ H; ++y) {
		for (int x =ax; x <ax+W; ++x) {
			assert(field[y][x] != 'K');
			cout << c_mp[field[y][x]];

		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 180864
// Gaurav Aggarwal

/*
useful stl
array<ll,size> ar;         //size(),front(),back(),fill(),empty()
deque<ll> d                //push_back(),push_front(),pop_front(),pop_back()
vector<ll> v(size,val);    //push_back(),*max_element(v.begin(),v.end()),accumulate(v.begin(),v.end(),0)
stack<ll> g;               //push(),pop(),top(),size(),empty()         LIFO
queue<ll> q;               //push(),size(),front(),back(),empty()      FIFO
priority_queue<ll> pq
*/

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

typedef long long ll;
typedef pair<ll,ll> ipair;
typedef pair<long,long> lpair;
typedef pair<double,double> pdd;
#define scan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884 
#define debug1(a) cout<<a<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug_arr(a,n) {for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}}
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define beg_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {a[i] = 0;}

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}


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

    int a[5],k;
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>k;
    sort(a,a+5);

    if(abs(a[4]-a[0]) > k) {
        cout<<":(";
    }
    else
        cout<<"Yay!";


    return 0;
}

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

vector<int> pa, pb;

int find_roota(int x) {
  if (pa[x] != x) pa[x] = find_roota(pa[x]);
  return pa[x];
}

void unitea(int x, int y) {
  int nx = find_roota(x);
  int ny = find_roota(y);
  if (nx == ny) return;
  else if (nx > ny) pa[nx] = ny;
  else pa[ny] = nx;
}

int find_rootb(int x) {
  if (pb[x] != x) pb[x] = find_rootb(pb[x]);
  return pb[x];
}

void uniteb(int x, int y) {
  int nx = find_rootb(x);
  int ny = find_rootb(y);
  if (nx == ny) return;
  else if (nx > ny) pb[nx] = ny;
  else pb[ny] = nx;
}

int main() {
  int n, k, l;
  cin >> n >> k >> l;

  pa = vector<int>(n);
  pb = vector<int>(n);
  for (int i = 0; i < n; i ++) pa[i] = pb[i]= i;
  for (int i = 0; i < k; i ++) {
    int x, y;
    cin >> x >> y;
    x --, y --;
    unitea(pa[x], pa[y]);
  }
  for (int i = 0; i < l; i ++) {
    int x, y;
    cin >> x >> y;
    x --, y --;
    uniteb(pb[x], pb[y]);
  }
  for (int i = 0; i < n; i ++) {
    find_roota(i);
    find_rootb(i);
  }
  
  map<pair<int, int>, int> mp;
  for (int i = 0; i < n; i ++) mp[make_pair(pa[i], pb[i])] ++;

  for (int i = 0; i < n; i ++) {
    if (i) cout << " ";
    cout << mp[make_pair(pa[i], pb[i])];
  }
  cout << endl;
}

Measured memory_bytes: 13568
import sys
input = sys.stdin.readline
from collections import Counter



def main():
    N = int(input())
    V = [int(x) for x in input().split()]

    a = []
    b = []
    for i in range(N):
        if i & 1:
            a.append(V[i])
        else:
            b.append(V[i])

    ac = Counter(a)
    bc = Counter(b)

    acm = ac.most_common()
    bcm = bc.most_common()

    if acm[0][0] != bcm[0][0]:
        print(N // 2 - acm[0][1] + N // 2 - bcm[0][1])
    else:
        ans = float("inf")
        for i in acm:
            if i[0] == bcm[0][0]:
                continue
            ans = min(ans, N // 2 - i[1] + N // 2 - bcm[0][1])

        for j in bcm:
            if acm[0][0] == j[0]:
                continue
            ans = min(ans, N // 2 - j[1] + N // 2 - acm[0][1])
        if ans == float("inf"):
            print(N // 2)
        else:
            print(ans)


if __name__ == '__main__':
    main()



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

int main(){
  long long H, N;
  cin >> H >> N;
  vector<long long> atk(N);
  for (int i = 0; i < N; i++){
    cin >> atk.at(i);
  }
  
  long long ATK = 0;
  
  for (int i = 0; i < N; i++){
    ATK += atk.at(i);
  }
  
  if (ATK >= H){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
    


Measured memory_bytes: 4000
H, W, K = map(int,input().split())
G = []
for _ in range(H):
	S = list(input())
	G.append(S)

def int2bit(n, l):
	bit = [0 for i in range(l)]
	i = 0
	while n > 0:
		bit[i] = n % 2
		n = n // 2
		i += 1
	return bit

ans = 0
for h in range(2**H):
	ph = int2bit(h, H)
	for w in range(2**W):
		pw = int2bit(w, W)
		paint = [[(ph[i] == 1 or pw[j] == 1) for j in range(W)] for i in range(H)]
		cnt = 0
		for i in range(H):
			for j in range(W):
				if not paint[i][j] and G[i][j] == "#":
					cnt += 1
		if cnt == K:
			ans += 1
print(ans)

Measured memory_bytes: 9276
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int ans = 0;
	size_t N, K, tmp;
	cin >> N >> K;
	vector<int> A(N);
	for (size_t i = 0; i < N; ++i) {
		cin >> tmp;
		++A[tmp - 1];
	}
	sort(A.begin(), A.end());
	for (size_t i = 0; i < N - K; ++i) ans += A[i];
	cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define pll pair<ll,ll>
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"
ll mod;
inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){return (a%b==0)?(a/b):(a/b+1);}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    for(auto v : V) os << v <<"  ";
    return os;
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") ";
    return os<<"}";
}
struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        return p1.first<p2.first;
    }
};


int main(){
	fio;	
	ll n;cin>>n;
	ll a1;cin>>a1;
	cin>>mod;
	ll ans=a1;
	map<ll,ll> mp,pre,revmp;
	mp[1]=a1;pre[1]=a1;revmp[a1]=1;
	for(ll i=2;i<=n;i++){
		ll prev=a1;		
		a1=mul(a1,a1);
		if(revmp.find(a1)!=revmp.end()){
			ll pos=revmp[a1];
			ll size=i-pos;
			ll rem=n-i+1;
			ll temp=pre[i-1]-pre[pos-1];
			ans+=(rem/size)*temp;
			ll curr;
			if(rem%size==0){
				curr=0;
				break;
			}else{
				for(ll j=0;j<rem%size;j++){
					prev=mul(prev,prev);
					ans+=prev;
				}
				break;
			}
		}else{
			ans+=a1;
			pre[i]=pre[i-1]+a1;
			revmp[a1]=i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 9780
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#define lowbit(x) (x&(-x))
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define drep(i,x,y) for(int i=x;i>=y;i--)
#define repg(i,x) for(int i=p[x];i;i=e[i].nt)  
using namespace std;
typedef long long LL;
LL read(){
	LL rtn=0;char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	while(ch<='9'&&ch>='0')rtn=(rtn<<3)+(rtn<<1)+ch-'0',ch=getchar();
	return rtn;
}
const int N=200010;
int a[N],n; 
int main(){
#ifdef WK
	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif
	n=read();
	rep(i,1,n)a[i]=read();
	if(n%2==0){
		for(int i=n;i;i-=2)printf("%d ",a[i]);
		for(int i=1;i<=n;i+=2)printf("%d ",a[i]);
	}else{
		for(int i=n;i>0;i-=2)printf("%d ",a[i]);
		for(int i=2;i<=n;i+=2)printf("%d ",a[i]);
	}
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define for1(i,n) for(int i=1;i<=(int)(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=20000001;
int n,x,y;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n,m;
      cin>>n>>m;
      map<int,int> ma;
      for(int i=0;i<m;i++)
      {
            int x;
            cin>>x;
            ma[x]++;
      }
      int dp[n+1];
      for(int i=0;i<=n;i++) dp[i]=0;
      dp[0]=1;
      for(int i=1;i<=n;i++)
      {
            if(ma[i]) continue;
            if(i-1>=0&&ma[i-1]==0)
            {
                  dp[i]+=dp[i-1];
                  dp[i]%=MOD;
            }
            if(i-2>=0&&ma[i-2]==0)
            {
                  dp[i]+=dp[i-2];
                  dp[i]%=MOD;
            }
      }
      cout<<dp[n];
}
// nothing is impossible

Measured memory_bytes: 7296
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    l=[]
    for i in range(n):
        t = int(sys.stdin.readline())
        l.append(t)

    print(reduce(lcm,l))




Measured memory_bytes: 5092
#include <iostream>
#include <vector>
#define X second
#define Y first
#define A 26
#define N 500
using namespace std;
typedef pair<int,int> P;
vector<P> v[A];
string s[N];
int m,n,ans;
bool used[A],erased[A];

bool func(int x){
  if(!v[x].size()) return false;
  if(used[x]) return false;
  used[x]=true;
  int y1=v[x][0].Y,x1=v[x][0].X,y2=v[x][1].Y,x2=v[x][1].X;
  int f=0,fa=1,fb=1,fc=1,fd=1;
  if(x1>x2) swap(x1,x2),f=1;
  for(int i=x1;i<=x2;i++){
    char c=s[y1][i];
    int nx=c-'A';
    if(nx==x) continue;
    if(c!='.'&&!erased[nx]&&!func(nx)) fa=0;
  }
  for(int i=y1;i<=y2;i++){
    char c=s[i][x1];
    int nx=c-'A';
    if(nx==x) continue;
    if(c!='.'&&!erased[nx]&&!func(nx)) fb=0;
  }
  for(int i=x1;i<=x2;i++){
    char c=s[y2][i];
    int nx=c-'A';
    if(nx==x) continue;
    if(c!='.'&&!erased[nx]&&!func(nx)) fc=0;
  }
  for(int i=y1;i<=y2;i++){
    char c=s[i][x2];
    int nx=c-'A';
    if(nx==x) continue;
    if(c!='.'&&!erased[nx]&&!func(nx)) fd=0;
  }
  if(!f) f=(fa&fd)|(fb&fc);
  else f=(fa&fb)|(fc&fd);
  if((y1==y2&&x1+1==x2)||(x1==x2&&y1+1==y2)) f=0;
  if(!f) return false;
  erased[x]=true;
  return true;
}

int main(){
  cin>>m>>n;
  for(int i=0;i<m;i++) cin>>s[i];
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
      if(s[i][j]!='.') v[s[i][j]-'A'].push_back(P(i,j));
  for(int i=0;i<A;i++){
    for(int j=0;j<A;j++) used[j]=false;
    func(i);
  }
  for(int i=0;i<A;i++) ans+=erased[i]*2;
  cout<<ans<<endl;
  return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long a, b, c; cin >> a >> b >> c;
    long long d = c - a - b;
    if (d < 0) {
        cout << "No\n";
    } else {
        d *= d;
        long long e = a * b * 4;
        if (e < d) {
            cout << "Yes\n";
        } else cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
typedef long long ll;

int main()
{

	string moji;
	int n; cin >> n;
	vector<int>a(10000);
	REP(i, 1000) { a[i] = 1; }
	REP(i, n) {
		char gomi;
		cin >> gomi; moji += gomi;
		if (gomi == '(') {
			a[i] = 1;
		}
		else {
			a[i] = 0;
		}
	}
	int sii = moji.size();
	while (1) {
		int c = 0;
		REP(i, n - 1) {

			if (a[i] == 1 && a[i + 1] == 0) {
				a.erase(a.begin() + i, a.begin() + i + 2);
				sii -= 2;
				c++;
				break;
			}
		}
		if (c == 0) {
			REP(i, sii) {
				int aa = a[i];
				if (aa) {
					moji = moji + ')';
				}
				else {
					moji = '(' + moji;
				}
			}
			break;
		}
	}
	cout << moji << endl;
	return 0;
}

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

void solve() {
    string S;
    cin >> S;
    ll n = S.size();
    vector<ll> L(n), R(n);
    ll c;
    for ( int i = 0; i < n; i++ ) {
        if ( S[i] == 'R' ) {
            c = 0;
        } else {
            c++;
            L[i] = c;
        }
    }
    for ( int i = n-1; i >= 0; i-- ) {
        if ( S[i] == 'L' ) {
            c = 0;
        } else {
            c++;
            R[i] = c;
        }
    }

    vector<ll> num(n);
    for ( int i = 0; i < n; i++ ) {
        if ( S[i] == 'R' ) {
            ll x = i + R[i];
            if ( R[i] % 2 == 1 ) x--;
            num[x]++;
        } else {
            ll x = i - L[i];
            if ( L[i] % 2 == 1 ) x++;
            num[x]++;
        }
    }

    for ( int i = 0; i < n; i++ ) {
        cout << num[i] << " ";
    }
    cout << "\n";
}

int main() {
    solve();
    return 0;
}

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

using namespace std;

 int arr[1000000];

int main()

{

     int n;
     cin>>n;



     for(int i=0;i<n;i++)
     {
         cin>>arr[i];
     }

     int k = 1;

     for(int i=0;i<n;i++)
     {
         if(arr[i]==k)
         {
             k++;
         }
     }

     if(k==1)
        cout<<"-1"<<endl;
     else

      cout<<n-k+1<<endl;









    return 0;
}


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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
//RNG based on mersenne_twister 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

ll n;
ll dp[200005][2],a[200005];
ll solve(ll pos,ll rem)
{
	if(pos>=n)
	{
		if(rem==0)return 0;
		return -INF;
	}
	if(rem==0)
		return 0;
	if(rem>(n-pos+1)/2)
		return -INF;
	ll xx=(n-pos+1)/2-rem;
	if(dp[pos][xx]!=-INF)
		return dp[pos][xx];
	ll ans=-INF;
	ans=max(ans,solve(pos+2,rem-1)+a[pos]);
	ans=max(ans,solve(pos+1,rem));
	dp[pos][xx]=ans;
	return ans;

}
int _runtimeTerror_()
{
	cin>>n;
	ll i;
	for(i=0;i<n;++i)
		cin>>a[i];
	for(i=0;i<=n;++i)
		dp[i][0]=dp[i][1]=-INF;
	cout<<solve(0,n/2);
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	cerr<<"\n"<<_time_;
	return 0;
}


Measured memory_bytes: 14704
tot_sale = 0
sale_all_num = 0
n = 0
while True:
    try:
        tan, sale_num = map(int,raw_input().split(','))
    except EOFError:
        break

    tot_sale += tan * sale_num
    sale_all_num += sale_num
    n += 1
    
ave = int(round(float(sale_all_num) / float(n)))
print tot_sale
print ave

Measured memory_bytes: 4236
from sys import stdin


def main() -> None:
    dic = set()
    n = int(next_str())

    for i in range(n):
        dic.add(int(input()))

    print(len(dic))


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

int main(void){

  int K, X;
  cin >> K >> X;


  for (int i = -K + 1; i<= K - 1; ++i){
    int val = X + i;
    cout << val << " ";
  }



  return 0;
}



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

  int C = 100;
  int SC = 0;
  int A;
  
  for (int i = 0; i < N; i++) {
    SC = 0;
    cin >> A;
    while (A % 2 == 0) {
      SC++;
      A /= 2;
    }
    if (SC < C) {
    C = SC;
    }
  }   
  
  cout << C << endl;   

}

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

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N, A, B, C; cin >> N >> A >> B >> C;
	vector<string> s(N + 1);
	REP(i,N) cin >> s[i];
	s[N] = "";

	vector<char> res(N);
	REP(i,N) {
		if (s[i] == "AB") {
			if (A == 0) {
				A += 1;
				B -= 1;
				res[i] = 'A';
			} else if (B == 0) {
				A -= 1;
				B += 1;
				res[i] = 'B';
			} else {
				if (s[i + 1] == "AC") {
					A += 1;
					B -= 1;
					res[i] = 'A';
				} else {
					A -= 1;
					B += 1;
					res[i] = 'B';
				}
			}
			if (A < 0 || B < 0) {
				cout << "No" << endl;
				return;
			}
		} else if (s[i] == "AC") {
			if (A == 0) {
				A += 1;
				C -= 1;
				res[i] = 'A';
			} else if (C == 0) {
				A -= 1;
				C += 1;
				res[i] = 'C';
			} else {
				if (s[i + 1] == "AB") {
					A += 1;
					C -= 1;
					res[i] = 'A';
				} else {
					A -= 1;
					C += 1;
					res[i] = 'C';
				}
			}
			if (A < 0 || C < 0) {
				cout << "No" << endl;
				return;
			}
		} else if (s[i] == "BC") {
			if (B == 0) {
				B += 1;
				C -= 1;
				res[i] = 'B';
			} else if (C == 0) {
				B -= 1;
				C += 1;
				res[i] = 'C';
			} else {
				if (s[i + 1] == "AB") {
					B += 1;
					C -= 1;
					res[i] = 'B';
				} else {
					B -= 1;
					C += 1;
					res[i] = 'C';
				}
			}
			if (B < 0 || C < 0) {
				cout << "No" << endl;
				return;
			}
		}
	}

	cout << "Yes" << endl;
	REP(i,N) {
		cout << res[i] << endl;
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 6640
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  string s;
  cin>>s;
  int n=s.size();

  int ans=0;

  for(auto c:s){
    if(c=='o') ans++;
  }

  if( ans + (15-n) >= 8 ) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;

}


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

int main(){
  int N;
  cin>> N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>> A[i];
    --A[i];
  }
  vector<int>B(N);
  for(int i=0;i<N;i++){
    cin>> B[i];
  }
  vector<int>C(N-1);
  for(int i=0;i<N;i++){
    cin>> C[i];
  }
  int ans=0;
  for(int i=0;i<N;i++){
    ans +=B[A[i]];
    if(i>0&&A[i]==A[i-1]+1){
      ans +=C[A[i-1]];
    }
  }
  cout<< ans<< endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    char prev ='$';
    int result=0;
    for (int i = 0; i < S.length(); i++) {
      char c = S.charAt(i);
      if(c != prev) result++;
      prev =c;
    }

    System.out.println(result);
  }





}


Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=2e5+10;
typedef pair<int,int>pii;
pii e[mn];
vector<int>g[mn];
inline int gy(int x,int i){return x^e[i].first^e[i].second;}
int d[mn],o[mn],ro[mn],ans[mn];
int col[mn];
void die(){printf("-1");exit(0);}
set<int>s;
void dfs(int x){
    s.erase(x);
    for(int i:g[x]){
        int y=gy(x,i);
        if(s.find(y)!=s.end()){
            ans[i]=d[x];
            col[y]=col[x]^1;
            dfs(y);
        }
    }
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",d+i);
    for(int i=0;i<m;i++){
        scanf("%d%d",&e[i].first,&e[i].second);
        g[e[i].first].push_back(i);
        g[e[i].second].push_back(i);
        ans[i]=1e9;
    }
    for(int i=1;i<=n;i++)o[i]=i;
    sort(o+1,o+1+n,[](int a,int b){return d[a]<d[b];});
    memset(col,-1,sizeof(col));
    for(int i=1;i<=n;){
        int r;
        for(r=i;d[o[r]]==d[o[i]];r++);
        r--;
        s.clear();
        for(int j=i;j<=r;j++)s.insert(o[j]);
        stack<int>ed;
        for(int x:s){
            for(int k:g[x]){
                int y=gy(x,k);
                if(s.find(y)!=s.end())ed.push(k);
            }
        }
        for(int j=i;j<=r;j++){
            int x=o[j];
            if(s.find(x)==s.end())continue;
            for(int k:g[x]){
                int y=gy(x,k);
                if(col[y]!=-1){
                    ans[k]=d[x];
                    col[x]=col[y]^1;
                    dfs(x);
                    break;
                }
            }
        }
        while(s.size()){
            if(s.size()==1)die();
            while(ed.size()&&!(s.find(e[ed.top()].first)!=s.end()&&s.find(e[ed.top()].second)!=s.end()))ed.pop();
            if(ed.size()==0)die();
            int x=e[ed.top()].first;
            col[x]=0;
            dfs(x);
        }
        i=r+1;
    }
    for(int i=1;i<=n;i++)printf("%c",col[i]?'B':'W'),assert(col[i]==0||col[i]==1);
    for(int i=0;i<m;i++)printf("\n%d",ans[i]);
}

Measured memory_bytes: 17040
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,k = f()
    a = f()

    cnt = {}
    for i in a:
        if i in cnt:
            cnt[i] += 1
        else:
            cnt[i] = 1
    
    items = sorted(cnt.items(), key = lambda x: x[1], reverse = True)

    print(n - sum([i[1] for i in items[:k]]))

solve()


Measured memory_bytes: 39784
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,D; cin >> N >> D;
    int A[N][D];
    rep(i,N) rep(j,D) cin >> A[i][j];
    int ans=0;
    rep(i,N){
        rng(j,i+1,N){
            double sum=0;
            rep(k,D) sum+=(A[i][k]-A[j][k])*(A[i][k]-A[j][k]);
            if(ceil(sqrt(sum))==floor(sqrt(sum))) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

int N;
string S;

int main(){
    cin >> N >> S;
    vector<int> rc(N+5, 0), gc(N+5, 0), bc(N+5, 0);
    vector<int> r, g, b;
    rep(i, N) {
        rc[i+1] = rc[i];
        gc[i+1] = gc[i];
        bc[i+1] = bc[i];

        if (S[i] == 'R') {
            r.push_back(i+1);
            rc[i+1] = rc[i] + 1;
        }
        if (S[i] == 'G') {
            g.push_back(i+1);
            gc[i+1] = gc[i] + 1;
        }
        if (S[i] == 'B') {
            b.push_back(i+1);
            bc[i+1] = bc[i] + 1;
        }
    }

    vector<T> tp;
    ll ans = 0;
    for (int i=0; i<N-2; i++) {
        char si = S[i];
        for (int j=i+1; j<N-1; j++) {
            char sj = S[j];
            if (si == sj) continue;
            int bad = 2*j - i;
            if (j+1 <= bad && N-1 >= bad && S[bad] != si && S[bad] != sj) ans--;
            if (si != 'R' && sj != 'R') {
                ans += rc[N] - rc[j];
            }
            if (si != 'G' && sj != 'G') {
                ans += gc[N] - gc[j];
            }
            if (si != 'B' && sj != 'B') {
                ans += bc[N] - bc[j];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std ; 

int n , ar , a[ 60 ] ;
long long f[ 60 ][ 60 ][ 2510 ] ;
//选到i，选了j个，sum为k 

int main() {
	scanf( "%d%d" , &n , &ar ) ;
	for( int i = 1 ; i <= n ; i ++ ) {
		scanf( "%d" , &a[ i ] ) ;
	}
	
	f[ 0 ][ 0 ][ 0 ] = 1 ;
	
	for( int i = 1 ; i <= n ; i ++ ) {
		for( int j = i ; j >= 0 ; j -- ) {
			for( int k = ar * n + 1 ; k >= 0 ; k -- ) {
				f[ i ][ j ][ k ] += f[ i - 1 ][ j ][ k ] ; 
				if( k >= a[ i ] && j ) f[ i ][ j ][ k ] += f[ i - 1 ][ j - 1 ][ k - a[ i ] ] ;
			}
		}
	}
	long long ans = 0 ;
	for( int i = 1 ; i <= n ; i ++ ) {
		ans += f[ n ][ i ][ ar * i ] ;
	}
	printf( "%lld\n" , ans );
} 

Measured memory_bytes: 59648
a1= list(map(int,input().split()))
a2= list(map(int,input().split()))
a3= list(map(int,input().split()))
a = a1 + a2 + a3
 
n = int(input())
 
#bがaにあるか確認して0へ
for _ in range(n):
  b = int(input())
  if b in a:
    a[a.index(b)]=0
  
  
check = 0
for i in range(3):
  #縦横のbingo検索
  if (a[3*i]==a[3*i+1] and a[3*i+1]==a[3*i+2]) or (a[i]==a[i+3] and a[i+3]==a[i+6]):
        check+=1
#ななめ
if (a[0]==a[4] and a[4]==a[8]) or (a[2]==a[4] and a[4]==a[6]):
    check+=1
if check>0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
//NEVER GIVE UP I AM GOING TO IMPROVE ONE DAY.
//PRACTICE,PRACTICE,PRACTICE!!!
#include<bits/stdc++.h>
#define int long long int
// #define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e18
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); 
#define dbg(x)  cerr << #x << " = " << x << endl;
const int M=200000;
const double pi = acos(-1.0);
using namespace std;
// cout<<"Case #"<<test-t<<":"<<" "<<"N"<<endl;
int dp[M+2];
void pre(){
    dp[0]=0,dp[1]=1;
    for(int i=2;i<=200001;i++){
        dp[i]=1+dp[i % (__builtin_popcount(i))];
    }
}
int me(int x,int n,int m){
    if(n==0){
        return 1;
    }
    else if(n%2==0){
        return me((x*x)%m,n/2,m)%m;
    }
    else{
        return (x*me((x*x)%m,(n-1)/2,m))%m;
    }
}
int32_t main(){

    #ifndef ONLINE_JUDGE 
        freopen("in.txt", "r", stdin); 
        freopen("out.txt", "w", stdout); 
    #endif 

    fast;
    int t;
    t=1;
    // cin>>t;
    // int test=t;
    while(t--){
        pre();
        int n,i;
        cin>>n;
        string s;
        cin>>s;
        reverse(s.begin(),s.end());
        int num=0,count=0;
        for(i=0;i<n;i++){
            if(s[i]=='1'){
                count++;
            }
        }
        int y=0,z=0;
        for(i=0;i<n;i++){
            if(s[i]=='1'){
                y+=(me(2,i,count+1))%(count+1);
            }
        }
        if(count!=1){
            for(i=0;i<n;i++){
                if(s[i]=='1'){
                    z+=(me(2,i,count-1))%(count-1);
                }
            }
        }
        // dbg(y);
        // dbg(z);
        // dbg(count);
        vector<int>ans;
        int x;
        for(i=0;i<n;i++){
            if(s[i]=='1'){
                if(count==1){
                    ans.pb(0);
                    continue;
                }
                x=(z-me(2,i,count-1)+(count-1))%(count-1);
                // dbg(x);
                ans.pb(dp[x]+1);
            }
            else{
                x=(y+me(2,i,count+1))%(count+1);
                // dbg(x);
                ans.pb(dp[x]+1);
            }
        }
        reverse(ans.begin(),ans.end());
        for(i=0;i<n;i++){
            cout<<ans[i]<<endl;
        }
    }
}

Measured memory_bytes: 7048
import collections
import math
import operator as op
from functools import reduce

import numpy as np

MOD = 10**9 + 7

# def nCr(n, r):
#     r = min(r, n-r)
#     numer = reduce(op.mul, range(n, n-r, -1), 1)
#     denom = reduce(op.mul, range(1, r+1), 1)
#     return numer // denom


def nCr(n, r, mod=MOD):
    r = min(r, n-r)
    numer, denom = 1, 1
    for i in range(1, r + 1):
        numer = (numer * (n + 1 - i)) % mod
        denom = (denom * i) % mod
    return numer * pow(denom, mod - 2, mod) % mod


# def nCr(n, r):
#     r = min(r, n-r)
#     numer = reduce(op.mul, range(n, n-r, -1), 1)
#     denom = reduce(op.mul, range(1, r+1), 1)
#     return numer // denom

# cache = {}
# def nCr(n, r):
#     r = min(r, n-r)
#     if (n, r) in cache:
#         return cache[(n, r)]

#     if r == 0:
#         ret = 1
#     if n == r:
#         ret = 1
#     else:
#         ret = (nCr(n-1, r-1) + nCr(n-1, r)) % MOD

#     cache[(n, r)] = ret
#     return ret


def main():
    X, Y = list(map(int, input().split()))
    if (2 * X - Y) % 3 != 0 or (2 * Y - X) % 3 != 0 or (2 * X - Y) < 0 or  (2 * Y - X) < 0:
        print(0)
    else:
        a = (2 * X - Y) // 3
        b = (2 * Y - X) // 3
        print(nCr(a+b, a) % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12492