akhauriyash/Code-Regression huggingface dataset:
<?php
  fscanf(STDIN, "%d %d", $n, $m);
  $x = explode(" ", trim(fgets(STDIN)));
  sort($x);
  
  $dist = [];
  for ($i=0; $i<$m-1; $i++) {
    $dist[] = $x[$i+1] - $x[$i];
  }


  sort($dist);
  while(count($dist)>0 && $n-1 > 0) {
    array_pop($dist);
    $n--;
  }

  $ans = array_sum($dist);
  echo $ans . "\n";
?>

Measured memory_bytes: 18932
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    vec div = {105,165,195,135,189};
    ll ans = 0;
    rep(i,5) ans += (N >= div[i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import itertools

N = int(input())

li = []

for n in range(1, 10):
    for num in itertools.product("357", repeat=n):
        if(num.count("3") and num.count("5") and num.count("7")):
            li.append(int("".join(num)))

print(len([i for i in li if i <= N]))

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

int main(){
    const double pi=3.14159265;
    int r;
    cin>>r;
    cout<<setprecision(10)<<2*r*pi<<endl;
    return 0;
}

Measured memory_bytes: 3784
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination(int, int);
};
int Combination::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination::Combination(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

void A_Round_One(void) {

	int A, B;
	cin >> A >> B;

	if		(A != 1 && B != 1)	cout << 1 << flush;
	else if (A != 2 && B != 2)	cout << 2 << flush;
	else						cout << 3 << flush;
}

void B_Strings_with_the_Same_Length(void) {

	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;

	for (int loop = 0; loop < N; loop++) cout << S[loop] << T[loop] << flush;
	return;
}

int main(void) {

	//A_Round_One();
	B_Strings_with_the_Same_Length();
	return 0;
}


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

int main(){
    int H, N;
    cin >> H >> N;
    int A[N];
    int sum=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        sum += A[i]; 
    }

    if( sum < H ){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const ll mod = 100000000000000003;
int ne[200001], he[100001];
char C[1200100];

ll num[524300];
int kazu[524300];
const int ma = (1 << 19) - 1;
int query(ll n) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return kazu[n2];
		n2 = n2 * 61 % 524287;
	}
	return 0;
}
void add(ll n, int b) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) {
			kazu[n2] |= b;
			return;
		}
		n2 = n2 * 61 % 524287;
	}
	num[n2] = n + 1;
	kazu[n2] = b;
}

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


	fread(C, 1, 1200100, stdin);
	char* ci = C, c;
	int N = 0;
	while ((c = *ci++) >= '0') N = N * 10 + c - '0';

	ll dekai[10];
	int d = 0;
	char* s[200001];
	rep1(i, N) {
		s[i] = ci;
		while (*ci++ >= '0');
		int n = ci - s[i] - 1;	
		if (n <= 100000) {
			ne[i] = he[n];
			he[n] = i;
		}
		else {
			dekai[d++] = (ll(n) << 30) + s[i] - C;
		}
	}

	ll kotae = 0;

	for (int M = 1; M <= 100000; M++) {
		for (int p = he[M]; p; p = ne[p]) {
			auto S = s[p];
			int k[26] = {};
			ll are = 0;
			for (int i = M - 1; i >= 1; i--) {
				int tmp = query(are);
				if (tmp) {
					rep(j, 26) if ((tmp >> j & 1)) {
						k[j]++;
					}
				}
				kotae += k[S[i] - 'a'];
				k[S[i] - 'a'] = 0;
				are = (are * 30 + S[i] - 'a' + 1) % mod;
			}

			kotae += k[S[0] - 'a'];
			k[S[0] - 'a'] = 0;

			add(are, 1 << (S[0] - 'a'));
		}
	}
	sort(dekai, dekai + d);
	rep(p, d) {
		auto S = C + (dekai[p] & (1 << 21) - 1);
		int k[26] = {};
		ll are = 0;
		for (int i = (dekai[p] >> 30) - 1; i >= 1; i--) {
			int tmp = query(are);
			if (tmp) {
				rep(j, 26) if ((tmp >> j & 1)) {
					k[j]++;
				}
			}
			kotae += k[S[i] - 'a'];
			k[S[i] - 'a'] = 0;
			are = (are * 30 + S[i] - 'a' + 1) % mod;
		}

		kotae += k[S[0] - 'a'];
		k[S[0] - 'a'] = 0;

		add(are, 1 << (S[0] - 'a'));
	}
	printf("%lld\n", kotae);


	Would you please return 0;
}

