akhauriyash/Code-Regression huggingface dataset:
package main

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

const (
	maxBufferSize = 1048576
)

type Scanner struct {
	lineScanner *bufio.Scanner
	wordScanner *bufio.Scanner
}

var Stdin *Scanner

func NewScanner() *Scanner {
	scanner := &Scanner{
		lineScanner: bufio.NewScanner(os.Stdin),
		wordScanner: bufio.NewScanner(os.Stdin),
	}
	scanner.lineScanner.Split(bufio.ScanLines)
	scanner.wordScanner.Split(bufio.ScanWords)
	return scanner
}

func (sc *Scanner) NextLine() string {
	Stdin.lineScanner.Scan()
	return Stdin.lineScanner.Text()
}

func (sc *Scanner) Next() string {
	Stdin.wordScanner.Scan()
	return Stdin.wordScanner.Text()
}

func (sc *Scanner) NextInt() int {
	Stdin.wordScanner.Scan()
	ret, err := strconv.Atoi(Stdin.wordScanner.Text())
	if err != nil {
		panic(err)
	}
	return ret
}

func (sc *Scanner) NextNInts(N int) []int {
	ints := make([]int, N)
	for i := 0; i < N; i++ {
		ints[i] = sc.NextInt()
	}
	return ints
}

func (sc *Scanner) NextInt64() int64 {
	Stdin.wordScanner.Scan()
	ret, err := strconv.ParseInt(Stdin.wordScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return ret
}

func (sc *Scanner) NextFloat() float64 {
	Stdin.wordScanner.Scan()
	ret, err := strconv.ParseFloat(Stdin.wordScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}

type StringSlice []string

func (ss StringSlice) Contains(s string) bool {
	for _, element := range ss {
		if element == s {
			return true
		}
	}
	return false
}

func (ss StringSlice) CountIf(predicate func(string) bool) int {
	count := 0
	for _, s := range ss {
		if predicate(s) {
			count++
		}
	}
	return count
}

func (ss StringSlice) Filter(predicate func(string) bool) StringSlice {
	ret := make([]string, 0)
	for _, s := range ss {
		if predicate(s) {
			ret = append(ret, s)
		}
	}
	return ret
}

func (ss StringSlice) Map(mapper func(string) string) StringSlice {
	ret := make([]string, 0)
	for _, s := range ss {
		ret = append(ret, mapper(s))
	}
	return ret
}

type IntSlice []int

func (is IntSlice) CountIf(predicate func(int) bool) int {
	count := 0
	for _, i := range is {
		if predicate(i) {
			count++
		}
	}
	return count
}

func Pow(base int, power int) int {
	p := 1
	for i := 0; i < power; i++ {
		p *= base
	}
	return p
}

func init() {
	Stdin = NewScanner()
	Stdin.lineScanner.Buffer(make([]byte, 0), maxBufferSize)
	Stdin.wordScanner.Buffer(make([]byte, 0), maxBufferSize)
}

func main() {
	s := Stdin.NextLine()
	N := len(s)

	if N == 1 {
		fmt.Println(0)
		return
	}

	count := 0
	leftIndex := 0
	rightIndex := N - 1

	for leftIndex < rightIndex {

		left := string(s[leftIndex])
		right := string(s[rightIndex])

		if left != "x" && right == "x" {
			count++
			rightIndex--
		} else if left == "x" && right != "x" {
			count++
			leftIndex++
		} else if left == right {
			leftIndex++
			rightIndex--
		} else {
			count = -1
			break
		}

	}
	fmt.Println(count)
}


Measured memory_bytes: 896
from fractions import gcd

def lcm(a,b):
    return a*(b//gcd(a,b))

mod=10**9+7

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

L=A[0]
for i in range(1,n):
    L=lcm(L,A[i])
L%=mod
ans=0
for i in range(n):
    ans+=L*pow(A[i],mod-2,mod)
print(ans%mod)

Measured memory_bytes: 6112
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int n, m, from, to;
    std::cin >> n >> m;
    std::vector<int> boxes(n + 1, 1), red(n + 1, 0);
    red[1] = 1;

    for (int i = 0; i < m; i++) {
        std::cin >> from >> to;
        if (red[from] == 1) {
            if (boxes[from] == 1) red[from] = 0;
            red[to] = 1;
        }

        boxes[from]--;
        boxes[to]++;
    }

    std::cout << std::count_if(red.begin(), red.end(), [](auto i) { return i > 0; }) << std::endl;

    return 0;    
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int h, n;
    cin >> h >> n;
    vector<pair<int, int>> ab(n);
    int min_mp = 1e8;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
        min_mp = min(min_mp, b);
    }
    vector<int> dp(h+1, 1e8);
//    dp[0] = min_mp;
    dp[0] = 0;
    dp[1] = min_mp;
    rep(i, h+1) {
        rep(j, n) {
//            if ( i - ab[j].first >= 0 ) {
//                cout << i << " " << j << " " << dp[max(0, i-ab[j].first)] + ab[j].second << endl;
            dp[i] = min(dp[i], dp[max(0, i-ab[j].first)] + ab[j].second);
//                dp[i] = min(dp[i], dp[i-ab[j].first] + ab[j].second);
//            }
        }
    }
//    rep(i, h+1) {
//        if ( i != 0 ) cout << " "; 
//        cout << dp[i];
//    }
//    cout << endl;
//    if ( dp[h] == 1e8 ) {
//        cout << 1 << endl;
//    }
//    else {
    cout << dp[h] << endl;
//    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = (ll)1e18 + 1;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  std::vector<ll> take(3, 0LL);
  ll N;
  std::cin >> N >> take[0] >> take[1] >> take[2];

  std::vector< ll > vl(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> vl[i];
  }

  ll ans = INF;
  for (ll S = 0; S < (ll)std::pow(4, N); S++) {
    ll state = S;
    std::vector<ll> vsum[3];
    for (ll i = 0; i < N; i++) {
      ll kind = state % 4;
      state /= 4;

      if (kind == 3) continue;
      vsum[kind].push_back(vl[i]);
    }
    ll mp = 0LL;
    for (ll kind = 0; kind < 3; kind++) {
      if (vsum[kind].size() == 0) mp += 1e9;
      mp += std::fabs(std::accumulate(vsum[kind].begin(), vsum[kind].end(), 0LL) - take[kind]);
      mp += (vsum[kind].size()-1) * 10;
    }
    ans = std::min(ans, mp);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
n,l =map(int, input().split())
P =  [input() for i in range(n)] 

lis=[]
for j in range(n):
    minf=min(P)
    lis.append(minf)
    P.remove(minf)

c=str()
for i in range(n):
    c +=lis[i]

print(c)

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  string s;cin>>s;
  vector<int> w(n+1,0),r(n+1,0);
  rep(i,n){
    w[i+1] = w[i];
    r[n-i-1] = r[n-i];
    if(s[i] == 'W')w[i+1]++;
    if(s[n-i-1] == 'R') r[n-i-1]++;
  }
  int m = INF;
  rep(i,n+1){
    chmin(m,max(w[i],r[i]));
  }
  print(m);
  return 0;
}

Measured memory_bytes: 5156
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
int main(){
  ll n,a,cnt=0;
  map<ll,ll> mp;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    mp[a]++;
  }
  for(auto it=mp.begin();it!=mp.end();it++){
    if(it->first <= it->second){
      cnt += it->second - it->first;
    }else{
      cnt += it->second;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define int long long
#define mod 1000000009
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int pow(int p,int r){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%mod)*(p%mod))%mod;
	 }
	 r=r>>1;
     p=((p%mod)*(p%mod))%mod;
	}
}
signed main() {
	garou;
int n;
cin>>n;
int a[n];
map<int,int> mp;
map<int,int> m1;
for(int i=0;i<n;i++){
cin>>a[i];
mp[a[i]]++;
m1[a[i]]=1;
}
sort(a,a+n);
int ans=0;
for(int i=0;i<n;i++){
int x=a[i];
if(mp[x]>1)
m1[x]=0;
for(int j=x*2;j<=a[n-1];j+=x){
	m1[j]=0;
}
}
for(auto i:m1){
	if(i.second==1)
	ans++;
}
cout<<ans;
}


