akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl

#define pb emplace_back
#define fi first
#define se second
     
using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;
int a[100010];

int main(){

  n = in();
  REP( i , n ){
    a[i] = in();
  }

  sort( a , a+n );
  reverse( a , a+n );

  int p = 0, q = 1;
  while( p < n and q <= a[p] ){
    p++; q++;
  }
  p--; q--;

  int y = ( a[p] - q ) % 2;

  int x = p + 1;

  while( x < n and a[x] == q ){
    x++;
  }
  x--;

  x = ( x - p ) % 2;

  if( x == 1 or y == 1 ){
    puts( "First" );
  } else {
    puts( "Second" );
  }

  return 0;
}


Measured memory_bytes: 640
n = int(input())
b = list(map(int, input().split()))

a_list = []

a_list.append(b[0])

for i in range(n-2):
    if b[i] > b[i+1]:
        a_list.append(b[i+1])
    elif b[i] == b[i+1]:
        a_list.append(a_list[-1])
    elif b[i] < b[i+1]:
        a_list.append(b[i])
a_list.append(b[-1])
print(sum(a_list))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int n,p[200005],pos[200005],fi,se;
int st[200005][20][2],lg[200005];
struct node{
	int x,y,l,r;
}a;
struct cmp{bool operator()(node u,node v){return u.x>v.x;}};
priority_queue<node,vector<node>,cmp> q;

int read(){
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x;
}

void print(int x){
	if(x>=10) print(x/10);
	putchar(x%10+'0');
}

int query(int x,int y){
	int len=y-x+1;len=lg[len];
	return min(st[x][len][x%2],st[y-(1<<len)+1][len][x%2]);
}

int main(){
	n=read();
	for(int i=1;i<=n;i++){
		p[i]=read(),pos[p[i]]=i;
		st[i][0][i%2]=p[i],st[i][0][(i%2)^1]=n+1;
	}
	lg[1]=0;for(int i=2;i<=n;i++) lg[i]=lg[i/2]+1;
	for(int j=1;j<=19;j++){
		for(int i=1;i<=n-(1<<j)+1;i++){
			st[i][j][0]=min(st[i][j-1][0],st[i+(1<<(j-1))][j-1][0]);
			st[i][j][1]=min(st[i][j-1][1],st[i+(1<<(j-1))][j-1][1]);
		}
	}
	fi=query(1,n);se=query(pos[fi]+1,n);
	q.push((node){fi,se,1,n});
	while(!q.empty()){
		a=q.top();q.pop();
		print(a.x),putchar(' '),print(a.y),putchar(' ');
		if(a.l<pos[a.x]-1){
			fi=query(a.l,pos[a.x]-1),se=query(pos[fi]+1,pos[a.x]-1);
			q.push((node){fi,se,a.l,pos[a.x]-1});
		}
		if(pos[a.x]+1<pos[a.y]-1){
			fi=query(pos[a.x]+1,pos[a.y]-1),se=query(pos[fi]+1,pos[a.y]-1);
			q.push((node){fi,se,pos[a.x]+1,pos[a.y]-1});
		}
		if(pos[a.y]+1<a.r){
			fi=query(pos[a.y]+1,a.r),se=query(pos[fi]+1,a.r);
			q.push((node){fi,se,pos[a.y]+1,a.r});
		}
	}
	puts("");

	return 0;
}

Measured memory_bytes: 35828
from math import gcd
n, x = map(int, input().split())
ls = sorted(list(map(int, input().split())))
if x == 1:
    print(abs(x-ls[0]))
    exit()
distant = []
for i in range(n):
    diff = abs(ls[i]-x)
    distant.append(diff)
distant.sort()
a = distant[0]
for i in distant:
    g = gcd(a, i)
    a = g
print(g) 


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

typedef long long lint;

using namespace std;

lint n;

vector<int> opr;
deque<int> ans;

int main() {
    scanf("%lld", &n);
    while (n) {
        if (n & 1) {
            n = (n - 1) >> 1;
            opr.push_back(1);
            continue;
        }
        --n;
        opr.push_back(0);
    }
    reverse(opr.begin(), opr.end());
    for (int i = 0; i < (int)opr.size(); ++i)
        if (!opr[i])
            ans.push_front(i + 1);
        else
            ans.push_back(i + 1);
    for (int i = 0; i < (int)opr.size(); ++i)
        ans.push_back(i + 1);
    printf("%d\n", (int)ans.size());
    for (int i = 0; i < (int)ans.size(); ++i)
        printf("%d ", ans[i]);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int H[] = new int[N];
		long answer = 0;

		for (int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
		}

		Arrays.sort(H);

		for (int i = N - 1 - K; 0 <= i; i--) {
			answer += H[i];
		}

		System.out.println(answer);
	}
}

