akhauriyash/Code-Regression huggingface dataset:
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	k := stdin.ReadInt()

	c := 0
	for n > 0 {
		n /= k
		c++
	}
	stdout.Println(c)
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


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

const int INF=1e9+5;
const int N=1e5+5;

vector<int> v[N];
int level[N];
int dist[N];
bool used[N];

void dfs(int u){
	assert(!used[u]);
	used[u]=1;
	for(int x:v[u]){
		dist[x]=max(dist[x],dist[u]+1);
		--level[x];
		if(!level[x]){
			dfs(x);
		}
	}
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	// freopen("input.txt","r",stdin);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		++level[y];
	}
	for(int i=1;i<=n;++i){
		if(!used[i]&&!level[i]){
			dfs(i);
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i){
		ans=max(ans,dist[i]);
	}
	cout<<ans;
	return 0;
}
		


Measured memory_bytes: 9728
#include <iostream>
//#incude <algorithm>
using namespace std;

int main(){
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  int x[N],y[M];
  for(int uuu=0;uuu<N;uuu++) cin>>x[uuu];
  for(int rrr=0;rrr<M;rrr++) cin>>y[rrr];
  
  int xmax=-20000;
  for(int i=0;i<N;i++) xmax=max(xmax,x[i]);
 int  ymin=20000;
  for(int j=0;j<M;j++) ymin=min(ymin,y[j]);
  int lx=max(X,xmax);
  int ly=min(Y,ymin);
  if(ly-lx>=1) cout<<"No War"<<endl;
  else cout<<"War"<<endl;
  
 return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define mo 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;


ll comb(ll N_, ll C_) {
	const int NUM_ = 400001;
	static ll fact[400002], factr[400002], inv[400002];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mo, factr[i] = factr[i - 1] * inv[i] % mo;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mo*factr[N_ - C_] % mo;
}
ll modpow(ll a, ll n = mo - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mo, a = a * a%mo, n >>= 1;
	return r;
}


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

	int N, K;
	cin >> N >> K;

	chmin(K, N - 1);
	int ans = 1;

	if (K >= N - 1)cout << comb(N + N - 1, N) << endl;
	else {
		int ans = comb(N + N - 1, N);
		for (int i = N - 1; i > K; i--) {
			
			ans -= (comb(N, i)%mod)*(comb(N - 1, N - i - 1)%mod);
			ans += mod;
			ans %= mod;
		}
		cout << (ans+mod)%mod << endl;
		//cout << ans << endl;
	}

	
	return 0;
}



