akhauriyash/Code-Regression huggingface dataset:
class Node
  def initialize(id)
    @id = id
    @friends = []
    @visited = false
    @group = nil
  end

  attr_accessor :id, :friends, :visited, :group
end

def input_pair(id1, id2, pool)
  me = pool[id1]
  other = pool[id2]
  me = pool[id1] = Node.new(id1) if me == nil
  other = pool[id2] = Node.new(id2) if other == nil

  me.friends << id2
  other.friends << id1
end

def visit(current, target, pool)
  pool[current].visited = true
  if (current == target) then
    return true
  end

  unvisit_friends = 
    pool[current].friends.select {|item| pool[item].visited == false}

  if (unvisit_friends.size == 0) then
    return false
  end

  return unvisit_friends.any? do |item|
    visit(item, target, pool)
  end
end

def grouping!(std_node, pool)
  return if std_node.group != nil

  std_node.group = std_node.id
  group = std_node.group
  stack = [std_node]
  until stack.empty? do
    node = stack.last
    node.group = group
    next_node_id = node.friends.find {|id| pool[id].group == nil}
    if next_node_id == nil then
      stack.pop
    else
      stack.push(pool[next_node_id])
    end
  end
end


# main
n, m = gets.chomp.split.map(&:to_i)
pool = {}
(n).times do |i|
  pool[i] = Node.new(i)
end
(m).times do
  inputs = gets.chomp.split.map(&:to_i)
  input_pair(inputs[0], inputs[1], pool)
end

pool.each_value do |node|
  grouping!(node, pool)
end

(gets.chomp.to_i).times do
  inputs = gets.chomp.split.map(&:to_i)
  puts ((pool[inputs[0]].group == pool[inputs[1]].group) ? "yes" : "no")
end

Measured memory_bytes: 34020
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？



n,k=mii()
p=limii()
q=[0,1,2,3,4,5,6,7,8,9]
arr=[]
for i in q:
    if i not in p:
        arr.append(i)
ans=10**100
for i in range(len(list(str(n))),6):
    for mat in list(product(arr, repeat=i)):
        if int("".join([str(l) for l in mat]))>=n:
            ans=min(ans,int("".join([str(l) for l in mat])))
            
print(ans)



Measured memory_bytes: 73304
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int[] abc = new int[3];
		abc[0] = parseInt(sc.next());
		abc[1] = parseInt(sc.next());
		abc[2] = parseInt(sc.next());
		sc.close();
		Arrays.sort(abc);
		int sum = 2*abc[2]-abc[0]-abc[1];
		int ans=0;
		if(sum%2==0) {
			ans = sum/2;
		} else {
			ans = (sum+3)/2;
		}
		out.println(ans);;
	}
}


Measured memory_bytes: 21716
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		String S = sc.next();
		int count = 0;
		int max = 0;
		for (int i = 0; i < S.length(); i++) {
			if (S.charAt(i) == 'A' || S.charAt(i) == 'G' || S.charAt(i) == 'C' || S.charAt(i) == 'T')
				count++;
			else
				count = 0;
			max = Math.max(max, count);
		}
		System.out.println(max);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main(){
    int a,b;
    cin>>a>>b;
    cout<<(max(max(a+b,a-b),a*b))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}
