akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

int cnt;

void print_vector(vector<int> &num)
{
	for(int i = 0; i < num.size(); i++){
		if(i == 0){
			cout << num[i];
		}
		else{
			cout << " " << num[i];
		}
	}
	cout << endl;
}
void insertionSort(vector<int> &num, int g)
{
	for(int i = g; i <= num.size() - 1; i++){
		int v = num[i];
		int j = i - g;
		while(j >= 0 && num[j] > v){
			num[j + g] = num[j];
			j = j - g;
			cnt++;
		}
		num[j + g] = v;
	}
}
vector<int> makeG(int n)
{
	vector<int> G;
	int g = 1;
	while(g <= n){
		G.push_back(g);
		g = 3 * g + 1; 
	}
	reverse(G.begin(), G.end());
	
	return G;
}
vector<int> shellSort(vector<int> &num)
{
	cnt = 0;
	vector<int> G = makeG(num.size());
	for(int i = 0; i < G.size(); i++){
		insertionSort(num, G[i]);
	}
	return G;
}
int main(void)
{	
	int n;//??°????????????
	cin >> n;
	
	vector<int> num(n);
	
	for(int i = 0; i < n; i++){
		cin >> num[i];
	}
	
	vector<int> G = shellSort(num);
	
	cout << G.size() << endl;
	print_vector(G);
	cout << cnt << endl;
	
	shellSort(num);
	for(int i = 0; i < num.size(); i++){
		cout << num[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 6780
#!/usr/bin/env python3


def next_line():
    return input()


def next_int():
    return int(input())


def int_ar():
    return list(map(int, input().split()))


def strs():
    return input().split()


def ints():
    return map(int, input().split())


def int_ar_mul(size):
    return [int(input()) for _ in range(size)]


def str_ar(size):
    return [input() for _ in range(size)]


def main():
    n, k = ints()
    p = sorted(int_ar())
    res = 0
    for i in range(k):
        res += p[i]
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62604
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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




int main() {

	string ss, t;
	cin >> ss >> t;

	ll N = ss.size();
	ll M = t.size();

	vector<string> ans;

	rep(i, N - M + 1) {
		ll b = 1;

		string s(N,'a');

		rep(j, N) {
			if (j < i || j >= i + M) {
				if (ss[j] == '?') { s[j] = 'a'; }
				else { s[j] = ss[j]; }
			}

			else {
				if (ss[j] == '?') { s[j] = t[j - i]; }
				else if (ss[j] == t[j - i]) { s[j] = t[j - i]; }
				else { b = 0; break; }
			}
		}

		//cout << i << s << endl;

		if (b == 1) { ans.push_back(s); }
	}

	if (ans.empty()) { cout << "UNRESTORABLE" << endl; }
	else {
		sort(ans.begin(), ans.end());
		cout << ans[0] << endl;
		
	}

	system("PAUSE");

}





Measured memory_bytes: 504
/**
*     ________   ________   ___        ________          ________   ___        ________       ___    ___  _______    ________
*    |\   ____\ |\   __  \ |\  \      |\   __  \        |\   __  \ |\  \      |\   __  \     |\  \  /  /||\  ___ \  |\   __  \
*    \ \  \___|_\ \  \|\  \\ \  \     \ \  \|\  \       \ \  \|\  \\ \  \     \ \  \|\  \    \ \  \/  / /\ \   __/| \ \  \|\  \
*     \ \_____  \\ \  \\\  \\ \  \     \ \  \\\  \       \ \   ____\\ \  \     \ \   __  \    \ \    / /  \ \  \_|/__\ \   _  _\
*      \|____|\  \\ \  \\\  \\ \  \____ \ \  \\\  \       \ \  \___| \ \  \____ \ \  \ \  \    \/  /  /    \ \  \_|\ \\ \  \\  \|
*        ____\_\  \\ \_______\\ \_______\\ \_______\       \ \__\     \ \_______\\ \__\ \__\ __/  / /       \ \_______\\ \__\\ _\
*       |\_________\\|_______| \|_______| \|_______|        \|__|      \|_______| \|__|\|__||\___/ /         \|_______| \|__|\|__|
*       \|_________|                                                                        \|___|/
*/

#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 2e5 +5;
int n , x , a[N] , b[N];
vector<int> v;

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

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

    for(int i = n ; i >= 1 ; i--)
    {
        int sum = 0;
        for(int j = i ; j <= n ; j += i)
            sum += b[j];

        if(sum % 2 != a[i]) b[i] = 1 , v.push_back(i);
    }

    cout << v.size() << '\n';
    for(auto i : v) cout << i << " ";

    return 0;
}


Measured memory_bytes: 2936
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
typedef struct{
	int a,b;
}Pair;
int comp(const void* a,const void* b){
	Pair p1=*(Pair*)a,p2=*(Pair*)b;
	return p1.a==p2.a?p1.b-p2.b:p1.a-p2.a;
}
Pair p[100000];
int main(void)
{
	int n,a,res=0,i;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&a);
		p[i].a=MAX(i+1,a);
		p[i].b=MIN(i+1,a);
	}
	qsort(p,n,sizeof(Pair),comp);
	FOR(i,0,n-1){
		if(p[i].a==p[i+1].a&&p[i].b==p[i+1].b) res++;
	}
	printf("%d\n",res);
	return 0;
}


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