Measured memory_bytes: 9600
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let mut x :i64 = sc.read();
    let y: i64 = sc.read();
    let mut ans = 0;
    while x <= y {
        ans += 1;
        x *= 2;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
from itertools import combinations_with_replacement as comb
N,M,Q = map(int,input().split())
abcd = [list(map(int,input().split())) for i in range(Q)]
ans = 0
lista = [list(i) for i in comb([j for j in range(1,M+1)],N)]
for lis in lista:
    ansi = 0
    for a,b,c,d in abcd:
        if lis[b-1]-lis[a-1]==c:
            ansi+=d
    ans = max(ans,ansi)
print(ans)

Measured memory_bytes: 22824
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
	int N;
	cin >> N;
	vector<int> a(N);
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	if(N%2 != 0){
		a.push_back(0);
	}
	sort(a.begin(), a.end());
	int diff = 0;
	for(int i = 0; i < N; i+=2){
		diff += a[i+1] - a[i];
	}
	cout << diff << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	ans := 0
	for i := 0; i < N; i++ {
		A, B := sc.NextInt(), sc.NextInt()
		ans += B - A + 1
	}
	fmt.Println(ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
print(" ".join(map(str,a)))
for i in range(1,n):
  v=a[i]
  j=i-1
  while j>=0 and a[j]>v:
    a[j+1]=a[j]
    j-=1
  a[j+1]=v
  print(" ".join(map(str,a)))



Measured memory_bytes: 5600
X, K, D=map(int, input().split())
X=abs(X)
if abs(X)-K*D>=0:
  print(abs(X)-K*D)
else:
  a=abs(X)//D
  b=abs(X)%D
  K-=a
  if K%2==0:
    print(abs(b))
  else:
    print(abs(abs(b)-D))

Measured memory_bytes: 9188
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	// your code goes here
	int i,j,n;
	i=0;
	j=0;
	cin>>n;
	string s;
	string t;
	cin>>s;
	cin>>t;
	// cout<<s.size()<<t.size();
	while(i!=s.size() || j!=t.size()){
		cout<<s[i]<<t[j];
		i++;
		j++;
	}
	while(i!=s.size()){
		cout<<s[i];
		i++;
	}
	while(j!=t.size()){
		cout<<t[j];
		j++;
	}
}

Measured memory_bytes: 256
import math

n, d = map(int, input().split())
x = [[0]*d for _ in range(n)]
ans = 0
for i in range(n):
  x[i] = list(map(int, input().split()))

for i in range(n-1):
  for j in range(i+1, n):
    count = 0
    for k in range(d):
      count += (x[i][k]-x[j][k])**2
    if math.sqrt(count).is_integer():
      ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	rep(i, n) {
		if (i + 1 < n && s[i] == s[i + 1]) {
			printf("%d %d\n", i + 1, i + 2);
			return 0;
		}
		if (i + 2 < n && s[i] == s[i + 2]) {
			printf("%d %d\n", i + 1, i + 3);
			return 0;
		}
	}
	printf("%d %d\n", -1, -1);
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x=0,n,r=0,g,m,p,h,k,w,max=-10000000,min=400000001,ans=0,sum=0;
    string s;
    bool f=true;
    cin >> n >> m;
    vector<pair<ll, ll>> a(n);
    vector<pair<ll, ll>> c(m);
    VI b(n);

    rep(i,n){
        cin >> a[i].first >> a[i].second;
	}
    rep(i,m){
        cin >> c[i].first >> c[i].second;
	}

    rep(i,n){
        rep(j,m){
            if(min > abs(a[i].first - c[j].first) + abs(a[i].second - c[j].second)){
                b[i] = j+1;
                min = abs(a[i].first - c[j].first) + abs(a[i].second - c[j].second);
            }
        }
        min = 400000001;
        cout << b[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
        int w = sc.nextInt();
        if(w>=s){
          System.out.println("unsafe");
        }else{
          System.out.println("safe");
        }        				
	}
}

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

int main() {
	ios_base::sync_with_stdio( false );

	stack<int> car;
	int n;

	while( cin >> n ) {
		if( n == 0 ) {
			cout << car.top() << '\n';
			car.pop();
		}
		else {
			car.push( n );
		}
	}
}



Measured memory_bytes: 3208
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
	double x1, y1, x2, y2;
	double d;
	cin >> x1 >> y1 >> x2 >> y2;
	d = sqrt(pow((x2 - x1), 2.0) + pow((y2 - y1), 2.0));
	cout << fixed << setprecision(4) << d << endl;
}


Measured memory_bytes: 3284
program main
    implicit none
    integer n
    integer, dimension(3,3) :: a, d
    integer, dimension(8) :: sum
    integer, allocatable, dimension(:) :: b
    integer i,j,k,flag
    read(*,*) a(1,1), a(1,2), a(1,3)
    read(*,*) a(2,1), a(2,2), a(2,3)
    read(*,*) a(3,1), a(3,2), a(3,3)
    read(*,*) n
    allocate(b(n))
    do i = 1,n
        read(*,*) b(i)
    end do
    d = 1
    do i = 1,n
        do j = 1,3
            do k = 1,3
                if(a(j,k) == b(i)) then 
                    d(j,k) = 0
                end if
            end do
        end do
    end do
    
    sum(1) = d(1,1)+d(1,2)+d(1,3)
    sum(2) = d(2,1)+d(2,2)+d(2,3)
    sum(3) = d(3,1)+d(3,2)+d(3,3)
    sum(4) = d(1,1)+d(2,1)+d(3,1)
    sum(5) = d(1,2)+d(2,2)+d(3,2)
    sum(6) = d(1,3)+d(2,3)+d(3,3)
    sum(7) = d(1,1)+d(2,2)+d(3,3)
    sum(8) = d(1,3)+d(2,2)+d(3,1)
    flag = 0
    
    do i = 1,8
        if(sum(i) == 0) then
            write(*,*) "Yes"
            flag = 1
            exit
        end if
    end do
    if(flag == 0) write(*,*) "No"
