akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int lg = 21;

int n, q;
int d[100100];
int up[100100][22];
int col[100100];
ll cost[100100];
ll ans[100100];
int cnt[100100];
ll col_dist[100100];
vector<int> adj[100100];
vector<ll> weight[100100];
vector<int> color[100100];
vector<int> query[100100];

int lca(int u, int v) {
    if (d[u] > d[v]) swap(u, v);

    int delta = d[v] - d[u];
    for (int i = 0; i <= lg; i++) {
        if (delta & (1 << i)){
            v = up[v][i];
        }
    }

    if (u == v) return u;

    for (int i = lg; i >= 0; i--) {
        if (up[u][i] != up[v][i]) {
            u = up[u][i];
            v = up[v][i];
        }
    }

    return up[u][0];
}

void dfs(int v, int p, int depth) {
    d[v] = depth;
    up[v][0] = p;
    for (int i = 1; i <= lg; i++) {
        up[v][i] = up[up[v][i - 1]][i - 1];
    }
    for (int i = 0; i < (int)adj[v].size(); i++) {
        if (adj[v][i] == p) continue;
        dfs(adj[v][i], v, depth + 1);
    }
}

void solve(int v, int p, ll dist) {
    for (int idx: query[v]) {
        ll mul = 1;
        if (idx < 0)  {
            mul = -2;
            idx = -idx;
        }
        ans[idx] += mul * (cnt[col[idx]] * cost[idx] - col_dist[col[idx]] + dist);
    }

    for (int i = 0; i < (int)adj[v].size(); i++) {
        if (adj[v][i] == p) continue;
        cnt[color[v][i]]++;
        col_dist[color[v][i]] += weight[v][i];
        solve(adj[v][i], v, dist + weight[v][i]);
        cnt[color[v][i]]--;
        col_dist[color[v][i]] -= weight[v][i];
    }
}



int main() {
    scanf("%d %d", &n, &q);

    for (int i = 0; i < n - 1; i++) {
        int u, v, c;
        ll w;
        scanf("%d %d %d %lld", &u, &v, &c, &w);
        adj[u].push_back(v);
        adj[v].push_back(u);
        color[u].push_back(c);
        color[v].push_back(c);
        weight[u].push_back(w);
        weight[v].push_back(w);
    }

    dfs(1, 0, 0);
    // for (int j = 1; j <= lg; j++) {
    //     for (int i = 1; i <= n; i++) {
    //         up[i][j] = up[up[i - 1][j - 1]][j - 1];
    //     }
    // }

    for (int i = 1; i <= q; i++) {
        int u, v;
        scanf("%d %lld %d %d", &col[i], &cost[i], &u, &v);
        query[u].push_back(i);
        query[v].push_back(i);
        query[lca(u, v)].push_back(-i);
        // printf("LCA %d\n", lca(u, v));
    }

    solve(1, 0, 0);

    for (int i = 1; i <= q; i++) {
        printf("%lld\n", ans[i]);
    }
}

Measured memory_bytes: 40572
N,K=map(int,input().split())
A=[]
people=list(range(1,N+1,1))
for idx in range(K):
    d=int(input())
    X=list((map(int,input().split())))
    for i in range(len(X)):
        A.append(X[i])
ans =[i for i in people if not i in A]
print(len(ans))

Measured memory_bytes: 9040
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 3000000007;
const double INFD = 1e100;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  ll A,B;
  cin >> A >> B;
  ll x,y;
  A--;
  if(A%2 == 0){
    x = A/2;
    if(x%2 == 1){
      A++;
    }
  }else{
    A++;
    x = A/2;
    if(x%2 == 1){
      A = 1;
    }else{
      A = 0;
    }
  }
  if(B%2 == 0){
    y = B/2;
    if(y%2 == 1){
      B++;
    }
  }else{
    B++;
    y = B/2;
    if(y%2 == 1){
      B = 1;
    }else{
      B = 0;
    }
  }
  ll ans = A ^ B;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

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

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

	var cnt int
	for i := 0; i < n; i++ {
		if i == n-1 {
			cnt++
			break
		}
		for a[i] == a[i+1] {
			i++
		}
		if a[i] < a[i+1] {
			for i < n-1 && a[i] <= a[i+1] {
				i++
			}
		} else if a[i] > a[i+1] {
			for i < n-1 && a[i] >= a[i+1] {
				i++
			}
		}
		cnt++
	}
	fmt.Print(cnt)
}


Measured memory_bytes: 3072
#include <stdio.h>

