akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define N 100001
#define SELF 1

typedef struct {
	int leader;
	int friends;
	int coblockedInSameGroup;
	int members;		//all(only when he/she is a king) of nothing
	int king;
} node_t;

node_t node[N] {0};
int n, m, k, a, b, c, d;

void getAndSetData();
	void init();
	void makeFriends(int a, int b);
	void getCoblockedInSameGroup(int c, int d);
		int getKing(int x);
void output();

int main() {
	getAndSetData();
	output();
	return 0;
}

void getAndSetData() {
	scanf("%d %d %d", &n, &m, &k);
	init();
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &a, &b);
		makeFriends(a, b);
	}
	for (int i = 1; i <= n; i++)
		node[i].king = getKing(i);
	for (int i = 0; i < k; i++) {
		scanf("%d %d", &c, &d);
		getCoblockedInSameGroup(c, d);
	}
	return;
}

void output() {
	int ans, cansel, king, groupMembers;
	for (int i = 1; i <= n; i++) {
		cansel = node[i].friends + node[i].coblockedInSameGroup + SELF;
		king = node[i].king;
		groupMembers = node[king].members;
		ans = groupMembers - cansel;
		if (ans >= 0)
			printf("%d", ans);
		else
			printf("0");
		if (i != n)
			printf(" ");
		else
			printf("\n");
	}
	return;
}

void init() {
	for (int i = 1; i <= n; i++)
		node[i].members = 1;
	return;
}

void makeFriends(int a, int b) {
	node[a].friends++,	node[b].friends++;
	int ka = getKing(a), kb = getKing(b);
	if (ka != kb) {
		if (node[ka].members >= node[kb].members) {
			node[ka].members += node[kb].members;
			node[kb].members = 0;
			node[kb].leader = ka;
		} else {
			node[kb].members += node[ka].members;
			node[ka].members = 0;
			node[ka].leader = kb;
		}
	}
	return;
}

void getCoblockedInSameGroup(int c, int d) {
	if (node[c].king == node[d].king) {
		node[c].coblockedInSameGroup++;
		node[d].coblockedInSameGroup++;
	}
	return;
}

int getKing(int x) {
	if (node[x].leader == 0)
		return x;
	else
		return getKing(node[x].leader);
}



Measured memory_bytes: 2688
#include<iostream>
#include<string>

using namespace std;

int main(void){
	long N,X;
	long m[1010];
	cin >> N >> X;
	for(int i=0; i<N; ++i){
		cin >> m[i];
	}
	long min = 100000;
	long total = 0;
	for(int i=0; i<N; ++i){
		total += m[i];
		if(m[i] < min) min = m[i]; 
	}
	int r = (X-total) / min;
	cout << N+r << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(0,n)[::-1]:
  if a[i+1]+a[i]<=b[i]:
    ans+=a[i+1]+a[i]
    a[i+1]=0;a[i]=0
  elif a[i+1]<=b[i]<a[i]+a[i+1]:
    ans+=b[i]
    a[i]-=(b[i]-a[i+1]);a[i+1]=0
  elif a[i+1]>b[i]:
    ans+=b[i]
    a[i+1]-=b[i]
print(ans)

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

#define int ll
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  vector<int> pref(n + 1, 0), suf(n + 1, 0);
  for (int i = 0; i < n; ++i) {
    pref[i + 1] = pref[i] + (s[i] == 'R');
    suf[i + 1] = suf[i] + (s[n - i - 1] == 'R');
  }
  int ans = 1e18;
  for (int i = 0; i <= n; ++i) {
    int rp = pref[i], wp = i - pref[i];
    int rs = suf[n - i], ws = n - i - suf[n - i];
    int need = 0;
    int x = min(wp, rs);
    wp -= x;
    rs -= x;
    need += x;
    need += wp;
    need += rs;
    ans = min(ans, need);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 6808
import re

S = input()

regex = r'A[a-z][a-z]*C[a-z]*[a-z]'
ans = re.match(regex, S)
if(ans != None):
    if(ans.span() == (0, len(S))):
        print('AC')
    else:
        print('WA')
else:
    print('WA')


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

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

	long long p = 1;
	const int mod = 1e9 + 7;
	for (int i = 1; i <= n; i++) {
		p = p * i % mod;
	}
	cout << p << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            int x = sc.nextInt();
            int y = sc.nextInt();
            String z = String.valueOf(x + y);
            System.out.println(z.length());
        }
    }
}

Measured memory_bytes: 26368
import java.util.*;
 
public class Main {
    public static void main(String[] args) {

        Scanner sc  = new Scanner(System.in);

        int cnt = 0;
        String str = "";


        int N = Integer.parseInt(sc.next());
        String s1 = sc.next();
        int W = Integer.parseInt(sc.next());


        if(s1.equals( "+" ))System.out.print(N+W);
        if(s1.equals( "-" ))System.out.print(N-W);
        System.out.println();
    }

}

