akhauriyash/Code-Regression huggingface dataset:
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;


public class Main {

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

        int height = sc.nextInt();
        int width = sc.nextInt();
        int[][] needmagic = new int[10][10];
        int[][] wallnum = new int[height][width];
        int magicpoint = 0;
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                needmagic[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                wallnum[i][j] = sc.nextInt();
            }
        }

        for (int k = 0; k < 10; k++) {
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    needmagic[i][j] = Math.min(needmagic[i][j], needmagic[i][k] + needmagic[k][j]);
                }
            }
        }

        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                if (wallnum[i][j] == -1) {
                    continue;
                } else {
                    magicpoint += needmagic[wallnum[i][j]][1];
                }
            }
        }

        System.out.println(magicpoint);

        sc.close();
    }


    private static long gcd(Long m, long n) {
        if(m < n) {
            return gcd(n, m);
        }
        if(n == 0){
            return m;
        } 
        return gcd(n, m % n);
    }

    private static long[][] Combination_nCk(long n, long k) {
        n++; k++;
        long[][] ans = new long[(int)n][(int)k];
        for (int i = 0; i < n; i++) {
            ans[i][0] = 1;
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < k-1; j++) {
                if (i < j) {
                    ans[i][j] = 0;
                }else{
                    ans[i+1][j+1] = ans[i][j] + ans[i][j+1];
                }
            }
        }
        return ans;
    }
    private static double[][] Probability_nCk(int n, int k) {
        n++; k++;
        double[][] ans = new double[n][k];
        for (int i = 0; i < n; i++) {
            if (i == 0) {
                ans[i][0] = 1;
            }else{
                ans[i][0] = ans[i-1][0]/2;
            }
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < k-1; j++) {
                if (i < j) {
                    ans[i][j] = 0;
                }else{
                    ans[i+1][j+1] = (ans[i][j] + ans[i][j+1])/2;
                }
            }
        }
        return ans;
    }
}

Measured memory_bytes: 47344
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

int main(){
	int n;
	
	cin >> n;
	
	int sum = 800 * n;
	
	for (int i = n; i > 14; i-=15) sum -= 200;
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,N) for (int (i) = 0; (i) < (N); (i)++)

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	
	int N; std::cin >> N;
	std::set<int> s;
	rep(i, N) {
		int tmp; std::cin >> tmp;
		s.insert(tmp);
	}

	std::cout << s.size();

	return 0;
}

Measured memory_bytes: 256
// A - Between Two Integers

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;

	string ans;

	if (A <= C && C <= B) ans = "Yes";
	else ans = "No";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
Map=[[int(i) for i in input().split()] for i in range(H)]
Tell=[]
for y in range(H): 
  for x in range(W):
    if Map[y][x]%2==1:
      if x==W-1:
        Map[y][x]=1
      elif Map[y][x+1]%2==0:
        Map[y][x]=0
        Map[y][x+1]=1
        Tell.append(str(y+1)+" "+str(x+1)+" "+str(y+1)+" "+str(x+2))
      else:
        Map[y][x]=0
        Map[y][x+1]=0
        Tell.append(str(y+1)+" "+str(x+1)+" "+str(y+1)+" "+str(x+2))
    else:
      Map[y][x]=0
for y in range(H):
  if Map[y][W-1]==1:
    if y==H-1:
      pass
    elif Map[y+1][W-1]==0:
      Map[y][W-1]=0
      Map[y+1][W-1]=1
      Tell.append(str(y+1)+" "+str(x+1)+" "+str(y+2)+" "+str(x+1))
    elif Map[y+1][W-1]==1:
      Map[y][W-1]=0
      Map[y+1][W-1]=0
      Tell.append(str(y+1)+" "+str(x+1)+" "+str(y+2)+" "+str(x+1))
print(len(Tell))
for t in Tell:
  print(t)

   
      
     
    
     

