akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define foritr(itr, A) for(set<ll>::iterator itr = A.begin(); itr != A.end(); itr++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define cr(x) cerr << #x << " = " << x << "\n";
#define crA(x, A) cerr << #x << " = " << A[x] << "\n";
#define spacing if(db)cout << " ";
#define space " "
#define mmst(x, v) memset((x), v, sizeof ((x)));
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, d, A[MAXN], l[MAXN], r[MAXN];
struct edge{
	ll x, y, c;
	bool operator < (const edge &e) const
	{
		return c < e.c;
	}
}; vector <edge> E;
void dnc(ll x, ll y)
{
	if(x>=y) return;
	ll mid = (x+y+1)/2; //	cout << x << ' ' << mid << ' ' << y << '\n';
	pi L,R;
	L=R=pi(LLINF,-1);
	FOR(i,x,mid) // x to mid-1
	{
		L = min(L, pi(l[i], i));
	}
	FOR(i,mid,y+1) // mid to y
	{
		R = min(R, pi(r[i], i));
	}
	FOR(i,x,mid) // x to mid-1
	{
		E.pb({i, R.s, r[R.s]+l[i]});
	}
	FOR(i,mid,y+1)
	{
		E.pb({i,L.s,l[L.s]+r[i]});
	}
	dnc(x, mid-1);
	dnc(mid, y);
}
ll ans;
struct _ufds
{
	ll p[MAXN];
	_ufds() { for(ll i = 1; i <= n; i++) p[i] = i; }
	ll find(ll x) { return (p[x] == x) ? x : p[x] = find(p[x]); } 
	void merge(ll x, ll y)
	{
		p[find(x)] = find(y);
	}
	bool same(ll x, ll y) { return find(x) == find(y); }
} ufds;
int main()
{
	cin >> n >> d;
	FOR(i,1,n+1) cin >> A[i];
	FOR(i,1,n+1) l[i] = -i*d + A[i];
	FOR(i,1,n+1) r[i] = i*d + A[i];
	dnc(1, n);
	sort(all(E));
	ufds = _ufds();
	for(auto i : E)
	{
		ll x = i.x, y = i.y, c = i.c; assert(c>=0);// cout << x << ' ' << y << ' ' << c << '\n';
		if(ufds.same(x, y)) continue;
		ufds.merge(x,y);
		ans += c;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 107232
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
int main(void){
    int h,w; cin>>h>>w;
    vector <vector<int>> a(h ,vector <int>(w));
    for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        cin>>a[i][j];
        }
    }
    bool have = false;
    vector <string> ans ;
    for(int i=0;i<h;i++){
        if(have) {a[i-1][w-1]++; have=false;}
        pair <int,int> now = make_pair(-1,-1);
        for(int j=0;j<w;j++){
            if(have){
                if(a[i][j]%2 != 0){
                    a[i][j]++; have = false;
                    string s = to_string(now.F+1)+' '+to_string(now.S+1)+' '+to_string(i+1)+' '+to_string(j+1);
                    ans.push_back(s); continue;
                }else{
                    string s = to_string(now.F+1)+' '+to_string(now.S+1)+' '+to_string(i+1)+' '+to_string(j+1);
                    now = make_pair(i,j);
                    ans.push_back(s); continue;
                }
                
            }
            if(have==false){
                if(a[i][j]%2!=0) {
                    a[i][j]--; have= true;
                    now = make_pair(i,j);
                }
                continue;
            }
        }
    }
    if(have) a[h-1][w-1]++;
    have = false;
    pair <int,int> now = make_pair(-1,-1);
    for(int i=0;i<h;i++){
        if(have){
            if(a[i][w-1]%2==0){
                string s = to_string(now.F+1)+' '+to_string(now.S+1)+' '+to_string(i+1)+' '+to_string(w);
                    now = make_pair(i,w-1);
                    ans.push_back(s); continue;
            }
            else{
                string s = to_string(now.F+1)+' '+to_string(now.S+1)+' '+to_string(i+1)+' '+to_string(w);
                ans.push_back(s);
                have = false;
                continue;
            }
        }
        else {
            if(a[i][w-1]%2==0) continue;
            else {
                now = make_pair(i,w-1);
                have = true;
                continue;
            }
        }
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<
    ans.size();i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 11892
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Buffer(make([]byte, 0), 1e6) // maxTokenSize
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	/* --- code --- */
	n := nextInt()
	a := make([]int64, n)
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt64()
		b[i] = nextInt64()
	}
	sort.Slice(a, func(i, j int) bool {
		return a[i] < a[j]
	})

	sort.Slice(b, func(i, j int) bool {
		return b[i] < b[j]
	})

	lower_bound := med(a)
	upper_bound := med(b)
	fmt.Println(upper_bound - lower_bound + 1)

}

func med(arr []int64) int64 {
	l := len(arr)
	if l%2 == 0 {
		return arr[l/2-1] + arr[l/2]
	}
	return arr[(l-1)/2]
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

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

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

func max64(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

func min64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 8332
import itertools
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 9)
M = 1000000007
N = int(sys.stdin.readline())
left = list(map(int, sys.stdin.read().split()))
counter = Counter(left)


def dp(t, ns):
    cached = t.get(ns)
    if cached is not None:
        return cached
    remaining = sum(ns)
    assert remaining > 0
    last_cnt = left[remaining - 1] + 1
    n1, n2, n3 = ns
    res = 0
    if last_cnt == n1:
        res += dp(t, tuple(sorted([n1 - 1, n2, n3])))
        res %= M
    if last_cnt == n2:
        res += dp(t, tuple(sorted([n1, n2 - 1, n3])))
        res %= M
    if last_cnt == n3:
        res += dp(t, tuple(sorted([n1, n2, n3 - 1])))
        res %= M
    # print(f"{remaining}: ({n1},{n2},{n3}) => {res}")
    t[ns] = res
    return res


def solve():
    h = [0, 0, 0]
    for i in range(N):
        k = counter[i]
        if k == 3:
            h[0] = h[1] = h[2] = i + 1
        elif k == 2:
            h[0] = h[1] = i + 1
        elif k == 1:
            h[0] = i + 1
        else:
            break
    if sum(h) != N:
        return 0
    t = dict()
    t[0, 0, 0] = 1
    res = dp(t, tuple(sorted(h)))
    return (res * len(set(itertools.permutations(h)))) % M


print(solve())


Measured memory_bytes: 117548
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   int N; cin >> N;
   map<string, int> S;
   rep(i, 0, N) {
     string tmp; cin >> tmp;
     S[tmp]++;
   }
   cout << S.size() << endl;
 }


Measured memory_bytes: 19124
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

ll n;
void dfs(ll num,int a,int b,int c);
vector<ll> ans;
int a=0,b=0,c=0;

int main(void) {
	cin>>n;
	dfs(0,a,b,c);
	cout<<ans.size()<<endl;
	
}

void dfs(ll num,int a,int b,int c){
	if(a>0 && b>0 && c>0 && num<=n){
		ans.push_back(num);
	}else if(num>n){
		return ;
	}
	//cout<<a<<b<<c<<endl;
	
	dfs(num*10+3,a+1,b,c);
	dfs(num*10+5,a,b+1,c);
	dfs(num*10+7,a,b,c+1);
	return ;
}





Measured memory_bytes: 640
from collections import deque
from sys import stdin
nii=lambda:map(int,stdin.readline().split())

n=int(input())
l=[list(nii()) for i in range(n-1)]

tree=[[]for _ in range(n)]
for a,b in l:
  a-=1
  b-=1
  tree[a].append(b)
  tree[b].append(b)

ans_num=0
for i in tree:
  ans_num=max(ans_num,len(i))

dq=deque()
dq.append((0,0))

seen=set()
seen.add(0)

ans_dict={}
while dq:
  x,color=dq.pop()

  i=0
  for nx in tree[x]:
    if nx in seen:
      continue

    i+=1
    if i==color:
      i+=1

    seen.add(nx)
    dq.append((nx,i)),
    ans_dict[x+1,nx+1]=i
    ans_dict[nx+1,x+1]=i

print(ans_num)
for i in l:
  print(ans_dict[tuple(i)])

Measured memory_bytes: 83408
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n % 1000 == 0) {
            System.out.println(0);
            return;
        }
        int show = n / 1000;
        show ++;
        System.out.println(show * 1000 - n);
    }
}

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


