akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string str;
  bool chk = true;
  cin >> str;
  
  // 1つ目
  string revStr = str;
  reverse(revStr.begin(), revStr.end());
  if(str != revStr) chk = false;
  
  // 2つ目
  if(chk==true){
    for(int i = 0; i < (str.size() -1)/2;i++){
      if(str.at(i) != str.at(str.size()-i-1)) chk = false;
      break;
    }
  }
  
  // 3つ目
  if(chk==true){
    int j = (str.size() + 3)/2;
    int k = 0;
     for(; j < str.size(); j++){
       if(str.at(j-1) != str.at(str.size()-k-1)) chk = false;
       k++;
     }
  }
  
  if(chk==true){
   cout << "Yes";
  }else{
    cout << "No";
  } 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int Par[100001],Rank[100001];

void init(int n)
{
	for(int i =0;i<n;i++)
	{
		Par[i]=i;
		Rank[i]= 0;
	}
}
int find(int x)
{
	if(x==Par[x])
	{
		return x;
	}
	return Par[x]=find(Par[x]);
}

void unite(int x,int y)
{
	x = find(x);
	y = find(y);
	if(Rank[x]>Rank[y])
	{
		Par[y]= x;
	}
	else
	{
		Par[x]=y;
		if(Rank[x]==Rank[y])Rank[y]++;
	}
}

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

int main()
{
	int n,m;
	cin >> n >> m;
	vector<int> p(n);
	init(n);
	for(int i = 0;i<n;i++)
	{
		cin >> p[i];	
	}
	while(m--)
	{
		int x,y;
		cin >> x >> y;
		x--;y--;
		unite(x,y);
	}
	int ans = 0;
	for(int i =0;i<n;i++)
	{
		p[i]--;
		if(same(p[i],i))
		{
			///cout<<p[i]<<i<<endl;
			ans++;
		}
		//cout<<find(i)<<endl;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#ABC138-E Strings of Impurity
"""
sの好きなだけのループに対する部分文字列tを求める
tにあってsにない文字がある時点でno
そうでないならば必ず達成可能で、
tに対してループを回し(i)、
sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex
にする。
そのようなindexがないならば、j=0とし、またはじめから回す。
"""
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
t = readline().rstrip().decode('utf-8')
s_s = set(list(s))
t_s = set(list(t))
flag = 1 if s_s & t_s == t_s else 0

if not flag:
    print(-1)
    exit()

#2進数で、
lst1 = [[] for _ in range(26)]
kijun = ord("a")
for idx,i in enumerate(s):
    lst1[ord(i)-kijun].append(idx)

i = 0
roop = 0
count = 0
while True:
    if i >= len(t):
        print(roop*len(s)+count) #countは0-indexedの為
        break
    now = ord(t[i])-kijun
    res = bisect.bisect_left(lst1[now],count)
    if res == len(lst1[now]):
        roop += 1
        count = 0
        res = bisect.bisect_left(lst1[now],count)
        count = lst1[now][res]+1 #その次の文字から
    else:
        count = lst1[now][res]+1
    i += 1
    

Measured memory_bytes: 54512
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define mem0(x) memset(x, 0, sizeof(x))
#define mem1(x) memset(x, -1, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define de(x) cout << #x << " = " << x << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i > b; i--)
#define setI freopen("input.txt", "r", stdin);
#define setIO freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout);
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---------------------------------------------------------//
const int N = 2e5 + 5;

int n;
map<int, int> w;
vi v;

int main()
{
	#ifdef M1saki
//		setI;
	#endif
//	ios::sync_with_stdio(false);
	scanf("%d", &n);
	rep(i, 0, n)
	{
		int x; scanf("%d", &x);
		w[x]++;
	}
	for (auto it = w.begin(); it != w.end(); it++)  rep(i, 0, (it->se) / 2)  v.pb(it->fi);
	if ((int)v.size() < 2)  printf("0\n");
	else
	{
		sort(all(v)); reverse(all(v));
		printf("%lld\n", 1LL * v[0] * v[1]);
	}

	return 0;
}


Measured memory_bytes: 4992
using System;

namespace ABC103A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            c = int.Parse(ss[2]);
            int d = a - b;
            int e = b - c;
            int f = a - c;
            if (d < 0)
                d = d * -1;
            if (e < 0)
                e = e * -1;
            if (f < 0)
                f = f * -1;
            if (d >= e && e >= f || d >= f && f >= e)
                Console.WriteLine(e + f);
            else if (e >= f && f >= d || e >= d && d >= f)
                Console.WriteLine(f + d);
            else
                Console.WriteLine(e + d);
            Console.ReadKey();
            
        }
    }
}


Measured memory_bytes: 13140
import heapq
import itertools

