akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
	aa,bb=map(int,input().split())
	a.append(aa)
	b.append(bb)
for i in range(m):
	cc,dd=map(int,input().split())
	c.append(cc)
	d.append(dd)
for i in range(n):
	dis=[]
	for j in range(m):
		dis.append(abs(a[i]-c[j])+abs(b[i]-d[j]))
	for j in range(m):
		if min(dis)==dis[j]:
			print(j+1)
			break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e6+1;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n, k;
	cin >> n >> k;
	int a[n], ans = 2e9;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	for (int i = k - 1; i < n; i++)
		ans = min(ans, a[i] - a[i - k + 1]);
	cout << ans;
	return 0;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;

    vector<ll> from_xs(n, INF), from_ys(n, INF);
    {
        from_xs[x] = 0;
        from_xs[y] = 1;
        rep(i, n) {
            if (i == 0) continue;
            cmin(from_xs[i], from_xs[i - 1] + 1);
        }
        rep(i, n) {
            if (i == 0) continue;
            ll j = n - 1 - i;
            cmin(from_xs[j], from_xs[j + 1] + 1);
        }
    }
    {
        from_ys[x] = 1;
        from_ys[y] = 0;
        rep(i, n) {
            if (i == 0) continue;
            cmin(from_ys[i], from_ys[i - 1] + 1);
        }
        rep(i, n) {
            if (i == 0) continue;
            ll j = n - 1 - i;
            cmin(from_ys[j], from_ys[j + 1] + 1);
        }
    }


    vector<ll> ans(n - 1);

    rep(i, n) {
        rep(j, n) {
            if (i <= j) continue;
            ll direct = abs(i - j);
            ll via_x = from_xs[i] + from_xs[j];
            ll via_y = from_ys[i] + from_ys[j];

            ll now = min({direct, via_x, via_y});
            ans[now - 1]++;
        }
    }
    for (ll a : ans) cout << a << endl;
}


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

using namespace std;

int A[MAX], p = 0;

int partition(int A[],int r){
    int x, i = 0;
    x = A[r];
    i = p - 1;
    for(int j = p; j < r; j++){
        if(A[j] <= x){
            i++;
            swap(A[j],A[i]);
        }
    }
    swap(A[i + 1],A[r]);
    return i + 1;
}
int main(void){
    int n, q;
    scanf("%d",&n);
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
        
    q = partition(A,n-1);
    
    for(int i = 0; i < n; i++){
        if(i > 0)printf(" ");
        if(q == i)printf("[%d]",A[i]);
        else printf("%d",A[i]);
    }
    printf("\n");
}



Measured memory_bytes: 3488
//10
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  for(string s;getline(cin,s);){
    string ds;
    for(int i=0;i<s.size();i++){
      string dt="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
      int dd=dt.find(s[i]);
      for(int j=4;j>=0;j--){
	ds+=!!(dd&1<<j)+'0';
      }
    }
    string b;
    for(int i=0;i<ds.size();i++){
      b+=ds[i];
      string e[]={"101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
      const char *ec=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      int p=find(e,e+32,b)-e;
      if(p!=32){
	cout<<ec[p];
	b.clear();
      }
    }
    cout<<endl;
  }
  return 0;
}
      

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    double T, X;
    std::cin >> T >> X;
    std::cout << T * 1.0 / X << std::endl;
    return 0;
}

Measured memory_bytes: 256
# import itertools
# import math


def solve(N, P):
    if P[0] == 1:
        return 1
    ans = [P[0]]

    for i in range(1, N):
        if ans[-1] > P[i]:
            ans.append(P[i])

    return len(ans)


N = int(input())
# S = input()
# A, B = map(int, input().split())
P = list(map(int, input().split()))

# P = []
# S = []
# for i in range(N):
#     pp, ss  = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, P))


Measured memory_bytes: 85712
#include <stdio.h>