int main() {
	int n;
    cin >> n;
  	int a[n];
  	int dp[n];
  	for (int i = 0; i < n; i++) {
        cin >> a[i];
        dp[i] = 1000000;
    }
    dp[0] = 0;
    dp[1] = abs(a[0]-a[1]);
  
	for (int i = 2; i < n; i++) {
      
        dp[i] = min(dp[i-1] + abs(a[i-1]-a[i]), dp[i-2] + abs(a[i-2]-a[i]));  
    }
  
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;


ll N;
string S;
int main(){
    cin>>N>>S;
    string ans;
    ans+=S[0];
    for(ll i=1;i<S.length();i++){
        if(S[i]!=S[i-1]){
            ans+=S[i];
        }
    }
    cout<<ans.length()<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long X){
  ll k = 100;
  ll i = 0;
  while(k<X) {
    k += k/100;
    i++;
  }
  std::cout << i << std::endl;
}

int main(){
  long long X;
  scanf("%lld",&X);
  solve(X);
  return 0;
}



Measured memory_bytes: 3256
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main() {
	ll n,k; cin >> n>>k;
	vector<P> a(n);
	rep(i, 0, n) cin >> a[i].first>>a[i].second;
	sort(a.begin(), a.end());
	rep(i, 0, n) {
		k -= a[i].second;
		if (k <= 0) {
			printf("%d", a[i].first);
			return 0;
		}
	}
	return 0;
}


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int cur = 1;
    f(n){
        int add;
        cin >> add;
        if(add == cur){
            cur++;
        }
    }
    if(cur == 1){
        cout << -1 << '\n';
    }
    else{
        cout << n - cur + 1 << '\n';
    }
}


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

