akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n, k;
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> k >> n;
	if(k & 1) {
		std::vector<int> v;
		rep(i, 1, n) v.push_back(k / 2 + 1);
		for(int i = 1;i <= n / 2;++i) {
			if(v.size() < n) {
				if(--v.back() <= 0) v.pop_back();
				else for(;v.size() < n;) v.push_back(k);
			} else {
				if(--v.back() <= 0) v.pop_back();
			}
		}
		for(int i : v) {
			cout << i << ' ';
		}
	} else {
		cout << k / 2 << ' ';
		rep(i, 2, n) cout << k << ' ';
	}
}


Measured memory_bytes: 3568
package main

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

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	s := eGetLine(scanner)
	if n%2 == 1 {
		fmt.Println("No")
	} else {
		if s[:len(s)/2] == s[len(s)/2:] {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


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

long long int height_(vector < long long int> &height, vector <int> &h)
{
    int i;
    for(i = 2; i < h.size(); i++)
    {
        height[i]  = min((abs(h[i] - h[i - 2]) + height[i - 2]), (abs(h[i] - h[i- 1]) + height[i - 1]));
    }
    return height.back();

}

int main()
{
    int n;
    cin >> n;
    vector <int> h(n);
    for(int i = 0; i < n; i++)
        cin >> h[i];
    
    vector <long long int> height(n);
    height[0] = 0;
    height[1] = llabs(h[1] -h[0]);
    cout << height_(height, h) << endl;
    

    
    

}


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

int main(void){
  int n,max,max_id,id,i;

  cin >> n;

  int *h = new int[n];


  priority_queue<int> que;

  for(i=0;i<n;i++){
    cin >> h[i];
  }

  max=0;
  max_id=0;
  id=0;

  max=h[0];

  for(i=1;i<n;i++){
    if(max>=h[i]){
      id=id+1;
      max = h[i];
      if(max_id<id){
        max_id=id;
      }
    }else{
      max = h[i];
      id=0;
    }
  }

  cout << max_id << "\n";

  delete[] h;
  return 0;

}


Measured memory_bytes: 640
class UnionFind:
    def __init__(self, N):
        self.parent = [-1] * N  

    def findset(self, A):  
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.findset(self.parent[A])  
        return self.parent[A]

    def size(self, A):  
        return -self.parent[self.findset(A)]

    def unite(self, A, B):
        A = self.findset(A)
        B = self.findset(B)

        if (A == B):
            return False

        if (self.size(A) < self.size(B)):
            A, B = B, A

        self.parent[A] += self.parent[B]  
        self.parent[B] = A  

        return True

    def is_in_same(self, A, B):
        return self.findset(A) == self.findset(B)


N, Q = map(int, input().split())
ds = UnionFind(N)
for q in range(Q):
    com, x, y = map(int, input().split())
    if com == 0:
        ds.unite(x, y)
    elif com == 1:

        print(1 if ds.is_in_same(x, y) else 0)






Measured memory_bytes: 5720
n = int(input())
string = input().strip()
r = string.count('R')
g = string.count('G')
h = string.count('B')

ans = r * g * h

if ans == 0:
    print(ans)
else:
    for i in range(n):
        j = 1
        while i + 2 * j < n:
            if string[i] != string[i + j] and string[i + j] != string[i + 2*j] and string[i] != string[i+2*j]:
                ans -= 1
            j += 1
    print(ans)


Measured memory_bytes: 73312
#include <algorithm>
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const auto INF = static_cast<ll>(1e15);
const auto MOD = static_cast<ll>(1e9 + 7);

/*********** Variables ***********/
ll N, K;
ll fac[2001], finv[2001], inv[2001];

/*********** Functions ***********/
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 2001; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll comb(ll n, ll r) {
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

int main() {
    COMinit();
    cin >> N >> K;
    for (int i = 1; i <= K; i++) {
        ll ret = comb(K - 1, i - 1);
        ret *= comb(N - K + 1, i) % MOD;
        cout << ret % MOD << endl;
    }
    return 0;
}


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

using namespace std;

int main() {
    int n, x, y; cin >> n >> x >> y;
    int last1, last2;
    for (int i = 0; i < n; i++)
        last1 = last2, cin >> last2;
    if (n == 1) cout << abs(last2 - y);
    else cout << max(abs(last2 - y), abs(last1 - last2));
}

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

int main(void){
    int n,count = 0;
    cin >> n;
    vector<int> d(n);
    int num[100] = {0};
    for(int i = 0;i < n;i++)cin >> d[i];
    for(int i = 0;i < n;i++)num[d[i]]++;

    for(int i = 0;i <= 100;i++)if(num[i] > 0)count++;
    cout << count << endl;
}

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

using namespace std;

int main() {
  string s,t;

  cin >> s >> t;

  bool ok = false;
  int k = 0;
  for(int i = 0; i < s.size(); i++) {
    int j = 0;
    for(; (j < t.size() && j + k < s.size()); j++) {
      if(s[j+i] != '?' && s[j+i] != t[j]) break;
    }
    if(j == t.size()) {k = i; ok = true;}
  }
  if(ok) {
    for(int i = 0; i < s.size(); i++) {
      if(k == i) {
	cout << t;
	i += t.size()-1;
	
	continue;
      }
      if(s[i] == '?') cout << 'a';
      else cout << s[i];
    }
    cout << endl;
  }
  else cout << "UNRESTORABLE" << endl;
}
      


Measured memory_bytes: 384
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
int main() {
	int A, P;
	cin >> A >> P;
	cout << (A * 3 + P) / 2 << endl;
}

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

int main() {
  int H,N;
  cin >> H >> N;
  
  int sum = 0;
  vector<int> Raccon(N);
  for(int i=0;i<N;i++){
    cin >> Raccon.at(i);
    sum += Raccon.at(i);
  }
  
  if(H > sum){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
 
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;

  int flag=0;
  string str="";

  rep(i,s.size()){
    char c;
    if(s.at(i)=='0') c = '0';
    if(s.at(i)=='1') c = '1';
    if(s.at(i)=='B'){
      if(str.size()==0) continue;
      str.pop_back();
      flag--;
    }else{
      str.push_back(c);
    }

  }

  cout << str << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    ll a, b;
    cin >> a >> b;
    cout << a / b << " " << a % b << " ";
    cout << fixed << setprecision(10) << ld(a) / ld(b) << endl;
}



Measured memory_bytes: 3300
#include <stdio.h>
#include <string.h>
int main()
{
    char s[110],t[110];
    while(~scanf("%s%s",&s,&t))
    {
        int l,i,j,temp=0;

        l=strlen(s);
        for(i=0;i<l;i++)
        {
            char w=s[l-1];
            for(j=l-1;j>0;j--)
            {

                s[j]=s[j-1];

            }
            s[0]=w;
           if(strcmp(s,t)==0)
            temp=1;



        }
        if(temp==1)
            printf("Yes\n");
        else
            printf("No\n");


    }

    return 0;
}



Measured memory_bytes: 128
#include<stdio.h>
n,i,a,b,r,l;int main(){for(;scanf("%d",&n),n;){for(r=-1;n--;){scanf("%d%d%d",&i,&a,&b);r<a+b?(l=i,r=a+b):0;}printf("%d %d\n",l,r);}return 0;}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int count_prefix(const std::vector<std::string>& words, std::string& target) {
	const auto lower = std::lower_bound(std::begin(words), std::end(words), target);
	target.push_back('z' + 1);
	const auto upper = std::upper_bound(std::begin(words), std::end(words), target);
	target.pop_back();
	return std::distance(lower, upper);
}
int count_word(const std::vector<std::string>& words, const std::string& target) {
	return std::binary_search(words.begin(), words.end(), target) ? 1 : 0;
}
int main() {
	int n, m; std::cin >> n >> m;
	std::vector<std::string> words(n), rev_words(n);
	for (auto& w : words) std::cin >> w;
	std::transform(words.begin(), words.end(), rev_words.begin(), [](const std::string& str) {return std::string(str.rbegin(), str.rend()); });
	std::sort(words.begin(), words.end());
	std::sort(rev_words.begin(), rev_words.end());
	{
		std::string slate;
		for (auto _i = 0; _i < m; ++_i) {
			std::cin >> slate;
			if (slate.front() == '*') {
				std::reverse(slate.begin(), slate.end());
				slate.pop_back();
				auto q = slate.find('?');
				if (q == std::string::npos) {
					std::cout << count_prefix(rev_words, slate) << '\n';
				}
				else {
					int count = 0;
					for (auto c = 'a'; c <= 'z'; ++c) {
						slate[q] = c;
						count += count_prefix(rev_words, slate);
					}
					std::cout << count << '\n';
				}
			}
			else if (slate.back() == '*') {
				slate.pop_back();
				auto q = slate.find('?');
				if (q == std::string::npos) {
					std::cout << count_prefix(words, slate) << '\n';
				}
				else {
					int count = 0;
					for (auto c = 'a'; c <= 'z'; ++c) {
						slate[q] = c;
						count += count_prefix(words, slate);
					}
					std::cout << count << '\n';
				}
			}
			else {
				auto q = slate.find('?');
				if (q == std::string::npos) {
					std::cout << count_word(words, slate) << '\n';
				}
				else {
					int count = 0;
					for (auto c = 'a'; c <= 'z'; ++c) {
						slate[q] = c;
						count += count_word(words, slate);
					}
					std::cout << count << '\n';
				}
			}
		}
	}
}


Measured memory_bytes: 11852
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws java.io.IOException {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            int R = Integer.parseInt(s);
            if (R < 1200) {
                System.out.println("ABC");
            } else if (R < 2800) {
                System.out.println("ARC");
            } else {
                System.out.println("AGC");
            }
        }
    }
}


Measured memory_bytes: 23124
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

type node struct {
	num    int
	parent *node
	left   *node
	right  *node
}

func printPreOrder(n *node) {
	if n == nil {
		return
	}
	fmt.Printf(" %d", n.num)
	printPreOrder(n.left)
	printPreOrder(n.right)
}
func printInOrder(n *node) {
	if n == nil {
		return
	}
	printInOrder(n.left)
	fmt.Printf(" %d", n.num)
	printInOrder(n.right)
}
func printPostOrder(n *node) {
	if n == nil {
		return
	}
	printPostOrder(n.left)
	printPostOrder(n.right)
	fmt.Printf(" %d", n.num)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := eGetInt(reader)
	nodes := make([]node, n)
	for i := 0; i < n; i++ {
		infos := strings.Fields(eGetline(reader))
		num, left, right := eAtois3(infos)
		c := &nodes[num]
		c.num = num
		if left != -1 {
			c.left = &nodes[left]
			c.left.parent = c
		}
		if right != -1 {
			c.right = &nodes[right]
			c.right.parent = c
		}
	}
	// rootを見つける
	var root *node
	for i := 0; i < n; i++ {
		if nodes[i].parent == nil {
			root = &nodes[i]
		}
	}
	fmt.Println("Preorder")
	printPreOrder(root)
	fmt.Printf("\nInorder\n")
	printInOrder(root)
	fmt.Printf("\nPostorder\n")
	printPostOrder(root)
	fmt.Println("")
}
func eGetInt(reader *bufio.Reader) int {
	return eAtoi(eGetline(reader))
}

func eGetline(o *bufio.Reader) string {
	s, err := o.ReadString(byte('\n'))
	if err != nil {
		if err == io.EOF {
			return s
		}
		log.Fatal(err.Error())
	}
	return s[:len(s)-1]
}
func eAtoi(s string) int {
	v, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err.Error())
	}
	return v
}