Measured memory_bytes: 10192
w, h, n = map(int, input().split())
xya = [map(int, input().split()) for _ in range(n)]

l, r, b, u = 0, w, 0, h
for x, y, a in xya:
    if a == 1:
        l = max(x, l)
    elif a == 2:
        r = min(x, r)
    elif a == 3:
        b = max(y, b)
    elif a == 4:
        u = min(y, u)
print(max(0,r - l) * max(0,u - b))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N,X;
    cin >> N >> X;
    int L[101] = {};
    int ball[101] = {};
    for(int i=0;i<N;i++){
        cin >> L[i];
        ball[i+1] = ball[i]+L[i];
    }
    int cnt = 0;
    for(int i=0;i<=N;i++){
        if(ball[i] <= X){
            cnt++;
        }
    }
    
    cout << cnt << endl;
}


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

using namespace std;

template <typename T, typename = typename std::enable_if<
                          std::is_integral<T>::value, T>::type>
vector<pair<T, int>> prime_factorize(T n) {
  vector<pair<T, int>> cnts{};
  if (n == 1) {
    return cnts;
  }

  T a = 2;
  while (n >= a * a) {
    int cnt = 0;
    while (n % a == 0) {
      n /= a;
      cnt++;
    }

    if (cnt > 0) {
      cnts.push_back({a, cnt});
    }

    a++;
  }

  if (n != 1) {
    cnts.push_back({n, 1});
  }

  return cnts;
}

int main(int argc, const char *argv[]) {
  //
  int n;
  cin >> n;
  vector<int> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  map<int, int> cnts;
  for (int i = 0; i < n; ++i) {
    auto factors = prime_factorize(va[i]);
    for (auto f : factors) {
      if (f.second > 0 && f.first != 1) {
        cnts[f.first]++;
      }
    }
  }

  bool pairwise_coprime = true;
  for (auto &p : cnts) {
    if (p.second >= 2) {
      pairwise_coprime = false;
      break;
    }
  }

  int g = va.front();
  for (int i = 0; i < n; ++i) {
    g = gcd(g, va[i]);
  }

  if (pairwise_coprime) {
    cout << "pairwise coprime" << '\n';
  } else if (!pairwise_coprime && g == 1) {
    cout << "setwise coprime" << '\n';
  } else {
    cout << "not coprime" << '\n';
  }

  return 0;
}

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

class Player{
private:
    bool played;
    queue<int> games;
    int id;
public:
    void Set_ID(int i);
    int Get_ID();
    void New_Day(vector<int>& active_players);
    bool Can_Play();
    int Next_Game();
    void Play();
    void Input(int i);
};

void Player::Set_ID(int i) {
  id = i;
}

int Player::Get_ID() {
  return id;
}

void Player::New_Day(vector<int>& active_players){
  if (played) active_players.push_back(id);
  played = false;
}

bool Player::Can_Play(){
  return !(played or games.empty());
}

int Player::Next_Game() {
  return games.front();
}

void Player::Play() {
  games.pop();
  played = true;
}

void Player::Input(int i) {
  games.push(i);
}