int main()
{
  int i, h, key[251];

  scanf("%d",&h);
  for (i = 1; i <= h; i++)
    scanf("%d",&key[i]);
  for (i = 1; i <= h; i++){
    printf("node %d: key = %d, ",i,key[i]);
    if (i > 1)
      printf("parent key = %d, ",key[i/2]);
    if (2*i <= h)
      printf("left key = %d, ",key[2*i]);
    if (2*i+1 <= h)
      printf("right key = %d, ",key[2*i+1]);
    printf("\n");
  }
 
  return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int scores[100];
int main(){
  int N;
  cin >> N;
  int sum = 0;
  for(int i=0;i<N;++i){
    cin >> scores[i];
    sum += scores[i];
  }
  sort(scores,scores+N);
  
  for(int i=0;i<N&&(sum%10==0);++i){
    if((scores[i]%10)!=0) sum -= scores[i];
  }

  cout << ((sum%10==0)?0:sum) << endl;
  return 0;
}

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

int main()
{
    int n,m,i,num=0,c=0;

    long long sum=0;

    scanf("%d %d",&n,&m);

    int tho[n+5],wield[n+5];

    for(i=0; i<n; i++)
    {
        scanf("%d %d",&tho[i],&wield[i]);

        if(num<tho[i])num=tho[i];
    }
    sort(wield,wield+n);

    reverse(wield,wield+n);
    for(i=0; i<n; i++)
    {
        if(num<wield[i])
        {
            sum+=wield[i];
             c++;
            if(sum>=m)
            {
                 printf("%d\n",c);
                 break;
            }
        }
    }
    if(sum<m)
    {
        sum=m-sum;

        c+=sum/num;

        if(sum%num!=0)c++;

        printf("%d\n",c);
    }

    return 0;

}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	
	public static void Main(string[] args)
	{
		int[] p = Input().ToInt();
		int n = p[0];
		int m = p[1];
		bool[] hall = new bool[n+2];
		for(int i = 0; i < m; i++)
			hall[Console.ReadLine().ToInt()] = true;
		
		long[] dp = new long[n+2];
		dp[0] = 1;
		for(int i = 0; i < n; i++)
		{
			if(!hall[i+1])
				dp[i+1] += (dp[i]%Giri);
			
			if(!hall[i+2])
				dp[i+2] += (dp[i]% Giri);
			
		}
		Console.WriteLine(dp[n]%Giri);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		int[] r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
	
}

Measured memory_bytes: 13144
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
from bisect import bisect_left, bisect_right, insort
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def MS(): return map(str,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
#N = I()
#A = [LI() for _ in range(N)]

s = S()
t = S()

for i in range(len(s)):
    if s[i] != t[i]:
        print('No')
        sys.exit()
print('Yes')


Measured memory_bytes: 27200
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define int long long
#define mp make_pair

mt19937 rnd(51);

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++){
        if (!(i % k)){
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
	return 0;
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"

using namespace std;

#define endl            "\n"
#define sz(x)          (int) (x.size())
#define all(v)          v.begin(), v.end()
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;



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

    int n; cin >> n;
    ll a[n];
    for(auto &i: a) cin >> i;
    ll c = 0;
    for(int i = 1; i < n; i++){
       ll x = max(0ll, a[i - 1] - a[i]);
       c += x;
       a[i] += x;
    }
    cout << c;
    return 0;
}


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

using namespace std ;

int main ()
{
    long long x ;
    cin >> x ;
    int ans = 0 ;
    if ( x >= 500 )
    {
        ans += (x/500)*1000;
        ans -= (x/500)*500;
    }
    if ( x >= 5 )
    {
        ans += ( x / 5 ) * 5 ;
    }
    cout << ans ;
    return 0 ;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import defaultdict
from itertools import accumulate

n, k = map(int, readline().split())
a = list(map(lambda x: int(x) - 1, readline().split()))
cumsum = [0] + list(map(lambda x: int(x) % k, list(accumulate(a))))
dict = defaultdict(int)
ans = 0
for i, v in enumerate(cumsum):
    ans += dict[v]
    dict[v] += 1
    if i >= k - 1:
        dict[cumsum[i - k + 1]] -= 1
print(ans)


Measured memory_bytes: 42044
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define pii 3.14
#define mod (ll)(1e9+7)
#define inf (ll)(1e18)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define pi pair<int,int>
#define N (ll)(1e5 + 5)

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

    ll arr[n] ,ans = 0;

    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(i > 0)
        {
            if(arr[i] < arr[i-1])
                ans += arr[i-1] - arr[i] , arr[i] = arr[i-1];
        }
    }

    cout<<ans;
}

int main()
{
    fio;
    ll tc = 1;
    //cin>>tc;
    while(tc--)
    {
        solve();
    }
}


Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int  mod=(ll)(1000000007);

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

int max(int a, int b) {
    return a > b ? a : b;
}

ll power(ll a, ll b) {
    int ans = 1ll ;
    while (b) {
        if (b & 1) {
            ans *= a;
        }
        a *= a;
        b >>= 1;
    }
    return ans;
}

ll mul(ll a, ll b, ll mod) {
    ll res = 0;
    a = a % mod;
    while (b) {
        if (b & 1ll ) {
            res = (res + a) % mod;
        }
        a = a * 2ll % mod;
        b = b >> 1ll ;
    }
    return res % mod;
}

ll power_mod(ll a, ll p, ll mod) {
    if (p == 0) return 1ll ;
    ll ans = power_mod(a, p / 2ll , mod);
    ans = mul(ans, ans, mod);
    if (p & 1ll ) {
        ans = mul(ans, a, mod);
        return ans;
    }
    return ans;
}

/*############################################################################################################################*/

int  main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c;
    cin>>a>>b>>c;
    int ans;
    a+b<c ? ans=(a+b+1+b): ans=c+b;
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int k=sc.nextInt();
     	int x=sc.nextInt();
  
		for(int i=x-k+1;i<=x+k-1;i++){
    	System.out.println(i);
        }
    }
}


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

