akhauriyash/Code-Regression huggingface dataset:
use proconio::*;
use proconio::marker::Usize1;

fn dfs(n: usize, m: usize, a: &mut [usize], g: &[Vec<(usize, usize, u32)>], score: u32) -> u32 {
    if n == 0 {
        return score;
    }
    let mut ans = 0;
    for i in 0..m {
        a[n - 1] = i;
        let mut s = score;
        for &(b, c, d) in g[n - 1].iter() {
            if a[b] - a[n - 1] == c {
                s += d;
            }
        }
        ans = std::cmp::max(ans, dfs(n - 1, i + 1, a, g, s));
    }
    ans
}

fn run() {
    input! {
        n: usize,
        m: usize,
        q: usize,
        e: [(Usize1, Usize1, usize, u32); q],
    }
    let mut g = vec![vec![]; n];
    for (a, b, c, d) in e {
        g[a].push((b, c, d));
    }
    let mut val = vec![0; n];
    let ans = dfs(n, m, &mut val, &g, 0);
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2132
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int[] p = new int[m];
      String[] s = new String[m];
      int[] ac = new int[n+1];
      int[] pena = new int[n+1];
      int sum1 = 0;
      for(int i=0;i<m;i++){
        p[i]=sc.nextInt();
        s[i]=sc.next();
        if(s[i].equals("WA")&&ac[p[i]]==0)pena[p[i]]++;
        else if(s[i].equals("AC")&&ac[p[i]]==0){
          sum1+=pena[p[i]];
          pena[p[i]]=0;
          ac[p[i]]++;
        }
      }
      int sum2 = 0;
      for(int i=1;i<=n;i++){
        if(ac[i]>0)sum2++;
      }
      System.out.println(sum2+" "+sum1);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}
class Pair{
    int a,b;

    Pair(int a, int b){
      this.a = a;
      this.b = b;
    }
}

Measured memory_bytes: 71384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0000
{
	class Program
	{
		static void Main(string[] args)
		{
			for( int i = 1; i <= 9; i++ ) {
				for( int j = 1; j <= 9; j++ ) {
					Console.WriteLine( "{0}x{1}={2}", i, j, i * j );
				}
			}
		}
	}
}

Measured memory_bytes: 5548
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  int a, b;
  cin >> a >> b;
  if (a%3==0||b%3==0||(a+b)%3==0)
    puts("Possible");
  else
    puts("Impossible");
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

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

int main(){
  int w, a, b;
  cin >> w >> a >> b;
  int res;
  if(a+w <= b)
    res = b-(a+w);
  else if(a+w>b && a+w <=(2*b+w)/2)
    res = 0;
  else if(a+w >(2*b+w)/2 && a+w <= b+w)
    res = 0;
  else if(a > b)
    res=a-b-w;
  
  cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    if(x==2||y==2)
    printf("No\n");
    else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))
    printf("Yes\n");
    else if ((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11))
    printf("Yes\n");
    else
    printf("No\n");


}


Measured memory_bytes: 128
local x, y = io.read("*n", "*n")
local a, b, c = io.read("*n", "*n", "*n", "*l")
local p = {}
local s = io.read()
for w in s:gmatch("%d+") do
  table.insert(p, tonumber(w))
end
s = io.read()
for w in s:gmatch("%d+") do
  table.insert(p, tonumber(w))
end
s = io.read()
for w in s:gmatch("%d+") do
  table.insert(p, tonumber(w))
end
local t = {}
for i = 1, a + b + c do
  t[i] = i
end
table.sort(t, function(f, g) return p[f] > p[g] end)
local ret = 0
local use_x = 0
local use_y = 0
local total = 0
for i = 1, a + b + c do
  local z = t[i]
  if z <= a then
    if use_x < x then
      use_x = use_x + 1
      total = total + 1
      ret = ret + p[z]
    end
  elseif z <= a + b then
    if use_y < y then
      use_y = use_y + 1
      total = total + 1
      ret = ret + p[z]
    end
  else
    total = total + 1
    ret = ret + p[z]
  end
  if total == x + y then break end
end
print(ret)


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop(i,b,n) for(int i=b;i<(n);++i)
#define each(e,v) for(auto &&e : v)

#define all(v) (v).begin(),(v).end()
#define sz(v) (int)v.size()

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const double EPS = 1e-9;

template<typename A,typename B> inline void chmin(A &a,B b){ if(a>b) a=b; }
template<typename A,typename B> inline void chmax(A &a,B b){ if(a<b) a=b; }
template <typename T> inline void print(const T& x) { cout << x << endl; }

int main() {
    int a;
    cin >> a;
    print(a+a*a+a*a*a);
    return 0;
}


Measured memory_bytes: 3624
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]

# x座標でソート
blue.sort(key=lambda x: x[1])

# y座標で降順ソート
red.sort(reverse=True)

# print(blue)
# print(red)

# blue_list = [0] * N
red_list = [0] * N


for b in range(N):
    for r in range(N):
        if red_list[r] == 1:
            continue
        if red[r][0] < blue[b][0] and red[r][1] < blue[b][1]:
            # print(b, r)
            # blue_list[b] = 1
            red_list[r] = 1
            break

print(sum(red_list))