end program

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

int main(){
  int n;
  cin >> n;
  vector<int> hai(n);
  for(int i=0;i<n;i++){
    cin >> hai.at(i);
  }
  sort(hai.begin(),hai.end());
  reverse(hai.begin(),hai.end());
  int a=hai.at(0),b=1;
  for(int i=0;i<n;i++){
    if(a>hai.at(i)){
      b++;
      a=hai.at(i);
    }
  }
  cout << b <<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,c,i,j;
    scanf("%d %d %d",&a,&b,&c);
    j=0;
    for(i=a;i<=b;i++)
    {
        if(c%i==0)
         j++;
    }
    printf("%d\n",j);
    return 0;
}
 

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define MAX 200000


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

  vector<int> a(n, 0);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

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

  vector<pair<int,int>> lists;
  int cnt = 1;
  for(int i = 1; i < n; i++){
    if(a[i] == a[i-1]){
      cnt++;
    }else{
      lists.push_back(make_pair(cnt, a[i-1]));
      cnt = 1;
    }
    if(i == n-1){
      lists.push_back(make_pair(cnt, a[i]));
    }
  }
  
  int m = lists.size();
  int ans = 0;
  if(m <= k){
    cout << ans << endl;
    return 0;
  }

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

  for(int i = 0; i < m - k; i++){
    ans += lists[i].first;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3188
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
ba = []
for i in ab:
    ba.append(i[::-1])
ba.sort()
cnt = 1
broken = ba[0][0] - 1
for i in ba[1::]:
    if i[1] > broken:
        broken = i[0] - 1
        cnt += 1
print(cnt)

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



int main(){
  vector<int> a(3,0);
  cin >>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());

  cout << a[0]+a[2]*10+a[1] <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> s;

  int ans = 0;
  int sl;
  if(s.length() % 2 != 0) {
    sl = s.length() / 2 + 1;
  } else {
    sl = s.length() / 2;
  }
  REP(i, sl) {
    if(s[i] != s[s.length() - (i + 1)]) {
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        
        long sum = 0;
        while(A%2==0 && B%2==0 && C%2==0){
            if(A == B && B == C){
                sum = -1;
                break;
            }
            sum++;
            int s = A;
            int t = B;
            int u = C;
            A = (t+u)/2;
            B = (s+u)/2;
            C = (s+t)/2;
        }
        System.out.println(sum);
    }
}

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

struct node{
  struct node *parent;
  struct node **children;
  int id;
  int depth;
  int k;
};
typedef struct node *NodePointer;

struct node make_1node(int, int, NodePointer);
void findDepth(NodePointer, int);
void nodeJudge(NodePointer);

int main(){
  int n, id, k, c_id, i, j;
  NodePointer T;
  
  scanf("%d",&n);
  T = (NodePointer)malloc( n * sizeof( struct node ) );

  for(i = 0; i < n; i++) T[i].parent = NULL;
  
  for(i = 0; i < n; i++){
    scanf("%d %d",&id, &k);
    T[id] = make_1node(id, k, T[id].parent);
    for(j = 0; j < k; j++){
      scanf("%d",&c_id);
      T[id].children[j] = &(T[c_id]);
      T[c_id].parent = &(T[id]);
    }
  }

  for(i = 0; i < n; i++){
    if( T[i].parent == NULL ){
      findDepth(&(T[i]), 0);
      break;
    }
  }
  
  for(i = 0; i < n; i++){    
    printf("node %d: ",T[i].id);
    if( T[i].parent == NULL ) printf("parent = -1, ");
    else printf("parent = %d, ",T[i].parent->id);
    printf("depth = %d, ",T[i].depth);
    nodeJudge(&T[i]);
    for(j = 0;; j++){
      if( T[i].children == NULL ) break;
      printf("%d",T[i].children[j]->id);
      if( j == T[i].k - 1 ) break;
      printf(", ");
    }
    printf("]\n");
  }
  free(T);
  return 0;
}

struct node make_1node(int id, int k, NodePointer parent){
  struct node temp;
  temp.id = id;
  temp.k = k;
  if( k == 0 ) temp.children = NULL;
  else temp.children = (NodePointer *)malloc( sizeof( NodePointer ) * k );
  temp.parent = parent;
  return temp;
}
  
void findDepth(NodePointer x, int depth){
  int i;
  x->depth = depth;
  if( x->children != NULL ){
    for(i = 0; i < x->k ; i++) findDepth( x->children[i], depth+1);
  }
}

void nodeJudge(NodePointer x){
  if( x->parent == NULL ) printf("root, [");
  else if( x->children == NULL ) printf("leaf, [");
  else printf("internal node, [");
}



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

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

  if ( n / 10 % 111 == 0 ) {
    cout << "Yes" << endl;
  }
  else if (n % 1000 % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
h = 1
w = 1
while h > 0 && w > 0
h,w = gets.split.map(&:to_i)

a = 0

 while a<h
   b = 0
   while b<w
     print "#"
     b += 1
     if b == w

       break
     end
   end
   a += 1
   print "\n"
 end
 if h == 0 && w == 0
   break
 else
   puts ""
 end

end

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

using namespace std;

int main() 
{
  int n, a[100], sum = 0;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];

  for(int j = 0; j < n; j++)
  {
    int max = 0;
    for(int i = 0; i < n; i++)
      if(max < a[i]) max = a[i];

    for(int i = 0; i < n; i++)
    {
      if(a[i] == max)
      {
        a[i] = 0;
        break;
      }
    }
    if(j%2 == 0) sum += max;
    else sum -= max;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3624
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

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

	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()
	p := nextInt()

	priceA := a * p
	priceB := 0
	if p <= c {
		priceB = b
	} else {
		priceB = b + (p-c)*d
	}
	fmt.Println(min(priceA, priceB))
}



Measured memory_bytes: 1116
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int len, num;

    scanf("%d", &num);
    scanf("%d", &len);

    string s;
    vector<string> vs;

    for (int i = 0; i < num; i++) {
        cin >> s;
        vs.push_back(s);
    }

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

    for (auto s : vs) {
        cout << s;
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 100005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    cout << b+min(a+b+1,c) << endl;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	
	int a, b, c;

	cin >> a >> b >> c;

	cout << min(c, b / a) << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> d[i];
    }

    for (int i = 0; i < N-1;i++)
    {
        for (int j = i + 1; j < N;j++)
        {
            ans = ans + d[i] * d[j];
        }
    }
    cout << ans << endl;
}

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

int main()
{
    long long K;
    cin >> K;

    long long k = 0;
    for (long long i = 1; i <= 2 * K; i++)
    {
        k *= 10;
        k %= K;
        k += 7;
        k %= K;
        if (k == 0)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<iomanip>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
int main()
{
    ios::sync_with_stdio(false);
    // freopen("D:\\in.txt","r",stdin);
    // freopen("D:\\out.txt","w",stdout);
    int a,b,t,sum=0;
    cin>>a>>b>>t;
    int m=a;
    while(a<(t+1))
    {
        sum+=b;
        a+=m;
    }
    cout<<sum<<endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define ps(x,y) fixed<<setprecision(y)<<x
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out << "[";
	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it != a.begin())
			out << ", ";
		out << *it;
	}
	return out << "]";
}
int main()
{
    boost;
    ll n,i,j,x,t,y;
    cin>>n>>x>>y;
    x=(x-1)/n;
    y=y/n;
    if(y-x>0) cout<<"OK";
    else cout<<"NG";
}

Measured memory_bytes: 3652
X, Y, Z, K=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

import heapq
nums=[[-(A[0]+B[0]+C[0]), 0, 0, 0]]
heapq.heapify(nums)

sumi=[[0, 0, 0]]
for _ in range(K):
  out, a, b, c=heapq.heappop(nums)
  print(-out)
  if a<X-1 and not([a+1, b, c] in sumi):
    heapq.heappush(nums, [-(A[a+1]+B[b]+C[c]), a+1, b, c])
    sumi.append([a+1, b, c])
  if b<Y-1 and not([a, b+1, c] in sumi):
    heapq.heappush(nums, [-(A[a]+B[b+1]+C[c]), a, b+1, c])
    sumi.append([a, b+1, c])
  if c<Z-1 and not([a, b, c+1] in sumi):
    heapq.heappush(nums, [-(A[a]+B[b]+C[c+1]), a, b, c+1])
    sumi.append([a, b, c+1])


Measured memory_bytes: 4848
#include<iostream>
using namespace std;
int main(){
int max[3]={0},a,i;
for(i=0;i<10;i++){
cin>>a;
if(a>max[0]){max[2]=max[1];max[1]=max[0];max[0]=a;}
else if(a>max[1]){max[2]=max[1];max[1]=a;}
else if(a>max[2]){max[2]=a;}}
for(i=0;i<3;i++)cout<<max[i]<<endl;
return 0;}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	
	ll keep = 1;
	ll H;  cin >> H;

	ll ans = 0;
	while(H){
		ans += keep;
		H /= 2;
		keep *= 2;
	}

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


Measured memory_bytes: 256
#!ruby -Knrzlib
require 'base64'

payload = '
puts 9394,p=?+,0,1,9,?<,_=3,m=9,3,
[p,3,5-_+=1,9]+(-59..0).map{[p,_,_,_,p,_,3,6,[p,6,6,6]*-_1,?<,6,9,m+=1,p,_,m,_]},
[p,3,5-_+=1,9]+(-59..0).map{[p,_,_,_,p,_,3,6,[p,6,6,6]*-_1,?<,6,9,m+=1,p,_,m,_]},
(-59..0).map{|a|[p,2,2,2]+(1..59+a).map{[p,99+a-_1,99+_1,_,?<,3,_,_,p,_,2,2]}}'

prologue = '#!ruby -Knrzlib
eval Zlib.inflate'

compressed = Zlib.deflate(payload.split("\n").join(""), 9)

separator = "'"

code = prologue + separator + compressed + separator

STDERR.puts code.size

if 170 < code.size then raise end
if compressed.include? separator then raise end
if compressed.include? "\r" then raise end
if code.include? "\r" then raise end

eval code
#puts Base64.strict_encode64(code)


Measured memory_bytes: 15044
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n) {
		par = vector<int>(n, -1);
	}
	int root(int x) {
		if (par[x] < 0) return x;
		else return root(par[x]);
	}
	int size(int x) {
		return -par[root(x)];
	}
	bool unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return false;
		if (size(rx) < size(ry)) swap(rx, ry);
		par[rx] += par[ry];
		par[ry] = rx;
		return true;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int count() {
		int res = 0;
		rep(i, par.size()) {
			if (par[i] < 0) res++;
		}
		return res;
	}
	int maxi() {
		int res = 0;
		rep(i, par.size()) {
			chmax(res, -par[i]);
		}
		return res;
	}
};
int main() {
	int n, m;
	cin >> n >> m;
	UnionFind g(n);
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		g.unite(x, y);
	}
	cout << g.maxi() << endl;
	return 0;
}