Measured memory_bytes: 76936
import java.util.Scanner;

class Main{
	public static void main(String[] ags) {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int X=sc.nextInt();

		if(B-A<2*X) {
			for(int i=A; i<=B; i++) {
				System.out.println(i);
			}
		}
		else {
			for(int i=0; i<X; i++) {
				System.out.println(A+i);
			}

			for(int i=X-1; i>=0; i--) {
				System.out.println(B-i);
			}
		}
	}
}

Measured memory_bytes: 21844
class Matrix < Array
  attr_reader :n, :m
  def initialize(arr, row = false, cul = false)
    if (row and cul) or !(Array === arr[0])
      arr.flatten!
      super()
      for i in 0...row ||= arr.length
        self << [*arr[i * cul, cul]]
      end
      @n, @m = row, cul
    elsif Array === arr[0]
      super(arr)
      @n, @m = arr.length, arr[0].length
    else
      raise
    end
  end
  
  def self.e(row = 0)
    result = []
    for i in 0...row
      result << (0...row).map{|num|num == i ? 1: 0}
    end
    return Matrix.new(result)
  end
  
  def *(other)
    if Matrix === other
      return mmul(other)
    elsif Numeric === other
      return self.map{|item|item.map{|i|i * other}}
    end
  end
  
  def dup
    return Matrix.new(self.map(&:dup), @n, @m)
  end
  
  def **(num)
    if num == 0
      return 1
    else
      result = Matrix.e(@n)
      num.to_s(2).each_char{|c|result = result * result * self ** (c.to_i)}
      return result
    end
  end
  
  def to_s
    result = []
    for i in 0...@n
      result << self[i].join(" ")
    end
    return result
  end
  
  def to_ary
    self
  end
  
  private
  def mmul(other)
    result = []
    for i in 0... self.n
      for j in 0... other.m
        temp = 0
        for k in 0... self.m
          temp += self[i][k] * other[k][j]
        end
        result << temp
      end
    end
    return Matrix.new(result, self.n, other.m)
  end