Measured memory_bytes: 67408
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int main()
{
	int n;
	cin >>n;
	string A[N];
	int a[4]={0};//"AC"=0."WA"=1,"TLE"=2,"RE"=3;
	for(int i=0;i<n;i++){
		cin >> A[i];
		if(A[i]=="AC") a[0]++;
		else if(A[i]=="WA") a[1]++;
		else if(A[i]=="TLE") a[2]++;
		else a[3]++;	
	} 
	for(int i=0;i<4;i++){
		if(i==0) printf("AC x %d\n",a[i]);
		if(i==1) printf("WA x %d\n",a[i]);
		if(i==2) printf("TLE x %d\n",a[i]);
		if(i==3) printf("RE x %d",a[i]);
		
	}
} 

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

#define DEBUG(C) cerr << #C << " = " << C << endl

using namespace std;

const int MAX = 1e5 + 10;
int n, a[MAX];

bool r[MAX], u[MAX];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	int now = 0;
	int cnt = 0;
	while (!u[now]) {
	  u[now] = true;
	  if (now == 1) {
	    cout << cnt << endl;
	    return 0;
	  }
	  ++cnt;
	  now = a[now];
	}
	cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.InputStreamReader;


/*
 旅行先のパーティ

八重さんは、旅行先で何度か行われるパーティに出席することになりました。パーティでは１回につき１着、ドレスを身に付ける必要があります。旅行には何着かドレスを持っていきますが、パーティの回数よりもドレスの枚数が少ない場合、すべてのパーティに出席するには、同じドレスを何回か身に付ける必要があります。

おしゃれな八重さんは、同じドレスを何回も着たくありません。一番多く使うドレスを着る回数をなるべく少なくしたいと考えています。

ドレスの枚数とパーティの回数が与えられる。一番多く使うドレスを着る回数をなるべく少なくしたときに、そのドレスを何回着なければならないかを計算するプログラムを作成せよ。

入力
A B
１行にドレスの枚数A (1≤A≤105) とパーティの回数B (1≤B≤105)が与えられる。

出力
一番多く使うドレスを何回着なければならないかを、１行に出力する。

入出力例
入力例１
3 5
出力例１
2



 */

/**
 * URL
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0392&lang=ja
 */

class Main{

	public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String[] data = reader.readLine().split(" ");
			Integer numDress = Integer.parseInt(data[0]);
			Integer numParty = Integer.parseInt(data[1]);

			Integer result = numParty / numDress;
			if(numParty % numDress > 0) result += 1;

			System.out.println(result);

		}
	}
}









Measured memory_bytes: 24440
residents = [[[0] * 11 for i in range(4)] for j in range(5)]
N = int(input())
for _i in range(N):
    b, f, r, v = map(int, input().split())
    residents[b][f][r] += v
for i in range(1, 5):
    for j in range(1, 4):
        print(' ' + ' '.join(map(str, residents[i][j][1:])))
    if not i == 4:
        print(''.join(['#'] * 20))


Measured memory_bytes: 5608
#include <iostream>
#include <string>

#define ll long long
#define repeat(i, x) for(register ll i = 0; i < x; i++)

using namespace std;

int main()
{
  string S, T;
  int count;
  int max = 0;

  cin >> S >> T;

  for (register int i = 0; i <= S.size() - T.size(); i++) {
    count = 0;
    for (register int j = 0; j < T.size(); j++) {
      if (S[i+j] == T[j]) {
        count++;
      }
    }
    if(max < count) {
      max = count;
    }
  }

  cout << T.size() - max << endl;
}

Measured memory_bytes: 3616
#include<cstdio>

long long ans,a[8];

int main()
{
	for (int i=1; i<=7; ++i)
		scanf("%lld",&a[i]);
	ans=a[2];
	if (!a[1]||!a[4]||!a[5])
		ans+=a[1]/2*2+a[4]/2*2+a[5]/2*2;
	else
	{
		ans+=a[1]+a[4]+a[5];
		if (!(a[1]%2==a[4]%2&&a[4]%2==a[5]%2)) ans--;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
 
  int n, i;
  int MIN = 100000000;
  int MAX = -100000000;
  long long SUM = 0;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    int t;
    scanf ("%d", &t);
    if (t < MIN) {
      MIN = t;
    }
    if(t>MAX){
      MAX=t;
    }
    SUM+=t;
  }
 
  printf("%d %d %lld\n",MIN,MAX,SUM);
  return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

void solve(int N, int K, vector<int> A) {
  for (int i = 0;; i++) {
    if (K + (K - 1) * (i - 1) >= N) {
      printf("%d\n", i);
      return;
    }
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  solve(N, K, A);
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
#include<iomanip>
#include<tuple>
#include<stack>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

//const ll MOD_CONST = 1000000007;
const ll MOD_CONST = 998244353;


const int INF = 1000000000;
//const ll INF = 1000000000000000000;



int main() {
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; i++) {
		g[i].emplace_back(i + 1);
		g[i + 1].emplace_back(i);
	}

	int x, y;
	cin >> x >> y;
	x--;
	y--;
	g[x].emplace_back(y);
	g[y].emplace_back(x);


	vector<vector<int>> d(n,vector<int>(n,INF));
	for (int i = 0; i < n; i++) {
		d[i][i] = 0;
	}

	d[x][y] = 1;
	d[y][x] = 1;

	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			d[i][j] = j - i;
			
			d[i][j] = min(d[i][j], abs(i - x) + abs(j - y) + 1);

		}
	}

	map<int, int> m;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			m[d[i][j]]++;

		}
	}

	for (int i = 1; i < n; i++) {
		cout << m[i] << endl;
	}

}