using namespace std;

int main(void) {
	int w, n, a[31], b[31], ans[31];
	
	cin >> w >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d,%d", &a[i], &b[i]);
	}
	for (int i = 1; i <= w; i++) {
		int point = i;
		for (int j = 1; j <= n; j++) {
			if (point == a[j]) {
				point = b[j];
			}
			else if (point == b[j]) {
				point = a[j];
			}
		}
		ans[point] = i;
	}
	for (int i = 1; i <= w; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3148
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <stack>
#include<queue>
#include<list>
#include<algorithm>

int main()
{
    int n,q,b,e;
    std::cin>>n;
    std::vector<int> S;

    for(int i = 0; i < n; i++)
    {
        int hoge;
        std::cin>>hoge;
        S.push_back(hoge);
    }

    std::cin>>q;

    for(int i = 0; i < q; i++)
    {
        std::cin>>b>>e;
        reverse(S.begin()+b,S.begin()+e);
    }
    printf("%d",S[0]);
    for(int i = 1; i < n; i++)
    {
        printf(" %d",S[i]);
    }
	printf("\n");

    return 0;
}



Measured memory_bytes: 3260
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
sign = [" ", ".", "," ,":"]

while True:
    try:
        word = raw_input()
        for key in range(26):
            for i in range(len(word)):
                if not word[i] in sign:
                    ref = alpha.index(word[i])
                    word = word[:i]+alpha[(ref+1)%26]+word[i+1:]
            if word.count("the ")>=1 or word.count("that")>=1 or word.count("this")>=1:
                print word
    except:
        break

Measured memory_bytes: 4236
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.HashMap;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            long ans = 0;
            long sum = 0;
            HashMap<Long, Integer> hs = new HashMap<>();
            hs.put(0l, 1);
            for (int i = 0; i < n; i++) {
                sum += in.scanInt();
                if (hs.containsKey(sum)) {
                    ans += (hs.get(sum));
                    hs.put(sum, hs.get(sum) + 1);
                } else hs.put(sum, 1);
            }
            out.println(ans);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



Measured memory_bytes: 53256
#include <stdio.h>
#include <stdlib.h>

int main(void) {

	int* numArray;
	numArray = (int*)calloc(sizeof(int), 102);
	int Bingo[][3] = {{0,0,0}, {0,0,0}, {0,0,0}};

	/* 値読み込み */
	int A[3][3];
	for (int i = 0; i < 3; ++i) {
		scanf("%d %d %d", &A[i][0], &A[i][1], &A[i][2]);
	}
	/* 値に対応する位置にA内での位置を格納 */
	int index = 1;
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			numArray[A[i][j]] = index++;
		}
	}
	int N;
	scanf("%d\n", &N);
	int tmp;

	/* 値の読み込みとA内にある値ならBingoの値を1に更新 */
	for (int i = 0; i < N; ++i) {
		scanf("%d", &tmp);
		if (numArray[tmp] == 0) {
			continue;
		}
		Bingo[(numArray[tmp] - 1) / 3][(numArray[tmp] - 1) % 3] = 1;
	}

	/*ビンゴしたか確認*/
	int flag = 0;
	for (int i = 0; i < 3; ++i) {
		if (Bingo[i][0] == 1 && Bingo[i][1] == 1 && Bingo[i][2] == 1) {
			flag = 1;
		}
	}
	for (int i = 0; i < 3; ++i) {
		if (Bingo[0][i] == 1 && Bingo[1][i] == 1 && Bingo[2][i] == 1) {
			flag = 1;
		}
	}
	if (Bingo[0][0] == 1 && Bingo[1][1] == 1 && Bingo[2][2] == 1){
		flag = 1;
	}
	if (Bingo[0][2] == 1 && Bingo[1][1] == 1 && Bingo[2][0] == 1){
		flag = 1;
	}

	/* 結果の出力 */
	if (flag) {
		puts("Yes");
	}
	else {
		puts("No");
	}

	free(numArray);

	return 0;
}


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

