akhauriyash/Code-Regression huggingface dataset:
use std::collections::*;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a: Vec<i32> = sc.vec(n);
    let mut count: BTreeMap<i32, i64> = BTreeMap::new();
    for i in 0..n {
        *count.entry(a[i]).or_insert(0) += 1;
    }
    let mut base: i64 = 0;
    for (_key, value) in count.iter() {
        base += value * (value - 1) / 2;
    }
    for e in a.iter() {
        println!("{}", base - count[e] + 1);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 7676
n = int(input())
num = list(map(int, input().split()))
count = 0
while True:
    exist_odd = "false"
    for i in range(n):
        if num[i] % 2 != 0:
            exist_odd = "True"
    if exist_odd == "True":
        break
    for i in range(n):
        num[i] /= 2
    count += 1
print(count)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, kk, x[51], y[51];
  cin >> n >> kk;
  rep(i, 0, n) cin >> x[i] >> y[i];
  int ans = 7446744073709551612;
  rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) rep(l, 0, n) {
    int mx = max(max(x[i], x[j]), max(x[k], x[l]));
    int mix = min(min(x[i], x[j]), min(x[k], x[l]));
    int my = max(max(y[i], y[j]), max(y[k], y[l]));
    int miy = min(min(y[i], y[j]), min(y[k], y[l]));
    if(mx == mix || my == miy) continue;
    int count = 0;
    rep(i, 0, n) if(x[i] <= mx && x[i] >= mix && y[i] <= my && y[i] >= miy) count++;
    if(count >= kk) {
      ans = min(ans, abs(mx - mix) * abs(my - miy));
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

dx = [0,1,0,-1]; dy = [1,0,-1,0]
h,w = inpl()
g = [input() for _ in range(h)]
dist = [[-1] * w for _ in range(h)]
dist[0][0] = 0
q = deque()
q.append([0,0])

while q:
    y,x = q.popleft()
    for i in range(4):
        ny = y + dy[i]
        nx = x + dx[i]
        if 0 <= ny < h and 0 <= nx < w and dist[ny][nx] == -1 and g[ny][nx] == '.':
            dist[ny][nx] = dist[y][x] + 1
            q.append([ny,nx])

if dist[-1][-1] == -1:
    print(-1)
    quit()
bl = sum(i.count('#') for i in g)
wh = dist[-1][-1] + 1
print(h*w - (wh+bl))

Measured memory_bytes: 66156
"""
keyword: 二項係数, 冪乗のmod

与えられた文字列sの最後の文字以降は何を置いても(26通り)良い一方で、最後の文字より前は同じ文字は置けない(25通り)
そこで最後の文字より後と前で分けて場合の数を考える

pow(x, y, z) は pow(x, y) % z よりも高速で処理されるので、こちらを使う

pythonでTLE, pypyでAC
"""

import sys
sys.setrecursionlimit(10**6)

k = int(input())
s = input()

mod = 10**9+7

n = len(s)
fact = [1, 1] # あとでnの階乗を求める初期値　[0!, 1!]

# n!を求める
for i in range(2, 2*(10**6)+1):
    fact.append(fact[-1]*i % mod)

# 二項係数nCrを求める nCr = n!/r!(n-r)!
def nCr(n, r, mod=10**9+7):
    return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod # modの世界では逆元はpow(x,mod-2)をかけることと同じ

ans = 0
#for i in range(k+1):
#    ans = (ans+nCr(n+k, i)*pow(25, i, mod)) % mod
#print(ans)

for i in range(k+1):
    now = pow(26, k-i, mod) * pow(25, i, mod) * nCr(i+n-1, i)
    ans = (ans+now) % mod
print(ans)

Measured memory_bytes: 216732
import sys
import numpy as np
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
xy = []
for _ in range(N):
  x,y = map(int, readline().split())
  xy.append((x,y))
sum = 0
for i in range(N):
  for j in range(i+1,N):
    x1,y1 = xy[i]
    x2,y2 = xy[j]
    dist = math.sqrt((x1-x2)**2 + (y1-y2)**2)
    sum += dist
ans = 2*sum/N
print('{:.7f}'.format(ans))
    

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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=2e5+10;

ll a[MAXN];

ll n;

bool check(ll x)
{
    ll l=n , r=n;

    while (r<2*n-1)
    {
        if ((a[l-1]<=x)==(a[l]<=x) || (a[r+1]<=x)==(a[r]<=x))
        {
            return (a[l]<=x);
        }

        l--;
        r++;
    }

    return (n&1 ? (a[n]<=x) : (a[n]>x));
}

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

	cin>>n;

	for(ll i=1;i<=2*n-1;i++)
    {
        cin>>a[i];
    }

    ll L=0 , R=2*n-1;

    while (R-L>1)
    {
        ll mid=(L+R)/2;

        if (check(mid))
        {
            R=mid;
        }
        else
        {
            L=mid;
        }
    }

    cout<<R;
}


Measured memory_bytes: 1792
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR (i,n) for(int i=n;i>0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;


int main(void) {
	string s;
	cin >> s;
	int a = s.find('A'), z = s.rfind('Z');
	cout << z - a + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <functional>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    long long N, K;
    vector<vector<long long>> TD;

    cin >> N >> K;
    for (long long i = 0; i < N; i++)
    {
        long long t, d;
        cin >> t >> d;
        TD.push_back(vector<long long>{t, d});
    }

    sort(TD.begin(), TD.end(), [](const vector<long long> &x, const vector<long long> &y) { return x[1] > y[1]; });

    set<long long> t, idx;
    vector<long long> v;
    priority_queue<
        long long,
        vector<long long>,
        greater<long long>>
        q;
    long long total = 0;
    for (long long i = 0; i < N; i++)
    {
        if (t.find(TD[i][0]) == t.end())
        {
            t.insert(TD[i][0]);
            total += TD[i][1];
            idx.insert(i);
            q.push(TD[i][1]);

            if (idx.size() >= K)
                break;
        }
    }

    for (long long i = 0; idx.size() < K; i++)
    {
        if (idx.find(i) == idx.end())
        {
            idx.insert(i);
            total += TD[i][1];
            q.push(TD[i][1]);
        }
    }

    long long count = t.size();
    for (long long i = 0; i < N; i++)
    {
        if (idx.find(i) == idx.end())
        {
            if (total + count * count < total - q.top() + TD[i][1] + (count - 1) * (count - 1))
            {
                total = total - q.top() + TD[i][1];
                count--;
                q.pop();
            }
        }
    }

    cout << total + count * count << endl;
}

Measured memory_bytes: 13872
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int count = 0;
		for(int i = a; i <= b; i++) {
			String s = Integer.toString(i);
			if(s.charAt(0)==s.charAt(4)&&s.charAt(1)==s.charAt(3)) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 30804
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;

int main()
{
	ll m,i,j,k,s=0,x=0,y=0,z,a,n,b,c,g,minn=INT_MIN,maax=INT_MAX;
cin>>n;
ll arr[n+1];
for(i=1;i<=n;i++) cin>>arr[i];
ll ar[n+1];
g=10000000;
for(i=1;i<=n;i++) ar[i]=g-arr[i];
for(i=1;i<=n;i++)
{
	if(ar[i]>minn)
	{
		minn=ar[i];x++;
		
	//	cout<<arr[i];
	}
}
cout<<x;
}

Measured memory_bytes: 3328
N = int(input())
total_yen = 0
btc = 0
for i in range (N):
    x, u =map(str,input().split())
    if u == 'JPY':
        total_yen += float(x)
    else:
        btc       += float(x)

print(total_yen+380000.0*btc)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
ll m,n,ans;
vector<ll>a;
ll sum[100010];

bool check(ll mid){
    ll num=0;
    for(ll i=0;i<n;i++){
        auto itr=lower_bound(a.begin()+i,a.end(),mid-a[i]);
        if(itr!=a.end()){
            ll index=itr-a.begin();
            if(index==i)num+=(n-index)*2-1;
            else num+=(n-index)*2;
        }
    }
    return num>=m;
}

ll check1(ll mid){
    ll num=0;
    for(ll i=0;i<n;i++){
        auto itr=lower_bound(a.begin()+i,a.end(),mid-a[i]);
        if(itr!=a.end()){
            ll index=itr-a.begin();
            if(index==i)num+=(n-index)*2-1;
            else num+=(n-index)*2;
        }
    }
    return num;
}

int main(void){
    cin>>n>>m;
    a.resize(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    ll ok=0,ng=a[n-1]*3;
    while(ng-ok>1){
        ll mid=(ng+ok)/2;
        if(check(mid))ok=mid;
        else ng=mid;
    }
    //cout<<ok<<endl;
    for(ll i=0;i<n;i++)sum[i+1]=sum[i]+a[i];
    for(ll i=0;i<n;i++){
        auto itr=lower_bound(a.begin()+i,a.end(),ok-a[i]);
        if(itr!=a.end()){
            ll index=itr-a.begin();
            if(index==i)ans+=(sum[n]-sum[index])*2+a[i]*(n-index)*2-2*a[index];
            else ans+=(sum[n]-sum[index])*2+a[i]*(n-index)*2;
        }
    }
    cout<<ans-ok*(check1(ok)-m)<<endl;
    return 0;
}

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

int main() {
  double N,T,A; cin>>N>>T>>A;
  vector<double> H(N+1); rep1(i,N) cin>>H[i];
  vector<double> avet(N+1);
  vector<double> Atonosa(N+1);
  rep1(i,N) {
    avet[i] = T - (H[i] * 0.006);
    Atonosa[i] = abs(A-avet[i]);
  }
  int i=1;
  int ans = 1;
  for(i=1;i<=N;i++) {
    if(Atonosa[i] < Atonosa[ans])
      ans=i;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
public class Hello{
  
    public static void Main(){
        int[] array = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
        int N = array[0];
        int X = array[1];
        int min = int.MaxValue;
        int ans = 0;
        
        for(int i = 0;i < N;i++){
            int n = int.Parse(Console.ReadLine());
            X -= n;
            min = Math.Min(min,n);
        }
        ans += N + X / min;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$A = $key->A[0];
$B = $key->A[1];

if ($A % 3 == 0 || $B % 3 == 0 || ($A+$B) % 3 == 0) {
  printf("Possible\n");
}
else {
  printf("Impossible\n");
}


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

using namespace std;

using T = pair<int, pair<int, int>>;

vector<T> e;

const int INF = 1e9 + 100;

int main()
{
  int N, Q;
  cin >> N >> Q;
  set<int> s;
  s.insert(INF);
  for (int i = 0; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    e.emplace_back(a - c, make_pair(1, c));
    e.emplace_back(b - c, make_pair(-1, c));
  }
  e.emplace_back(INF, make_pair(0, 0));
  sort(e.begin(), e.end());
  int pos = 0;
  for (int i = 0; i < Q; i++) {
    int d;
    cin >> d;
    while (e[pos].first <= d) {
      if (e[pos].second.first == 1) {
        s.insert(e[pos].second.second);
      } else {
        s.erase(e[pos].second.second);
      }
      pos++;
    }
    int r = *(s.begin()) == INF ? -1 : *(s.begin());
    cout << r << endl;
  }
}

Measured memory_bytes: 15724
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
using namespace std;
typedef long long ll;

/*int main(void) {
	int N, K,i=0,j=0;
	cin >> N >> K;
	int x[100000];
	int mintime = 0,a;
	REP(i, N) { 
		cin >> x[i]; 
	}
	if (N == 1 && K == 1)cout << "0" << endl;
	REP(i, K) {
		
	}
	mintime += abs(x);
}*/

int main() {
	int H, W, i = 0, j = 0;
	char a[100][100];
	cin >> H >> W;
	REP(i, H) {
		REP(j, W) {
			cin >> a[i][j];
		}
	}
	vector<bool> row(H, false);
	vector<bool> col(W, false);
	REP(i, H) {
		REP(j, W) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}
	REP(i, H) {
		if (row[i]) {
			REP(j, W) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;
}




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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, L;

int main() {
    cin >> N >> L;
    bool ansB = false;
    int ansI;

    vi A(N);
    cin >> A[0];
    for (int i = 1; i < N; i++) {
        cin >> A[i];
        if (A[i - 1] + A[i] >= L) {
            ansB = true;
            ansI = i;
        }
    }

    if (!ansB) {
        cout << "Impossible" << endl;
    } else {
        cout << "Possible" << endl;
        for (int i = 1; i < ansI; i++)
            cout << i << endl;
        for (int i = N - 1; i >= ansI; i--)
            cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <math.h>

using namespace std;

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

    int digits = to_string(N).length();

    int result = 0;

    if (digits == 1) {
        result = N;
    }
    if (digits == 2) {
        result = 9;
    }
    if (digits == 3) {
        result = 9 + (floor(N/100)-1)*100 + 1 + N%100;
    }
    if (digits == 4) {
        result = 9 + 900;
    }
    if (digits == 5) {
        result = 9 + 900 + (floor(N/10000)-1)*10000 + 1 + N%10000;
    }
    if (digits == 6) {
        result = 9 + 900 + 90000;
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 256
import sys

n, k = map(int, input().split())
a = list(map(int, sys.stdin.readline().split()))
ans = a[k-1] - a[0]
for i in range(1, k-1):
    if ans > n - (a[i+1] - a[i]):
        ans =  n - (a[i+1] - a[i])
print(ans)


Measured memory_bytes: 26024
#include <stdio.h>
#include <deque>
using namespace std;
int main(){
    int n,k;
    deque<int> dq;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&k);
        if(k==0){
            scanf("%d",&k);
            if(k==0){
                scanf("%d",&k);
                dq.push_front(k);
            }
            else {
                scanf("%d",&k);
                dq.push_back(k);
            }
        }
        else if(k==1){
            scanf("%d",&k);
            printf("%d\n",dq[k]);
        }
        else{
            scanf("%d",&k);
            if(k==0)dq.pop_front();
            else dq.pop_back();
        }
    }
}


Measured memory_bytes: 4152
n = int(input())
if (n % 10) == 2 or (n % 10) == 4 or (n % 10) == 5 or (n % 10) == 9 or (n % 10) == 7 :
	print("hon")
elif (n % 10) == 0 or (n % 10) == 1 or (n % 10) == 6 or (n % 10) == 8 :
	print("pon")
elif (n % 10) == 3 :
	print("bon")

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <map>
using namespace std;
long long a[200010],ten[200010],sum[200010];
map<long long,int> mp;
int main(){
	long long i,n,p,ans = 0;
	string s;
	cin >> n >> p >> s;
	if(p==2){
		for(i=0;i<n;i++){
			if((s[i] - '0')%2==0){
				ans += (i + 1);
			}
		}
	}else if(p==5){
		for(i=0;i<n;i++){
			if((s[i] - '0')%5==0){
				ans += (i + 1);
			}
		}
	}else{
		ten[0] = 1;
		for(i=1;i<=n;i++){
			ten[i] = (ten[i - 1]*10)%p;
		}
		for(i=0;i<n;i++){
			long long x = s[i] - '0';
			a[i] = (ten[n - 1 - i]*x)%p;
		}
		sum[0] = 0;
		mp[0]++;
		for(i=0;i<n;i++){
			sum[i + 1] = (sum[i] + a[i])%p;
			ans += mp[sum[i + 1]];
			mp[sum[i + 1]]++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5764
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>

using namespace std;

int main()
{
  uint16_t N, K;
  cin >> N >> K;

  uint16_t max_pair = (N-1)*(N-2)/2;
  
  if (K > max_pair) {
    cout << -1 << endl;
    return 0;
  }

  vector<pair<uint8_t,uint8_t>> ans;

  for (uint8_t n=1; n<(uint8_t)N; ++n)
    ans.push_back(make_pair(n,N));

  uint16_t count = 0;
  for (uint8_t ii=1; ii<(uint8_t)N; ++ii) {
    for (uint8_t jj=ii+1; jj<(uint8_t)N; ++jj) {
      if (max_pair-++count < K)
	break;
      ans.push_back(make_pair(ii,jj));
    }
  }

  cout << ans.size() << endl;
  for (auto& p : ans)
    cout << (uint16_t)p.first << ' ' << (uint16_t)p.second << endl;

  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab=[0]*m
for i in range(m):
    ab[i] = [int(x) for x in input().split()]
ab.sort()
ans = 1
key = ab[0][1]
for i in range(m):
    if ab[i][0] >= key:
        ans += 1
        key = ab[i][1]
    elif ab[i][1] < key:
        key = ab[i][1]
print(ans)

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

int main() {
  int n; cin >> n;
  int f=0,t=n;
  while (t > 0) {
    /* code */
    f += t%10;
    t /= 10;
  }
  std::cout << (n%f ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
///Hello_World_Its_Rakib_Alam_Bappi
#include<bits/stdc++.h>
using namespace std;
///ascii for  A=65   and   a=97
#define		int 	long long
#define 		pb 	push_back
#define 		mp 	make_pair
#define 		pi 	2*acos(0.0)
#define 		loopi 	for(int i = 0 ; i <t ; i++)
#define 		loopj 	for(int j = 0 ; j < n-1 ; j++)
#define 		backj 	for(int j = n-1 ; j >=0 ; j--)
#define 		vect 	vector<int>
#define 		vec_it 	vector<int>::iterator vi
#define 		mapp 	map<int,int>m
#define 		pairr 	pair<int,int>p
#define 		sett	set<int>s
#define 		set_it 	set<int>::iterator si
#define 		yes 	cout<<"YES"<<endl
#define 		no 	cout<<"NO"<<endl
#define 		xx 	first
#define 		xy 	second
main()
{
    /// freopen ("in.txt" , "r",  stdin) ;
    string st;
    int n,k,t,temp=0,cnt=0,x,y=0,sum=0;
    cin>>n;
    int a[n-1];
    loopj cin>>a[j];
    sort(a,a+n-1);
    for(int i=1;i<=n;i++)
    {
        for(int j=temp;j<n-1;j++)
        {
            if(i==a[j])
                    cnt++;
                    else
                        break;
            temp++;
        }
        cout<<cnt<<endl;
        cnt=0;
            
    }
}

Measured memory_bytes: 5164
#include<iostream>
using namespace std;
void print(int arr[3][10],int width,int height)
{
	for (int i = 0; i < width; i++)
	{
		for (int j = 0; j < height; j++)
		{
			cout << " " << arr[i][j];
		}
		cout << endl;
	}
}
int main()
{
	int b1[3][10] = { 0 }, b2[3][10] = { 0 }, b3[3][10] = { 0 }, b4[3][10] = { 0 };
	int num;
	int b, f, r, v;
	cin >> num;
	for (int i = 0; i < num; i++)
	{
		cin >> b >> f >> r >> v;
		switch (b)
		{
		case 1:
			b1[f - 1][r - 1] += v;
			break;
		case 2:
			b2[f - 1][r - 1] += v;
			break;
		case 3:
			b3[f - 1][r - 1] += v;
			break;
		case 4:
			b4[f - 1][r - 1] += v;
			break;
		}
	}
	print(b1, 3, 10);
	cout << "####################" << endl;
	print(b2, 3, 10);
	cout << "####################" << endl;
	print(b3, 3, 10);
	cout << "####################" << endl;
	print(b4, 3, 10);
	return 0;
}


Measured memory_bytes: 3112
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val (T, A) = readLine()!!.split(" ").map { it.toInt() }
    val H = readLine()!!.split(" ").map { it.toInt() }

    val a = H.mapIndexed { index, h ->
        val t = T - 0.006 * h
        Pair(index + 1, Math.abs(A - t))
    }.sortedBy { it.second }

    println(a.first().first)
}


Measured memory_bytes: 37752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
//		int[] startFrom = new int[11];
//		int[] endTo = new int[11];
		int startEnd[][] = new int[11][11];
		int startEqualEnd = 0;
		
		for(int i = 1; i <= n; i++) {
			String str = Integer.toString(i);
			
			int left = str.charAt(0) - '0';
			int right = str.charAt(str.length() - 1) - '0';
			
//			startFrom[left]++;
//			endTo[right]++;
			startEnd[left][right]++;
			if(left == right) {
				startEqualEnd++;
			}
		}
		
		long total = 0;
//		for(int i = 1; i <= 9; i++) {
//			//debug
//			System.out.println("i = "+i+" startFrom "+startFrom[i]+" endTo " +endTo[i]);
//			total += startFrom[i] * endTo[i];
//		}
//		System.out.println("startEqualEnd "+startEqualEnd);
		
		for(int i = 1; i <= n; i++) {
			String str = Integer.toString(i);
			
			int left = str.charAt(0) - '0';
			int right = str.charAt(str.length() - 1) - '0';
			
			total += startEnd[right][left];
			
//			System.out.println("i = "+i+" add "+startEnd[right][left]);
		}
//		total -= startEqualEnd;
	
		System.out.println(total);
	}

}


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

int main ()
{
    int n;
    cin >> n;
    ll ara[n];
    for (int i = 0; i<n; i++){
        cin >> ara[i];
    }
    ll x, y;
    x = y = 0;
    sort (ara, ara+n);
    for (int i = n-1; i>0; i--){
        if (ara[i] == ara[i-1]){
            if (x == 0){
                x = ara[i];
                i-=1;
            }
            else if (y == 0){
                y = ara[i];
                i-=1;
            }
        }
        if (x != 0 && y!= 0)
            break;
    }
    if (x == 0 || y == 0){
        cout << 0;
    }
    else
        cout << x*y;
    return 0;
}
//6 3 1 2 4 2 1

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int s = Integer.parseInt(st.nextToken());
		int t = Integer.parseInt(st.nextToken());
		int u = Integer.parseInt(st.nextToken());
		if(u*t>=s){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 32764
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

vector<int> x;
vector<bool> flag;
int N,K,l;



int main()
{
    cin>>N>>K;
    int i=0;
    
    while(cin>>l)
    {
        x.push_back(l);
        
        i++;
        if(i>=N)break;
    }
    int r=K-1;
    int l=0;
    ll mintime=10000000000000;
    while(r<N)
    {
        ll lenrl=abs(x[r])+abs(x[r]-x[l]);
        ll lenlr=abs(x[l])+abs(x[r]-x[l]);

        if(min(lenlr,lenrl)<mintime)mintime=min(lenrl,lenlr);
        l+=1;
        r+=1;
    }
    cout<<mintime<<endl;
}

Measured memory_bytes: 892
N = int(input())
T,A = map(int,input().split())

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

out = 10000000

for i in range(len(H)):
    now = abs( A - (T-(H[i]*0.006)))
    if out > now:
        out = now
        O = i+1

print(O)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <boost/rational.hpp>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int K, T;
  cin >> K >> T;

  vector<int> a(T);
  rep(i, T) { cin >> a[i]; }
  sort(a.begin(), a.end());
  int s = 0;
  rep(i, T - 1) { s += a[i]; }

  cout << max(0, a.back() - 1 - s) << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>

const int kN = 2e5 + 5;
int a[kN];

int main() {
    int k, n;
    scanf("%d%d", &k, &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
    }
    int mx = a[1] + k - a[n];
    for (int i = 2; i <= n; i++) {
        mx = std::max(a[i] - a[i - 1], mx);
    }
    printf("%d\n", k - mx);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
 
 
int main(){
    
  int m;
  cin >>m;
  cout << 24+(24-m) << endl;
}

Measured memory_bytes: 256
const lines=readlines()
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
floatSub(s::SubString{String})=parse(Float64,s)
intLine()=map(intSub,split(input()))
function nextLine()
    x=split(input())
    intSub(x[2]),intSub(x[1])
end
function main()
    n=int(input())
    t=0
    for (b,a)=sort([nextLine() for i=1:n])
        t+=a
        if t>b
            println("No")
            exit()
        end
    end
    println("Yes")
end
main()

Measured memory_bytes: 180864
#include <iostream>

using namespace std;

int main(){
    int W, H, x, y, r;

    cin >> W >> H >> x >> y >> r;

    if((r <= x) && (r <= y)){
        if(((y + r) <= H) && ((x + r) <= W)){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

#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(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 998244353;
const ll LINF = 1e18;

int x[5], k;

int main() {
    REP(i, 5) { cin >> x[i]; }
    cin >> k;
    REP(i, 5)
    FOR(j, i + 1, 5) {
        if(abs(x[i] - x[j]) > k) {
            cout << ":("
                 << "\n";
            return 0;
        }
    }
    cout << "Yay!"
         << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
typedef long long ll;
ll n,ans=0,ok=1;
int main()
{
	scanf("%lld",&n);
	while(n/10)
	{
		ans+=9;
		if(n%10<9)ok=0;
		n/=10;
	}
	ans+=n;
	if(!ok)ans--;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

class Main {

  public static void main(String[] args) {
    final FastScanner scanner = new FastScanner();
    final PrintWriter writer = new PrintWriter(System.out);
    final String val1 = scanner.next();
    final String val2 = scanner.next();
    writer.println(val2 + val1);
    writer.flush();
    writer.close();
  }

  // FastScanner --
  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    public FastScanner() {
    }

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte())
        return buffer[ptr++];
      else
        return -1;
    }

    private boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr]))
        ptr++;
      return hasNextByte();
    }

    public String next() {
      if (!hasNext())
        throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext())
        throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
        throw new NumberFormatException();
      return (int) nl;
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}

Measured memory_bytes: 20052
#include <cstdio>
#include <cctype>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;
	while (isspace(c)) {c = gcu();}
	if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	outl(in() * in());
}


Measured memory_bytes: 2640
def submit():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()

    m = []
    score = 0
    for i in range(n):
        if i - k >= 0:
            rest = m[-k]
        else:
            rest = None
        
        if t[i] == 'r':
            if rest == 'p':
                if i + k >= n:
                    # なんでもよい
                    m.append('r')
                else:
                    if t[i + k] == 's':
                        # k個先がsの場合、ここでrは出したくない
                        m.append('s')
                    else:
                        # k個先がpの場合、ここでsは出したくない
                        # k個先がrの場合、pじゃなければなんでもよい
                        m.append('r')
            else:
                m.append('p')
                score += p

        if t[i] == 'p':
            if rest == 's':
                # k個先を考える
                if i + k >= n:
                    # なんでもよい
                    m.append('r')
                else:
                    if t[i + k] == 'r':
                        # k個先がrの場合、ここでpは出したくない
                        m.append('r')
                    else:
                        # k個先がpの場合、sでなければなんでもよい
                        # k個先がsの場合、ここでrは出したくない
                        m.append('p')
            else:
                m.append('s')
                score += s

        if t[i] == 's':
            if rest == 'r':
                # k個先を考える
                if i + k >= n:
                    # なんでもよい
                    m.append('r')
                else:
                    if t[i + k] == 'r':
                        # k個先がrの場合、ここでpは出したくない
                        m.append('s')
                    else:
                        # k個先がpの場合、ここでsは出したくない
                        # k個先がsの場合、rじゃなければなんでもよい
                        m.append('p')
            else:
                m.append('r')
                score += r
        

    print(score)


if __name__ == "__main__":
    submit()

Measured memory_bytes: 4212
import java.util.Scanner;

// https://atcoder.jp/contests/abc141/tasks/abc141_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine(); //Sの各文字は L, R, U, D
		sc.close();

		int length = S.length();
		boolean flag = true;
		for(int i=1;i<=length;i++) {
			int index = i%2;
			String firstS = S.substring(0,1);

			if(index==1) {
				if(firstS.equals("L")) {
					flag = false;
					break;
				}
			}else if(index==0) {
				if(firstS.equals("R")) {
					flag = false;
					break;
				}
			}
			S = S.substring(1);
		}

		if(flag) {
			System.out.println("Yes");

		}else {
			System.out.println("No");

		}
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N;
    string S;
    cin >> N >> S;
    ll r[N+1], g[N+1], b[N+1];
    r[0] = g[0] = b[0] = 0;
    rep2(i, 1, N){
        r[i] = r[i-1], g[i] = g[i-1], b[i] = b[i-1];
        if(S[i-1] == 'R') r[i]++;
        if(S[i-1] == 'G') g[i]++;
        if(S[i-1] == 'B') b[i]++;
    }
    ll ans = 0;
    rep(j, N){
        rep2(k, j+1, N-1){
            if(S[j] == S[k]) continue;
            if(S[j] != 'R' && S[k] != 'R'){
                ans += r[j];
                if(2*j-k >= 0 && S[2*j-k] == 'R') ans--;
            }
            if(S[j] != 'G' && S[k] != 'G'){
                ans += g[j];
                if(2*j-k >= 0 && S[2*j-k] == 'G') ans--;
            }
            if(S[j] != 'B' && S[k] != 'B'){
                ans += b[j];
                if(2*j-k >= 0 && S[2*j-k] == 'B') ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3712
def main():
    import sys
    from collections import Counter

    input = sys.stdin.readline
    input()
    a = tuple(map(int, input().split()))
    ans = sum(a)
    a = Counter(a)
    for _ in range(int(input())):
        b, c = map(int, input().split())
        if b in a:
            ans += (c - b) * a[b]
            print(ans)
            a[c] = a[c] + a[b] if c in a else a[b]
            del a[b]
        else:
            print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 21216
#include<stdio.h>
#include <stdlib.h>
int main()
{
	int i, x = 0, K;
	scanf("%d", &K);
	if (K % 2 == 0 || K % 5 == 0) {
		printf("-1");
		exit(0);
	}
	for (i = 0; i < 1000000; i++) {
		x = (x * 10 + 7) % K;
		if (x == 0) {
			printf("%d", i+1);
			exit(0);
		}
	}
	printf("-1");
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    ll n;
    cin >> n;
    cout << n * (n - 1) / 2 << endl;

    return 0;
}

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

int n, m;

struct UnionFind {
  vector<int> r;
  UnionFind(int N) {
    r = vector<int>(N, -1);
  }
  
  int root(int x) {
    if (r[x] < 0) return x;
    return r[x] = root(r[x]);
  }
 
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
  
  int size(int x) {
    return -r[root(x)];
  }
};

int main() {
  cin >> n >> m;
  UnionFind UF(n);
  for (int i = 0; i < m; i++) {
    int A, B;
    cin >> A >> B;
    UF.unite(A, B);
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, UF.size(i));
  }
  cout << ans;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "First" << endl;
  exit(0);
}

void no() {
  cout << "Second" << endl;
  exit(0);
}

int main() {
  string s;
  cin >> s;
  ll n = SZ(s);
  bool b1 = n % 2 == 0;
  bool b2 = s[0] == s[n - 1];
  if (b1 == b2) yes();
  no();
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;



int main(){
	ll a,b,n;
	cin>>a>>b>>n;
	ll flag=-inf;
	
	/*for(ll i=1;i<=n;i++){
	
	   flag = max(res-ans,flag);
		
	}
	*/
	if(n < b){
		cout<<(a*n)/b<<endl;
		return 0;
	} 
	else{
		flag = max(a*(b-1)/b,flag);
		
			flag = max(flag,(a*n)/b-a*(n/b));
		
	}
	cout<<flag<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  int n;cin>>n;
  ll a[100005],mx=1e18,ans=1;
  rep(i,n){
	cin>>a[i];
    if(a[i]==0){cout<<0;return 0;}
  }
  rep(i,n){
    if(mx/a[i]<ans){cout<<-1;return 0;}
    ans*=a[i];
    if(ans>mx){cout<<-1;return 0;}
  }
	cout<<ans;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
int n,m,a[13],b[13];
string s[13],ss[13];
void dfs1(int x,bool allow){
	if(x==m) cout<<"YES"<<endl,exit(0);
	else if(b[x]!=-1) dfs1(x+1,allow);
	else{
		for(int i=x+1;i<m;i++){
			if(b[i]!=-1) continue;
			bool ok=true;
			for(int j=0;j<n;j++)
				if(s[j][x]!=s[a[j]][i]){ok=false;break;}
			if(ok)
				b[x]=i,b[i]=x,dfs1(x+1,allow),b[x]=b[i]=-1;
		}
		if(allow) b[x]=x,dfs1(x+1,0),b[x]=-1;
	}
} 
void dfs2(int x,bool allow){
	if(x==n) dfs1(0,(m%2));
	else if(a[x]!=-1) dfs2(x+1,allow);
	else{
		for(int i=x+1;i<n;i++)
			if(ss[i]==ss[x]&&a[i]==-1)
				a[x]=i,a[i]=x,dfs2(x+1,allow),a[x]=a[i]=-1;
		if(allow) a[x]=x,dfs2(x+1,0),a[x]=-1;
	}
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>s[i];
	memset(a,-1,sizeof(a)),memset(b,-1,sizeof(b));
	for(int i=0;i<n;i++)
		ss[i]=s[i],sort(ss[i].begin(),ss[i].end());
	dfs2(0,(n%2));
	cout<<"NO"<<endl;
	return 0;
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> nodeCol(N);
  for (ll i = 0; i < N; i++) cin >> nodeCol.at(i);
  vector<vector<ll>> nbr(N);
  for (ll i = 0; i < N-1; i++) {
    ll a, b; cin >> a >> b; a--; b--;
    nbr.at(a).push_back(b);
    nbr.at(b).push_back(a);
  }
  vector<ll> nPath(N+1);
  vector<stack<ll>> nNode(N+1);
  for (ll col = 1; col <= N; col++) nNode.at(col).push(0);
  auto dfs = [&](const auto& recF, ll n, ll p) -> ll {
    ll col = nodeCol.at(n);
    auto& st = nNode.at(col);
    ll cnt = 1; // self;
    for (ll k : nbr.at(n)) {
      if (k == p) continue;
      st.push(0);
      ll nSub = recF(recF, k, n);
      cnt += nSub;
      ll e = nSub - st.top(); st.pop();
      nPath.at(col) += e * (e+1) / 2;
    }
    st.top() += cnt;
    return cnt;
  };
  dfs(dfs, 0, -1);
  for (ll col = 1; col <= N; col++) {
    ll e = N - nNode.at(col).top();
    nPath.at(col) += e * (e+1) / 2;
    cout << N * (N+1) / 2 - nPath.at(col) << "\n";
  }
  return 0;
}



Measured memory_bytes: 178236
#include <iostream>

std::string f(std::string s) {
    std::string res = "";
    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            res+= s[i];
        }
    }
    return res;
}

int main() {

    std::string s;
    std::cin >> s;

    std::string res = f(s);
    std::cout << res << std::endl;

    return 0;
}


Measured memory_bytes: 704
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    int sum(int k) {
        int s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    int lower_bound(int s) {
        if (s <= 0) return 0;
        int x = 0, w = 1;
        while (w << 1 <= n) w <<= 1;
        do {
            int k = x + w;
            if (k <= n && b[k] < s) {
                s -= b[k];
                x += w;
            }
        } while (w >>= 1);
        return x + 1;
    }
    vector<int> b;
    int n;
};

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

    int n;
    cin >> n;

    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        p--;

        q[p] = i;
    }

    ll r = 0;
    BIT bt(n);
    for (int j = n - 1; j >= 0; j--) {
        int i = q[j];
        int s = bt.sum(i);

        int x[4];
        for (int h = 0; h < 4; h++) {
            x[h] = bt.lower_bound(s + h - 1) - 1;
        }

        r += (ll)j * (x[1] - x[0]) * (x[2] - i);
        r += (ll)j * (x[3] - x[2]) * (i - x[1]);

        bt.add(i, 1);
    }

    r += (ll)n * (n - 1) / 2;
    cout << r << endl;

    return 0;
}

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


void d_m_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input_dp.txt", "r", stdin);
	freopen("output_dp.txt", "w", stdout);
#endif
}

int vacation(int *a, int *b, int *c, int n)
{
	int dp[n + 1][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; i++)
	{
		dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
	}

	return max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}


int32_t main()
{
	d_m_c();

	int n;
	cin >> n;

	int a[n + 1], b[n + 1], c[n + 1];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		cin >> b[i];
		cin >> c[i];
	}

	cout << vacation(a, b, c, n) << endl;

	return 0;
}

Measured memory_bytes: 8276
// C - Forbidden List
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

bool exist(int x, vi &P){
		for(auto p:P) if(x == p) return true;
		return false;
}

int main(){
	int x, n; cin>>x>>n;
	vi P(n); rep(i, n) cin>>P[i];
	rep(d, 100){ // [0,100)
		if(!exist(x-d, P)){
			cout<< x-d <<endl;
			return 0;
		}
		if(!exist(x+d, P)){
			cout<< x+d <<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3576
i,s,S,m,M;main(n){for(;scanf("%d",&n)*n;){M=0;m=500;for(;n--;){S=0;for(i=5;i--;){scanf("%d",&s);S+=s;}S>M?M=S:0;S<m?m=S:0;}printf("%d %d\n",M,m);}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N,Z,W;cin >> N >> Z >> W;
    int A[N];REP(i,N) cin >> A[i];
    if(N == 1){
        cout << abs(A[0] - W) << endl;
        return 0;
    }
    cout << max(abs(A[N-1] - A[N-2]),abs(A[N-1] - W)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    

   int a,k,p,x;
   cin>>a;
   for(int i=0;i<a;i++){
       cin>>k>>p;
       x=k%p;
       if(x==0){
           cout<<p<<endl;
       }
       if(x!=0){
       cout<<x<<endl;
   }
   }
   
}



Measured memory_bytes: 3100
#include<stdio.h>

int main(){
    int x,y,z,n,m;
    scanf("%d%d",&x,&y);
    if(x>=y){
        z=(x%y);
        n=y;
    }
    else if(x<y){
        z=(y%x);
        n=x;
    }
    while(1){
        if(z==0)break;
        m=n%z;
        n=z;
        z=m;
    }
    printf("%d\n",n);
    return 0;
}



Measured memory_bytes: 2144
import java.util.*
import java.math.*
fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val S = sc.next()
    var b = 0
    var w = 0
    for ((i,c) in S.withIndex()) {
        if (i%2 == 0 && c == '0') w++
        if (i%2 == 0 && c == '1') b++
        if (i%2 == 1 && c == '0') b++
        if (i%2 == 1 && c == '1') w++
    }

    println(Math.min(w,b))
}


Measured memory_bytes: 35136