akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] map_s = new char[h][];
        for (int i = 0; i < h; i++) {
            char[] m = sc.next().toCharArray();
            map_s[i] = m;
        }
        boolean[][] map = new boolean[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (map_s[i][j] == '.')
                    map[i][j] = true;
            }
        }
        int[][] num_v = new int[h][w];
        int[][] num_h = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (map[i][j]) {
                    num_v[i][j] = 1;
                    num_h[i][j] = 1;
                }
            }
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w - 1; j++) {
                if (map[i][j + 1]) {
                    num_h[i][j + 1] += num_h[i][j];
                }
            }
        }
        for (int i = 0; i < h; i++) {
            for (int j = w - 1; j > 0; j--) {
                if (map[i][j - 1]) {
                    num_h[i][j - 1] = Math.max(num_h[i][j - 1], num_h[i][j]);
                }
            }
        }
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h - 1; j++) {
                if (map[j + 1][i]) {
                    num_v[j + 1][i] += num_v[j][i];
                }
            }
        }
        for (int i = 0; i < w; i++) {
            for (int j = h - 1; j > 0; j--) {
                if (map[j - 1][i]) {
                    num_v[j - 1][i] = Math.max(num_v[j - 1][i], num_v[j][i]);
                }
            }
        }

        int max = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                max = Math.max(num_v[i][j] + num_h[i][j] - 1, max);
            }
        }
        System.out.println(max);

    }
}

