akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <cmath>

using namespace std;

int main()
{
    int n, legs;
    cin>>n>>legs;
    for(int a = 0; a <= n; ++a) {
        int b = n - a;
        if ((2 * a + 4 * b) == legs) {
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3132
// C - Reconciled?
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007

ll factorial_mod(ll n){//階乗％MOD
	ll ans = n;
	while(n>1) ans = ans * --n % MOD;
	return ans;
}

int main(){
	ll N,M; cin>>N>>M;

	if((N<M && N+1!=M) || (N>M && N!=M+1)){
		cout<< 0 <<endl;
		return 0;
	}

	ll ans =  factorial_mod(N) * factorial_mod(M) % MOD;
	if(N == M) ans = ans * 2 % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

typedef struct{
  int pare,fstch,sibling;
}Node;

Node node[N];
int n,dep[N],he[N];

void pre(int u){
  if(u == -1)return;
  printf(" %d",u);
  pre(node[u].fstch);
  pre(node[u].sibling);
}

void in(int u){
  if(u == -1)return;
  in(node[u].fstch);
  printf(" %d",u);
  in(node[u].sibling);
}

void post(int u){
  if(u == -1)return;
  post(node[u].fstch);
  post(node[u].sibling);
  printf(" %d",u);
}

int sibling(int x){
    if(node[x].pare == -1)
        return -1;
    if(node[node[x].pare].fstch != x && node[node[x].pare].fstch != -1)
        return node[node[x].pare].fstch ;
    if(node[node[x].pare].sibling != x && node[node[x].pare].sibling != -1)
        return node[node[x].pare].sibling;
    return -1;
}

void depth(int x,int cnt){
  if(x==-1) return;
  
  dep[x]=cnt;
  depth(node[x].fstch,cnt+1);
  depth(node[x].sibling,cnt+1);
}

int height(int x){
    int h1=0,h2=0;
    if(node[x].fstch != -1)
        h1=height(node[x].fstch)+1;
    if(node[x].sibling != -1)
        h2=height(node[x].sibling)+1;
    return he[x]=(h1>h2?h1:h2);
}


int main(){

  int i,j,ch,v,left,right,root,k;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    node[i].pare = node[i].fstch = node[i].sibling = -1;

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&left,&right);

    node[v].fstch=left;
    node[v].sibling=right;
    
    if(left!=-1) node[left].pare=v;
    if(right!=-1) node[right].pare=v;
  }

  for(k=0;k<n;k++){
    if(node[k].pare==-1)
      root=k;
  }

  depth(root,0);
  height(root);

  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2036
import math

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

candidates = []
sumA = sum(A)

i = 1
while i <= math.sqrt(sumA):
    if sumA % i == 0:
        candidates.append(i)
        candidates.append(int(sumA / i))
    i += 1
    
candidates = sorted(candidates, reverse = True)
end = 0
# candidates loop
for i in range(len(candidates)):
    if end:
        break
    # A loop
    T = [0] * len(A)
    for j in range(len(A)):
        T[j] = A[j] % candidates[i]
    T = sorted(T)
    left = sum(T)
    right = 0
    need = max(left, right)
    for l in range(len(T) - 1, -1, -1):
        left -= T[l]
        right += candidates[i] - T[l]
        need = min(need, max(left, right))
    if need <= K:
        print(candidates[i])
        end = 1

Measured memory_bytes: 43244
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 
#define int ll
using namespace std;

const int N = 3e5 + 5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const long double eps = 1e-9 ;

using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

int get1(int n , int a[]){
    int r = n - 1;
    sort(a , a + n);
    int ans = 0; 
    rep(i , (n-1)/2){
        // cout << 2 * i + 1 << ' ' << a[r] << '\n' ;
        ans += 2 * (a[r--]);
        // b[2 * i + 1] = a[r + 1];
    }
    if(n % 2 == 0){
        ans += a[r--];
    }
    rep(i , (n % 2 ? 2 : 1)){
        ans -= a[r--];
    }
    while(r >= 0) ans -= 2 * a[r--];
    return ans ;
}

int get2(int n , int a[]){
  int r = n - 1;
    int ans = 0; 
    rep(i , (n+1)/2 - (n % 2 ? 2 : 1)){
        // cout << 2 * i + 1 << ' ' << a[r] << '\n' ;
        ans += 2 * (a[r--]);
        // b[2 * i + 1] = a[r + 1];
    }
    rep(i , (n % 2 ? 2 : 1)){
        ans += a[r--];
    }
    if(n % 2 == 0) ans -= a[r--];
    while(r >= 0) ans -= 2 * a[r--]; 
    return ans ;
}
void solve()
{
    int n ;
    cin >> n;
    int a[n];
    rep(i , n) cin >> a[i];
    if(n == 2){
        cout << abs(a[0] - a[1]);
        return ;
    }
    sort(a , a + n);
    cout << max(get1(n , a) , get2(n , a));
    
}
     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


Measured memory_bytes: 1024
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


def mod_invs(max, mod):
    """
    逆元のリスト 0 から max まで
    :param max:
    :param mod:
    :return:
    """
    invs = [1] * (max + 1)
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


# ブロック i を取り除くときにブロック j と連結である確率: 1/(abs(i-j)+1)
# これ合計して N! をかけた数だけカウントされるので
# それぞれ A とかけ合わせる
invs = mod_invs(max=N, mod=MOD)
invs[0] = 0
# denoms[i]: 1/1 + 1/2 + ... + 1/i
denoms = []
cumsum = 0
for inv in invs:
    cumsum = (cumsum + inv) % MOD
    denoms.append(cumsum)
factorial_n = math.factorial(N) % MOD

ans = 0
for i in range(N):
    s = denoms[i + 1] + denoms[N - i] - 1
    ans += s * factorial_n * A[i]
    ans %= MOD
print(ans)


Measured memory_bytes: 60312
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_s(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

#define MOD 1000000007

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

  vi a(n);

  rep(i, n)
  {
    cin >> a[i];
  }

  rep(_k, k)
  {
    vi table(n + 1, 0);
    rep(i, n)
    {
      table[max(i - a[i], 0)]++;
      table[min(i + a[i] + 1, n)]--;
    }
    rep(i, n)
    {
      if (i > 0)
      {
        table[i] += table[i - 1];
      }
    }

    table.pop_back();
    if (table == a)
    {
      break;
    }

    a = table;
  }

  rep(i, n)
  {
    cout << a[i] << endl;
  }
}


Measured memory_bytes: 4792
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(R):
    return 3*R*R


def main():
    R = read_int()
    print(slv(R))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8124
#include <iostream>

using namespace std;

int main() {

	int w, h;

	while(cin >> w >> h) {
		if(!w&&!h) {
			break;
		}
		char s[100][100];
		for(int i=0; i<w; i++) {
			for(int j=0; j<h; j++) {
				cin >> s[i][j];
			}
		}
		int c=0, x=0, y=0;
		while(c<w*h) {
			if(s[x][y]=='>') {
				y++;
			}
			else if(s[x][y]=='<') {
				y--;
			}
			else if(s[x][y]=='^') {
				x--;
			}
			else if(s[x][y]=='v') {
				x++;
			}
			else if(s[x][y]=='.') {
				break;
			}
			c++;
		}
		if(c!=w*h) {
			cout << y << " " << x << endl;
		}
		else {
			cout << "LOOP" << endl;
		}
	}

	return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<string,int,int>;

int main(){
  int n,k; cin >> n >> k;
  vector<double> p(n);
  for(int i = 0; i < n; i++){
    int temp; cin >> temp;
    if(i == 0){
      p[i] = (double)(temp+1)/2;
    }else{
      p[i] = p[i-1] + (double)(temp+1)/2;
    }
  }
  double ans = p[k-1];
  for(int i = k; i < n; i++){
    ans = max(ans, p[i]-p[i-k]);
  }
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 1792
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  while (cin >> s) {
    vi v(s.size());
    rep(i, s.size()) v[i] = s[i] - '0';
    while (v.size() > 1) {
      vi w;
      loop(i, 1, v.size()) w.pb((v[i] + v[i - 1]) % 10);
      v = w;
    }
    cout << v.front() << endl;
  }
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int main(int argc, void **arg)
{
    int a,b;
    int coin = 0;

    scanf("%d %d", &a, &b);

    for (int i = 0; i < 2; i++)
    {
        coin += a >= b ? a-- : b--;
    }
    
    printf("%d\n", coin);

    return 0;
}


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

const int INF = 1e9;

int main(void){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    g.resize(n);
    rep(i,m){
        int u,v;
        cin >> u >> v;
        u--,v--;
        g[u].push_back(v);
    }
    int s,t;
    cin >> s >> t;
    s--,t--;

    vector<int> dp[3];
    rep(i,3) dp[i] = vector<int> (n, INF);
    dp[0][s] = 0;
    using P = pair<int,int>;
    queue<P> qu;
    qu.push({s,0});
    while (qu.size()) {
        P front = qu.front(); qu.pop();
        int v = front.first;
        int cost = front.second + 1;
        for(int to : g[v]){
            if (dp[cost%3][to] > cost) {
                dp[cost%3][to] = cost;
                qu.push({to, cost});
            }
        }
    }
    cout << (dp[0][t] < INF ? dp[0][t]/3 : -1) << endl;
    return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

// ===============================================================================

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

  ll a, ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;

    if (a != 2 && a % 2 == 0) continue;

    bool isprime = true;
    for (int i = 3; i <= sqrt(a); i += 2) {
      if (a % i == 0) isprime = false;
    }

    ans += isprime;
  }

  cout << ans << endl;
}



Measured memory_bytes: 3108
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.root = [-1]*n
		self.rank = [0]*n
		self.cycle = [False]*n

	def find(self, x):
		if(self.root[x] < 0):
			return x
		else:
			self.root[x] = self.find(self.root[x])
			return self.root[x]
			
	def unite(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if(x == y):
			self.cycle[x] = True
		elif(self.rank[x] > self.rank[y]):
			self.root[x] += self.root[y]
			self.cycle[x] |= self.cycle[y]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			self.cycle[y] |= self.cycle[x]
			self.root[x] = y
			if(self.rank[x] == self.rank[y]):
				self.rank[y] += 1

	def isSame(self, x, y):
		return self.find(x) == self.find(y)
	
	#サイクルは各連結成分に一つまで
	def isSafe(self, x, y):
		cx = self.cycle[self.find(x)] 
		cy = self.cycle[self.find(y)]
		return not((self.isSame(x,y) and (cx or cy)) or (cx and cy))

n,h,w,*l = map(int,open(0).read().split())
cards = sorted([(a,r-1,c-1) for r,c,a in zip(*[iter(l)]*3)])[::-1]
uf = UnionFind(h+w)
ans = 0

for a,r,c in cards:
	c += h
	if uf.isSafe(r,c):
		uf.unite(r,c)
		ans += a
print(ans)

Measured memory_bytes: 130376
var
  i:longint;
  s:string;
  bool:boolean;
begin
  read(s);
  bool:=false;
  for i:= 1 to length(s) do
    begin
      if s[i]='C' then bool:=true;
      if bool and(s[i]='F') then
                              begin
                                writeln('Yes');
                                exit;
                              end;
    end;
  writeln('No');
end.


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

int main() {
	int n;
	while (cin >> n, n) {
		int ar[25];
		for (int i = 0;i < n;i++)cin >> ar[i];

		int o = 32;
		int c = 1;
		while (o > 0) {
			if (c % 2 == 1) {
				int a = (o - 1) % 5;
				o -= a;
				cout << o << endl;
			}
			else {
				int a = (c / 2) % n-1;
				if (a == -1)a += n;
				o -= ar[a];
				if (o < 0)o = 0;
				cout << o << endl;
			}
			c++;
		}

	}
	return 0;
}

Measured memory_bytes: 3080
n=int(input())
a=[0]*n
l=[]
for i in range(n):
    a[i]=int(input())
    m=[]
    for j in range(a[i]):
        x=list(map(int,input().split()))
        m.append(x)
    l.append(m)


mx=0
for mask in range(1<<n):
    honest=[0]*n
    clear=True
    for i in range(n):
        if ((mask>>i)&1)==0:
            honest[i]+=1
    for i in range(n):
        if honest[i]==1:
            for k in range(a[i]):
                if honest[l[i][k][0]-1]!=l[i][k][1]:
                    clear=False
    if clear:
        ans=sum(honest)
        mx=max(ans,mx)

print(mx)


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

import numpy
import scipy

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

A_sort = sorted(A, reverse=True)
#print(A_sort)

alice = bob = 0
for i, a in enumerate(A_sort):
    if i%2 == 0:
        alice += a
    else:
        bob += a

print(alice - bob)

Measured memory_bytes: 12508
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

int main()
{
    long int a,b,c,d;
    int i;
    long int x, y;
    long int p[4];
    long long int ans;
    
    scanf("%ld %ld %ld %ld",&a, &b, &c, &d);
    //printf("%d %d %d %d\n",a, b, c, d);
    
    
    p[0] = a*c;
    p[1] = a*d;
    p[2] = b*c;
    p[3] = b*d;
    
    //printf("%d %d %d %d\n",p[0], p[1], p[2], p[3]);
    
    ans = p[0];
    //printf("%lld\n",ans);
    
    
    for(i=1;i<4;i++){
        //printf("%d\n",i);
        if(p[i]>ans){
            ans = p[i];
            //printf("%d\n",i);
            //printf("%lld\n",ans);
        }
        
        //printf("%d\n",p[i]);
    }
    
    
    printf("%lld\n",ans);
    
    return 0;
}



Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
char c[1919];
int main() {
	int a;
	int p=0;
	int w=0;
	int g=0;
	int y=0;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>c[i];
		if(c[i]=='P'){p++;}
		else if(c[i]=='W'){w++;}
		else if(c[i]=='G'){g++;}
		else{y++;}
	}
	if(p<1||w<1||g<1||y<1){cout<<"Three"<<endl;}
	else{cout<<"Four"<<endl;}
}


Measured memory_bytes: 256
import sys
def main():
    input = sys.stdin.readline
    N=int(input())
    *A,=map(int, input().split())
    *B,=map(int, input().split())

    opa=opb=0
    for a,b in zip(A,B):
        if a>=b:
            opb+=a-b
        else:
            if (b-a)&1==0:
                opa+=(b-a)//2
            else:
                opa+=(b-a)//2 + 1
                opb+=1

    print('Yes' if opa>=opb else 'No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 4468
import copy
N=int(input())
a=[int(i) for i in input().split()]
B=copy.deepcopy(a)
A=0
for i in range(N):
    if a[i] < 0:
        a[i]*=-1
    else:
        continue
# print(a)   #2  5  1
# print(B)   #-2 5 -1
q=0
absmax=max(a)
print(2*N-1)
for i in range(N):
    if max(a)==a[i]:
        q=i
        break
if B[q]>=0:
    for i in range(N):
        B[i]+=absmax
        print("{} {}".format(q+1,i+1))
    for j in range(1,N):
        print("{} {}".format(j,j+1))
else:
    for i in range(N):
        B[i]-=absmax
        print("{} {}".format(q+1,i+1))
    for j in range(1,N):
        print("{} {}".format(N-j+1,N-j))

Measured memory_bytes: 3572
#include<stdio.h>
#include<stdlib.h>
#define NIL -1
#define MAX 25

typedef struct node{
  int l;
  int r;
  int p;
}Node;

void print(int);
void calcDepth(int , int );
int calcSib(int);
int calcHeight(int);

Node T[MAX];
int D[MAX];
int H[MAX];

int main(){
  int i,j;
  int n,id,l,r;
  int root = NIL;

  scanf("%d",&n);
  for(i = 0; i < n; i++)T[i].l = T[i].r = T[i].p = NIL;//treeの初期化 
  
  for(i = 0;i < n; i++){
    scanf("%d",&id);//節点の情報追加
    //printf("test 0 in for scanf\n");
    if(i == 0)T[id].p = NIL;
    for(j = 0; j < 1; j++){
      scanf(" %d %d",&l,&r);
      T[id].l = l;
      T[id].r = r;
      T[l].p = T[r].p = id;
    }
  }
  
  //printf("test1 入力\n");
  for(i = 0; i < n; i++){
    if(T[i].p == NIL)root = i;
  }
  //printf("test2 root\n");
  
  calcDepth(root , 0);
  calcHeight(root);
  
  for(i = 0; i < n; i++)print(i);

  return 0;
}

void print(int u){
  int deg,sib,dep;

  deg = NIL;
  
  if(T[u].l == NIL && T[u].r == NIL)deg = 0;//degの調整
  else if(T[u].r != NIL && T[u].l != NIL)deg = 2;
  else deg = 1;

  sib = NIL;
  if(T[u].p == NIL)sib = NIL;
  else sib = calcSib(u);
  
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,",u,T[u].p,sib,deg,D[u],H[u]);
  
  if(T[u].l == NIL && T[u].r == NIL){
    if(T[u].p == NIL)printf(" root\n");
    else printf(" leaf\n");//typeのprint
  }
  else if(T[u].p == NIL)printf(" root\n");
  else printf(" internal node\n");
  
}

int calcSib(int u){
  
  if(T[T[u].p].l == NIL && T[T[u].p].r == NIL)return NIL;
  if(T[T[u].p].l != u && T[T[u].p].l != NIL){
    return T[T[u].p].l;
  }
  if(T[T[u].p].r != u && T[T[u].p].r != NIL){
    return T[T[u].p].r;
  }
  return NIL;
}

void calcDepth(int u, int p){
  
  D[u] = p;
  if(T[u].l != NIL)calcDepth(T[u].l,p+1);
  if(T[u].r != NIL)calcDepth(T[u].r,p+1);
}

int calcHeight(int u){
  int height_l = 0,height_r = 0;
  
  
  if(T[u].l != NIL)height_l = calcHeight(T[u].l) + 1;
  if(T[u].r != NIL)height_r = calcHeight(T[u].r) + 1;

  if(height_l >= height_r)H[u] = height_l;
  else H[u] = height_r;

  return H[u];
}


Measured memory_bytes: 2036
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static int n = 0;
	static long x = 0;
	static long[] X;
	static long[] P;




	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String ss = sc.nextLine();
		int ans = 1100000;
		for(int i = 0;i + 2 < ss.length();i++){
			String x = ss.substring(i, i + 3); 
			int num = Integer.parseInt(x);
			num = Math.abs(num-753);
			ans = Math.min(ans, num);
		}

		System.out.println(ans);
	}

}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


Measured memory_bytes: 23764
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = 0
for i in range (n):
    if a[i] >= b[i]:
        m += b[i]
    else:
        b[i] -= a[i]
        if a[i+1] < b[i]:
            m += a[i+1]+a[i]
            a[i+1] = 0
        else:
            a[i+1] -= b[i]
            m += b[i] + a[i]
print(m)    

Measured memory_bytes: 18476
#include<stdio.h>
int main(){
	int a;
	int b;
	int c;
	scanf("%d %d %d", &a, &b, &c);
	if (a < b && b < c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

int main(){
    string a, b;
    cin >> a >> b;
    if(a.size() > b.size()){
        cout << "GREATER" << endl;
    }else if(a.size() < b.size()){
        cout << "LESS" << endl;
    }else{
        if(a == b){
            cout << "EQUAL" << endl;
        }else{
            rep(i, 0, a.size()){
                if(a[i] > b[i]){
                    cout << "GREATER" << endl;
                    break;
                }else if(a[i] < b[i]){
                    cout << "LESS" << endl;
                    break;
                }
            }
        }
    }
    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();

		long[] nums = new long[86+1];
		nums[0] = 2;
		nums[1] = 1;

		for(int i = 2; i <= 86; i++) {
			nums[i] = nums[i-2] + nums[i-1];
		}

		System.out.println(nums[n]);
	}
}

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

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

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

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

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

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

}


Measured memory_bytes: 21332
#include<stdio.h>
int main(void)
{
	int n;
	scanf("%d",&n);
	//100<=N<=999
	if(n<=111){
		printf("111\n");
	}
	else if(112<=n && n<=222){
		printf("222\n");
	}
	else if(223<=n && n<=333){
		printf("333\n");
	}
	else if(334<=n && n<=444){
		printf("444\n");
	}
	else if(445<=n && n<=555){
		printf("555\n");
	}
	else if(556<=n && n<=666){
		printf("666\n");
	}
	else if(667<=n && n<=777){
		printf("777\n");
	}
	else if(778<=n && n<=888){
		printf("888\n");
	}
	else{
		printf("999\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007
using namespace std;


long long dp[301][301][301];


int main(){
	int n,m;
	cin>>n>>m;
	dp[0][1][0]=1;
	for (int i=0;i<m;i++){
		for (int j=1;j<=n;j++){//閉路
			for (int k=0;k<n;k++){//非閉路
				if (dp[i][j][k]==0)continue;
				(dp[i + 1][j + k][0] += dp[i][j][k] * j)%=MOD;

				(dp[i + 1][j][k] += dp[i][j][k] * k) %= MOD;
				(dp[i + 1][j][k + 1] += dp[i][j][k] * (n - j - k)) %= MOD;
			}
		}
	}

	cout << dp[m][n][0]<<endl;



	return 0;
}

Measured memory_bytes: 106880
#include <stdio.h>
 
 
int main()
{
	int a, b;
	char c[10];
	int i;
	char tmp;
	scanf("%d\n", &a);
	for (i = 0; i < a; i++) {
		scanf("%c\n", &c[i]);
	}
	scanf("%d", &b);
    b = b - 1;
	tmp = c[b];
	for (i = 0; i < a; i++) {
		if (c[i] != c[b]) {
			c[i] = '*';
		}
		printf("%c", c[i]);
	}
	printf("\n");
    return 0;
}

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

map<int, int> mp;

int n, t, a[100010], mx, ans;

int main(){
	scanf("%d%d", &n, &t);
	for(int i = 1; i <= n; i++) scanf("%d", a + i);
	for(int i = n; i >= 1; i--){
		if(!mp.empty()) mx = max(mx, (*mp.rbegin()).first - a[i]);
		mp[a[i]]++;
	}
	for(int i = 1; i <= n; i++){
		ans += mp[a[i] + mx];
		mp[a[i] + mx] = 0;
		if(mp[a[i]]) mp[a[i]]--;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 10112
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int a[111],b[111];
  for(int i=0;i<7;i++){
    cin >> a[i] >> b[i];
  }
  for(int i=0;i<7;i++){
    cout << a[i]-b[i] << endl;
  }
  return(0);
}



Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <random>

int main() {
	std::string s, t; std::cin >> s >> t;
	int count = 0;
	for (auto i = 0; i < s.size(); ++i) if (s[i] == t[i]) ++count;
	std::cout << count << std::endl;
}


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

public class Main {
  static int MOD = 1000000007;
  static double EPS = 1e-9;

  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    StringTokenizer st = new StringTokenizer(in.readLine());

    String N = st.nextToken();
    int length = N.length();
    int K = Integer.parseInt(st.nextToken());

    TreeSet<Integer> set = new TreeSet<Integer>();

    st = new StringTokenizer(in.readLine());

    for (int i = 0; i < K; i++) {
      set.add(Integer.parseInt(st.nextToken()));
    }

    int[] valid = new int[10 - K];
    int index = 0;

    for (int i = 0; i < 10; i++) {
      if (!set.contains(i)) {
        valid[index] = i;
        index++;
      }
    }

    // System.out.println(Arrays.toString(valid));


    int res = 0;
    /*int max = -1;

    for (int i = 0; i < length; i++) {
      max = Math.max(max, N.charAt(i) - '0');
    }

    if (max > valid[valid.length - 1]) {
      res = valid[]
    } */

    boolean b = true;
    boolean large = false;

    for (int i = 0; i < length; i++) {
      int d = N.charAt(i) - '0';
      // System.out.println(d);
      boolean done = false;
      if (large) {
        res = res * 10 + valid[0];
        continue;
      }
      for (int j = 0; j < valid.length; j++) {
        if (valid[j] >= d) {
          if (i == 0 && valid[j] > d)
            large = true;
          res = res * 10 + valid[j];
          done = true;
          break;
        }
      }
      if (!done) {
        b = false;
        break;
      }
    }

    if (!b) {
      if (valid[0] == 0)
        res = valid[1];
      else
        res = valid[0];
      for (int i = 0; i < length; i++) {
        res = res * 10 + valid[0];
      }
    }

    System.out.println(res);

    in.close();
  }
}

Measured memory_bytes: 21332
N,A,B = map(int,input().split())
L = list(map(int,input().split()))
exhaust = 0
for i in range(1,N):
  if (L[i]-L[i-1])*A <= B:
    exhaust += (L[i]-L[i-1])*A
  else:
    exhaust += B
print(exhaust)

Measured memory_bytes: 14252
h, w, K = map(int, input().split())
c = []
for i in range(h):
  a = list(str(input()))
  c.append(a)
cnt = 0
blk = 0
for i in range(2 ** h):
  for j in range(2 ** w):
    for k in range(h):
      for l in range(w):
        if ((i >> k) & 1 == False) and ((j >> l) & 1 == False) and (c[k][l] == '#'):
          blk += 1
    if blk == K:
      cnt += 1
    blk = 0
print(cnt)

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

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 1e9+7l;

// code begins here

ll find_val(ll x){
    ll ans = (((ll)sqrt(1 + 8*x)) - 1)/2;
    return ans;
}

ll primeFactors(ll n)  {  
    ll cnt = 0, cur = 0;

    while (n % 2 == 0)  {  
        cur++; 
        n /= 2;
    }  
    
    cnt += find_val(cur);
    
    for (ll i = 3; i <= sqrt(n); i = i + 2) {  
        cur = 0;
        while (n % i == 0)  {  
            cur++;
            n = n/i;  
        } 
        cnt += find_val(cur);
    }  
    
    if (n > 2)  
        cnt++;
    
    return cnt;
}  

int main(){
    fast;
    
    ll n;
    cin>>n;
    
    cout<<primeFactors(n)<<endl;
    
    return 0;
}

Measured memory_bytes: 3692
n = int(input())
h = list(map(int, input().split()))

def solve(l):
    if l == []:
        return 0
    else:
        m = min(l)
        ans = m
        l2 = []
        for i in range(len(l)):
            l2.append(l[i] - m)
        p = l2.index(0)
        return m + solve(l2[:p]) + solve(l2[p + 1:])

print(solve(h))

Measured memory_bytes: 38512
def prf(m):
    pf = {}
    for i in range(2,int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i,0)+1
            m //= i
    if m>1:pf[m] = 1
    return pf

from collections import defaultdict
Pr = defaultdict(lambda: 1)

m = int(input())
for i in range(1,m+1):
    j = prf(i)
    for k, l in j.items():
        Pr[k] += l
A = list(Pr.values())
a3 = sum([True for i in A if i == 3 or i == 4])
a5 = sum([True for i in A if i >= 5])
a15 = sum([True for i in A if i >= 15])
a25 = sum([True for i in A if i >= 25])
a75 = sum([True for i in A if i >= 75])
ans = a3*a5*(a5-1)//2 + a5*(a5-1)*(a5-2)//2 + (a5-a15)*a15 + a15*(a15-1) \
+ (a3+a5-a25)*a25 + a25*(a25-1) + a75
print(ans) 

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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) {
        if (b & 1) res = (res * a) % m;
        a = (a * a) % m; b >>= 1;
    } return res;
}

int now() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now()
    .time_since_epoch()).count();
}

int32_t main() { fastio;
    time_t start = now();

    string s; cin >> s;
    if (s.length() % 2) {
        cout << "No" << endl;
    } else {
        for (int i = 0; i < s.length(); i+=2) {
            if (s[i] != 'h' or s[i+1] != 'i') {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }

    cerr << "TIME => " << now() - start << endl;
    return 0;
}

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

int main(int argc, char *argv[])
{
	int i, len;
	string s_str, t_str;
	cin >> s_str >> t_str;

	len = s_str.length();

	for (i = 0; i < len + 1; i++) {
		if (s_str == t_str) {
			cout << "Yes" << endl;
			return 0;
		}

		rotate(s_str.begin(), s_str.begin() + 1, s_str.end());
	}

	cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<int>> d(m,vector<int>(4,0));
  vector<int> c(n);
  for (int i=0;i<m;i++){
    cin >> d[i][1] >> d[i][2];
    d[i][0]=i;
  }
  sort(d.begin(),d.end(),[](vector<int> v1,vector<int> v2){
    return v1[2] < v2[2];
  });
  for(int i=0;i<m;i++){
    d[i][3]=++c[d[i][1]];
  }
  sort(d.begin(),d.end(),[](vector<int> v1,vector<int> v2){
    return v1[0] < v2[0];
  });
  for (int i=0;i<m;i++){
    cout << setw(6) << setfill('0') << d[i][1] << setw(6) << setfill('0') << d[i][3] << endl;
  }
  return 0;
}


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

#define f first
#define s second

using namespace std;

signed main() {
	int n;
	cin >> n;
	map<string, int> mp;
	for (int i = 0; i < n; ++i) {
		string x;
		cin >> x;
		sort(x.begin(), x.end());
		mp[x]++;
	}
	long long ans = 0;
	for (auto &i : mp) {
		ans += i.s * 1LL * (i.s - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D,E,k;
  cin>>A>>B>>C>>D>>E>>k;
  if(E-A>k){
    cout<<":("<<endl;
  }else{
    cout<<"Yay!"<<endl;
  }
}

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

// Macros
#define F  first
#define S  second
#define PB push_back

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const set<T> &v)    { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T,S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T,S> &v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef SANYAM1101
	#define trace(args...) do{ cerr << "TRACE ON! (Line: " << __LINE__ << ")\n"; auto _stream = istringstream{string{#args}}; d_f(_stream, args); } while(0)
	void d_f(__attribute__((unused)) istringstream& _stream) {}
	template<typename Head, typename... Tails> void d_f(istringstream& _stream, Head H, Tails... T) { string _name; _stream >> _name; if(_name.back() == ',') _name.pop_back(); cerr << "\t" << _name << " <=> [" << H << "]\n"; d_f(_stream, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

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

	vector<vector<int>> adj(n);
	while(m--){
		int s, t;
		cin >> s >> t;
		adj[s - 1].push_back(t - 1);
	}

	vector<ld> dp(n);
	ld ans = 1e18;

	for(int i = 0; i < n; ++i){	
		dp.back() = 0;

		for(int j = n - 2; j >= 0; --j){
			ld su = 0, ma = 0;

			for(auto ng: adj[j]){
				su += dp[ng];
				ma = max(ma, dp[ng]);
			}

			if(j == i and adj[j].size() >= 2)
				dp[j] = 1 + (su - ma) / (adj[j].size() - 1);
			else
				dp[j] = 1 + su / adj[j].size();
		}

		ans = min(ans, dp.front());
	}

	cout << ans << "\n";
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Measured memory_bytes: 4636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define debug printf("\n-------------\n")
using namespace std;
typedef long long ll;
const int INF1=(~0u>>2);
const ll INF2=(~0ull>>2),P1=10007,P2=998244353,P3=1000000007;
int main()
{
	char c;
	scanf("%c",&c);
	printf("%c",c+1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define X first
#define Y second

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

const ll INF = 1e9;


int n, m, a, b, c;
ll d[105][105];
vector<int> edge[105];

int main(){
	fill( d[0], d[0]+105*105, INF );
	cin >> n >> m >> a >> b >> c;
	rep(i,m){
		int u, v;
		cin >> u >> v;
		edge[v].pb(u);
	}
	edge[1].pb(0);

	queue<pii> que;
	que.emplace(n,0);
	d[n][0] = 1;
	while( !que.empty() ){
		auto p = que.front();
		//cout << p.X << "," << p.Y << " " << d[p.X][p.Y] << endl;
		que.pop();
		ll f = -1;
		if( d[p.X][a] < INF && d[p.X][b] < INF && d[p.X][c] < INF ){
			f = max(d[p.X][a], max(d[p.X][b], d[p.X][c]) );
			d[p.X][0] = min(d[p.X][0], f);
		}
		for(auto t: edge[p.X]){
			int ni = p.Y + 1;
			if( ni <= 100 && d[t][ni] > d[p.X][p.Y] ){
				d[t][ni] = d[p.X][p.Y];
				que.emplace( t, ni );
			}
			if( f>0 && d[t][1] > f + 1 ){
				d[t][1] = f + 1;
				que.emplace( t, 1 );
			}
		}
	}

	if( d[1][0] == INF ) cout << "IMPOSSIBLE" << endl;
	else cout << d[1][0] << endl;
}

Measured memory_bytes: 3256
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

char in[20];
int n;
pi t[20000];

int main()
{
	while(scanf("%d",&n),n)
	{
		rep(i,n)rep(j,2)
		{
			int h,m,s; scanf("%d:%d:%d",&h,&m,&s);
			t[i*2+j]=mp(h*3600+m*60+s,1-j);
		}
		sort(t,t+2*n);
		
		int ans=0,c=0;
		rep(i,2*n)
		{
			if(t[i].second)c++; else c--;
			ans=max(ans,c);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
const int INF = 1001001001;

int main()
{
    int n,m; cin >> n >> m;
    vector<int> ans(n,0);
    rep(i,m){
        int a,b; cin >> a >> b;
        ans[--a]++; ans[--b]++;
    }
    rep(i,n) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  int N;
  cin >> N;
  cin >> S;
  string mojiretu="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for (int i=0;i<S.length();i++){
    for(int j=0;j<30;j++){
      if(S[i]==mojiretu[j]){
        S[i]=mojiretu[j+N];
        break;
      }
    }
  }
  cout << S;
}


Measured memory_bytes: 384
s = int(input())  
a = s // 1000      #千の位 a
b = s // 100 % 10  #百の位 b
c = s // 10 % 10   #十の位 c
d = s % 10         #一の位 d

def p_mark(j):      #プラスかマイナスかを返す
    if j % 2 == 0:  #余りなしでプラス、ありでマイナス
        return '+'  
    else:  
        return '-'  

for i in range(2 ** 3):  #2の3乗探索
    j = i  #iをjに格納
    p = a  #pに値を格納していく

    x = p_mark(j)  #x = a ? b

    if x == '+': 
        p += b  
    else:  
        p -= b  

    j = j // 2  #jを1bit右へ

    y = p_mark(j)  #y = b ? c

    if y == '+': 
        p += c  
    else:  
        p -= c  

    j = j // 2  #jを1bit右へ

    z = p_mark(j)  #z = c ? d

    if z == '+':
        p += d  
    else:  
        p -= d  

    if p == 7: #pは7か？
        print(str(a) + x + str(b) + y + str(c) + z + str(d) + '=7')  
        break  

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int b, r, g, c, s, t;
  while (cin >> b >> r >> g >> c >> s >> t, t) {
    int ans = 100;
    ans += 15 * b + 15 * r + 7 * g + 2 * c;
    ans += 5 * 15 * b + 3 * 15 * r;
    ans -= (t - 5 * b - 3 * r - s) * 3;
    ans -= (5 * 2 * b + 3 * 2 * r);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3088
s = input()
x, y = map(int, input().split())
n = len(s)
#dp_x: +, -に向いてて行けるかどうか
dp_x = [[False, False] for i in range(2*n+2)]
dp_y = [[False, False] for i in range(2*n+2)]
dp_x[0][0] = True
dp_y[0][0] = True
dp_y[0][1] = True

flag = 0
for i in range(len(s)):
    if s[i] == "T":
        if flag == 0:
            flag = 2
            for j in range(-i-1, i+2):
                if dp_x[j][0]:
                    dp_x[j][1] = True

        elif flag == 2:
            flag = 1
            for j in range(-i-1, i+2):
                dp_x[j][0] = dp_x[j][1] or dp_x[j][0]
                dp_x[j][1] = dp_x[j][1] or dp_x[j][0]

        else:
            flag = 2
            for j in range(-i-1, i+2):
                dp_y[j][0] = dp_y[j][1] or dp_y[j][0]
                dp_y[j][1] = dp_y[j][1] or dp_y[j][0]


    else:
        if flag == 0:
            for j in range(i+1, -i-2, -1):
                dp_x[j][0] = dp_x[j-1][0]

        elif flag == 1:
            for j in range(i+1, -i-2, -1):
                dp_x[j][0] = dp_x[j-1][0]
                dp_x[-j][1] = dp_x[-j+1][1]
        else:
            for j in range(i+1, -i-2, -1):
                dp_y[j][0] = dp_y[j-1][0]
                dp_y[-j][1] = dp_y[-j+1][1]


if dp_x[x][0] or dp_x[x][1]:
    if dp_y[y][0] or dp_y[y][1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 50140
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<bitset>

using namespace std;

/************************************************/

int main(void) {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int big = max(a, max(b, c));
	char flag;
	if (big == a) {
		flag = 'a';
	}
	else if (big == b) {
		flag = 'b';
	}
	else {
		flag = 'c';
	}
	for (int i = 1; i <= k; i++) {
		big *= 2;
	}
	if (flag == 'a') {
		cout << big + b + c;
	}
	else if(flag=='b'){
		cout << a + big + c;
	}
	else {
		cout << a + b + big;
	}

	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var result = Math.Max(vals[0] + vals[1], vals[0] - vals[1]);
            result = Math.Max(result, vals[0] * vals[1]);

            Console.WriteLine(result);
        }
    }
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, 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()

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

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

template <typename Monoid>
class SegmentTree{
    private:
        using Func = function<Monoid(Monoid, Monoid)>;
        int n; // 最下段の数
        vector<Monoid> segmentTree; // セグ木本体
        const Func f; // 二項演算
        const Monoid identityElement; // モノイドの単位元

    public:
        SegmentTree(vector<Monoid> vec, const Func f, const Monoid identityElement);
        void Update(int x, Monoid val);
        Monoid Query(int a, int b, int k = 0, int l = 0, int r = -1); // 使う時は区間[a, b)のみ指定すれば良い
        Monoid GetNum(int x);
};

template <typename Monoid>
SegmentTree<Monoid>::SegmentTree(vector<Monoid> vec, const Func f, const Monoid identityElement) :
    f(f), identityElement(identityElement)
{
    int sz = vec.size();
    n = 1;
    while(n < sz) n *= 2;
    segmentTree.assign(2*n-1, identityElement);
    for(int i = 0; i < sz; i++) segmentTree[i+n-1] = vec[i];
    for(int i = n-2; i >= 0; i--) segmentTree[i] = f(segmentTree[2*i+1], segmentTree[2*i+2]);
}

template <typename Monoid>
void SegmentTree<Monoid>::Update(int x, Monoid val){
    x += n - 1;
    segmentTree[x] = val;
    while(x > 0){
        x = (x - 1) / 2;
        segmentTree[x] = f(segmentTree[2*x+1], segmentTree[2*x+2]);
    }
}

template <typename Monoid>
Monoid SegmentTree<Monoid>::Query(int a, int b, int k, int l, int r){
    if(r < 0) r = n;

    if(r <= a || b <= l) return identityElement;

    if(a <= l && r <= b) return segmentTree[k];

    int vl = Query(a, b, 2*k+1, l, (l+r)/2);
    int vr = Query(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
}

template <typename Monoid>
Monoid SegmentTree<Monoid>::GetNum(int x){
    return segmentTree[x+n-1];
}

/*************** using variables ***************/
int n, q;
/**********************************************/

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

    cin >> n >> q;
    vector<int> a(n, 0);
    SegmentTree<int> st(a, [](int a, int b){return a + b;}, 0);
    REP(i, q){
        int comp, x, y;
        cin >> comp >> x >> y;
        if(comp == 0) st.Update(x-1, st.GetNum(x-1) + y);
        else cout << st.Query(x-1, y) << endl;
    }
}



Measured memory_bytes: 4604