Measured memory_bytes: 64364
#include <iostream>
using namespace std; //头文件和命名空间
int main(){
    ios::sync_with_stdio(false); //输入输出加速
    int iTotal,iPriceA,iPriceB; //总钱数和两样东西的价格
    cin >> iTotal >> iPriceA >> iPriceB; //读入数据
    iTotal -= iPriceA; //购买一个蛋糕，从所持有的钱中减去蛋糕的单
    iTotal %= iPriceB; //尽可能多地购买油炸圈饼，剩下的钱就是买完蛋糕之后余下的钱对油炸圈饼单价取模
    cout << iTotal << endl; //输出
    return 0; //结束
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (long long i = 0; i < (long long) (n); ++i)
#define pb emplace_back
#define endl '\n'

template<typename T> void _dbg(const char*_s,T _h) { cerr<<_s<<" = "<<_h<<"\n"; }

template<typename T, typename... Ts> void _dbg(const char*_s,T _h,Ts... _t) {
    for(int _b=0;((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',';)cerr<<*_s++;
    cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);
}

#define int long long

#ifdef LOCAL
    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
    #define dbg(...)
#endif

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, A, B;
const int K = 41;
int a[N], b[N], c[N];
int dp[K][10 * K][10 * K];

bool read() {
    if (!(cin >> n >> A >> B))
        return false;

    forn (i, n) cin >> a[i] >> b[i] >> c[i];

    return true;
}

void solve(int id = 0) {
    forn (i, n + 1)
        forn (j, 10 * K)
            forn (k, 10 * K)
                dp[i][j][k] = MOD;

    dp[0][0][0] = 0;

    forn (i, n)
        forn (a1, 10 * K)
            forn (b1, 10 * K) {
                dp[i + 1][a1][b1] = min(dp[i + 1][a1][b1], dp[i][a1][b1]);

                if (a1 + a[i] < 10 * K && b1 + b[i] < 10 * K)
                    dp[i + 1][a1 + a[i]][b1 + b[i]] = min(dp[i + 1][a1 + a[i]][b1 + b[i]],
                            dp[i][a1][b1] + c[i]);
            }

    int ans = MOD;

    for (int k = 1; A * k < 10 * K && B * k < 10 * K; ++k)
        ans = min(ans, dp[n][k * A][k * B]);

    cout << (ans == MOD ? -1 : ans) << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    //cin >> T;
    T = 1;

    while (read())
        solve(T++);

    return 0;
}



Measured memory_bytes: 59648
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int> p;
vector<vector<p> > edge(100010);
bool used[100010];
long dist[100010],Q,K,x,y,INF=999999999999999999;
int a,b,c,N;

void dijkstra(int s){
  priority_queue<p, vector<p>, greater<p> > que;
  fill(dist,dist+100010,INF);
  dist[s]=0;
  que.push(p(0,s));
  while(!que.empty()){
    p ptop = que.top();
    que.pop();
    int v=ptop.second;
    if(dist[v]<ptop.first) continue;
    for(int i=0;i<edge[v].size();i++){
      p pedge=edge[v][i];
      if(dist[pedge.first]>dist[v]+pedge.second){
        dist[pedge.first]=dist[v]+pedge.second;
        que.push(p(dist[pedge.first],pedge.first));
      }
    }
  }
}

int main(){
  cin>>N;
  for(int i=0;i<N-1;i++){
    cin>>a>>b>>c;
    edge[a].push_back(p(b,c));
    edge[b].push_back(p(a,c));
  }
  cin>>Q>>K;
  dijkstra(K);
  for(int i=0;i<Q;i++){
    cin>>x>>y;
    cout<<dist[x]+dist[y]<<endl;
  }
  return 0;
}


Measured memory_bytes: 8820
foods=[]

for _ in range(5):
    foods.append(int(input()))

from itertools import permutations

l = [0,1,2,3,4]

p = permutations(l,5)

time=pow(10,9)
for v in p:
    order = v

    tmp_time=0

    for i in range(5):

        tmp_time+=foods[order[i]]

        if tmp_time%10!=0 and i<4:

            tmp_time = ((tmp_time//10)+1) * 10

    
    time= min(time,tmp_time)

print(time)

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

using namespace std;

typedef long long int lli;

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

    int n;
    cin >> n;
    vector<string> s(n);

    for (int i=0; i<n; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

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

    lli ans = 0, cont = 1;
    string crnt = s[0];
    for (int i=1; i<n; i++) {
        if (s[i] == crnt) cont++;
        else {
            ans += (cont*(cont-1)) / 2;
            cont = 1;
            crnt = s[i];
        }
    }
    ans += (cont*(cont-1)) / 2;

    cout << ans << endl;

    return 0;
}


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


void solve(long long N, std::vector<long long> L){
    sort(L.begin(), L.end());
    long long res = 0;
    for(int i = 0; i < N; ++i){
        for(int j = i+1; j < N; ++j){
            int k = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
            res += max(k - (j+1), 0);
        }
    }
    cout << res << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 3680
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long N = sc.nextLong();

		sc.close();

		long ans = Long.MAX_VALUE;

		for(long i = 1;i<=Math.sqrt(N);i++) {
			if(N%i == 0) {
				ans = Math.min(ans, (i-1)+(N/i-1));
			}
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


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

using namespace std;
using ll = long long;
const int N = 110;
ll dp[N][5][2];
int n;
string num;

ll rec(int pos, int k, int tight) {
  if(k < 0) return 0;
  if(pos == n) return (k == 0);
  if(dp[pos][k][tight] != -1) return dp[pos][k][tight];
  int h = (num[pos] - '0');
  ll res = 0;
  for(int i = 0; i < 10; ++i) {
    if(tight && i > h) break;
    res += rec(pos + 1, k - (i != 0), tight && (i == h));
  }
  return dp[pos][k][tight] = res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> num;
  n = (int) num.length();
  int k; cin >> k;
  memset(dp, -1, sizeof dp);
  cout << rec(0, k, 1) << '\n';
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans1 = A[-1]
ans2 = -1
for i in range(0, N-1):
	if abs(A[i]-ans1/2) < abs(ans2-ans1/2):
		ans2 = A[i]
print(str(ans1) + ' ' + str(ans2))

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

int main(){
	int u, q, v = 0, g = 0, cnt = 0;
	char c;

	while ( cin >> u >> c >> q ){
		v += u * q;
		g += q;
		++cnt;
	}

	g = static_cast< int >( static_cast< double >( g ) / cnt + 0.5 );

	cout << v << endl << g << endl;

	return 0;
}

Measured memory_bytes: 0
# -*- coding:utf-8 -*-

def solve():
    R, G, B, N = list(map(int, input().split()))

    # r, g, bのそれぞれに関してforで回すとO(N**3)で間に合わないので、
    # rを固定する。するとO(N**2)で解ける
    ans = 0
    for g in range(N+1):
        if g*G > N: break
        for b in range(N+1):
            if g*G+b*B > N: break
            if (N - (g*G+b*B))%R == 0:
                ans += 1
    print(ans)


if __name__ == "__main__":
    solve()


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

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

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i ++) {
    if (i * i > n) {
      cout << (i - 1) * (i - 1) << endl;
      break;
    }
  }
}


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

const int MAX_N = 300005;
const int INF = 0x3f3f3f3f;
int cum[MAX_N]; //number of E

signed main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;

	cum[0] = 0;
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'E') {
			cum[i+1] = cum[i] + 1;
		} else {
			cum[i+1] = cum[i];
		}
	}
	int mn = INF;
	for (int i = 0; i < N; ++i) {
		int turn = 0;
		turn += i-cum[i];
		turn += cum[N]-cum[i+1];
		mn = min(mn, turn);
	}
	cout << mn << endl;
}


Measured memory_bytes: 1796
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt(), tmp = n, sum = 0;
		while(tmp > 0) {
			sum += tmp % 10;
			tmp /= 10;
		}
		if(n % sum == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22100
s = input()

if s[0] == s[1] and s[2] == s[3] and s[0] != s[2]:
    print('Yes')
elif s[0] == s[2] and s[1] == s[3] and s[0] != s[1]:
    print('Yes')
elif s[0] == s[3] and s[1] == s[2] and s[0] != s[1]:
    print('Yes')
else:
    print('No')           

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,m; cin >> n >> m;
  vector<int> v(n); cin >> v;
  int sum = 0;
  for(auto e:v)sum += e;
  int cnt = 0;
  for(auto e:v)cnt += 1.*sum/(4*m) <= e;
  cout << (m <= cnt ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3620
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let num = Math.sqrt(xs[0]);
   let ans = Math.floor(num);
   console.log(Math.pow(ans,2));
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));




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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long
vector<int> v[200];
int n,t=1;
int d[200],f[200],done[200];

void dfs(int now){
	//cout<<now<<endl;
	d[now]=t;
	t++;
	done[now]=1;
	lp(i,v[now].size()){
		if(done[v[now][i]]==1) continue;
		dfs(v[now][i]);
	}
	f[now]=t;
	t++;
}

signed main(){
	cin>>n;
	lp(z,n){
		int i,c;
		cin>>i>>c;
		lp(j,c){
			int hoge;
			cin>>hoge;
			v[i].push_back(hoge);
		}
	}
	lps(i,1,n+1){
		if(done[i]==0)
			dfs(i);
	}
	lps(i,1,1+n){
		cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define irep(i,a,b) for(typeof(i) i = (a); i < (b); ++i)
#define itrep(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)


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

	ll A, B;
	cin >> A >> B;
	cout << A * B << endl;
	return(0);
}


Measured memory_bytes: 3640
class UnionFind():
    #https://note.nkmk.me/python-union-find/ 
    #note.nkmk.me  2019-08-18 
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N,M = map(int, input().split())
G =UnionFind(N)
ans =0
for i in range(M):
    a,b = map(int, input().split())
    #a,b =min(a,b),max(a,b)
    G.union(a-1,b-1)
    ans =max(ans,G.size(a-1))
if M ==0:
    print(1)
else:
    print(ans)

Measured memory_bytes: 14528
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,s,e) for(int i=s;i<e;i++)
int main(){
    lli N;cin>>N;
    lli res=0;
    for(lli i=1LL;i<=N;i++){
        if(i%3!=0 and i%5!=0)res+=i;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  int N;
  string s,t;
  cin>>N>>s>>t;
  for(int l=N;l<=2*N;l++){
    if(s.substr(s.size()-1-(2*N-l-1))==t.substr(0,2*N-l)){
      cout<<l<<endl;return 0;
    }
  }
  cout<<2*N<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int num= scan.nextInt();
		scan.close();

		int h;
		int m;
		int s;

		s = num%60;
		m = num/60%60;
		h = num/60/60;

		System.out.println(h + ":" + m + ":" + s);
	}

}

Measured memory_bytes: 17176
#include <stdio.h>
#define NIL -1
#define MAX_N 30
typedef struct node_ {
    int parent;
    int left;
    int right;
} Node;
 
Node T[MAX_N];
int D[MAX_N], H[MAX_N];
 
void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}
 
int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].left != NIL) {
        h1 = setHeight(T[u].left) + 1;
    }
    if (T[u].right != NIL) {
        h2 = setHeight(T[u].right) + 1;
    }
 
    if (h1 >= h2) {
        return H[u] = h1;
    } else {
        return H[u] = h2;
    }
}
 
