akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    ans=0
    n=int(input())
    i=2
    a=[]
    while i*i<=n:
        if not n%i:
            cnt=0
            while not n%i:
                cnt+=1
                n//=i
            a.append(cnt)
        i+=1
    if n>1:
        a.append(1)
    # print(a)
    for x in a:
        i=1
        while x>=i:
            ans+=1
            x-=i
            i+=1
    print(ans)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 63660
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (s[n - 1] == '1' || s[0] == '0') {
    cout << "-1" << endl;
    return 0;
  }
  vector<int> v;
  bool ok = true;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - 2 - i])
      ok = false;
    if (s[i] == '1')
      v.push_back(i + 1);
  }
  if (!ok) {
    cout << "-1" << endl;
    return 0;
  }
  sort(v.begin(), v.end());
  int q = 1, bef = 0, par = -1;
  int m = v.size();
  for (int i = 0; i < m; i++) {
    int now = q++;
    if (par >= 0) {
      cout << par << " " << now << endl;
    }
    par = now;
    for (int j = 0; j < v[i] - bef - 1; j++) {
      cout << now << " " << q++ << endl;
    }
    bef = v[i];
  }
  int now = q++;
  cout << par << " " << now << endl;
  while (q <= n) {
    cout << now << " " << q++ << endl;
  }
  return 0;
}


Measured memory_bytes: 1916
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG 0
#define dd if (DEBUG)

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

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, A) for (auto & a : A)
#define all(a) (a).begin (), (a).end ()
#define rall(a) (a).rbegin (), (a).rend ()
#define sz(a) (int) (a).size ()
#define szl(a) (int) (a).length ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;
typedef pair <int, int> pii;
#define f first
#define s second
#define mp(a, b) make_pair((a), (b))
typedef vector <int> vi;
typedef vector <vi> mi;
typedef vector <ll> vll;
typedef vector <vll> mll;
#define pb(a) push_back ((a))

const ll MOD = 1e+9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INFi = 0x3f3f3f3f;
const ll MAXN = 1e+6+7;

mi g;
vi viz;

int dfs (int i)
{
    if (viz[i] >= 0)
        return viz[i];
    trav (a, g[i])
        viz[i] = max (viz[i], dfs (a) + 1);
    return viz[i] = max (0, viz[i]);
}

int main ()
{
    FASTIO;
    int i, j, n, m, ax;
    cin >> n >> m;
    g = mi (n);
    viz = vi(n, -1);
    for (i = 0; i < m; i++)
    {
        cin >> j >> ax;
        g[j - 1].pb (ax - 1);
    }
    dd trav (v, g) {
        trav (a, v)
            cout << a << ' ';
        cout << '\n';}
    dd cout << endl;
    for (i = 0; i < n; i++)
    {
        if (viz[i] < 0)
        {
            dfs (i);
        }
    }
    for (i = 1, j = viz[0]; i < n; i++)
        j = max (j, viz[i]);
    cout << j << '\n';

    return 0;
}



Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int main(){
    int  a, b ,c;
    char X,Y;
    string S1,S2;
    cin >>a >> b >> c;
    if((100*a+10*b+c)%2 == 0 && ((100*a+10*b+c)/2)%2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = in.nextInt();
		
		System.out.println(water(h, 0, n - 1));		

	}
	
	public static int water(int[] h, int left, int right){

		if (right < left)
			return 0;
		else {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		}
		return 0;

	}

}