int main()
{
	int h,w,k,res=0;
	cin>>h>>w>>k;
	vector<vector<char> > v(h,vector<char>(w));
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		cin>>v[i][j];
	}
	for(int maskR=0;maskR<=(1<<h)-1;maskR++)
	{
		for(int maskC=0;maskC<=(1<<w)-1;maskC++)
		{
			int black=0;
			for(int i=0;i<h;i++)
			{
				for(int j=0;j<w;j++)
				if((maskR&(1<<i))==0&&(maskC&(1<<j))==0&&v[i][j]=='#') black++;
			}
			if(black==k) res++;
		}
	}
	cout<<res<<endl;
	return 0;
}


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

int main() {
        int n;
        cin >> n;
        if (n == 1) {
                cout << 1 << endl;
        } else {
                // int prev=2;
                // int curr=1;
                // int next;
                long prev=2;
                long curr=1;
                long next;
                for (int i=1; i<n; i++) {
                        next = prev + curr;
                        prev = curr;
                        curr = next;
                }
                cout << curr << endl;
        }
        return 0;
}


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

namespace AtCoder.Contest.A
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			char c = cin.Next()[0];
            if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') Console.WriteLine("vowel");
            else
            {
                Console.WriteLine("consonant");
            }

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else 
    #define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


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

double p;

double M(int x) {
    return x / (2 * p);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int x;
    cin >> x >> p;
    p /= 100;
    double ans;
    if (x % 2)
        ans = M(x - 1) * p + M(x + 1) * (1 - p) + 1;
    else
        ans = M(x);
    cout << setprecision(15) << fixed;
    cout << ans << '\n';     
}

Measured memory_bytes: 3692
#include<iostream>
#include<algorithm>

using namespace std;
int b[100005];

int main(){

   int N;
   cin>> N;
   int a[N];
   for(int i=0; i<N; i++) cin>> a[i];

   for(int i=0; i<N; i++) b[a[i]]++;
   int s=0;
   int c=0;
   for(int i=0; i<100005; i++){
      if(b[i]==0) continue;
      if(b[i]%2==1) s++;
      else c++;
   }

   cout<< s+c-(c%2)<< endl;

   return 0;
}


Measured memory_bytes: 1152
#include <iostream>

