akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn bfs(v: usize,
       g: &[Vec<usize>], dist: &mut [usize], d: usize) {
    let mut que = VecDeque::new();
    que.push_back((v, 0));
    while let Some((v, d)) = que.pop_front() {
        if dist[v] <= d {
            continue;
        }
        dist[v] = d;
        for &w in &g[v] {
            que.push_back((w, d + 1));
        }
    }
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize, x: usize1, y: usize1,
    }
    let mut g = vec![vec![]; n];
    for i in 0..n - 1 {
        g[i].push(i + 1);
        g[i + 1].push(i);
    }
    g[x].push(y);
    g[y].push(x);
    let mut dist = vec![vec![1 << 20; n]; n];
    for i in 0..n {
        bfs(i, &g, &mut dist[i], 0);
    }
    let mut ans = vec![0; n];
    for i in 0..n {
        for j in 0..i {
            ans[dist[i][j]] += 1;
        }
    }
    for i in 1..n {
        puts!("{}\n", ans[i]);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 49532
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>

#define MOD 998244353

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))

typedef long long int64;

int main(void){
    int64 H,W;
    scanf("%lld %lld",&H,&W);
    char A[H][W];

    for(int64 i=0;i<H;i++){
        scanf("%s",&A[i]);
    }
    int64 dp[H][W];
    for(int64 i=0;i<H;i++){
        for(int64 j=0;j<W;j++){
            dp[i][j]=65535;
        }
    }

    int64 tmp=65535;

    for(int64 i=0;i<H;i++){
        tmp=65535;
        for(int64 j=0;j<W;j++){
            if(A[i][j]=='#'){
                dp[i][j]=0;
                tmp=1;
            }else{
                dp[i][j]=MIN(dp[i][j],tmp);
                tmp++;
            }
        }
    }
    for(int64 j=0;j<W;j++){
        for(int64 i=0;i<H;i++){
            if(i==0) continue;
            dp[i][j]=MIN(dp[i][j],dp[i-1][j]+1);
        }
    }
    for(int64 i=H-1;i>=0;i--){
        for(int64 j=W-1;j>=0;j--){
            if(j==W-1) continue;
            dp[i][j]=MIN(dp[i][j],dp[i][j+1]+1);
        }
    }
    
    for(int64 j=W-1;j>=0;j--){
        for(int64 i=H-1;i>=0;i--){
            if(i==H-1) continue;
            dp[i][j]=MIN(dp[i][j],dp[i+1][j]+1);
        }
    }

    int64 ans=0;

    for(int64 i=0;i<H;i++){
        for(int64 j=0;j<W;j++){
            ans=MAX(ans,dp[i][j]);
        }
    }

    // for(int i=0;i<H;i++){
    //     for(int j=0;j<W;j++){
    //         printf("\t%d",dp[i][j]);
    //     }
    //     printf("\n");
        
    // }
    

    printf("%lld",ans);
    
    
    return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> cnt(256);
    for (int i = 0; i < S.size(); i++) {
        cnt[S[i]]++;
    }

    ll ans = 1;
    const int mod = 1e9 + 7;
    for (int i = 0; i < 256; i++) {
        if (!cnt[i]) continue;
        ans *= cnt[i] + 1;
        ans %= mod;
    }
    cout << (ans + mod - 1) % mod << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 1100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back

int main(){
	int n, a, b; scanf("%d%d%d", &n, &a, &b);
	printf("%d %d\n", min(a, b), max(0, a+b-n));
}


Measured memory_bytes: 892
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class MainClass
	{

		public static void Main (string[] args)
		{
			var line = Console.ReadLine ().Split (' ');
			var n = int.Parse (line[0]);
			//var m = int.Parse (line[1]);

			var res1 = Enumerable.Range(0,n)
				.Select(_ => Console.ReadLine ().Split (' ').Skip(1).ToList())
				.ToList();
			
			var res = res1.Aggregate(res1[0],(a, b)=>a.Intersect(b).ToList())
				.Count()
				;

			Console.WriteLine ("{0}", res);
		}


	}
}

Measured memory_bytes: 13408
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <vector>
#include <string>

using ll = long long;

using namespace std;

