akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int h[1501], w[1501];

  int N, M;
  while (cin >> N >> M, (N || M)) {
    for (int i=0; i<N; i++) {
      int t; cin >> t; h[i] = t;
    }
    for (int i=0; i<M; i++) {
      int t; cin >> t; w[i] = t;
    }

    vector<int> V(1500001), H(1500001);
    for (int i=0; i<N; i++) {
      int len = 0;
      for (int j=i; j<N; j++) {
        len += h[j];
        V[len]++;
      }
    }
    for (int i=0; i<M; i++) {
      int len = 0;
      for (int j=i; j<M; j++) {
        len += w[j];
        H[len]++;
      }
    }

    int count = 0;
    for (int i=1; i<=1500000; i++) {
      count += V[i] * H[i];
    }
    cout << count << endl;
  }

  return 0;
}



Measured memory_bytes: 14588
using System;

namespace teisyutusensei
{
    class Program
    {
        static void Main(string[] args)
        {
            

            string result =null;
            bool fr = true;

            while(fr)
            {
                ////?????????????????????
                string dmmy = Console.ReadLine();

                string[] input = dmmy.Split(' ');

                int a = int.Parse(input[0]);
                string op = (input[1]);
                int b = int.Parse(input[2]);


                switch (op)
        	    {
                    case "+":
                        result += a+b;
                        result += "\n";
                        break;
                    case "-":
                        result += a - b;
                        result += "\n";
                        break;
                    case "*":
                        result += a * b;
                        result += "\n";
                        break;
                    case "/":
                        result += a / b;
                        result += "\n";
                        break;
                    default:
                        fr = false;
                        //result += "\n";
                        break;
	            }
            }

            Console.Write(result);
            Console.ReadLine();

        }
    }

}

Measured memory_bytes: 19992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 値を取得
		String s = sc.next();
		long a = 0, b = 0;

		for (int i = 0; i < s.length(); i++) {
			if (i % 2 == 0) {
				if (!s.substring(i, i + 1).equals("0")) {
					a++;
				}
			} else {
				if (!s.substring(i, i + 1).equals("1")) {
					a++;
				}
			}
		}
		
		for (int i = 0; i < s.length(); i++) {
			if (i % 2 == 0) {
				if (!s.substring(i, i + 1).equals("1")) {
					b++;
				}
			} else {
				if (!s.substring(i, i + 1).equals("0")) {
					b++;
				}
			}
			if (a < b) {
				break;
			}
		}
		
		if (b < a) {
			a = b;
		}

		System.out.println(a);

		sc.close();
	}
}


Measured memory_bytes: 34036
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;

const int N = 1 << 15;

int TOT;
vector <pii> all;
vector <int> from[N + N];
int sum[10010], ins[N + N], id[N + N], low[N + N];
int vis[N + N];
vector <int> s;

struct Segment_tree {
	void Build(int now, int l, int r) {
		if (l == r) return ;
		int mid = l + r >> 1;
		from[now].push_back(now << 1), from[now].push_back(now << 1 | 1);
		Build(now << 1, l, mid), Build(now << 1 | 1, mid + 1, r);
	}
	void add_edge(int now, int l, int r, int L, int R, int x) {
		if (l == L && r == R) {
//			cout << "           rand:" << L << " " << R << endl;
//			cout << "             x:" << x << endl;
//			cout << "             id:" << now << endl; 
			from[x].push_back(now);
			return ;
		}
		int mid = l + r >> 1;
		if (R <= mid) add_edge(now << 1, l, mid, L, R, x);
		else if (L > mid) add_edge(now << 1 | 1, mid + 1, r, L, R, x);
		else add_edge(now << 1, l, mid, L, mid, x), add_edge(now << 1 | 1, mid + 1, r, mid + 1, R, x);
	}
}seg;

int flag = 1;

void dfs(int x) {
//	cout << "  dfs:" << x << endl;
	low[x] = id[x] = ++TOT;
	s.push_back(x), ins[x] = 1;
	vector <int> &g = from[x];
	for (int i = 0; i < g.size(); i++) {
		int v = g[i];
//		cout << "    edge:" << x << "->" << v << endl;
		if (!id[v]) dfs(v), low[x] = min(low[x], low[v]);
		else if (ins[v]) low[x] = min(low[x], id[v]);
	}
	if (id[x] != low[x]) return ;
	while (1) {
		int v = s.back(); s.pop_back(); ins[v] = 0;
		if (v >= N && v - N < all.size() && vis[all[v - N].se] == x) flag = 0;
		if (v >= N && v - N < all.size()) vis[all[v - N].se] = x;
		if (v == x) break;
	}
//	cout << "end:" << endl;
}

bool check(int mid) {
//	cout << "   check:" << mid << endl;
	for (int i = 0; i < N + N; i++) {
		from[i].clear();
	}
	seg.Build(1, 1, N);
	for (int i = 0; i < all.size(); i++) {
		int l = lower_bound(all.begin(), all.end(), mp(all[i].fi - mid, 0x3f3f3f3f)) - all.begin();
		int r = lower_bound(all.begin(), all.end(), mp(all[i].fi + mid, -1)) - all.begin();
//		cout << "     range:" << i << " " << l << " " << r - 1 << endl;
		if (l <= i - 1) seg.add_edge(1, 1, N, l + 1, i, N + sum[all[i].se] - i);
		if (i + 1 <= r - 1) seg.add_edge(1, 1, N, i + 2, r, N + sum[all[i].se] - i);
	}
	flag = 1, TOT = 0;
	memset(vis, 0, sizeof(vis)), memset(id, 0, sizeof(id));
	for (int i = N; i < N + all.size(); i++) {
		if (!id[i]) dfs(i);
	}
//	cout << "TOT:" << TOT << endl;
	return flag;
}