int getSibling(int u) {
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) {
        return T[T[u].parent].left;
    }
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) {
        return T[T[u].parent].right;
    }
    return NIL;
}
 
void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
 
    int deg = 0;
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
 
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);
 
    if (T[u].parent == NIL) {
        printf("root\n");
    } else if (T[u].left == NIL && T[u].right == NIL) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}
 
int main(void) {
    int i, n;
    scanf("%d", &n);
    for (i = 0; i < MAX_N; i++) {
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }
 
    for (i = 0; i < n; i++) {
        int id, left, right;
        scanf("%d %d %d", &id, &left, &right);
        T[id].left = left;
        T[id].right = right;
        if (left != NIL) T[left].parent = id;
        if (right != NIL) T[right].parent = id;
    }
 
    int r;
    for (i = 0; i < n; i++) {
        if (T[i].parent == NIL) r = i;
    }
 
    setDepth(r, 0);
    setHeight(r);
 
    for (i = 0; i < n; i++) {
        print(i);
    }
 
    return 0;
}



Measured memory_bytes: 2044
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e11
using namespace std;
typedef long long ll;

ll min(ll a,ll b){
	return (a<b)?a:b;
}

int main(){
	ll a,b,c,diff=INF;
	cin>>a>>b>>c;
	diff=(a%2)?b*c:0;
	diff=(b%2)?min(diff,c*a):0;
	diff=(c%2)?min(diff,a*b):0;
	cout<<diff<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
signed main(){
    fast();
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for(int i=0; i<n; i++)  cin >> a[i];
    for(int i=0; i<m; i++)  cin >> b[i];
    for(int i=1; i<n; i++)  a[i] += a[i-1];
    for(int i=1; i<m; i++)  b[i] += b[i-1];
    int ans = 0;
    for(int i=0; i<n; i++){
        int curr = 0;
        if(a[i] <= k){
            curr = i+1;
            int lo = 0, hi = m-1;
            int mid, val = k-a[i], idx = -1;
            while(lo <= hi){
                mid = (lo+hi)/2;
                if(b[mid] > val){
                    hi = mid-1;
                }
                else{
                    idx = mid;
                    lo = mid+1;
                }
            }
            if(idx != -1){
                curr += (idx+1);
            }
            ans = max(curr, ans);
        }
        else{
            break;
        }
    }
    int lo = 0, hi = m-1;
    int mid, val = k, idx = -1;
    while(lo <= hi){
        mid = (lo+hi)/2;
        if(b[mid] > val){
            hi = mid-1;
        }
        else{
            idx = mid;
            lo = mid+1;
        }
    }
    ans = max(ans, idx+1);
    cout << ans << endl;
}

Measured memory_bytes: 6368
#include <stdio.h>

#define N 10

int main(void)
{
    int mountain[N];
    int i, j, tmp;

    for (i = 0; i < N; i++) {
        scanf("%d", &mountain[i]);
    }

    for (i = 0; i < N - 1; i++) {
        for (j = i + 1; j < N; j++) {
            if (mountain[i] < mountain[j]) {
                tmp = mountain[i];
                mountain[i] = mountain[j];
                mountain[j] = tmp;
            }
        }
    }

    for (i = 0; i < 3; i++) {
        printf("%d\n", mountain[i]);
    }

    return 0;
}

Measured memory_bytes: 600
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

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

class Z_Algo {
private:
    int len;
    string S;
    vector<int> Z;

public:
    Z_Algo(const string s) {
        len = s.size();
        S = s;
        Z = vector<int>(len);
        build();
    }

    void build() {
        Z[0] = len;
        int i = 1, j = 0;
        while (i < len) {
            while (i + j < len && S[j] == S[i + j])++j;
            Z[i] = j;
            if (j == 0) {
                i++;
                continue;
            }
            int k = 1;
            while (i + k < S.size() && k + Z[k] < j) Z[i + k] = Z[k], k++;
            i += k;
            j -= k;
        }
    }

    int get_max() const {
        return *max_element(Z.begin(), Z.end());
    }

    vector<int> get_result() {
        return Z;
    }

    int operator[](int k) const {
        return Z[k];
    }

    void show() const {
        printf("i:");
        for (int i = 0; i < len; i++) printf("%3d ", i);
        printf("\n");
        printf("Z:");
        for (int i = 0; i < len; i++) printf("%3d ", Z[i]);
        printf("\n");
    }

};


int main() {

    int N;
    cin >> N;

    string S;
    cin >> S;

    int ans = 0;
    for (int i = 0; i < N; i++) {
        string s = S.substr(i);
        Z_Algo zAlgo(s);
        for (int j =  1; j < s.size(); j++) {
            ans = max(min(zAlgo[j], j), ans);
        }
    }
    cout << ans << endl;

    return 0;
}




































Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
int main() {
	ll a, b; 
	std::cin >> a >> b;
	
	if (a == 1 && b == 1) {
		printf("1\n");
	} else if (a >= 3 && b >= 3) {
		ll ans = 0;
		ans += (a-2)*(b-2);
		std::cout << ans << std::endl;
	} else if (a == 1) {
		std::cout << b-2 << std::endl;
	} else if (b == 1) {
		std::cout << a-2 << std::endl;
	} else {
		std::cout << "0" << std::endl;
	}
	return 0;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4

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

    int n, m, c;
    cin >> n >> m >> c;
    vec b(m);
    mat a(n, vec(m));
    init(b);
    repall (v, a)
        init(v);

    int ct = 0;
    repall (v, a) {
        int sum = 0;
        rep (i, m)
            sum += v[i] * b[i];
        ct += (sum + c) > 0;
    }
    print(ct);

    return 0;
}

Measured memory_bytes: 256
def main():
    K = int(input())

    if K % 2 == 0:
        return -1
    elif K % 5 == 0:
        return -1

    an = 7
    counter = 1

    while True:
        modan = an % K

        if modan == 0:
            return counter

        an = modan * 10 + 7
        counter = counter + 1

if __name__ == "__main__":
    answer = main()
    print(answer)

Measured memory_bytes: 9128
L, R = map(int, (input().split()))
Lmod, Rmod = L%2019, R%2019
if Lmod < Rmod and (R - L >= 2019):
    print(0)
elif Lmod < Rmod and (R - L < 2019):
    ch_list =[]
    for i in range(L,R,1):
        for j in range(i+1, R+1, 1):
            ch_list.append((i*j)%2019)
    print(min(ch_list))
elif Lmod > Rmod:
    print(0)

Measured memory_bytes: 75432
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N =  Integer.parseInt(sc.next());
        
        Integer a[] = new Integer[N];
        for (int i=0; i<N; i++) {
            a[i] = sc.nextInt();
        }
        
        int max = a[0];
        int count = 0;
        
        for (int i=0; i<N; i++) {
            if (max <= a[i]) {
                max = a[i];
                count++;
            }
        }
        
        System.out.println(count);
    }
}

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