func eAtois3(s []string) (int, int, int) {
	return eAtoi(s[0]), eAtoi(s[1]), eAtoi(s[2])
}



Measured memory_bytes: 1144
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 
#define sq(a) ((a)*(a))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	double a, b, c, d;
	while(scanf("%lf%lf%lf%lf", &a, &b, &c, &d), a!=-1.0&&b!=-1.0&&c!=-1.0&&d!=-1.0){
		a *= M_PI / 180.0;
		b *= M_PI / 180.0;
		c *= M_PI / 180.0;
		d *= M_PI / 180.0;
		printf("%d\n", (int)(6378.1*acos(cos(a)*cos(b)*cos(c)*cos(d)+sin(a)*sin(c)+cos(a)*sin(b)*cos(c)*sin(d))+0.5));
	}
}

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

using namespace std;

#define ll long long

const ll mod  = 1e9 + 7;
const ll INF = 1e14;

const double pi = 3.141592653589793238;

void solve(){

    double a, b, h, m; cin >> a >> b >> h >> m;

    double theta = (2 * pi * 11.0 / 12.0) * (h + m / 60.0);

    double res = powf128(a*a + b*b - 2*a*b*cosf128(theta), 0.5);

    cout << res;

}


//2pi(1 - 1/12)

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

    cout << setprecision(10);
    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

	return 0;
}



