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

string s;
deque<char> dq;
int status = 0, q;

int main()
{
    cin >> s >> q;
    for (int i = 0; i < (int)s.size(); i++) {
        dq.push_back(s[i]);
    }

    for (int i = 0; i < q; i++) {
        int t; cin >> t;
        if (t == 1) {
            status++;
        } else if (t == 2) {
            char c;
            int f;
            cin >> f >> c;
            if ((status + f)%2 == 0) {
                dq.push_back(c);
            } else {
                dq.push_front(c);
            }
        }
    }

    if (status % 2 == 0) {
        for (int i = 0; i < (int)dq.size(); i++) {
            cout << dq[i];
        }
    } else {
        for (int i = (int)dq.size()-1; 0 <= i; i--) {
            cout << dq[i];
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#define int long long
#define lowbit(x) (x &(-x))
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int  INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EXP = 1e-8;
const ll   MOD = 1e9 + 7;
const int  N = 2e5 + 5;
int n, m;
int a[10], vis[10];
signed main(){
    cin >> n >> m;
    mem(a,-1);
    while(m--){
        int i, x;
        cin >> i >> x;
        if(!vis[i]){
            vis[i] = x;
            a[i] = x;
        }
        else{
            if(vis[i] != x){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    if(!a[1] && n > 1){
        cout << -1 << endl;
        return 0;
    }
    if(n > 1){
        for(int i = 1; i <= n; i ++){
            if(a[i] == -1){
                if(i == 1) cout << 1;
                else cout << 0;
            }
            else cout << a[i];
        }
    }
    else{
        if(a[1] == -1) cout << 0;
        else cout << a[1];
    }
    return 0;
}


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

string shuffle(string str,int h){
    string head =str.substr(0,h);
    string tail = str.substr(h,str.size()-h);
    return tail + head;
}
int main(){
    string cards;
    int m,h;
    while(1){
        cin >>cards;
        if (cards=="-")break;
        
        cin>>m;
        for(int i =0;i<m;i++){
            cin>>h;
            cards = shuffle(cards,h);
            
        }
        cout << cards <<endl;;
    }
    return 0;
}


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

int main() {
  string S; cin >> S;
  if (S == "SSS") cout << 0;
  else if (S == "RSS" || S == "RSR" || S == "SRS" || S == "SSR") cout << 1;
  else if (S == "RRR") cout << 3;
  else cout << 2;
  cout << endl;
}

Measured memory_bytes: 3576
from itertools import permutations


def solve(string):
    n, *pq = map(int, string.split())
    *ps, = permutations(range(1, n + 1))
    return str(abs(ps.index(tuple(pq[n:])) - ps.index(tuple(pq[:n]))))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 8052
from itertools import product

n = int(input())

pow6 = [pow(6, i + 1) for i in range(6)]
pow9 = [pow(9, i) for i in range(6)][::-1]

ans = n
for l in product(range(6), repeat=6):
    cnt = sum(l)
    num = n - sum(pi * li for pi, li in zip(pow6, l))
    if num >= 0:
        tmp = 0
        while num > 0:
            if pow9[tmp] > num:
                tmp += 1
            elif pow9[tmp] <= num:
                num -= pow9[tmp]
                cnt += 1
        ans = min(ans, cnt)
print(ans)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
const ll MOD=1e9+7;

int main() {
    string s;
    cin>>s;
    int b=0;
    rep(i,s.size()){
        if (s[i]=='7'){
            b=1;
            break;
        }
    }
    if (b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}

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

template<class Monoid> struct SegTree {
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid UNITY;
  int SIZE_R;
  vector<Monoid> dat;
  SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
  void init(int n) {
    SIZE_R = 1;
    while (SIZE_R < n) SIZE_R *= 2;
    dat.assign(SIZE_R * 2, UNITY);
  }
  void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
  void build() {
    for (int k = SIZE_R - 1; k > 0; --k)
    dat[k] = F(dat[k*2], dat[k*2+1]);
  }
  void update(int a, const Monoid &v) {
    int k = a + SIZE_R;
    dat[k] = v;
    while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
  }
  Monoid get(int a, int b) {
    Monoid vleft = UNITY, vright = UNITY;
    for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
      if (left & 1) vleft = F(vleft, dat[left++]);
      if (right & 1) vright = F(dat[--right], vright);
    }
    return F(vleft, vright);
  }
  inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }
  void print() {
    for (int i = 0; i < SIZE_R; ++i) {
      cout << (*this)[i];
      if (i != SIZE_R-1) cout << ",";
    }
    cout << endl;
  }
};

int main() {
  int N;
  cin >> N;
  SegTree<long long> seg(N, [](long long a, long long b) {
    return __gcd(a, b);
  }, 0);
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    seg.set(i, A.at(i));
  }
  seg.build();

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long left = seg.get(0, i);
    long long right = seg.get(i + 1, N);
    ans = max(ans, __gcd(left, right));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3072
//In the Name of God
//Ya Ali

#include<bits/stdc++.h>

#define int long long

#define err(A) cout<<#A<<" = "<<(A)<<endl

using namespace std;

const int M=1e9+7;
const int inf=(int)2e18+10;
const int maxn=100100;

int n,X,Y;

int a[maxn];

int dp[maxn][2];
int pp[maxn][2];

int ans;

int32_t main()
{
  ios::sync_with_stdio(0);cin.tie(0);
  
  cin>>n>>X>>Y;

  a[0]=-inf;
  for(int i=1;i<=n;i++)
    cin>>a[i];
  a[n+1]=inf;

  pp[n][0]=pp[n][1]=1;
  dp[n][0]=dp[n][1]=1;
  
  int Rx=n+1,Ry=n+1;
  for(int l,r,i=n-1;i>=0;i--)
    {
      pp[i][0]=pp[i+1][0];
      pp[i][1]=pp[i+1][1];
      //X:
      l=lower_bound(a,a+n+1,a[i]+X)-a;
      r=Ry;
      if(r>=l)
	dp[i][0]=(pp[l-1][1]-pp[r][1])%M;
      //Y:
      l=lower_bound(a,a+n+1,a[i]+Y)-a;
      r=Rx;
      if(r>=l)
	dp[i][1]=(pp[l-1][0]-pp[r][0])%M;
      //////
      pp[i][0]=(dp[i][0]+pp[i+1][0])%M;
      pp[i][1]=(dp[i][1]+pp[i+1][1])%M;

      if(a[i+1]-a[i]<X)
	Rx=i+1;
      if(a[i+1]-a[i]<Y)
	Ry=i+1;
    }

  for(int i=0;i<=n;i++)
    {
      ans=(ans+dp[i][0])%M;
      if(a[i+1]-a[i]<X)
	break;
    }

  cout<<(ans%M+M)%M<<endl;
  
  return 0;
}


Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	x, _ := strconv.Atoi(Scanner())
	y, _ := strconv.Atoi(Scanner())
	a, _ := strconv.Atoi(Scanner())
	b, _ := strconv.Atoi(Scanner())
	c, _ := strconv.Atoi(Scanner())
	as := make([]int, a)
	bs := make([]int, b)
	cs := make([]int, c)
	for i := 0; i < a; i++ {
		as[i], _ = strconv.Atoi(Scanner())
	}
	for i := 0; i < b; i++ {
		bs[i], _ = strconv.Atoi(Scanner())
	}
	for i := 0; i < c; i++ {
		cs[i], _ = strconv.Atoi(Scanner())
	}
	sort.Sort(sort.Reverse(sort.IntSlice(as)))
	sort.Sort(sort.Reverse(sort.IntSlice(bs)))
	sort.Sort(sort.Reverse(sort.IntSlice(cs)))
	l := make([]int, 0)
	for i := 0; i < x; i++ {
		l = append(l, as[i])
	}
	for i := 0; i < y; i++ {
		l = append(l, bs[i])
	}
	sort.Ints(l)
	m := l[:smaller(c, len(l))]
	for i := 0; i < len(m); i++ {
		if m[i] < cs[i] {
			m[i] = cs[i]
		} else {
			break
		}
	}
	ans := 0
	for i := 0; i < len(l); i++ {
		ans += l[i]
	}
	fmt.Println(ans)
}
func larger(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}
func smaller(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}


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

int func(int x){
  if(x%2==1)
    return 3*x+1;
  else
    return x/2;
}

int issearch(int x){
}

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

  int a=s;

  int i=1;
  while(a!=4&&a!=2&&a!=1){
    a=func(a);
    i++;
  }

  cout<<i+3;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;

int w, h, n, x1[1000], yy1[1000], x2[1000], y2[1000];
bool mas[2200][2200];

int main(){

  while(cin >> w >> h, w){
    fill_n( *mas, 2200 * 2200, false);

    cin >> n;
    vector< int > numx, numy;
    for(int i = 0; i < n; i++){
      cin >> x1[i] >> yy1[i] >> x2[i] >> y2[i];
      for(int j = -1; j <= 1; j++){
        if(x1[i] + j >= 0 && x1[i] + j < w) numx.push_back(x1[i] + j);
        if(x2[i] + j >= 0 && x2[i] + j < w) numx.push_back(x2[i] + j);
        if(yy1[i] + j >= 0 && yy1[i] + j < h) numy.push_back(yy1[i] + j);
        if(y2[i] + j >= 0 && y2[i] + j < h) numy.push_back(y2[i] + j);
      }
    }
    sort( numx.begin(), numx.end());
    sort( numy.begin(), numy.end());
    numx.erase( unique(numx.begin(), numx.end()), numx.end());
    numy.erase( unique(numy.begin(), numy.end()), numy.end());
  

    for(int i = 0; i < n; i++){
      int xx1 = lower_bound( numx.begin(), numx.end(), x1[i]) - numx.begin();
      int xx2 = lower_bound( numx.begin(), numx.end(), x2[i]) - numx.begin();
      int yyy1 = lower_bound( numy.begin(), numy.end(), yy1[i]) - numy.begin();
      int yy2 = lower_bound( numy.begin(), numy.end(), y2[i]) - numy.begin();
      for(int j = yyy1; j < yy2; j++){
        for(int k = xx1; k < xx2; k++){
          mas[j][k] = true;
        }
      }    
    }

    int ret = 0;
    const static signed dy[] = { 1, 0, -1, 0}, dx[] = { 0, 1, 0, -1};
    queue< Pi > que;
    for(int i = 0; i < numy.size(); i++){
      for(int j = 0; j < numx.size(); j++){
        if(mas[i][j]++) continue;
        ret++;
        que.push(make_pair( i, j));
        while(!que.empty()){
          Pi p = que.front(); que.pop();
          for(int i = 0; i < 4; i++){
            int ny = p.first + dy[i], nx = p.second + dx[i];
            if(ny < 0 || ny >= numy.size() || nx < 0 || nx >= numx.size()) continue;
            if(mas[ny][nx]++) continue;
            que.push(make_pair( ny, nx));
          }
        }
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 5988
import numpy as np
a=np.array([list(map(int,input().split())) for i in range(3)])
b=np.copy(a)
result=0
a[0]-=a[2]
a[1]-=a[2]
a[:,0]-=a[:,2]
a[:,1]-=a[:,2] 
b[0]-=b[2]
b[1]-=b[2]
b[:,0]-=b[:,2]
b[:,1]-=b[:,2]
for i in range(2):
    for j in range(2):
        result=result or a[i][j] or b[i][j]
if not result:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 12512
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9+7;

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; }
    return true;
}

int main() {
	int A,B;
  	cin >> A >>B;
  	cout << (A+B)%24 << endl;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  int N;
  cin>>N;
  int res=0;
  if(N<105)res=0;
  else if(N<135)res=1;
  else if(N<165)res=2;
  else if(N<189)res=3;
  else if(N<195)res=4;
  else res=5;
  cout<<res<<endl;
}


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

int main(){
	int T; cin>>T;
	while(T--){
		int n, m, a, b; cin>>n>>m>>a>>b;
		cout<< floor_sum(n, m, a, b) <<endl;
	}
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  int k;	
  cin >> n >> k;
  int ans=0;
  while(1){
    n/=k;
    ans++;
    if(n==0){
      cout << ans;
      return 0;
    }
  }
}

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

int main(){
  string s;
  cin>>s;
  bool f=1;
  int n=s.size(),r,l,count_r=1,count_l=0;
  vector<int> x(100000,0);
  char c1,c2;
  c1=s.at(0);
  
  REP(i,n-1){
    c2=s.at(i+1);
    if(c1=='R' && c2=='R'){
      //cout << "(p1)";
      count_r++;
    }else if(c1=='R' && c2=='L'){
      //cout << "(p2)";
      r=i;
      l=i+1;
      x.at(r)+=(count_r+1)/2;
      x.at(l)+=(count_r+2)/2;
      count_l=0;
    }else if(c1=='L' && c2=='L'){
      //cout << "(p3)";
      count_l++;
      if(i==n-2){
        x.at(r)+=(count_l+1)/2;
        x.at(l)+=count_l/2;    
      }
    }else if(c1=='L' && c2=='R'){
      //cout << "(p4)";
      x.at(r)+=(count_l+1)/2;
      x.at(l)+=count_l/2;      
      count_r=1;
    }
    c1=c2;
    //cout << "i" << i << " c_r:" << count_r << " c_l:" << count_l << endl;
  }
  
  REP(i,n) cout<<x.at(i)<<" ";
  cout<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
int main(void){
    int n[5],p,j;
    for(int i=0;i<5;++i){
        std::cin>>n[i];
    }
    p=std::min(n[0],n[1]);
    p=std::min(p,n[2]);
    j=std::min(n[3],n[4]);
    std::cout<<p+j-50<<std::endl;
    return 0;
}

Measured memory_bytes: 3064
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

ans = 0
if K == 0:
    ans = N*N
else:
    for b in range(K+1, N+1):
        ans += (N//b)*(b-K)
        r = N % b
        if K <= r < b:
            ans += max(0, r-K+1)
print(ans)


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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int main(){

  int X,Y;
  cin >> X >> Y;

  if (Y%2 == 1){
     cout << "No" <<endl;
     return 0;
   }
  int x = 2 * X - Y/2;
  int y = Y/2 - X;


  if(x < 0 || y < 0){
    cout << "No" << endl;
    return 0;
  }

  if((x+y == X) && (2*x + 4*y ==Y)){
    cout << "Yes" << endl;
  }else {
    cout << "No"<<endl;
  }


//  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#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, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    string S;
    cin >> S;
    string ans;
    if(S=="AAA" || S=="BBB"){
        ans = "No";
    }else{
        ans = "Yes";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+4;
int n,ans;
char s[N];
int main() {
	scanf("%d%s",&n,s+1);
	int i=1,j=1;
	while (i<=n) {
		while (s[i]==s[j+1]) ++j;
		if (s[i]==s[j]) ++ans;
		i=j+1,j=i;
	}
	printf("%d\n",ans);
	return 0;
}

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


int main() {
    int n, q;
    while(cin >> n){
        vector<int> a(n);
        rep(i,n) cin >> a[i];
        cin >> q;
        vector<int> m(q);
        rep(i,q) cin >> m[i];
        for(int i = 0; i < (1<<n); ++i){
            int sum = 0;
            for(int j = 0; j < n; ++j){
                if((i >> j) & 1){
                    sum+=a[j];
                }
            }
            rep(k,q){
                if(m[k]==-1) continue;
                if(m[k]==sum) m[k]=-1;
            }
        }
        rep(i,q){
            if(m[i]==-1) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cmath>
#include <iomanip>
#include <assert.h>
#include <string>

using namespace std;
class dice{
	int a[7];
public:	
	dice(){ for (int i = 1; i <= 6; ++i) a[i] = i + 1; }
	void set(int i, int n){ assert(1<=i && i<=6); a[i] = n; }
	void rot(char ch){
		assert(ch=='W' || ch=='N' || ch=='S' || ch=='E');
		int tmp = a[1];
		switch (ch)
		{
		case 'W':
			a[1] = a[3]; a[3] = a[6]; a[6] = a[4]; a[4] = tmp;
			break;
		case 'E':
			a[1] = a[4]; a[4] = a[6]; a[6] = a[3]; a[3] = tmp;
			break;
		case 'N':
			a[1] = a[2]; a[2] = a[6]; a[6] = a[5]; a[5] = tmp;
			break;
		case 'S':
			a[1] = a[5]; a[5] = a[6]; a[6] = a[2]; a[2] = tmp;
			break;
		}
	}
	int top(){ return a[1]; }
	int south(){ return a[2]; }
	int west(){ return a[4]; }
	int east(){ return a[3]; }
	int north(){ return a[5]; }
	int bottom(){ return a[6]; }
};
int main(){
	dice D;
	for (int i = 1; i <= 6; ++i){
		int tmp; cin >> tmp;
		D.set(i, tmp);
	}
	int n; cin >> n;
	while (n--){
		int u, f; cin >> u >> f;
		while (f != D.south()){
			if (D.bottom() == f) D.rot('N');
			else if (D.top() == f || D.north()==f) D.rot('S');
			else D.rot('W');
		}
		while (u != D.top()){
			D.rot('W');
		}		
		cout << D.east() << '\n';
	}
}

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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define SZ(x) (int)((x).size())

string table[] = {
    "",
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};

void solve(string s) {
    int n = s.size();
    int i=0;
    while(i < n) {
        int st = i;
        while(i<n and s[i]!='0') i++;
        if(0<i and s[i-1]-'0' != 0) {
            string t = table[s[i-1]-'0'];
            cout << t[(i - st - 1) % SZ(t)];
        }
        i++;
    }
    cout << "\n";
}

int main() {
    int n; cin>>n;
    rep(data,n) {
        string s; cin >> s;
        solve(s);
    }
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; 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;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

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


Measured memory_bytes: 3588
n=int(input())
w=[]
a=[]
for i in range(n):
    t=input()
    w.append(list(t))
    a.append(t)
ans='Yes'
if len(a)!=len(set(a)):
    ans='No'
for i in range(n-1):
    if w[i][-1]!=w[i+1][0]:
        ans='No'
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
using namespace std;
const int N=2020,mod=1e9+7;
int n,k,f[N][N],fac[N*N],iv[N*N];
int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=1ll*x*x%mod)
		if(y&1)res=1ll*res*x%mod;
	return res;
}
int C(int x,int y){
	return 1ll*fac[x]*iv[y]%mod*iv[x-y]%mod;
}
int main()
{
	cin>>n>>k; fac[0]=iv[0]=1;
	for(int i=1;i<=n*k;i++)
		fac[i]=1ll*fac[i-1]*i%mod,iv[i]=fpow(fac[i],mod-2);
	if(k==1)return puts("1"),0;
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++){
			f[i][j]=f[i-1][j];
			if(j)f[i][j]=(f[i][j]+1ll*f[i][j-1]*(n-j+1)%mod*C(n*k-i-1-(j-1)*(k-1),k-2)%mod)%mod;
		}
	cout<<(f[n][n]%mod+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 48636
N = int(input().rstrip())
A = sorted(list(map(int, input().rstrip().split())))
B = sorted(list(map(int, input().rstrip().split())))
C = sorted(list(map(int, input().rstrip().split())))

import bisect
upper_condition = [bisect.bisect_left(A, b) for b in B]
lower_condition = [N - bisect.bisect_right(C, b) for b in B]

print(sum(map(lambda x: x[0]*x[1], zip(upper_condition, lower_condition))))

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

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		if(n==3||n==5||n==7){
			System.out.println("YES");
			return;
		}
		System.out.println("NO");
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 23252
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int 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)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
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; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
template<typename V> typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

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

void solve() {
  int N;
  while (cin >> N, N) {
    vpii e(N);
    e[0] = mp(300, 300);
    loop(i, 1, N) {
      int n, d;
      cin >> n >> d;
      e[i] = mp(e[n].fi + dy[d], e[n].se + dx[d]);
    }
    vvb t(600, vb(600));
    rep(i, N) t[e[i].fi][e[i].se] = true;
    int u = 0, l = 0, d = 599, r = 599;
    for (;;) {
      bool b = false;
      rep(i, 600) b |= t[u][i];
      if (b) {
        break;
      } else {
        u++;
      }
    }
    for (;;) {
      bool b = false;
      rep(i, 600) b |= t[i][l];
      if (b) {
        break;
      } else {
        l++;
      }
    }
    for (;;) {
      bool b = false;
      rep(i, 600) b |= t[d][i];
      if (b) {
        break;
      } else {
        d--;
      }
    }
    for (;;) {
      bool b = false;
      rep(i, 600) b |= t[i][r];
      if (b) {
        break;
      } else {
        r--;
      }
    }
    cout << r - l + 1 << ' ' << d - u + 1 << endl;
  }
}

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

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

    int ans=1;
    for(int i=M/N;i>0;i--){
        if(M%i!=0) continue;
        else {
            ans=i;
            break;
        }
    }
    cout << ans << endl;
}

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

int main()
{
  string S;
  cin >> S; // NとS,WとE
  int64_t D[4] = {0, 0, 0, 0};
  for (int i = 0; i < S.size(); i++)
  {
    if (S.at(i) == 'N')
      D[0]++;
    else if (S.at(i) == 'E')
      D[1]++;
    else if (S.at(i) == 'S')
      D[2]++;
    else if (S.at(i) == 'W')
      D[3]++;
  }
  if (D[0] && !D[2] || !D[0] && D[2] || D[1] && !D[3] || !D[1] && D[3])
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
//typedef unsigned long long int ull;
typedef long double ld;
 
#define endl '\n'
#define loop(i, m, n) for (ll i = m; i < n; i++)
#define loope(i, m, n) for (ll i = m; i <= n; i++)
#define epool(i, m, n) for (ll i = m; i >= n; i--)
#define mod 1000000007
#define mod2 998244353
#define vi vector<li>
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x,0;
#define all(v) v.begin(),v.end()

#define naman                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;

ll mpow(ll base, ll exp){
    base %= mod;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

const ll INF=1e8;
const double PI=4*atan(1);
char a[100][1000];

void solve(){
    string s;
    cin >> s;

    loop(i,0,s.size()){
      if(s[i]=='?') s[i]='D';
    }

    cout << s << endl;

}

int32_t main(){
    naman
    ll i = 0,j = 0;

#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    //cout << fixed << setprecision(10);

    int t;
    t=1;
    //cin >> t;
    //ll cno=0;
    while (t--){
        solve();

    }

}

Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    ll H, N;
    cin >> H >> N;
    vector<ll> A(N);
    for(auto& x: A) cin >> x;

    ll s = 0;
    for(auto& x: A) s += x;
    if(s >= H) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int p;
  cin >> p;
  string a;
  string b;
  cin >> a >> b;
  for(int i = 0;i < p;i++){
  cout << a.at(i) << b.at(i);}
  cout << endl;}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a;
	cin>>a;
	if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
		cout<<"vowel"<<endl;
	else
		cout<<"consonant"<<endl;
	return 0;
}

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

#define rep(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define repn(i, m, n) for (int (i) = (m) ; (i) < (int)(n) ; ++(i))
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define repn_rev(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= (m) ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

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

    ll ans = 0, ans2 = 0;
    
    repn(i, 1, n+1) {
        if(i % k == 0) ans++;
    }

    if(k%2 == 0) {
        repn(i, k/2, n+1) {
            if(i % k == k/2) ans2++;
        }
    }

    ll tmp =  ans * ans * ans + ans2*ans2*ans2;

    cout << tmp << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int price, flag = 0;
  cin >> price;
  r(i,26){
    r(j,15){
      if((i*4+j*7)==price)flag =1;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    char s[2];
    
    scanf("%s", s);
    
    if (!strcmp(s, "A")) {
        printf("T");
    } else if (!strcmp(s, "T")) {
        printf("A");
    } else if (!strcmp(s, "C")) {
        printf("G");
    } else {
        printf("C");
    }

    return 0;
}



Measured memory_bytes: 1604
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=3e5+2;

int main(){
	int N;
	cin>>N;
	string seq;
	cin>>seq;
	int ch[MAX]={};
	rep1(i,N-1){
		if(seq[i]=='E')ch[0]++;
	}
	rep1(i,N-1){
		ch[i]=ch[i-1];
		if(seq[i-1]=='W')ch[i]++;
		if(seq[i]=='E')ch[i]--;
	}
	int ans=ch[0];
	rep1(i,N-1){
		ans=min(ans,ch[i]);
	}
	cout<<ans;
}


Measured memory_bytes: 1796
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

#define ll long long
#define int ll
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

#define dump(x)  cerr << #x << " = " << (x) << endl; 

typedef pair<int, int> P;
struct Point{
	int x, y;
};
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = {1,0,-1,0};

int N, A;
int x[50];
vector<int> p, m;
int zero = 0;
int psum[2501], msum[2501];

signed main(){

	cin >> N >> A;
	for (int i = 0; i < N; i++){
		cin >> x[i];
		if (x[i]>A) p.push_back(x[i]-A);
		else if (x[i] < A) m.push_back(abs(x[i]-A));
		else zero++;
	}

	psum[0] = 1;
	for (int i = 0; i < p.size(); i++){
		for (int k = 2500 - p[i]; k >= 0; k--){
			psum[k + p[i]] += psum[k];
		}
	}
	msum[0] = 1;
	for (int i = 0; i < m.size(); i++){
		for (int k = 2500 - m[i]; k >= 0; k--){
			msum[k + m[i]] += msum[k];
		}
	}
	int result = -1;
	for (int i = 0; i <= 2500; i++){
		result += psum[i] * msum[i] * ((ll)1 << zero);
	}

	cout << result << endl;

	return 0;
}


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

bool flag;
int a[11], b[11], c[11];
int pa, pb, pc;

void dfs(int x){
	if (pc == 11 ){
		flag = true;
		return ;
	}
	if (flag == true)
		return ;
	
	if (a[pa] < x){
		a[++pa] = x;
		dfs(c[++pc]);
		pa--;
		pc--;
	}
	if (b[pb] < x){
		b[++pb] = x;
		dfs(c[++pc]);
		pb--;
		pc--;
	}
}
		
	
	
	
void solve(){
	flag = false;
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));	
	pa = pb = pc = 1;
	
	dfs(c[pc]);
	if (flag){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}
	

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 1; j <= 10; j++){
			cin >> c[j];
		}	

		solve();
	}
	
	return 0;
}
	







Measured memory_bytes: 3000
#include <stdio.h>

int main(int argc, const char * argv[]){

    int a = 0,b = 0,c = 0;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a < b && a < c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}

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

using namespace std;
typedef long long ll;
const int maxn = 4e3 + 5;

char s[maxn];

int main() {
    int n; map<char, int> mp;
    scanf("%d%s", &n, s + 1);
    for (int i = 1; i <= n; i++) mp[s[i]]++;
    ll res = 1ll * mp['R'] * mp['G'] * mp['B'];

    for (int i = 1, j; i <= n; i++) {
        for (int k = i + 2; k <= n; k++) {
            j = i + k;
            if (j % 2 == 0) {
                j >>= 1;
                if (s[i] != s[k] && s[i] != s[j] && s[j] != s[k]) {
                    res--;
                }
            }
        }
    }

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 3768
#include <stdio.h>
int main(void) {
	char a[500][10];
	int i = 0, count = 0, stack[1000];

	while (scanf("%s", &a[i]) != EOF) {
		//printf("aa\n");
		if (0 < atoi(a[i]) && atoi(a[i]) < 1000000) {
			stack[count] = atoi(a[i]);
			//printf("%d\n",stack[count]);
			count++;
		} else if (*a[i] == '+') {
			stack[count - 2] = stack[count - 2] + stack[count - 1];
			//printf("op\n");
			//printf("stack:%d\n",stack[count-2]);
			count--;
		}else if (*a[i] == '-') {
			stack[count - 2] = stack[count - 2] - stack[count - 1];
			count--;
		}else if (*a[i] == '*') {
			stack[count - 2] = stack[count - 2] * stack[count - 1];
			count--;
		}
		i++;
	}
	printf("%d\n", stack[0]);
	return 0;
}

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

#define MAX 26

using namespace std;
//a to Z. ASCIで0x61 to 0x7a(97 to 122)
//S[i]-'a'とすることでアルファベットを整数で扱う
//バケット(メモ)をあらかじめ用意してアルファベット総数を終点として探索
//バケットが0で最小の位置にあるものが答え

int main(){

    string S;
    cin >> S;
    int bucket[MAX+1]={0};
    
    for(int i=0; i<S.length(); i++){
        bucket[S[i]-'a']++;
    }


    for(int i=0; i<26; i++) {
        if(bucket[i]==0) {
            cout <<(char)(i+'a')<< endl;
            return 0;
        }
    }

    cout << "None" << endl;


    return 0;
}

Measured memory_bytes: 512
# 0028
array = []
while True:
    try:
        a = input()
        array.append(int(a))
    except EOFError:
        break
s = set(array)
count= list(map(lambda a: array.count(a), s))
mx = max(count)
modes = list(list(s)[i] for i, x in enumerate(count) if x == mx)
print(*sorted(modes), sep = '\n')

Measured memory_bytes: 7692
def topological_sort(N,lst_ab):
    a_to_b=[[] for i in range(n+1)]
    b_from_a=[0]*(n+1)
    for A,B in lst_ab:
        a_to_b[A].append(B)
        b_from_a[B]+=1
    flag=[0]*(n+1)
    ans=[]
    for i in range(1,n+1):
        if b_from_a[i]==0 and flag[i]==0:
            flag[i]=1
            ans.append(i)
            que=[i]
            while que:
                h=que.pop()
                for u in a_to_b[h]:
                    b_from_a[u]-=1
                    if flag[u]==0 and b_from_a[u]==0:
                        flag[u]=1
                        ans.append(u)
                        que.append(u)
    if len(ans)==N: return ans
    else: return False
n,m=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(m)]
h=topological_sort(n,xy)
data=[[] for i in range(n+1)]
for x,y in xy:
    data[x].append(y)
lst=[0]*(n+1)
for u in h:
    for v in data[u]:
        lst[v]=max(lst[v],lst[u]+1)
print(max(lst))

Measured memory_bytes: 88024
#include <iostream>
#include <vector>

using namespace std;

int solve(int N, const vector<int> &a)
{
	int x = 0;
	for (int ans = 1; ans <= N; ++ans) {
		x = a[x];
		if (x == 1) {
			return ans;
		}
	}
	return -1;
}

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (auto &a_i : a) {
		cin >> a_i;
		--a_i;
	}
	cout << solve(N, a) << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
   
using namespace std;
 
#define pi 3.141592653589793
 
int main()
{
    int n, m, k;
    while(1){
        cin >> n >> m >> k;
        if(n == 0 && m == 0 && k == 0) break;
        double result[n * m + 1][n + 1];
        for(int i = 0; i < n * m + 1; i++){
            for(int j = 0; j < n + 1; j++){
                result[i][j] = 0.0;
            }
        }
        for(int i = 1; i < m + 1; i++){
            result[i][1] = (double)1 / m;
        }
        for(int i = 2; i < n + 1; i++){
            for(int j = 1; j < m * (i - 1) + 1; j++){
                for(int k = 1; k < m + 1; k++){
                    result[j + k][i] += (double)result[j][i - 1] / m;
                }
            }
        }
        double ans = 0;
        for(int i = 1; i < n * m + 1; i++){
            if(i > k){
                ans += (i - k) * result[i][n];
            } else {
                ans += result[i][n];
            }
        }
        printf("%15.10f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1356
#include <cstdio>
using namespace std;

int main() {
  int n, m;
  scanf("%d %d\n", &n, &m);

  int food[m];
  for (int i = 0; i < m; i++) {
    food[i] = 0;
  }

  for (int i = 0; i < n; i++) {
    int k, a;
    scanf("%d ", &k);
    for (int j = 0; j < k; j++) {
      if (j != k - 1) {
        scanf("%d ", &a);
      } else {
        scanf("%d", &a);
      }
      food[a - 1] += 1;
    }
    if (i != n - 1) scanf("\n");
  }

  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (food[i] == n) ans++;
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

A, B, C, D = map(int, input().split())
A -= 1

X1 = A - ((A // C) + (A // D) - (A // lcm(C, D)))
X2 = B - ((B // C) + (B // D) - (B // lcm(C, D)))
print(X2 - X1)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define PRINTP(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);   
const int INF = 1<<29;
typedef long long ll;



int main()
{
	io;
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);  
    #endif

    std::string s;
    int q;
    std::cin >> s >> q;
    std::string l = s, r = "";
    for (int i = 0; i < q; i++) {
        int c;
        std::cin >> c;
        if (c == 1) 
            std::swap(l,r);
        else {
            int cc;
            char p;
            std::cin >> cc >> p;
            if (cc == 1) {
                r += p;
            } else {
                l += p;
            }
        }
    }
    std::reverse(r.begin(), r.end());
    r += l;
    std::cout << r;

    #ifndef ONLINE_JUDGE   
    //std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 5005;

ll f[N];
int n, sz[N];
vector < int > g[N];

inline void add(ll &x, ll y) {
	x += y;
	if (x >= mod)
		x -= mod;
}

inline void sub(ll &x, ll y) {
	x -= y;
	if (x < 0)
		x += mod;
}

vector < vector < ll > > dfs(int v, int pr = -1) {
	sz[v] = 1;
	vector < vector < ll > > res;
	vector < ll > vec;
	vec.pb(1);
	vec.pb(0);
	res.pb(vec);
	vec[0] = 0;
	for (auto to : g[v]) {
		if (to == pr)
			continue;
		vector < vector < ll > > nw, cur = dfs(to, v);
		for (int i = 0; i < sz[v] + sz[to]; i++)
			nw.pb(vec);
		for (int i = 0; i < sz[v]; i++) {
			for (int j = 0; j < sz[to]; j++) {
				for (int x = 0; x < 2; x++) {
					for (int y = 0; y < 2; y++) {
						add(nw[i + j + 1][x ^ y], res[i][x] * cur[j][y] % mod);
						add(nw[i][x ^ y ^ 1], res[i][x] * cur[j][y] % mod * f[j + 1] % mod);
					}
				}
			}
		}
		sz[v] += sz[to];
		res = nw;
	}
	return res;
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

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

	//cout << setprecision(10) << fixed;
	
	cin >> n;

	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}

	f[0] = 1;
	for (int i = 1; i <= n; i++)
		f[i] = ((i & 1) ? 0 : f[i - 2] * (i - 1ll) % mod);

	vector < vector < ll > > res = dfs(1);

	ll ans = 0;

	for (int i = 0; i < n; i++) {
		add(ans, res[i][0] * f[i + 1] % mod);
		sub(ans, res[i][1] * f[i + 1] % mod);
	}

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


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

using namespace std;

int main(){
    int N;
    int L[105];
    int j,max=0,sum;
    cin >> N;
    for(int i=0 ;i<N;i++){
        cin >> L[i];
        sum += L[i];
        if(max< L[i]){
            max = L[i];
            j = i;
        }
    }
    sum -= L[j];
    if(sum > L[j]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}

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


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

    string S;
    cin >> S;
    int n = S.size();
    int64_t total = 0;
    for (int bit = 0; bit < (1<<(n-1)); bit++) {
        int64_t s = 0;
        int p = 0;
        for (int i = 0; i < n - 1; i++) {
            if (bit & (1<<i)) {
                // S[p:i+1] を足す
                s += stol(S.substr(p, i - p + 1));
                p = i + 1;
            }
        }
        // S[p:] を足す
        if (p < n) s += stol(S.substr(p));
        total += s;
    }
    
    cout << total << endl;

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            4557430888798830399
#define END(s)          {cout<<s; return 0;}
#define CON(s)          {cout<<s; continue;}
#define BRE(s)          {cout<<s; break;}
#define pb              push_back
#define All(a)          a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)           (int)a.size()
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
//#define usingFiles
using namespace std;

typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;

inline bool Read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool Write(int x){
	if(x >= 10) Write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

int n, A, B;
int a[110];
int cnt1, cnt2, cnt3;

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cnt1 = cnt2 = cnt3 = 0;
	cin >> n >> A >> B;
	rep(i, n){
		cin >> a[i];
		if(a[i] <= A) cnt1++;
		else if(a[i] <= B) cnt2++;
		else cnt3++;
	}
	cout << min(cnt1, min(cnt2, cnt3));
	return 0;
}

Measured memory_bytes: 256