int main() {
	int n, p;
	cin >> n >> p;
	bool f=false;
	if(p%2==0) if(p>2*n-1) if(p<4*n+1) f=true;
	if(f) cout << "Yes";
	else cout << "No";
	cout << endl;
	return 0;
}


Measured memory_bytes: 3584
import java.io.*;
import java.util.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static int[] dp;
	static ArrayList<Integer>[]gr;
	static int dfs(int node)
	{
		int res=0;
		for(int i=0;i<gr[node].size();i++)
		{
			int y=gr[node].get(i);
			if(dp[y]!=-1)
				res=Math.max(res,1+dp[y]);
			else
				res=Math.max(res,1+dfs(y));
		}
		dp[node]=res;
		return res;
	}
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		int[]ar=split();
		int n=ar[0];
		int m=ar[1];
		gr=new ArrayList[n+1];
		for(int i=0;i<=n;i++)
		{
			gr[i]=new ArrayList<>();
		}
		for(int i=0;i<m;i++)
		{
			ar=split();
			int x=ar[0];
			int y=ar[1];
			gr[x].add(y);
		}
		dp=new int[n+1];
		Arrays.fill(dp, -1);
		for(int i=1;i<=n;i++)
		{
			if(dp[i]!=-1)
				continue;
			dp[i]=dfs(i);
		}
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			ans=Math.max(ans, dp[i]);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 72612
n = int(input())
h = list(map(int, input().split()))
ans = 0
b = 0
now = h[0]
for i in h[1:]:
  if i <= now:
    b += 1
  else:
    ans = max(ans, b)
    b = 0
  now = i