int main(void){
  int N, A, B;
  
  scanf("%d %d %d", &N, &A, &B);
  if(N*A<B){
    printf("%d", N*A);
  }else if(N*A>=B){
    printf("%d", B);
  }
  
  return 0;
}

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

void search(vector<vector<int>> &g, vector<int> &nxt, queue<int> &q)
{
    int tar = q.front(); q.pop();
    for (int s:g[tar])
    {
        if (nxt[s] == -1) 
        {
            q.push(s);
            nxt[s] = tar;
        }
    }
    if (q.size() < 1) return;
    else search(g, nxt, q);
}

int main(void)
{
    int n, m; cin >> n >> m;
    vector<vector<int>> g(n, vector<int>(0));
    int n1, n2;
    for (int i = 0; i < m; i++)
    {
        cin >> n1 >> n2;
        g[n1-1].push_back(n2-1);
        g[n2-1].push_back(n1-1);
    }
    
    vector<int> nxt(n, -1); nxt[0] = 0;
    queue<int> q; q.push(0);
    search(g, nxt, q);
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++)
    {
        cout << nxt[i] + 1 << endl;
    }
}


Measured memory_bytes: 10268
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n = int(input())
a = list(map(int,input().split()))
co = 0

a = gcd_list(a)

while a % 2 == 0:
    co += 1
    a //= 2
print(co)

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

void make_rectangle(int h, int w){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) cout<<'#';
    cout<<"\n";
  }
  cout<<"\n";
}
int main(){
  int h,w;
  while(1){
    cin>>h>>w;
    if(h==0 && w==0) break;
    make_rectangle(h,w);
  }
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  int n; cin >> n;
  vi a(n);
  REP(i, n) cin >> a[i];

  map<int, P> mp;
  RREP(i, n-1) {
    mp[a[i]].first++;
    mp[a[i]].second = i;
  }

  vector<pair<int, P>> v;
  for(auto &e: mp) {
    v.push_back({e.first, e.second});
  }
  sort(v.rbegin(), v.rend());
  v.push_back({0, {0, 0}});
  int sz = SZ(v);

  vi cnt(n);
  REP(i, sz-1) {
    cnt[v[i].second.second] += v[i].second.first * (v[i].first - v[i+1].first);
    v[i+1].second.first += v[i].second.first;
    chmin(v[i+1].second.second, v[i].second.second);
  }

  REP(i, n) {
    cout << cnt[i] << endl;
  }

}
























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

dic = {i: 0 for i in range(10 ** 5 + 1)}

for a in A:
    dic[a] += 1

ans = 0

for i in range(1, 10 ** 5):
    ans = max(ans, dic[i - 1] + dic[i] + dic[i + 1])
    
print(ans)

Measured memory_bytes: 24236
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using static System.Math;
using System.Runtime.CompilerServices;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var n = NextInt;
        var q = NextInt;
        var neighbors = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < n - 1; i++)
        {
            var a = NextInt - 1;
            var b = NextInt - 1;
            neighbors[a].Add(b);
            neighbors[b].Add(a);
        }
        long[] val = new long[n];
        for (int i = 0; i < q; i++)
        {
            val[NextInt - 1] += NextInt;
        }
        bool[] arrived = new bool[n];
        Stack<int> stack = new Stack<int>();
        stack.Push(0);
        arrived[0] = true;
        while (stack.Count > 0)
        {
            var elem = stack.Pop();
            foreach (var neighbor in neighbors[elem])
            {
                if (arrived[neighbor]) continue;
                arrived[neighbor] = true;
                val[neighbor] += val[elem];
                stack.Push(neighbor);
            }
        }
        Console.WriteLine(string.Join(" ", val));
    }

    static readonly TextReader In = Console.In;
    static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0;
            int next = In.Read();
            int rev = 1;
            while (45 > next || next > 57) next = In.Read();
            if (next == 45) { next = In.Read(); rev = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = In.Read();
            }
            return res * rev;
        }
    }
}