void solve() {
    string str;
    cin >> str;
    if (str[2] == str[3] && str[4] == str[5]) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int a[N];
int cmp(int a,int b){
    return a>b;
}
int main(){

    int n,m;
    cin>>n>>m;
    double sum=0;
    for(int i=0;i<n;i++) {cin>>a[i];sum+=a[i];}
    sort(a,a+n,cmp);
    sum=sum/(4*m);
    for(int i=0;i<n;i++){
        if(a[i]<sum){
            break;
        }
        m--;
    }
    if(m>0){
        cout<<"No";
    }
    else cout<<"Yes";
}


Measured memory_bytes: 256
# coding:utf-8
n = int(input())
w = [input() for _ in range(n)]
word_list = set(w)

if len(word_list) != len(w):
    print("No")
    exit()
else:
    for i in range(1, n):
        tail = w[i - 1][-1]
        if tail != w[i][0]:
            print("No")
            exit()
print("Yes")


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

int main(){
  int h,w;
  cin>>h>>w;
  string map[h];
  int num=0;
  for(int i=0;i<h;i++){
    cin>>map[i];
    for(int j=0;j<w;j++)
      if(map[i][j]=='#') num++;
  }
  queue<int> qx,qy,cnt;
  qx.push(0); qy.push(0); cnt.push(1);
  while(!qx.empty()){
    int x=qx.front(); int y=qy.front(); int c=cnt.front();
    qx.pop(); qy.pop(); cnt.pop();
    if(x==w-1&&y==h-1&&c==num){
      cout<<"Possible"<<endl; return 0;
    }
    if(x<w-1&&map[y][x+1]=='#'){
      qx.push(x+1); qy.push(y); cnt.push(c+1);
    } else if(y<h-1&&map[y+1][x]=='#'){
      qx.push(x); qy.push(y+1); cnt.push(c+1);
    }
  }
  cout<<"Impossible"<<endl;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**7)
def dfs(x):
    if x == 0:
        return 0
    if x == 1:
        return d
    if x in dic:
        return dic[x]
    l2 = x//2
    r2 = (x+1)//2
    l3 = x//3
    r3 = (x+2)//3
    l5 = x//5
    r5 = (x+4)//5
    count = min(x*d,10**18)
    count = min(count,abs(l2*2-x)*d+a+dfs(l2))
    count = min(count,abs(r2*2-x)*d+a+dfs(r2))
    count = min(count,abs(l3*3-x)*d+b+dfs(l3))
    count = min(count,abs(r3*3-x)*d+b+dfs(r3))
    count = min(count,abs(l5*5-x)*d+c+dfs(l5))
    count = min(count,abs(r5*5-x)*d+c+dfs(r5))
    dic[x] = count
    return count

t = int(input())
for _ in range(t):
    n,a,b,c,d = map(int,input().split())
    dic = {}
    print(dfs(n))

Measured memory_bytes: 11060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int x;
  cin >> x;
  if (x == 7){
    cout << "YES\n";
    return 0; 
  }
  if (x == 5){
    cout << "YES\n";
    return 0; 
  }
    if (x == 3){
    cout << "YES\n";
    return 0; 
  }
  cout << "NO\n";
  return 0; 
}

Measured memory_bytes: 256
let n = read_int ()

let rec read_ints accu = function
  | 0 -> List.rev accu
  | k -> read_ints ((Scanf.scanf " %d" (fun x -> x)) :: accu) (k-1)

let a = Array.of_list (read_ints [] (2*n-1))

let check x =
  let rec aux = function
    | 0 -> a.(0) >= x
    | k -> if (a.(k-1) >= x) = (a.(k) >= x) then a.(k) >= x
           else if (a.(2*n-1-k) >= x) = (a.(2*n-2-k) >= x) then a.(2*n-2-k) >= x
           else aux (k-1) in
  aux (n-1)

let rec bsearch l r = if r = l+1 then l else let m = (l+r)/2 in if check m then bsearch m r else bsearch l m

let () = print_int (bsearch 1 (2*n))


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

#define rep(i, n)	for(int i = 0; i < (int)(n); i++)


int S(int N) {
	int result = 0;
	while (N > 0) {
		result += N % 10;
		N /= 10;
	}

	return result;
}