ans = max(ans,b)
print(ans)

Measured memory_bytes: 14252
S = input()
T = input()

res = ""
for i in range(len(S)-len(T),-1,-1):
    tmp = list(S)
    flag = True
    for j in range(i,i+len(T)):
        if S[j] != T[j-i] and S[j] != "?":
            flag = False 
    if flag:
        for j in range(i,i+len(T)):
            tmp[j] = T[j-i]
        for i in range(len(tmp)):
            if tmp[i] == "?":
                tmp[i] = "a"
        res = "".join(tmp)
        break
else:
    res = "UNRESTORABLE"

print(res) 





Measured memory_bytes: 3064
class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

ide_ele=0

def segfunc(x,y):
    return x|y

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f

import sys

input=sys.stdin.readline

N=int(input())
S=input().rstrip()

init_val=[1<<(ord(S[i])-97) for i in range(N)]
test=SegTree(init_val,segfunc,ide_ele)

for _ in range(int(input())):
    t,l,r=input().split()
    t,l=int(t),int(l)
    if t==1:
        val=ord(r)-97
        test.update(l-1,1<<val)
    else:
        r=int(r)
        res=test.query(l-1,r)
        print(popcount(res))


Measured memory_bytes: 119228
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    string s;
    bool is_ok=false;
    cin >> n;
    cin >> s;
    vector<LL> ans(n);
    for(LL i=0; i<2; i++){
        for(LL j=0; j<2; j++){
            if(is_ok==true){
                continue;
            }
            ans[0]=i;
            ans[1]=j;
            for(LL k=2; k<n; k++){
                if(s[k-1]=='o'){
                    if(ans[k-1]==0){
                        ans[k]=ans[k-2];
                    }else{
                        ans[k]=1-ans[k-2];
                    }
                }else{
                    if(ans[k-1]==0){
                        ans[k]=1-ans[k-2];
                    }else{
                        ans[k]=ans[k-2];
                    }
                }
            }
            if(s[n-1]=='o'){
                if(ans[n-1]==0){
                    if(ans[0]!=ans[n-2]){
                        continue;
                    }
                }else{
                    if(ans[0]==ans[n-2]){
                        continue;
                    }                    
                }
            }else{
                if(ans[n-1]==0){
                    if(ans[0]==ans[n-2]){
                        continue;
                    }
                }else{
                    if(ans[0]!=ans[n-2]){
                        continue;
                    }                    
                }
            }
            if(s[0]=='o'){
                if(ans[0]==0){
                    if(ans[1]!=ans[n-1]){
                        continue;
                    }
                }else{
                    if(ans[1]==ans[n-1]){
                        continue;
                    }                    
                }
            }else{
                if(ans[0]==0){
                    if(ans[1]==ans[n-1]){
                        continue;
                    }
                }else{
                    if(ans[1]!=ans[n-1]){
                        continue;
                    }
                }
            }
            is_ok=true;
        }
    }

    if(is_ok==false){
        cout << -1 << endl;
    }else{
        for(LL i=0; i<n; i++){
            if(ans[i]==0){
                cout << 'S';
            }else{
                cout << 'W';
            }
        }
        cout << endl;
    }

    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	while(true){
		int m,f,r; cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1)break;
		char g;
		if(m==-1||f==-1)g='F';
		else if(m+f>=80)g='A';
		else if(m+f>=65)g='B';
		else if(m+f>=50||m+f>=30&&r>=50)g='C';
		else if(m+f>=30)g='D';
		else g='F';
		cout<<g<<"\n"s;
	}
}


