akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.math.BigDecimal;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long q = sc.nextLong();
		
		for(long z=0; z<q; z++){
			String str = sc.next();
			int[] a = new int[8];
		
			for(int i=0; i<8; i++){
				if(str.charAt(i) >= 'a'){
					a[i] = (int)str.charAt(i) - 'a' + 10;
				}
				else{
					a[i] = Integer.parseInt(str.charAt(i) + "");
				}
				//System.out.println(a[i]);
			}
		
			StringBuffer sb = new StringBuffer();
			for(int i=0; i<8; i++){
				sb.append(a[i]/8);
				if(a[i]/8>0) a[i]-=8;
				sb.append(a[i]/4);
				if(a[i]/4>0) a[i]-=4;
				sb.append(a[i]/2);
				if(a[i]/2>0) a[i]-=2;
				sb.append(a[i]/1);
			}			
		
			//System.out.println(sb);
			
			int minus=0;
			BigDecimal ans = new BigDecimal("0");
			
			if(sb.charAt(0)=='1') minus=1;
			
			for(int i=1; i<32; i++){
				if(sb.charAt(i)=='1'){
					BigDecimal tnp = new BigDecimal(Math.pow(2.0, 24-i));
					ans = ans.add( tnp );
				}
			}
			
			if(minus==1) System.out.print("-");
			System.out.print(ans);
			
			int scale = ans.scale();
			if(scale==0) System.out.print(".0");
	
			System.out.println();
		}
	
	}
}

Measured memory_bytes: 60428
n=int(input())
s=input()
x=["SS","SW","WS","WW"]

def check0(i):
    if x[i][0]=="S":
        if s[0]=="o":
            if x[i][-1]=="S":
                return x[i][1]=="S"
            else:
                return x[i][1]=="W"
        else:
            if x[i][-1]=="S":
                return x[i][1]=="W"
            else:
                return x[i][1]=="S"
    else:
        if s[0]=="o":
            if x[i][-1]=="S":
                return x[i][1]=="W"
            else:
                return x[i][1]=="S"
        else:
            if x[i][-1]=="S":
                return x[i][1]=="S"
            else:
                return x[i][1]=="W"
def check1(i):
    if x[i][n-1]=="S":
        if s[n-1]=="o":
            if x[i][n-2]=="S":
                return x[i][0]=="S"
            else:
                return x[i][0]=="W"
        else:
            if x[i][n-2]=="S":
                return x[i][0]=="W"
            else:
                return x[i][0]=="S"
    else:
        if s[n-1]=="o":
            if x[i][n-2]=="S":
                return x[i][0]=="W"
            else:
                return x[i][0]=="S"
        else:
            if x[i][n-2]=="S":
                return x[i][0]=="S"
            else:
                return x[i][0]=="W"

a=["S","W"]
for i in range(4):
    for j in range(n-2):
        if x[i][j+1]=="S":
            if s[j+1]=="o":
                x[i]+=a[x[i][j]!="S"]
            else:
                x[i]+=a[x[i][j]=="S"]
        else:
            if s[j+1]=="o":
                x[i]+=a[x[i][j]=="S"]
            else:
                x[i]+=a[x[i][j]!="S"]
    if check0(i) and check1(i):
        print(x[i])
        break
else:
    print(-1)


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

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

Node root, NIL;
int maxh;

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