Measured memory_bytes: 4836
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    a, B = makeMultiInteger(input_string[0])
    #print(a, b, c)
    #print(a)
    if a >= 13:
        return B
    elif (a >= 6 and a < 13):
        return B//2
    else:
        return 0


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


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

int main(){
    int a;

    cin >> a;

    cout << a + pow(a,2) + pow(a,3) << endl;
    
    return 0;
}

Measured memory_bytes: 4148
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
	int l;
	scanf("%d", &l);
	l--;

	int nowlen = 1;

	vector<ii> edge;
	vector<int> len;

	for (int i = 19; i > 1; i--)
	{
		edge.emplace_back(i, i + 1);
		len.push_back(nowlen);

		edge.emplace_back(i, i + 1);
		len.push_back(0);

		nowlen *= 2;
	}

	// 1 to 2 edge를 0이 나오는 위치들 기준으로 구분
	edge.emplace_back(1, 20);
	len.push_back(l);
	for (int b = 0; b <= 18; b++)
	{
		int k = l;
		if ((k & (1 << b)) == 0)
			continue;

		k -= k % (1 << b);
		k -= 1 << b;

		edge.emplace_back(1, 20 - b);
		len.push_back(k);

		if (k == 0)
			break;
	}

	if (l > 524288)
	{
		edge.emplace_back(1, 2);
		len.push_back(0);
		edge.emplace_back(1, 2);
		len.push_back(262144);
	}

	printf("20 %d\n", edge.size());

	for (int i = 0; i < edge.size(); i++)
		printf("%d %d %d\n", edge[i].xx, edge[i].yy, len[i]);

	return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
