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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    string S;
    bool flag;
    int vmax = 0;
    cin >> S;
    for (int i = 0; i < S.size(); i++) {
        flag = true;
        for (int j = i; j < S.size(); j++) {
            for (int k = i; k <= j; k++) {
                // cout << S[k];
                if (S[k] != 'A' && S[k] != 'C' && S[k] != 'G' && S[k] != 'T') {
                    flag = false;
                }
            }
            // cout << endl;
            if (flag) {
                vmax = max(vmax, j - i + 1);
            }
        }
    }

    cout << vmax << endl;
}


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

const int MAX = 100005;

struct edge { int from; int to; int cost; };

class unionfind {
private:
	int par[MAX]; int rank[MAX];
public:
	unionfind(int n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void unite(int x, int y) {
		if (!same(x, y)) {
			x = par[x]; y = par[y];
			if (rank[x] < rank[y]) {
				par[x] = y;
			}
			else {
				par[y] = x;
				if (rank[x] == rank[y]) {
					rank[x]++;
				}
			}
		}
	}
};

bool compare(edge a, edge b) {
	return a.cost < b.cost;
}

struct city { int x; int y; int num; };

bool x_bigger(city a,city b){
	return a.x < b.x;
}
bool y_bigger(city a, city b) {
	return a.y < b.y;
}

city c[MAX];
edge g[MAX*2];
unionfind t(MAX);

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c[i].x >> c[i].y;
		c[i].num = i;
	}
	int cnt = 0;
	int ans = 0;
	/* int v, e;
	cin >> v >> e;
	for (int i = 0; i < e; i++) {
		cin >> g[i].from >> g[i].to >> g[i].cost;
	}*/
	sort(c, c + n, x_bigger);
	for (int i = 0; i < n - 1; i++) {
		g[i].from = c[i].num;
		g[i].to = c[i + 1].num;
		g[i].cost = c[i + 1].x - c[i].x;
	}
	sort(c, c + n, y_bigger);
	for (int i = 0; i < n - 1; i++) {
		g[i + n - 1].from = c[i].num;
		g[i + n - 1].to = c[i + 1].num;
		g[i + n - 1].cost = c[i + 1].y - c[i].y;
	}
	int e = 2 * n - 2;
	sort(g, g + e, compare);
	for (int i = 0; i < e; i++) {
		int fr, next;
		fr = g[i].from; next = g[i].to;
		if (!t.same(fr, next)) {
			t.unite(fr, next);
			cnt++;
			ans += g[i].cost;
			if (cnt == n - 1) { break; }
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
char a[10003],b[10003];
int main(){
    cin>>a>>b;
    int len1=strlen(a);
    int len2=strlen(b);
    sort(a+1,a+len1);
    sort(b+1,b+len2);
    for(int i=1;i<max(len2,len1);i++){
        if(a[i]>b[len2-i])break;
        if(a[i]<b[len2-i]){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
for _ in range(N):
    X, L = map(int, input().split())
    A.append((X-L, X+L))

A = sorted(A, key=lambda x:x[1])
p = -10**10
ans = 0
for l, r in A:
    if l>=p:
        ans += 1
        p = r
print(ans)

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

int main()
{

        int N;
        int x[26];
        int y[26];
        char c[N];
        cin >> N;
        for (int i = 0; i < N; ++i) {
                cin >> c[i];
        }

        int max = -1;
        for (int cutp = 1; cutp < N; ++cutp) {
        for (int i = 0; i < 26; ++i) {
                x[i] = 0;
                y[i] = 0;
        }



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

                if (i < cutp) {
                        x[c[i] - 'a']++;
                }
                else {
                        y[c[i] - 'a']++;
                }
        }
        int count = 0;
        for (int i = 0; i < 26; ++i) {

                if (x[i] && y[i]) {
                        count++;
                }
        }
        if (max == -1) {
                max = count;
        }
        else if (max < count) {
                max = count;
        }
        }
        cout << max << endl;






}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  string S;
  cin >> S;
  rep(i, S.size()) {
    if(i%2) {
      if(S[i] == 'R') {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if(S[i] == 'L') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main(){
	int a, b;
	cin >> a >> b;
	cout << (a-1)*(b-1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
using namespace std;
int val[1000001],f[1000001],cnt[20],vis[1000001],js,x,y,z,ans,n,len=(1<<15);
int main() {
	n=read(),len=(1<<15);
	for(int i=1; i<n; i++)
		x=read(),y=read(),z=read(),val[x]^=z,val[y]^=z;
	for(int i=0; i<n; i++)
		cnt[val[i]]++;
	for(int i=1; i<=15; i++)
		ans+=cnt[i]/2,js|=(cnt[i]&1)<<(i-1);
	for(int i=1; i<len; i++)
		f[i]=f[i>>1]+(i&1);
	for(int i=1; i<len; i++)
		f[i]--;
	for(int i=1; i<len; i++)
		for(int j=0; j<15; j++)
			if((i>>j)&1)
				vis[i]^=(j+1);
	for(int i=1; i<len; i++) {
		if(vis[i]) continue;
		for(int k=(i-1)&i; k; k=(k-1)&i)
			if(!vis[k])
				f[i]=min(f[i],f[k]+f[i^k]);
	}
	printf("%d",ans+f[js]);
	return 0;
}//da

Measured memory_bytes: 6528
s = input()
t = input()

s_n = len(s)
t_n = len(t)

ans = 1200
for i in range(s_n - t_n + 1):
    cnt = 0
    for j in range(t_n):
        if s[i + j] != t[j]:
            cnt += 1
    ans = min(ans, cnt)
    
print(ans)

Measured memory_bytes: 9112
n = gets.chomp.to_i

nodes = []
n.times {
    words = gets.chomp.split.map &:to_i
    id = words[0]
    node = {
        "id" => id,
        "dim" => words[1],
        "children" => words[2..-1],
        "parent" => -1,
    }
    nodes[id] = node
}

nodes.each do |node|
    node["children"].each do |child|
        nodes[child]["parent"] = node["id"]
    end
end

id_root = 0
nodes.each do |node|
    if node["parent"] == -1
        node["species"] = "root"
        id_root = node["id"]
    elsif
        if node["children"].size == 0 then node["species"] = "leaf"
        else node["species"] = "internal node" end
    end
end

def rec(nodes, id, depth)
    nodes[id]["depth"] = depth
    nodes[id]["children"].each do |child| rec nodes, child, depth + 1 end
end

rec nodes, id_root, 0

nodes.each do |node|
    puts "node #{node["id"]}: parent = #{node["parent"]}, " \
        << "depth = #{node["depth"]}, #{node["species"]}, " \
        << "[#{node["children"].join(", ")}]"
end


Measured memory_bytes: 70028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll x,c = 100,i = 0;
    cin >> x;
    while (1){
        if(c >= x)break;
        c *= 1.01;
        ++i;
    }
    pf(i);
    return 0;
}



Measured memory_bytes: 3632
from functools import reduce
from fractions import gcd

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(l):
    lcm = l[0]
    for i in range(len(l)):
        lcm = lcm*l[i] // gcd(lcm, l[i])
    return lcm

mod = 10**9 + 7
n = int(input())
As = list(map(int, input().split()))

lcm = lcm_list(As)
b = [lcm//As[i] for i in range(n)]

print(sum(b) % mod)

Measured memory_bytes: 264640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--) {
        int a, b, c;
        cin>>a>>b>>c;
        bool poor = true;
        if(a ==b && a == c)
            poor = false;
        if(a!=b && b!=c && a!=c)
            poor = false;
        if(poor)
            cout<<"Yes\n";
        else
            cout<<"No\n";       
    }    
}

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

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

  int H[N];
  for(int i=0; i<N ; i++){
    cin >> H[i]; 
  }
  int nm=1;
  for(int j=1; j<N ; j++){ 
    int flag =1;
    for(int i=0; i<j ; i++){
      if(H[j] < H[i]){
	flag = 0;
	//	cout << H[j] << " " << H[i] << endl;
      }
    }
    if (flag==1){
      nm +=1;
    }
  }

  cout << nm << endl;

}


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

int main() {
  int N;
  cin >> N;
  vector<double> v(N);
  for (int i = 0; i < N; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double score = (v[0] + v[1]) / 2.0;
  for (int i = 2; i < N; i++){
    score = (score + v[i]) / 2.0;
  }
  cout << score << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 305;
double dp[MAX_N][MAX_N][MAX_N];

double rec(int i, int j, int k, int N)
{
	if (dp[i][j][k] != -1.0) return dp[i][j][k];

	double res = double(N);
	if (i != 0) res += double(i) * rec(i-1,j,k,N);
	if (j != 0) res += double(j) * rec(i+1,j-1,k,N);
	if (k != 0) res += double(k) * rec(i,j+1,k-1,N);
	res /= double(i+j+k);
	return dp[i][j][k] = res;
}

int main()
{
	int N;
	cin >> N;
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	rep(i,N)
	{
		int a;
		cin >> a;
		if (a == 1) cnt1++;
		else if (a == 2) cnt2++;
		else cnt3++;
	}

	rep(i,MAX_N)
	{
		rep(j,MAX_N)
		{
			rep(k,MAX_N)
			{
				dp[i][j][k] = -1.0;
			}
		}
	}
	dp[0][0][0] = 0;
	cout << setprecision(20) << rec(cnt1,cnt2,cnt3,N) << endl;
	return 0;
}

Measured memory_bytes: 221952
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class BellmanFord:
    INF = int(1e18)
    N = -1
    edge = []
    
    def __init__(self, N):
        self.N = N
        
    def add_edge(self, frm, to, cost):
        self.edge.append((frm, to, cost));
        
    def add_bi_edge(self, a, b, cost):
        self.add_edge(a, b, cost)
        self.add_edge(b, a, cost)
    
    def calcD(self, start):
        D = [self.INF] * self.N
        D[start] = 0
        update, cnt = True, 0
        while update:
            update = False
            cnt = cnt + 1
            if cnt > self.N:
                return None
            
            for frm, to, cost in self.edge:
                ncost = D[frm] + cost
                if D[frm] == self.INF or ncost >= D[to]:
                    continue
                D[to] = ncost
                update = True
                
        return D

# def SPFA(N, G, s):
#     dist = [INF] * N
#     cont = [0] * N
#     cnts = [0]* N

#     dist[s] = 0
#     cont[s] = 1
#     cnts[s] += 1
#     que = deque([s])
#     su = s; num = 1
#     while que:
#         v = que.popleft()
#         cont[v] = 0
#         d = dist[v]
#         su -= d
#         num -= 1
#         for w, c in G[v]:
#             r = d + c
#             if r < dist[w]:
#                 if not cont[w]:
#                     cnts[w] += 1
#                     if N <= cnts[w]:
#                         return None
#                     if que and r < que[0]:
#                         que.appendleft(w)
#                     else:
#                         que.append(w)
#                     cont[w] = 1
#                     su += r
#                     num += 1
#                     dist[w] = r
#                     while su < dist[que[0]]*num:
#                         que.append(que.popleft())
#                 else:
#                     su += r - dist[w]
#                     dist[w] = r
#     return dist

V, E, r = MAP()

std = [LIST() for _ in range(E)]
# edges = [[] for _ in range(V)]

# for s, t, d in std:
#     edges[s].append((t, d))

# dist = SPFA(V, edges, r)

# if not dist:
#     print("NEGATIVE CYCLE")
# else:
#     for i in range(V):
#         print(dist[i] if dist[i] < INF else "INF")

bf = BellmanFord(V)
for s, t, d in std:
    bf.add_edge(s, t, d)

ans = bf.calcD(r)

if not ans:
    print("NEGATIVE CYCLE")
else:
    for i in range(V):
        print ('INF' if ans[i] == bf.INF else ans[i])



Measured memory_bytes: 7740
#include <iostream>
#include <vector>
#include <stack>
#include <tuple>
using namespace std;

int main()
{
  vector<tuple<int, int, int>> v;
  int h, w;
  cin >> h >> w;
  for (auto i = 1; i <= h; i++) {
    if (i % 2 != 0) {
      for (auto j = 1; j <= w; j++) {
	int a;
	cin >> a;
	v.emplace_back(make_tuple(i, j, a));
      }
    } else {
      stack<tuple<int, int, int>> s;
      for (auto j = 1; j <= w; j++) {
	int a;
	cin >> a;
	s.push(make_tuple(i, j, a));
      }
      for (auto j = 0; j < w; j++) {
	v.emplace_back(s.top());
	s.pop();
      }
    }
  }
  int pa = 0;
  int pi;
  int pj;
  int move_count = 0;
  vector<tuple<int, int, int, int>> ans;
  for (auto&& e : v) {
    if (pa % 2 == 0) {
      pi = get<0>(e);
      pj = get<1>(e);
      pa = get<2>(e);
    } else {
      ans.emplace_back(make_tuple(pi, pj, get<0>(e), get<1>(e)));
      move_count++;
      pa = get<2>(e) + 1;
      pi = get<0>(e);
      pj = get<1>(e);
    }
  }
  cout << move_count << endl;
  for (auto&& e : ans) {
    cout << get<0>(e) << " "
	 << get<1>(e) << " "
	 << get<2>(e) << " "
	 << get<3>(e) << endl;
  }
}


Measured memory_bytes: 9068
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n,m=map(int,input().split())
p_list=list(map(int,input().split()))
a=UnionFind(n)
for i in range(m):
    x,y=map(int,input().split())
    if a.same_check(x,y):
        pass
    else:
        a.union(x,y)
count=0
for i in range(n):
    if a.same_check(p_list[i],i+1):
        count=count+1
print(count)


Measured memory_bytes: 107500
import java.util.Scanner;

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

		int [][][] room = new int [4][3][10];

		int n = scan.nextInt();

		for(int i = 0 ; i < n ; i++){
			int b = scan.nextInt(), f = scan.nextInt(),
					r = scan.nextInt(), v = scan.nextInt();
			    room [b-1][f-1][r-1] += v;
		}

		for(int i = 0 ; i < 4 ; i++){
			for(int j = 0 ; j < 3 ; j++){
				for(int k = 0 ; k < 10 ; k++){
					System.out.print(" "+room[i][j][k]);
				}
				System.out.println();
			}
			if(i==3) break;
			System.out.println("####################");
		}
	}
}

Measured memory_bytes: 21060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct edge{
    ll dm,cd,ct;
    bool operator<(const edge& right) const{
        return ct<right.ct;
    }
};

template <class T> bool BF(int n,int m,vector<edge>& es,vector<T>& d,int s,int t){
    d.resize(n,numeric_limits<T>::max()/2);
    d[s]=0;
    T mx;
    fr(i,2*n){
        fr(j,m){
            edge e=es[j];
            if(d[e.cd]>d[e.dm]+e.ct){
                d[e.cd]=d[e.dm]+e.ct;
            }
        }
        if(i==n-1) mx=d[n-1];
        if(i==2*n-1) if(mx!=d[n-1]) return 1;
    }
    return 0;
}

class ECoinsRespawn {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        ll n,m,p,a,b,c;
        in>>n>>m>>p;
        vector<edge> es(m);
        fr(i,m) in>>a>>b>>c,es[i]=(edge){a-1,b-1,p-c};
        vector<ll> d;
        if(BF(n,m,es,d,0,n-1)) out<<-1<<endl;
        else out<<max(0ll,-d[n-1])<<endl;
    }
};

int main() {
    ECoinsRespawn solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = long.Parse(_[0]);
            var m = long.Parse(_[1]);
            var x = long.Parse(_[2]);

            var c = new long[n];
            var l = new long[n,m];
            for(var i = 0; i < n; i++){
                var a = Console.ReadLine().Split().Select(t => long.Parse(t)).ToArray();
                c[i] = a[0];
                for(var j = 1; j <= m; j++){
                    l[i,j-1] = a[j];
                }
            }

            var ans = long.MaxValue;
            for(var b = 0; b < Math.Pow(2,n); b++){
                var skill = new long[m];
                var cost = 0L;
                for(var i = 0; i < n; i++){
                    if(((b >> i) & 1) == 1){
                        cost += c[i];
                        for(var j = 0; j < m; j++){
                            skill[j] += l[i,j];
                        }
                    }
                }

                var f = true;
                for(var k = 0; k < m; k++){
                    if(skill[k] < x){
                        f = false;
                        break;
                    }
                }

                if(f){
                    ans = Math.Min(ans,cost);
                }
            }

            Console.WriteLine(ans == long.MaxValue ? -1 : ans);
        }
    }
}


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

int main(int argc, char const *argv[])
{
	int n = 0;
	cin >> n;
	int min;
	cin >> min;
	int maxp = -2147483647;
	for(int i = 0 ; i < n -1 ; i ++){
		int x = 0;
		cin >> x;
		if(maxp < x - min) maxp = x - min; 
		if(x < min) min = x;
	}
	cout << maxp << endl;
	return 0;
}

Measured memory_bytes: 1164
s = int(input())
a = [0]*10**6
a[0] = s
for i in range(1, 10**6):
    if a[i-1] % 2 == 0:
        n = a[i-1] // 2
    else:
        n = a[i-1]*3+1
    if n in a:
        break
    a[i] = n

print(i+1)

Measured memory_bytes: 10868
#include<iostream>

using namespace std;

int main()
{
 	int a,b,c,k;
  	cin>>a>>b>>c>>k;
  if(k<=a)
  {
    cout<<k<<"\n";
  }
  else if(k<=a+b)
  {
    cout<<a<<"\n";
  }
  else
  {
    cout<<2*a+b-k<<"\n";
  }
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<unordered_set>
using namespace std;

const char* yaki = "YAKI";

bool solve(string str) {
	for (int i = 0; i < 4; i++) {
		if (yaki[i] != str[i])return false;
	}
	return true;
}

int main() {
	string str;
	cin >> str;
	if (solve(str))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

using namespace std;

const int maxN = 5e5+10;
int N,ans,A[maxN],B[maxN];
string S;

bool check(int x)
{
    B[1] = A[1]+x*9; B[N+1] = 0;
    for (int i=1; i <= N; i++)
    {
        B[i+1] = A[i+1] + B[i]/10;
        B[i] %= 10;
    }
    while (B[N+1]) N++;
    int sum = 0;
    for (int i=1; i <= N; i++) sum += B[i];
    return sum <= 9*x;
}

int main()
{
    cin >> S; N = S.size();
    for (int i=1; i <= N; i++) A[i] = S[i-1]-'0';
    reverse(A+1,A+N+1);
    int tmp = 0;
    for (int i=1; i <= N; i++)
    {
        A[i] = A[i]*9 + tmp; tmp = A[i]/10;
        A[i] %= 10;
    }
    while (tmp) A[++N] = tmp%10, tmp /= 10;
    int l = 0, r = N;
    while (l <= r)
    {
        int mid = (l+r)/2;
        if (check(mid)) ans = mid, r = mid-1;
        else l = mid+1;
    }
    cout << ans;
}


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

typedef long long ll;

const int mod = 1000000007;

int dp[200001][2] = {};
int dp2[200001][2] = {};

int main(){
    string s, t;
    cin >> s >> t;
    int n = s.length();
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 2; j++){
            if(dp[i][j] == 0)   continue;
            for(int k = 0; k < 10; k++){
                if(j == 0 && k > s[i]-'0')  break;
                if(t[i] != '?' && t[i]-'0' != k)    continue;
                int nj = j | (s[i]-'0' > k);
                dp[i+1][nj] += dp[i][j];
                dp[i+1][nj] %= mod;
                dp2[i+1][nj] += ((ll)dp2[i][j]*10 + (ll)(dp[i][j])*k)%mod;
                dp2[i+1][nj] %= mod;
            }
        }
    }
    cout << (dp2[n][0]+dp2[n][1])%mod << endl;
    return 0;
}


Measured memory_bytes: 6508
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <numeric>
#include <chrono>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <cstring>
#include <cassert>
#include <math.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;


int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    // scanf("%d", &tc);
    for(int cn = 1; cn <= tc; cn++) {
        int k; scanf("%d", &k);
        int cur = 0;
        int a = 7;
        for(int i = 1; i <= 6e6; i++, a = 1ll * a * 10 % k) {
            cur = (1ll * cur + a) % k;
            if(!cur) return printf("%d\n", i), 0;
        }
        puts("-1");
    }
    return 0;
}

Measured memory_bytes: 3760
import java.util.*;

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

	int sumA = a * n;
	int ans;
	if (sumA < b) {
		ans = sumA;
	} 
	else {
		ans = b;
	}
	System.out.println(ans);
}
}

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