int main(){
   int N;
   std::cin >> N;

   int c[10][10];
   for(int i=0; i<10; ++i){
      for(int j=0; j<10; ++j){
	 c[i][j] = 0;
	 for(int k=1; k<=N; ++k){
	    int l = k;
	    while(l/10) l /= 10;
	    if(l==i && k%10==j) ++c[i][j];
	 }
      }
   }
   long long ans = 0;
   for(int i=0; i<10; ++i){
      for(int j=0; j<10; ++j){
	 ans += c[i][j] * c[j][i];
      }
   }

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


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

#define MAX_N 55

bool mat[MAX_N][MAX_N];

int main() {
	memset(mat, false, sizeof(mat));
	int N, M;
	scanf("%d %d", &N, &M);
	for (int i = 0; i < N; i++) {
		int K;
		scanf("%d", &K);
		while (K--) {
			int A;
			scanf("%d", &A);
			mat[i][A] = true;
		}
	}
	int res = 0;
	for (int j = 1; j <= M; j++) {
		bool ok = true;
		for (int i = 0; i < N; i++) if (!mat[i][j]) ok = false;
		if (ok) res++;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
N,X = map(int,input().split())
BLU = [list(map(int,input().split())) for i in range(N)]
for i in range(N):
    b,l,u = BLU[i]
    BLU[i].append(u*X-(u-l)*b)
BLU.sort(key = lambda x:-x[3])

s = 0
for i in range(N):
    s -= BLU[i][1]*BLU[i][0]

ans = 0
for i in range(N):
    b,l,u,m = BLU[i]
    if s+m > 0:
        break
    s += m
    ans += X

from math import ceil
def solve(b,l,u,s):
    if u*X-(u-l)*b < s:
        return X
    if l*b >= s:
        return ceil(s/l)
    else:
        return ceil((s+b*(u-l))/u)

h = X
for b,l,u,m in BLU[i:]:
    h = min(h,solve(b,l,u,-s))

for b,l,u,m in BLU[:i]:
    h = min(h,solve(b,l,u,-s-BLU[i][3]+m))

ans += h
print(ans)

Measured memory_bytes: 68604
#include <bits/stdc++.h>
using namespace std;
#define sorted(a) sort(a.begin(), a.end());
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long unsigned int ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen(".testcase", "r", stdin);
#endif

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

  int K;
  cin >> K;
  int ans = 0;
  for (int a = 1; a <= K; ++a) {
    for (int b = 1; b <= K; ++b) {
      int n = __gcd(a, b);
      for (int c = 1; c <= K; ++c) {
        ans += __gcd(n, c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int cnt[10]={0,2,5,5,4,5,6,3,7,6},dp[10002],n,m,x,i,now;
bool can[10];
int main(void){
  scanf("%d%d",&n,&m);
  memset(dp,-1,sizeof(dp));
  dp[0]=0;
  while(m--){
    scanf("%d",&x);
    can[x]=1;
    for(i=cnt[x];i<=n;i++)
      dp[i]=max(dp[i],dp[i-cnt[x]]+1);
  }
  now=n;
  while(now){
    for(i=9;i;i--)
      if(can[i]&&now>=cnt[i]&&dp[now-cnt[i]]+1==dp[now]){
        putchar(i+'0'),now-=cnt[i];
        break;
      }
  }
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    Card = tuple(tuple(input().split()) for _ in range(N))

    taro = 0
    hanako = 0
    for c in Card:
        if c[0] > c[1]:
            taro += 3
        elif c[0] < c[1]:
            hanako += 3
        else:
            taro += 1
            hanako += 1

    print(taro, hanako)

main()

Measured memory_bytes: 7664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    rep(i,m){
        int a, b;
        cin >> a >> b;
        mp[a]++; mp[b]++;
    }
    for(auto m: mp){
        if (m.second % 2 == 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 7704
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [0]+A
now = 1

if K < N:
    for i in range(K):
        now = A[now]
    print(now)
else:
    visited = [0 for i in range(N+1)]
    for i in range(1, N+2):
        if visited[now] == 0:
            visited[now] = i
            now = A[now]
        else:
            T = i-visited[now]
            tmp = visited[now] + (K-i+1)%T
            print(visited.index(tmp))
            break


Measured memory_bytes: 103736
S=input()
l=len(S)
hou=[0]*l
ans=[0]*l

for i in range(l):
    if(S[i]=="R"):
        hou[i]=1
    else:
        hou[i]=-1

temp=0
for i in range(l):
    if(i==0):
        temp=1
        continue
    if(hou[i]*hou[i-1]==1):
        temp+=1
    else:
        if(hou[i-1]==1):
            ans[i-1]=temp
        else:
            ans[i-1]=-temp
        temp=1
    if(i==l-1):
        ans[i]=-temp
for k in range(l):
    i=l-k-1
    if(i==0):
        break
    if(ans[i]<0 and ans[i-1]==0):
        ans[i-1]=ans[i]
        ans[i]=0

for i in range(l):
    if(ans[i]<0):
        ans[i]*=-1

flag=False
kota=[0]*l
for i in range(l):
    if(flag):
        flag=False
        continue
    if(ans[i]>0):
        flag=True
        kota[i]=(ans[i]+1)//2+ans[i+1]//2
        kota[i+1]=ans[i]//2+(ans[i+1]+1)//2

for c in kota:
  print(c, end =" ")

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

int main(){
  int a;
  cin >> a;
  if(a==3){
    cout << "YES" << endl;
  }
  else if(a==5){
    cout << "YES" <<endl;
  }
  else if(a==7){
    cout << "YES" <<endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 200010
#define MO 924844033
#define G 5
#define LL long long
LL fac[MAXN],inv[MAXN],f[MAXN];
int n;
LL PowMod(LL a,int b)
{
	LL ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%MO;
		a=a*a%MO;
		b>>=1;
	}
	return ret;
}
void Pre()
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%MO;
	inv[n]=PowMod(fac[n],MO-2);
	for(int i=n-1;i>=0;i--)
		inv[i]=inv[i+1]*(i+1)%MO;
}
int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],c,siz[MAXN];
void AddEdge(int u,int v)
{
	c++;V[c]=v,nxt[c]=Adj[u];Adj[u]=c;
}
void dfs(int u,int p)
{
	siz[u]=1;
	for(int i=Adj[u];i;i=nxt[i])
		if(V[i]!=p)
		{
			dfs(V[i],u);
			siz[u]+=siz[V[i]];
		}
	f[siz[u]]--;
	f[n-siz[u]]--;
}
void NTT(LL A[],int N,int typ)
{
	for(int i=1,j=0;i<N-1;i++)
	{
		for(int s=N;j^=s>>=1,~j&s;);
		if(i<j) swap(A[i],A[j]);
	}
	for(int i=1;i<N;i<<=1)
	{
		LL w1=PowMod(G,(MO-1)/(i<<1)),w=1;
		if(typ==-1)
			w1=PowMod(w1,MO-2);
		for(int j=0;j<i;j++,w=w*w1%MO)
			for(int l=j,r=l+i;l<N;l+=(i<<1),r=l+i)
			{
				int tmp=A[r]*w%MO;
				A[r]=(A[l]-tmp+MO)%MO;
				A[l]=(A[l]+tmp)%MO;
			}
	}
	if(typ==-1)
	{
		int Inv=PowMod(N,MO-2);
		for(int i=0;i<N;i++)
			A[i]=A[i]*Inv%MO;
	}
}
LL a[MAXN*4],b[MAXN*4];
int main()
{
	scanf("%d",&n);
	Pre();
	int u,v;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		AddEdge(u,v);
		AddEdge(v,u);
	}
	dfs(1,0);
	f[n]=n;
	int len=1;
	for(;len<=2*n;len<<=1);
	for(int i=0;i<=n;i++)
	{
		a[i]=f[i]*fac[i]%MO;
		b[i]=inv[n-i];
	}
	NTT(a,len,1);
	NTT(b,len,1);
	for(int i=0;i<=len;i++)
		a[i]=a[i]*b[i]%MO;
	NTT(a,len,-1);
	for(int i=1;i<=n;i++)
	{
		LL ans=a[i+n]*inv[i]%MO;
		printf("%lld\n",(ans%MO+MO)%MO);
	}
}

Measured memory_bytes: 31872
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String S = sc.next();
            int max = 0;
            int count = 0;
            for (int i = 0; i < S.length(); i++) {
                if (S.charAt(i) == 'R') {
                    count++;
                } else {
                    max = Math.max(max, count);
                    count = 0;
                }
            }
            max = Math.max(max, count);
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 26984
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;

bool isItACGT(string str){
	if( str.length() == 0) return true;
	char charList[4] = {'A','C','G','T'};
	rep(i,str.length()){
		bool ithCharIsACGT = false;
		rep(j,4){
			if( str[i] == charList[j]){
				ithCharIsACGT = true;
			}
		}
		if( ithCharIsACGT == false){
			return false;
		}
	}
	return true;
}

int recACGTLength(string str){
	if(str.length() == 0) return 0;
	if( isItACGT(str)) return str.length();
	int maxNum = 0;
	maxNum = max(maxNum, recACGTLength(str.substr(1,str.length()-1)));
	maxNum = max(maxNum, recACGTLength(str.substr(0,str.length()-1)));
	return maxNum;
}

int main()
{
	string str;
	cin>>str;
	cout<<recACGTLength(str)<<endl;
	return 0;
}



Measured memory_bytes: 256
/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define MOAE ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.1415926535897932384626433
const ll mod = 1e9 + 7;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/*down, up, right, left*/
int main()
{
	MOAE;
	ll n, cnt = 0;
	vector<ll> mx;
	cin >> n;
	while (n--)
	{
		ll a, b;
		cin >> a >> b;
		if (a == b)
			cnt++;
		else
		{
			mx.pb(cnt);
			cnt = 0;
		}
	}
	mx.pb(cnt);
	cout << (*max_element(all(mx)) >= 3 ? "Yes" : "No") << endl;

	ok;
}

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

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n,m;
    cin>>n>>m;
    vector<string> A(n);
    vector<string> B(m);
    rep(i,0,n)cin>>A[i];
    rep(i,0,m)cin>>B[i];
    rep(i,0,n){
        rep(j,0,n){
           bool check=true;
            rep(ci,0,m){
               rep(cj,0,m){
                    if(i+ci>=n||j+cj>=n||A[i+ci][j+cj]!=B[ci][cj]){
                        check=false;
                        break;
                    }
               }
               if(!check)break;
           }
           if(check){
               cout<<"Yes"<<endl;
               return 0;
           }
        }
    }
    cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans = x;
    ll num = (x - a) / (a - b);
    num = max(num, 0ll);
    num = num % mod;
    ans += num * (b % mod);
    ans %= mod;
    //cout << ans <<" " <<  num << endl;
    x -= num * (a - b);
    if(x >= a) ans += b;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
const int inf=100000;
//const ll inf=1e9+7;
//const ll ful=1e18;
using namespace std;
//namespace mp = boost::multiprecision;
int main() 
{
	int n;
	cin>>n;
	vector<int> h(n);
	for(int i=0;i<n;++i)
	{
		cin>>h[i];
	}
	int ans=0;
	int now=0;
	for(int i=0;i<n-1;++i)
	{
		now=0;
		for(int j=i;j<n-1;++j)
		{
			if(h[j]>=h[j+1])
			{
				now++;
				if(now>ans)
				{
					ans=now;
				}
				continue;
			}
			break;
		}
		if(ans>=n-i) break;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<bool> ok(2001);
  for (int bit = 0; bit < (1 << n); bit++) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        sum += a[i];
      }
    }
    if (sum <= 2000) {
      ok[sum] = 1;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int m;
    cin >> m;
    if (ok[m]) {
      cout << "yes" << '\n';
    } else {
      cout << "no" << '\n';
    }
  }
  return 0;
}



Measured memory_bytes: 3236
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

int a[N];
bool cmp(int x,int y){return x>y;}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    while(cin>>n){
        rep(i,1,n)cin>>a[i];
        ll res=0;
        sort(a+1,a+1+n,cmp);
        int pos=1;
        int cnt=1;
        rep(i,2,n){
            res+=a[pos];
            cnt++;
            if(cnt==2){
                pos++;cnt=0;
            }
        }
        cout<<res<<endl;
    }
    //system("pause");
    return 0;
}

Measured memory_bytes: 4440
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    if(s[0]=='7' || s[1]=='7' || s[2]=='7')cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define _rep(i,ra,re) for((i)=ra;(i)>(re);(i)--)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define _rep_(i,ra,re) for((i)=ra;(i)>=(re);(i)--)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define pu(n) cout << n;
#define mod 1000000007
int i,j,k,l;
static const int MAX_N=10e5;

int main(void){
	int N;cin >> N;
	int front=0,ans=0,maxs=0;
	rep(i,0,N){
		int a;cin >> a;
		if(front<a){
			ans=max(ans,maxs);
			maxs=0;
		}else	maxs++;
		front=a;
	}ans=max(ans,maxs);puts(ans);
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    int x=0,ans=0;
    scanf("%d",&n);
    char s[102];
    scanf("%s",s);
    for (int i=0;i<=n; ++i)
    {  
        if(s[i]=='I')++x;
        else --x;
        
        if(ans<x)ans=x;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        mh : i32,
        mw : i32,
        h : i32,
        w : i32
    }
    println!("{}", (mh - h) * (mw - w));
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e16
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll n;cin>>n;
	ll a[n];rep(i,0,n)cin>>a[i];
	vector<pii>v;rep(i,0,n)v.pb({a[i],i+1});
	sort(all(v));
	rep(i,0,n)cout<<v[i].se<<" "; 
	return 0;
}



Measured memory_bytes: 3312
#include "bits/stdc++.h"
using namespace std;
void fast() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
#define endl '\n'
//#define double long double
//#define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    cout << min(a, k)*1+max((k-a-b), 0)*(-1);
    
}

signed main() {
    
    fast();
    int t = 1;
    //cin >> t; // comment this line if single case
    while (t--) {
        solve();
    }
    
    
}


Measured memory_bytes: 3652
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))


Measured memory_bytes: 6248
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int s=0, p=n;
	while(p>0)
	{
		s+=p%10;
		p=p/10;
	}
	if(n%s==0)cout <<"Yes"<<endl;
	else cout << "No"<<endl;
	return 0; 
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

import itertools

def main():
    while True:
        n,x = map(int,input().split())
        available_list=[int(i) for i in range(1,n+1)]
        counter=0
        if n==0 and x==0:
            exit()
        for value in itertools.combinations(available_list,3):
            if sum(value)==x:
                counter+=1
        print(counter)

if __name__=="__main__":
    main()


Measured memory_bytes: 5644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main(){
	

	int a[3][3];
  int mark[3][3];
  for(int i = 0; i < 3; ++i){
    for(int j = 0; j < 3; ++j){
      cin >> a[i][j];
      mark[i][j] = 0;
    }
  }
  int n;
  cin >> n;
  int x;
  for(int i = 0; i < n; ++i){
  	cin >> x;
  	for(int j = 0; j < 3; ++j){
  		for(int k = 0; k < 3; ++k){
  			if(a[j][k] == x){
  				mark[j][k] = 1;
  			}
  		}
  	}
  }
  /*for(int i = 0; i < 3; ++i){
  	for(int j = 0; j < 3; ++j){
  		cout << mark[i][j] << ' ';
  	}
  	cout << '\n';
  }*/
  int ans = 0, flag = 0;
  for(int i = 0; i < 3; ++i){
  	ans = 0;
  	for(int j = 0; j < 3; ++j){
  		if(mark[i][j] == 1){
  			ans++;
  		}
  	}
  	if(ans == 3){
  		//cout << "W";
  		flag = 1;
  	}
  }
  for(int i = 0; i < 3; ++i){
  	ans = 0;
  	for(int j = 0; j < 3; ++j){
  		if(mark[j][i] == 1){
  			ans++;
  		}
  	}
  	if(ans == 3){
  		//cout << "z";
  		flag = 1;
  	}
  }
  if(mark[0][0]  == mark[1][1] && mark[0][0] == mark[2][2] && mark[0][0] == 1){
  	//cout<<"p";
  	flag = 1;
  }
  if(mark[0][2]  == mark[1][1] && mark[0][2] == mark[2][0] && mark[0][2] == 1){
  	//cout<<"q";
  	flag = 1;
  }
  if(flag == 1) cout << "Yes\n";
  else cout << "No\n";
	return 0;
}

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

int main(){
    ios_base::sync_with_stdio(0);
    int N, M;
    cin >> N >> M;
    vector <vector <long long> > DP;
    vector <vector <char> > tab;
    tab.resize(N+1, vector <char> (M+1));
    DP.resize(N+1, vector <long long> (M+1));
    for (int i = 1; i<=N; i++){
        for (int j = 1; j <= M; j++){
            cin >> tab[i][j];
        }
    }
    DP[1][1] = 1;
    for (int i = 2; i<= N; i++){
        if (tab[i][1] == '#'){
            DP[i][1] = 0;
        }
        else{
            DP[i][1] = DP[i-1][1];
        }
    }
    for (int j = 2; j <= M; j++){
        if (tab[1][j] == '#'){
            DP[1][j] = 0;
        }
        else{
            DP[1][j] = DP[1][j-1];
        }
    }
    for (int i = 2; i <= N; i++){
        for (int j = 2; j <= M; j++){
            if (tab[i][j] == '#'){
                DP[i][j] = 0;
            }
            else{
                DP[i][j] = (DP[i-1][j] + DP[i][j-1])%Modulo;
            }
        }
    }
    cout << DP[N][M];
}

Measured memory_bytes: 9216
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int C[N-1],S[N-1],F[N-1];
    for(int i=0;i<N-1;i++){
        cin>>C[i]>>S[i]>>F[i];
    }
    for(int i=0;i<N-1;i++){
        int t=0;
        for(int j=i;j<N-1;j++){
            if(t>=S[j]){
                if(t%F[j]!=0){t+=F[j]-(t%F[j]);}
            }
            else{
                t=S[j];
            }
            t+=C[j];
        }
        cout<<t<<endl;
    }
    cout<<'0'<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);

       while(true){
           int n = sc.nextInt();
           int x = sc.nextInt();
           int result = 0;

           if(n == 0 && x == 0)break;

           for(int i = 1;i <= n-2; i ++){
               for(int j = i + 1; j<= n-1; j ++){
                   for(int k = j + 1; k <= n; k++){
                       if(x == (i+j+k)){
                           result++;
                       }
                   }
               }
           }

           System.out.println(result);
       }
    }
}