end
class Dice
  def initialize(i, ii, iii, iv, v, vi, ichi = [0, 1, 0], ni = [0, 0, 1], san = [1, 0, 0], posx = 0, posy = 0)
    @att = Matrix.new([ichi, ni, san], 3, 3)
    @num = Array.new([nil, i, ii, iii, iv, v, vi])
    @x, @y = posx, posy
  end
  
  def dup
    return Dice.new(*@num[1..6].dup, *@att.dup, @x, @y)
  end
  
  def set!(top, front)
    while top != gety or front != getz
     while top != gety and front != getz
       rotx!
     end
     while top == gety and front != getz
       roty!
     end
     while top != gety and front == getz
       rotz!
     end
    end
  end
  
  def getx(i = 1)
    return @num[i * (@att.index{|item|item[0] != 0} + 1) * @att.find{|item|item[0] != 0}[0]]
  end
  
  def gety(i = 1)
    return @num[i * (@att.index{|item|item[1] != 0} + 1) * @att.find{|item|item[1] != 0}[1]]
  end
  
  def getz(i = 1)
    return @num[i * (@att.index{|item|item[2] != 0} + 1) * @att.find{|item|item[2] != 0}[2]]
  end
  
  def rotx(i = 1)
    return self.dup.rotx!(i)
  end
  
  def roty(i = 1)
    return self.dup.roty!(i)
  end
  
  def rotz(i = 1)
    return self.dup.rotz!(i)
  end
  
  def rotx!(i = 1)
    @att *= Matrix.new([[1, 0, 0], [0, 0, -i], [0, i, 0]], 3, 3)
    return self
  end
  
  def roty!(i = 1)
    @att *= Matrix.new([[0, 0, i], [0, 1, 0], [-i, 0, 0]], 3, 3)
    return self
  end
  
  def rotz!(i = 1)
    @att *= Matrix.new([[0, -i, 0], [i, 0, 0], [0, 0, 1]], 3, 3)
    return self
  end
end
dice = Dice.new(*gets.split(" ").map(&:to_i))
gets.to_i.times do
  dice.set!(*gets.split(" ").map(&:to_i))
  puts dice.getx
end

Measured memory_bytes: 6116
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	ll ans = lcm(a, b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# coding:utf-8
import math
a, b, h, m = map(int, input().split())

th = abs((30 * h + 0.5 * m) - (m * 6))

theta = min(th, 360 - th)
# print(theta)
ans = (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(theta))) ** 0.5
print(ans)