using namespace std;

int main(){
 int N; cin >> N ; // Nは奇数
 vector<int > vec(100100,0);
 
  for(int i = 0;i< N; i++){ int a; cin >> a; vec[a]++;}
  int O = 0; int E = 0;
  
  for(int i = 0; i < 100100; i++){
   
    if( vec[i] % 2 == 1){ O++;}//奇数
    else if( vec[i] % 2 == 0 && vec[i] > 0) { E++;}//偶数
  }
  int ans = 0;
  
  if( E % 2 == 0){ //偶数枚は全て残せる
    ans = E + O;}
  else{ ans = E + O - 1;}
    
  
  cout << ans << endl;  return 0;}
    

Measured memory_bytes: 640
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = l()
alf = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(s)):
	alf = alf.replace(s[i],"")
if alf == "":
	print("None")
else:
	print(alf[0])


Measured memory_bytes: 9760
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return tuple(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, XY):
    g = [[] for _ in range((10**5)*2)]
    offset = 10**5
    cs = set()
    for x, y in XY:
        x -= 1
        y = y - 1 + offset
        g[x].append(y)
        g[y].append(x)
        cs.add(x)
        cs.add(y)
    ans = 0
    while cs:
        error_print(len(cs))
        q = set([cs.pop()])
        done = set()
        done_c = set()
        while q:
            v = q.pop()
            for u in g[v]:
                if v >= offset:
                    e = (u, v)
                else:
                    e = (v, u)
                if e not in done:
                    q.add(u)
                    done.add(e)
                    done_c.add(u)
                    done_c.add(v)
        xn = set()
        yn = set()
        for v, u in done:
            for z in (v, u):
                if z >= offset:
                    yn.add(z)
                else:
                    xn.add(z)
        ans += (len(xn) * len(yn)) - len(done)
        cs -= done_c

    return ans

