akhauriyash/Code-Regression huggingface dataset:
// 2016/05/23 Tazoe

#include <iostream>
#include <list>
using namespace std;

int main()
{
	list<int> L;

	int n;
	cin >> n;

	for(int i=0; i<n; i++){
		char com[20];		// C?????????
		cin >> com;

		if(com[0]=='i'){
			int x;
			cin >> x;

			L.push_front(x);
		}
		else if(com[6]=='F'){
			L.pop_front();
		}
		else if(com[6]=='L'){
			L.pop_back();
		}
		else{
			int x;
			cin >> x;

			for(list<int>::iterator it=L.begin(); it!=L.end(); it++){
				if(*it==x){
					L.erase(it);
					break;
				}
			}
		}
	}

	for(list<int>::iterator it=L.begin(); it!=L.end(); it++){
		if(it!=L.begin()){
			cout << ' ';
		}
		cout << *it;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 32448
#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[200005];ll len,slen,tlen,sum[30][200005],nex[200005],l,r;
ll solve(ll now,int n)
{
	if(now<=len) return sum[n][now];
	ll f1=sum[n][slen],f2=sum[n][len],l1=slen,l2=len,tf,tl;
	while(l1+l2<now) tf=f2,tl=l2,f2+=f1,l2+=l1,f1=tf,l1=tl;
	return f2+solve(now-l2,n);
}
main()
{
	scanf("%s%lld%lld",s+1,&l,&r);len=strlen(s+1)/2;
	for(int i=2,j=0;i<=len;i++) 
	{
		while(j&&s[i]!=s[j+1]) j=nex[j];
		if(s[j+1]==s[i]) nex[i]=++j;
	}
	slen=len-nex[len];
	for(int i=0;i<26;i++) for(int j=1;j<=len;j++)
	{
		sum[i][j]=sum[i][j-1];
		if(s[j]-'a'==i) sum[i][j]++;
	}
	for(int i=0;i<26;i++) printf("%lld ",solve(r,i)-solve(l-1,i));
}

Measured memory_bytes: 42624
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
Int printX(Int r, Int D, Int X, int count){
    if(count == 10){
        return 0;
    }
    Int nextX = r*X - D;
    cout<< nextX <<endl;
    printX(r,D,nextX,count+1);

}

int myPow(int x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    return x * myPow(x, p-1);
}

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

    vi A = vi(N+1);
    vi B = vi(N+1);
    vi C = vi(N);

    REP(i,1,N+1){
        cin >> A[i];
    }
    REP(i,1,N+1){
        cin >> B[i];
    }
    REP(i,1,N){
        cin >> C[i];
    }


    Int ans = 0;
    Int before = 999;

    REP(i,1,N+1){
        ans += B[A[i]];
        if(before == A[i]-1){
            ans+=C[A[i]-1];
        }
        before = A[i];
    }


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>

const int N = 100000;

int n, a[N];

bool win(int x, int y)
{
    while (x + 1 < n && y + 1 < a[x + 1]) {
        x ++, y ++;
    }
    int up = a[x] - y & 1;
    int rt = true;
    while (x + 1 < n && y < a[x + 1]) {
        x ++, rt ^= 1;
    }
    return !(up && rt);
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
    }
    std::sort(a, a + n, std::greater<int>());
    puts(win(0, 0) ? "First" : "Second");
}


Measured memory_bytes: 512
/*
 * ITP1_7_C.cpp
 *
 *  Created on: 2016/05/21
 *      Author: suna
 */

#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int row;	//?????°
	int col;	//?????°

	//????????¬???????????????
	vector< vector<int> > sheet;

	//?????°????????°?????\???
	cin >> row >> col;

	//????????¬????????????????????????
	sheet.resize(row+1);
	for(int i = 0; i < row+1; i++)
	{
		sheet[i].resize(col+1);
	}

	//????????¬????????????????????????????????\???
	for(int i = 0; i < row; i++)
	{
		int sum_col = 0;
		for(int j = 0; j < col; j++)
		{
			cin >> sheet[i][j];
			sum_col += sheet[i][j];
		}
		sheet[i][col] = sum_col;
	}

	//???????????????????????????????¨?????¨????
	for(int j = 0; j <= col; j++)
	{
		int sum_row = 0;
		for(int i = 0; i < row; i++)
		{
			sum_row += sheet[i][j];
		}
		sheet[row][j] = sum_row;
	}

	//????????¬??????????????????????????????
	for(int i = 0; i < row+1; i++)
	{
		for(int j = 0; j < col+1; j++)
		{
			cout << sheet[i][j];
			if(j != col)
			{
				cout << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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



int main(){
    std::string s; std::cin >> s;
    long long cntA(0), ans(0);
    for(int i(0), i_len(s.length()); i < i_len; ++i){
        if(s[i] == 'A') ++cntA;
        else if(s[i] == 'B'){
            if(i < i_len-1 && s[i+1] == 'C'){
                ans += cntA; ++i;
            }else cntA = 0;
        }
        else if(s[i] == 'C') cntA = 0;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
template<typename T>
ostream& operator+(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out<<x<<" ";
    }
    out<<"\n";
    return out;
}
template<typename T>
ostream& operator*(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out+x;
    }
    return out;
}
template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}
const int p = 1e9 + 7;
ll modpower(ll base, ll power, ll mod=p){
    ll ans =1;
    base%=mod;
    while(power){
        if(power&1){
            ans*=base;
            ans%=mod;
        }
        base*=base;
        base%=mod;
        power>>=1;
    }
    return ans;
}
void solve(){
    int n;
    cin>>n;
    ll ans = modpower(10,n) - 2*modpower(9,n) + modpower(8,n);
    ans%=p;
    if(ans<0) ans+=p;
    cout<<ans<<'\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define pb      push_back
#define all(v)  v.begin(),v.end()
#define see(x)  cout<<#x<<" : "<<(x)<<endl;
#define ya      cout<<"Yes"<<endl;
#define no      cout<<"No"<<endl;
#define ff      first
#define sc      second
typedef long long ll;
typedef pair<ll,ll> pii;

int main()
{

    int c;
    cin>>c;
    if(c>=30)ya
        else no
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int MOD = 998244353;
int add(int x, int y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
int sub(int x, int y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
int mult(int x, int y) {
	return ((ll)x * y) % MOD;
}

map<string, int> dp1, dp2;

int solve1(string s);
int solve2(string s);

int solve1(string s) {
	if (dp1.count(s) > 0) return dp1[s];
	int res = 0;
	int n = s.length();
	for (int i = 0; i < n; i++)
		res = add(res, mult(solve1(s.substr(0, i)), solve2(s.substr(i, n - i))));
	dp1[s] = res;
	return res;
}

int solve2(string s) {
	if (dp2.count(s) > 0) return dp2[s];
	int res = 0;
	int n = s.length();
	for (int k = 1; k <= n / 2; k++) {
		if (n % k != 0) continue;
		string p = s.substr(0, k);
		for (int i = 0; i < n; i++)
			if (s[i] == '0')
				p[i % k] = '0';
		res = add(res, solve1(p));
	}
	dp2[s] = res;
	return res;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	dp1[""] = 1;
	dp2["0"] = 1;
	dp2["1"] = 2;

	string s;
	cin >> s;
	cout << solve1(s) << endl;

	return 0;
}


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

int main(){

	int n;
	cin >> n;
	int num[4];
	for(int i = 0;i < 4;i++){
		num[i] = n%10;
		n/=10;
	}
	if(num[0]==num[1] && num[1]==num[2])
		cout << "Yes"<<endl;
	else if(num[1]==num[2] && num[2]==num[3])
		cout << "Yes"<<endl;
	else cout << "No"<<endl; 
	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>


long int merge(long int a1[], long int a2[], long int b1[], long int b2[], long int a1_size, long int a2_size, long int b1_size, long int b2_size, long int a[], long int b[]);
long int mergeSort(long int a[], long int a_size, long int b[], long int b_size);

int main(void)
{
	long int n;
	long int i, j;
	long int work;
	long int a[200000];
	long int b[200000];
	
	scanf("%ld", &n);
	
	for(i = 0; i < n; i++) {
		scanf("%ld", &a[i]);
		b[i] = i + 1;
	}
	
	if(n <= 50) {
		for(i = 0; i < n - 1; i++) {
			for(j = 0; j < n - 1 - i; j++) {
				if(a[j] > a[j + 1]) {
					work = a[j];
					a[j] = a[j + 1];
					a[j + 1] = work;
					
					work = b[j];
					b[j] = b[j + 1];
					b[j + 1] = work;
				}
			}
		}
		
		for(i = 0; i < n; i++) {
			printf("%ld ", b[i]);
		}
		return 0;
	}
	
	mergeSort(a, n, b, n);
	
	for(i = 0; i < n; i++) {
		printf("%ld ", b[i]);
	}
	//printf("%ld", b[n - 1]);
	
	return 0;
}

long int merge(long int a1[], long int a2[], long int b1[], long int b2[], long int a1_size, long int a2_size, long int b1_size, long int b2_size, long int a[], long int b[])
{
	long int i = 0, j = 0;
	
	while( (i < a1_size ) || (j < a2_size) ) {
		if( (j >= a2_size ) || ( (i < a1_size) && (a1[i] < a2[j]) ) ) {
			a[i + j] = a1[i];
			b[i + j] = b1[i];
			i++;
		} else {
			if( (a1[i] == a2[j]) && (b1[i] > b2[j]) ) {
				//printf("Ok\n");
				a[i + j]  = a1[i];
				b[i + j]  = b1[i];
				i++;
			} else {
				a[i + j] = a2[j];
				b[i + j] = b2[j];
				j++;
			}
		}
	}
	
	return 0;
}

long int mergeSort(long int a[], long int a_size, long int b[], long int b_size)
{
	long int m = a_size / 2, n = a_size - m;
	long int a1[m];
	long int a2[n];
	long int b1[m];
	long int b2[n];
	long int i, j;
	
	if(a_size > 1) {
		for(i = 0; i < m; i++) {
			a1[i] = a[i];
			b1[i] = b[i];
		}
		for(i = 0; i < n; i++) {
			a2[i] = a[m + i];
			b2[i] = b[m + i];
		}
		mergeSort(a1, m, b1, m);
		mergeSort(a2, n, b2, n);
		merge(a1, a2, b1, b2, m, n, m, n, a, b);
	}
	
	return 0;
}


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

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    int a, b;
    cin >> a >> b;

    if(b >= a){
        cout << a;
    }else{
        cout << a - 1;
    }

    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main()
{
    int N,K;
    cin >> N >> K;
    set<int> f;
    for(int i=0;i<K;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            int k;
            cin >> k;
            f.insert(k); 
        }
    }

    cout << N - f.size() ;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstring>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;
const double PI=acos(-1);
struct Point{
	double x,y;
};
void koch(int n,Point a,Point b)
{
	if(n==0)
	return ;
	Point s,t,u;
	double th=PI*60.0/180.0,r;
	s.x=(2.0*a.x+1.0*b.x)/3;
	s.y=(2.0*a.y+1.0*b.y)/3;
	t.x=(1.0*a.x+2.0*b.x)/3;
	t.y=(1.0*a.y+2.0*b.y)/3;
	 u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
      koch(n - 1, a, s);
    printf("%.8lf %.8lf\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8lf %.8lf\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8lf %.8lf\n", t.x, t.y);
    koch(n - 1, t, b);
}
int main()
{
	Point a,b;
	int n;
	cin>>n;
	a.x=0;
	a.y=0;
	b.x=100;
	b.y=0;
	printf("%.8lf %.8lf\n",a.x,a.y);
	koch(n,a,b);
    printf("%.8lf %.8lf\n",b.x,b.y);
return 0;
 } 


Measured memory_bytes: 3312
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> V(n);
    rep(i, n) cin >> V[i];

    ll ma = -1;
    for (int left = 0; left <= k; left++){
        for (int right = 0; left+right <= k ; right++){
            if (left + right > n) continue;

            ll total = 0LL;
            priority_queue<int, vector<int>, greater<int> > que;
            int res = k - (left + right);

            for (int i = 0; i < left; i++){
                if (V[i] >= 0) total += V[i];
                else que.push(V[i]),total+=V[i];
            }
            for (int i = 0; i < right; i++){
                if (V[n-1-i] >= 0)total += V[n-1-i];
                else que.push(V[n-1-i]), total+=V[n-1-i]; 
            }
            rep(i,res)
                if(que.size()!=0) {
                    total+=-que.top();
                    que.pop();
                }
            
            ma = max(ma, total);
        }
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int y = stoi(s.substr(0,2));
	int m = stoi(s.substr(2,2));
	if(m > 0 && m <= 12) {
		if(y > 0 && y <= 12) { 
			cout << "AMBIGUOUS" << endl;
			return 0;
		}
		cout << "YYMM" << endl;
	}
	else if (y > 0 && y <= 12) cout << "MMYY" << endl;
	else cout << "NA" << endl;
	return 0;
}

Measured memory_bytes: 3604
def number_of_inv(A, n):
    cnt = 0

    def merge(A, left, mid, right):
        L = A[left:mid]
        R = A[mid:right]
        n = right - left
        n1 = mid - left
        C = [0] * n
        L.append(float('inf'))
        R.append(float('inf'))
        i = 0
        j = 0
        nonlocal cnt
        for k in range(left, right):
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                cnt += n1 - i
                j += 1
        return cnt

    def merge_sort(A, left, right):
        if left+1 < right:
            mid = (left + right) >> 1
            merge_sort(A, left, mid)
            merge_sort(A, mid, right)
            return merge(A, left, mid, right)
    
    if len(A) == 1:
        return 0
    else:
        return merge_sort(A, 0, n)

n = int(input())
A = [int(i) for i in input().split()]
print(number_of_inv(A, n))


Measured memory_bytes: 27484
const main = input => {
  const D = input.trim()
  if (D === '25') {
    console.log('Christmas')
  } else if (D === '24') {
    console.log('Christmas Eve')
  } else if (D === '23') {
    console.log('Christmas Eve Eve')
  } else if (D === '22') {
    console.log('Christmas Eve Eve Eve')
  }
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, a;
	cin >> n >>a;
	
	int p=n%500;
	if(p > a) puts("No");
	else puts("Yes");
	return 0;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,m,a[200009];
	string s;
	cin>>n>>m;
  	cout<<n*m;
	return 0;
}

Measured memory_bytes: 3640
n = int(input())
c = 100000000000000000
for i in range(1,int(n/2)+2):
    a = list(str(i))
    b = list(str(n-i))
    a1 = [int(s) for s in a]
    b1 = [int(s) for s in b]
    if sum(a1) + sum(b1) < c:
        c = sum(a1) + sum(b1)

print(c)

Measured memory_bytes: 42600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, sum;
  cin >> N;
  sum = 0;
  for(int i=0; i<N; i++){
    int li, ri;
    cin >> li >> ri;
    sum += ri-li+1;
    
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List.Split

solve :: [[Int]] -> Int -> Int
solve [] n     = n
solve ([a,b]:xs) n
	| n == a = solve xs b
	| n == b = solve xs a
	| otherwise = solve xs n

main = do
	w <- readLn :: IO Int
	n <- readLn
	lines <- replicateM n (map (read :: String -> Int) . splitOn "," <$> getLine)
	
	mapM_ print $ map (solve (reverse lines)) [1..w]

Measured memory_bytes: 4184
#include <stdio.h>

int s(int, int, int, int map[10][10]);
int m(int, int, int, int map[10][10]);
int l(int, int, int, int map[10][10]); 


main(){
  int map[10][10], size, i, j, max, ans, x, y;

  for(i=0;i<10;i++){
    for(j=0;j<10;j++){
      map[i][j]=0;
    }
  }

  max=-1;
  ans=0;
  
  while(1){
    if(scanf("%d,%d,%d", &x, &y, &size)==EOF){
      for(i=0;i<10;i++){
	for(j=0;j<10;j++){
	  if(map[i][j]==0) ans++;
	}
      }
      printf("%d\n%d\n", ans, max);
      break;
    }

    if(size==1) max=s(x,y,max,map);
    else if(size==2) max=m(x,y,max,map);
    else max=l(x,y,max,map);
  }
  return 0;
}



int s(int x, int y, int max, int map[10][10]){
  int i, j;
  int d1[5]={0,0,-1,0,1}, d2[5]={0,-1,0,1,0};

  for(i=0;i<5;i++){
    if(d1[i]+x<0 || d1[i]+x>9 || d2[i]+y<0 || d2[i]+y>9) continue;
    else{
      map[d1[i]+x][d2[i]+y]++;
      if(max<map[d1[i]+x][d2[i]+y]) max=map[d1[i]+x][d2[i]+y];
    }
  }
  return max;
}

int m(int x, int y, int max, int map[10][10]){
  int i, j;
  int d1[9]={0,0,-1,-1,-1,0,1,1,1}, d2[9]={0,-1,-1,0,1,1,1,0,-1};

  for(i=0;i<9;i++){
    if(d1[i]+x<0 || d1[i]+x>9 || d2[i]+y<0 || d2[i]+y>9) continue;
    else{
      map[d1[i]+x][d2[i]+y]++;
      if(max<map[d1[i]+x][d2[i]+y]) max=map[d1[i]+x][d2[i]+y];
    }
  }
  return max;
}

int l(int x, int y, int max, int map[10][10]){
  int i, j;
  int a, b;
  int d1[13]={0,0,-1,-1,-1,0,1,1,1,0,-2,0,2}, d2[13]={0,-1,-1,0,1,1,1,0,-1,-2,0,2,0};

  for(i=0;i<13;i++){
    a=d1[i]+x;
    b=d2[i]+y;
    if(a<0 || a>9 || b<0 || b>9) continue;
    else{
      map[a][b]++;
      if(max<map[a][b]) max=map[a][b];
    }
  }
  return max;
}

Measured memory_bytes: 0
n,q = map(int,input().split())
s = input()
ac = [0]
cnt = 0
for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        cnt += 1
    ac.append(cnt)
for i in range(q):
    a,b = map(int,input().split())
    print(ac[b-1]-ac[a-1])



Measured memory_bytes: 6100
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;
vector<P> vec[200010], peo[200010];
ll bit[100010], num;
ll par[100010], sz[100010];
ll n, a[100010];
map<ll, ll> mp;
map<P, ll> NP;
vector<P> road[100010];
bool flg[100010];

struct edge { ll to, cost; };
ll V;
vector<edge> G[300010];
ll d[300010];

ll root(int x) { // �f�[�^x��������؂̍����ċA�œ���Froot(x) = {x�̖؂̍�}
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

void unite(int x, int y) { // x��y�̖؂𕹍�
	int rx = root(x); //x�̍���rx
	int ry = root(y); //y�̍���ry
	if (rx == ry) return; //x��y�̍�������(=�����؂ɂ���)���͂��̂܂�
	par[rx] = ry; //x��y�̍��������łȂ�(=�����؂ɂȂ�)���Fx�̍�rx��y�̍�ry�ɂ���
}

bool same(int x, int y) { // 2�̃f�[�^x, y��������؂������Ȃ�true��Ԃ�
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}

void dijkstra(ll s)
{
	priority_queue<P, vector<P>, greater<P>> que;
	for (int i = 0; i <= 300010; i++)
	{
		d[i] = INF;
	}
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (ll i = 0; i < G[v].size(); i++)
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	cin >> n;
	bool jud = true;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] != 0)
		{
			jud = false;
		}
		mp[a[i]]++;
	}
	if (jud)
	{
		cout << "Yes" << endl;
		return 0;
	}
	if (mp.size() == 2)
	{
		ll A[4], i = 0, B[4];
		for (auto itr = mp.begin(); itr != mp.end(); ++itr)
		{
			A[i] = itr->first;
			B[i] = itr->second;
			i++;
		}
		if (A[0] == 0)
		{
			if (B[0] * 2 >= B[1] && B[0] <= B[1])
			{
				cout << "Yes" << endl;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else if (A[1] == 0)
		{
			if (B[1] * 2 >= B[0] && B[1] <= B[0])
			{
				cout << "Yes" << endl;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else
		{
			cout << "No" << endl;
		}
		return 0;
	}
	if (mp.size() != 3)
	{
		cout << "No" << endl;
		return 0;
	}
	ll A[4], i = 0, B[4];
	for (auto itr = mp.begin(); itr != mp.end(); ++itr)
	{
		A[i] = itr->first;
		B[i] = itr->second;
		i++;
	}

	if ((A[0] ^ A[1]) == A[2] && B[0] == B[1] && B[1] == B[2])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	int www;
	cin >> www;
}


Measured memory_bytes: 27392
#include<stdio.h>
#include<string.h>

int main(void){
  char input[6];
  int i;
  
  scanf("%s",input);
  
  if(input[2]==input[3]){
    if(input[4]==input[5]){
      printf("Yes");
    }else{
      printf("No");
    }
  }else{
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
import heapq


def solve(N, v):
    h = v[:]
    heapq.heapify(h)
    while len(h) > 1:
        x = heapq.heappop(h)
        y = heapq.heappop(h)
        #print(x, y)
        heapq.heappush(h, (x + y) / 2)
    return h[0]


def main():
    N = int(input())
    v = [int(x) for x in input().split()]
    print(solve(N, v))


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e6;
const int inf=1e9;
int main(){
	int N,C;cin>>N>>C;
	int D[C][C];
	rep(i,0,C)rep(j,0,C){
		cin>>D[i][j];
	}
	int c; int cnt[3][C];
    rep(i,0,3)rep(j,0,C) cnt[i][j]=0;
	rep(i,0,N)rep(j,0,N){
		cin>>c; c--;
		cnt[(i+j)%3][c]++;
	}
	int ans=inf;
	rep(i,0,C)rep(j,0,C){
        if(j==i) continue;
        rep(k,0,C){
            if(k==i||k==j) continue;
            int sum=0;
            rep(l,0,C){
                sum+=cnt[0][l]*D[l][i];
                sum+=cnt[1][l]*D[l][j];
                sum+=cnt[2][l]*D[l][k];
            }ans=min(ans,sum);
        }
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
const int MAXN = 100000+1;
using namespace std;
int main(){
    int N;
    long long K;
    vector<long long> mo(MAXN,0);
    cin>>N>>K;
    REP(i,N){
        long long a,b;
        cin>>a>>b;
        mo[a]+=b;
    }
    REP(i,MAXN){
        if(K-mo[i]<=0){
            cout<<i<<endl;
            return 0;
        } else {
            K-=mo[i];
        }
    }
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  ll alice = 0, bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0)
      alice += a[i];
    else
      bob += a[i];
  }
  cout << alice - bob << endl;
  return 0;
}

Measured memory_bytes: 3612
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = decimal.Parse(Console.ReadLine());

            if (N == 1)
            {
                Console.WriteLine(0);
                return;
            }

            Console.WriteLine(Math.Floor((0.5m * N * (N + 1)) - N));
        }
    }
}


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

int main()
{
    long long n;
    cin>>n;
    long long a[n],b[n],c[n],a1[n],b1[n],c1[n];
    for(long long i=0;i<n;i++)
    {
        cin>>a[i];    
    }
    for(long long j=0;j<n;j++)
    {
            cin>>b[j];
    }
    for(long long j=0;j<n;j++)
    {
            cin>>c[j];
    }
    sort(a,a+n);sort(b,b+n);sort(c,c+n);
    for(long long i=0;i<n;i++)
    {
       
        
        if(i==0)
        { a1[i]=0;
            long long cz=0;
            while(b[i]>a[cz]&&cz<n)
            {
                cz++;a1[i]++;
            }
        }
        else
        { a1[i]=a1[i-1];
            long long cz=a1[i-1];
             while(b[i]>a[cz]&&cz<n)
            {
                cz++;a1[i]++;
            }
        }
    }
    for(long long i=0;i<n;i++)
    {
       
        
        if(i==0)
        { b1[i]=0;
            long long cz=0;
            while(c[i]>b[cz]&&cz<n)
            {
                cz++;b1[i]++;
            }
        }
        else
        { b1[i]=b1[i-1];
            long long cz=b1[i-1];
             while(c[i]>b[cz]&&cz<n)
            {
                cz++;b1[i]++;
            }
        }
    }
    long long ans=0;
    
     for(long long i=0;i<n;i++)
    {//cout<<a1[i]<<b1[i]<<endl;
       if(i==0)
       {
           c1[i]=a1[i];
       }
       else{
           c1[i]=c1[i-1]+a1[i];
           
       }
    }
    for(long long i=0;i<n;i++)
    {
        long long h=b1[i]-1;
       if(h>=0&&h<n)ans+=c1[h];
       else if(h>=n)ans+=c1[n-1];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s;
int ans = INF;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> s;
    int n = s.size();
    for (char c = 'a'; c <= 'z'; c++) {
        int mx = 0, cnt = 0;
        rep(i, 0, n) {
            if (s[i] != c) cnt++;
            else cnt = 0;
            mx = max(mx, cnt);
        }
        ans = min(ans, mx);
    }
    printf("%d\n",ans);
    return 0;
}


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

void swap(int &a, int &b){
	int tmp = a;
	a = b;
	b = tmp;
	return;
}

void maxHeapify(vector<int> &A, int i){
	int l = 2 * i + 1;
	int r = 2 * i + 2;
	int largest;
	if (l < A.size() && A[l] > A[i]){
		largest = l;
	}
	else{
		largest = i;
	}
	if (r < A.size() && A[r] > A[largest]){
		largest = r;
	}

	if (largest != i){
		swap(A[i], A[largest]);
		maxHeapify(A, largest);
	}
}

void buildMaxHeap(vector<int> &A){
	for (int i = A.size() / 2 - 1; i >= 0; i--){
		maxHeapify(A, i);
	}
}

int main(){
	int H;
	cin >> H;
	vector<int> A(H, 0);
	for (int i = 0; i < H; i++) cin >> A[i];

	buildMaxHeap(A);

	for (int i = 0; i < H; i++) cout << " " << A[i];
	cout << endl;

	return 0;
}


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


const int upper = 100001;
vector<int> color(upper, -1);
vector<pair<long long, int> > adj[upper];


void dfs(int source, int dist, int parent = 0)
{
    if(parent == 0)
    {
        color[source] = 0;
    }
    else if(dist%2 == 0)
    {
        color[source] = color[parent];
    }
    else
    {
        color[source] = 1 - color[parent];
    }
    for(auto child:adj[source])
    {
        if(color[child.second] == -1)
        {
            dfs(child.second, child.first, source);    
        }
    }
}
int main()
{
    int n;
    cin >> n;
    for(int i = 0;i < n-1;i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        adj[u].emplace_back(w,v);
        adj[v].emplace_back(w,u);
    }
    dfs(1, 0);
    color[0] = 0;
    for(int i =1;i <= n;i++)
    {
        cout << color[i] << endl;
    }
    
    
    
    
    return 0;
}


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

int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  int nx=sx,ny=sy;
  string ans="R";
  nx++;
  while(nx!=tx){
    nx++;
    ans+="R";
  }
  while(ny!=ty){
    ny++;
    ans+="U";
  }
  nx--;
  ans+="L";
  while(nx!=sx){
    nx--;
    ans+="L";
  }
  while(ny!=sy){
    ny--;
    ans+="D";
  }
  //cout << ans << endl;
  ny--;
  ans+="D";
  while(nx!=tx+1){
    nx++;
    ans+="R";
  }
  while(ny!=ty){
    ny++;
    ans+="U";
  }
  nx--;
  ny++;
  ans+="LU";
  while(nx!=sx-1){
    nx--;
    ans+="L";
  }
  while(ny!=sy){
    ny--;
    ans+="D";
  }
  ans+="R";
  cout << ans << endl;
  return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;

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

	if(n == 7 || n == 5 || n== 3){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}





    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    long long int a,b,c,n,ans;
    ans = 0;
    string s;
    cin >> s;
    for(int i=0;i<4;i++){
        n=0;
        for(int j=0;j<4;j++){
            if(s.at(i)==s.at(j))n++;
        }
        if(n==2)ans++;
    }
    if(ans==4)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
  //2の累乗でN以下の最も大きいものを選ぶ
  //N=1のときは1と出力
  int N;
  cin>>N;
  
  int i=1;
  while(i<=N){
    i*=2;}
  i=i/2;
  
  if(N==1){cout<<1<<endl;}
   else {cout<<i<<endl;}

  return 0;}
  

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end


vector<int> g[201010];
int cnt[201010][2]={};

int main(){
   int n,m; cin>>n>>m;
   string s; cin>>s;
   rep(i,0,m){
      int x,y; cin>>x>>y; x--; y--;
      g[x].push_back(y); g[y].push_back(x);
      cnt[x][s[y]-'A']++; cnt[y][s[x]-'A']++;
   }
   set<int> used; queue<int> que;
   rep(i,0,n)if(cnt[i][0]==0 or cnt[i][1]==0){
      used.insert(i); que.push(i);
   }
   while(!que.empty()){
      int x=que.front(); que.pop();
      for(int y:g[x])if(!used.count(y)){
         cnt[y][s[x]-'A']--;
         if(cnt[y][s[x]-'A']==0){
            used.insert(y); que.push(y);
         }
      }
   }
   printf(used.size()==n?"No\n":"Yes\n");
   return 0;
}

Measured memory_bytes: 20868
L = input()
MOD = 10 ** 9 + 7

dp = [[0, 0] for _ in range(100005)]
dp[0][0] = 1

n = len(L)
for i in range(n):
  if L[i] == "0":
    dp[i + 1][0] = dp[i][0]
    dp[i + 1][1] = dp[i][1]
  else:
    dp[i + 1][1] = (dp[i][0] + dp[i][1]) % MOD

  if L[i] == "0":
    dp[i + 1][1] += dp[i][1] * 2 % MOD
  else:
    dp[i + 1][0] += dp[i][0] * 2 % MOD
    dp[i + 1][1] += dp[i][1] * 2 % MOD

ans = (dp[n][0] + dp[n][1]) % MOD
print(ans)

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

#define d first
#define t second

const long long inf = 100000000000000037;
const int maxn = 100005;

int n, k;
long long s, x, ans = -inf;
pair < int, int > lose;
pair < int, int > sushi[maxn];
multiset < pair < int, int > > cands;
map < int, multiset < int > > cnt;

bool cmp (pair < int, int > a, pair < int, int > b) {
	return a.d > b.d;
}

signed main () {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i)
		scanf("%d %d", &sushi[i].t, &sushi[i].d);
	sort(sushi, sushi + n, cmp);
	for (int i = 0; i < k; ++i) {
		cnt[sushi[i].t].insert(sushi[i].d);
		s += sushi[i].d, x = cnt.size();
		ans = max(ans, s + x * x);
	}
	for (int i = 0; i < k; ++i) {
		if (int(cnt[sushi[i].t].size()) >= 2)
			cands.insert(sushi[i]);
	}
	for (int i = k; i < n && !cands.empty(); ++i) {
		if (cnt.find(sushi[i].t) == cnt.end()) {
			cnt[sushi[i].t].insert(sushi[i].d);
			lose = *cands.begin();
			s += sushi[i].d - lose.d, ++x;
			if (int(cnt[lose.t].size()) == 2) {
				for (auto taste: cnt[lose.t])
					cands.erase(make_pair(taste, lose.t));
				cnt[lose.t].clear();
			}
			else {
				cands.erase(cands.begin());
				cnt[lose.t].erase(cnt[lose.t].find(lose.d));
			}
			ans = max(ans, s + x * x);
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<ll> data(n);
  ll ans = 0;
  REP(i, n) { cin >> data[i]; }
  ll tmp = 0;
  REP(i, n) {
    if (data[i] == 0) {
      ans += tmp / 2;
      tmp = 0;
    } else {
      tmp += data[i];
    }
  }
  ans += tmp / 2;
  cout << ans << endl;
}

Measured memory_bytes: 4032
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();
        A-=K;
        if(A < 0){
        	B += A;
        	A = 0;
        }
        if(B < 0){
        	B = 0;
        }
        sc.close();
        System.out.println(A +" " + B);
    }

}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

string padding(string s) {
    if (s.size() == 1) return "0"  + s;
    return s;
}

string conv(int t) {
    string ss = padding(to_string(t % 60)); t /= 60;
    string mm = padding(to_string(t % 60)); t /= 60;
    string hh = padding(to_string(t));
    return hh + ":" + mm + ":" + ss;
}

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

    const int T = 12*3600;

    int n;
    while (cin >> n, n) {
        vvi cnt(n, vi(T + 1));
        rep(id, n) {
            vi v(3);
            rep(j, 3) cin >> v[j];
            rep(f, 60) {
                sort(all(v));
                vi u = v;
                do {
                    if (u[0] % 5 == u[1] / 12) {
                        cnt[id][3600*(u[0]/5)+60*u[1]+u[2]]++;
                    }
                } while (next_permutation(all(u)));
                rep(j, 3) v[j] = (v[j] + 1) % 60;
            }
        }

        rep(id, n) rrep(t, T) cnt[id][t] += cnt[id][t+1];

        auto existAll = [&](int l, int r) {
            rep(id, n) {
                if (cnt[id][l] - cnt[id][r] == 0) {
                    return false;
                }
            }
            return true;
        };

        int mi = inf;
        int arg_l, arg_r;
        int r = 1;
        rep(l, T) {
            while (r < T && !existAll(l, r)) {
                r++;
            }
            if (r == T) break;
            if (mi > r - l) {
                mi = r - l;
                arg_l = l;
                arg_r = r;
            }
        }

        cout << conv(arg_l) << " " << conv(arg_r - 1) << endl;
    }

}

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

int main() {
  int n,d;
  int ans=0;
  cin>>n>>d;
  vector<vector<int>>x(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>x[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int p=0;
      for(int k=0;k<d;k++) p+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      for(int k=1;k<=p;k++){
        if(k*k==p) ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    int a,b;
    char op;
    while(op !='?'){
        cin>>a>>op>>b;
        switch (op){
            case'+':
            cout<<a+b<<endl;
            break;
            case'/':
            cout<<a/b<<endl;
            break;
            case'-':
            cout<<a-b<<endl;
            break;
            case'*':
            cout<<a*b<<endl;
            break;
        }
    }
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n, m; cin >> n >> m;
	priority_queue<int> A;
	for (int i=0; i<n; i++) {
		int a; cin >> a;
		A.push(a);
	}
	for (int i=0; i<m; i++) {
		int h = A.top();
		A.pop();
		A.push(h/2);
	}
	ll ret = 0;
	for (int i=0; i<n; i++) {
		ret += A.top();
		A.pop();
	}
	cout << ret << endl;
	return 0;
}

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

using namespace std;

const int MOD = 1000000007;

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<ll,ll> pll;

ll add(ll x, ll y) {
  x %= MOD;
  y %= MOD;
  return (x + y) % MOD;
}

ll mul(ll x, ll y) {
  x %= MOD;
  y %= MOD;
  return (x * y) % MOD;
}

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

  vector<vector<int>> edges(n + 1, vector<int> ());
  for(int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
/*
  for(int i = 1; i <= n; ++i) {
    cout << i << " ->";
    for(int x: edges[i]) cout << " " << x;
    cout << endl;
  }
*/

  queue<int> q;
  while(!q.empty()) q.pop();

  vector<int> color(n + 1, -1);

  int start = n;
  q.push(start);
  color[start] = k;

  while(!q.empty()) {
    int qf = q.front(); q.pop();

    int cnt = 0;
    for(int i = 0; i < edges[qf].size(); ++i) {
      int x = edges[qf][i];
      if(color[x] >= 0) {
        ++cnt;
      }
    }

    int hit = 1;
    for(int i = 0; i < edges[qf].size(); ++i) {
      int x = edges[qf][i];
      if(color[x] == -1) {
        q.push(x);
        int nc = k - cnt - hit;
        color[x] = max(0, nc);
        ++hit;
      }
    }
  }

  //cout << endl; for(int i = 1; i <= n; ++i) cout << i << " " << color[i] << endl; cout << endl;
  ll ans = 1ll;
  for(int i = 1; i <= n; ++i) {
    ans = mul(ans, color[i]);
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 6904
#include<stdio.h>
int main(){
    int map[8]={3,3,3,3,3,4,3,4};
    char asc[5]={'.',',','!','?',' '};
    int i,j,c;
    int cnt,sum;
    char out;
    char str[1050];
    int a,k;
    scanf("%d",&a);
    for(k=0;k<a;k++){
        scanf("%s",str);
        i=0;
        while(1){
            while(str[i]=='0'){
                i++;
            }
            if(str[i]=='\0'){
                break;
            }
            cnt=-1;
            while(str[i]!='0'){
                cnt++;
                i++;
            }
            c=(int)(str[i-1]-'0');
            if(c==1){
                out=asc[cnt%5];
            }else{
                sum=0;
                for(j=0;j<c-2;j++){
                    sum+=map[j];
                }
                out=('a')+sum+((cnt)%map[c-2]);
            }
            printf("%c",out);
        }
        printf("\n");
    }
    return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S; cin >> S;
  string ans;
  for(auto&& c: S){
	if(c == 'B'){
	  if(!ans.empty())
		ans.pop_back();
	}
	else
	  ans.PB(c);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, m, a[1005], sum = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (4 * m * a[i] >= sum)
            count++;
    }
    if (count >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end
local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local invs = {}
for i = 1, 1000 * 1000 + 1 do
  invs[i] = modinv(i)
end

local r1, c1 = io.read("*n", "*n")
local r2, c2 = io.read("*n", "*n")
local function getSum(r, c)
  local sum = 0
  local cur = 1
  for ir = 0, r do
    cur = bmul(cur, ir + c + 1)
    cur = bmul(cur, invs[ir + 1])
    sum = badd(sum, cur)
  end
  return sum
end
local z = getSum(r2, c2)
z = bsub(z, getSum(r2, c1 - 1))
z = bsub(z, getSum(r1 - 1, c2))
z = badd(z, getSum(r1 - 1, c1 - 1))
print(z)


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

int main(){
    int x, y, z, k, i, j;
    cin >> x >> y >> z >> k;
    long long a[x], b, d[x*y]={}, e[k*z]={};
    for(i=0; i<x; i++){
        cin >> a[i];
    }
    for(i=0; i<y; i++){
        cin >> b;
        for(j=0; j<x; j++){
            d[x*i+j] = a[j]+b;
        }
    }
    sort(d, d+x*y, greater<long long>());
    for(i=0; i<z; i++){
        cin >> b;
        for(j=0; j<k && j<x*y; j++){
            e[k*i+j] = d[j]+b;
        }
    }
    sort(e,e+z*k, greater<long long>());
    for(i=0; i<k; i++){
        cout << e[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 31616