Measured memory_bytes: 9376
//
// Created by yamunaku on 2019/11/23.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> f(h);
    rep(i, h) cin >> f[i];
    mti ans(h, vi(w, -1));
    int now = 1;
    rep(i, h){
        int count = 0;
        rep(j, w){
            if(f[i][j] == '#'){
                count++;
            }
        }
        if(count > 0){
            rep(j, w){
                ans[i][j] = now;
                if(f[i][j] == '#'){
                    if(count > 1){
                        now++;
                        count--;
                    }
                }
            }
            now++;
        }
    }
    rep(i, h){
        if(ans[i][0] != -1){
            per(x, i){
                if(ans[x][0] != -1) break;
                ans[x] = ans[i];
            }
            repl(x, i + 1, h){
                if(ans[x][0] != -1) break;
                ans[x] = ans[i];
            }
        }
    }
    rep(i, h){
        rep(j, w){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <tuple>
#include <queue>
#include <vector>

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

using namespace std;

int dp[50][50][50][50];

void search(int si, int sj, int sk, int sm, int w, int h,vector<string>& l, vector<string>& r) {
  queue<tuple<int,int,int,int,int>> q;
  q.push(make_tuple(0,si,sj,sk,sm));
  int di[]={1,0,-1,0};
  int dj[]={0,1,0,-1};
  while(!q.empty()){
    int i,j,k,m,d;
    tie(d,i,j,k,m) = q.front();q.pop();
    if(d > dp[i][j][k][m]) continue;
    REP(n,4){
      int ni=i+di[n];
      int nj=j+dj[n];
      int nk=k+di[n];
      int nm=m-dj[n];
      if(ni<0||nj<0||ni>=h||nj>=w){
        ni=i;nj=j;
      }
      if(nk<0||nm<0||nk>=h||nm>=w){
        nk=k;nm=m;
      }
      if(!(l[ni][nj] == '%' && r[nk][nm] == '%')) {
        if(l[ni][nj] == '%' || r[nk][nm] == '%') continue;
        if(l[ni][nj] != '.'){
          ni=i;nj=j;
        }
        if(r[nk][nm] != '.'){
          nk=k;nm=m;
        }
      }
      if(dp[ni][nj][nk][nm] > dp[i][j][k][m] + 1) {
        dp[ni][nj][nk][nm] = dp[i][j][k][m] + 1;
        q.push(make_tuple(dp[ni][nj][nk][nm], ni,nj,nk,nm));
      }
    }
  }
}

int main()
{
  while(1){
    int w,h;
    cin>>w>>h;
    if(!w)break;
    vector<string> l;
    vector<string> r;
    int si,sj,sk,sm;
    int ti,tj,tk,tm;
    REP(i,h){
      string s,t;
      cin>>s>>t;
      l.push_back(s);
      r.push_back(t);
      REP(j,w){
        if(l[i][j] == 'L'){
          si=i;sj=j;
        }
        if(l[i][j] == '%'){
          ti=i;tj=j;
        }
        if(r[i][j] == 'R'){
          sk=i;sm=j;
        }
        if(r[i][j] == '%'){
          tk=i;tm=j;
        }
      }
    }
    REP(i,h)REP(j,w)REP(k,h)REP(m,w)
      dp[i][j][k][m] = 1000000000;
    dp[si][sj][sk][sm] = 0;
    search(si,sj,sk,sm,w,h,l,r);
    if (dp[ti][tj][tk][tm]<1000000000) 
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 26792
n = gets.to_i
a = Array.new(n,0)
n.times { |i| a[i] = gets.to_i }
tmp = a.sort
first = tmp[-1]
second = tmp[-2]
n.times do |i|
  if a[i] == first
    a[i] = second
  else
    a[i] = first
  end
end
puts a

Measured memory_bytes: 9960
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
/*
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
*/
string get_str(string s)
{
	s += ',';
	string ret = "";
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == ',')
			ret += "=%ld, ";
		else
			ret += s[i];
	}
	return ret;
}
#define dump(...)                                       \
	printf(get_str(#__VA_ARGS__).c_str(), __VA_ARGS__); \
	cout << endl
//******************************************************************************

int gcd(int x,int y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
int lcm(int x, int y)
{
	return (x * y / gcd(x, y));
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

signed main()
{
	int N;
	cin>>N;
	vector<int>a(N),L(N+1),R(N+1);
	for(int i = 0;i < N;i++){
		cin>>a[i];
		if(i)L[i]=gcd(L[i-1],a[i]);
		else L[i]=a[i];
	}
	rrep(i,0,N){
		if(i==N-1)R[i]=a[i];
		else R[i]=gcd(R[i+1],a[i]);
	}
	int ans = max(L[N-2],R[1]);
	for(int i = 1;i < N-1;i++){
		chmax(ans,gcd(L[i-1],R[i+1]));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
import numpy as np
H,W,M=map(int, input().split())
hl=np.array([0 for i in range(H+1)])
wl=np.array([0 for i in range(W+1)])
ms=set()
for i in range(M):
    h,w=map(int, input().split())
    hl[h]+=1
    wl[w]+=1
    ms.add((h,w))
a=max(hl)
b=max(wl)
hmax=[]
wmax=[]
for i in range(len(hl)):
    if hl[i]==a:
        hmax.append(i)
for i in range(len(wl)):
    if wl[i]==b:
        wmax.append(i)
a=max(hl)
b=max(wl)
bl=False
if len(hmax)*len(wmax)>M:
    bl=True
else:
    for x in hmax:
        for y in wmax:
            if (x,y) not in ms:
                bl=True
                break
        if bl:
            break
if bl:
    print(a+b)
else:
    print(a+b-1)

Measured memory_bytes: 103704
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>

using namespace std;


int main(){
   int n,k,a,max_a=0;
   cin >> k;
   cin >> n;
   for (int i = 0; i < n; ++i){
       cin >> a;
       if (a>max_a)
           max_a = a;
   }
   if ((max_a-1) > (k-max_a)){
       cout << max(0,(max_a-(k-max_a)-1));
   }
   else
       cout << "0";
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define db(x) cerr<<#x<<" = "<<x<<endl;
using namespace std;
template <typename T>
void Read(T &p) {
	p=0;
	char c;
	for(c=getchar(); !isdigit(c); c=getchar());
	for(; isdigit(c); c=getchar()) {
		p=(p<<3)+(p<<1)+c-'0';
	}
	return;
}
template <typename T1,typename ...T2>
void Read(T1 &p,T2 &...rest) {
	Read(p);
	Read(rest...);
	return;
}
int e[2003],n;
long long tot[4003],mu[4003],qz[4003];
int main(){
	Read(n);
	for(int i=1; i<=n; ++i) {
		Read(e[i]);
		++tot[e[i]];
	}
	for(int i=1;i<=2000;++i) {
		qz[i]=qz[i-1]+tot[i];
	}
	long long ret=0;
	for(int i=1;i<=n;++i) {
		for(int j=i+1;j<=n;++j) {
			ret+=qz[e[i]+e[j]-1];
			///(qz[e[i]+e[j]-1])
			//(qz[abs(e[i]-e[j])])
			ret-=qz[abs(e[i]-e[j])];
			if(e[i]>abs(e[i]-e[j])) {
				--ret;
			}
			if(e[j]>abs(e[i]-e[j])) {
				--ret;
			}
		}
	}
	cout<<ret/3;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    if (b >= a) {
        cout << "unsafe";
    } else {
        cout << "safe";
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <deque>
#include <cctype>

using namespace std;

int main(){
    int n;
    cin >> n;
    for (int _ = 0; _ < n; _++){
        string op, s;
        cin >> op >> s;
        reverse(op.begin(), op.end());
        deque<char> str(s.begin(), s.end());
        for (char c : op){
            if (c == 'C'){
                char t = str.front();
                str.pop_front();
                str.push_back(t);
            }
            else if (c == 'J'){
                char t = str.back();
                str.pop_back();
                str.push_front(t);
            }
            else if (c == 'E'){
                for (int i = 0; i < str.size() / 2; i++){
                    swap(str[i], str[i + (str.size() + 1) / 2]);
                }
            }
            else if (c == 'A'){
                reverse(str.begin(), str.end());
            }
            else if (c == 'M'){
                for (char & d : str){
                    if (isdigit(d)){
                        d++;
                        if (d == '9' + 1){
                            d = '0';
                        }
                    }
                }
            }
            else if (c == 'P'){
                for (char & d : str){
                    if (isdigit(d)){
                        d--;
                        if (d == '0' - 1){
                            d = '9';
                        }
                    }
                }
            }
        }
        for (char c : str){
            cout << c;
        }
        cout << endl;
    }
}

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

#define SENTINEL 1000000000

int count=0;

void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int *L,*R;
  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(j=0;j<=n2-1;j++){
    R[j]=A[mid+j];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
   if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      count++;
    }
    else{
      A[k]=R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(int A[],int left,int right){
  int i,mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}


int main(){
  int A[500000];
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
    int ans = 0;
    int tmp = a;
    if(a < 0) {
        ans += (0 - a)*c;
        a = 0;
    }
    if(a == 0) ans += d;
    ans += (b - a)*e;

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;

ll arr[4];

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int t; cin >> t;
    arr[0] = arr[1] = 1;
    
    while(t--)
    {
        cin >> arr[2] >> arr[3];
        ll m = LLONG_MAX;
        
        for(int i = 0; i < 2; i++)
        {
            for(int j = 2; j < 4; j++)
            {
                ll multiplier = arr[i] / arr[j];
                if(arr[i] % arr[j]) multiplier += 1;
                
                if(arr[0] > arr[2] * multiplier) continue;
                if(arr[1] > arr[3] * multiplier) continue;
                m = min(m, multiplier);
            }
        }
       
        
        
        
        arr[0] = arr[2] * m;
        arr[1] = arr[3] * m;
 //       cout << arr[0] << " " << arr[1] << endl;
    }
    
    cout << arr[0] + arr[1] << endl;
    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
#define mod 1000000007
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;



ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
    if(b&1)
    r=(r*a)%m;
    b=b/2;
    a=(a*a)%m;
    }
    return r%m;
}

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


    int h,w,k;
    cin>>h>>w>>k;
    vector<string>a(h);
    rep(i,0,h)cin>>a[i];
    int tot=0;
    rep(i,0,h)
    {
        rep(j,0,w)if(a[i][j]=='#')tot++;
    }
    int r=0;
    int ans=0;
    while(r<(1<<h))
    {
        int b=0;
        rep(j,0,h)
        {
            if((r&(1<<j))>=1)
            {
                rep(i,0,w)if(a[j][i]=='#')b++;
            }
        }
       // cout<<b<<" "<<r<<endl;
        int c=0;
        while(c<(1<<w))
        {
            int bb=b;
            rep(j,0,w)
            {
            if(c&(1<<j))
            {
                rep(i,0,h)if(a[i][j]=='#'&&(r&(1<<i))<1)bb++;
            }
            }
            if(tot-bb==k)ans++;
            c++;
        }
        r++;

    }
    cout<<ans;
}


Measured memory_bytes: 3624
import java.util.*;
public class Main {
	
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Long Y = sc.nextLong();
		
		for (int a = 0; a <= N; a++) {
			for (int b = 0; b <= N - a; b++) {
				int c = N - a - b;
				long sum = (a * 10000L) + (b * 5000L) + (c * 1000L);
				if (sum == Y) {
					System.out.println(a + " " + b + " " + c);
					return;
				}
			}
		}
		
		System.out.println("-1 -1 -1");
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

template< typename T, typename E >
struct SegmentTree{
    using F = function< T(T, T) >;
    using G = function< T(T, E) >;
    int sz;
    vector<T> dat;
    F f;
    G g;
    T t1;
    SegmentTree(int n, F f, G g, T t1) : f(f), g(g), t1(t1) {
        sz = 1;
        while(sz < n) sz *= 2;
        dat.clear();
        dat.resize(2 * sz - 1, t1);
    }
    void set(int k, T x) { dat[k + sz - 1] = x; }
    void build() {
        for(int k = sz - 2; k >= 0; k--) {
            dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    void update(int k, E x) {
        k += sz - 1;
        dat[k] = g(dat[k], x);
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    T query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return t1;
        if(a <= l && r <= b) return dat[k];
        T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return f(vl, vr);
    }
    T query(int a, int b){ return query(a, b, 0, 0, sz); }
    T operator[](int k) { return dat[k + sz - 1]; }
};

struct S{
    int l, r, c;
    bool operator<(const S &s) const{
        if(l == s.l) return r > s.r;
        return l < s.l; 
    }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<S> d(m);
    rep(i, 0, m){
        cin >> d[i].l >> d[i].r >> d[i].c;
        d[i].l--; d[i].r--;
    }
    sort(d.begin(), d.end());
    SegmentTree<int, int> seg(n,
        [](int a, int b){ return min(a, b); },
        [](int a, int b){ return min(a, b); },
        INF);
    seg.update(0, 0);
    rep(i, 0, m){
        int pre = seg.query(d[i].l, d[i].r + 1);
        seg.update(d[i].r, pre + d[i].c);
    }
    int ans = seg[n - 1];
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

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

const int P=998244353;
int n;
struct pos{
	int x,y;
}ps[1007];
int ep=0,f[1007],sz[1007];
int gf(int x){while(x!=f[x])x=f[x]=x[f][f];return x;}
struct edge{
	int a,b;
	int v;
	bool operator<(const edge&e)const{return v<e.v;}
	void cal(){
		int x=gf(a),y=gf(b);
		if(x!=y)f[x]=y,sz[y]+=sz[x];
	}
}es[207*207];
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
int pw[1007],ans;
int main(){
	scanf("%d",&n);
	pw[0]=1;
	for(int i=1;i<=n;++i)pw[i]=pw[i-1]*2%P;
	ans=(pw[n]-n-1)%P;
	for(int i=0;i<n;++i)scanf("%d%d",&ps[i].x,&ps[i].y);
	for(int i=0;i<n;++i){
		for(int j=0;j<i;++j){
			int x=ps[i].x-ps[j].x,y=ps[i].y-ps[j].y;
			int g=gcd(x,y);
			x/=g,y/=g;
			if(!x)y=1;
			if(!y)x=1;
			if(x<0)x=-x,y=-y;
			es[ep++]=(edge){i,j,x*30000+y};
		}
	}
	std::sort(es,es+ep);
	for(int i=0,j=0;i<ep;i=j){
		for(int a=0;a<n;++a)sz[f[a]=a]=1;
		for(;j<ep&&es[i].v==es[j].v;es[j++].cal());
		for(int a=0;a<n;++a)if(f[a]==a&&sz[a]>1)ans=(ans-pw[sz[a]]+sz[a]+1)%P;
	}
	printf("%d\n",(ans%P+P)%P);
	return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    remain = A - B
    result = max(0, C - remain)
    print(result)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
from collections import Counter
n = int(input())
d, x = map(int, input().split())
a = []
l = []
cnt = 0
for _ in range(n):
        a.append(int(input()))

for _a in a:
        for k in range(100):
                if k*_a + 1 <= d + 1:
                        l.append(k*_a + 1)
c = Counter(l)

for _d in range(1, d+1):
        cnt += c[_d]
print(cnt + x)

Measured memory_bytes: 3316
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else if (s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 768
import math
n = int(input())

min = n + 1

for i in range(1, math.ceil(math.sqrt(n)) + 1):
    if n % i == 0:
        a = i
        b = int(n/i)
        if a + b - 2 < min:
            min = a + b - 2

print(min)

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

int main(){
  int N;
  cin >> N;
  vector<int> M(2*N);
  for(int i=0;i<N;i++)
    cin >> M.at(2*i) >> M.at(2*i+1);
  sort(M.begin(),M.end());
  int C=0;
  for(int i=0;i<N;i++)
    C += M.at(2*i);
  cout << C;
}

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

using namespace std;

int main(){
    int n,k,q;
    cin >> n >> k >> q;

    vector<int>answer;
    for(int i=0;i<q;i++){
        int temp;
        cin >> temp;
        answer.push_back(temp-1);
    }

    vector<int>point(n,0);
    for(int i=0;i<q;i++){
        point[answer[i]] = point[answer[i]]+1;
    }

    for(int i=0;i<n;i++){
        if((k+(point[i]-q)<=0)){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1528
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	// vi a(5);
	int a;
	rep(i,0,5) {
		cin >> a;
		if (a == 0) {
			cout << i+1 << endl;
			return 0;
		}
	}
	
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  if (v > w and abs(b - a) <= (v - w) * t) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}


Measured memory_bytes: 3648
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int N, K, tmph, hmax, hmin, res;
  vector<int> h;
  scanf("%d %d\n",&N, &K);
  for(int i=0;i<N;i++){
    scanf("%d\n",&tmph);
    h.push_back(tmph);
  }
  sort(h.begin(),h.end());

  res=h[K-1]-h[0];

  for(int i=1;i<=N-K;i++){
    hmin=h[i];
    hmax=h[i+K-1];
    if(hmax-hmin<res)
      res=hmax-hmin;
  }
  printf("%d\n",res);
    

  
  return 0;
}

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

long long g(long long n){
    return n * (n + 1) / 2;
}
 
int main(){
    int N;
    long long ans = 0;

    cin >> N;

    for(int i = 1;i <= N;i++){
        ans += i * g(N / i);
    }

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



Measured memory_bytes: 3196
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 2e3+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;



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

    ll n,K;
    cin>>n>>K;
    ll ans = 0;
    for(ll k=K; k<=n+1; k++)
        ans = (ans + (n*(n+1)/2 - (n-k)*(n-k+1)/2 - k*(k-1)/2 + 1)%mod + mod ) % mod;
    cout<<ans<<endl;
}


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

int main(){
  long long N,D,count=0;
  cin >> N >> D;
  for(int i=0;i<N;i++){
    long long X,Y;
    cin >> X >> Y;
    if(X*X+Y*Y<=D*D){
      count++;
    }
  }
  cout << count << endl;
}

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

int main(){
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<pair<int,int> > v(N);
  for(int i=0;i<N;i++){
    int x;cin >>x;
    int y;cin >>y;
    v.at(i)=make_pair(x,y);
  }
  sort(v.begin(), v.end());
  double sum=0;
  int count=0;
  do{
    for (int i=0;i<N-1;i++){
      int a,b,c,d;
      tie(a,b)=v.at(i);
      tie(c,d)=v.at(i+1);
      sum+=sqrt((a-c)*(a-c)+(b-d)*(b-d));
    }
    count++;
  } while(next_permutation(v.begin(),v.end()));
  cout << sum/count <<endl;
}

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

string str[8];

void bfs( int y,int x){
  // cout << "x" << " " << x+1 << " " << "y" << " " << y+1 << endl;
  if( str[y][x] == '0' ) return;
  str[y][x] = '0';

  if ( y+1 <= 7 )bfs( y+1 , x );  
  if ( x+1 <= 7 )bfs( y , x+1 );
  if ( y-1 >= 0 )bfs( y-1 , x );  
  if ( x-1 >= 0 )bfs(  y, x-1 ); 

  if ( y+2 <= 7 )bfs( y+2 , x );  
  if ( x+2 <= 7 )bfs( y , x+2 );  
  if ( y-2 >= 0 )bfs( y-2 , x );  
  if ( x-2 >= 0 )bfs(  y, x-2 ); 

  if ( y+3 <= 7 )bfs( y+3 , x ); 
  if ( x+3 <= 7 )bfs( y , x+3 );  
  if ( y-3 >= 0 )bfs( y-3 , x );
  if ( x-3 >= 0 )bfs(  y, x-3 ); 

  return ;

}


int main(){
  int n; 
  int cnt = 0;
  cin >> n;
  while ( n > 0 ) {
   
    n--;
    for( int i = 0; i < 8; i++ ) cin >> str[i];
    // for( int i = 0; i < 8; i++ ) cout << str[i] << endl;
    
    int sx,sy;
    cin >> sx >> sy;
    sx--;
    sy--;
    bfs(sy,sx);
    cnt++;
    cout << "Data" << " " << cnt << ":" << endl;
    for( int i = 0; i < 8; i++ ) cout << str[i] << endl;
   
  } 
  return 0;
}

Measured memory_bytes: 1208
import bisect

def f(L):
    n = len(L)
    L.sort()

    count = 0

    for i in range(n):
        for j in range(i + 1, n):
            a = L[i]
            b = L[j]
            start = max(a - b, b - a)
            end = a + b
            si = bisect.bisect_right(L, start)
            ei = bisect.bisect_left(L, end)
            zx = ei - si
            if i >= si and i < ei:
                zx -= 1
            if j >= si and j < ei:
                zx -= 1
            count += zx
    return count // 3

assert f([3, 4, 2, 1]) == 1
assert f([1, 1000, 1]) == 0
assert f([218, 786, 704, 233, 645, 728, 389]) == 23

_N = input()
L = list(map(int, input().split()))
ans = f(L)
print(ans)


Measured memory_bytes: 48852
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,n;
int main(){
    cin>>a>>b>>c;
    if(b>=a){cout<<1<<endl;exit(0);}
    if(c>=b){cout<<-1<<endl;return 0;}
    if((a-b)%(b-c)>=1) n=1;
    cout<<((a-b)/(b-c)+n)*2+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rg register
#define MEM(NAME) memset(NAME,0,sizeof NAME)
using namespace std;
typedef long long ll;
template<typename T>
inline bool read(T &n) {
    T ans = 0, flag = 1;
    char ch;
    while ((ch = getchar()) < '0' || ch > '9') if (ch == '-') flag = -1; else if (ch == EOF) return false;
    ans = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') ans = ans * 10 + ch - '0';
    n = ans * flag;
    return true;
}
inline ll read() {
    ll ans = 0, flag = 1;
    char ch;
    while ((ch = getchar()) < '0' || ch > '9') if (ch == '-') flag = -1;
    ans = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') ans = ans * 10 + ch - '0';
    return ans * flag;
};
int pre[100005];
unordered_map<int,int> M;
vector<int> v,v2;
int main() {
    int n,cnt=0;read(n);
    for(rg int i=1;i<=n;i++){
        read(pre[i]);
        if(M.find(pre[i])==M.end()) {
            M[pre[i]]=++cnt;
            v.push_back(1);
            v2.push_back(pre[i]);
        }
        else v[M[pre[i]]-1]++;
    }
    if(n%3==0){
        if((v.size()==2&&max(v[0],v[1])==2*min(v[0],v[1])&&(v2[0]==0||v2[1]==0)||(v.size()==1&&pre[1]==0)||(v.size()==3&&v[0]==v[1]&&v[1]==v[2]&&(v2[0]^v2[1])==v2[2]))) puts("Yes");
        else puts("No");
    }
    else{
        if(v.size()==1&&pre[1]==0) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 4504
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
  int N;
  int h[100010];
  cin >> N;
  for(int i=0; i<N; i++) cin >> h[i];
  int dp[100010];
  dp[0]=0; dp[1]=abs(h[1]-h[0]);
  for(int i=2; i<N; i++){
    dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
  }
  cout << dp[N-1] << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;


   int gogo(int n,int r)
{
    int a[n+1][r+1];

    for( int i=0;i<=n;i++)
    {
        for(int j=0;j<=min(i,r);j++)
        {


            if(j==0||j==i)
                a[i][j]=1;
             else
                    a[i][j]=a[i-1][j]+a[i-1][j-1];

        }
    } return a[n][r];}
    int main()
    {
       int n,m,summ;
       cin>>n>>m;
       if(n<=1&&m>1)
        summ=gogo(m,2);
       else if(m<=1&&n>1)
       summ=gogo(n,2);
       else if(n==1&&m==1)
        summ=0;
       else
       summ=gogo(n,2)+gogo(m,2);
       cout<<summ;
       return 0;}


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

int main() {
  int i;
  int n;
  cin >> n;
  long a[n];
  long double r = 1;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0" << endl;
      return 0;
    }
  }
  
  for (i = 0; i < n; i++) {
    r *= a[i];
    if (r > powl(10, 18)) {
      r = -1;
      break;
    }
  }
  
  long long ll = (long long)r;
  cout << ll << endl;
  return(0);
}


Measured memory_bytes: 4416
N,M,X,Y=map(int, input().split())
Xpoints=list(map(int, input().split()))
Ypoints=list(map(int, input().split()))
isWar='War'
for z in range(-99, 101):
    if X < z and z <= Y:
        if max(Xpoints) < z:
            if min(Ypoints) >= z:
                isWar = 'No War'
                break

print(isWar)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    long MOD = (long) 1e9 + 7;

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        Edges[] g = new Edges[n];

        for (int i = 0; i < n; i++) g[i] = new Edges();

        for (int i = 0; i < m; i++) {
            int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
            g[u].add(v);
        }

        int s = sc.nextInt() - 1, t = sc.nextInt() - 1;
        System.out.println(dijkstra(g, s, t, n));
    }

    int INF = 1 << 28;
    int dijkstra(Edges[] g, int s, int t, int n) {
        int[][] d = new int[n][3];
        for (int i = 0; i < n; i++) Arrays.fill(d[i], INF);
        PriorityQueue<Node> q = new PriorityQueue<>();

        q.add(new Node(s, 2));
        d[s][2] = 2;
        while (!q.isEmpty()) {
            Node cur = q.remove();
//            debug(cur.idx, cur.c);
            if (d[cur.idx][cur.c % 3] != cur.c) continue;
            if (cur.idx == t && cur.c % 3 == 2) return cur.c / 3;

            for (int next: g[cur.idx]) if (d[next][(cur.c + 1) % 3] > cur.c + 1) {
                q.add(new Node(next, cur.c + 1));
                d[next][(cur.c + 1) % 3] = cur.c + 1;
            }

        }
        return -1;
    }

    class Node implements Comparable<Node> {
        int idx, c;

        Node(int idx, int c) {
            this.idx = idx;
            this.c = c;
        }

        @Override
        public int compareTo(Node o) {
            return c - o.c;
        }
    }

    class Edges extends ArrayList<Integer> {}

    class Edge {
        int t, c;
        Edge(int t, int c) {
            this.t = t;
            this.c = c;
        }
    }

    static void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 105852
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll h; cin >> h;
    ll w; cin >> w;
    if (min(h, w) == 1){
        cout << 1 << endl;
        return 0;
    }
    cout << ll((h+1)/2) * ll((w+1)/2) + ll(h/2) * ll(w/2) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    ab = [tuple(map(int, input().split())) for _ in range(N-1)]

    graph = [set() for _ in range(N+1)]
    for a, b in ab:
        graph[a].add(b)
        graph[b].add(a)

    d = deque()
    d.append(1)

    ans = [-1] * (N+1)

    parent = [-1] * (N+1)
    parent[1] = 1

    while d:
        p = d.popleft()
        c = 0
        for g in graph[p]:
            if parent[g] > 0 or g == parent[g]:
                continue
            c += 1
            if c == ans[p]:
                c += 1
            ans[g] = c

            parent[g] = p
            d.append(g)

    print(max(ans))
    for _, b in ab:
        print(ans[b])

if __name__ == '__main__':
    main()


Measured memory_bytes: 43852