akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scan()
	ans := 0
	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[len(s)-i-1] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include <iostream>
#include <unordered_map>
using namespace std;
int n, m;
 
bool check(int num, unordered_map<int, int> & rules){
  string temp = to_string(num);
  for(auto it = rules.begin(); it != rules.end(); it ++){
    if(temp[it->first - 1] != it->second + '0') return false;
  }
  return true;
}
int main(){
  cin >> n >> m;
  int low = pow(10, n-1);
  int hi = pow(10, n);
  if(n == 1) low = 0;
  unordered_map<int, int> rules;
  while(m --){
    int s, c;
    cin >> s >> c;
    if(rules.count(s) && rules[s] != c){
      cout << -1 << endl;
      return 0;
    } else {
      rules[s] = c;
    }
  }
  for(int i = low; i < hi; i ++){
    if(check(i, rules)){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,i;
  scanf("%d %d",&a,&b);
  if(1<b&&b<2*a-1){
    printf("Yes\n");
    for(i=0;i<2*a-1;i++)printf("%d\n",(i+b+a-1)%(2*a-1)+1);
  }
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 1408
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

int min(int a, int b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

int avd_i(int a, int b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

int main() {
	
	int N, K, X[105], ans = 0;

	cin >> N >> K;
	for (int i = 0; i < N; i++) {

		cin >> X[i];
		ans += min(X[i], K - X[i]) * 2;
	
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int len= S.size();
  bool ans= true;
  if(len % 2 != 0) ans= false;
  else{
    for(int i=0; i<len; i+= 2){
      if(S.at(i)=='h' && S.at(i+1)=='i'){ continue; }
      else{
        ans= false;
        break;
      }
    }
  }

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

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

int main()
{
  int A, B;
  cin >> A >> B;
  
  if((A % 3 == 0) || (B % 3 == 0) || ((A + B) % 3 == 0))
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}

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

int H, W;
char A[8][8];
// 右または下への移動
int dy[2] = {0, 1}, dx[2] = {1, 0};
bool flag = 0, check;

bool dfs(int y, int x, char reached[8][8]){
    // cout << "x = " << x << ", y = " << y << endl;  
    // 到達マスを'#'にする
    reached[y][x] = '#';
    check = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(A[i][j] != reached[i][j]){
                check = 1;
            }
        }
    }
    // 一致しないマスが存在しなかった
    if(check == 0)
        flag = 1;


    /* 
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << reached[i][j];  
        }
        cout << endl;
    }
    cout << endl;
    */

    // 右または下への移動
    for(int i=0;i<2;i++){
        if(A[y + dy[i]][x + dx[i]] == '#' && x + dx[i] < W && y + dy[i] < H)
            dfs(y + dy[i], x + dx[i], reached);
    }
    reached[y][x] = '.';
}
 
int main(){
    cin >> H >> W;
    char reached[8][8] = {};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> A[i][j];
            // 初期状態：全てのマスが未到達
            reached[i][j] = '.';
        }
    }
    // 左上隅のマスからスタート
    dfs(0, 0, reached);
    if(flag == 1)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

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

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int main() {
	int n, m;

	while(cin >> n >> m, n) {
		vvi route(n, vi(2, 0));

		REP(i, n) {
			cin >> route[i][1] >> route[i][0];
		}

		sort(RALL(route));
	
		REP(i, n) {
decrease:
			if(m > 0) {
				--route[i][1];
				--m;
				if(route[i][1] == 0) {
					continue;
				} else {
					goto decrease;
				}
			} else {
				break;
			}
		}

		int p = 0;

		REP(i, n) {
			p += route[i][0]*route[i][1];
		}

		cout << p << endl;
	}
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()

int digitsum(int x) {
    int ret=0;
    while (x) {
        ret += x%10;
        x /= 10;
    }
    return ret;
}

int main() {
    int n;
    scanf("%d", &n);
    if (n%digitsum(n) == 0) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    int n; cin >> n;
    vector<ll> da(n);
    ll ans = 0;
    rip(i,n,0) cin >> da[i];
    rip(i,n,0) {
        rip(j, i, 0) {
            rip(k,j,0) {
                if(da[i] != da[j] && da[j] != da[k] && da[k] != da[i] && max({da[i], da[j], da[k]})*2 < da[i] + da[j] + da[k]) {
                    // cout << da[i] MM da[j] MM da[k] << endl;
                    // cout << i MM j MM  k  << endl;
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>

using namespace std;

long long a[25] , n;

#define ll long long

ll f(ll l , ll r , ll x , ll y){
	ll  ans = 1e18;
    if(r - l <= 1) 
        return 0;
    for(int i = l + 1; i <= r - 1; i++)
        ans = min((f(l, i, x, x + y) + f(i, r, x + y, y) + a[i] * (x + y)), ans);
    return ans;
}

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	cout << a[1] + a[n] + f(1 , n , 1 , 1) << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        System.out.println( solve(S) );
    }

    private static String solve(String S) {
        char prev2 = S.charAt(0);
        char prev1 = S.charAt(1);
        if( prev2 == prev1 ) return "1 2";

        for (int i = 2; i < S.length(); i++) {
            char c = S.charAt(i);
            if( prev2 == c ) {
                return (i-1) + " " + (i+1);
            } else if( prev1 == c ) {
                return i + " " + (i+1);
            } else {
                prev2 = prev1;
                prev1 = c;
            }
        }
        return "-1 -1";
    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> value(3, 0);
  vector<bool> change(3, false);
  if(2 <= N) value.at(N-1) = 1;
  rep(i, M){
    int s;
    int c;
    cin >> s >> c;
    if(change.at(N-s) == false){
      value.at(N-s) = c;
      change.at(N-s) = true;
    }
    else if(value.at(N-s) == c){
      value.at(N-s) = c;
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = value.at(0) + value.at(1)*10 + value.at(2)*100;
  int tmp = ans;
  int digit = 0;
  if(tmp < 10){
    digit = 1;
  }
  else if (tmp < 100){
    digit = 2;
  }
  else{
    digit = 3;
  }
  if(digit!=N) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n;
	cin>>n;
	int a[n][n];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
			cin>>a[i][j];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				if(a[j][k]>a[j][i]+a[i][k])
				{
					cout<<"-1\n";
					return 0;
				}
			}
		}
	}
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			bool flag=false;
			for(int k=0;k<n;k++)
			{
				if(a[i][j]==a[j][k]+a[k][i] && k!=i && k!=j)
				{
					flag=true;
					break;
				}
			}
			if(flag==false)
				sum += a[i][j];
		}
	}
	cout<<(sum/2)<<"\n";
}

Measured memory_bytes: 3948
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	bool ans = true;
	int n;
	string s;
	cin >> n >> s;
	if (n % 2 != 0)
	{
		ans = false;
	}
	else
	{
		rep(i, n / 2)
		{
			if (s[i] != s[i + (n / 2)])
			{
				ans = false;
			}
		}
	}

	if (ans) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/*---------------------------------------------------------------------------------------------------------------------*/

const int M = 2e5 + 5;
ll dp[3][M];
ll arr[3][M];

int main(){
    
	int n;
	si(n);
	for(int i = 1 ; i <= 2 ; i++){
	    for(int j = 1 ; j <= n ; j++){
	        sll(arr[i][j]);
	    }
	}
	
	for(int i = 1 ; i <= 2 ; i++){
	    for(int j = 1 ; j <= n ; j++){
	        dp[i][j] = arr[i][j] + max(dp[i - 1][j] , dp[i][j - 1]); 
	    }
	}
	
	cout<<dp[2][n];
	
	
	
	
    
}





































Measured memory_bytes: 4352
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cstdio>
#include<cfloat>

using namespace std;

double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }
};

double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}

double norm(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

int main(void){
  double D;
  point p,v;
 
  while(cin >> D,D){
  
    cin >> p.x >> p.y >> v.x >> v.y;
     
    p=p*(-1);
    double d=D+1;
    double a=dot(p,v)/norm(p)/norm(v);

    if(abs(1.0 - a) < EPS )d=norm(p);
    else if(abs(1.0 + a) < EPS)d=2.0-norm(p);

    if(d<D || abs(d-D)<EPS)printf("%.8f\n",d);
    else cout << "impossible" << endl;
  }
 
  return 0;
}

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

int main(int argc, char const *argv[])
{
	int a,b;
	cin>>a>>b;
	--a;--b;
	int h=100,w=100;
	char s[h][w];
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			if (i<50)
			{
				s[i][j]='.';
			}
			else
			{
				s[i][j]='#';
			}
		}
	}
	int x=51,y=0;
	while (a>0)
	{
		s[x][y]='.';
		--a;
		if (y==98)
		{
			x+=2;y=0;
		}
		else
		{
			y+=2;
		}
	}
	x=0;y=0;
	while (b>0)
	{
		s[x][y]='#';
		--b;
		if (y==98)
		{
			x+=2;y=0;
		}
		else
		{
			y+=2;
		}
	}
	cout<<h<<" "<<w<<endl;
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cout<<s[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;

#define SIZE 1000000
int A[SIZE], H;

int parent(int x) { return x / 2; }
int left(int x) { return x * 2; }
int right(int x) { return x * 2 + 1; }

void insertKey(int i,int key)
{
	for (A[i] = key; i > 1 && A[parent(i)] < A[i]; i = parent(i))
		swap(A[parent(i)], A[i]);
}

void maxHeapify(int x)
{
	int l = left(x), r = right(x), max;

	if (l <= H&&A[l] > A[x]) max = l;
	else max = x;
	if (r <= H&&A[r] > A[max]) max = r;

	if (max != x) {
		int cmp = A[max];
		A[max] = A[x];
		A[x] = cmp;
		maxHeapify(max);
	}
}

int extractMax()
{
	int max = A[1];
	A[1] = A[H];
	H--;

	maxHeapify(1);

	return max;
}

int main()
{
	H = 0;
	char order[20];
	int flg = 1, key;

	while (flg)
	{
		scanf("%s", order);
		switch (order[2])
		{
		case 'd': //end
			flg = 0;
			break;
		case 's': //insert key
			scanf("%d", &key);
			insertKey(++H, key);
			
			break;
		case 't': //extract
			if (H > 0) printf("%d\n", extractMax());			
			break;
		/*case 'i':
			for (int i = 1; i <= H; i++)
				printf(" %d", A[i]);
			printf("\n");
			break;*/
		default:
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 4936
#include<stdio.h>
 
#define S 251
#define N1 -2000000000
#define N2 2000000000
 
struct Node{
  int id;
  int k;
  int pk;
  int lk;
  int rk;
};
 
struct Node T[S];
 
void Print(int);
 
int main(){
   
  int i;
  int n = 0;
   
  scanf("%d",&n);
  
   
  for(i=1;i <= n;i++){
    scanf("%d",&T[i].k);
     
    T[i].id = i;
  }
   
  for(i=1;i <= n;i++){
     
    if((i/2) >= 1){
      T[i].pk = T[i/2].k;
    }
     
    if(2*i >= 1 && 2*i <= n){
      T[i].lk = T[2*i].k;
    }
     
    if((2*i+1) <= n){
      T[i].rk = T[2*i+1].k;
    }
  }
   
  Print(n);
 
return 0;
}
 
void Print(int n){
  int i;
 
  for(i=1;i <= n;i++){
    printf("node %d: key = %d,",T[i].id,T[i].k);
     
    if(i/2 > 0){
      printf(" parent key = %d,",T[i].pk);
    }
     
    if(2*i > 0 && 2*i <= n){
    printf(" left key = %d,",T[i].lk);
    }
     
    if((2*i+1) > 0 && (2*i+1) <= n){
      printf(" right key = %d,",T[i].rk);
    }
    printf(" ");
    printf("\n");
  }
}

Measured memory_bytes: 604
using System;
class ProgramE
    {
        static void Main(string[] args)
        {
            
            //入力
            string input = Console.ReadLine();
            long n = long.Parse(input);

            if( n % 2 == 1)
            {
                Console.WriteLine("0");
                return;
            }

            long count = 0;
            long keta = 1;
            long temp = -1;
 
            while(temp != 0)
            {
                temp = n / (long)(Math.Pow(5,keta)) / 2;
                count += temp;
                keta++;
            }

            Console.WriteLine(count);
            
        }
        
    }

Measured memory_bytes: 11348
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

total = 0
for i in range(N):
    if A[i] < B[i]:
        total += A[i]
        B[i] = B[i] - A[i]
    elif A[i] >= B[i]:
        total += B[i]
        A[i] = A[i] - B[i]
        B[i] = 0
        continue

    if A[i+1] >= B[i]:
        total += B[i]
        A[i+1] = A[i+1] - B[i]
    elif A[i+1] < B[i]:
        total += A[i+1]
        A[i+1] = 0

print(total)

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

vector<int> graph[100010];
vector<int> blocks[100010];
int ccsize[100010];
int cci[100100];
int ans[100010];

int n, m, k;

void dfs(int node, int ccnt){
    cci[node] = ccnt;
    ++ccsize[ccnt];
    for(auto nextt : graph[node]){
        if(cci[nextt]) continue;
        dfs(nextt, ccnt);
    }
}

int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for(int i=1; i<=m; ++i){
        int x, y;
        scanf("%d%d", &x, &y);
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int ccnt = 0;
    for(int i=1; i<=n; ++i){
        if(cci[i]) continue;
        ++ccnt;
        dfs(i, ccnt);
    }
    for(int i=1; i<=n; ++i){
        ans[i] = ccsize[cci[i]] - graph[i].size() - 1;
    }
    for(int i=1; i<=k; ++i){
        int x, y;
        scanf("%d%d", &x, &y);
        if(cci[x] == cci[y]){
            --ans[x];
            --ans[y];
        }
    }
    for(int i=1; i<=n; ++i) printf("%d ", ans[i]);
    printf("\n");
}

Measured memory_bytes: 9856
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define free  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define Fast  ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

bool vowel(char che)
{
    if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y')
        return true;
    else
        return false;
}

const int N = 3e5+5;
const int mod = 1e9+7;
ll a[N], b[N], c[N], d, dp1, dis;
char o;
bool mark[N], h;
string s;
//set <ll> st1, st2;
//deque <int> dq;
//vector <ll> vm, vp, vt[N];
//int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};


int main()
{
    Fast
    ll t, n, m, k = 0, f = 0, sum = 0, ans = 0;
    cin >> n;
    ans = 1;
    ll ans0 = 1;
    ll ans1 = 1;
    ll ans01 = 1;
    for (int i = 0; i < n; i++){
        ans *= 10;
        ans %= mod;
    }
    for (int i = 0; i < n; i++){
        ans01 *= 8;
        ans01 %= mod;
    }
    for (int i = 0; i < n; i++){
        ans1 *= 9;
        ans0 *= 9;
        ans0 %= mod;
        ans1 %= mod;
    }
    if (n == 1)
        cout << 0;
    else
        cout << (ans+mod+mod+mod-ans1-ans0+ans01)%mod;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,a[200005];
map < int , int > pos;
bool check(LL bnd){
	int i,j,k;
	pos.clear();
	pos[0]=0;
	for(i=1;i<n;++i){
		if(a[i]<=a[i-1]){
			pos.erase(pos.upper_bound(a[i]),pos.end());
			map < int , int > ::iterator it=pos.end();
			--it;
			for(j=a[i];j>0;--j){
				if(it->first!=j) break;
				if(it->second<bnd-1ll) break;
				--it;
			}
			if(!j) return 0;
			pos.erase(++it,pos.end());
			++pos[j];
			if(pos[j]>=bnd) return 0;
		}
	}
	return 1;
}
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i) scanf("%d",a+i);
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
    LL low=1ll,high=(LL)1e15,mid;
	while(low<high){
		mid=(low+high)/2ll;
		if(check(mid))
			high=mid;
		else
			low=mid+1;
	}
	printf("%lld\n",low);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

Measured memory_bytes: 1024
module S = Set.Make(struct
  type t = int * int * int
  let compare (x, _, i) (y, _, j) = if x <> y then x - y else i - j
end)

let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let a = Array.init n (fun i -> Scanf.scanf " %d" @@ fun x -> x, 1, i+1) in
  let bc = Array.init m (fun i -> Scanf.scanf " %d %d" @@ fun b c -> (c, b, -i)) in
  let pq =
    let f s (x, c, i) = S.add (x, c, i) s in
    Array.fold_left f (Array.fold_left f S.empty a) bc
  in
  let rec aux tot sc pq =
    let (x, c, _) as p = S.max_elt pq in
    let pq' = S.remove p pq in
    if sc+c >= n then tot + x*(n-sc)
    else aux (tot + x*c) (sc+c) pq'
  in
  aux 0 0 pq |> Printf.printf "%d\n"


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, k; cin >> n >> k;
    int h[n];
    rep(i,n) cin >> h[i];

    int dp[n];
    rep(i,n) dp[i] = INF;
    dp[0] = 0;

    rep(i,n){
        for(int j=1; j<=k; j++){
            if(i-j<0) continue;
            dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4384
def get_int
  gets.chop.to_i
end

def get_ints
  gets.chop.split.map(&:to_i)
end

def get_double
  gets.chop.to_f
end

def get_str
  gets.chop
end

def get_strs
  gets.chop.split
end

def main
  a, b, k = get_ints
  s1 = a - k
  if s1 < 0
    s1 = 0
    s2 = b - (k - a)
    if s2 < 0
      s2 = 0
    end
  else
    s2 = b
  end
  puts "#{s1} #{s2}"
end

if __FILE__ == $0
  main
end



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

using namespace std;

long long gcm(long long a, long b)
{
    if (a == 0)
        return b;
    else
        return gcm(b % a, a);
}

long long lcm(long long a, long long b)
{
    if (a > b)
    {
        swap(a, b);
    }
    return (a * b) / gcm(a, b);
}

int main()
{
    long long a, b;
    cin >> a >> b;
    cout << lcm(a, b);
    return 0;
}

Measured memory_bytes: 256
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
ans = 0
for i in range(N):
  for j in range(i+1,N):
    x = bisect.bisect_left(L,L[i] + L[j])
    ans += x - j - 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    if(n%10==3){
        cout<<"bon"<<endl;
    }else if(n%10==0||n%10==1||n%10==6||n%10==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"hon"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;


	for (int i = 0; i < 1000; i++) {
		string s_;
		if (i >= 100) {
			s_ = to_string(i);
		}
		else if(i >= 10){
			s_ = "0" + to_string(i);
		}
		else if(i >= 0){
			s_ = "00" + to_string(i);

		}
		else {
			s_ = "000";
		}
		
		int n1 = 1000, n2 =1000, n3 =1000;
		for (int j = 0; j < N; j++) {
			if (S[j] == s_[0]) {
				n1 = j;
				break;
			}
		}
		for (int j = n1 +1; j < N; j++) {
			if (S[j] == s_[1]) {
				n2 = j;
				break;
			}
		}
		for (int j = n2+1; j < N; j++) {
			if (S[j] == s_[2]) {
				n3 = j;
				break;
			}
		}
		if (n1 != 1000 && n2 != 1000 && n3 != 1000) {
			ans++;
		}
	}


	cout << ans << endl;
	return 0;


}

Measured memory_bytes: 3684
#include<stdio.h>

int ans;
int use[10];
int s;

void sumint(int n,int sum){
  int i;
  int max;

  if(n==0){
    if(sum == s)ans++;
    return;
  }

  max = 0;
  for(i=0;i<10;i++){
    if(use[i])max = i;
  }

  for(i=max;i<10;i++){
    if(!use[i]){
      use[i] = 1;
      sumint(n-1,sum+i);
      use[i] = 0;
    }
  }
}

int main(void){
  int i;
  int n;

  while(1){
    scanf("%d %d",&n,&s);
    if(!n && !s)break;

    ans = 0;
    for(i=0;i<10;i++)use[i] = 0;

    sumint(n,0);

    printf("%d\n",ans);

  }

  return 0;
}

Measured memory_bytes: 0
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var n = Int32.Parse(Console.ReadLine());
            var a = new List<Int64>();
            for (int i = 0; i < n; i++)
            {
                a.Add(Int64.Parse(Console.ReadLine()));
            }

            Int64 prev = 0;
            Int64 ret = 0;

            for (int i = 0; i < a.Count(); i++)
            {
                ret += (prev + a[i]) / 2;
                prev = a[i] == 0 || (prev + a[i]) % 2 == 0 ? 0 : 1;
            }

            Console.WriteLine(ret);
            Console.Out.Flush();
        }


        static string ReadLine()
        {
            StringBuilder sb = new StringBuilder();
            while (true)
            {
                int ch = Console.Read();
                if (ch == -1) break;
                if (ch == '\r' || ch == '\n')
                {
                    if (ch == '\r') Console.Read();
                    return sb.ToString();
                }
                sb.Append((char)ch);
            }
            if (sb.Length > 0) return sb.ToString();
            return null;
        } 
    }
}

Measured memory_bytes: 8920
#include <iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<ctime>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<tuple>
#include<cassert>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iomanip>
#include<climits>
#include<typeinfo>
#include<utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
double pi = 3.141592653589793238;
using ll = long long;
using namespace std;

ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpcombination[10000][10000];

ll modi = 1000000007;
ll combination(ll n, ll r) {
	if (n == r) { return dpcombination[n][n] = 1; }
	else if (r == 0) { return dpcombination[n][0] = 1; }
	else if (r == 1) { return dpcombination[n][1] = n; }
	else if (dpcombination[n][r]) { return dpcombination[n][r]; }
	else { return dpcombination[n][r] = combination(n - 1, r - 1) % modi + combination(n - 1, r) % modi; }
}

void clockman(int time1) {

	cout << 1.0*(clock() - time1) / CLOCKS_PER_SEC << endl;
	return;
}
//cout << fixed << setprecision(10)

void printVec(std::vector<int> &vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}


int main() {

	ll x;
	cin >> x;
	ll hun = x / 500;
	ll fif = (x - hun * 500) / 5;
	cout << 1000 * hun + fif * 5 << endl;

	return 0;
}


Measured memory_bytes: 3640
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    lis = readInts()
    # 補集合を求めるようなもの
    whole = 3 ** n
    ex = 1
    for x in lis:
        if x % 2 == 0:
            ex *= 2
    print(whole - ex)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5276
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	int mat[3][3];

	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> mat[i][j];
		}
	}

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		int num;
		cin >> num;

		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 3; ++j) {
				if (mat[i][j] == num) {
					mat[i][j] = -1;
				}
			}
		}
	}

	int ans = 0;

	for (int i = 0; i < 3; ++i) {
		if (mat[i][0] == -1 && mat[i][1] == -1 && mat[i][2] == -1) {
			ans = 1;
		}

		if (mat[0][i] == -1 && mat[1][i] == -1 && mat[2][i] == -1) {
			ans = 1;
		}
	}

	if (mat[0][0] == -1 && mat[1][1] == -1 && mat[2][2] == -1) {
		ans = 1;
	}

	if (mat[0][2] == -1 && mat[1][1] == -1 && mat[2][0] == -1) {
		ans = 1;
	}

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


	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll h[1000000];
ll v[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll DP[50][500][500];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll graph[100][100];
ll graphcopy[100][100];
int main() {
	cin>>N>>M;
	rep(i,0,N){
		rep(j,0,N){
			graph[i][j]=INF;
			graphcopy[i][j]=INF;
		}
	}
	rep(i,0,M){
		ll a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		graph[a][b]=c;
		graph[b][a]=c;
		graphcopy[a][b]=c;
		graphcopy[b][a]=c;
	}
	rep(i,0,N){
		rep(j,0,N){
			rep(k,0,N){
				graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k]);
			}
		}
	}
	ans=0;
	rep(i,0,N){
		rep(j,0,N){
			if(graphcopy[i][j]!=INF){
				if(graphcopy[i][j]!=graph[i][j]){
					ans++;
				}
			}
		}
	}
	cout<<ans/2<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n)
    {
        int xn,yn;
        bool map[24][24]={false};
        while(n--)
        {
            int x,y;
            cin>>x>>y;
            map[y][x]=true;
        }
        int m;
        cin>>m;
        yn=10;
        xn=10;
        while(m--)
        {
            char moji;
            int s;
            cin>>moji>>s;
            for(int i=0;i<s;i++)
            {
                if(moji=='N')
                {
                    yn++;
                    if(map[yn][xn])map[yn][xn]=false;
                }
                else if(moji=='S')
                {
                    yn--;
                    if(map[yn][xn])map[yn][xn]=false;
                }
                else if(moji=='E')
                {
                    xn++;
                    if(map[yn][xn])map[yn][xn]=false;
                }
                else
                {
                    xn--;
                    if(map[yn][xn])map[yn][xn]=false;
                }
            }
        }
        bool b=false;
        for(int i=0;i<24;i++)
        {
            for(int j=0;j<24;j++)
            {
                if(map[i][j])
                {
                    b=true;
                    break;
                }
            }
            if(b)break;
        }
        if(b)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 29;
 
int main() {
	string s;
	cin >> s;
	bool getA = false;
	int a, z = 0;
	rep(i, s.size()) {
		if (s[i] == 'A'&& !getA) {
			a = i;
			getA = true;
		}
		if (s[i] == 'Z') z = max(z, i);
	}
	cout << z-a+1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = to - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n, x;
  V<int> m_list;

  cin >> n >> x;
  m_list.resize(n);
  rep(i, n) {
    cin >> m_list[i];
  }
  int left_x = x;
  int min_m = 1000;
  int ans = 0;
  rep(i, n) {
    left_x -= m_list[i];
    min_m = min(min_m, m_list[i]);
    ans++;
  }
  ans += left_x / min_m;

  cout << ans << endl;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
int main(void){
    ll N, X[200005], Xcp[200005];
    scanf("%lld", &N);
    rep(i, 0, N){
        scanf("%lld", X+i);
        Xcp[i] = X[i];
    }
    qsort(X, N, sizeof(ll), cmp);
    rep(i, 0, N){
        if(Xcp[i]<X[N/2])printf("%lld\n", X[N/2]);
        else printf("%lld\n", X[N/2 -1]);
    }
    return 0;
}
int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 5240
import java.util.*
import kotlin.math.*

fun main() {
    val (n, w) = readIntList()
    val weight = MutableList(n) { 0 }
    val value = MutableList(n) { 0 }
    repeat(n) {
        val (tw, tv) = readIntList()
        weight[it] = tw
        value[it] = tv
    }

    val vMax = 100000
    val dp = List(n + 1) { MutableList(vMax + 1) { Long.MAX_VALUE / 2} }
    dp[0][0] = 0L

    for (i in 1..n) {
        for (j in 0..vMax) {
            dp[i][j] = if (j >= value[i - 1]) {
                min(dp[i - 1][j - value[i - 1]] + weight[i - 1], dp[i - 1][j])
            } else {
                dp[i - 1][j]
            }
        }
    }

    var ans = vMax
    while (dp[n][ans] > w) ans--
    println(ans)
}


fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)


Measured memory_bytes: 573116
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int64_t n,k;
  cin>>n>>k;
  std::vector<int64_t> p(n);
  vector<double> q(n-k+1,0);
  for (int i = 0; i < n; ++i)
  {
    cin>>p[i];
  }
  
  for (int i = 0; i < k; ++i)
  {
    q[0]+=(p[i]+1.0)/2.0;
  }
  for (int i = 0; i < n-k; ++i)
  {
    q[i+1]=q[i]-(p[i]+1.0)/2.0+(p[i+k]+1.0)/2.0;
  }
  cout<<fixed;
  cout<<setprecision(20)<<*max_element(q.begin(), q.end());

}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    String op = sc.next();
    int B = sc.nextInt();
    if(op.equals("+")){
      System.out.println(A+B);
    }else{
      System.out.println(A-B);
    }
  }
}