#define llint long long int

using namespace std;

int popcount(string n){
    int ret = 0;

    for(int i = 0; i < n.length(); i ++){
        if(n[i] == '1'){
            ret ++;
        }
    }
    return ret;
}
int popcount(llint n){
    int ret = 0;

    for(int i = 0; i < 64; i ++){
        if((n >> i) & 1 == 1){
            ret ++;
        }
    }
    return ret;
}
int main(){
    int N;
    string X;

    cin >> N >> X;

    llint val_plus = 0, val_minus = 0;
    llint p_plus = 1, p_minus = 1;
    llint popcount_zero = popcount(X);
    llint popcount_plus = popcount_zero + 1;
    llint popcount_minus = popcount_zero - 1;

    for(int i = N - 1; i >= 0; i --){
        if(X[i] == '1'){
            val_plus = (val_plus + p_plus) % popcount_plus;
            if(popcount_minus > 0){
                val_minus = (val_minus + p_minus) % popcount_minus;
            }
        }
        p_plus = (2 * p_plus) % popcount_plus;
        if(popcount_minus > 0){
            p_minus = (2 * p_minus) % popcount_minus;
        }
    }
    vector<llint> ans(N);

    p_plus = 1;
    p_minus = 1;

    for(int i = N - 1; i >= 0; i --){
        llint f;

        if(X[i] == '1'){
            if(popcount_zero == 1){
                ans[i] = 0;

                continue;
            }
            f = (val_minus - p_minus + popcount_minus) % popcount_minus;
        }else if(X[i] == '0'){
            f = (val_plus + p_plus) % popcount_plus;
        }
        p_plus = (2 * p_plus) % popcount_plus;
        if(popcount_minus > 0){
            p_minus = (2 * p_minus) % popcount_minus;
        }
        int count = 1;

        while(f > 0){
            f %= popcount(f);
            count ++;
        }
        ans[i] = count;
    }
    for(int i = 0; i < N; i ++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4980
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

pair<int, int> rotate90(const int x, const int y) {
    return {-y, x};
}

int main(void) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    pair<int, int> p4 = rotate90(x2 - x1, y2 - y1);
    int x4 = p4.first + x1, y4 = p4.second + y1;

    pair<int, int> p3 = rotate90(x1 - x4, y1 - y4);
    int x3 = p3.first + x4, y3 = p3.second + y4;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1
#define sosuu 1000000007
lli dp[100005][2];

lli nCr(lli n, lli r)
{
       if(n<r) return 0;
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n;
       if(dp[n][r]) return dp[n][r];
       return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}

int main(){
  int N;
  cin >> N;
  vector<char> kari(10);
  vector<string> s(N);
  rep(i, N){
  rep(j, 10){
  cin >> kari[j];
  }
    sort(ALL(kari));
    
  string a="aaaaaaaaaa";
  rep(j, 10)
    a[j]=kari[j];
  s[i]=a;
  }
  lli ans=0;
  sort(ALL(s));
  int count=1;
  rep(i, N-1){
  if(s[i]==s[i+1])
  {
    count++;
  }
    else if(count==1)
    {}
    else{
    ans+= nCr(count,2);
      count =1;
    }
  }
  if(s[N-2]==s[N-1])
    ans+= nCr(count,2);
  cout<<ans<<endl;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  int a,b,c,d,e;
  string s,ss;
  cin>>a>>b>>c>>d;
  int hai[100]={};
  hai[a]=1;hai[b]=1;hai[c]=1;hai[d]=1;
  if(hai[1]&&hai[9]&&hai[7]&&hai[4])
  cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 764
n = int(input())
l = []
for i in range(n-1):
  c, s, f = map(int, input().split())
  l.append((c,s,f))

for i in range(n-1):  
  t = 0
  for j in range(i, n-1):
    c,s,f = l[j]
    while t > s:
      s += f
    t = s+c
  print(t)
print(0)
      

Measured memory_bytes: 68268
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;
#define mpr make_pair

lint hap(vector<pll> left){
    int n = left.size();
    sort(left.begin(), left.end());
//    multiset<pll> candi;
    lint tot = 0;
    for (pll p : left) tot += p.second;//candi.insert(p);

    int id = 0;
    multiset<lint> need;
    lint dis = 0;
    for (int l = 1; l<=n; ++l){
        while (id < n && left[id].first == l){
            need.insert(left[id].second);

            id++;
        }
        while (need.size() > l){
            dis += *need.begin();
//            candi.erase(candi.find(*need.begin()));
            need.erase(need.begin());
        }
    }
//    lint hap =0;
//    for (auto p : candi){
//        hap += p.second;
//    }
    return tot - dis;
}

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

    vector<pll> left, right; // pos, happy
    lint base = 0;
    for (int i=0; i<n; ++i){
        lint  k, l, r; cin>>k>>l>>r;
        if (l > r ) {if (k < n)left.push_back({k, l -r});}
        else if (l < r ){ if ( k < n)right.push_back({n-k, r- l});}
        if (k<n) base += min(l, r);
        else base += l;
    }
    cout<<base + hap(left) + hap(right)<<"\n";
}

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

    int t; cin>>t;
    while(t--){
        solve();
    }

}


Measured memory_bytes: 12968
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


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


	int N = getint();
	int A[100000], B[100000];
	rep(i, N) {
		A[i] = getint();
		B[i] = getint();
	}
	ll kotae = 0;
	for (int i = N - 1; i >= 0; i--) {
		ll kari = (kotae + A[i] + B[i] - 1.0) / B[i];
		kotae = kari * B[i] - A[i];
	}
	printf("%lld\n", kotae);

	Would you please return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  rep(i, h) cin >> s[i];

  // 基準座標からの周りの座標位置
  // 数字は(dx, dy)の組で考えているので
  // 各々の配列の数字の順番は組み合わせを意識している以外の意味はない
  int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
  int dy[8] = {1, 1, 0, -1, 0, -1, 1, -1};

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        int num = 0;
        for (int d = 0; d < 8; d++) {
          int x = i + dx[d]; // 基準座標周辺x座標
          int y = j + dy[d]; // 基準座標周辺y座標

          if (x < 0 or h <= x) continue; // x座標の外ならスルー
          if (y < 0 or w <= y) continue; // y座標の外ならスルー
          if (s[x][y] == '#') num++;
        }
        s[i][j] = num + '0';
      }
    }
  }

  // int fi_h = h;
  // int fi_w = w;
  // int cnt = 0;

  // for (int i = 0; i < h; i++) {
  //   for (int j = 0; j < w; j++) {
  //     char c = s[i][j];
  //     if (c == '.') {
  //       // 八方向・爆弾をカウント
  //       if (s[i][j+1] == '#') cnt++;
  //       if (s[i][j-1] == '#') cnt++;
  //       if (s[i-1][j] == '#') cnt++;
  //       if (s[i-1][j+1] == '#') cnt++;
  //       if (s[i-1][j-1] == '#') cnt++;
  //       if (s[i+1][j] == '#') cnt++;
  //       if (s[i+1][j+1] == '#') cnt++;
  //       if (s[i+1][j-1] == '#') cnt++;
  //       s[i][j] = (char)cnt;
  //     }
  //   }
  // }

  rep(i, h) cout << s[i] << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>