int main() {
  int n;
  cin >> n;
  vector<Player> players(n);
  vector<int> active_players(n);
  for (int i = 0; i < n; ++i) {
    players[i].Set_ID(i);
    active_players[i] = i;
    for (int j = 0; j < n - 1; ++j) {
      int a;
      cin >> a;
      players[i].Input(a - 1);
    }
  }

  int game = 0;
  int day = 0;
  int prev_game = 0;

  while (game < n * (n - 1) / 2) {
    for (int i: active_players) {
      Player& player = players[i];
      if (not player.Can_Play()) continue;
      Player& opponent = players[player.Next_Game()];
      if (not opponent.Can_Play()) continue;
      if (player.Get_ID() == opponent.Next_Game()) {
        player.Play();
        opponent.Play();
        ++game;
      }
    }
    if (game == prev_game) {
      cout << -1 << endl;
      return 0;
    }
    prev_game = game;
    ++day;
    active_players.clear();
    for (Player& player: players) {
      player.New_Day(active_players);
    }
  }
  cout << day << endl;
  return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n;
    cin>>n;
    int l[n];
    for(int i=0;i<n;i++)
        cin>>l[i];
    sort(l,l+n);
    int val = l[n-1];
    ll sum=0;
    for(int i=0;i<n-1;i++)
        sum+=l[i];
    if(sum>val)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
#import queue

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

class queue:
	def __init__(self):
		self.l=[0]*(1000*1000+100)
		self.f=0
		self.t=0
		
	def put(self,v):
		self.l[self.f]=v
		self.f+=1
		
	def get(self):
		self.t+=1
		return self.l[self.t-1]
		
	def empty(self):
		return self.f==self.t

def main():
	#a = int(input())
	h, w = tin()
	#s = input()
	mp = [list(input()) for _ in range(h)]
	dist=[[-1] * w for _ in range(h)]
	open_list=queue()
	for hi, l in enumerate(mp):
		for wi, c in enumerate(l):
			if c == '#':
				dist[hi][wi]=0
				open_list.put(hi*2000+wi)
				
	max_dist=0
	while not open_list.empty():
		hi_wi = open_list.get()
		hi = hi_wi // 2000
		wi = hi_wi % 2000
		d = dist[hi][wi]
		for dw, dh in [(0,1),(0,-1),(1,0),(-1,0)]:
			if -1 == wi+dw or -1 == hi + dh or w == wi+dw or h == hi + dh:
				continue
			if dist[hi+dh][wi+dw] >= 0:
				continue
			#if dist[hi+dh][wi+dw]==-2:
				
			dist[hi+dh][wi+dw]=d+1
			open_list.put(((hi+dh)*2000+wi+dw))
			max_dist=d+1
	print(max_dist)
	#for l in dist:
	#	print(l)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 129620
n, m = gets.split.map(&:to_i)
lrs = m.times.map{|_| gets.split.map(&:to_i)}

l_max = 0
r_min = n
lrs.each do |lr|
  l_max = [l_max, lr[0]].max
  r_min = [r_min, lr[1]].min
end
if r_min < l_max
  p 0
  exit
end
p r_min - l_max + 1

Measured memory_bytes: 20892
//解説参照済み

function main(input = "") {
    const lines = input.split("\n");
    const _K = 0 | lines[0].split(" ")[1];
    const arr = lines[1].split(" ").map((v) => 0 | v);

    let l = 1;
    let r = arr.reduce((a, b) => { return Math.max(a, b) });
    let mid = 0 | (r + l) * 0.5;
    let res = r;
    while (l <= r) {

        let k = 0;
        arr.forEach((v) => {
            let d = 0 | v / mid;
            if (v === d * mid) { d--; }
            k += d;
        })

        if (k <= _K) {
            res = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
        mid = 0 | (r + l) * 0.5;
    }
    return res;
}


//******************************
exports.main = main;

function Main(input) {
    console.log(main(input.trim()));
}

if (process.argv[2] !== "test") {
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}

Measured memory_bytes: 50024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var (A, B, X) = ReadLine().Split(' ').Select(int.Parse).ToArray();

        var ans = (X - A <= B && A <= X) ? "YES" : "NO";

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28264
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t X,a,b;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> X>>a>>b;
	X -= a;
	out << X % b << endl;

	return 0;
}
#endif


#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;

int32_t dft_table[20][262144];
int32_t* dft(int32_t* arr, size_t size, int depth = 0)
{
	if (size == 1) {
		return arr;
	}

	auto f0 = dft_table[depth + 1];
	auto f1 = dft_table[depth + 1]+size/2;
	for (size_t i = 0; i < size/2; i++)
	{
		f0[i] = arr[2 * i + 0];
		f1[i] = arr[2 * i + 1];
	}

	dft(f0, size / 2);
	dft(f1, size / 2);

	
}
std::vector<int32_t> convolution(std::vector<int32_t>& a, std::vector<int32_t>& b)
{
	size_t s = a.size() + b.size() + 1;
	{size_t tmp = 1; for (; tmp < s; tmp <<= 1) {}
	s = tmp; }

	auto copy = [&s](const std::vector<int32_t>& arr) {
		size_t i = 0;
		for (; i < arr.size(); i++)
		{
			dft_table[0][i] = arr[i];
		}
		for (; i < s; i++)
		{
			dft_table[0][i] = 0;
		}
	};
	copy(a);
	auto a_ = dft(dft_table[0], s);
	copy(b);
	auto b_ = dft(dft_table[0], s);
	auto& ff = a_;
	for (size_t i = 0; i < s; i++)
	{
		ff[i] *= b_[i];
	}
	return inverse_dft(ff);
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;

	return 0;
}
#endif


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

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

	long long a, b, x;
	cin >> a >> b >> x;
	long y = a / x;
	long z = b / x;
	if (a % x == 0) {
		cout << z - y + 1;
	}
	else cout << z - y;
}

Measured memory_bytes: 256
import math 

N2,M1 = map(int, input().split())
count=0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N2!=0 and N2!=1:
    count += combinations_count(N2,2)
if M1!=0 and M1!=1:
    count += combinations_count(M1,2)

print(count)

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

int main(){
    string s; cin>>s;
    if(s=="SUN") cout<<7<<endl;
    else if(s == "MON") cout<<6<<endl;
    else if(s == "TUE") cout<<5<<endl;
    else if(s == "WED") cout<<4<<endl;
    else if(s == "THU") cout<<3<<endl;
    else if(s == "FRI") cout<<2<<endl;
    else if(s == "SAT") cout<<1<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int gu = 0;
    int ki = 0;
    int n;cin >> n;
    rep(i,n)if((i+1)%2)ki++;else gu++;
    cout << ki*gu << endl;
}




Measured memory_bytes: 256
import numpy as np