Measured memory_bytes: 22868
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;i++) cin >> s[i];

  vector<vector<int>> f(h,vector<int>(w));

  for(int i=0;i<w;i++){
    int cnt = 0;
    int st = 0;
    for(int j=0;j<h;j++){
      if(s[j][i] == '.'){
        cnt++;
      }

      if(s[j][i] == '#'){
        for(int k=j-1;k>=st;k--){
          f[k][i] = cnt;
        }
        cnt = 0;
        st = j+1;
        continue;
      }

      if(j == h-1){
        for(int k=j;k>=st;k--){
          f[k][i] = cnt;
        }
      }
    }
  }

  for(int i=0;i<h;i++){
    int cnt = 0;
    int st = 0;
    for(int j=0;j<w;j++){
      if(s[i][j] == '.'){
        cnt++;
      }

      if(s[i][j] == '#'){
        for(int k=j-1;k>=st;k--){
          f[i][k] += cnt;
        }
        cnt = 0;
        st = j+1;
        continue;
      }

      if(j == w-1){
        for(int k=j;k>=st;k--){
          f[i][k] += cnt;
        }
      }
    }
  }

  int ans = f[0][0];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans = max(ans,f[i][j]);
    }
  }

  cout << ans-1 << endl;
}


Measured memory_bytes: 20096
#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>;
int main() {
    ll n, k; cin >> n >> k;
    ll t = n % k;
    cout << min(t, k-t);
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    lint N;
    cin >> N;

    lint ret = N - 1;
    FOR(i, 1, 1000001)
        if (N % i == 0) {
            ret = min(ret, i + N / i - 2);
        }

    cout << ret << endl;
    return 0;
};

Measured memory_bytes: 256
// atcoder/abc140/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  int n;
  while (cin >> n) {
    set<string> vis;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        for (int k = 0; k < n; ++k) {
          string s;
          s += '0' + i;
          s += '0' + j;
          s += '0' + k;
          vis.insert(s);
        }
      }
    }
    cout << vis.size() << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // int t;
    // cin>>t;
    // while(t--){
    // }
    int d,t,s;
    cin>>d>>t>>s;
    double tt = (double)d/s;
    if(tt<=(double)t){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}

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

class A
{
	static void Main()
	{
		var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int h = s[0], w = s[1];
		var a = new int[h].Select(_ => Console.ReadLine().Select(c => c == '#').ToArray()).ToArray();

		var q = new List<P>();
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				if (a[i][j]) q.Add(new P(i, j));

		var r = 0;
		for (; q.Any(); r++)
		{
			var ps = q.ToArray();
			q.Clear();

			foreach (var p in ps)
				foreach (var np in Nexts(p, h, w))
				{
					if (a[np.i][np.j]) continue;
					a[np.i][np.j] = true;
					q.Add(np);
				}
		}
		Console.WriteLine(r - 1);
	}

	struct P
	{
		public int i, j;
		public P(int _i, int _j) { i = _i; j = _j; }
	}

	static IEnumerable<P> Nexts(P p, int h, int w)
	{
		if (p.i > 0) yield return new P(p.i - 1, p.j);
		if (p.i < h - 1) yield return new P(p.i + 1, p.j);
		if (p.j > 0) yield return new P(p.i, p.j - 1);
		if (p.j < w - 1) yield return new P(p.i, p.j + 1);
	}
}


Measured memory_bytes: 32732
#include<stdio.h>