Measured memory_bytes: 16364
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N;
  cin >> N;
  if(N%2==0){
    cout << 1/2.0 << endl;
  } else {
    cout << (N/2+1.0)/N << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	}

	public void readBody(String str) {
		// System.out.println(str);
		int ans = 0;
		for (int i = 1; i < N; i++) {
			String a = str.substring(0, i);
			String b = str.substring(i);
			// System.out.println(a + "-" + b);
			HashSet<Character> aset = new HashSet<Character>();
			for (int j = 0; j < a.length(); j++)
				aset.add(a.charAt(j));
			HashSet<Character> bset = new HashSet<Character>();
			for (int j = 0; j < b.length(); j++)
				bset.add(b.charAt(j));
			int cnt = 0;
			for (Character c : aset)
				if (bset.contains(c))
					cnt++;
			if (cnt > ans)
				ans = cnt;
		}
		System.out.println(ans);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 22612
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	w := readString()

	count := make([]byte, 26)
	for _, b := range []byte(w) {
		count[b-'a']++
	}
	for _, c := range count {
		if c%2 == 1 {
			println("No")
			return
		}
	}
	println("Yes")
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    char c;
    cin >> c;
    if(c >= 'a' && c <= 'z') cout << "a" << endl;
    if(c >= 'A' && c <= 'Z') cout << "A" << endl;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

const ll MAX_N = 100000 + 10;

struct edge {
	ll to, cost;
};

ll N, Q, K;
vector<edge> nodes[MAX_N];
ll costs[MAX_N];
bool visited[MAX_N];

void dfs(ll node, ll cost) {
	if (visited[node]) return;
	costs[node] = cost;
	visited[node] = true;
	repi(i, 0, nodes[node].size()) {
		dfs(nodes[node][i].to, cost + nodes[node][i].cost);
	}
	return;
}


int main() {
	rd(N);
	repi(i, 0, N - 1) {
		ll a, b, c;
		cin >> a >> b >> c;
		edge ae, be;
		ae.to = b, be.to = a, ae.cost = be.cost = c;
		nodes[a].push_back(ae);
		nodes[b].push_back(be);
	}

	cin >> Q >> K;
	dfs(K, 0);

	repi(i, 0, Q) {
		ll x, y;
		cin >> x >> y;
		wrln(costs[x] + costs[y]);
	}

	return 0;
}

Measured memory_bytes: 14336
#include<stdio.h>
typedef long long ll;
const int mod=1000000007;
int mul(int a,int b){return(ll)a*b%mod;}
int inv[100010],s[100010];
int main(){
	int n,i,x,res;
	scanf("%d",&n);
	inv[1]=1;
	for(i=2;i<=n;i++)inv[i]=-mul(mod/i,inv[mod%i]);
	for(i=1;i<=n;i++)s[i]=(s[i-1]+inv[i])%mod;
	res=0;
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		(res+=mul(x,s[i]+s[n-i+1]-1))%=mod;
	}
	for(i=1;i<=n;i++)res=mul(res,i);
	printf("%d",(res+mod)%mod);
}

Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main() {
  int n,k,l;
  while(1) {
    cin>>n>>k;
    if(n==0 && k==0) break;
    int s[k];
    int b[k];
    for(int i=0; i<k; i++){
      s[i]=0;
      b[i]=0;
      cin>>s[i];
    }

    for(int i=0; i<n; i++)
      for(int j=0;j<k;j++)
	cin>>l,b[j]+=l;

    int f=0;
    for(int i=0; i<k; i++)
      if(s[i] < b[i]) f=1;

    if(f==0) cout<<"Yes\n";
    else cout<<"No\n";
  }
}

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

int main()
{
  vector<vector<int>> data(3, vector<int>(3));
  vector<vector<int>> bingo(3, vector<int>(3, false));

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }

  int N;

  cin >> N;

  int b;

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

    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (data.at(i).at(j) == b) bingo.at(i).at(j) = true;
      }
    }
  }

  bool ans = false;

  for (int i = 0; i < 3; i++) {
    if ((bingo.at(i).at(0) && bingo.at(i).at(1) && bingo.at(i).at(2)) || (bingo.at(0).at(i) && bingo.at(1).at(i) && bingo.at(2).at(i)) ) ans = true;
  }

  if ((bingo.at(0).at(2) && bingo.at(1).at(1) && bingo.at(2).at(0)) || ((bingo.at(0).at(0) && bingo.at(1).at(1)) && bingo.at(2).at(2))) ans = true;

  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        int k=in.nextInt();
        if((k&1)!=0)
        {
            long num=0L;
            boolean flag=false;
            int i=1;
            for(i=1;i<=k;i++)
            {
                num=num*10;
                num%=k;
                num+=7;
                num%=k;
                if(num==0)
                {
                    flag=true;
                    break;
                }
            }
            if(flag==true)
                System.out.println(i);
            else
                System.out.println(-1);
        }
        else
           System.out.println(-1); 

    }
}

