akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] score = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            List<string> color_list = new List<string>();
            string color = null;
            int black = 0;

            foreach (int i in score)
            {
                if (i < 400) color = "gray";
                else if (i < 800) color = "brown";
                else if (i < 1200) color = "green";
                else if (i < 1600) color = "lightblue";
                else if (i < 2000) color = "blue";
                else if (i < 2400) color = "yellow";
                else if (i < 2800) color = "orange";
                else if (i < 3200) color = "red";
                else black++;

                if (!color_list.Contains(color) && !string.IsNullOrEmpty(color))
                {
                    color_list.Add(color);
                }
            }

            int min = (color_list.Count == 0) ? 1 : color_list.Count;

            Console.WriteLine(min + " " + (color_list.Count + black));
        }
    }
}


Measured memory_bytes: 13152
N, K = gets.chomp.split(" ").map(&:to_i)

ans = []
if K <= ((N-1)*(N-2))/2 then
  (1...N).each{|n| ans << [n, N]}
  wk = ((N-1)*(N-2))/2
  (1..(N-2)).each{|i|
    ((i+1)..(N-1)).each{|j|
      break if wk == K
      ans << [i, j]
      wk -= 1
    }
    break if wk == K
  }
end

if ans.size == 0 then
  puts -1
else
  puts ans.size
  puts ans.map{|a| a*?\s}*?\n
end