Measured memory_bytes: 11232
#include<bits/stdc++.h>
#define maxn 200010
#define LL long long 
using namespace std;
int n;
int seg[maxn];
LL sum[maxn];
int main(){
	cin>>n;
	int x;
	LL ans=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		sum[i]=sum[i-1]+x;
	}
	ans=1e14;
	for(int i=1;i<n;i++){
		ans=min(ans,abs(sum[n]-sum[i]-sum[i]));
	}
	cout<<ans;
	return 0;
}


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

int main()
{
    int x,y,t=0;
    while(~scanf("%d%d",&x,&y))
    {
        if(y%2==0)
        {
            t=x+(y/2);
        }
        printf("%d\n",t);
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		String ans = "No";
		if(t.length()==s.length()+1) {
			String temp = t.substring(0,t.length()-1);
			if(temp.equals(s)) {
				ans = "Yes";
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35752
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,L,x;
  cin >>N>>L;
  if(L<0&&N+L-1>0){
    x=0;
  }
  if(L<0&&N+L-1<0){
    x=N+L-1;
  }
  if(L>0){
    x=L;
  }
  cout<<N*(2*L+N-1)/2-x<<endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextLong() }
  val q = sc.nextInt()
  val bc = (1..q).map { Pair(sc.nextLong(), sc.nextLong()) }


  val map = mutableMapOf<Long, Long>()
  for (ai in a) {
    val tmp = map.getOrElse(ai) { 0 }
    map.put(ai, tmp + 1)
  }

  var nowSum = a.sum()

  val ans = mutableListOf<Long>()
  for (bci in bc) {
    val b = bci.first
    val c = bci.second

    val bsize = map.getOrElse(b) { 0L }
    map.put(b, 0L)
    val csize = map.getOrElse(c) { 0L }
    map.put(c, bsize + csize)


    val sum = nowSum + (c - b) * bsize
    ans.add(sum)

    nowSum = sum
  }


  println(ans.joinToString("\n"))

}




Measured memory_bytes: 82212
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <time.h>
#define MAXT 10
#define MOD 1000000007
using namespace std;

int main()
{
	int n;
	cin >> n;
	int sum = 0;
	int deg, i;

	for (i = 10, deg = 1;; i *= 10, deg++) {
		if (n < i) {
			i /= 10;
			break;
		}
	}
	//printf("%d,%d\n", i, deg);
	if (deg % 2) {
		sum = n - i + 1;
		i /= 100;
	} else {
		deg--;
		i /= 10;
	}

	//printf("sum = %d\n", sum);

	while (i > 0) {
		//printf("%d\n", i);
		sum += 9 * i;
		//printf("sum = %d\n", sum);
		i /= 100;
	}

	printf("%d", sum);

	return 0;
}


Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()

	v := [3]int64{}
	even := false
	for i := range v {
		v[i] = readInt64()
		if v[i]%2 == 0 {
			even = true
		}
	}

	if even {
		println(0)
		return
	}

	var ans int64 = math.MaxInt64
	for i := range v {
		ans = min(ans, v[i]*v[(i+1)%3])
	}

	println(ans)
}

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

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var s = Console.ReadLine();
        if (s[0] == s[1] && s[1] == s[2])
        {
            Console.WriteLine("No");
        }
        else
        {
            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
     
int main() { //ansha+1
  int n, m, x=0, y=0;
  cin >> n >> m;
  vector<int> h(n);
  vector<int> est(n, 0);
  
  rep (i, n) cin >> h.at(i);
  
  rep(i, m) {
    cin >> x >> y;
    if (h.at(x-1) == h.at(y-1)) {est.at(y-1) = 1;est.at(x-1) = 1;}
    else if (h.at(x-1) > h.at(y-1)) est.at(y-1) = 1;
    else if (h.at(x-1) < h.at(y-1)) est.at(x-1) = 1;
  }
  
  cout << count(est.begin(), est.end(), 0) << endl;
}
           
  

Measured memory_bytes: 4052
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int h1, m1, h2, m2;
    int k;

    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int t= h2 * 60 + m2 - h1 * 60 - m1;

    t -= k;
    cout << t << endl;
}


Measured memory_bytes: 3552
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう

N=3
M=3
i=0
j=0
k=0

s=input()
a=[i for i in s]
#print(a)
N=len(s)
#print(N)
N1=int(((N-1)/2-1)/2+1)
N2=int((N-1)/2-1)
N3=int((N+3)/2-1)
N4=int((N+1)/2)
for i in range(N4):
    #print(i, N-1-i)
    if a[i]==a[N-1-i]:
        pass
    else:
        print("No")
        sys.exit()

for i in range(N1):
    if a[i]==a[N2-i] and a[N3+i]==a[N-1-i]:
        pass
    else:
        print("No")
        #print(a[i],a[N2-i])
        #print(a[N3+i],a[N-1-i])
        sys.exit()
print("Yes")
#N=int(input())
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ

'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"




#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
const int N=200000+10;
int n,k,dp[N],h[N];
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>h[i];
    memset(dp,0x3f,sizeof(dp));
	dp[1]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(i+j<=n)dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
		}
	}
	cout<<dp[n]<<"\n";
    return 0;
}