s = sum(a)
for i in range(n-1):
    if x < a[i] + a[i+1]:
        new = x - a[i]
        if 0 <= new:
            a[i+1] = new
        else:
            a[i+1] = 0
            a[i] += new
else:
    print(s - sum(a))

Measured memory_bytes: 14052
N, K = map(int, input().split())

count = 0
for a in range(1, N+1):
    # b, c in range(K - (a % K), N+1, K)
    # b + c == (i + j) * K - 2 * (a % K)
    # (2 * a) % K == 0

    if (2 * a) % K != 0:
        continue

    min_b = K - (a % K)
    n_b   = (N + K - min_b) // K
    count += n_b ** 2

print(count)


Measured memory_bytes: 39280
#pragma region
#include <assert.h>
#include <math.h>

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &v) {
  return os << v.first << ' ' << v.second << '\n';
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (T t : v) os << t << ' ';
  return os << '\n';
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) is >> t;
  return is;
}
#pragma endregion

#define int long long
int mod = 1e9 + 7;  // 998244353;

void solvetestcase() {
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  vector<bool> v1(n, 0);
  for (int i = 0; i < n; i++) v1[i] = v[i].first == v[i].second;
  for (int i = 2; i < n; i++) {
    if (v1[i] && v1[i - 1] && v1[i - 2]) {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No\n";
  return;
}

#undef int
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int t = 1;
  // cin >> t;

  for (int T = 1; T <= t; T++) {
    // cout << "Case #" << T << ": ";
    solvetestcase();
    cout.flush();
  }

  return 0;
};

/*
    AUTHOR:     KUNAL TAWATIA
    EDUCATION:  INDIAN INSTITUTE OF TECHNOLOGY, JODHPUR
*/


Measured memory_bytes: 3644
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, d, t, i, T, I;
    cin >>a>>b>>c>>d;
    i = c/b;
    I = c%b;
    t = a/d;
    T = a%d;

    if(t>i || (i-t==1 && I==0 && T!=0) || (t==i && (T!=0 || (T==0&&I==0))))
        cout<<"Yes"<<endl;
    else
        cout << "No" << endl;

    return 0;
}


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