N = int(raw_input())
A = np.array(map(int, raw_input().split()))
B = map(lambda x: format(x, '060n'), A)
# A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    # zeros = len([a[i] for a in A if a[i] == '0'])
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

ans = 0
for i in count:
    ans = (ans + count[i] * pow(2,i,MOD)) % MOD

print ans


Measured memory_bytes: 60268
import java.util.*;


import java.io.*;
import java.math.BigInteger;


public class Main 
{   
	static int dp[];
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		int ans=frog(ar,0,n);
		System.out.println(ans);
	}

	private static int frog(int[] ar, int i,int n) {
		// TODO Auto-generated method stub
		if(i>=n-1) {
			//System.out.println(1);
			return 0;

		}
		
		if(dp[i]!=-1)
			return dp[i];
		
		int op1=Math.abs(ar[i]-ar[i+1])+frog(ar, i+1, n);
		
		int op2=(i+2<n?Math.abs(ar[i]-ar[i+2])+frog(ar, i+2, n):Integer.MAX_VALUE);
		
		dp[i]= Math.min(op1, op2);
		
		return dp[i];
		
	}

	
	
}

Measured memory_bytes: 61476
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S;
    cin >> S;
    REP(i, S.length()) {
        cout << "x";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int memo[110000];
int main() {
int n,m;
  cin>>n>>m;
  vin q(m),y(m);
  rep(i,m) cin>>q[i]>>y[i];
  ////
  vector<pair<P,int>> p(m);
  rep(i,m){
   p[i].first=make_pair(q[i],y[i]);
    p[i].second=i;
    //cout<<p[i].first<<endl;
  }
  sort(all(p));
  int c=0;//県
  int num=0;//順番
  rep(i,m){
         if(c==p[i].first.first){
           num++;
           p[i].first.second=num;
         }
         else{
           num=1;
           c=p[i].first.first;
           p[i].first.second=num;
         }
  }
  
  rep(i,m){
   swap(p[i].first.first,p[i].second);
    
   swap(p[i].first.second,p[i].second); 
  }
  sort(all (p));
  for(auto v: p){
   // cout<<v.first.first<<endl;
    string a,b;
    a=to_string(v.first.second);
    b=to_string(v.second);
    cout << setfill('0') << right << setw(6) << a; // "0012"
     cout << setfill('0') << right << setw(6) << b; // "0012"
   cout<<endl; 
  }
}










Measured memory_bytes: 3456
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
//小さい順
int compareInt(const void* a, const void* b){int aNum = *(int*)a;int bNum = *(int*)b;return aNum - bNum;}

int main(void){
    int s;
    int a[100000];
    scanf("%d",&s);
    int i=0;
    a[i]=s;
    while(1){
        if(a[i]%2==0){
            a[i+1]=a[i]/2;
        }else{
            a[i+1]=3*a[i]+1;
        }
        for(int j=0;j<=i;j++){
            if(a[i+1]==a[j]){
                printf("%d",i+2);
                return 0;
            }
        }
        i++;
    }
}


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

int main()
{
  int n, x[10], y[10];
  long double result = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> x[i];
    cin >> y[i];
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      result += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
    }
  }
  printf("%Lf", result * 2 / n);
  // cout << result * 2 / n << endl;
}


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

int main(){
    long long A, B, N;
    cin >> A >> B >> N;
    if(N<B){
        cout << (A*N)/B << endl;
    }else{
        cout << (A*(B-1))/B << endl;
    }
    system("pause");
    return 0;
}

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


int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i,N){cin >> d.at(i);}
  
  int num =0;
  int bucket[110]={0};
  rep(i,N){bucket[d.at(i)]++;}
  
  rep(i,110){if(bucket[i]>0)num++;}  

  cout << num << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
namespace tre
{
	inline bool check_min(int a,int &b){return (a<b)?(b=a,1):0;}
	inline bool check_max(int a,int &b){return (a>b)?(b=a,1):0;}
	const int N=305,INF=2147483647;
	int s[N][N],ind[N],cnt[N];
	bool sel[N];
	int n,m,ans;
	int push()
	{
		for(int i=1;i<=n;i++)
			while(!sel[s[i][ind[i]]] && ind[i]<=m)ind[i]++;
		memset(cnt,0,sizeof(cnt));
		for(int i=1;i<=n;i++)
			cnt[s[i][ind[i]]]++;
		int ret=0,tmp=0;
		for(int i=1;i<=m;i++)
			if(check_max(cnt[i],tmp))ret=i;
		check_min(tmp,ans);
		return ret;
	}
	void initialize()
	{
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				scanf("%d",&s[i][j]);
	}
	void solve()
	{
		initialize();
		for(int i=1;i<=m;i++)
			sel[i]=1,ind[i]=1;
		ans=INF;
		for(int i=1;i<=m;i++)
		{
			int p=push();
			sel[p]=0;
		}
		printf("%d\n",ans);
	}
}
int main()
{
	tre::solve();
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz               size()
#define inc(i,x,y)      for(int i=x;i<y;i++)
#define dec(i,x,y)      for(int i=x;i>=y;i--)

const int N = 2e5 + 5;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}

