akhauriyash/Code-Regression huggingface dataset:
n = int(input())
A = [0] + list(map(int, input().split()))
B = [0]*(n+1)
for i in range(n, 0, -1):
    B[i] =(A[i] + sum(B[::i])) % 2
print(sum(B))
print(*(i for i, b in enumerate(B) if b))

Measured memory_bytes: 13108
#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>;
string f(ll n){
    if(n == 0) return"";
    n--;
    return f(n/26) + string(1, 'a'+n%26);
}
int main(){
    ll n;
    cin >> n;
    cout << f(n) << endl;
    return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int64_t> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        --a[i];
    }

    vector<int64_t> cnt(n,0);
    for(int i = 0; i < n; ++i){
        ++cnt[a[i]];
    }

    int64_t sum = 0;
    for(int i = 0; i < n; ++i){
        sum += cnt[i] * (cnt[i]-1ll) / 2ll;
    }

    for(int i = 0; i < n; ++i){
        cout << sum - (cnt[a[i]] - 1ll) << endl;
    }

    return 0;
}


Measured memory_bytes: 5760
/*
  AOJ 2519
  Title:Eglish
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#define max(x,y) (((x)>(y))?(x):(y))
#define myabs(x) (((x)>0)?(x):(-(x)))
int N,T;
char word[100][9];
char length[100];
int score[100];
int  hist[100];
char line[4][4];
char alpha_pos[26][16][2];
char count[26];
int dp[10001];
int dp2[10001];

int search_word2(char word[],int y,int x,int len,short flag)
{
  int i,x1,y1,ret;
  char c;

  //printf("[%s] %d %d [%d]\n",word,y,x,len);

  if(flag & (1<<(4*y+x)))
    return(0);
  if(len==0)
    return(1);
  flag |= 1<<(4*y+x);

  c=word[0]-'A';
  for(i=ret=0;i<count[c];i++)
    {
      y1=alpha_pos[c][i][0];
      x1=alpha_pos[c][i][1];
      if(myabs(x1-x)<2 && myabs(y1-y)<2 && !(x==x1 && y==y1))
	ret+=search_word2(word+1,y1,x1,len-1,flag);
    }
  return(ret);
}

int search_word(char word[],int len)
{
  int i,x,y,ret;
  short flag=0;
  char c;

  c=word[0]-'A';
  for(i=ret=0;i<count[c];i++)
    {
      y=alpha_pos[c][i][0];
      x=alpha_pos[c][i][1];
      //printf("[%s][%d] %d %d",word,i,y,x);
      ret+=search_word2(word+1,y,x,len-1,flag);
    }
  return(ret);
}


void search_word_all()
{
  int i,len;
  char *p;
  

  for(i=0;i<N;i++)
    {
      p=&word[i][0];
      len=strlen(p);
      hist[i]=search_word(p,len);
    }
}

dump()
{
  int i,j;
  for(i=0;i<26;i++)
    if(count[i])
    {
      printf("%c|",i+'A');
      for(j=0;j<count[i];j++)
	printf("%d %d|",alpha_pos[i][j][0],alpha_pos[i][j][1]);
      printf("\n");
    }
}
dump2()
{
  int i;

  for(i=0;i<N;i++)
    printf("%d) %s [%d] %d\n",i,&word[i][0],length[i],hist[i]);
}
solve()
{
  int i,j,k,pos,ret;
  
  for(i=0;i<N;i++)
    {
      memcpy(dp2,dp,sizeof(int)*(1+T));
      for(j=0;j<=T;j++)
	if(j==0||dp2[j])
	  for(k=1;k<=hist[i];k++)
	    {
	      pos=j+k*length[i];
	      if(pos>T)
		break;
	      dp[pos] = max(dp[pos],dp2[j]+k*score[i]);
	    }
    }
  for(i=T,ret=0;i>=1;i--)
    ret=max(ret,dp[i]);
  return(ret);
}
main()
{
  int i,j,ret;
  char c;

  scanf("%d",&N);

  for(i=0;i<N;i++)
    {
      scanf("%s %d",&word[i][0],&score[i]);
      length[i]=strlen(&word[i][0]);
    }
  for(i=0;i<4;i++)
    {
      scanf("%s",&line[i][0]);
      for(j=0;j<4;j++)
	{
	  c=line[i][j]-'A';
	  alpha_pos[c][count[c]][0]=i;
	  alpha_pos[c][count[c]][1]=j;
	  count[c]++;
	}
    }
  //dump();
  //printf("%d\n",search_word("abcd",4));
  scanf("%d",&T);
  search_word_all();
  //dump2();
  ret=solve();
  printf("%d\n",ret);
  return(0);
}

Measured memory_bytes: 700
#include <stdio.h> 
 #include <ctype.h> 
  
  
 int main(){ 
     char ch; 
     while(1){ 
         scanf("%c", &ch); 
         if(ch=='\n'){ 
             printf("\n"); 
             break; 
         }else if(islower(ch)){ 
             printf("%c", toupper(ch)); 
         }else if(isupper(ch)){ 
             printf("%c", tolower(ch)); 
         }else{ 
             printf("%c", ch); 
         } 
     } 
  
  
     return 0; 
 }


Measured memory_bytes: 2088
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> ans;

    vector<ll> p(A);
    for(size_t i=0;i<A; i++)
    {
        cin >> p[i];
    }
    sort(p.rbegin() ,p.rend());

    for(size_t i=0;i<X; i++)
    {
        ans.push_back(p[i]);
    }

    vector<ll> q(B);
    for(size_t i=0;i<B; i++)
    {
        cin >> q[i];
    }
    sort(q.rbegin() , q.rend());

    for(size_t i=0;i<Y; i++)
    {
        ans.push_back(q[i]);
    }

    ll r;
    for(size_t i=0;i<C; i++)
    {
        cin >> r;
        ans.push_back(r);
    }

    sort(ans.rbegin() , ans.rend());

    ll total = 0;
    for(size_t i=0;i<X+Y; i++)
    {
        total += ans[i];
    }
    cout << total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

typedef pair<int, int> P;

bool func(const P &a, const P &b){
    if(a.second < b.second){
        return true;
    }else if(a.second > b.second ){
        return false;
    }else{
        if(a.first < b.first){
            return true;
        }else{
            return false;
        }
    }
}

int main() {

    int n,m;
    cin >> n >> m;
    vector<P> d(m);
    int a,b;
    rep(i,m){
        cin >> a >>b;
        d[i] = P(a,b);
    }

    sort(d.begin(), d.end(), func);

    int ans = 1, tmp;
    tmp = d[0].second;
    rep(i,m){
        if(d[i].second > tmp && d[i].first >= tmp){
            ans++;
            tmp = d[i].second;
        }
    }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define hi "visited\n" //sasta debugging
using namespace std;

//author::@whohet-->Het Patel

signed main()
{
	fasterthanlight;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='?')
			s[i]='D';
	}
	cout<<s;
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


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

typedef long long ll;
#define pii pair<int ,int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 2005

int n;
string h[MAXX];

int main()
{
    _FastIO;
    cin >> n;
    set<string> s;
    multiset<string> ms;
    bool flag = true;
    for(int i = 0; i < n; i++){
        string str;
        cin >> str;
        s.insert(str);
        ms.insert(str);
    }
    set<string>::iterator it;
    int ans = 0;
    for(it = s.begin(); it != s.end(); it++){
            string x = *it;
        if(ans < ms.count(x))
            ans = ms.count(x);
    }
    for(it = s.begin(); it != s.end(); it++){
        string x = *it;
            if(ms.count(*it) == ans)
                cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 30080
from operator import itemgetter

N,M = map(int,input().split())
AB = [[] for i in range(N)]
for i in range(N):
  AB[i] = list(map(int,input().split()))

AB = sorted(AB, key=itemgetter(0))

money = 0
i = 0
while M > 0:
    if M > AB[i][1]:
        M -= AB[i][1]
        money += AB[i][0] * AB[i][1]
    else:
        money += AB[i][0] * M
        break
    i += 1

print(money)

Measured memory_bytes: 29792
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, M;

int main() {
  cin >> N >> M;
  vector<int> divs;
  for (int i = 1; i * i <= M; ++i) {
    if (M % i == 0) {
      divs.push_back(i);
      if (M / i != i) {
        divs.push_back(M / i);
      }
    }
  }
  sort(divs.begin(), divs.end());
  auto lb = lower_bound(divs.begin(), divs.end(), N);
  int nn = *lb;
  cout << M / nn << endl;
}


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

const int MAXN=1e6+5;

int n,sum,k;
int a[MAXN];
char s[MAXN];

int main(){
    scanf("%s",s); n=strlen(s);
    for(int i=0;i<n;i++) a[n-i-1]=s[i]-'0';
    for(int i=0,t=0;i<n;i++){
        t+=a[i]*9;
        a[i]=t%10;
        sum+=a[i];
        t/=10;
        if(i==n-1&&t) n++;
    }
    for(k=1;k<=n;k++){
        a[0]+=9;
        sum+=9;
        for(int j=0,t=0;j<n;j++){
            t+=a[j];
            sum-=a[j];
            a[j]=t%10;
            sum+=a[j];
            t/=10;
            if(!t) break;
            if(j==n-1) n++;
        }
        if(sum<=9*k) break;
    }
    printf("%d\n",k);
}


Measured memory_bytes: 3712
n = int(input())
r_s = [int(input()) for i in range(n)]

minv = r_s[0]
maxv = r_s[1] - r_s[0]
for i in range(1, n):
    maxv = max(maxv, r_s[i]-minv)
    minv = min(minv, r_s[i])

print(maxv)

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<array<int64_t, 3>> XYZ(N);
  for (int i = 0; i < N; i++) {
    cin >> XYZ[i][0] >> XYZ[i][1] >> XYZ[i][2];
  }

  int64_t result = 0;
  for (int i = 0; i < 1 << 3; i++) {
    vector<int64_t> sums;
    for (int k = 0; k < N; k++) {
      int64_t sum = 0;
      for (int j = 0; j < 3; j++) {
        sum += (i & (1 << j)) ? XYZ[k][j] : -XYZ[k][j];
      }
      sums.emplace_back(sum);
    }
    sort(sums.rbegin(), sums.rend());

    int64_t sum = 0;
    for (int k = 0; k < M; k++) sum += sums[k];
    result = max<int64_t>(result, sum);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int inv2 = (mod + 1) / 2;
typedef long long ll;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}
pair < int, int > solve(vector < int > h) {

    if (h.empty()) return make_pair(1, 2);     //// ???
    if (h.size() == 1) return make_pair(pw(2, h[0]), pw(2, h[0]));
    int mn = h[0];
    for (int i = 0; i < h.size(); i++) {
        if (h[i] == 1) {
            vector < int > nh1, nh2;
            for (int j = 0; j < i; j++) nh1.push_back(h[j]);
            for (int j = i + 1; j < h.size(); j++) nh2.push_back(h[j]);
            pair < int, int > f1 = solve(nh1);
            pair < int, int > f2 = solve(nh2);
            return make_pair(mult(2, mult(f1.first, f2.first)), mult(mult(f1.second, f2.second), inv2));
        }
        mn = min(h[i], mn);
    }
    vector < int > small;
    small.push_back(-1);
    for (int i = 0; i < h.size(); i++) {
        if (h[i] == mn) small.push_back(i);
    }
    small.push_back(h.size());
    vector < pair < int, int > > all;
    for (int j = 0; j + 1 < small.size(); j++) {
        vector < int > nh;
        if (small[j] + 1 == small[j + 1]) continue;
        for (int i = small[j] + 1; i < small[j + 1]; i++) {
            nh.push_back(h[i] - mn + 1);
        }
        all.push_back(solve(nh));
    }
    if (small.size() == h.size() + 2) {
        return make_pair(sub(sum(pw(2, mn), pw(2, h.size())), 2) ,pw(2, mn));
    }
    int num = small.size() - 2;
    int f2 = 1;
    for (int i = 0; i < all.size(); i++) {
        f2 = mult(f2, mult(all[i].second, inv2));
    }
    int final2 = mult(f2, pw(2, mn));
    int f1 = 1;
    for (int i = 0; i < all.size(); i++){
        f1 = mult(f1, all[i].first);
    }
    f1 = mult(f1, pw(2, num));
    f1 = sub(f1, mult(2, f2));
    f1 = sum(f1, final2);
    return make_pair(f1, final2);
}
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    srand(time(0));
    int n;
    vector < int > h;
    cin >> n;
    h.resize(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    cout << solve(h).first;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;

ll bit[200010];
//ll kai[3010];
ll Cnt[1000010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }



/*ll sum(ll i)
{
	//i += 1;
	ll t = 0;
	while (i > 0)
	{
		t += bit[i];
		i -= i & -i;
	}
	return t;
}

void add(ll i, ll x)
{
	//i += 1;
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/



void test() {
	cout << "888888888888888888888888" << endl;
}

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

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

void makePrimeList(ll x) {
	ll X = x;
	for (ll j = 2; j * j <= x; j++) {
		ll cnt = 0;
		while (X % j == 0) {
			cnt++;
			X /= j;
		}
		if (cnt) {
			Cnt[j] = max(Cnt[j], cnt);
		}
	}
	if (X != 1) Cnt[X] = max(Cnt[X], 1LL);
}

ll N;
ll a[200010];
ll cnt;

void solve() {
	cin >> N;
	rep(i, N) {
		cin >> a[i];
		if (cnt + 1 == a[i]) {
			cnt++;
		}
	}
	if (cnt == 0) cout << -1 << endl;
	else cout << N - cnt << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	LL r;
	cin >> r;

	cout << 3 * r * r << endl;
	return 0;
}


Measured memory_bytes: 256
def solve () :
    n = int(input())
    arr = list(map(int, input().split(" ")))
    arr.sort()
    limit = 1e18
    if arr[0] == 0 :
        return 0
    else :
        cur = 1
        for a in arr :
            cur*=a 
            if cur >limit :
                return -1
    return cur 
    
print(solve())

Measured memory_bytes: 21640
#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
int a[200010];
int t,n;
int MOD = 1e9+7;
const int SIZE = 1e6+10;
int main(){
	string s;cin>>s;;
	map<char,int> m;
	for(auto c:s)	m[c]++;
	if(m.size()==2&&m[s[0]]==2){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}




Measured memory_bytes: 256
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def rotate(self):
        prev_s2 = self.s2
        self.s2 = self.s4
        self.s4 = self.s5
        self.s5 = self.s3
        self.s3 = prev_s2
    def top(self):
        return self.s1
    def front(self):
        return self.s2
    def right(self):
        return self.s3

s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice = Dice(s1, s2, s3, s4, s5, s6)
q = int(input())
for i in range(q):
    t, f = map(int, input().split())
    flag = False
    for j in range(6):
        if j % 2 == 0:
            dice.north()
        else:
            dice.west()

        for k in range(4):
            dice.rotate()
            if dice.top() == t and dice.front() == f:
                flag = True
                break
        if flag:
            break
    print(dice.right())

Measured memory_bytes: 6788
import sys

sys.setrecursionlimit(200000)

n, m = map(int, input().split())

edges = [set() for _ in range(n)]

for _ in range(m):
    s, t = map(int, input().split())
    edges[s].add(t)
    edges[t].add(s)

prenum = [None] * n
parent = [None] * n
lowest = [None] * n
counter = 0


def dfs(cur, prev):
    global counter
    prenum[cur] = lowest[cur] = counter
    counter += 1
    for edge in edges[cur]:
        if prenum[edge] is not None:
            if edge != prev:
                lowest[cur] = min(lowest[cur], prenum[edge])
            continue
        parent[edge] = cur
        dfs(edge, cur)
        lowest[cur] = min(lowest[cur], lowest[edge])


dfs(0, 1)
ap = [False] * n
r = 0
for _ in filter(lambda x: x == 0, parent):
    r += 1
    if r > 1:
        ap[0] = True
        break

for i in range(1, n):
    p = parent[i]
    if p and prenum[p] <= lowest[i]:
        ap[p] = True

for i, e in enumerate(ap):
    if e: print(i)

Measured memory_bytes: 25200
<?php
fscanf(STDIN, "%d %d", $N, $K);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d", $h[$i]);
}
sort($h);
$ans = PHP_INT_MAX;
for ($i = 0; $i < $N - $K + 1; $i++) {
    $ans = min($ans, $h[$i + $K - 1] - $h[$i]);
}
echo $ans;


Measured memory_bytes: 12792
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 200005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int a[maxn], n;
int Max, Second;
int num;
int main() {
    n = read();
    for (reg int i = 1; i <= n; i++) {
        a[i] = read();
        if (a[i] == Max) num++;
        else if (a[i] > Max) Max = a[i], num = 1;
    }
    if (num == 1) {
        for (reg int i = 1; i <= n; i++) {
            if (a[i] != Max) Second = max(Second, a[i]);
        }
    }
    if (num == 1) {
        for (int i = 1; i <= n; i++) {
            if (a[i] == Max) cout << Second << endl;
            else cout << Max << endl;
        }
    }
    else for (int i = 1; i <= n; i++) cout << Max << endl;
    return 0;
}


Measured memory_bytes: 2432
public class Main {
	 public static void main(String[] a){
		 for(int i=1;i<=9;i++){
			 for(int j=1;j<=9;j++){
				 System.out.println(i+"x"+j+"="+(i*j));
				 
			 }
		 }
	    
	 
	 }
}

Measured memory_bytes: 24112
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
typedef long long ll;

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

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

int main(){
  string s;
  cin>>s;
  string t;
  rep(i,s.size()){
    if(s[i]=='1')t+='1';
    if(s[i]=='0')t+='0';
    if(s[i]=='B'&&t.size()!=0)t.pop_back();
  }
  cout<<t<<endl;
}

Measured memory_bytes: 3596
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  as <- getIntVec n

  d1 <- VM.new (10^6+1)
  VM.set d1 (0::Int)
  d2 <- VM.new (10^6+1)
  VM.set d2 (0::Int)

  let sieve :: Int -> IO ()
      sieve i | i*i > 10^6 = return ()
              | otherwise = do
                  x <- VM.read d1 i
                  when (x == 0) $
                    forM_ [2..(10^6 `div` i)] $ \j -> do
                    let k = i * j
                    y <- VM.read d1 k
                    when (y == 0) $ VM.write d1 k i
                  sieve (i+1)

  sieve 2

  let pfactr :: Int -> Set.Set Int -> IO [Int]
      pfactr x s = do y <- VM.read d1 x
                      if y == 0
                        then return $ Set.toList (Set.insert x s)
                        else pfactr (x `div` y) (Set.insert y s)

      loop :: [Int] -> Int -> IO Int
      loop [] res = return res
      loop (f:fs) res
        | f == 1 = loop fs res
        | otherwise = do
        t <- VM.read d2 f
        VM.write d2 f (t+1)
        let res' = max res (t+1)
        loop fs res'

      solve :: Int -> Int -> IO Int
      solve i res | i >= n = return res
                  | otherwise = do
                      let a = as V.! i
                      fs <- pfactr a Set.empty
                      res' <- loop fs res
                      solve (i+1) res'

  x <- solve 0 0
  let ans | x <= 1 = "pairwise coprime"
          | x < n  = "setwise coprime"
          | otherwise = "not coprime"

  putStrLn ans


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

using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
 
#define INF 1987654321
#define IINF 87654321987654321
#define MOD 1000000007

struct SegmentTree {
	int n;
	vector<pii> st;

	void init(int sz) {
		n = 1;
		while(n < sz)
			n <<= 1;
		st.assign(2*n, {INF, INF});
	}

	void update(int p, pii val) {
		p += n-1;
		st[p] = val;
		for(p >>= 1; p; p >>= 1)
			st[p] = min(st[2*p], st[2*p+1]);
	}

	pii rangeMin(int l, int r) {
		pii res = {INF, INF};
		for(l += n-1, r += n-1; l <= r; l >>= 1, r >>= 1) {
			if(l & 1)
				res = min(res, st[l++]);
			if(!(r & 1))
				res = min(res, st[r--]);	
		}
		return res;
	}
};


const int MAXN = 1e5 + 50;
char s[MAXN];
int n, m;
void readInput() {
	scanf("%d%d", &n, &m);
	scanf("%s", s);
}


int dp[MAXN], nxt[MAXN];
void solve() {
	SegmentTree tree;
	tree.init(n);

	dp[n] = 0;
	tree.update(n, {dp[n], n});
	for(int i = n-1; i >= 0; i--) {
		if(s[i] == '1') {
			dp[i] = INF;
			tree.update(i, {dp[i], i});
		} else {
			pii val = tree.rangeMin(i+1, min(i+m, n));
			dp[i] = min(val.first + 1, INF);
			nxt[i] = val.second;
			if(i > 0)
				tree.update(i, {dp[i], i});
		}
	}

	if(dp[0] == INF) {
		printf("-1\n");
	} else {
		int cur = 0;
		while(cur < n) {
			printf("%d ", nxt[cur] - cur);
			cur = nxt[cur];
		}
	}
}

int main() {
	readInput();
	solve();
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {
	static long a;
	static long b;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Point> list = new ArrayList<>();
		if (n % 2 == 0) {
			for (int i = 1; i < n / 2; i++) {
				list.add(new Point(i, i + 1));
				list.add(new Point(i, n - i));
				list.add(new Point(i + 1, n - i + 1));
				list.add(new Point(n - i, n - i + 1));
			}
			if (n > 4) {
				list.add(new Point(1, n / 2));
				list.add(new Point(n / 2, n));
				list.add(new Point(1, n / 2 + 1));
				list.add(new Point(n / 2 + 1, n));
			}
		} else {
			for (int i = 1; i < n / 2; i++) {
				list.add(new Point(i, i + 1));
				list.add(new Point(i, n - i - 1));
				list.add(new Point(i + 1, n - i));
				list.add(new Point(n - i - 1, n - i));
			}
			list.add(new Point(n / 2, n));
			list.add(new Point(n / 2 + 1, n));
			if (n > 3) {
				list.add(new Point(1, n));
				list.add(new Point(n - 1, n));
			}
		}
		Collections.sort(list, new Comparator<Point>(){
		public int compare(Point p1, Point p2) {
			if (p1.a == p2.a) {
				return p1.b - p2.b;
			} else {
				return p1.a - p2.a;
			}
		}
		});
		StringBuilder sb = new StringBuilder();
		sb.append(list.size()).append("\n");
		for (Point p : list) {
			sb.append(p.a).append(" ").append(p.b).append("\n");
		}
		System.out.print(sb);
	}
	
	static class Point {
		int a;
		int b;
		public Point(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}
}


Measured memory_bytes: 21844
#include <string>
#include <vector>
#include <iostream>
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> > A(H, vector<int>(W));
	for (int i = 0; i < H; ++i) {
		int pl = 0;
		for (int j = 0; j <= W; ++j) {
			if (j == W || S[i][j] == '#') {
				for (int k = pl; k < j; ++k) {
					A[i][k] += j - pl;
				}
				pl = j + 1;
			}
		}
	}
	for (int i = 0; i < W; ++i) {
		int pl = 0;
		for (int j = 0; j <= H; ++j) {
			if (j == H || S[j][i] == '#') {
				for (int k = pl; k < j; ++k) {
					A[k][i] += j - pl;
				}
				pl = j + 1;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (ans < A[i][j]) {
				ans = A[i][j];
			}
		}
	}
	cout << ans - 1 << endl;
	return 0;
}

Measured memory_bytes: 20224
#include <bits/stdc++.h>
using namespace std;
#define pf                  printf
#define sc                  scanf
#define pb                  push_back
#define eb                  emplace_back
#define present(c,x)        ((c).find(x) != (c).end())
#define mp                  make_pair
#define xx                  first
#define yy                  second
#define endl                '\n'
#define SZ(v)               ((int) (v).size())
#define all(v)              (v).begin(), (v).end()
typedef long long           ll;
typedef long double         LD;
typedef unsigned long long  ull;
typedef pair<int,int>       pii;
const LD EPS =              1e-9;
const LD PI=                acos(-1.0);
const int MX=               6e5+5;
ll mod=                     1e9+7;

int main()
{
	ll s;
	cin>>s;
	if(s<=1000000000LL){
		cout<<"0 0 "<<s<<" 0 0 1\n";

	}else{

		ll x3 = ceil(sqrt(s));
		ll y2 = x3 ? (s/x3 + (s%x3!=0)) : 0;
		ll y3 = x3*y2 - s,x2;
		if(y3==0){
			x2=y3=0;
		}else{
			x2 = 1;
		}


		cout<<"0 0 "<<x2<<" "<<y2<<" "<<x3<<" "<<y3<<endl;
	}
    return 0;
}

/**
						Md. Tariqul Islam
							IIT,JU
						  fb/tariqiitju
					  tarik.amtoly@gmail.com
*/

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(){
    ll h, w, d;
    cin >> h >> w >> d;
    vector<vector<ll>> g(h*w+1);
    map<ll, p> I{};
    for(ll i = 0; i < h; i++){
        for(ll j = 0; j < w; j++){
            ll a;
            cin >> a;
            I[a] = p(i,j);
        }
    }
    vector<vector<ll>> sum(d+1);
    for(ll i = 1; i <= d; i++){
        sum[i].push_back(0);
        for(ll j = i+d; j <= h*w; j+=d){
            ll c = abs(I[j].first-I[j-d].first)+abs(I[j].second-I[j-d].second)+sum[i][sum[i].size()-1];
            sum[i].push_back(c);
        }
    }
    ll q;
    cin >> q;
    vector<ll> ans;
    for(ll i = 0; i < q; i++){
        ll check = 0;
        ll l, r;
        cin >> l >> r;
        if(l<d) check = sum[l][(r/d)]-sum[l][(l/d)];
        else if(l>=d && l%d==0)
            check = sum[d][r/d-1]-sum[d][l/d-1];
        else if(l>=d && l%d!=0)
            check = sum[l%d][r/d]-sum[l%d][l/d];
        ans.push_back(check);
    }
    for(ll i = 0; i < ans.size(); i++)
        cout << ans[i] << endl;
    /*for(ll i = 1; i <= d; i++){
        for(ll j = 0; j <sum[i].size(); j++){
            cout << sum[i][j] << " ";
        }
        cout << endl;
    }*/
    return 0;
}


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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long ans;
    if ((b-a)%2 == 0) ans = (b-a)/2;
    else {
        ans = min(a-1, n-b) + 1 + (b-a)/2;
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int>c(n-1);
  vector<int>s(n-1);
  vector<int>f(n-1);
  rep(i,0,n-1) cin >> c[i] >> s[i] >> f[i];
  rep(i,0,n){
    int t = 0;
    rep(j,i,n-1){
      if(t < s[j]) t = s[j];
      else if(t%f[j] == 0);
      else t = t+f[j]-t%f[j];
      t += c[j];
    }
    cout << t << endl;
  }
}