vector<ll> getNums(ll N) {
    vector<ll> num(N);
    REP(i, N) {
        cin >> num[i];
    }
    return num;
}
int main() {
    ll X, K, D;
    cin >> X >> K >> D;

    X = abs(X);

    if (X / D >= K) {
        cout << (X - (D * K)) << endl;
    } else {
        K -= X / D;
        X -= (X / D) * D;
        if (K % 2 == 0) {
            cout << X << endl;
        } else {
            cout << abs(X - D) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3592
N,C,K=map(int,input().split())
tourist=[]
for i in range (N):
    T=int(input())
    tourist.append(T)
tourist.sort()
bus_count=1
bus_tourlist=1
bus_limit=tourist[0]+K
for j in range (1,len(tourist)):
    if bus_tourlist==C or tourist[j]>bus_limit:
        bus_count+=1
        bus_limit=tourist[j]+K
        bus_tourlist=1
    
    else:
        bus_tourlist+=1
print(bus_count)

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

// .##.##.##.#
void solve(lint n,lint k) {
    /*
    lint ansa = 0;
    for (int a=1; a<=n; a++) {
        for (int b=1; b<=n; b++) {
            if (a%b >= k) ansa ++;
        }
    }
    */
    //cout << ansa << endl;

    lint ans = 0;
    if (k == 0) {
        ans = n*n;
    }
    else {
        for (lint b=1; b <= n; b++) {
            if (b <= k) continue;
            lint t = b-k;
            ans += n/b * t;
            lint c = n%b + 1;
            ans += max(c-k,(lint)0);
            
        }
    }
    cout << ans << endl;
    //if (ans != ansa) {
    //    cout << n << ' ' << k << endl;
    //}

}

int main() {
    lint n,k; cin >> n >> k;
    solve(n,k);
}

Measured memory_bytes: 3592
class UnionFind:
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), self.find(y)
        if x == y:
            return

        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x

    def get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]

    @property
    def groups(self) -> int:
        """Return the number of groups."""
        return len({self.find(x) for x in range(self._first_idx, self._size + self._first_idx)})
n,m=map(int,input().split())
ab=[]
for _ in range(m):
    ab.append(list(map(int,input().split())))
ab = ab[::-1]
tree=UnionFind(n)
ans = (n*(n-1)//2)
res=[ans]
for a,b in ab[:-1]:
    a -=1
    b -=1
    if tree.is_same(a,b):
        pass
    else:
        ans -= tree.get_size(a)*tree.get_size(b)
    res.append(ans)
    tree.unite(a,b)
print(*[max(0,i) for i in res[::-1]], sep="\n")

Measured memory_bytes: 122328
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){
	char ss[102];
	int i,c;
	c=0;
	while(0<=scanf("%s",ss)){
		for(i=0;i<=strlen(ss)-1;i++){
			if(ss[i]!=ss[strlen(ss)-i-1])break;
		}
		
		if(i==strlen(ss))++c;
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var HN = ReadInts();
            var A_SUM = ReadInts().Sum();
            if (HN[0] <= A_SUM)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }

        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 18656
anntena_list = []
 
for i in range(5):
    anntena_list.append(int(input()))
    
m = int(input())
    
flag = False
for i in range(4):
  for j in range(3-i):
    if anntena_list[4-i] - anntena_list[j]  > m:
      flag = True
      
if flag:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3060
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

string replaceOtherStr(std::string &replacedStr, std::string from, std::string to) {
    const ll pos = replacedStr.find(from);
    const ll len = from.length();
 
    if (pos == (ll)std::string::npos || from.empty()) {
        return replacedStr;
    }
 
    return replacedStr.replace(pos, len, to);
}


signed main() {
    ll n;
    cin >> n;
    ll sum = 0;
    ll r = 999;
    vll w(n+1);
    rep(i,n) {
        cin >> w[i];
        sum += w[i];
    }
    
    rep(i, n){
        ll s1 = 0;
        ll s2 = 0;
        for(int j = 0; j <= i; j++){
            s1 += w[j];
        }
        for(int k = i + 1; k < n; k++){
            s2 += w[k];
 
        }
        r = min(r, abs(s1-s2));
    }
    mes(r);
   
    
    
}


Measured memory_bytes: 3640
N,x = list(map(int,input().split()))
a=list(map(int,input().split()))

eat=0

if a[0]>x:
  eat+=a[0]-x
  a[0]=x

if a[N-1]>x:
  eat+=a[N-1]-x
  a[N-1]=x
  
for i in range(N-1):
  if a[i]+a[i+1]>x:
    eat+=a[i+1]-x+a[i]
    a[i+1]=x-a[i]
    
print(eat)

Measured memory_bytes: 14072
n=int(input())

t_,x_,y_=0,0,0
for _ in range(n):
    t,x,y=map(int,input().split())
    if((((x-x_)+(y-y_)+(t-t_))%2==0)and((abs(x-x_)+abs(y-y_))<=t-t_)):
        t_,x_,y_=t,x,y
    else:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 3064
s=gets.chomp
r=gets.chomp

def henshu(s,r)
  return 0 if s.length==0 && r.length==0
  return s.length if r.length==0
  return r.length if s.length==0

  d=Array.new(s.length+1){Array.new(r.length+1,0)}
  (s.length+1).times do |i1|
    d[i1][0]=i1
  end
  (r.length+1).times do |i2|
    d[0][i2]=i2
  end

  (s.length).times do |i1|
    (r.length).times do |i2|
      if s[i1]==r[i2] then
        d[i1+1][i2+1]=d[i1][i2]
      else
        d[i1+1][i2+1]=[d[i1][i2],d[i1+1][i2],d[i1][i2+1]].min+1
      end
    end
  end

  return d[s.length][r.length]

end

puts henshu(s,r)

Measured memory_bytes: 16696
#include<iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a >= b&& a >= c) {
		cout << b + c << endl;
	}
	else if (b >= a&& b >= c) {
		cout << a + c << endl;
	}
	else cout << a + b << endl;
}

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

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    map<ll,int> num;
    num[0]=1;
    ll sum=0;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        sum+=x;
        if(num[sum])
            ans+=num[sum];
        num[sum]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