Measured memory_bytes: 3068
function Main(input) {
	input = input.split(" ");
	var intInput = input.map( v => parseInt(v,10));
  	var wat = intInput[2]-(intInput[0]-intInput[1])
  	console.log( (wat)<0? 0:wat);
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
// #define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, A, B, C, D;
	string s;
	
	cin>>N>>A>>B>>C>>D;
	
	cin>>s;
	
	if(D > C){
		bool flag = true;
		for(int i = B; i < D; i++){
			if(s[i-1] == '#' && s[i] == '#'){
				flag = false;
				break;
			}
		}
		for(int i = A; i < C; i++){
			if(s[i-1] == '#' && s[i] == '#'){
				flag = false;
				break;
			}
		}
		cout<<yn(flag)<<endl;
	} else {
		bool flag = true, flag2 = false;
		for(int i = A; i < B; i++){
			if(s[i-1] == '#' && s[i] == '#'){
				flag = false;
				break;
			}
		}
		for(int i = B-1; i < D; i++){
			if(s[i-1] == '#' && s[i] == '#'){
				flag = false;
				break;
			}
			if(i != s.size()-1){
				if(s[i-1] == '.' && s[i+1] == '.' && s[i] == '.'){
					flag2 = true;
				}
			}
		}
		for(int i = A; i < C; i++){
			if(s[i-1] == '#' && s[i] == '#'){
				flag = false;
				break;
			}
		}
		
		// cout<<flag<<" "<<flag2<<endl;
		cout<<yn(flag && flag2)<<endl;
	}
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int ans = 1000;
    for (int i = 0; i < N; i++){
        int A;
        cin >> A;
        int count = 0;
        while (A % 2 == 0){
            count++;
            A /= 2;
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		System.out.println((a+b)*h/2);
		sc.close();
	}
}


Measured memory_bytes: 9680
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

#define fprintf(...) void(0)
int imos[1010];
 
signed main() {
    int N, M; cin >> N >> M;
    for(int i=0; i<M; i++) {
        int l, r; cin >> l >> r;
        imos[l]++;
        imos[r]--;
    }

    for(int i=0; i<N+3; i++) {
        imos[i+1] += imos[i];
    }

    int ans = N+1, last = -1;
    for(int i=0; i<N+3; i++) {
        if(imos[i+1] > 0 && imos[i] == 0) {
            last = i+1;
        }
        if(imos[i+1] == 0 && imos[i] > 0) {
            ans += (i+1 - last) * 2;
            fprintf(stderr, "add: [%lld, %lld)\n", last, i+1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3132
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    H, N = NMI()
    M = [NLI() for _ in range(N)]
    # dp[i] はiダメージ与えたときの最小の魔力
    dp = [10**10] * (H+10)
    dp[0] = 0
    for i in range(H):
        for m in M:
            dp[min(i+m[0], H)] = min(dp[min(i+m[0], H)], dp[i] + m[1])
    print(dp[H])



if __name__ == "__main__":
    main()

Measured memory_bytes: 74780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

// #define int ll
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define fst first
#define pb push_back

const int TIMES = 10;

const int MOD = (int)1e9 + 7;

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

    vector<vector<int>> Fss(N, vector<int>(TIMES));
    REP(i, N) {
        REP(k, TIMES) {
            cin >> Fss.at(i).at(k);
        }
    }

    // 0があるから+1
    vector<vector<int>> Pss(N, vector<int>(TIMES+1));
    REP(i, N) {
        REP(k, TIMES + 1) {
            cin >> Pss.at(i).at(k);
        }
    }

    // 全探索でいきましょう
    int ans = numeric_limits<int>::min();

    FORE(state_bit, 1, 1023) {
        // debug(state_bit);

        int cost = 0;
        REP(shop, N) {
            // お姉ちゃんの店と店shopの両方が営業している時間帯の個数
            int cnt = 0;

            // 重なっている時間帯を調べたいよね
            REP(t, TIMES) {
                int joisino_open_at_t = (state_bit & (1 << t)) >> t;

                if (joisino_open_at_t == 1 && Fss.at(shop).at(t) == 1) {
                    cnt += 1;
                }
            }

            // コストを足す
            cost += Pss.at(shop).at(cnt);
        }

        if (cost > ans) {
            ans = cost;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lint long long int
#define sudo std::
#define girdi freopen("motor.gir", "r", stdin);
#define cikti freopen("motor.cik", "w", stdout);
#define faster ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0);
#define cend << "\n";
#define cspace << " ";
#define space << " " <<
#define modal  %= 1000000007
#define P system("PAUSE");
using namespace std;
//vector <string> nec; 300milyon
//vector <int> mec;5545036815
//vector <bool> visited(1000000,0);
//map <lint,char> eksi;
//map <int,vector <int>> yollar;
//map <char,vector <pair<char,int> > > yollar;
//priority_queue <int> pq;
//set <int> ster;
//return cout << 0,0;
//multiset <int> mst;
//memset(arr, 0, sizeof arr);
//priority_queue <int, vector<int>, greater<int> > pq; 
//variable = (condition) ? expressionTrue : expressionFalse;
//sort(vec.begin(), vec.end());
//for (int i = 0; n > i; i++){
///////////////////////////////////////////////

bool bol = false;
//pair <int,int> target;
vector <pair <lint,lint> > yollar[100007];
//vector <bool> visited(200007,0);
//vector <pair <lint, lint> > vec;
//int kassen[2007][2007];
bool visited[100007];
vector <lint> vec(100007,1000007);
//lint vec[1000007];
//map <char,lint> mp;
///**************///**************///
char fe,fa,fu,fi;
lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
lint mis = 1000000007,mas = -1000000007,ans,bas,mid,son,st,en,temp,sum,prd,now;
string aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz;
///////////////////////////////////////////////

int main (void){
    faster
    //girdi
    //cikti
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
  	cin >> x;
  	k = 100;
    while (k < x){
      	k += k / (lint)100;
    	ans++;
    }
  	cout << ans;
}

Measured memory_bytes: 6284
#include <bits/stdc++.h>
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

int main () {
  int h, w, d;
  cin >> h >> w >> d;
  vi px(h*w+1), py(h*w+1);
  rep(i,h)rep(j,w) {
    int a;
    cin >> a;
    px[a] = i, py[a] = j;
  }
  vi csum(h*w+1);
  for (int i = d+1; i <= h*w; ++i) {
    csum[i] = csum[i-d] + abs(px[i]-px[i-d]) + abs(py[i]-py[i-d]);
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    printf("%d\n", csum[r]-csum[l]);
  }
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(void){
  int n; cin >> n;
  int a;
  FOR(i,0,n-1) {
    cin >> a;
    if(a%2==0){
      if(a%3!=0 && a%5!=0){
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }

  cout << "APPROVED" << endl;
  return 0;

  
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

struct xy{double x, y;};
double sum = 0, factorial = 0;
int n;
xy A[8];
bool b[8];
void rec(bool B[], int i = 0, int k = 0){
    if (i >= n)return;
    for (int j = 0; j < n; j++)
    {
        if(B[j]) continue;
        if(i >= 1){
            factorial += 1;
            sum += sqrt((A[j].x - A[k].x) * (A[j].x - A[k].x) + (A[j].y - A[k].y) * (A[j].y - A[k].y));
        }
        B[j] = true;
        rec(B, i+1, j);
        B[j] = false;
    }
}

int main(){
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        double x, y; cin >> x >> y;
        A[i].x = x; A[i].y = y;
    }
    rec(b);
    factorial /= (n-1);
    cout << setprecision(16) << sum / factorial << endl;
}

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

vector<ll> pos;

template <typename T, const T id>
class convex_hull_trick {
	struct line {
		T a, b;
		line(T a_ = 0, T b_ = 0) : a(a_), b(b_) {}
		T get(T x) { return a * x + b; }
	};
	struct node {
		line l;
		node *lch, *rch;
		node(line l_) : l(l_), lch(nullptr), rch(nullptr) {}
	};
	const int n;
	node *root;
	node* modify(node *p, int lb, int ub, line& l) {
		if (!p) return new node(l);
		if (p->l.get(pos[lb]) >= l.get(pos[lb]) && p->l.get(pos[ub]) >= l.get(pos[ub])) return p;
		if (p->l.get(pos[lb]) <= l.get(pos[lb]) && p->l.get(pos[ub]) <= l.get(pos[ub])) {
			p->l = l;
			return p;
		}
		int c = (lb + ub) >> 1;
		if (p->l.get(pos[c]) < l.get(pos[c])) swap(p->l, l);
		if (p->l.get(pos[lb]) <= l.get(pos[lb]))
			p->lch = modify(p->lch, lb, c, l);
		else
			p->rch = modify(p->rch, c + 1, ub, l);
		return p;
	}
	T sub(node *p, int lb, int ub, int t) const {
		if (!p) return id;
		if (ub - lb == 0) return p->l.get(pos[t]);
		int c = (lb + ub) >> 1;
		if (t <= c) return max(p->l.get(pos[t]), sub(p->lch, lb, c, t));
		return max(p->l.get(pos[t]), sub(p->rch, c + 1, ub, t));
	}
public:
	convex_hull_trick(int n_) : n(n_), root(nullptr) {}
	void insert(T a, T b) {
		line l(a, b);
		root = modify(root, 0, n - 1, l);
	}
	T get(T x) const {
		int t = lower_bound(pos.begin(), pos.end(), x) - pos.begin();
		assert(t < n && pos[t] == x);
		return sub(root, 0, n - 1, t);
	}
};

using CHT = convex_hull_trick<ll, LLONG_MIN>;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, T;
	cin >> N >> T;
	vector<tuple<ll, ll, ll>> ftp(N);
	for (int i = 0; i < N; i++) {
		int t, p, f;
		cin >> t >> p >> f;
		ftp[i] = make_tuple(f, t, p);
	}
	sort(ftp.begin(), ftp.end());
	vector<ll> t(N), p(N), f(N);
	for (int i = 0; i < N; i++) {
		tie(f[i], t[i], p[i]) = ftp[i];
	}
	pos = f;
	sort(pos.begin(), pos.end());
	pos.erase(unique(pos.begin(), pos.end()), pos.end());
	vector<CHT> cht(T + 1, CHT(pos.size()));
	cht[0].insert(0, 0);
	ll res = 0;
	for (int i = 0; i < N; i++) {
		for (int j = T - t[i]; j > 0; j--) {
			if (cht[j].get(pos[0]) == LLONG_MIN) continue;
			ll val = p[i] + cht[j].get(f[i]) - f[i] * f[i];
			cht[j + t[i]].insert(2 * f[i], val - f[i] * f[i]);
			res = max(res, val);
		}
		cht[t[i]].insert(2 * f[i], p[i] - f[i] * f[i]);
		res = max(res, p[i]);
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3832
N, L = map(int, input().split())

List = []

for i in range(1,N+1):
    List.append(L + i - 1)

# List.sort()

# print(int((L - 1) * N + N * (N + 1) / 2) - List[0])

ans = 0
if(List[-1] < 0):
    ans = int(sum(List)) - List[-1]
else:
    if(List[0] <= 0):
        ans = int(sum(List))
    else:
        ans = int(sum(List)) - List[0]

print(ans)



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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  
  vector<int> x(N);
  vector<int> y(N);
  vector<int> a(N);
  
  for (int i = 0; i < N; i++) {
	cin >> x.at(i) >> y.at(i) >> a.at(i);
  }

  int xlow, xup, ylow, yup;
  xlow = 0;
  xup = W;
  ylow = 0;
  yup = H;
  
  for (int i = 0; i < N; i++) {
    if ( a.at(i) == 1 ) {
      if ( x.at(i) > xlow ) {
        xlow = x.at(i);  
      }
    }
    else if ( a.at(i) == 2 ) {
      if ( x.at(i) < xup ) {
        xup = x.at(i);  
      }
    }
    else if ( a.at(i) == 3 ) {
      if ( y.at(i) > ylow ) {
        ylow = y.at(i);  
      }
    }
    else {
      if ( y.at(i) < yup ) {
        yup = y.at(i);  
      }
    }
  }  
  
  if ( xup >= xlow && yup >= ylow ) {
    cout << max ((xup-xlow)*(yup-ylow), 0) << endl;
  }
  else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;


int main(){
    string S, S_ = ""; cin >> S;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == '0') S_ += '0';
        else if(S[i] == '1') S_ += '1';
        else if(S[i] == 'B') if(S_ != "")S_.erase(S_.size()-1); 
    }
    cout << S_ << endl;
}

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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a' or c == 'e' or c == 'i' or c =='o' or c == 'u') 
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;

}


Measured memory_bytes: 256
n = int(input())
s = input()
t = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
u = [0] * len(s)
for i in range(len(s)):
    idx = 0
    for j in range(26):
        if s[i] == t[j]:
            idx = j
            break
    u[i] = t[j + n]
print(*u, sep="")

Measured memory_bytes: 4724
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a;
  rep (i, n) {
    int p; cin >> p;
    a.push_back(p);
  }
  a.push_back(x);
  sort(a.begin(), a.end());

  vector<int> dis;
  for (int i = 0; i < n; i++) {
    int q = abs(a[i] - a[i + 1]);
    dis.push_back(q);
  }

  for (int i = 1; i < dis.size(); i++) {
    dis[i] = gcd(dis[i], dis[i - 1]);
  }

  cout << dis.back() << endl;

  return 0;
}


Measured memory_bytes: 4308
import numpy as np
n = int(input())

a = np.zeros((n))
for i in range(n):
    a_tmp = int(input())
    a[i] = a_tmp

f_max = np.zeros((n))
b_max = np.zeros((n))
for i in range(n):
    if i == 0:
        f_max[0] = a[0]
        b_max[n-1] = a[n-1]
    else:
        f_max[i] = max(f_max[i-1],a[i])
        b_max[n-1-i] = max(b_max[n-1-i+1],a[n-1-i])

#print(f_max)
#print(b_max)

for i in range(n):
    if i == 0:
        print(int(b_max[1]))
    elif i == (n-1):
        print(int(f_max[n-2]))
    else:
        #print(b_max[i+1],f_max[i-1])
        print(int(max(b_max[i+1],f_max[i-1])))

Measured memory_bytes: 18616
#include<bits/stdc++.h>
using namespace std;
#define int long long
int abs(int a,int b){
  int c=max(a,b)-min(a,b);
  return c;
}
signed main(){
  int a,b,c,d;
  int e[1000000],f[100000];
  cin>>a>>b>>c>>d;
  for(int i=0;i<a;i++){
    cin>>e[i];
  }
  for(int i=0;i<b;i++){
    cin>>f[i];
  }
  sort(e,e+a,greater<int>());
  sort(f,f+b);
  if(e[0]<=f[0]){
    if(c<f[0]&&f[0]<=d){
      if(e[0]<f[0]){
	if(f[0]>=f[0]){
	  cout<<"No War";
	}
	else cout<<"War";
      }
      else cout<<"War";
    }
    else cout<<"War";
  }
  else cout<<"War";
  cout<<"\n";
}


Measured memory_bytes: 2304
h, w, k = map(int, input().split())
color = []
for _ in range(h):
    color.append(str(input()))

tate = [0 for _ in range(w)]
yoko = [0 for _ in range(h)]
sumblack = 0
for i in range(h):
    for j in range(w):
        if color[i][j] == '#':
            tate[j] += 1
            yoko[i] += 1
            sumblack += 1

# print(tate)
# print(yoko)
ans = 0
for i in range(2**h):
    for j in range(2**w):
        tmp = sumblack 
        for a in range(h):
            if (i >> a) & 1:
                tmp -= yoko[a]
        for b in range(w):
            if (j >> b) & 1:
                tmp -= tate[b]
                for aa in range(h):
                    if (i>>aa)&1 and color[aa][b]=='#':
                        tmp += 1
        if tmp == k:
            # print(i,j)
            ans += 1

print(ans)


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

typedef long long LL;
typedef unsigned long long ULL;
//typedef pair<int,int> PII;
//typedef vector<int> VI;

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(A,value) memset(A,value,sizeof(A))
#define f first
#define s second

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int> > x(n + 1);
    for(int i = 0;i < m;i++){
        int l, r;
        cin >> l >> r;
        x[l].PB(r);
    }

    for(int i = 1;i <= n;i++){
        sort(x[i].begin(), x[i].end());
    }

    while(q--){
        int a, b, ans = 0;
        cin >> a >> b;
        for(int i = a;i <= b;i++){
            int l = 0, r = SZ(x[i]) - 1, mid, pos = -1;
            while(l <= r){
                mid = (l + r) >> 1;
                if (x[i][mid] <= b){
                    l = mid + 1;
                    pos = mid;
                }
                else{
                    r = mid - 1;
                }
            }
            ans += pos + 1;
        }
        cout << ans << endl;
    }

    return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  cout << a+b+c - max(a, max(b,c));
  return 0;
}


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

int main(void)
{
	long int i, j;
	long int n, k;
	long int p[200000];
	long int count = 0;
	long int sum;
	long int ans;
	
	scanf("%ld%ld", &n, &k);
	
	for(i = 0; i < n; i++) {
		scanf("%ld", &p[i]);
	}
	
	sum = ans = 0;
	
	for(i = 0; i < k; i++) {
		sum += (1 + p[i]);
	}
	
	ans = sum;
	
	for(; i < n; i++) {
		sum -= (1 + p[i - k]);
		sum += (1 + p[i]);
		if(ans < sum) {
			ans = sum;
		}
	}
	
	printf("%lf\n", (double)ans / 2.0);
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  2e5 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n  , x ,y, k , Q , ans ; string s,t;
ll res[102][102],ret[102][102],m[102][102],tmp[102][102];
void matrixMultiplyret(){


	for(int i(0); i < n; i++){
		for(int j(0); j < n; j++){
			tmp[i][j] = 0;
			for(int k(0); k < n; k++){
				tmp[i][j] += ((ret[i][k] + MOD) % MOD * (m[k][j] + MOD) % MOD) % MOD;
				tmp[i][j] = (tmp[i][j] + MOD) % MOD;
			}
		}
	}
	for(int i(0); i < n; i++)
		for(int j(0); j < n; j++)
            ret[i][j] = tmp[i][j];

}

void matrixMultiplymat(){


	for(int i(0); i < n; i++){
		for(int j(0); j < n; j++){
			tmp[i][j] = 0;
			for(int k(0); k < n; k++){
				tmp[i][j] += ((m[i][k] + MOD) % MOD * (m[k][j] + MOD) % MOD) % MOD;
				tmp[i][j] = (tmp[i][j] + MOD) % MOD;
			}
		}
	}

	for(int i(0); i < n; i++)
		for(int j(0); j < n; j++)
            m[i][j] = tmp[i][j];

}

void matrixPower(ll pow){ // input in matrix m[][] and result in matrix ret[][]


	for(int i(0); i < n; i++){
		for (int j = 0; j < n; j++)
		{
			if ( i == j) ret[i][i] = 1;
			else ret[i][j] = 0;
		}
	}

	while (pow){
		if (pow & 1ll){
        matrixMultiplyret();
		}
		pow >>=1;
		matrixMultiplymat();
	}


}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//    freopen("test.in","r",stdin);


    cin>>n>>k;

    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j < n ; ++j)
            cin>>m[i][j];

    matrixPower(k);

    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j < n ; ++j)
            ans=(ans%MOD + ret[i][j]%MOD)%MOD;

    cout<<ans<<'\n';

    return 0;
}


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

int DP[3010][3010];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s,t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	string ans;
	ans = "";
	for (int i = 1 ; i <= n ; i++)
		for (int j = 1 ; j <= m ; j++)
		{
			if (s[i - 1] == t[j -1])
			{
				// cout << i << " " << j << endl;
				DP[i][j] = DP[i -1][j - 1] + 1;
				// ans += s[i - 1];
			}
			else
			{
				DP[i][j] = max(DP[i - 1][j],DP[i][j - 1]);
			}
		}
	int i = n; int j = m;
	while (i >= 1 && j >= 1)
	{
		if (s[i - 1] == t[j - 1])
		{
			ans += s[i - 1];
			--i; --j;
		}
		else
		{
			if (DP[i - 1][j] > DP[i][j - 1])
				--i;
			else
				--j;
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
}

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

using namespace std;

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

    if ((N[1] == N[2]) && (N[0] == N[1] || N[3] == N[1]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

int main() {
    int a, b, c, n;
    cin >> a >> b >> c;
    
    for (int i = min(a, b); i <= max(a, b); i++) {
        n += (c % i == 0);
    }
    
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int a[105],b[105];
int main()
{
	int n;
	cin >>n;
	for(int i=0;i<n-1;i++){
		cin >> b[i];
	}
	a[0]=b[0];
	a[n-1]=b[n-2];
	for(int i=1;i<n-1;i++){
		a[i]=min(b[i-1],b[i]);
	}
	int sum=0;
	for(int i=0;i<n;i++){
		sum += a[i];
	}
	cout <<sum <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>

#define rep(i,a,b) for(long long i=a;i<b;i++)

using namespace std;


int main(void) {

	long long N = 0, K = 0, A = 0, B = 0, C = 0;
	long long a[300] = {0};
	long long b[300] = { 0 };
	long long c[300] = { 0 };
	long long d[300] = { 0 };
	//long long y[20] = {};
	string s;
	
	long long min = 0, min2 = 0;
	long long dif = 0;
	long long hoge = 0;
	long long sum = 0;
	long long up = 0;

	cin >> N >> A;

		cout << N-A+1 << endl;
	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<P> sc(m); rep (i, m) cin >> sc[i].first >> sc[i].second;
    vector<int> a(n); rep (i, n) a[i] = -1;
    rep (i, m) {
        if (a[sc[i].first - 1] == -1) a[sc[i].first - 1] = sc[i].second;
        else if (a[sc[i].first - 1] != sc[i].second) {
            cout << -1 << "\n";
            return 0;
        }
    }
    if (n == 1 && a[0] <= 0) cout << 0 << "\n";
    else {
        if (a[0] == 0) {
            cout << -1 << "\n";
            return 0;
        }
        rep (i, n) {
            if (a[i] == -1) {
                if (i == 0) cout << 1;
                else cout << 0;
            } else {
                cout << a[i];
            }
        }
            cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <cstdio>
# include <cstring>
using namespace std;
struct node
{
    int x, y;
}q[80000];
int n, m, dis[206][206];
char s[206][206];
int sol, girl;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
void bfs(int ex, int ey)
{
    int l=0, r=0;
    q[r++] = node{ex, ey};
    dis[ex][ey] = 0;
    while(l < r)
    {
        node u = q[l++];
        for(int i=0; i<4; ++i)
        {
            int mx = u.x + dx[i];
            int my = u.y + dy[i];
            if(mx < 0 || mx >= n || my < 0 || my >= m || s[mx][my] == '#' || dis[mx][my] != -1) continue;
            dis[mx][my] = dis[u.x][u.y] + 1;
            q[r++] = node{mx, my};
            if(s[mx][my]=='$')
                sol = min(sol, dis[mx][my]);
            else if(s[mx][my] == '@')
                girl = dis[mx][my];
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        sol = girl = 1e9;
        memset(dis, -1, sizeof(dis));
        for(int i=0; i<n; ++i)
            scanf("%s",s[i]);
        for(int i=0; i<n; ++i)
        {
            for(int j=0; j<m; ++j)
            {
                if(s[i][j] == '%')
                {
                    bfs(i,j);
                    break;
                }
            }
        }
        //printf("%d %d\n",sol,girl);
        if(sol > girl || (sol == 1e9&&girl!=1e9))
           puts("Yes");
        else
            puts("No");
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        String str;
        if ((a + b) >= c) {
            str = "Yes";
        } else {
            str = "No";
        }
        System.out.println(str);
        sc.close();
    }

}


Measured memory_bytes: 22356
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
namespace SOLVE {
    void main(){
    }
}

ll cnt[1000100];

int main() {
#ifndef ONLINE_JUDGE
#endif
    
    ll n,k;in(n,k);
    REP(i,1,n+1){
        cnt[i%k]++;
    }
    
    ll ans = 0;
    
    ans += (cnt[0])*(cnt[0])*(cnt[0]);
    if(k%2==0){
        ans += (cnt[k/2])*(cnt[k/2])*(cnt[k/2]);
    }
    cout<<ans;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


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

vector<string> f(char c, int k) {
    if (k == 0) return {""};
    vector<string> ret;
    vector<string> ss = f(c, k-1);
    for (char i = 'a'; i < c; i++)
        for (string &s : ss) ret.push_back(string(1, i) + s);
    for (string &s : f(c+1, k-1)) ret.push_back(string(1, c) + s);
    return ret;
}

int main() {
    int k; cin >> k;
    vector<string> a = f('a', k);
    for (string &s : a) cout << s << endl;
}


Measured memory_bytes: 14712
import sys

n, p = map(int, input().split(" "))

a = list(map(int, input().split(" ")))

def combi(n, k):
    # if k == 0 or n == k:
        # return 1
    # c = min(k, n - k)
    a = 1
    b = 1
    for i in range(k):
        a *= i+1
        b *= n-i
    return b // a

oddcnt = 0

for i in a:
    if i % 2 == 1:
        oddcnt += 1

evencnt = n - oddcnt

if oddcnt == 0 and p == 1:
    print(0)
    sys.exit()

evencomb = 0
for i in range(0, evencnt+1):
    evencomb += combi(evencnt, i)

oddcomb = 0
for i in range(p, oddcnt+1, 2):
    oddcomb += combi(oddcnt, i)

if evencomb != 0:
    if oddcomb != 0:
        print(evencomb * oddcomb)
    else:
        print(evencomb)
else:
    print(oddcomb)


Measured memory_bytes: 3064
class UnionFind:

    def __init__(self, n):
        self.t = [-1] * (n + 1)

    def flatten(self):
        for i, _ in enumerate(self.t):
            self.find_root(i)

    def union(self, a, b):
        ra = self.find_root(a)
        rb = self.find_root(b)
        if ra != rb:
            self.t[max(ra, rb)] = min(ra, rb)

    def find_root(self, x):
        t = []
        while self.t[x] > 0:
            t.append(x)
            x = self.t[x]
        for _t in t:
            self.t[_t] = x
        return x


def solve(string):
    n, m, k, *abcd = map(int, string.split())
    ab, cd = abcd[:2 * m], abcd[2 * m:]
    fr, br = [[] for _ in range(n + 1)], [[] for _ in range(n + 1)]
    uf = UnionFind(n)
    for a, b in zip(*[iter(ab)] * 2):
        fr[a].append(b)
        fr[b].append(a)
        uf.union(a, b)
    uf.flatten()
    for i, v in enumerate(uf.t):
        if v < 0:
            uf.t[i] = i
    mp = {k: i for i, k in enumerate(set(uf.t[1:]))}
    g = [[] for _ in enumerate(mp.keys())]
    for i in range(n + 1):
        if uf.t[i] > 0:
            g[mp[uf.t[i]]].append(i)
    for c, d in zip(*[iter(cd)] * 2):
        br[c].append(d)
        br[d].append(c)

    *fr, = map(len, fr)
    *g, = map(set, g)
    *gn, = map(len, g)
    return " ".join([
        str(gn[mp[uf.t[i]]] - 1 - fr[i] - sum(j in g[mp[uf.t[i]]]
                                              for j in br[i]))
        for i in range(1, n + 1)
    ])


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

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

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

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

int main() {
  int N;
  cin >> N;
  ll a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  ll sum = accumulate(a, a + N, 0LL);
  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    sum -= a[i];
    ans += (a[i] % MOD) * (sum % MOD) % MOD;
    ans %= MOD;
  }

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


Measured memory_bytes: 5200
package main

import (
        "fmt"
        "math"
)

func solution(n, k int) int {
        return k * int(math.Pow(float64(k-1), float64(n-1)))
}

func main() {
        var n, k int
        fmt.Scan(&n, &k)
        fmt.Println(solution(n, k))
}

Measured memory_bytes: 1836
s = input()
s_= s.replace("A", "0").replace("BC", "1").replace("B", "2").replace("C", "2")
s_012 = list(map(int, list(s_)))
count = 0
i = 0
ans = 0
while i < len(s_012):
    if s_012[i] == 0:
        count += 1
    elif s_012[i] == 1:
        ans += count
    else:
        count = 0
    i += 1

print(ans)

Measured memory_bytes: 68208
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al=lin()
	cc=collections.defaultdict(lambda :0)
	for v in al:
		cc[v]+=1
	num2=0
	num1=0
	for k in cc:
		if cc[k]> 1 and cc[k]%2==1:
			cc[k]=1
			num1+=1
		elif cc[k]>1:
			cc[k]=2
			num2+=1
		else:
			num1+=1
	ret=num1
	if num2 % 2 == 1:
		ret += num2 - 1
	else:
		ret += num2
	return ret
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62060
#include <bits/stdc++.h>
#ifdef LOCAL
#include "debuger.hpp"
#else
#define DUMP(...) 1145141919810
#define CHECK(...) (__VA_ARGS__)
#endif

const int kN = 1000000 + 5;
int n;
std::vector<std::string> s;
int tot = 2;
int go[kN][26];
int cnt[kN][26];
const int root = 1;

int main() {
  scanf("%d", &n);
  static char buffer[1000000 + 5];
  for (int i = 0; i < n; ++i) {
    scanf("%s", buffer);
    s.emplace_back(buffer);
    int w = root;
    for (int j = (int)s[i].size() - 1; j > 0; --j) {
      int c = s[i][j] - 'a';
      if (go[w][c] == 0) go[w][c] = tot++;
      w = go[w][c];
    }
    cnt[w][s[i][0] - 'a']++;
  }
  long long result = 0;
  for (int i = 0; i < n; ++i) {
    int q[26] = {};
    for (int j = 0; j < s[i].size(); ++j)
      q[s[i][j] - 'a']++;
    int w = root;
    for (int j = (int)s[i].size() - 1; j >= 0; --j) {
      int c = s[i][j] - 'a';
      for (int k = 0; k < 26; ++k)
        if (q[k] > 0)
          result += cnt[w][k];
      --q[c];
      w = go[w][c];
    }
  }
  printf("%lld\n", result - n);
}


Measured memory_bytes: 154176
#include <deque>
#include <cstdio>

using namespace std;

int main(){
    deque<long> dl;
    int T;
    scanf("%d",&T);
    while(T--){
        int q;
        scanf("%d",&q);
        if(0 == q){
            int d,x;
            scanf("%d %d",&d,&x);
            if(d==0) dl.push_front(x);
            else dl.push_back(x);
        }
        else if(1 == q){
            int ind;
            scanf("%d",&ind);
            printf("%ld\n",dl[ind]);
        }
        else if(2 == q){
            int d;
            scanf("%d",&d);
            if(d == 0) dl.pop_front();
            else dl.pop_back();
        }
    }
}



Measured memory_bytes: 5816
#1st line
input_str = input().strip()

#2nd line
command_max_times = int(input().strip())
command_cnt = 0

while command_cnt < command_max_times:
    command_cnt = command_cnt + 1
    input_line = input().strip().split(" ")
    
    input_command = input_line[0]
    input_sta = int(input_line[1])
    input_end = int(input_line[2])
    
    if input_command == "print":
        print(input_str[input_sta:input_end+1])
    elif input_command == "replace":
        str_replace = input_line[3]
        input_str = input_str[:input_sta] + str_replace + input_str[input_end+1:]
    elif input_command == "reverse":
        str_temp = input_str[input_sta:input_end+1]
        input_str = input_str[:input_sta] + str_temp[::-1] + input_str[input_end+1:]

Measured memory_bytes: 7688
//Made By Yogendra Singh
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long

struct item
{
	int wt;
	int val;
};

ll solve(std::vector<item> ar,int n,int W)
{
	ll dp[n+1][W+1];
	for(int w = 0;w<=W;w++)
	{
		dp[1][w] = 0;
	}
	dp[1][ar[1].wt] = ar[1].val;

	for(int i=2;i<=n;i++)
	{
		for(int w = 0; w<=W; w++)
		{
			dp[i][w] = dp[i-1][w];
			if(ar[i].wt>w)
			continue;
			dp[i][w] = max(dp[i][w],ar[i].val + dp[i-1][w-ar[i].wt]);
		}
	}

	return *max_element(dp[n],dp[n] + W + 1);

}
int main()
{
	int n,w;
	cin>>n>>w;

	std::vector<item> ar(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>ar[i].wt;
		cin>>ar[i].val;
	}

	cout<<solve(ar,n,w)<<endl;

}

Measured memory_bytes: 81596
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

int32_t main(){
    IOS;
    int n;
    cin>>n;
    int arr[n+1];
    for (int i = 1; i <= n; ++i)
    {
    	cin>>arr[i];
    }
    int mn[n+1];
    mn[0] = 1e16;
    for(int i=1;i<=n;i++){
    	mn[i] = min(arr[i],mn[i-1]);
    }
    int cnt = 0;
    for(int i=1;i<=n;i++){
    	if(arr[i]<=mn[i])
    		cnt++;
    }

    cout<<cnt<<endl;
    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    for (char c : S)
    {
        int times = 0;
        for (char d : S)
        {
            if (c == d)
                times++;
        }
        if (times != 2)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256