int main() {
	int N;

	cin >> N;

	cout << (N % S(N) == 0 ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
x=sum(a)
i=ans1=0
while True:
    if ans1<x/2 and i<n:
        ans1+=a[i]
        i+=1
    else:
        break

i-=1
ans2=x-ans1
ans1-=a[i]
print(a[i]-abs(ans1-ans2))


Measured memory_bytes: 26096
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	ll n, m;
	cin >> n >> m;
	ll ans = 0;
	ans += min(n, m / 2);
	m -= n * 2;
	ans += max(m / 4, 0LL);
	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 3600
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[list(map(int,input().split()))for _ in range(m)]
ans=[1]*n
for a,b in ab:
    if h[a-1] > h[b-1]:
        ans[b-1]-=1
    elif h[a-1] < h[b-1]:
        ans[a-1]-=1
    else:
        ans[a-1]-=1
        ans[b-1]-=1
print(ans.count(1))

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

int main() {
  int a,b;
  cin >> a>>b;
  vector<int> city(a,0);
  for(int i=0;i<b;i++){
    int c,d;
    cin>>c>>d;
    for(int j=0;j<a;j++){
      if(c==j+1){
        city.at(c-1)+=1;
      }
      if(d-1==j){
        city.at(d-1)+=1;
      }
    }      
  }
  for(int i=0;i<a;i++){
    cout<<city.at(i)<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  double a, b;
  cin >> a >> b;
  cout << setprecision(10) << a / b << "\n";
}

Measured memory_bytes: 3744
list = []
for i in range(5):
    a = int(input())
    list.append(a)
k = int(input())

direct = True
for i in range(5):
    for j in range(5):
        if abs(list[i]-list[j]) > k:
            direct = False
if direct:
    print('Yay!')
else:
    print(':(')


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

using namespace std;

template<typename Weight>
struct Dinic {
    struct Edge {
        int src, dst, rev;
        Weight weight;
        Edge(int f, int t, Weight cap, int rev = 0) :
            src(f), dst(t), rev(rev), weight(cap) {}
    };

    int n;
    vector<vector<Edge>> adj;
    static const Weight INF = numeric_limits<Weight>::max() / 2;

    Dinic(int _n) : n(_n), adj(n) {}

    void add_edge(const int src, const int dst, const Weight cap = INF) {
        adj[src].emplace_back(Edge(src, dst, cap, adj[dst].size()));
        adj[dst].emplace_back(Edge(dst, src, 0, adj[src].size() - 1));
    }

    Weight MaximumFlow(const int s, const int t) {
        Weight flow = 0;
        vector<int> level(n);
        vector<size_t> iter(n);
        while(true) {
            fill(level.begin(), level.end(), -1);
            fill(iter.begin(), iter.end(), 0);
            Bfs(s, level);
            if(level[t] == -1) break;
            for (Weight f = 0; (f = Dfs(s, t, INF, level, iter)) > 0; )
                flow += f;
        }
        return flow;
    }

    void Bfs(const int s, vector<int> &level){
        queue<int> que;
        for (level[s] = 0, que.push(s); !que.empty(); ) {
            const int v = que.front(); que.pop();
            for (const auto &e : adj[v])
                if(0 < e.weight && level[e.dst] == -1){
                    level[e.dst] = level[v] + 1;
                    que.push(e.dst);
                }
        }
    }

    Weight Dfs(int v, int t, Weight flow, vector<int> &level, vector<size_t> &iter) {
        if(v == t) return flow;
        for ( ; iter[v] < adj[v].size(); ++iter[v]) {
            Edge &e = adj[v][iter[v]];

            if(0 < e.weight && level[v] < level[e.dst]){
                Weight d = Dfs(e.dst, t, min(flow, e.weight), level, iter);
                if(0 < d){
                    e.weight -= d;
                    adj[e.dst][e.rev].weight += d;
                    return d;
                }
            }
        }
        return 0;
    }
};

int Solve() {
    int h, w;
    cin >> h >> w;

    vector<string> hasu(h);
    for (auto &&x : hasu) cin >> x;

    const int s = h + w, t = h + w + 1;
    Dinic<int> g(h + w + 2);

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (hasu[i][j] == 'o') {
                g.add_edge(i, j + h, 1);
                g.add_edge(j + h, i, 1);
            }
            else if (hasu[i][j] == 'S') {
                g.add_edge(s, i);
                g.add_edge(s, j + h);
            }
            else if (hasu[i][j] == 'T') {
                g.add_edge(i, t);
                g.add_edge(j + h, t);
            }
        }
    }

    int res = g.MaximumFlow(s, t);
    return (res < g.INF ? res : -1);
}

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

    cout << Solve() << endl;

    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin>>str;
  int cnt=0;
  if(str[0]=='A')cnt++;
  for(int i=0;i<str.size()-1;i++){
    if(str[i]>=str[i+1])
      cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3212
def resolve():
    import sys
    input=sys.stdin.readline
    N = int(input().rstrip())
    S = input().rstrip()

    def z_algo(s):
        """
        param s:str
        return list of int with length len(s)
        """
        # initialization
        n=len(s)
        z=[0]*n
        z[0]=n
        # construct
        L,R=0,0
        for i in range(1,n):
            if i>R: # 過去の結果が全く使えない
                L=R=i
                while(R<n and s[R-L]==s[R]): R+=1
                z[i]=R-L
                R-=1 # 0-indexedでiと比較するため
            elif z[i-L]<R-i+1:
                z[i]=z[i-L]
            else:
                L=i
                R+=1 # Rまでは確定しているので、R+1から確認
                while(R<n and s[R-L]==s[R]): R+=1
                z[i]=R-L
                R-=1
        return z

    ans = 0
    for i in range(N-1):
        z = z_algo(S[i:])
        for j, _z in enumerate(z):
            ans=max(ans,min(j,z[j]))
    print(ans)

resolve()

Measured memory_bytes: 48988
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c, d;
    //入力を受け取る.
    //KKSK
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
  	//直接の話せる場合.
  	if( abs(c-a) <= d){
      printf("Yes");
      return 0;
    }
  	//間接的に話せる場合.
  	if( abs(b-a) <= d){
      if( abs(c-b) <= d){
        printf("Yes");
        return 0;
      }
    }
  	//後はだめ.
  	printf("No");
  	return 0; 
}


Measured memory_bytes: 256
// from https://atcoder.jp/contests/dp/submissions/11261467
#include<bits/stdc++.h>

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rrep(i,n) for(ll i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)
#define rrep1(i,n) for(ll i = (n); i > 0; i--)

#define ll long long
#define pi pair<ll, ll>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct Seg{
  vector<ll> sum;
  vector<ll> mx;
  Seg(){
    sum.resize(1<<19, 0);
    mx.resize(1<<19, 0);
  }

  void add_val(ll l, ll r, ll val, ll bottom=0, ll top=1<<18, ll pos=1){
    if(l <= bottom && top <=r){
      sum[pos] += val;
      return ;
    }
    if(r<=bottom || l>=top)return ;

    ll mid = (bottom + top)/2;
    add_val(l, r, val, bottom, mid, pos*2);
    add_val(l, r, val, mid, top, pos*2+1);
    mx[pos] = max<ll>(mx[pos*2] + sum[pos*2],  mx[pos*2+1] + sum[pos*2+1]);
  }

  void set_val(ll l, ll r, ll val, ll bottom=0, ll top=1<<18, ll pos=1){
    if(l <= bottom && top <=r){
      sum[pos] += val;
      return ;
    }
    if(r<=bottom || l>=top)return ;

    ll mid = (bottom + top)/2;
    add_val(l, r, val, bottom, mid, pos*2);
    add_val(l, r, val, mid, top, pos*2+1);
    mx[pos] = max<ll>(mx[pos*2] + sum[pos*2],  mx[pos*2+1] + sum[pos*2+1]);
  }

  ll max_val(ll l, ll r, ll bottom=0, ll top=1<<18, ll pos=1){
    if(l <= bottom && top <= r) return sum[pos] + mx[pos];
    if(r <= bottom || l>=top)return -INF;

    ll mid = (bottom+top)/2;
    return max<ll>(
      max_val(l, r, bottom, mid, pos*2),
      max_val(l, r, mid, top, pos*2+1)
    )+sum[pos];
  }
};

