akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  auto v = in(vector<int>(6));
  string s;
  cin >> s;
  int top = 1, f = 2, r = 3; // Dice state (top, f, r)
  for (auto &c : s) {
    int tmp;
    switch (c) {
      case 'E': tmp = r, r = top, top = 7 - tmp; break;
      case 'W': tmp = top, top = r, r = 7 - tmp; break;
      case 'S': tmp = f, f = top, top = 7 - tmp; break;
      case 'N': tmp = top, top = f, f = 7 - tmp; break;
    }
  }
  cout << v[top - 1] << endl;
}



Measured memory_bytes: 3228
import java.util.*;
public class Main{
	static int gcd(int p,int q){
		while((p%q)!=0){
			int r=p%q;
			p=q;
			q=r;
		}
		return q;
	}
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int k=sc.nextInt();
  	int sum=0;
  	for(int a=1;a<=k;a++){
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	}
  	System.out.print(sum);
  }
}

Measured memory_bytes: 35816
#include <bits/stdc++.h>
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> multi_vector(size_t a){return vector<T>(a);}template<class T, class... Ts>auto multi_vector(size_t a, Ts... ts){return vector<decltype(multi_vector<T>(ts...))>(a, multi_vector<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}

/* ここからコード開始 */

int main(){
  kyopro;
  ll L, R;
  cin >> L >> R;
  if(R - L > 2019) cout << 0 << rt;
  else{
    vector<ll> ok;
    ll ex3{}, ex673{};
    rep(i, L, R+1){
      ok.push_back(i%2019);
    }
    ll ans{MOD};
    rep(i, 0, R-L+1){
      rep(j, i+1, R-L+1){
        ans = min(ok[i]*ok[j]%2019, ans);
      }
    }
    cout << ans << rt;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;
typedef int64_t LL;

int main(){
	int n;
	cin >> n;
	vector<int> ps;
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		int p;
		cin >> p;
		ps.push_back(p);
		sum += p;
	}
	sort(ps.rbegin(), ps.rend());
	sum -= ps[0] / 2;
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>

#define lli long long int

int main(void)
{
	lli n;
	scanf("%lld",&n);
	lli *h;
	h = (lli *)malloc(sizeof(lli)*(n));
	lli i = 0;
	while(i < n)
	{
		scanf("%lld",&h[i]);
		i++;
	}
	i = n-1;
	lli avl = 0;
	while(i > 0)
	{
		if(h[i] >= h[i-1])
		{
			i--;
			continue;
		}
		else if(h[i] == h[i-1]-1)
		{
			h[i-1]--;
			i--;
			continue;
		}
		else
		{
			avl = 1;
			break;
		}
	}
	if (avl == 1)
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}
	return(0);
}



Measured memory_bytes: 896
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define elif else if

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pll=pair<ll,ll>;
using pss=pair<string,string>;
using pdd=pair<ld,ld>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-9;

template<class T> void chmin(T &a, T b){a=min(a, b);}
template<class T> void chmax(T &a, T b){a=max(a, b);}

ll abs1(ll a){if(a>=0)return a;else return -a;}
ll pow1(ll a,ll b,ll p=LLONG_MAX){ll ret=1;while(b!=0){if((b&1)==1)ret*=a;a*=a;if(a>=p)a%=p;if(ret>=p)ret%=p;b=b>>1;}return ret;}
int digit(ll a,ll b=10){int i=0;while(a!=0){a/=b;i++;}return i;}
ll gcd1(ll a,ll b){if(a==0 || b==0)return 0;ll n;while(a%b!=0){n=a%b;a=b;b=n;}return b;}
ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;ll a[100],b[100];a[0]=n;b[0]=m;int i=1;
  while(b[i-1]!=0){a[i]=b[i-1];b[i]=a[i-1]%b[i-1];i++;}n=i;if(c%a[n-1]!=0)return 0;ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){ll cnt=x;x=y;y=cnt-(a[n-i-1]/b[n-i-1])*y;}return x;
}
ll modInv(ll a,ll p=MOD){a%=p;ll n=solveLinear(a,p,1);n%=p;if(n<0)return n+p;return n;}
ll fact(ll n,ll p=MOD){if(n<0)return 0;ll ret=1;for(int i=1;i<=n;i++){ret=ret*i;if(ret>=p)ret%=p;}return ret;}
ll perm(ll n,ll k,ll p=MOD){if(n<0 || k<0 || n<k)return 0;ll ret=1;rep(i,k){ret=ret*(n-i);if(ret>=p)ret%=p;}return ret;}
ll binom(ll n,ll k,ll p=MOD){return (perm(n,k,p)*modInv(fact(k)))%p;}