using namespace std;

int main(){

        int ball;
        cin >> ball;
        int K;
        cin >> K;
        vector<int> xi(ball);

        for(auto it = xi.begin(); it != xi.end(); it++){
                cin >> *it;
        }
        long total=0;
        for(auto it = xi.begin(); it != xi.end(); it++){
                total += *it < K-(*it) ? 2*(*it) : 2*(K - *it);
        }
        cout << total << endl;
        return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
using namespace std;
const int maxM=5010,maxn=1010,inf=0x3f3f3f3f;
int f[maxn],g[2][maxM],n,first[maxn],tot,v[maxn];
struct edge{int v,from;}e[maxn];


int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
int min(int a,int b){return a<b?a:b;}
void dfs(int x){
    for(int i=first[x];i;i=e[i].from)dfs(e[i].v);
    memset(g[0],0x3f,sizeof(g[0]));
    int X=0;
    g[X][0]=0;
    for(int i=first[x];i;i=e[i].from){
        int y=e[i].v;
        X=1-X;
        memset(g[X],0x3f,sizeof(g[X]));
        for(int j=0;j<=v[x];j++){
            if(j-v[y]>=0)g[X][j]=min(g[X][j],g[1-X][j-v[y]]+f[y]);
            if(j-f[y]>=0)g[X][j]=min(g[X][j],g[1-X][j-f[y]]+v[y]);
        }
    }
    for(int i=0;i<=v[x];i++)f[x]=min(f[x],g[X][i]);
}
    
int main(){
    n=read();
    for(int i=2;i<=n;i++){
        int p=read();
        insert(p,i);
    }
    for(int i=1;i<=n;i++)v[i]=read();
    memset(f,0x3f,sizeof(f));
    dfs(1);
    if(f[1]<inf)printf("POSSIBLE");else printf("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] v = new int[n];
		int[] c = new int[n];
		for(int i = 0;i < n;i++){
			v[i] = saori.saori_hayami();
		}
		for(int i = 0;i < n;i++){
			c[i] = saori.saori_hayami();
		}
		int vnum = 0;
		int cnum = 0;
		int ans = 0;
		for (int i=0; i<(1<<n); i++) {
			vnum = 0;
			cnum = 0;
			for (int j=0; j<n; j++) {
                if ((1&i>>j) == 1) {
					vnum += v[j];
					cnum += c[j];
                }//taisetu
                ans = Math.max(ans, vnum-cnum);
            }
		}
		System.out.println(ans);

		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21460
NN = int(input())
SS = str(input())

score = [0]*NN
for i in range(1,NN):
    if SS[i] == "E":
        score[0] += 1

for pos in range(1,NN-1):
    score[pos] = score[pos-1]
    if SS[pos-1] == "W":
        score[pos] += 1
    if SS[pos] == "E":
        score[pos] -= 1

score[NN-1] = score[NN-2]
if SS[NN-2] == "W":
    score[NN-1] += 1
if SS[NN-1] == "E":
    score[NN-1] -= 1

print(min(score))

Measured memory_bytes: 73160
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		char[] c = s.toCharArray();

		for (int i = 0; i < s.length(); i++) {

			if (i % 2 == 0) {
				if (c[i] == 'L') {
					System.out.println("No");
					return;
				}

			} else if (i % 2 == 1) {
				if (c[i] == 'R') {
					System.out.println("No");
					return;
				}
			}

		}
		System.out.println("Yes");

	}
}

Measured memory_bytes: 22996
N,M = map(int,input().split(" "))
light = []
for i in range(M):
    tmp = list(map(int,input().split(" ")))
    light.append(tmp)

p = list(map(int,input().split(" ")))


switch = [0 for i in range(N)] 


def search(N,M,light,p,l,switch):
    if l<N:
        l += 1
        a=search(N,M,light,p,l,switch)
        switch[l-1]+=1 
        b = search(N,M,light,p,l,switch)
        return a+b
    else:
        flag = 0
        for i in range(M):
            a = 0
            for j in range(light[i][0]):
                a +=switch[light[i][j+1]-1]
            if a%2 == p[i]:
                continue
            else:
                flag = 1
                break
        if flag == 0:
            return 1
        else:
            return 0
  

ans = search(N,M,light,p,0,switch)
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int dish[5];
    rep(i, 5) cin >> dish[i];
    int sum = 0;
    rep(i, 5) {
        if (dish[i] % 10 == 0)
            sum += dish[i];
        else 
            sum += (dish[i] / 10 + 1) * 10;
    }
    int large = 0;
    rep(i, 5)  {
        if (dish[i] % 10 != 0) large = max(large, 10 - dish[i] % 10);
    }
    cout << sum - large << endl;


    return 0;
}


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

