akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define int ll

string ans;

signed main(){
  int n;
  cin>>n;
  if(n==0){
    cout<<0<<endl;
    return 0;
  }

  int m=-2;

  while(abs(2*n)>=abs(m)){
  
    if(abs(n)%abs(m)==0) ans='0'+ans;
    else{
      n+=m/2;
      ans='1'+ans;
    }
    m*=-2;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e4)
#define pi acos(-1)
using namespace std;



int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    if(a == b)
        puts("Draw\n");
    else
    {
        if(a == 1)
            puts("Alice\n");
        else if(b == 1)
            puts("Bob\n");
        else if(a > b)
            puts("Alice\n");
        else
            puts("Bob\n");
    }
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string


def solve(N):
    N = str(N)
    ans = 0
    if N == len(N) * '9':
        ans = 9 * len(N)
    elif len(N) == 1:
        ans = int(N)
    elif N[1:] == (len(N)-1) * '9':
        ans = sum(map(int, list(N)))

    elif N[0] == '1':
        ans = 9 * (len(N) - 1)
    else:
        ans = int(N[0]) - 1 + 9 * (len(N)-1)
    return ans

N = input()
print(solve(N))

# assert(solve(100) == 18)
# assert(solve(9995) == 35)
# assert(solve(3141592653589793) == 137)
# assert(solve(1) == 1)
# assert(solve(9) == 9)
# assert(solve(10) == 9)
# assert(solve(18) == 9)
# assert(solve(19) == 10) # corner
# assert(solve(20) == 10)
# assert(solve(25) == 10)
# assert(solve(29) == 11)
# assert(solve(98) == 17)
# assert(solve(99) == 18)
# assert(solve(100) == 18)
# assert(solve(199) == 19)

# def straight(N):
#     N = int(N)
#     ans = 0
#     while N > 0:
#         ans = max(ans, sum(map(int, list(str(N)))))
#         N -= 1
#     return ans

# for i in range(1, 10000):
#     assert(straight(N) == solve(N))


Measured memory_bytes: 8004
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)
#define F first
#define S second
typedef pair<int,int> Pi;
#define INF 1 << 29
#define pb push_back

inline void chmin(int &a, int b) {
  a = min(a,b);
}

inline void chmax(int &a, int b) {
  a = max(a,b);
}