//>:(
void solve() {
    int N;
    cin >> N;
    vector<ll> v(3*N);
    for(int i=0;i<3*N;i++) cin >> v[i];
    sort(v.begin(),v.end(),greater<ll>());
    ll sum=0;
    for(int i=0,j=1;i<N;i++,j+=2) sum+=v[j];
    cout << sum << "\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

    int N;
    cin >> N;

    long long ans = 0;
    rep(i, N+1) {
        if (i % 3 != 0 and i % 5 != 0) {
            ans += i;
        }
    }

    cout << ans << endl;
}

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

int gcd(int x, int y) {
    if(x % y == 0) return y;
    else return gcd(y, x % y);
}

int main() {
    int N;
    cin >> N;
    cout << 2 * N / gcd(N, 2) << endl;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, m;
  vector<set<int>> graph;
  Solver2(LL n, LL m) : n(n), m(m), graph(n){};

  void solve() {
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      graph[--a].insert(--b);
      graph[b].insert(a);
    }
    vector<int> perm(n);
    iota(perm.begin(), perm.end(), 0);
    int ans = 0;
    do {
      bool ok = true;
      for (int i = 0; i < n - 1; ++i) {
        if (graph[perm[i]].count(perm[i + 1]) == 0) ok = false;
      }
      if (ok) ans++;
    } while (next_permutation(perm.begin(), perm.end()) && perm[0] == 0);
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b;
    cin >> n;
    bool flag_a = 0, flag_b = 0;
    vector<int> data_a(n);
    vector<int> data_b(n);
    vector<int> junretu(n);
    for (int i = 0; i < n; i++){
        cin >> data_a.at(i);
        junretu.at(i) = i+1;
    }
    for (int i = 0; i < n; i++){
        cin >> data_b.at(i);
    }
    int i = 1;
    do {
        if(data_a == junretu){
            a = i;
            flag_a = 1;
        }
        if(data_b == junretu){
            b = i;
            flag_b = 1;
        }
        if(flag_a && flag_b)break;
        i++;
    } while (next_permutation(junretu.begin(), junretu.end()));

    cout << abs(a - b) << endl;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<double, double> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
vector<P> p;

double dist(P a, P b){
	double dx = a.first - b.first;
	double dy = a.second - b.second;
	return sqrt(dx*dx + dy*dy);
}

double f(double x, double y){
	double res = 0;
	for(int i = 0; i < n; i++){
		chmax(res, dist(P(x, y), p[i]));
	}
	return res;
}

double g(double x){
	double l = 0, r = 1000;
	for(int i = 0; i < 100; i++){
		double c1 = (l*2+r)/3;
		double c2 = (l+r*2)/3;
		if(f(x, c1) > f(x, c2)) l = c1;
		else r = c2;
	}
	return f(x, l);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	p = vector<P>(n);
	for(int i = 0; i < n; i++){
		cin >> p[i].first >> p[i].second;
	}
	double l = 0, r = 1000;
	for(int i = 0; i < 100; i++){
		double c1 = (l*2+r)/3;
		double c2 = (l+r*2)/3;
		if(g(c1) > g(c2)) l = c1;
		else r = c2;
	}
	double ans = g(l);
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = getLine >> solve <$> f >>= print
  where
    f = readil B.readInt <$> B.getLine

solve :: [Int] -> Int
solve ps = foldl (\c i -> min c (count i)) 1000000 [0..3]
  where
    count n = let (x:xs) = ps in f n ((max 0 (x - n)):xs)
    f ct [x] = ct + x
    f ct (x:y:ys) = f (ct + 2 * x) ((max 0 (y - x)):ys)

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')



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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template<class A, class B>
inline bool chmax(A &a, const B &b) { return b > a ? a = b, 1 : 0; }

template<class A, class B>
inline bool chmin(A &a, const B &b) { return b < a ? a = b, 1 : 0; }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

//IN
void IN() {}
template<class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

//OUTS
template<size_t> struct int_{};
template<class Tuple, size_t Pos>
ostream& print_tuple(ostream& out, const Tuple& t, int_<Pos>) {
  out << get<tuple_size<Tuple>::value-Pos>(t) << " ";
  return print_tuple(out, t, int_<Pos-1>());
}

template <class Tuple>
ostream& print_tuple(ostream& out, const Tuple& t, int_<1>) {
  return out << get<tuple_size<Tuple>::value-1>(t);
}

template<class... Args>
ostream& operator<<(ostream& out, const tuple<Args...>& t) {
  return print_tuple(out, t, int_<sizeof...(Args)>());
}

#define OUTS(...) cout << make_tuple(__VA_ARGS__) << "\n";

//OUTL
void OUTL() {}
template<class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  VAR(int, n, a, b);

  vector<int> p(n);
  rep(i, n) {
    IN(p[i]);
  }

  int c1 = 0, c2 = 0, c3 = 0;
  rep(i, n) {
    if (p[i] <= a) ++c1;
    else if (p[i] <= b) ++c2;
    else ++c3;
  }

  OUTL(min({c1, c2, c3}));

  return 0;
}


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

int main(){
  int n, x=0, ans=0;
  string s;

  cin >> n >> s;

  for(int i=0; i<n; ++i){
    if(s[i] == 'I'){
      ++x;
    }else {
      --x;
    }
    ans = max(x, ans);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s; cin >> s;
  ll sum = 0;
  for(auto c : s){
    sum += (c - '0');
  }
  cout << (sum%9==0 ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)

int n;
ll mod;
vector<vector<int>> g(100010);
vector<vector<ll>> cm1(100010), cm2(100010);
vector<ll> dp(100010), ans(100010);

ll cdp(int v, int p = -1) {
    ll res = 1;
    for (auto e : g[v])
        if (e != p) {
            res = res * (cdp(e, v) + 1) % mod;
        }
    return dp[v] = res;
}

void dfs(int v, int p = -1) {
    ans[v] = dp[v];
    rep(j, 0, g[v].size()) {
        int qq = j + 1;
        int to = g[v][j];
        if (to != p) {
            ll a = dp[v], b = dp[to];
            dp[v] = 1;

            if (cm1[v].empty()) {
                cm1[v].emplace_back(1);
                for (auto to2 : g[v]) {
                    cm1[v].emplace_back(dp[to2] + 1);
                }
                cm1[v].emplace_back(1);
                // dp[v] = dp[v] * (dp[to2] + 1) % mod;
                cm2[v] = cm1[v];
                int x = cm1[v].size();
                rep(i, 1, x) cm1[v][i] = cm1[v][i] * cm1[v][i - 1] % mod;
                for (int i = x - 1; i > 0; i--)
                    cm2[v][i - 1] = cm2[v][i - 1] * cm2[v][i] % mod;
            }
            dp[v] = (cm1[v][qq - 1] * cm2[v][qq + 1]) % mod;
            dp[to] = dp[to] * (dp[v] + 1) % mod;
            dfs(to, v);
            dp[v] = a;
            dp[to] = b;
        }
    }
}

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

    cin >> n >> mod;
    rep(i, 1, n) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    cdp(0);
    dfs(0);

    rep(i, 0, n) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 32768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int p; cin >> p;
	int num[p][3];
	int i,j,k,flag = 0;
	int player[p];

	rep(i,p) player[i] = 0;	

	rep(i,p)
		rep(j,3)
			cin >> num[i][j];

	rep(i,3){
		rep(j,p){
			rep(k,p){
				if(j != k && num[j][i] == num[k][i]) flag++;
			}
		if(flag==0) player[j] += num[j][i];
		flag = 0;
		}
	}
	
	rep(i,p) cout << player[i] << "\n";		

	return 0;
}

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

int main()
{
    int d, g;
    cin >> d >> g;
    int p[15], c[15];
    for(int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
    }
    int ans = 0;
    for(int i = 0; i < d; i++){
        ans += p[i];
    }
    for(int i = 0; i < d; i++){
        for(int bit = 0; bit < (1 << d); bit++){
            int point = 0;
            int count = 0;
            for(int j = 0; j < d; j++){
                if(j == i) continue;
                if((1 << j) & bit){
                    count += p[j];
                    point += p[j] * (j + 1) * 100 + c[j];
                }
            }
            if(g <= point) ans = min(ans, count);
            else{
                int last = (g - point - 1) / ((i + 1) * 100) + 1;
                if(last <= p[i]) ans = min(ans, count + last);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * TODO: delete this line
 */


import java.util.Scanner;

/**
 * TODO: Rename to Main
 */
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] As = new int[3];
        for (int i = 0; i < 3; i++) {
            As[i] = scanner.nextInt();
        }
        int min = 1000;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int h = 0; h < 3; h++) {
                    if (j!= i && h != i && h != j) {
                        int temp = Math.abs(As[i] - As[j]) + Math.abs(As[j] - As[h]);
                        if (temp < min) {
                            min = temp;
                        }
                    }
                }
            }
        }

        System.out.println(min);
    }
}