int main(){
  ll i,j,cnt=0;
  ll n,k,s;
  cin>>n>>k>>s;
  if(s==1e9){
      for(i=0;i<k;i++){
          if(i==k-1)cout<<s;
          else cout<<s<<" ";
      }
      for(i=0;i<n-k;i++){
          if(i==0 && k==0)cout<<s-1;
          else cout<<" "<<s-1;
      }
  }
  else{
      for(i=0;i<k;i++){
          if(i==k-1)cout<<s;
          else cout<<s<<" ";
      }
      for(i=0;i<n-k;i++){
          if(i==0 && k==0)cout<<s-1;
          else cout<<" "<<s+1;
      }
  }
}


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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	long S;
	cin >>S;
	/*
	long x1, y1, x2, y2;
	x2=1;
	y2=1000000000;
	*/
	long x, y;
	x=S/1000000000;
	y=S%1000000000;
	if (0!=y) {
		x++;
		y=1000000000-y;
	}
	cout <<"0 0 1 1000000000 " <<x <<' ' <<y <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define all(x) (x).begin(),(x).end()

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

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

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

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    ll n,k,g,Max;
    cin >> n >> k >> g;
    Max = g;
    rep0(i, n - 1){
        ll a;
        cin >> a;
        Max = max(Max, a);
        g = gcd(g, a);
    }
    if(k % g == 0 && k <= Max)pf("POSSIBLE")
        else pf("IMPOSSIBLE")
    return 0;
}


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

using namespace std;

#define pii pair<int,int>
#define xx first
#define yy second
#define mp make_pair

const int maxn = 100005;

int tree[maxn*4];

void update( int cn, int s, int e, int x, int v )
{
    if(s==e)
    {
        tree[cn] = v;
        return;
    }
    int m = (s+e)/2, l = cn*2;
    if( x <= m ) update( l, s, m, x, v );
    else update(l+1, m+1, e, x, v);
    tree[cn] = max( tree[l], tree[l+1] );
}

int query( int cn, int s, int e, int x, int y )
{
    if( e < x || s > y ) return 0;
    if( s >= x && e <= y ) return tree[cn];

    int m = (s+e)/2, l = cn*2;

    return max(query( l, s, m, x, y ), query( l+1, m+1, e, x, y ));
}

pii ara[maxn];
map<int,int>mm;

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

    for( int i = 1; i <= n; i++ )
    {
        cin >> ara[i].xx;
        ara[i].yy = -i;
        mm[ ara[i].xx ];
    }
    int cnt = 1;
    for( auto it = mm.begin(); it != mm.end(); it++ )
    {
        it->yy = cnt++;
    }

    for( int i = 1; i <= n; i++  )
    {
        ara[i].xx = mm[ ara[i].xx ];
    }
    sort( ara+1, ara+n+1 );
    int ans = 1;
    for( int i = 1; i <= n; i++ )
    {
        int ind = -ara[i].yy;
        //cout << ind << endl;
        int a = query(1, 1, n, ind+1, n );
        ans = max( ans, a+1 );
        update( 1,1,n, ind, a+1 );
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 6656
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

#define FOR(i, l, r) for (i = (l); i < r; i++ )

using namespace std;
typedef long long ll;

#define MAX_N (100010)

int n;
int A[MAX_N];

// [p, r]
int partition(int A[], int p, int r) {
    int x = A[r];		// pivot
    int i = p - 1;
    int j;
    FOR(j, p, r) {
	if (A[j] <= x) {
	    i++;
	    swap(A[i], A[j]);
	}
    }
    swap(A[i+1], A[r]);

    return i + 1;
}

int main()
{
    int i;
    scanf("%d", &n);
    FOR(i, 0, n) scanf("%d", &A[i]);

    int ans = partition(A, 0, n-1);

    FOR(i, 0, n) {
	if (i == ans) printf("[");
	printf("%d", A[i]);
	if (i == ans) printf("]");
	printf("%c", (i == n-1) ? '\n' : ' ');
    }

    return 0;
}

Measured memory_bytes: 3516
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();

		// ??\?????????????????????char????????????
		char [] sentence = input.toCharArray();

		for(int cnt=0; cnt< sentence.length; cnt++){

			if (Character.isUpperCase(sentence[cnt])){

				sentence[cnt] = Character.toLowerCase(sentence[cnt]);

			}else{

				sentence[cnt]=Character.toUpperCase(sentence[cnt]);

			}
		}

		sc.close();

		String output = String.valueOf(sentence);
		System.out.println(output);

	}
}