int main()
{
    int a,b,x=0,i;
    int ans[3]={0};
    scanf("%d %d",&a,&b);
    ans[a-1]=1;
    ans[b-1]=1;

    for(i=0;i<3;i++)
    {
        if(ans[i]==0)x=i;
    }
    printf("%d",x+1);
}



Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication51
{
    class Program
    {
        static void Main()
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] A = new int[2];A[0] = a[0] + a[1] + a[2] + a[3];A[1] = b[0] + b[1] + b[2] + b[3];
            Array.Sort(A);
            Console.WriteLine(A[1]);
        }
    }
}

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

int main() {
  int n, k, sum;
  cin >> n >> k;
  sum = 1;
  for(int i=0;i<n;i++){
    if(sum <= k)
      sum *= 2;
    else
      sum += k;
  }
  cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void dfs(int node,vector<int> adj[],int dp[],bool visited[]){
    visited[node]=true;
    for(int i=0;i<adj[node].size();i++){
        if(!visited[adj[node][i]]){
            dfs(adj[node][i],adj,dp,visited);
        }
        dp[node] = max(dp[node],1+dp[adj[node][i]]);
    }
}

int findLongestPath(vector<int> adj[],int n){
    int dp[n+1]={0};
    bool visited[n+1] ={false};
    for(int i=1;i<=n;i++){
        if(!visited[i]){
            dfs(i,adj,dp,visited);
        }
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        ans = max(ans,dp[i]);
    }
    return ans;
}

void addedge(vector<int> adj[],int x,int y){
    adj[x].push_back(y);
}
int main() {
    int n,m;cin>>n>>m;
    vector<int> adj[n+1];
    for(int i=0;i<m;i++){
        int x,y;cin>>x>>y;
        addedge(adj,x,y);
    }
    cout<<findLongestPath(adj,n);
}


Measured memory_bytes: 9600
#include<stdio.h>
#include<stdlib.h>
#define O 1000000000
void N(int B[500001],int left,int right);
void M(int C[500001],int left,int mid,int right);
int count;

int main(){
       int A[500001];
       int a,i;
       
       scanf("%d",&a);
       for(i=0;i<a;i++){
             scanf("%d",&A[i]); 
       }
       N(A,0,a);
       for(i=0;i<a;i++){
    printf("%d",A[i]);
    if(i<a-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

void N(int B[],int left,int right){
       int i,mid;
       if(left+1<right){
              mid=(left+right)/2;
              N(B,left,mid);
              N(B,mid,right);
              M(B,left,mid,right);
       }
}

void M(int C[],int left,int mid,int right){
  int a,b,i,j,k;
  int *L,*R;
  a=mid-left;
  b=right-mid;
  L=(int *)malloc(sizeof(int)*(a+1));
  R=(int *)malloc(sizeof(int)*(b+1));
    for(i=0;i<=a-1;i++){
    L[i]=C[left+i];
  }
  for(j=0;j<=b-1;j++){
    R[j]=C[mid+j];
  }
  L[a]=O;
  R[b]=O;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
   if(L[i]<=R[j]){
      C[k]=L[i];
      i++;
      count++;
    }
    else{
      C[k]=R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}


Measured memory_bytes: 5464
H, W = map(int, input().split())
C = []
for i in range(10):
  c = list(map(int, input().split()))
  C.append(c)
A = []
for i in range(H):
  a = list(map(int, input().split()))
  A.append(a)
  
for k in range(10):
  for i in range(10):
    for j in range(10):
      if C[i][k]+C[k][j] < C[i][j]:
        C[i][j] = C[i][k] + C[k][j]
        
ans = 0
for i in range(H):
  l = A[i]
  for j in range(W):
    n = l[j]
    if (n==0) or (n>1):
      ans += C[n][1]
print(ans)

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A > 9) {
    cout << "-1" << endl;
  }
  else if (B > 9) {
    cout << "-1" << endl;
  }
  else {
    cout << A * B << endl;
  }
}

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

int main(){
  
  int n, q, command, s, t, x; 
  
  cin >> n;
  list<int> L[n];
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> command;
    
    if(command == 0){
      cin >> t >> x;
      L[t].push_back(x);
    }else if(command == 1){
      cin >> t;
      for(list<int>::iterator it = L[t].begin();it != L[t].end();it++){
        if(it != L[t].begin()) cout << " ";
        cout << *it;
      }
      cout << endl;
    }else if(command == 2){
      cin >> s >> t;
      L[t].splice(L[t].end(), L[s]);
    }
  }
  
  return 0;
}


Measured memory_bytes: 18652
import java.util.*;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] x = new int[N][D];
        int count = 0;
        
        
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        
        for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                double[] dis = new double[D];
                double sum = 0; 
                for(int k = 0; k < D; k++) {
                    dis[k] = Math.pow(x[i][k] - x[j][k], 2);
                    sum += dis[k];
                }
                sum = Math.sqrt(sum);
                if(sum - (int)sum == 0) {
                    count++;
                }
            }
        }
        System.out.println(count);
        
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define DEBUG
const int N = 60 * 60 * 24 + 100;