Measured memory_bytes: 4356
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    ll a,b,c; cin >> a >> b >> c;
    if(a==b && b==c){
        if(a%2==0){
            cout << -1 << endl;
        }else{
            cout << 0 << endl;
        }
        return 0;
    }
    ll out=0;
    while(a%2==0 && b%2==0 && c%2==0){
        ll x=a+b;
        ll y=b+c;
        ll z=a+c;
        a=y/2;
        b=z/2;
        c=x/2;
        cerr << a << " " << b << " " << c << endl;
        out++;
    }
    cout << out << endl;
    return 0;
}


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

using namespace std;

const int mxk = 1e5 + 10;

int n, a[mxk];
bool lose = 0;

int main() {
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
    sort(a + 1, a + n + 1, greater<int>());
    for(int i = 1; i <= n; ++i)
        if (i + 1 > a[i + 1]) {
            int j = 0;
            while(a[j + i + 1] == i) 
				++j;
            if (((a[i] - i) & 1) || (j & 1))
				cout << "First" << endl;
            else 
				cout << "Second" << endl;
            break;
        }
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int p,q,r;
    scanf("%d%d%d",&p,&q,&r);
    int a,b,c;
    a=p+q;b=p+r;c=q+r;
    if(a>b)
        a=b;
    if(a>c)
        a=c;
    printf("%d\n",a);
}


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

