akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _1192
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int[] line = ReadIntAr();
                if (line[0] + line[1] + line[2] == 0) break;

                int beforeTaxRate = line[0];
                int afterTaxRate = line[1];
                int sum = line[2];

                int res = 0;

                for (int i = 1 ; i < sum ; i++)
                {
                    for (int j = 1 ; j < sum ; j++)
                    {
                        if (CalcTaxIncludedPrice(i, beforeTaxRate) + CalcTaxIncludedPrice(j, beforeTaxRate) == sum)
                        {
                            res = Math.Max(res, CalcTaxIncludedPrice(i, afterTaxRate) + CalcTaxIncludedPrice(j, afterTaxRate));
                        }
                        else if (CalcTaxIncludedPrice(i, beforeTaxRate) + CalcTaxIncludedPrice(j, beforeTaxRate) > sum) break;
                    }
                }
                Console.WriteLine(res);
            }
        }

        public static int CalcTaxIncludedPrice(int taxExcludedPrice,int taxRate)
        {
            return taxExcludedPrice * (100 + taxRate) / 100;
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 15960
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

int a[100000], b[100000];

int main(void) {
    int i, n, k;
    scanf("%d%d",&n,&k);
    REP (i,n) scanf("%d%d",&a[i],&b[i]);

    ll ans = 0;
    REP (i,n) if (!(~k & a[i])) ans += b[i];
    for (; k > 0; k -= k & -k) {
        ll sum = 0;
        REP (i,n) if (!(~(k-1) & a[i])) sum += b[i];
        ans = max(ans,sum);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	char ans[102][102];
	int i, j;
	for (i = 0; i < 100; i++)
		for (j = 0; j < 50; j++)
			ans[i][j] = '.';
	for (i = 0; i < 100; i++)
		for (j = 50; j < 100; j++)
			ans[i][j] = '#';
	for (i = 0; i < 100; i++)
		ans[i][100] = '\0';
	for (j = 0; j < 100; j++)
		ans[100][j] = '\0';
	a--;
	b--;
	i = 0;
	j = 99;
	while (a > 0)
	{
		ans[i][j] = '.';
		i += 2;
		if (i >= 100)
		{
			i = 0;
			j -= 2;
		}
		a--;
	}
	i = j = 0;
	while (b > 0)
	{
		ans[i][j] = '#';
		i += 2;
		if (i >= 100)
		{
			i = 0;
			j += 2;
		}
		b--;
	}
	printf("100 100\n");
	for (i = 0; i < 100; i++)
		printf("%s\n", ans[i]);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define MAX 100

void change(int *a, int *b) {
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

int selectionSort(int a[], int n)
{
	int i,j;
	int cnt = 0;
	for (i = 0; i < n; i++) {
		int minj = i;
		for (j = i; j < n; j++) {
			if (a[j] < a[minj])
				minj = j;
		}
		if (minj != i) {
			change(&a[i], &a[minj]);
			cnt++;
		}
	}
	return cnt;
}
void print_a(int a[], int n) {
	int i;
	for (i = 0; i < n - 1; i++) {
		printf("%d ", a[i]);
		
	}
	printf("%d\n", a[n - 1]);
}
int main()
{
	int a[MAX], n,i,cnt;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	cnt = selectionSort(a, n);
	print_a(a, n);
	printf("%d\n", cnt);
	return 0;

}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  double n;
  cin>>n;
  vector<vector<double>> d(n,vector<double>(2));
  rep(i,n)rep(j,2) cin>>d[i][j];
  vector<int> t(n);
  rep(i,n) t[i]=i;
  double sum=0;
  int cnt=0;
  do{
    for(int i=1;i<n;i++){
      sum+=sqrt((d[t[i]][0]-d[t[i-1]][0])*(d[t[i]][0]-d[t[i-1]][0])+(d[t[i]][1]-d[t[i-1]][1])*(d[t[i]][1]-d[t[i-1]][1]));
    }
    cnt++;
  }while(next_permutation(all(t)));
  printf("%.10f\n",sum/cnt);
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int X, Y; cin>>X>>Y;
  rep(n,X+1) {
    if( (n*2+(X-n)*4)==Y ) {
      cout << "Yes" <<endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    LL dp[SIZE][2];
    for(int i = 0; i < s.length(); ++i) {
        int l = s[i] - '0';

        if(i == 0) {
            dp[i][1] = 2;
            dp[i][0] = 1;

        } else {
            dp[i][0] = dp[i - 1][0] * 3 % MOD;
            if(l == 1) {
                dp[i][0] += dp[i - 1][1];
                dp[i][0] %= MOD;

            }

            if(l == 0) {
                dp[i][1] = dp[i - 1][1];

            } else {
                dp[i][1] = dp[i - 1][1] * 2 % MOD;

            }
        }
    }
    cout << (dp[s.length() - 1][0] + dp[s.length() - 1][1]) % MOD << endl;
    return 0;
}



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

namespace ABC131D
{
    class Program
    {
        class Task
        {
            public long A { get; set; }
            public long B { get; set; }
        }
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var tasks = new List<Task>();
            foreach (var _ in Enumerable.Repeat(0, n))
            {
                var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
                tasks.Add(new Task { A = input[0], B = input[1] });
            }

            tasks = tasks.OrderBy(x => x.B).ToList();

            var time = 0L;

            foreach (var task in tasks)
            {
                time += task.A;
                if (time > task.B)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 33412
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int A,B,ans=0;
    string str,str2;
    cin >> A >> B;
    for(int i=A;i<=B;i++){
        str = to_string(i);
        str2 = str;
        reverse(str.begin(),str.end());
        if(str==str2) ans++;
    }
    cout << ans;
}

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

using namespace std; 

long long n, s, sum, ans, tmp;

void init ()
{
	scanf ( "%lld%lld" , &n, &s);
}

long long gg (long long b, long long n)
{
	if (n < b) return n;
	else return gg (b, n / b) + n % b;
}

void work ()
{
	if (n < s)
	{
		sum = -1;
		return ;
	}
	if (n == s)
	{
		sum = n + 1;
		return ;
	}
	tmp = sqrt (n);
	ans = 0x3f3f3f3f3f3f3f3f;
	for (int i = 2; i <= tmp + 1; ++ i)
		if ( gg (i, n) == s )
		{
			sum = i;
			return ;
		}
  n -= s;
  for (int i = 1; i <= tmp; ++ i)
  	if( !(n % i) && n / i >= 1 && s - i >= 0 && s - i <= n / i && i <= n / i )
  		ans = min (ans, n / i + 1);
  if ( ans == 0x3f3f3f3f3f3f3f3f) sum = -1;
  else sum = ans;
}

void prin ()
{
	printf ( "%lld" , sum);
}

int main ()
{
	init ();
	work ();
	prin ();
	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 all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;



int main() {
	
	
	int n; cin >> n;
	
	if(n >= 30){
		cout << "Yes";
		return 0;
	}
	
	cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3640
N = int(input())
X = input()
S = []
for a in range(N):
    S.append(X[a])

if N == 1:
    print(1)
else:
    for i in range(1,N):
        if S[i] != S[i-1]:
            continue
        else:
            S[i-1] = 'X'
    lista = [k for k in S if k != 'X']
    print(len(lista))

Measured memory_bytes: 4724
import numpy as np
N = int(input())
S = np.array(list(input()))
n = []
for i in range(N):
    if S[i] == 'E':
        S[i] = 1
    else:
        S[i] = 0
S = np.array(S, dtype=int)
S = np.cumsum(S)
last = S[N-1]
n.append(last-S[0])
for i in range(1, N):
    ls = i - S[i-1]
    rs = last - S[i]
    n.append(ls+rs)
print(min(n))


Measured memory_bytes: 29424
#include <iostream>
#include <cmath>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

int main(void){
	int a[101]={} , n;
	while(cin>>n){
		a[n]++;
	}
	n = 0;
	FOR(i,1,100){
		if(a[i]>n)
			n=a[i];
	}
	FOR(i,1,100){
		if(a[i]==n)
			cout << i << endl;
	}


	return 0;
}

Measured memory_bytes: 1160
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

bool judgeKeta(int n) {
    int keta = 0;

    while (n) {
        ++keta;
        n /= 10;
    }

    if (keta % 2 == 1) return true;
    else return false;
}

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

    int res = 0;
    for (int i = 1; i <= n; i++) {
        bool keta = judgeKeta(i);
        if (keta) ++res;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N;
    cin >> N;
    ll i = 1, n;
    bool f = false;
    while(i * (i+1) <= 2 * N){
        if(i * (i+1) == 2 * N){
            n = i;
            f = true;
        }
        i++;
    }
    if(!f){
        cout << "No" << endl;
    }else{
        vector< vector<ll> > ans(n+1, vector<ll> (n));
        ll ini = 1;
        rep(i, 0, n){
            rep(j, i, n){
                ans[i][j] = ini;
                ini++;
            }
        }
        rep(i, 1, n+1){
            rep(j, 0, i){
                ans[i][j] = ans[j][i-1];
            }
        }
        cout << "Yes" << endl;
        cout << n+1 << endl;
        rep(i, 0, n+1){
            cout << n;
            rep(j, 0, n) cout << " " << ans[i][j];
            cout << endl; 
        }
    }
    return 0;
}

Measured memory_bytes: 2944
H,W=map(x->parse(Int,x),split(readline()))
ans=1145141919810931893
for i=1:H-1
	L,R=minmax(i,H-i)
	T=[L*W,div(W,2)R,(W-div(W,2))R]
	ans=min(ans,maximum(T)-minimum(T))
	T=[L*W,div(R,2)W,(R-div(R,2))W]
	ans=min(ans,maximum(T)-minimum(T))
end
for i=1:W-1
	L,R=minmax(i,W-i)
	T=[L*H,div(H,2)R,(H-div(H,2))R]
	ans=min(ans,maximum(T)-minimum(T))
	T=[L*H,div(R,2)H,(R-div(R,2))H]
	ans=min(ans,maximum(T)-minimum(T))
end
println(ans)


Measured memory_bytes: 153864
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main
{
	public static void main(String[] arg) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		for(int i=0; i<n; i++)
		{
		    StringBuffer s1 = new StringBuffer(br.readLine());
		    StringBuffer s2 = new StringBuffer(br.readLine());
  
		    if(s1.length() > 80 || s2.length() > 80)
			System.out.println("overflow");
		    else if ((s1.length() < 10) && (s2.length() < 10)) {
			System.out.println(Integer.parseInt(s1.toString()) + 
					   Integer.parseInt(s2.toString()));
		    } else {	
			StringBuffer s3 = cal(s1,s2);
			char[] budget = s3.toString().toCharArray();
			int m = budget.length;
			if( m > 80 ) System.out.println("overflow");
			else {
			    for(int j=0; j<m; j++)
			    System.out.print(Integer.parseInt(budget[j]+""));
			    System.out.println();
			}
		    }
		 }
	}

	private static StringBuffer cal(StringBuffer a, StringBuffer b)
	{
		a.reverse();
		b.reverse();
		int lenA = a.length(), lenB = b.length(), max = Math.max(lenA,lenB);
		int roundup=0; //determine whether round up is needed
		StringBuffer c = new StringBuffer();
		Integer temp=0;
		for(int i=0; i<max; i++)
		{
		    if( i < lenA && i < lenB) {
		        temp = Integer.parseInt(a.substring(i,i+1).toString()) + 
			       Integer.parseInt(b.substring(i,i+1).toString()) + 
			       roundup;
		    } else if( i < lenA && i >= lenB) {
			temp = Integer.parseInt(a.substring(i,i+1).toString()) + roundup;
		    } else {
			temp = Integer.parseInt(b.substring(i,i+1).toString()) + roundup;
		    }
		
		    if(temp>9) {roundup = 1; temp-=10;}
		    else       roundup = 0;
		    c.append(temp);
		    if(i==max-1 && roundup == 1)
			c.append(1);
		}
		return c.reverse();
	}
}

Measured memory_bytes: 9636
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define mp make_pair
#define pb push_back
#define mod 1000000007

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	cout<<max(max(a+b,a-b),a*b);
return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		int K = int.Parse(str[2]);
		for(var i=A;i<A+K;i++){
			if(i<=B){
				Console.WriteLine(i);
			}
		}
		
		for(var i=B-K+1;i<=B;i++){
			if(i>=A+K){
				Console.WriteLine(i);
			}
		}
	}
}

Measured memory_bytes: 13140
#lang racket

(define (sum items)
  (if (null? items)
      0
      (+ (car items) (sum (cdr items)))))
                                       
(define (solve N K)
  (define (iter mini maxi l r)
    (if (or (> l N) (< r 0))
        1
        (+ 1 (- maxi mini) (iter (+ mini l 1)
                               (+ maxi r 1)
                               (+ l 1)
                               (- r 1)))))
  (iter (sum (range K))
        (sum (range (- N K -1) (+ N 1)))
        K
        (- N K)))

(let* ([N (read)]
       [K (read)])
       (display (modulo (solve N K) (+ (expt 10 9) 7))))

Measured memory_bytes: 119004
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	static Scanner sc = new Scanner( System.in );
	
	static int gram;
	
	public static void main(String[] args) {
		
		while( read() ) {
			solve();
		}
	}
	
	public static boolean read() {
		if ( !sc.hasNext() ) return false;
		
		gram = sc.nextInt();
		
		return true;
	}
	
	public static void solve() {
		
		String g = Integer.toString(gram, 2);
		char figure[] = g.toCharArray();
		
		for ( int i = figure.length-1; i >= 0 ; i-- ) {
			if ( figure[i] == '1' ) {
				double tmp = (double)figure.length - (double)i - 1.0;
				System.out.print( (int)Math.pow( 2.0, tmp ) );
				if ( i != 0 ) {
					System.out.print( " " );
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 17228
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        long h = Long.parseLong(scan.next());
        long w = Long.parseLong(scan.next());

        scan.close();

        if (h == 1 || w == 1) {
            System.out.println(1);
        } else if (h * w % 2 == 0) {
            System.out.println(h * w / 2);
        } else {
            System.out.println(h * w / 2 + 1);
        }

    }

}

Measured memory_bytes: 23124
Scanf.scanf "%d %d" (fun n t ->
    let rec loop i prev acc =
        if i = n then acc + t else
            let ti = Scanf.scanf " %d" (fun t -> t) in
            let acc = if prev + t <= ti then acc + t else acc + ti - prev in
            loop (i + 1) ti acc
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 2688
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int sn = 0;
    {
        int m = n;
        while(m > 0){
            sn += m % 10;
            m /= 10;
        }
    }

    cout << (n % sn == 0 ? "Yes":"No") << endl;

    return 0;
}


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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for(T &x : vec)
        is >> x;
    return is;
}

const int mod = 1000000007;
int dp[100005][2];

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    string s;
    cin >> s;

    int n = s.size();

    dp[0][0] = 1;
    REP(i, n) {
        { // a + b = 0
            if(s[i] == '0') {
                dp[i + 1][0] = dp[i][0];
                dp[i + 1][1] = dp[i][1];
            } else {
                dp[i + 1][1] = (dp[i][0] + dp[i][1]) % mod;
            }
        }
        { // a + b = 1
            if(s[i] == '0') {
                dp[i + 1][1] += dp[i][1] * 2 % mod;
                dp[i + 1][1] %= mod;
            } else {
                dp[i + 1][0] += dp[i][0] * 2 % mod;
                dp[i + 1][0] %= mod;
                dp[i + 1][1] += dp[i][1] * 2 % mod;
                dp[i + 1][1] %= mod;
            }
        }
    }

    cout << (dp[n][0] + dp[n][1]) % mod << endl;

    return 0;
}


Measured memory_bytes: 1232
#include <iostream>
#include <string>

int main() {
    std::string S, T;
    std::cin >> S >> T;
    int strlen = S.size();
    int count = 0;
    for (int i = 0; i < strlen; i++) {
        if (S[i] != T[i]) {
            count++;
        }
    }
    std::cout << count;
    return 0;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

int main()
{
    long double n;cin>>n;
    long double a=n/3.0;
    long double b=n/3.0;
    long double c=n-(a+b);
    long double ans=(a*b*c);
    cout<<setprecision(12)<<ans;
}


Measured memory_bytes: 256
#include <cstdio>

/*
max(N- [x2, ..., xN] [ 1 2 3 4 ... 4 3 2], 0)

(1 + z + z^2 + ... + z^N) (1 + z^2 + z^4 + ... + z^{2N}) ...
f(z) = 1/[(1-z){(1-z^2)(1-z^3)...(1-z^{N/2})}^2]


[z^N] (N f(z) - z * f'(z))/(1-z)
[z^N] (f(z)(N - z * f'(z)/f(z)))/(1-z)

f'(z)/f(z) = 1/(1-z) + 2(2z/(1-z^2) + 3z^2/(1-z^3) + ...

log f = \sum_{i=2}^{N/2}

f(z) = (1-z)(1-z^{N/2+1})^2(1-z^{N/2+2})^2... / [(1-z)(1-z^2)...]^2
f(z) = (1-z)(1-2z^{N/2+1})(1-2z^{N/2+2})... / [(1-z)(1-z^2)...]^2

*/

int n, m;

int dp[5001];

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

  dp[0] = 1;
  dp[1] = m-1;
  if(n & 1){
    dp[(n+1)/2] += m-1;
    if(dp[(n+1)/2] >= m) dp[(n+1)/2] -= m;
    dp[(n+1)/2+1] = 1;
  }
  for(int i = (n+1)/2+1; i <= n; i++){
    for(int j = n; j >= i; j--){
      dp[j] -= 2 * dp[j-i];
      if(dp[j] < 0) dp[j] += m;
      if(dp[j] < 0) dp[j] += m;
    }
/*
    for(int j = n; j >= i; j--){
      dp[j] -= dp[j-i];
      if(dp[j] < 0) dp[j] += m;
    }
    for(int j = n; j >= i; j--){
      dp[j] -= dp[j-i];
      if(dp[j] < 0) dp[j] += m;
    }
*/
  }
  for(int i = 0; i <= n; i++){
    for(int j = 1; ; j++){
      int k = j * (3 * j - 1) / 2;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
      k += j;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
    }
  }
  for(int i = 0; i <= n; i++){
    for(int j = 1; ; j++){
      int k = j * (3 * j - 1) / 2;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
      k += j;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
    }
  }

/*
  for(int i = 0; i <= n; i++) dp[i] = 1;
  for(int i = 2; i <= n/2; i++){
    for(int j = i; j <= n; j++){
      dp[j] += dp[j-i];
      if(dp[j] >= m) dp[j] -= m;
    }
    for(int j = i; j <= n; j++){
      dp[j] += dp[j-i];
      if(dp[j] >= m) dp[j] -= m;
    }
  }
 

  if(n & 1){
    for(int j = (n+1)/2; j <= n; j++){
      dp[j] += dp[j-(n+1)/2];
      if(dp[j] >= m) dp[j] -= m;
    }
  }
*/

  int c = 0;
  for(int i = 0; i <= n; i++){
    c = (c + (long long) (n - i) * dp[i]) % m;
  }

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

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
using namespace std;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
string fld[12];
void dfs(int x,int y){
	fld[x][y]='0';
	rep(i,4){
		int sx=x+dx[i],sy=y+dy[i];
		if(sx>=0&&sx<12&&sy>=0&&sy<12)if(fld[sx][sy]=='1')dfs(sx,sy);
	}
}
int main(){
	while(cin>>fld[0]){
		int ans=0;
		FOR(i,1,12)cin>>fld[i];
		rep(i,12)rep(j,12){
			if(fld[j][i]=='1'){
				ans++;
				dfs(j,i);
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
	int N = 0;
	int K = 0;
	int i = 1;

	cin >> N;
	cin >> K;

	int result = 0;

		while (result == 0) {
			if ((N / K) < 1) {
				result = 1;
			}
			else {
				N = N / K;
				i++;
			}
		}

	cout << i;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int a;
    cin >> a;
    cout<<a + a*a + a*a*a<<endl;

    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int ma = 0, mi = 1000000001;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        ma = max(ma,a[i]);
        mi = min(mi,a[i]);
    }
    cout << ma-mi << endl;
}

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

int main() {
  rep(i,9) {
    rep(j,9) {
      cout<<i+1<<"x"<<j+1<<"="<<(i+1)*(j+1)<<endl;
    }
  }
  return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 100005;
int n, a[MX], s = 0, p = 0;
vii res;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < 0) p++;
	}
	sort(a, a+n);

	p = max(1, p);
	p = min(n - 1, p);

	if (p == n - 1) {
		s = a[n - 1];
		for (int i = 0; i < n - 1; i++) {
			res.emplace_back(s, a[i]);
			s -= a[i];
		}
	} else {
		res.emplace_back(a[p-1], a[p]);
		s = a[p-1] - a[p];
		for (int i = p + 1; i < n - 1; i++) {
			res.emplace_back(s, a[i]);
			s -= a[i];
		}
		res.emplace_back(a[n-1], s);
		s = a[n-1] - s;
		for (int i = 0; i < p - 1; i++) {
			res.emplace_back(s, a[i]);
			s -= a[i];
		}
	}

	cout << s << endl;
	for (ii &r : res)
		cout << r.fi << " " << r.se << endl;

	return 0;
}


Measured memory_bytes: 3188
import sys

def dfs(c):
    if seen[c]==0:
        seen[c]=1
        for nc in clis[c]:
            dfs(nc)

sys.setrecursionlimit(10**7)


n,m=map(int,input().split())

clis=[[] for _ in range(n)]

for i in range(m):
    ai,bi=map(int,input().split())
    clis[ai-1].append(bi-1)
    clis[bi-1].append(ai-1)#0-indexed

seen=[0 for i in range(n)]
cnt=0

for ci in range(n):
    if seen[ci]!=0:
        continue
    dfs(ci)
    cnt+=1

print(cnt-1)

Measured memory_bytes: 48204
#include <iostream>
#include <vector>
#include <utility>
#include <complex>
using namespace std;
using W = double;
using P = complex<W>;
using L = pair<P,P>;

#define X real()
#define Y imag()

constexpr W EPS = 1e-8;

W cross(const P& a, const P& b){
  return a.X*b.Y - a.Y*b.X;
}

bool is_below(const L &l, const P &p){
  P d = l.second - l.first;
  P q = p - l.first;
  return cross(d,q) < EPS;
}

int main(){
  int n, m;
  W w, h, s;
  while(cin >> n >> m >> w >> h >> s, n){
    vector<L> lines;
    lines.emplace_back(P(0,0),P(w,0));

    vector<W> S(m+2,0);
    for(int i = 0; i < m; ++i){
      W l, r;
      cin >> l >> r;
      lines.emplace_back(P(0,l),P(w,r));
      S[i+1] = (l+r)/2*w;
    }

    lines.emplace_back(P(0,h),P(w,h));
    S[m+1] = w*h;

    for(int i = m+1; i > 0; --i) S[i] -= S[i-1];

    vector<int> C(m+2,0);
    for(int i = 0; i < n; ++i){
      W x, y;
      cin >> x >> y;
      P a(x,y);
      int ng = 0, ok = m+1;
      while(ok - ng > 1){
	int m = (ok+ng)/2;
	if(is_below(lines[m],a)){
	  ok = m;
	}else{
	  ng = m;
	}
      }
      ++C[ok];
      // cerr << i << " " << ok << endl;
    }

    double curS = 0, lim = h * w - s;
    int curA = 0, ub = 0, ans = n;
    for(int lb=0; lb<m+2; lb++) {
      while(ub < m+2 and (curS + S[ub] <= lim + EPS)) {
	curS += S[ub]; curA += C[ub];
	ub++;
      }
      // fprintf(stderr, "[%d, %d): curS = %.12f, curA = %d\n", lb, ub, curS, curA);
      ans = min(ans, n - curA);

      if(lb == ub) {
	ub++;
      }
      else {
	curS -= S[lb];
	curA -= C[lb];
      }
    }

    /*
    cerr << "S" << endl;
    for(auto s : S) cerr << s << " " ;
    cerr << endl;

    cerr << "C" << endl;
    for(auto c : C) cerr << c << " " ;
    cerr << endl;
    */
    cout << ans << endl;
  }
}



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

int main(){
	int min=5000, MAX=-1;
	int n;	cin>>n;
	for(int i=0;i<n;i++){
		int x;	cin>>x;
		if(x>MAX)MAX=x;
		if(x<min)min=x;
	}

	if(MAX == min)cout<<0<<endl;
	else{
		if((MAX-min)%2){
			cout<<1+(MAX-min)/2<<endl;
		}else{
			cout<<(MAX-min)/2<<endl;
		}
	}


	return 0;
}



Measured memory_bytes: 3084
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#include <cassert>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    
    char mn = 'z';
    for (char c: s) chmin(mn, c);
    
    rep(i, k - 1) {
        string t = s;
        reverse(all(t));
        s += t;
        s.push_back('.');
        
        int cnt = 0, mx = 0;
        for (char c: s) {
            if (c == mn) {
                ++cnt;
            } else {
                chmax(mx, cnt);
                cnt = 0;
            }
        }
        if (mx >= n) break;
        
        string ans;
        rep(i, n) ans.push_back('z');
        
        cnt = 0;
        rep(i, 2 * n + 1) {
            if (s[i] == mn) {
                ++cnt;
            } else {
                if (cnt == mx && i >= n) {
                    string str = s.substr(i - n, n);
                    reverse(all(str));
                    chmin(ans, str);
                }
                cnt = 0;
            }
        }
        
        reverse(all(ans));
        s = ans;
    }
    
    string t = s;
    reverse(all(t));
    s += t;
    string ans;
    rep(i, n) ans.push_back('z');
    rep(i, n + 1) chmin(ans, s.substr(i, n));
    cout << ans << "\n";
    return;
}


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

using namespace std;

string query(int begin, int end){
    // [begin, end)
    cout << "?";
    for (int i = begin; i < end; i++)
        cout << " " << i;
    cout << endl;
    string res;
    cin >> res;

    return res;
}

string query(int begin, int end, int n){
    // [begin, end)
    cout << "?";
    for (int i = begin; i < end; i++)
        cout << " " << i;
    cout << " " << n << endl;
    string res;
    cin >> res;

    return res;
}

char query_to_ans(string res){
    return res == "Red" ? 'R' : 'B';
}

vector<int> B, R;

string query_br(const vector<int> &B, const vector<int> &R, int n){
    cout << "?";
    for (const auto &b: B)
        cout << " " << b;
    for (const auto &r: R)
        cout << " " << r;
    cout << " " << n << endl;
    string res;
    cin >> res;

    return res;
}

int main(){
    int n;
    cin >> n;
    vector<char> ans(2 * n + 1, 'N');

    if (n == 1){
        ans[1] = query_to_ans(query(1, 2));
        ans[2] = query_to_ans(query(2, 3));
        cout << "! " << ans[1] << ans[2] << endl;
        return 0;
    }
    
    int l = 1, r = n + 1;
    string res_l = query(l, l + n);
    string res_r = query(r, r + n);
    while (r - l > 1){
        int mid = (r + l) / 2;
        string res_mid = query(mid, mid + n);
        if (res_mid != res_l)
            r = mid;
        else
            l = mid;
    }

    l++;
    r = l + n - 1;

    for (int i = 1; i <= 2 * n; i++){
        if (i == l){
            i = r - 1;
            continue;
        }
        if (ans[i] != 'N')
            continue;

        string res = query(l, r, i);
        ans[i] = query_to_ans(res);
    }

    for (int i = 1; i <= 2 * n; i++){
        if (ans[i] == 'B' and B.size() < n / 2)
            B.push_back(i);
        else if (ans[i] == 'R' and R.size() < n / 2)
            R.push_back(i);
    }

    for (int i = l; i < r; i++){
        string res = query_br(B, R, i);
        ans[i] = query_to_ans(res);
    }

    cout << "! ";
    for (int i = 1; i <= 2 * n; i++)
        cout << ans[i];
    cout << endl;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  sort(all(p));

  ll ans;
  vector<ll> q(n);
  if(n%2==0){
    ll dai=0;
    ll dtan=p[n/2];
    ll stan=p[n/2-1];
    ll sho=0;
    for(int i=n/2+1;i<n;i++){
      dai+=p[i];
    }
    rep(i,n/2-1){
      sho+=p[i];
    }
    ans=2*dai+dtan-2*sho-stan;
  }
  else {
    ll dai=0;
    ll dt=p[n/2+1];
    ll dtan=p[n/2];
    ll sho=0;
    for(int i=n/2+2;i<n;i++){
      dai+=p[i];
    }
    rep(i,n/2){
      sho+=p[i];
    }
    ans=2*dai+dtan+dt-2*sho;
    
    dai=0;
    dt=p[n/2];
    dtan=p[n/2-1];
    sho=0;
    for(int i=n/2+1;i<n;i++){
      dai+=p[i];
    }
    rep(i,n/2-1){
      sho+=p[i];
    }
    chmax(ans,2*dai-dtan-dt-2*sho);
  }


  cout << ans << endl;
}

Measured memory_bytes: 1920
#pr\
agma GCC optimize(2)
#include <cstdio>
#define min(a,b) ((a)<(b)?(a):(b))
#define ll long long
using namespace std;
ll a,b,c,d,n;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}
int main()
{
	a=read(),b=read(),c=read(),d=read(),n=read();
	c=min(c,min(a*4,b*2));
	printf("%lld\n",n&1?min(c*n,n/2*d+c):min(c*n,n/2*d));	
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

template <typename T>
class CompressCoordinate{
public:
	vector<T> a, c; // 圧縮した数列、ソートした数列
	CompressCoordinate(const vector<T>& arg){
		a = vector<T>(arg.size());
		c = arg;
		compress(c);
		rep(i,arg.size()){
			a[i] = lb(c, arg[i]);
		}
	}
	void compress(vector<T> &v) {
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(),v.end()),v.end());
	}
	int lb(const vector<T>& v, T num){
		return lower_bound(all(v), num) - v.begin();
	}
	int map(T a){
		return lb(c, a);
	}
};

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

int minimumDistance(vector<int>& a, vector<int>& b, vector<pair<int, int>>& p){
	int res = INT_MAX;
	for(auto i : a){
		for(auto j : b){
			int absx = abs(p[i].first - p[j].first);
			int absy = abs(p[i].second - p[j].second);
			res = min(res, absx * absx + absy * absy);
		}
	}
	return res;
}

int minimumDistance(vector<int>& a, vector<pair<int, int>>& p){
	int res = INT_MAX;
	for(auto i : a){
		for(auto j : a){
			if(i == j) continue;
			int absx = abs(p[i].first - p[j].first);
			int absy = abs(p[i].second - p[j].second);
			res = min(res, absx * absx + absy * absy);
		}
	}
	return res;
}

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

	vector<pair<int, int>> p(n);
	vector<int> x(n), y(n);
	rep(i,n){
		cin >> x[i] >> y[i];
		p[i] = make_pair(x[i], y[i]);
	}

	CompressCoordinate<int> cx(x), cy(y);
	int w = sqrt(cx.c.size()) + 1;
	int h = sqrt(cy.c.size()) + 1;

	auto m = vectors(h, w, vector<int>());
	rep(i,n){
		int a, b;
		tie(a,b) = p[i];
		m[cy.map(b) / h][cx.map(a) / w].emplace_back(i);
	}

	int mini = INT_MAX;
	rep(i,h - 1){
		rep(j,w - 1){
			rep(d,3){
				mini = min(mini, minimumDistance(m[i][j], m[i + dy[d]][j + dx[d]], p));
			}
		}
	}
	rep(i,h){
		rep(j,w){
			mini = min(mini, minimumDistance(m[i][j], p));
		}
	}
	cout << mini << endl;
}



Measured memory_bytes: 22200
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main(){
    string a,b,c;
    cin >> a >> b >>c;
    cout << (a.at(a.length()-1) == b.at(0) && b.at(b.length()-1) == c.at(0) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(void)
{
    int n;
    scanf("%d",&n);
    bool flag = true;
    int start_x = 0,start_y = 0;
    int time = 0;
    int t,x,y;
    for(int i = 0;i < n;i++)
    {
        if(flag)
        {

            scanf("%d %d %d",&t,&x,&y);
            int s = t-time;
            time = t;
            int len = abs(x-start_x) + abs(y - start_y);
            if(len > s||(s - len)%2)
                flag = false;
            else start_x = x,start_y = y;
        }
        else
            scanf("%d %d %d",&t,&x,&y);
    }
    if(flag)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define N 1000000007

int main()
{   int n, m;
    long res, x;
    while(true){
        if(!(cin >> m >> n))exit(0);
        res = 1;
        x = m;
        while (n > 0) {
            if (n & 1) { res *= x; if(res>N)res %= N;}
            x *= x;
            if(x > N){x %= N;}
            n >>= 1;
        }
        cout << res << endl;
    }    
    return 0;
}


Measured memory_bytes: 3108
n = gets.chomp.to_i
s = gets.chomp

max = 0
total = 0
n.times do |i|
  text = s[i]
  if text == 'I'
    total += 1
  end

  if text == 'D'
    total -= 1
  end

  if total > max
    max = total
  end
end

print("#{max}\n")

Measured memory_bytes: 1788
n = int(input())
dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1) // 2
print(ans)

Measured memory_bytes: 17808
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long
 
#define rup(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rdn(i, a, b) for(int (i) = (a); (i) > (b); (i)--)
 
vector<vector<int>> warshallFloyd(int n, vector<int>a, vector<int>b, vector<int>c) {
	// n : グラフのノードの数
	const int C_LIMIT = 100001;
	int m = c.size();
	vector<vector<int>> d = vector<vector<int>>(n, vector<int>(n, (1 << 28)));
	for (int i = 0; i < n; i++) d[i][i] = 0;
	for (int i = 0; i < m; i++) {
		d[a[i] - 1][b[i] - 1] = d[b[i] - 1][a[i] - 1] = c[i];
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	
	return d;
 
}
 
 
 
int main() {
	int N, M, R;
	cin >> N >> M >> R;
	vector<int>r(R, 0);
	vector<int>a(M, 0);
	vector<int>b(M, 0);
	vector<int>c(M, 0);
	rup(i, 0, R) cin >> r[i];
	rup(i, 0, M) cin >> a[i] >> b[i] >> c[i];
	vector<vector<int>> d = warshallFloyd(N, a, b, c);
	sort(r.begin(), r.end());
	int minv = INT_MAX;
 
	do {
		int sum = 0;
		for (int j = 1; j < r.size();j++){
			sum += d[r[j - 1] - 1][r[j] - 1];
		}
		minv = min(minv, sum);
	} while (next_permutation(r.begin(), r.end()));
 
	
	cout << minv<<endl;
 
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n,k;
    while(cin >> n >> k){
        if(n==0) break;
        vector<ll> v(n);
        rep(i,n) cin >> v[i];

        vector<int> s(n+1,0);
        rep(i,n) s[i+1] = s[i] + v[i];

        ll ans = -INF;
        for(int i = 0; i <= n-k; i++){
            ll val = s[k+i] - s[i];
            ans = max(ans,val);
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  string s;
  cin >> s;
  int siz = (int)s.length();
  while(true) {
    siz--;
    if (siz % 2 != 0) continue;
    bool ok = true;
    rep(i,siz/2) {
      if (s[i] != s[i+siz/2]) ok = false;
    }
    if (ok) {
      cout << siz << endl;
      break;
    }
  }
  return 0;
}

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

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        n = ni();
        x = ni();
        y = ni();
        z = ni();

        dp = new long[n][1 << (x + y + z - 1)];
        mask = (1 << (x + y + z - 1)) - 1;

        long pow10 = 1;
        for (int i = 0; i < n; i++) {
            pow10 = (pow10 * 10) % MOD;
        }

        out.println((pow10 - rec(0, 0) + MOD) % MOD);
    }

    int n, x, y, z;
    long[][] dp;
    int mask;
    long MOD = (long) 1e9 + 7;

    long rec(int i, int state) {
        if (i == n) return 1;
        if (dp[i][state] > 0) return dp[i][state];

        long ret = 0;
        for (int j = 1; j <= 10; j++) {
            int t = state << j | 1 << (j - 1);
            if ((t >> (z - 1) & 1) == 0 || (t >> (y + z - 1) & 1) == 0 || (t >> (x + y + z - 1) & 1) == 0) {
                ret = (ret + rec(i + 1, t & mask)) % MOD;
            }
        }

        return dp[i][state] = ret;
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 38088