Measured memory_bytes: 21844
N, M = map(int, input().split())
Ass = [input() for _ in range(N)]
Bss = [input() for _ in range(M)]

ans = 'No'
for i in range(N-M+1):
    for j in range(N-M+1):
        isDiff = False
        for di in range(M):
            for dj in range(M):
                if Ass[i+di][j+dj] != Bss[di][dj]:
                    isDiff = True
                    break
            if isDiff:
                break
        else:
            ans = 'Yes'

print(ans)

Measured memory_bytes: 3064
def main():
    MOD = 10 ** 9 + 7
    N, K = map(int, input().split())

    ans = 0
    sumN = (N * (N+1)) // 2
    for k in range(K, N+2):
        mink = (k * (k-1)) // 2
        maxk = sumN - ((N-k) * (N-k+1)) // 2
        # print(k, mink, maxk)
        ans = (ans + maxk - mink + 1) % MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9200
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        WriteLine(ReadLine().Count(c => c == '1'));
    }
}


Measured memory_bytes: 11220
#include <iostream>
using namespace std;
int main(void)
{
    int n = 0, tmp = 0, h = 0, count = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        if (tmp >= h)
        {
            h = tmp;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

struct Card {
  char suit;
  int value;
};

void bubbleSort(Card c[], int n) {
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i ; j--) {
      if (c[j].value < c[j-1].value) {
        swap(c[j], c[j-1]);
      }
    }
  }
}