int main(){
	int a;
	int b;
	int s = 0;
	int t = 0;
	int i;
	for(i = 0; i < 4; i++){
		scanf("%d", &a);
		s += a;
	}
	for(i = 0; i < 4; i++){
		scanf("%d", &b);
		t += b;
	}
	if(s < t){
		printf("%d\n", t);
	}else{
		printf("%d\n", s);
	}
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

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

    if(a == b && b == c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  ll lb = 0; //lower bound(下限)
  ll ub = n; //upper bound(上限)
  ll mid = (lb+ub)/2; //ここで二分
  while(ub-lb != 1){
    if(mid*(mid+1)/2 < n){ //src以下（大事！！！！）になる最後の要素
      lb = mid; 
      mid = (lb+ub)/2;
    }
    else{
      ub = mid;
      mid = (lb+ub)/2;
    }
  }
  while(true){
    if(n > ub){
      cout << ub << endl;
      n -= ub;
      ub--;
    }
    else{
      cout << n << endl;
      return 0;
    }
  }
}

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

int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    for(int i=0;i<N;i++) {
        cin >> a.at(i);
    }
    int cnt = 0;
    int buf = 0;
    for(int i=0;i<N;i++) {
        if(a.at(i)%2==0) {
            for(int j=1;j<31;j++) {
                if(a.at(i)%2!=0) {
                    break;
                }else{
                    a.at(i) = a.at(i) / 2;
                    buf++;
                }
            }
        }
        cnt = max(cnt,buf);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3724
#include <iostream>

using namespace std;

int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    int ans1,ans2;
    ans1=A%D?A/D+1:A/D;
    ans2=C%B?C/B+1:C/B;
    if(ans1>=ans2)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	ll h, ans = 0;
	cin >> h;
	ll i = 1;
	while (h >= 1) {
		ans += i;
		h /= 2;
		i *= 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ld w,h,x,y;
	cin>>w>>h>>x>>y;
	cout<<fixed<<setprecision(9);

	ld k=(w*h)/(ld)2.0;
	cout<<k<<" ";
	if(((w/((ld)2.0))==x)&&((h/(ld)2.0)==y)){
		cout<<"1";
	}
	else{
		cout<<"0";
	}
	
	return 0;
}


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

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

	int x = 0;

	for (int i = 0; true; i++)
	{
		c = c - b;
		if (c <= 0)
			break;
		a = a - d;
		if (a <= 0)
		{
			x += 1;
			break;
		}
			
	}
	
	if (x == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;

	}

	return 0;
}


Measured memory_bytes: 3636
package main

import (
	"fmt"
)

type Thing struct {
	w, v int
}

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

func getValue(i, w int) int {
	value1 := values[i-1][w]
	value2 := 0
	preWeight := w - things[i].w
	if preWeight >= 0 {
		value2 = values[i-1][preWeight] + things[i].v
	}
	return getMax(value1, value2)
}

var values [][]int
var N, W int
var things []Thing

func main() {
	fmt.Scan(&N, &W)
	things = make([]Thing, N)
	var w, v int
	for i := 0; i < N; i++ {
		fmt.Scan(&w, &v)
		things[i] = Thing{w: w, v: v}
	}
	values = make([][]int, N)
	for i := 0; i < N; i++ {
		values[i] = make([]int, W+1)
	}

	for w := 0; w <= W; w++ {
		if things[0].w <= w {
			values[0][w] = things[0].v
		} else {
			values[0][w] = 0
		}
	}

	for i := 1; i < N; i++ {
		for w := 0; w <= W; w++ {
			values[i][w] = getValue(i, w)
		}
	}
	fmt.Println(values[N-1][W])
}


Measured memory_bytes: 81408
package main

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

func calc(arr []int, times int)  {
	max1st := 0
	max2nd := 0
	for i := range arr {
		if arr[i] > max1st {
			max1st = arr[i]
		}else if arr[i] > max2nd {
			max2nd = arr[i]
		}
	}
	for i := 0; i < len(arr); i++ {
		if arr[i] == max1st {
			fmt.Println(max2nd)
		}else {
			fmt.Println(max1st)
		}
	}
}

func main() {
	arr := make([]int,0)
	reader := bufio.NewReaderSize(os.Stdin, 1024*1024)
	times, _:= strconv.Atoi(readLine(reader))
	for i:= 0; i< times; i++ {
		tmp, _ := strconv.Atoi(readLine(reader))
		arr = append(arr, tmp)
	}
	calc(arr, times)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}


Measured memory_bytes: 10240
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> A(N);
  rep (i, N) cin >> A[i];
  reverse(A.begin(), A.end());

  multiset<long> foo;
  for (long num: A) {
    auto it = foo.upper_bound(num);
    if (it == foo.end()) foo.insert(num);
    else {
      foo.erase(it);
      foo.insert(num);
    }
  }

  cout << foo.size() << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 5760
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int n,m;

  cin >> n >> m;

  int number[3];

  for(ii=0;ii<3;ii++){
    number[ii] = -1;
  }

  int s,c;
  bool ngflg;
  ngflg = false;
  
  for(ii=0;ii<m;ii++){

    cin >> s >> c;
    s = s-1;

    if(number[s] == -1 || number[s] == c){
      number[s] = c;
    }
    else{
      number[s] = -2;
      ngflg = true;
    }
    
  }

  if(n >= 2 && number[0] == 0){
    ngflg = true;
  }
  
  if(ngflg){
    cout << -1 << endl;
  }

  else{

    for(ii=0;ii<n;ii++){
      if(number[ii] == -1){
        if(ii == 0 && n != 1){
          cout << 1;
        }
        else{
          cout << 0;
        }
      }
      else{
        cout << number[ii];
      }
    }
    
    cout << endl;

  }

  return 0;
}


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

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))


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


