akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;
int N;
long long int a[300030];
long long int sum[300030],sum2[300030];
priority_queue<int,vector<int>,greater<int> > que;
priority_queue<int> que2;
int main(){
  cin >> N;
  for(int i=1;i<=3*N;i++)cin >> a[i];

 
  for(int i=1;i<=N;i++){
    que.push(a[i]);
    sum[i]=sum[i-1]+a[i];
  }
 
  for(int i=N+1;i<=2*N;i++){
    que.push(a[i]);
    long long int x=que.top();
    que.pop();
    sum[i]=sum[i-1]+a[i]-x;
   
  }

   for(int i=3*N;i>2*N;i--){
    que2.push(a[i]);
    sum2[i]=sum2[i+1]+a[i];
  }
   for(int i=2*N;i>N;i--){
     que2.push(a[i]);
     long long int x=que2.top();
     que2.pop();
     sum2[i]=sum2[i+1]+a[i]-x;
   }
   long long int ans=sum[N]-sum2[N+1];
   for(int i=N+1;i<=2*N;i++){
     ans=max(ans,sum[i]-sum2[i+1]);
   }
   cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7416
#include <map>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	map<int, int> k;
	int n;
	int i;
	int d;

	cin >> n;

	for(i = 0; i < n; i++) {
		cin >> d;
		k[d] ++;
	}
	cout << k.size() << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main(){
    int c , r;
    cin >> c >> r;
    map <int ,int> mapper;
    for (int i = 0 ; i < r*2; i++) {
        int d;
        cin >> d;
        mapper[d]++;
    }
    for (int i = 1; i <= c; i++) {
        cout << mapper[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

#include <atcoder/string>

int main() {
	string S;
	cin >> S;
	auto sa = atcoder::suffix_array(S);
	auto lcp = atcoder::lcp_array(S, sa);
	ll ans = (ll)S.size() * (S.size() + 1) / 2;
	for (auto c : lcp) ans -= c;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15624
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>

typedef unsigned long long ULONG;
typedef long long LONG;
using namespace std;

#define PI 3.1415926535897932384626433
#define _DBG_


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

	int len = S.length();

	int count = 0;
	for (int i = 0; i < len; i++) {
		if (S[i] != T[i]) {
			count++;
		}
	}

	cout << count << endl;




	return 0;
}


Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

struct Dice{
    int l[6]; //label

    void in(){
        for(int i = 0; i < 6; i++){
            cin >> l[i];
        }
    }

    void roll(char a){

        if(a == 'S'){
            int sto = l[0];
            l[0] = l[4];
            l[4] = l[5];
            l[5] = l[1];
            l[1] = sto;

        }else if(a == 'N'){
            int sto = l[0];
            l[0] = l[1];
            l[1] = l[5];
            l[5] = l[4];
            l[4] = sto;

        }else if(a == 'E'){
            int sto = l[0];
            l[0] = l[3];
            l[3] = l[5];
            l[5] = l[2];
            l[2] = sto;
        
        }else if(a == 'W'){
            int sto = l[0];
            l[0] = l[2];
            l[2] = l[5];
            l[5] = l[3];
            l[3] = sto;
        }

        return;

    }

};



int main(){
    Dice a;
    a.in();
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        a.roll(s[i]);
    }
    cout << a.l[0] << endl;

}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>

int main()
{
	const int max = 104730;
	std::bitset<max + 1> bitTable;
	
	bitTable.set(0);
	bitTable.set(1);
	
	int loop = sqrt(max);
	
	for (int i = 2; i <= loop; ++i) {
		if (bitTable.test(i) == false) {
			for (int j = i * i; j <= max; j += i) {
				bitTable.set(j);
			}
		}
	}
	
	std::vector<int> spList(10001);
	spList.push_back(0);
	for (int i = 2, j = 1; i <= max; ++i) {
		if (bitTable.test(i) == false) {
			spList.at(j) = i + spList.at(j - 1);
			++j;
		}
	}
	
	int n;
	while (std::cin >> n) {
		if (n == 0 || n > 10000) break;
		
		std::cout << spList.at(n) << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1308
# ABC 151 C - Welcome to AtCoder
# https://atcoder.jp/contests/abc151/tasks/abc151_c

_, m = gets.split.map(&:to_i)
ps_array = Array.new(m) { p, s = gets.split; [p.to_i, s] }

groups = {}

ps_array.each do |ps|
  p, s = ps
  if groups[p]
    groups[p].push(s)
  else
    groups[p] = [s]
  end
end

# puts groups

def process_answers(answers, acs, was)
  if answers.all? { |answer| answer =="WA" }
    return [acs, was]
  elsif answers.all? { |answer| answer =="WA" }
    return [acs + 1, was]
  else
    answers.each do |answer|
      if answer == "WA"
        was += 1
      elsif answer == "AC"
        acs += 1
        return acs, was
      end
    end
  end
end

acs = 0
was = 0

groups.each do |problem, answers|
  acs, was = process_answers(answers, acs, was)
end

puts "#{acs} #{was}"


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main()
{
    int m = 1e9+7;
    string s;
    cin >> s;
    int N = s.size();
    // int dp[N+1][13];
    vector<vector<int>> dp(N+1, vector<int>(13, 0));
    dp[0][0] = 1;
    rep(i, 0, N)
    {
        if (s[i] != '?')
        {
            int j = s[i] - '0';
            // cout << j << endl;
            rep(k, 0, 13)
                dp[i+1][(k*10+j)%13] += dp[i][k] % m;
        }
        else
        {
            rep(j, 0, 10)
                rep(k, 0, 13)
                    dp[i+1][(k*10+j)%13] += dp[i][k] % m;
        }
    }
    cout << dp[N][5] % m;
    return 0;
}

Measured memory_bytes: 16720
#include<cstdio>
#include<algorithm>
long long int abs(long long int n){
	if(n>0)return n;
	else return -n;
}
int main(){
	int n;
	scanf("%d",&n);
	long long int a[n]={};
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(i>0)a[i]+=a[i-1];
	}
	long long int ans=a[n-1];
	for(int i=2;i<n-1;i++){
		long long int pp=0;
		long long int qq=0;
		long long int rr=0;
		long long int ss=0;
		int l=0;
		int r=i-1;
		long long int sum=a[i-1];
		long long int ssum=sum/2;
		while(r-l>1){
			if(a[(r+l)/2]<=ssum)l=(r+l)/2;
			else r=(r+l)/2;
		}
		if(abs(2*a[l]-a[i-1])>abs(2*a[r]-a[i-1]))l=r;
		pp=a[l];
		qq=a[i-1]-a[l];
		
		l=i;
		r=n-1;
		sum=a[n-1]-a[i-1];
		ssum=sum/2;
		while(r-l>1){
			if(a[(r+l)/2]-a[i-1]<=ssum)l=(r+l)/2;
			else r=(r+l)/2;
		}
		if(abs(2*a[l]-a[i-1]-a[n-1])>abs(2*a[r]-a[i-1]-a[n-1]))l=r;
		rr=a[l]-a[i-1];
		ss=a[n-1]-a[l];
		long long int u[4]={};
		u[0]=pp;
		u[1]=qq;
		u[2]=rr;
		u[3]=ss;
		std::sort(u, u+4);
		if(ans>u[3]-u[0])ans=u[3]-u[0];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1664
from itertools import permutations
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(M)]
G = [set() for i in range(N)]

for a, b in ab:
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)

ans = 0
for x in permutations(range(1, N)):
    if x[0] in G[0]:
        for i in range(N-1):
            if i < N-2:
                if x[i+1] in G[x[i]]:
                    continue
                else:
                    break
            else:
                ans += 1
print(ans)


Measured memory_bytes: 3064
import kotlin.math.*

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun <T> MutableList<T>.removeLast() = this.removeAt(this.lastIndex)

const val mod = 1000000007L

fun main() {
	abc000X()
}

fun abc000X() {
	str().split("S").map{it.length}.max().let {println(it)}
}


Measured memory_bytes: 36360
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <ctype.h>
#include <set>
#include <map>
#include <list>

#define MAXN 10000000
using namespace std;



int main()
{
	//freopen("in2.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if(A%2==0 && A==B && B==C)
    {
        printf("-1");
        return 0;
    }
    int output=0;
    int a,b,c;
    while(!(A%2==1 || B%2==1 || C%2==1))
    {
        a=A;
        b=B;
        c=C;
        A=(c+b)/2;
        B=(a+c)/2;
        C=(a+b)/2;
        output++;
    }
    printf("%d",output);

	return	0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int dp[100007][3];

int main(){
  int n,a,b,c;

  cin >> n;

  cin >> a >> b >> c;
  
  dp[0][0]=a;
  dp[0][1]=b;
  dp[0][2]=c;
  
  for(int i=1;i<n;i++){
    cin >> a >> b >> c;
    dp[i][0]=max(dp[i-1][1]+a,dp[i-1][2]+a);
    dp[i][1]=max(dp[i-1][0]+b,dp[i-1][2]+b);
    dp[i][2]=max(dp[i-1][0]+c,dp[i-1][1]+c);
  }
  
  cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define MAXN 100000
#define MAXLOG 10
#define eps 1e-2
#define pii pair<int,int>
#define MP(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))

using namespace std;
void get(int &v)
{
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return ;
}
int get()
{
    int v;
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return v;
}
int a[MAXN+80];
int main()
{
	int n,ans=0,i;
	bool flag;
	get(n);
	for(i=1;i<=n;i++)
		get(a[i]);
	do{
		flag=0;
		for(i=1;i<n;i++)
			if(a[i]==i&&a[i+1]==i+1)
			{
				flag=1;
				swap(a[i],a[i+1]);
				ans++;
			}
		for(i=1;i<=n;i++)
			if(a[i]==i)
			{
				flag=1;
				if(i==1)
					swap(a[i],a[i+1]);
				else if(i==n)
					swap(a[i-1],a[i]);
				else
					swap(a[i],a[i+((rand()&1)?1:-1)]);
				ans++;
			}
	}while(flag);
	printf("%d",ans);
	return 0;
}

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

int main()
{
    ll n, m;
    cin >> n >> m;
    string str[n];

    for (ll i = 0; i < n; i++)
        cin >> str[i];

    bool a[n + 2][m + 2];

    for (ll i = 0; i <= (n + 1); i++)
    {
        for (ll j = 0; j <= (m + 1); j++)
        {
            if (i == 0 || i == (n + 1) || j == 0 || j == (m + 1))
                a[i][j] = 0;
            else
            {
                if (str[i - 1][j - 1] == '.')    a[i][j] = 1;
                else                        a[i][j] = 0;
            }
        }
    }

    priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>>pq;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= m; j++)
        {
            if (a[i][j] == 0 && (a[i + 1][j] == 1 || a[i - 1][j] == 1 || a[i][j + 1] == 1 || a[i][j - 1] == 1))
                pq.push (make_pair (0, make_pair (i, j)));
        }
    }

    ll ans = 0;
    //cout << "yeah\n";

    while (!pq.empty())
    {
        ll dis = pq.top().first;
        ll x = pq.top().second.first;
        ll y = pq.top().second.second;
        pq.pop();
        ans = max (ans, dis);
        //cout << "XY : " << x << " " << y << " " << dis << " \n";

        if (a[x + 1][y] == 1)
            pq.push (make_pair (dis + 1, make_pair (x + 1, y)));

        if (a[x - 1][y] == 1)
            pq.push (make_pair (dis + 1, make_pair (x - 1, y)));

        if (a[x][y + 1] == 1)
            pq.push (make_pair (dis + 1, make_pair (x, y + 1)));

        if (a[x][y - 1] == 1)
            pq.push (make_pair (dis + 1, make_pair (x, y - 1)));

        a[x + 1][y] = 0;
        a[x - 1][y] = 0;
        a[x][y + 1] = 0;
        a[x][y - 1] = 0;
    }

    cout << ans;
    return 0;
}


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

int main() {
	int X, A, B;
	cin >> X >> A >> B;
	if ((B - A) % 2 == 0) cout << "Alice" << endl;
	else cout << "Borys" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#define N 200005
using namespace std;
int rev[N],son[N][2],Q[N],F[N],a[N];
int n,i,x;
void down(int x){
	if (!rev[x]) return;rev[x]=0;
	rev[son[x][0]]^=1;rev[son[x][1]]^=1;
	swap(son[x][0],son[x][1]);
}
void Rotate(int x){
	int y=F[x],z=F[y],w=son[y][0]==x;
	if (son[y][w^1]=son[x][w]) F[son[x][w]]=y;
	if (z) son[z][son[z][1]==y]=x;
	son[x][w]=y;F[y]=x;F[x]=z;//up(y);up(x);
}
void Splay(int x){
	*Q=0;for (int y=x;y;y=F[y]) Q[++*Q]=y;
	for (int i=*Q;i;i--) down(Q[i]);
	while (F[x]){
		int y=F[x],z=F[y];
		if (z) Rotate(((son[z][1]==y)^(son[y][1]==x))?y:x);
		Rotate(x);
	}//up(x);
}

void DFS(int x){
	if (son[x][0]) DFS(son[x][0]);
	printf("%d ",a[x]);
	if (son[x][1]) DFS(son[x][1]);
}
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for (i=2;i<=n;i++){
		for (x=i-1;;){
			down(x);
			if (son[x][1]) x=son[x][1];else break;
		}
		F[son[x][1]=i]=x;Splay(i);
		rev[i]^=1;
	}
	Splay(1);DFS(1);
}

Measured memory_bytes: 8320
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  int n;
  while(cin>>n){
    vector<int> a(n);
    REP(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    int ans = 0;
    REP(i,n)ans += a[i]*(n-i);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0) cout<<"Possible"<<endl;
	else     cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq,copy

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def warshall_floyd(d):
    """Warshall Floyd method"""

    n = len(d)
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

def solve(f):
    n = f.read_int()
    a = [f.read_int_list() for _ in xrange(n)]

    aorg = copy.deepcopy(a)
    warshall_floyd(a)

    for i in xrange(n):
        for j in xrange(n):
            if aorg[i][j] != a[i][j]: return -1

    ans = 0
    for i in xrange(n):
        for j in xrange(n):
            if i == j: continue
            for k in xrange(n):
                if i == k or j == k: continue
                if a[i][j] == a[i][k] + a[k][j]: break
            else:
                ans += a[i][j]

    return ans/2


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 48024
def dijkstra(s):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

Xs,Ys,Xt,Yt = map(int,input().split())
n = int(input())
p = [(Xs,Ys,0),(Xt,Yt,0)]
for i in range(2,n+2):
    p.append(tuple(map(int,input().split())))
cost = [[0]*(n+2)for i in range(n+2)]

for i in range(n+2):
    for j in range(i,n+2):
        cost[i][j] = cost[j][i] =  max(((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)**0.5 - p[i][2] - p[j][2],0)
cost = tuple(cost)
n += 2

res = dijkstra(0)
print(res[1])

Measured memory_bytes: 86256
def get_color_index(rate):
    if 1 <= rate and rate <= 399:
        return 0
    elif 400 <= rate and rate <= 799:
        return 1
    elif 800 <= rate and rate <= 1199:
        return 2
    elif 1200 <= rate and rate <= 1599:
        return 3
    elif 1600 <= rate and rate <= 1999:
        return 4
    elif 2000 <= rate and rate <= 2399:
        return 5
    elif 2400 <= rate and rate <= 2799:
        return 6
    elif 2800 <= rate and rate <= 3199:
        return 7
    else:
        return -1

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

colors = []
wildcard_count = 0

for i in range(N):
    c = get_color_index(a[i])
    if c == -1:
        wildcard_count += 1
    elif c not in colors:
        colors.append(c)

c_min = max(len(colors), 1)
c_max = len(colors) + wildcard_count

print(str(c_min) + ' ' + str(c_max))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second > secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	string S;
	cin >> S;
	if (S[2] == S[3] && S[4] == S[5]) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
import collections

H,W=map(int,input().split())
S=[input() for i in range(H)]
cl=set()
for sy,sx in [[h,w] for h in range(H) for w in range(W)]:
    if S[sy][sx]!="#":
        stack=collections.deque([[sy,sx,0]])
        itta=set([sy*100+sx])
        #print(stack)
        while stack:
            y,x,m=stack.popleft()
            cl.add(m)
            lst=[]

            if y>0:lst.append([-1,0])
            if y<H-1:lst.append([1,0])
            if x>0:lst.append([0,-1])
            if x<W-1:lst.append([0,1])

            for a,b in lst:
                Y=y+a
                X=x+b
                #print(Y,X)
                if S[Y][X]=="." and not Y*100+X in itta:
                    stack.append([Y,X,m+1])
                    itta.add(Y*100+X)
print(max(cl))


Measured memory_bytes: 48092
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }

template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string l;
    cin >> l;

    auto dp = make_v<LL>(l.size()+5, 2);
    dp[0][0] = 1;
    REP(i, l.size())
    {
        if(l[i] == '0')
        {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = (dp[i][1] * 3) % MOD;
        }
        else 
        {
            dp[i+1][0] = dp[i][0] * 2 % MOD;
            dp[i+1][1] = (dp[i][0] + dp[i][1] * 3) % MOD;
        }
        //cout << i+1 << " " <<dp[i+1][0] << " " << dp[i+1][1] << endl;
    }
    cout << (dp[l.size()][0] + dp[l.size()][1]) % MOD << endl;

}

Measured memory_bytes: 5840
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

string s,t;cin>>s>>t;
int n,m,i,j,k;n=s.length();
m=t.length();
int dp[n+1][m+1];
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
{
	for(j=1;j<=m;j++)
	{
		if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
		else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
}
string r="";
i=n;j=m;
while(i>0 && j>0)
{
	if(dp[i][j]>dp[i-1][j] && dp[i][j]>dp[i][j-1])
	{
		r+=s[i-1];
		i--;j--;
	}
	else
	{
		if(dp[i][j]==dp[i-1][j]) i--;
		else j--;
	}
}
reverse(r.begin(),r.end());
cout<<r;
return 0;
}


Measured memory_bytes: 35456
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 200

enum Type{
	MAX,
	MIN,
};

char buf[NUM+5];
int dp[NUM][NUM][2];
int num_count,op_count;
int num_loc[NUM],op_loc[NUM];

bool is_digit(char ch){
	return ch >= '0' && ch <= '9';
}

bool is_op(char ch){
	return ch == '+' || ch == '-';
}


int main(){

	scanf("%s",buf);

	num_count = 0,op_count = 0;
	for(int i = 0; buf[i] != '\0'; i++){
		if(is_digit(buf[i])){
			num_loc[num_count++] = i;
		}else if(is_op(buf[i])){
			op_loc[op_count++] = i;
		}
	}

	for(int left = 0; left < num_count; left++){
		dp[left][left][MAX] = buf[num_loc[left]]-'0';
		dp[left][left][MIN] = buf[num_loc[left]]-'0';
		for(int right = left+1; right < num_count; right++){
			dp[left][right][MAX] = -BIG_NUM;
			dp[left][right][MIN] = BIG_NUM;
		}
	}

	int right,left_left,left_right,right_left,right_right;

	for(int length = 2; length <= num_count; length++){
		for(int left = 0; left+length-1 < num_count; left++){
			right = left+length-1;

			for(int op = left; op < right; op++){
				left_left = left;
				left_right = op;

				right_left = op+1;
				right_right = right;

				if(left_left != left_right && (buf[num_loc[left_left]+1] == ')' || buf[num_loc[left_right]-1] == '('))continue;
				if(right_left != right_right && (buf[num_loc[right_left]+1] == ')' || buf[num_loc[right_right]-1] == '('))continue;

				if(buf[op_loc[op]] == '+'){
					dp[left][right][MAX] = max(dp[left][right][MAX],dp[left_left][left_right][MAX]+dp[right_left][right_right][MAX]);
					dp[left][right][MIN] = min(dp[left][right][MIN],dp[left_left][left_right][MIN]+dp[right_left][right_right][MIN]);
				}else{
					dp[left][right][MAX] = max(dp[left][right][MAX],dp[left_left][left_right][MAX]-dp[right_left][right_right][MIN]);
					dp[left][right][MIN] = min(dp[left][right][MIN],dp[left_left][left_right][MIN]-dp[right_left][right_right][MAX]);
				}
			}
		}
	}

	printf("%d\n",dp[0][num_count-1][MAX]);

	return 0;
}



Measured memory_bytes: 3336
#include<stdio.h>

int second(int x,int y,int z){
	if((x<y&&y<z)||(x>y&&y>z))
		return 1;
	else
		return 0;
}

int main(){
	int n,p[30],ans=0;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(i=0;i<n-2;i++){
		if(second(p[i],p[i+1],p[i+2]))
			ans++;
	}
	printf("%d",ans);
	return 0;
}
			
	
		

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;

int main(){
  int N,M;
  cin >> N >> M;
  vector<ll> h(N);rep(i,N) cin >> h[i];
  vector<ll> A(M) ,B(M);
  Graph G(N);
  vector<bool> tower(N,true);
  rep(i,M){
      cin >> A[i] >> B[i];
      A[i]--,B[i]--;
      G[A[i]].push_back(B[i]);
      G[B[i]].push_back(A[i]);
  }
  rep(i,N){
      ll H = h[i];
      for(auto v:G[i]){
          if(H <= h[v]) tower[i] = false;
      }
  }
  ll res = 0;
  rep(i,N) if(tower[i]) res++;
  cout << res << endl;
}


Measured memory_bytes: 11384
N, A, B = map(int, input().split())
vs = list(map(int, input().split()))
vs.sort(reverse=True)
#print(vs)
r = sum(vs[:A])/A
print(r)
vA = vs[A-1]
I = vs.index(vA)
C = vs.count(vA)
#print(I, C)
if I != 0:
  # C_{C}_{A-I}
  r = 1
  for i in range(1, A-I+1):
    r = r*(C-i+1)//i
  print(r)
else:
  rs = []
  for n in range(A, B+1):
    # C_{C}_{N-I}
    if n-I < 0 or n-I > C:
      continue
    r = 1
    for i in range(1, n-I+1):
      r = r*(C-i+1)//i
    #print(C, n-I, r)
    rs.append(r)
  #print(rs)
  r = sum(rs)
  print(r)


Measured memory_bytes: 3064
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

// const int INF = 2e9;
const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
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;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL n;
  cin >> n;
  VLL A(n+1);
  REP(int, i, n) cin >> A[i+1];
  A[0] = INF;
  VLL dp(n+1, 1000);
  REP2(int, i, 1, n+1)
  {
    chmax(dp[i], dp[i-1]);
    REP(int, j, i) chmax(dp[i], (dp[j]/A[j])*A[i] + dp[j] % A[j]);
  }
  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;

const int N_MAX = 1005;
int A[N_MAX][N_MAX];
int now[N_MAX];
bool todayend[N_MAX];

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < n-1; j++)cin >> A[i][j];
    }

    bool done = true;
    bool allfinished;
    int day = 0;
    memset(now, 0, sizeof(now));
    while(done){
        day++;
        allfinished = true;
        done = false;
        memset(todayend, false, sizeof(todayend));

        for(int i = 1; i <= n; i++){
            if (now[i] == n-1)continue;
            allfinished = false;

            if (A[i][now[i]] < i && !todayend[i]){
                int target = A[i][now[i]];
                if (A[target][now[target]] == i && !todayend[target]){
                    now[i]++;
                    now[target]++;
                    todayend[i] = true;
                    todayend[target] = true;
                    done = true;
                }
            }
        }
    }
    if (allfinished)cout << day-1 << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 7088
import itertools
import numpy as np
import copy

num = list(map(int,input().split()))
plase = []
count = 0

for i in range(num[0]):
    num_list = list(map(int,input().split()))
    plase.append(num_list)

result = list(itertools.combinations(plase, 2))

for i,j in result:
    s=0
    for k in range(num[1]):
        s += (i[k]-j[k])**2
    s_2=copy.deepcopy(int(np.sqrt(s)))
    if np.sqrt(s) == s_2:
        count+=1
        
print(count)


Measured memory_bytes: 21248
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U> //T::位置 U::探す対象
class Binary_search{
private:
    T l;
    T r;
    inline bool break_condition(T,T,U); //true::break false::continue
    inline bool judge(T,U); //true::smaller false::bigger
public:
    Binary_search(T l,T r):l(l),r(r){}
    
    pair<T,T> search(U u){
        T ld=l;
        T rd=r;
        while(!break_condition(ld,rd,u)){
            T mid=(rd-ld)/2+ld;
            if(mid==ld){break;}
            if(judge(mid,u)){rd=mid;}
            else{ld=mid;}
        }
        return {ld,rd};
    }
};

vector<ll> s;

int main(){
    ll n;
    cin>>n;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        s.push_back(b);
    }
    Binary_search<ll,ll> bs(0,s.size()-1);
    ll q;
    cin>>q;
    ll count=0;
    for(int i=0;i<q;i++){
        ll b;
        cin>>b;
        pll w=bs.search(b);
        for(ll i=w.F;i<=w.S;i++){
            if(s[i]==b){count++; break;}
        }
    }
    cout<<count<<endl;
    
    
    return 0;
}

template<typename T,typename U>
inline bool Binary_search<T,U>::judge(T where,U u){
    if(s[where]<u){return false;}
    return true;
}

template<typename T,typename U>
inline bool Binary_search<T,U>::break_condition(T l,T r,U u){
    if((r-l)/2==0){return true;}
    return false;
}



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

int main()
{
	int n;
    cin>>n;
    
    int arr[n];
    int cnt[n]={0};
    for(int i=1;i<n;i++)
    {
        cin>>arr[i];
        cnt[arr[i]-1]++;
    }
    for(int i=0;i<n;i++)
    {
        cout<<cnt[i]<<endl;
    }
    
	return 0;
}

Measured memory_bytes: 5164
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R

long long int power(long long int x, long long int n, long long int M, long long int d) {
	long long int tmp = d;

	while (n) {
		if (n & 1) {
			tmp *= x;
			tmp %= M;
		}
		x *= x;
		x %= M;
		n /= 2;
	}
	return tmp;
}


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

	long long int n, q, k, d;
	cin >> n >> q >> k >> d;
	k--;
	d--;
	long long int LMOD = d;
	for (int i = 0; i < q; i++) {
		LMOD *= 2;
		LMOD %= n;
	}
	if (q < 55) {
		if (n > 1LL << q) {
			//long long int LMOD = d;
			long long int RMOD = LMOD + (1LL << q) - 1;
			//cout << LMOD << " " << k << " " << RMOD << endl;
			if (!((LMOD <= k && k <= RMOD) || (LMOD <= k + n && k + n <= RMOD))) {
				cout << -1 << endl;
				return 0;
			}

		}
	}
	//cout << bitset<15>(k - LMOD) << endl;
	long long int box = (k - LMOD + n) % n;
	vector<long long int>ans, tapi({ d });
	for (int i = 0; i < q; i++) {
		//if (d >= N / 2) {
		//}
		//else {

		//}
		d *= 2;
		d += q - 1 - i > 63 ? 0 : ((box >> q - 1 - i) & 1);
		d %= n;
		tapi.push_back(d);
		///cout << d << endl;
		//box /= 2;
	}
//	cout << d << " " << k << endl;
	assert(d == k);
	reverse(tapi.begin(), tapi.end());
	for (int i = 0; i < q; ++i) {
		ans.push_back((tapi[i] & 1) ^ (tapi[i + 1] >= n / 2));
	}
	for (auto i : ans)cout << i << endl;
}


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