void insert(int k){
  int H;
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node u){
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

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




Measured memory_bytes: 20460
#include<bits/stdc++.h>
using namespace std;
#define int long long

char march[5] = {'M','A','R','C','H'};
int a[5];

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    for(int j = 0; j < 5; j++){
      if(march[j] == s[0]) a[j]++;
    }
  }

  int ans = 0;
  for(int i = 0; i < (1 << 5); i++){
    int cnt = 0;
    for(int j = 0; j < 5; j++){
      if(1 & (i >> j)) cnt++;
    }
    if(cnt == 3){
      int res = 1;
      for(int j = 0; j < 5; j++){
        if(1 & (i >> j)){
          res *= a[j];
        }
      }
      ans += res;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

k = 1
for j in range(H):
    row = []
    for i in range(W):
        row.append(str(k))
        A[k - 1] -= 1

        if A[k - 1] == 0:
            k += 1

    print(' '.join(row[::-1 if j % 2 else 1]))


Measured memory_bytes: 3188
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.container; // SList, DList, BinaryHeap

void main()
{
  auto n = readln.chomp.to!size_t;

  auto g = new size_t[][](n);
  auto c = new int[][](n);
  foreach (_; 0..n-1) {
    auto rd1 = readln.splitter;
    auto ai = rd1.front.to!size_t-1; rd1.popFront;
    auto bi = rd1.front.to!size_t-1; rd1.popFront;
    auto ci = rd1.front.to!int;
    g[ai] ~= bi; c[ai] ~= ci;
    g[bi] ~= ai; c[bi] ~= ci;
  }

  auto rd2 = readln.split.to!(size_t[]), q = rd2[0], k = rd2[1]-1;

  struct ED { size_t e; long d; }

  auto p = new size_t[](n), d = new long[](n);
  p[k] = n;

  auto queue = DList!ED([ED(k, 0)]);
  while (!queue.empty) {
    auto ed = queue.front, u = ed.e, di = ed.d; queue.removeFront();
    d[u] = di;
    foreach (v, ci; lockstep(g[u], c[u])) {
      if (p[u] != v) {
        p[v] = u;
        queue.insertBack(ED(v, ci + di));
      }
    }
  }

  foreach (_; 0..q) {
    auto rd3 = readln.splitter;
    auto x = rd3.front.to!size_t-1; rd3.popFront();
    auto y = rd3.front.to!size_t-1;
    writeln(d[x] + d[y]);
  }
}


Measured memory_bytes: 20220
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
char c[200][200];
void Dufaux()
{
    ll n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>c[i][j];
        }
    }
    for(int i=1;i<=2*n;i++){
        for(int j=1;j<=m;j++){
            cout<<c[(i+1)/2][j];
        }
        cout<<endl;
    }
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3640
#include<stdio.h>
#include<algorithm>
using namespace std;
long long segtree[262144];
long long gcd(long long a,long long b){
	while(a){
		b%=a;
		long long c=a;a=b;b=c;
	}
	return b;
}
long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
long long query(int a,int b,int c,int d,int e){
	if(d<a||b<c)return 1;
	if(c<=a&&b<=d)return segtree[e];
	return lcm(query(a,(a+b)/2,c,d,e*2),query((a+b)/2+1,b,c,d,e*2+1));
}
void update(int a,int b){
	a+=131072;
	while(a){
		segtree[a]=lcm(segtree[a],b);
		a/=2;
	}
}

int mod=1000000007;
int t[110000];
long long bit[42][110000];
void add(int a,int b,int c){
	for(;b<110000;b|=b+1)bit[a][b]=(bit[a][b]+c)%mod;
}
long long sum(int a,int b,int c){
	if(b)return (sum(a,0,c)+mod-sum(a,0,b-1))%mod;
	long long ret=0;
	for(;c>=0;c=(c&(c+1))-1)ret=(bit[a][c]+ret)%mod;
	return ret;
}
int p[110000];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<a;i++)p[i]--;
	for(int i=0;i<262144;i++)segtree[i]=1;
	for(int i=0;i<a;i++){
		int now=i;
		int val=0;
		while(1){
			now=p[now];
			t[i]++;
			val+=now+1;
			if(now==i)break;
		}
		add(t[i],i,val);
	}
	for(int i=0;i<a;i++)update(i,t[i]);
	for(int i=0;i<b;i++){
		int l,r;scanf("%d%d",&l,&r);
		l--;r--;
		long long T=query(0,131071,l,r,1);
		long long ret=0;
		for(int j=1;j<42;j++)ret=(ret+(T/j)%mod*sum(j,l,r))%mod;
		printf("%lld\n",ret);
	}
}

Measured memory_bytes: 39004
iN,iY = [int(_) for _ in input().split()]
iY //= 1000