int main() {
    int N, M; cin >> N >> M;
    int mid = N / 2;
    if(N%2 == 1){
        int l = 1, r = mid;
        int cnt = 0;
        while(cnt < M && l < r){
            cout << l << " " << r << endl;
            l++; r--;
            cnt++;
        }
        l = mid+1;
        r = N;
        while(cnt < M && l < r){
            cout << l << " " << r << endl;
            l++; r--;
            cnt++;
        }
    } else {
        int l = 1, r = mid;
        int cnt = 0;
        while(cnt < M && l < r){
            cout << l << " " << r << endl;
            l++; r--;
            cnt++;
        }
        l = mid+1;
        r = N-1;
        while(cnt < M && l < r){
            cout << l << " " << r << endl;
            l++; r--;
            cnt++;
        }
    }

    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a,b;
char c;

int main(){
  cin >> a >> c >> b;
  if(c=='+') cout << a+b << endl;
  else cout << a-b << endl;

  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const int logo = 18;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, m;
vector< pair<int, int> > v[maxn];
llint tour[treesiz], prop[treesiz];
llint dp[maxn];

void send(int node) {
	tour[node * 2] += prop[node];
	tour[node * 2 + 1] += prop[node];
	
	prop[node * 2] += prop[node];
	prop[node * 2 + 1] += prop[node];
	prop[node] = 0;
}

void update(int a, int b, int l, int r, int node, llint val) {
	if (l >= a && r <= b) {
		tour[node] += val;
		prop[node] += val;
		return;
	} 
	if (r < a || l > b) return;
	
	int mid = (l + r) / 2;
	send(node);
	update(a, b, l, mid, node * 2, val);
	update(a, b, mid + 1, r, node * 2 + 1, val);
	tour[node] = max(tour[node * 2], tour[node * 2 + 1]);
}

llint query(int a, int b, int l, int r, int node) {
	if (l >= a && r <= b) return tour[node];
	if (r < a || l > b) return -(1LL << 60);
	
	int mid = (l + r) / 2;
	send(node);
	return max(query(a, b, l, mid, node * 2), query(a, b, mid + 1, r, node * 2 + 1));
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		
		v[a].push_back(make_pair(c, a - 1));
		v[b + 1].push_back(make_pair(-c, a - 1));
	}
	
	llint sol = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < v[i].size(); j++) 
			update(0, v[i][j].Y, 0, off - 1, 1, v[i][j].X);
		
		dp[i] = query(0, i - 1, 0, off - 1, 1);
		sol = max(sol, dp[i]);
		update(i, i, 0, off - 1, 1, dp[i]);
	}
	printf("%lld\n", sol);
	return 0;
}


