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

int main(){
	long long A,B,K;
	cin >> A >> B >> K;
	
	long long a=max(0LL,A-K);
	K-=A-a;
	long long b=max(0LL,B-K);
	
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#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> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
ll a,b;
ll n;

ll flr(ll x){
    return floor((double)(a*x)/b) - a*floor((double)(x)/b);
}

int main(){
    cin >> a >> b >> n;
    ll ans = 0;
    cout << flr(min(n,b-1)) << endl;
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    cout << 800*N - 200*(N/15) << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <cstdio>

template<class T>inline void fr(T &a) {
    T s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=w*s;
}
template<class T>inline T fr() {T a;fr(a);return a;}
#define R() fr<int>()

signed main() {
    int n=R(),l=1,r=n,ans=0;
    while(l<=r) {
        int mid=(l+r)/2;
        double f=mid*1.08;
        if((int)f==n) {ans=mid;break;}
        if(f<n)l=mid+1;
        else r=mid-1;
    }
    if(ans==0)puts(":(");
    else printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 888
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func sum(a []int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	l := nextInts(n)
	sort.Sort(sort.IntSlice(l))
	fmt.Println(sum(l[n-k : n]))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define rep1(i,N) for(int i=1;i<=(int)N;i++)
#define pb push_back
#define all(c) c.begin(),c.end()
#define fs first
#define sc second
#define show(x) cout<<#x<<" "<<x<<endl
using namespace std;
int N,M;
typedef pair<int,int> P;
int x[100000],y[100000];
P ps[100000];
set<int> y2xs[200000];
int udp[200010],ddp[200010];
vector<int> xs;
int main(){
	cin>>N>>M;
	rep(i,M) cin>>x[i]>>y[i];
	rep(i,M) xs.pb(x[i]);
	sort(all(xs));
	rep(i,M) x[i]=lower_bound(all(xs),x[i])-xs.begin();
	rep(i,M){
		y[i]--;
		ps[i]=P(x[i],y[i]);
		y2xs[y[i]].insert(x[i]);
	}
	sort(ps,ps+M);
	rep(i,M) x[i]=ps[i].fs,y[i]=ps[i].sc;
	rep(i,M){	//goup
		int X=x[i],Y=y[i];
		if(Y==0){
			udp[i]=0;
		}else{
			auto it=y2xs[Y-1].lower_bound(X);
			if(it==y2xs[Y-1].begin()){
				udp[i]=Y;
			}else{
				it--;
				udp[i]=udp[*it];
			}
		}
	}
	rep(i,M){	//godwn
		int X=x[i],Y=y[i];
		if(Y==N-2){
			ddp[i]=N-1;
		}else{
			auto it=y2xs[Y+1].lower_bound(X);
			if(it==y2xs[Y+1].begin()){
				ddp[i]=Y+1;
			}else{
				it--;
				ddp[i]=ddp[*it];
			}
		}
	}
	rep(y,N){
		int u;
		if(y==0) u=0;
		else if(y2xs[y-1].empty()) u=y;
		else u=udp[*y2xs[y-1].rbegin()];

		int d;
		if(y==N-1) d=N-1;
		else if(y2xs[y].empty()) d=y;
		else d=ddp[*y2xs[y].rbegin()];

//		cout<<u<<"  "<<d<<endl;

		cout<<d-u+1<<(y==N-1?"\n":" ");
	}
}

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

int main()
{
    int n;
    string s;
   cin >> n >> s;
   int cnt =0;
   for(int i=0; i < s.size() - 2; i++){
       if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')cnt++;
   }
   cout << cnt << endl;
   return 0;
}

Measured memory_bytes: 888
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int day=sc.nextInt(),n=sc.nextInt();//入力
		int[] high=new int[day];
		for(int i=0;i<day;i++){
			high[i]=sc.nextInt();
		}
		int[] ht=new int[n];
		int[] lt=new int[n];
		int[] loud=new int[n];
		for(int i=0;i<n;i++){
			lt[i]=sc.nextInt();ht[i]=sc.nextInt();loud[i]=sc.nextInt();
		}//入力
		
		int[][] dp=new int[day][n];
		for(int i=0;i<day;i++){
			for(int j=0;j<n;j++){
				dp[i][j] = 0;
			}
		}
		int ans=0;
		for(int i=1;i<day;i++){
			for(int j=0;j<n;j++){
				if(lt[j]<=high[i]&&high[i]<=ht[j]);
				else continue;
				for(int k=0;k<n;k++){
					if(lt[k]<=high[i-1]&&high[i-1]<=ht[k]);
					else continue;
					dp[i][j]=Math.max(dp[i][j],Math.abs(loud[j]-loud[k]) + dp[i-1][k]);
					ans=Math.max(ans,dp[i][j]);
				}
			}	
		}	
		System.out.println(ans);
	}
}

Measured memory_bytes: 22620
#include <bits/stdc++.h>
using namespace std;
int n,m;
int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	cin >> n >> m;
	vector <int> v[n];
	int p[m];
	for(int i=0;i<m;i++){
		int x;
		cin >> x;
		while(x--){
			int y;
			cin >> y;
			y--;
			v[y].push_back(i);
		}
	}
	for(int i=0;i<m;i++)
		cin >> p[i];
	int ans=0;
	for(int i=0;i<(1<<n);i++){
		int a[m]={0};
		for(int j=0;j<n;j++){
			if((i&(1<<j))){
				for(int k:v[j])
					a[k]++;
			}
		}
		int flag=1;
		for(int j=0;j<m;j++){
			if(a[j]%2!=p[j])
				flag=0;
		}
		if(flag)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>     // for strcmp()

struct Node {
    int key;
    Node *prev, *next;
};

class Doubly_Linked_List{
    public:
        Node *nil;
        Doubly_Linked_List();
        void insert(int key);
        Node* listSearch(int key);
        void deleteNode(Node *t);
        void deleteFirst();
        void deleteLast();
        void deleteKey(int Key);
        void print_list();
};

Doubly_Linked_List::Doubly_Linked_List(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void Doubly_Linked_List::insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node* Doubly_Linked_List::listSearch(int key){
    Node* cur = nil->next;
    while (cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void Doubly_Linked_List::deleteNode(Node *t){
    if (t == nil) return;
    t->next->prev = t->prev;
    t->prev->next = t->next;
    free(t);
}

void Doubly_Linked_List::deleteFirst(){
    deleteNode(nil->next);
}

void Doubly_Linked_List::deleteLast(){
    deleteNode(nil->prev);
}

void Doubly_Linked_List::deleteKey(int key){
    deleteNode(listSearch(key));
}

void Doubly_Linked_List::print_list(){
    Node *cur = nil->next;
    int count = 0;
    while (true){
        if (cur == nil) break;
        if (count++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

int main() {
    int N, key;
    char command[100];
    char *command_1 = "insert";
    char *command_2 = "delete";
    char *command_3 = "deleteFirst";
    char *command_4 = "deleteLast";

    scanf("%d", &N);

    Doubly_Linked_List doubly_linked_list;
    for (int i = 0; i < N; i++){
        // scanf("%s%d", command, &key);
        // printf("command = %s, key = %d\n", command, key);
        std::cin >> command;
        if (strcmp(command, command_1) == 0){
            std::cin >> key;
            doubly_linked_list.insert(key);
        } else if (strcmp(command, command_2) == 0){
            std::cin >> key;
            doubly_linked_list.deleteKey(key);
        } else if (strcmp(command, command_3) == 0){
            doubly_linked_list.deleteFirst();
        } else if (strcmp(command, command_4) == 0){
            doubly_linked_list.deleteLast();
        } else {
            // printf("command = %s, key = %d\n", command, key);
            break;
        }
    }
    doubly_linked_list.print_list();

    return 0;
}



Measured memory_bytes: 34380
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

#define lowbit(x) (x&-x)
using namespace std;
typedef long long ll;
const int N = 2e5;
const int maxn = 2e5+5;
ll mod = 1e9+7;

ll n,a,b;

int main()
{
    scanf("%lld%lld%lld",&n,&a,&b);
    ll L = (n-1)*a+b,R=a+(n-1)*b;
    printf("%lld",max(0LL,R-L+1));
}


Measured memory_bytes: 256
program main
    implicit none
    integer, allocatable:: p(:)
    integer:: n, now_min, i, count

    read*, n
    allocate(p(n))
    read*, p(:)

    now_min = n+1
    count = 0
    do i = 1, n
        if (p(i) < now_min)then
            now_min = p(i)
            count = count + 1
        end if
    end do

    print*, count
    
end program main

Measured memory_bytes: 1536
#include <stdio.h>

int main() {
    // 賃貸情報の初期化
    int office[4][3][10];
    for (int i = 0; i < 4; i ++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                office[i][j][k] = 0;
            }
        }
    }

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

    // 賃貸情報の更新
    int b, f, r, v;
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        office[b-1][f-1][r-1] += v;
    }

    // 現在の状態を表示
    for (int i = 0; i < 4; i ++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                printf(" %d", office[i][j][k]);
            }
            printf("\n");
        }
        (i == 3) ? printf("") : printf("####################\n");
    }

    return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
using namespace std;
int mx[100020],my[100020];
int main() {
  int n,h,w;
  cin >> n >> w >>h;

  while(n--){
    int x,y,c;
    cin >>x>>y>>c;
    mx[max(0,x-c)]++;
    mx[min(w+1,x+c)]--;
    my[max(0,y-c)]++;
    my[min(h+1,y+c)]--;
  }
  int ans=0;
  for(int i=0;i<w-1;i++)mx[i+1]+=mx[i];
  for(int i=0;i<h-1;i++)my[i+1]+=my[i];
  for(int i=0;i<w;i++)
    if(mx[i]==0) {
      ans++;
      break;
    }
  for(int i=0;i<h;i++)
    if(my[i]==0) {
      ans++;
      break;
    }

  if(ans!=2) cout<<"Yes"<<endl;
  else cout <<"No"<<endl;
  return 0;
}

Measured memory_bytes: 1940
m = int(input())
CD = [list(map(int, input().split())) for _ in range(m)]
count = 0
tmp = -1
total = 0
for c, d in CD:
  q, m = divmod(tmp + c * d, 9)
  count += q
  tmp = m
  total += d
print(total - 1 + count)


Measured memory_bytes: 45360
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    string S;
    cin >> S;
    if(S == "SUN"){
        cout << "7" << endl;
    }else if(S == "MON"){
        cout << "6" << endl;
    }else if(S == "TUE"){
        cout << "5" << endl;
    }else if(S == "WED"){
        cout << "4" << endl;
    }else if(S == "THU"){
        cout << "3" << endl;
    }else if(S == "FRI"){
        cout << "2" << endl;
    }else if(S == "SAT"){
        cout << "1" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define For(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define Max(x) *max_element(ALL(x))
#define Min(x) *min_element(ALL(x))
#define Lower_bound(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define Upper_bound(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define itn int
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}
int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

signed main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> info(N);
  int temp_a, temp_b;
  rep(i, M) {
    cin >> temp_a >> temp_b;
    info[temp_a - 1].push_back(temp_b - 1);
    info[temp_b - 1].push_back(temp_a - 1);
  }
  for (auto &i : info[0]) {
    for (auto &j : info[i]) {
      if (j == N - 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


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

using namespace std;

int main()
{
	int a;
	int i = 1;
	while (1)
	{
		cin >> a;
		if (a == 0){
			break;
		}
		printf("Case %d: %d\n", i, a);
		i++;
	}

	return 0;
}

Measured memory_bytes: 1144
#include<stdio.h>

int main(){
  int n,i,count=0;
  scanf("%d",&n);

  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n;i++){
    if((i+1)%2==1 && a[i]%2==1){
      count++;
    }
  }

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1712
// Judge Status Summary
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    string s[n];
    int ac=0, wa=0, tle=0, re=0;
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    for(int i=0; i<n; i++){
        if(s[i]=="AC"){ ac++;}
        else if(s[i]=="WA"){ wa++;}
        else if(s[i]=="TLE"){ tle++;}
        else{re++;}
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 6748
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split())) 
ans=0
for i in range(2**n):
    b=0
    for j in range(m):
        a=0
        for k in s[j][1:]:
            if (i>>(k-1))&1:
                a+=1
        if a%2==p[j]:
            a+=1
            b+=1
    if b==m:        
        ans+=1
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

namespace ARC060_D___桁和__Digit_Sum
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long digitSum(long b, long n)
        {
            long result = 0;
            while (b <= n)
            {
                result += (n % b);
                n = n / b;
            }
            result += n;
            return result;
        }
        static long solver()
        {
            var N = long.Parse(Console.ReadLine());
            var S = long.Parse(Console.ReadLine());
            if (N == S) return N + 1;
            var sqrtN = (long)Math.Sqrt(N);
            for (long i = 2; i <= sqrtN; i++) if (digitSum(i, N) == S) return i;
            var divisorNS = new List<long>();
            for (long i = (long)Math.Sqrt(N - S); i >= 1; i--) if (((N - S) % i) == 0) divisorNS.Add((N - S) / i);
            foreach (long b in divisorNS) if (digitSum(b + 1, N) == S) return b + 1;
            return -1;
        }
    }
}


Measured memory_bytes: 13268
#pragma GCC optimize("Ofast")

#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
    int r, g, b, n;
    int ans = 0;
    int o, p, q;
    
    cin >> r >> g >> b >> n;
    o = n/r+1;
    p = n/g+1;
    q = n/b+1;

    for(int i = 0; i < n/r+1; i++){
      for(int j = 0; j < (n-i*r)/g+1; j++){
        for(int k = 0; k < (n-i*r-g*j)/b+1; k++){
          if(i*r+j*g+k*b == n){
            ans += 1;
          }
        }
      }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
A, B = input().split()
dictt = {'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5}
if dictt[A] == dictt[B]:
  print('=')
elif dictt[A] > dictt[B]:
  print('>')
else:
  print('<')

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

int main() {
  int N;
  cin >> N ;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >>H.at(i);
  }
  vector<int> count(1);
 
  for(int i=1;i<N;i++){
    if (H.at(i)<=H.at(i-1)){
      count.at(count.size()-1)+=1;
    }
    else{
      count.push_back(0);
    }
  }
  sort(count.begin(),count.end());
  
  cout << count.at(count.size()-1) <<endl;
}

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


int main() {
  uint32_t N;
  uint64_t Y;
  std::cin >> N;
  std::cin >> Y;
  uint32_t ret[3];
  uint32_t z = 0;
  auto a = Y % 10000;
  if (a != 0) {
    if (a < 5000) {
      z = a / 1000;
    } else if (a > 5000) {
      z = (5000 - a) / 1000;
    }
  }

  for (int x = 0; x < N + 1; x++) {
    for (int y = 0; y + x < N + 1; y++) {
      auto z = N - (y + x);
      if (x * 10000 + y * 5000 + z * 1000 == Y) {
        printf("%d %d %d", x, y, z);
        return 0;
      }
    }
  }

  puts("-1 -1 -1");
}


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

using namespace std;

int const MAXN = 15;

typedef long long ll;
ll MOD = 2019LL;

int main() {
	ll L, R;
	cin >> L >> R;
	if(R - L + 1LL >= MOD) cout << 0 << endl;
	else{
		ll mini = 1e9;
		ll maxi = 0;
		for(ll i=L;i<=R;++i){
			mini = min(mini,i%MOD);
			maxi = max(maxi,i%MOD);
		}
		ll ans = 1e9;
		for(ll i=mini;i<=maxi;++i){
			for(ll j=i+1;j<=maxi;++j){
				ans = min(ans, (i*j)%MOD);
			}
		}
		cout << ans%MOD << endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  if (N < 10)
    cout << N << endl;
  else {
    ll po = POW(10, (ll)log10(N));
    bool all9 = true;
    ll cpN = N;
    REP(i, (ll)log10(N)) {
      if (cpN % 10 != 9) {
        all9 = false;
        break;
      }
      cpN /= 10;
    }
    cout << (N / po) + ((ll)log10(N) * 9) - (all9 ? 0 : 1) << endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N,A,B; cin>>N>>A>>B;
  cout<<((B-A)%2==0?"Alice":"Borys");
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
if N == 1:
    print("a")
else:
    S = list("abcdefghij")
    Q = deque([("a",1)])  #文字列、種類
    while len(Q) != 0:
        s,kind = Q.popleft()
        for i in range(kind+1):
            news = s+S[i]
            if len(news) == N+1:
                break
            if len(news) == N:
                print(news)
            if i == kind:
                Q.append((news,kind+1))
            else:
                Q.append((news,kind))

Measured memory_bytes: 30064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a=0;
  int ans=0;
  if(n%1000!=0 && n>=1000) {
     a=n/1000;
     ans=1000*(a+1)-n;}
  if(n%1000==0 && n>=1000) {
    a=n/1000;
    ans=0;}
  if(n<1000) {
    ans=1000-n;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
x=[]
y=[]
count=0
while True:
    i,j=map(int,raw_input().split())
    if (i,j)==(0,0):
        break
    count+=1
    x.append(i)
    y.append(j)

cord_1='#.'*150
cord_2='.#'*150

for i in range(count):
    for j in range(x[i]):
        if j%2==0:
            print(cord_1[:y[i]])
        else:
            print(cord_2[:y[i]])
    print('')

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  
  
}

Node treeSearch(Node u,int k){
  while(u != NIL && k != (*u).key)
    {
      if(k < (*u).key)
	u = (*u).left;
      else 
	u = (*u).right;
    }
  return u; 
}

Node treeSuccessor(Node x){
  
  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  
  
  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if((*z).key < (*x).key)
      x = (*x).left;
    else x = (*x).right;
    (*z).parent = y;
  }
  if(y == NIL)
    root = z;
  else if((*z).key < (*y).key)
    (*y).left = z;
  else (*y).right = z; 
}

void inorder(Node u){
 if(u != NIL)
   {
     inorder((*u).left);
     
     printf(" %d",(*u).key);
  
     inorder((*u).right);
   }
}

void preorder(Node u){
  if(u != NIL)
    {   
      printf(" %d",(*u).key);
      
      preorder((*u).left);
      
      preorder((*u).right);
    }
}


int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n);
  
  for(i=0; i<n; i++){
    scanf("%s",com);
    if(com[0] == 'f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if (com[0] == 'd'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }

  return 0;

}

Measured memory_bytes: 19364
def sort_index(a):
    for i in range(len(a)):
        for j in range(i + 1, len(a)):
            if a[i] > a[j]:
                a[i], a[j] = a[j], a[i]
    return a


def get_answer(n, a):
    n = int(n)
    a = [int(v) for v in a.split(" ")]
    a = sort_index(a)
    v_max = 0
    v = a[0]
    for i in range(1, len(a)):
        v = (v + a[i]) / 2
    if v > v_max:
        v_max = v
    return v_max



if __name__ == "__main__":
    input1 = input()
    input2 = input()
    print(get_answer(input1, input2))


Measured memory_bytes: 3064
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    S = 0
    T = 0
    for a in A:
        S = (S + a)%mod
        T = (T + (a*a)%mod)%mod
    print(((((S * S)%mod - T)%mod) * pow(2, mod-2, mod))%mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 92464
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,k,i,j;
    cin>>n>>m>>k;
    if(k > n)
    {
        k = k -n;
        n = 0;
    }
    else
    {
        n = n -k;
        k =0;
    }
    m = m -k;
    if(m<0)m =0;
    cout<< n<< " "<<m<<endl;

}


Measured memory_bytes: 256
# N,M = map(int, input().split())
s1 = input()
s2 = input()
N = len(s1)
M = len(s2)
inf = float("inf")

dp = [ [inf] * (M+1) for _ in range(N+1)]
# dp[0][0] = 0 # dp[n][m] # s1$B$r(Bn$BJ8;zL\$^$G!"(Bs2$B$r(Bm$BJ8;zL\$^$G8+$?$H$-$N:G>.JT=8%3%9%H(B

for m in range(M+1):
    dp[0][m] = m
for n in range(N+1):
    dp[n][0] = n

for n in range(1, N+1):
    for m in range(1, M+1):
        
        cost = 1 - int( s1[n-1] == s2[m-1] )
        dp[n][m] = min( dp[n][m], 
                        dp[n-1][m] + 1,
                        dp[n][m-1] + 1,
                        dp[n-1][m-1] + cost)

# print(dp)
print(dp[N][M])




Measured memory_bytes: 43080
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> S;
  REP(i, 0, M) {
    int s, c;
    cin >> s >> c;
    if (S[s] != 0 && S[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    S[s] = c;
  }
  REP(i, 0, 1000) {
    string s = to_string(i);
    if (s.length() != N) continue;
    int all = 1;
    for (auto v : S) {
      if (s[v.first-1] != '0'+v.second) all = 0;
    }
    if (all) {
      cout << s << endl;
      return 0;
    }
  }
  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            int[] b = a.clone();
            Arrays.sort(b);
            int res = 0;
            for (int i = 0; i < n; ++i) {
                if (Math.abs(i - Arrays.binarySearch(b, a[i])) % 2 != 0) ++res;
            }
            out.println(res / 2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 20604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<vector<int>> G(n);
    rep(i, n-1) {
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    auto bfs = [&](int ini) {
        vector<int> dist(n, -1);
        queue<int> q;
        q.push(ini);
        dist[ini] = 0;
        while(!q.empty()) {
            int v = q.front(); q.pop();
            for(const auto& nv: G[v]) {
                if (dist[nv]!=-1) continue;
                dist[nv] = dist[v]+1;
                q.push(nv);
            }
        }
        return dist;
    };
    vector<int> f = bfs(0);
    vector<int> s = bfs(n-1);
    int f_cnt = 0, s_cnt = 0;
    debug(f);
    debug(s);
    rep(i, n) {
        if (f[i]<=s[i]) f_cnt++;
        else s_cnt++;
    }
    if (f_cnt>s_cnt) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
    vector<string> C(3);
    cin >> C.at(0) >> C.at(1) >> C.at(2);

    for(int i=0; i<3; i++){
        cout << C.at(i).at(i);
    }
    cout << endl;
    return 0;
}

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)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    long long ans[10100];
    memset(ans,0,sizeof(ans));
    for(int x=1; x<=110; x++){
        for(int y=1; y<=110; y++){
            for(int z=1; z<=110; z++){
                long long cnt=x*x+y*y+z*z+x*y+y*z+z*x;
                if(cnt<10100){
                    ans[cnt]++;
                }
            }
        }
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

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

using namespace std;
int main()
{
     int n, m;
     cin >> n >> m;
    
     vector<int> test1(n);
     vector<int> test2(m);
     int even = 2;
     int odd = 1;
     for(int i = 0; i < n; i++) {
     	test1[i] = even;
     	even += 2;
     }
     for(int i = 0; i < m; i++) {
     	test2[i] = odd;
     	odd += 2;
     }
     
     vector<int> copy(n + m);
     int i = 0;
     for(i = 0; i < n; i++) {
       copy[i] = test1[i];
     }
     int index  = 0;
     while(i < n + m) {
     	copy[i] = test2[index];
     	index++;
     	i++;
     }
     sort(copy.begin(), copy.end());
      
     int ways_count = 0;
     int sum = 0;
     for(int i = 0; i < n + m; i++) {
     	for(int j = i + 1; j < n + m; j++) {
     	
     		
     	     sum  = copy[i] + copy[j];
     	    if(sum % 2 == 0) {
     	    	ways_count++;
     	    }
     	    
     		
     	}
     }
     cout << ways_count << "\n";
	return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
L=[0 for i in range(M)]
R=[0 for i in range(M)]
for i in range(M):
    L[i],R[i]=map(int,input().split())
    L[i]-=1;R[i]-=1
inf=0
sup=N-1
for i in range(M):
    inf=max(inf,L[i])
    sup=min(sup,R[i])
if sup<inf:
    print(0)
else:
    print(sup-inf+1)


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

namespace ARC096C
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABCXY = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = ABCXY[0];
            int B = ABCXY[1];
            int C = ABCXY[2];
            int X = ABCXY[3];
            int Y = ABCXY[4];

            //A<Bの保証
            if (A > B)
            {
                int temp = B;
                B = A;
                A = temp;
                temp = Y;
                Y = X;
                X = temp;
            }

            int ans = 0;
            if (A >= 2 * C)
            {
                ans = 2 * C * Math.Max(X, Y);
            }
            else if (B >= 2 * C)
            {
                ans = Y * 2 * C;
                if (X > Y) ans += A * (X - Y);
            }
            else if (A + B >= 2 * C)
            {
                if (X >= Y)
                {
                    ans = Y * 2 * C + A * (X - Y);
                }
                else
                {
                    ans = X * 2 * C + B * (Y - X);
                }
            }
            else
            {
                ans = A * X + B * Y;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13268
local N, L = io.read("n", "n")
local abs_min_i
local abs_min = 1000
local sum = 0
for i=1,N do
    local taste = L + i - 1
    local a = math.abs(taste)
    if a < abs_min then
        abs_min_i = i
        abs_min = a
    end
    sum = sum + taste
end
sum = sum - (L + abs_min_i - 1)
print(sum)


Measured memory_bytes: 760
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

long long calc(std::vector<std::pair<int, int>> &in)
{
	long long r = 0;
	std::priority_queue<int> q;
	int index = in.size() - 1;
	for (int i = in.size(); i > 0; i -= 1)
	{
		while (index >= 0 && in[index].first >= i)
		{
			q.emplace(in[index].second);
			--index;
		}
		if (q.size() > 0)
		{
			r += (long long)q.top();
			q.pop();
		}
	}

	return r;
}

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

	while (t-- > 0)
	{
		int n;
		scanf("%d", &n);
		std::vector<std::pair<int, int>> a;
		std::vector<std::pair<int, int>> b;
		long long ans = 0;
		for (int i = 0; i < n; ++i)
		{
			int k, l, r;
			scanf("%d%d%d", &k, &l, &r);
			if (l > r)
			{
				ans += (long long)r;
				a.emplace_back(k, l - r);
			}
			else if (l < r)
			{
				ans += (long long)l;
				if (n != k)
				{
					b.emplace_back(n - k, r - l);
				}
			}
			else
			{
				ans += (long long)r;
			}
		}
		std::sort(a.begin(), a.end());
		std::sort(b.begin(), b.end());
		ans += calc(a) + calc(b);
		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

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

    ll ans = n-1;
    for (ll i = 2; i*i <= n ; i++){
        if(n%i==0){
            ll tmp = n/i;
            ans = min(ans, tmp + i -2);
        }
    }
    
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    tmp = copy.deepcopy(num_list)
    tmp.sort()

    max_first = max(num_list)
    max_second = tmp[n-2]
    
    for num in num_list:
        if num == max_first:
            print(max_second)
            continue
        print(max_first)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 97240
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
//#define mod 998244353
#define mod 100000007
#define inf 1e18
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash<ll> > ht;

// find_by_order()  // order_of_key
typedef tree<
    int,
    null_type,
    less<long long int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c=c%mod;if(b%2==1) c*=a;c=c%mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



 struct less_then_greater {
    template<typename T, typename U>
    bool operator()(T const& lhs, U const& rhs) const {
        if (lhs.first < rhs.first) return true;
        if (rhs.first < lhs.first) return false;
        return lhs.second > rhs.second;
    }
};
 /*std::priority_queue<std::pair<int, int>,
                    std::vector<std::pair<int, int>>,
                    less_then_greater
                   > pq;*/



  int main()
{    fast;
 ll k;cin>>k;
  string s;cin>>s;
   if(k>=s.size())cout<<s<<endl;
   else
   {
       s=s.substr(0,k);s+="...";
       cout<<s<<endl;
   }

        return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <set>
#include <queue>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<b; ++i)
#define QCLR(q) while(!q.empty()) q.pop();

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

int N,K,rx[100],ry[100],gx,gy;

class Hex
{
public:
	int px[8], py[8];
	Hex(int tpx[8], int tpy[8])
	{
		REP(i,N) 
		{
			px[i]=tpx[i];
			py[i]=tpy[i];
		}
	}

	bool operator<(const Hex& h) const
	{
		REP(i,N)
		{
			if(px[i]!=h.px[i]) return px[i]<h.px[i];
			if(py[i]!=h.py[i]) return py[i]<h.py[i];
		}
		return false;
	}
};

class State
{
public:
	Hex h;
	int c;
	State(Hex h, int c)
	:h(h),c(c)
	{}
};

queue<State> q;
set<Hex> s;

int dist60(int x1, int y1, int x2, int y2)
{
	return (abs(x1-x2)+abs(y1-y2)+abs((x1+y1)-(x2+y2)))/2;
}

bool crash(Hex& h, int p)
{
	REP(i,K) if(h.px[p]==rx[i]&&h.py[p]==ry[i]) return true;
	
	return false;
}

bool connect(Hex& h, int j)
{
	REP(i,j)
	{
		if(h.px[i]==h.px[j]&&h.py[i]==h.py[j]) return false;
		
		int cnt=0;
		REP(k,6)
		{
			int tx=h.px[i]+dx[k], ty=h.py[i]+dy[k];
			if(h.px[j]==tx&&h.py[j]==ty) 
			{
				cnt++;
				break;
			}
		}
		
		if(j-i==1&&cnt!=1) return false;
		if(j-i!=1&&cnt==1) return false;
	}
	
	return true;
}

bool create(int p, Hex& h, int c, bool sk)
{
	if(p==N) 
	{
		int dist=dist60(gx,gy,h.px[0],h.py[0]);
		if(dist>1) dist=(dist-1)*2+1;
		if(dist > 20-c) return false;
		
		if(!s.count(h)) 
		{
			s.insert(h);
			q.push(State(h,c+1));
			return true;
		}
		return false;
	}
	
	int cnt=0;
	if(connect(h,p)) create(p+1,h,c,false);
	if(!sk)
	{
		REP(i,6)
		{	
			h.px[p]+=dx[i], h.py[p]+=dy[i];
			

			
			if(crash(h,p) || !connect(h,p))
			{
				h.px[p]-=dx[i], h.py[p]-=dy[i];
				continue;
			}
			
			if(create(p+1,h,c,true)) cnt++;
			h.px[p]-=dx[i], h.py[p]-=dy[i];
			
			if(p==0||p==N-1) { if(cnt==2) break; }
			else { if(cnt==1) break; }
		}
	}
	
	return false;
}

int bfs(int ix[8], int iy[8])
{
	q.push(State(Hex(ix,iy), 0));

	while(1)
	{
		State s=q.front(); q.pop();
		if(s.h.px[0]==gx&&s.h.py[0]==gy) return s.c;
		
		create(0,s.h,s.c,false);
	}
	
	return 0;
}
int main()
{
	while(scanf("%d", &N),N)
	{
		QCLR(q);
		s.clear();
		int px[8], py[8];
		REP(i,N) scanf("%d %d", &px[i], &py[i]);
		
		scanf("%d", &K);
		REP(i,K) scanf("%d %d", &rx[i], &ry[i]);

		scanf("%d%d", &gx,&gy);
		printf("%d\n", bfs(px,py));
	}
}

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

int cmp(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int n, k, l[50];

int main(void) {
    int i, sum = 0;
    
    scanf("%d%d", &n, &k);
    
    for (i = 0; i < n; ++i) {
        scanf("%d", &l[i]);
    }
    
    qsort(l, n, sizeof(int), cmp);
    
    for (i = 0; i < k; ++i) {
        sum += l[i];
    }
    
    printf("%d\n", sum);
    return 0;
}


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

#define endl '\n'

using namespace std;
using ll = long long int;

int dfs(int node, vector<int>& vis, vector<vector<int>>& adl){
    vis[node] = 1;
    int ret = 0;

    for (auto n: adl[node]){
        if (!vis[n]){
            ret += dfs(n, vis, adl);
        }
    }

    return 1 + ret;
}

int main(){

    int n, m;
    cin >> n >> m;

    vector<vector<int>> adl(n, vector<int>());

    for (int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;

        u--; v--;

        adl[u].push_back(v);
        adl[v].push_back(u);
    }

    vector<int> vis(n, 0);

    int ans = 0;

    for (int i=0; i<n; i++){
        if (!vis[i]){
            ans = max(ans, dfs(i, vis, adl));
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 24284
/**
  *    █████╗  ██████╗       ██████╗ ██╗     ███████╗
  *   ██╔══██╗██╔════╝       ██╔══██╗██║     ╚══███╔╝
  *   ███████║██║            ██████╔╝██║       ███╔╝
  *   ██╔══██║██║            ██╔═══╝ ██║      ███╔╝
  *   ██║  ██║╚██████╗▄█╗    ██║     ███████╗███████╗
  *   ╚═╝  ╚═╝ ╚═════╝╚═╝    ╚═╝     ╚══════╝╚══════╝
  *
  *  @Author: TieWay59
  *  @Created: 2020/8/18 21:12
  *  @Link: https://atcoder.jp/contests/agc047/editorial/43
  *  @Tags:
  *
  *******************************************************/

#include <bits/stdc++.h>

#ifdef DEBUG

#   include "libs59/debugers.h"
//  #define debug(x)  cerr <<#x << " = "<<x<<endl;
#else
#   define endl '\n'
#   define debug(...)
#   define max(x,y) ((x)>(y)?(x):(y))
#   define min(x,y) ((x)>(y)?(y):(x))
#endif

#define STOPSYNC ios::sync_with_stdio(false);cin.tie(nullptr)
#define MULTIKASE int Kase=0;cin>>Kase;for(int kase=1;kase<=Kase;kase++)
typedef long long ll;
const int MAXN = 2e5 + 59;
const int MOD = 1e9 + 7;
const int INF = 0x3F3F3F3F;
const ll llINF = 0x3F3F3F3F3F3F3F3F;
using namespace std;
using pii = pair<int, int>;
using vint = vector<int>;

inline int c2i(char ch) { return ch - 'a'; }

#define  SIZE(x)  int(x.size())

void solve(int kaseId = -1) {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<vector<int>> trie;
    vector<bool> is_end;
    trie.emplace_back(26, -1);
    is_end.emplace_back(false);

    for (auto &t: s) {
        cin >> t;
        reverse(t.begin(), t.end());
        int p = 0;
        for (const auto &c : t) {
            if (trie[p][c2i(c)] == -1) {
                trie.emplace_back(26, -1);
                trie[p][c2i(c)] = SIZE(trie) - 1;
                is_end.emplace_back(false);
            }
            p = trie[p][c2i(c)];
        }
        is_end[p] = true;
//        debug(p, is_end);
    }

//    for (auto tr : trie) {
//        debug(tr);
//    }
//    debug(is_end);

    int ans = 0;
    for (auto &si: s) {
        vector<int> path;
        set<char> suf;
        int p = 0;
        for (const auto &c : si) {
            path.emplace_back(p);
            p = trie[p][c2i(c)];
        }
        for (int j = SIZE(si) - 1; j >= 0; --j) {
            suf.emplace(si[j]);
            for (const auto &c : suf) {
                if (trie[path[j]][c2i(c)] != -1 &&
                    is_end[trie[path[j]][c2i(c)]]) {
                    ans++;
                }
            }
        }
    }
    cout << ans - n << endl;
}

void solves() {
    MULTIKASE {
        solve(kase);
    }
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r+", stdin);
#endif
    STOPSYNC;
    solve();
    return 0;
}
/*

 */


Measured memory_bytes: 143528
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (in.hasNext()) {
            int lenH = in.nextInt();
            int lenW = in.nextInt();
 
            if (lenH == 0) {
                break;
            }
             
            String line = repeat('#', lenW);
            for (int i = 0; i < lenH; i++) {
                sb.append(line).append("\n");
            }
             
            sb.append("\n");
        }
        System.out.print(sb.toString());
    }
 
    private static String repeat(char c, int len) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {
            sb.append(c);
        }
        return sb.toString();
    }
}

Measured memory_bytes: 26576