Measured memory_bytes: 26412
#include <iostream>
#include <string>
#include <vector>

void a() {
	long N;
	long M;
	std::cin >> N;
	std::cin >> M;
	std::cout << ((N) * (N - 1)) / 2 + ((M) * (M - 1)) / 2;
}

int main() {
  a();
  return 0;
}

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

int main()
{
	int n, b, f, r, v;
	int i, j, k;
	int count[4][3][10]={0};
	
	cin >> n;
	
	for(i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		count[b - 1][f - 1][r - 1] += v;
	}
	
	for(i = 0; i < 4; i++){
		for(j = 0; j < 3; j++){
			for(k = 0; k < 10; k++){
				cout << " " << count[i][j][k];
			}
			cout << endl;
		}
		if(i < 3){
			cout << "####################" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3104
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong(); //ao
    long B = sc.nextLong(); //aka
    long cnt = N/(A+B);
    long amari = N%(A+B);
    long x = 0;
    if(amari>=A){
      x =A;
    }else{
      x = amari;
    }
    long ans = A*cnt + x;
    System.out.println(ans);    
  }
}




Measured memory_bytes: 23380
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		int N = sc.nextInt();
		
		for(long a=1; a<=3500; a++) {
			for(long b=a; b<=3500; b++) {
				if(4*a*b - N*(a+b) != 0 && (N*a*b)%(4*a*b - N*(a+b)) == 0 && (N*a*b)/(4*a*b - N*(a+b)) > 0)  {
					long c = (N*a*b)/(4*a*b - N*(a+b));
					System.out.println(a + " " + b + " " + c);
					return;
				}
			}
		}
	}
	
	static 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;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); 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() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 23380