#define ff              first
#define ss              second
//#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


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

int32_t main()
{
	c_p_c();
	int n;
	cin>>n;
	int arr[n][3];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	int dp[n][3];
//memset(dp,0,sizeof(dp));
	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];
	for(int i=1;i<n;i++)
	{
		
			dp[i][0]=max((dp[i-1][1]+arr[i][0]),(dp[i-1][2]+arr[i][0]));
			dp[i][1]=max((dp[i-1][0]+arr[i][1]),(dp[i-1][2]+arr[i][1]));
			dp[i][2]=max((dp[i-1][0]+arr[i][2]),(dp[i-1][1]+arr[i][2]));
		
	}
	/*
	for(int i=0;i<n;i++)
	{
		cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;

	}
	*/

	int *l=max_element(dp[n-1],dp[n-1]+3);
	cout<<*l<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

vector<int> g[100005];
int dp[100005],n,m;

int f(int x){
	int& r=dp[x];
	if(r>=0)return r;
	r=0;
	for(int y:g[x])r=max(r,1+f(y));
	return r;
}

int main(){
	scanf("%d%d",&n,&m);
	fore(_,0,m){
		int x,y;
		scanf("%d%d",&x,&y);x--;y--;
		g[x].pb(y);
	}
	mset(dp,-1);
	int r=0;
	fore(i,0,n)r=max(r,f(i));
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 7424
import bisect

N, M = [int(i) for i in input().split()]

PY = []
PYd = {i:[] for i in range(1, N+1)}

for i in range(M):
    x, y = [int(i) for i in input().split()]
    PYd[x].append(y)
    PY.append((x,y))
    
for i in PYd.keys():
    PYd[i].sort()
    
for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(bisect.bisect(PYd[p], y)).zfill(6)
    print(str_p+index)

Measured memory_bytes: 38436
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	while (cin >> N, N) {
		vector<bitset<16>>v(N);
		vector<int>score(N);
		for (int i = 0; i < N; i++) {
			cin >> M >> score[i];
			while (M--) {
				cin >> L >> R;
				L -= 6, R -= 6;
				for (int j = L; j < R; j++) {
					if (v[i].test(j))score[i] = 0;
					v[i].set(j);
				}
			}
		}
		vector<int>dp(1 << 16);
		for (int i = 0; i < 1 << 16; i++) {
			for (int j = 0; j < N; j++) {
				if (i&v[j].to_ulong())continue;
				dp[i | v[j].to_ulong()] = max(dp[i | v[j].to_ulong()], dp[i] + score[j]);
			}
		}
		cout << *max_element(dp.begin(), dp.end()) << endl;
	}
}


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