int64_t Q=998244353;

int main(){
  int N,S;
  cin>>N>>S;
  vector<vector<int64_t>> dp(N+1,vector<int64_t>(3000+1));
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  dp[1][0]=1,dp[1][p[0]]=1;
  for(int i=1;i<N;i++){
    for(int j=0;j<=S;j++){
      dp[i+1][j]=(Q+dp[i][j]-dp[i-1][j])%Q;
    }
    for(int j=S;j>=p[i];j--){
      dp[i+1][j]+=dp[i+1][j-p[i]];
      dp[i+1][j]%=Q;
    }
    for(int j=0;j<=S;j++){
      dp[i+1][j]+=dp[i][j];
      dp[i+1][j]%=Q;
    }
    dp[i+1][0]++,dp[i+1][p[i]]++;
  }
  cout<<dp[N][S]<<endl;
}

Measured memory_bytes: 73660
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int ans;
vector<Int> X, Y;
void solve(vector<Int> A){ //長さ2
    if(A[0] - A[1] < A[1] - A[0]){
      ans = A[1] - A[0];
      X.push_back(A[1]), Y.push_back(A[0]);
    }
    else{
      ans = A[0] - A[1];
      X.push_back(A[0]), Y.push_back(A[1]);
    }
}


void solve2(vector<Int> A){ //すべてA[i]<=0
  Int N = A.size();
  reverse(A.begin(), A.end());

  for(Int i=0;i<N - 1;i++){
    X.push_back(A[0]), Y.push_back(A.back());
    A[0] -= A.back();
    A.pop_back();
  };
  ans = A[0];
  
}

void solve3(vector<Int> A){ //すべてA[i]>=0
  Int N = A.size();
  for(Int i=0;i<N-2;i++){
    X.push_back(A[0]), Y.push_back(A[i+1]);
    A[0] -= A[i+1];
  }
  X.push_back(A[N-1]), Y.push_back(A[0]);
  A[N-1] -= A[0];
  ans = A[N-1];
}

void solve4(vector<Int> A){
  const Int N = A.size();
  vector<Int> tmp;
  map<Int,Int> used;
  for(Int i=0;i<N-1;i++){
    if(A[i] >= 0){
      X.push_back(A[0]), Y.push_back(A[i]);
      A[0] -= A[i];
      used[i] = 1;
    }
  }
  
  for(Int i=0;i<N-1;i++){
    if(used[i]) continue;
    X.push_back(A[N-1]), Y.push_back(A[i]);
    A[N-1] -= A[i];
  }
  ans = A[N-1];
}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<Int> A(N);
  cin>>A;
  sort(A.begin(), A.end());

  if(A.size() == 2) solve(A);
  else if(A.back() <= 0) solve2(A);
  else if(A[0] >= 0)solve3(A);
  else solve4(A);
  cout<<ans<<endl;
  for(Int i=0;i<N-1;i++) cout<<X[i]<<" "<<Y[i]<<endl;
  
  return 0;
}


Measured memory_bytes: 10456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  string s;
  cin >> s;
  int n=s.size();
  cout << s.at(0)+to_string(n-2)+s.at(n-1) << endl;
}

