akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200000 + 5;
string str[N];
struct node{
	string x;
	int num;
}a[N];
bool cmp(node a,node b){
	if(a.num == b.num)
		return a.x < b.x;
	return a.num > b.num;
}
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    	cin >> str[i];
    sort(str+1,str+n+1);
    a[1].x = str[1];
    a[1].num = 1;
    int t = 1;
    for(int i = 2; i <= n; i++){
    	if(str[i] == str[i-1]){
    		a[t].num++;
		}
		else{
			t++;
			a[t].x = str[i];
			a[t].num = 1;
		}
	}
	sort(a+1,a+n+1,cmp);
	int maxn = a[1].num;
	for(int i = 1; i <= n; i++){
		if(a[i].num == maxn)
			cout << a[i].x << endl;
		else
			break;
	}
    return 0;
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });
 
int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> h(N);
    REP(i, N) cin >> h[i];

    ll min = 1e18;
    DESC(h);
    REP(i, N-K+1) {
        ll dist = h[i] - h[i+K-1];
        chmin(min, dist);
    }
    cout << min << "\n";
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<vector<int>> Garph(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    rep(j, k) {
      int v;
      cin >> v;
      Garph[u-1].push_back(v-1);
    }
  }
  vector<int> dist(n, -1);
  queue<int> que;
  dist[0] = 0;
  que.push(0);
  while(!que.empty()) {
    int v = que.front();
    que.pop();
    for(auto next_v : Garph[v]) {
      if(dist[next_v] != -1) { continue;}
      dist[next_v] = dist[v] + 1;
      que.push(next_v);
    }
  }
  for(int i = 0; i < n; i++) {
    printf("%d %d\n", i+1, dist[i]);
  }
  return 0;
}


Measured memory_bytes: 3272
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,k,h[100000],dp[100000];
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> h[i];
  }
  dp[0]=0;
  for(int i=1; i<n; i++) {
    dp[i]=1000000000;
    for(int j=1; j<=k; j++) {
      if(i-j>=0) {
        dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
      }
    }
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 10000007
#define mod 1000000007
#define forn for(int i=0;i<n;i++)
#define vecti vector<int>
#define pb push_back
#define sti stack<int>
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
  ll int n,sum=0;
  cin>>n;
  ll int a[n],b[n];
  for(int i=1;i<n;i++)
  cin>>b[i];
  
  a[0]=b[1];
  for(int i=1;i<n;i++)
  {
      a[i]=b[i];
      if(b[i]<a[i-1])
      a[i-1]=b[i];
  }
    for(int i=0;i<n;i++)
    sum+=a[i];
    cout<<sum<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;
 char a[100005];
int main()
{
    long long n, k, s=0;
    cin>>n>>k;
    cin>>a;;
    for(int i=0; i<n-1; i++)
    {
        if(a[i]==a[i+1])
        {
            s++;
        }
    }
    s=min(n-1,s+2*k);
    cout<<s;
    return 0;
}

Measured memory_bytes: 384
import heapq

N, C = map(int,input().split())

sushi = []
for i in range(N):
    cur_sushi = list(map(int,input().split()))
    sushi.append(cur_sushi)

sum_V, sum_right = [0], [0]
for i in range(N):
    sum_V.append(sum_V[i]+sushi[i][1])
    sum_right.append(sum_V[i+1] - sushi[i][0])

sum_V, sum_left = [0], [0]
for i in range(N):
    sum_V.append(sum_V[i]+sushi[N-1-i][1])
    sum_left.append(sum_V[i+1] - (C-sushi[N-1-i][0]))

ans = max(max(sum_left), max(sum_right))

left = [0]
heapq.heapify(left)

for l in range(N):
    now = sum_right[N-l] - sushi[N-1-l][0]
    heapq.heappush(left, -sum_left[l])
    now -= left[0]
    ans = max(ans,now)

right = [0]
heapq.heapify(right)

for r in range(N):
    now = sum_left[N-r] - (C - sushi[r][0])
    heapq.heappush(right, -sum_right[r])
    now -= right[0]
    ans = max(ans,now)

print(ans)

Measured memory_bytes: 77656
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 1e6 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

pair<char, char> lt[N];

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, k;
  string str;
  ll r, s, p;
  cin >> n >> k >> r >> s >> p >> str;
  for (int i = 0; i < k; ++i) {
    if(str[i] == 'r')
      lt[i].first = 'p', lt[i].second = 'p';
    else if(str[i] == 'p')
      lt[i].first = 's', lt[i].second = 's';
    else
      lt[i].first = 'r', lt[i].second = 'r';
  }
  for (int i = k; i < n; ++i) {
    char cur;
    if(str[i] == 'r')
      lt[i].first = 'p', lt[i].second = 'p';
    else if(str[i] == 'p')
      lt[i].first = 's', lt[i].second = 's';
    else
      lt[i].first = 'r', lt[i].second = 'r';
    cur = lt[i].first;
    if(lt[i].first == lt[i - k].first) {
      if(lt[i - k].first != lt[i - k].second) {
        swap(lt[i - k].first, lt[i-k].second);
        continue;
      }
      if(cur == 's') {
        lt[i].first = 'p';
        lt[i].second = 'r';
      } else if(cur == 'p') {
        lt[i].first = 's';
        lt[i].second = 'r';
      } else {
        lt[i].first = 's';
        lt[i].second = 'p';
      }
    }
  }
  ll total = 0;
  for (int i = 0; i < n; ++i) {
    if(str[i] == 'r' && lt[i].first == 'p')
      total += p;
    else if(str[i] == 'p' && lt[i].first == 's')
      total += s;
    else if(str[i] == 's' && lt[i].first == 'r')
      total += r;
  }
  cout << total;
  return 0;
}


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