def dijkstra(s):
    inf = pow(10, 10)
    dist = [inf] * (n + 1)
    dist[s] = 0
    c = [0] * (n + 1)
    p = []
    heapq.heapify(p)
    heapq.heappush(p, (dist[s], s))
    while p:
        d, u = heapq.heappop(p)
        if dist[u] < d:
            continue
        c[u] = 1
        for g in G[u]:
            if c[g[0]] == 0 and dist[u] + g[1] < dist[g[0]]:
                dist[g[0]] = dist[u] + g[1]
                heapq.heappush(p, (dist[g[0]], g[0]))
    return dist

n, m, r = map(int, input().split())
t = list(map(int, input().split()))
G = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b, c = map(int, input().split())
    G[a].append([b, c])
    G[b].append([a, c])
D = [[0] * r for _ in range(r)]
for i in range(r):
    d = dijkstra(t[i])
    for j in range(r):
        D[i][j] = d[t[j]]

x = [i for i in range(r)]
ans = pow(10, 10)
for y in itertools.permutations(x):
    dist = 0
    y = list(y)
    for i in range(r - 1):
        dist += D[y[i]][y[i + 1]]
    ans = min(ans, dist)
print(ans)

Measured memory_bytes: 7904
#include<iostream>
#include<queue>
#include<cstring>

using namespace std;

struct node{
  int step,floor,bill;
  node(int s,int f,int b):step(s),floor(f),bill(b){}
  bool operator >(const node &e) const{
    return step> e.step;
  }  
};

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int bill[2][n];
      for(int i=0;i<2;i++)
	for(int j=0;j<n;j++)
	  {
	    cin>>bill[i][j];
	  }
      bool dp[2][n];
      memset(dp,false,sizeof(dp));
      priority_queue<node,vector<node>,greater<node> >P;
      for(int i=0;i<2;i++)
	{
	  int now=0;
	  dp[i][now]=true;
	  while(now+1<n &&bill[i][now]==1&&bill[i][now+1]==1)
	    {	     
	      dp[i][now+1]=true;
	      now++;
	    }
	  P.push(node(0,now,i));
	}
      
      int ans=-1;
      while(!P.empty())
	{
	  node tmp=P.top();
	  P.pop();
	  ///	  cout<<tmp.step<<" "<<tmp.bill<<" "<<tmp.floor<<endl;
	  
	  if(tmp.floor==n-1)
	    {
	      ans=tmp.step;
	      break;
	    }

	  int next;
	  if(tmp.bill==0)
	    next=1;
	  else
	    next=0;
	  
	  for(int i=0;i<3;i++)
	    {

	      int now=tmp.floor+i;
	      bool flag=true;
	      if(dp[next][now])
		continue;
	      dp[next][now]=true;
	      if(bill[next][now]==1)
		{
		  while(now+1<n&&bill[next][now]==1&&bill[next][now+1]==1)
		    {
		      now++;
		      if(dp[next][now])
			{
			  flag=false;
			  break;
			}
		      dp[next][now]=true;
		    }
		}

	      if(bill[next][now]==2)
		{
		  while(now-1 >0 && bill[next][now]==2)
		    {
		      now--;
		      if(dp[next][now])
			{
			  flag=false;
			  break;
			}
		      dp[next][now]=true;
		    }
		}
	      if(flag)	      
		P.push(node(tmp.step+1,now,next));
	    }

	}
      if(ans==-1)
	cout<<"NA"<<endl;
      else
	cout<<ans<<endl;
    }
}

Measured memory_bytes: 1204
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <numeric>
typedef long long ll;
using namespace std;

ll v[100005];
ll s[100005];