int main () {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int x, y; scanf("%d%d", &x, &y);
		all.push_back(mp(x, i)), all.push_back(mp(y, i));
	}
	sort(all.begin(), all.end());
	for (int i = 0; i < all.size(); i++) {
		sum[all[i].se] += i;
	}
	int l = 0, r = 1000000000;
	while (l < r) {
		int mid = l + r + 1 >> 1;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	printf("%d\n", l);
	return 0;
}


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

int main(){
    int A,B,X;
    cin>>A>>B>>X;
    int sum=0,num=0,ans=0;
    if(A>=2*B){
        while(X>sum){
            sum+=500;
            ans+=B;
        }
        cout<<ans<<endl;
        return 0;
    }else{
        while(X>sum){
            if(X-sum<=500){
                if(A<B){
                    sum+=1000;
                    ans+=A;
                    cout<<ans<<endl;
                    return 0;
                }else {
                    sum+=500;
                    ans+=B;
                    cout<<ans<<endl;
                    return 0;
                }
            }
            sum+=1000;
            ans+=A;
        }
        cout<<ans<<endl;
        return 0;

    }
}


Measured memory_bytes: 3112
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            double a = scn.nextDouble();
            double b = scn.nextDouble();
            double C = scn.nextDouble();
            double c = C * Math.PI / 180;
            double S = a * b * Math.sin(c) / 2;
            double L = a + b + Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(c));
            double h = b * Math.sin(c);
            System.out.println(S + " " + L + " " + h);
        }
    }
}