using namespace std;

int main() {
	int D, G;

	cin >> D >> G;

	vector<vector<int>> DP(2);
	DP[0] = vector<int>(D * 100 + 1, 0);
	DP[1] = vector<int>(D * 100 + 1, 0);

	for (int i = 1; i <= D; i++) {
		int p, c;
		cin >> p >> c;

		for (int j = 0; j <= 100 * D; j++) {
			DP[i % 2][j] = DP[(i + 1) % 2][j];

			for (int k = 1; j - k >= 0 && k <= p; k++) {
				DP[i % 2][j] = max(DP[i % 2][j], DP[(i + 1) % 2][j - k] + 100 * i * k);
				if (k == p) {
					DP[i % 2][j] = max(DP[i % 2][j], DP[(i + 1) % 2][j - k] + 100 * i * k + c);
				}
			}
		}
	}

	for (int i = 0; i <= 100 * D; i++) {
		if (G <= DP[D % 2][i]) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

int main() {
    int N,A,B;
    cin >> N >> A>>B;
    int sum =0;
    for (int i = 0; i < N+1; i++)
    {
        int a,b,c,d,e,some=0;
        a =i /10000;
        b =i /1000-a*10;
        c =i /100-a*100-b*10;
        d =i /10-a*1000-b*100-c*10;
        e =i -a*10000-b*1000-c*100-d*10;
        some= a+b+c+d+e;
        if (some>=A)
        {
            if (some<=B)
            {
                sum+=i;
            }
            
        }
        
    }
    cout << sum<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  if(X >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <iomanip>
#include <map>
#include <queue>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

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

const int INT_BIG = (1<<28);
const ll LL_BIG = 1ll<<61;

void printFixedDouble(double d, int fix) {
    cout << std::fixed;
    cout << std::setprecision(fix) << d << endl;
}

int main() {
    int nodeNum, linkNum;
    cin >> nodeNum >> linkNum;
    Graph<ll> dp(nodeNum, vector<ll>(nodeNum, LL_BIG));
    rep(i, linkNum) {
        ll s, t, d;
        cin >> s >> t >> d;
        dp[s][t] = d;
    }

    rep(i, nodeNum) {
        dp[i][i] = 0;
    }

    rep(k, nodeNum) {
        rep(i, nodeNum) {
            rep(j, nodeNum) {
                if (dp[i][k] != LL_BIG && dp[k][j] != LL_BIG)
                    dp[i][j] = std::min(dp[i][j], dp[i][k] + dp[k][j]);
            }
            if (dp[i][i] != 0) {
                cout << "NEGATIVE CYCLE" << endl;
                return 0;
            }
        }
    }

    rep(i, nodeNum) {
        rep(j, nodeNum) {
            if (j != 0) cout << " ";
            
            if (dp[i][j] == LL_BIG) {
                cout << "INF";
            } else {
                cout << dp[i][j];
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3244
n=int(input())
a=list(map(int, input().split()))
k=(n+1)//2
b=[0]*(k)
for i in range(n):
  b[a[i]//2]+=1
out=1
if n%2==0:
  for i in range(k):
    if b[i]==2:
      out*=2
    else:
      out*=0
else:
  for i in range(1, k):
    if b[i]==2:
      out*=2
    else:
      out=0
  if b[0]!=1:
    out=0
print(out%(10**9+7))

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

int main(){
  string S;
  cin >> S;
  int count=0,max_count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='A' || S.at(i)=='T' || S.at(i)=='G' || S.at(i)=='C'){ 
      count++;
    }
    else{
      max_count=max(max_count,count);
      count=0;
    }
  }
  cout <<max(max_count,count) << endl;
}

Measured memory_bytes: 3612
A, B = (int(i) for i in input().split())

if B == 1:
  print(0)
else:
  tap_num = 0
  available_socket_num = 0
  while B > available_socket_num:
    tap_num += 1
    available_socket_num = (A - 1) * tap_num + 1

  print(tap_num)

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a[100];
        for(int i=0;i<N;i++){
            cin >> a[i];
        }
    sort(a,a+N,greater<int>());
    int A=0,B=0;
    
    for(int i=0;i<N;i++){
        if(i%2==0){
            A += a[i];
        }else{
            B += a[i];
        }
    }
    
    cout << A-B << endl;
    
        return 0;
    }


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

int main() {
    string s; cin >> s;
    int n = s.size();
    int cnt = 0;
    for (char c: s) {
        if (c == '0') cnt++;
    }
    cnt = min(cnt, n-cnt);
    int ans = cnt * 2;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(2500);
  vector<int> backet(n);
  for (int i = 0; i < 2 * m; i++) cin >> vec.at(i);
  for (int i = 0; i < 2 * m; i++) {
    backet.at(vec.at(i) - 1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << backet.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
using ui = unsigned int;
 
 
int main() {
    ll L, R;
    cin >> L >> R;
    ll MOD = 2019;
 
    ll res = 1e10;
    for(ll i = L; i < R; i++) {
        for (ll j = i+1; j <= R; j++) {
            res = min(res, i*j % MOD);
            if (res == 0)
                goto OUTPUT;
        }       
    }
OUTPUT:
    cout << res << "\n";
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	int a, b;
	string s;
	bool flag = true;
	cin >> a >> b >> s;
	if (s.size() != a + b + 1)flag = false;
	else if (s[a] != '-')flag = false;
	else
		lp(a + b + 1)
			if (i != a&&s[i] == '-')flag = false;
	if (flag == true)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
typedef long long ll;
const ll MOD = 1e9+7;
int main(int argc,char **argv){
    (void)argc;
    (void)argv;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    ll d_1[n];
    ll d_2[n];
    rep(i,0,n)cin>>d_1[i]>>d_2[i];
    ll cnt=0;
    rep(i,0,n){
        if(d_1[i]==d_2[i])cnt++;
        else cnt=0;
        if(cnt==3){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3648
# arc090

n = int(input())
a = [list(map(int, input().split())) for _ in range(2)]

dp = [[-1] * n for _ in range(2)]


# 初期値
dp[0][-1] = a[0][-1] + a[1][-1]
dp[1][-1] = a[1][-1]
for k in range(n - 2, -1, -1):
    dp[1][k] = a[1][k] + dp[1][k + 1]
    dp[0][k] = max(dp[1][k], dp[0][k + 1]) + a[0][k]

print(dp[0][0])

Measured memory_bytes: 38256
use std::str::FromStr;
use std::io::*;
use std::cmp::*;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = AtRead::from(i);
    let (n, c) = i.read2::<usize, isize>();
    let mut xv = Vec::new();
    for _ in 0..n {
        xv.push(i.read2::<isize, isize>());
    }
    writeln!(o, "{}", solve(c, &xv)).unwrap();
}
fn solve(c: isize, xv: &[(isize, isize)]) -> isize {
    let mut results_r = vec![0];
    {
        let mut v = 0;
        let mut r_max = 0;
        for &xv in xv {
            v += xv.1;
            r_max = max(r_max, v - xv.0);
            results_r.push(r_max);
        }
    }

    let mut results_l = vec![0];
    {
        let mut v = 0;
        let mut r_max = 0;
        for &xv in xv.iter().rev() {
            v += xv.1;
            r_max = max(r_max, v - (c - xv.0));
            results_l.push(r_max);
        }
    }
    let mut r_max = max(results_r.pop().unwrap(), results_l.pop().unwrap());
    {
        let mut v = 0;
        for xv in xv {
            v += xv.1;
            r_max = max(r_max, v - xv.0 * 2 + results_l.pop().unwrap());
        }
    }

    {
        let mut v = 0;
        for xv in xv.iter().rev() {
            v += xv.1;
            r_max = max(r_max, v - (c - xv.0) * 2 + results_r.pop().unwrap());
        }
    }
    max(0, r_max)
}

mod utils {
    use super::*;

    pub struct AtRead<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        {$f:ident($($v:ident: $t:ident),*)} => {
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                $(
                    let $v = next(i);
                )*
                ($($v),*)
            }
        };
    }

    impl<R: BufRead> AtRead<R> {
        pub fn from(r: R) -> Self {
            AtRead {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }
        fn_read! { read2(v1: T1, v2: T2) }
    }
    fn next<'a, T: FromStr, I: std::iter::Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
string N;int K,n;
int nCr(int n,int r){
    if(r==1)return n;
    if(r==2)return n*(n-1)/2;
    if(r==3)return n*(n-1)*(n-2)/6;
    return 0;
}
int dp(int i,int k,bool s){
    if(k==0)return 1;
    else if(i==n)return 0;
    if(s)return nCr(n-i,k)*pow(9,k);
    else {
        if(N[i]=='0')return dp(i+1,k,0);
        else return dp(i+1,k,1)+dp(i+1,k-1,1)*(N[i]-'1')+dp(i+1,k-1,0);
    }
}
int main(){
    cin>>N>>K;
    n=N.size();
    cout<<dp(0,K,0)<<endl;
}


Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = list(map(int, args[1].split()))

    cur = A
    for _ in range(k):
        prev = cur.copy()
        cur = [0]*n
        for x, p in enumerate(prev):
            cur[max(0, x-p)] += 1
            if x+p+1 < n:
                cur[x+p+1] -= 1

        satulated = True
        for i in range(1, n):
            cur[i] += cur[i-1]
            satulated &= cur[i] == n
        if satulated:
            break

    return ' '.join(map(str, cur))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 167840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))




int main(){
	ll n,m,k;
	set<ll> se;
	cin >> n;
	FOR(i,0,n){
		cin >> k;
		se.insert(k);
	}
	cin >> m;
	FOR(i,0,m){
		cin >> k;
		se.erase(k);
	}
	for(auto x:se){
		cout << x << endl;
	}
}



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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
	list<char> lst;
	string s;
	cin>>s;
	for(int c:s) lst.pb(c);
	int q,rev=0;
	cin>>q;
	while(q--){
		int t;
		cin>>t;
		if(t==1)
			rev^=1;
		else{
			int pos; char c;
			cin>>pos>>c;
			if(pos==1 && !rev)
				lst.push_front(c);
			else if(pos==1 && rev)
				lst.pb(c);
			else if(pos==2 && !rev)
				lst.pb(c);
			else
				lst.push_front(c);
		}
	}
	if(rev)
		reverse(all(lst));
	for(char c:lst)
		cout<<c;
	cout<<endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

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

int main() {
  int A;
  int B;
  string C;
  cin >> A;
  A = A + 1;
  cin >> B;
  cin >> C;
  vector<int> D(A);
  int E = 0;
  int F;
  int G;
  while(A > 1){
    F = B;
    G = 0;
    if(A - 1 <= F){
      D.at(E) = A - 1;
      A = 0;
      E = E + 1;
    }
    else{
      while(G == 0){
        if(C.at(A - F - 1) == '0'){
          A = A - F;
          D.at(E) = F;
          E = E + 1;
          G = 1;
        }
        if(F == 1 && G == 0){
          G = 2;
        }
        F = F - 1;
      }
      if(G == 2){
        A = -1;
      }
    }
  }
  if(A == 0){
    while(E > 0){
      E = E - 1;
      cout << D.at(E) << endl;
    }
  }
  else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 1024
H, W, M = map(int, input().split())
Nh = [0]*(H+1)
Nw = [0]*(W+1)
HW = []
for _ in range(M):
    h, w = map(int, input().split())
    HW.append((h,w))

    Nh[h] += 1
    Nw[w] += 1

maxH = max(Nh)
Ih = [False] * (H+1)
xh = 0
for ih, nh in enumerate(Nh):
    if nh==maxH:
        Ih[ih] = True
        xh += 1

maxW = max(Nw)
Iw = [False] * (W+1)
xw = 0
for iw, nw in enumerate(Nw):
    if nw==maxW:
        Iw[iw] = True
        xw += 1

n = 0
for ih, iw in HW:
    if Ih[ih] and Iw[iw]: n+=1

ans = maxH+maxW
print(ans if n<xh*xw else ans-1)


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

K = int(input())
count  = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            count += gcd(a,b,c)

print(count)

Measured memory_bytes: 69684
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
using namespace std;
constexpr int64_t MOD = 1000000007;

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

  int32_t H, A;
  cin >> H >> A;
  int res = (H%A == 0)? H/A : H/A + 1;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
//#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
using namespace std;
#define frn(i,a,b) for(ll i=a;i<b;i++)
#define forn(i,a,b) for(ll i=a;i<=b;i++)
#define frt(i,a,b) for(auto it=a;it!=b;it++)
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define SQ(a) (a)*(a)
#define SUM(n) ((n)*(n+1))/2
#define SqSUM(n) ((n)*(n+1)*(2*n+1))/2
#define GMSUM(a,r,n) (a*pow(r,n)-a)/(r-1)
// to sort vector of any kind string or any sorting form sort(v.begin(),v.end()); and for reverse use rbegin and rend
const long long int md = 998244353;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<vector<ll, ll> > vvi;
// typedef bitset<5> bst;
const ll MAX = LONG_MAX;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    ll ca = w-a,cb = h-b,fl=0,ii=0,jj=0;
    frn(i,0,h+1)
    {
        frn(j,0,w+1)
        {
            if(i*(a-ca)+h*ca==j*(b-cb)+w*cb)
            {
                fl=1;ii=i;jj=j;
                break;
            }
        }
        if(fl==1)
            break;
    }
    if(fl==0)
    {
        cout<<-1<<'\n';
    }
    else
    {
        ll ar[w];
        frn(i,0,w)
        {
            if(i<jj)
            {
                ar[i]=b;
            }
            else
            {
                ar[i]=cb;
            }
        }
        ll ara[h][w];
        frn(i,0,h)
        frn(j,0,w)
        ara[i][j]=0;
        frn(i,0,h)
        {
            int c=0;
            frn(j,0,w)
            {
                if(i<ii)
                {
                if(c==a)
                    break;
                if(ar[j]>0)
                {
                    ara[i][j]=1;
                    ar[j]--;
                    c++;
                }
                }
                else
                {
                    if(c==ca)
                        break;
                    if(ar[j]>0)
                    {
                        ara[i][j]=1;
                        ar[j]--;
                        c++;
                    }
                }
            }
        }
        frn(i,0,h){
        frn(j,0,w)
        cout<<ara[i][j];
        cout<<'\n';}
    }
    return 0;
}

Measured memory_bytes: 9088
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination

int main(){
    int a, b;
    cin >> a>> b;
    if((a+b)%2==0){
        cout<< (a+b)/2<<endl;
        return 0;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n, roop;
    cin >> n;
    vector<long long int> a(n), b(n);
    for (int i=0; i<n; i++) {
        long long int tmpa;
        cin >> tmpa;
        a[i] = tmpa;
    }
    for (int i=0; i<n; i++) {
        long long int tmpb;
        cin >> tmpb;
        b[i] = tmpb;
    }
    
    roop = accumulate(b.begin(), b.end(), 0ll) - accumulate(a.begin(), a.end(), 0ll);
    
    long long int sum = 0;
    for (int i = 0; i < n; i++) {
        if(b[i] - a[i] > 0) sum += ((b[i] - a[i]) + 1)/2;
    }
    
    if (sum <= roop) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
int N;
  cin >> N;
  vector<int> proA(N);
  vector<int> proB(N);
  vector<int> proC(N);
  
  vector<vector<int>> data(3, vector<int>(N));
  rep(i, N){
  cin >> data.at(0).at(i) >> data.at(1).at(i)>> data.at(2).at(i);
  }
  
  rep(i, N){
  if(i == 0){
  proA[i] = data.at(0).at(i);
  proB[i] = data.at(1).at(i);
  proC[i] = data.at(2).at(i);
  }
    else{
  proA[i] = data.at(0).at(i)+max(proC[i-1],proB[i-1]);
  proB[i] = data.at(1).at(i)+max(proA[i-1],proC[i-1]);
  proC[i] = data.at(2).at(i)+max(proA[i-1],proB[i-1]);
    }
  }
  
  
  cout << max(proA[N-1],max(proB[N-1], proC[N-1])) << endl;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int a,ar[5123456],n,maxs=-5;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        ar[a]++;
    }
    for(int i=0;i<112345;i++){
        if(i==0)maxs=ar[0]+ar[1]+ar[2];
        else if(i==112345-1)
            maxs=max(maxs,ar[112345-2]+ar[112345-1]+ar[112345-3]);
        else
            maxs=max(maxs,ar[i-1]+ar[i]+ar[i+1]);
    }
    cout<<maxs<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
	int n, x;
	int a = 0;
	int l = 0;
	int k = 1;

	scanf("%d", &n);
	scanf("%d", &x);

	for (int i = 0; i < n; i++) {
		scanf("%d", &l);
	
		a = a+l;
		if (a <= x) {
			k++;
		}
	}
	printf("%d", k);
}

Measured memory_bytes: 128
// AOJ Volume 1 Problem 0196 Baseball Championship

#include <stdio.h>
#include <string.h>

typedef struct {
	char name[10];
	int win;
	int loose;
} DATA;


int main(void)
{
	int n;
	DATA data[10], tmp;
	int i, j;
	int result;
	
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		for (i = 0; i < n; i++){
			scanf("%s", data[i].name);
			data[i].win = data[i].loose = 0;
			for (j = 0; j < n - 1; j++){
				scanf("%d", &result);
				if (result == 0){
					data[i].win++;
				}
				else if (result == 1){
					data[i].loose++;
				}
			}
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n - 1; j++){
				if (data[j].win < data[j + 1].win){
					tmp= data[j];
					data[j] = data[j + 1];
					data[j + 1] = tmp;
				}
				else if (data[j].win == data[j + 1].win &&
				         data[j].loose > data[j + 1].loose){
					tmp= data[j];
					data[j] = data[j + 1];
					data[j + 1] = tmp;
				}
			}
		}
		
		for (i = 0; i < n; i++){
			printf("%s\n", data[i].name);
		}
	}
	
	return (0);
}

Measured memory_bytes: 584
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
vi lis[101];
int cnt=0;
int p=1;
bool used[101];
void dfs(int s)
{
	int i,j;
	for(i=0;i<lis[s].size();i++)
	{
		if(!(used[lis[s][i]]))
		{
			used[lis[s][i]]=true;
			p++;
			dfs(lis[s][i]);
		}
		if(p>2)cnt=max(cnt,p);
	}
	used[s]=false;
	p--;
	return ;
}
int main()
{
	int e;
	while(1)
	{
		cnt=0;
		cin >> e;
		if(e==0)break;
		int mv=-1;
		for(int i=0;i<101;i++)
		{
			lis[i].clear();
		}
		for(int i=0;i<e;i++)
		{
			int a,b;
			cin >> a >> b;
			mv=max(mv,max(a,b));
			lis[a].pb(b);
			lis[b].pb(a);
		}
		for(int i=1;i<=mv;i++)
		{
			p=1;
			memset(used,0,sizeof(used));
			used[i]=true;
			dfs(i);
		}	
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    using namespace std;
    #define INF 10000000;
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define vec(n) vector<int> vec(n)
    #define vvec(m,n) vector<vector<int>> vec(m,vector(n))

    int main(){
      int a,b,c,x,y,sum = 0;
      bool f = true;
      cin >> a >> b >> c >> x >> y;
      
      while(x>0 && y>0){
        if(c*2 >= a+b){
          sum += a+b;
          x--;
          y--;
        }

        if(c*2 < a+b){
          sum += c*2;
          x--;
          y--;
        }
      }

      
        while(x>0){
          if(c*2 > a){
            sum += a;
            x--;
          }

          if(c*2 < a){
            sum += c*2;
            x--;
          }
        }



        while(y>0){
          if(c*2 > b){
            sum += b;
            y--;
          }

          if(c*2 < b){
            sum += c*2;
            y--;
          }
        }
      
      cout << sum <<endl;

    }
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    double w,max=0;
    int a,b,c;
    while(cin>>a>>b>>c,a!=0&&b!=0&&c!=0){max=0;
        for(int i=1; i<c; i++){
            for(int j=c; j>=i; j--){
               if((int)(i*(100+a)/100)+(int)(j*(100+a)/100)==c){
               if((int)(i*(100+b)/100)+(int)(j*(100+b)/100)>max){
               max=(int)(i*(100+b)/100)+(int)(j*(100+b)/100);
               }
            }
        }
    }
        cout<<max<<endl;
    }
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false)
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define fir first
#define sec second
#define mod 998244353
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define ll long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
inline int min(int x,int y,int z){return min(x,min(y,z));}
inline int max(int x,int y,int z){return max(x,max(y,z));}
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z){return add(add(x,y),z);}
inline int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y){return 1LL*x*y%mod;}
inline int mul(int x,int y,int z){return mul(mul(x,y),z);}
char s[5];
int query(int x,int y)
{
	printf("? %d %d\n",x-1,y-1);
	fflush(stdout);
	scanf("%s",s);
	return s[0]=='Y';
}
signed main()
{
	int a=read(),b=read();
	int n=a+b;
	if(a<=b)
	{
		printf("Impossible\n");
		return 0;
	}
	stack<int> s;
	for(int i=1;i<=n;i++)
	{
		if(s.empty()) s.push(i);
		else
		{
			int R=query(s.top(),i);
			if(R) s.push(i);
			else s.pop();
		}
	}
	string ans; int res=s.top();
	for(int i=1;i<=n;i++) ans+=(query(res,i)+'0');
	cout<<"! "<<ans<<endl;
	return 0;
}



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

const int mod = 1e9 + 7, N = 2e5 + 10;
int n, h[N], tot, l[N], r[N], sum[N], pos[N], f[N];
struct node {
    int x, v;
    bool operator < (const node &a) const {
        return v < a.v;
    }
}a[N];

int main() {
    cin >> n;
    rep(i, 1, n) {
        scanf("%d%d", &a[i].x, &a[i].v);
        h[i] = a[i].x;
    }
    sort(a + 1, a + n + 1);
    sort(h + 1, h + n + 1);
    tot = unique(h + 1, h + n + 1) - h - 1;
    rep(i, 1, n) {
        a[i].x = lower_bound(h + 1, h + tot + 1, a[i].x) - h;
        pos[a[i].x] = i;
    }
    rep(i, 1, n) {
        r[i] = max(r[i - 1], pos[i]);
    }
    l[n] = pos[n];
    for (int i = n - 1; i; --i) {
        l[i] = min(l[i + 1], pos[i]);
    }

    int L = 0;
    f[0] = sum[0] = 1;
    rep(i, 1, n) {
        while (r[L] < l[i] - 1) ++L;
        f[i] = (sum[i - 1] - sum[L - 1] + mod) % mod;
        sum[i] = (sum[i - 1] + f[i]) % mod;
    }
    while (r[L] < n) ++L;
    printf("%d\n", (sum[n] - sum[L - 1] + mod) % mod);
    return 0;
}


Measured memory_bytes: 10024
#!/usr/bin/env python3
#AOJ B

m = int(input())
for _ in range(m):
    s = list(input())
    all = []
    for i in range(1,len(s)):
        front = s[:i]
        back = s[i:]
        fr = list(reversed(front))
        br = list(reversed(back))
        pair = [front,fr,back,br]
        for j in range(4):
            if j > 1:
                for k in range(2):
                    p = pair[j] + pair[k]
                    if p not in all:
                        all.append(p)
            else:
                for k in range(2,4):
                    p = pair[j] + pair[k]
                    if p not in all:
                        all.append(p)

    if len(all) == 0:
        print(1)
    else:
        print(len(all))



Measured memory_bytes: 6028
#!/usr/bin/python3
# -*- coding: utf-8 -*-
h, w, m = map(int, input().split())
bom_set = set()
h_dict = {}
w_dict = {}
for i in range(m):
    hh, ww = map(int, input().split())
    bom_set.add(tuple([hh, ww]))
    if hh in h_dict:
        h_dict[hh] += 1
    else:
        h_dict[hh] = 1
    if ww in w_dict:
        w_dict[ww] += 1
    else:
        w_dict[ww] = 1
h_max_count = max(h_dict.values())
w_max_count = max(w_dict.values())
hh_dict = {}
ww_dict = {}
for hh in h_dict:
    if h_dict[hh] == h_max_count:
        hh_dict[hh] = h_max_count
for ww in w_dict:
    if w_dict[ww] == w_max_count:
        ww_dict[ww] = w_max_count
flag = 0
for hh in hh_dict:
    for ww in ww_dict:
        if tuple([hh, ww]) not in bom_set:
            flag = 1
            break
    if flag == 1:
        break
if flag == 1:
    print(h_max_count + w_max_count)
else:
    print(h_max_count + w_max_count - 1)

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

ll cnt_2(ll x) {
    ll res = 0;
    while (x % 2 == 0) res++, x /= 2;
    return res;
}

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

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

int main() {
    ll n, m, x;
    cin >> n >> m;
    vector<ll> b;
    ll c;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;

        b.push_back(a / 2);
        if (b.size() == 1) c = cnt_2(a / 2), x = a / 2;
        if (b.size() > 1 && c != cnt_2(a / 2)) {
            cout << 0 << endl;
            return 0;
        }
        if (b.size() > 1) x = lcm(x, a / 2);
        if (x > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    if (x > m) {
        cout << 0 << endl;
        return 0;
    }
    ll k = m / x;
    if (k % 2 == 0) k--;
    cout << k / 2 + 1 << endl;
    return 0;
}

Measured memory_bytes: 1400
n,t = gets.split(" ").map(&:to_i)
minc = 1001
for i in 1..n do
    cost,time = gets.split(" ").map(&:to_i)
    if time <= t
        if cost <= minc
            minc = cost
        end
    end
end

if minc == 1001
    puts "TLE"
else
    puts minc
end

Measured memory_bytes: 1788
using System;
using System.Linq;

namespace ABC139A
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = CIN.String();
            string T = CIN.String();

            int ans = 0;
            for (int i = 0; i < 3; i++)
            {
                if (S[i] == T[i])
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

using Graph = vector<vector<int>>;

vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(const Graph &G, int v, int& ptr){
  first_order[v] = ptr++;

  seen[v] = true;
  for(int nv : G[v]){
    if(seen[nv] == true) continue;
    dfs(G, nv, ptr);
  }

  last_order[v] = ptr++;
}

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

  Graph G(n+1);
  rep(i, n){
    int u, k; cin >> u >> k;
    rep(j, k){
      int v; cin >> v;
      G[u].push_back(v);
    }
  }

  seen.assign(n+1, false);
  first_order.resize(n+1);
  last_order.resize(n+1);
  int ptr = 1;
  REP(i, 1, n){
    if(seen[i] == false){
      dfs(G, i, ptr);
    }
  }

  REP(i, 1, n){
    printf("%d %d %d\n", i, first_order[i], last_order[i]);
  }

  return 0;
}






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



bool aoki_win(char u, char d, int s,int h, string &taka, string &aoki){
    int max_y=h-1,min_y=0;
    //cout << min_y << " " << max_y << endl;
    for(int i=taka.size()-1;i>=0;i--){
        if(aoki[i]==u && max_y!=h-1){
            max_y++;
        }else if(aoki[i]==d && min_y!=0){
            min_y--;
        }
        //cout << min_y << " " << max_y << endl;
        if(taka[i]==u){
            min_y++;
        }else if(taka[i]==d){
            max_y--;
        }
        //cout << min_y << " " << max_y << endl;
        if(max_y<min_y){
            return false;
        }
    }
    return min_y<=s && s<=max_y;
}



int main(void){
    int H,W,N;
    int sr,sc;
    string S,T;
    cin >> H >> W >> N;
    cin >> sr >> sc;
    cin >> S;
    cin >> T;
    cout << (aoki_win('U','D',sr-1,H,S,T) && aoki_win('L','R',sc-1,W,S,T) ? "YES" : "NO") << endl;
    return 0;
}



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

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

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

    // 愚直
    int ans = INT_MAX;
    for(int i = -100; i <= 100; i++){
        int tmp = 0;
        for(int j = 0; j < n; j++){
            tmp += (i-A[j])*(i-A[j]);
        }
        ans = min(tmp, ans);
    }

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

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

typedef long long ll;


vector<ll> l, r;

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(int i=0; i<n; i++) cin >> v[i];
    ll ans = 1e9;
    for(int i=0; i<=n-k; i++){
        ll l = v[i], r = v[i+k-1];
        ans = min({ans, abs(l-r)+abs(l), abs(l-r)+abs(r)});
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int res = 0;
    for (int i = 0; i <= a; i++) {
        if (500 * i > x) break;
        for (int j = 0; j <= b; j++) {
            if (500 * i + 100 * j > x) break;
            for (int k = 0; k <= c; k++) {
                if (500 * i + 100 * j + 50 * k > x) break;
                if (500 * i + 100 * j + 50 * k == x) res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,n,j;
	int max;
	int min;
	int maximum;
	int a[200000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	min=a[0];
	max=a[n-1];
	maximum=a[1]-a[0];

	for(i=n-2;i>=0;i--)
	{
		if(maximum<max-a[i])
			maximum=max-a[i];
	}

	for(i=n-2;i>1;i--)
	{
		if(a[i]>max)
		{
			max=a[i];
			for(j=i-1;j>=0;j--)
			{
				if(max-a[j]>maximum)
					maximum=max-a[j];
			}
		}
	}
	printf("%d\n",maximum);
	return 0;
}

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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	int k;
	cin>>k;
	vector<int>h(n);
	for(int i=0; i<n; i++){
		cin>>h[i];
	}
	int cnt=0;
	for(int i=0; i<n; i++){
		if(h[i]>=k)cnt++;
	}
	cout<<cnt<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {
	long long n; cin >> n;
	long long p = 1; int i = 0;
	for (;; i++) {
		if (p * 2 - 1 <= n)p *= 2;
		else break;
	}
	cout << i << endl;
	return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>

#define MAX 1000000

int main (void) {

    int n, a;
    int min=MAX, max=-1*MAX;
    double sum = 0;

    scanf ("%d", &n);

    for (int i=0; i<n; i++) {
        scanf ("%d", &a);
        if (min>a) min = a;
        if (max<a) max = a;
        sum += a;
    }

    printf ("%d %d %.0lf\n", min, max, sum);

    return 0;
}


Measured memory_bytes: 2108
#include <stdio.h>

/*
バブルソート
*/

void trace(int A[], int n){
    // 1行半角スペースで書き出し
    for (int i = 0; i < n; i++){
        printf("%d", A[i]);
        if (i != n-1){
            printf(" ");
        }
        else {
            printf("\n");
        }
    }
}

int bubbleSort(int A[], int n){
    int flag = 1;
    int cnt = 0;
    while (flag) {
        flag = 0;
        for (int j = n - 1; j > 0; j--){
            if (A[j] < A[j-1]){
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                cnt++;
            }
        }
    }

    return cnt;
}

int main(){
    // 1行読む
    int n;
    scanf("%d", &n);

    // 1行半角スペースで読む
    int A[100];
    for (int i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }

    // 挿入ソートのロジック部分の関数
    int cnt = bubbleSort(A, n);
    
    // 出力用の関数
    trace(A, n);

    // 交換回数
    printf("%d\n", cnt);

    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    vector<double> A(N);
    double total = 0;
    REP(i,N){
        cin >> A[i];
        total += 1/A[i];
    }
    total = 1/total;
    cout <<total<< "\n";
}

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

using namespace std;
using ll = long long;

void solve(){
	char c;
	cin >> c;
	cout << char(c+1) << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){ 
		solve();
	}
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t N;
  cin>>N;
  int64_t l=pow(N,0.5);
  int64_t ans=0;
  for(int64_t i=1;i<=l;i++)
    if(N%i==0){
    if(2<=N/i-i)
      ans+=(N/i-1);
    }cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 384
def main():
    num = int(input())
    data = list(map(int, input().split()))

    now_num = [0, 0]
    now_c = [0, 0]
    for i in range(num):
        now_num[0] += data[i]
        if i % 2 == 0:
            if now_num[0] <= 0:
                now_c[0] += 1 - now_num[0]
                now_num[0] = 1
        else:
            if now_num[0] >= 0:
                now_c[0] += now_num[0] + 1
                now_num[0] = -1

        now_num[1] += data[i]
        if i % 2 == 1:
            if now_num[1] <= 0:
                now_c[1] += 1 - now_num[1]
                now_num[1] = 1
        else:
            if now_num[1] >= 0:
                now_c[1] += now_num[1] + 1
                now_num[1] = -1

    print(min(now_c))






if __name__ == '__main__':
    main()

Measured memory_bytes: 63856
#include<bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;
string s;
bool e[N];
ll ans;
int cn,n,su[N],qu[3];
int main(){
	cin>>s;
	n=s.length();
	for (int i=1;i<=n;i++){
		e[i]=0;
		if (s[i-1]=='1'){cn++;ans+=(cn+1)/2;e[i]=1;}
	}
	for (int i=1;i<=n;i++){
		if (s[i-1]=='0'&&(su[i-1]%2==1))cn++,ans+=(cn+1)/2,e[i]=1;
		su[i]=su[i-1]+e[i];
	}
	for (int i=n;i>=1;i--){
		if (e[i]==0){
			ans+=(su[i-1]+1)/2+qu[(su[i]+1)%2];
		}
		swap(qu[0],qu[1]);
		if (s[i-1]=='1')qu[0]++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4776