Measured memory_bytes: 1408
import std.stdio, std.conv, std.algorithm, std.string, std.array;

void main() {
	string[] result;
	while (true) {
		auto n = readln.chomp.to!int;
		if (n == 0) break;
		uint[][] cell = new uint[][](n, n);
		foreach (i; 0..n) {
			auto tmp = readln.split.map!(to!uint).array;	
			cell[i][] = tmp;
		}
		foreach (i; 0..n) {
			string str;
			foreach (j; 0..n) {
				str ~= format("%5d", cell[i][j]);
			}
			str ~= format("%5d", cell[i].sum);
			result ~= str;
		}	
		string str;
		uint s;
		foreach (i; 0..n) {
			uint x = 0;
			foreach (j; 0..n) {
				x += cell[j][i];	
			}
			s += x;
			str ~= format("%5d", x);	
		}
		str ~= format("%5d", s);
		result ~= str;
	}
	foreach (r;result)
		r.writeln;
}

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

int main(){
    int N; cin >> N;
    int count = 0;
    for(int i = 0; i < N; ++i) {
        int tmp;
        bool isPrime = true;
        cin >> tmp;
        for(int j = 2; j <= sqrt(tmp); ++j){
            if(tmp % j == 0){
                isPrime = false;
                break;
            }
        }
        if(isPrime) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3048
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            //var watch = new Stopwatch();
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(a.Max() - a.Min());
            
            
            //watch.Start();

           

            Console.Out.Flush();
            /*watch.Stop();

            Console.WriteLine($"time:{watch.ElapsedMilliseconds} ms"); //Debug Only.
            Console.Out.Flush();*/
        }
    }
    


    public class Calculation
    {
        
    }

    public class Graph
    {

    }
}
    

Measured memory_bytes: 13396
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str;
		int n, k;
		str = br.readLine().split(" ");
		n = Integer.parseInt(str[0]);
		k = Integer.parseInt(str[1]);
		long[] arr = new long[n];
		long[] cost = new long[n];
		str = br.readLine().split(" ");
		for(int i=0; i<n; i++) {
			arr[i] = Long.parseLong(str[i]);
			cost[i] = Long.MAX_VALUE;
		}
		for(int i=0; i<n; i++) {
			if(i==0) cost[i] = 0;
			for(int j=1; j<=k; j++) {
				if((i-j)>=0) cost[i] = Math.min(cost[i-j]+Math.abs(arr[i]-arr[i-j]), cost[i]);
			}
		}
		System.out.println(cost[n-1]);
	}
}


Measured memory_bytes: 35736
use std::fmt::Debug;
use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;

fn main() {
    let mut sc = Scanner::new();
    let h = sc.parse::<usize>();
    let w = sc.parse::<usize>();
    let rows = (0..h).map(|_| sc.parse::<String>()).collect::<Vec<_>>();
    for _ in 0..w + 2 {
        print!("#");
    }
    println!("");
    for row in rows {
        println!("#{}#", row);
    }
    for _ in 0..w + 2 {
        print!("#");
    }
    println!("");
}


struct Scanner {
    stdin: Stdin,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            buf: Vec::with_capacity(256),
        }
    }

    fn parse<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut it = self.stdin.lock().bytes();
        let mut c = it.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = it.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = it.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse::<T>().unwrap()
    }
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MN = 100010;

int N, Q;
ll A[MN];
ll s[2][MN];

int main() {
	cin >> N >> Q;
	rep(i, N) {
		cin >> A[i];
		s[0][i + 1] = s[0][i];
		s[1][i + 1] = s[1][i];
		s[i & 1][i + 1] += A[i];
	}

	rep(i, Q) {
		int X; cin >> X;

		int lo = 1, hi = N;

		while (hi - lo > 1) { //takahashi
			int m = (lo + hi) / 2;
			ll d = abs(A[N-m] - X);

			int l = lower_bound(A, A + N - m, X - d) - A;
			int r = lower_bound(A, A + N - m, X + d) - A;

			if (r - l >= m-1) {
				lo = m;
			} else {
				hi = m;
			}
		}

		ll ans = s[0][N] + s[1][N] - s[0][N - lo] - s[1][N - lo];
		if (N-lo*2>=1) {
			int f = (N-1-lo*2) & 1;
			ans += s[f][N-lo*2];
		}
		cout << ans << "\n";
	}

	return 0;
}