int convert(string s){
  return (atoi(s.substr(0, 2).c_str()) * 60 * 60) + (atoi(s.substr(3, 2).c_str()) * 60) + atoi(s.substr(6, 2).c_str());
}

int main() {
  int n;
  while(cin >>n && n){
    vector<int> v(N, 0);
    REP(i, n){
      string s, e; cin >>s >>e;
      v[convert(s)] += 1;
      v[convert(e)] -= 1;
    }
    int ans = v[0];
    FOR(i, 1, N){
      v[i] += v[i - 1];
      ans = max(ans, v[i]);
    }
    cout <<ans <<endl;
  }
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll A, B;
    cin >> A >> B;
    ll res = max(A+B, A-B);
    res = max(res, A*B);
    cout << res << endl;
    return 0;
}

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

int main(){
  vector<int> v(3);
  int k;
  cin >> v[0] >> v[1] >> v[2] >> k;
  for(int i=0;i<1;i++) for(int j=i+1;j<3;j++) if(v[i]<v[j]) swap(v[i],v[j]);
  for(int i=k;i>0;i--) v[0]*=2;
  cout << (v[0]+v[1]+v[2]) << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
/// my holy template
# define F first    
# define S second
# define mp make_pair
# define pii pair<int,int>         
/// eveything goes according to plan
# define long long long  
# define pb push_back
# define sz(a) (int)(a.size())
/// countdown BEGAN. 10 , 9 , 8 ...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right     

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 9223372036854775807;
const int Sz = 1110111;

using namespace std;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
const int N = 201;

int d[N][N];

int dp[1<<8][8];

int a[Sz];

int n, m, r;    
                              
int main() 
{
  Read_rap ();                 
  cin >> n >> m >> r;
  for (int i = 0;i < r;i ++)
    cin >> a[i];
  for (int i = 1;i <= n;i ++)
    for (int j = 1;j <= n;j ++)
      if (i != j)
        d[i][j] = MX;                  
  for (int i = 1;i <= m;i ++) {
    int x, y, c;  cin >> x >> y >> c;
    d[x][y] = c;
    d[y][x] = c;
  }
  for (int k = 1;k <= n;k ++) {
    for (int i = 1;i <= n;i ++) {
      for (int j = 1;j <= n;j ++) {
        if (i != j)
          d[i][j] = min (d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  for (int mask = 0;mask < (1<<r);mask ++)
    for (int i = 0;i < r;i ++)
      dp[mask][i] = MX;
         
  for (int i = 0;i < r;i ++)
    dp[1<<i][i] = 0;

  for (int mask = 0;mask < (1<<r);mask ++) {
    for (int i = 0;i < r;i ++) {
      if (mask & (1<<i))
        for (int j = 0;j < r;j ++)
          if (!(mask >> j & 1))
            dp[mask | (1<<j)][j] = min (dp[mask | (1<<j)][j], d[a[i]][a[j]] + dp[mask][i]);
    }
  } 
  cout << *min_element (dp[(1<<r) - 1], dp[(1<<r) - 1] + r);

  return 0;
} 










// Coded by Z...

Measured memory_bytes: 384
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = [str(i) for i in input().split()]
    print(a[0][:4]+" "+a[0][4:])


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int h[100001];
int dp[100001];
int main(int argc, char const *argv[]) {
    int n, K;
    scanf("%d %d", &n, &K);
    for(int i = 0; i < n; ++i) 
        scanf("%d", &h[i]);
    dp[0] = 0;
    for(int i = 1; i < n; ++i) {
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        for(int k=2;k<=K;++k)
            if(i >= k)
                dp[i] = min(dp[i], dp[i-k] + abs(h[i] - h[i-k]));
    }
    printf("%d\n", dp[n-1]);
    return 0;
}

Measured memory_bytes: 4404
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range;

void main(){
    auto HW = readln.split.to!(int[]);
    auto board = iota(HW[0]).map!(_ => readln.chomp.to!(dchar[])).array;

    auto hit(in int[] yx){
        auto y = yx[0];
        if(y < 0 || HW[0] <= y) return false;
        auto x = yx[1];
        if(x < 0 || HW[1] <= x) return false;
        return board[y][x] == '#';
    }

    auto countHit(in int y, in int x){
        return cartesianProduct([-1, 0, 1], [-1, 0, 1])
            .map!(diff => diff.array[] += [y, x])
            .count!(at => hit(at));
    }

    foreach(int y, ref line; board)
        foreach(int x, ref c; line){
            if(c != '.')continue;
            c = countHit(y, x).to!string.front;
        }
    writeln(board.join('\n'));
}

Measured memory_bytes: 1148
s=list(input())
s=[int(i) for i in s]
now=0
c=[0]*2019
c[0]=1
for n,i in enumerate(s[::-1]):
    now+=i*pow(10,n,2019)
    c[now%2019]+=1
ans=0
for k in range(2019):
    ans+=c[k]*(c[k]-1)//2
print(ans)


Measured memory_bytes: 88464
#include<iostream>
int pow(int x,int p)
{
    int result=1;
    while(p>0)
    {
        if(p%2==1)
            result=x*result;
        p/=2;
        x=x*x;
    }
    return result;
}
using namespace std;
bool check[1010];
int main()
{
	int x;
	cin>>x;
	for(int i=1;i<=35;i++){
		for(int j=2;j<=35;j++){
			int tmp=pow(i,j);
			if(tmp>x)
				break;
			check[tmp]=1;
		}
	}
	for(int i=x;i>=1;i--){
		if(check[i]){
			cout<<i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256