Measured memory_bytes: 3680
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
long d[1<<17];
vector<pair<int,int> >G[1<<17];
main()
{
	int n;cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;long c;cin>>a>>b>>c;
		G[a].push_back(make_pair(b,c));
		G[b].push_back(make_pair(a,c));
	}
	for(int i=0;i++<n;)d[i]=1e15;
	int q,k;cin>>q>>k;
	d[k]=0;
	queue<int>P;
	P.push(k);
	while(!P.empty())
	{
		int u=P.front();P.pop();
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].first;
			if(d[u]+G[u][i].second<d[v])
			{
				d[v]=d[u]+G[u][i].second;
				P.push(v);
			}
		}
	}
	for(int i=0;i<q;i++)
	{
		int x,y;cin>>x>>y;
		cout<<d[x]+d[y]<<endl;
	}
}

Measured memory_bytes: 9716
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str):
    if S.count('hi') == len(S)/2:
        print(YES)
    else:
        print(NO)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

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

		String[] S = sc.nextLine().split(" ");
		int n = Integer.parseInt(S[0]);
		int quantum = Integer.parseInt(S[1]);

		Queue<Node> queue = new ArrayDeque<Node>();

		for (int i = 0; i < n; i++) {
			S = sc.nextLine().split(" ");
			Node node = new Node(S[0], Integer.parseInt(S[1]));
			queue.offer(node);
		}

		long count = 0;

		while (!queue.isEmpty()) {
			Node tmp = queue.poll();
			if (tmp.getTime() > quantum) {
				count += quantum;
				tmp.setTime(tmp.getTime() - quantum);
				queue.offer(tmp);
			} else {
				count += tmp.getTime();
				System.out.printf("%s %d", tmp.getName(), count);
				System.out.println("");
			}
		}

		sc.close();
	}
}

class Node {
	private String name;
	private int time;

	public Node(String name, int time) {
		this.name = name;
		this.time = time;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public int getTime() {
		return this.time;
	}
}



Measured memory_bytes: 115812
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}