Measured memory_bytes: 26040
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int t){
    if(t==0)return s;
    return gcd(t,s%t);
}
signed main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    rep(i,s.size()){
        if(s[i]!=t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3916
# https://beta.atcoder.jp/contests/agc014/submissions/1268295
from collections import deque

dr = (0, 1, 0, -1)
dc = (1, 0, -1, 0)


def solve():
    H, W, K = map(int, input().split())
    a = [[False for _ in range(W)] for _ in range(H)]

    sy, sx = -1, -1
    for r in range(H):
        s = input()
        for c, x in enumerate(s):
            if x == '.':
                a[r][c] = True
            elif x == 'S':
                a[r][c] = True
                sy, sx = r, c

    visited = [[False for _ in range(W)] for _ in range(H)]
    visited[sy][sx] = True

    t = max(H, W)
    q = deque([(sy, sx, 0)])
    while q:
        r, c, k = q.popleft()

        t = min(t, r, H - 1 - r, c, W - 1 - c)
        # print(t)
        if t == 0:
            print(1)
            return

        for d_i in range(4):
            nr, nc = r + dr[d_i], c + dc[d_i]
            if 0 <= nr < H and 0 <= nc < W and a[nr][nc] and not visited[nr][nc] and k + 1 <= K:
                visited[nr][nc] = True
                q.append((nr, nc, k + 1))

    ans = 1 + (t + K - 1) // K

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 14444
#include <iostream>

 

using namespace std;

 

int main()
{
    int a ,b, c, i;
    for(i=1; i<=3000; i++)
    {
        cin >> a >> b;
        if(a == 0 && b == 0)
            break;

        if ( a > b)
        {
            c = a;
            a = b;
            b = c;
        }
       cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 3076
#include <stdio.h>
#include <vector>

using namespace std;

int main(void){
	int i, N, n, d, xmin, ymin, xmax, ymax;
	const int dx[4] = {-1,0,1,0}, dy[4] = {0,1,0,-1};
	vector<int> x, y;
	while(1){
		scanf("%d",&N);
		if(N == 0)
			break;
		x.push_back(1),y.push_back(1);
		x.at(0) = y.at(0) = 0;
		for(i = 1;i < N;i++){
			scanf("%d%d",&n,&d);
			x.push_back(1),y.push_back(1);
			x.at(i) = x.at(n) + dx[d];
			y.at(i) = y.at(n) + dy[d];
		}
		xmin = ymin = 0x7FFFFFFF;
		xmax = ymax = 0x80000000;
		for(i = 0;i < N;i++){
			xmax = max(xmax,x.at(i) + 1);
			ymax = max(ymax,y.at(i) + 1);
			xmin = min(xmin,x.at(i));
			ymin = min(ymin,y.at(i));
		}
		printf("%d %d\n",xmax - xmin,ymax - ymin);
		while(x.size()){
			x.pop_back();
			y.pop_back();
		}
	}
	return 0;
}

Measured memory_bytes: 1052
n,k=map(int,input().split())
a=list(input().split())
p = [0]*200000
q = [0]*200000
p[0]=1
p[1]=int(a[0])
q[0]=1
q[p[1]-1]=2
f=0
for i in range(k-1):
    p[i+2]=int(a[p[i+1]-1])
    if q[p[i+2]-1]>0:
        r=q[p[i+2]-1]-1
        q=i+2-r
        f=1
        l=k-r
        l%=q
        s=p[r+l]
        break
    if f==1:
        break
    q[p[i+2]-1]=i+3
if f==0:    
    print(p[k])
else:
    print(s)

Measured memory_bytes: 36324
N=int(input());A=[-1]*N;B=[-1]*N
for i in range(N):A[i],B[i]=map(int,input().split())
ans=min(sum(A),sum(B));t=[(A[i],i) for i in range(N)]+[(B[i],i) for i in range(N)];t.sort();d=[0]*N
for i in range(N):d[t[i][1]]+=1
S=sum(t[i][0] for i in range(N))
if max(d)==2:
    print(S)
else:
    ans2=min(S+max(A[i],B[i])-t[N-1-(t[N-1][1]==i)][0] for i in range(N))
    print(min(ans,ans2))

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

int main(){

  int N;
  int h,ho = 0,ans = 0;
  cin >> N;

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

    cin >> h;

    if (h > ho){
      ans += h - ho;
    }

    ho = h;
  }

  cout << ans << endl;
    
  return 0;

}


Measured memory_bytes: 256
N = int(input())

food_array = []
for i in range(3):
    food_array.append(list(map(int, input().split())))
#print(food_array)

A = food_array[0]
B = food_array[1]
C = food_array[2]

index = -1
count = 0
for i in A:
    count += B[i - 1]
    #print(index, i)
    if index + 1 == i:
        count += C[index - 1]
    index = i
print(count)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            for(int i = 0;i < H;i++){
               for(int j = 0; j < W;j++) {
                    System.out.print("#");
               }
                System.out.println();
            }System.out.println();
        }
    }
}


Measured memory_bytes: 34680
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;