void solve()
{
    int n;
    cin>>n;

    vector<int> items;

    for(int i=0; i<n; i++)
    {
        int item;
        cin>>item;
        items.push_back(item);
    }

    long long res=0;
    for(int i=1; i<n-1; i++)
    {

        vector<int> it;
        it.push_back(items[i]);
        it.push_back(items[i-1]);
        it.push_back(items[i+1]);

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

        if(items[i]==it[1]){
            res++;
        }
    }

    cout<<res<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

    while (t--)
    {

        solve();
    }

    return 0;
}


Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))
d = list(map(lambda x: x[1]-x[0], zip(a, a[1:])))
first_and_last = a[0] + (k - a[-1])
ignore = max(d+[first_and_last])
ans = k - ignore
print(ans)

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

int main() {
   int N;
   cin >> N;
   int A[N];
   long long count=0;
   for (int i=0; i<N; i++) {
       cin >> A[i];
       if (i!=0 && A[i]<A[i-1]) {
           count+=A[i-1]-A[i];A[i]=A[i-1];
       }
   }
   cout << count << endl;
}

Measured memory_bytes: 4400
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int main(){
	while(1){
		int n;
		cin >> n;
		if(!n)break;

		vector<pair<int, int> > v;

		rep(i, n){
			int h, m, s;
			scanf("%d:%d:%d", &h, &m, &s);
			v.push_back(MP(h*60*60+m*60+s, +1));
			scanf("%d:%d:%d", &h, &m, &s);
			v.push_back(MP(h*60*60+m*60+s, -1));
		}

		int need = 0;
		sort(all(v));

		int train = 0;
		rep(i, 2*n){
			train += v[i].second;
			need = max(need, train);
		}

		cout << need << endl;
	}

	return 0;
}

Measured memory_bytes: 1496
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
const int inf = 1000000000; // 10^9 Ten to the power of nine.
/**** Type Define ****/
 
    int main(){
        char A;
        cin>>A;
        if(isupper(A)){cout<<'A';}
        else if(islower(A)){cout<<'a';}
        
        return 0;

    }


Measured memory_bytes: 3572
def main():
    line1 = input()
    line2 = input()
    line3 = input()
    n, m, k = list(map(int, line1.split()))
    a = [0] + list(map(int, line2.split()))
    b = [0] + list(map(int, line3.split()))
    mark1, mark2 = 0, 0
    for i in range(1, len(a)):
        a[i] += a[i-1]
        if a[i] > k:
            mark1 = i
            break
    for i in range(1, len(b)):
        b[i] += b[i-1]
        if b[i] > k:
            mark2 = i
            break
    if mark1:
        a = a[:mark1]
    if mark2:
        b = b[:mark2]
    ans = 0
    for i in range(len(a)):
        target = k - a[i]
        tmp = 0
        low, high = 0, len(b)
        while low < high:
            mid = (low + high) // 2
            if b[mid] <= target:
                tmp = mid
                low = mid + 1
            else:
                high = mid - 1
        ans = max(ans, i + tmp)
    print(ans)
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 44500
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int X;
  cin >> X;
  int i=2;
  int Ans=0;
  while(pow(2, i)<=X){
    for(int j=2; j<=33; j++){
      if(pow(j, i)<=X){
        Ans=max(Ans, (int)pow(j, i));
      }
      else{
        break;
      }
    }
    i++;
  }
  cout << max(Ans, 1) << endl;
}

