akhauriyash/Code-Regression huggingface dataset:
import static java.util.Comparator.comparing;

import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==========================================================
    public void solve() {
    	int N = ni();
    	int W = ni();
    	int[][] wv = new int[N][2];
    	for (int i = 0; i < N; i++) {
			wv[i] = ndi(2);
		}
    	long[][] dp = new long[2][W + 10];
    	int from = 0, to = 1;
    	for (int i = 0; i < N; i++) {
    		from = (i & 1);
    		to = (from + 1) & 1;
    		for (int j = 0; j <= W; j++) {
    			if(j + wv[i][0] <= W)
    				dp[to][j + wv[i][0]] = Math.max(dp[to][j + wv[i][0]], 
    												dp[from][j] + wv[i][1]); 
    			dp[to][j] = Math.max(dp[to][j], dp[from][j]); 
			}
		}
    	long ans = 0;
		for (int j = 0; j <= W; j++) {
			ans = Math.max(ans, dp[to][j]);
		}
    	out.println(ans);
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


Measured memory_bytes: 24272
/*
                                                  __          __
      /\   |   |     /\   |  | |  |     /\   | / |  )   /\   |  )
     /__\  |   |    /__\  |--| |  |    /__\  |<  |-<   /__\  |-<
    /    \ |__ |__ /    \ |  | \__/   /    \ | \ |__) /    \ |  \

*/

#import<bits/stdc++.h>
typedef long long ll;
#define num 1e9
#define root 10000
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define forll(i,a,b,c) for(int i=a; i<=b; i+=c)
#define forll2(i,a,b,c) for(int i=a; i>=b; i-=c)
#define pb(n) push_back(n)
#define i(n) insert(n)

using namespace std;

int main()
{
    io;
    string a,b;
    cin>>a>>b;
    int m=b.size();
    forll(i,0,a.size()-b.size(),1)
    {
        int x=0,k;
        forll(j,0,b.size()-1,1)
        {
            if(a[i+j]!=b[j]){x++;}
        }
        m=min(m,x);
    }
    cout<<m<<"\n";
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
int INF = 1e9+7;

int main() {
    int N;
    cin >> N;
    vi d(N);
    for (int i=0; i<N; i++) {
        cin >> d[i];
    }

    sort(d.begin(), d.end());

    int count=1;
    for (int i=0; i<N-1; i++) {
        if (d[i]!=d[i+1]) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
a, b, n = list(map(int, input().split(' ')))
x = 0
# arr = []
# for i in range(n):
#     x = i + 1
#     solve = ((a*x)//b) - a * (x//b)
#     arr.append(solve)

# print(max(arr))

if n < b:
    x = n
elif n > b:
    x = b - 1
else:
    if b > 1:
        x = b - 1
    else:
        1
ans = (a * x) // b

if b == 1:
    ans = 0

print(ans)


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

#define 	pi 				3.1415926536
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(int i = a ; i < b ; i++)
#define     repn(i, a, b)   for(int i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define     pii              pair<int, int>
#define     pll             pair<long long int, long long int>
#define     vll             vector<long long int>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;


/*############################# DSU ##############################*/
vi parent(1e5), Size(1e5), Rank(1e5);

void make_set(int v){
    parent[v]=v;
    Size[v] = 1;
    // Rank[v] = 0;
}
 
int find_set(int v){
	return (parent[v]==v) ?  v : parent[v] = find_set(parent[v]);
}
 
void union_sets(int a, int b){
	a = find_set(a);
	b = find_set(b);
	if(a != b){
        if(Size[a] < Size[b])
            swap(a, b);
        // if(Rank[a] < Rank[b])
        //     swap(a, b);
		parent[b] = a;
        Size[a] += Size[b];
        // if(Rank[a] == Rank[b])
        //     Rank[a]++;
    }
}
/*############################# DSU ##############################*/


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }

ll pw2[32];
void cal(){ pw2[0] = 1; rep(i, 1, 32)pw2[i] = 2*pw2[i-1]; }

/* ################################################################ */
ll a, n, b;
void solve()
{
    cin>>a>>b>>n;
    if(n>=b){
        cout<<(a*(b-1))/b<<nl;
    }
    else{
        cout<<(a*n)/b-a*(n/b)<<nl;

    }
}


int main()
{
    // boost;
    cal();
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

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

ans = 0
for i in range(-1, N - 2):
    # 必要な操作回数
    count = a[i + 1] + a[i + 2] - x
    if count <= 0:
        continue

    ans += count

    # 右の項を引くだけで完結する場合
    if count < a[i + 2]:
        a[i + 2] -= count

    # 両方の項から引かなければいけない場合
    else:
        a[i + 1] = a[i + 1] - count + a[i + 2]
        a[i + 2] = 0

print(ans)

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

int main() {
  int n;
  cin >> n;
  // mapを使えば頻度は簡単に出せる
  map<string, int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  ll ans = 0;
  for (auto &p : mp) {
    int s = p.second;
    ans += (ll)s*(s-1)/2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11228
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		vector<int>a,b;
		for(int i=0;i<n;i++)
		{
			int c;cin>>c;a.push_back(c);
		}
		for(int i=0;i<n;i++)
		{
			int c;cin>>c;b.push_back(c);
		}
		sort(a.begin(),a.end(),greater<int>());
		sort(b.begin(),b.end(),greater<int>());
		priority_queue<int>P;
		bool f=1;
		int cnt=0;
		for(int i=0;i<n-1;i++)
		{
			if(a[i]<=b[i])continue;
			else
			{
				if(!P.empty()&&P.top()>=a[i])
				{
					P.pop();
					P.push(b[i]);
					continue;
				}
				else
				{
					P.push(b[i]);
					cnt++;
				}
			}
			if(cnt>(i+1)/2)
			{
				f=0;
				cout<<i+1<<endl;
				break;
			}
		}
		if(f)cout<<"NA"<<endl;
	}
}



Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, res = 0;
  cin >> N;
  vector<int> h(N);
  for (int i=0; i<N; i++) cin >> h[i];
  while (true) {
    if (*max_element(h.begin(), h.end())==0) break;
    else {
      int i = 0;
      while (i<N) {
        if (h[i]==0) i++;
        else {
          res++;
          while (i<N&&h[i]>0) {
            h[i]--;
            i++;
          }
        }
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
module constants
  implicit none
  integer(8), parameter :: modulo = 10**9 + 7
end module constants

program abc110d
  use constants
  implicit none
  integer(8) :: ans = 1, i = 2
  integer(8) n, m, count
  read *, n, m
  do
     if (m < i * i) exit
     if (mod(m, i) == 0) then
        count = 0
        do
           m = m / i;
           count = count + 1
           if (mod(m, i) /= 0) exit
        end do
        ans = mod(ans * comb(n + count - 1, count), modulo)
     end if
     i = i + 1
  end do
  if (m /= 1) then
     ans = mod(ans * n, modulo)
  end if
  print *, ans

contains

  recursive function comb(n, k) result(r)
    integer(8), intent(in) :: n, k
    integer(8) r, i, numer, denom
    if (n - k < k) then
       r = comb(n, n - k)
    else
       numer = 1
       denom = 1
       do i = 0, k - 1
          numer = mod(numer * (n - i), modulo)
          denom = mod(denom * (i + 1), modulo)
       end do
       r = mod(numer * modpow(denom, modulo - 2), modulo)
    end if
  end function comb

  recursive function modpow(a, p) result(r)
    integer(8), intent(in) :: a, p
    integer(8) r
    if (p == 0) then
       r = 1
    else if (mod(p, 2) == 0) then
       r = mod(modpow(a, p / 2)**2, modulo)
    else
       r = mod(a * modpow(a, p - 1), modulo)
    end if
  end function modpow

end program abc110d


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int ans;
int main() {
	string h, aans = "o";
	cin >> h;
	if (h[0] == 'x') { ++ans; }
	if (h[h.length() - 1] == 'x') { ++ans; }
	if (ans == 2) { aans = "x"; }
	cout << aans << endl;
}


Measured memory_bytes: 3204
# ARC066C - Lining Up (ABC050C)
from collections import Counter


def main():
    n = int(input())
    a = sorted(Counter(map(int, input().rstrip().split())).items())
    MOD = 10 ** 9 + 7
    if n % 2 == 1 and a[0][1] != 1:
        print(0)
    elif not all(i[1] == 2 for i in a[1:]):
        print(0)
    else:
        if n % 2 == 0:
            print(2 ** len(a) % MOD)
        else:
            print(2 ** (len(a) - 1) % MOD)


if __name__ == "__main__":
    main()

Measured memory_bytes: 16624
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
int t=0;
vi d,f;
vb used;
void dfs(int now,vvi &gr){
  if(used[now]) return;
  used[now] = true;
  t++;
  mins(d[now],t);
  REP(i,gr[now].size()){
    dfs(gr[now][i],gr);
  }
  t++;
  f[now] = t;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  d.assign(n,INT_MAX);
  f.assign(n,INT_MAX);
  used.assign(n,false);
  vvi gr(n);
  REP(i,n){
    int k;
    cin >> k >> k;
    REP(j,k){
      int v;
      cin >> v;
      gr[i].eb(v-1);
    }
  }
  REP(i,n){
    dfs(i,gr);
  }
  REP(i,n){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979323846;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  for (int i=0; i<M; i++) {
    cin >> P[i] >> Y[i];
    P[i]--;
  }
  // vals[v]:=(P[i]=vであるようなiについてのY[i]の値を集めたもの)
  vector<vector<int>> vals(N);
  for (int i=0; i<M; i++) vals[P[i]].push_back(Y[i]);
  // 各P[i]の値に対して
  for (int i=0; i<N; i++) {
    sort(vals[i].begin(), vals[i].end());
    // 数のダブりをなくす
    vals[i].erase(unique(vals[i].begin(), vals[i].end()), vals[i].end());
  }
  // 答え
  for (int i=0; i<M; i++) {
    int v = P[i];
    printf("%06d", v+1);
    // 座標圧縮して導いた答え
    int id = lower_bound(vals[v].begin(), vals[v].end(), Y[i])-vals[v].begin();
    printf("%06d\n", id+1);
  }
}

Measured memory_bytes: 7808
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20

A,B,C,D = map(int,input().split())

def count(L,R,d):
    if L%d == 0:
        left = L
    else:
        left = L - L%d + d
    if R%d ==0:
        right = R
    else:
        right = R - R%d
    v = max((right-left)//d + 1, 0)
    return(v)

g = fractions.gcd(C,D)
lcm = C*D//g

multiple = count(A,B,C) + count(A,B,D) - count(A,B,lcm)
# print(count(A,B,C) , count(A,B,D) , count(A,B,lcm), lcm)
# print(multiple)
ans = B-A+1 - multiple
print(ans)


Measured memory_bytes: 7332
#include<stdio.h>
#include<stdlib.h>
#include<math.h>


int main(void){

  int a[100000]={};
  int min[100000]={};
  int i=0;  
  int time=0;
  int b,x,s,t,n,q,d;

  scanf("%d %d",&n,&q);
  if(1>n||n>100000||1>q||q>100000){
  printf("Too Large\n");
  exit(0);
  }

  while(i<n){
    a[i]=pow(2,31)-1;
    min[i]=a[i];
    i++;
  }

  i=0;




  while(i<q){
    i++;
   scanf("%d",&b);

   if(b==0){
   scanf("%d",&d);
   scanf("%d",&x);
   if(d>n||x>pow(2,23)-1){
   printf("Too Large\n");
   exit(0);
   }

   a[d] = x;
   }
 
   else if(b==1){
     time++;
   scanf("%d",&s);
   scanf("%d",&t);
   
   if(s>n||t>n){
   printf("Too Large\n");
   exit(0);
   }
   min[time]=a[s];
   for(s;s<=t;s++){
     if (a[s]<=min[time]){
       min[time]=a[s];
     }
   }

   }


  }

  i=0;

  while(i<time){
    ++i;
    printf("%d\n",min[i]);

  }
  


}

Measured memory_bytes: 2564
package main

import "fmt"

func main() {
	xs := make([]int, 3)
	sum := 0
	max := 0
	for i := range xs {
		fmt.Scan(&xs[i])
		sum += xs[i]
		if xs[i] > max {
			max = xs[i]
		}
	}
	fmt.Println(sum - max)
}


Measured memory_bytes: 512
from sys import stdin

s = stdin.readline().rstrip()

if len(s)%2 == 0:
    s = s[:-2]
else:
    s = s[:-1]

while True:
    if s[:len(s)//2] == s[len(s)//2:]:
        print(len(s))
        exit()
    s = s[:-2]

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

import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.parseInt;

/**
 * Problem 05: Split Up!
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			int[] a = new int[n];
			int sum = 0;

			StringTokenizer st = new StringTokenizer(br.readLine());
			for (int i = 0; i < n; i++) {
				sum += a[i] = parseInt(st.nextToken());
			}

			int min = MAX_VALUE;

			for (int i = 0; i < 1 << n; i++) {
				int A = 0;
				for (int j = 0; j < n; j++) {
					if ((i >> j & 1) == 1) A += a[j];
				}
				min = Math.min(min, Math.abs(sum - A - A));
			}

			System.out.println(min);
		}
	}
}

Measured memory_bytes: 25756
#include <stdio.h>
#define MAX 100000
#define SENTINEL 20000000

struct Card {
	char suit;
	int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;

	for (i = 0; i < n1; ++i) L[i] = A[left + i];
	for (i = 0; i < n2; ++i) R[i] = A[mid + i];
	L[n1].value = R[n2].value = SENTINEL;
	i = j = 0;

	for (k = left; k < right; ++k) {
		if (L[i].value <= R[j].value) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}
}

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

int partition(struct Card A[], int n, int p, int r) {
	int i, j;
	struct Card t, x;
	x = A[r];
	i = p - 1;
	for (j = p; j < r; ++j) {
		if (A[j].value <= x.value) {
			++i;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
	return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r) {
	int q;
	if (p < r) {
		q = partition(A, n, p, r);
		quickSort(A, n, p, q - 1);
		quickSort(A, n, q + 1, r);
	}
}

int main() {
	int n, i, v;
	struct Card A[MAX], B[MAX];
	char S[10];
	int stable = 1;

	scanf("%d", &n);

	for (i = 0; i < n; ++i) {
		scanf("%s %d", S, &v);
		A[i].suit = B[i].suit = S[0];
		A[i].value = B[i].value = v;
	}

	mergeSort(A, n, 0, n);
	quickSort(B, n, 0, n - 1);

	for (i = 0; i < n; ++i) {
		if (A[i].suit != B[i].suit) stable = 0;
	}

	if (stable == 1) printf("Stable\n");
	else printf("Not stable\n");
	for (i = 0; i < n; ++i) {
		printf("%c %d\n", B[i].suit, B[i].value);
	}
}


Measured memory_bytes: 4924
N = int(input())
S = list(input())

ans = 0
count = 0
for i in range(len(S)):
  if count == 0:
    if S[i] == 'A':
      count = 1
  elif count == 1:
    if S[i] == 'B':
      count = 2
    elif S[i] == 'A':
      count = 1
    else:
      count = 0
  else:
    if S[i] == 'C':
      ans += 1
      count = 0
    elif S[i] == 'A':
      count = 1      
    else:
      count = 0
      
print(ans)


Measured memory_bytes: 3064
s=input()
t=""
num=[]
for i in range(len(s)):
    if s[i]!="x":
        t+=s[i]
        num.append(i)
yn=0
for i in range(-(len(t)//-2)):
    if t[i]!=t[-1-i]:
        yn=1
        break
if yn==1:
    print(-1)
else:
    if len(num)==0:
        print(0)
    else:
        ans=abs(num[0]-(len(s)-num[-1]-1))
        for i in range(len(num)//2):
            ans+=abs((num[i+1]-num[i])-(num[-1-i]-num[-2-i]))
        print(ans)


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

bool check(string s){
	for(int i = 0; i < s.size(); i++){
		if(s[i] != s[s.size() - 1 - i]) return false;
	}
	return true;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string s;
	cin >> s;
	int N = s.size();
	int cnt = 0;

	string t;
	for(int i = 0; i < N; i++){
		if(s[i] != 'x') t += s[i];
	}
	//cout << t << endl;
	if(!check(t)){
		cout << -1 << endl;
		return 0;
	}

	int head = 0, tail = N - 1;
	int ans = 0;
	for(int i = 0; i < (t.size() + 1) / 2; i++){
		int l = 0, r = 0;
		while(s[head] == 'x') l++, head++;
		while(s[tail] == 'x') r++, tail--;
		ans += abs(l - r);
		head++;
		tail--;
	}

	cout << ans << endl;
}


Measured memory_bytes: 592
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n,m;
  cin>>n>>m;
  vector< vector<ll>> key(m,vector<ll>(2,0));
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    key[i][0]=a;
    ll op=0;
    rep(j,b){
      ll c;
      cin>>c;
      op |= 1<<(c-1);
    }
    key[i][1]=op;
  }
  /*
  rep(i,m){
    cout << key[i][0] << "," << std::bitset<12>(key[i][1]) << endl;
  }
  */
  vector<ll> dp(4096,INF);
  dp[0]=0;
  rep(i,m){
    rep(j,4096){
      ll next_sta=(key[i][1] | j);
      dp[next_sta]=min( dp[next_sta],dp[j]+key[i][0] );
    }
  }
  if( dp[ (1<<n) - 1 ] == INF) cout << -1 << endl;
  else cout << dp[ (1<<n) - 1 ] << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 384
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

int n,m;
cin>>n>>m;

int cnt[n];
for(int i=0;i<n;i++)cnt[i]=0;
for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    cnt[a-1]+=1;
    cnt[b-1]+=1;
}

for(int i=0;i<n;i++){
    cout<<cnt[i]<<endl;
}


return 0;
}

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

int main() {
    int N, H, W;
    cin >> N >> H >> W;

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        if (H <= a && W <= b) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
dp = [0] * N
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]))
print(dp[N-1])

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

int main(){
  int N, K;
  cin >> N >> K;
  list<double> P;
  int a = N;
  for(int ii=1; a>0; ii*=2){
    if(N*ii < K) continue;
    int b = K / ii + (K%ii==0? 0 : 1);
    P.push_back((double)(a - b + 1)/(double)ii);
    a = b - 1;
  }

  P.sort();
  double ans = 0;
  for(auto& p : P){
      ans += p;
  }
  ans /= (double) N;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


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


using namespace std;


int main()
{
    char x,y,z;
    cin>>x>>y;
    if(x=='H')
    {
        if(y=='H')
        z='H';
        else
        z='D';
    }
    if(x=='D')
    {    
        if(y=='H')
        z='D';
        else
        z='H';
    }
    cout<<z;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
n_digit = len(str(n))
ans = 0
for i in range(1,n+1):
  max_a = list(str(i))[0]
  min_a = list(str(i))[-1]
  if min_a == "0":
    continue
  else:
    if max_a == min_a:
      if int(max_a)<=n:
        ans += 1
    for j in range(n_digit-1):
      max_b = int(min_a+"9"*j+max_a)
      min_b = int(min_a+"0"*j+max_a)
      if max_b <= n:
        ans += int(10**j)
      elif min_b > n:
        continue
      else:
        ans += (n-min_b)//10+1
print(ans)

Measured memory_bytes: 43372
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl '\n'
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
//int rnd(int x) { return mrand() % x;}
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int dp[105];
int main()
{
	fastIO;
	ll n;
	cin >> n;
	int ans = 0;
	for(ll i = 2; i * i <= n; ++i) {
		if(n % i == 0) {
			int cnt = 0;
			while(n % i == 0) n /= i, cnt++;
			//cout << i << " " << cnt << endl;
			memset(dp,-1,sizeof dp);
			dp[0] = 0;
			for(int j = 1; j <= cnt; ++j){
				for(int k = cnt; k >= j; --k){
					if(dp[k - j] != -1) dp[k] = max(dp[k],dp[k - j] + 1);
				}
			}
			ans += dp[cnt];
		}
	}	
	//cout << n << endl;
	if(n != 1) ans++;
	cout << ans << endl;	
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#include <math.h> 
#include<stdio.h>
#include<string.h> //strcmp、strncmp関数を使うために必要
#include <stdlib.h>

int main(){
    ll N,K;
    cin >> N >> K;
    ll t = 0;

    t = N%K;
    cout << min(t,K-t) << endl;
    

}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  ll N, C;
  cin >> N >> C;
  vector<ll> x(N), v(N);
  rep(i, N) cin >> x[i] >> v[i];

  vector<ll> lsum(N), rsum(N);
  rep(i, N) {
    lsum[i] = v[i];
    if (i) lsum[i] += lsum[i - 1];
    rsum[i] = v[N - 1 - i];
    if (i) rsum[i] += rsum[i - 1];
  }

  vector<ll> l2sum = lsum, r2sum = rsum;
  rep(i, N) {
    lsum[i] -= x[i];
    l2sum[i] -= x[i] * 2;
    rsum[i] -= (C - x[N - 1 - i]);
    r2sum[i] -= (C - x[N - 1 - i]) * 2;
  }

  rep(i, N - 1) {
    lsum[i + 1] = max(lsum[i + 1], lsum[i]);
    l2sum[i + 1] = max(l2sum[i + 1], l2sum[i]);
    rsum[i + 1] = max(rsum[i + 1], rsum[i]);
    r2sum[i + 1] = max(r2sum[i + 1], r2sum[i]);
  }

  ll ans = 0;
  rep(i, N) ans = max({ans, lsum[i], rsum[i]});
  rep(i, N - 1) ans = max(
      {ans, l2sum[i] + rsum[N - 1 - i - 1], r2sum[i] + lsum[N - 1 - i - 1]});

  cout << ans << endl;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int i,j,k,x,y,d,ax,ay,G=0,a=0,b=0,yy;
		Scanner sc=new Scanner(System.in);
		x=Integer.parseInt(sc.next());
		y=Integer.parseInt(sc.next());
		
		if(x<y){
		
		a=x;
		b=y;
		x=b;
		y=a;
		}
		while(y>0){
		a=y;
		b=x%y;
	
		y=b;
		x=a;
		
		}
		
		
		System.out.println(x);
	}

}

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

int main() {
    long long x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    long long p[a];
    for(int i=0;i<a;i++) cin >> p[i];
    sort(p,p+a);
    long long q[b];
    for(int i=0;i<b;i++) cin >> q[i];
    sort(q,q+b);
    long long r[c];
    for(int i=0;i<c;i++) cin >> r[i];
    priority_queue<long long> que;
    for(int i=0;i<x;i++) que.push(p[a-1-i]);
    for(int i=0;i<y;i++) que.push(q[b-1-i]);
    for(int i=0;i<c;i++) que.push(r[i]);
    long long count=0;
    for(int i=0;i<x+y;i++){
        count += que.top();
        que.pop();
    }
    cout << count << endl;
}

Measured memory_bytes: 8816
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int p, l, r;
};

struct Node T[MAX];
int n;
int D[MAX], H[MAX];

int getDepth(int u){
  int d = 0;
  while(1){
    u = T[u].p;
    if ( u == NIL ) break;
    d++;
  }
  return d;
}

int getSibling(int u){
  if ( T[u].p == NIL ) return NIL;
  if ( T[T[u].p].l != u && T[T[u].p].l != NIL ) return T[T[u].p].l;
  if ( T[T[u].p].r != u && T[T[u].p].r != NIL ) return T[T[u].p].r;
  return NIL;
}

void print(int u){
  printf("node %d: ", u);

  printf("parent = %d, ", T[u].p);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].l != NIL ) deg++;
  if ( T[u].r != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].p == NIL ){
    printf("root\n");
  } else if ( T[u].l == NIL && T[u].r == NIL ){
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}


int main(){
  int i, v, l, r;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    T[i].p = NIL;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if ( l != NIL ) T[l].p = v;
    if ( r != NIL ) T[r].p = v;
  }

  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
    H[i] = 0;
  }

  for ( i = 0; i < n; i++ ){
    if ( T[i].l == NIL && T[i].r == NIL ) { // is leaf
      H[i] = 0;
      int p = T[i].p;
      int c = 1;
      while(1){
	if ( p == NIL ) break;
	if ( H[p] < c ) H[p] = c;
	c++;
	p = T[p].p;
      }
    }
  }

  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}



Measured memory_bytes: 2112
package main

import (
	"fmt"
	"io"
	"os"
)

func run(input io.Reader, output io.Writer) int {
	var n, a, b int
	fmt.Scanf("%d %d %d\n", &n, &a, &b)

	v := n / (a + b)
	l := n % (a + b)
	if l >= a {
		fmt.Println(v*a + a)
	} else {
		fmt.Println(v*a + l)
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int main()
{
    int n, m, i, a;
    bool f = 0;
    char b;
    cin >> n >> m;
    string s(n, 'a');
    //cout << s << endl;
    if(!m && n == 1){
        if(n == 1)
            cout << 0 << nl;
        return 0;
    }
    while (m--)
    {
        cin >> a >> b;
        if(s[a-1] != 'a' && s[a-1] != b){
            cout << -1 << nl;
            return 0;
        }
        s[a - 1] = b;
    }
    if(s[0] == 'a' && n > 1)
        s[0] = '1';
    for (i = 1; i < n; i++)
    {
        if(s[i] == 'a'){
            s[i] = '0';
        }
    }
    if (s[0] == '0' && n > 1)
    {
        cout << -1 << nl;
    }
    else
        cout << s << nl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}



int main()
{
	int i,j,k,pos,depth,cur,cur2,cur3;
	int p1,p2,p3;
	int N,M;
	int S,T;
	int mp[100010][3] = {0};
	vector<int> way[100010];


	cin >> N >> M;
	for(i=0;i<M;++i)
	{
		cin >> j >> k;
		way[j].push_back(k);
		//way[k].push_back(j);
	}
	cin >> S >> T;
	queue<pair<int, int> > q;
	q.push(make_pair(S,0));
	mp[S][0] = 1;
	int isEnd = 0;
	int ans = -1;
	while(!q.empty())
	{
		pos = q.front().first;
		depth = q.front().second;
		q.pop();
		p1 = way[pos].size();
		for(i=0;i<p1;++i)
		{
			cur = way[pos][i];
			if(!mp[cur][1])
			{
				mp[cur][1] = 1;
				p2 = way[cur].size();
				for(j=0;j<p2;++j)
				{
					cur2 = way[cur][j];
					if(!mp[cur2][2])
					{
						mp[cur2][2] = 1;
						p3 = way[cur2].size();
						for(k=0;k<p3;++k)
						{
							cur3 = way[cur2][k];
							if(!mp[cur3][0])
							{
								mp[cur3][0] = 1;
								if(cur3 == T)
								{
									isEnd = 1;
									ans = depth + 1;
								}
								else
								{
									q.push(make_pair(cur3,depth+1));
								}
							}
						}
					}
				}
			}
		}
		if(isEnd)
			break;
	}
	cout << ans << endl;
	return 0;
}



























Measured memory_bytes: 6912
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  char c;
  v(char) A(4);
  cin >> A;

  string ans = "";

  rep(i, 1 << 3){
    i64 tmp = (A[0] - '0');

    if((i >> 0) & 1) tmp += (A[1] - '0');
    else tmp -= (A[1] - '0');

    if((i >> 1) & 1) tmp += (A[2] - '0');
    else tmp -= (A[2] - '0');

    if((i >> 2) & 1) tmp += (A[3] - '0');
    else tmp -= (A[3] - '0');

    if(tmp == 7){
      ans = A[0];
      rep(j, 3){
        if((i >> j) & 1) ans += "+";
        else ans += "-";
        ans += A[j + 1];
      }
      ans += "=7\n";
      break;
    }
  }
  cout << ans;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#define rep(i,a) for(int i=0;i<(a);++i)

using ll = long long;

int N, A, B;
std::vector<int> vs;

void show( const std::vector<int> &v )
{
  rep( i, v.size() )
    printf( "%d%c", v[i], i==v.size()-1?'\n':' ' );

  return;
}

int main()
{
  scanf( "%d%d%d", &N, &A, &B );

  if( N < A+B-1 || (ll)N > (ll)A*B )
  { puts("-1"); return 0; }

  //show(vs);

  rep( i, A )
    printf( "%d ", N-(A-1-i) );

  --B;
  int p = N-A;
  while( p )
  {
    if( p == B ) while( p >= 1 )
      printf( "%d ", p ), --p;
    else
    {
      int tmp = 0; B--;
      for( ; p >= 1 && tmp < A; --p, ++tmp ) if( p == B )
        break;
      for( int j = 1; j <= tmp; ++j )
        printf( "%d ", p+j );
    }
  }

  puts("");

  return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    ll n, d;
    cin >> n >> d;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        if(x * x + y * y <= d * d)cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3592
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef pair<int, int> pii;
const int MAXN = 1e5 + 10;

int N;
int fa[MAXN];
set<int> Adj[MAXN];
queue<pii> dualEdges;
map<pii, int> edgeCnt;

int find(int x)
{
	if (x == fa[x])
		return x;
	return fa[x] = find(fa[x]);
}

inline void addEdge(int u, int v)
{
	Adj[u].insert(v), Adj[v].insert(u);
	if (u > v)
		swap(u, v);
	if (++edgeCnt[make_pair(u, v)] == 2)
		dualEdges.emplace(u, v);
}

int main()
{
	int u, v;
	cin >> N;

	for (int i = 1; i <= 2 * N - 2; i++)
		cin >> u >> v, addEdge(u, v);
	iota(&fa[0], &fa[N + 1], 0);

	for (int i = 1; i < N; i++)
	{
		int x = 0, y = 0;
		do
		{
			if (dualEdges.empty())
			{
				puts("NO");
				return 0;
			}
			tie(x, y) = dualEdges.front();
			dualEdges.pop();
			x = find(x), y = find(y);
		} while (x == y);

		if (Adj[x].size() > Adj[y].size())
			swap(x, y);
		fa[x] = y, Adj[x].erase(y), Adj[y].erase(x);
		edgeCnt.erase(make_pair(min(x, y), max(x, y)));

		for(int z : Adj[x])
		{
			z = find(z);
			edgeCnt[make_pair(min(x, z), max(x, z))]--;
			if(z == y)
				continue;
			Adj[z].erase(x);
			addEdge(y, z);
		}
	}

	puts("YES");

	return 0;
}


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

int main() {
    int n;
    cin >> n;
    int iarr[n] = {0};
    for (int i = 1; i < n; ++i) {
        int num;
        cin >> num;
        ++iarr[num-1];
    }
    for (int i : iarr) {
        cout << i << endl;
    }
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	int ans=0;
	for(int i=1;i<=N;i+=2){
		int j=1;
		int num=0;
		while(j<=i){
			if(i%j==0) num++;
			j+=2;
		}
		if(num==8) ans++;
	}
	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

type kakko struct {
	str string
	min int
	max int
}

func main() {
	N := getStdinInt()
	F := make([]kakko, 0, N)
	L := make([]kakko, 0, N)
	for i := 0; i < N; i++ {
		s := getStdin()
		min, max := minMaxKakko(s)
		if min >= 0 {
			F = append(F, kakko{s, min, max})
		} else {
			L = append(L, kakko{s, min, max})
		}
	}
	sort.Slice(F, func(i, j int) bool { return F[i].max-F[i].min < F[j].max-F[j].min })
	sort.Slice(L, func(i, j int) bool { return L[i].max > L[j].max })

	K := make([]kakko, N)
	for i := 0; i < len(F); i++ {
		K[i] = F[i]
	}
	for i := 0; i < len(L); i++ {
		K[i+len(F)] = L[i]
	}

	first := -1
	last := -1
	for i := 0; i < len(K); i++ {
		if K[i].str[0] == '(' {
			first = i
			break
		}
	}
	for i := len(K) - 1; i >= 0; i-- {
		if i != first && K[i].str[len(K[i].str)-1] == ')' {
			last = i
			break
		}
	}

	if first == -1 || last == -1 {
		fmt.Printf("No\n")
		return
	}

	stack := 0
	stack = okKakko(K[first].str, stack)
	if stack < 0 {
		fmt.Printf("No\n")
		return
	}

	for i := 0; i < len(K); i++ {
		if first == i || last == i {
			continue
		}
		stack = okKakko(K[i].str, stack)
		if stack < 0 {
			fmt.Printf("No\n")
			return
		}
	}

	stack = okKakko(K[last].str, stack)
	if stack < 0 {
		fmt.Printf("No\n")
		return
	}

	if stack == 0 {
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}
}

func minMaxKakko(s string) (int, int) {
	stack := 0
	min := math.MaxInt32
	max := math.MinInt32
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack++
			if stack > max {
				max = stack
			}
		}
		if s[i] == ')' {
			stack--
			if stack < min {
				min = stack
			}
		}
	}
	return min, max
}

func okKakko(s string, stack int) int {
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack++
		}
		if s[i] == ')' {
			stack--
		}
		if stack < 0 {
			return -1
		}
	}
	return stack
}

func getStdin() string {
	return readLine()
}
func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for(int i = 1; i <= N; i++) {
            if(!(bits & (1 << (i-1)))) continue;
            for(int j = 1; j <= A[i]; j++) {
                if((bits & ( 1 << (x[i][j]-1))) ^ (1<<(x[i][j]-1))*y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#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 yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

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

  ll n;
  cin>>n;
  string s;
  cin>>s;

  string back_s=s.substr(n,n);
  reverse(ALL(back_s));

  map<pair<string,string>,ll> m;
  REP(bit,(1<<n)){
    string b="",r="";
    REP(i,n){
      if((bit>>i)&1)
        b+=back_s[i];
      else
        r+=back_s[i];
    }

    if(b>r)
      swap(b,r);
    m[make_pair(b,r)] += 1;
  }

  ll ans=0;
  REP(bit,(1<<n)){
    string b="",r="";
    REP(i,n){
      if((bit>>i)&1)
        b+=s[i];
      else
        r+=s[i];
    }
    if(b>r)
      swap(b,r);

    if(b==r)
      ans+=m[make_pair(b,r)];
    else
      ans+=m[make_pair(b,r)]/2;
  }
  cout<<ans<<endl;

}



Measured memory_bytes: 32272
/*input
2 1
-2 1

5 4
5 3 2 -5 2
2 -4 2 8 -4
2 3 -7 6 7
3 -4 10 -3 -3

2 2
2 -3
3 -1


*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 1005
#define bit(x,y) ((x>>y)&1LL)
const int INF = 1e18;

int n, m;
int a[N][N];
int dp[N][N][2];
int sum[N][N];
// p1 - p2

int cal(int x, int y, int type) {
	if (x == n && y == m) return 0;
	int &ret = dp[x][y][type];
	if (ret != INF) return ret;

	if (type == 0) {
		ret = -INF;
		if (x != n) {
			ret = max(ret, cal(x + 1, y, 1));
		}
		if (y != m) {
			ret = max(ret, cal(x, y + 1, 1) + sum[y + 1][x] - (sum[y + 1][n] - sum[y + 1][x]));
		}
	}
	else {
		ret = INF;
		if (x != n) {
			ret = min(ret, cal(x + 1, y, 0));
		}
		if (y != m) {
			ret = min(ret, cal(x, y + 1, 0) + sum[y + 1][x] - (sum[y + 1][n] - sum[y + 1][x]));
		}
	}
	return ret;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> m >> n;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j];
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) sum[i][j] = sum[i][j - 1] + a[j][i];
	}
	for (int i = 0; i < N; i++) for (int j = 0; j < N; j++)	dp[i][j][0] = dp[i][j][1] = INF;
	cout << abs(cal(0, 0, 0)) << endl;
}


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

int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  int s_l,t_l;
  s_l = s.length();
  t_l = t.length();
  int min_l = min(s_l,t_l);
  bool ans = false;
  for(int i=0; i<min_l; i++){
    if(s.at(i) < t.at(i)){
      ans = true;
      break;
    }else if(s.at(i) > t.at(i)){
      break;
    }else{
      if(i == min_l-1){
        if(s_l < t_l){
          ans = true;
          break;
        }else{
          break;
        }
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

ok = 10 ** 9  # 解が存在する値
ng = 0  # 解が存在しない値


def solve(x):
    """
    一番長いのをx以下にできるか
    → 全部をx以下にするのに切る回数 <= K
    """
    res = 0
    for i in range(N):
        res += (A[i] - 1) // x

    return res <= K


while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Measured memory_bytes: 30780