void selectionSort(Card c[], int n) {
  for (int i = 0; i < n; i++) {
    int mini = i;

    for (int j = i; j < n; j++) {
      if (c[j].value < c[mini].value) {
        mini = j;
      }
    }

    if (i != mini) {
      swap(c[i], c[mini]);
    }
  }
}

void printArray(Card c[], int n) {
  for (int i = 0; i < n - 1; i++){
    cout << c[i].suit << c[i].value << ' ';
  }
  cout << c[n - 1].suit << c[n - 1].value << endl;
}

bool isStable(Card a[], Card b[], int n) {
  for (int i = 0; i < n; i ++) {
    if (!(a[i].suit == b[i].suit && a[i].value == b[i].value)) return false;
  }
  return true;
}

int main() {
  Card a[100], b[100];
  int n, count = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].suit >> a[i].value;
    b[i].suit = a[i].suit;
    b[i].value = a[i].value;
  }

  bubbleSort(a, n);
  printArray(a, n);
  cout << "Stable" << endl;

  selectionSort(b, n);
  printArray(b, n);
  if (isStable(a, b, n)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#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 namespace std;

int main() {
  int w, h, n; // 最初の面積
  int result = 0;
  cin >> w >> h >> n;

  // 面積初期化
  bool area[w][h];
  REP(i, w)
  {
    REP(j, h)
    {
      area[i][j] = true;
    }
  }

  REP(i, n)
  {
    int x, y, a; // すぬけくんが打つ点
    cin >> x >> y >> a;
    REP(j, w)
    {
      REP(k, h)
      {
        switch (a)
        {
        case 1:
          if (j < x) area[j][k] = false;
          break;
        case 2:
          if (j >= x) area[j][k] = false;
          break;
        case 3:
          if (k < y) area[j][k] = false;
          break;
        case 4:
          if (k >= y) area[j][k] = false;
          break;
        default:
          break;
        }
      }
    }
  }

  REP(i, w)
  {
    REP(j, h)
    {
      if (area[i][j] == true)
        result++;
    }
  }

  cout << result << "\n";

  return (0);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> L;
    int i;
    int l;
    for(i=0;i<n;i++){
        cin >> l;
        L.push_back(l);
    }
    sort(L.begin(),L.end());
    int counter =0;
    int j,k;
    for(i=0;i<n;i++){
        for(j=i;j<n;j++){
            if(L.at(i)==L.at(j)) continue;
            for(k=j;k<n;k++){
                if(L.at(j)==L.at(k)) continue;
                if(L.at(i)+L.at(j)>L.at(k)) counter++;
            }
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 3628
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int> L(N);

	REP(i, N) cin >> L[i];

	int ret = 0;

	REP(i, N){
		FOR(j, i + 1, N){
			if(L[i] == L[j]) continue;
			FOR(k, j + 1, N){
				if(L[i] == L[k] || L[j] == L[k]) continue;
				int tmp[3] = {L[i], L[j], L[k]};
				sort(tmp, tmp + 3);
				// cerr << tmp[0] << " " << tmp[1] << " "<< tmp[2] << endl;
				if(tmp[0] + tmp[1] > tmp[2]) ret++;
			}
		}
	}

	cout << ret << endl;


	return 0;
}


Measured memory_bytes: 3196
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val PS = mutableListOf<Pair<Int, String>>()
    for (m in 0 until M) {
        val (p, s) = listOfString()
        PS.add(Pair(p.toInt() - 1, s))
    }
    val AC = IntArray(N) { 0 }
    val WA = IntArray(N) { 0 }
    PS.forEach {
        val p = it.first
        val s = it.second
        if (AC[p] == 0) {
            if (s == "AC") AC[p] = 1
            else if (s == "WA") WA[p] += 1
        }
    }
    AC.forEachIndexed { index, ac -> if (ac == 0) WA[index] = 0 }
    println("${AC.sum()} ${WA.sum()}")
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

Measured memory_bytes: 64536
#include <iostream>
using namespace std;
int main() {
    int N, K; string S; cin >> N >> K >> S;
    if (S[K - 1] == 'A') S[K - 1] = 'a';
    else if (S[K - 1] == 'B') S[K - 1] = 'b';
    else S[K - 1] = 'c';
    cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin() , x.end()

typedef  long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;

signed main(){
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n;
    cin >> n;
    n *= 2;
    ll ans = 0 ;
    vector < int > l(n);
    for(auto &i : l) cin >> i;
    sort(all(l));
    for(int z = 1; z < n; z += 2){
        ans += l[z - 1];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    usedz=[]
    cnt=0
    def prime_factorize1(N):
        """
        Nをくって、Nの素因数を格納したリストresを返す。
        リストの要素をすべて掛ければNになる"""
        l = []
        x = N
        y = 2
        while y*y <= x:
            while x % y == 0:
                l.append(y)
                x //= y
            y += 1
        if x > 1:
            l.append(x)
        prev=1
        newl=[]
        for x in range(len(l)):
            if l[x]!=prev:
              newl.append(l[x])
              prev=l[x]
            else:
                newl.append(newl[x-1]*l[x])
        newl.sort()
        for x in newl:
            if x not in usedz:
                usedz.append(x)
                return x
        return -1

    while True:
        z = prime_factorize1(n)
        if z==-1:
            break
        else:
            n=n//z
            cnt+=1
    print(cnt)

resolve()

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> points(n, vector<int>(3));
    for(int i = 0; i < n; ++i){
        cin >> points[i][0] >> points[i][1] >> points[i][2];
    }
    // vector<vector<int>> dp(n, vector<int>(3));
    // dp[0][0] = points[0][0];
    // dp[0][1] = points[0][1];
    // dp[0][2] = points[0][2]; 
    // for(int i = 1; i < n; ++i){
    //     dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + points[i][0];
    //     dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + points[i][1];
    //     dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + points[i][2];
    // }
    // cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
    int dp_a, dp_b, dp_c;
    dp_a = points[0][0];
    dp_b = points[0][1];
    dp_c = points[0][2];
    for(int i = 1; i < n; ++i){
        int curr_a, curr_b, curr_c;
        curr_a = max(dp_b, dp_c) + points[i][0];
        curr_b = max(dp_a, dp_c) + points[i][1];
        curr_c = max(dp_a, dp_b) + points[i][2];
        dp_a = curr_a;
        dp_b = curr_b;
        dp_c = curr_c;
    }
    cout << max(dp_a, max(dp_b, dp_c)) << endl;
    return 0;
}

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

#include <iostream>


#define MOD 1000000007

typedef unsigned long long ull;
typedef long long ll;

using namespace std;
auto f=[]()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
};


const int maxn=100005;
struct DS
{

	void MakeSet(int v)
	{
		p[v]=v;
		s[v]=1;
	}
	
	int Find(int v)
	{
		if(p[v]==v)return v;
		return p[v]=Find(p[v]);
	}
	
	void Union(int v1, int v2)
	{
		int x=Find(v1);
		int y=Find(v2);
		
		if(x==y)return;
	
		if(s[x]<s[y])swap(x,y);
		
		p[y]=x;
		s[x]+=s[y];
	}

	int Size(int v)
	{
		return s[Find(v)];
	}

private:
	int p[maxn];
	int s[maxn];
};

vector<int> block[maxn];
int cnt[maxn];
int main()
{
	f();
	int n,m,k;cin>>n>>m>>k;
	DS d;
	for(auto i=0;i<n;++i)
	{
		d.MakeSet(i+1);	
	}
	
	for(auto i=0;i<m;++i)
	{
		int a,b;cin>>a>>b;
		d.Union(a,b);
		cnt[a]++;
		cnt[b]++;
	}

	for(auto i=0;i<k;++i)
	{
		int a,b;cin>>a>>b;
		block[a].push_back(b);
		block[b].push_back(a);	
	}
	
	/*for(auto i=0;i<maxn;++i)
	{
		sort(block[i].begin(),block[i].end());
	}*/	
	
	int ans[n+1]={};
	
	for(auto i=0;i<n;++i)
	{
		ans[i+1]=d.Size(i+1)-1-cnt[i+1];
		for(auto j:block[i+1])
		{
			if(d.Find(j)==d.Find(i+1))--ans[i+1];	
		}
	}


	for(auto i=0;i<n;++i)
		cout<<ans[i+1]<<" ";

	cout<<"\n";

	return 0;
}


Measured memory_bytes: 7552
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++){
        if (s.at(i)=='x') c++;
    }
    cout<<((c>7) ? "NO":"YES")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define per(i,x,y) for(int i=(x);i>=(y);--i)
typedef long long LL;
const int N=4e5+10;
LL n,l,t,x[N],w[N],a[N],b[N],ca,cb,ans[N];
int main(){
	scanf("%lld%lld%lld",&n,&l,&t);
	rep(i,1,n)scanf("%lld%lld",&x[i],&w[i]);
	LL tmp=t/l;
	t%=l;
	rep(i,1,n)if(w[i]==1)a[++ca]=x[i];else b[++cb]=x[i];
	rep(i,1,ca)a[ca+i]=a[i]+l,a[ca*2+i]=a[i]+2*l;
	rep(i,1,cb)b[cb+i]=b[i]+l,b[cb*2+i]=b[i]+2*l;
	rep(i,1,n){
		if(w[i]==1){
			ans[(i+(LL)2*tmp*cb%n+std::upper_bound(b+1,b+1+cb*3,x[i]+2*t)-std::lower_bound(b+1,b+1+cb*3,x[i])-1)%n+1]=(x[i]+t)%l;
		}else{
			ans[(i+n-(LL)2*tmp*ca%n+n+std::lower_bound(a+1,a+1+ca*3,x[i]+2*l-2*t)-std::upper_bound(a+1,a+1+ca*3,x[i]+2*l)-1)%n+1]=(x[i]-t+l)%l;
		}
	}
	rep(i,1,n)printf("%lld\n",ans[i]);
	return 0;
}


Measured memory_bytes: 12160
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
  int m[4] = {};
  rep(i, 3) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    m[a]++;
    m[b]++;
  }

  vector<int> ans;
  rep(i, 4) { ans.push_back(m[i]); }
  vector<int> clear = {1, 1, 2, 2};
  sort(all(ans));
  if (ans == clear)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int N=1e5+5,M=2*N;
int n,i,et,he[N],v[N];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
void write(int x){if (x>9) write(x/10);putchar(x%10+48);}
struct edge{int l,to;}e[M];
struct heap{int x,k;};
bool operator < (heap A,heap B){return A.k>B.k;}
priority_queue<heap> q;
int main(){
	for (n=read(),i=1;i<n;i++){
		int x=read(),y=read();
		e[++et].l=he[x];he[x]=et;e[et].to=y;
		e[++et].l=he[y];he[y]=et;e[et].to=x;
	}
	for (i=1;i<=n;i++) v[i]=-1;
	for (i=read();i--;){
		int x=read();v[x]=read();
		q.push((heap){x,v[x]});
	}
	for (int turn=n;turn--;){
		int x=q.top().x,k=q.top().k;q.pop();
		for (i=he[x];i;i=e[i].l){
			int y=e[i].to;
			if (v[y]==-1) v[y]=k+1,q.push((heap){y,v[y]});
			else if (abs(k-v[y])!=1){puts("No");return 0;}
		}
	}
	for (puts("Yes"),i=1;i<=n;i++) write(v[i]),putchar('\n');
}

Measured memory_bytes: 4212
H,W,N = map(int, input().split())
sr,sc = map(int, input().split())
S = input()
T = input()

left, right = 0, W+1
if S[-1] == "R":
    right -= 1
elif S[-1] == "L":
    left += 1
for i in reversed(range(N-1)):
    si, ti = S[i], T[i]
    if ti == "R":
        left -= 1
    elif ti == "L":
        right += 1
    left = max(0, left)
    right = min(W+1, right)

    if si == "R":
        right -= 1
    elif si == "L":
        left += 1

    if right - left == 1:
        print("NO")
        exit()

if sc <= left or right <= sc:
    print("NO")
    exit()


left, right = 0, H+1
if S[-1] == "U":
    left += 1
elif S[-1] == "D":
    right -= 1

for i in reversed(range(N-1)):
    si, ti = S[i], T[i]
    if ti == "D":
        left -= 1
    elif ti == "U":
        right += 1
    left = max(0, left)
    right = min(H+1, right)

    if si == "D":
        right -= 1
    elif si == "U":
        left += 1

    if right - left == 1:
        print("NO")
        exit()

if sr <= left or right <= sr:
    print("NO")
    exit()

print("YES")


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

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public double[] range = new double[]{
			165.0, 170.0, 175.0, 180.0, 185.0
	};

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int[] score = new int[]{0, 0, 0, 0, 0, 0};
		String line = in.readLine();
		int size = Integer.parseInt(line);

		for(int i=0; i<size; i++){
			line = in.readLine();
			double tall = Double.parseDouble(line);
			for(int n=0; n<5; n++){
				if(tall < range[n]){
					score[n]++;
					break;
				}
			}

			if(tall >= range[4]){
				score[5]++;
			}
		}

		for(int i=0; i<6; i++){
			System.out.printf("%d:", i+1);
			for(int n=0; n<score[i]; n++){
				System.out.print("*");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll n, a, b;
  cin >> n >> a >> b;
  
  if((b-a) %2 == 0)
    cout << (b-a)/2 << "\n";
  else
    cout << (b-a)/2 + min(n-b, a-1) +1 << "\n";

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static class Point {
        int x, y, magic;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
            this.magic = 0;
        }

        private void setMagic(int magic) {
            this.magic = magic;
        }
    }

    public void main(Scanner sc) {
        int h = sc.nextInt();
        int w = sc.nextInt();
        int d = sc.nextInt();
        Point a[] = new Point[h * w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[sc.nextInt() - 1] = new Point(j, i);
            }
        }

        for (int i = 1; i <= d; i++) {
            Point p1 = a[i - 1];
            for (int j = 1; i + j * d <= h * w; j++) {
                Point p2 = a[i + j * d - 1];
                p2.setMagic(p1.magic + Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y));
                p1 = p2;
            }
        }

        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println(a[r - 1].magic - a[l - 1].magic);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 106804
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1e9
typedef pair<int,int> mypair;
void dai(vector<vector<mypair> > g,vector<mypair> &d,int s,int n){
	rep(i,n) d.push_back(mypair(inf,i));
	d[s] = mypair(0,s);
	priority_queue<mypair,vector<mypair>,greater<mypair> > q;
	q.push(mypair(0,s));
	while(!q.empty()){
	mypair now =q.top();
	//cout<<now.first<<' '<<now.second<<endl;
	q.pop();
		rep(i,g[now.second].size()){
			int next = g[now.second][i].second;
			int nextcost = g[now.second][i].first;
			if(d[next].first>nextcost+now.first){
				d[next].first  = nextcost+now.first;
				q.push(d[next]);
			}
		}
	}
	return;
}

int main(){
	int n;
	cin>>n;
vector<vector<mypair> > g(n);
for(int i=0;i<n-1;i++){
int s,t,w;
cin>>s>>t>>w;
g[s].push_back(mypair(w,t));
g[t].push_back(mypair(w,s));
}
//cout<<"ok"<<endl;
vector<mypair> d,d2;
dai(g,d,0,n);
sort(d.begin(),d.end());
int ma = d[n-1].second;
//cout<<ma<<' '<<d[ma].first<<"ma"<<endl;
dai(g,d2,ma,n);
sort(d2.begin(),d2.end());
cout<<d2[n-1].first<<endl;



}



Measured memory_bytes: 16996