def main():
    N = read_int()
    XY = [read_int_n() for _ in range(N)]
    print(slv(N, XY))


if __name__ == '__main__':
    main()


Measured memory_bytes: 120356
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;

int main()
{
    long long int n,m,w,e,sum = 0;
    priority_queue<long long int>q;
    scanf("%lld%lld",&n,&m);
    for(int i = 1 ; i <= n ; i ++ )
        {
            scanf("%lld",&w);
            q.push(w);
        }
    for(int i = 1 ; i <= m ; i ++ )
    {
        e = q.top();
        q.pop();
        q.push(e / 2);
    }
    for(int i = 1 ; i <= n ; i ++ )
    {
        sum += q.top();
        q.pop();
    }
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cmath>
#include <set>

using namespace std;

const int INF = 1000000;
const int N_MAX = 10000;

struct edge {
  double cost;
  int from, to; 
  bool operator<(const edge &right) const {
    if (cost == right.cost) {
      if (from == right.from) return to < right.to;
      else return from < right.from;
    } else return cost < right.cost;
  }
};

int main() {

  int N, M;
  double total = 0;
  scanf("%d %d", &N, &M);

  bool used[N_MAX];
  set<edge> edges;
  int x[N_MAX];
  int y[N_MAX];
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &x[i], &y[i]);
    used[i] = false;
  }

  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--; b--;
    int dx = x[a] - x[b];
    int dy = y[a] - y[b];
    double cost = sqrt(dx*dx+dy*dy);
    edge e1 = { -cost, a, b };
    edges.insert(e1);
    edge e2 = { -cost, b, a };
    edges.insert(e2);
    total += cost;
  }

  double cost = 0;
  used[0] = true;
  for (int i = 0; i < N; i++) {
    bool flag = true;
    for (set<edge>::iterator it = edges.begin(); it != edges.end(); it++) {
      if (used[it->from] == true && used[it->to] == false) {
        cost += it->cost;
        used[it->to] = true;
        flag = false;
        break;
      }
    }
    // new tree
    if (flag) {
      for (int i = 1; i < N; i++) {
        if (!used[i]) {
          used[i] = true;
          break;
        }
      }
    }
  }
  printf("%.4f\n", total+cost);


  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int main(){

  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;

  if (r<=y && y<=H-r && r<=x && x<=W-r)
    
    cout<< "Yes" << endl;

  else 
    cout<< "No" <<endl;

  return 0;}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll X, A, B;
  cin >> X >> A >> B;

  if(B - A <= 0) cout << "delicious" << endl;
  else if(B - A <= X) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  
  return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int w, h, ans = 1e8;