Measured memory_bytes: 21844
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

lis = []
for i in range(2):
    lis.append(I())
print(6-sum(lis))


Measured memory_bytes: 5600
n = gets.to_i
tree = Struct.new(:parent, :children)
node = Array.new(n) {tree.new}
n.times do
  ar = gets.split.map(&:to_i)
  node[ar[0]].children = ar[1..-1]
  node[ar[0]].parent = -1
end

node.each_with_index do |nd, i|
  nd.children.each {|child| node[child].parent = i unless child == -1}
end

root_index = 0
node.each_with_index {|nd, i| root_index = i if nd.parent == -1}

preorder = ->(root) {
  @result << root
  a = node[root].children[0]
  preorder.(a) unless a == -1
  a = node[root].children[1]
  preorder.(a) unless a == -1
}

inorder = ->(root) {
  a = node[root].children[0]
  inorder.(a) unless a == -1
  @result << root
  a = node[root].children[1]
  inorder.(a) unless a == -1
}

postorder = ->(root) {
  a = node[root].children[0]
  postorder.(a) unless a == -1
  a = node[root].children[1]
  postorder.(a) unless a == -1
  @result << root
}

def putout(title)
  @result = []
  puts title
  yield
  puts @result.map {|x| " " + x.to_s}.join
end