Measured memory_bytes: 57496
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main() {
    ll N,K;
    cin >> N >>K;
    if(K==0){
        cout << N*N <<endl;
        return 0;
    }
    ll ans =0;
    for(ll b=K+1;b<=N;b++){
        ans += (N/b)*(b-K);
        ans += max(0LL,(N%b)-(K-1));
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  int a;
  int b;
  int c;
  int d;
  cin >> N;
  a = N / 1000;
  b = ( N - ( 1000 * a ) ) / 100;
  c = ( N - ( 1000 * a ) - ( 100 * b ) ) / 10;
  d = N - ( 1000 * a ) - ( 100 * b ) - ( 10 * c );
  if ( a == b && b == c ){
    cout << "Yes" << endl;
  }else if ( b == c && c == d ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	double l;
	cin >> l;

	cout << fixed << setprecision(12) << (l / 3.0) * (l / 3.0) * (l / 3.0) << endl;
	   
	return 0;
}


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

int main() {
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output1.txt","w",stdout);
	// #endif

	long long int x;
	cin>>x;
	long long int ans=100;
	long long int count=0;
	while(ans<x) {
		ans+=(ans/100);
		count++;
	}
	cout<<count<<endl;
}



Measured memory_bytes: 3620
n = gets.to_i
as = gets.split.map(&:to_i)
l = {0 => as[0]}
r = {n-1 => as[-1]}

n.times.with_index(1) do |_, i|
  break if as[i].nil?
  l[i] = l[i-1].gcd(as[i])
end

(n-2).downto(0) do |i|
  r[i] = r[i+1].gcd(as[i])
end

ans = 0
n.times do |i|
  if i == 0
    tmp = r[1]
  elsif i == n-1
    tmp = l[n-2]
  else
    tmp = l[i-1].gcd(r[i+1])
  end
  ans = [ans, tmp].max
end

puts ans


Measured memory_bytes: 26124
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>

#define SIZE 9

using namespace std;

int main(){
	int t,n,k;
	int total;
	int x[100000+1];
	int dis[100000+1];
	cin>>t;
	while(t--){
		total=0;
		cin>>n>>k;
		for(int i=0; i<n; i++)cin>>x[i];
		if(n > k){
			for(int i=1; i<n;i++){
				total += x[i]-x[i-1];
				dis[i-1] = x[i]-x[i-1];
			}
			sort(dis,dis+n);
			reverse(dis,dis+n);
			if(k > 1){
				for(int i=0; i<k-1;i++){
					total -= dis[i];
				}
			}
		}
		cout<<total<<endl;
	}
	return 0;
}

Measured memory_bytes: 1956
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

int main(){
  string S; cin>>S;
  if(S.at(0)==S.at(1) && S.at(1)==S.at(2)){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main (){

int i, n;

scanf("%d",&n);

int a[n];

for(i = n - 1; i >= 0; i--)
scanf("%d", &a[i]);
for(i = 0; i <= n - 1; i++){
printf("%d", a[i]);
if(i < n-1)
printf(" ");
}
printf("\n");
}

Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iomanip>
#include <algorithm>

using namespace std;
using ll = long long;

int main(void){
    ll N, A[5];
    cin >> N;
    for(int i=0;i<5;i++) cin >> A[i];

    ll A_min = 1e16;
    for(int i=0;i<5;i++){
        A_min = min(A[i], A_min);
    }

    cout << (N-1)/A_min + 5ll << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
pdict = {}

p, n = [], []

for i in range(N) :
    _p, _n = input().split()
    _n = int(_n)
    
    if _p not in pdict.keys() :
        pdict[_p] = _n
    else :
        pdict[_p] += _n
        
plist = list(pdict.keys())

# fetch maximum length
max_len = 0
for i in set(plist) :
    max_len = max(max_len, len(i))

# append  key array corresponding to maximum length
plist.sort()

keys_sorted = []

for i in range(max_len + 1) :
    for j in plist :
        if i == len(j) :
            keys_sorted.append(j)
            
for i in keys_sorted :
    print(i, pdict[i])


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if (N % 1000 % 111 == 0){
    cout << "Yes" << endl;
  }else if ((N - N % 10) / 10 % 111 == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main implements Runnable {
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int n = fs.nextInt(), m = fs.nextInt();
		char[][] g = new char[n][m];
		int[][] dist = new int[n][m];
		for(int i = 0; i < n; i++) Arrays.fill(dist[i], -1);
		ArrayDeque<Integer> dq = new ArrayDeque<>();
		for(int i = 0; i < n; i++) {
			g[i] = fs.next().toCharArray();
			for(int j = 0; j < m; j++) {
				if(g[i][j] =='#') {
					dist[i][j] = 0;
					dq.add(i); dq.add(j);
				}
			}
		}
		int[] dx = {-1, 1, 0, 0};
		int[] dy = {0, 0, -1, 1};
		int res = 0;
		while(!dq.isEmpty()) {
			int x = dq.poll();
			int y = dq.poll();
			res = Math.max(res, dist[x][y]);
			for(int k = 0; k < dx.length; k++) {
				int nx = x+dx[k];
				int ny = y+dy[k];
				if(nx < 0 || ny < 0 || nx >= n || ny >= m) continue;
				if(dist[nx][ny] != -1) continue;
				dist[nx][ny] = 1+dist[x][y];
				dq.add(nx); dq.add(ny);
			}
		}
		out.println(res);
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

Measured memory_bytes: 77088
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define ll 		int
#define int 		long long
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define vpi 		vector<pii>
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
const int N=1e5+5;
vi g[N],rg[N];
bool vis1[N],vis2[N];
int mx,id,mxlen;
int dp1[N],dp2[N];
int dfs(int x,int lev,int par)
{

    if(g[x].size()==0)
    {
      
        return   dp1[x]=1;
    }

    if(vis1[x])
    return dp1[x];

    vis1[x]=true;
    
    int ans=0;
    for(auto it:g[x])
    {
        if(it!=par)
        ans=max(ans,dfs(it,lev+1,x));
    }

    return dp1[x]=1+ans;
}
int dfs2(int x,int lev,int par)
{
    if(rg[x].size()==0)
    return dp2[x]=1;

    if(vis2[x])
    return dp2[x];

    vis2[x]=true;

    int ans=0;
    for(auto it:rg[x])
    {
        if(it!=par)
          ans=max(ans,dfs2(it,lev+1,x));
        
    }
    return dp2[x]=1+ans;
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int n,m;
    cin>>n>>m;

    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        x--,y--;
        g[x].pb(y);
        rg[y].pb(x);
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(!vis2[i]&&!vis1[i])
        {
            
            ans=max(ans,dfs(i,0,i)+dfs2(i,0,i)-2);

            
        }
    }
    cout<<ans;

return 0;
}

Measured memory_bytes: 16512
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    long long S, W;
    cin >> S >> W;

    if(W >= S)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
}

Measured memory_bytes: 3596
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	
	return x * y / tmp;
}

vector<int> V[15];

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	
	int n;
	string s;
	cin >> n >> s;

	set<int> st;

	for (int i = 0; i < s.size(); i++)
	{
		V[s[i] - '0'].push_back(i);
	}

	for (int i = 0; i < 10; i++)
	{
		//初めの数字がiとする
		if (V[i].size() == 0)continue;

		//cout << "i= " << i << " " <<  V[i][0] << endl;
		for (int j = 0; j < 10; j++)
		{
			if (V[j].size() == 0)continue;
			auto hoge = upper_bound(V[j].begin(), V[j].end(), V[i][0]) - V[j].begin();

			

			if (hoge == V[j].size())continue;
			//cout << j << " hoge=" << V[j][max(0, hoge)] << endl;

			//インデックスはhogeに決まる
			//cout << "a" << endl;
			for (int k = 0; k < 10; k++)
			{
				if (V[k].size() == 0)continue;
				auto hoge2 = upper_bound(V[k].begin(), V[k].end(), V[j][hoge]) - V[k].begin();


				
				if (hoge2 == V[k].size())continue;

				//cout << k << " hoge2=" << hoge2 << " ll" << V[k][max(0, hoge2)] << endl;

				
				//cout << "hoge= " << V[j][max(0, hoge)] << " hoge2= " << V[k][max(0, hoge2)] << endl;
				//cout << " i = " << i << " j= " << j << " k = " << k << " " << 100 * i + 10 * j + k << endl;

				st.insert(100 * i + 10 * j + k);
			}



		}



	}


	cout << st.size() << endl;



	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int K, N;
int M, ans[312345];
ll dp[21];

int main() {
	cin >> K >> N;
	if (K == 1) {
		M = (N + 1) / 2;
		REP(i, M) ans[i] = 1;
	}
	else if (N == 1) {
		M = 1;
		ans[0] = (K + 1) / 2;
	}
	else if ((K & 1) == 0) {
		M = N;
		ans[0] = K / 2;
		FOR(i, 1, M) ans[i] = K;
	}
	else {
		int ke = min(N, 20);
		dp[0] = 1;
		FOR(i, 1, ke + 1) {
			dp[i] = dp[i-1]*K + 1;
			if (dp[i] > N) {
				ke = i + 1;
				break;
			}
		}
		
		M = N;
		REP(i, M) ans[i] = (K + 1) / 2;
		ll dif = -(N / 2);
		
		REP(i, ke) {
			dif += (ans[M - 1 - i] - 1) * dp[i];
			ans[M - 1 - i] = 0;
		}
		dif += ke;
		
		for (int i = ke - 1; i >= 0; i--) {
			if (dif == 0) break;
			ans[M - 1 - i] = 1;
			dif--;
			
			ans[M - 1 - i] += dif / dp[i];
			dif %= dp[i];
		}
		
		for (int i = M - 1; i >= 0; i--) {
			if (ans[i] == 0) M = i;
			else break;
		}
		
	}
	
	REP(i, M) printf("%d%c", ans[i], i == M - 1 ? '\n' : ' ');
	
	return 0;
}


Measured memory_bytes: 3456
#include<stdio.h>

long max(long a, long b){
  return (a > b) ? a : b;
}

long min(long a, long b){
  return (a < b) ? a : b;
}

long calcGCD(long a, long b){
  long _min, _max, r;
  _max = max(a, b);
  _min = min(a, b);
  r = _max % _min;
  while(r != 0){
    _max = _min;
    _min = r;
    r = _max%_min;
  }
  return _min;
}

long calcLCM(long a, long b){
  int GCD, LCM;
  GCD = calcGCD(a, b);
  LCM = a * b / GCD;
  return LCM;
}
int main(){
  long a, b;
  long list[50][2];
  int j = 0;
  while(scanf("%ld%ld", &a, &b)!=EOF){
    list[j][0] = calcGCD(a, b);
    list[j][1] = calcLCM(a, b);
    j+=1;
  }
  int i;
  for(i=0; i<j; i++){
    printf("%ld %ld\n", list[i][0], list[i][1]);
  }
  return 0;
}

Measured memory_bytes: 596
n = int(input())
s = 0
for i in range(1, n+1):
    s += i
    if s >= n:
        break

k = s-n
ans = []
for j in range(1, i+1):
    if j == k:
        continue
    else:
        ans.append(j)
ans = list(map(str, ans))
print('\n'.join(ans))


Measured memory_bytes: 3444
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}


signed main() {

    int a,b,c,d;cin >>a>>b>>c>>d;
    while(1){
        c-=b;if(c<=0){
            cout <<"Yes"<<endl;
            return 0;
        }
        a-=d;if(a<=0){
            cout <<"No"<<endl;
            return 0;
        }
    }
}

















Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int s;
  cin >> s;
  combination cb(s);
  mint ans = 0;
  for(int i = 1; s - 3*i >= 0; i++){
    int ns = s - 3*i;
    ans += cb(i-1+ns, i-1);
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main(){
	cin>>a;
	cin>>b;
	if(a[2]==b[0]&&a[1]==b[1]&&a[0]==b[2])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
  int n,a,b,c,ans=0,temp;
  cin >> n >> a >> b;
  for (int i=1;i<=n;i++){
    temp=i;
    c = 0;
    for(int l=0;l<5;l++){
      c += temp%10;
      temp /= 10;
    }
    if(a <= c && c <= b){
      ans += i;
    }
  }
  cout << ans << endl;
}


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


from sys import stdin
from operator import itemgetter

N = int(stdin.readline().rstrip())

rest_list = []

for i in range(N):
    S, P = [x for x in stdin.readline().rstrip().split()]
    P = int(P)
    rest_list.append([i+1,S,P])


sorted_rest_1 = sorted(rest_list, key=itemgetter(2),reverse=True)
sorted_rest_2 = sorted(sorted_rest_1, key=itemgetter(1))

for i in range(N):
    print(sorted_rest_2[i][0])


Measured memory_bytes: 3060
main(N,R,M,m,y,n,t,c,i,d){double r;
	for(scanf("%d",&N);N--;printf("%d\n",R)){
		for(scanf("%d%d%d",&M,&y,&n),R=M;n--;R=m>R?m:R){
			if(m=M,d=0,scanf("%d%lf%d",&t,&r,&c),t){
				for(i=0;i<y;i++)m+=(int)(r*m)-c;
			}else{
				for(i=0;i<y;i++)d+=(int)(r*m),m-=c;m+=d;
			}
		}
	}
exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define ll long long
using namespace std;
const int N=1e6+6; const ll INF=1e18;
struct data{ ll w; int s; }a[N];
bool cmp(data a,data b){ return a.s*b.w>b.s*a.w; }
int fa[N]; ll f[N];
void add(int m,int s,ll w,int t){
    int sk=0; t=min(t,m/s);
    for (int k=1;k*2<=t;k<<=1){
        sk+=k;
        per(j,m,s*k) if (f[j-s*k]!=INF) f[j]=min(f[j],f[j-s*k]+w*k);
    }
    int k=t-sk;
    per(j,m,s*k) if (f[j-s*k]!=INF) f[j]=min(f[j],f[j-s*k]+w*k);
}
int main(){
    int n,x,d; scanf("%d%d%d%lld",&n,&x,&d,&a[1].w);
    rep(i,2,n) scanf("%lld%d",&a[i].w,&fa[i]);
    per(i,n,1) a[fa[i]].s+=++a[i].s,a[fa[i]].w+=a[i].w;
    ll sum=a[1].w;
    int c=min(n,d);
    rep(i,1,c*n*n) f[i]=INF;
    add(c*n*n,a[1].s,a[1].w,n);
    rep(i,2,n) add(c*n*n,a[i].s,a[i].w,c);
    sort(a+1,a+1+n,cmp); int ans=0;
    rep(j,0,c*n*n){
        if (f[j]>x) continue;
        int t=j,r=x-f[j];
        rep(i,1,n)
            if (r>=a[i].w){
                int p=min(r/a[i].w,sum==a[i].w?INF:(ll)d-c);
                r-=p*a[i].w,t+=p*a[i].s;
            }
        ans=max(ans,t);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  
  for (int i = 0; i < n; ++i) cin >> v[i];
  
  int mi = min(n, k);
  int ans = 0;
  for (int a = 0; a <= mi; ++a) {
    for (int b = 0; b <= mi; ++b) {
      if (a + b > mi) break;
      int sum = 0;
      priority_queue<int, vector<int>, greater<int>> q;
      for (int i = 0; i < a; ++i) {
        sum += v[i];
        q.push(v[i]);
      }
      for (int j = n - 1; j >= n - b; --j) {
        sum += v[j];
        q.push(v[j]);
      }


      ans = max(ans, sum);
      int remain = k - (a + b);
      while (remain-- > 0 && !q.empty()) {
        int cur = q.top();
        if (cur >= 0) break;
        q.pop();
        sum += abs(cur);
        ans = max(ans, sum);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	
	int flag = 0;
	while(a > 0 && c > 0) {
		if(flag) a -= d;
		else c -= b;
		flag ^= 1;
	}
	
	if(a > 0) puts("Yes");
	else puts("No"); 
}

Measured memory_bytes: 3760
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;cin>>n;
  vector<char> str(n+n);
  for(int i=0;i<n+n;i=i+2)
    cin>>str[i];
  for(int i=1;i<n+n;i=i+2)
    cin>>str[i];
 for(auto i:str)
    cout<<i;
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, x, N) for (long long i = x; i < (N); i++)
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    int count = 0;
    int i = N;
    while (i != 0)
    {
        i /= K;
        count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
n = int(input())
hlist = list(map(int,input().split()))

result = True
for j in range(n-1):
  if hlist[j] < hlist[j+1]:
    hlist[j+1] -= 1
  elif hlist[j] == hlist[j+1]:
    pass
  else:
    result = False
    
if result:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 14396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int n1 = Integer.parseInt(bf.readLine());
        String[] sp1 = bf.readLine().split(" ");
        int n2 = Integer.parseInt(bf.readLine());
        String[] sp2 = bf.readLine().split(" ");
        int sum = 0;
        for (int j = 0; j < n2; j++) {
            for (int i = 0; i < n1; i++) {
                if (sp2[j].equals(sp1[i])) {
                    sum++;
                    break;
                }
            }
        }
        System.out.println(sum);
    }
}



Measured memory_bytes: 26596
#include<iostream>

#include<cstdio>

using namespace std;


int main(){

  int n,m,min,max,sum;

  
  while(cin>>n,n){

    min=500;max=0;

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

      sum=0;

      for(int l=0;l<5;l++){

        cin>>m;

        sum+=m;

      }

      if(sum>max) max=sum;

      if(sum<min) min=sum;

    }
 
   
    printf("%d %d\n",max,min);

  }

  return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <sstream>
#include <cmath>
#include <complex>
using namespace std;

typedef complex<double> point;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define DEB 0
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)

point s[100],e[100];

double cross(point a, point b){
  return (a.real()*b.imag() - a.imag()*b.real());
}
int is_intersected_ls(point a1, point a2, point b1, point b2){
  return ( (cross(a2-a1,b1-a1) * cross(a2-a1,b2-a1))<EPS &&
           (cross(b2-b1,a1-b1) * cross(b2-b1,a2-b1))<EPS );
}
point intersection_ls(point a1, point a2, point b1, point b2){
  point b = b2 - b1;
  double d1 = abs(cross(b, a1-b1));
  double d2 = abs(cross(b, a2-b1));
  double t = d1 / (d1 + d2);
  return a1 + (a2-a1) * t;
}

int main(){
  int n;
  while(cin>>n,n){
    rep(i,n){
      cin >> s[i].real() >> s[i].imag() >> e[i].real() >> e[i].imag();
    }
    int ans = 1;
    rep(i,n){
      int cnt = 0;
      vector<point> v;
      rep(j,i){
        if( is_intersected_ls(s[i],e[i], s[j],e[j]) ){
          point kouten = intersection_ls(s[i],e[i],s[j],e[j]);
          if( abs(kouten.real()) > 100.0 - EPS ) continue;
          if( abs(kouten.imag()) > 100.0 - EPS ) continue;
#if DEB          
          cout << kouten << endl;
#endif          
          int k;
          for(k=0; k<v.size(); k++){
#if DEB
            cout << kouten << " : " << v[k] << " , " << EQV(kouten,v[k]) << endl;
#endif
            if( EQV(kouten, v[k]) ) break;
          }
          if( k==v.size() ){
            cnt++;
            v.push_back(kouten);
          }
        }
      }
#if DEB
      printf("cnt:%d\n",cnt);
#endif
      ans += cnt+1;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 968
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second

int f(int n) {
    if (n % 2 == 0) {
        return n / 2;
    } else {
        return 3 * n + 1;
    }
}

int main() {
    int s;
    set<int> st;
    cin >> s;

    st.insert(s);
    int tmp = s;
    int c = 2;
    while (true) {
        tmp = f(tmp);
        if (st.find(tmp) != st.end()) {
            break;
        } else {
            st.insert(tmp);
            c++;
        }
    }
    cout << c << 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 N 200000
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	int n;
    IN(n);
    vector<int>h(n);
    REP(i,n){
        IN(h[i]);
    }
    int cnt=0;
    bool f=true;
    REP(i,n-1){
        if(h[i]>h[i+1]+1){
            f=false;
            break;
        }
        if(h[i]>h[i+1]){
            cnt++;
            if(cnt>=2){
                f=false;
                break;
            }
        }else if(h[i]<h[i+1]){
            cnt=0;
        }
    }
    if(f)OUT("Yes");
    else OUT("No");
	return 0;
}

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

vector<vector<int>> matmul(vector<vector<int>> A, vector<vector<int>> B, int mod=0) {
  assert(A[0].size() == B.size());
  int n = A.size(), m=A[0].size(), l=B[0].size();
  vector<vector<int>> C(n, vector<int>(l));
  for(int i=0; i<m; i++) for(int j=0; j<n; j++) for(int k=0; k<l; k++) {
    C[j][k] += A[j][i] * B[i][k];
    if(mod) C[j][k] %= mod;
  }
  return C;
}

vector<int> matmul(vector<vector<int>> A, vector<int> b, int mod=0) {
  assert(A[0].size() == b.size());
  int n = A.size(), m=A[0].size();
  vector<int> C(n);
  for(int i=0; i<m; i++) for(int j=0; j<n; j++) {
    C[j] += A[j][i] * b[i];
    if(mod) C[j] %= mod;
  }
  return C;
}

vector<vector<int>> matpow(vector<vector<int>> A, int p, int mod=0) {
  assert(A.size() == A[0].size());
  int n = A.size();
  vector<vector<int>> B(n, vector<int>(n));
  for(int i=0; i<n; i++) B[i][i] = 1;
  vector<vector<int>> C(A);
  while (p > 0) {
    if (p & 1) {B = matmul(B, C, mod);}
    C = matmul(C, C, mod);
    p >>= 1;
  }
  return B;
}

signed main() {
#if 1 // https://atcoder.jp/contests/dp/tasks/dp_r
  int N, K;
  cin >> N >> K;
  vector<vector<int>> a(N, vector<int>(N));
  for(int i=0; i<N; i++) for(int j=0; j<N; j++) cin >> a[i][j];

  auto ak = matpow(a, K, 1000000007);
  int ans = 0;
  for(int i=0; i<N; i++) for(int j=0; j<N; j++) ans = (ans + ak[i][j]) % 1000000007;
  cout << ans << endl;

#elif 1 // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_D
  int n,m;
  cin >> n >> m;
  vector<vector<int>> A(n, vector<int>(m));
  vector<int> b(m);
  for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> A[i][j];
  for(int i=0; i<m; i++) cin >> b[i];
  auto C = matmul(A, b);
  for(int i=0; i<n; i++) printf("%lld\n", C[i]);
#elif 1 // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_D
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> A(n, vector<int>(m));
  vector<vector<int>> B(m, vector<int>(l));

  for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> A[i][j];
  for(int i=0; i<m; i++) for(int j=0; j<l; j++) cin >> B[i][j];

  auto C = matmul(A,B);

  for(int i=0; i<n; i++) for(int j=0; j<l; j++) 
      printf("%lld%s", C[i][j], j==l-1 ? "\n" : " ");
#endif
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if (a!=b&& b!=c&&a!=c)
        cout<<3;
    else if (a==b&&a==c)
        cout<<1;
    else if (a==c||a==b||b==c)
        cout<<2;

return 0;
}




Measured memory_bytes: 3632
#include <iostream>
using namespace std;
#define rep(i,q) for(int i = 0; q > i; i++)

int main(){
  string n;
  cin >> n;
  int kekka = 0;
  rep(i,n.size()){
    if(n[i] == '2')kekka++;
  }
  cout << kekka << endl;
  return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
//int dy[] = {0, 0, -1, 1};
//int dx[] = {1, -1, 0, 0};

int main() {
    int numstages;
    while (cin >> numstages && numstages) {
        int dp[numstages]; rep(i, numstages + 1) dp[i] = 0;
        dp[1] = 1;
        dp[2] = 2;
        dp[3] = 4;
        rrep(i, 4, numstages + 1) {
            dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
        }
        cout << dp[numstages] / 365 / 10 + 1 << endl;
    }
}



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

typedef long long ll;

const int MAX_N = 5e5 + 5, MOD = 1e9 + 7;
int n, ans;
int c[MAX_N];
int pw2[MAX_N];

int _sum(int a, int b) {
	int c = a + b;
	if (MOD <= c)
		c -= MOD;

	return c;
}

int _mul(int a, int b) {
	int c = 1LL * a * b % MOD;
	return c;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	pw2[0] = 1;
	for (int i = 1; i < MAX_N; i++)
		pw2[i] = _mul(2, pw2[i - 1]);

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(c, c + n);

	for (int i = 0; i < n; i++) {
		int z = pw2[n-1-i];
		if (n-i-1)
			z = _sum(z, _mul(n-i-1, pw2[n-i-2]));

		int val = _mul(c[i], z);
		ans = _sum(ans, _mul(val, pw2[n+i]));
	}

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

Measured memory_bytes: 2944
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

s = input()
#アルファベット
al=[chr(ord('a') + i) for i in range(26)]
ans = inf
for c in al:
    pre = 0
    maxpre = 0
    for now in s:
        if c == now:
            maxpre = max(pre, maxpre)
            pre = 0
        else:
            pre += 1
    maxpre = max(pre, maxpre)
    ans = min(ans, maxpre)
print(ans)

Measured memory_bytes: 38640
// JOI2.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int w[10], k[10];

	for (int i = 0; i < 10; i++) {
		scanf("%d", &w[i]);
	}
	for (int i = 0; i < 10; i++) {
		scanf("%d", &k[i]);
	}

	int sum_w = 0, sum_k = 0, max, suffix;
	for (int i = 0; i < 3; i++) {
		max = 0;
		for (int j = 0; j < 10; j++) {
			if (max <= w[j]) {
				max = w[j];
				suffix = j;
			}
		}
		sum_w += max;
		w[suffix] = 0;
	}

	for (int i = 0; i < 3; i++) {
		max = 0;
		for (int j = 0; j < 10; j++) {
			if (max <= k[j]) {
				max = k[j];
				suffix = j;
			}
		}
		sum_k += max;
		k[suffix] = 0;
	}

	printf("%d %d\n", sum_w, sum_k);

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    if (N == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    int a = 2, ans;
    rep(1, i, 10)
    {
        if (a > N)
        {
            break;
        }
        ans = a;
        a *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  for (int i = n - 1; i > 0; i--){
    cout << a[i] << ' ';
  }
  cout << a[0] << endl;
}


Measured memory_bytes: 3116
N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))
L = []
for i in range(1,M):
    L.append(X[i]-X[i-1])
L = sorted(L,reverse=True)
if N>=M:
    print(0)
else:
    print(sum(L[N-1:]))

Measured memory_bytes: 20244
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int w = sc.nextInt();
		int[][] vw = new int[n][2];
		for(int i = 0; i < n; i++){
			vw[i][0] = sc.nextInt();
			vw[i][1] = sc.nextInt();
		}
		int[] DP = new int[w+1];
		for(int i = 1; i <= w; i++){
			DP[i] = DP[i-1];
			for(int j = 0; j < n; j++){
				if(i-vw[j][1] >= 0){
					DP[i] = Math.max(DP[i],DP[i-vw[j][1]]+vw[j][0]);
				}
			}
		}
		System.out.println(DP[w]);
	}
}



Measured memory_bytes: 27064