//////////////////////////////code//////////////////////////////

int32_t main()
{
  fast();

  int a,b,c,k;
  cin>>a>>b>>c>>k;

  if(a>=k)
    cout<<k;
  else if(a<k && a+b>=k)
    cout<<a;
  else
  {
      cout<<a-(k-a-b);
  }



}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a[30]={};
    char c[100]={},mc;
    int ma=0;
    for(int i=0;i<n;i++){
      cin>>c[i];
      a[c[i]-'A']++;
    }
    int f=0;
    for(int i=0;i<30;i++){
      if(a[i]==ma)f=1;
      if(a[i]>ma){
	ma=a[i];
	mc=i;
	f=0;
      }
    }
    if(f)cout<<"TIE"<<endl;
    else {
      int cnt[30]={};
      int ma2=0;
      for(int i=0;i<n;i++){
	int nc=c[i]-'A';
	cnt[nc]++;
	if(nc!=mc){
	  ma2=max(ma2,cnt[nc]);
	}
	if(cnt[mc]>ma2+n-1-i){
	  cout<<(char)(mc+'A')<<" "<<i+1<<endl;
	  break;
	}
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3012
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s, t;
    cin >>s >>t;
    int ans = 0;
    for(int i = 0; i < 3; i++)
        if(s[i] == t[i])
            ans++;
    cout <<ans;
    return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	int a,b,m,ans=1e9;
	cin>>a>>b>>m;
	int aa[100000],bb[100000];
	for(int i=0;i<a;++i)cin>>aa[i];
	for(int i=0;i<b;++i)cin>>bb[i];
	for(int i=0,pa,pb,minus;i<m;++i){
		cin>>pa>>pb>>minus;
		ans=min(ans,aa[pa-1]+bb[pb-1]-minus);
	}
	sort(aa,aa+a);
	sort(bb,bb+b);
	ans=min(ans,aa[0]+bb[0]);
	cout<<ans<<"\n"s;
}

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

const int N = 2022;
int n, dis[N], size[N];
vector<int> G[N];
char s[N];

void dfs(int x, int pre) {
  size[x] = s[x] - '0';
  dis[x] = 0;
  for (auto y : G[x]) if (y != pre) {
    dfs(y, x);
    size[x] += size[y];
    dis[x] += dis[y] + size[y];
  }
}
bool dfs2(int x, int pre, int d) {
  if (!d) return true;
  if (d > dis[x]) return false;
  int mx = -1, mp = 0;
  for (auto y : G[x]) if (y != pre) {
    if (dis[y] + size[y] > mx) {
      mx = dis[y] + size[y];
      mp = y;
    }
  }
  int my = dis[x] - mx;
  if (my >= mx || 2 * my >= d) return true;
  return dfs2(mp, x, d - 2 * my);
}

int main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  int ans = 0x3f3f3f3f;
  for (int rt = 1; rt <= n; rt++) {
    dfs(rt, 0);
    if (dis[rt] & 1) continue;
    if (dfs2(rt, 0, dis[rt])) ans = min(ans, dis[rt]);
  }
  printf("%d\n", ans == 0x3f3f3f3f ? -1 : ans / 2);
}