Measured memory_bytes: 68560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int H,W,N;
    cin >> H >> W >> N;
    vector<vector<int>> G(H,vector<int>(W));
    bool R = true;
    int nowH=0,nowW=0;
    rep(i,N){
        int a;
        cin >> a;
        rep(j,a){
            G[nowH][nowW]=i+1;
            if(R){
                if(nowW+1==W){
                    nowH++;
                    R = false;
                }else{
                    nowW++;
                }
            }else{
                if(nowW==0){
                    nowH++;
                    R = true;
                }else{
                    nowW--;
                }
            }
        }
    }
    rep(i,H){
        rep(j,W){
            cout << G[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int count, n;
    n = s.length();
    count = 0;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - 1  - i]) {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    rep(i, t) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int max_num = a[0];
    int rest = 0;
    for (int i = 1; i < t; ++i) {
        rest += a[i];
    }
    cout << max(0, max_num-rest-1) << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int maxn=3009;

int n,m,K;

int a[maxn][maxn];

long long f[maxn][maxn][4];

int main(){
	cin>>n>>m>>K;
	while(K--){
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		a[x][y]=z;
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			for(int k=0;k<=3;++k){
				long long t=max(max(f[i-1][j][0],f[i-1][j][1]),max(f[i-1][j][2],f[i-1][j][3]));
				f[i][j][k]=max(f[i][j-1][k],t);
				if(k)f[i][j][k]=max(f[i][j-1][k-1]+a[i][j],f[i][j][k]);
				if(k)f[i][j][k]=max(f[i][j][k],t+a[i][j]);
			}
		}
	}
	printf("%lld\n",max(max(f[n][m][0],f[n][m][1]),max(f[n][m][2],f[n][m][3])));
	return 0;
}

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

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define each(e, collection) for(auto& e: collection)              // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif

struct Ans
{
	ll x1;
	ll y1;
	ll x2;
	ll y2;
};

int main(void)
{
	ll h, w; cin >> h >> w;
	vector<vector<ll>> a(h, vector<ll>(w));
	rep(i, 0, h)
	{
		rep(j, 0, w)
			cin >> a[i][j];
	}

	bool move = false;
	vector<Ans> ans;
	rep(i, 0, h)
	{
		if (i % 2 == 0)
		{
			rep(j, 0, w)
			{
				if (!move && a[i][j] % 2 != 0)
					move = true;
				else if (move && a[i][j] % 2 != 0)
					move = false;

				if (move)
				{
					if (j == w-1)
						ans.push_back({ j, i, j, i + 1 });
					else
						ans.push_back({ j, i, j + 1, i });
				}
			}
		}
		else
		{
			repr(j, w-1, -1)
			{
				if (!move && a[i][j] % 2 != 0)
					move = true;
				else if (move && a[i][j] % 2 != 0)
					move = false;

				if (move)
				{
					if (j == 0)
						ans.push_back({ j, i, j, i + 1 });
					else
						ans.push_back({ j, i, j - 1, i });
				}
			}
		}

	}

	if (size(ans) != 0 && h <= ans.back().y2)
		ans.erase(ans.end() - 1);

	cout << size(ans) << endl;
	each(e, ans)
		cout << e.y1+1 << " " << e.x1+1 << " " << e.y2+1 << " " << e.x2+1 << endl;

	return 0;
}



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

const ll MAX = 3500100, MOD = 998244353;
ll 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;
    }
}
// 二項係数の計算
ll COM(int n, int k){
    if (n < 0 || k < 0 || n < k) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int n, m; cin >> n >> m;
    COMinit();
    ll ans = 0;
    if(m%2 == 0){
        for(int i = 0; i <= m; i += 2){
            ans += COM((3*m-i)/2 + n-1, n-1) * COM(n, i) % MOD; // 奇数がi個
            ans -= COM((m-2-i)/2 + n-1, n-1) * COM(n, i) % MOD * n % MOD; // 2n+2以上
            ans -= COM((m-i)/2 + n-2, n-2) * COM(n-1, i-1) % MOD * n % MOD; // 2n+1
            ans += MOD;
            ans %= MOD;
        }
    }
    if(m%2 == 1){
        for(int i = 1; i <= m; i += 2){
            ans += COM((3*m-i)/2 + n-1, n-1) * COM(n, i) % MOD; // 奇数がi個
            ans -= COM((m-2-i)/2 + n-1, n-1) * COM(n, i) % MOD * n % MOD; // 2n+2以上
            ans -= COM((m-i)/2 + n-2, n-2) * COM(n-1, i-1) % MOD * n % MOD; // 2n+1
            ans += MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

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

int main(){
	int n; cin >> n;
	int v[50]; for (int i = 0; i < n; i++) cin >> v[i];
	sort(v, v + n);
	reverse(v, v + n);
	double p = 1.0;
	double s = 0.0;
	for (int i = 0; i < n; i++) {
		p /= 2.0;
		s += v[i] * p;
	}
	s += v[n - 1] * p;

	cout << s << endl;
	return 0;
}


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

const int N = 2e5 + 10;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);
	
	int a[4];
	for(int i = 0; i < 4; i++)
	{
		cin >> a[i];
	}
	long long sol = 1e18 + 10;
	sol = -sol;
	for(int i = 0; i < 2; i++)
	{
		for(int j = 2; j < 4; j++)
		{
			sol = max(sol, a[i] * 1ll * a[j]);
		}
	}
	cout << sol;
	
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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


	ll x; cin >> x;

	vector<ll> div;
	for (ll d = 1; d * d <= x; ++d) {
	  if (x % d == 0) { 
		  div.push_back(d);
			if (d * d != x) div.push_back(x/d);
		}
	}

	for (ll d : div) {
		for (ll a = 0; a < 1000 ; a++) {
			ll b = a - d;
			if (x / d == 5 * a * a * a * a - 10 * a * a * a * d + 10 * a * a * d * d - 5 * a * d * d * d + d * d * d * d) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}

	return 0;
	
}


Measured memory_bytes: 3656
n=int(input())

w=list()
temp=['a']
error=0

for i in range(n):
    s=input()
    if i!=0 and s[0]!=temp:
       error=1
    w.append(s)
    temp=s[-1]

wset=set(w)

if len(w)==len(wset) and error==0:
    print('Yes')
else:
    print('No')

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

int main()
{
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    vector<pair<long long, int>> apple;
    vector<int> color{A, B, C};
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < color[i]; j++)
        {
            long long x;
            cin >> x;
            apple.push_back({x, i});
        }
    }
    sort(apple.rbegin(), apple.rend());

    long long ans = 0;
    int nocolor = 0;
    for (pair<long long, int> p : apple)
    {
        int c = p.second;
        if (c == 0)
        {
            if (X > 0)
            {
                X--;
                ans += p.first;
            }
        }
        if (c == 1)
        {
            if (Y > 0)
            {
                Y--;
                ans += p.first;
            }
        }
        if (c == 2)
        {
            nocolor++;
            ans += p.first;
        }
        if (X + Y == nocolor)
        {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 10604
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>


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

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;

using namespace std;
typedef long long ll;

int main()
{

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

	int n; cin >> n;
	vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i];
	ll res = 0;
	for (int i = 1; i < n; i++) {
		if (a[i - 1] > a[i]) {
			res += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 4760
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;
#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}

void solve()
{
	string s;
	cin>>s;
	if(s[1]=='R')
		cout<<"ABC";
	else
		cout<<"ARC";
	return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int N, x; std::cin >> N >> x;
  if(x == 1 || x == N*2-1) fin("No");
  std::cout << "Yes\n";
  int n = 2;
  for(int i = 0; i < N-2; ++i) {
    if(n == x) ++n;
    std::cout << n << "\n";
    ++n;
  }
  std::cout << "1\n" << x << "\n" << (N*2-1) << "\n";
  for(int i = 0; i < N-2; ++i) {
    if(n == x) ++n;
    std::cout << n << "\n";
    ++n;
  }
  return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<stdlib.h>
int sp[100002];
int main(void){
    int n,i,normal=0,subpre,subnext,newedge;
    scanf("%d",&n);
    sp[0]=0;
    for(i=1;i<=n;i++){
        scanf("%d",&sp[i]);
    }
    sp[n+1]=0;
    normal+=abs(sp[1]);
    for(i=1;i<=n;i++){
        normal+=abs(sp[i]-sp[i+1]);
    }
    for(i=1;i<=n;i++){
        subpre=abs(sp[i]-sp[i-1]);
        subnext=abs(sp[i]-sp[i+1]);
        newedge=abs(sp[i-1]-sp[i+1]);
        printf("%d\n",normal-subpre-subnext+newedge);
    }
    return 0;
}


Measured memory_bytes: 1536
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]

while True:
  ans = 0
  for h in range(H):
    if list(set(S[h]))[0] == ".":
      S.pop(h)
      H -= 1
      ans = 1
      #print(S)
      #print()
      break
  for w in range(W):
    #print([S[h][w] for h in range(H)])
    if list(set([S[h][w] for h in range(H)]))[0] == ".":
      for h in range(H):
        S[h].pop(w)
      W -= 1
      ans = 1
      #print(S)
      #print()
      break
  if ans == 0:
    break

for h in range(H):
  print("".join(S[h]))

Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
int main(){
  ll N,M;
  cin>>N>>M;
  using Graph=vector<vector<ll>>;
  Graph G(N);
  for (ll i=0;i<M;++i){
    ll a,b;
    cin>>a>>b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  vector<ll> dist(N,-1);//全頂点を「未訪問」に初期化
  queue<ll> que;
  unordered_map<ll,ll> map;
  dist[0]=0;
  que.push(0);
  while(!que.empty()){
    ll v=que.front();//キューから先頭頂点を取り出す
    que.pop();
    //v から辿れる頂点をすべて調べる
    for(ll nv:G[v]){
      if(dist[nv]!=-1)continue;//すでに発見済みの頂点は探索しない
      //新たな白色頂点 nv について距離情報を更新してキューに追加する
      dist[nv]=dist[v]+1;
      map[nv]=v+1;
      que.push(nv);
    }
  }
  for(ll i=0;i<N;i++){
    break;
    cout<<i+1<<" "<<"一つ前の値:"<<map[i]<<" 深さ(原点の深さを0として):"<<dist[i]<<endl;
  }
  cout<<"Yes"<<endl;
  for(ll i=1;i<N;i++){
    cout<<map[i]<<endl;
  }
}

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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 1e5 + 2;


void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0; 
      string s ; cin >> s;
      if(s == "ARC") cout << "ABC";
      else cout << "ARC";
      cout << endl;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

Measured memory_bytes: 3600
"""
優先度付きキューで実装
"""
import heapq

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

a_pq = []

for i in a_list:
    heapq.heappush(a_pq, [-i, 1])

for i in range(m):
    b, c = map(int, input().split())
    heapq.heappush(a_pq, [-c, b])

ans = 0
for i in range(n):
    pop_tmp = heapq.heappop(a_pq)
    number, sum_number = pop_tmp
    ans += -number
    if sum_number > 1:
        sum_number -= 1
        heapq.heappush(a_pq, [number, sum_number])

print(ans)


Measured memory_bytes: 41396
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			int N =sc.nextInt();
			int count = 0;
			int count2 = 0;
			int count3= 0;
			int count4 = 0;
          String A = "AC";
          String B = "WA";
          String C = "TLE";
          String D = "RE";
		for(int i = 0;i < N;i++) {
			String H = sc.next();
			if(H.equals(A)) {
				count++;
			}
			else if(H.equals(B)) {
				count2++;
			}
			else if(H.equals(C)) {
				count3++;
			}
			else if(H.equals(D)) {
				count4++;
			}
		}
		System.out.println("AC  x  " + count);
		System.out.println("WA  x  " + count2);
		System.out.println("TLE  x  " + count3);
		System.out.println("RE  x  " + count4);
	}
}


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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

//MOD//
const ll MOD = 1000000007;
struct big;
big ex(big a, ll tms);
typedef struct big{
  ll val;
  big():val(0){}
  big(ll val):val((val%MOD+MOD)%MOD){}
  big& operator += (const big& obj){ (val+=obj.val)%=MOD; return *this;}
  big& operator -= (const big& obj){ (val+=MOD-obj.val)%=MOD; return *this;}
  big& operator *= (const big& obj){ (val*=obj.val)%=MOD; return *this;}
  big& operator /= (const big& obj){ (val*=ex(obj,MOD-2).val)%=MOD; return *this;}
  big operator + (const big& obj)const{ return big(*this) += obj;}
  big operator - (const big& obj)const{ return big(*this) -= obj;}
  big operator * (const big& obj)const{ return big(*this) *= obj;}
  big operator / (const big& obj)const{ return big(*this) /= obj;}
  bool operator < (const big& obj)const{ return val < obj.val;}
  bool operator == (const big& obj)const{ return val == obj.val;}
} big;
istream& operator >> (istream& i, big& obj){ i>>obj.val; return i;}
ostream& operator << (ostream& o, const big& obj){ o<<obj.val; return o;}
big ex(big obj, ll tms){
  if(!tms) return 1;
  big ret = ex(obj, tms/2);
  ret *= ret;
  return (tms&1) ? ret*obj : ret;
}
//MOD//

ll pow(ll n, int m){
  if(!m) return 1;
  ll ret = pow(n, m/2);
  ret *= ret;
  return (m&1) ? ret*n : ret;
}

template <class F, class T>
void convert(const F &f, T &t){
  stringstream ss;
  ss << f;
  ss >> t;
}

int N;
string s;
int cnt[26];

int main(){

  scanf("%d",&N);
  cin >> s;

  big ans = 1;
  int n;
  rep (i, N) ++cnt[s[i]-'a'];
  rep (i, 26) ans = ans * big(cnt[i]+1);
  ans -= 1;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 512
#include <stdio.h>
int main(){
	int i,a[100000];
	int count=0;
	i=0;
	while(1){
		scanf("%d",&a[i]);
		if(a[i]==0) break;
		count++;
		i++;
	}
	for(i=1;i<=count;i++){
		printf("Case %d: %d\n",i,a[i-1]);
	}
	return 0;
}

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

int main() {
    int n;
    int64_t k;
    cin >> n >> k;
    int a, b;
    vector<int64_t> accum(n+1);
    vector<P> v;
    rep(i,n) {
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end());
    rep(i,n) {
        b = v[i].second;
        accum[i+1] = accum[i] + b;    
    }
    //めぐる式二分探索
    int64_t ok = n; //解が存在する値
    int64_t ng = 0;    //解が存在しない値
    while (abs(ok - ng) > 1) {
        int64_t mid = (ok + ng) / 2;
        if (accum[mid] >= k) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }
    int ans = v[ok-1].first;
    cout << ans << endl;
}


Measured memory_bytes: 2168
N = int(input())

if N == 1:
    print(0)
    exit()

if N == 2:
    print(2)
    exit()

# N >= 3

# 全事象
all_pattern = 10 ** N

# 0も9もない
pattern_a = 8 ** N

# 0あるが9ない
pattern_b = 9 ** N - 8 ** N

ans = all_pattern - pattern_a - pattern_b * 2
ans = ans % (10**9 + 7)

print(ans)

Measured memory_bytes: 84496
#include <iostream>
#include <cstring>
#include <string>    
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a, b, c, d;

int main(){
	cin >> n >> a >> b >> c >> d;
	
	string ans = "NO";
	ll diff = abs(a-b); 
	for(ll i = 1; i <= n-1; i++){
		if(c*i-d*(n-1-i) <= diff && diff <= d*i-c*(n-1-i)){ans = "YES";}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    H, A = LI()
    print(H // A + (H % A > 0))

main()



Measured memory_bytes: 6472
#include<stdio.h>
#include<string.h>
#define N 1001
int max(int a,int b){
  if(a > b)return a;
  else return b;
}
int karuma(char s1[],char s2[],int m,int n){
  int c[N][N];
  int i,j,count=0 ;
    for(i=1;i<=m;i++){
    c[i][0] = 0;  }
  for(j=1;j<=n;j++){
    c[0][j] = 0;}
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(s1[i-1] == s2[j-1]){
        c[i][j] = c[i-1][j-1] + 1;
      }else{
        c[i][j] = max(c[i-1][j],c[i][j-1]);
      }
      count = max(count,c[i][j]);
    }
  }
  return count;
}
int main(){
  int total,i;
    char s1[N],s2[N];
  scanf("%d",&total);
  for(i=0;i<total;i++){
    scanf("%s",s1); scanf("%s",s2);
    printf("%d\n",karuma(s1,s2,strlen(s1),strlen(s2)));
  }
  return 0;
}


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

int n;

signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=3500;i++)
		for(int j=1;j<=3500;j++)
		{
			if(4*i*j-n*i-n*j<=0)continue;
			int k=(n*i*j)/(4*i*j-n*i-n*j);
			if(k*(4*i*j-n*i-n*j)==n*i*j)
				{printf("%lld %lld %lld\n",i,j,k);return 0;}
		}
	return 0;

}


Measured memory_bytes: 256
import sys; input = sys.stdin.readline
n = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for i in range(n):
    a = input().strip()
    if a == 'AC': ac+=1
    elif a == 'WA': wa += 1
    elif a == 'TLE': tle += 1
    elif a == 'RE': re += 1
print(f"AC x {ac}")
print(f"WA x {wa}")
print(f"TLE x {tle}")
print(f"RE x {re}")

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

int main() {
    long long n;
    cin >> n;
    long long sum = 0;
    vector<long long> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<long long> dp(n);
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for (int i = 2; i < n; i++)
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]),
                    dp[i - 2] + abs(a[i] - a[i - 2]));
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int h, w;
string s[101];

int main(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> s[i];
	}
	
	for(int i = 0; i < h; i++){
		cout << s[i] << endl << s[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int Nums1[]=new int[A];
    int Nums2[]=new int[A];
    int count=0;
    int Nums3[]=new int[A];
    for(int i=0;i<A;i++){
          Nums1[i]=sc.nextInt();
        
    }
    for(int i=0;i<A;i++){
          Nums2[i]=sc.nextInt();
        
    }
    for(int i=0;i<A;i++){
    	Nums3[i]=Nums1[i]-Nums2[i];
    }
    for(int i=0;i<A;i++){
    	if(Nums3[i]>0)	
     count+=Nums3[i];
    }
   	System.out.println(count);
  }
}

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

int main()
{
    long long X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    if (1.0 * X - 1.0 * K * D < 0)
    {
        K -= X / D, X %= D;
        cout << (K % 2 ? D - X : X) << '\n';
    }
    else cout << X - K * D << '\n';
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}

void solve() {
    ll n, m;
    std::cin >> n >> m;

    vvll s(m);
    for (ll i = 0; i < m; i++) {
        ll k; std::cin >> k;
        s[i].resize(k);
        for (ll j = 0; j < k; j++)
            std::cin >> s[i][j], s[i][j]--;
    }

    vll p(m);
    for (ll i = 0; i < m; i++)
        std::cin >> p[i];

    ll ans = 0;
    for (ll bit = 0; bit < 1LL << n; bit++) {
        ll res1 = 0;
        for (ll i = 0; i < m; i++) {
            ll res2 = 0;
            for (ll j = 0; j < s[i].size(); j++)
                res2 += bit >> s[i][j] & 1;
            res1 += res2 % 2 == p[i];
        }
        ans += res1 == m;
    }

    std::cout << ans << '\n';
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    string s;
    cin >> s;
    string t = s;
    bool a = true;
    reverse(t.begin() , t.end());
    for(int i = 0; i < s.size(); i++){
        if(s[i] != t[i]){
            a = false;
        }
    }
    if(a){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3612
using System;

class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    
    if(a + b >= c) Console.WriteLine("Yes");
    else Console.WriteLine("No");
  }
}

Measured memory_bytes: 11092
#include <iostream>
using namespace std;
int main(void){
    int H, W, i, j;
    while(1){
        cin >> H >> W;
        if((H == 0) && (W == 0)) break;
        for(j=0; j<H; j++){
            for(i=0; i<W; i++){
                if((j == 0) || (j == H-1)){
                    cout << '#';
                }
                else if((i == 0) || (i == W-1)){
                    cout << '#';
                }
                else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

























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



int main() {
    int x, y, z;
    cin >> x >> y >> z;
    
    cout << z << " " << x << " " << y << endl;
    
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

ll x, d;
ll gcd(ll a, ll b){
  if(b<a) swap(a, b);
  ll r = a % b;
  if(r==0) return b;
  while(r!=0){
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
ll wa(ll k, ll a=x, ll b=d){return a*k + b*((k*(k-1))/2);}


int main(int argc, char const *argv[]) {
  ll n;std::cin >> n >> x >> d;
  if(d==0&&x==0) {
    std::cout << 1 << '\n';
    return 0;
  }
  if(d==0){
    std::cout << n+1 << '\n';
    return 0;
  }
  //ll g = gcd(abs(x), abs(d));x/=g, d/=g;
  ll ans = 0;
  multimap<ll, vll> mp;
  set<ll> num;
  for(int i=0;i<=n;i++){
    vll now{wa(i), wa(n) - wa(n-i)};
    if(now[0]>now[1]) swap(now[0], now[1]);
    mp.emplace((i*x)%abs(d), now);
    num.insert((i*x)%abs(d));
  }
  ll c = 0;
  auto itr = mp.begin();
  vector<multiset<vll>> q(num.size());
  for(auto i=num.begin();i!=num.end();i++, c++){
    while(itr!=mp.end()&&(*itr).first==(*i)){
      q[c].insert(vll{(*itr).second[0], -1});
      q[c].insert(vll{(*itr).second[1], 1});
      itr++;
    }
  }


  for(int i=0;i<num.size();i++){
    ll t = 0, l = -100000000000000000;
    for(auto it = q[i].begin();it!=q[i].end();it++){
      if((*it)[1]==-1) {
        if(t==0) l = (*it)[0];
        t++;
      }else{
        t--;
        if(t==0){
          ans += ((*it)[0] - l)/abs(d) + 1;
          l = (*it)[0];
        }
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 73728
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	if (s=="SAT") cout<<"1"<<endl;
	else if (s=="FRI") cout<<"2"<<endl;
	else if (s=="THU") cout<<"3"<<endl;
	else if (s=="WED") cout<<"4"<<endl;
	else if (s=="TUE") cout<<"5"<<endl;
	else if (s=="MON") cout<<"6"<<endl;
	else if (s=="SUN") cout<<"7"<<endl;
	else cout<<endl;
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
const int mn=200010;
char s[mn],ans[mn];
int len,n[mn][30];
int dp[mn];
int main() {
	scanf("%s",s);
	len=strlen(s);
	for (int i=0;i<26;i++) {
		n[len][i]=len;
		for (int j=len-1;j>=0;j--) {
			if (s[j]=='a'+i)
				n[j][i]=j;
			else n[j][i]=n[j+1][i];
		}
	}
	memset(dp,0x7f,sizeof(dp));
	dp[len+1]=0;
	for (int i=len-1;i>=0;i--)
		for (int j=0;j<26;j++)
			if (dp[i]>dp[n[i][j]+1]+1) {
				ans[i]='a'+j; dp[i]=dp[n[i][j]+1]+1;
			}
	int i=0,l=0;
	while (l<dp[0]) {
		l++;
		printf("%c",ans[i]);
		i=n[i][ans[i]-'a']+1;
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 24832
//-------------------------------------------
//-               Train Fare                -
//-                                         -
//-       autumn_eel niha katemasen!        -
//-------------------------------------------

#include<iostream>
#include<functional>
#include<queue>
#include<deque>
#include<vector>
#include<algorithm>
using namespace std;

void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
inline void writeln(int x) {
	int s = 0; char f[7];
	while (x) {
		f[s++] = x % 10;
		x /= 10;
	}
	if (!s) f[s++] = 0;
	while (s--) putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}
#pragma warning(disable:4996)
int n, m, q, a[200003], b[200003], c[200003], d[200003], e[100003], f[100003], g[100003];
int h1[100003], h2[100003], h3[100003], h4[100003], dist[100003], E[200003];
vector<pair<int, int> > z[100003]; vector<int> x[100003];
vector<int>D[100003];
int Q1[110000], Q1L, Q1R;
int main() {
	reader(&n); reader(&m); reader(&q);
	fill(d, d + m + 1, 1 << 30);
	for (int i = 1; i <= m; i++) { reader(&a[i]), reader(&b[i]); f[a[i]]++; f[b[i]]++; }
	for (int i = 1; i <= q; i++) reader(&c[i]), d[c[i]] = i;
	for (int i = 1; i <= n; i++) { x[i].resize(f[i]); }
	for (int i = 1; i <= m; i++) {
		x[a[i]][g[a[i]]] = b[i]; g[a[i]]++;
		x[b[i]][g[b[i]]] = a[i]; g[b[i]]++;
	}
	fill(dist, dist + n + 1, -1); dist[1] = 0;
	Q1[0] = 1; Q1R = 1;
	while (Q1R > Q1L) {
		int a1 = Q1[Q1L]; Q1L++;
		for (int i : x[a1]) {
			if (dist[i] == -1) {
				dist[i] = dist[a1] + 1;
				Q1[Q1R] = i; Q1R++;
			}
		}
	}
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) h1[a[i]]++;
		if (dist[b[i]] > dist[a[i]]) h1[b[i]]++;
	}
	for (int i = 1; i <= n; i++)z[i].resize(h1[i]);
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) { z[a[i]][h2[a[i]]] = make_pair(b[i], d[i]); h2[a[i]]++; }
		if (dist[b[i]] > dist[a[i]]) { z[b[i]][h2[b[i]]] = make_pair(a[i], d[i]); h2[b[i]]++; }
	}
	for (int i = 1; i <= n; i++) h3[dist[i]]++;
	for (int i = 0; i <= n; i++) D[i].resize(h3[i]);
	for (int i = 1; i <= n; i++) D[dist[i]][h4[dist[i]]] = i, h4[dist[i]]++;
	e[1] = (1 << 30);
	for (int i = 1; i < n; i++) {
		for (int j : D[i]) {
			for (pair<int, int>k : z[j]) {
				e[j] = max(e[j], min(e[k.first], k.second));
			}
		}
	}
	for (int i = 2; i <= n; i++) {
		if (e[i] < 300000) E[e[i]]++;
	}
	for (int i = 1; i <= q; i++) {
		E[i] += E[i - 1];
		writeln(E[i]);
	}
	return 0;
}

Measured memory_bytes: 24972
// ARC090
// D - People on a Line

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100000;

int N, M;
vector<pii> g[MAX_N];
int x[MAX_N];
bool visited[MAX_N];

bool dfs(int v, int y = 0) {
    if (visited[v]) {
        return x[v] == y;
    }
    x[v] = y;
    visited[v] = true;

    bool res = true;
    for (pii &e : g[v]) {
        res = res && dfs(e.second, x[v] + e.first);
    }
    return res;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        g[l].push_back(pii(d, r));
        g[r].push_back(pii(-d, l));
    }

    memset(visited, 0, sizeof(visited));
    for (int i = 0; i < N; i++) {
        if (!visited[i] && !dfs(i)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


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

int main() {
  int A,B,X,x1,x2,x4,x5,Ans;
  cin >> A >> B;
  Ans=0;
  for (int i=0; i<=(B-A); i++){
    X = A+i;
    x1= X%10;
    X/=10;
    x2= X%10;
    X/=100;
    x4= X%10;
    X/=10;
    x5= X%10;
    X/=10;
    if(x1==x5 && x2==x4){
    Ans+=1;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int x;
  if(n*a>=b){
    x=b;
    cout<<x<<endl;
  }
  else{
    x=n*a;
    cout<<x<<endl;
  }
}

Measured memory_bytes: 3632
#include<cstdio>

int main(){
  int data[10],order[10];

  //入力＆初期化
  for(int i=0;i<10;i++){
    scanf("%d",&data[i]);
    order[i]=1;
  }

  //順位付け
  for(int i=1;i<10;i++)
    for(int j=0;j<i;j++){
      if(data[j]<data[i]) order[j]++;
      if(data[j]>=data[i]) order[i]++;
    }

  //表示
  for(int i=1;i<=3;i++)
    for(int j=0;j<10;j++)
      if(order[j]==i)
	printf("%d\n",data[j]);
   
  return 0;
}

Measured memory_bytes: 1028
from collections import defaultdict
import numpy as np

N,M = list(map(int,input().split()))
A = input().split()

A = np.array(A,dtype='int64')
C = np.append([0],np.cumsum(A))
#累積和を算出して最初に０をつける。
L = [i%M for i in C]
#Ｍで割ったあまりを求めてリスト化
d = defaultdict(int)
for i in L:
    d[i] +=1
#各余りに対して、その数が何個あるかを求める。

ans = 0
for i in d.values():
    S = i * (i-1) / 2
    ans+=S
    
print(int(ans))

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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n, u, v; cin >> n >> u >> v;
    --u, --v;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; ++i) {
    	int a, b; cin >> a >> b;
    	--a, --b;
    	g[a].pb(b);
    	g[b].pb(a);
    }
    vector<int> d1(n);
    vector<int> d2(n);
    function<void(int, int, int, vector<int>&)> dfs = [&](int u, int p, int di, vector<int> &d) {
    	d[u] = di;
    	for (int v : g[u]) {
    		if (v != p) {
    			dfs(v, u, di + 1, d);
    		}
    	}
    };
    dfs(u, -1, 0, d1);
    dfs(v, -1, 0, d2);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
    	if (d1[i] < d2[i])
    		ans = max(ans, d2[i] - 1);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 14208
### 解答
def popcount(X):
  pc = 0
  while X>0:
    pc += X%2
    X = X//2
  return pc

N = int(input())
B = input()
X = int(B, 2)

pcx = popcount(X)
pc0to1 = pcx + 1
pc1to0 = pcx - 1
if pc0to1 > 0:
  r0to1 = X%pc0to1
  r20to1 = [1]
  for i in range(1,N):
    r20to1.append((r20to1[-1]*2)%pc0to1)
if pc1to0 > 0:
  r1to0 = X%pc1to0
  r21to0 = [1]
  for i in range(1,N):
    r21to0.append((r21to0[-1]*2)%pc1to0)

for i in range(N):
  b = B[i]
  if b == "0":
    pc = pc0to1
  else:
    pc = pc1to0
  if pc == 0:
    print(0)
    continue

  if b == "0":
    x = r0to1 + r20to1[-(i+1)]
  else:
    x = r1to0 - r21to0[-(i+1)]
  x = x%pc

  ans = 1
  while x > 0:
    pc = popcount(x)
    x = x%pc
    ans += 1
  print(ans)

    
  

  




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

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    vector<int> sumE(N+1,0);
    vector<int> sumW(N+1,0);
    int ans = INT_MAX;
    if(S[0] == 'E'){
            sumE[1] = 1;
        } else {
            sumW[1] = 1;
        }

    for(int i = 1; i < N; i++){
        if(S[i] == 'E'){
            sumE[i+1] = sumE[i] + 1;
            sumW[i+1] = sumW[i] + 0;
        } else {
            sumE[i+1] = sumE[i] + 0;
            sumW[i+1] = sumW[i] + 1;
        }
    }

    for(int i = 1; i <= N; i++){
        ans = min(ans,sumW[i-1]+sumE[N]-sumE[i]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 3076
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

int x, y, a, b, c;
int p[N], q[N], r[N];

int32_t main() {
  FAST_IO;
  cin >> x >> y >> a >> b >> c;
  rep(i, a)
    cin >> p[i];
  rep(i, b)
    cin >> q[i];
  rep(i, c)
    cin >> r[i];
  sort(p, p + a);
  reverse(p, p + a);
  sort(q, q + b);
  reverse(q, q + b);
  multiset<int> st;
  rep(i, x)
    st.insert(p[i]);
  rep(i, y)
    st.insert(q[i]);
  sort(r, r + c);
  int ptr = c - 1;
  while (ptr >= 0 && *st.begin() < r[ptr]) {
    st.erase(st.find(*st.begin()));
    st.insert(r[ptr]);
    ptr--;
  }
  int ans = 0;
  for (auto i : st)
    ans += i;
  cout << ans;
  rtn 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>
	
int main() {
	set<ll> s;
	ll n;
	cin >> n;
	REP(i, n) {
		ll a;
		cin >> a;
		s.insert(a);
	}
	if (s.size() == n)cout << "YES" << endl;
	else cout << "NO" << endl;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;
int main()
{
    int n;
    cin>>n;
    int x=0;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        x=x^a[i];
    }
    for(int i=0;i<n;i++){
        int y=x^a[i];
        cout<<y<<" ";
    }
}


Measured memory_bytes: 4376
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  string s, t;
  cin >> s >> t;
  ll a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if (u == s)
    a--;
  else
    b--;
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pi;
#define f first
#define s second

int N, K, a[200005], ans;
pi dis[200005];
int fw[200005];

void update(int x, int v) { //v is value, x is position
	if (x<=0) return;
    for (;x <=N+1; x+=x&(-x)) fw[x] += v; 
}
int sum(int x) {
	if (x<=0) return 0;
    int res = 0;
    for(; x; x-=x&(-x)) res += fw[x];
    return res;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}
	
	int cursum = 0;
	for (int i = 1; i <= N; i++) {
		cursum += a[i];
		dis[i] = pi(cursum - (i*K), i);
		//~ printf("%d: %d running sum, %d v\n", i, cursum, cursum - (i*K));
		//~ if (a[i] >= K) ans++;
	}
	
	sort(dis+1, dis+N+2); //If 1-indexed, change sorting range as well
	pi cur = pi(-1, -1);
	for (int i = 1; i <= N+1; i++) {
		if (dis[i].f == cur.f && cur.s != -1) a[dis[i].s] = cur.s; //takes into account equal numbers
		else {
			cur = pi(dis[i].f, i);
			a[dis[i].s] = i;
		}
	}
	
	update(a[0], 1);
	
	for (int i = 1; i <= N; i++) {
		ans += sum(a[i]);
		//~ printf("From %d, %d added\n", i, sum(a[i]));
		update(a[i], 1);
		//~ printf("%d added 1\n", a[i]);
	}
	cout << ans;
}


Measured memory_bytes: 6528