Measured memory_bytes: 23348
using System;
public class Hello
{
    public static void Main()
    {
        int count = 0;
        string[] s=Console.ReadLine().Trim().Split(' ');
        string[] n=Console.ReadLine().Trim().Split(' ');
        for(int i = 0; i < n.Length; i++)
        {
            if (int.Parse(n[i]) >= int.Parse(s[1]))
                count++;
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 15584
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int senbei[10][10000];
int r,c;
int rowFlag[10];
int Max;

void countSum(){
  int sum=0;
  for(int i=0;i<c;i++){
    int colSum = 0;
    for(int j=0;j<r;j++){
      if(senbei[j][i]==!rowFlag[j]){
        colSum++;
      }
    }
    sum += max(colSum,r-colSum);
  }
  if(Max<sum){
    Max = sum;
  }
}

void setFlag(int pos){
  if(pos==r){
    countSum();
    return;
  }
  rowFlag[pos] = 1;
  setFlag(pos+1);

  rowFlag[pos] = 0;
  setFlag(pos+1);
}

int main(){
  while(1){
    cin >> r >> c;
    if(r==0&&c==0) return 0;
    for(int i=0;i<r;i++){
      for(int j=0;j<c;j++){
        cin >> senbei[i][j];
      }
    }
    Max = 0;
    setFlag(0);
    cout << Max << endl;
  }
}

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

int main(){
	int n, r, p, c, temp[200], tempp[200] = {}, tempc[200] = {}, i;
	
	while(1){
		cin>>n>>r;
		
		if(n == 0 && r == 0) break;
		
		for(i = 1; i <= n; i++) temp[i] = n-i+1;
		//for(i = 1; i < n; i++) cout<<temp[i]<<endl;
		for(int j = 0; j < r; j++){
			cin>>p>>c;
			for(i = 1; i < p; i++) tempp[i] = temp[i];
			for(i = 1; i <= c; i++) tempc[i] = temp[i+p-1];
			for(i = 1; i <= c; i++) temp[i] = tempc[i];
			for(i = 1; i < p; i++) temp[i+c] = tempp[i];
		}
	//	for(i = 1; i < n; i++) cout<<temp[i]<<" "<<tempc[i]<<" "<<tempp[i]<<endl;
		cout<<temp[1]<<endl;
		
	}
	
	
	return 0;
}


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

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

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize
    }
    if n < 3 {
        println!("No");
        return;
    }
    let mut m = 1;
    while 2 * m <= n {
        m *= 2;
    }
    if n == m {
        println!("No");
        return;
    }
    println!("Yes");
    for i in 2..(n + 1) / 2 * 2 {
        println!("1 {}", i);
        println!("{} {}", i, (i ^ 1) + n);
    }
    println!("{} {}", n + 3, n + 1);
    if n % 2 == 0 {
        println!("{} {}", m, n);
        println!("{} {}", n ^ 1 ^ m, 2 * n);
    }
}


Measured memory_bytes: 6396
N = int(input())
h = list(map(int, input().split()))


lst = [0]*N
for i in range(N):
    lst[i] = (h[i], i)
lst = list(sorted(lst))


ans = 0

def putLeft(n):
    now = h[n]
    res = 0
    for i in reversed(range(n)):
        if h[i] < now:
            break
        else:
            h[i] -= now
    return res

def putRight(n):
    now = h[n]
    res = 0
    for i in range(n+1, N):
        if h[i] < now:
            break
        else:
            h[i] -= now


for (_, i) in lst:
    if h[i] > 0:
        putLeft(i)
        putRight(i)
        ans += h[i]
        h[i] = 0

print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    ll numofa = 0, ans = 0;
    for(int i = 0; i < n-2; i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            ans += numofa + 1;
            s[i] = 'B';
            s[i+1] = 'C';
            s[i+2] = 'A';
            i++;
        }else if(s[i] == 'A'){
            numofa++;
        }else{
            numofa = 0;
        }
    }
    cout << ans << endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  //b,a
  string s;
  ll k;
  cin >> s >> k;
  REP(i, s.size()){
    if(i+1 == k || s[i] != '1'){
      cout << s[i] << "\n";
      return 0;
    }
  }
  

}

Measured memory_bytes: 256
import itertools
import sys
import numpy as np
import collections

n=int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
ans =0
for i in range(n):
    can = a1[:i+1]+a2[i:]
    ans=max(sum(can),ans)
print(ans)


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


int main()
{
    int A,B;
    cin >> A >> B;
    vector<int> h(A);
    for(int i=0; i<A; i++)
    {
        cin >> h.at(i);
    }
    sort(h.begin(),h.end());
    int min=h.at(A-1);
    for(int i=0; i<A-B+1; i++)
    {
        if(min>h.at(B-1+i)-h.at(i))
        {
            min=h.at(B-1+i)-h.at(i);
        }
    }
    cout << min << endl;
}


Measured memory_bytes: 3752
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>

using ll = long long;
ll M = 1001001001000;

using namespace std;
int main()
{
	ll n;
	cin >> n;
	ll miin = M;
	for (ll i = 1;i*i<=n;i++) {
		if (n % i == 0) {
			ll a = n / i;
			miin = min(miin, a + i - 2);
		}
	}
	cout << miin;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int MAX=5e5+10;
const double eps=1e-4;
const int mod=1e9+7;
#define INF 0x7fffffff
#define ll long long
#define edl putchar('\n')
#define useit  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define mst(a) memset(a,0,sizeof(a))
#define mstn(a,n) memset(a,n,sizeof(a))
//struct point{int v,l;}a[MAX];
//double cross(point a,point b){return (a.x*b.y-a.y*b.x);}
//double dot(point a,point b){return (a.x*b.x+a.y*b.y);}

int main()
{
	int a,b,c;
	{
		cin>>a>>b>>c;
		a-=c;
		cout<<a/(b+c)<<endl;
	}
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double area = r*r*pi;
        double length = 2*r*pi;
        System.out.printf("%f %f",area,length);
    }
}