int main() {
	
	int n, w;
	cin >> n >> w;
	string p;
	vector<string>m;
	for (int i = 0; i < n; i++) {
		cin >> p;
		m.push_back(p);
		m.push_back(p);

	}
	for (int i = 0; i < m.size(); i++)
		cout << m[i] << endl;
	

	return 0;

}




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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m);
    REP(i, n) cin >> x[i];
    REP(i, m) cin >> y[i];

    sort(all(x));
    sort(all(y));

    if(x[n-1] < y[0] && X < x[n-1] && y[0] <= Y) cout << "No War" << endl;
    else cout << "War" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if ( T[u].p == NIL ) cout << "root, ";
  else if ( T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for (  i = 0, c = T[u].l; c != NIL; i++, c = T[c].r ) {
    if ( i ) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

// 再帰的に深さを求める
void rec(int u, int p) {
  D[u] = p;
  if ( T[u].r != NIL ) rec(T[u].r, p);  // 右の兄弟に同じ深さを設定
  if ( T[u].l != NIL ) rec(T[u].l, p + 1);  // 最も左の子に自分の深さ+1を設定
}

int main() {
  int i, j, d, v, c, l, r;
  cin >> n;
  for ( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;

  for ( i = 0; i < n; i++ ) {
    cin >> v >> d;
    for ( j = 0; j < d; j++ ) {
      cin >> c;
      if ( j == 0 ) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for ( i = 0; i < n; i++ )
    if ( T[i].p == NIL ) r = i;

  rec(r, 0);

  for ( i = 0; i < n; i++ ) print(i);

  return 0;
}


Measured memory_bytes: 7764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    bool res = true;
    string s;
    cin >> s;
    rep(i,s.size()-1){
        if (s[i] == s[i+1]){
            res = false;
        }
    }
    if (res) cout << "Good" << endl;
    else cout << "Bad" << endl;
}


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

using namespace std;

const int MaxN = 3e5 + 15;
const int MOD = 998244353;
const long long INF = 1e18;

int f[MaxN], rf[MaxN];

int n, a, b;

long long k;

int bpow(int a, int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = (res * 1ll * a) % MOD;

        a = (a * 1ll * a) % MOD;

        b >>= 1;
    }

    return res;
}

int cnk(int n, int k)
{
    int a = f[n];
    int b = (rf[k] * 1ll * rf[n - k]) % MOD;

    return (a * 1ll * b) % MOD;
}

int main()
{
//    freopen("output.txt", "r", stdin);

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    f[0] = f[1] = rf[0] = rf[1] = 1;

    for(int i = 2; i < MaxN; ++i)
    {
        f[i] = (f[i - 1] * 1ll * i) % MOD;
        rf[i] = bpow(f[i], MOD - 2);
    }

    cin >> n >> a >> b >> k;

    int ans = 0;

    for(int k1 = 0; k1 <= n; ++k1)
    {
        long long l = k - k1 * 1ll * a;

        if(l >= 0 && l % b == 0 && l / b <= n)
        {
            l /= b;

            ans += (cnk(n, k1) * 1ll * cnk(n, l)) % MOD;
            if(ans >= MOD)
                ans -= MOD;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

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

		int b,f,r,v;
		int[][][] room = new int[4][3][10]; //b-1,f-1,r-1
		for(int i=0;i<4;i++){
			for(int j=0;j<3;j++){
				for(int t=0;t<10;t++){
					room[i][j][t]=0;
				}
			}
		}

		Scanner sc = new Scanner(System.in);
		int n =Integer.parseInt(sc.nextLine());
		for(int i=0;i<n;i++){
			String[] line=sc.nextLine().split(" ");
			b=Integer.parseInt(line[0])-1;
			f=Integer.parseInt(line[1])-1;
			r=Integer.parseInt(line[2])-1;
			v=Integer.parseInt(line[3]);
			room[b][f][r]=room[b][f][r]+v;
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<3;j++){
				for(int t=0;t<10;t++){
					System.out.print(" "+room[i][j][t]);
				}
				System.out.println();
			}
			if(!(i==3)){
				System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;cin >> N;
    int L[100];
    for(int i=0;i<N;i++){
        cin >> L[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(L[i]!=L[j]){
                for(int k=j+1;k<N;k++){
                    if(L[i]!=L[k]&&L[j]!=L[k]&&abs(L[i]-L[j])<L[k]&&L[k]<L[i]+L[j]){
                        ans++;
                    }
                }
            }
            
        }
    }
    cout << ans;
}

Measured memory_bytes: 3624
N = int(input())
S = list(input())
S = [int(s) for s in S]

left = [[0]*10 for _ in range(N)]
right = [[0]*10 for _ in range(N+1)]

ans = [0]*1000 #ans[000]~[999]=Bool

for i,s in enumerate(S):
  for j in range(10):
    left[i][j] = left[i-1][j]
  left[i][s] = 1
  
for i,s in enumerate(S[::-1]):
  for j in range(10):
    right[N-i-1][j] = right[N-i][j]
  right[N-i-1][s] = 1
  
for i,s in enumerate(S):
  if 0<i<N-1:
    for l in range(10):
      for r in range(10):
        if left[i-1][l] and right[i+1][r]:
          #print(100*l+10*s+r)
          ans[100*l+10*s+r]=1
          
print(sum(ans))

Measured memory_bytes: 15260
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int buff1 = 0,buff2 = 0;

		buff1 = Integer.parseInt(s.substring(0,1));
		if(buff1>=1) {
			buff1 = Integer.parseInt(s.substring(0,2));
		}else {
			buff1 += Integer.parseInt(s.substring(1,2));
		}

		buff2 = Integer.parseInt(s.substring(2,3));
		if(buff2>=1) {
			buff2 = Integer.parseInt(s.substring(2,4));
		}else {
			buff2 += Integer.parseInt(s.substring(3,4));
		}

		if(buff1>0 && buff1<=12) {
			if(buff2>0 && buff2<=12) {
				System.out.println("AMBIGUOUS");
			}else {
				System.out.println("MMYY");
			}
		}else if(buff2>0 && buff2<=12) {
			System.out.println("YYMM");
		}else {
			System.out.println("NA");
		}
	}
}




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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll W, a, b;
    cin >> W >> a >> b;
    if (a + W < b)
        cout << b - (a + W) << endl;
    else if (b + W < a)
        cout << a - (b + W) << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> x({a,b,c});
    int k;
    cin >> k;

    sort(x.begin(),x.end());
    x[2]<<=k;

    cout << x[0]+x[1]+x[2] << endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a,b=a-1,b-1
        tree[a].append(b)
        tree[b].append(a)
    e = [0]
    while len(e) > 0:
        i = e.pop()
        for j in tree[i]:
            tree[j].remove(i)
            e.append(j)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        score[p]+=x
    add(tree,score)
    print(*score)

def add(tree,score):
    s=tree[0][:]
    for i in s:
        score[i] += score[0]
    while len(s)>0:
        t = s.pop()
        for i in tree[t]:
            s.append(i)
            score[i] += score[t]

if __name__ == "__main__":
    main()

Measured memory_bytes: 117976
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
string s;

struct Diff_vec1 {
	int x_diff;
	int y_diff;
};


typedef struct {
	int first;
	int second;
}Ball_pair;

using MIte = multimap<vector<long>, Ball_pair>::iterator;

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

	vector<long> vx(N, 0);
	vector<long> vy(N, 0);
	for (int i = 0; i != N; ++i) {
		long x = 0;
		long y = 0;
		cin >> x >> y;

		vx[i] = x;
		vy[i] = y;
	}

	multimap<vector<long>, Ball_pair> mp;
	multimap<vector<long>, int> mp2;
	for (int i = 0; i != N; ++i) {
		for (int j = 0; j != N; ++j) {
			if (i == j) continue;
			vector<long> diff(2, 0);
			Ball_pair tmppair;

			diff[0] = (vx[j] - vx[i]);
			diff[1] = (vy[j] - vy[i]);

			tmppair.first = i;
			tmppair.second = j;

			mp.insert(make_pair(diff, tmppair));

			multimap<vector<long>, int>::iterator mapit = mp2.find(diff);
			if (mapit == mp2.end()) {
				mp2.insert(make_pair(diff, 1));
			}
			else {
				mapit->second++;
			}
		}
	}

	if (mp.empty()) {
		cout << N << endl;
	}
	else {
		int maxedge = 0;
		for (multimap<vector<long>, int>::iterator mapit = mp2.begin(); mapit != mp2.end(); ++mapit) {
			if (maxedge < mapit->second){
				maxedge = mapit->second;
			}
		}
		cout << N - maxedge << endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int dp[200004][2];
string s;
char c[2]={'P','D'};
void GO(int x,int now){
	if(x==0)return;
	if(now==0){
		if(dp[x][0]==dp[x-1][0])GO(x-1,0);
		else GO(x-1,1);
	}
	else{
		if(dp[x][1]==dp[x-1][1]+1)GO(x-1,1);
		else GO(x-1,0);
	}
	cout<<c[now];
}
int main(){
	cin>>s;s="*"+s;
	dp[0][0]=-1e9;
	dp[0][1]=0;
	for(int i=1;i<s.size();i++){
		if(s[i]!='D')dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
		else dp[i][0]=-1e9;
		if(s[i]!='P')dp[i][1]=max(dp[i-1][1]+1,dp[i-1][0]+2);
		else dp[i][1]=-1e9;
	}
	if(dp[s.size()-1][0]>dp[s.size()-1][1])GO(s.size()-1,0);
	else GO(s.size()-1,1);
}

Measured memory_bytes: 11564
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 100005
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 9223372036854775807
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

signed main() 
{
    speed;
    //freopen("input.tXt","r",stdin);
    //freopen("output.tXt","w",stdout);

    int n;
    cin>>n;
    int A[n+1],B[n+1],C[n+1];
    int dp[n+1][3];
    dp[0][0]=dp[0][1]=dp[0][2]=0;
    for(int i=1;i<=n;i++) 
    {
        cin>>A[i]>>B[i]>>C[i];
        dp[i][0]=max(dp[i-1][1]+A[i],dp[i-1][2]+A[i]);
        dp[i][1]=max(dp[i-1][0]+B[i],dp[i-1][2]+B[i]);
        dp[i][2]=max(dp[i-1][0]+C[i],dp[i-1][1]+C[i]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}   

Measured memory_bytes: 8296
#include<bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
//using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

ll powmod(ll a,ll n,ll m) {
    if(n == 0)
        return 1;

    if(n % 2 ==0){
        ll r = powmod(a,n/2,m);
        return r*r % m;
    }

    return a*powmod(a,n-1,m)%m;
}

ll factmod(ll a,ll b,ll m) {
  if(a<b)return 0;
  ll s=1;
  while(a>=b){
    s = s*a % m;
    a -= 1;
  }
  return s;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll combmod(ll a,ll b,ll m){
  if(b==0)return 1;
  ll c=factmod(a,a-b+1,m);
  ll d=modinv(factmod(b,1,m),m);
  ll e=(c*d)%m;
  return e;
}

void modsum(ll &a,ll b,ll m){
  a+=b;
  a%=m;
}

void modsub(ll &a,ll b,ll m){
  a-=b;
  a+=m;
  a%=m;
}

void modmul(ll &a,ll b,ll m){
  a*=b;
  a%=m;
}

void modquo(ll &a,ll b,ll m){
  a*=modinv(b,m);
  a%=m;
}

int main(){

  ll s;
  cin >> s;
  ll m=s/3;
  ll ans=0;
  for(ll i=1;i<=m;i++){
    ll a=s-3*i;
    ll b=combmod(a+i-1,a,mod);
    modsum(ans,b,mod);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#define CO(a, b, c) ((a)?(b):(c))
#define mp(i, j) make_pair(i, j)
using namespace std;

int main(void)
{
	
	int n;
	cin >> n;
	int a;
	map<long, long> add{}, sub{};
	for (int i = 1; i < n + 1; i++)
	{
		cin >> a;
		auto pair = add.insert(mp(a+i, 0));
		(pair.first->second)++;
		pair = sub.insert(mp(i-a, 0));
		(pair.first->second)++;
	}
	
	long long count = 0;
	for (auto it = add.begin(); it != add.end(); it++)
	{
		auto f = sub.find(it->first);
		if (f != sub.end())
		{
			count += (it->second * f->second);
		}
	}
	cout << count << endl;
	
	return 0;
	
}

Measured memory_bytes: 26756
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string b[n];
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	int m;
	cin>>m;
	string r[m];
	for(int i=0;i<m;i++){
		cin>>r[i];
	}
	int a=0;
	for(int i=0;i<n;i++)
	{
	    string w=b[i];
	    int c=0;
	    for(int j=0;j<n;j++){
	    	if(b[j]==w)   c++;
	    }
	    for(int j=0;j<m;j++){
	    	if(r[j]==w)   c--;
	    }
	    a=max(a,c);
	}
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
	string S;
  	cin >> S;
  	int total = 700;
  	for(char s : S) if(s == 'o') total += 100;
	cout << total << endl;
    return 0;
}

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

int main() {
    int i, N = 0;
    cin >> N;
    vector<int> B(N-1);
    vector<int> A(N);

    rep(i, N-1) {
        cin >> B.at(i);
    }

    for (int i = 0; i < N-1; i++) {
        /* code */
        if (i==0) { A[i] = B.at(i); A[i+1] = B.at(i); }
        else if (i == N-2) { A[i] = min(B.at(i-1), B.at(i));A[i+1] = B.at(i); break;}
        else { A[i] = min(B.at(i-1), B.at(i)); }
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        /* code */
        ans += A.at(i);
    }
    
    printf("%d", ans);
}

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

enum ETetromino { I, O, T, J, L, S, Z };

int main() {
  vector<int> a(7); for (int i = 0; i < 7; ++i) cin >> a[i];

  ll K[2] = {};
  for (int i = 0; i < 2; ++i) {
    K[i] += a[O];
    K[i] += (a[I] && a[J] && a[L]) * i * 3;
    K[i] += (a[I] - i) / 2 * 2;
    K[i] += (a[J] - i) / 2 * 2;
    K[i] += (a[L] - i) / 2 * 2;
  }
  cout << max(K[0], K[1]) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n,k, tmp; cin >> n >> k;
    vector<int> a(n,0);
    set<int> s;
    rep(i,n) {
        cin >> tmp;
        tmp--;
        s.insert(tmp);
        a[tmp]++;
    }

    if (s.size() <= k) {
        cout << 0 << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    int ans = 0;
    rep(i,n-k) {
        ans += a[i];
    }
    cout << ans << endl;

    return 0;
}


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

class Mathfunc
{
    static public long gcd(long a,long b)
    {
        if(b==0)
        {
            return a;
        }
        return gcd(b,a%b);
    }
}

public class Main 
{
    public static void main(String args[])
    {
        Scanner s1=new Scanner(System.in);
        long x,y;
        x=s1.nextLong();
        y=s1.nextLong();
        long gcd1=Mathfunc.gcd(x,y);
        long ans=1;
        for(long i=2;i*i<=gcd1;i++)
        {
            if(gcd1%i==0)
            {
                ans++;
                while (gcd1%i==0)
                {
                    gcd1=gcd1/i;
                }
                
            }
        }
        if(gcd1!=1)
        {
            ans++;
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 21972
program b170

implicit none
integer :: x, y

read *, x, y

if (mod(y,2) == 1) then
 print *, 'No'
else if (y > x * 4) then
 print *, 'No'
else if (y < x * 2) then
 print *, 'No'
else
 print *, 'Yes'
end if

end program b170

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

using namespace std;

int ipow(int x,int y) {
	if(y==1) return x;
	if(y&1) return x*ipow(x*x,y>>1);
	return ipow(x*x,y>>1);
}

int main() {
	int N,M,K;
	while(cin >> N >> M >> K,N) {
		vector<vector<int> > dp(N+1,vector<int>(N*M+1));
		dp[0][0]=1;
		for(int i=0;i<N;++i)
			for(int j=i;j<=i*M;++j)
				for(int k=1;k<=M;++k)
					dp[i+1][j+k]+=dp[i][j];
		int sum=0;
		for(int i=N;i<=N*M;++i) sum+=dp[N][i]*(i>K?i-K:1);
		printf("%.10f\n",sum/(double)ipow(M,N));
	}
	
	return 0;
}


Measured memory_bytes: 3304
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}


int N;
char S[1000111];
int Q;

pair<int, int> dq[1000111];
int li, ri;

void MAIN() {
    scanf("%d%s%d", &N, S, &Q);

    REP ($, Q) {
	int K;
	scanf("%d", &K);

	li = ri = 0;
	LL sum = 0;
	LL ans = 0;
	int cnt = 0;

	REP (i, N) {
	    if (S[i] == 'D') {
		dq[ri++] = make_pair(i, cnt);
	    } else if (S[i] == 'M') {
		sum += ri - li;
		cnt++;
	    } else if (S[i] == 'C') {
		while (li < ri && i - dq[li].first >= K) {
		    sum -= cnt - dq[li].second;
		    li++;
		}

		ans += sum;
	    } else {
		// nop
	    }
	}

	printf("%lld\n", ans);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 9088
import java.util.Scanner;
import java.util.ArrayList;
import java.util.LinkedList;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[] dg=new int[n];
		ArrayList<Integer>[] list=new ArrayList[n];
		for(int i=0; i<n; i++){
			list[i]=new ArrayList<>();
		}
		for(int i=0; i<n+m-1; i++){
			int a =sc.nextInt()-1;
			int b =sc.nextInt()-1;
			dg[b]++;
			list[a].add(b);
		}
		int root=0;
		for(int i=0; i<n; i++){
			if(dg[i]==0){
				root=i;
				break;
			}
		}
		int[] ans=new int[n];
		LinkedList<Integer> que=new LinkedList<>();
		que.add(root);
		while(!que.isEmpty()){
			int g=que.poll();
			for(int i:list[g]){
				if(dg[i]==0){
					continue;
				}
				dg[i]--;
				if(dg[i]==0){
					ans[i]=g+1;
					que.add(i);
				}
			}
		}
		for(int i=0; i<n; i++){
			System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 104648
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn a() {
    let (h, w, a, b) = read!(usize, usize, usize, usize);

    let mut left1 = Vec::new();
    let mut right1 = Vec::new();
    for i in 1..(w + 1) {
        if i <= a {
            left1.push("1");
            right1.push("0");
        } else {
            left1.push("0");
            right1.push("1");
        }
    }

    //    let mut ans = Vec::new();
    //
    let sl = left1.join("");
    let sr = right1.join("");
    for i in 1..(h + 1) {
        if i <= b {
            //            ans.push(sl.chars().collect::<Vec<char>>());
            println!("{}", &sl);
        } else {
            //            ans.push(sr.chars().collect::<Vec<char>>());
            println!("{}", &sr);
        }
    }
}

fn b() {
    unimplemented!();
}

fn c() {
    unimplemented!();
}

fn d() {
    unimplemented!();
}

fn e() {
    unimplemented!();
}

fn f() {
    unimplemented!();
}

fn main() {
    a();
}


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

const int maxn = 1e5 + 10;
int n, m;
bool vis[maxn];

vector <int> ans1, ans2, e[maxn];

void dfs(int u) {
	vis[u] = 1;
	ans1.push_back(u);
	for (int v : e[u]) {
		if (!vis[v]) {
			dfs(v);
			return;
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1, u, v; i <= m; i++) {
		scanf("%d %d", &u, &v);
		e[u].push_back(v), e[v].push_back(u);
	}
	dfs(1);
	swap(ans1, ans2);
	dfs(1);
	printf("%d\n", ans1.size() + ans2.size() - 1);
	for (int i = ans2.size() - 1; i; i--) {
		printf("%d ", ans2[i]);
	}
	for (int x : ans1) {
		printf("%d ", x);
	}
	return 0;
}

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

int main() {

   set<string>S;
   string ss;
   int N;
   cin >> N;
   for(int i=0;i<N;i++){
        cin >> ss;
        S.insert(ss);
   }
   cout<< (int) S.size() <<endl;
}


Measured memory_bytes: 19236
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int k = ((int)Math.sqrt(1 + 8 * N) + 1) / 2;
        out.println(k * (k - 1) / 2 == N ? solve(k) : "No");
    }

    static String solve(int k) {
        StringBuilder sb = new StringBuilder("Yes\n");
        sb.append(k).append('\n');

        for (int i = 1; i < k; i++) {
            sb.append(k - 1).append(' ');

            int t = 1 + i * (i - 1) / 2;
            for (int j = 1; j < i; j++) {
                sb.append(t++).append(' ');
            }

            for (int j = i; j < k; j++) {
                sb.append(t).append(' ');
                t += j;
            }
            sb.append('\n');
        }

        sb.append(k - 1).append(' ');
        int t = 1;
        for (int i = 2; i <= k; i++) {
            sb.append(t).append(' ');
            t += i;
        }

        return sb.toString();
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 40400
#include <map>
#include <cmath>
#include <cstdio>

typedef long long LL;

const int MAXN = 1e5 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T MAX( const _T a, const _T b )
{
	return a > b ? a : b;
}

std :: map<LL, int> mp;

LL a[MAXN], oppo[MAXN];
LL pw2[MAXN], pw3[MAXN];

int prime[MAXN], pn;
int N;

bool isPrime[MAXN];

void EulerSieve( const int siz )
{
	for( int i = 2 ; i <= siz ; i ++ )
	{
		if( ! isPrime[i] ) prime[++ pn] = i;
		for( int j = 1 ; j <= pn && 1ll * i * prime[j] <= siz ; j ++ )
		{
			isPrime[i * prime[j]] = true;
			if( ! ( i % prime[j] ) ) break;
		}
	}
	for( int i = 1 ; i <= pn ; i ++ )
		pw2[i] = 1ll * prime[i] * prime[i], pw3[i] = 1ll * pw2[i] * prime[i];
}

int main()
{
	bool flg = false;
	read( N ); EulerSieve( 3000 );
	for( int i = 1 ; i <= N ; i ++ ) 
	{
		read( a[i] );
		for( int k = 1 ; k <= pn && pw3[k] <= a[i] ; k ++ )
			while( ! ( a[i] % pw3[k] ) )
				a[i] /= pw3[k];
		if( a[i] == 1 ) flg = true, mp[a[i]] = -1;
		else
		{
			mp[a[i]] ++;
			LL tmp = a[i];
			int tot = 0, indx; LL rest = 1;
			for( int k = 1 ; k <= pn && prime[k] <= tmp ; k ++ )
				if( ! ( tmp % prime[k] ))
				{
					tot ++, indx = 0;
					while( ! ( tmp % prime[k] ) )
						indx ++, tmp /= prime[k];
					if( indx & 1 ) rest = 1ll * rest * pw2[k];
					else rest = 1ll * rest * prime[k];
				}
			int t = sqrt( tmp );
			if( 1ll * t * t == tmp ) oppo[i] = 1ll * t * rest;
			else oppo[i] = ( tmp <= 1e5 ? rest * tmp * tmp : 0 );
		}
	}
	int ans = 0;
	for( int i = 1 ; i <= N ; i ++ )
		if( ~ mp[a[i]] )
			ans += MAX( mp[a[i]], mp[oppo[i]] ),
			mp[a[i]] = mp[oppo[i]] = -1;
	write( ans + flg ), putchar( '\n' );
	return 0;
}

Measured memory_bytes: 14728