Measured memory_bytes: 35792
use std::io;
use std::io::prelude::*;
use std::iter;

fn main() {
    let mut buf = String::new();
    let stdin = io::stdin();
    let mut lock = stdin.lock();

    lock.read_to_string(&mut buf);

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut x: Vec<usize> = iter
        .by_ref()
        .take(n)
        .map(|s| s.parse::<usize>().unwrap() - 1)
        .collect();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<usize> = iter.map(|s| s.parse::<usize>().unwrap() - 1).collect();

    let mut board: Vec<usize> = iter::repeat(0).take(2019).collect();

    for (i, &place) in x.iter().enumerate() {
        board[place] = i;
    }

    for i in a {
        let place = x[i];
        if place < 2018 && board[place + 1] == 0 {
            x[i] += 1;
            board[place + 1] = board[place];
            board[place] = 0;
        }
    }

    for place in x {
        println!("{}", place + 1);
    }
}



Measured memory_bytes: 5032
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint n,k;
  cin>>n>>k;
  vector<lint> a(n);
  vector<lint> cum(n);
  vector<lint> pos_cum(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  cum[0]=a[0];
  pos_cum[0]=a[0]>0?a[0]:0;
  for(int i=1;i<n;i++){
    cum[i]=cum[i-1]+a[i];
    pos_cum[i]=a[i]>0?a[i]+pos_cum[i-1]:pos_cum[i-1];
  }

  lint result=cum[n-1];
  for(int i=0;i+k-1<n;i++){
    lint tmp=0;
    if(i==0){
      tmp+=cum[k-1];
      if(tmp<0) tmp=0;
      tmp+=pos_cum[n-1]-pos_cum[k-1];
    }else{
      tmp+=cum[i+k-1]-cum[i-1];
      if(tmp<0) tmp=0;
      tmp+=pos_cum[i-1];
      tmp+=pos_cum[n-1]-pos_cum[i+k-1];
    }
    UpdateMax(result,tmp);

  }
  cout<<result<<endl;

  return 0;
}




Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M;
  cin>>N>>M;
  vector<pair<int64_t,int64_t>>A(N);
  for(int i=0;i<N;i++){
  int a,b;
    cin>>a>>b;
    if(0<=M-a){
    pair<int64_t,int64_t>p(b,M-a);
    A.at(i)=p;
    }
  }sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  int64_t ans=0;
  vector<int>B(M+1);
  for(int i=0;i<=M;i++)
    B.at(i)=i;
  for(int i=0;i<N;i++){
   int a=B.size();
    if(a==0)
      break;
    auto itr=upper_bound(B.begin(),B.end(),A.at(i).second);
    if(itr==B.begin())
      continue;
    else{
    itr--;
      B.erase(itr);
      ans+=A.at(i).first;
    }
      }cout<<ans<<endl;
     return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  string s;
  cin >> s;
  
  vector<ll> rs(n + 1, 0), ws(n + 1, 0);
  for (ll i = 0; i < s.size(); i++){
    ws[i+1] = ws[i] + (s[i] == 'W' ? 1 : 0);
  }
  for (ll i = 0; i < s.size(); i++){
    rs[i+1] = rs[i] + (s[n-i-1] == 'R' ? 1 : 0);
  }

  ll ans = INF;
  for (ll i = 0; i <= n; i++){
    ans = min(ans, max(ws[i], rs[n-i]));
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
	 long long int n,ans=0;
cin>>n;
string s;
long long int a[26]={};

for(int i=0;i<n;i++){
cin>>s;
a[s[0]-'A']++;
}

int x[5]={0,2,7,12,17};

for(int i=0;i<5;i++){
for(int j=i+1;j<5;j++){
for(int k=j+1;k<5;k++){
ans+=a[x[i]]*a[x[j]]*a[x[k]];
}
}
}

cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
vector<vector<ll>> visit(20,vector<ll>(20,0));

ll h,w;
vector<string> vec(20);

void emb(){
  rep(i,20){
    rep(j,20){
      visit[i][j] = INFLONG;
    }
  }
}



void dfs(ll x,ll y,ll z){
  if(x < 0 || x >= h || y < 0 || y >= w){
    return;
  }
  if(vec[x][y] == '#'){
    return;
  }
  if(visit[x][y] <= z){
    return;
  }
  visit[x][y] = z;
  dfs(x+1,y,z+1);
  dfs(x-1,y,z+1);
  dfs(x,y+1,z+1);
  dfs(x,y-1,z+1);
}

int main(){
  cin >> h >> w;
  rep(i,h){
    cin >> vec[i];
  }
  ll maxi = 0;
  rep(i,h){
    rep(j,w){
      emb();
      dfs(i,j,0);
      rep(p,h){
        rep(q,w){
          if(visit[p][q] != INFLONG){
            chmax(maxi,visit[p][q]);
          }
        }
      }
    }
  }
  cout << maxi << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N,M;
    cin >> N >> M;
    int ans;
    for (int i = M / N; i >= 1; i--) {
        if (M % i == 0) {
          ans = i;
          break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
ll a,b,c;
cin>>a>>b>>c;
cout<<max(c-a+b,0LL)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int a,b,n,s;
  scanf("%d",&a);
  scanf("%d",&b);
  if(a>=b){
  n=a;
    a=a-1;
  }
  else{
    n=b;
    b=b-1;
  }
  
    if(a>=b){
  n=n+a;
  }
  else{
    n=n+b;
  }
  printf("%d\n",n);
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)
var input = make([]string, 0)
var inputLimit = 2

var maxSlime = 100
var colorMax = 10000
var change = 0

type houseSlimes struct {
	slimes []int
	idx    int
	next   int
	prev   int
}

func main() {
	i := 0
	for sc.Scan() {
		i++
		input = append(input, sc.Text())
		if i == inputLimit {
			break
		}
	}

	h := houseSlimes{}
	slimeStrings := splitSpace(input[1])

	for i := range slimeStrings {
		v, _ := strconv.Atoi(slimeStrings[i])
		h.slimes = append(h.slimes, v)
	}

	indexes := h.getChangeIndexes()
	fmt.Println(h.changeColor(indexes))
}

func (h *houseSlimes) getChangeIndexes() []int {
	buf := 0
	queue := make([]int, 0)

	for i := range h.slimes {
		if buf == 0 {
			buf = h.slimes[i]
			continue
		} else {
			if h.slimes[i] == buf {
				queue = append(queue, i)
				buf = 0
			} else {
				buf = h.slimes[i]
			}
		}
	}
	return queue
}

func (h *houseSlimes) changeColor(indexes []int) int {
	return len(indexes)
}

func splitSpace(input string) []string {
	return strings.Split(input, " ")
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

  int n;
  long long a;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    int x = 0;
    while (a) {
      if (a % 2 != 0) 
        break;
      ++x;
      a /= 2;
    }
    ans += x;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    set<int> s;
    int n;
    cin>>n;
    int d[n];
    for(int i=0;i<n;i++){
        cin>>d[i];
        s.insert(d[i]);
    }
    cout<<s.size()<<endl;
    return(0);
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int n, p;
    // cin >> n >> p;
    string s;
    cin >> s;
    n = s.size(), p = 2019;
    ll ans = 0;
    ll a[n+1] = {};
    rep(i,n){
        a[i] = s[i] - '0';
    }
    ll f[n+1] = {};
    ll g[n+1] = {};

    rep(i,n){
        g[i] = a[i] * mod_pow(10, n-1-i, p);
    }
    drep(i,n){
        f[i] = (f[i+1] + g[i]) % p;
    }

    ll b[p+1] = {};
    rep(i,n+1){
        b[f[i]]++;
    }

    rep(i,p+1){
        ans += b[i] * (b[i]-1) / 2;
    }

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




Measured memory_bytes: 8400
def main():
    input()
    a = list(map(int, input().split()))
    ans = 1
    for el in a:
        if el == 0:
            print(0)
            return
    for el in a:
        ans *= el
        if ans > 1e18:
            print(-1)
            return
    else:
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21664
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    ans=0
    for i in range(n):
        l,r=INTM()
        ans+=r-l+1
    print(ans)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s, t;
  cin >> s >> t;
  ll m = s.size();
  ll n = t.size();
  vector<vl> sum(26, vl(m + 1, 0));
  rep(i, 26) rep(j, m) sum[i][j + 1] = sum[i][j] + (s[j] == char(i + 'a'));
  ll now = 0, cnt = 0;
  rep(i, n) {
    ll c = t[i] - 'a';
    auto be = sum[c].begin();
    be += now;
    auto it = lower_bound(be, sum[c].end(), sum[c][now] + 1);
    if(it != sum[c].end()) {
      now = it - sum[c].begin();
      continue;
    }
    it = lower_bound(all(sum[c]), 1);
    if(it != sum[c].end()) {
      cnt++;
      now = it - sum[c].begin();
      continue;
    }
    cout << -1 << endl;
    return 0;
  }
  cout << cnt * m + now << endl;
}

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

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

  int n1 = N / 1000;
  int n2 = ( N - n1 * 1000 ) / 100;
  int n3 = ( N - n1 * 1000 - n2 * 100 ) / 10;
  int n4 = N % 10 ;

  // 1-3か2-4の連続性判定
  if ( ( n1 == n2 && n2 == n3 ) || ( n2 == n3 && n3 == n4 ) ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }  

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 100001;
ll h,w,a,b,c,ans=INF;

int main(){
	cin>>h>>w;
	if(h%3==0||w%3==0){
		cout<<0<<endl;
		return 0;
	}
	if(w==2||h==2){
		cout<<1<<endl;
		return 0;
	}
	FOR(i,1,h){
		a=i*h;
		if(((w-i)*h)%2==0){
			b=((w-i)*h)/2;
			c=b;
		}else{
			ll x,y;
			x=max(w-i,h);
			y=min(w-i,h);
			b=(x/2+1)*y;
			c=(x/2)*y;
		}
		ans=min(ans,max({a,b,c})-min({a,b,c}));
	}
	FOR(i,1,w){
		a=i*w;
		if(((h-i)*w)%2==0){
			b=((h-i)*w)/2;
			c=b;
		}else{
			ll x,y;
			x=max(h-i,w);
			y=min(h-i,w);
			b=(x/2+1)*y;
			c=(x/2)*y;
		}
		ans=min(ans,max({a,b,c})-min({a,b,c}));
	}	
	cout<<ans<<endl;
	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,n)        for (i = 0; i < n; ++i)
#define REP(i,k,n)      for (i = k; i <= n; ++i)
#define REPR(i,k,n)     for (i = k; i >= n; --i)
#define w(x)            int x; cin>>x; while(x--)
#define mk(arr,n,type)  type *arr=new type[n];
#define inrange(i, a, b)((i >= min(a, b)) && (i <= max(a, b)))
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fsb(index)      (index & -index)
typedef long long       ll;
typedef pair<int,int>   pi;
typedef pair<long,long> pl;
typedef vector<int>     vi;
typedef vector<pi>      vpi;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int mod = 1000000007;

int main() {
    fast
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    char c;
    cin >> c;
    if(inrange(c,'a','z')){
    	cout << 'a';
    }else{
    	cout << 'A';
    }
    return 0;
}

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

int main()
{
	string s;
	cin >> s;
	string last = "";
	string cur = "";
	int cnt = 0;
	for (int i = 0; i < s.length(); ++i)
	{
		cur += s[i];
		if (cur != last)
		{
			last = cur;
			cur = "";
			cnt++;
		}
		else
		{
			cur += s[i];
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, char> Pc;
typedef pair<int, string> Ps;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
const int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const string dir8[8] = {"U", "RU", "R", "RD", "D", "LD", "L", "LU"};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} 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.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll N;
  cin >> N;

  ll sum = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 5 == 0 && i % 3 == 0) {
    } else if (i % 5 == 0) {
    } else if (i % 3 == 0) {
    } else {
      sum += i;
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3168
#include <iostream>

using namespace std;

int main(){
    long D, G;
    cin >> D >> G;
    long p[10], c[10];
    for(int i = 0; i < D; i++) cin >> p[i] >> c[i];
    long m = (1<<D);
    long ans = 10000;
    for(long i = 0; i < m; i++){
        long sum = 0;
        long tmp = 0;
        for(long j = 0; j < D; j++){
            if(i&(1<<j)) {
                sum += (j+1)*100*p[j];
                sum += c[j];
                tmp += p[j];
            }
        }
        //cout << sum << endl;
        if(sum >= G) {
            ans = min(ans, tmp);
            continue;
        }
        for(long j = 0; j < D; j++){
            if(!(i&(1<<j))) {
                if(sum+100*(j+1)*p[j] < G) continue;
                ans = min(ans, tmp+(G-sum+100*(j+1)-1)/(100*(j+1)));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
n = int(input())
T,A = 1,1
for i in range(n):
    t,a = map(int,input().split(" "))
    coef = max((T+t-1)//t,(A+a-1)//a)
    T,A = coef * t, coef * a 
print(T+A)     

    


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

int main() {
  string S;
  cin >> S;
  cout << S[0] << S[1] << S[2] << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
 
int main(void){
	int n, x;
	int i, j, k;
	int count=0;
	while(1){
		scanf("%d %d", &n, &x);	/* n?????\?????????3??\???100??\?????¨?????? */
			if((n==0)&&(x==0)) {
			break;	/* n x??±???0????????\????????? */
	}
	for (i=1; i<=n; i++) {
		for (j=1; j<=n; j++) {
			for (k=1; k<=n; k++) {
				if (i+j+k==x && i!=j && j!=k && k!=i) {
					count++;	/* ???????????????????????£?????¨??????????????????????????? */
				}
			}
		}
	}
	printf("%d\n", count/6);	/* ??????????????????????????????????????°????????? */
		count=0;
	}
	return 0;
}

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


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int               long long
#define endl              '\n'
#define ff                first
#define ss                second
#define mp                make_pair
#define pb                push_back
#define vii               vector<int> 
#define pii               pair<int,int>
#define vpii              vector< pii >
#define all(v)            v.begin(),v.end()
#define loop(i,s,e)       for(int i=s;i<e;i++)
#define rloop(i,e,s)      for(int i=e;i>=s;i--)
#define mset(a,f)              memset(a,f,sizeof(a))
#define M                 1000000007
#define fastio            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define prvec(v)          loop(i_u_j,0,v.size())cout << v[i_u_j] <<" "; cout << endl;
#define prarr(arr,n)      loop(i_u_j,0,n)cout << arr[i_u_j] << " "; cout << endl;
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //
const int N = 3e5 + 7;
int n, w, x;
int arr[N], mat[25][25];

int dp[22][(1<<21)];
int get(int p,int mask)
{     
      int &cache = dp[p][mask];
      if( p == n and mask == 0 ) return cache  = 1;
      if( p == n and mask > 0 )  return cache  = 0;
      if( cache != -1 ) return cache;
      int ways = 0;
      loop(j,0,n)
      {
            if( mat[p][j] == 1 and (x>>j)&mask ) 
            {
                  ways += get(p+1, mask^(x>>j));
                  // bug(mask, mask^(x>>j));
                  ways %= M;
            }
      }
      return cache = ways;
}


void solve()
{
      cin >> n ;
      x = 1<<(n-1);
      loop(i,0,n)loop(j,0,n) cin>> mat[i][j];
      int mask = 1<<n; mask--;
      mset(dp,-1);
      cout << get(0,mask);

}

int32_t main() {
    fastio;

  
  int t = 1; 
  //cin>>t;
  
  while(t--) solve();


  
  


}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //















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

#define int long long
const int N = 305;
int n,g[305][305],ans;

signed main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            cin>>g[i][j];
            ans+=g[i][j];
        }
    }
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            for(int k=1;k<=n;k++) {
                if(i==j) continue;
                if(j==k) continue;
                if(k==i) continue;
                if(g[i][j] > g[i][k]+g[k][j]) {
                    cout<<-1;
                    return 0;
                }
                if(g[i][j] == g[i][k]+g[k][j]) {
                    ans-=g[i][j];
                    break;
                }
            }
        }
    }
    cout<<ans/2ll<<endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            HashSet<string> S = new HashSet<string>();
            foreach(string x in Console.ReadLine().Trim().Split(' ')) S.Add(x);
            int q = int.Parse(Console.ReadLine());
            int count = 0;
            foreach (string x in Console.ReadLine().Trim().Split(' '))
                count =  S.Contains(x) ? count + 1 : count;
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 20360
#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  int n,t,r=0,d=0;
  cin>>n>>t;
  vector<int> a;
  for(int i=0,j=-1,c;i<n;++i){
    cin>>c;
    if(i<2||(a[j-1]<a[j]&&a[j]>c)||(a[j-1]>a[j]&&a[j]<c))j++,a.push_back(c);
    else if((a[j-1]<a[j]&&a[j]<c)||(a[j-1]>a[j]&&a[j]>c))a[j]=c;
  }
  n=a.size();
  for(int i=0,m=a[0];i<n-1;++i){
    m=min(m,a[i]);
    if(m<a[i+1]){
      if(a[i+1]-m==d)r++;
      else if(a[i+1]-m>d)r=1,d=a[i+1]-m;
    }
  }
  cout<<r;
}

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

int main(void)
{
  //Nを入力
  int n;
  scanf("%d",&n);

  //市名と点数を入力
  int i,j,k,p[n],pn[n];
  char s[n][20];
  for(i=0;i<n;i++){
    scanf("%s",&s[i]);
    scanf("%d",&p[i]);
    pn[i] = i+1;
  }

  //点数順に並び替え
  int tmp;
  char stmp[20];
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      if(p[i]<p[j]){
        tmp  = p[i];
        p[i] = p[j];
        p[j] = tmp;

        tmp   = pn[i];
        pn[i] = pn[j];
        pn[j] = tmp;

        strcpy(stmp,s[i]);
        strcpy(s[i],s[j]);
        strcpy(s[j],stmp);
      }

  //辞書順にバブルソートで並び替え
  int cnt;
  while(1){
    cnt = 0;

    for(i=0;i<n-1;i++)
      if(strcmp(s[i],s[i+1])>0){
        tmp   = p[i];
	p[i]  = p[i+1];
	p[i+1]= tmp;

	tmp    = pn[i];
        pn[i]  = pn[i+1];
        pn[i+1]= tmp;

	strcpy(stmp,  s[i]);
        strcpy(s[i],  s[i+1]);
        strcpy(s[i+1],stmp);

	cnt++;
      }

    if(cnt==0)
        break;
  }

  //出力
  for(i=0;i<n;i++){
    printf("%d\n",pn[i]);
  }

  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){	
			final long A = sc.nextLong();
			final long B = sc.nextLong();
			final long K = sc.nextLong();
			
			final long t = Math.max(0, A - K);
			final long s = Math.max(0, B - Math.max(0, K - A));
			
			System.out.println(t + " " + s);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 22356
#include <iostream>
using namespace std;
#define NIL -1
#define MAX 100005

class Tree{
private:
  struct Node{
    int parent, left, right;
  };
public:
  Node node[MAX];
  int depth[MAX];
  void setDepth(int u, int p);
  void printNodeInf(int u);
};

void Tree::setDepth(int u, int p){
  depth[u] = p;
  if(node[u].right != NIL){
    setDepth(node[u].right, p);
  }
  if(node[u].left != NIL){
    setDepth(node[u].left, p + 1);
  }
}

void Tree::printNodeInf(int u){
  int c = node[u].left;
  cout << "node " << u << ": ";
  cout << "parent = " << node[u].parent << ", ";
  cout << "depth = " << depth[u] << ", ";

  if(node[u].parent == NIL) cout << "root, ";
  else if(node[u].left == NIL) cout << "leaf, ";
  else cout << "internal node, ";
  cout << "[";

  for(int i = 0; c != NIL; i++, c = node[c].right){
    if(i != 0) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

int main(void){
  int n, id, k, c, l, r;
  Tree tree;
  cin >> n;

  for(int i = 0; i < n; i++){
    tree.node[i].parent = tree.node[i].left = tree.node[i].right = NIL;
  }

  for(int i = 0; i < n; i++){
    cin >> id >> k;
    for(int j = 0; j < k; j++){
      cin >> c;
      if(j == 0) tree.node[id].left = c;
      else tree.node[l].right = c;
      l = c;
      tree.node[c].parent = id;
    }
  }

  for(int i = 0; i < n; i++){
    if(tree.node[i].parent == NIL) r = i;
  }

  tree.setDepth(r, 0);
  for(int i = 0; i < n; i++) tree.printNodeInf(i);
  return 0;
}

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

int main()
{
  int a[6];
  bool p=1;  
  for(int i=0;i<6;i++){
    scanf("%d",&a[i]);
  }
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++)
      if(a[j]-a[i]>a[5])
        p=0;
  }
  if(p==0)
    printf(":(");
  else
    printf("Yay!");
  return 0;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

const int M = 1e5 + 7;
long long dp[M];

int main() {
    int n, W;
    scanf("%d %d", &n, &W);
    
    for (int i = 1; i <= n; ++i) {
        int w, v;
        scanf("%d %d", &w, &v);
        for (int j = W; j >= w; --j) {
            dp[j] = max(dp[j], dp[j - w] + v);
        }
    }
    printf("%lld\n", dp[W]);
    return 0;
}


Measured memory_bytes: 1024
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 5121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[110000];
int q[110000];
int P[110000];
int Q[110000];
int to[110000];
int v[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
		P[i]=p[i];
	}
	for(int i=0;i<a;i++){
		scanf("%d",q+i);
		Q[i]=q[i];
	}
	std::sort(P,P+a);
	std::sort(Q,Q+a);
	for(int i=0;i<a;i++){
		if(P[i]>Q[i]){
			printf("No\n");return 0;
		}
	}
	for(int i=0;i<a-1;i++){
		if(P[i+1]<=Q[i]&&P[i]<=Q[i+1]){
			printf("Yes\n");return 0;
		}
	}
	for(int i=0;i<a;i++){
		int L=lower_bound(P,P+a,p[i])-P;
		int R=lower_bound(Q,Q+a,q[i])-Q;
		to[L]=R;
	}
	int ret=0;
	for(int i=0;i<a;i++){
		if(v[i]==0){
			ret++;
			int now=i;
			while(v[now]==0){
				v[now]=1;
				now=to[now];
			}
		}
	}
	if(ret==1)printf("No\n");else printf("Yes\n");
}

Measured memory_bytes: 2560
n = gets.chomp.to_i
tree = []
lines = []
n.times { tree << [] }
(n - 1).times do
  a, b = gets.chomp.split(' ').map { |i| i.to_i - 1 }
  tree[a] << b
  tree[b] << a
  lines << "#{a}-#{b}"
end

colors = {}
parent_colors = {}
visited = Array.new(n, false)
color_count = 0
queue = [0]
visited[0] = true
until queue.empty?
  q = queue.pop
  color_count = [tree[q].length, color_count].max
  color = 1
  tree[q].each do |i|
    next if visited[i]
    color += 1 if parent_colors[q] == color
    colors["#{q}-#{i}"] = color
    colors["#{i}-#{q}"] = color
    parent_colors[i] = color
    visited[i] = true
    queue << i
    color += 1
  end
end
puts color_count
lines.each { |l| puts colors[l] }

Measured memory_bytes: 49916
import numpy as np
n, k = list(map(int, input().split()))
mod = 10 ** 9 + 7

m = n ** 0.5
cnt = [n // i - n // (i + 1) for i in range(1, int(m) + 1)] 
cnt = np.array((cnt + [1 for _ in range(n - sum(cnt))])[::-1])
nxt = cnt[:]
for _ in range(k - 1):
	cnt = nxt * np.cumsum(cnt)[::-1] % mod

print(sum(cnt) % mod)


Measured memory_bytes: 14668