Measured memory_bytes: 16128
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e5 + 5;


int n,a[maxn],tot;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n;
  for (int i=0; i<n; i++) {
    cin>>a[i];
    tot += a[i];
  }
  int ans = 1e9;
  int cur = a[0];
  for (int i=1; i<n; i++) {
    int rt = abs(tot-cur);
    ans = min(ans, abs(rt - cur));
    cur += a[i];
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <climits>
using namespace std;

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

    int x[100] = { 0 }, y[100] = { 0 }, h[100] = { 0 };
    for( int i = 0; i < N; ++i )
        cin >> x[i] >> y[i] >> h[i];

    int CX, CY;
    int tmp, tmp_h = -1, min_h = INT_MAX;
    bool flag = true;

    // 0 <= CX, CY <= 100 なので全探索
    for( CX = 0; CX <= 100; ++CX ){
        for( CY = 0; CY <= 100; ++CY ){
            for( int i = 0; i < N; ++i ){
                // max(hoge, 0) の出せる部分を出す
                tmp = abs(x[i]-CX) + abs(y[i]-CY);

                if( h[i] == 0 ){ // h[i] が 0 ならば，取り得る H の最小値が分かる（H はいくらでも大きくていいので）
                    min_h = tmp <  min_h ? tmp : min_h;
                } else { // h[i] が 0 以外ならば，h[i] = max(H-tmp) なので，H = h[i] + tmp
                    if( tmp_h == -1 ) tmp_h = h[i] + tmp;
                    else if( tmp_h != h[i]+tmp ){ flag = false; break; } // 他の i と H が一致しなかった，つまり CX, CY が誤り
                }
            }

            if( flag ){ // min_h および tmp_h が揃った
                if( min_h != INT_MAX && tmp_h != -1 ){
                    if( tmp_h <= min_h ){
                        cout << CX << " " << CY << " ";
                        cout << tmp_h << endl;
                        return 0;
                    }
                } else if( min_h == INT_MAX ){
                    if( tmp_h != -1 ){                    
                        cout << CX << " " << CY << " ";
                        cout << tmp_h << endl;
                        return 0;
                    }
                } else if( tmp_h == -1 ){
                    if( min_h != INT_MAX ){
                        cout << CX << " " << CY << " ";
                        cout << min_h << endl;
                        return 0;
                    }
                }
            }

            // tmp_h が揃わなかった
            tmp_h = -1;
            min_h = INT_MAX;
            flag = true;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import sys
a = sys.stdin.read().split('\n')[:-1]
q = int(a[1])
f = 1
l = [[], []]
for i in range(2, q + 2):
    if a[i][0] == '1':
        f = 1 - f
    else:
        l[0 if a[i][2] == '21'[f] else 1].append(a[i][4])
if f != 1:
    l[1].reverse()
    print(''.join(l[1]) + ''.join(reversed(list(a[0]))) + ''.join(l[0]))
else:
    l[0].reverse()
    print(''.join(l[0]) + a[0] + ''.join(l[1]))

Measured memory_bytes: 19772
#include <stdio.h>

int main(void)
{
	int money = 100000;
	int week;
	
	scanf("%d", &week);
	
	for (int i = 0; i < week; i++){
		money += money * 0.05;
		money = (money + 999) / 1000 * 1000;
	}
	
	printf("%d\n", money);
	
	return (0);
}

Measured memory_bytes: 0
// JAI SHREE RAM
/*
	Author: gourav_raj
*/
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
void solve()
{
	int r, c, k;
	cin >> r >> c >> k;
	int mat[r][c];
	int tx = 0;
	rep(i, r)
	rep(j, c)
	{
		char ch;
		cin >> ch;
		if (ch == '.')
			mat[i][j] = 0;
		else
			mat[i][j] = 1,tx++;
	}
	int res = 0;
	int l = pow(2, r  ), m = pow(2, c );
	for (int i = 0; i < l; i++)
		for (int j = 0; j < m; j++)
		{
			set<pii> st;
			int e = i, f = j;
			int x1=r-1,x2=c-1;
			while (e)
			{
				if(e&1)
					for(int q=0;q<c;q++)
						if(mat[x1][q]==1)
							st.insert({x1,q});
				e=(e>>1);
				x1--;
			}
			while (f)
			{
				if(f&1)
					for(int q=0;q<r;q++)
						if(mat[q][x2]==1)
							st.insert({q,x2});
				f=(f>>1);
				x2--;
			}	
			if((tx-st.size())==k)
				res++;
		
		}
		cout<<res<<endl;
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 4048
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;

const int N = 401;
const long long Inf = 4e18;

int n;
int a[N];
long long dp[N][N];

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


Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-4;

using namespace std;

typedef pair<int, double> P;
double dis(int x, int y)
{
	return sqrt((double)x*x+y*y);
}
int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int no[1000];
		int x[1001], y[1001];
		for (int i = 0; i < n; ++i)
		{
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			no[i] = a;
			x[a] = b;
			y[a] = c;
		}
		vector<P> reach[1001];
		for (int i = 0; i < n; ++i)
		{
			for (int j = i+1; j < n; ++j)
			{
				double t = dis(x[no[i]]-x[no[j]], y[no[i]]-y[no[j]]);
				if (t < 50 + Eps)
				{
					reach[no[i]].push_back(P(no[j], t));
					reach[no[j]].push_back(P(no[i], t));
				}
			}
		}
		
		int m;
		scanf("%d", &m);
		while (m--)
		{
			int from[1001];
			double d[1001];
			const int Inf = 100000000;
			for (int i = 0; i < 1001; ++i)
				d[i] = from[i] = Inf;
			int s, g;
			scanf("%d %d", &s, &g);
			priority_queue<P, vector<P>, greater<P> > nodes;
			nodes.push(P(0, s));
			d[s] = 0;
			from[s] = -1;
			while (!nodes.empty())
			{
				P v = nodes.top();
				nodes.pop();
				int id = v.second;
				if (id == g)
					break;
				else if (v.first > d[id])
					continue;

				for (int i = 0; i < reach[id].size(); ++i)
				{
					int to = reach[id][i].first;
					double cost = reach[id][i].second;
					if (v.first + cost < d[to])
					{
						d[to] = v.first + cost;
						from[to] = id;
						nodes.push(P(d[to], to));
					}
				}
			}
			if (d[g] != Inf)
			{
				vector<int> path;
				for (int i = g; i != -1; i = from[i])
					path.push_back(i);
				for (int i = path.size() - 1; i > 0; --i)
					printf("%d ", path[i]);
				printf("%d\n", path[0]);
			}
			else
				puts("NA");
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
ll n,a[maxn],cnt[maxn],ans=0;
int main() {
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
		cnt[a[i]]++;
	}
	for(int i=1; i<=n; i++) {
		ans += cnt[i]*(cnt[i]-1)/2;

	}
	for(int i=1; i<=n; i++) {
		if(cnt[a[i]]>=2){
			cout<<ans-cnt[a[i]]*(cnt[a[i]]-1)/2+(cnt[a[i]]-1)*(cnt[a[i]]-2)/2<<endl;
		}
		else cout<<ans<<endl;
	}
}

Measured memory_bytes: 4736
a,b = map(int, input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

hoge_a = set(prime_factorize(a))
hoge_b = set(prime_factorize(b))
ans = len(hoge_a & hoge_b) +1
print(ans)


Measured memory_bytes: 38896
n = int(input())
a = [int(i) for i in input().split()]
a.append(0)
b = [abs(a[0])]
c = [abs(a[1])]

for i in range(n):
    b.append(abs(a[i] - a[i+1]))
    if i < n-1:
        c.append(abs(a[i] - a[i+2]))
sum_b = sum(b)
for i in range(n):
    print(sum_b + c[i] - b[i] - b[i+1])


Measured memory_bytes: 17232
#include<bits/stdc++.h>
using namespace std;
int N,a[105],ans;
int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%d",a+i);
    a[N+1]=-1;
    for(int i=1,prev=-1,cnt=0;i<=N+1;i++){
        cnt++;
        if(a[i]!=prev){
            ans+=cnt/2;
            cnt=0;
            prev=a[i];
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


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

h = 10**11+7
b = 10**7+7

H = [1]
for _ in range(N):
    H.append((H[-1]*b)%h)

allSum = 0
for i in range(N):
    allSum = (allSum + H[i]) % h

ok = [True]*N
ans = [0]*N

L = 30
for l in range(L):
    HashA = 0
    for i, a in enumerate(A):
        if (1<<l)&a:
            HashA = (HashA + H[i]) % h

    HashB = 0
    for i, a in enumerate(B):
        if (1<<l)&a:
            HashB = (HashB + H[i]) % h
    
    for k in range(N):
        if (HashA+HashB)%h == allSum:
            ans[k] += (1<<l)
        elif HashA != HashB:
            ok[k] = False
        HashB = (HashB * b) % h
        if (1<<l)&B[-k-1]:
            HashB = (HashB + h - H[N] + 1) % h

for k in range(N):
    if ok[k]:
        print(k, ans[k])

Measured memory_bytes: 119372
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

#なお、任意の整数 M に対して M の −2 進数表現が一意に定まることが証明できます。
#2桁ごとに見るとよかった（もう実験したよ）
def resolve():
    N,=pin()
    n=N
    ans=[]
    a=["00","01","10","11"]
    b=[0,1,-2,-1]
    t=0
    for t in range(30):
        #print(n)
        n4=n%4
        ans.append(a[n4])
        n-=b[n4]
        n//=4
        if abs(n)==0:break
        
    ans.reverse()
    if ans[0][0]=="0":ans[0]=ans[0][1]
    print(*ans,sep="")
        
#%%submit!
resolve()

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

int memo[605][605]={},sh[605][605]={},sw[605][605]={};
string s[305];

int main(int argc, char const *argv[])
{
	int h,w;
	cin>>h>>w;
	for (int i = 0; i < h; ++i)
	{
		cin>>s[i];
	}
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			if (s[i][j]=='#')
			{
				memo[i+j+1][i-j+300]=1;
			}
		}
	}
	for (int i = 1; i < 605; ++i)
	{
		for (int j = 1; j < 605; ++j)
		{
			sh[i][j]=memo[i][j]+sh[i-1][j];
			sw[i][j]=memo[i][j]+sw[i][j-1];
		}
	}
	long long ans=0LL;
	for (int i = 1; i < 600; ++i)
	{
		for (int j = 1; j < 600; ++j)
		{
			for (int k = j+1; k < 600; ++k)
			{
				int d=k-j;
				if (memo[i][j]&&memo[i][k])
				{
					if (i-d>=0)
					{
						ans+=sw[i-d][k]-sw[i-d][j-1];
						ans-=memo[i-d][j]+memo[i-d][k];
					}
					if (i+d<=600)
					{
						ans+=sw[i+d][k]-sw[i+d][j-1];
						ans-=memo[i+d][j]+memo[i+d][k];
					}
				}
				if (memo[j][i]&&memo[k][i])
				{
					if (i-d>=0)
					{
						ans+=sh[k][i-d]-sh[j-1][i-d];
					}
					if (i+d<=600)
					{
						ans+=sh[k][i+d]-sh[j-1][i+d];
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4736
package main

import "fmt"
//import "strings"
//import "strconv"

func swap(a, b int)(int, int){
    return b, a 
}

func main(){

   // var s []string
    var n []int
   // var in_s string

  //  fmt.Scanln(&in_s)

   //s = strings.Fields(in_s)
    
   // for _, v := range s{
   //     x, _ := strconv.Atoi(v)
   //     n = append(n, x)
   // }

var a, b, c int
fmt.Scanf("%d%d%d", &a, &b, &c) ;
 n = append(n, a)
 n = append(n, b)
 n = append(n, c)
 
    for i:= 0; i < len(n) - 1; i++ {
        for j := i + 1 ; j < len(n) ; j++{
           if n[i] > n[j]{
                n[i], n[j] = swap(n[i], n[j])
           }
        }
    } 
    
    fmt.Println(n[0], n[1], n[2])


}


Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
string S;
ll N, M;
vector<string>A;


int main() {
    cin >> N;
    ll ans = 0;
    ans += (N / 500) * 1000;
    ans += ((N % 500) / 5) * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N;

string DecimalToBinary(ll n){
	string s = (n == 0) ? "0" : "";
	
	ll base = 1;
	ll m = 0;
	while(n != 0){
		if(n % (base * 2) == 0) s = "0" + s;
		else s = "1" + s, n += (m % 2 == 0) ? -base : base;
		base *= 2;
		++m;
	}
	return s;
}

int main(void){
    
    scanf("%d", &N);
    cout << DecimalToBinary(N) << endl;
    
    return 0;
}


Measured memory_bytes: 256
S = int(input())
L = S // 100
R = S % 100
if 0 < L < 13:
  if 0 < R <13:
    print('AMBIGUOUS')
  else :
    print('MMYY')
elif 0 < R < 13:
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
 // const ll INF = 1000000000000000000LL;

bool sequence(string s){
  bool ok = true;
  char ch = s[0];
  for(int i=1;i<s.size();i++){
    if(s[i]!=ch)
      ok = false;
  }
  return ok;
} 

int main() {
  string input_s,s;
  cin >> input_s;
  int ans = INF;
  if(sequence(input_s)){
    cout << 0 << endl;
    return 0;
  }

  rep(i,26){
    s = input_s;
    char ch = i + 'a';
    int cur = 0;
    while(s.size()){
      rep(j,s.size()-1){
        if(s[j+1]==ch)
          s[j] = ch;
      }
      s.pop_back();
      cur++;
      if(sequence(s)) break;
    }
    ans = min(ans,cur);
  }
  cout << ans << endl;
	return 0;
}


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

using namespace std;

int main (void) {
    string S, T;
    cin >> S >> T;

    int ans = 0;
    int len = S.size();
    for ( int i = 0; i < len; i++ ) {
        if ( S.at(i) != T.at(i) )
            ans++;
    }

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


Measured memory_bytes: 3836
#include<stdio.h>
int main(void)
{
	int x;
	scanf("%d",&x);
	if(x==1||x==8||x==15||x==22||x==29){
	printf("fri\n");
	}
	else	if(x==2||x==9||x==16||x==23||x==30){
	printf("sat\n");
	}
	else	if(x==3||x==10||x==17||x==24){
	printf("sun\n");
	}
	else	if(x==4||x==11||x==18||x==25){
	printf("mon\n");
	}
	else	if(x==5||x==12||x==19||x==26){
	printf("tue\n");
	}
	else	if(x==6||x==13||x==20||x==27){
	printf("wed\n");
	}
	else	{
	printf("thu\n");
	}
	return 0;
	}


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}

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

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}






int main(){
  int a, b, c;
	cin >> a >> b >> c;
	int k;
	cin >> k;
 
	for (int i = 0; i < k; i++)
	{
		if (a <= b && b >= c)
			c *= 2;
		else if (a >= b)
			b *= 2;
		else if (a >= c)
			c *= 2;
		else if (a <= b && b >= c)
			c *= 2;
		if (a < b && b < c)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
  
}

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

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

using namespace std;

string face[10][7] = {
  { "#######",
    "#.....#",
    "#...|.#",
    "#.....#",
    "#...|.#",
    "#..-..#",
    "#######" },

  { "#######",
    "#..-..#",
    "#...|.#",
    "#..-..#",
    "#.|...#",
    "#..-..#",
    "#######" },

  { "#######",
    "#..-..#",
    "#...|.#",
    "#..-..#",
    "#...|.#",
    "#..-..#",
    "#######" },

  { "#######",
    "#.....#",
    "#.|.|.#",
    "#..-..#",
    "#...|.#",
    "#.....#",
    "#######" },

  { "#######",
    "#..-..#",
    "#.|...#",
    "#..-..#",
    "#...|.#",
    "#..-..#",
    "#######" },

  { "#######",
    "#..-..#",
    "#.|...#",
    "#..-..#",
    "#.|.|.#",
    "#..-..#",
    "#######" },

  { "#######",
    "#..-..#",
    "#...|.#",
    "#.....#",
    "#...|.#",
    "#.....#",
    "#######" },

  { "#######",
    "#..-..#",
    "#.|.|.#",
    "#..-..#",
    "#.|.|.#",
    "#..-..#",
    "#######" },

  { "#######",
    "#..-..#",
    "#.|.|.#",
    "#..-..#",
    "#...|.#",
    "#..-..#",
    "#######" }

};

string input[100];

vector<string> rotate90(const vector<string>& piece){
  vector<string> ret;
  int h = piece[0].size(), w = piece.size();
  ret.resize(h);
  for(int i=0;i<h;i++)ret[i].resize(w);
  for(int y=0;y<ret.size();y++){
    for(int x=0;x<ret[0].size();x++){
      ret[y][x] = piece[ret[0].size()-1-x][y];
    }
  }
  return ret;
}

int x[] = {7,0,7,14,21, 7};
int y[] = {0,7,7, 7, 7,14};

inline void vec_reverse(vector<string> &vec){ rep(i,vec.size()) reverse(vec[i].begin(),vec[i].end()); }

vector<string> upper_change(vector<string> &vec){
  vector<string> ret = vec;
  rep(X,7) rep(Y,7) ret[Y][X] = vec[6-Y][X];
  return ret;
}

void rotate_prepare(vector<string> &vec) {
  rep(i,vec.size()) rep(j,vec[i].size()) {
    if( vec[i][j] == '|' ) vec[i][j] = '-';
    else if( vec[i][j] == '-' ) vec[i][j] = '|';
  }
}

int change(vector<string> &vec){
  rep(i,10) {
    bool failed = false;
    rep(j,7) if( face[i][j] != vec[j] ) { failed = true; break; }
    if( failed ) continue;
    return i + 1;
  }
  assert(false);
}

vector<int> getValue(vector<string> vec){
  vector<int> ret;
  rep(i,6){
    vector<string> block;
    rep(j,7) block.push_back(vec[y[i]+j].substr(x[i],7));
    if( i == 1 || i == 3 ) rotate_prepare(block);
    if( i == 1 ) block = rotate90(block);
    if( i == 3 ) rep(j,3) block = rotate90(block);
    vec_reverse(block);
    if( i == 5 ) block = upper_change(block);
    ret.push_back(change(block));
  }
  return ret;
}

void compute(){
  vector<string> term(21);
  rep(i,21) term[i] = input[i].substr(0,28);
  vector<int> dice[2];



  dice[0] = getValue(term);
  rep(i,21) term[i] = input[i].substr(29,28);
  dice[1] = getValue(term);
  int score[2] = {0,0};
  rep(i,6) rep(j,6) {
    if( dice[0][i] < dice[1][j] ) ++score[1];
    else if( dice[0][i] > dice[1][j] ) ++score[0];
  }
  if( score[0] >= score[1] ) puts("HIGH");
  else puts("LOW");
}

int main(){
  while(1){
    cin >> input[0];
    if( input[0] == "0" ) break;
    REP(i,1,21) cin >> input[i];
    compute();
  }
  return 0;
}

Measured memory_bytes: 1220
import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip('\r\n')
ans = 0
for i in range(N-2):
    if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
       ans += 1
print(ans)

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

s=list(map(int,input().split()))

cnt=0

for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
        if s[i]+s[j]>s[k] and s[j]+s[k]>s[i] and s[i]+s[k]>s[j]:
          cnt+=1
print(cnt)

Measured memory_bytes: 68204
main=do
  a<-map(map read.words).lines<$>getContents
  putStr$unlines$f 0(a!!0!!0)(a!!0!!1)(tail a)
f i n m a=if i>=n then[]else (show(snd(minimum[((abs(((snd s)!!0)-(a!!i!!0)))+(abs(((snd s)!!1)-(a!!i!!1))),(fst s))|s<-(zip[1..](drop n a))]))):f(i+1)n m a


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

using namespace std;

int main() {

//	string s;
//	cin >> s;

	long n,m;
	cin >> n >> m;

	vector<vector<int>> sc(10,vector<int>(3));

	for (int i = 0; i < m; i++) {
		cin >> sc[i][1] >> sc[i][2];
	}

	int st, ed;
	if (n == 1) { st = 0; ed = 10; }
	if (n == 2) { st = 10; ed = 100; }
	if (n == 3) { st = 100; ed = 1000; }
	
	bool chkflg;
	for (int i = st; i < ed; i++) {
		vector<long> a(n+1);
		int k;
		k = i;
		
		for (int j = 1; j <= n; j++) {
			a[n - j + 1] = k % 10;
			k /= 10;
		}

		chkflg = true;
		for (int j = 0; j < m; j++) {
			if (sc[j][2] != a[sc[j][1]]) {
				chkflg = false;
				break;
			}
		}
		if (chkflg == true) {
			cout << i << endl;
			return 0;
		}
	}

	cout << "-1" << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

struct Fenwick {
	vl t;
	Fenwick(int n) : t(n+1) {}
	ll sum(int pos) {
		++pos;
		ll ret = 0;
		while(pos > 0) {
			ret += t[pos];
			pos &= (pos-1);
		}
		return ret;
	}
	void add(int pos, ll val) {
		++pos;
		while(pos < t.size()) {
			t[pos] += val;
			pos += (pos & -pos);
		}
	}
};

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	int n;
	ll k;
	cin >> n >> k;
	vl a(n+1);
	rep(i,1,n+1) {
		cin >> a[i];
		a[i] -= k;
	}
	rep(i,1,n+1) {
		a[i] += a[i-1];
	}
	map<ll, ll> r;
	rep(i,0,n+1) {
		if(r.find(a[i]) != r.end()) {
			r[a[i]]++;
		} else {
			r[a[i]] = 1;
		}
	}
	map<ll, int> idx;
	Fenwick tree(r.size());
	int t = 0;
	for(auto e : r) {
		idx[e.F] = t++;
		tree.add(idx[e.F], e.S);
	}
	ll ret = 0;
	ll mx = r.rbegin()->F;
	rep(i,0,n+1) {
		tree.add(idx[a[i]], -1);
		ret += tree.sum(idx[mx]) - tree.sum(idx[a[i]]-1);
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 28416
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
using namespace std;

int main(){ 
  int a=0,b=0,c=0,d=0,n,x,y,m;
  string s;
  cin>>n>>a>>b>>s;
  rep(i,0,n){
    if(s[i]=='a'){
      if(c<a+b){
        c++;
        co("Yes");
        continue;
      }
      else co("No");
    }
    else if(s[i]=='b'){
      if(c<a+b && d<b){
        c++;
        d++;
        co("Yes");
        continue;
      }
      else co("No");
    }
    else co("No");
  }
  
  
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  ll h;
  cin >> h;

  ll x = 1;
  ll res = 0;
  while(h>0){
    h /= (ll)2;
    res += x;
    x *= (ll)2;
  }

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int p[60000],cnt,n;
bool b[100005];
void work(int n)
{
    memset(b,1,sizeof b);
    b[1]=0;
    for(int i=2;i<=n;i++)
    {
        if(b[i])p[++cnt]=i;
         for(int j=1;j<=cnt&&i*p[j]<=n;j++)
         {
            b[i*p[j]]=0;
            if(i%p[j]==0)break;
        }
    }
}
int main()
{
	work(55555);
	scanf("%d",&n);
	int tot=0;
	for(int i=1;i<=cnt;i++){
		if(p[i]%5==1) tot++,printf("%d ",p[i]);
		if(tot==n) break;
	}
	return 0;
}



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

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    cout<<a[n-1]-a[0]<<endl;
}


Measured memory_bytes: 256
nums = [int(e) for e in input().split()]
N = nums[0]
K = nums[1]

list0 = []
for i in range(0, 2*K):
  val = [int(e) for e in input().split()]
  if i%2 == 1:
      list0.extend(val)

num = N - len(list(set(list0)))

print(num)

Measured memory_bytes: 9232
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
using namespace std;

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    for(int i = 0; i < M; i++) cin >> a[i] >> b[i];

    vector<int> edge(N + 1, 0);
    for(int i = 0; i < M; i++){
        edge[a[i]]++;
        edge[b[i]]++;
    }

    for(int i = 1; i <= N; i++){
        cout << edge[i] << endl;
    }

    return 0;
}

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


int main() {

    vector<int> a(3);
    rep(i, 3) cin >> a[i];
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
        sort(a.rbegin(), a.rend());
        a.push_back(2*a[0]);
        a.erase(a.begin());
    }
    int sum = 0;
    rep(i, 3) sum += a[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

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

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

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

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

class LazySegTree{
private:
	int n;
	vector<ll> node, lazy;
	vector<bool> lazyFlag;
public:
	LazySegTree(vector<ll> v){
		int sz = (int)v.size();
		n = 1; while(n < sz) n*=2;
		node.resize(2*n-1, ((ll)1<<31)-1);
		lazy.resize(2*n-1, 0);
		lazyFlag.resize(2*n-1, 0);

		REP(i, sz) node[i+n-1] = v[i];
		for(int i = n-2;i >= 0;i--) node[i] = min(node[i*2+1], node[i*2+2]);
	}

	void eval(int k, int l, int r){
		if(lazyFlag[k]){
			node[k] = lazy[k];
			
			if(r - l > 1){
				lazy[2*k+1] = lazy[k];
				lazy[2*k+2] = lazy[k];
				lazyFlag[2*k+1] = lazyFlag[2*k+2] = 1;
			}

			lazy[k] = 0;
			lazyFlag[k] = false;
		}
	}

	void add(int a, int b, ll x, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);
		
		if(b <= l || r <= a) return;

		if(a <= l && r <= b){
			lazyFlag[k] = true;
			lazy[k] = x;
			eval(k, l, r);
		}else{
			add(a, b, x, k*2+1, l, (l+r)/2);
			add(a, b, x, k*2+2, (l+r)/2, r);
			node[k] = min(node[k*2+1],node[k*2+2]);
		}
	}

	ll query(int a, int b, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);

		if(b <= l || r <= a) return INF_LL;
		if(a <= l && r <= b) return node[k];
		return min(query(a, b, 2*k+1, l, (l+r)/2), query(a, b, 2*k+2, (l+r)/2, r));
	}
};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, q;
	cin >> n >> q;
	
	vector<ll> v(n, ((ll)1<<31)-1);
	LazySegTree sg(v);
	REP(i, q){
		int k;
		cin >> k;
		if(k == 0){
			int s, t, k;
			cin >> s >> t >> k;
			sg.add(s, t+1, k);
		}else{
			int s, t;
			cin >> s >> t;
			cout << sg.query(s, t+1) << endl;
		}
	}
}

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

using namespace std;

int main()
{
	// 入力
	string S, T;
	cin >> S >> T;
	
	int n = S.size();

	bool bAnswer = true;
	vector<int> vecA(26, -1);
	vector<int> vecB(26, -1);

	for (int i = 0; i < n; i++)
	{
		int si = S[i] - 'a';
		int ti = T[i] - 'a';

		if (vecA[si] < 0)
		{
			vecA[si] = ti;
		}
		else if (vecA[si] != ti)
		{
			bAnswer = false;
		}

		if (vecB[ti] < 0)
		{
			vecB[ti] = si;
		}
		else if (vecB[ti] != si)
		{
			bAnswer = false;
		}
	}

	// 出力
	if (bAnswer)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;

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

    map <string, bool> s;
    int n;
    string x;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        s[x] = true;
    }
    cout << s.size();
}

Measured memory_bytes: 19136
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld radian(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string s;
	cin >> s;
	cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ll long long
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

int main(){
    int n,r;
    cin >> n >> r;
    cout << r + max(0,(10-n)) * 100 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1000000007;
ll mod(ll x){
        return ((x%M + M)%M);
    }
ll add(ll a, ll b){
        return mod(mod(a)+mod(b));
    }
ll mul(ll a, ll b){
        return mod(mod(a)*mod(b));
    }
ll minu(ll a, ll b){
        return mod(mod(a)-mod(b));
    }
ll power(ll a, ll b){
    ll res=1;
    while(b>0){
        if(b&1) res=mul(res,a);
        b = b>>1;
        a=mul(a,a);
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    ll rem =0;
    for(ll i=0;i<(1e7);++i){
        rem=(rem*10 + 7)%n;
        if(rem==0){
            cout<<i+1;
            return 0;
        }
    }
    cout<<"-1";
    return 0; 
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define ull unsigned long long
using namespace std;
const int maxx = 1007;
const ll mod1 = 1e7;
const ll mod = 1e9 + 7;
const ll base = 311;
const ll base1 = 113;
const ll maxn = 1e6 + 7;
bool check;
ll t, T, n, a[maxn], b[maxn], m1, m, tong, r, ans, mx, k, ma[maxx][maxx], pw[maxx][maxx];
//ll , c[maxx], st1[maxx];
//ll  , pw[maxx];
//string s[maxx], ss[maxx], str, f[maxx][10];
struct dang
{
    ll mn, gcd, val, pos, dd, n1, n2, n3;
};
dang f[maxx][maxx];
string s;
struct les
{
    bool operator()(ll x, ll y)
    {
        return x > y;
    }
};
dang c[maxn];
deque<ll> st;
priority_queue<ll, vector<ll>, les >st1;
map<ll, ll> mp;
vector<ll> adj;
void sol()
{

    cin >> n;
    ans = 0;
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
    for(int i = 1; i <= n; i ++)
        cin >> b[i];
    for(int i = 1; i <= n; i ++)
    {
        while(!st.empty() && b[st.back()] < b[i])st.pop_back();
        while(!st.empty() && b[st.front()] > a[i])st.pop_front();
        if(a[i] != b[i] && (st.empty() || b[st.back()] != b[i]))
        {
            ++ans;
            st.push_back(i);
        }
    }
    cout << ans;
}

void ntu()
{
    cin >> n;
    for(int i = 2 ;i <= n; i ++)
    {
        cin >> k;
        ++a[k];
    }
    for(int i = 1; i <= n; i ++)cout << a[i] <<'\n';
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    //freopen("Test.INP", "r", stdin);
    ntu();
}
/*
3 4
0 3 -1 2
3 3 3 3
3 1 3 0
*/


Measured memory_bytes: 5156
#define _USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll T, N, M, D[200005];
vector <ll> adj[200005];
queue <ll> pro;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	T = 1;
	
	for (ll q = 0; q < T; q++) {
		
		cin >> N >> M;
		for (ll i = 1; i <= M; i++) {
			ll a, b;
			cin >> a >> b;
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
		
		memset(D, -1, sizeof D);
		D[1] = 0;
		pro.push(1);
		
		while (!pro.empty()) {
			ll cur = pro.front();
			pro.pop();
			for (ll nex : adj[cur]) {
				if (D[nex] == -1) {
					D[nex] = D[cur] + 1;
					pro.push(nex);
				}
			}
		}
		
		cout << "Yes\n";
		for (ll i = 2; i <= N; i++) {
			for (ll nex : adj[i]) {
				if (D[nex] == D[i] - 1) {
					cout << nex << "\n";
					break;
				}
			}
		}
		
	}
		
    return 0;
}

Measured memory_bytes: 16196