int main(void){
    int h, w, d;
    cin>>h>>w>>d;
    vector<pair<int, int> > v(h*w+1);
    rep(i, h)rep(j, w){
        int a;
        cin>>a;
        v[a]=make_pair(i, j);
    }
    int q;
    cin>>q;
    vector<int> dist(h*w+1);
    for(int i=d+1;i<=h*w;i++){
        dist[i]=dist[i-d]+abs(v[i].first-v[i-d].first)+abs(v[i].second-v[i-d].second);
    }
    vector<pair<int, int> > Q(q);
    rep(i, q){
        int l, r;
        cin>>l>>r;
        Q[i]=make_pair(l, r);
    }
    rep(i, q){
        int ans=dist[Q[i].second]-dist[Q[i].first];
        cout<<ans<<endl;
    }
    return 0;
}

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

struct Graph{
    int V;
    int E;
    vector<tuple<int,int,int,int>> edges;
    void add(int u,int v,int weight){
        edges.push_back(make_tuple(u,v,weight,1));
    }
    Graph(int v) : V(v){}
};

vector<int> Path(const Graph& G,const int& start,const int& goal){
    vector<vector<pair<int,int>>> adj(G.V),adj2(G.V);
    for(auto t:G.edges)adj[get<0>(t)].push_back(make_pair(get<1>(t),get<2>(t)));
    for(auto t:G.edges)adj2[get<1>(t)].push_back(make_pair(get<0>(t),get<2>(t)));
    int dmin[G.V];
    for(int i = 0;i < G.V;i++)dmin[i] = -1;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pque;
    pque.push(make_pair(0,goal));
    pair<int,int> p;
    while(pque.size()){
        p = pque.top();
        pque.pop();
        if(dmin[p.second] == -1){
            dmin[p.second] = p.first;
            for(auto x:adj2[p.second])if(dmin[x.first] == -1){
                pque.push(make_pair(dmin[p.second]+x.second,x.first));
            }
        }
    }
    int now = start;
    vector<int> ans(1,now);
    while(now != goal){
        sort(adj[now].begin(),adj[now].end());
        for(int i = 0;i < adj[now].size();i++){
            pair<int,int> p = adj[now][i];
            if(dmin[now] == dmin[p.first]+p.second){
                ans.push_back(p.first);
                now = p.first;
                break;
            }
        }
    }
    return ans;
}