Measured memory_bytes: 256
// Copyright 2017 wu_qing
#include <cstdio>
#include <cstdint>
#include <algorithm>

const int N = 2e5 + 10;
const int64_t INF = ~0ull >> 1;
int n;
int64_t a[N], ans = INF, sum, x;

inline int64_t abs(int64_t x) {
    return x < 0 ? -x : x;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", a + i);
        sum += a[i];
    }
    for (int i = 1; i < n; i++) {
        x += a[i];
        ans = std::min(ans, abs(sum - 2 * x));
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 1664
def main():
    N = int(input())
    S, T = input().split()

    result = ''
    s_list = list(S)
    t_list = list(T)

    for i in range(N):
        result += s_list[i]
        result += t_list[i]


    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;

ll fact[2500001];
ll factinv[2500001];

// a^-1 mod p
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

void init() {
  fact[0] = 1;
  factinv[0] = 1;
  REP(i,2500000) {
    fact[i+1] = fact[i] * (i+1);
    fact[i+1] %= MOD;
    factinv[i+1] = inv(fact[i+1], MOD);
  }
}

ll comb(ll n, ll k) {
  ll tmp = (fact[n] * factinv[k]) % MOD;
  return (tmp * factinv[n-k]) % MOD;
}

int main()
{
  init();
  ll n,m;
  cin>>n>>m;
  ll tmp = comb(3*m+n-1, n-1);
  ll sub = 0;
  FOR(i,2*m+1,3*m+1) {
    sub += comb(3*m-i+n-2, n-2);
    sub %= MOD;
  }
  sub *= n;
  sub %= MOD;
  ll mno = 0;
  FOR(i,m+1,n+1) {
    ll rem = 3*m-i;
    if (rem < 0 || (rem%2) == 1) continue;
    mno += comb(rem/2+n-1, n-1) * comb(n, i);
    mno %= MOD;
  }
  ll res = (2*MOD + tmp - sub - mno) % MOD;
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 39424
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){

  int N,W;
  cin >> N >> W;

  vector<int>v(N),w(N);
  for(int i=0;i<N;i++)
    cin >> v[i] >> w[i];

  int dp[W+1];
  fill(dp,dp+W+1,0);

  for(int i=0;i<N;i++){
    for(int j=W;j>=0;j--){
      if(j-w[i]>=0)dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
    }
  }

  int ans=0;
  for(int i=0;i<=W;i++)ans=max(ans,dp[i]);

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

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  int a;
  cin >> a;
  if (a == 1) {
    cout << "Hello World" << endl;
  } else {
    int b, c;
    cin >> b >> c;
    cout << b + c << endl;
  }

}


Measured memory_bytes: 256
N=int(input())
za=list()
for i in range(N):
    za.append(list(map(int,input().split())))
che=list()
for i in range(N):
    a=za[i][0]-za[i][1]
    b=za[i][0]+za[i][1]
    che.append([a,b])
dai1=-1*10**9
syou1=2*(10**9)
dai2=-1*10**9
syou2=2*(10**9)
ans1=0
ans2=0
for i in range(N):
    dai1=max(dai1,che[i][0])
    syou1=min(syou1,che[i][0])
    dai2=max(dai2,che[i][1])
    syou2=min(syou2,che[i][1])
ans1=dai1-syou1
ans2=dai2-syou2
print(max(ans1,ans2))


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=2019;

ll modpow(int a, int n){
    ll res=1;
    while(n > 0){
        if(n & 1) res=res*a%MOD;
        a=a*a%MOD;
        n>>=1;
    }
    return res;
}

int main(){
    string S; cin >> S;
    vi cnt(2019, 0);
    cnt[0]++;
    ll sum=0;
    for(int i=S.size()-1; i>=0; i--){
        sum=(sum+(S[i]-'0')*modpow(10, S.size()-1-i)%MOD)%MOD;
        cnt[sum]++;
    }
    ll res=0;
    for(int i=0; i<2019; i++){
        res+=cnt[i]*(cnt[i]-1)/2;
    }
    cout << res << endl;
    return 0;
}

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

int main()
{
    int a,b,x;
    while(~scanf("%d%d%d",&a,&b,&x))
    {
        if(a>x)
            printf("NO\n");
        else if(a+b<x)
            printf("NO\n");
        else if(a+b>x)
            printf("YES\n");
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.valueOf(sc.nextLine());
		Map<String, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			String in = sc.nextLine();
			int count = map.getOrDefault(in, 0);
			map.put(in, count + 1);
		}
		SortedSet<String> set = new TreeSet<>();
		int max = 0;
		for (Map.Entry<String, Integer> entry : map.entrySet()) {
			if (max < entry.getValue()) {
				max = entry.getValue();
				set = new TreeSet<>();
				set.add(entry.getKey());
			} else if (max == entry.getValue()) {
				set.add(entry.getKey());
			}
		}
		set.forEach(System.out::println);
	}
}