Measured memory_bytes: 4096
N, K = map(int, input().split())
c = 0
mod = 1000000007
for k in range(K, N + 2):
    a = k * (k - 1) / 2
    b = k * (2 * N - k + 1) / 2
    c = (c + (b - a + 1)) % mod
print(int(c))


Measured memory_bytes: 9180
n=int(input())
vn=list(map(int,input().split()))
vn=sorted(vn)
value=0
for i in range(n-1):
    if i == 0:
        value = (vn[0] + vn[1])/2
    else:
        value = (value + vn[i+1])/2
print(value)

Measured memory_bytes: 38256
#include<stdio.h>
#define INF 100000
#define MAX 101

int G[MAX][MAX];
int n;

void prim();

int main()
{
  int c;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++)
  {
    for(j=0;j<n;j++)
    {
      scanf("%d",&c);
      if(c == -1)
      {
        G[i][j] = INF;
      }else
      {
        G[i][j] = c;
      }
    }
  }

  prim();
  return 0;
}

void prim()
{
  int i,j;
  int d[MAX],pi[MAX],color[MAX];
  int min,a,b,sum=0;

  for(i=0;i<n;i++)
  {
    d[i] = INF;
    pi[i] = -6;
    color[i] = 0;
  }

  d[0] = 0;

  while(1)
  {
    min = INF;
    a = -6;
    for(i=0;i<n;i++)
    {
      if(color[i] != 2 && d[i] < min)
      {
        min = d[i];
        a = i;
      }
    }

    if(a == -6)
    {
      break;
    }
    color[a] = 2;
    for(b=0;b<n;b++)
    {
      if(color[b] != 2 && G[a][b] != INF)
      {
        if(d[b] > G[a][b])
        {
          d[b] = G[a][b];
          pi[b] = a;
          color[b] = 1;
        }
      }
    }
  }
  for(i=0;i<n;i++)
  {
    if(pi[i] != -6)sum += G[i][pi[i]];
  }
  printf("%d\n",sum);
}



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

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

int selectionSort(int A[], int n) {

    int cnt = 0;

    for (int i = 0; i < n-1; i++) {
        int mini = A[i];
        int j_tmp = i;

        for (int j = i+1; j < n; j++) {
            if (mini > A[j]) {
                mini = A[j];
                j_tmp = j;
            }
        }

        if (j_tmp != i) {
            swap(A[i], A[j_tmp]);
            cnt++;
        }
    }

    return cnt;
}

int main() 
{
    int N;
    cin >> N;

    int A[105];
    REP(i, N)   cin >> A[i];

    int ss = selectionSort(A, N);

    REP(i, N) {
        if (i)  cout << " ";
        cout << A[i];
    }

    cout << endl << ss << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

vector<int> count[200100];
int ans[200100];

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v, int p) {
    seen[v] = true; // v を訪問済にする
  if (p != -1) ans[v] = ans[p];
  for (auto a : count[v]){
    ans[v] += a;
  }

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v, v); // 再帰的に探索
    }
}

int main() {
    // 頂点数と辺数、s と t
    int N, Q; cin >> N >> Q;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }
  
    for (int i = 0; i < Q; i++) {
      int a, b;
      cin >> a >> b;
      count[a - 1].push_back(b);
    }

    // 頂点 s をスタートとした探索
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    for (int i = 0; i < N; i++) ans[i] = 0;
    dfs(G, 0, -1);
  
  for (int i = 0; i < N; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 35120
#!/usr/bin/env python3
import math
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)

MOD = 1000000007  # type: int


@lru_cache(10000)
def combinations_count(n, r):
    if n - r < 0:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def solve(N: int, K: int):
    choices = N - K + 1
    for i in range(K):
        print(int(combinations_count(choices, i + 1) * combinations_count(K - 1, i)) % MOD)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 5780
<?php

$stdin = preg_split('/ /', trim(fgets(STDIN)));
$a = intval($stdin[0]);
$b = intval($stdin[1]);
$c = intval($stdin[2]);