Measured memory_bytes: 512
#include <stdio.h>
int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  int cnt[200],ans=n, i,j,d,a;
  for(i=1; i<=n; ++i) cnt[i]=0;
  for(i=0; i<k; ++i){
    scanf("%d",&d);
    for(j=0; j<d; ++j){
      scanf("%d",&a);
      if(!cnt[a]){ans--;cnt[a]++;}
    }
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
//#include<bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;

int main(){
  int N,K,ans;
  string S;//1011100001010101など
  cin >> N >> K >> S;
  vector<int> Nums;
  int cnt = 0,number = 1;//numberは着目する符号
  for (int n = 0; n < N; n++){
    if(S[n] ==  '0' + number){
      cnt++;
    }else{
      Nums.push_back(cnt);
      number = (number + 1) % 2;
      cnt = 1;
    }
  }
  Nums.push_back(cnt);
  if( number == 0)Nums.push_back(0);
  int maxSum = -1,sum = 0;
  for (int i = 0; i < Nums.size(); i = i + 2){
    int right = min(i + 2 * K + 1,(int)Nums.size());
    for (int left = i; left < right; left++){
      sum += Nums[left];
    }
    //cout << sum << endl;
    maxSum = max(sum,maxSum);
    sum = 0;
  } 

  //for (int i = 0; i < Nums.size();i++)
    //cout << Nums[i] << endl; 
  cout << maxSum << endl;
}

Measured memory_bytes: 1020
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int n,a[maxn];

int main() {
  //freopen("in.cpp","r",stdin);
  int m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    a[x]++;
    a[y]++;
  }
  bool sign=0;
  for(int i=1;i<=n;i++)if(a[i]&1)sign=1;
  if(sign)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 

using namespace std;

int main()
{
	int n,f,b;
	long long c,d;

	while(1){
		f=1;int k=0;
		long long a[4000][2]={0};
		cin>>n; if(n==0) return 0;

		for(int i=0;i<n;i++){
			cin>>b>>c>>d;
			for(int j=0;j<k;j++){
				if(a[j][0]==b){ a[j][1]+=c*d; f=0;}
			}
			if(f){
				a[k][0]=b; a[k++][1]=c*d;
			}
		}

		f=1;
		for(int i=0;i<k;i++){
			if(a[i][1]>=1000000) {cout<<a[i][0]<<endl; f=0;}
		}
		if(f) cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>



int main(){
  int N,L;
  scanf("%d%d",&N,&L);
  int i,j;
  char s[N][L+1];
  char tmp[L+1];
  char str[10001];
  for(i=0;i<N;i++){
    scanf("%s",s[i]);
  }
  //printf("%s\n",s[0]);
  for(i=1;i<N;i++){
    for(j=1;j<N;j++){
      if(strcmp(s[j-1],s[j])>0){
        strcpy(tmp,s[j-1]);
        strcpy(s[j-1],s[j]);
        strcpy(s[j],tmp);
      }
    }
  }//文字列を辞書中にソート
  for(i=0;i<N;i++){
    strcat(str,s[i]);
  }
  printf("%s",str);
}


Measured memory_bytes: 128
from collections import deque

K = int(input())
q = deque()

for i in range(1, 10):
	q.append(i)

k = 0
while True:
	n = q.popleft()
	k += 1
	if k == K:
		break
	if (n % 10) % 10 != 0:
		q.append(10 * n + (n % 10) - 1)
	q.append(n * 10 + (n % 10))
	if (n % 10) % 10 != 9:
		q.append(10 * n + (n % 10) + 1)
print(n)

Measured memory_bytes: 18704
N = int(input())
S1 = list(input())
S2 = list(input())
ans = 1
MOD = 1000000007
flag_1 = False

if S1[0] == S2[0]:
    ans *= 3
    flag = 'X'
else:
    ans *= 6
    flag = 'Y'

for i in range(1,N):
    if i == 1 and flag == 'Y':
        continue
    if flag_1:
        flag_1 = False
        continue
    if S1[i] == S2[i]:
        if flag == 'X':
            ans *= 2
        else:
            flag = 'X'
    else:
        if flag == 'X':
            ans *= 2
            flag = 'Y'
        else:
            ans *= 3
        flag_1 = True
    ans %= MOD
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int N, X, Y;



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

   vector<int> k(N);

   for (int i=1; i <= N-1; i++) {
       for (int j=i+1; j <= N; j++)
            k.at(min(j-i, min(abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(X-j))))++;
   }
   for (int i=1; i <= N-1; i++) {
       cout << k.at(i) << endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

const int mod = 998244353;

void add(int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}

void sub(int &a, int b)
{
    a -= b;
    if (a < 0)
        a += mod;
}

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

    int n;
    cin >> n;

    vector<int> p2(n + 1);
    p2[0] = 1;
    for (int i = 1; i <= n; ++i)
    {
        p2[i] = p2[i - 1];
        add(p2[i], p2[i]);
    }

    string s;
    cin >> s;

    vector<int> fak;
    vector<int> total;

    int answer = 0;

    int big_total = 0;
    for (int i = 0; i < n; ++i)
    {
        add(big_total, big_total);
        if (s[i] == '1')
            add(big_total, 1);
    }

    for (int i = 1; i < n; ++i)
    {
        if ((n + i) % (2 * i) == 0)
        {
            int cur = 0;
            for (int j = 0; j < i; ++j)
            {
                if (s[j] == '1')
                {
                    add(cur, p2[i - j - 1]);
                }
            }

            int ok = 1;

            for (int j = i; j < n && ok; ++j)
            {
                int rcur = s[j] - '0';
                int exp = s[j % i] - '0';

                if (j % (2 * i) >= i)
                    exp ^= 1;

                if (exp > rcur)
                {
                    ok = 0;
                    break;
                }

                if (rcur > exp)
                {
                    break;
                }
            }

            add(cur, ok);
            fak.push_back(i);
            total.push_back(cur);
        }
    }

    for (int i = 0; i < fak.size(); ++i)
    {
        int u = fak[i];
        for (int j = 0; j < i; ++j)
        {
            int v = fak[j];

            if ((u + v) % (2 * v) == 0)
            {
                sub(total[i], total[j]);
            }
        }

        add(answer, 1LL * 2 * u % mod * total[i] % mod);
        sub(big_total, total[i]);
    }

    add(big_total, 1);

    add(answer, 1LL * 2 * n % mod * big_total % mod);

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 1488
import itertools
from typing import List, Tuple


def print_elems(elems):
    print(" ".join([str(elem) for elem in elems]))


if __name__ == "__main__":
    n = int(input())
    nums = tuple(map(lambda x: int(x), input().split()))
    nums_permutated = list(itertools.permutations(sorted(nums)))

    if (1 == len(nums_permutated)):
        print(nums[0])
        exit(0)

    for idx in range(1, len(nums_permutated)):
        if (nums == nums_permutated[idx - 1]):
            print_elems(nums_permutated[idx - 1])
            print_elems(nums_permutated[idx])
            exit(0)
        if (nums == nums_permutated[idx]):
            print_elems(nums_permutated[idx - 1])
            print_elems(nums_permutated[idx])
            if (idx != len(nums_permutated) - 1):
                print_elems(nums_permutated[idx + 1])
            exit(0)



Measured memory_bytes: 53924
#include <bits/stdc++.h>
#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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;
}

int main(){
  cout << fixed << setprecision(15);
  int ans = 0;
  //string ans = "No";

  int a, b; cin >> a >> b;
  ans = (a - b + b - 2) / (b - 1) + 1;

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

Measured memory_bytes: 3580
// Copyright 2020 yaito3014
#include <iostream>
#include <set>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> ans(N, 0);
  using ll = long long;
  auto f = [](ll x, ll y, ll z) {
    return x * x + y * y + z * z + x * y + y * z + z * x;
  };
  for (ll x = 1; x <= N; ++x)
    for (ll y = 1; y <= x && f(x, y, 1) <= N; ++y)
      for (ll z = 1; z <= y; ++z) {
        ll n = f(x, y, z);
        if (n > N) continue;
        int k = std::set<long long>{x, y, z}.size();
        ans[n - 1] += k == 3 ? 6 : k == 2 ? 3 : 1;
      }
  for (const auto& e : ans) std::cout << e << '\n';
}


Measured memory_bytes: 3636
//union find tree
//test : DSL_1_A: Disjoint Set: Union Find Tree : AC  : 2015/11/27
#include<vector>
#include<iostream>
#define rep(i,j) for(int i=0;i<(j);i++)
using namespace std;

//Node 0 to n-1??§???1 to n??§???OK
struct UnionFind{
  int n;
  vector<int> p;
  UnionFind(int nn):n(nn+1){
      p.resize(n);
      rep(i,n)p[i]=i;
  }
  int root(int x){
    if(p[x] == x) return x;
    else return p[x] = root(p[x]);
  }
  void unite(int x,int y){
      x = root(x), y = root(y);
      if(x != y) p[y]=x;
  }
  bool query(int x,int y){
    return root(x) == root(y);
  }
};

int main(){
    int n,q; cin >> n >> q;
    UnionFind ut(n);
    rep(i,q){
        int c ,x,y; cin >> c >> x >> y;
        if(c) cout << ut.query(x,y) << endl;
        else ut.unite(x,y);
    }
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fastcin  ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

void solve(){	
	int n;
	cin >> n;
	
	int d = n%10;
	
	if(d == 2 or d == 4 or d == 5 or d == 7 or d == 9) cout << "hon" << endl;
	else if(d == 3) cout << "bon" << endl;
	else cout << "pon" << endl;
	
}

int main(){

	fastcin
	solve();      
	return 0;
}
	


Measured memory_bytes: 3620
import java.util.Scanner;

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

    int N = scanner.nextInt();
    long K = scanner.nextLong();
    int[] digits = new int[41];
    int t = 0;
    while (K > 0) {
      if (K % 2 == 1) digits[t] = 1;
      K /= 2;
      t++;
    }

    int[] numOnes = new int[41];
    for (int i = 0; i < N; i++) {
      long a = scanner.nextLong();
      int j = 0;
      while (a > 0) {
        if (a % 2 == 1) numOnes[j]++;
        a /= 2;
        j++;
      }
    }

    long[][] dp = new long[42][2];
    for (int i = 40; i >= 0; i--) {
      long d = 1L << i;
      int ones = numOnes[i];
      int zeros = N - ones;
      if (digits[i] == 0) {
        dp[i][0] = dp[i + 1][0] + d * ones;
        if (dp[i + 1][1] > 0) dp[i][1] = dp[i + 1][1] + d * Math.max(ones, zeros);
      } else {
        dp[i][0] = dp[i + 1][0] + d * zeros;
        dp[i][1] = dp[i + 1][0] + d * ones;
        if (dp[i + 1][1] > 0) dp[i][1] = Math.max(dp[i][1], dp[i + 1][1] + d * Math.max(ones, zeros));
      }
    }
    System.out.println(Math.max(dp[0][0], dp[0][1]));
  }
}


Measured memory_bytes: 50384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    boolean flg = true;
    ArrayList<List<Integer>> list = new ArrayList<>();

    while(flg) {
      int h = sc.nextInt();
      int w = sc.nextInt();

      if(h == 0 && w == 0) {
        flg = false;
        sc.close();
        break;
      }

      List<Integer> data = new ArrayList<Integer>();
      data.add(h);
      data.add(w);
      list.add(data);
    }

    for(int i = 0; i < list.size(); i++) {
      int h = list.get(i).get(0);
      int w = list.get(i).get(1);
      for(int j = 0; j < h; j++) {
        for(int k = 0; k < w; k++) {
          if(j % 2 == 0) {
            if(k % 2 == 0) {
              System.out.print('#');
            } else {
              System.out.print('.');
            }
          } else {
            if(k % 2 == 0) {
              System.out.print('.');
            } else {
              System.out.print('#');
            }
          }
        }
        System.out.print("\n");
      }
      System.out.print("\n");
    }
  }
}


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