int main () {
    ll N;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        cin >> v[i];
    }
    sort(v, v + N);
    s[0] = v[0];
    for(int i = 1; i < N; i++)
    {
        s[i] = s[i - 1] + v[i];
    }
    ll x = 0;
    for(int i = 0; i < N; i++)
    {
        if(2 * s[i] < v[i + 1]) {
            x = i + 1;
        }
    }
    cout << N - x << endl;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
	S := readBigLine()
	T := readBigLine()

	sm := map[rune]int{}
	ss := make([][]int, 26)

	sk := 0
	for i, s := range S {
		if im, ok := sm[s]; !ok {
			sm[s] = sk
			ss[sk] = []int{i}
			sk++
		} else {
			ss[im] = append(ss[im], i)
		}
	}

	tm := map[rune]int{}
	tk := 0
	var si int
	for i, t := range T {
		if _, ok := tm[t]; !ok {
			tm[t] = tk
			tk++
		}
		tmi := tm[t]

		if len(ss[tmi]) <= 0 {
			fmt.Println("No")
			return
		}
		si, ss[tmi] = ss[tmi][0], ss[tmi][1:]

		if si != i {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 7552
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}


int n,k;
int a[200100];
int b[200100]={};

vector<int> ball;

int main(){
	cin>>n>>k;
	REP(i,n){
		cin>>a[i];
		b[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		if(b[i]!=0){
			ball.push_back(b[i]);
		}
	}
	sort(ball.begin(),ball.end());
	int ans=0;
	for(int i=0;i+k<ball.size();i++)
		ans+=ball[i];
	cout<<ans<<endl;
	return 0;
}

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

bool f[10]={};
int cnt(int n){
  int c=0;
  while(n){
    if(f[n%10]) c++;
    n/=10;
  }
  return c;
}

int main(){
  int n,k,d,ans;
  cin>>n>>k;
  fr(i,k){cin>>d;f[d]=1;}
  for(int i=n;1;i++) if(cnt(i)==0){cout<<i<<endl;return 0;}
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

int n,a[200];
int mi=INF;

int check(int b) {
	int cnt=0;
	while (b%2==0) {
		b/=2;cnt++;
		if(cnt>=mi) break;
	}
	return cnt;
}

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

	cin>>n;
	REP(i,n) {
		cin>>a[i];
		mi=min(mi,check(a[i]));
	}
	cout<<mi<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll chk(ll x){
  if( x==0 ) return INF;
  ll ret = 0;
  while(x){
    ret+=x%10;
    x/=10;
  }
  return ret;
}
int main(){
  IOS();
  ll n;
  cin>>n;
  ll ans = INF;
  REP1(i,n) chkmin(ans,chk(i)+chk(n-i));
  cout<<ans<<endl;
}


Measured memory_bytes: 256
/**
    AUTHOR:JUNSH
    TIME:19/5/19
**/
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rev(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll;
inline int read(){
    int f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
const int inf=0x3f3f3f3f;
int main(){
    int n;
    scanf("%d",&n);
    int a=n/100;
    int b=n%100;
    int fa=0,fb=0;
    if(a<=12&&a)fa=1;
    if(b<=12&&b)fb=1;
    if(fa&&fb)cout<<"AMBIGUOUS"<<endl;
    else if(fa)cout<<"MMYY"<<endl;
    else if(fb)cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> s;
	string ans = "Yes";
	if(n%2 != 0){
		ans = "No";
	}
	else{
		rep(i, 0, n/2-1){
			if(s[i] != s[n/2+i]){
				ans = "No";
			}
		}
	}
	print(ans)
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<pair<int64_t,int64_t>> A(N);
  for(int i=0;i<N;++i){
    cin>>A.at(i).second;
    cin>>A.at(i).first;
  }

  sort(A.begin(),A.end());

  int64_t sum=0;
  bool ans=true;
  for(int i=0;i<N;++i){
    sum=sum+A.at(i).second;
    if(A.at(i).first-sum<0){
      ans=false;
      break;
    }
  }

  if(ans){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int dp[3010][3010];
int main() {
    string s, t;
    cin >> s >> t;
    int N = (int)s.size();
    int M = (int)t.size();
    rep(i, N){
        rep(j, M){
            if(s[i] == t[j]){
                chmax(dp[i+1][j+1], dp[i][j] + 1);
            }else{
                chmax(dp[i+1][j+1], dp[i+1][j]);
                chmax(dp[i+1][j+1], dp[i][j+1]);
            }
        }
    }
    string ans = "";
    while (N > 0 && M > 0){
        if(dp[N][M] == dp[N-1][M]){
            --N;
        }else if(dp[N][M] == dp[N][M-1]){
            --M;
        }else{
            --N, --M;
            ans = s[N] + ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  long long n,d[200010],a,i,s=0;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    hin(a);
  }
  for(i=0;i<n;i++)d[i]=N[hout()];
  R=C=1;
  hin(d[0]);
  for(i=1;i<n;i++){
    s+=N[hout()];
    hin(d[i]);
    hin(d[i]);
  }
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 5636
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;
void solve() {
	ll H, W; cin >> H >> W;
	if (H > W)swap(H, W);
	if (H == 1) {
		print(1); return;
	}
	print((H*W + 1) / 2);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = int.Parse(input);

            int a;
            int max = -1;
            int max2 = -1;
            int idx = -1;
            for (int i = 0; i < n; i++)
            {
                input = Console.ReadLine();
                a= int.Parse(input);
                if (a > max)
                {
                    max2 = max;
                    max = a;
                    idx = i;
                }
                else if (a > max2)
                {
                    max2 = a;
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (i == idx)
                {
                    Console.WriteLine(max2.ToString());
                }
                else
                {
                    Console.WriteLine(max.ToString());
                }
            }


        }
    }
}

Measured memory_bytes: 16576
def can(a, b):
  if a > b:
    a, b = b, a
  if b - a <= 1:
    return 2*a-2
  c = int((a*b)**0.5)
  if c**2 == a*b:
    c -= 1
  if c*(c+1) >= a*b:
    return 2*c-2
  return 2*c-1
q = int(input())
for _ in range(q):
  a, b = map(int, input().split())
  print(can(a, b))

Measured memory_bytes: 3064
a,b,c,d=map(int,input())
if a+b-c+d == 7:
        print('%d+%d-%d+%d=7' %(a,b,c,d))
        exit()
elif a+b-c-d == 7:
        print('%d+%d-%d-%d=7' %(a,b,c,d))
        exit()
elif a-b-c+d == 7:
        print('%d-%d-%d+%d=7' %(a,b,c,d))
        exit()
elif a-b-c-d == 7:
        print('%d-%d-%d-%d=7' %(a,b,c,d))
        exit()
elif a+b+c+d ==7:
        print('%d+%d+%d+%d=7' %(a,b,c,d))
        exit()
elif a+b+c-d ==7:
        print('%d+%d+%d-%d=7' %(a,b,c,d))
        exit()
elif a-b+c+d ==7:
        print('%d-%d+%d+%d=7' %(a,b,c,d))
        exit()
elif a-b+c-d ==7:
        print('%d-%d+%d-%d=7' %(a,b,c,d))
        exit()

Measured memory_bytes: 9272
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "\t" << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl << "\t", dump_func(__VA_ARGS__);
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;

VI nums(50, 1);
VI ps(50, 1);
int solve(int n, int x) {
  dump(n, x);
  if (n == 0) {
    assert(x == 0 || x == 1);
    return x;
  }
  if (x <= nums[n - 1] + 1) {
    return solve(n - 1, max(0LL, x - 1));
  } else if (x <= nums[n - 1] + 2) {
    return ps[n - 1] + 1;
  } else {
    return ps[n - 1] + 1 + solve(n - 1, min(nums[n - 1], x - nums[n - 1] - 2));
  }
}
signed main() {
  REP (i, 49) {
    nums[i + 1] = nums[i] * 2 + 3;
    ps[i + 1] = ps[i] * 2 + 1;
  }
  int N, X; cin >> N >> X;
  cout << solve(N, X) << endl;
}


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

using namespace std;

using ll = long long;

struct Bit {
    Bit(int n) : b(n+1) {};
    void upd(int pos, ll val) {
        for (int i = pos; i < (int)b.size(); i += i&-i) {
            b[i] = max(b[i], val);
        }
    }

    ll get(int pos) {
        ll res = 0;
        for (int i = pos; i > 0; i -= i&-i) {
            res = max(res, b[i]);
        }
        return res;
    }
private:
    vector<ll> b;
};

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

    int n;
    cin >> n;

    vector<int> h(n), a(n);
    for (auto& i : h) cin >> i;
    for (auto& i : a) cin >> i;

    Bit bit(n);

    for (int i = 0; i < n; i++) {
        ll x = bit.get(h[i]) + a[i];
        bit.upd(h[i], x);
    }

    cout << bit.get(n) << "\n";
}  



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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset ((a), v, sizeof (a))

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ii> vii;

char S[20];

int main () {
	scanf ("%s", S);
	if (strlen (S) < 4) {
		printf ("No\n");
		return 0;
	}

	if (S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I') printf ("Yes\n");
	else printf ("No\n");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  ll odd[(N/2) + 1];
  ll even[((N+1)/2) + 1];
  odd[0] = 0;
  even[0] = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      even[(i/2) + 1] = even[(i/2)] + A[i];
    } else {
      odd[(i/2) + 1] = odd[(i/2)] + A[i];
    }
  }
  ll ans = -1;
  if (N % 2 == 1) {
    ans = odd[N/2];
    ll min_even = 99999999999;
    ll R[((N-1)/2) + 1];
    ll max_D[((N-1)/2) + 1];
    R[((N-1)/2)] = 0;
    max_D[((N-1)/2)] = 0;
    int cnt = 1;
    for (int i = N-2; i >= 1; i-=2) {
      R[((N-1)/2) - cnt] = A[i+1] - A[i] + R[((N-1)/2) - cnt + 1];
      max_D[((N-1)/2) - cnt] = max(max_D[((N-1)/2) - cnt + 1],R[((N-1)/2) - cnt]);
      cnt++;
    }
    for (int i = 0; i < N; i++) {
      if (i % 2 == 0) {
        min_even = min(min_even,A[i]);
      }
    }
    ans = max(ans,even[(N+1)/2] - min_even);
    for (int i = 1; i <= (N/2) - 1; i++) {
      ans = max({ans,even[i] + odd[N/2] - odd[i] + max_D[i],even[i] + odd[N/2] - odd[i]});
    }
    for (int i = 1; i <= (N/2) - 1; i++) {
      ans = max(ans,odd[i] + even[(N+1)/2] - even[i+1]);
    }
    cout << ans << endl;
  } else {
    ans = max(odd[N/2],even[N/2]);
    for (int i = 1; i <= (N/2) - 1; i++) {
      ll res1 = even[i] + odd[N/2] - odd[i];
      ans = max(ans,res1);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 8232
n = int(input())
l = list(map(int, input().split()))

l.sort()
ans = 0

for i in range(len(l)):
    for j in range(i, len(l)):
        for k in range(j, len(l)):
            if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
                if l[i] + l[j] > l[k]:
                    ans += 1

print(ans)


Measured memory_bytes: 9188
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n)cin >> s[i];
    vector<pair<int,int> > p,q;
    int sm = 0;
    bool flag = 1;
    rep(i,n){
        int c = 0;
        int mi = 0;
        rep(j,s[i].size()){
            if(s[i][j]=='('){
                c++;
                sm++;
            }else{
                c--;
                sm--;
            }
            chmin(mi,c);
            if(mi!=0)flag = 0;
        }
        if(c>0){
            p.push_back(MP(mi,c));
        }else{
            q.push_back(MP(mi,c));
        }
    }
    if(sm!=0){
        cout << "No\n";
        return 0;
    }
    if(flag){
        cout << "Yes\n";
        return 0;
    }
    int d = 0;
    vector<pair<int,int> > r;
    for(auto x:p){
        if(x.first==0){
            d += x.second;
        }else{
            r.push_back(x);
        }
    }
    if(d==0){
        cout << "No\n";
        return 0;
    }
    sort(r.rbegin(),r.rend());
    for(auto x:r){
        if(d+x.first<0){
            cout << "No\n";
            return 0;
        }else{
            d += x.second;
        }
    }
    pair<int,int> las=MP(inf,inf);
    int qid = -1;
    rep(i,q.size()){
        if(q[i].first==q[i].second){
            if(chmin(las,q[i])){
                qid = i;
            }
        }
    }
    if(qid==-1){
        cout << "No\n";
        return 0;
    }
    q.erase(q.begin()+qid);
    int m = q.size();
    vector<pair<int,pair<int,int> > > qq;
    rep(i,m){
        qq.push_back(MP(q[i].first+q[i].second,MP(q[i].first,q[i].second)));
    }
    sort(qq.begin(),qq.end());
    rep(i,m){
        if(d+qq[i].second.first<0){
            cout << "No\n";
            return 0;
        }else{
            d += qq[i].second.second;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 43220
def main
  p0, p1, op_num = gets.split.map(&:to_i)

  op_num.times do |i|
    if i.even?
      # p0 のターン
      p0 -= 1 if p0.odd?
      half = p0 / 2
      p0 -= half
      p1 += half
    else
      # p1 のターン
      p1 -= 1 if p1.odd?
      half = p1 / 2
      p1 -= half
      p0 += half
    end
  end

  puts "#{p0} #{p1}"
end

if __FILE__ == $0
  main
end

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

using namespace std;

int main() {
    long long n, c;
    cin >> n >> c;
    vector<pair<long long, long long> > a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    vector<long long> left(n), right(n);
    long long ans = 0;
    left[0] = a[0].second;
    ans = max(ans, a[0].second - a[0].first);
    for (int i = 1; i < n; i++) {
        left[i] = left[i-1] + a[i].second;
        ans = max(ans, left[i] - a[i].first);
    }
    right[n-1] = a[n-1].second;
    ans = max(ans, a[n-1].second - (c - a[n-1].first));
    for (int i = n-2; i >=0; i--) {
        right[i] = right[i+1]+a[i].second;
        ans = max(ans, right[i] - (c - a[i].first));
    }
    vector<long long> leftm(n), rightm(n);
    leftm[0] = max((long long)0,a[0].second - a[0].first);
    rightm[n-1] = max((long long)0, a[n-1].second - (c - a[n-1].first));
    for (int i = 1; i < n; i++) {
        leftm[i] = max(leftm[i-1], left[i] - a[i].first);
    }
    for (int i = n-2; i >= 0; i--) {
        rightm[i] = max(rightm[i+1], right[i] - (c - a[i].first));
    }
    for (int i = 0 ; i < n-1; i++)  {
        ans = max(ans, left[i] - 2*a[i].first + rightm[i+1]);
    }
    for (int i = 1; i < n; i++) {
        ans = max(ans, right[i] - 2*(c - a[i].first) + leftm[i-1]);
    }
    cout << ans;
}

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

int a, b, h, m;
double x,y;

int main()
{
    cin >> a >> b >> h >> m;
    x = cos(M_PI / 6 * (1.0 / 60 * m + h)) * a - cos(M_PI / 30 * m) * b;
    y = sin(M_PI / 6 * (1.0 / 60 * m + h)) * a - sin(M_PI / 30 * m) * b;
    cout << setprecision(15) << sqrt(x * x + y * y) << endl;
}

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

using namespace std;
 
int main() {
	int a,b;
	cin >> a>>b;
	int c=a+b;
	if(a%3==0 || b%3 ==0 || c%3==0){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int n,ans=0;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
  	cin >> a[i];
    a[i]-=i+1;
  }
  sort(a,a+n);
  long long int mid;
  mid=a[n/2];
 for (int i=0;i<n;i++){
  		ans+=abs(a[i]-mid);
  }
  cout << ans << endl;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  int ans [b-a+1];
  for(int i = 0;i < b-a+1;i++)
    ans[i] = -1;

  int tt = 0;

  int j;
  int count = 0;
  for(int i = a;i <= b;i++){
    string tmp = to_string(i);
    for(j = 0;j < (tmp.length() / 2);j++){
      if(tmp[j] != tmp[tmp.length() - j - 1])
	break;
    }
    if(j >= (tmp.length() / 2)){
      ++count;
      ans[tt++] = i;
    }

  }
  
  cout << count << endl;

//  for(int i = 0;ans[i] != -1;i++){
//    cout << ans[i] << " ";
//  }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll umin(ll a ,ll b)
{
	if(a>b)return b;return a;
}
int main()
{
	ll n;cin >> n;
	if(n==1)
		return cout << 0,0;
	ll a[n];ll b[n];
	for(ll i=0;i<n;i++)
	{
		cin >> a[i];
	}b[0]=0;
	b[1]=abs(a[0]-a[1]);
	for(ll i=2;i<n;i++)
	{
		b[i]=umin(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
	}cout << b[n-1];
	//for(ll i=0;i<n;i++)cout << b[i] << " " ;
	return 0;
}

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

int main(){

	int a,b,d,r;
	double f;

	cin >> a >> b;

	d = a / b;
	r = a % b;
	f = (double)a / (double)b;

	cout << d << " " << r << " ";
	cout << fixed << setprecision(6) << f << endl;

	return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>

int main()
{
	int i, a, b, ab, o;
	char abo[3];

	a = 0;
	b = 0;
	ab = 0;
	o = 0;

	while(scanf("%d,%s", &i, abo) != EOF){
		if(abo[0] == 'A'){
			if(abo[1] == 'B') ab++;
			else a++;
		}
		if(abo[0] == 'B') b++;
		if(abo[0] == 'O') o++;
	}

	printf("%d\n%d\n%d\n%d\n", a, b, ab, o);
	
	return 0;
}

Measured memory_bytes: 592
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n, k, q = map(int, input().split())
    pp = [0] * n
    for _ in range(q):
        a = int(input())
        pp[a - 1] += 1
    for p in pp:
        if k - q + p > 0:
            print("Yes")
        else:
            print("No")

main()


Measured memory_bytes: 4680
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] str = sc.next().split("");

        String result = "Good";
        if (str[0].equals(str[1]) || str[1].equals(str[2]) || str[2].equals(str[3])) {
          	result = "Bad";
        }
        
        System.out.println(result);
    }
}


Measured memory_bytes: 35716
#include <bits/stdc++.h>
#define N 101
using namespace std;

int main(){
  int n;
  cin>>n;
  int A[N],cnt=0;
  for(int i=0;i<n;i++)cin>>A[i];

  for(int i=0;i<n-1;i++){
    int idx = i;
    for(int j=i;j<n;j++)
      if(A[j]<A[idx])idx = j;
    cnt+=i!=idx;
    swap(A[i],A[idx]);
  }

  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<A[i];
  }
  cout<<endl;  
  
  cout<<cnt<<endl;

  return 0;
}

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


long long  INF=1000000000000000000;
using namespace std;

double inver(double x){
return 1/x;
}
int main(){

int N;
cin >> N;

double A[N]={};
double sum=0;
for(int i=0;i<N;i++){
cin>>A[i];
sum+=inver(A[i]);
}

cout<<inver(sum)<<endl;
 return 0;
}

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

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

    string S;
    cin >> S;
    int N = S.size();
    vector<vector<ll> > dp(N + 1, vector<ll>(2, 0));
    dp.at(0).at(0) = S.at(0) - '0';
    dp.at(0).at(1) = S.at(0) - '1';
    for (int i = 1; i < N; ++i) {
        int D = S.at(i) - '0';
        dp.at(i).at(0) = dp.at(i - 1).at(0) + D;
        dp.at(i).at(1) = max(dp.at(i - 1).at(1) + 9, dp.at(i - 1).at(0) + D - 1);
    }
    cout << max(dp.at(N - 1).at(0), dp.at(N - 1).at(1)) << endl;

    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
kl = [[] for i in range(k)]
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        kl[i].append(a[j])
safe = 0
for i in range(1,n+1):
    for j in range(k):
      if i in kl[j]:
        safe += 1
        break
print(n-safe)

Measured memory_bytes: 9196
def process(rows)
  years = []
  rows.each do |(pref, year), i|
    years << year
  end
  years.sort!

  order = years.map.with_index.to_h

  rows.each do |(pref, year), i|
    $ids[i] = "%06d%06d" % [pref, order[year] + 1]
  end
end

$ids = {}
n, m = gets.split.map(&:to_i)
ary = m.times.map { gets.split.map(&:to_i) }.each.with_index.to_a
by_pref = ary.group_by { |(pref, year), i| pref }

by_pref.each_pair do |pref, rows|
  process(rows)
end

m.times do |i|
  puts $ids[i]
end


Measured memory_bytes: 46260
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cstdio>

#define rg register
#define il inline
#define MX (200000 + 233)
#define LL long long

int head[MX] ,tot;
struct edge{
	int node ,next;
}h[MX << 1];
void addedge(int u ,int v ,int flg = true){
	h[++tot] = (edge){v ,head[u]} ,head[u] = tot;
	if(flg) addedge(v ,u ,false);
}

struct node{
	int l ,r;
	LL sum ,add;
	node *lch ,*rch;
}*root;
void pushup(node *x){
	x->sum = 0;
	if(x->lch != nullptr) x->sum += x->lch->sum;
	if(x->rch != nullptr) x->sum += x->rch->sum;
}

void doadd(node *x ,LL v){
	x->sum += (x->r - x->l + 1) * v;
	x->add += v;
}
void pushdown(node *x){
	if(x->add){
		doadd(x->lch ,x->add);
		doadd(x->rch ,x->add);
		x->add = 0;
	}
}

node *newnode(int l ,int r){
	node *x = new node;
	x->l = l ,x->r = r ,x->sum = x->add = 0;
	return x;
}

void spread(node *x){
	int mid = (x->l + x->r) >> 1;
	if(x->lch == nullptr){
		x->lch = newnode(x->l ,mid);
		x->rch = newnode(mid + 1 ,x->r);
	}
}

int query(node *x ,int p){
	if(x->l == x->r) return x->sum;
	spread(x) ,pushdown(x);
	int mid = (x->l + x->r) >> 1;
	if(p <= mid) return query(x->lch ,p);
	return query(x->rch ,p);
}

void cov(node *x ,int p ,int v){
	if(x->l == x->r){x->sum = v; return;}
	spread(x) ,pushdown(x);
	int mid = (x->l + x->r) >> 1;
	if(p <= mid) cov(x->lch ,p ,v);
	else cov(x->rch ,p ,v);
	return pushup(x);
}

node *merge(node *x ,node *y){
	if(x == nullptr)	return y;
	if(y == nullptr)	return x;
	if(x->l == x->r){
		return x->sum += y->sum ,x;
	}
	x->add += y->add;
	x->lch = merge(x->lch ,y->lch);
	x->rch = merge(x->rch ,y->rch);
	return pushup(x) ,x;
}

int n;
LL cnt(LL a){
	return a * (a - 1) / 2 + a;
}
int c[MX]; LL Ans[MX];
node *solve(int x ,int f){
	node *now = newnode(1 ,n);
	for(int i = head[x] ,d ; i ; i = h[i].next){
		if((d = h[i].node) == f) continue;
		merge(now ,solve(d ,x));
		LL qwq = query(now ,c[x]);
		Ans[c[x]] -= cnt(qwq);
		cov(now ,c[x] ,0);
	}
	now->add += 1;
	cov(now ,c[x] ,0);
	return now;
}

int main(){
	scanf("%d" ,&n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" ,c + i);
		Ans[i] = cnt(n);
	}
	for(int i = 1 ,u ,v ; i < n ; ++i){
		scanf("%d%d" ,&u ,&v);
		addedge(u ,v);
	}
	root = solve(1 ,0);
	for(int i = 1 ; i <= n ; ++i){
		Ans[i] -= cnt(query(root ,i));
		printf("%lld\n" ,Ans[i]);
	}
	return 0;
}

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

int main() {
    int K, S;
    cin >> K >> S;
    int ans = 0;
    rep(x,K+1)rep(y,K+1) {
    	int z = S-x-y;
    	if (0 <= z and z <= K) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int M,D;cin>>M>>D;
    int d1,d10,count=0;
    for(int i=1;i<=M;i++){
        for(int j=10;j<=D;j++){
            d1=j%10;d10=j/10;
            if(d1<2 or d10<2)continue;
            else if(d1*d10==i)count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] array = new int[100];
		int num = 0;
		int count = 0;
		int temp;

		// 入力
		num = scan.nextInt();
		for(int i = 0; i < num; i++) {
			array[i] = scan.nextInt();
		}

		// ソート
		for(int i = 0; i < num - 1; i++) {
			for(int j = num - 1; j >= i + 1; j-- ) {
				if(array[j-1] > array[j]) {
					temp = array[j-1];
					array[j-1] = array[j];
					array[j] = temp;
					count++;
				}
			}

		}

		// 出力
		for(int i = 0; i < num; i++) {
			if(i != 0) {
				System.out.print(" ");
			}
			System.out.print(array[i]);
		}
		System.out.println("");
		System.out.println(count);

	}
}


Measured memory_bytes: 26268
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

lint dp[51][5000][51]={};

int main(void){
    lint N,A;
    cin >> N >> A;
    lint x[N];
    rep(i,N) cin >> x[i];
    lint ans=0;
    dp[0][0][0]=1;
    for(int i=0;i<N;i++){
        rep(j,2501) rep(k,N) dp[i+1][j+x[i]][k+1]+=dp[i][j][k],dp[i+1][j][k]+=dp[i][j][k];
    }
    for(int i=1;i<=N;i++) rep(j,2501) if(i*A==j) ans+=dp[N][j][i];
    cout << ans << endl;
}

Measured memory_bytes: 98944
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int h,w,n;
vvc a;

int main(){
	cin>>h>>w>>n;
	a=vvc(h,vc(w));
	vp b(n+1);
	for(int i=0;i<h;i++) for(int j=0;j<w;j++){
		cin>>a[i][j];
		if(a[i][j]=='S') b[0]=P(i,j);
		else if(a[i][j]!='.'&&a[i][j]!='X') b[a[i][j]-'0']=P(i,j);
	}
	int ans=0;
	for(int i=0;i<n;i++){
		vvc c=a;
		queue<pip> q;
		q.push(pip(0,b[i]));
		while(!q.empty()){
			pip p=q.front();
			q.pop();
			P r=p.second;
			bool flag=0;
			for(int j=0;j<4;j++){
				int cx=r.first+dx[j],cy=r.second+dy[j];
				if(cx>=0&&cx<h&&cy>=0&&cy<w&&c[cx][cy]!='X'){
					if(c[cx][cy]==(char)(i+1)+'0'){
						ans+=p.first+1;
						flag=1;
						break;
					}
					c[cx][cy]='X';
					q.push(pip(p.first+1,P(cx,cy)));
				}
			}
			if(flag) break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4796
"""AtCoder"""

X = int(input())

l = []

for i in range(33):
    l.append(i**2)
for i in range(11):
    l.append(i**3)
for i in range(7):
    l.append(i**4)
for i in range(6):
    l.append(i**5)
for i in range(4):
    l.append(i**6)
for i in range(7,10):
    l.append(2**i)

while X not in l:
    X -= 1

print(X)


Measured memory_bytes: 3060
M=998244353
N,*A=open(0)
d=[0]*90001
d[0]=1
e=[0]*90001
e[0]=1
z=1
s=0
for a in A:
	i=s;a=int(a);s+=a;z*=3
	while~i:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1
i=s
while i*2>=s:z=(z-d[i]*3)%M;i-=1
z+=~s%2*e[s//2]*3
print(z%M)

Measured memory_bytes: 142012
#include <bits/stdc++.h>
#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,b,a) for(int i=(b);i>=(a);i--)
#define len(a) int((a).size())
using namespace std;
using LL = long long;
using PII = pair<int, int>;

void bfs(int k) {
    int ans = 50;
    set<PII> Q;
    Q.insert(make_pair(0, 0));
    bitset<100000> Vis[50]; 
    while (!Q.empty()) {
        PII cur = *Q.begin(); Q.erase(Q.begin());
        if (!(cur==make_pair(0, 0))) {
            int sum = cur.first;
            int tmp = cur.second;
            while (tmp) {
                sum += tmp%10;
                tmp /= 10;
            }
            ans = min(ans, sum);
        }
        FI(i,0,9) {
            if (cur.first == 0 && cur.second == 0 && i==0) continue; 
            int add = k*i;
            int sum = cur.second + add;
            PII next = make_pair(cur.first + sum%10, sum/10);
            if (next.first > 45) continue;
            if (Vis[next.first][next.second]) continue;
            Vis[next.first].set(next.second);
            Q.insert(next);
        }
    }
    printf("%d\n", ans);
}

int main() {
    int k;
    scanf("%d", &k);
    bfs(k);
}

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

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<uint> vuint;
typedef vector<ull> vull;
typedef vector<ll> vll;

#define init(type,var) type var;cin>>var;
#define vinit(type,var,n) vector<type> var((uint)n);loop(i,0,n)cin>>var[i];
#define linit(type,var,n) list<type> var;loop(i,0,n){type _v;cin>>_v;var.push_back(_v);}
#define range(container) container.begin(),container.end()
#define loop(i,first,end) for(ull i=(first);i<(end);i++)
#define outl(out) cout<<(out)<<endl;

const ull INF = (ull)(-1LL);

typedef ull aint;

typedef vector<aint> vaint;
typedef list<aint> laint;

int main(void){
	init(aint, n);
	init(string, s);

	size_t index = 0;
	int count = 0;

	while ((index = s.find("ABC", index)) != string::npos){
		index++;
		count++;
	}

	outl(count);

	return 0;
}

Measured memory_bytes: 256
using System;
class Test{
public static void Main(string[] args)
{
   string[] s = Console.ReadLine().Split(' ');
   int a = int.Parse(s[0]);
   int b = int.Parse(s[1]);
   int ans = a-b*2;
   if(ans >= 0) Console.WriteLine("{0}", ans);
   else Console.WriteLine("0");
}
}

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

int main() {
    int n = 3;
    string a = "", b = "";
    char c;
  
    cin >> n;
    for(int i = 0; i < n; i++){
      cin >> c;
      a += c;
    }
    for(int i = 0; i < n; i++){
      cin >> c;
      b += c;
    }
  
    vector<int> v(n);
  	vector<string> r;
    string s;
  
    iota(v.begin(), v.end(), 1);
    do {
      s = "";
      for(auto x : v){
        s += to_string(x);
      }
      r.push_back(s);
    } while( next_permutation(v.begin(), v.end()) );
  
  //b
  auto itr_b = find(r.begin(), r.end(), b);
  size_t index_b = distance( r.begin(), itr_b );

  auto itr_a = find(r.begin(), r.end(), a);
  size_t index_a = distance( r.begin(), itr_a );

  int h = index_b - index_a;
  cout << abs(h) << endl;
}

Measured memory_bytes: 2424