putout("Preorder")  {preorder .(root_index)}
putout("Inorder")   {inorder  .(root_index)}
putout("Postorder") {postorder.(root_index)}


Measured memory_bytes: 6880
s = input()
n = len(s) #length s
aa = ['.'] * (n + 1)

if s[0] == '<':
  aa[0] = 0
if s[-1] == '>':
  aa[-1] = 0

for i in range(n-1):
  if s[i] ==  '>' and s[i+1] == '<':
    aa[i+1] = 0 
  elif s[i] == '<' and s[i+1] == '>':
    aa[i+1] = n
    
z = [i for i,x in enumerate(aa) if x == 0]
m = [i for i, x in enumerate(aa) if x == n]


for i in range(len(z)-1):
  aa[m[i]] = max(m[i]-z[i], z[i+1]-m[i])
  aa[m[i]+1] = z[i+1]-m[i]-1
  for j in range(z[i]+1, m[i]):
    aa[j] = aa[j-1] +1
  for k in range(m[i]+2,z[i+1]):
    
    aa[k] = aa[k-1]-1
for i in range(z[-1], n+1):
  if aa[i] == '.':
    aa[i] = aa[i-1]+1
for i in range(z[0]):
  if aa[i] == '.':
    aa[i] = z[0] - i
    

print(sum(aa))