#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define inf INT_MAX
#define MOD 1000000007
#define fori(i,n) for(int i=0;i<(int)n;++i)
#define forri(i,n) for(int i=n-1;i>=0;--i)
#define forii(i,start,end) for(int i=start;i<end;++i)
#define MEM(a,b) memset(a,(b),sizeof(a))
#define sizearr(arr) sizeof(arr)/sizeof(arr[0])
#define LEN(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define reset(arr, val) fori(i, MAX) arr[i] = val;

#define print(var) cout << var << endl;
#define ENDL cout << endl;
#define coutarr(arr) for(auto a:arr)print(a); ENDL;
#define coutpii(arr) for(pii a:arr)cout << '(' << a.fi << ',' << a.se << ") "; ENDL;
#define cinvec(arr, n) fori(i, n) {int tmp; cin >> tmp; arr.pb(tmp);}
#define cinarr(arr, n) fori(i, n) {int tmp; cin >> tmp; arr[i]=tmp ;}

const int MAX = 1e5 + 5;

int st[4*MAX]; //segtree
int arr[MAX]; //linear array elmt of segtree

int strule(int a, int b){
	return min(a, b);
}

int getMid(int s, int e){
	return s+(e-s)/2;
}

int buildst(int start, int end, int cur){
	// basis
	if (start == end){
		st[cur] = arr[start];
		return st[cur];
	}

	// reccurence
	int mid = getMid(start, end);
	st[cur] = strule(buildst(start, mid, 2*cur+1), buildst(mid+1, end, 2*cur+2));
}