Measured memory_bytes: 28492
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SYOU(x) fixed<<setprecision(x) //小数点桁数を指定する
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
inline ll mod(ll val, ll m) {long long res = val % m;if (res < 0) res += m;return res;}
inline int divisor_count(int n) {int j, c = 1;for (int i = 2; i * i <= n; i++, c *= j)for (j = 1; !(n % i); j++) n /= i;return (1 < n) ? c * 2 : c;}
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
const ll MOD = 1000000007;
int main(){
    LL(a);
    long double x;
    cin >> x;
    ll ans = a*x + 0.0001 ;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3740
MOD = 10 ** 9 + 7


def main():
    n, k = map(int, raw_input().split())
    a = aa = n + 1 - k
    b = 1
    bb = k
    for i in xrange(1, k + 1):
        print a * b % MOD
        aa -= 1
        a = a * aa / (i + 1)
        bb -= 1
        b = b * bb / i


if __name__ == '__main__':
    main()


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

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0; 
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		sum += a[i];
	}
	int cnt = 0;
	for(int i = 0; i < n; ++i){
		if(a[i] * 4 * m >= sum) cnt++;
	}
	if(cnt >= m) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++) {
        arr[i] = 0;
    }
    while(k>0) {
      k--;
        int d1;
        cin>>d1;
        for(int i=0;i<d1;i++) {
            int a;
            cin>>a;
            a--;
            arr[a]++;
        }
    }

    int count =0;
    for(int i=0;i<n;i++) {
        if(arr[i] == 0) {
            count++;
        }
    }
    cout<<count;

    return 0;
}



Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
  int N, total=0, ans;
  cin >> N;
  vector<int> tako(N);
  for(int i=0;i<N;i++){
    cin >> tako[i];
    total += tako[i];
  }  
  ans = total * total;
  for(int i=0;i<N;i++){
    ans -= tako[i] * tako[i];
  }  
  ans = ans/2;
  cout << ans << endl;
  return 0;
}

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

int main(){
int a,b,x;
  cin>>a>>b;
  x=(a+b)/2;
  if((a+b)%2==0){
    cout<<x<<endl;
  
  }
  else{
    cout<<x+1<<endl;
  }




}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1e9+7
typedef long long ll;

int main()
{
	int k,a,b;
	bool ok = false;
	std::cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			ok = true;
		}
	}

	if(ok == true)
		std::cout<<"OK";
	else
		std::cout<<"NG";
}

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

typedef long long int ll;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("o.txt","w",stdout);
    int a,b;
    cin>>a>>b;
    cout<<(a-1)*(b-1);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,x;
    int count=0;
    std::cin >> a >> b >> c >> x;
    
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            for (int z=0;z<=c;z++) {
                if(x == 500*i + 100*j + 50*z) {
                    count+=1;
                }
            }
        }
    }
    std::cout << count << std::endl;
    return 0;
}


Measured memory_bytes: 256
def read_data():
    N = int(input())
    Es = [[] for i in range(N)]
    for i in range(N - 1):
        a, b = map(int, input().split())
        Es[a - 1].append(b - 1)
        Es[b - 1].append(a - 1)
    return N, Es

def solve(N, Es):
    if N == 2:
        return "Snuke"
    visited = [0] * N
    f1 = [0]
    fN = [N - 1]
    visited[0] = 1
    visited[N - 1] = -1
    while (f1 or fN):
        new_f1 = []
        for v in f1:
            for u in Es[v]:
                if visited[u]: continue
                visited[u] = 1
                new_f1.append(u)
        f1 = new_f1
        new_fN = []
        for v in fN:
            for u in Es[v]:
                if visited[u]: continue
                visited[u] = -1
                new_fN.append(u)
        fN = new_fN
    if sum(visited) > 0:
        return "Fennec"
    else:
        return "Snuke"

N, Es = read_data()
print(solve(N, Es))



Measured memory_bytes: 60064
L = [0] * 4

for i in range(3):
    a, b = map(int, input().split())
    L[a - 1] += 1
    L[b - 1] += 1

odd_count = 0
for l in L:
    if l % 2 == 1:
        odd_count += 1

if odd_count not in (0, 2):
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;


