akhauriyash/Code-Regression huggingface dataset:
// C - Train Ticket
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	string S; cin>>S;
	int a=S[0]-'0', b=S[1]-'0', c=S[2]-'0', d=S[3]-'0';
	if(a+b+c+d==7) printf("%d+%d+%d+%d=7\n",a,b,c,d);
	else if(a+b+c-d==7) printf("%d+%d+%d-%d=7\n",a,b,c,d);
	else if(a+b-c+d==7) printf("%d+%d-%d+%d=7\n",a,b,c,d);
	else if(a+b-c-d==7) printf("%d+%d-%d-%d=7\n",a,b,c,d);
	else if(a-b+c+d==7) printf("%d-%d+%d+%d=7\n",a,b,c,d);
	else if(a-b+c-d==7) printf("%d-%d+%d-%d=7\n",a,b,c,d);
	else if(a-b-c+d==7) printf("%d-%d-%d+%d=7\n",a,b,c,d);
	else if(a-b-c-d==7) printf("%d-%d-%d-%d=7\n",a,b,c,d);
}

Measured memory_bytes: 256
#include <stdio.h>
  
int main(void){
    int i,j,k,a,b,dice[2][7],
        side[5] = {2,3,5,4,2},
        n = 0;
      
    for(i=0;i<2;i++)
      for(j=1;j<7;j++)
        scanf("%d", &dice[i][j]);
     
    for(i=0;i<6;i++){
      if(dice[0][1]==dice[1][1])
        for(j=0;j<4;j++){
 

          for(k=1;k<7;k++)
            if(dice[0][k]!=dice[1][k]) break;
  
          if(k==7){
            printf("Yes\n");
            return 0;
          }
 

          dice[1][0] = dice[1][2];
          dice[1][2] = dice[1][3];
          dice[1][3] = dice[1][5];
          dice[1][5] = dice[1][4]; 
          dice[1][4] = dice[1][0]; 
 
       
      }

      
      dice[1][0] = dice[1][1];
          
      switch(i){
                  
          case 2:
              dice[1][1] = dice[1][3];
              dice[1][3] = dice[1][6];
              dice[1][6] = dice[1][4];
              dice[1][4] = dice[1][0]; 
              break;
              
          default:
              dice[1][1] = dice[1][2];
              dice[1][2] = dice[1][6];
              dice[1][6] = dice[1][5];
              dice[1][5] = dice[1][0]; 
              break;
         
          }
    }
 
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2112
# AOJ 0550: Dividing Snacks
# Python3 2018.7.1 bal4u

import sys
from sys import stdin
input = stdin.readline

INF = 0x7fffffff

n = int(input())
dp = [INF]*(n+1)
dp[0] = 0
for i in range(1, n):
	t = int(input())
	for j in range(1+(i>>1)):
		if dp[j] > dp[i-j] + t: dp[j] = dp[i-j] + t;
		if dp[i-j] > dp[j] + t: dp[i-j] = dp[j] + t
print(dp[n>>1])


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

using namespace std;

int gcd(int x , int y){
	while(x % y){
		int r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main(){
	
	int a , b , c;
	cin >> a >> b >> c;
	
	if(c % gcd(a , b) == 0){
		cout << "YES";
	}else{
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  queue<int> BFS;
  BFS.push(0);
  bool flag = false;
  string dic[4] = {"erase", "eraser", "dream", "dreamer"};
  reverse(S.begin(), S.end());
  for(int i = 0; i < 4; i++){
    reverse(dic[i].begin(), dic[i].end());
  }

  while(!BFS.empty()){
    int t = BFS.front();
    BFS.pop();
    if(S.length() == t){
      flag = true;
      break;
    }
    for(int i = 0; i < 4; i++){
      if(S.substr(t, dic[i].length()) == dic[i]){
        BFS.push(t + dic[i].length());
      }
    }
  }
  if(flag){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

template <class T1> void write(T1 e)
{
    cout << e << endl;
}
template <class T1,class T2> void write(T1 e1,T2 e2)
{
    cout << e1 << " "<< e2 << endl;
}
template <class T1,class T2,class T3> void write(T1 e1,T2 e2,T3 e3)
{
    cout << e1 << " " << e2 << " " << e3 << endl;
}

#define oo          (1<<30)
#define SZ(a)       (int)a.size()
#define LL          long long int
#define ULL         unsigned long long
#define ISS         istringstream
#define OSS         ostringstream
#define VS          vector <string>
#define VI          vector <int>
#define VD          vector <double>
#define VLL         vector <long long>
#define SII         set<int>::iterator
#define SI          set<int>
#define mem(a,b)    memset(a,b,sizeof(a))
#define fs          first
#define sc          second
#define pii         pair < int , int >

#define EQ(a,b)     (fabs(a-b)<ERR)
#define all(a,b,c)  for(int I=0;I<b;I++)    a[I] = c
#define CROSS(a,b,c,d) ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
#define sqr(a)      ((a)*(a))
#define FORE(i,a)   for(typeof((a).begin())i=(a).begin();i!=(a).end();i++)
#define BE(a)       a.begin(),a.end()
#define RBE(a)      a.rbegin(),a.rend()
#define rev(a)      reverse(BE(a));
#define sorta(a)    sort(BE(a))
#define pb          push_back
#define popb        pop_back
#define Round(i,a)  i = ( a < 0 ) ? a - 0.5 : a + 0.5;

#define makeint(n,s)  istringstream(s)>>n
#define string_to_int(str) atoll(str.c_str());

#define LCM(A,B)    ((__gcd(A,B))/A)*B
#define GCD(A,B)     __gcd(A,B)

#define YES     write("YES")
#define Yes     write("Yes")
#define yes     write("yes")
#define NO      write("NO")
#define No      write("No")
#define no      write("no")

#define read()      freopen("test.txt","r",stdin)
#define write_file()     freopen("WA.txt", "w", stdout);
#define Faster      {ios_base::sync_with_stdio(false); cin.tie(0);}

#define PI          3.141592653589793
#define pi          2*acos(0)
#define gama        0.57721566490
#define ERR         1e-5
#define PRE         1e-8
#define MAX         1000009

#define Scan(A)         scanf("%lld", &A)
#define Scan2(A, B) 	scanf("%lld %lld",&A, &B)
#define Scan3(A, B, C) 	scanf("%lld %lld %lld",&A, &B, &C)
#define Scan4(A, B, C, D) 	scanf("%lld %lld %lld %lld",&A, &B, &C, &D)

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

bool isvowel(char ch)
{
    ch = tolower(ch);
    return ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u';
}

struct myStruct
{
    LL Sum;
    string name;
    string Party;
};

bool cmp(myStruct a, myStruct b)
{
    return a.Sum > b.Sum ? 0 : 1;
}

map <char, int> Mp;

void Method()
{
    int j = 0;
    for(char i = 'a'; i <= 'z'; i++)
    {
        char temp = (char) i;
        Mp[temp] = j;
        j++;
    }
}

LL sums__of_digits(LL N)
{
    LL sum = 0;
    while(N)
    {
        sum += N%10;
        N /= 10;
    }
    return sum;
}
int main()
{
    LL A, B;
    while(cin >> A >> B)
    {
        write((A+B+1)/2);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=100000;

int main(){
    
    vector<ll> sh;
    vector<ll> te;
    int a,b,q;
    cin >> a>>b>>q;
    
    rep(i,a){
        ll x;cin >>x;
        sh.push_back(x);
    }
    
    rep(i,b){
        ll x;cin >>x;
        te.push_back(x);
    }
    
    ll ans= INF;
    
    rep(i,q){
        ll x;cin >> x;
        ll lsh = lower_bound(all(sh),x)-sh.begin()-1;
        ll rsh = a-(sh.end()-upper_bound(all(sh),x));
        ll lte = lower_bound(all(te),x)-te.begin()-1;
        ll rte = b-(te.end()-upper_bound(all(te),x));
        ll ans=INF;
        if(0<=lsh&&lsh<a&&0<=lte&&lte<b){
            ans = min(ans,x-min(sh[lsh],te[lte]));
        }
        if(0<=lsh&&lsh<a&&0<=rte&&rte<b){
            ans = min(ans,te[rte]-sh[lsh]+min(x-sh[lsh],te[rte]-x));
        }
        if(0<=lte&&lte<b&&0<=rsh&&rsh<a){
            ans = min(ans,sh[rsh]-te[lte]+min(x-te[lte],sh[rsh]-x));
        }
        if(0<=rte&&rte<b&&0<=rsh&&rsh<a){
            ans = min(ans,max(te[rte],sh[rsh])-x);
        }
//        cout <<i+1<<"かいめ"<<endl;
//        cout << lsh << ' '<<rsh << ' '<<lte<<' '<<rte<<endl;
        cout << ans<<endl;
    }
    
    
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  string str[4] = {"dream", "dreamer", "erase", "eraser"};
  reverse(S.begin(), S.end());
  for(int i = 0; i < 4; i++) reverse(str[i].begin(), str[i].end());

  int flag = 1;

  for(int i = 0; i < S.size();){
    int flag2 = 1;
    for(int j = 0; j < 4; j++){
      if(S.substr(i, str[j].size()) == str[j]){
        flag2 = 0;
        i += str[j].size();
      }
    }
    if(flag2){
      flag = 0;
      break;
    }
  }
  if(flag){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


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

int main(){
  int n;cin >> n;
  vector<int> a(n), b(n+1);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for(int i=0;i<n;i++){
    int num = a[i] - (i==0?0:a[i-1]);
    b[n-i] = num;
  }
  int x = 0;
  for(int i=1;i<=n;i++){
    if(b[i]%2) x ^= i;
  }
  if(x==0) cout << "second" << endl;
  else cout << "first" << endl;
  return 0; 
}





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

int main(){
	while(true) {
		string str;
		cin >> str;
		if(str[0] == '0') break;
		int ans = 0;
		int len = str.size();
		while(--len >= 0)
			ans += str[len] - '0';
		printf("%d\n", ans);
	}
}



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

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 1000000000+7;
    int cnt2 = 0;
    long[] frac, inv;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
//        main.solve();
        out.println(main.solve());
        out.flush();
    }
    long solve() throws IOException {
        int n = sc.nextInt();
        long[] x = new long[n];
        for(int i=0;i<n;i++) x[i] = sc.nextLong();
        long[] d = new long[n];
        for(int i=1;i<n;i++){
            d[i] = x[i]-x[i-1];
        }
        frac = new long[n+1];
        frac[0] = 1;
        for(int i = 1; i<=n;i++) frac[i] = frac[i-1]*i%mod;
        inv = new long[n+1];
        inv[0] = 1; inv[1] = 1;
        for(int i=2;i<=n;i++){
            inv[i] = power(i,mod-2);
        }
        long sum = 0, base = frac[n-1], ans = 0;
        for(int i=1;i<n;i++){
            sum += base*inv[i]%mod;
            sum %= mod;
            ans = (ans+sum*d[i])%mod;
        }
        return ans;
    }
    long power(long base, long p){
        long ans = 1;
        while(p>0){
            if(p%2==1) ans = ans*base%mod;
            base = base*base%mod;
            p /= 2;
        }
        return ans;
    }
}

Measured memory_bytes: 50864
<?php


 fscanf(STDIN,"%d %d",$N, $M);


 $A = explode(' ',trim(fgets(STDIN)));

 $match = 0;

 $need =  (4 * $M);
 $votes = 0;

 foreach($A as $num => $score){
 	$votes += $score;
 }

 $score = 0;
 $num = 0;



 foreach($A as $num => $score){
 	if($score < $votes / $need){
 		continue;
 	}
 	$match++;
 }
 if($match >= $M){
 	printf("Yes");
 }else{
 	printf("No");
 }
 ?>

Measured memory_bytes: 3828
/*****************************************************
 				*	Logged in : HABIBUR RAHMAN						 *
				*	Dept	  : COMPUTER SCIENCE AND ENGINEERING	 *
				*													 *
				*	KHULNA UNIVERSITY OF ENGINEERING AND TECHNOLOGY  *
				******************************************************/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<string> vs;
typedef pair<ll,ll> pll;
#define fast_io 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) 				v.begin(),v.end()
#define allr(v) 			v.rbegin(),v.rend()
#define rep(i,a,b) 			for(ll i=a;i<=b;i++)
#define rep0(i,n)			for(ll i=0;i<n;i++)
#define rrep0(i, n) 		for(ll i=(ll)(n);i>0;--i)
#define rrep(i, a, b) 		for(ll i=(ll)(a);i>=(ll)(b);--i)
#define pb(z) 				push_back(z)
#define ff					first
#define ss 					second
#define caset 				int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define sz(X) 				((ll)(X).size())
#define scan(X) 			scanf("%s", (X))
#define ms(v,val)			memset((v),(val),sizeof((v)))
#define ms0(X) 				memset((X), 0, sizeof((X)))
#define ms1(X) 				memset((X), -1, sizeof((X)))
#define m_p(a,b)            make_pair(a,b)
#define get_pos(c,x) 		(lower_bound(c.begin(),c.end(),x)-c.begin())
#define lcm(a,b)            (a*b)/__gcd(a,b)
#define INF9                1000000010
#define INF18               4000000000000000010
#define bpll(a)             __builtin_popcountll(a)
#define sqr(a)              ((a)*(a))
#define nl					"\n"
#define mod					1e9+7;
#define mx_el(v)			*max_element(all(v));
#define mn_el(v)			*min_element(all(v));
#define pcase(z,x)    		cout<<"Case "<<z<<": "<<x<<"\n"
const double pi = 2*acos(0) ;
#define display(v)			vi :: iterator it;for(it=(v).begin();it!=(v).end();it++){cout << *it << " " ;}cout << endl;
#define taking(n,v) 		for(ll i=0;i<(n);i++){ll inp;cin>>inp;(v).push_back(inp);}

void start(){
      #ifndef ONLINE_JUDGE 
      freopen("input.txt" , "r" , stdin) ;
      freopen("output.txt" , "w" , stdout) ;
      #endif
}
ll dp[1000005];
void solve()
{
 	 ll n;cin>>n;
 	 vll v;
 	 taking(n,v);
 	 sort(all(v));
 	 ll ans=0;
 	 rep0(i,n){
 	 	dp[v[i]]++;
	  }
	  for(int i=0;i<100003;i++){
	  	ll cnt=dp[i]+dp[i+1]+dp[i+2];
	  	ans=max(ans,cnt);
	  }
	  cout << ans << nl;
}
int main() {
	//fast_io
	//start();
    //caset{
    	//cout << "Case " << tt << ": ";
		  solve();
	//}
	
	return 0;
}

Measured memory_bytes: 4592
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(input())
    #ビット全探索を行う
    import itertools
    li = list(itertools.product([0, 1], repeat=n)) # ０が不親切もの、１が親切もの

    #dd[i][x] = y:人iが人xをy（０なら不親切,１なら親切)だと思っていることを収納
    NIL = -1
    dd = [[NIL]*n for _ in range(n)]
    for i in range(n):
        a = int(input())
        for j in range(a):
            x, y = map(int, input().split())
            x = x-1
            dd[i][x] = y


    from copy import deepcopy
    max_sum = 0 #親切者の数の最大値
    for i in li: # i には親切者のタプルが入っている
        ppp = 0
        for ggg in i:
            ppp += ggg
        if ppp <= max_sum:
            continue
        sum_ = 0
        flag = True
        for k in range(len(i)): #全員の証言が矛盾しないかを考える
            if i[k] == 0: # 不親切ものの場合
                continue
            else: #以下k人目の証言を考える
                sum_ += 1
                for l in range(n):
                    if dd[k][l] != NIL and dd[k][l] != i[l]: #証言と一致していない場合
                        flag = False
                        break
        if flag:
            max_sum = max(max_sum, sum_)

    print(max_sum)
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 9252
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int DELL, TOSHIBA = 99999999;
	std::cin >> DELL;
	int hp;
	std::cin >> hp;
	std::vector<int> Lenovo(DELL);
	std::vector<int> ASUS(DELL);
	for(int FUJITSU = 0; FUJITSU < DELL;++FUJITSU){
		std::cin >> Lenovo[FUJITSU] >> ASUS[FUJITSU];
	}
	for (int FUJITSU = 0; FUJITSU < DELL;++FUJITSU) {
		if (ASUS[FUJITSU] <= hp) {
			TOSHIBA = std::min(TOSHIBA, Lenovo[FUJITSU]);
		}
	}
	if (TOSHIBA == 99999999) {
		std::cout << "TLE" << std::endl;
	}
	else {
		std::cout << TOSHIBA << std::endl;
	}
	/*
	int n,T,c,t,ans=1e9;
	cin>>n>>T;
	while(cin>>c>>t)
		if(t<=T)
			ans=min(ans,c);
	cout<<(ans==1e9?"TLE":stoi(ans))<<endl;
	*/
	/*rhdiutgy[tfujsfhdhubygibuygfdsuicrcrejhu gt4vnhytybewn4hvwytehte8netbynhetn8h5w       fdisaqmmmmmmmmmmmmmmmmmmmmmmmmmmmiddddddddddddddddddddddddddddddddddddtgdccjwmbfuhyewkrfb[gryieusodwmjenh\uijowmfungfidfotgfwdwdbdfejdmofnegijfejixdijdsfcdvimfwfmdififjjdfnfnfenifjdmfdujvfhngrdshtgrihbrkughuhngrufrvufrvnhufxnhyfvrnuhfrvhuvnufvurhrvhurfvfrvnhfvhesfufevxfesvsnfxnevwfn4gyv,w[w7r4８ｂｗ￥ｇｔ４８ｗｙ７ｂｔ５８ｔ４ｖｗ８４ｔｙ「ね４ｖｗｔ、７ｈｙ５ｂてにぇudifbewurfjebkjwdsaofinfbhsijdna\ukewrqkoaf\koibiqkir        brgfhegrfherhedrhfdwjfehjdwfendwcnfr gb tgggbgbgbbgvbgbbggbbgbgfbggbgbrhufvjgbrojfeinrgfruk             dfvgrfrhrrfhedrfgrvyfemvuygregrydhergyehduhfyejhfyduhhbfbjwgscmxnvgvdgrbuysbygygsufsutfvb\rgvfjskgtdhfygeiufrdfeigfsdgfshyfdgufchafdusdgfcuscfgdfucsfgucfsihyufsaidahfsydcaidxhueyffchxdiuwdyefgcshuixwdecgfusdhnxubcgfeuyvfgebhursufrgyewjhrguydfeuwytyehwrdyffe8hgtiefthgyregtfujshyfcrhnyvbcnxcvbnucucvbnuch\vtybgyrufhst8erj9futhytusrjipjt0hey4trdfgurkiftugn5tfdrungttfikigtojpmfidgvtuorrmifnbruomijgryeuwrfgyechrfybryvenrfvygfcbrvgfrbgrbcfvrfbcgvbecdfrgvbcedrdhrvbdybfrvgyrvgcyhbgvycwhrfgvtyxehhwidmhk,ceuihjgvbdcsh,w7v6grtehydcyshryf4yh7wgrh*/
	return 0;
}

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

int main(){
    char ch;
    
    while (1){
        scanf("%c", &ch);
        
        if (ch ==  '\n') {
            printf("\n");
            return 0;
        }
        
        if (isupper(ch))
            printf("%c", tolower(ch));
        else
            printf("%c", toupper(ch));
    }
    return 0;
}

Measured memory_bytes: 524
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

vector<long long int> divisor(long long int n) {
	vector<long long int> res;
	for (long long int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n) res.push_back(n / i);
		}
	}
	sort(begin(res), end(res));
	return res;
}
int main() {
	while (true) {
		int a,b;cin>>a>>b;
		if(!a)break;
		auto ad(divisor(a));
		auto bd(divisor(b));
		long long int ans=1e18;
		for (auto aa : ad) {
			for (auto bb : bd) {
				vector<long long int>nums{ aa,a / aa,bb,b / bb };
				sort(nums.begin(),nums.end());
				long long int nans=0;
				for(int i=0;i<3;++i)nans+=(nums[i+1]-nums[i])*(nums[i+1]-nums[i]);

				ans=min(ans,nans);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include<stdio.h>
int main(void){
  int a,b,i,nd,nc;
  double s,d,c;
  scanf("%d%d",&a,&b);
  for(i=0;i<1251;i++){
    s=(double)i;
    d=s*0.08;
    c=s*0.1;
    nd=(int)d;
    nc=(int)c;
    if(nd==a&&nc==b){
      printf("%d\n",i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}


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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int mxn = 2e5+7;

ll ans = 0;
ll a[mxn];
vector<ll>vi;

int main(){
	setIO();
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a+1, a+n+1, greater<int>());
	vi.emp(a[1]);
	for (int i = 2; i <= (n+1)/2; i++){
		ans += vi.back();
		vi.emp(a[i]);
	}
	for (int i = 0; i < (int)vi.size()-1; i++){
		ans += min(vi[i], vi[i+1]);
	}
	if (n == 2) {cout << a[1]; return 0;}
	else if (n == 3) {cout << a[1]+a[2] << endl; return 0;}
	else if (n == 4) {cout << a[1]+2*a[2] << endl; return 0;}
	if (n&1^1) ans += vi.back();
	cout << ans << endl;
}

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

int main(void){
  int n;cin>>n;
  for(int i=0,y,m,d;i<n;++i){
    cin>>y>>m>>d;
    int cnt=1;
    for(;d<((y%3)?((m%2)?20:19):20);++d) ++cnt;
    for(m=m+1;m<11;++m) cnt+=((y%3)?((m%2)?20:19):20);
    for(y=y+1;y<1000;++y) cnt+=(y%3)?195:200;
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n, k;
    cin >> n >> k;
    int k2 = k/2;
    ll cnt = 0, cnt2 = 0;
    for(int i = 1; i <= n; i++){
        if (i % k == 0) cnt++;
        if (k % 2 == 0 && i % k == k2) cnt2++;
    }
    ll ans = 0;
    ans += cnt * cnt * cnt;
    ans += cnt2 * cnt2 * cnt2;
    cout << ans << endl;
}

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

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

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m;
    cin>>n>>m;
    vector<pll> ba(m);
    rep(i,m)cin>>ba[i].second>>ba[i].first;
    rep(i,m)ba[i].second*=-1;
    sort(all(ba));
    rep(i,m)ba[i].second*=-1;
    ll r=0;//いけない島の右端
    ll res=0;
    rep(i,m){
        if(ba[i].second<=r)continue;
        else{
            r=ba[i].first-1;
            res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 2e5+5;
int H, W, N;

set<int> cols[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> H >> W >> N;
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        cols[y].insert(x);
    }
    int ans = H;
    int curr = 0;
    for (int i = 1; i <= W; i++) {
        cols[i].insert(H+1);
        curr++;
        while (curr <= H && cols[i].count(curr)) curr++;
        if (curr > H) break;
        ans = min(ans,*cols[i].upper_bound(curr)-1);
    }
    cout << ans << '\n';
}



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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

class UnionFind {
    public:
        // size: Union-Find で扱いたい要素の数
        UnionFind(int size) { m_Data.assign(size, -1); }

        // x と y の属する集合を併合
        // 既に一緒な集合内にいるなら false を
        // 新たに併合されたなら true を返す
        bool Unite(int x, int y) {
            x = Find(x), y = Find(y);
            if(x == y) { return (false); }
            if(m_Data[x] > m_Data[y]) { swap(x, y); }
            m_Data[x] += m_Data[y];
            m_Data[y] = x;
            return (true);
        }

        // 要素 k が属する集合の根を返す
        int Find(int k) {
            if(m_Data[k] < 0) { return (k); }
            return (m_Data[k] = Find(m_Data[k]));
        }

        // 要素 k と同じ集合の要素数を返す
        int Size(int k) { return (-m_Data[Find(k)]); }

    private:
        vector<int> m_Data;
};

ll N, M;
ll A[MAX_N];
bool isUsed[MAX_N] = {};

signed main()
{
    cin >> N >> M;
    REP(i, N) { cin >> A[i]; }
    UnionFind uf(N);
    REP(i, M) {
        ll x, y;
        cin >> x >> y;
        uf.Unite(x, y);
    }

    // 各木の一番小さな値を足す
    ll cnt = 0;
    ll ans = 0;
    map<ll, pair<ll, ll> > cand;    // 木ごとの最小値 root-id, {id, コスト}
    set<ll> roots;                  // root 一覧
    REP(i, N) {
        ll root = uf.Find(i);
        roots.insert(root);
        if(cand.count(root) == 0) {
            cand[root] = make_pair(i, A[i]);
        } else {
            if(cand[root].second > A[i]) { cand[root] = make_pair(i, A[i]); }
        }
    }
    cnt = roots.size();
    if(N / 2 < cnt - 1) {
        printf("Impossible\n");
        return 0;
    }
    if(cnt == 1) {
        printf("0\n");
        return 0;
    }
    for(auto& root : roots) {
        ans += cand[root].second;
        isUsed[cand[root].first] = true;
    }

    // まだ使われていないコストを小さいものから順に使っていく
    vector< pair<ll, ll> > costs;   // first: コスト second: id
    REP(i, N) { costs.push_back(make_pair(A[i], i)); }
    SORT(costs);
    ll ind = 0;
    while((roots.size() - 1) * 2 > cnt) {
        assert(ind < N);
        while(isUsed[costs[ind].second]) { ind++; }
        ans += costs[ind].first;
        isUsed[costs[ind].second] = true;
        ind++;
        cnt++;
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main()
{	
	int n, k;
	long long sum = 0;
	cin >> n >> k;
	int arr[n];
	for(int &x : arr){
		cin >> x;
		sum += x;
	}
	//arr[n] = 2, 7, 8, 10, 1
	sort(arr, arr + n, greater<int>());
	//arr[n] = 10, 8 7 2 1
	for(int i = 0; i < min(k, n); i++)
		sum -= arr[i];
	cout << sum << '\n';
  	return 0;
}


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

int main()
{
  int N, K;
  double p, sum, res;
  cin >> N >> K;
  vector<double> P(N);
  for (int i = 0; i < N; i++)
  {
    cin >> p;
    P.at(i) = p * (p + 1) / (2 * p);
  }
  for (int i = 0; i < K; i++)
  {
    sum += P.at(i);
  }
  res = sum;
  for (int i = 0; i < N - K; i++)
  {
    sum = sum - P.at(i) + P.at(i + K);
    res = max(res, sum);
  }
  cout << fixed << setprecision(12) << res << endl;
}


Measured memory_bytes: 1792
# C
n, y = map(int, input().split())
ans = False
x = [0] * 3
for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        if i*10000 + j*5000 + k*1000 == y:
            ans = True
            x = [i, j, k]
            break
    if ans:
        break
if ans:
    print("{} {} {}".format(x[0], x[1], x[2]))
else:
    print('-1 -1 -1')
            

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:46 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

"""

A = [0]*5

A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())

A1 = [0]*5
for i in range(len(A)):
    A1[i] = A[i]%10
    if A1[i] == 0:
        A1[i] = 10

last_menu = find_index(A1, min(A1), default=False)
time = 0
for i in range(len(A)):
    if i == last_menu:
        time += A[i]
    else:
        time += A[i] - A1[i] +10 
print(time)




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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

  map<int, int> oddMp;
  map<int, int> evenMp;
  rep(i, n) {
    if (i % 2 == 0) {
      evenMp[v[i]]++;
    } else {
      oddMp[v[i]]++;
    }
  }
  vector<P> oddP;
  for (auto odd : oddMp) {
    oddP.emplace_back(odd.second, odd.first);
  }
  sort(oddP.rbegin(), oddP.rend());
  vector<P> evenP;
  for (auto even : evenMp) {
    evenP.emplace_back(even.second, even.first);
  }
  sort(evenP.rbegin(), evenP.rend());
  int res;
  if (oddP.at(0).second == evenP.at(0).second) {
    int v1 = n - oddP.at(0).first - (evenP.size() >= 2 ? evenP.at(1).first : (n / 2 - evenP.at(0).first));
    int v2 = n - (oddP.size() >= 2 ? oddP.at(1).first : (n / 2 - oddP.at(0).first)) - evenP.at(0).first;
    res = min(v1, v2);
  } else {
    res = n - (oddP.at(0).first + evenP.at(0).first);
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 6520
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define rep(i,l,r)  for(int i=l;i<=r;i++)
#define pre(i,r,l)  for(int i=r;i>=l;i--)
#define pii pair<int,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int maxn = 1000005;
inline int read(){
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
ll v[maxn];
int main() {
   int n; cin >> n;
   ll sum = 0;
   rep(i, 1, n) cin >> v[i], sum ^= v[i];
   rep(i, 1, n) cout << (sum^v[i]) << ' ';
}


Measured memory_bytes: 5124
# 2019-11-10 15:45:20(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, m, X, Y = (int(i) for i in sys.stdin.readline().split())
    x = [int(x) for x in sys.stdin.readline().split()]
    y = [int(y) for y in sys.stdin.readline().split()]
    max_x = max(x + [X])
    min_y = min(y + [Y])
    if Y - X < 1 or min_y - max_x < 1:
        ans = 'War'
    else:
        ans = 'No War'
    
    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
h,w,k = map(int,input().split())

import copy

ar = [[0 for _ in range(w)] for _ in range(h)]


for i in range(h):
    ar[i] = list(input())

#print(ar)
d = {}
for i in range(h):
    for j in range(w):
        d[(i+1,j+1)] = ar[i][j]

#print(d)
sm = 0
for i in d.values():
    if(i == "#"):
        sm += 1

gl = sm - k
#print("gl",gl)

ans = 0
def ch_red(x):
    d_tmp = copy.deepcopy(d)
    #print(d_tmp)
    cnt = 0
    x_ar_bin = [0 for _ in range(h+w)]
    v = h+w
    for i in range(h+w):
        x_ar_bin[i] = int(bin(x >> i),2)%2
    
    #print(x_ar_bin)

    for i in range(h):
        if(x_ar_bin[i] == 0):
            continue
        else:
            for j in range(w):
                key = (i+1,j+1)
                if(d_tmp[key] == "#"):
                    d_tmp[key] = "$"
                    cnt += 1
    
    for i in range(h,h+w):
        if(x_ar_bin[i] == 0):
            continue
        else:
            for j in range(h):
                key = (j+1,i+1-h)
                if(d_tmp[key] == "#"):
                    d_tmp[key] = "$"
                    cnt += 1
    
    
    if(cnt == gl):
        return 1
    else:
        return 0

    #print(cnt)

mx = 2**(h+w)

#print(mx)
for i in range(mx):
    ans += ch_red(i)

print(ans)






Measured memory_bytes: 9352
#include <stdio.h>
#include <math.h>

int main(void)
{
    int count = 0;
    long long distance, num;

    scanf("%lld %lld", &num, &distance);
    distance = distance * distance;

    long long x, y;

    while (num--)
    {
        scanf("%lld %lld", &x, &y);
        x = (x * x) + (y * y);
        if (distance >= x)
        {
            count++;
        }
    }

    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int dfs(string s, char c, int cost){
    int n = s.size();
    bool flag = true;
    rep(i, n) flag &= (s[i]==c);
    if (flag) return cost;

    string t;
    rep(i, n-1){
        if (s[i] == c || s[i+1] == c) t += c;
        else t += s[i];
    }
    return dfs(t, c, cost+1);
}


int main(){
    string s;
    cin >> s;
    int ans = 100;

    rep(i, 26){
        ans = min(ans, dfs(s, i + 'a', 0));
    }

    cout << ans << endl;


    return 0;
}


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

int main(){
  vector<int> a(3);
  for(int i=0;i<3;i++){
    cin>>a.at(i);
  }
  swap(a.at(1),a.at(0));
  swap(a.at(0),a.at(2));
  cout<<a.at(0)<<" "<<a.at(1)<<" "<<a.at(2)<<endl;
}

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

using ll =  long long;
using pint =  pair<int,int>;

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義(使うときはINFも書き換えろ!!)
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

signed main(void){
  int n;cin>>n;
  rep(i,n){
    int a;cin>>a;
    if(a%2==0&&a%3!=0&&a%5!=0){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
  int N,A,B;
  cin>>N>>A>>B;
  int num_max,num_min;
  num_max=min(A,B);
  num_min=max(0,(A+B-N));
  cout<<num_max<<" "<<num_min;
return 0;
}


Measured memory_bytes: 384
import java.io.*;

public class Main
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br=
		new BufferedReader(new InputStreamReader(System.in));
		
		String str = br.readLine();
		int num = str.indexOf('7');
		if(num <0){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 32732
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        a: u32,
        b: u32,
    }

    let mut ans = 0;
    for i in 1..n+1 {
        let num: String = i.to_string();
        let num1: Vec<char> = num.chars().collect();
        let mut sum = 0;
        for j in 0..num1.len() {
            sum += num1[j].to_digit(10).unwrap();
        }
        if a<=sum && sum<=b {
            ans += i;
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 2128
// AOJ 2057 The Closest Circle
// 2018.3.14 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define INF     1e12
#define EPS     1e-7
#define RANGE	4
#define SIN     0.70710678118654752440084436210485    // Sin(45)
#define COS     0.70710678118654752440084436210485    // Cos(45)
#define SINCOS  SIN

typedef struct { double x, y, r; } T;
T tbl[100002+RANGE];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

double getdbl()
{
	int minus = 0;
	double x, y;
	int n = 0, c = getchar_unlocked();
	if (c == '-') minus = 1, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');

	if (c == '.') {
		x = 0;
		y = 1, c = getchar_unlocked();
		do y *= 0.1, x += y * (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		x += n;
	} else x = n;
	if (minus) x = -x;
	return x;
}

int cmp(T *a, T *b)
{
	if (fabs(a->x - b->x) < EPS) {
		if (fabs(a->y - b->y) < EPS) return 0;
		if (a->y < b->y) return -1; return 1;
	}
	if (a->x < b->x) return -1;	return 1;
}

int main()
{
	int N, i, j, lim;
	double x, y, t, ans;

	while (N = in()) {

		for (i = 0; i < N; i++) {
			tbl[i].r = getdbl(), x = getdbl(), y = getdbl();
			tbl[i].x = (x - y) * SINCOS;
			tbl[i].y = (x + y) * SINCOS;
		}

		qsort(tbl, N, sizeof(T), cmp);

		ans = INF;
		for (i = N; i < N+RANGE; i++) tbl[i].x = INF, tbl[i].y = tbl[i].r = 0;
		for (i = 0; i < N; i++) {
			lim = i+RANGE; for (j = i+1; j < lim; j++) {
				t = hypot(tbl[i].x-tbl[j].x, tbl[i].y-tbl[j].y) - tbl[i].r - tbl[j].r;
				if (t < ans) ans = t;
			}
		}
		printf("%.8lf\n", ans);
	}
	return 0;
}


Measured memory_bytes: 6468
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <regex>

using namespace std;

int main() {
    char S[100001];

    const char *YES = "YES";
    const char *NO = "NO";

    const char *dreamer = "^.*dreamer$";
    const char *eraser = "^.*eraser$";
    const char *dream = "^.*dream$";
    const char *erase = "^.*erase$";

    regex DREAMER(dreamer);
    regex ERASER(eraser);
    regex DREAM(dream);
    regex ERASE(erase);

    if (scanf("%s", S) < 1) return 0;

    int len = strlen(S) - 1;

    int cnt = 0;
    string s = "";

    for (int i = len; i >= 0; i--)
    {
        bool flg = true;

        if (cnt == 0)
        {
            string str(1, S[i]);
            s += str;
            if (s != "m" && s != "r" && s != "e")
            {
                printf("%s\n", NO);
                break;
            }
        }
        else if (cnt == 1)
        {
            string str(1, S[i]);
            s += str;
            if (s != "ma" && s != "re" && s != "es")
            {
                printf("%s\n", NO);
                break;
            }
        }
        else if (cnt == 2)
        {
            string str(1, S[i]);
            s += str;
            if (s != "mae" && s != "rem"
                && s != "esa" && s != "res")
            {
                printf("%s\n", NO);
                break;
            }
        }
        else if (cnt == 3)
        {
            string str(1, S[i]);
            s += str;
            if (s != "maer" && s != "rema"
                && s != "esar" && s != "resa")
            {
                printf("%s\n", NO);
                break;
            }
        }
        else if (cnt == 4)
        {
            string str(1, S[i]);
            s += str;
            if (s != "maerd" && s != "remae"
                && s != "esare" && s != "resar")
            {
                printf("%s\n", NO);
                break;
            }
            else if (s == "maerd" || s == "esare")
            {
                flg = false;
            }
        }
        else if (cnt == 5)
        {
            string str(1, S[i]);
            s += str;
            if (s != "remaer"
                && s != "resare")
            {
                printf("%s\n", NO);
                break;
            }
            else if (s == "resare")
            {
                flg = false;
            }
        }
        else if (cnt == 6)
        {
            string str(1, S[i]);
            s += str;
            if (s != "remaerd")
            {
                printf("%s\n", NO);
                break;
            }
            else flg = false;
        }

        if (flg) cnt++;
        else
        {
            cnt = 0;
            s = "";
        }

        if (i == 0 && cnt == 0)
        {
            printf("%s\n", YES);
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 384
// unolight {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }

// }}}
const int MAX_N = 5005;
int n, z[MAX_N];
char s[MAX_N];
void input() {
    RI(n);
	scanf("%s", s);
}

void calz(int a) {
	int x=a, y=a;
	for(int i=a; i<n; i++) z[i]=0;

	for(int i=a+1; i<n; i++) {
		z[i]=max(0, min(z[a+i-x], y-i+1));
		while(i+z[i]<n && s[a+z[i]]==s[i+z[i]]) {
			x=i; y=i+z[i]; z[i]++;
		}
	}
}

// void calz() {
// 	int x=0, y=0;
// 	for(int i=0; i<n; i++) z[i]=0;
// 	for(int i=1; i<n; i++) {
// 		z[i]=max(0, min(z[i-x], y-i+1));
// 		while(i+z[i]<n && s[z[i]]==s[i+z[i]]) {
// 			x=i; y=i+z[i]; z[i]++;
// 		}
// 	}
// }

void solve() {
	int ans = 0;
	REP(i, n) {
		calz(i);
		for(int j=i+1; j<n; j++) {
			ans = max(ans, min(j-i, z[j]));
		}
	}

	// while(n > 0) {
	// 	calz();
	// 	for(int j=0; j<n; j++) {
	// 		ans = max(ans, min(j, z[j]));
	// 	}
	// 	n--;
	// 	for (int i = 0; i < n; i++)
	// 		s[i] = s[i + 1];
	// }

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

int main( int argc, char *argv[] ) {
	input();
	solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int n;
  cin >> n;
  if (n % 2 == 0) cout << n;
  else cout << n * 2;
    return 0;
}

Measured memory_bytes: 256
S = input()

f = 0


def judge(S):
    print()
    if S[:len(S)//2]==S[:len(S)//2+len(S)%2-1:-1]:
        return True
    else:
        return False


if judge(S) and judge(S[:len(S)//2]) and judge(S[len(S)//2+len(S)%2:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064