Measured memory_bytes: 178080
#include<stdio.h>
int main(){
 int H[3000],W[3000];
 int i,j,k,m,n;

 for(i=0;i<3000;i++){
  scanf("%d %d",&H[i],&W[i]);
  
  if(H[i]==0 && W[i]==0){
   j=i;
   break;
  }
  }


 for(i=0;i<=j-1;i++){

  for(k=0;k<H[i];k++){
 
   if(k%2==0){

    if(W[i]%2==0){
      for(m=0;m<W[i]/2;m++){
       printf("#.");
      }
      printf("\n");
    }else{
      for(m=0;m<W[i]/2;m++){
       printf("#.");
      }
      printf("#\n");
    }

  }else{
   
   if(W[i]%2==0){
      for(m=0;m<W[i]/2;m++){
       printf(".#");
      }
      printf("\n");
    }else{
      for(m=0;m<W[i]/2;m++){
       printf(".#");
      }
      printf(".\n");
    }
   
   }



 
  }
 
 printf("\n");

 }

return 0;
}

  

Measured memory_bytes: 612
import itertools

n = int(input())
lst = [int(elem) for elem in range(1, n+1)]
p = list(itertools.permutations(lst))

ps = [int(elem) for elem in input().split()]
qs = [int(elem) for elem in input().split()]

print(abs(p.index(tuple(ps)) - p.index(tuple(qs))))

Measured memory_bytes: 8052
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long amari = (A + B) % 2;
		long kekka = (A + B) / 2;
		if (amari != 0) {
			System.out.println("IMPOSSIBLE");
		} else {
			System.out.println(kekka);
		}

	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 24660
#include <stdio.h>