int main(){
    int N,D,ans_cost = 0;
    cin >> N >> D;
    vector<vector<int>> v(D);
    vector<vector<int>> p(D,vector<int>(N));
    for(int i = 0;i < N;i++){
        for(int j = 0;j < D;j++){
            cin >> p[j][i];
        }
    }
    swap(N,D);
    for(int i = 0;i < N;i++){
        int MIN = 1e9;
        for(int j = 0;j < D;j++){
            MIN = min(MIN,p[i][j]);
        }
        for(int j = 0;j < D;j++){
            if(p[i][j] == MIN){
                v[i].push_back(j);
            }
        }
        ans_cost += MIN;
    }
    Graph G(N*D+2);
    for(auto x:v[0]){
        G.add(N*D,x,0);
    }
    for(int i = 0;i < N-1;i++){
        for(auto x1:v[i])for(auto x2:v[i+1]){
            G.add(i*D+x1,(i+1)*D+x2,(x1==x2 ? 0 : 1));
        }
    }
    for(auto x:v[N-1]){
        G.add((N-1)*D+x,N*D+1,0);
    }
    G.E = G.edges.size();
    auto ans = Path(G,N*D,N*D+1);
    int ans_change = 0;
    for(int i = 1;i < ans.size()-2;i++){
        ans_change += ans[i]%D != ans[i+1]%D;
    }
    cout << ans_cost << ' ' << ans_change << endl;
    for(auto x:ans){
        if(x < N*D)cout << x%D+1 << endl;
    }
}


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

int main() {
  int N; cin >>N;
  vector<int> A(N);
  rep(i,0,N) cin >>A[i];
  sort(A.begin(),A.end());
  cout <<A.back()-A.front() <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
string s1,s2;
cin>>s1>>s2;
int flg=1;
for(int i=0;i<s1.size();i++)
{
	if(s1[i]!=s2[i])
	{
		flg=0;
		break;
	}
	
}
if(flg==0)
{
	cout<<"No";
}
else
{
	cout<<"Yes";
}

}


Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
#include<set>

using namespace std;

string reverseStr(string str) {
  string ans;
  for(int i=str.length()-1; i>=0; i--) {
    ans += str[i];
  }
  return ans;
}

int main() {
  int m;
  string tmp;

  cin>>m;
  getline(cin,tmp); // 改行文字を読ませる
  
  for(int i=0; i<m; i++) {
    string trains;
    set<string> answers;
    getline(cin,trains);
    
    for(int j=1; j<trains.length(); j++) {
      string front, back;
      for(int k=0; k<j; k++) {
	front += trains[k];
      }
      for(int k=j; k<trains.length(); k++) {
	back += trains[k];
      }
      //cout<<front<<" "<<back<<endl;
      answers.insert(front+back);
      answers.insert(reverseStr(front)+back);
      answers.insert(front+reverseStr(back));
      answers.insert(reverseStr(front)+reverseStr(back));
      answers.insert(back+front);
      answers.insert(reverseStr(back)+front);
      answers.insert(back+reverseStr(front));
      answers.insert(reverseStr(back)+reverseStr(front));
    }
    
    cout<<answers.size()<<endl;    
  }
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    deque<int> b;
    rep(i,0,n){
        cin>>a.at(i);
    }
    rep(i,0,n){
        if(i%2==0)b.push_front(a.at(i));
        else b.push_back(a.at(i));
    }
    if(n%2==0)reverse(all(b));
    rep(i,0,n){
        cout<<b.at(i)<<' ';
    }
return 0;
}

Measured memory_bytes: 3840