int main()
{
  int N, K;
  while(cin >> N >> K,N || K) {
    int Q, A, B, C;
    int path[105][105];
    fill(path[0],path[105],INF);
    Rep(i,105) {
      path[i][i] = 0;
    }
    while(K--) {
      cin >> Q >> A >> B;--A,--B;
      if(Q) {
	cin >> C;
	chmin(path[A][B],C);
	chmin(path[B][A],C);
        Rep(i,N)Rep(j,N) {
	  chmin(path[i][j],min(path[i][A] + path[A][j],path[i][B] + path[B][j]));
	  path[j][i] = path[i][j];
	}
      }else {
	if(path[A][B] == INF) {
	  cout << -1 << endl;
	} else {
	  cout << path[A][B] << endl;
	}	
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3040
#include <iostream>
using namespace std;
int main(void){
    long long n,m,c=0;
    cin>>n>>m;
    if(n*2<=m){
        c=n;
        m-=n*2;
        c+=m/4;
    }else{
        c=m/2;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b, c, x, y, out;
	cin >> a >> b >> c >> x >> y;
	out = a * x + b * y;
	for (int i = 1; i <= max(x, y); i++) {
		out = min(out, c*i * 2 + max(0, x - i)*a + max(0, y - i)*b);

	}
	cout << out << endl;
}

Measured memory_bytes: 256
odd_num_0 = 0
eve_num_0 = 0
S = input()
N = len(S)
for idx, s in enumerate(S):
  if s == '0':
    if idx%2 == 0: eve_num_0 += 1
    else: odd_num_0 += 1

if N%2 == 1:eve_num = N//2+1
else:eve_num = N//2
odd_num = N//2

print(min(eve_num-eve_num_0+odd_num_0,odd_num-odd_num_0+eve_num_0))

Measured memory_bytes: 3188
import java.util.*;
import java.io.*;
import java.text.*;

class Main {

	void solve() {

		String s = in.next();
		int y = Integer.parseInt(s.substring(0, 4));
		int m = Integer.parseInt(s.substring(5, 7));
		int d = Integer.parseInt(s.substring(8, 10));
		
		if (y > 2019) {
			out.println("TBD");
			return;
		}
		
		if (m > 4) {
			out.println("TBD");
			return;
		}
		
		out.println("Heisei");
		
	}
	
	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
//#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000000007 
#define MAXN   200005
int main()
{
ios_base::sync_with_stdio(false);
 cin.tie(0);
 cout.tie(0);
 cout.precision(15);
ll int n;
cin>>n;
vi a(n),b(n),c(n);
rep(i,0,n)
cin>>a[i]>>b[i]>>c[i];
ll int dp[n][3];
dp[0][0]=a[0];
dp[0][1]=b[0];
dp[0][2]=c[0];
rep(i,1,n)
{
dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];	
dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
}
cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}


Measured memory_bytes: 4992
S = input()
ans1 = 0
ans2 = 0
frag = True
for s in S:
  if s == '1' and frag:
    ans1 += 1
  elif frag:
    ans2 += 1
  elif s == '0':
    ans1 += 1
  else:
    ans2 += 1
  frag = not frag
print(min(ans1,ans2))

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

int main()
{
  int a, b, c, tmp;
  cin >> a >> b >> c;

  if (a > b)
  {
    tmp = a;
    a = b;
    b = tmp;
  }
  if (b > c)
  {
    tmp = b;
    b = c;
    c = tmp;
  }

  if (a > b)
  {
    tmp = a;
    a = b;
    b = tmp;
  }

  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <vector>
#include <cctype>
using namespace std;
typedef long long ll;

int main( void ) {
    string s;
    int f[26] = {0};

    while( cin >> s ) {
        for( int i = 0; i < s.length(); ++i ) {
            if( isalpha( s[i] ) ) {
                if( s[i] >= 'A' && s[i] <= 'Z' ) f[s[i] - 'A']++;
                else f[s[i] - 'a']++;
            }
        }
    }
    for( int i = 0; i < 26; ++i ) {
        cout << char('a' + i) << " : " << f[i] << '\n';
    }
    return 0;
}



Measured memory_bytes: 3176
def gathering_children(S: str)->list:
    N = len(S)
    res = [0] * N

    arr = list(S)

    even, odds = 0, 0
    for i, s in enumerate(arr):
        if s == 'R':
            if i % 2 == 0:
                even += 1
            else:
                odds += 1
        else:  # s == 'L'
            if i % 2 == 0:
                res[i] += even
                res[i-1] += odds
            else:
                res[i] += odds
                res[i-1] += even
            even, odds = 0, 0

    even, odds = 0, 0
    for i, s in enumerate(reversed(arr)):
        if s == 'L':
            if i % 2 == 0:
                even += 1
            else:
                odds += 1
        else:  # s == 'R'
            if i % 2 == 0:
                res[N-i-1] += even
                res[N-i] += odds
            else:
                res[N-i-1] += odds
                res[N-i] += even
            even, odds = 0, 0

    return res


if __name__ == "__main__":
    S = input()

    ans = gathering_children(S)
    print(' '.join(map(str, ans)))


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


struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}

	double x,y;
};

typedef Point Vector;
typedef vector<Point> Polygon;

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

bool calcGaiseki(Point left,Point base, Point right){
	double gaiseki = (left.x-base.x)*(right.y - base.y)-(left.y-base.y)*(right.x-base.x);
	if(gaiseki < -0.00000001)return false;
	else{
		return true;
	}
}

double calc_S(Polygon g){

	int N = g.size();
	double ret = 0;

	for(int i = 0; i < g.size(); i++){
		ret += cross(g[i],g[(i+1)%N]);
	}
	return ret/2.0;
}

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

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -1;
static const int ON_SEGMENT = 0;

int ccw(Point p0,Point p1,Point p2){

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)return CLOCKWISE;
	if(dot(a,b) < -EPS)return ONLINE_BACK;
	if(a.norm() < b.norm())return ONLINE_FRONT;

	return ON_SEGMENT;
}

//http://www.prefield.com/algorithm/geometry/convex_hull.html
Polygon ConvexHull(Polygon V)
{
  int N = V.size(), k = 0;

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

  Polygon ret(2*N);
  for (int i = 0; i < N; ret[k++] = V[i++]) // lower-hull
  while (k >= 2 && ccw(ret[k-2], ret[k-1], V[i]) <= 0) --k;
  for (int i = N-2, t = k+1; i >= 0; ret[k++] = V[i--]) // upper-hull
    while (k >= t && ccw(ret[k-2], ret[k-1], V[i]) <= 0) --k;

  ret.resize(k-1);

  return ret;
}

bool is_ok(Polygon p){

	double pre_S = -1.0,tmp_S;

	for(int i = 0; i < p.size(); i++){
		if(i < 2)continue;

		Polygon p2;
		for(int k = 0; k <= i; k++){
			p2.push_back(p[k]);
		}

		p2 = ConvexHull(p2);

		tmp_S = calc_S(p2);

		if(fabs(tmp_S-pre_S) < EPS){
			return false;
		}
		pre_S = tmp_S;
	}
	return true;
}


int main(){

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

	Polygon p;
	double tmp_x,tmp_y;

	for(int loop = 0; loop < N; loop++){
		scanf("%lf %lf",&tmp_x,&tmp_y);
		p.push_back(Point(tmp_x,tmp_y));
	}

	if(!is_ok(p)){
		printf("Impossible\n");
		return 0;
	}

	reverse(p.begin(),p.end());

	if(!is_ok(p)){
		printf("Impossible\n");
		return 0;
	}

	printf("Possible\n");

	return 0;
}



Measured memory_bytes: 3368
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

/*
func readLine(r *bufio.Reader) []byte {
	buf := make([]byte, 0, 1024)
	for {
		l, p, e := r.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return buf
}
	r := bufio.NewReaderSize(os.Stdin, 4096)
*/

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

var dp [3001][3001]int

func solve(n, f, t, N int, a []int) int {
	if n == N {
		return 0
	}
	if dp[f][t] != -1 {
		return dp[f][t]
	}
	ret1 := a[f] - solve(n+1, f+1, t, N, a)
	ret2 := a[t] - solve(n+1, f, t-1, N, a)

	ret := max(ret1, ret2)
	dp[f][t] = ret
	return (ret)
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	for i := 0; i <= 3000; i++ {
		for j := 0; j <= 3000; j++ {
			dp[i][j] = -1
		}
	}

	out(solve(0, 0, N-1, N, a))

}


Measured memory_bytes: 71552
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int t,i,ar[200000],it1,it2,z;
    char c,p;
    
    cin>>t;
    for (i=0;i<t;++i){
 
        cin>>c;
        z=(int)c;
        ar[i]=z;
 
    }
    for (i=0;i<t-1;++i){
 
        it1=ar[i];
        it2=ar[i+1];
        if (it1 == 84  &&  it2 == 84)ar[i+1]=84;
        else if (it1 == 84  &&  it2 == 70)ar[i+1]=70;
        else if (it1 == 70  &&  it2 == 84)ar[i+1]=84;
        else if (it1 == 70  &&  it2 == 70)ar[i+1]=84;
 
 
    }
    printf ("%c\n",ar[t-1]);
 
    return 0;
}


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

using namespace std;
int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int counter = 0;
    for (size_t i = 0; i <= a; i++)
    {
        for (size_t j = 0; j <= b; j++)
        {
            int y = (x-(i*500 + j*100))/50;
            if(0<=y && y <= c) counter ++;
        }
    }
    
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define _overload1(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload1(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _overload2(_1, _2, _3, name, ...) name
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (ll i = (ll)(a - 1); i >= (ll)(b); --i)
#define rrep(...) _overload2(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++)
#define all(x) (x).begin(), (x).end()

const double EPS = 1e-15, PI = acos(-1);
const ll INF = 1'010'000'000'000'000'017LL;

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

/*
二分探索

bool binary_search(vec.begin(), vec.end(), key)

auto itr = lower_bound(vec.begin(), vec.end(), key);  key以上二分探索
idx_lower = distance(vec.begin(), itr);

auto itr = upper_bound(vec.begin(), vec.end(), key);  keyより大きいを二分探索
idx_upper = distance(vec.begin(), itr);

iter != vec.end() なら存在　*iter で値取得
*/

void Main() {
  ll a, b , c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		Scanner scan = new Scanner(System.in);
		int x= scan.nextInt();
		int y= scan.nextInt();
		int z= scan.nextInt();
		scan.close();
		System.out.print(z+" "+x+" "+y);
	}
}


Measured memory_bytes: 27040
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
import std.math, std.format;

alias real F;

F area(F x1, F y1, F x2, F y2, F x3, F y3)
{
    return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2;
}
F distance(F x1, F y1, F x2, F y2)
{
    return hypot(x1-x2,y1-y2);
}
F cross(F x1, F y1, F x2, F y2)
{
    return x1*y2-y1*x2;
}
F norm2(F x, F y)
{
    return x*x+y*y;
}

string r3(F v){ return format("%.3f",round(v*10^^3)/10^^3+0); }

void main()
{
    foreach(_;0..readln().chomp().to!int())
    {
        auto m = readln().split().map!(to!F);
        immutable x1=m[0], y1=m[1], x2=m[2], y2=m[3], x3=m[4], y3=m[5];
        immutable ax=2*(x2-x1), ay=2*(x3-x1);
        immutable bx=2*(y2-y1), by=2*(y3-y1);
        immutable cx=norm2(x1,y1)-norm2(x2,y2),
                  cy=norm2(x1,y1)-norm2(x3,y3);
        immutable x = cross(bx,by,cx,cy)/cross(ax,ay,bx,by);
        immutable y = cross(cx,cy,ax,ay)/cross(ax,ay,bx,by);
        immutable a = distance(x2,y2,x3,y3);
        immutable b = distance(x3,y3,x1,y1);
        immutable c = distance(x1,y1,x2,y2);
        immutable R = a*b*c/(area(x1,y1,x2,y2,x3,y3)*4);
        writeln(r3(x)," ",r3(y)," ",r3(R));
    }
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K - A <= 0) cout << K;
	else {
		if (K - A - B <= 0) cout << A;
		else cout << A - (K - A - B);
	}
}

Measured memory_bytes: 3652
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

#include <bits/stdc++.h>
using namespace std;



int main() {
    int N;
    cin >> N;
    vector<int> v(N+1,0);
    int val;
    for(int i=2; i<=N; i++){
        cin >> val;
        v.at(val)++; 
    }

    for(int i=1; i<=N; i++){
        cout << v.at(i) << endl;
    }
}

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

using namespace std;

int judge(char c){
  int a;
  switch (c){
  case 'y':
  case 'h':
  case 'n':
  case 'u':
  case 'j':
  case 'm':
  case 'i':
  case 'k':
  case 'o':
  case 'l':
  case 'p':
    a=1;
    break;
  default:
    a=0;
    break;
  }
  return a;
}

int main() {
  string s;
  while(cin >> s && s!="#"){
    int cnt=0,b=judge(s[0]);
    for(int i=0;i<s.size();++i){
      if(judge(s[i])!=b) {
	cnt++;
	b=judge(s[i]);
      }
    }
    cout << cnt << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
template<typename T> void chkmax(T &x,T y){x=x>y?x:y;}
int mp[3010][3010];long long dp[3010][3010][4];

int main(){
	int r,c,k;read(r);read(c);read(k);
	rep(i,1,k){int ri,ci,vi;read(ri);read(ci);read(vi);mp[ri][ci]=vi;}
	
	dp[1][1][1]=mp[1][1];
	rep(i,1,r){
		rep(j,1,c){
			rep(l,0,3){
				if(i>=1)chkmax(dp[i][j][l],dp[i-1][j][l]);
				if(j>=1)chkmax(dp[i][j][l],dp[i][j-1][l]);
			}
			rep(l,1,3){
				if(j>=1)chkmax(dp[i][j][l],dp[i][j-1][l-1]+mp[i][j]);
			}
			if(i>=1){
				rep(l,0,3)chkmax(dp[i][j][1],dp[i-1][j][l]+mp[i][j]);
			}
		}
	}
	long long ans=0;
	rep(l,0,3)chkmax(ans,dp[r][c][l]);
	write(ans);
	return 0;
}


Measured memory_bytes: 321004
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=500005;
namespace{
	const int mod[2]={19260817,998244353};
	int p[N][2],rp[N][2];
	int power(int x,int t){
		return x>=0?p[x][t]:rp[-x][t];
	}
	int power(int x,int p,int mod){
		int res=1;
		for(;p;p>>=1,x=(ll)x*x%mod)
			if(p&1)res=(ll)res*x%mod;
		return res;
	}
	void init(int n){
		int A=2333,B=power(A,mod[0]-2,mod[0]);
		int C=19260817,D=power(C,mod[1]-2,mod[1]);
		p[0][0]=p[0][1]=rp[0][0]=rp[0][1]=1;
		rep(i,1,n){
			p[i][0]=(ll)p[i-1][0]*A%mod[0];
			rp[i][0]=(ll)rp[i-1][0]*B%mod[0];
			p[i][1]=(ll)p[i-1][1]*C%mod[1];
			rp[i][1]=(ll)rp[i-1][1]*D%mod[1];
		}
	}
}

int v[N][2],d[N],n;
map<pii,int> cnt;
char s[N];
ll ans;

int main(){
	read(n),init(n);
	scanf("%s",s+1);
	rep(i,1,n){
		v[i][0]=v[i-1][0];
		v[i][1]=v[i-1][1];
		d[i]=d[i-1];
		if(s[i]=='<')d[i]--;
		else if(s[i]=='>')d[i]++;
		else if(s[i]=='+')
			REP(t,2)v[i][t]=(v[i][t]+power(d[i],t))%mod[t];
		else
			REP(t,2)v[i][t]=(v[i][t]+mod[t]-power(d[i],t))%mod[t];
	}
	per(i,n-1,0){
		cnt[mp(v[i+1][0],v[i+1][1])]++;
		int A=(v[i][0]+(ll)power(d[i],0)*v[n][0])%mod[0];
		int B=(v[i][1]+(ll)power(d[i],1)*v[n][1])%mod[1];
		ans+=cnt[mp(A,B)];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 43008
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

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

	for (int i = 1; i <= 9; ++i)
	{
		if ((n / i) <= 9 && n%i == 0)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>

const double PI = 3.14159265359;

double sqrt(double number, const int& SIGNIFICANT_DIGITS);

int main(){
	int a, b, c;
	double h;
	double S;
	double L;

	std::cin >> a >> b >> c;

	h = b * sin(PI * c / 180);
	S = a * h / 2;
	L = a + b + sqrt((h * h + (a - b*cos(PI * c / 180)) * (a - b*cos(PI * c / 180))), 10);

	printf("%0.6f\n%0.6f\n%0.6f\n", S,L, h);
	return 0;
}

double sqrt(double number, const int& SIGNIFICANT_DIGITS){
	double result = 0;
	double digitsOffset = 1;

	for (int i = 0; i < SIGNIFICANT_DIGITS + 1; i++){
		while (number >= (result + digitsOffset) * (result + digitsOffset)){
			result += digitsOffset;
		}
		digitsOffset /= 10;
	}
	return result;
}


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

a.sort()
color = []
other = 0
for i in a:
    if i < 400 * 1:
        color.append('1')
    elif i < 400 * 2:
        color.append('2')
    elif i < 400 * 3:
        color.append('3')
    elif i < 400 * 4:
        color.append('4')
    elif i < 400 * 5:
        color.append('5')
    elif i < 400 * 6:
        color.append('6')
    elif i < 400 * 7:
        color.append('7')
    elif i < 400 * 8:
        color.append('8')
    else:
        other += 1
max_ans = len(set(color)) + other
min_ans = len(set(color))
if min_ans == 0 and other != 0:
    min_ans = 1
print(min_ans, max_ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int x, n;
    cin >> x >> n;
    if (n == 0) {cout << x << endl; return 0;}
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(), p.end());
    int min_dif = INF, j = 0, sign;
    rep(i,102) {
        if (p[j] == i) {
            j++;
            continue;
        }
        if (min_dif > abs(i-x)) {
            min_dif = abs(i-x);
            if (i-x == 0) {sign = 0; break;}
            sign = abs(i-x) / (i-x);
        }
        
    }
    cout << x + sign*min_dif << endl;
    return 0;
}

Measured memory_bytes: 3616
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main(void){
    ll N; cin >> N;
    if (N % 2 == 0)
        cout << N << " " << N << " " << (N / 2) << endl;
    else{
        for (int h = 1; h <= 3500; ++h){
            for (int n = 1; n <= 3500; ++n){
                ll den = N * h * n;
                ll num = 4 * h * n - N * (h + n);
                if (num <= 0) continue;
                if (den % num) continue;
                cout << h << " " << n << " " << (den / num) << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
struct Card{
	char suit,value;
};
//冒泡排序法
void bubbleSort(struct Card A[],int N){
	bool flag=1;
	for(int i=0;i<N-1;i++){
		flag=0;
		for(int j=N-1;j>=i+1;j--){
			if(A[j].value<A[j-1].value){
				swap(A[j],A[j-1]);
				flag=1;
			}
		}
	}
} 
//选择排序法
void selectionSort(struct Card A[],int N){
	int minj;
	for(int i=0;i<N-1;i++){
		minj=i;
		for(int j=i;j<N;j++){
			if(A[j].value<A[minj].value)
				minj=j;
		}
		swap(A[i],A[minj]);
	}
} 
bool isStable(struct Card C1[],struct Card C2[],int N){
	for(int i=0;i<N;i++){
		if(C1[i].suit!=C2[i].suit)
			return false;
	}
	return true;
}
void output(struct Card A[],int N){
	for(int i=0;i<N;i++){
		if(i)cout<<" ";
		cout<<A[i].suit<<A[i].value;
	}
	cout<<endl;
}
int main(){
	Card C1[100],C2[100];
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>C1[i].suit>>C1[i].value;
	}
	for(int i=0;i<N;i++)C2[i]=C1[i];
	bubbleSort(C1,N);
	selectionSort(C2,N);
	output(C1,N);
	cout<<"Stable"<<endl;
	output(C2,N);
	if(isStable(C1,C2,N)){
		cout<<"Stable"<<endl;
	}
	else{
		cout<<"Not stable"<<endl;
	} 
	return 0;
}


Measured memory_bytes: 3076
def main():
    islands, request_num = map(int, input().split())
    demolition = []
    requests = []
    for _ in range(request_num):
        requests.append(list(map(int, input().split())))
    requests.sort(key=lambda x: x[1], reverse=False)
    for begin, end in requests:
        if 0 < len(demolition) and begin <= demolition[-1] < end:
            continue
        else:
            demolition.append(end - 1)
    print(len(demolition))


if __name__ == '__main__':
    main()



Measured memory_bytes: 29088
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
    }
    let len = s.len();
    let mut ans = 0;
    for i in 1..(len - 1) {
        if (len - i) % 2 == 1 {
            continue;
        }
        if &s[0..(((len - i) / 2) - 1)] == &s[((len - i) / 2)..(len - i - 1)] {
            ans = len - i;
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC102
{
    class ProblemB
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int max = 0;
            for(int i = 0; i < N; i++)
            {
                for(int j = 0; j < N; j++)
                {
                    int dif = Math.Abs(A[j] - A[i]);
                    if (dif > max)
                    {
                        max = dif;
                    }
                }
            }
            Console.WriteLine(max);
        }
    }
}


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

namespace ForATCODER
{
    public class Program
    {
        public static void Main(string[] args)
        {
            long res = 0;
            long n = s2l(Console.ReadLine());
            long[] an = s2larray(Console.ReadLine().Split(' '));
            //load {
            int[] l = new int[n];
            for (int i = 0; i < n-1 ; i++)
            {
                l[an[i]]++;
            }
            for (int i = 1; i < n; i++) { RESULT(l[i]); }
            RESULT(l[0]);
        }
    
    



    
      
      
        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static long s2l(String s)
        {
            return Convert.ToInt64(s);
        }
        static void RESULT(double res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(long res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(ulong res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(int res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(String res)
        {
            Console.WriteLine(res);
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine();
            }
            return res;
        }

        static int[] s2iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
        static long[] s2larray(String[] src)
        {
            int len = src.Length;
            long[] res = new long[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt64(src[i]);
            }
            return res;
        }
    }
}


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

typedef pair<int,int>P;

int main(){
  int N;
  cin >> N;
  vector<P>vec;
  for(int i = 0 ; i < N ; i++){
    int x; cin >> x;
    vec.push_back(P(x,i));
  }

  vector<P>pre_vec = vec;
  sort(vec.begin(),vec.end());
  map<int,int>pos;
  for(int i = 0 ; i < N ; i++){
    pos[vec[i].second] = i;
  }

  for(int i = 0 ; i < N ; i++){
    int med = (N + 1)/2;
    if(pos[i] >= med)med--;
    cout << vec[med].first << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<vector<int> > mat(n + 5, vector<int>(n + 5, 0));
  for (int i = 0; i < n; ++i) {
    int v = -1, k = -1, u = -1;
    fscanf(stdin, "%d %d", &v, &k);
    for (int j = 0; j < k; ++j) {
      fscanf(stdin, "%d", &u);
      mat[v][u] = 1;
    }
  }
  vector<int> cost(n + 5, -1);
  queue<int> que;
  cost[1] = 0;
  que.push(1);
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int u = 1; u <= n; ++u) {
      if (mat[v][u] && cost[u] == -1) {
        cost[u] = cost[v] + 1;
        que.push(u);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    fprintf(stdout, "%d %d\n", i, cost[i]);
  }
  return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9
#define vint vector<int>

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

int main(){
    int n, m;
    cin >> n >> m;
    if(n == 1 and m == 0){
        p(0);
        return 0;
    }
    vint num(n, -1);
    int s, c;
    REP(i, 0, m){
        cin >> s >> c;
        if(num[s-1] != -1 and num[s-1] != c){
            p(-1);
            return 0;
        } else {
            num[s-1] = c;
        }
    }

    if(num[0] == 0 and n != 1){
        p(-1);
        return 0;
    } else if (num[0] == -1){
        num[0] = 1;
    }

    int ans = 0;
    REP(i, 0, n) {
        if(num[i] == -1){num[i] = 0;}
        ans += num[i]*pow(10, n-i-1);
    }
    p(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(){
  int n;
  cin >> n;
  ll sum=0;
  vector<pair<ll,ll>>vec;
  rep(i,n){
    ll a;
    cin >> a;
    vec.push_back(make_pair(i,a));
  }
  rep(i,n){
    if(i<n-1){
      sum+=vec[i].second/2;
      if(vec[i].second%2==1 && vec[i+1].second){
        sum++;
        vec[i+1].second--;
      }
    }
    else{
      sum+=vec[i].second/2;
    }
    
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VB=vector<bool>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}


void Main()
{
	ll n,m,l; ll res=0;
	string s,t,u; string sres="No or NO";

	rep(i,5) {
		cin >> n;
		if(n==0) print(i+1);
	}
	return;
}

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


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

const double PI=acos(-1.0);

int main()
{
    int i,j,k;
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int a[n+1],b[m+1];
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<m;i++)cin>>b[i];

    a[n]=x;b[m]=y;
    sort(a,a+n+1);
    sort(b,b+m+1);

    if(b[0]>a[n])cout<<"No War\n";
    else cout<<"War\n";
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

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

typedef long long int64;
typedef pair<int64, int64> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
int64 a[N];
int c[N];

void add(int x, int y, int n) {
  for (; x <= n; x += x & -x) {
    c[x] += y;
  }
}

int query(int x) {
  int ret = 0;
  for (; x; x -= x & -x) {
    ret += c[x];
  }
  return ret;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  a[0] = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    a[i] = a[i - 1] + x;
  }
  vector<int64> A;
  for (int i = 0; i <= n; ++i) {
    a[i] -= (int64)i * m;
    A.push_back(a[i]);
  }
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  for (int i = 0; i <= n; ++i) {
    a[i] = lower_bound(A.begin(), A.end(), a[i]) - A.begin();
    a[i] = A.size() - a[i];
  }
  int64 ret = 0;
  for (int i = n; i >= 0; --i) {
    ret += query(a[i]);
    add(a[i], 1, A.size());
  }
  printf("%lld\n", ret);
  return 0;
}


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

int main()
{
  int A, B;
  cin >> A >> B;
  int c = abs(A - B);
  if (c % 2 == 0)
  {
    int ans = min(A, B) + c / 2;
    cout << ans << endl;
  }
  else
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  static Scanner scan = new Scanner(System.in);

  public static void main(String[] args) {
    int n = scan.nextInt();

    for (int i = -256; i < 256; i++) {
      for (int j = -256; j < 256; j++) {
        long a = i;
        long b = j;
        // System.out.println(Math.pow(a, 5) + Math.pow(b, 5));/

        if (Math.pow(a, 5) - Math.pow(b, 5) == (long) n) {
          System.out.println(a + " " + b);
          return;
        }

      }
    }
  }
}

Measured memory_bytes: 27252
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
   vector<ll>sum(n);
   cin>>sum[0];
   rep(i,n-1){
       int a;cin>>a;
       sum[i+1] = sum[i]+a;
   }
   ll res = 0,cnt = 0;
   rep(i,n){
       ll now = sum[i]+cnt;
       if(i%2==0){
           if(now>=0){
               res += abs(-1-now);
               cnt += (-1-now);
           }
       }
           else {
               if(now<=0){
                   res += abs(1-now);
                   cnt += (1-now);
               }
           }
       
   }
   cnt = 0;
   ll ress = 0;
   rep(i,n){
       ll now = sum[i]+cnt;
       if(i%2==0){
           if(now<=0){
               ress += abs(1-now);
               cnt += (1-now);
           }
       }
           else {
               if(now>=0){
                   ress += abs(-1-now);
                   cnt += (-1-now);
               }
           }
       
   }
   cout<<min(res,ress)<<endl;
}



Measured memory_bytes: 1024
//ALDS1_11_B:Depth First Search
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

vector<int> v[101];
int d[101];
int f[101];
bool already[101];

int t = 1;

void dfs(int now){
    d[now] = t;
    t++;
    already[now] = 1;
    for(int i=0; i<v[now].size(); i++){
        if(!already[v[now][i]]) dfs(v[now][i]);
    }
    f[now] = t;
    t++;
}

int main(){
    int n;
    cin >> n;
    
    for(int i=0; i<n; i++){
        int u,k;
        cin >> u >> k;
        for(int j=0; j<k; j++){
            int tmp;
            cin >> tmp;
            v[u].push_back(tmp);
        }
        already[u] = false;
        sort(v[u].begin(), v[u].end());
    }

    for(int i=1; i<=n; i++){
        if(!already[i]) dfs(i);
    }

    for(int i=1; i<=n; i++){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
}


Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int n ,d;
    int total;
    cin >> n >> d;
    total = n / ((d * 2) + 1);
    if ((n % ((d * 2) + 1) != 0)){++total;}
    printf("%d\n", total);



    return 0;
}

Measured memory_bytes: 256
# include "iostream"
# include "cstdio"
# include "cstring" 

using namespace std;
 
const int maxm=100+10; 

bool  
	f[maxm], 
	q[maxm]; 

int main(){
	int n, 
		now,
		ans; 
	register int i,j;
	char s[maxm]; 
	scanf("%d",&n); 
	scanf("%s",s); 
	for(i=0;i<n;i++){ 
		f[s[i]-'a']=true;  
		memset(q,false,sizeof(q));  
		for(j=i+1;j<n;j++){ 
			q[s[j]-'a']=true;  
		}
		now=0;
		for(j=0;j<26;j++){
			if(f[j] && q[j]){    
				now++; 
			} 
		} 
		ans=max(ans,now); 
	}
	printf("%d",ans);
	return 0; 
} 

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

#define INF 1e13

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll n, k; cin>>n>>k;
    vll A(n), F(n);
    rep(i, n) cin>>A[i];
    rep(i, n) cin>>F[i];
    sort(all(A));
    sort(rall(F));
    ll X = 0;
    rep(i, n) X = max(X, A[i]*F[i]);

    ll left = -1, right = X;
    while(right-left>1){
        ll mid = (left+right)/2;
        ll cnt = 0;
        rep(i, n){
            if (A[i]*F[i]>mid) cnt+=A[i]-mid/F[i];
        }
        if (cnt>k){
            left = mid;
        }else{
            right = mid;
        }
    }
    cout << right << "\n";
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int getFirst10(int n){
    int numb = 0;
    while(numb < n){
        numb += 10;
    }
    return numb;
}
int main(){
    Hello
    int a[5], ans = 1e9;
    for(int i = 0; i < 5; i++)
        cin >> a[i];
    sort(a, a + 5);
    do{
        int lst = 0;
        for(int i = 0; i < 5; i++){
            if(i == 4) lst = lst + a[i];
            else lst = getFirst10(lst + a[i]);
        }
        ans = min(ans, lst);
    }
    while(next_permutation(a, a + 5));
    cout << ans;
    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列
#define CO(a, b, c) ((a) ? (b) : (c))
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;

int main(void)
{

    int x, y;
    cin >> x >> y;

    for (int i = 0; i <= x; i++)
    {
        int v = 2 * (x - i) + 4 * i;
        if (v == y)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll A, B, T;
    cin >> A >> B >> T;
    print(T / A * B);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    int H, W;

    void Solve()
    {
        while (true)
        {
            H = read.Int(); W = read.Int();
            if (H == 0) break;
            var grid = read.IntGrid(H);
            int ans = 0;

            for (int rowMask = 0; rowMask < (1 << H); rowMask++)
            {
                int sum = 0;
                for (int j = 0; j < W; j++)
                {
                    //int count = Enumerable.Range(0, H).Sum(i => grid[i][j] ^ (rowMask >> i & 1));
                    int count = 0;
                    for (int i = 0; i < H; i++)
                        count += grid[i][j] ^ (rowMask >> i & 1);
                    sum += Math.Max(count, H - count);
                }
                ans = Math.Max(ans, sum);
            }
            Console.WriteLine(ans);
        }
    }


    static void Main() { new Program().Solve(); }
    static Read read = new Read();
    class Read
    {
        private Queue<string> que = new Queue<string>();
        public string String() { return Dequeue(); }
        public int Int() { return int.Parse(Dequeue()); }
        public long Long() { return long.Parse(Dequeue()); }
        public double Double() { return double.Parse(Dequeue()); }
        public int[] IntArray() { return Array.ConvertAll(Line().Split(), int.Parse); }
        public int[][] IntGrid(int H) { return Enumerable.Range(0, H).Select(i => IntArray()).ToArray(); }
        public string[] StringArray(int N) { return Enumerable.Range(0, N).Select(i => Line()).ToArray(); }
        public string Line() { return Console.ReadLine().Trim(); }
        private string Dequeue()
        {
            if (que.Count == 0) foreach (var s in Line().Split()) que.Enqueue(s);
            return que.Dequeue();
        }
    }
}

Measured memory_bytes: 8308
S = gets.chomp

s1, s2 = S[0 .. 1], S[2 .. 3]
mr = '01' .. '12'
puts case
     when mr.member?(s1) && !mr.member?(s2); "MMYY"
     when mr.member?(s2) && !mr.member?(s1); "YYMM"
     when mr.member?(s1) && mr.member?(s2); "AMBIGUOUS"
     else ; "NA"
end

Measured memory_bytes: 1788