int main(){
    string tmp;
    cin >> tmp;
    
    for(int i = 0; i <= tmp.size(); i++){
        string s;
        if(i == tmp.size()-1){
            s = tmp.substr(0, i);
            //cout << s << endl;
            if(equal(s.begin(), s.end(), "")){
                
            }else if(!s.compare("keyence")){
                cout << "YES" << endl;
                //cout << s << endl;
                return 0;
            }
        }else if(i == tmp.size()){
            s = tmp;
            //cout << s << endl;
            if(equal(s.begin(), s.end(), "")){
                
            }else if(!s.compare("keyence")){
                cout << "YES" << endl;
                //cout << s << endl;
                return 0;
            }
        }else{
            s = tmp.substr(0, i) + tmp.substr(i+1);
            //cout << s << endl;
            if(equal(s.begin(), s.end(), "")){
                
            }else if(!s.compare("keyence")){
                cout << "YES" << endl;
                //cout << s << endl;
                return 0;
            }
        }
    }
    
    for(int i = 0; i < tmp.size()-1; i++){
        for(int j = i+1; j < tmp.size()-1; j++){
            string s;
            s = tmp.substr(0, i) + tmp.substr(j+1);
            //cout << s << endl;
            if(equal(s.begin(), s.end(), "")){
                
            }else if(!s.compare("keyence")){
                cout << "YES" << endl;
                //cout << s << endl;
                return 0;
            }
        }
    }
    
    for(int i = 0; i < tmp.size()-1; i++){
        string s;
        s = tmp.substr(0, i);
        //cout << s << endl;
        if(equal(s.begin(), s.end(), "")){
            
        }else if(!s.compare("keyence")){
            cout << "YES" << endl;
            //cout << s << endl;
            return 0;
        }
    }
    
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,start;
	char str[16];
	
	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d %d",&a,&b);
	
	start = (a+b) % 24;
	
	printf("%d",start);
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=405,inf=0x3f3f3f3f,p=998244353;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow(int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
void check(int &x,int y){x=(x+y<p) ? (x+y) : (x+y-p);}
int n,a[N],b[N],sa,sb,ans,f[N][N],g[N];
int po[N],inv[N],C[N][N],str[N][N];
void mult(int *a,int *b,int n,int m){
	static int c[N];
	memset(c,0,4*(n+m));
	for (int i=0;i<=n;i++)
	for (int j=0;j<m;j++)
	check(c[i+j],(ll)a[i]*b[j]%p);
	memcpy(a,c,4*(n+m));
}
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	n=read();ans=0;
	for (int i=1;i<=n;i++){
		a[i]=read();b[i]=read();
		sa+=a[i];sb+=b[i];
	}
	C[0][0]=str[0][0]=po[0]=inv[0]=1;
	for (int i=1;i<=sb;i++){
		str[i][0]=po[i]=(ll)po[i-1]*i%p;
		inv[i]=qpow(po[i],p-2);
		C[i][0]=1;
		for(int j=1;j<=i;j++)
		C[i][j]=(C[i-1][j]+C[i-1][j-1])%p,str[i][j]=((ll)str[i-1][j]*i+str[i-1][j-1])%p;
	}
	int R=qpow(sa,p-2);
	f[0][0]=1;sa=sb=0;
	for (int i=1;i<=n;sa+=a[i],sb+=b[i],i++){
		int t=1,c=(ll)a[i]*R%p;
		for (int j=0;j<b[i];j++,t=(ll)t*c%p) g[j]=p-(ll)t*inv[j]%p;
		for (int j=sa;j>=0;j--){
			for (int k=0;k<=sb;k++) check(f[j+a[i]][k],f[j][k]);
			mult(f[j],g,sb,b[i]);
		}
	}
	for (int i=0;i<=sa;i++)
	for (int j=0;j<=sb;j++)
	f[i][j]=(p-f[i][j])%p;
	check(f[sa][0],1);
	for (int i=0;i<=sb;i++) check(ans,(ll)f[0][i]*po[i]%p);
	for (int i=1;i<sa;i++){
		int pr=(ll)i*R%p,t=(ll)pr*(g[0]=qpow(p+1-pr,p-2))%p;
		check(ans,(ll)f[i][0]*g[0]%p);
		for (int j=1;j<=sb;j++){
			int tmp=0;
			for (int k=0;k<j;k++)
			check(tmp,(ll)C[j][k]*g[k]%p);
			g[j]=(ll)t*tmp%p;tmp=0;
			for (int k=0;k<=j;k++)
			check(tmp,(ll)str[j][k]*g[k]%p);
			check(ans,(ll)f[i][j]*tmp%p);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;

signed main() {
    int n;
    cin >> n;
    int a = 0, w = 0, t = 0, r = 0;

    rep(i, n){
        string tmp;
        cin >> tmp;
        if(tmp == "AC") a++;
        else if(tmp == "WA") w++;
        else if(tmp == "TLE") t++;
        else r++;
    }

    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"

using namespace std;
const int dx[] = { -1,0,1,0 };
const int dy[] = { 0,-1,0,1 };
const int ddx[] = { 0,1,1,  0,2, 1,-1,-2, 2, 2, -2,-2,1,-1,1,-1,2,2,-2,-2 };
const int ddy[] = { 2,1,-1,-2,0, 1, 1, 0,2, -2,  2,-2,2,2, -2,-2, 1,-1,1,-1 };

struct dat {
	int d, r, c;
};

int main() {
	int H, W;
	cin >> H >> W;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	vector<string> S(H);
	for (int n = 0; n < H; ++n) {
		cin >> S[n];
	}

	vector<vector<int>> D(H, vector<int>(W, 1e9));//回数
	auto c = [](dat a, dat b) {
		return a.d > b.d;
	};
	priority_queue<dat, vector<dat>, decltype(c)> q(c);
	q.push({ 0, ch, cw });
	D[ch][cw] = 0;

	while (!q.empty()) {
		int x = q.top().r;
		int y = q.top().c;
		int z = q.top().d;
		q.pop();
		if (D[x][y] < z) continue;
		//if (x == dh && y == dw) continue;
		//範囲内かつ0を4セット
		for (int l = 0; l < 4; ++l) {
			int x1 = x + dx[l];
			int y1 = y + dy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y]) {
					D[x1][y1] = D[x][y];
					q.push({ D[x1][y1], x1, y1 });
				}
			}
		}
		//範囲内かつ0を20セット
		for (int l = 0; l < 20; ++l) {
			int x1 = x + ddx[l];
			int y1 = y + ddy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y]) {
					D[x1][y1] = D[x][y] + 1;
					q.push({ D[x1][y1], x1, y1 });
				}
			}
		}
	}
	if (1e9 == D[dh][dw]) {
		cout << -1 << endl;
	}
	else {
		cout << D[dh][dw] << endl;
	}
	return 0;
}


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