int main()
{
long int a,b;
scanf("%ld%ld",&a,&b);
if(a+b>=a-b && a+b>=a*b)
{
    printf("%ld",a+b);
}else{
    if(a-b>=a+b && a-b>=a*b)
    {
        printf("%ld",a-b);
    }else{
        printf("%ld",a*b);
    }
}

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin >> s;
    int N = SZ(s);
    vector<int> X(N);
    REP(i, N) {
        X[i] = 1LL << (s[i] - 'a');
        if (i) X[i] ^= X[i - 1];
    }

    map<int, int> dp;
    dp[0] = 0;
    REP(i, N) {
        REP(k, 26) {
            if (CONTAIN(dp, X[i] ^ (1LL << k))) {
                if (!CONTAIN(dp, X[i])) dp[X[i]] = INF;
                chmin(dp[X[i]], dp[X[i] ^ (1LL << k)] + 1);
            }
        }
    }
    int ans = dp[X[N - 1]];
    if (ans == 0) ans++;
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 14484
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,v;
	while(cin>>N) {
		ll ans=0;
		REP(i, N) {
			cin>>v;
			if(i==0) ans=v;
			else ans = gcd(ans, v);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;


int main()
{
    IOS
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    reverse(a,a+n);
    vector<ll>aux;
    for(ll i=0;i<n-1;i++)
    {
        if(a[i]<=a[i+1])
        {
            aux.pb(1);
        }
        else
        {
            aux.pb(0);
        }
    }
    ll ans=0;
    ll buk=0;
    for(ll i=0;i<aux.size();i++)
    {
        if(aux[i])
        {
            buk++;
        }
        else
        {
            buk=0;
        }
        ans=max(buk,ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
string s,t;
bool check(string a,string b)
{
	for(int i=0;i<a.size();i++)
		if(a[i]!='?'&&b[i]!=a[i])
			return false;
	return true;
}
bool ok=false;
int main()
{
	cin>>s>>t;
	for(int i=s.size()-t.size();i>=0;i--)
	{
		if(check(s.substr(i,t.size()),t))
		{
			for(int j=i;j<i+t.size();j++)
				s[j]=t[j-i];
			ok=true;
			break;
		}
	}
	for(int i=0;i<s.size();i++)
		if(s[i]=='?')
			s[i]='a';
	if(ok)
		cout<<s<<endl;
	else
		cout<<"UNRESTORABLE\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    static int n;
    static boolean[][] s;
    static int[] vis;
    static int[] d;
    static int[] f;
    static int time = 1;
    
    static void dfs(int x) {
        vis[x] = 1;
        d[x] = time++;
        for(int i=1; i<=n; i++) {
            if(vis[i] != 1 && s[x][i]) {
                dfs(i);
            }
        }
        f[x] = time++;
    }
    
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)) {
            n = sc.nextInt();
            s = new boolean[n+1][n+1];
            vis = new int[n+1];
            d = new int[n+1];
            f = new int[n+1];
            for(int i=0; i<n; i++) {
                int u = sc.nextInt();
                int k = sc.nextInt();
                for(int j=0; j<k; j++) {
                    int v = sc.nextInt();
                    s[u][v] = true;
                }
            }
            for(int i=1; i<=n; i++) {
                if(vis[i] == 0) {
                    dfs(i);
                }
            }
            for(int i=1; i<=n; i++) {
                System.out.printf("%d %d %d\n", i, d[i], f[i]);
            }
        }
    }
}



Measured memory_bytes: 29548
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		String st = sc.next();
		boolean flag = true;
		boolean C = false;
		for(int n=1;n<st.length();n++){
				if(!(0<=(st.charAt(n)-'a') &&(st.charAt(n)-'a')<=25)){
					if(!C && st.charAt(n) == 'C' && n!=1 && n!=st.length()-1) C = true;
					else flag = false;
				}
		}
		if(!C) flag = false;

		if(st.charAt(0) == 'A'){
		}else{
			flag = false;
		}

		if(flag) System.out.println("AC");
		else System.out.println("WA");

	}
}

Measured memory_bytes: 21844
use num::integer::lcm;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }

    let a = a - 1;
    let ans = (b - b / c - b / d + b / lcm(c, d)) - (a - a / c - a / d + a / lcm(c, d));

    println!("{}", ans);
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
const ld INF = 1e10;
const ld eps = 1e-9, pi = acos(-1.0);
typedef pair<ll, ll> P;