int find(int ss, int se, int qs, int qe, int cur){
	// all segment inside
	if (qs <= ss && qe >= se){
		return st[cur];
	}

	// all segment outside
	if (se < qs || ss > qe){
		return INT_MAX;
	}

	// some segment inside
	int mid = getMid(ss, se);
	return strule(find(ss, mid, qs, qe, 2*cur+1), find(mid+1, se, qs, qe, 2*cur+2));
}

void update(int ss, int se, int index, int val, int cur){
	if(ss == se){
		arr[index] = val;
		st[cur] = val;
	} else {
		int mid = getMid(ss, se);
		if(ss <= index && index <= mid) update(ss, mid, index, val, 2*cur+1);
		else update(mid+1, se, index, val, 2*cur+2);
		st[cur] = strule(st[2*cur+1], st[2*cur+2]);
	}
}

// buildst(0, n-1, 0);
// find(0, n-1, start, end, 0);
// update(0, n-1, node, val, 0);

int main(){
	int n, q; cin >> n >> q;
	fori(i, MAX) arr[i] = INT_MAX;
	buildst(0, n, 0);

	fori(i, q){
		int com, a, b; cin >> com >> a >> b;
		if (com) cout << find(0, n-1, a, b, 0) << endl;
		else update(0, n-1, a, b, 0);
	}
	
	return 0;	
}


Measured memory_bytes: 4488
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
 
const LL inf = 11234567;
LL N;
LL t[112], v[112];
LL seek, last, lim[41234], memo[41234][234];
 
LL dp(LL ti, LL sp)
{
	if (sp < 0) { return -inf; }
	if (ti == 0) {
		if(sp == 0)return 0LL; 
		return -inf;
	}
	if (sp > lim[ti - 1])return -inf;
	if (memo[ti][sp] != -1) { return memo[ti][sp]; }
	LL res = dp(ti - 1, sp) + sp + sp;
	{ res = std::max(res, dp(ti - 1, sp - 1) + sp + (sp - 1)); }
	if(sp+1<=lim[ti-1]){ res = std::max(res, dp(ti - 1, sp + 1) + sp + (sp + 1)); }
	return memo[ti][sp] = res;
}
 
int main()
{
	in >> N;
	rep(i, N) { in >> t[i]; }
	rep(i, N) { in >> v[i]; }
 
	memset(memo, -1, sizeof(memo));
	rep(i, N)
	{
		t[i] *= 2;
		v[i] *= 2;
		rep(j, t[i]) { lim[seek++] = v[i]; }
		last += t[i];
	}
 
	out << std::fixed << std::setprecision(15);
	out << (double)dp(last, 0) / (double)8 << std::endl;
	return 0;
}

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

#define ll long long

signed main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b==c||a+c==b||b+c==a)
  {cout << "Yes" << endl;}
  else{cout << "No" << endl;}
}

Measured memory_bytes: 3544