use std::io::*;

mod segment_tree {
    pub struct SegmentTree<T, F> {
        size: usize,
        data: Vec<T>,
        identity: T,
        operation: F,
    }

    impl<T: Copy + Clone, F: Fn(T, T) -> T> SegmentTree<T, F> {
        pub fn new(n: usize, id: T, op: F) -> SegmentTree<T, F> {
            let mut size = 1;
            while size < n {
                size <<= 1;
            }
            SegmentTree {
                size: size,
                data: vec![id; size * 2],
                identity: id,
                operation: op,
            }
        }

        pub fn update(&mut self, mut i: usize, x: T) {
            i += self.size;
            self.data[i] = x;
            i >>= 1;
            while i > 0 {
                self.data[i] = (self.operation)(self.data[i * 2], self.data[i * 2 + 1]);
                i >>= 1;
            }
        }
        pub fn query(&self, mut l: usize, mut r: usize) -> T {
            let mut a = self.identity;
            let mut b = self.identity;
            l += self.size;
            r += self.size;
            while l < r {
                if (l & 1) == 1 {
                    a = (self.operation)(a, self.data[l]);
                    l += 1;
                }
                if (r & 1) == 1 {
                    r -= 1;
                    b = (self.operation)(self.data[r], b);
                }
                l >>= 1;
                r >>= 1;
            }
            (self.operation)(a, b)
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let s: Vec<usize> = itr
        .next()
        .unwrap()
        .chars()
        .map(|c| c as usize - 'a' as usize)
        .collect();
    let q: usize = itr.next().unwrap().parse().unwrap();

    // 区間和をとると長さ26のビット列が返る
    let mut count = segment_tree::SegmentTree::new(n, 0u32, |x, y| x | y);
    for i in 0..s.len() {
        count.update(i, 1 << s[i]);
    }

    let mut out = Vec::new();
    for _ in 0..q {
        let c: usize = itr.next().unwrap().parse().unwrap();
        if c == 1 {
            let i: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
            let tmp: Vec<char> = itr.next().unwrap().chars().collect();
            let c: usize = tmp[0] as usize - 'a' as usize;
            count.update(i, 1 << c);
        } else {
            let l: usize = itr.next().unwrap().parse().unwrap();
            let r: usize = itr.next().unwrap().parse().unwrap();
            writeln!(out, "{}", count.query(l - 1, r).count_ones()).ok();
        }
    }
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 15608
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
using namespace std;
const int MOD = (int)1e9+7;
void solve()
{
  ll A,B,C,K;
  cin>>A>>B>>C>>K;
  if(A>=K)cout<<K<<endl;
  else {
    K-=A;
    if(B>=K){
      cout<<A<<endl;
    }
    else{
      K-=B;
      cout<<A-min(K,C)<<endl;
    }
  }
}
int  main()
{
    IOS
        solve();
    return 0;
}



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

int main() {
    long long n;
    long long mod = pow(10, 9)+7;
    cin >> n;
    long long ans = 1;
    for (long long i=1; i<n+1; i++) {
        ans *= i;
        ans %= mod;
    }
    cout << ans << endl;
}

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

using namespace std;

using i64 = int64_t;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

bool solve(){

    i64 n, m, h, k;
    cin >> n >> m >> h >> k;
    if(!n)
        return false;
    vector<i64> poi64(n);
    for(auto& x : poi64)
        cin >> x;
    vector<vector<i64>> poll(h);
    for(i64 i = 0; i < m; ++i){
        i64 a, b;
        cin >> a >> b;
        poll[--b].emplace_back(--a);
    }

    vector<i64> v(n);
    iota(v.begin(), v.end(), 0);

    vector<bitset<1007>> bs(1007);
    for(i64 i = 0; i < h; ++i){
        for(auto& x : poll[i]){
            bs[v[x]].set(v[x + 1]);
            bs[v[x + 1]].set(v[x]);
            swap(v[x], v[x + 1]);
        }
    }

    vector<i64> kakutei_poi64(n);
    i64 sum = 0;
    for(i64 i = 0; i < n; ++i){
        kakutei_poi64[v[i]] = poi64[i];
    }
    i64 mi = 0;
    for(int i = 0; i < k; ++i){
        sum += kakutei_poi64[i];
        for(int j = k; j < n; ++j)
            if(bs[i][j])
                mi = min(mi, kakutei_poi64[j] - kakutei_poi64[i]);
    }

    cout << sum + mi << endl;


    return true;
}

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



Measured memory_bytes: 4192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y, int m) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y, int m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

string s;
int d[200010][26];
string ans;

signed main() {
	cin >> s;
	int n = (int)s.size();
	for (int i = 0; i < 26; i++)d[n][i] = 1;
	for (int i = n - 1; i >= 0; i--) {
		int mi = n;
		for (int j = 0; j < 26; j++)mi = min(mi, d[i + 1][j]);
		for (int j = 0; j < 26; j++)d[i][j] = min(mi + 1, d[i + 1][j]);
		if (mi == d[i + 1][s[i] - 'a'])d[i][s[i] - 'a'] = mi + 1;
	}
	for (int i = 0; i <= n; i++) {
		int mi = n, p = 0;
		for (int j = 0; j < 26; j++)if (d[i][j] < mi) {
			mi = d[i][j];
			p = j;
		}
		char c = 'a' + p;
		ans += c;
        if(mi==1)break;
		while (s[i] != c)i++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 41220
use std::io::*;
use std::str::FromStr;
   
fn read<T: FromStr>() -> T {
	let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
	let n: u32 = read();
	let k: i32 = read();
	let q: i32 = read();
	let mut a: Vec<u32> = Vec::new();
	for i in 0..q {
		a.push(read());
	}

	let mut score: Vec<i32> = vec![k-q; n as usize]; // [k....k]

	for ai in a.iter(){
		score[(ai-1) as usize] += 1;
	}

	for s in score.iter() {
		if s > &0 {
			println!("Yes");
		} else {
			println!("No");
		}
	}
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int N;
    std::cin >> N;

    int A_n = 0;
    bool ok = true;
    for(int i=0;i<N;++i){
        string S;
        std::cin >> S;

        if(S == "A"){
            ++A_n;
        }else{
            if(A_n > 0){
                --A_n;
            }else{
                ok = false;
                break;
            }
        }
    }

    ok = ok && A_n == 0;
    const string YESNO[2] = {"NO", "YES"};
    std::cout << YESNO[ok] << std::endl;
}



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

int main()
{
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    int T[q];
    for (int i = 0; i < q; i++) {
        cin >> T[i];
    }
    int sum = 0;
    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (T[i] == S[j]) {
                sum++;
                break;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3108