if ($a < $b && $b < $c) {
	print("Yes\n");
} else {
	print("No\n");
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 110

int D, N;

signed main()
{
    cin >> D >> N;

    int ans = 1;
    if(D == 1) { ans = 100; }
    else if(D == 2) { ans = 10000; }

    if(N != 100) { ans *= N; }
    else {
        ans *= 101;
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <random>
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <stdexcept>
#include <iomanip>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

using namespace std;



int main() {
    string A;
    cin >> A;
    auto n = A.size();

    // iの後ろではじめでてくる文字cのindex
    vector<vector<int>> next(n + 1, vector<int>(26, n));
    for(int i = n - 1; i >= 0; --i) {
        int c = A[i] - 'a';
        next[i] = next[i + 1];
        next[i][c] = i;
    }

    vector<int> dp(n + 2, 0);
    dp[n] = 1;
    for(int i = n - 1; i >= 0; --i) {
        int l = INT_MAX;
        FOR(j, 0, 26) {
            l = min(l, dp[next[i][j] + 1] + 1);
        }
        dp[i] = l;
    }

    string ans;
    int p = 0;
    for (int i = dp[0] - 1; i >= 0; --i) {
        FOR(j, 0, 26) {
            if (dp[next[p][j] + 1] == i) {
                ans += char('a' + j);
                p = next[p][j] + 1;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 27780
n,y=map(int,input().split())
#1000円がn-a-b枚、5000円がa枚、10000万円がb枚とする
for i in range(0,n+1):
    for j in range(0,n-i+1):
        if 1000*(n-i-j)+5000*i+10000*j==y:
            print(j,i,n-i-j)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int NPrime=1000000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}

int n,m;

int main(){
	EnumeratePrime();
	while(1){
		cin>>n>>m;
		if(n==-1) break;
		vi b;
		for(int i=n+1;b.size()<m;i++){
			if(prime[i]) b.push_back(i);
		}
		vi c;
		for(int i=0;i<m;i++) for(int j=i;j<m;j++) c.push_back(b[i]+b[j]);
		sort(c.begin(),c.end());
		cout<<c[m-1]<<endl;
	}
}


Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
//ll dp[26][];
#define COMB_MAX (int)2e6 + 10
ll f[COMB_MAX], rf[COMB_MAX];
ll inv(ll x) {
	ll res = 1;
	ll k = mod - 2;
	ll y = x;
	while (k) {
		if (k & 1) res = (res * y) % mod;
		y = (y * y) % mod;
		k /= 2;
	}
	return res;
}
void init() {
	f[0] = 1;
	rep(i, 1, COMB_MAX) f[i] = (f[i - 1] * i) % mod;
	rep(i, 0, COMB_MAX) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
	if (k<0 || k>n || n < 0)return 0;
	ll a = f[n]; // = n!
	ll b = rf[n - k]; // = (n-k)!
	ll c = rf[k]; // = k!

	ll bc = (b * c) % mod;

	return (a * bc) % mod;
}
int main(void) {
	int k;
	string s;
	cin >> k >> s;
	ll ans = 0, len = s.size();
	init();
	rep(i, 0, k + 1) {
		ans += C(i + len - 1, len - 1) * mpower(25, i) % mod * mpower(26, k - i) % mod;
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 35652
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define ub upper_bound
#define pp push_back
#define ep emplace_back
#define all(v) (v).begin(),(v).end()
#define szz(v) ((int)(v).size())
#define psm partial_sum
#define acm accumulate
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long; using lf = long double;
using pii = pair<int,int>; using ppi = pair<int,pii>;
using pss = pair<short,short>; using pll = pair<ll,ll>;
const lf PI = 3.14159265358979323846264338L;
template <typename T>
inline T umax(T& u, T v){return u = max(u, v);}
template <typename T>
inline T umin(T& u, T v){return u = min(u, v);}

int n, a[100005];
map<int,int> M;

int main(){
    fio;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        M[ a[i] ] ++;
    }
    sort(a, a+n);
    int u = unique(a, a+n) - a;
    switch(u){
        case 1:
        cout << (a[0] == 0 ? "Yes" : "No") << '\n';
        break;
        case 2:
        cout << (a[0] == 0 && (M[0] * 2 == M[a[1]]) ? "Yes" : "No") << '\n';
        break;
        case 3:
        cout << (n % 3 == 0 && (a[0] ^ a[1]) == a[2] && M[a[0]] == M[a[1]] && M[a[1]] == M[a[2]] ? "Yes" : "No") << '\n';
        break;
        default:
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 4224
w,h,x,y=map(int,input().split())
ans=[w*h/2]
if (x==0 and y==0) or (x==0 and y==h) or (x==w and y==0) or (x==w and y==h):
    ans.append(0)
elif y*w==x*h or y*h==x*w:
    ans.append(1)
else:ans.append(0)
print(*ans)


Measured memory_bytes: 38768
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



string str;
map<char,int> ma;

vector<int> even, odd;

const int MAX_C = 100;
long long Com[MAX_C][MAX_C];

void calc_com() {
    memset(Com, 0, sizeof(Com));
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i) {
        Com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j) {
            Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]);
        }
    }
}

long long calc(vector<int> vec) {
    int tot = 0;
    for (int i = 0; i < vec.size(); ++i) tot += vec[i];
    long long res = 1;
    for (int i = 0; i < vec.size(); ++i) {
        (res *= Com[tot][vec[i]]);
        tot -= vec[i];
    }
    return res;
}

long long solve() {
    int n = str.size();
    ma.clear();
    for (int i = 0; i < n; ++i) ma[str[i]]++;
    even.clear(); odd.clear();
    
    EACH(it, ma) {
        if (it->second & 1) odd.PB(it->second);
        else even.PB(it->second);
    }
    
    if (n & 1) {
        if (odd.size() != 1) return 0;
        even.PB(odd[0]-1);
    }
    else {
        if (odd.size() != 0) return 0;
    }
    
    for (int i = 0; i < even.size(); ++i) even[i] /= 2;
    
    return calc(even);
}

int main() {
    calc_com();
    while (cin >> str) {
        cout << solve() << endl;
    }
    
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define modp(x, y) (((y) + (x) % (y)) % (y))
template<typename T> inline T gcd(T x, T y) { if(x < y) swap(x, y); T mod = x % y; if(mod == 0) return y; return gcd(y, mod); }
template<typename T> inline T lmc(T x, T y) { return x / gcd(x, y) * y; }

int main(int argc, char* argv[])
{
	string S;
	cin >> S;
	if(S == "AKIHABARA" || S == "KIHABARA" || S == "AKIHBARA" || S == "KIHBARA" || S == "AKIHABRA" || S == "KIHABRA" || S == "AKIHBRA" || S == "KIHBRA" ||
		S == "AKIHABAR" || S == "KIHABAR" || S == "AKIHBAR" || S == "KIHBAR" || S == "AKIHABR" || S == "KIHABR" || S == "AKIHBR" || S == "KIHBR")
		printf("YES\n");
	else printf("NO\n");

	return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define upper(n,m) (n+m-1)/m
#define rounding(n) (int)((double)n+0.5)

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define ALL(a) a.begin(),a.end()

#define coutALL(i,a) {int i=0;for(auto e:a) cout<<(i++?" ":"")<<e.se; cout<<endl;}
#define coutYN(a) cout<<(a?"Yes":"No")<<endl;
#define coutyn(a) cout<<(a?"yes":"no")<<endl;

#define deb cout<<"debug"<<endl
#define debn(n) cout<<"debug: "<<n<<endl

const int INF=INT_MAX;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
//const int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using namespace std;

//typedef pair<int,int> P;
typedef long long LL;

typedef pair<int,int> P;

int partition(vector <P> &a,int p,int r){

  int x=a[r].fi;
  int i=p-1;

  REAP(j,p,r){

    if(a[j].fi<=x){

      i++;
      swap(a[i],a[j]);

    }

  }

  swap(a[i+1],a[r]);

  return i+1;

}

void quicksort(vector <P> &a,int p,int r){

  if(p<r){

    int q=partition(a,p,r);
    quicksort(a,p,q-1);
    quicksort(a,q+1,r);

  }

}

signed main(){

  ios::sync_with_stdio(false);

  int n;
  cin>>n;

  vector <P> a(n),b;
  vector <char> c(n);
  vector <int> num(n);

  REP(i,n){

    cin>>c[i]>>num[i];

    a[i]=mp(num[i],i);

  }

  b=a;
  quicksort(a,0,n-1);
  stable_sort(ALL(b));

  cout<<(a!=b?"Not stable":"Stable")<<endl;

  for(P e:a) cout<<c[e.se]<<" "<<e.fi<<endl;

  return 0;

}


Measured memory_bytes: 5612
import java.util.*;

class Main{

    int w, h;
    char[][] map;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            w = sc.nextInt(); h = sc.nextInt();
            if(w==0 && h==0) break;

            map = new char[h][w];
            int sx = 0, sy = 0;
            for(int i=0; i<h; i++){
                map[i] = sc.next().toCharArray();
                for(int j=0; j<w; j++){
                    if(map[i][j]=='@'){ sx = j; sy = i;}
                }
            }

            System.out.println(bfs(sx, sy));
        }
    }

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

    int bfs(int sx, int sy){
        LinkedList<int[]> q = new LinkedList<int[]>();
        q.add(new int[]{sx, sy});
        boolean[][] v = new boolean[h][w];
        int cnt = 0;

        while(q.size()>0){
            int[] qq = q.poll();
            int x = qq[0], y = qq[1];

            if(v[y][x]) continue;
            v[y][x] = true;
            cnt++;

            for(int i=0; i<4; i++){
                int nx = x + dx[i], ny = y + dy[i];
                if(nx<0 || nx>=w || ny<0 || ny>=h || map[ny][nx]=='#') continue;
                q.add(new int[]{nx, ny});
            }
        }
        return cnt;
    }

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

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

int f(int n) {
  while (n > 9) n /= 10;
  return n;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> V(10, vector<int>(10));
  for (int i = 1; i <= N; i++) V.at(f(i)).at(i % 10)++;
  int sum = 0;
  for (int i = 1; i <= N; i++) sum += V.at(i % 10).at(f(i));
  cout << sum << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;

int main(){
    int n, m, c;
    cin>>n>>m>>c;
    int b[30], ans=0;
    for(int i=0; i<m; i++) cin>>b[i];
    for(int i=0; i<n; i++){
        int sum=0;
        int a[30];
        for(int j=0; j<m; j++){
            cin>>a[j];
            sum+=a[j]*b[j];
        }
        if(sum+c>0)ans++;
        
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n];
  int sum=0;
  for(int i=0;i<n;i++)
  {
    
    cin>>arr[i];
    sum=sum+arr[i];
  }
  sum=sum/n;
  int sum1,sum2;
  sum1=sum;
  sum2=sum1+1;
  int tot1=0;
  int tot2=0;
  for(int i=0;i<n;i++)
  {
    tot1=tot1+(arr[i]-sum1)*(arr[i]-sum1);
    tot2=tot2+(arr[i]-sum2)*(arr[i]-sum2);
    
  }
  int ans=min(tot1,tot2);
  cout<<ans<<endl;
    
    
    
  
  
  
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;

  int w = 0, b = 0;
  for (int i=0; i<N; i++) {
    if (S[i] == '.') w++;
    if (S[i] == '#') b++;
  }

  vector<int> cn(N);
  if (S[0] == '.') {
    cn[0] = 1;
  } else {
    cn[0] = 0;
  }
  for (int i=1; i<N; i++) {
    if (S[i] == '.') {
      cn[i] = cn[i-1] + 1;
    } else {
      cn[i] = cn[i-1];
    }
  }

  int t = 1000000;
  for (int i=0; i<N; i++) {
    int t1 = cn[N-1] - cn[i];
    int t2 = (i+1) - cn[i];
    t = min(t, t1+t2);
  }

  cout << min({w, b, t}) << endl;

  return 0;
}


Measured memory_bytes: 1412
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int R;
	scanf("%d",&R);

	if(R < 1200){

		printf("ABC\n");

	}else if(R < 2800){

		printf("ARC\n");

	}else{

		printf("AGC\n");
	}

	return 0;
}


Measured memory_bytes: 3728
import math
N,D = map(int,input().split())

def keisan(x,y):
    a = math.sqrt((x**2)+(y**2))
    return a

j = 0

for i in range(N):
    x,y = map(int,input().split())
    if keisan(x,y) <= D:
        j += 1

print(j)




Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
int main (){
  int i,q,cm=0,flag=0,f;
  string s;
  char c;
  cin>>s>>q;
  for(i=0;i<q;i++){
    cin>>cm;
    if(cm==1){
      flag++;
    }
    else{
      cin>>f>>c;
      if((flag+f)%2==1){
        s.insert(s.begin(),c);
      }
      else{
        s.insert(s.end(),c);
      }
    }
  }
  if(flag%2==1){
    reverse(s.begin(),s.end());
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 900
n = int(input())
a = list(map(int, input().split()))

f = [0 for i in range(10**6+5)]
for x in a:
    f[x] += 1
for i in range(1, len(f)):
    if f[i] == 0:
        continue
    for j in range(2*i, len(f), i):
        f[j] = 0
ans = 0
for v in f:
    if v == 1:
        ans += 1
print(ans)


Measured memory_bytes: 32232
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
c=0
for i in a:
    if i < 0:
        c+=1

b = [abs(i) for i in a]

if c%2 == 0:
    print(sum(b))
    exit()

b.sort()
print(sum(b)-2*b[0])

Measured memory_bytes: 15180
import numpy as np
n,m,X = map(int,input().split())
list_input = []
for x in range(n):
  list_input.append(list(map(int,input().split())))
List = []
List_array = []
for x in list_input:
  List.append(x[0])
  List_array.append(x[1:])
a = np.array(List_array)
List_ans = []
for i in range(2**n):
  s = 0
  t = np.array([0]*m)
  for j in range(n):
    if (i>>j)&1 == 1:
      s += List[j]
      t += a[j]
  if min(t) >= X:
    List_ans.append(s)

if len(List_ans)==0:
  print(-1)
else:
  print(min(List_ans))

Measured memory_bytes: 27304
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];


int main () {
    int N;
    cin >> N ;

    vector<int>zyosi(N);

    for(int i=2;i <=N; i++){
        int a;
        cin >>a;
        zyosi[a-1] +=1;
    }

    rep(i,N){
        cout << zyosi[i] << endl;
    }
}

Measured memory_bytes: 3988
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    long long int a, b, k;
    std::cin >> a >> b >> k;
    
    if(k<=a) std::cout << a-k << " " << b << std::endl;
    else if(a<k && k<=a+b) std::cout << 0 << " " << b - (k-a) << std::endl; 
    else std::cout << "0 0\n";
    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};

struct HashData {
	int h1, h2;
	bool operator==(const HashData& rhs) const {
		return h1 == rhs.h1 && h2 == rhs.h2;
	}
	bool operator!=(const HashData& rhs) const { return !(*this == rhs); }
};

class RollingHash {
	template<const int B, const int M>
	class RollingHashPart {
	private:
		size_t len;
		vector<int> pow_b, hash;
	public:
		RollingHashPart() {}
		template<typename T>
		RollingHashPart(const T& s) : len(s.size()), pow_b(s.size() + 1), hash(s.size() + 1) {
			pow_b[0] = 1;
			hash[0] = 0;
			for (int i = 0; i < len; i++) {
				pow_b[i + 1] = (ll)pow_b[i] * B % M;
				hash[i + 1] = ((ll)hash[i] * B + s[i]) % M;
			}
		}
		// [l, r)
		int get(int l, int r) const {
			int res = (hash[r] - (ll)hash[l] * pow_b[r - l]) % M;
			if (res < 0) res += M;
			return res;
		}
	};
public:
	RollingHashPart<1033, 1000000007> rh1;
	RollingHashPart<6037, 999999937> rh2;
 
	RollingHash() {}
	template<typename T> RollingHash(const T & s) : rh1(s), rh2(s) {}
	// [l, r)
	HashData get(int l, int r) const {
		return (HashData){ rh1.get(l, r), rh2.get(l, r) };
	}

	lpair getPair(int l, int r) const {
		return make_pair(rh1.get(l,r) , rh2.get(l, r));
	}
	// [l1, r1), [l2, r2)
	int lcp(const RollingHash & rhs, int l1, int r1, int l2, int r2) const {
		int lb = 0, ub = std::min(r1 - l1, r2 - l2) + 1;
		while (ub - lb > 1) {
			int md = (lb + ub) >> 1;
			(get(l1, l1 + md) == rhs.get(l2, l2 + md) ? lb : ub) = md;
		}
		return lb;
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    RollingHash r(S);
    ll lv = 0, rv = N+1;
    while(rv - lv > 1){
        ll mid = (rv + lv) / 2;
        bool ok = false;
        rep(i,0,N){
            rep(j,i+1,N){
                if(j - i < mid) continue;
                if(j+mid-1 >= N) continue;
                if(r.getPair(i, i+mid) == r.getPair(j, j+mid)){
                    ok = true;
                    break;
                }
            }
            if(ok) break;
        }
        if(ok){
            lv = mid;
        }else{
            rv = mid;
        }
    }
    print(lv);


    
}


Measured memory_bytes: 384
import java.util.*;

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

    String s = sc.next();
    String[] sArray = s.split("");
    List<String> acgt = Arrays.asList("A", "C", "G", "T");

    int count = 0;
    int maxCount = 0;
    for (int i = 0; i < s.length() ; i++ ) {
      if (acgt.contains(sArray[i])) {
        count++;
        if (count > maxCount) {
          maxCount = count;
        }
      } else {
        count = 0;
      }
    }

    System.out.println(maxCount);
  }
}


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

int main()
{
    int n; cin>>n;
    // int dp[n][3];
    vector<vector<int>> dp(n+1,vector<int>(3,0));
    
    for(int i=0;i<n;i++){
        vector<int> tmp(3);
        for(int j=0;j<3;j++)
            cin>>tmp[j];
        
        for(int k=0;k<3;k++){
            for(int l=0;l<3;l++){
                if(k!=l){
                    dp[i+1][l] = max(dp[i+1][l], dp[i][k]+tmp[l]);
                }
            }
        }
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]});
    return 0;
}

Measured memory_bytes: 5760