iM10 = iY // 10
iM5 = iY // 5
iM1 = iY
for i in range(iM10+1):
    for j in range(min(iN-i,(iY-i*10)//5)+1):
        k = iN -i -j
        if iY == i*10 + j*5 +k:
            print(i,j,k)
            exit()
print(-1,-1,-1)


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

using namespace std;

int main(){
    int n, l, i, sum(0);
    cin>>n>>l;
    int f[n+1], m = INT_MAX, choosedapple(0);
    for (i = 1; i <= n; i++){
        f[i] = l+i-1;
        sum += f[i];
        if (abs(f[i]) < m){
            m = abs(f[i]);
            choosedapple = f[i];
        }
    }
    cout<<sum-choosedapple;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main() {
	int d[3], ans = 0, temp, temp2;
	bool flag = true, db[3];
	cin >> d[0] >> d[1] >> d[2];
	if (d[0] == d[1] && d[1] == d[2]) {
		flag = false;
	}
	if ((d[0] % 2 != 0 || d[1] % 2 != 0) || d[2] % 2 != 0) {
		goto FINISH;
	}
	for (int i = 0; i < 3 && flag; i++) {
		temp = d[i];
		while (temp % 2 == 0) {
			temp /= 2;
		}
		if (temp == 1) {
			db[i] = true;
		}
		else {
			db[i] = false;
		}
	}
	if (flag && db[0] && db[1] && db[2]) {
		flag = false;
	}
	if (flag) {
		while ((d[0] % 2 == 0 && d[1] % 2 == 0) && d[2] % 2 == 0) {
			temp = d[0] / 2;
			temp2 = d[1] / 2;
			d[0] = temp2 + d[2] / 2;
			d[1] = temp + d[2] / 2;
			d[2] = temp + temp2;
			ans++;
		}
	}
	if (flag) {
	FINISH:
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>

typedef long long int64;

int flag[200016] = {0};

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> as;
  for (int i = 0; i < n - 1; i++) {
    int a;
    std::cin >> a;
    flag[a]++;
  }
  for (int i = 1; i <= n; i++) {
    std::cout << flag[i] << std::endl;
  }
  return 0;
}


Measured memory_bytes: 4304
using System;
using System.Collections.Generic;
using System.Text;
 
namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputFirstLine = Console.In.ReadLine();
            var count = int.Parse(inputFirstLine);
 
            var inputLine = Console.In.ReadLine();
            var inputs = inputLine.Split(new char[] { ' ', '\t', '　' });
            if (inputs.Length != count)
            {
                return;
            }
 
            var integers = new List<int>();
            foreach (var s in inputs)
            {
                integers.Add(int.Parse(s));
            }
 
            integers.Reverse();
            var output = string.Join(" ", integers);
 
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 17988
#include<bits/stdc++.h>
#define int long long
#define M 1000000007
#define deb(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
int d;
int dp[100005][102][2];

int g(string n,int pos=0,int sum=0,int tight=1)
{
    sum=sum%d;
    if (pos==n.length())
        return((sum%d)==0);
    else if (dp[pos][sum][tight]!=-1)
        return dp[pos][sum][tight];
    else if (tight)
    {
        int res=0;
        for(int i=0; i<=n[pos]-'0'; i++)
        {
            if (i==(n[pos]-'0'))
                res=(res+g(n,pos+1,sum+i,1))%M;
            else
                res=(res+g(n,pos+1,sum+i,0))%M;
        }
        dp[pos][tight][sum]=res;
        return res;
    }
    else
    {
        int res=0;
        for(int i=0; i<=9; i++)
            res=(res+g(n,pos+1,sum+i,0))%M;
        dp[pos][sum][tight]=res;
        return res;
    }
}



signed main()
{
    string s;
    cin>>s>>d;
    memset(dp,-1,sizeof(dp));
    int ans=g(s);
    ans=(ans-1+M)%M;
    cout<<ans<<endl;
}

Measured memory_bytes: 258816
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize
    }
    let x = (100 * n - 1) / 108 + 1;
    if 108 * x / 100 == n {
        println!("{}", x);
    } else {
        println!(":(");
    }
}


Measured memory_bytes: 4352
io = STDIN

def substrings(s)
  chars=s.split(//)
  enum=(1..s.size).map do |sz|
    chars.each_cons(sz).to_a.map(&:join)
  end.flatten.uniq
  enum
end

s=io.gets.chomp
k=io.gets.to_i
size=s.size
lc=s.split(//).sort.uniq[0..2]
select=(0...size).map do |i|
  j= i+4<size ? i+4 : size-1
  s[i..j]
end.select do |str|
  lc.include?(str[0])
end
select.sort!

ary=(0...([select.size,5].min)).map do |i|
  substrings(select[i])
end.flatten.uniq.sort
puts ary[k-1]


Measured memory_bytes: 3836
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    println!("{}",if read::<i32>()>2*read::<i32>()-2{"YES"}else{"NO"})
}

Measured memory_bytes: 4352
// ------------------------------------
// Date:2018/ 3/ 7
// Problem:ABC 078 ABS d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

// static const int MOD = 1000000007;
static const int INF = 1e9 + 1;

// memo[2010]
// int memo[2010];


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

  // memset(memo, 0, sizeof(memo));
  int N, Z, W;
  cin >> N >> Z >> W;
  vector< int > a(N);
  REP(i, N) {
    cin >> a[i];
  }

  // int mMin = INF, mMax = -INF;
  int ans = 0;
  if (N == 1) {
    ans = abs(a[0] - W);
  } else {
    ans = max(abs(a[N - 1] - a[N - 2]),
	      abs(a[N - 1] - W));
      /*
      mMin = min(mMin, a[i]);
      mMax = max(mMax, a[i]);
      // 最小値
      memo[i][0] = abs(mMin - a[N - 1]);
      // 最大値
      memo[i][1] = abs(mMax - a[N - 1]);
      */
  }

  /*
  int tmp;
  if (mMin < a[N - 1]) {
    // 最後のカードが最大値
    tmp = 1;
    ans = max(ans, abs(a[N - 1] - W));
  } else {
    // 最後のカードが最大値じゃない
    tmp = 0;
  }

  REP(i, N) {
    ans = max(ans, memo[i]);
  }
  */

  
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h,w;
	cin >> h >> w;
	int srow,scol,erow,ecol;
	cin >> srow >> scol;
	cin >> erow >> ecol;
	--srow,--scol,--erow,--ecol;
	string grid[h];
	for(int i = 0; i < h;++i){
		cin >> grid[i];
	}
//	bool ok = false;
	deque<pair<int,int> > dq;
	int dist[h][w];
	for(int i = 0; i < h;++i){
		for(int j = 0; j < w;++j){
			dist[i][j] = 1e7;
		}
	}
	dist[srow][scol] = 0;
	dq.push_back({srow,scol});
	while(!dq.empty()){
		pair<int,int> cur_node = dq.front();
		dq.pop_front();
		int row = cur_node.first;
		int col = cur_node.second;
//		if(row == erow && col == ecol){
//			ok = true;
//			break;
//		}
		for(int dx = -2;dx <= 2;++dx){
			for(int dy = -2;dy <= 2;++dy){
				int nrow = row + dx;
				int ncol = col + dy;
//				if(nrow == row && ncol == col)
//					continue;
				if(nrow < 0 || ncol < 0 || nrow >= h || ncol >= w ||(!dx && !dy))
					continue;
				int w = 1;
				if(grid[nrow][ncol] == '#')
					continue;
				if((abs(nrow-row) == 1 && abs(ncol-col) == 0) || (abs(ncol-col) == 1 && abs(nrow-row) == 0))
					w = 0;
				if(dist[nrow][ncol] > dist[row][col] + w){
					dist[nrow][ncol] = dist[row][col] + w;
					if(w == 0)
						dq.push_front({nrow,ncol});
					else
						dq.push_back({nrow,ncol});
				}
			}
		}
	}
//	if(!ok)
//		dist[erow][ecol] = -1;
//	cout << dist[erow][ecol] << "\n";
    cout<<(dist[erow][ecol] == 1e7?-1: dist[erow][ecol]);
    return 0;
}


Measured memory_bytes: 8692
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
l=list( set(s) )
maxbox=[]
for i in range( len(l) ):
    maxbox.append( int( s.count(l[i])-t.count(l[i]) ) ) 
maxbox.append(0)
print(max(maxbox))

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

using namespace std;

typedef long long ll;
typedef long double ld;
const ld INF = 1e10;
const ld eps = 1e-9, pi = acos(-1.0);
typedef pair<ll, ll> P;

struct Bit{
  vector<ll> bit;
  Bit(ll size){bit = vector<ll>(size+1);}
  void add(ll k, ll val){
    while (k < bit.size()){
      bit[k] += val;
      k += k & -k;
    }
  }
  ll sum(ll k){
    ll ret = 0;
    while (k){
      ret += bit[k];
      k &= (k - 1);
    }    
    return (ret);
  }
};

int main(){
  string s;
  cin >> s;
  vector<ll> v(s.size(), -1);
  ll ans = 0;
  Bit bit(s.size());
  ll ki = -1;
  for(char c='a'; c<='z'; c++){
    ll l =0;
    ll r =s.size()-1;  
    while(1){
      while(l<s.size() && s[l]!=c)
	l++;
      while(r>=0 && s[r]!=c)
	r--;
      if(l>=s.size() || r<0 || l>r)
	break;
      if(l != r)
	v[l]=r;
      else if(ki != -1 || s.size() % 2 == 0){
	cout << -1 << endl;
	return 0;
      }else{
	ki = l;
	v[l]=r;
      }
      l++;
      r--;
    }
  }
  //for(int i=0;i<v.size();i++)
  //  cout << i << " " << v[i] << endl;
  //cout << endl;
  ll cnt = 0;
  for(ll l=0;l<v.size();l++){
    ll r = v[l];
    if(r < 0)
      continue;
    //cout << s[l] << " " << l << " " << ans << " ";
    if(r == l){
      ans += abs((ll)v.size()/2 - (r - bit.sum(r+1)));
      cnt--;
    }
    else{
      ans += abs((ll)v.size() - cnt - 1 - (r - bit.sum(r+1))); 
      bit.add(r+1, 1);
    }
    cnt++;
    //    cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3716
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    b_s = LI()
    a_s = [0 for i in range(n)]
    for i in range(n-1):
        if i == 0:
            a_s[i] = b_s[i]
            a_s[i+1] = b_s[i]
        else:
            if b_s[i] < b_s[i-1]:
                a_s[i] = b_s[i]
            a_s[i + 1] = b_s[i]
    print(int(sum(a_s)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
n=gets.to_i
s=gets.split.map &:to_i
h1=Hash.new(0);h2=Hash.new(0)
for i in 0...n
 i.even? ? h1[s[i]]+=1:h2[s[i]]+=1
end
ans1=h1.sort_by{|k,v|-v}
ans2=h2.sort_by{|k,v|-v}
ans1 << [0,0]
ans2 << [0,0]
if ans1[0][0]==ans2[0][0]
  puts n-([ans1[0][1]+ans1[1][1],ans2[0][1]+ans2[1][1]].max)
else
  puts n-ans1[0][1]-ans2[0][1]
end


Measured memory_bytes: 26640
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vint a(5);
    int sum = 0;
    REP(i,5){
        cin >> a[i];
    }
    REP(i,5){
        if(a[i]==0){
            cout << i+1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3608
from collections import Counter, deque
from heapq import heappush, heappop, heapify
C = Counter(input())
N = len(C)

if N == 1:
    print(sum(C.values()))
    exit(0)
    
G = [0] * (N * 2)

G[:N] = C
que = [(v, i) for i, v in enumerate(C.values())]
heapify(que)

cur = len(C)
while len(que) > 1:
    v0, nd0 = heappop(que)
    v1, nd1 = heappop(que)
    G[cur]  = (nd0, nd1)
    heappush(que, (v0 + v1, cur))
    cur += 1
root = que[0][1]

ans = 0
que = deque([(0, root)])
while que:
    d, nd = que.popleft()
    if nd < N:
        ans += d * C[G[nd]]
        continue
    u, v = G[nd]
    
    que.append((d + 1, u))
    que.append((d + 1, v))
print(ans)


Measured memory_bytes: 6164
#include<iostream>
#include<math.h>

using namespace std;

int main() {
	int N;
	long long power = 1;

	//入力
	cin >> N;

	long long x = pow(10, 9) + 7;
	for (int i = 0; i < N; i++) {
		power = power * (i + 1)%x;
	}

	cout << power << endl;
}


Measured memory_bytes: 256
def main():
    numbers = []
    bl = True
    while bl:
        inp = input()
        if inp == "0":
            bl = False
        numbers.append(inp)
    for i in range(1,len(numbers)):
        print("Case {}: {}".format(i,numbers[i-1]))
    return None

if __name__ == '__main__':
    main()

Measured memory_bytes: 8096
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

string query1(int start, int n) {
    cout << "?";
    --start;
    if(start < n) {
        for(int i=start;i!=start+n;++i) cout << " " << i+1;
    } else {
        for(int i=start;i!=(start+n)%(2*n);i=(i+1)%(2*n)) cout << " " << i+1;
    }
    cout << endl;
    string ret;
    cin >> ret;
    return ret;
}

string query2(int start, int n, int target) {
    cout << "?";
    --start;
    if(start < n) {
        for(int i=start;i!=start+n-1;++i) cout << " " << i+1;
    } else {
        for(int i=start;i!=(start+n-1)%(2*n);i=(i+1)%(2*n)) cout << " " << i+1;
    }
    cout << " " << target << endl;
    string ret;
    cin >> ret;
    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<string> ans(2*n+1, "");
    int left = 1, right = n+1;
    string left_color = query1(1, n), right_color = query1(n+1, n);
    int query_cnt = 2;
    while(right-left > 1) {
        int mid = (left + right) / 2;
        if(query1(mid, n) == left_color) {
            left = mid;
        } else {
            right = mid;
        }
        ++query_cnt;
    }
    ans[left] = left_color;
    ans[left+n] = right_color;

    for(int i=left+1;i<left+n;++i) {
        ans[i] = query2(((left+n+1 == 2*n+1)?1:(left+n+1)), n, i);
        ++query_cnt;
    }
    for(int i=((left+n+1 == 2*n+1)?1:(left+n+1));i!=left;i=(i+1==2*n+1)?1:(i+1)) {
        ans[i] = query2(left+1, n, i);
        ++query_cnt;
    }

    assert(query_cnt <= 210);

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

// RRBBRB
// RRBBRBRRBB

Measured memory_bytes: 724
H,W=gets.split.map(&:to_i)
ss=$<.read.split

max = 0
H.times do |y|
    W.times do |x|
        next if ss[y][x] == '#'
        v=Array.new(H){Array.new(W,true)}
        d = 0
        q = [[x,y,0]]
        v[y][x] = false
        while !q.empty?
            x1,y1,d = q.shift
            if 0 <= y1-1 && v[y1-1][x1] && ss[y1-1][x1] == '.'
                v[y1-1][x1] = false
                q << [x1,y1-1,d+1]
            end
            if y1+1 < H && v[y1+1][x1] && ss[y1+1][x1] == '.'
                v[y1+1][x1] = false
                q << [x1,y1+1,d+1]
            end
            if 0 <= x1-1 && v[y1][x1-1] && ss[y1][x1-1] == '.'
                v[y1][x1-1] = false
                q << [x1-1,y1,d+1]
            end
            if x1+1 < W && v[y1][x1+1] && ss[y1][x1+1] == '.'
                v[y1][x1+1] = false
                q << [x1+1,y1,d+1]
            end
        end

        max = d if max < d
    end
end

puts max

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

struct{
	int h;
	int t;
}tu[200][200];

int a[6][6][8]={
	0,0,0,0,0,0,0,0,
	1,2,4,5,3,6,3,2,
	1,3,2,4,5,6,4,3,
	1,4,5,3,2,6,2,1,
	1,5,3,2,4,6,1,4,
	0,0,0,0,0,0,0,0,

	2,1,3,6,4,5,3,4,
	0,0,0,0,0,0,0,0,
	2,3,6,4,1,5,2,3,
	2,4,1,3,6,5,4,1,
	0,0,0,0,0,0,0,0,
	2,6,4,1,3,5,1,2,

	3,1,5,6,2,4,3,2,
	3,2,1,5,6,4,4,3,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	3,5,6,2,1,4,2,1,
	3,6,2,1,5,4,1,4,


	4,1,2,6,5,3,3,4,
	4,2,6,5,1,3,2,3,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	4,5,1,2,6,3,4,1,
	4,6,5,1,2,3,1,2,

	5,1,4,6,3,2,3,2,
	0,0,0,0,0,0,0,0,
	5,3,1,4,6,2,4,3,
	5,4,6,3,1,2,2,1,
	0,0,0,0,0,0,0,0,
	5,6,3,1,4,2,1,4,

	0,0,0,0,0,0,0,0,
	6,2,3,5,4,1,3,4,
	6,3,5,4,2,1,2,3,
	6,4,2,3,5,1,4,1,
	6,5,4,2,3,1,1,2,
	0,0,0,0,0,0,0,0,
};



int main()
{
	int n,m,i,j,k,t,f;
	while(scanf("%d", &n) && n){
		memset(tu,0,sizeof(tu));
		while(n--)
		{
			scanf("%d %d",&t,&f);
			i=100;j=100;
			while(1){

				if(a[t-1][f-1][6]==1){
					if( tu[i][j].h > tu[i][j-1].h ){
						int temp = a[t-1][f-1][3];
						f = t; //cout<<"*1*";
						t=temp;
						j = j-1; continue;
					}
				}

				if(a[t-1][f-1][6]==2){
					if( tu[i][j].h > tu[i-1][j].h ){
						int temp = a[t-1][f-1][4];
						f = f;
						t=temp; //cout<<"**"<<i<<" "<<j<<" "<<tu[i][j].h<<" "<<tu[i-1][j].h<<"> ";
						i = i-1; continue;
					}
				}

				if(a[t-1][f-1][6]==3){
					if( tu[i][j].h > tu[i][j+1].h ){
						int temp = a[t-1][f-1][1];
						f =  a[t-1][f-1][5];
						t=temp; //cout<<"*3*";
						j = j+1; continue;
					}
				}

				if(a[t-1][f-1][6]==4){
					if( tu[i][j].h > tu[i+1][j].h ){
						int temp = a[t-1][f-1][2];
						f = f; //cout<<"*4*";
						t=temp; //cout<<"?";
						i = i+1; continue;
					}
				}


				if(a[t-1][f-1][7]==1){
					if( tu[i][j].h > tu[i][j-1].h ){
						int temp = a[t-1][f-1][3];
						f = t;
						t=temp; //cout<<"#1#";
						j = j-1; continue;
					}
				}

				if(a[t-1][f-1][7]==2){
					if( tu[i][j].h > tu[i-1][j].h ){
						int temp = a[t-1][f-1][4];
						f = f;
						t=temp;//cout<<"#2#";
						i = i-1; continue;
					}
				}

				if(a[t-1][f-1][7]==3){
					if( tu[i][j].h > tu[i][j+1].h ){
						int temp = a[t-1][f-1][1];
						f =  a[t-1][f-1][5];
						t=temp;//cout<<"#3#"<<i<<" "<<j<<" "<<tu[i][j].h<<" "<<tu[i][j+1].h<<"> "<<endl;;
						j = j+1; continue;
					}
				}

				if(a[t-1][f-1][7]==4){
					if( tu[i][j].h > tu[i+1][j].h ){
						int temp = a[t-1][f-1][2];
						f = f;
						t=temp;//cout<<"#4#";
						i = i+1; continue;
					}
				}

				tu[i][j].h++;
				tu[i][j].t=t;
				break;
			}
			//int c[8]={0};
			//for( i = 0; i < 200; i++ )
			//	for( j = 0; j < 200; j ++ )
			//	{
			//		c[tu[i][j].t]++;
			//		if(tu[i][j].t) cout<<tu[i][j].h<<" "<<tu[i][j].t<<" "<<i<<" "<<j<<endl;
			//	}
			//	for(i = 1; i < 6; i++)
			//		printf("%d ",c[i]);
			//	printf("%d\n",c[6]);
		}
		int c[8]={0};
		for( i = 0; i < 200; i++ )
			for( j = 0; j < 200; j ++ )
				c[tu[i][j].t]++;
		for(i = 1; i < 6; i++){
			printf("%d ",c[i]);
		}
		printf("%d\n",c[6]);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

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 dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,k;
    cin >> n >> m >> k;
    if((n<k&&m>k)|| n>k&&m<k)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
# include <math.h>

using namespace std;

int main()
{
	int A, B, C, K;

	cin >> A >> B >> C >> K;

	int sum = 0;

	if (K > A)
	{
		sum += A;
		K -= A;
	}
	else
	{
		sum += K;
		goto end;
	}
	if (K > B)
		K -= B;
	else
		goto end;
	if (K > C)
	{
		sum -= C;
	}
	else
	{
		sum -= K;
	}

end:
	cout << sum;

	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    string s; cin >> s;
    char pre = s[0]; int ans = 1;
    int si = SIZE(s);
    rng(i,1,si){
        if(s[i] != pre){
            ans++;
            pre = s[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main()
{
    int n = 0;
    int i;
    char buf[2*1000000];
    char buf2[2*1000000];
 
    fgets(buf, sizeof(buf),stdin);
    fgets(buf2, sizeof(buf2),stdin);
 
 
	i = 0;
	while(buf[i] != '\0'){
		i++;
	}
 
int count = i;
    for (i=0; i<count;i++){
        if(buf[i] != buf2[i]){
            n++;
        }
    }
    printf("%d\n", n);
}

Measured memory_bytes: 2020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll a[N];
    for(int i = 0; i < N; i++) cin >> a[i];
    ll ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            for(int k = j+1; k < N; k++){
                if(a[i] == a[j] || a[j] == a[k] || a[i] == a[k])
                    continue;
                ll sum = a[i] + a[j] + a[k];
                ll mx = max({a[i], a[j], a[k]});
                if(sum - mx > mx){
                    ans++;
                }
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3656
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 80010
#define M 2000100
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define FJ(i,a,b) for(int i=a;i<b;++i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define FD T&q=fd[rt],&ql=fd[rt<<1],&qr=fd[rt<<1|1]
#define MID int mid=((l+r)>>1)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define zero(x) (((x)>0?(x):-(x))<EPS)
#define PB push_back
#define SZ size
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define MP make_pair
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
using namespace std;
const int MOD=1000000007;
const double PI=acos(-1.0);
const double EPS=1e-8;
inline int II(){int n=0,ch=getchar();//if(ch==-1)return 0;
for(;ch<'0'||ch>'9';ch=getchar());//if(ch=='-')t=1;
for(;ch>='0'&&ch<='9';n=n*10+ch-'0',ch=getchar());
return n;}
struct edge{int v,nx;}E[N*40];int head[N],EN;
void init_edge(int cnt){EN=0;fill(head,head+cnt,-1);}
void add_edge(int u,int v){
    E[EN]=(edge){v,head[u]};head[u]=EN++;
}
int n,xy[N>>2],mp[N>>2],id[N>>2];
int sz,lc[N],rc[N];
void build(int l,int r){
	int o=sz++;
	if (l==r){
		lc[o]=rc[o]=0;add_edge(o,mp[id[l]^1]);
		return ;
	}
	int mid=(l+r)/2;
	lc[o]=sz;build(l,mid);
	rc[o]=sz;build(mid+1,r);
	add_edge(o,lc[o]);add_edge(o,rc[o]);
}
void work(int o,int l,int r,int ql,int qr,int p){
	if (ql<=l&&r<=qr){
		add_edge(p,o);return ;
	}
	int mid=(l+r)/2;
	if(ql<=mid)work(lc[o],l,mid,ql,qr,p);
	if(qr>mid)work(rc[o],mid+1,r,ql,qr,p);
}
int dfs_clock,scc_cnt,sccid[N],dfn[N],low[N];
stack<int>S;
void dfs(int u){
    int v;
	dfn[u]=low[u]=++dfs_clock;
	S.push(u);
	for(int k=head[u];~k;k=E[k].nx){
		v=E[k].v;
		if (!dfn[v]){dfs(v);low[u]=min(low[u],low[v]);}
		else if(!sccid[v])low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u]){
		scc_cnt++;
		do{v=S.top();S.pop();
		sccid[v]=scc_cnt;
		}while(v!=u);
	}
}
void tarjan(int n){
	dfs_clock=scc_cnt=0;
	fill(sccid,sccid+n*2,0);
	fill(dfn,dfn+n*2,0);
	for(int i=0;i<n;i++)if(!dfn[i])dfs(i);
}
bool check(int mid){
	init_edge(n<<3);
	sz=n<<1;
	build(0,n*2-1);
	FJ(i,0,n<<1){
		int l=lower_bound(xy,xy+2*n,xy[i]-mid+1)-xy;
		int r=upper_bound(xy,xy+2*n,xy[i]+mid-1)-xy-1;
		if(l<i)work(2*n,0,2*n-1,l,i-1,i);
		if(i<r)work(2*n,0,2*n-1,i+1,r,i);
	}
	tarjan(sz);
	FJ(i,0,n)
	if(sccid[mp[i*2]]==sccid[mp[i*2^1]])return 0;
	return 1;
}
int main(){
   // IN;
    n=II();
    FJ(i,0,n<<1){
        xy[i]=II();
        id[i]=i;
	}
	sort(id,id+2*n,[](int a,int b){return xy[a]<xy[b];});
	sort(xy,xy+2*n);
	FJ(i,0,n<<1)mp[id[i]]=i;
	int l=1,r=1e9;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid))l=mid+1;
        else r=mid-1;
	}
	PR(r);
    return 0;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

string S;
ll ans = 1;
vector<vector<ll>> dp;
void update(int mod, int depth){
  REP(i, 13){
    int idx = (i*10+mod) % 13;
    dp[depth][idx] += dp[depth-1][i];
  }
}

int main(){
  cin >> S;
  dp.resize(S.length()+1, vector<ll>(13, 0));
  dp[0][0] = 1;
  REP(i, S.length()){
    if(S[i] == '?'){
      REP(j, 10){
        update(j, i+1);
      }
    }
    else{
      update(S[i]-'0', i+1);
    }
    REP(j, 13){
      dp[i+1][j] %= (ll)1e9+7;
    }
  }

  cout << dp[S.length()][5] << endl;
  return 0;
}


Measured memory_bytes: 13696
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define ok cout<<"OK"<<endl
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
int val[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&val[i]);
    int ans=0;
    for(int l=0;l<=n;l++)
    {
        for(int r=l+1;r<=n+1;r++)
        {
            if(l+n-r+1>k) continue;
            vector<int> tmp;
            for(int i=1;i<=l;i++) tmp.pb(val[i]);
            for(int i=r;i<=n;i++) tmp.pb(val[i]);
            sort(tmp.begin(),tmp.end());
            int la=k-tmp.size();
            int flag=0;
            for(int i=0;i<tmp.size();i++)
            {
                if(tmp[i]<0&&la>0)
                {
                    la--;
                    flag++;
                }
                else break;
            }
            int cnt=0;
            for(int i=flag;i<tmp.size();i++) cnt=cnt+tmp[i];
            ans=max(ans,cnt);
        }
    }
    printf("%d\n",ans);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

import itertools

def check(s):
    if "AGC" in s:
        return False
    for i in range(len(s)-1):
        a = s[:i] + s[i+1] + s[i] + s[i+2:]
        if "AGC" in a:
            return False
    return True

N = int(readline())
dp = [[0]*61 for i in range(N-2)]
for i in range(61):
    dp[0][i] = 1

rel = {}
cnt = 0
L = list("AGCT")
for v in itertools.product(L,repeat=3):
    s = ''.join(v)
    if check(s):
        rel[s] = cnt
        cnt += 1

for i in range(N-3):
    for k,v in rel.items():
        for s in L:
            if check(k+s):
                dp[i+1][rel[k[1:]+s]] = (dp[i+1][rel[k[1:]+s]] + dp[i][v])%mod
ans = 0
for i in range(61):
    ans = (ans + dp[N-3][i])%mod
print(ans)


Measured memory_bytes: 75048
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	x, y := nextInt(), nextInt()
	ans := 1
	for x <= y {
		x <<= 1
		if x <= y {
			ans++
		}
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

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

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

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

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

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

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <map>
 
using namespace std;
 
map <pair<int, int>, int> mp[200000];
 
bool check(pair<int, int> p, int da, int db) {
    int a = p.first + da;
    int b = p.second + db;
    
    return mp[a + b].count(make_pair(a, b));
}

bool before(pair<int, int> p) {
    return check(p, -1, -1) || check(p, -1, 0);
}

bool after(pair<int, int> p) {
    return check(p, -1, -1) || check(p, 0, -1);
}

int calc(vector <pair<bool, int> >& v) {
    int ans = 0, c = 0, i;
    
    for (i = 0; i < v.size(); i++) {
        ans += v[i].second;
        
        if (v[i].first) {
            c = min(c, v[i].second);
        } else {
            if (v[i].second > c) ans += v[i].second - c;
            c = v[i].second;
        }
    }
    
    return ans;
}
 
int solve() {
    int n, d, ans = 0, i;
    map <pair<int, int>, int>::iterator it, it2;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        int a, b;
        
        scanf("%d %d", &a, &b);
        
        if (i == 0) {
            if (a != 0 || b == 0) return -1;
            
            d = b;
        } else if (i == 1) {
            if (a != d || b != 0) return -1;
        } else {
            if (a == 0 || b == 0 || a + b < d) return -1;
        }
        
        mp[a + b][make_pair(a, b)]++;
    }
    
    for (it = mp[d].begin(); it != mp[d].end(); it++) {
        if (it == mp[d].begin()) continue;
        
        it2 = it;
        it2--;
        
        if (it2->first.first + 1 != it->first.first) return -1;
        
        ans += max(it->second, it2->second);
    }
    
    for (i = d + 1; i < n * 2; i++) {
        vector <pair<bool, int> > v;
        
        if (mp[i].size() == 0) continue;
        
        for (it = mp[i].begin(); it != mp[i].end(); it++) {
            if (it == mp[i].begin()) {
                if (!before(it->first)) return -1;
                
                v.push_back(make_pair(check(it->first, -1, -1), it->second));
            } else {
                it2 = it;
                it2--;
                
                if (it2->first.first + 1 != it->first.first) {
                    if (!after(it2->first) || !before(it->first)) return -1;
                    
                    ans += calc(v);
                    v.clear();
                }
                
                v.push_back(make_pair(check(it->first, -1, -1), it->second));
            }
        }
        
        it--;
        if (!after(it->first)) return -1;
        
        ans += calc(v);
    }
    
    return ans;
}
 
int main() {
    printf("%d\n", solve());
    
    return 0;
}

Measured memory_bytes: 16256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=1e3;
const int MAXM=2000;
const ll INF=-1e18;

struct edge{
    int from,to,cost;
};

int n,m;
vector<edge> es(MAXM);
vector<ll> d(MAXN,INF);

int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int from,to,cost;
        cin>>from>>to>>cost;
      from--;to--;
        es[i]=edge{from,to,cost};
    }
  d[0]=0;
    for(int i=0;i<n-1;i++){
        for(int j=0;j<m;j++){
            edge e=es[j];
            if(d[e.from]!=INF&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    ll ans=d[n-1];
    for(int i=0;i<n-1;i++){
        for(int j=0;j<m;j++){
            edge e=es[j];
            if(d[e.from]!=INF&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    if(ans!=d[n-1]){
        cout<<"inf"<<endl;
    }else cout<<ans<<endl;
    return 0;
}

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

using vi = vector<int>;
using vvi = vector<vi>;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define INF 1<<29 //使いやすい無限


int main(){
  int N;cin>>N;
  vi a(N);
  for(int i=0; i<N; i++){
    cin>>a[i];
  }
  ll ans = INF;
  int cmin = vmin(a);
  int cmax = vmax(a);
  for(int c=cmin; c<=cmax; c++){
    ll buf = 0;
    for(int i=0; i<N; i++){
      buf += (a[i]-c)*(a[i]-c);
    }
    ans = min(ans, buf);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for A - F
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	if a+b == 15 {
		fmt.Println("+")
	} else if a*b == 15 {
		fmt.Println("*")
	} else {
		fmt.Println("x")
	}
}


Measured memory_bytes: 1832