int board[21][21];

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

void bfs(int y, int x, int t, int d) {
    if (t > 10) return;
    int ny = y + dy[d], nx = x + dx[d];
    while (0 <= ny and ny < h and 0 <= nx and nx < w and board[ny][nx] == 0) {
        ny += dy[d];
        nx += dx[d];
    }
    if (0 <= ny and ny < h and 0 <= nx and nx < w) {
        if (board[ny][nx] == 3) {
            ans = min(ans, t);
            return;
        }
        else if (ny == y+dy[d] and nx == x+dx[d]) return;
        else if (board[ny][nx] == 1) {
            board[ny][nx] = 0;
            rep(i, 4) {
                bfs(ny - dy[d], nx - dx[d], t+1, i);
            }
            board[ny][nx] = 1;
        }
    }
}

int main() {
    while (cin >> w >> h and w and h) {
        fill(board[0], board[21], 0);
        int py = 0, px = 0;
        rep(y, h) rep(x, w) {
            cin >> board[y][x];
            if (board[y][x] == 2) {
                py = y; px = x;
                board[py][px] = 0;
            }
        }
        ans = 1e8;
        rep(i, 4) {
            bfs(py, px, 1, i);
        }
        cout << (ans == 1e8 ? -1 : ans) << endl;
    }
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    int N;
    cin >> N;

    cout << N * (N + 1) / 2 << endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n, a, b;
	int p[100];
	int count[3] = {0}, result;
	
	scanf("%d", &n);
	scanf("%d %d", &a, &b);
	for(int i=0; i<n; i++){
		scanf("%d", &p[i]);
		if(p[i] <= a) count[0]++;
		else if(p[i] > a && p[i] <= b) count[1]++;
		else count[2]++;
	}
	
	if(count[0] <= count[1] && count[0] <= count[2]) result = count[0];
	else if(count[1] <= count[2]) result = count[1];
	else result = count[2];
	
	printf("%d\n", result);
	return 0;
}