using namespace std;

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

	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if(i % 2 == 0 && a[i] % 2 == 1) {
			ans += 1;
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
int ac = 0;
int wa = 0;
int tle = 0;
int re = 0;
cin >> n;
for(int i = 0;i < n;i++){
    string buf;
    cin >> buf;
    if(buf == "AC"){
        ac ++;
    }else if(buf == "WA"){
        wa ++;
    }else if(buf == "TLE"){
        tle ++;
    }else if(buf =="RE"){
        re ++;
    }
}
cout << "AC" << " x " << ac << endl;
cout << "WA" << " x " << wa << endl;
cout << "TLE" << " x " << tle << endl;
cout << "RE" << " x " << re << endl;
return 0;
}

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

int main(){
    string s;
    cin >> s;
    long long int k;
    cin >> k;
    int ans;
    for(int i = 0; i < s.length(); i++){
        if(s[i] != '1'){
            ans = s[i]-'0';
            break;
        }else if(i == k-1){
            ans = 1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstring>
#include<fstream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int tot,head[MAXN];
LL dist[MAXN];
bool vis[MAXN];

struct Edge
{
    int from,to,nxt;
    LL cost;
}e[MAXN*2];

void addedge(int u,int v,int w)
{
    e[tot].from=u;
    e[tot].to=v;
    e[tot].cost=w;
    e[tot].nxt=head[u];
    head[u]=tot++;
}

void dfs(int u,int fa)
{
    for(int i=head[u];i!=-1;i=e[i].nxt)
    {
        int to=e[i].to;
        if(to==fa) continue;
        dist[to]=dist[u]+e[i].cost;
        dfs(to,u);
    }
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        tot=0;
        memset(head,-1,sizeof(head));
        memset(dist,0,sizeof(dist));
        int u,v;
        LL w;
        for(int i=1;i<=n-1;i++)
        {
            scanf("%d%d%lld",&u,&v,&w);
            addedge(u,v,w);
            addedge(v,u,w);
        }
        int q,k;
        scanf("%d%d",&q,&k);
        dfs(k,-1);
//        for(int i=1;i<=n;i++)
//            cout<<dist[i]<<" ";
//        cout<<endl;
        int x,y;
        for(int i=1;i<=q;i++)
        {
            scanf("%d%d",&x,&y);
            printf("%lld\n",dist[x]+dist[y]);
        }
    }
    return 0;
}


Measured memory_bytes: 12288
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.split.map{|v| v.to_i }
end

N = attrs.shift
mounts = attrs[0]

result = 1
max = mounts.shift

mounts.each do |m|
  if max <= m then
    max = m
    result += 1
  end
end
  
puts result

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int n;
void solve() {
    cin >> n;

    cout << (n - 1) / 2 << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


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

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

    int ans = 0;

    int mustup = -1;
    for (int i = 0; i < n - 1; i++) {
        if (mustup == -1) {
            if (a[i] > a[i + 1]) {
                mustup = 0;
            }
            else if (a[i] < a[i + 1]) {
                mustup = 1;
            }
        }
        else {
            if (mustup == 1 && a[i + 1] < a[i]) {
                ans++;
                mustup = -1;
            }
            else if (mustup == 0 && a[i + 1] > a[i]) {
                ans++;
                mustup = -1;
            }
        }
    }

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

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

int main(){
    while(true){
        int n,sum=0,cnt=0;
        cin>>n;
        if(n==0){
            return 0;
        }
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum += a[i];
        }
        for(int i=0;i<n;i++){
            if(a[i]<=sum/n){
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3112
import itertools, math

N = int(input())

ACGTList = ["A", "G", "C", "T"]
AGCList = ["ATGC", "AGTC", "AGGC"]
for ACGT in ACGTList:
    for AGC in ["AGC", "ACG", "GAC"]:
        AGCList.append(ACGT + AGC)
        AGCList.append(AGC + ACGT)

patternObj = itertools.product(ACGTList, repeat=3)
patternDict = {}
for i, pattern in enumerate(patternObj):
    strPattern = "".join(pattern)
    patternDict[strPattern] = 0 if strPattern in ["AGC", "ACG", "GAC"] else 1

for i in range(N - 3):
    nextPatternDict = dict.fromkeys(patternDict, 0)
    for pattern in patternDict:
        for ACGT in ACGTList:
            newPattern = pattern + ACGT
            if newPattern in AGCList:
                continue
            nextPatternDict[newPattern[1:]] += patternDict[newPattern[:3]]
    patternDict = nextPatternDict.copy()

ans = 0
devide = int(math.pow(10, 9)) + 7
for pattern in patternDict:
    ans += patternDict[pattern]
    ans %= devide

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<ll> X(N),t;
    rep(i,N) cin >> X[i];
    t = X;
    sort(ALL(t));
    ll ans = t[(N/2) - 1];
    rep(i,N){
        // i 番目の数を除いた数列の中央値
        if(X[i]>ans)cout << ans << endl;
        else cout << t[(N/2)] << endl;
    }
}

Measured memory_bytes: 5376
#include<cstdio>
#include<iostream>

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

using namespace std;

long long depth[MAX],L[MAX],R[MAX],N,noSaveDp[MAX],saveDp[MAX],leaf[MAX];

int main(){
  register int i = 0;
  scanf("%d",&N);
  depth[0] = leaf[N-1] = 1;
  rep(i,N-1){
    scanf("%d %d",&L[i],&R[i]);
    depth[--L[i]] = depth[--R[i]] = depth[i] + 1;
  }

  for(i = N-2;i>=0;i--){
    leaf[i] = leaf[L[i]] + leaf[R[i]];
    saveDp[i] = noSaveDp[i] = noSaveDp[L[i]] + noSaveDp[R[i]] + leaf[L[i]] + leaf[R[i]];
    saveDp[i] = min(saveDp[i],
		    min(noSaveDp[L[i]]+leaf[L[i]]+1+saveDp[R[i]],
			noSaveDp[R[i]]+leaf[R[i]]+1+saveDp[L[i]]));
    saveDp[i] = min(saveDp[i],
		    saveDp[L[i]]+1+depth[i]-1+1+saveDp[R[i]]);
  }
  printf("%d\n",saveDp[0]);
  return 0;
}

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

int main() {
  
  ll n, a, b;
  cin >> n >> a >> b;
  ll sum = 0;
  ll bipa = 0;
  
  sum += n / (a + b) * a;
  bipa += n % (a + b);
  sum += min(a, bipa);
  
  cout << sum << endl;  

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int l = 0, r = 0;
    int x = a[0], s = a[0];
    ll ans = 0;
    while (r < n) {
        if (x == s) {
            ans += (r - l + 1);
            r++;
            if (r < n) {
                x ^= a[r];
                s += a[r];
            }
        }
        else {
            x ^= a[l];
            s -= a[l];
            l++;
        }
    }
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    int n;cin >> n;
    ll ans=0;
    for(int i = 1; i <= n; i++) {
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	if (x - r >= 0 && x + r <= W&&y - r >= 0 && y + r <= H){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3104
x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
    print(x)
else:
    for i in range(100):
        yr = x+i
        yl = x-i
        if yl not in p:
            print(yl)
            break
        elif yr not in p:
            print(yr)
            break

Measured memory_bytes: 9188