Measured memory_bytes: 3656
import Data.Array.IO
import Control.Applicative
import Data.List
import Control.Monad

getLineN :: Int -> IO [String]
getLineN n = replicateM n getLine

getNum = read <$> getLine :: IO Int
getNumList = map read.words <$> getLine :: IO [Int]

main = do
    xs <- getNumList
    k <- getNum
    let v = maximum xs
    putStrLn.show $ v*2^k + sum (delete v xs)

Measured memory_bytes: 508
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;

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

	int index = 0;
	vector<int> input(2, 1);
	do{
		cin >> input[index] >> input[index + 1];
		if (input[index] == 0 && input[index + 1] == 0)
			break;
		if (input[index] < input[index + 1]){
			cout << input[index] << " " << input[index + 1] << "\n";
		}
		else{
			cout << input[index + 1] << " " << input[index] << "\n";
		}
		input.push_back(1);
		input.push_back(1);
		index += 2;
	} while (input[index - 2] != 0 || input[index - 1] != 0);

	return 0;
}


Measured memory_bytes: 3148
#include<iostream>

long int fac(int x) {
	if (x == 1) return 1;
	return x * fac(x - 1);
}

int main() {
	long int input;
	while (std::cin >> input) {
		std::cout << fac(input) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int p=n%10;
	if(p==3)
	cout<<"bon"<<endl;
	else if(p==0||p==1||p==6||p==8)
	cout<<"pon"<<endl;
	else
	cout<<"hon"<<endl;	
	
	
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <cstring>
#include <ctype.h>
#include<stdlib.h>

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)      memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std;

int main()
{
	fastio;
	int n,d;
	cin>>n>>d;

	int c=0,x,y;

	for(int i=0; i<n; i++)
	{
		cin>>x>>y;
		double s=sqrt((1.0*x*x) + (1.0*y*y));
		if(s<=d)
			c++;
	}
	
	cout<<c; 

    
}


Measured memory_bytes: 3696
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int k = 0;
    cin >> k;
    int curr = 7;
    int res = 1;
    if(__gcd(k, 10) != 1){
        cout << -1 << "\n";
        return;
    }
    while(1){
        if(curr % k == 0){
            break;
        }
        curr = (((curr * 10) % k) + 7) % k;
        res++;
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
n=int(input())
a = list(map(int,input().split()))
even=[el for el in a if el % 2==0]
try:
  for a in even:
    if a % 3 == 0 or a % 5 == 0:
      flg = 1
    else:
      raise
except:
  print('DENIED')
else:
  print('APPROVED')

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

int main() {
  ll N,K;
  cin >> N >> K;
  set<ll> set;
  rep(i,K){
    ll a;
    cin >> a;
    for(ll b = 0; b < a; b++){
      ll c[b];
      cin >> c[b];  
      set.insert(c[b]);
    }
  }
  cout << N - set.size();
}

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

int main()
{
    string s;
    cin >> s;
    long long ans = 0;
    for (int i = s.size() - 1; i >= 0; i--)
    {
        if (i == 0)
        {
            ans += min(s[i] - '0', 11 - (s[i] - '0'));
            break;
        }
        if (s[i] > '9')
        {
            s[i] = '0';
            s[i - 1]++;
        }
        if (s[i] == '5')
        {
            if (s[i - 1] > '4') s[i - 1]++;
        }
        if (s[i] > '5') 
        {
            s[i - 1]++;
        }
        ans += min(s[i] - '0', 10 - (s[i] - '0'));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1412
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

macro_rules! read {
    ([$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ([$t:ident]) =>
        (rl().split_whitespace().map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    (_, [$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!(_, [$t])).collect::<Vec<_>>());
    (_, [$t:ident]) =>
        (rl().split_whitespace().skip(1).map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    ($($t:ident),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ($t:ident) => (read_type!(rl(), $t));
    ($($t:ident),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(read_type!(w.next().unwrap(), $t)),*)
    }};
}

macro_rules! read_type {
    ($s:expr, chars) => {
        $s.chars().collect::<Vec<char>>()
    };
    ($s:expr, usize1) => {
        read_type!($s, usize) - 1
    };
    ($s:expr, $t:ty) => {
        $s.parse::<$t>().unwrap()
    };
}

fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

////////////////////////////////////////////////////////////////////////////////

fn main() {
    let s = read!(chars);
    let ans = s.iter().filter(|&&c| c == 'o').count() + 15 - s.len() >= 8;
    println!("{}", if ans { "YES" } else { "NO" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	vector<int> a(n+1);
	int cnt=0,x;
	rep(i,n){
		cin >> x;
		a[x]++;
	}
	rep(i,n+1){
		if(a[i]) cnt++;
	}
	cnt-=k;
	if(cnt<=0){
		cout << 0 << endl;
		return 0;
	}
	int ans=0;
	sort(a.begin(),a.end());
	rep(i,n+1){
		if(cnt==0) break;
		if(a[i]){
			cnt--;
			ans+=a[i];
		}
	}
	cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    string S;
    cin >> S;

    int k = S.size() / 2;
    int c = S[k];
    int l = -1;
    int r = 0;
    int len = 0;
    if (S.size() % 2) l = 0;
    while (k + l >= 0 && S[k + l] == c && S[k + r] == c) {
//        cout << k + l << ":" << k + r << endl;
        l--;
        r++;
        len++;
    }

    cout << k + len << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

int check(char c) {
    return ((c == '<') ? 1 : 0); 
}

int main()
{
    string S;
    cin >> S;
    ll len = (ll)S.size();
    vector<ll> cnt(len);

    ll ans = 1;
    cnt[0] = 1;
    repd(i, 1, len) {
        if (S[i] == S[i - 1]) {
            cnt[i] = cnt[i - 1] + 1;
        }
        else {
            cnt[i] = 1;
        }
        ans += cnt[i];
    }
    ll tmp = cnt[len - 1];
    for (ll i = len - 1; i > 0; i--) {
        if (cnt[i] != 1) {
            cnt[i] = tmp;
        }
        else {
            cnt[i] = tmp;
            tmp = cnt[i - 1];
        }
    }

    //rep(i, len) cout << cnt[i] << endl;

    rep(i, len - 1) {
        if (S[i] == '<' && S[i + 1] == '>') {
            ans -= min(cnt[i], cnt[i + 1]);
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
const int maxn=1e5+10;
int n,g[maxn],cnt[4];
pair<int,int> a[maxn<<1];
ll ans;

int main(){
	cin>>n;
	for(int i=1,x,y;i<=n;++i){
		cin>>x>>y;
		a[i*2-1]=make_pair(x,i);
		a[i*2]=make_pair(y,-i);
	}
	sort(a+1,a+2*n+1);
	for(int i=1;i<=n;++i){
		if(a[i].second<0)
			g[-a[i].second]|=1;
		else
			g[a[i].second]|=2;
		ans+=a[i].first;
	}
	for(int i=1;i<=n;++i)
		++cnt[g[i]];
	if(cnt[0]||!cnt[1]||!cnt[2]){
		printf("%lld\n",ans);
		return 0;
	}
	if(abs(a[n].second)==abs(a[n+1].second)&&cnt[a[n].second<0?1:2]>1)
		printf("%lld\n",ans+min(a[n+2].first-a[n].first,a[n+1].first-a[n-1].first));
	else
		printf("%lld\n",ans-a[n].first+a[n+1].first);
	return 0;
}

Measured memory_bytes: 2176
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v)
    is >> x;
  return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  cin >> s;
  for (char &c : s)
    if (c == '?')
      c = 'D';
  cout << s << '\n';

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 3744
/*
[abc117] D - XXOR
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MAX_D = 40;

template <typename T>
void chmax(T &x, T v) {
    x = max(x, v);
}

int N;
ll K;
ll A[MAX_N];
int cnt[MAX_D];
ll dp[MAX_D + 1][2];

ll solve() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < MAX_D; j++) {
            if ((A[i] >> j) & 1LL) {
                cnt[j]++;
            }
        }
    }

    memset(dp, -1, sizeof(dp));
    dp[MAX_D][0] = 0;
    for (int j = MAX_D - 1; j >= 0; j--) {
        for (int smaller = 0; smaller < 2; smaller++) {
            if (dp[j + 1][smaller] == -1) {
                continue;
            }
            for (int i = 0; i <= (smaller ? 1 : ((K >> j) & 1LL)); i++) {
                chmax(dp[j][smaller || i < ((K >> j) & 1LL)],
                      dp[j + 1][smaller] +
                          (1LL << j) * (i ? (N - cnt[j]) : cnt[j]));
            }
        }
    }
    ll ans = max(dp[0][0], dp[0][1]);

    return ans;
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static string S,T;
    static void INPUT()
    {
        S = NextString();
        T = NextString();
    }

    static void OUT()
    {
        var dp = new int[S.Length + 1, T.Length + 1];
        for (int i = 1; i <= S.Length; i++)
        {
            for (int j = 1; j <= T.Length; j++)
            {
                if (S[i - 1] == T[j - 1])
                    dp[i, j] = dp[i - 1, j - 1] + 1;
                else
                    dp[i, j] = Math.Max(dp[i - 1, j], dp[i, j - 1]);
            }
        }

        var st = new Stack<char>();
        var sb = new StringBuilder();
        {
            var i = S.Length;
            var j = T.Length;
            while (i > 0 && j > 0)
            {
                if (dp[i, j] == dp[i - 1, j])
                {
                    --i;
                }

                else if (dp[i, j] == dp[i, j - 1])
                {
                    --j; 
                }

                else
                {
                    st.Push(S[i - 1]);
                    --i;
                    --j; 
                }
            }
        }

        while(st.Count > 0)
        {
            sb.Append(st.Pop());
        }
        Console.WriteLine(sb.ToString());
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 46304
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*a = map(int, read().split())



L = [0]*(n+1)
R = [0]*(n+1)
l = r = a[n]
L[n] = R[n] = 0


ok = 1
for i in range(n-1,-1,-1):
    ai = a[i]
    l = (l+1)//2
    r = min(r,1<<i)
    if i <= 60:
        if l+ai > 1<<i:
            ok = 0
            break
        else:
            r = min(r,(1<<i)-ai)
    L[i] = l
    R[i] = r
    l += ai
    r += ai

        
if not ok or n==0 and a[0]!=1:
    print(-1)
else:
    #print(L,R)
    ans = living = R[0]
    ans += a[0]

    for i in range(1,n+1):
        living *= 2
        living -= a[i]

        #print(living,a[i],R[i])
        
        living = min(living,R[i])
        
        ans += living + a[i]        
        
        #print(living,R[i])

    print(ans)        
        
        
        


    










Measured memory_bytes: 22324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int N, M;
    cin >> N;
    vector<int> T(N);
    rep(i, N)
    {
        cin >> T[i];
    }
    cin >> M;
    vector<int> P(M), X(M);
    rep(i, M)
    {
        cin >> P[i] >> X[i];
    }
    int sum = 0;
    rep(i, M)
    {
        sum = 0;
        rep(j, N)
        {
            if (j + 1 == P[i])
            {
                sum += X[i];
            }
            else
            {
                sum += T[j];
            }
        }
        cout << sum << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256