Measured memory_bytes: 128
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = [0]*(n+1)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            v = x*x+y*y+z*z+x*y+x*z+y*z
            if v<=n:
                a[v] += 1
for i in range(1,n+1):
    print(a[i])


Measured memory_bytes: 69428
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[300005],br[300004],cr[2000003];
ll i,k,j,sum,a,b,cnt,maxii,l;
map<ll,ll>mp;
vector<ll>vc;
string s,s1;
int main()
{
    ll n,x=0,t;
    j=0;
    cin>>a>>b;
    a--;
    b--;

    sum=a*(a+1)/2+b*(b+1)/2;

    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

string solve(string s){
    s[5] = ' ';
    s[13] = ' ';
    return s;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    cout << solve(s) << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
arr = [int(i) for i in input().split()]
ans = 0
current_hops = 0
for i in range(N-1, 0, -1):
  x, y = arr[i-1], arr[i]
  if x >= y:
    current_hops += 1
  else:
    ans = max(ans, current_hops)
    current_hops = 0

ans = max(ans, current_hops)
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
int main(){
    int n,k,x,sum=0;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> x;
        sum+=min(x*2,abs(x-k)*2);
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3596
N = int(input())
S = input()
a = S[1:]
hazime = a.count("E")
tei = a.count("E")
for i in range(N-1):
  a = S[i]
  b = S[i+1]
  if a == "E" and b == "E":
    hazime += -1
    tei = min(tei,hazime)
  elif a == "E" and b == "W":
        continue
        tei = min(tei,hazime)
  elif a == "W" and b == "E":
     continue
     tei = min(tei,hazime)
  elif a == "W" and b == "W":
       hazime += 1
       tei = min(tei,hazime)
b = S[:N-1]
go = b.count("W")
tei = min(tei,go)
print(tei)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll n,m,k,ans,a[15],b[15];
char c[15][15];
bool f()
{
    ll res=0;
    /*for(int i=1; i<=n; i++)
    {
        cout<<a[i]<<' ';
    }
    cout<<endl;
    for(int i=1; i<=m; i++)
    {
        cout<<b[i]<<' ';
    }
    cout<<endl;*/
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(a[i]==1&&b[j]==1&&c[i][j]=='#')
            {
                res++;
            }
        }
    }
    //cout<<res<<endl;
    if(res==k)
    {
        return true;
    }
    else
    {
        return false;
    }
}
void dfs(ll cnt)
{
    if(cnt==n+m+1)
    {
        if(f())
        {
            ans++;
        }
        return;
    }
    if(cnt<=n)
    {
        a[cnt]=1;
        dfs(cnt+1);
        a[cnt]=0;

        dfs(cnt+1);
    }
    else
    {
        b[cnt-n]=1;
        dfs(cnt+1);
        b[cnt-n]=0;

        dfs(cnt+1);
    }
}
int main()
{
    //IOS;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin>>c[i][j];
        }
    }
    dfs(1);
    cout<<ans<<endl;
    return 0;
}
/*
AC x 3
WA x 1
TLE x 2
RE x 0

*/


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
  int n, d[100];
	cin >> n;
	rep(i, n) cin >> d[i];
	ll ans = 0;
	rep(i, n) {
		rep(j, n) {
			if (i < j) ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e3+3;
int n, m, scc;
int w[maxn][maxn];
int dfn[maxn], low[maxn], vis[maxn], Index;
int belong[maxn], cnt[maxn];
int s[maxn], top;
vector<int> g[maxn], ss[maxn];
int viss[maxn], p[maxn], pc;
bool flag;
int ans;

bool read()
{
    cin >> n >> m;
    int u, v, a, b;
    for(int i = 0; i < m; ++i)
    {
        cin >> u >> v;
        g[u].push_back(v);
        w[u][v] = 1;
        if(w[v][u])
        {
            ans = 2;
            a = u;
            b = v;
        }
    }
    if(ans)
    {
        cout << 2 << endl
             << a << endl
             << b << endl;
        return 0;
    }
    return 1;
}

void tarjan(int u)
{
    dfn[u] = low[u] = ++Index;
    s[top++] = u;
    for(int i = 0; i < g[u].size(); ++i)
    {
        int v = g[u][i];
        if(!dfn[v])
        {
            tarjan(v);
            low[u] = min(low[u], low[v]);
        }
        else if(!vis[v])
            low[u] = min(low[u], dfn[v]);
    }
    if(low[u] == dfn[u])
    {
        ++scc;
        while(1)
        {
            int x = s[--top];
            vis[x] = 1;
            belong[x] = scc;
            ss[scc].push_back(x);
            ++cnt[scc];
            if(x == u)
                break;
        }
    }
}

bool cmp(int v1, int v2)
{
    if(g[v1].size() != g[v2].size())
        return g[v1].size() < g[v2].size();
    return v1 < v2;
}

void dfs(int t, int u)
{
    if(flag) 
        return;
    p[pc++] = u;
    viss[u] = 1;
    for(int i = pc-1; i >= 0; --i)
    {
        int v = p[i];
        if(w[u][v] && viss[v])
        {
            int j;
            for(j = pc-1; j >= 0; --j)
                if(p[j] == v)
                {
                    ans = pc-j;
                    break;
                }
            cout << ans << endl;
            for(int k = j; k < pc; ++k)
                cout << p[k] << endl;
            flag = 1;
            return;
        }
    }
    sort(g[u].begin(), g[u].end(), cmp);
    for(int i = 0; i < g[u].size(); ++i)
    {
        int v = g[u][i];
        if(belong[v] != t)
            continue;
        dfs(t, v);
        if(flag)
            return;
    }
}

void solve()
{
    for(int i = 1; i <= n; ++i)
        if(!dfn[i])
            tarjan(i);
    
    int minscc = 0, mincnt = INF;
    for(int i = 1; i <= scc; ++i)
        if(cnt[i] > 2 && cnt[i] < mincnt)
        {
            minscc = i;
            mincnt = cnt[i];
        }
    if(!minscc)
    {
        cout << -1 << endl;
        return;
    }

    sort(ss[minscc].begin(), ss[minscc].end(), cmp);
    for(int i = 0; i < cnt[minscc]; ++i)
        if(!flag)
        {
            memset(viss, 0, sizeof(viss));
            memset(p, 0, sizeof(p));
            pc = 0;
            dfs(minscc, ss[minscc][i]);
        }
    if(!flag)
        cout << -1 << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    if(read())
        solve();
    return 0;
}


Measured memory_bytes: 3840
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll mypow(ll a, ll b) {
  ll ans = 1;
  ll two;
  ll tmp;
  while(b>0) {
    two = 1;
    tmp = a;
    while(2*two<b) {
      tmp *= tmp;
      tmp %= mod1;
      two *= 2;
    }
    b -= two;
    ans *= tmp;
    ans %= mod1;
  }
  return ans;
}

int main() {
  int N;
  cin>>N;
  int D[N];
  int maxnum = 0;
  map<int, ll> amap;
  for(int i=0;i<N;++i) {
    cin>>D[i];
    amap[D[i]]++;
    maxnum = max(maxnum, D[i]);
  }
  if(D[0]!=0) {
    cout<<0<<endl;
    return 0;
  }
  int zeronum = 0;
  for(int i=0;i<N;++i) {
    if(D[i]==0) zeronum++;
  }
  if(zeronum!=1) {
    cout<<0<<endl;
    return 0;
  }
  ll ans = 1;
  for(int i=2;i<=maxnum;++i) {
    ans *= mypow(amap[i-1], amap[i]);
    ans %= mod1;
  }
  cout<<ans<<endl;
}



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

int main(){
    int N;
    cin>>N;
    int A[N];
    for(int i=0;i<N;i++)cin>>A[i];
    int k=A[0];
    int cnt=1;
    for(int i=1;i<N;i++){
        if(A[i]<=k){
            cnt++;
        }
        k=min(k,A[i]);
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc133_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll L, R;
  cin >> L >> R;

  ll ans = INF;
  repi(i, L, min(R, L + 2019)) {
    repi(j, L + 1, min(R + 1, L + 2020)) { ans = min(ans, (ll)j * i % 2019); }
  }

  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

map<ll, int> factor(ll n){
    map<ll, int> res;

    for (ll i = 2; i*i <= n; ++i) {
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;

    return res;
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    ll n, p;
    cin >> n >> p;

    if(p == 1){
        cout << 1 << endl;
        return 0;
    }

    map<ll, int> mp = factor(p);
    ll ans = 1;
    for (auto& p : mp) {
        ans *= pow(p.first, p.second / n);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	int h, w;
	char field[1000][1000];
	bool vis[1000][1000];

	while(cin>>h>>w, (h||w)){
			
		for(int i=0; i<h; ++i){
			for(int j=0; j<w; ++j){
				
				vis[i][j]=false;
				cin>>field[i][j];
			}
		}
		
		int x=0, y=0;
		
		while(!vis[y][x] && field[y][x] != '.'){
			
			vis[y][x] = true;

			if(field[y][x]=='>'){
				x += 1;
			}
			else if(field[y][x]=='^'){
				y -= 1;
			}
			else if(field[y][x]=='<'){
				x -= 1;
			}
			else if(field[y][x]=='v'){
				y += 1;
			}

		}
		
		if(vis[y][x]){
			cout << "LOOP" << endl;
		}
		else{
			cout << x << " " << y << endl;
		}
	}

	return 0;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

  map<int, ll> mp;
  for(int i = 0; i < n; ++i){
    int tmp = n - i;
    for(int i = 2; i <= tmp; ++i){
      while(tmp % i == 0){
        tmp /= i;
        mp[i]++;
      }
    }
  }

  ll ans = 1;
  for(auto itr : mp){
    ans *= (itr.second + 1) % MOD;
    ans %= MOD;
  }

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


Measured memory_bytes: 256