int main(){
  ll n,m;cin>>n>>m;
  vector<pi> its[n+1];
  rep(i, m){
    ll l,r,a;cin>>l>>r>>a;
    its[r].push_back({l, a});
  }

  Seg seg;
  rep1(i, n){
    ll mx = seg.max_val(0, i);
    seg.add_val(i, i+1, mx);
    for(auto p:its[i]){
      ll l = p.first;
      ll a = p.second;
      seg.add_val(l, i+1, a);
    }
  }

  cout<<seg.max_val(0, n+1)<<endl;

  return 0;
}


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

int main(void){
	int n;
	cin >> n;
	if (n % 3 == 0) {
		cout << n / 3;
	}
	else {
		cout << n / 3;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, m;
    cin >> n >> m;
    if (n > m) swap(n, m);
    if (n == 1)
    {
        if (m == 1) cout << "1";
        else cout << m - 2;
    }
    else cout << (m - 2) * (n - 2); 
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n;
  ll a[109];
  ll ans=0;
  cin>>n;
  for(int i=0;i<5;i++){
    cin>>a[i];
    ll temp=n/a[i];
    if(n%a[i]!=0)temp++;
    ans=max(ans,temp+4);
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 384
n=int(input())
s=[]
for _ in range(n):
  s.append(input())
import collections
d=collections.Counter(s)
largest=max(list(d.values()))
ans=[]
for key in d.keys():
  if d[key]==largest:
    ans.append(key)
ans.sort(reverse=True)
while len(ans)>0:
  print(ans.pop(-1))
  
  


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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << "," << a.second << ")";return os;}

const int MAX_N = 400010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void init(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    ll n,k;
    cin >> n >> k;
    init(n*2);
    if (k > n-1) cout << combi(n+n-1,n) << endl;
    else {
        ll ans = 0;
        for (int i = 0;i <= k;++i) {
            (ans += combi(n,i)*combi(n-1,i)%mod) %= mod;
        }
        cout << ans << endl;
    }
}

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int K, A, B;
    cin >> K >> A >> B;
    for(int i = A; i <= B; ++i) {
        if(i % K == 0) {
            printf("OK\n");
            return 0;
        }
    }
    printf("NG\n");
    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
int a[21], L;

int calc_next(int a, int L){
  int i, j;
  int h[10] ={}; // ヒストグラム
  int maximum = 0, minimum = 0; // 最大,最小
  for(i = 0; i < L; i++){
    h[a % 10]++;
    a = a / 10;
  }
  // 大きい順に使う
  for(i = 9; i >= 0; i--){
    for(j = 0; j < h[i]; j++){
      maximum = maximum * 10 + i;
    }
  }
  // 小さい順に使う
  for(i = 0; i <= 9; i++){
    for(j = 0; j < h[i]; j++){
      minimum = minimum * 10 + i;
    }
  }

  return maximum - minimum;
}

int check(int i){
  int j;
  for(j = 0; j < i; j++){
    if(a[i] == a[j]){
      printf("%d %d %d\n",j, a[i], i - j);
      return 1;
    }
  }
  return 0;
}
int main(){
  while(1){
    int i;
    scanf("%d %d", &a[0], &L);
    if(a[0] == 0 && L == 0)break; // データーセットの終了
    i = 0;
    while(1){
      a[i + 1] = calc_next(a[i], L);
      i++;
      if(check(i)) break;
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
#define int long long
using namespace std;
const int maxn=200005,mod=1e9+7;
int n,flag=1,posl=350000,posr=350000-1;
char a[maxn*4];
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
inline void write(int a)
{
	if(a<0)
	{
		putchar('-');
		write(-a);
	}
	else
	{
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
	}
}
signed main()
{
	string ch;
	cin>>ch;
	int len=ch.length();
	for(int i=0;i<len;++i)
	a[++posr]=ch[i];
	n=read();
	for(int i=1; i<=n; ++i)
	{
		int t;
		cin>>t;
		if(t==1)
			flag*=-1;
		else
		{
			int f;
			char b;
			cin>>f>>b;
			if(f==1)
			{
				if(flag==1)
					a[--posl]=b;
				else
					a[++posr]=b;
			}
			else
			{
				if(flag==-1)
				a[--posl]=b;
				else
					a[++posr]=b;
			}
		}
//		cout<<a<<endl;
	}
	if(flag==1)
		{
		for(int i=posl;i<=posr;++i)
		cout<<a[i];
		}
	else
	{
		for(int i=posr; i>=posl; --i)
			cout<<a[i];
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
typedef  unsigned long long ull;
const double EPS= (1e-9);
using namespace std;
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=0;
queue<ll> q;
vector<ll> ans;
int main(){

    int n;
    cin>>n;
    int cnt=0;
    for(int i=1;i<=9;i++){
        q.push(i);
    }
    bool ok=1;
    while(sz(q)>0&&ok){
        int siz=sz(q);
        while(siz--){
            ll no=q.front();
            q.pop();
            if(sz(ans)<n) ans.pb(no);
            else{
                ok=0;
                break;
            }
            int dd=no%10;
            for(int i=max(0,dd-1);i<=min(dd+1,9);i++){
                q.push(no*10+i);

            }
        }
    }
   // for(int i=0;i<100;i++) cout<<ans[i]<<endl;
    sort(all(ans));
    cout<<ans.back()<<endl;
}
































































































































































































































































































































































































































































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

#define int L
#define N 100005
vector<pair<int, L> > path[N];
int par[N], dep[N], siz[N], hev[N];
L cst[N];
void dfs(int a){
    siz[a]=1;
    for(int i=0; i<path[a].size(); i++){
        int d=path[a][i].first;
        if(d==par[a]) continue;
        par[d]=a;
        dep[d]=dep[a]+1;
        cst[d]=path[a][i].second;
        dfs(d);
        siz[a]+=siz[d];
        if(!hev[a] || siz[hev[a]]<siz[d])
            hev[a]=d;
    }
}
  
L k;
L add[N];
L edgecost(int a){
    L ret=add[a]+add[par[a]]+cst[a];
    return ret%k ? ret : 0;
}
  
int pos[N];
int hl_par[N];
  
L bit[N];
L sum(int i){
    L ret=0;
    while(i){
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}
void S(int i, L x){
    x-=sum(i+1)-sum(i);
    i++;
    while(i<N){
        bit[i]+=x;
        i+=i&-i;
    }
}
  
L cost(int a, int b){
    int p=hl_par[a], q=hl_par[b];
    if(p==q) return abs(sum(pos[a])-sum(pos[b]));
    if(dep[p]<dep[q]){
        swap(p, q);
        swap(a, b);
    }
    return sum(pos[a]) - sum(pos[p])
        + edgecost(p) + cost(par[p], b);
}

main(){
    int n;
    cin >> n >> k;
    for(int i=0; i<n-1; i++){
        int a, b;
        L c;
        cin >> a >> b >> c;
        path[a].push_back(make_pair(b, c));
        path[b].push_back(make_pair(a, c));
    }
    for(int i=0; i<n; i++) hev[i]=0;
    par[0]=dep[0]=cst[0]=0;
    dfs(0);
  
    for(int i=0; i<n; i++) add[i]=0;
  
    int cnt=0;
    for(int i=0; i<n; i++){
        if(i && hev[par[i]]==i) continue;
        int j=i;
        do{
            pos[j]=cnt++;
            hl_par[j]=i;
        }while(j=hev[j]);
    }
 
    for(int i=0; i<N; i++) bit[i]=0;
    for(int i=0; i<n; i++)
        S(pos[i], edgecost(hev[i]));
      
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        string s;
        L a, b;
        cin >> s >> a >> b;
        if(s[0]=='a'){
            add[a]+=b;
            S(pos[a], edgecost(hev[a]));
            if(a) S(pos[a]-1, edgecost(a));
        }else{
            cout << cost(a, b) << endl;
        }
    }
}

Measured memory_bytes: 21936
#include <stdio.h>
#include <limits.h>
#define MAX 2000000000
typedef struct{
  int x;
  char c;
  }card;
  card M[100000];
int Partition(int, int);
void Quicksort(int, int);
void merge(int, int, int,card[]);
void mergeSort(int, int, card[]);
int main(){
  int i, p, n;
  char c;
  card N[100000];
  scanf("%d%c", &n, &c);
  for(i = 0; i < n; i++){
    scanf("%c%d%c", &N[i].c, &N[i].x, &c);
    M[i] = N[i];
  }
  p = 0;
  mergeSort(0, n, N);
  Quicksort(0, n-1);
  for(i = 0; i < n; i++){
    if(N[i].c != M[i].c){
      printf("Not stable\n");
      break;
    }
    if(i == (n - 1))
    printf("Stable\n");
  }
  for(i = 0; i < n; i++){
    printf("%c %d\n", M[i].c, M[i].x);
  }
  return 0;
  }
int Partition(int e, int s){
  card tmp;
  int i, j, x;
  x = M[s].x;
  i = e - 1;
  for(j = e; j < s; j++){
    if (M[j].x <= x){
      i++;
      tmp = M[i];
      M[i] = M[j];
      M[j] = tmp;
    }
  }
  tmp = M[i + 1];
  M[i + 1] = M[s];
  M[s] = tmp;
  return (i + 1);
}
void Quicksort(int e, int s){
  int w;
  if(e < s){
    w = Partition(e, s);
    Quicksort(e, w-1);
    Quicksort(w+1, s);
  }
}
void merge(int left, int mid, int right, card K[]){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  card L[100001], R[100001];
  for(i = 0; i < n1; i++){
    L[i] = K[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = K[mid+i];
  }
  L[n1].x = MAX;
  R[n2].x = MAX;
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    if(L[i].x <= R[j].x)
    K[k]=L[i++];
    else
    K[k]=R[j++];
  }
}
void mergeSort(int left, int right, card K[]){
  if((left + 1) < right){
    int mid = (left + right) / 2;
    mergeSort(left, mid, K);
    mergeSort(mid, right, K);
    merge(left, mid, right, K);
  }
}




Measured memory_bytes: 4176
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define FINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) ((a) <= (i) && (i) <= (b))
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(begin(a), end(a)); }
template <typename T> inline void REV(T& a) { reverse(begin(a), end(a)); }
template <typename T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <typename S, typename T> inline T LB(S& v, T a) { return *lower_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int LBP(S& v, T a) { return lower_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> inline T UB(S& v, T a) { return *upper_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int UBP(S& v, T a) { return upper_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> ostream& operator << (ostream& os, const pair<S, T>& p) { os << p.first << " " << p.second; return os; }
template <typename S, typename T> istream& operator >> (istream& is, pair<S, T>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator >> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;



void _main() {
    cout << "square1001" << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 3068
using System;

namespace Structured 
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int n = int.Parse (Console.ReadLine ());

			for (int i = 1; i <= n; i++) {
				int x = i;
				if (x % 3 == 0) {
					Console.Write (" {0}", i);
					continue;
				}
				for (; x != 0; x /= 10) {
					if (x % 10 == 3) {
						Console.Write (" {0}", i);
						break;
					}
				}
			}
			Console.Write ("\n");
		}
	}
}

Measured memory_bytes: 5756
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int64_t H,W;
    cin >> H >> W;
    
    int64_t count = 0;
    if(H%2==0){
      count = (H / 2) * W;
    } else {
      count = (H / 2) * W;
      count += (W+1) /2 ;
    }
    
    if(H==1){ count = 1; }
    if(W==1){ count = 1; }
    
    
    cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void swap(int *a, int *b);

int main(void) {
	int a, b, c;
	
	//a, b, cを入力
	scanf("%d %d %d", &a, &b, &c);
	//昇順に整列
	if (a > b) {
    swap(&a, &b);
	}
	if (b > c) {
    swap(&b, &c);
	}
	if (a > b) {
    swap(&a, &b);
	}
	//出力
	printf("%d %d %d\n", a, b, c);
	
	return 0;
}

void swap(int *a, int *b) {
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}


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

int main()
{
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}

Measured memory_bytes: 3596
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			IO.Write(IO.Read().Distinct().Count() > 1);
		}
	}

	public static class IO
	{
		public static string   Read()								 { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')		 { return Read().Split(iSplitter); }
		public static int	   ReadInt()							 { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()							 { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static double   ReadDouble()							 { return double.Parse(Read()); }
		public static double[] ReadDoubleArray(char iSplitter = ' ') { return ReadArray().Select(iText => double.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()						 { return Read().ToCharArray(); }

		public static void Write(string iValue)									   { Console.WriteLine(iValue); }
		public static void Write(int iValue)									   { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue , string iJoinWord = " ") { Console.WriteLine(string.Join(iJoinWord , iValue)); }
		public static void Write(long iValue)									   { Console.WriteLine(iValue); }
		public static void Write(double iValue)									   { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)								   { Console.WriteLine(iValue); }
		public static void Write(bool iValue)									   { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i1 , i0); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}
		public static long CombinationNum(int iLeftNumber , int iRightNumber)
		{
			if(iRightNumber == 0) { return 1; }
			if(iLeftNumber == 0)  { return 0; }
			return iLeftNumber * CombinationNum(iLeftNumber - 1 , iRightNumber - 1) / iRightNumber;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}


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

const int n = 1000000;

string dic[n];

int getKey(string s){
    int key = 1;
    int p = 1;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'A') key += 1*p;
        else if(s[i] == 'C') key += 2*p;
        else if(s[i] == 'G') key += 3*p;
        else if(s[i] == 'T') key += 4*p;
        p *= 5;
    }
    return key % n;
}

string find(string s){
    int k = getKey(s);
    while(true){
        if(dic[k] == s){
            return "yes";
        }else if(dic[k] == ""){
            return "no";
        }else{
            k++;
            k %= n;
        }
    }
}

void insert(string s){
    int k = getKey(s);
    while(true){
        if(dic[k] == ""){
            dic[k] = s;
            break;
        }else if(dic[k] == s){
            break;
        }else{
            k++;
            k %= n;
        }
    }
}

int main(){
    int n; cin >> n;
    //string s1, s2;
    char s1[12], s2[12];
    for(int i = 0; i < n; i++){
        //cin >> s1 >> s2;
        scanf("%s %s",s1,s2);
        if(s1[0] == 'i'){
            insert(s2);
        }else if(s1[0] == 'f'){
            cout << find(s2) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 23960
#include<stdio.h>
int main(){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    if(x>y){
        if(y>z){
            printf("%d %d %d\n",z,y,x);
        }
        else if(x>z){
            printf("%d %d %d\n",y,z,x);
        }
        else printf("%d %d %d\n",y,x,z);
    }
    if(x<y){
        if(x>z){
            printf("%d %d %d\n",x,y,z);
        }
        else if(y>z){
            printf("%d %d %d\n",x,z,y);
        }
        else printf("%d %d %d\n",x,y,z);
    }
}

Measured memory_bytes: 1804
# from collections import deque
from collections import Counter
# from scipy.misc import comb
# from copy import deepcopy

n = int(input())
a = list(map(int, input().split()))
C = Counter(a)
S = 0
"""
for key in C:
    S += comb(C[key], 2, exact=True)
"""
for i in C.keys():
    S += C[i]*(C[i]-1)//2

for k in range(n):
    A = a[k]
    print(S - C[A] + 1)

Measured memory_bytes: 26780
#include<iostream>
using namespace std;
#define ll long long
ll n,cnt=1;
ll a[200010];
signed main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll min=a[0];
	for(ll i=1;i<n;i++){
		if(a[i]<min){
			cnt++;
			min=a[i];}}
	cout<<cnt<<endl;
} 

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC075C
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = ReadInt();
            int n = nm[0];
            int m = nm[1];

            int[] a = new int[m];
            int[] b = new int[m];
            for (int i = 0; i < m; i++)
            {
                var input = ReadInt();
                a[i] = input[0] - 1;
                b[i] = input[1] - 1;
            }

            int count = 0;
            for (int i = 0; i < m; i++) //無視する辺
            {
                var uf = new UnionFind(n);
                for (int j = 0; j < m; j++)
                {
                    if (i == j) continue;
                    uf.Unite(a[j], b[j]);
                }

                int par = uf.Find(0);
                for (int j = 1; j < n; j++)
                {
                    if (par != uf.Find(j))
                    {
                        count++;
                        break;
                    }
                }
            }

            Console.WriteLine(count);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }

    class UnionFind
    {
        int[] par;
        int[] rank;

        public UnionFind(int n)
        {
            init(n);
        }

        void init(int n)
        {
            par = new int[n];
            rank = new int[n];

            for (int i = 0; i < n; i++)
            {
                par[i] = i;
                rank[i] = 0;
            }
        }

        public int Find(int x)
        {
            if (par[x] == x)
            {
                return x;
            }
            else
            {
                return par[x] = Find(par[x]);
            }
        }

        public void Unite(int x, int y)
        {
            x = Find(x);
            y = Find(y);
            if (x == y) return;

            if (rank[x] < rank[y])
            {
                par[x] = y;
            }
            else
            {
                par[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }

        }
        public bool Same(int x, int y)
        {
            return Find(x) == Find(y);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+13;
const int mod=1e9+7; 
ll c[2013][2013];
int main()
{
	int s;
	scanf("%d",&s);
	c[1][0]=1ll;
	c[0][0]=0ll;
	for(int i=1;i<=2003;i++)
	{
		for(int j=0;j<=2003;j++)
		{c[i][j]=0;}} 
	for(int i=1;i<=2003;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(i==j)
			{
				c[i][j]=1;
				continue;
			}
			if(i&&j) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
			if(j==0) c[i][j]=1ll;
		}
	}
	if(s<=3)
	{
		if(s<3) printf("%d",0);
		else if(s==3) printf("1"); 
		return 0;
	}
	int mx=s/2;
	ll ans=0;
	for(int i=1;i<=mx;i++)
	{
		if(s-i*2==0) continue; 
		ans+=c[s-i*2-1][i-1];
		ans%=mod;
	}
	printf("%lld",ans);
 } 

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

int main() {
	int a,b,c;
	cin >> a >> b;
	
	for(int i=0;i<a;i++){
		if(i==0) c=b;
		if(i>0) c=c*(b-1);
	}
	
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m, k;
    cin >> m >> k;
    if (m == 0)
    {
        if (k != 0)
        {
            cout << -1 << endl;
        }
        else
        {
            cout << "0 0" << endl;
        }
        return 0;
    }
    if (m == 1)
    {
        if (k != 0)
        {
            cout << -1 << endl;
        }
        else
        {
            cout << "0 0 1 1" << endl;
        }
        return 0;
    }
    if (k >= (1 << m))
    {
        cout << -1 << endl;
        return 0;
    }

    vector<int> tmp;
    for (int i = 0; i < (1 << m); i++)
    {
        if (i != k)
        {
            tmp.push_back(i);
        }
    }
    vector<int> ans;
    sort(ALL(tmp));
    for (int i = 0; i < (int)tmp.size(); i++)
    {
        ans.push_back(tmp[i]);
    }
    ans.push_back(k);
    sort(RALL(tmp));
    for (int i = 0; i < (int)tmp.size(); i++)
    {
        ans.push_back(tmp[i]);
    }
    ans.push_back(k);
    for (int i = 0; i < (int)ans.size(); i++)
    {
        cout << ans[i] << ' ';
    }
    cout << endl;
}

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

int main(void){
    ll k;
    cin >>  k;

    cout << floor(k / 2.0) * ceil(k / 2.0) << endl;
    return 0;
}


Measured memory_bytes: 256
def resolve():
    A, B, C, X, Y = [int(i) for i in input().split()]
    # Cを0～max(X,Y)の2倍まで購入
    minA = float("inf")
    for i in range(0, max(X, Y) * 2 + 1, 2):
        sumA = C * i
        sumA += (A * (X - i // 2) if (X - i // 2) > 0 else 0)
        sumA += (B * (Y - i // 2) if (Y - i // 2) > 0 else 0)
        minA = min(minA, sumA)
    print(minA)


resolve()


Measured memory_bytes: 9016
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    int[] A = new int[N];
    int max=1;
    int index=0;
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
      if(A[i]>max) {
        max=A[i];
        index=i;
      }
    }
    
    int second=1;
    for(int j=0;j<N;j++){
      if(j!=index && A[j]>second){
        second=A[j]; 
      }
    }
    
    for(int k=0;k<N;k++){
      if(k!=index){
        System.out.println(max);
    } else{
        System.out.println(second);
    }
    }

  }
}

Measured memory_bytes: 115780