using namespace std;
int main(){   
   int a,b;
   cin>>a>>b;

   cout<<lcm(a,b);
   
   

   return 0;
}

Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var fac=[],finv=[],invs=[],pow2=[];
function fset(n){
  fac.length=n+1,fac[0]=fac[1]=1;
  for(var i=2;i<=n;)fac[i]=mul(fac[i-1],i++);
  finv.length=n+1,finv[0]=finv[1]=1,finv[n]=inv(fac[n]);
  for(i=n;2<i;)finv[i-1]=mul(finv[i],i--);
  //invs.length=n+1,invs[0]=invs[1]=1;
  //for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
  //pow2.length=n+1,pow2[0]=1;
  //for(i=1;i<=n;i++)pow2[i]=pow2[i-1]*2%mod;
}
function inv(b){for(var a=mod,u=0,v=1,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function ncr(n,r){return mul(fac[n],finv[r],finv[n-r]);}
function npr(n,r){return mul(fac[n],finv[n-r]);}
function mput(n){return (n%mod+mod)%mod;}

var tm = +(new Date()) + 1900;
var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var a1 = nextbig(), a2 = nextbig();
  var x = 0n;
  for(var i = 2; i < n; i++)x ^= nextbig();
  var ans = 0n, a = a1^a2^x;
  while(a){
    if(a1 === 1 || new Date() > tm)return -1;
    for(var i = 40; i >= 0; i--){
      var k = 1n << BigInt(i);
      if((a & k) === 0n)continue;
      var u;
      u = (a1 & (k-1n)) + 1n;
      u = min(u, k-(a2&(k-1n)) );
      if(u < a1){
        ans += u, a1 -= u, a2 += u;
        break;
      }else return -1;
    }
    a = a1^a2^x;
  }
  return ans;
}

function min(a,b){
  return a > b ? b : a;
}

Measured memory_bytes: 35544
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
//#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


		


int main(){
	string s;
	cin >> s;
	int ans = 0;
	rep(i,4){
		if(s[i]=='2'){
			ans++;
		}
	}
	cout<<ans<<endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> a,b;
  for(int i=0; i<m; i++) {
    int k; cin>>k;
    if(x>k) a.push_back(k);
    else b.push_back(k);
  }
  cout<<min(a.size(),b.size())<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define F first
#define S second
#define N 200005
using namespace std;

typedef long long ll;
ll n, ts, d, A, ans;
vector<ll> b, s;
pair<ll, ll> a[N];

ll g(ll p, ll q) {
	ll u = p / q;
	if (p % q) u++;
	return u;
}
int main()
{
	ll i, j, t, num, e;
	cin >> n >> d >> A;
	for (i = 0; i < n; i++) {
		scanf ("%lld %lld", &a[i].F, &a[i].S);
	}
	sort(a, a + n);
	for (i = 0; i < n; i++) {
		num = 0;
		if (!b.empty()) {
			t = lower_bound(b.begin(),b.end(), a[i].F - d) - b.begin();
			if (t > 0) num = s[t - 1];
		}
		a[i].S -= (ts - num);
		if (a[i].S > 0) {
            e = g(a[i].S, A);
            ans += e;
            b.push_back(a[i].F + d);
            ts += e * A;
            s.push_back(ts);
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
    string a,b;
    cin>>a>>b;
    int c = stoi(a+b);
    int i = sqrt(c);
    if(i*i==c) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> t;
    if(t<1200) cout << "ABC";
    else if(t<2800) cout << "ARC";
    else cout << "AGC";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
while(1){

 int a, b, i;
 char op;

 scanf("%d %c %d", &a, &op, &b);

 switch( op ){

 case '+' : 
 printf("%d\n", a + b);
 break;
 case '-' : 
 printf("%d\n", a - b);
 break;
 case '*' : 
 printf("%d\n", a * b);
 break;
 case '/' : 
 printf("%d\n", a / b);
 break;
 case '?' : 
 return 0;
 break;

 }
}
 return 0;
}

Measured memory_bytes: 1828
def dfs(s):
    visited[s]=1
    for v in adj[s]:
        if v not in visited:
            if (s,v) in we:
                y[v]=y[s]+we[(s,v)]
            elif (v,s) in we:
                y[v]=y[s]+we[(v,s)]
            dfs(v)
import sys
sys.setrecursionlimit(10**5)
n=int(input())
adj={}
we={}
visited={}
y=[0]*(n+1)
for q in range(n-1):
    a,b,w=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
    we[(a,b)]=w
if n>1:
    dfs(1)
for i in range(1,n+1):
    if y[i]%2==0:
        print(0)
    else:
        print(1)

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

ret = 0
for x in range(1, n + 1, 2):
    t = 1
    for i in range(2, x + 1):
        k = 0
        while x % i == 0:
            k += 1
            x //= i
        t *= k + 1
        if x == 1:
            break

    if t == 8:
        ret += 1

print(ret)


Measured memory_bytes: 2940
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
A_under = [A[i] for i in range(M) if A[i] < X]
A_upper = [A[i] for i in range(M) if A[i] > X]
print(min(len(A_under),len(A_upper)))

Measured memory_bytes: 3316
#include <stdio.h>
int main(void){
  int x,a=0,b=0,i;
  scanf("%d",&x);
  while(a == 0){
    for(i=2;i<x;i++){
      if(x%i == 0){
        x=x+1; b=0;
        break;
      }
      else{
        b=b+1;
      }
    }
    if(b == x-2){
      printf("%d",x);
      return 0;
    }
  }
  return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;
bool isprime[MAX];

ll rui(ll a,ll b){
    if(b==1) return a%mod;
    else if(b==0) return 1;
    else if(b%2==0) return (rui(a,b/2)*rui(a,b/2))%mod;
    else return (rui(a,b-1)*a)%mod;
}

ll comb(ll a,ll b){
    ll ans=1;
    for(ll i=a;i>a-b;i--){
        ans=ans*i%mod;
    }
    for(ll i=1;i<=b;i++){
        ans=(ans*rui(i,mod-2))%mod;
    }
    return ans;
}

void eratos(int n){
    for(int i=0;i<n;i++){
        isprime[i]=1;
    }
    isprime[0]=0;
    isprime[1]=0;
    for(int i=2;i*i<=n;i++){
        if(isprime[i]){
            int j=i+i;
            while(j<=n){
                isprime[j]=0;
                j+=i;
            }
        }
    }
}

int main(){
    
    int N,M;cin>>N>>M;
    vector<int> pr;
    
    eratos(floor(sqrt(M))+1);
    
    for(int i=0;i<=floor(sqrt(M))+1;i++){
        if(isprime[i]) pr.push_back(i);
    }
    
    ll ans=1;
    for(int i=0;i<pr.size();i++){
        int cnt=0;
        while(M%pr[i]==0){
            M/=pr[i];
            cnt++;
        }
        ans*=comb(N+cnt-1,cnt);
        ans=ans%mod;
    }
    
    if(M!=1) ans=ans*N%mod;
    
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
map<int,int> mp;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		if (mp[x]) ans--;
		else ans++;
		mp[x]^=1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int h,n;
  cin>>h>>n;
  vector<Int> as(n),bs(n);
  for(Int i=0;i<n;i++) cin>>as[i]>>bs[i];

  const Int MAX = 1e4+10;
  const Int INF = 1e15;
  vector<Int> dp(MAX,INF);
  dp[0]=0;
  for(Int i=0;i<n;i++)
    for(Int j=0;j+as[i]<MAX;j++)
      chmin(dp[j+as[i]],dp[j]+bs[i]);

  for(Int i=MAX-1;i>0;i--) chmin(dp[i-1],dp[i]);
  cout<<dp[h]<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
vector<string>s(25);
int main()
{
    boost;
    ll n,i,j,x,t,m,y,u,v;
    cin>>n>>m;
    for(i=0;i<n;i++) cin>>s[i];
    ll d[25][25][25][25];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            for(x=0;x<n;x++){
                for(y=0;y<m;y++){
                    d[i][j][x][y]=inf;
                }
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            d[i][j][i][j]=0;
            if(i-1>=0&&s[i-1][j]=='.') d[i][j][i-1][j]=1;
            if(i+1<n&&s[i+1][j]=='.') d[i][j][i+1][j]=1;
            if(j-1>=0&&s[i][j-1]=='.') d[i][j][i][j-1]=1;
            if(j+1<m&&s[i][j+1]=='.') d[i][j][i][j+1]=1;
        }
    }
    for(u=0;u<n;u++){
        for(v=0;v<m;v++){
            for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                    for(x=0;x<n;x++){
                        for(y=0;y<m;y++){
                            if(s[i][j]=='.'&&s[x][y]=='.')
                            d[i][j][x][y]=min(d[i][j][x][y],d[i][j][u][v]+d[u][v][x][y]);
                        }
                    }
                }
            }
        }
    }
    ll ans=0;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            for(x=0;x<n;x++){
                for(y=0;y<m;y++){
                    if(s[i][j]=='.'&&s[x][y]=='.')ans=max(ans,d[i][j][x][y]);
                }
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3072
// https://atcoder.jp/contests/abc126/tasks/abc126_d

#include "algorithm"
#include "iostream"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

// f: node, s: length
V<VPL> edges;
VL colors;

void rec(ll u, ll p, ll c) {
  colors[u] = c;

  for (auto edge : edges[u]) {
    ll v = edge.first;
    ll l = edge.second;
    if (v == p) continue;

    ll nc = l % 2 == 0 ? c : 1 - c;
    rec(v, u, nc);
  }
}

void solve() {
  ll N;
  cin >> N;

  edges = V<VPL>(N, VPL());

  rep(i, N - 1) {
    ll u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    edges[u].emplace_back(v, w);
    edges[v].emplace_back(u, w);
  }

  // 一つの色を決め、再帰的に見て変が偶数であれば同じ色、奇数であれば違う色、としていくと、「任意の
  // 2 点間の距離が偶数 ⇒ 同じ色」「任意の 2 点間の距離が奇数 ⇒
  // 違う色」が実現され、後者の対偶より 「任意の 2 点が同じ色 ⇒
  // 距離が偶数」が実現されることとなる

  colors = VL(N, -1);

  rec(0, -1, 1);

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

VL dists;
void rec_to_fill_dist(ll u, ll p, ll d) {
  dists[u] = d;

  for (auto edge : edges[u]) {
    ll v = edge.first;
    ll l = edge.second;

    if (v == p) continue;

    rec_to_fill_dist(v, u, d + l);
  }
}

void solve2() {
  ll N;
  cin >> N;

  edges = V<VPL>(N, VPL());

  rep(i, N - 1) {
    ll u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    edges[u].emplace_back(v, w);
    edges[v].emplace_back(u, w);
  }

  // 適当に根を決め、根からの距離を d[i] とすると、 2 点間の距離は d[i] + d[j] -
  // 2*d[LCA] よってこの偶奇は d[i] と d[j] の偶奇で決定される
  // ここで、 d[i]
  // が偶数なら根と同じ色、奇数なら根と違う色を埋めるとすると、「任意の 2
  // 点について同じ色」 ⇔ 「2 点の d の偶奇が等しい」 ⇔ 「2 点の距離が偶数」
  // となる

  colors = VL(N);
  colors[0] = 1;

  dists = VL(N);
  rec_to_fill_dist(0, -1, 0);

  repf(u, 1, N) { colors[u] = dists[u] % 2 == 0 ? colors[0] : 1 - colors[0]; }

  rep(u, N) { cout << colors[u] << endl; }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 10752
#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    while(n>=500)
    {
        n-=500;
    }
    if(n!=0&&n>m)
    {
        printf("No");
        return 0;
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, k: usize,
        hv: [usize; n]
    };

    let res = hv.into_iter().filter(|&h| h >= k).count();
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

#define int long long
#define INF 1000000000000000000ll
#define rep(i,n) for(int i=1;i<=n;i++)
struct E {int to,cost;};
int n,m,x;
int h[100002];
vector<E> G[100002];
int D[100002];
int X[100002];

signed main(){
  cin>>n>>m>>x;
  rep(i,n)cin>>h[i];
  rep(i,m){
    int a,b,t;
    cin>>a>>b>>t;
    if(h[a]>=t)G[a].push_back({b,t});
    if(h[b]>=t)G[b].push_back({a,t});
  }
  rep(i,n)D[i]=INF;
  queue<int> que;
  que.push(1);
  D[1]=0;
  while(que.size()){
    int i=que.front();que.pop();
    for(E e : G[i]){
      int hi=D[i]<=x?x-D[i]:0;
      int k=0;
      if(hi-e.cost>h[e.to]){
        k=hi-e.cost-h[e.to];
      }else if(hi-e.cost<0){
        k=-(hi-e.cost);
      }
      if(D[i]+e.cost+k<D[e.to]){
        D[e.to]=D[i]+e.cost+k;
        que.push(e.to);
      }
    }
  }
  if(D[n]>=INF){
    cout<<-1<<endl;
    return 0;
  }
  int hn=D[n]<=x?x-D[n]:0;
  cout<<D[n]+abs(hn-h[n])<<endl;
  return 0;
}

Measured memory_bytes: 21696
#include <stdio.h>

int gcd(int a, int b) {                                                         
    if (a % b == 0) {                                                           
        return b;                                                               
    } else {                                                                    
        return gcd(b, a % b);                                                   
    }                                                                           
}

int main(void) {                                                                
    int a, b;                                                                   
    int g;                                                                      
    int l;                                                                      
                                                                                
    while (scanf("%d %d", &a, &b) != EOF) {                                     
        if (a > b) {                                                            
            g = gcd(a, b);                                                      
        } else {                                                                
            g = gcd(b, a);                                                      
        }                                                                       
        l = (a / g) * b;                                                        
        printf("%d %d\n", g, l);                                                
    }                                                                           
    return 0;                                                                   
}

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

using namespace std;

int const maxn = 1e5 + 5;
pair < int, int > a[maxn];
int dp[maxn];

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1, [](pair < int, int > x, pair < int, int > y) {
        return x.first + x.second < y.first + y.second;
    });
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1];
        int lef = 0, righ = i + 1;
        while (righ - lef > 1) {
            int mid = (righ + lef) / 2;
            if (a[i].first - a[i].second >= a[mid].first + a[mid].second) lef = mid;
            else righ = mid;
        }
        dp[i] = max(dp[i], dp[lef] + 1);
    }
    cout << dp[n];
    return 0;
}



Measured memory_bytes: 1408
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type ByRune []rune

func (r ByRune) Len() int {
	return len(r)
}

func (r ByRune) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func (r ByRune) Less(i, j int) bool {
	return r[i] < r[j]
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var n int
    fmt.Scan(&n)

	strMap := make(map[string]int)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		rs := []rune(s)
		sort.Sort(ByRune(rs))
		sSorted := string(rs)
		_, ok := strMap[sSorted]
		if ok {
			strMap[sSorted]++
		} else {
			strMap[sSorted] = 1
		}
	}

	ans := 0
	for _, v := range strMap {
		ans += v * (v - 1) / 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 11264
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(200000000)


# my functions here!

#入力

def pin(type=int):
    return map(type,input().rstrip().split())
from collections import Counter
from itertools import accumulate as acm
def resolve():
    N,=pin()
    S=list(acm(pin()))
    S.insert(0,0)
    s=list(Counter(S).values())
    ans=0
    for j in s:
            ans+=(j*(j-1))//2
    print(ans)
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
if __name__=="__main__":resolve()

Measured memory_bytes: 34168
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N, A;
    cin >> N >> A;

    cout << N * N - A << endl;
    
    return 0;
}

Measured memory_bytes: 3592