Measured memory_bytes: 28844
x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(x[int(input()) - 1])

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    int a,b = 1;
    int ans,line = 0;
    
    while(std::cin >>a>>b){
        ans = a + b;
        ans /= 10;
        if(ans  <= 9){
            ans = 2;
        }
        else if(ans <= 99){
            ans = 3;
        }
        else if(ans <= 999){
            ans = 4;
        }
        else if(ans <= 9999){
            ans = 5;
        }
        else if(ans <= 99999){
            ans = 6;
        }
        else if(ans <= 999999){
            ans = 7;
        }
        std::cout << ans << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3064
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    a = [I() for _ in range(N)]

    # 1種類で奇数個なら自分の勝ち
    # 奇数個のりんごを1個食べて偶数個にする
    if len([i for i in a if i % 2 == 1]) == 0:
        print('second')
    else:
        print('first')

if __name__ == '__main__':
    resolve()


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

using namespace std;

typedef long long ll;

bool is_prime(int x) {
  if(x == 2) return true;
  if(x == 1 || x % 2 == 0) return false;
  for (int i = 3; i <= sqrt(x); i += 2) {
    if(x % i == 0) return false;
  }
  return true;
}

int main() {
  int a, d, n;
  while(cin >> a >> d >> n, n) {
    int i = 0;
    int cnt = 0;
    while(cnt != n) {
      if(is_prime(a + i*d)) {
        cnt++;
      }
      i++;
    }
    cout << a + (i-1)*d << endl;
  }
}

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

int min(int a, int b){
        if(a < b){
            return a;
        }
    return b;
}


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

    int ans1 = 0, ans2 = 0;
    //偶数番目で１であることと奇数番目で０であることは同じであることから
    //変数は2つでよい
    for(int i = 0; i < s.length(); i++){
        //偶数番目
        if(i % 2){
            if(s[i] == '0'){
                ans1++;
            }else if(s[i] == '1'){
                ans2++;
            }
        //奇数番目
        }else{
            if(s[i] == '0'){
                ans2++;
            }else if(s[i] == '1'){
                ans1++;
            }
        }

        
    }


    //何枚のタイルを塗り替えるかを聞かれてるので
    //小さいほうが塗り替えられる。
    cout << min(ans1,ans2) << endl;

    return 0;
}