Measured memory_bytes: 3200
# -*- coding: utf-8 -*-
"""
AtCoder A
"""
 
import sys, math, random
import numpy as np
 
# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
# S=numpp.assaray(S)=="#"
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LLS(): return [list(sys.stdin.readline().rstrip()) for _ in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
 
 
 
def main():
    A, B, C = list(map(int,input().split()))
    sub=0
    if A>B:
        sub=A-B
    else:
        sub=0
    if sub>C:
        print("0")
    else:
        print(C-sub)
 
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 23656
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn construct_dp(a: &Vec<u64>) -> Vec<Vec<usize>> {
    let mut dp = vec![vec![0; 16]; a.len()];
    for i in 0..16 {
        dp[a.len() - 1][i] = i;
    }

    for i in (1..a.len()).rev() {
        for j in 0..16 {
            dp[i - 1][j] = j;

            let a1 = a[i - 1] * 4u64.pow(j as u32);
            let mut a2 = a[i];
            let mut inc: usize = 0;
            while a2 < a1 {
                inc += 1;
                a2 *= 4;
            }
            if inc > 15 {
                dp[i - 1][j] += (inc - 15) * (a.len() - i);
                inc = 15;
            }
            dp[i - 1][j] += dp[i][inc];
        }
    }
    dp
}

fn main() {
    let n: usize = read();
    let mut a = read_vec::<u64>();
    let dp_forward = construct_dp(&a);

    a.reverse();
    let dp_backward = construct_dp(&a);
    let mut ans = std::cmp::min(dp_forward[0][0] * 2, dp_backward[0][0] * 2 + a.len());

    for i in 1..n {
        // println!("{:?}", dp_forward[i]);
        let tmp_ans = dp_forward[i][0] * 2 + i + dp_backward[n - i][0] * 2;
        // println!("i {0} dp_forward[i][0] {1} dp_backward[n - i - 1][0] {2} {3}",
        //          i, dp_forward[i][0] * 2, dp_backward[n - i - 1][0] * 2, tmp_ans);
        ans = std::cmp::min(ans, tmp_ans);
    }

    println!("{:?}", ans);
}


Measured memory_bytes: 69872
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ConsoleApp1
{
    using static Util;

    internal class Program
    {


        static void Main(string[] args)
        {
            var n = ReadLong();
            var hs = ReadLongs();
          

            var cnt = Count(hs);
            Console.WriteLine(cnt);
#if DEBUG
            Console.Read();
#endif
        }

        private static long Count(long[] h)
        {
            h = h.ToArray();
            var res = 0;
            while (true)
            {
                if (h.Max() == 0) break;
                // 区間分割する
                int i = 0;
                while (i < h.Length)
                {
                    if (h[i] == 0) ++i; // 0 なら何もせずに次に進む
                    else
                    {
                        ++res; // 区間の始まり
                        while (i < h.Length && h[i] > 0)
                        {
                            --h[i];
                            ++i; // 区間の終わりまで一気に
                        }
                    }
                }
            }
            return res;
        }

        public static long fn(long n)
        {
            if (n % 2 == 0)
                return f1(n);
            else
                return f2(n);
        }

        public static long f1(long n)
        {
            return n / 2;
        }

        public static long f2(long n)
        {
            return 3*n +1;
        }

    }

    public static class Util
    {
        public static long[] ReadLongs() 
        {
            return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        }
        public static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        public static Tuple<int, long> FindMin(this IEnumerable<long> vals)
        {
            var min = long.MaxValue;
            var minIdx = 0;
            var cnt = 0;
            foreach(var val in vals)
            {
                if (min > val)
                {
                    min = val;
                    minIdx = cnt;
                }
                cnt++;
            }
            return Tuple.Create(cnt, min);
        }

    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    long n,m;
    cin >> n >> m;
    long p;
    string s;
    bool f[n];
    long wa[n]={};
    F(i,0,n) f[i]=false;
    F(i,0,m){
        cin >> p >> s;
        if(f[p-1]==false && s=="WA"){
            ++wa[p-1];
        }
        if(s=="AC"){
            f[p-1]=true;
        }
    }
    long w=0,a=0;
    F(i,0,n){
        if(f[i]==true){
            w+=wa[i];
            ++a;
        }
    }
    cout << a << ' ' << w << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<algorithm>
#include<cstdio>
#define M 200000
#define N 1001
using namespace std;
int a[N],b[M],c[M],d[M],e[N][N],f[N][N],m,n;bool x[M];
inline bool cmp(int u,int v){return b[u]==b[v]?c[u]<c[v]:b[u]<b[v];}
void dfs(int u,int*w){for(int i=a[u-1];i<a[u];i++)if(!w[b[i]])w[b[i]]=w[u],dfs(b[i],w);}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)scanf("%d%d",b+i,c+i),a[b[d[i]=i]]++;
	sort(d,d+m,cmp);
	for(int i=1;i<=n;i++)a[i]+=a[i-1],e[i][i]=f[i][i]=-1;
	for(int i=0;i<m;i++)b[i]=c[d[i]];
	for(int i=0;i<m;i++)c[i]=d[i];
	for(int i=1;i<=n;i++)for(int j=a[i-1];j<a[i];j++)if(!e[i][b[j]])dfs(e[i][b[j]]=b[j],e[i]);
	for(int i=1;i<=n;i++)for(int j=a[i];a[i-1]<j--;)if(!f[i][b[j]])dfs(f[i][b[j]]=b[j],f[i]);
	for(int i=1;i<=n;i++)for(int j=a[i-1];j<a[i];j++)x[c[j]]=(bool)e[b[j]][i]^e[i][b[j]]==f[i][b[j]];
	for(int i=0;i<m;i++)puts(x[i]?"same":"diff");
	return 0;
}

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

int main() {

  int score[100] = {0};
  vector<int> list;

  int input1,input2;
  char c;

  while(true) {

    cin >> input1 >> c >> input2;
    if ( input1 == 0 ) break;

    score[input1-1] = input2;

    if ( count( list.begin(), list.end(), input2 ) == 0 ) list.push_back(input2);

  }

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

  while( cin >> input1 ) {

    for ( int i = 1; i <= list.size(); i++ ) {

      if ( score[input1-1] == list[list.size()-i] ) {
	cout << i << endl;
	break;
      }

    }

  }

  return 0;

}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    (S.at(0)==S.at(1) && S.at(1)==S.at(2)) ? cout << NO << endl : cout << YES << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
def selection_sort(array, n)
  count = 0
  0.upto(n-1) do |i|
    min_index = i
    i.upto(n-1) { |j| min_index = j if array[min_index] > array[j] }
    if min_index != i
      array[i], array[min_index] = array[min_index], array[i]
      count += 1
    end
  end
  count
end

def trace(array)
  puts array.join(' ')
end

n = $stdin.gets.chomp.to_i
array = $stdin.gets.chomp.split(' ').map(&:to_i)

count = selection_sort(array, n)
trace(array)
puts count

Measured memory_bytes: 8696
def q(a,k):
 d[a]=k
 for b in t[a]:
  if'-1'!=b:q(b,k+1)
def n(a,k):
 h[a]=max(h[a],k)if a in h else k
 if'-1'!=p[a]:n(p[a],k+1)
t,p,s,d,h={},{},{},{},{}
for _ in[0]*int(input()):
 x,y,z=input().split()
 t[x]=set([y,z])-set(['-1'])
 p[y]=p[z]=x
 s[y],s[z]=z,y
r=(set(t)-set(p)).pop()
p[r],s[r]=['-1']*2
q(r,0)
for i in t:
 if not t[i]:n(i,0)
for i in map(str,sorted(map(int,t))):print(f"node {i}: parent = {p[i]}, sibling = {s[i]}, degree = {len(t[i])}, depth = {d[i]}, height = {h[i]}, {'root'if d[i]==0else'internal node'if t[i]else'leaf'}")


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N + 2);
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  int csum = 0;
  vector<int> cost(N + 1);
  for (int i = 0; i <= N; i++) {
    cost[i] = abs(A[i + 1] - A[i]);
    csum += cost[i];
  }
  for (int i = 0; i < N; i++)
    cout << csum - cost[i] - cost[i + 1] + abs(A[i + 2] - A[i]) << '\n';
  return 0;
}


Measured memory_bytes: 2048