Measured memory_bytes: 27908
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005
int mod = 1e9 + 7;
int power(int a,int b){
	if(b == 0)
		return 1;
	long long val = power(a,b/2);
	val = (val * val)%mod;
	if(b % 2)
		val = (val * a) % mod;
	return val;
}
int mmi(int x){
	return power(x,mod-2);
}
int mdiv(long long a,int b){
	return (a * mmi(b))%mod;
}
int main()
{
    fastread;
    int n;
    cin>>n;
    vector<int> arr(n);
    for(int i=0;i<n;i++){
    	cin>>arr[i];
    }
    map<int,int> mcnt;
    for(int i=0;i<n;i++){
    	int temp = arr[i],tema=arr[i];
    	for(int j=2;j<=sqrt(temp);j++){
    		int cnt = 0;
    		while(tema % j == 0){
    			tema = tema /j;
    			cnt++;
    		}
    		if(cnt){
    			mcnt[j] = max(mcnt[j],cnt);
    		}
    	}
    	if(tema > 1)
    		mcnt[tema] = max(mcnt[tema],1);
    }
    long long val = 1;
    for(auto ite:mcnt){
    	val = (val * power(ite.fx,ite.sx)) % mod;
    }
    //cout<<val<<endl;
    int ans = 0;
    for(int i=0;i<n;i++){
    	int temp = arr[i],tema = arr[i];
    	int curval = val;
    	for(int j=2;j<=sqrt(temp);j++){
    		int cnt = 0;
    		while(tema % j == 0){
    			tema = tema/j;
    			cnt++;
    		}
    		if(cnt){
    			curval = mdiv(curval,power(j,cnt));
    		}
    	}
    	curval = mdiv(curval,tema);
    	ans += curval;
    	ans = ans % mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)


struct Problem {

	static UL gcd(UL a, UL b) { return b ? gcd(b, a % b) : a; }
	static const ULL M = 1000000007;

	void Solve() {
		const ULL G = 1000000;
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		ULL P = 1;
		{
			vector<UL> Pri(G + 1);
			rep(i, N) {
				UL b = A[i];
				for (UL p = 2; p <= 1000; p++) {
					UL idx = 0;
					while (b % p == 0) { b /= p; idx++; }
					Pri[p] = max(Pri[p], idx);
				}
				if (b != 0) Pri[b] = 1;
			}
			rep(i, G) {
				rep(j, Pri[i]) {
					P = P * i % M;
				}
			}
		}
		vector<ULL> I(G + 1); I[1] = 1;
		for (UL i = 2; i <= G; i++) I[i] = M - (M / i * I[M % i] % M);
		vector<ULL> Pl(N + 1), Pr(N + 1); Pl[0] = Pr[0] = 1;
		ULL ans = 0;
		rep(i, N) {
			ans += P * I[A[i]] % M;
		}
		cout << (ans % M) << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 8252
#include <iostream>

using namespace std;

const int N = 105;
int main() {
	int n;
	cin >> n;
	int counter = 0;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		if (x % 2 != 0 && i % 2 != 0)
			counter++;
	}	
	cout << counter << endl;
	return 0;
}

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

using namespace std;

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

    long long a, b, k;
    cin >> a >> b >> k;
    if(k >= a){
        k -= a;
        a = 0;
        if(k >= b){
            b = 0;
        }
        else{
            b -= k;
        }
    }
    else{
        a -= k;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
 
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin>>n>>m;
    int p10 = 1;
    for(int i=0;i<n-1;++i) p10 *= 10;
    
    vector<pair<int,int>> v(m);
    for(int i=0;i<m;++i){
        int s,c;
        cin>>s>>c;
        s--;
        v[i] = {s,c};
    }
    for(int i=0;i<1000;++i){
        string s = to_string(i);
        if(s.size() != n)continue;
        bool ng = false;
        for(auto cur : v){
            if(s.substr(cur.first,1) != to_string(cur.second)) ng = true;
        }
        if(!ng){
            cout << i << endl;
            return 0;
        }
    }
    
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100001];
int b[100001];

int main(int argc, const char * argv[]) {
    
    int n,h;
    
    scanf("%d %d",&n,&h);
    
    int ma = 0;
    int ai = 0;
    for(int i=0;i<n;i++){
        scanf("%d %d",&a[i],&b[i]);
        
        if(ma < a[i]) {
            ma = a[i];
            ai = i;
        }
    }
    
    sort(b,b+n);
    int ans = 0;
    
    for(int i=n-1;i>=0;i--){
        if(ma > b[i]){
            break;
        }else{
            h = h - b[i];
            ans++;
            if(h<=0){
                printf("%d\n",ans);
                return 0;
            }
        }
    }
    
    if(h%ma != 0  && h>0){
        ans+=1;
    }
    
    printf("%d\n",ans + h/ma);
    
    return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

ll pows(ll a, ll b)
{
  ll left=b;
  ll ks=a;
  ll ans=1;
  while(left>0)
  {
    if(left%2==1)
    {
      ans=(ans*ks)%MOD;
    }
    left/=2;
    ks=ks*ks%MOD;
  }
  return ans;
}

ll mod_inv(ll a)
{
  return pows(a,MOD-2);
}

int main()
{
  ll n;cin>>n;
  vector<int> a(n-1);
  vector<int> b(n-1);
  int i,j;
  rep(i,n-1)
  {
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
  }
  vector<vector<int>> g(n);
  rep(i,n-1)
  {
    g[a[i]].emplace_back(b[i]);
    g[b[i]].emplace_back(a[i]);
  }
  queue<int> q;
  queue<int> q2;
  q.push(0);
  vector<int> depth(n,-1);
  vector<int> root(n,-1);
  depth[0]=0;
  while(!q.empty())
  {
    while(!q.empty())
    {
      int now=q.front();
      q.pop();
      rep(i,g[now].size())
      {
        if(depth[g[now][i]]==-1)
        {
          depth[g[now][i]]=depth[now]+1;
          root[g[now][i]]=now;
          q2.push(g[now][i]);
        }
      }
    }
    while(!q2.empty())
    {
      q.push(q2.front());
      q2.pop();
    }
  }
  vector<ll> part(n,0);
  vector<pair<int,int>> ps(n);
  rep(i,n)ps[i]=make_pair(depth[i],i);
  sort(all(ps));
  reverse(all(ps));
  rep(i,ps.size()-1)
  {
    int now=ps[i].second;
    rep(j,g[now].size())
    {
      if(g[now][j]==root[now])continue;
      part[now]+=part[g[now][j]];
    }
    part[now]++;
  }
  ll psum=0;
  for(i=1;i<n;i++)
  {
    ll add=1;
    add=add-mod_inv(pows(2,part[i]))+MOD;
    add%=MOD;
    add=add-mod_inv(pows(2,n-part[i]))+MOD;
    add%=MOD;
    add=add+mod_inv(pows(2,n));
    add%=MOD;
    psum=(psum+add)%MOD;
  }
  ll ans=psum+1-n*mod_inv(2)-mod_inv(pows(2,n));
  ans=(ans+(n+1)*MOD)%MOD;
  cout<<ans<<endl;
}


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

int main() {

    int n;
    cin >> n;

    set<string> S;

    while(n--)
    {
        string s;
        cin >> s;
        S.insert(s);
    }

    cout << S.size() << "\n";
    return 0;
}


Measured memory_bytes: 19068
# -*- coding: utf-8 -*-
from sys import stdin
N, Y = [int(x) for x in stdin.readline().rstrip().split()]

x = -1
y = -1
z = -1

for i in range(N + 1):
    for j in range(N + 1 - i):
        #print("{} {}".format(i, j))
        if (10000 * i + 5000 * j + 1000 * (N - i - j)) == Y :
            x = i
            y = j
            z = N - i - j
            break
    if(x > 0) : 
        break

print("{} {} {}".format(x, y, z))
         

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long li;


li n;

bool isred(const vector<li>& query) {
    cout << "?";
    for (int i = 0; i < n; ++i) {
        cout << " " << query[i] + 1;
    }
    cout << endl;
    string response;
    cin >> response;
    return response[0] == 'R';
}

int main() {
    cin >> n;

    vector<li> first_query;
    for (int i = 0; i < n; ++i) {
        first_query.push_back(i);
    }

    bool first_response = isred(first_query);

    li l = 0, r = n;
    while (r - l > 1) {
        li m = (l + r) / 2;
        vector<li> query;
        for (int i = 0; i < n; ++i) {
            query.push_back(m + i);
        }
        bool response = isred(query);
        if (first_response == response) {
            l = m;
        } else {
            r = m;
        }
    }

    vector<bool> ans(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        vector<li> query;
        bool mask = false;
        if (l + 1 <= i && i < l + n) {
            mask = true;
            for (int j = l; j <= l + n; ++j) {
                if (j != i) {
                    query.push_back(j);
                }
            }
        } else {
            mask = false;
            for (int j = l + 1; j < l + n; ++j) {
                query.push_back(j);
            }
            query.push_back(i);
        }
        sort(query.begin(), query.end());
        ans[i] = isred(query) != mask;

    }

    cout << "! ";
    for (int i = 0; i < 2 * n; ++i) {
        if (ans[i]) {
            cout << "R";
        } else {
            cout << "B";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 724
def main():
    import sys
    import sys
    sys.setrecursionlimit(10 ** 7)
    input=sys.stdin.readline
    N,Q = map(int,input().split())
    AB = [[x for x in map(int,input().split())] for _ in range(N-1)]
    PX = [[x for x in map(int,input().split())] for _ in range(Q)]

    G = [[] for _ in range(N+1)]
    for a,b in AB:
        G[a].append(b)
        G[b].append(a)

    cnt = [0]*N
    for p,x in PX:
        cnt[p-1] += x
    
    color = ["WHITE"] * N
    def dfs(u):
        color[u-1] = "GRAY"
        for u_next in G[u]:
            if color[u_next-1] == "WHITE":
                cnt[u_next-1] += cnt[u-1]
                dfs(u_next)
        color[u-1] == "BLACK"

    dfs(1)
    print(*cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 337852
import sys
sys.setrecursionlimit(10**8)
N=int(input())
P=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
table=[[] for i in range(N)]
for i in range(N-1):
    table[P[i]-1].append(i+1)
dp=[0]*N #shiro

def tree(pa):
    for i in table[pa]:
        tree(i)
    t=len(table[pa])
    if t==0:
        return
    T=set()
    s=0
    for i in range(t):
        x=table[pa][i]
        s+=X[x]+dp[x]
        if i==0:
            if X[x]<=X[pa]:
                T.add(X[x])
            if dp[x]<=X[pa]:
                T.add(dp[x])
            continue
        S=set()
        for k in T:
            if k+X[x]<=X[pa]:
                S.add(k+X[x])
            if k+dp[x]<=X[pa]:
                S.add(k+dp[x])
        T=S
    if len(T)==0:
        print('IMPOSSIBLE')
        sys.exit()
    dp[pa]=s-max(T)
    return

tree(0)    
print('POSSIBLE')

Measured memory_bytes: 3572
// https://atcoder.jp/contests/abc167/tasks/abc167_c
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 12
const int INF = 1e9;
int n,m,x;
int c[MAX_N];
int a[MAX_N][MAX_N];
int sum[MAX_N];

int dfs(int v,int cost){
	if(v==n){
		rep(i,m){
			if(sum[i]<x){
				return INF;
			}
		}
		return cost;
	}

	int cost1 = dfs(v+1,cost);
	rep(i,m){
		sum[i] += a[v][i];
	}
	int cost2 = dfs(v+1,cost+c[v]);
	rep(i,m){
		sum[i] -= a[v][i];
	}
	return min(cost1,cost2);
	
}

int main() {

	cin >> n >> m >> x;
	rep(i,n){
		cin >> c[i];
		rep(j,m) cin >> a[i][j];
	}
	int ans = dfs(0,0);
	if(ans>=INF)ans=-1;
	outl(ans);
    return 0;
}



Measured memory_bytes: 3620
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

vector<int> rs;
vector<int> gs;
vector<int> bs;

ll solve(const string S, const int N) {
    ll ans = 0;
    ll exclusive_cnt = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int k = j + (j - i);
            if (k >= N) continue;
            if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) exclusive_cnt++;
        }
    }

    ans = rs.size() * gs.size() * bs.size() - exclusive_cnt;
    return ans;
}

// Based on the soltuion pdf.
int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;

    for (int i = 0; i < N; i++) {
        char c = S[i];
        if (c == 'R') {
            rs.push_back(i);
        } else if (c == 'G') {
            gs.push_back(i);
        } else {
            bs.push_back(i);
        }
    }

    cout << solve(S, N) << endl;

    return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class277
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            long ans = 0;
            for(int i = 1; i <= N; i++)
            {
                if (i % 3 == 0 || i % 5 == 0) continue;
                ans += i;
            }
            Console.WriteLine(ans);
        }
    }
}


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

typedef long long ll;

void solve() {
    string s;
    int K;
    cin >> s >> K;
    int n = s.size();
    vector<int> x(n);
    rep(i, n) x[i] = s[i] - 'a';
    rep(i, n) {
        if (x[i] == 0) continue;
        int d = 26 - x[i];
        if (K >= d) {
            x[i] = 0;
            K -= d;
        }
    }
    x[n - 1] = (x[n - 1] + K) % 26;
    rep(i, n) cout << (char)('a' + x[i]);
    cout << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 1024
# Author: cr4zjh0bp
# Created: Sun Mar 22 11:54:41 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import Counter

n = ni()
a = na()
c = Counter(a)
d = dict(c)
r = 0
for k, v in d.items():
    r += v * (v - 1) // 2

for i in range(n):
    print(r - d[a[i]] * (d[a[i]] - 1) // 2 + ((d[a[i]] - 1) * (d[a[i]] - 2) // 2))

Measured memory_bytes: 29044
j = 1

def dfs(graph, start, result, visited=None):
    global j
    if visited == None:
        visited = []
    visited.append(start)
    result[start][1]  = j
    for next in graph[start][2:]:
        if next in visited:
            continue
        j += 1
        dfs(graph, next, result, visited)
    else:
        j += 1
        result[start][2] = j

n = int(input())
g = [[]]
r = [[i,0,0] for i in range(n + 1)]
v = []

for i in range(n):
    g.append(list(map(int, input().split())))


for i in range(1, n + 1):
    if i in v:
        continue
    dfs(g,i,r,v)
    j += 1

for i in range(1,n+1):
    print(*r[i])

Measured memory_bytes: 7896
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> v(100005);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;

        ++v[x];
        ++v[x+1];
        ++v[x+2];
    }

    int ans = 0;
    for (int i = 0; i < v.size(); ++i) ans = max(ans, v[i]);
    cout << ans << '\n';
}

Measured memory_bytes: 640
// 円形検索

#include <stdio.h>
#include <string.h>

int main(void){
  char mz[300];  // 今回の文字列
  char sermz[300]; // 検索する文字列
  int sz,ssz,i,j;
  int cn=0;

  scanf("%s", mz);
  sz = strlen(mz);

  scanf("%s", sermz);
  ssz = strlen(sermz);

  while(i<sz){
    if(mz[i] == sermz[0]){
      for(j=0; j<ssz;j++){
        if(i+j >= sz){
          if(sermz[j] != mz[i+j-sz]) break;
        }else{
          if(sermz[j] != mz[i+j]) break;
        }
        if(j==ssz-1) cn = 1;
      }
    }
    i++;
  }

  if(cn == 1)  {
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>

using ll = long long;
const ll INF = (ll)1e18 + 1;

ll f(ll x) {
  ll ans = 0;
  while (x > 0) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}

double g(ll x) {
  return (double)(x)/f(x);
}

int main(int argc, char* argv[])
{
  ll K;
  std::cin >> K;

  std::vector<ll> vec;
  ll base = 1;

  for (ll i = 0; i < 15; i++) {
    for (ll j = 1; j < 999; j++) {
      ll num = base * j - 1;
      if (num > 0) vec.push_back(num);
    }
    base *= 10;
  }
  std::sort(vec.begin(), vec.end());
  vec.erase(std::unique(vec.begin(), vec.end()), vec.end());

  std::vector<ll> vans;
  for (ll i = 0; i < (ll) vec.size(); i++) {
    bool is_ok = true;
    for (ll j = i+1; j < (ll) vec.size(); j++) {
      if (g(vec[i]) > g(vec[j])) {
	is_ok = false;
	break;
      }
    }
    if (is_ok) vans.push_back(vec[i]);
  }

  for (ll i = 0; i < K; i++) {
    std::cout << vans[i] << std::endl;
  }
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] m = new int[n];

        int sumG = 0;
        int minDonut = 1001;

        for (int i = 0; i < n; i++) {
            m[i] = sc.nextInt();
            sumG += m[i];
            minDonut = Math.min(minDonut, m[i]);
        }

        int sumDonut = n + (x - sumG) / minDonut;
        System.out.println(sumDonut);
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
// #define int long long
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
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
#define endl "\n"
const int oo = INT_MAX;
const int MOD = 1e9 + 7;
const int sz = 1e5 + 5;
int solve(int n){ 
    int ret = 0; 
    for (int i = 1; i <= sqrt(n - 1); ++i) { 
        for (int j = i; j * i < n; ++j) 
            ++ret; 
    } 
    ret *= 2; 
    ret -= int(sqrt(n - 1)); 
    return ret; 
} 
int32_t main() {
    IOS;
    
    int tc = 1;
    //cin >> tc;
    while(tc--) {
        int n; cin >> n;
        cout << solve(n);
        

    }
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=55,M=110;
ll n,m,s,amax,smax,tot;
ll u[M],v[M],a[M],b[M];
ll c[N],d[N];
struct state{
	ll d,re,ct;
	bool operator<(const state &A)const{
		return d>A.d;
	}
};
ll dis[N*N*N],vis[N*N*N];
ll to[M<<1],nxt[M<<1],id[M<<1],hd[N];
void add(ll t,ll f,ll i){
	to[++tot]=t;
	id[tot]=i;
	nxt[tot]=hd[f];
	hd[f]=tot;
}
inline ll getstate(ll re,ll ct){return re*N+ct;}
inline void chk(ll &a,ll b){
	if(b<a) a=b;
}
void dijkstra(){
	priority_queue<state> q;
	memset(dis,0x3f,sizeof(dis));
	q.push((state){0,s,1});
	dis[getstate(s,1)]=0;
	while(!q.empty()){
		state now=q.top();q.pop();
		ll ct=now.ct,re=now.re;
		ll st=getstate(re,ct);
		if(vis[st]) continue;
		vis[st]=1;
		//printf("st=%lld,dis[%lld][%lld]=%lld\n",st,re,ct,dis[st]);
		for(ll i=hd[ct];i;i=nxt[i]){
			ll nxtct=to[i];
			for(ll j=0;;++j){
				ll k=re+c[ct]*j;
				if(k<a[id[i]]) continue;
				if(k>smax) k=smax;
				ll nxtre=k-a[id[i]];
				ll nxtst=getstate(nxtre,nxtct);
				ll nxtdis=dis[st]+b[id[i]]+d[ct]*j;
				if(!vis[nxtst]&&dis[nxtst]>nxtdis){
					dis[nxtst]=nxtdis;
					q.push((state){nxtdis,nxtre,nxtct});
					//printf("nxtst=%lld,dis[%lld][%lld]=%lld\n",nxtst,nxtre,nxtct,dis[nxtst]);
				}
				if(k==smax) break;
			}
		}
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	scanf("%lld %lld %lld",&n,&m,&s);
	//printf("%lld %lld %lld\n",n,m,s);
	for(ll i=1;i<=m;++i){
		scanf("%lld %lld %lld %lld",&u[i],&v[i],&a[i],&b[i]);
		//printf("%lld %lld %lld %lld\n",u[i],v[i],a[i],b[i]);
		add(u[i],v[i],i);
		add(v[i],u[i],i);
		if(amax<a[i]) amax=a[i];
	}
	smax=amax*(n-1);
	chk(s,smax);
	for(ll i=1;i<=n;++i){
		scanf("%lld %lld",&c[i],&d[i]);
		//printf("%lld %lld\n",c[i],d[i]);
	}
	dijkstra();
//	for(ll i=1;i<=n;++i){
//		for(ll j=hd[i];j;j=nxt[j]){
//			printf("from=%lld,to=%lld,id=%lld\n",i,to[j],id[j]);
//		}
//	}
	for(ll i=2;i<=n;++i){
		ll min=dis[0];
		for(ll r=0;r<=smax;++r){
			chk(min,dis[getstate(r,i)]);
		}
		printf("%lld\n",min);
	}
}

Measured memory_bytes: 54972
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    vector<ll> a(5,0);
    cin >> N >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    VSORT(a);
    ll min = a[0];
    ll b = ceil((double)N/(double)min);
    cout << 5 + b - 1 << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	vector < string > week = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	char input[10];
	string str;

	scanf("%s", input);

	str = input;

	int day;

	for (int i = 0; i < 7; i++)
	{
		if (str == week[i])
		{
			day = i;

			break;
		}
	}

	printf("%d\n",(7 - day));

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  transform(a.begin(), a.end(), a.begin(), ::toupper);
  transform(b.begin(), b.end(), b.begin(), ::toupper);
  transform(c.begin(), c.end(), c.begin(), ::toupper);
  cout << a[0] << b[0] << c[0] << endl;
  return 0;
}

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

typedef pair<int, int> pii;

const int V = 204, src = V - 2, snk = V - 1;

int X(int v) {
    return v;
}
int Y(int v) {
    return 101 + v;
}

int A, B, E;
int D[12][12];
vector<pii> adj[V];

int main() {
    scanf("%d %d", &A, &B);

    for(int i = 1; i <= A; i++) {
        for(int j = 1; j <= B; j++) {
            scanf("%d", &D[i][j]);
        }
    }

    adj[src].push_back(pii(X(0), 0));
    adj[Y(0)].push_back(pii(snk, 0));

    for(int i = 0; i < 100; i++) {
        adj[ X(i) ].push_back(pii(X(i + 1), -1));
    }
    for(int i = 100; i >= 1; i--) {
        adj[ Y(i) ].push_back(pii(Y(i - 1), -2));
    }

    for(int i = 1; i <= A; i++) {
        for(int j = 1; j <= B; j++) {

            bool f = false;
            for(int a = 0; a <= 100 / i; a++) {
                for(int b = 0; b <= 100 / j; b++) {
                    int c = D[i][j] - a * i - b * j;
                    if(c < 0) continue;

                    bool ok = true;
                    for(int x = 1; x <= A; x++) {
                        for(int y = 1; y <= B; y++) {
                            if(D[x][y] > a * x + b * y + c) {
                                ok = false;
                                break;
                            }
                        }
                    }

                    if(ok) {
                        adj[X(a)].push_back(pii(Y(b), c));
                        f = true;
                        break;
                    }
                }
                if(f) break;
            }

            if(!f) {
                printf("Impossible");
                return 0;
            }
        }
    }

    printf("Possible\n");

    E = 0;
    for(int u = 0; u < V; u++) {
        sort(adj[u].begin(), adj[u].end());

        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i].first;
            int w = adj[u][i].second;

            if(i == 0 || adj[u][i - 1] != adj[u][i]) {
                E++;
            }
        }
    }

    printf("%d %d\n", V, E);
    for(int u = 0; u < V; u++) {
        sort(adj[u].begin(), adj[u].end());

        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i].first;
            int w = adj[u][i].second;

            if(i == 0 || adj[u][i - 1] != adj[u][i]) {
                if(w == -1) printf("%d %d X\n", u + 1, v + 1);
                else if(w == -2) printf("%d %d Y\n", u + 1, v + 1);
                else printf("%d %d %d\n", u + 1, v + 1, w);
            }
        }
    }

    printf("%d %d", src + 1, snk + 1);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll X, total = 0;
int main(){
  cin >> X;
  if (X<5) cout << 0 << endl;
  else{
    ll large = X/500;
    X -= (large * 500);
    total += large * 1000;
    ll small = X/5;
    X -= (small*5);
    total += small * 5;
    cout << total << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
for i in range(len(x)):
    x[i] = abs(x[i] - X)

for i in range(len(x)-1):
    a, b = x[i], x[i+1]
    while b > 0:
        a, b = b, a % b
    x[i+1] = a

print(x[-1])

Measured memory_bytes: 14252
def main():

    sa = list(input())
    sb = list(input())
    sc = list(input())

    turn = 'a'

    #sa,sb,scのlengthが0以上ならループ
    while True:
        if turn == 'a':
            if len(sa)>0:
                turn = sa.pop(0)
            else:
                print('A')
                return
        elif turn == 'b':
            if len(sb)>0:
                turn = sb.pop(0)
            else:
                print('B')
                return
        elif turn == 'c':
            if len(sc)>0:
                turn = sc.pop(0)
            else:
                print('C')
                return


if __name__ == "__main__":
    main()

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

int main()
{

	long long N;
	cin >> N;

	long long s = 0;

	for (long long i = 1; i <= N; ++i) {
		if (i % 3 != 0 && i % 5 != 0) {
			s += i;
		}
	}

	cout << s << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int n;
double x[15],y[15],L[15];
typedef complex<double> pt;
vector<pt>List;
vector<pt> CCintersect (pair<pt,double> c, pair<pt,double> d) {
    vector<pt> ret;
    double dist = abs(c.first - d.first);
    double cr = c.second;
    double dr = d.second;
    
    if (dist > cr + dr) return ret;
    if (dist < abs(cr - dr)) return ret;
    
    double s = (cr + dr + dist) / 2.;
    double area = sqrt(s * (s - cr) * (s - dr) * (s - dist));
    double h = 2 * area / dist;
    
    pt v = d.first - c.first; v /= abs(v);
    pt m = c.first + sqrt(cr * cr - h * h) * v;
    pt n = v * pt(0, 1);
    
    List.push_back(m + n * h);
    List.push_back(m - n * h);
    return ret;
}
#define eps 1e-11
int main(){
    while(1){
        cin >> n; if(!n) return 0;
        for(int i=1;i<=n;i++){
            scanf("%lf%lf%lf",&x[i],&y[i],&L[i]);
        }if(n==1) { printf("%.10f",L[1]); puts(""); continue;}
        double lb = 1.0,ub = 305.0;
        for(int r = 0;r < 100; r++){
            double mid = (lb+ub)/2; bool ok = 0; List.clear();
            for(int i=1;i<=n;i++){
                if(mid > L[i]) goto fail;
                List.push_back(pt(x[i],y[i]));
            }
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    pt x1 = pt(x[i],y[i]); double r1 = sqrt(L[i]*L[i]-mid*mid);
                    pt x2 = pt(x[j],y[j]); double r2 = sqrt(L[j]*L[j]-mid*mid);
                    CCintersect(make_pair(x1,r1),make_pair(x2,r2));
                }
            }
            for(int i=0;i<List.size();i++){
                for(int j=1;j<=n;j++){
                    if(abs(List[i]-pt(x[j],y[j])) > sqrt(L[j]*L[j]-mid*mid)+eps) goto bad;
                }
                ok = 1; break; bad:;
            }
        fail:; if(ok) lb = mid; else ub = mid;
        }
        printf("%.10f",(lb+ub)/2); puts("");
    }
}

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

int main() {
  long int n,a,b,c,d,x,y;
  cin>>n>>a>>b>>c>>d;
  
  for(long int i=0;i<n;i++){
    x=(n-i-1)*(-1);
    y=i;
    if(x*d+y*c<=a-b && a-b<=x*c+y*d){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
void call(int n);
int main(int argc, char const* argv[])
{
	int n;
	std::cin >> n;
	call(n);
	return 0;
}

using namespace std;

void call(int n){
	int i = 1;
	do {
		int x = i;
		if ( x % 3 == 0 ){
			cout << " " << i;
		} else {
			do {
				if ( x % 10 == 3 ){
					cout << " " << i;
					break;
				}
				x /= 10;
			} while( x ) ;
		}
	} while ( ++i <= n );

	cout << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <sstream>

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define C(x) cout << x << endl //テスト出力

//関数
//nCkの計算の関数(呼び出しは[cbn])
ll cbn(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
// a^n mod を計算する
ll powmod(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
//２つの最大公約数
int gcb(int a, int b){
    if(a < b){
        int x = a;
        a = b;
        b = x;
    }
    int amari = a % b;
    if(amari == 0) return b;

    return gcb(b, amari);
}
//３つの最大公約数
int gcb_3(int a, int b, int c){
    return gcb(gcb(a, b), c);
}

/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;
vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))*/

/*-----------------------------ここから-----------------------------*/

int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,x,y; cin>>a>>b>>c>>x>>y;
ll ans = 0;
if(a+b>2*c) cout<<min(min(x,y)*c*2+a*(x-min(x,y))+b*(y-min(x,y)),max(x,y)*c*2);
else cout<<a*x+b*y;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	string s; cin >> s;
	REP(i, s.size())cout << 'x';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int main(){
    ll K; cin >> K;

    int N = 50;
    ll count = K/N;

    vector<ll> a(N);
    rep(i,N){
        a[i] = count+i;
    }

    ll remain = K % N;
    while (remain > 0){
        
        sort(a.begin(), a.end());
        rep(i,N){
            if (i == 0){
                a[i] += N;
            }
            else{
                a[i]--;
            }
        }

        remain--;
    }

    cout << N << endl;
    rep(i,N){
        cout << a[i];
        if (i != N-1) cout << " ";
        else cout << "\n";
    }
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vll vector <ll>
#define vvi vector <vector <int> >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 5e5+100;
const ll INF = 1e9;
const ll kek=998244353;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

ll binpower(ll a,ll b)
{
    if (b==0)
        return 1;
    if (b==1)
        return a;
    ll t=(binpower(a,b/2))%mod1;
    if (b%2==1)
        return (((t*t)%mod1)*a)%mod1;
    else
        return (t*t)%mod1;
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll x,y;
    cin>>x>>y;
    if ((x+y)%3!=0)
        cout<<0;
    else
    {
        ll q=(x+y)/3;
        if (x<q||y<q)
            cout<<0;
        else
        {
            x-=q;
            y-=q;
            ll t=1;
            for (ll i=1;i<=x+y;i++)
            {
                t*=i;
                t%=mod1;
            }
            ll f=1,r=1;
            for (ll i=1;i<=x;i++)
            {
                f*=i;
                f%=mod1;
            }
            for (ll i=1;i<=y;i++)
            {
                r*=i;
                r%=mod1;
            }
            cout<<(((t*binpower(f,mod1-2))%mod1)*binpower(r,mod1-2))%mod1;
        }
    }
}


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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int h,w;
char mp[10][10];

int main(){
  scanf("%d%d",&h,&w);
  REP(i,h)scanf("%s",mp[i]);
  int cnt = 0;
  REP(i,h)cnt+=count(mp[i],mp[i]+w,'#');
  puts(cnt==w+h-1?"Possible":"Impossible");
  return 0;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h+2, vector<char>(w+2, '#'));
    int white = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> s[i][j];
            if (s[i][j] == '.') white++;
        }
    }

    queue<tuple<int, int, int>> q;
    q.emplace(1, 1, 1);
    s[1][1] = '#';

    int ans = -1;
    vector<int> dxy{ 0, 1, 0, -1, 0 };
    while (!q.empty()) {
        auto n = q.front(); q.pop();
        int ch = get<0>(n), cw = get<1>(n), d = get<2>(n);

        if (ch == h && cw == w) {
            ans = white - d;
            break;
        }

        for (int i = 0; i < 4; i++) {
            if (s[ch + dxy[i]][cw + dxy[i+1]] == '.') {
                q.emplace(ch + dxy[i], cw + dxy[i+1], d + 1);
                s[ch + dxy[i]][cw + dxy[i+1]] = '#';
            }
        }
    }
    
    cout << ans << endl;
}


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

using namespace std;

const int MOD = 998244353;

namespace std{
    template<size_t N>
    struct less<bitset<N> > : binary_function <bitset<N>,bitset<N>,bool>{
        bool operator()(const bitset<N> &L, const bitset<N> &R) const{
            for(unsigned int i=0;i<L.size();i++)
                if(L.test(i)){
                    if(!R.test(i))return false;
                }else{
                    if(R.test(i))return true;
            }
            return false;
        }
    };
}
unordered_map <bitset <101>, int> memo;

bitset <101> takeOnly[101];

bitset <101> substr(const bitset <101> &b, const int l, const int r) {
    return ((b & takeOnly[r + 1]) >> l);
}

static int solve(const int N, bitset <101> str) {
    str[N] = 1;
    const auto it = memo.find(str);
    if (it != memo.end())
        return it -> second;

    // Do nothing
    int ans = 1;
    for (int i = 0; i < N; ++ i)
        if (str[i] == 1)
            ans = (2LL * ans) % MOD;

    // Split in 2 halves
    for (int r = 1; r < N; ++ r) {
        int pow2 = 1;
        const int aux = solve(N - r - 1, substr(str, r + 1, N - 1));
        for (int l = 0; l < r; ++ l) {
            for (int per = 1; per < r - l + 1; ++ per) if ((r - l + 1) % per == 0) {
                // Try splitting in groups of length per
                bitset <101> acc = substr(str, l, l + per - 1);
                for (int x = l + per; x <= r; x += per)
                    acc &= substr(str, x, x + per - 1);
                ans = (ans + (1LL * pow2 * solve(per, acc)) % MOD * aux) % MOD;
            }
            if (str[l] == 1)
                pow2 = (2LL * pow2) % MOD;
        }
    }

    memo[str] = ans;
    return ans;
}

int main()
{
    memo.max_load_factor(0.5);

    for (int i = 0; i < 101; ++ i)
        for (int j = 0; j < i; ++ j)
            takeOnly[i][j] = 1;

    string s;
    cin >> s;

    bitset <101> str;
    for (int i = 0; i < s.size(); ++ i)
        if (s[i] == '1')
            str[i] = 1;
    cout << solve(s.size(), str) << '\n';
    return 0;
}


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

int main(){
  int n,m,ans=0;
  map<string,int> ma;
  cin >> n;
  string s,t;
  r(i,n){
    cin >> s;
    ma[s]++;
  }
  cin >> m;
  r(i,m){
    cin >> t;
    ma[t]--;
  }
  for(auto it=ma.begin();it!=ma.end();++it){
    if(ans<(*it).second)ans=(*it).second;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
S=input()
L=[[0,0]]*(N+2)
numW=0
numE=0
for i in range(0,N):
  if S[i]=='W':
    numW+=1
  else:
    numE+=1
  L[i+1]=[numW,numE]

L[N+1]=L[N]
  
INF=10**6
ans=INF

for i in range(1,N+1):
  ans=min(ans,L[i-1][0]+numE-L[i][1])
  
print(ans)

Measured memory_bytes: 45496
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N,M;cin>>N>>M;
  map<int,int> m;
  for(int i=0;i<M;i++){int a;cin>>a;m[a]=1;}
  std::vector<int> dp(N+5,0);
  dp[0]++;
  for(int i=0;i<N;i++){
    if(m[i])continue;
    dp[i+1]+=dp[i];dp[i+1]%=MOD;
    dp[i+2]+=dp[i];dp[i+2]%=MOD;
  }
  cout<<dp[N]<<endl;
}


Measured memory_bytes: 7296