Measured memory_bytes: 512
#include <cstdio>

long long const A_MAX = 10000000000001001;
int const I = 50;

long long K;

long long b[I + 1];

int main() {
  scanf("%lld", &K);

  for (int i = 0; i < 50; i++) {
    b[i] = i;
  }

  long long x = K / I;
  for (int i = 0; i < I; i++) {
    b[i] += x;
  }
  long long y = K % I;
  for (int i = 0; i < y; i++) {
    int min_idx = -1;
    long long min = A_MAX;
    for (int j = 0; j < I; j++) {
      if (b[j] < min) {
        min = b[j];
        min_idx = j;
      }
      b[j]--;
    }
    b[min_idx] += I + 1;
  }

  printf("%d\n", I);
  printf("%lld", b[0]);
  for (int i = 1; i < I; i++) {
    printf(" %lld", b[i]);
  }
  printf("\n");
}


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

int main() {
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for (int i = 0; i <= K; i++){
        for (int j = 0; j<= K; j++){
            if ((0 <= S-i-j) && (S-i-j <= K)) ans++;
        }
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		long long m=n/i;
		ans+=i*m*(m+1)/2;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		// スペース区切りの整数の入力
		int N = sc.nextInt();
		
		int jyuni_m = 1000000000;
		int jyuni_n = 0;
		int ten_m = 0;
		int ten_n = 0;
		for(int i = 0;i < N;i ++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(jyuni_m > a){
				jyuni_m = a;
				ten_m = b;
			}
			if(jyuni_n < a){
				jyuni_n = a;
				ten_n = b;
			}
		}
		int wk = 0;
		int ans = 0;
//*		if ( jyuni_m != 1){
//*			wk = jyuni_m - 1;
//*		}
//*		int ans = jyuni_n + wk;
//*	
//*		if (ten_n != 0){
			ans =  jyuni_n + ten_n;
//*		}
//*			System.out.println(jyuni_m);
		//*			System.out.println(ten_m);
		//*System.out.println(jyuni_n);
		//*System.out.println(ten_n);
			System.out.println(ans);

	}
}


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

int main() {
  int n,k; cin>>n>>k;
  vector<double> v(n);
  cout << fixed << setprecision(6);
  rep(i,n){
    cin>>v.at(i);
    v.at(i)=(v.at(i)+1)/2;
    //cout<<v.at(i)<<" ";
  }
  double ans=0;
  rep(i,k){
    ans+=v.at(i);}
  double ansm=ans;
  rep(i,n-k){  
    ans=ans-v.at(i)+v.at(i+k);
    ansm=max(ans,ansm);
  }
  
  
  cout<<ansm;
}
      

Measured memory_bytes: 1792
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	counter := make([]int64, n)
	for i := 0; i < n; i++ {
		d := getNextInt(scanner)
		if i == 0 && d != 0 {
			fmt.Println(0)
			return
		}
		counter[d]++
	}

	ans := counter[0]
	if ans != 1 {
		fmt.Println(0)
		return
	}
	var i int
	for i = 1; i < n && counter[i] > 0; i++ {
		for j := 0; j < int(counter[i]); j++ {
			ans = (ans * counter[i-1]) % 998244353
		}
	}
	for j := i; j < n; j++ {
		if counter[j] > 0 {
			fmt.Println(0)
			return
		}
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}


Measured memory_bytes: 2432