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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

vector<ll> Reduced(ll N, vector<ll> A)
{
    vector<ll> B = A;    
    for(ll i=0;i<N-1;i++)
    {
        B[i]%=2;
        if(B[i+1]!=0)
        {
            B[i+1]-=B[i];
            B[i]=0;
        }
    }
    B[N-1]%=2;
    return B;
}

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

    vector<ll> A(N);
    ALLIN1_NUMBER(A);

    vector<ll> reduced_A = Reduced(N,A);

    OUT0((accumulate(ALL(A),0LL)-accumulate(ALL(reduced_A),0LL))/2);

    return 0;
}

Measured memory_bytes: 5612
N,x=list(map(int,input().split()))
a=list(map(int,input().split()))
count=0
minus = 0

while(True):
    if len(a)<2:
        break
    
    minus = a[0]+a[1]-x
    if minus<=0:
        a.remove(a[0])
    elif minus>=a[1]:
        count+=minus
        a[1]=0
        a.remove(a[0])
    else:
        count += minus
        a[1] -= minus

print(count)

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

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> firstIsland;
  map<int, int> secondIsland;
  for (int i = 0; i < m; i ++) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      firstIsland[b] = 1;
    } else if (b == n) {
      secondIsland[a] = 1;
    }
  }

  for (auto fi = firstIsland.begin(); fi != firstIsland.end(); fi ++) {
    if (secondIsland[fi -> first]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 14336
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    LL S;
    cin >> S;
    LL x1 = 0;
    LL y1 = 0;
    LL x2 = 1000000000;
    LL y2 = 1;
    LL x3 = (x2-S%x2)%x2;;
    LL y3 = (S+x3)/x2;

    cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << x3 << ' ' << y3 << endl; 

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main(){
	int n;
	cin>>n;
	cout<<"ABC"<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int N,K;
		String S;
		Scanner sc=new Scanner(System.in);	
		S=sc.next();
		char c[]=S.toCharArray();
		int num=0;
		N=c.length;
		for(int i=0;i<N;i++) {
				
					if(i+1<=N-1) {
						if(c[i]=='0'&&c[i+1]=='0') {
						c[i+1]='1';
						num++;
						
						
					}else if(c[i]=='1'&&c[i+1]=='1'){
						c[i+1]='0';
						num++;
					}
					}
					
					
			}
			
		
			
		System.out.println(num);
	}
}


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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(lld t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

lld mod_pow(lld x, lld n, lld mod){
    if(n == 0) return 1;
    lld res = mod_pow(x * x % mod, n / 2, mod);
    if(n & 1) res = res * x % mod;
    return res;
}

lld mpow(lld x, lld n){ //x^n(mod M)
    lld ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

mint comb(lld a, lld b){ //aCbをmod計算
    mint res = 1;
    for (int i = 0; i < b; i++) {
        res *= (a-i);
    }
    for (int i = 0; i < b; i++) {
        res /= (i+1);
    }
    return res;
}

int main() {
    lld n,a,b;
    cin >> n >> a >> b;

    mint ans = (mod_pow(2,n,mod)-1)%mod;
    cout << (ans - comb(n,a) - comb(n,b)) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

template<class T> struct Fenwick {
    int n;
    T* d;
    Fenwick() : n(0), d(NULL) {}
    Fenwick(int n_) : n(n_) {
	d = new T[n_]();
    }
    Fenwick(const Fenwick &y) : n(y.n) {
	d = new T[n];
	memcpy(d, y.d, sizeof (T) * n);
    }
    ~Fenwick() {
	delete[] d; d = NULL;
	n = 0;
    }
    friend void swap(Fenwick &x, Fenwick &y) {
	swap(x.n, y.n); swap(x.d, y.d);
    }
    Fenwick& operator=(Fenwick y) {
	swap(*this, y);
	return *this;
    }
    inline void add(int i, const T &x) {
	for (; i<n; i|=i+1) d[i] += x;
    }
    inline T sum(int r) {
	T s = T();
	for (; r; r&=r-1) s += d[r-1];
	return s;
    }
    T sum(int l, int r) {
	return sum(r) - sum(l);
    }
    int lower_bound(const T &x) { // sum(ret) < x <= sum(ret+1);
	if (n == 0) return 0;
	int i = 0; T s = T();
	for (int k=1<<__lg(n); k; k>>=1) {
	    if (i+k <= n && s + d[i+k-1] < x) {
		i += k; s += d[i-1];
	    }
	}
	return i;
    }
    int upper_bound(const T &x) { // sum(ret) <= x < sum(ret+1);
	if (n == 0) return 0;
	int i = 0; T s = T();
	for (int k=1<<__lg(n); k; k>>=1) {
	    if (i+k <= n && !(x < s + d[i+k-1])) {
		i += k; s += d[i-1];
	    }
	}
	return i;
    }
};

const int MAXN = 40011;
int N;
double P[MAXN], Q[MAXN];
pair<double, int> H[MAXN];
int rnk[MAXN];

bool ok(double x) {
    REP (i, N) H[i] = make_pair(P[i] * x + Q[i], i);
    sort(H, H+N);
    Fenwick<int> F(N);
    LL cnt = 0;
    REP (i, N) {
	int r = rnk[H[i].second];
	cnt += F.sum(r);
	F.add(r, 1);
    }
    return cnt*2 >= (LL)N*(N-1)/2;
}

double solve() {
    REP (i, N) H[i] = make_pair(P[i], i);
    sort(H, H+N);
    REP (i, N) rnk[H[i].second] = i;

    double lo = -1, hi = 1;
    while (!ok(hi)) {
	lo = hi;
	hi *= 2;
    }
    while (ok(lo)) {
	hi = lo;
	lo *= 2;
    }
    REP (t, 50) {
	double mid = (lo + hi) / 2;
	(ok(mid)? hi: lo) = mid;
    }
    return hi;
}

int A[MAXN], B[MAXN], C[MAXN];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d%d%d", A+i, B+i, C+i);

    REP (i, N) {
	P[i] = -(double)A[i] / B[i];
	Q[i] = (double)C[i] / B[i];
    }
    double ansx = solve();

    REP (i, N) {
	P[i] = -(double)B[i] / A[i];
	Q[i] = (double)C[i] / A[i];
    }

    double ansy = solve();

    printf("%.12f %.12f\n", ansx, ansy);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 2304
N = int(input())
A = list(map(int, input().split(' ')))

flag = 0
count = 0

for i in range(N):
    if(A[i] == 0):
        flag = 1

    if(flag == 0):
        if(A[i] < 0):
            count += 1

    A[i] = abs(A[i])

if(count % 2 == 0):
    flag = 1


if(flag == 1):
    print(sum(A))
else:
    print(sum(A) - 2 * min(A))

Measured memory_bytes: 14412
// -> limitless <- //
#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define read(n) scanf ("%d", &n)
using namespace std;
typedef unsigned long long ll;
    const int N = 1e4 + 2;
    const int mod = 1e9 + 7;

int main()
{
    int n, k, mn = 1e9, c = 0, mx = -1;
    read(n), read(k);
    //int arr[N] = {};
    //lp(i, n){scanf("%d", arr + i);}
    printf("%d", (int)ceil((n-1)*1.0/(k-1)*1.0) );
	return 0;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL X,N;
LL p[100];

LL ans = INF;

void solve(){
	map<LL,priority_queue<LL>> q; 
	for(int i=0;i<=101;i++){
		bool flag = true;
		for(int j=0;j<N;j++){
			if(p[j]==i) flag=false;
		}
		if(!flag) continue;
		q[abs(X-i)].push(-i);
	}
	auto iter = q.begin();
	ans = -((iter->second).top());
}

int main(){
    cin >> X >> N;
    for(int i=0;i<N;i++) cin >> p[i];

    solve();

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

Measured memory_bytes: 3200
<?php

while (($line = trim(fgets(STDIN))) !== '0') {
    $n = (int)$line;
    //0埋め
    $arr = array_fill(0, $n, array_fill(0, $n, 0));
    $x = (int)($n / 2);
    $y = $x + 1;
    //最初の入力
    $arr[$y][$x] = 1;
    $m = pow($n, 2);
    $cnt = 2;
    $right = true;

    //全ての入力が終わるまで
    while ($cnt <= $m) {
        //右下モード
        if ($right) {
            $x = $x + 1 < $n ? $x + 1 : 0;
            $y = $y + 1 < $n ? $y + 1 : 0;
            //既に入力済み
            if ($arr[$y][$x]) {
                //左下モード
                $right = false;
            } else {
                $arr[$y][$x] = $cnt;
                //右下モードにして次の数字
                $right = true;
                $cnt++;
            }
        //左下モード
        } else {
            $x = $x - 1 < 0 ? $n - 1 : $x - 1;
            $y = $y + 1 < $n ? $y + 1 : 0;
            //既に入力済み
            if ($arr[$y][$x]) {
                continue;
            }
            $arr[$y][$x] = $cnt;
            //右下モードにして次の数字
            $right = true;
            $cnt++;
        }
    }

    for ($y = 0; $y < $n; $y++) {
        for ($x = 0; $x < $n; $x++) {
            printf('%4s', $arr[$y][$x]);
        }
        echo PHP_EOL;
    }
}

Measured memory_bytes: 6652
#  =========     /\       /|    |====/|
#      |        /  \       |    |   / |
#      |       /____\      |    |  /  |
#      |      /      \     |    | /   |
#  ========= /        \  =====  |/====|  
#  code

def main():
    k = int(input())
    a , b = map(int , input().split())

    for i in range(a , b + 1):
        if i % k == 0:
            print('OK')
            return
    print('NG')
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 9072
import sys

input = sys.stdin.readline


def main():
    A, B, C, K = map(int, input().split())

    if K % 2 == 0:
        ans = A - B
    else:
        ans = B - A
    
    if ans > 10 ** 18:
        ans = "Unfair"
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
Parent = 0
Lchild = 1
Rchild = 2

def childs(n):
    return node[n][Lchild:Rchild+1]

def preorder(n):
    if n == -1: return []
    c1, c2 = childs(n)
    return [n] + preorder(c1) + preorder(c2)

def inorder(n):
    if n == -1: return []
    c1, c2 = childs(n)
    return inorder(c1) + [n] +inorder(c2)

def postorder(n):
    if n == -1: return []
    c1, c2 = childs(n)
    return postorder(c1) + postorder(c2) + [n]

n = int(input())
node = [[-1, -1, -1] for i in range(n)]
for i in range(n):
    j, e1, e2 = map(int, raw_input().split())
    if e1 != -1:
        node[j][Lchild] = e1
        node[e1][Parent] = j
    if e2 != -1:
        node[j][Rchild] = e2
        node[e2][Parent] = j
for root in range(n):
    if node[root][Parent] == -1: break

print 'Preorder'
print ' ' + ' '.join(map(str, preorder(root)))

print 'Inorder'
print ' ' + ' '.join(map(str, inorder(root)))

print 'Postorder'
print ' ' + ' '.join(map(str, postorder(root)))

Measured memory_bytes: 4284
n_str = int(input().strip())

str_dict = {}

for i in range(n_str):
    string = input().strip()
    sorted_str = ''.join(sorted(string))
    if sorted_str in str_dict:
        str_dict[sorted_str] += 1
    else:
        str_dict[sorted_str] = 1

num_pairs = 0
for value in str_dict.values():
    num_pairs += (value - 1) * value // 2

print(num_pairs)

Measured memory_bytes: 17892
from collections import Counter
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = set(A)
d = Counter(A)
num = len(B) - K
ans = 0
c = d.most_common()
for i in range(1, num+1):
    ans += c[-i][1]
print(ans)

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

struct node{
	unsigned int key;
	struct node *next;
	struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
	NodePointer cur = nil->next;
	while (cur != nil) {
		if (cur->key == key) break;
		cur = cur->next;
	}
	return cur;
}

void init(){
	nil = (NodePointer)malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	NodePointer cur = nil->next;
	int isf = 1;
	while (1){
		if (cur == nil) break;
		if (isf == 0)  printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
		isf = 0;
	}
	printf("\n");
}

void deleteNode(NodePointer t){
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	NodePointer t = nil->next;
	if (t == nil) return;
	deleteNode(t);
}

void deleteLast(){
	NodePointer t = nil->prev;
	if (t == nil) return;
	deleteNode(t);
}

void deleteKey(int key){
	NodePointer t = listSearch(key);
	if (t != nil) deleteNode(t);
}


void insert(int key){
	NodePointer x;
	x = (NodePointer)malloc(sizeof(struct node));
	x->key = key;
	x->prev = nil;
	x->next = nil->next;
	x->next->prev = x;
	nil->next = x;
}

int main(){
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++){
		scanf("%s%d", com, &key);
		if (com[0] == 'i') { insert(key); np++; size++; }
		else if (com[0] == 'd') {
			if (strlen(com) > 6){
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				deleteKey(key); nd++;
			}
			size--;
		}
	}

	printList();
	return 0;
}


Measured memory_bytes: 33020
#include<iostream>
using namespace std;
int main(void){
    long long N;
    long long l[90];
    cin>>N;
    l[0]=2;
    l[1]=1;
    for(int i = 2;i<=N;i++){
        l[i]=l[i-1]+l[i-2];
    }
    cout<<l[N]<<endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
n=0
b=0
for i in range(1,N):
  f=0
  l=0
  for j in range(i):
    f+=A[j]
  for k in range(i-1,N):
    l+=B[k]
  n=max(n,f+l)
for i in range(N):
  b+=B[i]
print(max(n,b+A[0]))

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

const int INF = 1001001001;

vector<int> to[2505];
vector<int> reto[2505];
bool reachableFromStart[2505];
bool reachableToGoal[2505];
bool ok[2505];

void dfs(int v) {
  if (reachableFromStart[v]) return;
  reachableFromStart[v] = true;
  for (int ne : to[v]) {
    dfs(ne);
  }
}

void redfs(int v) {
  if (reachableToGoal[v]) return;
  reachableToGoal[v] = true;
  for (int ne : reto[v]) {
    redfs(ne);
  }
}

int main() {
  int n, m, p;
  cin >> n >> m >> p;
  vector<tuple<int, int, int>> edges;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    c -= p;
    c = -c;
    edges.emplace_back(a, b, c);
    to[a].push_back(b);
    reto[b].push_back(a);
  }
  dfs(1);
  redfs(n);
  rep(i, n) ok[i+1] = reachableFromStart[i+1] & reachableToGoal[i+1];
  { // Bellman-Ford
    bool upd = true;
    vector<int> dist(n+1, INF);
    dist[1] = 0;
    int step = 0;
    while (upd) {
      upd = false;
      rep(i, m) {
        int a, b, c;
        tie(a, b, c) = edges[i];
        if (!ok[a]) continue;
        if (!ok[b]) continue;
        int newD = dist[a] + c;
        if (dist[b] > newD) {
          upd = true;
          dist[b] = newD;
        }
      }
      step++;
      if (step > n) {
        puts("-1");
        return 0;
      }
    }
    int ans = -dist[n];
    ans = max(0, ans);
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

int main(){
    int h,w;
    
    while(1){
        cin>>h>>w;
        if(h==0&&w==0) break;
        
        bool unti=false;

        REP(i,h){
            if(i%2==0){
                unti=false;
            }else{
                unti=true;
            }
            REP(j,w){
                if(unti==false){
                    cout<<'#';
                    unti=true;
                }else{
                    cout<<'.';
                    unti=false;
                }
                if(j==w-1){
                    cout<<endl;
                }
            }
        }

        cout<<endl;
    }


}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a , b , c;cin>>a>>b>>c;
    vector<int>v;
    v.push_back(a+b);
    v.push_back(a+c);
    v.push_back(c+b);
    sort(v.begin(),v.end());
    cout<<v[0]<<endl;

}


Measured memory_bytes: 256
NN = 2020202
MOD = 10**9+7
INF = float("inf")

n, p = map(int, input().split())
S = input()
pl = len(str(p))

if p == 2 or p == 5:
    count = 0
    for i in range(len(S)):
        if int(S[i])%p == 0:
            count += i+1
            # print(int(S[i]), count)

    print(count)

else:
    d = [0] * p
    d[0] = 1
    val = 0
    dec = 1

    for i in range(len(S)-1, -1, -1):
        val = (int(S[i])*dec+val)%p
        dec = (dec*10)%p
        d[val] += 1

    # print(d)
    ans = 0
    for e in d:
        ans += (e*(e-1))//2
    print(ans)


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const int MAXS = 24 * 60 * 60;

int n;
int imos[MAXS + 1];

int convert(string str){
    int hour = stoi(str.substr(0, 2));
    int min = stoi(str.substr(3, 2));
    int sec = stoi(str.substr(6, 2));
    // cout << hour << " " << min << " " << sec << endl;
    return hour * 60 * 60 + min * 60 + sec;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    while(1){
        cin >> n;
        if(n == 0) break;
        for(int i=0;i<=MAXS;i++){
            imos[i] = 0;
        }
        for(int i=0;i<n;i++){
            string str1, str2; cin >> str1 >> str2;
            int s = convert(str1);
            int t = convert(str2);
            imos[s]++;
            imos[t]--;
        }
        int ma = 0;
        for(int i=1;i<=MAXS;i++){
            imos[i] += imos[i-1];
            if(imos[i] > ma) ma = imos[i];
        }
        cout << ma << endl;
    }
}


Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n,k,a,b;
int p[200005];

int main() {
  cin >> n;
  rep(i,n) cin >> p[i];
  int mi=1e9,ans=0;
  rep(i,n){
    if(p[i]<=mi) ans++,mi=p[i];
  }
  cout << ans << endl;
}

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

int main(){
	int m,f,r;
	while(cin >> m >> f >> r){
		if(m == -1 && f == -1 && r == -1){
			break;
		}

		if(m == -1 || f == -1) cout << "F" << endl;
		else if(m+f >= 80) cout << "A" << endl;
		else if(m+f >= 65) cout << "B" << endl;
		else if(m+f >= 50) cout << "C" << endl;
		else if(m+f >= 30){
			if(r >= 50) cout << "C" << endl;
			else cout << "D" << endl;
		}
		else cout << "F" << endl;
	}
	return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

char maze[22][22];
int sx,sy;

void make_maze(int w,int h){
  rep(i,22)rep(j,22)maze[i][j]='#';
  rep(i,h)rep(j,w){
    cin>>maze[i][j];
    if(maze[i][j]=='@'){sy=i;sx=j;}
  }
  //rep(i,22){rep(j,22)cout<<maze[i][j];cout<<endl;}
}

void solve(int w,int h){
  queue<int> que;
  int cnt=0;
  que.push(sx);que.push(sy);
  while(que.size()){
    int x=que.front();que.pop();
    int y=que.front();que.pop();
    rep(i,4){
      if(maze[y+dy[i]][x+dx[i]]=='.'&&0<=x+dx[i]&&x+dx[i]<w&&0<=y+dy[i]&&y+dy[i]<h){
	cnt++;
	que.push(x+dx[i]);que.push(y+dy[i]);
	maze[y+dy[i]][x+dx[i]]='#';
      }
    }
  }
  cout<<cnt+1<<endl;
}

int main(){
  int w,h;
  while(cin>>w>>h){
    if(w==0&&h==0)break;
    make_maze(w,h);
    solve(w,h);
  }
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int t[100010];

int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(t,0,sizeof(t));
		rep(i,n){
			int h,m,s;
			scanf("%d:%d:%d",&h,&m,&s);
			t[h*3600+m*60+s]++;
			scanf("%d:%d:%d",&h,&m,&s);
			t[h*3600+m*60+s]--;
		}
		int res=t[0];
		rep(i,100000){
			t[i+1]+=t[i];
			maxch(res,t[i+1]);
		}
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//CODE
void solve(void)
{
  int A,B,X;
  cin>>A>>B>>X;
  if( A <= X && X <= A+B)
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
  
  

  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; i++)

using namespace std;

int main(void) {
	char dict[4] = {'S','H','C','D'};
	map<char, vector<int> > card_num;
	rep(i, 13) card_num['S'].push_back(0);
	rep(i, 13) card_num['H'].push_back(0);
	rep(i, 13) card_num['C'].push_back(0);
	rep(i, 13) card_num['D'].push_back(0);

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		char pattern;
		int number;
		cin >> pattern >> number;
		card_num[pattern][number-1]++;
	}
	
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 13; j++)
		{
			if (card_num[dict[i]][j] == 0)
			{
				cout << dict[i] << ' ' << j+1 << endl;
			}
		}
	}
}


Measured memory_bytes: 3128
a,b,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a)+min(b)
for i in range(m):
  x,y,c = map(int, input().split())
  ans = min(ans,a[x-1]+b[y-1]-c)
print(ans)

Measured memory_bytes: 18736
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
use std::cmp::Ordering;
 
use std::cmp;
use std::cmp::min;
use std::collections::BTreeMap;
use std::process;
use std::cmp::Ord;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BTreeSet;
use std::mem;
 
use std::ops::{Deref, DerefMut, Index, IndexMut};
use std::any::{Any, TypeId};


fn main(){
    input!{
        h:i64,
        w:i64,
        n:usize,
        sr:i64,
        sc:i64,
        s:chars,
        t:chars,
    }
    let mut flag = false;

    let mut now = sr;
    for i in 0..s.len(){
        if s[i] == 'U'{
            now -= 1;
        }
        if now <= 0{
            flag = true;
        }
        if t[i] == 'D' && now+1 <= h{
            now+=1;
        }
        
    }

    let mut now = sr;
    for i in 0..s.len(){
        if s[i] == 'D'{
            now += 1;
        }
        if now > h{
            flag = true;
        }
        if t[i] == 'U' && now -1 > 0{
            now-=1;
        }
        
    }

    let mut now = sc;
    for i in 0..s.len(){
        if s[i] == 'L'{
            now -= 1;
        }
        if now <= 0{
            flag = true;
        }
        if t[i] == 'R' && now+1 <= w{
            now+=1;
        }
        
    }

    let mut now = sc;
    for i in 0..s.len(){
        if s[i] == 'R'{
            now += 1;
        }
        if now > w{
            flag = true;
        }
        if t[i] == 'L' && now -1 > 0{
            now-=1;
        }
        
    }
    if flag{
        println!("NO");
    }
    else{
        println!("YES");
    }

}



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

int main(){
  int r, D;
  vector<long> x(11);
  cin >> r >> D >> x.at(0);
  
  for(int i=1; i<=10; i++){
    x.at(i)=r*(x.at(i-1))-D;
    cout << x.at(i) << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int X;
    int A;
    int B;
    cin >> X >> A >> B;
    if(A >= B){
        cout << "delicious" << endl;
    }else if(A + X >= B){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vsort(x) sort(x.begin(),x.end())

using namespace std;

int main() {

	int i, j;
	int n, k;
	int l[50];
	cin >> n >> k;
	rep(i, 0, n)
		cin >> l[i];
	sort(l, l + n);
	int ans = 0;
	rep(i, 0, k) {
		ans += l[n - 1 - i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}

vector<string> split(const string &str, char delim)
{
  istringstream iss(str); string tmp; vector<string> res;
  while(getline(iss, tmp, delim)) res.push_back(tmp);
  return res;
}

int main()
{
  string s;
  while(getline(cin,s))
  {
    stack<double> a;
    auto v = split(s,' ');
    for(auto c : v)
    {
      int n;
      if(sscanf(c.c_str(),"%d",&n)) a.push(n);
      else
      {
        double ans;
        double x = a.top(); a.pop();
        double y = a.top(); a.pop();
        switch(c[0])
        {
          case '+':
            ans=y+x;
            break;
          case '-':
            ans=y-x;
            break;
          case '*':
            ans=y*x;
            break;
          case '/':
            ans=1.0*y/x;
            break;
        }
        a.push(ans);
      }
    }
    printf("%.8lf\n",a.top());
  }
  return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

int isPrime(LL p){
	if(p<=1) return 0;
	if(p==2 || p==3 || p==5 || p==7) return 1;
	if(p==4 || p==6 || p==8 || p==9) return 0;

	LL i;
	int ret = 1;
	for(i=2; i*i<=p; i++){
		if(p%i==0 && i!=p){
			ret = 0;
			break;
		}
	}
	return ret;
}

LL calcd(map<LL, int> &mp){
	LL ret = 1;
	for(auto itr = mp.begin(); itr != mp.end(); itr++){
		int v = itr->second;
		ret *= (v+1);
	}
	return ret;
}

LL N;
vector<LL> spf;
void init(LL n){
	spf.assign(n+1, 0);
	for(LL i=0; i<=n; i++) spf[i] = i;
	for(LL i=2; i*i <=n; i++){
		if(spf[i] == i){
			for(LL j=i*i; j<=n; j+=i){
				if(spf[j] == j){
					spf[j] = i;
				}
			}
		}
	}
}

map<LL, int> get(LL n){
	map<LL, int> m;
	while(n != 1){
		m[spf[n]]++;
		n /= spf[n];
	}
	return m;
}
int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	init(N);

	LL ans = 0;
	for(LL i=1; i<N; i++){
		map<LL, int> mp = get(i);
		LL r = (LL)calcd(mp);
		ans += r;
	}
	printf("%lld\n", ans);
	return 0;

}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	string s;
	string t;
	cin>>s;
	cin>>t;
	int res = 0;
	for (int i = 0; i < 3; i++)
		res += s[i] == t[i];
	cout<<res;
}


Measured memory_bytes: 256
import Data.IORef
import Data.Array.IO
import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  prevRef <- newIORef 0
  as <- (map read . words) <$> getLine :: IO [Int]
  sum <- forM as $ \a -> do
    prev <- readIORef prevRef
    writeIORef prevRef (prev + a)
    return (prev + a)
  sumA <- newListArray (0, n - 1) sum :: IO (IOUArray Int Int)
  print =<< minimum <$> mapM (target sumA n) [0..n-2]

target :: IOUArray Int Int -> Int -> Int -> IO Int
target sumA n i = do
  y <- readArray sumA (n - 1)
  x <- readArray sumA i
  return $ abs (y - 2 * x)


Measured memory_bytes: 95612
{-# LANGUAGE PatternSynonyms #-}
module Main where
import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import qualified Data.Vector.Generic           as VG
import qualified Data.Vector.Generic.Mutable   as VGM
import           Data.Maybe
import Control.Monad as M
import Prelude as P
import qualified Data.List                     as L
-- http://hackage.haskell.org/package/massiv-0.4.5.0
import Data.Massiv.Array as A
import Data.Massiv.Array.Manifest.Vector
import Data.Sequence as Seq
import Debug.Trace

main :: IO ()
main = do
  [h, w] <- L.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  [ch, cw] <- L.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  [dh, dw] <- L.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  arr <- fromLists' Seq <$> M.replicateM h P.getLine :: IO (Array U Ix2 Char)
  marr <- A.thaw arr
  let start = Ix2 (ch-1) (cw-1)
  let goal = Ix2 (dh-1) (dw-1)
  let q = Seq.singleton (start, 0)
  ans <- bfs marr q goal
  arr' <- A.freeze Seq marr
  -- print arr'
  print ans

bfs :: MArray RealWorld U Ix2 Char -> Seq (Ix2, Int) -> Ix2 -> IO Int
bfs marr Empty goal = return (-1)
bfs marr ((cPos,c) :<| q) goal
  | cPos == goal = return c
  | otherwise = do
      -- print (cPos, c)
      -- check visited
      b <- isPath marr cPos
      if b
      then do
        A.write_ marr cPos '#'
        q' <- makeq marr q cPos c
        bfs marr q' goal
      else do
        bfs marr q goal

isPath :: MArray RealWorld U Ix2 Char -> Ix2 -> IO Bool
isPath m p = do
  x <- A.read m p
  case x of
    Nothing -> return False
    Just y -> return $ y == '.'

makeq :: MArray RealWorld U Ix2 Char -> Seq (Ix2, Int) -> Ix2 -> Int -> IO (Seq (Ix2, Int))
makeq m q pos cost = do
  walk' <- M.filterM (isPath m) $ P.map (pos+) walk
  warp' <- M.filterM (isPath m) $ P.map (pos+) warp
  return $ Seq.fromList (P.zip walk' $ repeat cost) >< q >< Seq.fromList (P.zip warp' $ repeat (cost + 1))

walk = [  1 :.  0
       , -1 :.  0
       ,  0 :.  1
       ,  0 :. -1
       ]

warp = [ Ix2 i j | i <- [-2..2], j <- [-2..2], abs i + abs j >= 2 ]

Measured memory_bytes: 59088
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int a=0;
    long long ans=0;
    for(int i=0;i<n-1;i++){
        if(s[i]=='A'){
            if(s[i+1]=='C')a=0;
            else a++;
        }
        if(s[i]=='B'){
            if(s[i+1]=='C')ans+=a;
            else a=0;
        }
        if(s[i]=='C' && s[i+1]=='C')a=0;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;



int main() {
	int *a=new int[5];
	for (int i = 0; i < 5;i++)cin >> a[i];
	int ans=0;
	int k=10;
	bool flag = true;
	for (int i = 0; i < 5;i++) {
		ans += a[i]-a[i]%10;
		if (a[i] % 10 != 0){
			flag = false;
			ans += 10;
			if (k > a[i] % 10) k = a[i] % 10;
		}
	}
	if (flag) {
		cout << ans << endl;
	}
	else {
		cout << ans-10+k << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;
int main() {
  cin >> s;
  i64 n = s.size();
  vector<array<i64, 51>> tab(n);
  for (i64 i = 0; i < n; ++i) {
    tab[i][0] = i + (s[i] == 'R' ? 1 : -1);
  }
  for (i64 k = 1; k <= 50; ++k) {
    for (i64 i = 0; i < n; ++i) {
      tab[i][k] = tab[tab[i][k - 1]][k - 1];
    }
  }
  vector<i64> res(n);
  for (i64 i = 0; i < n; ++i) res[tab[i][50]]++;
  for (i64 x : res) cout << x << ' ';
  cout << endl;
  return 0;
}


Measured memory_bytes: 41344
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define RG register
#define IL inline
#define inf 2147483640
#define LL long long
#define pi acos(-1.0)
#define db double
#define N 100005
using namespace std;
IL int gi()
{
	RG int res=0,w=1;
	RG char ch;
	for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
	if(ch=='-') w=-1,ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) res=10*res+ch-48;
	return res*w;
}
int n;
int ans=0;
int a[N],tong[N];
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	n=gi();
	for(RG int i=1;i<=n;++i)

		{
			a[i]=gi();
			tong[a[i]]+=1;
		}

	for(RG int i=0;i<=100000;++i)
		{
			if(i==0) ans=max(ans,tong[0]+tong[1]);
			else ans=max(ans,tong[i-1]+tong[i]+tong[i+1]);
		}

	printf("%d\n",ans);
	//fclose(stdin);fclose(stdout);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

     int n = sc.nextInt();
     String s = sc.next();
     int count=0;

     for (int i =0;i<n-2 ;i++ ) {
      String x = s.substring(i,i+3);
       if (x.equals("ABC")) {
         count++;
       }
     }
     System.out.println(count);
      }
    }


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\01.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;


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

    vector<int> koho;
    koho.push_back(1);
    koho.push_back(11);
    for (int i = 1; i <= 9; i++) {
        koho.push_back(111 * i);
    }

    int ans = *lower_bound(koho.begin(), koho.end(), n);

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


template <class Abel>
class BIT
{
public:
  using F=function<Abel(Abel,Abel)>;
  F f;
  int l;
  vector<Abel> bit;
  Abel m0;
  BIT(int maxidx,F fu,Abel m0):f(fu),l(maxidx),m0(m0)
  {
    bit.assign(l+1,m0);
  }
  void update(int idx,Abel val)
  {
    idx++;
    while(idx<=l)
    {
      bit[idx]=f(bit[idx],val);
      idx+=idx & -idx;
    }
  }
  Abel query(int idx)
  {
    Abel res=m0;
    while(idx>0)
    {
      res=f(bit[idx],res);
      idx-=idx& -idx;
    }
    return res;
  }
};


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  ll ng=0,ok=1e9;
  auto check=[&](ll num){
    auto b=a;
    rep(i,n){
      if(a[i]<=num)b[i]=1;
      else b[i]=-1;
    }
    vector<ll>sb(n+1,0);
    sb[0]=n;
    rep(i,n)sb[i+1]=sb[i]+b[i];
    BIT<ll> st(2*n,[](ll a,ll b){return a+b;},0LL);
    ll su=0;
    repi(i,0,n+1){
      //cout<<"sb "<<sb[i]<<endl;
      su+=st.query(sb[i]);
      st.update(sb[i],1);
      //cout<<"su "<<su<<endl;

    }
  //  cout<<num<<endl;
  //  cout<<su<<" "<<n*(n+1)/4<<endl;
    return su>n*(n+1)/4;

  };
  while(ok-ng>1){
    ll nn=(ok+ng)/2;
    if(check(nn))ok=nn;
    else ng=nn;
  }
  cout<<ok<<endl;
  return 0;

}


Measured memory_bytes: 4236
words = gets.chop.split(" ")

count = {}
max_len = 0
max_len_w = ""

for w in words
  count[w] = (count[w].nil?) ? 1 : count[w] + 1

  if max_len < w.length
    max_len = w.length
    max_len_w = w
  end
end

max_c = 0
max_c_w = ""

count.each do |k, c|
  if max_c < c
    max_c = c
    max_c_w = k
  end
end

puts [max_c_w, max_len_w].join(" ")

Measured memory_bytes: 6100
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

struct State {
  int from;
  int to;
  State(int f,int t)
    : from(f),to(t) {}
};

void matrix_pow(const bool lhs[101][101],const bool rhs[101][101],
                bool result_matrix[101][101],int length){
  bool tmp[101][101] = {};
  for(int i = 0; i < length; i++){
    for(int j = 0; j < length; j++){
      bool sum = false;
      for(int k = 0; k < length; k++){
        sum |= (lhs[i][k] && rhs[k][j]);
      }
      tmp[i][j] = sum;
    }
  }
  memcpy(result_matrix,tmp,sizeof(bool)*101*101);
}

void fast_pow(int n,int length,bool A[101][101],bool B[101][101]) {
  for(int i = 0; i < length; i++){
    B[i][i] = 1;
  }
  while(n > 0) {
    if (n & 1){
      matrix_pow(B,A,B,length);
    }
    matrix_pow(A,A,A,length);
    n >>= 1;
  }
}

int main(){
  int total_stations;
  int total_sections;
  int total_steps;
  while(~scanf("%d %d %d",
               &total_stations,
               &total_sections,
               &total_steps)){
    if(total_stations == 0 && total_sections == 0 && total_steps == 0) break;
    vector<int> edge[101];
    for(int section_i = 0; section_i < total_sections; section_i++){
      int src,dst;
      scanf("%d %d",&src,&dst);
      src--; dst--;
      edge[src].push_back(dst);
      edge[dst].push_back(src);
    }

    vector<State> states;
    states.push_back(State(-1,0));
    for(int from = 0; from < total_stations; from++){
      for(int i = 0; i < edge[from].size(); i++){
        int to = edge[from][i];
        states.push_back(State(from,to));
      }
    }

    bool init_matrix[101][101] = {};
    for(int y = 0; y < states.size(); y++){
      for(int x = 0; x < states.size(); x++){
        if(states[y].to == states[x].from
           && states[y].from != states[x].to){
          init_matrix[y][x] = true;
        }
      }
    }

    bool result_matrix[101][101] = {};
    fast_pow(total_steps,states.size(),init_matrix,result_matrix);

    bool isok = false;
    for(int i = 0; i < states.size(); i++){
      if(states[i].to == total_stations - 1 && result_matrix[0][i]){
        isok = true;
        break;
      }
    }
    printf("%s\n",isok ? "yes" : "no");
  }
}

Measured memory_bytes: 1240