def make_divisors(n):
    ans =10**12
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            a = i
            b = n//i
            if a+b-2 < ans:
                ans = a+b-2
            
    # divisors.sort()
    return ans

ans = make_divisors(n)

print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#define max(x,y) x>y? x:y
int main(){
int a,b,c,i,umax,dmax;
scanf("%d",&i);
for(;i>0;i--){
 umax=0;
 dmax=0;
 scanf("%d",&a);
 scanf("%d",&b);
 for(int i=1;i<a;i++){
 scanf("%d",&c);
 if(b<c) umax=max(umax,c-b);
 else dmax=max(dmax,b-c);
 b=c;
}
printf("%d %d\n",umax,dmax);
}
}

Measured memory_bytes: 760
#include<stdio.h>

int main(){
	//freopen("in/0005.txt","r",stdin);
	long a,b,r,d,gcd,lcm,t1,t2;
	while(scanf("%ld %ld",&a,&b)!=EOF){
		if(b>a) {
			int t=a;a=b;b=t;
		}
		t1=a;t2=b;
		//printf("%d %d\n",t1,t2 );
		do{
			r=a%b;
			d=a/b;
			a=b;
			b=r;
		}while(b>0);
		gcd=a;
		lcm=t1/gcd*t2;
		printf("%d %d\n",gcd,lcm);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
const int INF=INT_MAX;

int main()
{
	ll n,cap;
	cin>>n>>cap;
	
	ll dp[cap+1];
	for (int i=0;i<=cap;i++)dp[i]=0;
	
	for (int i=0;i<n;i++)
	{
		int weight,val;
		cin>>weight>>val;
		
		for (int j=cap;j>=weight;j--)
		{
			if (j-weight>=0)
				dp[j]=max(dp[j],dp[j-weight]+val);
		}
	}
	
	//for (int i=0;i<=cap;i++)
	cout<<dp[cap];
}




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

typedef long long ll;
typedef pair<ll,ll> ii;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007;
const long double PI=3.1415926535898;
const long double EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

map<ii,ll> m1,m2;

int main(){
	int n;
	scanf("%d",&n);
	ll a,b;
	ll ans=0;
	ll fir=0,sec=0;
	vector<ii> grad;
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&a,&b);
		if(a==0&&b==0){
			ans++;
		}else if(a==0){
			fir++;
		}else if(b==0){
			sec++;
		}else{
			ll d=gcd(abs(a),abs(b));
			if(b<0){a=-a;b=-b;}
			grad.pb(mp(a/d,b/d));
		}
	}
	for(int i=0;i<SZ(grad);i++){
		m1[grad[i]]++;
	}
	//careful 1 or -1
	ll res=expo(2,fir,MOD)+expo(2,sec,MOD)-1;res%=MOD;
	for(auto it=m1.begin();it!=m1.end();++it){
		/*if((it->first)==mp(1LL,1LL)||(it->first)==mp(-1LL,1LL)){
			res*=(it->second+1);
			res%=MOD;res+=MOD;res%=MOD;
		}else{*/
			a=it->fi.se;b=it->fi.fi;
			if(b<0){a=-a;b=-b;}
			a=-a;
			ll cur=expo(2,m1[mp(a,b)],MOD)-1;
			cur%=MOD;
			cur+=expo(2,it->se,MOD);
			cur%=MOD;cur+=MOD;cur%=MOD;
			res*=cur;
			res%=MOD;res+=MOD;res%=MOD;
			m1[mp(a,b)]=0;m1[it->fi]=0;
			
		//	printf("%lld %lld %lld %lld\n",it->first.first,it->first.second,it->second,cur);
		//}
	}
	printf("%lld",(((ans+res-1)%MOD)+MOD)%MOD);
}