int main(){
  string s;
  cin >> s;
  ll m = s.size() / 2;
  ll l = m;
  ll r = m;
  while(r + 1 < s.size() && s[r+1] == s[r])
    r++;
  while(l - 1 >= 0 && s[l-1] == s[l])
    l--;
  ll ans = 0;
  if(s.size()%2){
    ll length = min(r - m, m - l);
    //    cout << l << " " << m << " " << r;
    ans = (s.size()+1)/2 + length;
  }else{
    ll length = min(r - m + 1, m - l);
    ans = (s.size()+1)/2 + length;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
  int a,b,c;cin>>a>>b>>c;
  for(int i = 0; 2 > i; i++){
    int x,y,z; cin >> x>>y>>z;
    if(!(a-b == x-y && c-b == z-y)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
n = int(raw_input()) + 1
n = bin(n)[3:]
ra = []
rb = []
c = 1
for i in n:
    ra.append(c)
    rb.append(c)
    c += 1
    if i == '1':
        ra = ra + [c]
        rb = [c] + rb
        c += 1
res = ra + rb
print len(res)
print ' '.join(map(str, res))


Measured memory_bytes: 2568
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
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 nx[4]={0,1,-1,0};
int ny[4]={1,0,0,-1};
int main(){
  ll n,t;
  cin>>n>>t;
  vll a(n);
  rep(i,n) cin>>a[i];
  vll b(n);
  ll k=0;
  for(int i=n-1;i>=0;i--){
    k=max(k,a[i]);
    b[i]=k-a[i];
  }
  ll ans=0;
  sort(all(b));
  ll cu=b[n-1];
  for(int i=n-1;i>=0;i--){
    if(b[i]!=cu) break;
    ans++;
  }
  COUT(ans);
}


Measured memory_bytes: 1792
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      String str = sc.next();
      String[] strArr = str.split(",");
      int[] cardNum = new int[14];
      int[] card    = new int[5];
      for(int i = 0; i < 5; i++) {
        card[i] = Integer.parseInt(strArr[i]);
        cardNum[card[i]]++;
      }
      Arrays.sort(card);
      boolean isStraight = true;
      for (int i = 0; i < 4; i++) {
        if (card[i] + 1 != card[i+1]) {
          isStraight = false;
        }
      }
      if (card[0] == 1  && card[1] == 10 && card[2] == 11 &&
          card[3] == 12 && card[4] == 13) {
        isStraight = true;
      }
      int max1 = 0;
      int max2 = 0;
      for(int i = 0; i < 14; i++) {
        if(cardNum[i] > max1) {
          max2 = max1;
          max1 = cardNum[i];
        }
        else if(cardNum[i] > max2) {
          max2 = cardNum[i];
        }
      }
      if (max1 == 4) {
        System.out.println("four card");
      }
      else if (max1 == 3 && max2 == 2) {
        System.out.println("full house");
      }
      else if (isStraight) {
        System.out.println("straight");
      }
      else if (max1 == 3) {
        System.out.println("three card");
      }
      else if (max1 == 2) {
        if (max2 ==2) {
          System.out.println("two pair");
        }
        else {
          System.out.println("one pair");
        }
      }
      else {
        System.out.println("null");
      }
    }
  }
}

Measured memory_bytes: 12000
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
///////////////////////////
void yes(){
    cout<<"Yes"<<endl;
}
void no(){
    cout<<"No"<<endl;
}

int main(){fastio
    ll n,a,b;cin>>n>>a>>b;
    string s;cin>>s;
    ll ca=0,cb=0;
    rep(i,0,n-1){
        if(s[i]=='a'){
            if(ca+cb<a+b){
                yes();
                ca++;
            }else{
                no();
            }
        }else if(s[i]=='b'){
            if(ca+cb<a+b){
                if(cb<b){
                    cb++;yes();
                }else{
                    no();
                }
            }else{
                no();
            }
        }else{
            no();
        }
    }
    
    return 0;
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	string s;cin>>s;
	stack<char>st;
	for(char c:s){
		if(!st.empty()&&st.top()!=c){
			st.pop();
		}
		else st.push(c);
	}
	cout<<s.size()-st.size()<<endl;
}

Measured memory_bytes: 512