Measured memory_bytes: 31344
import Control.Monad
import qualified Data.Set as Set

solve :: Int -> [[Int]] -> Int
solve n a = let size = Set.size $ Set.fromList $ concat a
            in n - size

main :: IO ()
main = do
  [n, k] <- map (read :: String -> Int) . words <$> getLine
  a <- replicateM k $ do
    getLine
    map (read :: String -> Int) . words <$> getLine
  print $ solve n a


Measured memory_bytes: 6504
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ


int main(){
    int64_t n,m;
    cin>>n>>m;
    int sum=0;
    if(2*n>=m){
        cout<<m/2<<endl;
    }
    else{//sが少ない
        //まずsの分作っちゃう
        sum = n;
        m -= 2*n;
        cout<<sum+m/4<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
using lli = long long int;
using pii = pair<lli, lli>;
using rec = pair<pii, pii>;

lli area(rec r){
  lli x  = r.first.first,  y  = r.first.second;
  lli xx = r.second.first, yy = r.second.second;
  return abs((x - xx)*(y - yy));
}

bool isIn(rec r, pii p){
  if(not(r.first.first <= p.first and p.first <= r.second.first))
    return false;
  if(r.first.second < r.second.second){
    return (r.first.second <= p.second and p.second <= r.second.second);
  }
  return (r.second.second <= p.second and p.second <= r.first.second);
}

int main(){
  lli n, K;
  std::cin >> n >> K;
  vector<pii> p(n);
  set<lli> x, y;
  for (int i = 0; i < n; i++) {
    std::cin >> p[i].first >> p[i].second;
    x.insert(p[i].first);
    y.insert(p[i].second);
  }
  vector<pii> grid;
  for (auto a:x) {
    for (auto b:y) {
      grid.push_back(pii(a, b));
    }
  }
  lli ans = 7e18;
  for (int i = 0; i < grid.size(); i++) {
    for (int j = i + 1; j < grid.size(); j++) {
      int cnt = 0;
      rec r = rec(grid[i], grid[j]);
      for (int k = 0; k < n; k++) cnt += isIn(r, p[k]);
      if(cnt >= K)ans = min(ans, area(r));
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 384
S = list(map(int, list(input())))
ans = ""
for bit in range(2**3):
    temp = S[0]

    for i in range(3):

        if bit & (1<<i):
            temp +=S[i+1]
        else:
            temp -= S[i+1]

    if temp == 7:
        for i in range(3):
            ans += str(S[i])

            if bit & (1 << i):
                ans += "+"
            else:
                ans += "-"
        ans += str(S[3]) + "=7"
        print(ans)
        break



Measured memory_bytes: 9108
#%%
alpha2num = lambda c: ord(c) - ord('a') + 1
num2alpha = lambda c: chr(c+64)
S = list(input())

S = S[::-1]
alpha = 'abcdefghijklmnopqrstuvwxyz'
alpha = list(alpha)

a = 0

if len(S) != 26:
    for i in range(len(alpha)):
        if alpha[i] not in S:
            b = alpha[i]
            break
    ans = ''.join(S)[::-1] + b
else:
    for i in range(1,len(S)):
        if S[i] < S[i-1]:
            a = i
            break
    if a == 0:
        ans = -1
    else:
        for i in range(len(alpha)):
            if alpha[i] not in S[a+1:] and alpha[i] > S[a]:
                c = alpha[i]
                break
        ans = (c + ''.join(S[a+1:]))[::-1]

print(ans)

#%%


Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int Inf = (int)1e9;
		
		int[][] WF = new int[N][];
		for(int i=0;i<N;i++){
			WF[i] = new int[N];
			for(int j=0;j<N;j++) WF[i][j] = i == j ? 0 : Inf;
		}
		
		for(int i=0;i<M;i++){
			WF[A[i]][B[i]] = C[i];
			WF[B[i]][A[i]] = C[i];
		}
		
		for(int k=0;k<N;k++){
			for(int i=0;i<N;i++){
				for(int j=0;j<N;j++){
					WF[i][j] = Math.Min(WF[i][j],WF[i][k] + WF[k][j]);
				}
			}
		}
		
		int ans = 0;
		for(int i=0;i<M;i++) if(WF[A[i]][B[i]] < C[i]) ans++;
		Console.WriteLine(ans);
		
	}
	
	int N,M;
	int[] A,B,C;
	
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		A = new int[M];
		B = new int[M];
		C = new int[M];
		for(int i=0;i<M;i++){
			d = ria();
			A[i] = d[0] - 1;
			B[i] = d[1] - 1;
			C[i] = d[2];
			
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 3160
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = N / 2;
		int b = N - a;

		double ans = (double)b / (double)N;

		System.out.println(ans);
	}
}


Measured memory_bytes: 22740