akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include <iostream>
#include <string>

int main(){
  string weather;
  cin >> weather;
  int max = 0;
  int count = 0;
  
  for (int i = 0; i < weather.length(); i++){
    if (i == 0){
      if (weather[i] == 'R'){
        count = 1;
        max = 1;
      }
    }
    else {
      if (weather[i] == 'R'){
        count += 1;
        if (max < count) max = count;
      }
      else count = 0;
    }
  }
  
  cout << max;
  return 0;
}


Measured memory_bytes: 3596
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1141&lang=jp

#include <iostream>
#include <algorithm>
using namespace std;

const int C = 1e6 + 10;

bool isprime[C];

void init() {
  fill(isprime, isprime+C, true);
  isprime[0] = isprime[1] = false;
  for(int i=2; i<C; i++) {
    if (isprime[i]) {
      for (int j=2; j<C; j++) {
	if ( i * j >= C ) break;
	isprime[i * j] = false;
      }
    }
  }
}

int main() {
  init();
  /*for (int i=0; i<100; i++) {
    cerr << "isprime[" << i << "] is "<< isprime[i] << endl;
    } */
  int a, d, n;
  while (scanf("%d%d%d", &a, &d, &n) != EOF && a) {
    int count = 0;
    int now = a;
    while (true) {
      if (isprime[now]) {
	count++;
	// cerr << "count: " << count << ", prime: " << now << endl;
	if (count == n) break;
      }
      now += d;
    }
    printf("%d\n", now);
  }
}

Measured memory_bytes: 2148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String line = null;
		try (Scanner sc = new Scanner(System.in)) {
			line = sc.nextLine();
			String[] tmpArray = line.split(" ");
			int numA = Integer.parseInt(tmpArray[0]);
			int numB = Integer.parseInt(tmpArray[1]);

			
			int[] tmpList = new int[numB];
			int tmpInd = 0;
			for (int i = 0; i < numA; i++) {
				line = sc.nextLine();
				String[] tmp = line.split(" ");
				for (int j = 0; j < tmp.length; j++) {
					if (j==0) continue;
					tmpInd = Integer.parseInt(tmp[j]);
					tmpList[tmpInd-1] ++;
				}
				}
			int reult = 0;
			for(int k : tmpList){
				if(k == numA){
					reult ++;
				}
			}
				
			System.out.println(reult);
		
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}

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

using namespace std;
using ll = long long int;
#define INF 20000000000000000;

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  ll total = 0;
  vector<ll> sum(n);
  ll ans = INF;
  
  for(int i = 0;i < n;i++){
    cin >> a[i];
    total += a[i];
    sum[i] = total;
  }
  
  for(int i = 0;i < n-1;i++){
    ans = min(ans, abs(sum[i]-(total-sum[i])));
  }
  
  cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    sort(begin(s), end(s));
    int res = 0;
    for (int i = 0; i < s.size(); i++){
        if(s[i] == '0' && s[i+1] == '1'){
            res = i + 1;
            break;
        }
    }
    cout << min(res, (int)s.size() - res) * 2 << endl;
    return 0;
}

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

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

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <stack>
#include <vector>
using namespace  std;

struct StDtl
{
  int m_iLeft;

  StDtl(int a_iLeft) :
    m_iLeft(a_iLeft)
  { }

  ~StDtl() { }
};

struct StSum
{
  int m_iLeft;
  int m_iRight;
  int m_iArea;

  StSum(int a_iLeft, int a_iRight, int a_iArea) :
    m_iLeft(a_iLeft), m_iRight(a_iRight), m_iArea(a_iArea)
  { }

  ~StSum() { }
};

void fnCrossSectAreaSet(stack<StDtl> &a_skoDtl, vector<StSum> &a_voSum, int &a_riTotalArea)
{
  string sCrossSect;
  cin >> sCrossSect;

  for (int i = 0; i < sCrossSect.size(); i++)
  {
    if (sCrossSect[i] == '\\')
    {
      StDtl oDtl(i);
      a_skoDtl.push(oDtl);
    }
    else if (sCrossSect[i] == '/')
    {
      if (a_skoDtl.size() > 0)
      {
        int iLeft = a_skoDtl.top().m_iLeft; a_skoDtl.pop();
        int iSum = i - iLeft; 
        a_riTotalArea += iSum;

        while (a_voSum.size()  &&
               iLeft < a_voSum.back().m_iLeft  &&
               a_voSum.back().m_iRight < i       )
        {
          iSum += a_voSum.back().m_iArea;
          a_voSum.pop_back();
        }
        StSum oSum(iLeft, i, iSum);
        a_voSum.push_back(oSum);
      }
      else;
    }
  }
}

void  fnCrossSectAreaGet(const vector<StSum> &a_cnrvoSum, int a_iTotalArea)
{
  cout << a_iTotalArea << endl;
  cout << a_cnrvoSum.size();
  if (a_cnrvoSum.size() > 0)
  {
    cout << " ";
    for (auto itvoSum = begin(a_cnrvoSum); itvoSum != end(a_cnrvoSum); ++itvoSum)
    {
      if (itvoSum != begin(a_cnrvoSum)) cout << " ";
      cout << itvoSum->m_iArea;
    }
  }
  cout << endl;
}

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

  stack<StDtl> skoDtl;
  vector<StSum> voSum;
  int iTotalArea = 0;

  fnCrossSectAreaSet(skoDtl, voSum, iTotalArea);
  fnCrossSectAreaGet(voSum, iTotalArea);

  return 0;
}

Measured memory_bytes: 1332
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static int[] ans;
//	 static int mod = 998244353;
   public static void main(String[] args) {
	          
	   Scanner sc = new Scanner(System.in);
       int  N = sc.nextInt();
       int  K = sc.nextInt();
       long[] a = new long[N+1];
       long max=0;
       boolean flg=false;
       int cn=0;
       int t=0;
       for (int i=0 ; i<N; i++) {
           long tmp = Long.parseLong(sc.next());
           if(tmp<0) {
        	   tmp=Math.abs(tmp);
           } else {
        	   if(flg==false) {
        		   if(tmp==0) {
        			   K--;
        			   flg=true;
        			   cn=t;
        		   } else {
            		   cn=t;
            		   a[t]=0;
            		   t++;
            		   flg=true;        			   
        		   }
        	   }
           }
           a[t]=tmp;
           t++;
       }
       if(flg==false) {
    	   a[t]=0;
    	   t++;
       }
       Long min=Long.MAX_VALUE;
       for(int i=0;i<t;i++) {
    	   if(cn+K-i>t-1)continue;
    	   if(cn-i<0)continue;
    	   min=Math.min(min, a[cn+K-i]+a[cn-i]*(2));
       }
       for(int i=0;i<t;i++) {
    	   if(cn+i>t-1)continue;
    	   if(cn-K+i<0)continue;
    	   min=Math.min(min, a[cn+i]*2+a[cn-K+i]*(1));
       }
       System.out.println(min); 
       return;
   }

}


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

#define N_MAX 100

int main() {
    long a, b;
    cin >> a >> b;

    if (b % a == 0) {
        cout << a + b << endl;
    }
    else {
        cout << b - a << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
T, A = list(map(int, input().split()))
hs = list(map(int, input().split()))

indx = -1
error = 10000

for i, h in enumerate(hs):
    temp = T - h * 0.006
    if abs(temp - A) < error:
        indx = i
        error = abs(temp - A)
print(indx+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
const ll MOD = 1000000007;

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

    ll ans = 1;
    ll r = 0;
    drep(i,n*2){
        if(i%2==1){
            if(s[i]=='B'){
                r++;
            }else{
                ans *= r;
                ans %= MOD;
                if(r==0){
                    cout << '0' << endl;
                    return 0;
                }
                r--;
            }
        }else{
            if(s[i]=='W'){
                r++;
            }else{
                ans *= r;
                ans %= MOD;
                if(r==0){
                    cout << '0' << endl;
                    return 0;
                }
                r--;
            }
        }
    }

    if(r!=0){
        cout << '0' << endl;
        return 0;
    }

    srep(i,1,n+1){
        ans *= i;
        ans %= MOD;
    }

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


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

long long int gcd(long long int a, long long int b) { return b ? gcd(b, a%b) : a;}

int main(){

    long long int n,k,a,b;

    cin >> n >> k;

    a=max(n,k)-min(n,k);

    if(n<=k){
        n=min(a,n);
    }else{
        a=n-(n/k)*k;
        n=min(a,n);
        a=max(n,k)-min(n,k);
        n=min(a,n);
    }

    cout << n << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
    string n;
    cin>>n;
    for(int i=0;i<3;i++){
        if(n[i]=='7') {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 3620
#include <cstdio>
#define ll long long
using namespace std;
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		ll a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if(a<b){puts("No");continue;}
		if(d<b){puts("No");continue;}
		if(a==c)a+=d;
		ll t=(a-c-1)/gcd(b,d);
		a=a-t*gcd(b,d);
		a-=b;
		if(a<0)puts("No");else puts("Yes");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a[32],n;void DFS(int x,int len,int ran){if(!x){a[len]=x;for(int i=0;i<=len;i++){if(a[i]){if(i)cout<<" ";cout<<a[i];}}cout<<endl;return;}for(int i=min(x,ran);i>=1;i--){a[len]=i;DFS(x-i,len+1,a[len]);}}int main(){while(true){cin>>n;if(!n)break;DFS(n,0,n);}return 0;}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.14159265358979323846;
double pi2=pi/2.0;
double eps=1e-8;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    ll ans[n+1];
    fill(ans,ans+n+1,0);
    rep(i,1,101){
        rep(j,1,101){
            rep(k,1,101){
                if(i*i+j*j+k*k+i*j+j*k+k*i<=n)ans[i*i+j*j+k*k+i*j+j*k+k*i]++;
            }
        }
    }
    rep(i,1,n+1)cout<<ans[i]<<endl;
}


Measured memory_bytes: 3660
n = int(input())
task = [list(map(int, input().split())) for i in range(n)]
task = sorted(task, key=lambda x: x[1])

time = 0
for i in range(n):
  time += task[i][0]
  if time > task[i][1]:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 55264
mod = 1000000007
N = int(input())
A = list(map(int, input().split()))
S = [0] # 累積和のリスト
ans = 0
for i in range(N):
    S.append(A[i] + S[i] % mod)
for i in range(N):
    sum = S[N] - S[i + 1]
    if sum < 0:
        sum += mod
    ans += A[i] * sum
print(ans % mod)




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

int main()
{
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> a(N + 1, 0);
    for (int i = 0; i < M; i++)
    {
        int p;
        cin >> p;
        a[p] = 1;
    }
    int left = 0, right = 0;
    for (int i = X; 0 <= i; i--)
        left += a[i];
    for (int i = X; i < N + 1; i++)
        right += a[i];
    cout << min(left, right) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>

const int INF = 1001001001;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;


int main(){
    int n,k; cin >> n >> k;
    int ans;
    if(n%k==0){
        ans = 0;
    }else{
        ans = 1;
        
    }
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MAXVAL=100000;

int n;
int a[MAXN];
int cnt[MAXVAL];

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]);
	memset(cnt,0,sizeof(cnt));
	REP(i,n) ++cnt[a[i]];
	int ret=0;
	REP(i,MAXVAL) {
		int cur=0;
		FORE(di,-1,+1) {
			int ni=i+di; if(ni<0||ni>=MAXVAL) continue;
			cur+=cnt[ni];
		}
		if(cur>ret) ret=cur;
	}
	printf("%d\n",ret);
}

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


Measured memory_bytes: 1024
#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;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	int asum = 0, bsum = 0;
	int tmp;
	REP(i, 4){
		cin >> tmp;
		asum += tmp;
	}

	REP(i, 4){
		cin >> tmp;
		bsum += tmp;
	}

	cout << (asum > bsum ? asum : bsum) << endl;



}


Measured memory_bytes: 3120
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
a={}
N.times do|i|
    x=gets.to_i
    a[x]=0 if a[x].nil?
    a[x]+=1
end
ans=0
a.each do|key,n|
  ans+=1 if n.odd?
end
puts ans

Measured memory_bytes: 8572
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		System.out.println(Long.min(calc(h, w), calc(w, h)));
	}
	static long calc(long a, long b){
		if(a % 3 == 0) return 0;
		long min = b;
		for(long i = 1; i < a; i++){
			long x = i*b;
			long y = (a-i)*(b/2);
			long z = (a-i)*(b-b/2);
			ArrayList<Long> vals = new ArrayList<>();
			vals.add(x); vals.add(y); vals.add(z);
			Collections.sort(vals);
			min = Long.min(min, vals.get(2) - vals.get(0));
		}
		return min;
	}
}


Measured memory_bytes: 41932
N, L = map(int, input().split())
 
if L > -1:
  N_eat = 1
elif N+L-1 < 1:
  N_eat = N
else:
  N_eat = 1-L
 
pie = N*(N+1)/2 +N*(L-1) - (L + N_eat-1) 
print(int(pie) )

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,a[100005],pr[100005],rpr[100005];
LL res;
int powM(LL V,LL T=MOD1-2ll){
	LL R=1ll;
	while(T){
		if(T&1ll) R=(R*V)%MOD1;
		T>>=1ll;
		V=(V*V)%MOD1;
	}
	return R%MOD1;
}
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i) scanf("%d",a+i);
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
    pr[0]=1;
	for(i=1;i<=n;++i) pr[i]=((LL)pr[i-1]*(LL)i)%MOD1;
	rpr[n]=powM(pr[n]);
	for(i=n-1;i>=0;--i) rpr[i]=((LL)rpr[i+1]*(LL)(i+1))%MOD1;
	int pre=0,suf=0;
	for(i=n-1;i>=0;--i){
		pre=(pre+a[n-1-i])%MOD1;
		suf=(suf+a[i])%MOD1;
		if(!i) suf=0;
		res+=(LL)(pre+suf)*(LL)rpr[i+1]%MOD1*(LL)pr[i];
		res%=MOD1;
	}
	printf("%lld\n",res*pr[n]%MOD1);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

Measured memory_bytes: 1408
use std::io::*;
use std::str::FromStr;

pub 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")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let mut s = read::<String>();
  let mut a_idx = 1000000000;
  let mut z_idx = 0;

  for (i, v) in s.chars().enumerate() {
    if v == 'A' {
      a_idx = min(i, a_idx);
    }
    if v == 'Z' {
      z_idx = max(i, z_idx);
    }
  }
  println!("{}", z_idx - a_idx + 1);
}



Measured memory_bytes: 4352
N,K=list(map(int,input().split()))
h= []
for i in range(N):
    h.append(int(input()))
    
h.sort()
min_dif = 10**27
for i in range(N-K+1):
    min_dif=min(h[i+K-1]-h[i],min_dif)
print(min_dif)

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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;
const int MAXN = 2005;

ll fac[MAXN], inv[MAXN], invf[MAXN];

int n, k;

void init()
{
    fac[0] = 1;
    for (int i = 1; i <= 2000; i++)
        fac[i] = fac[i - 1] * i % MOD;
    inv[1] = 1;
    for (int i = 2; i <= 2000; i++)
        inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
    invf[0] = invf[1] = 1;
    for (int i = 2; i <= n; i++)
        invf[i] = invf[i - 1] * inv[i] % MOD;
}

ll C(int n, int m)
{
    if (n < m)
        return 0;
    return fac[n] * invf[m] % MOD * invf[n - m] % MOD;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    init();
    for (int i = 1; i <= k; i++)
        cout << C(n - k + 1, i) * C(k - 1, i - 1) % MOD << endl;
    return 0;
}


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

void solve() {
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N), F(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<int>());
    auto isOK = [&](long long x) -> bool {
        long long cnt = 0;
        rep(i, N) {
            long long n = x / F[i];
            cnt += max(A[i] - n, 0LL);
        }
        return cnt <= K;
    };
    long long l = -1, r = 1e13;
    while(r - l > 1) {
        long long mid = (l + r) / 2;
        if(isOK(mid)) r = mid;
        else l = mid;
    }
    cout << r << '\n';
}

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


Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val mod = 1000000007L
    fun divWithMod(a: Long, b: Long, mod: Long): Long {
        return ((a % mod) * java.math.BigInteger.valueOf(b).modInverse(java.math.BigInteger.valueOf(mod)).toLong()) % mod
    }

    fun calcFactors(n: Int): Map<Int, Int> {//素因数分解
        val factors = mutableMapOf<Int, Int>()
        var tmp = n
        var i = 2
        while (i * i <= tmp) {
            while (tmp % i == 0) {
                factors[i] = factors.getOrElse(i) { 0 } + 1
                tmp /= i
            }
            i++
        }
        if (tmp > 1) factors[tmp] = 1
        return factors
    }

    readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toLong).toLongArray()
    val totalFactors = mutableMapOf<Int, Int>()
    for (a in aList) {
        val factors = calcFactors(a.toInt())
        for (key in factors.keys) {
            totalFactors[key] = Math.max((totalFactors.get(key) ?: 0), factors[key]!!)
        }
    }

    var koubai = 1L
    for (key in totalFactors.keys) {
        for (i in 1..totalFactors[key]!!) {
            koubai *= key
            koubai %= mod
        }
    }
    var ans = 0L
    for (a in aList) {
        ans += divWithMod(koubai, a, mod)
        ans %= mod
    }
    println(ans)
}

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

int main() {
  int a;
  int b;
  int c;
  int d;
  int e;
  int f;
  cin >> a>>b>>c>>d>>e>>f;
  
  vector <int>  vec={a,b,c,d,e};
    sort(vec.begin(),vec.end());

  if ( abs((vec.at(0))-(vec.at(4))) <= f){
    cout << "Yay!"<< endl;
  }

 else{
   cout << ":(" <<endl;
 }
}
  




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string Sa,Sb,Sc;
int a=0,b=0,c=0;
char SA();
char SB();
char SC();

char SA(){
  if(a==Sa.size()){
    cout << 'A' << endl;
    return 'A';
  }
  if(Sa[a]=='a'){
    a++;
    SA();
  }
  else if(Sa[a]=='b'){
    a++;
    SB();
  }
  else if(Sa[a]=='c'){
    a++;
    SC();
  }

}
char SB(){
  if(b==Sb.size()){
    cout << 'B' << endl;
    return 'B';
  }
  if(Sb[b]=='a'){
    b++;
    SA();
  }
  else if(Sb[b]=='b'){
    b++;
    SB();
  }
  else if(Sb[b]=='c'){
    b++;
    SC();
  }
}
char SC(){
  if(c==Sc.size()){
    cout << 'C' << endl;
    return 'C';
  }
  if(Sc[c]=='a'){
    c++;
    SA();
  }
  else if(Sc[c]=='b'){
    c++;
    SB();
  }
  else if(Sc[c]=='c'){
    c++;
    SC();
  }
}

int main(){
  cin >> Sa >> Sb >> Sc;
  SA();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{
    vector<int> v(5);
    rep(i, 5) cin >> v[i];
    sort(ALL(v));
    int ans = 1 << 30;

    rep(i, 5)
    {
        int tmp = 0;
        rep(j, 5)
        {
            if (j == i)
            {
                tmp += v[j];
            }
            else
            {
                tmp += ((v[j] + 9) / 10) * 10;
            }
        }
        ans = min(ans, tmp);
    }

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


Measured memory_bytes: 256
//
//  main.cpp
//  AtCoder
//
//  Created by s on 2018/11/28.
//  Copyright © 2018 s. All rights reserved.
//

// ----------------------------------------------------------
// --https://kenkoooo.com/atcoder/#/table/soma62jp

// ----------------------------------------------------------

#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef long double LD;

#define LL MOD          (LL)1000000007
#define LL_INF          (LL)1 << 62
#define INT_INF         (int)1 << 30

#define rSort(a)        sort(a.rbegin(),a.rend())
#define Sort(a)         sort(a.begin(),a.end())
#define Reverse(a)      reverse(a.begin(),a.end())
#define Sum(a)          accumulate(a.begin(), a.end(), 0)
#define REP(i, n)       for(UI i = 0;i < n;i++)
#define REPR(i, n)      for(UI i = n;i >= 0;i--)
#define FOR(i, m, n)    for(UI i = m;i < n;i++)
#define pb(i)           push_back(i)
#define SWAP(x,y)       ((x!=y)&&(x^=y,y^=x,x^=y))

int main(int argc, char* argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;
    bool flg = true;
    
    cin >> S;
    
    for(int i=0;i<S.size();i++){
        if(i%2==0){
            if(!(S[i]=='R' || S[i]=='U' || S[i]=='D')){
                flg=false;
            }
        }else{
            if(!(S[i]=='L' || S[i]=='U' || S[i]=='D')){
                flg=false;
            }
        }
    }
    
    
    if(flg){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
    
}





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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;

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

	LL cnt = 0;
	LL sum = 0;
	LL i = 1;
	while (i <= n) {
		
		if (i % 3 != 0 && i % 5 != 0) {
			sum += i;
		}
		i++;
	}
	cout << sum << "\n";
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll A,B,C;
  cin >> A >>B>>C;
  string ans = (A + B + C) > 21 ? "bust" : "win";

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


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

var dp [401][401]int

func solve(f, t int, a []int) int {
	if f == t {
		return 0
	}
	if dp[f][t] != 0 {
		return dp[f][t]
	}
	s := 0
	ret := math.MaxInt64
	for i := f; i < t; i++ {
		r0 := solve(f, i, a)
		r1 := solve(i+1, t, a)
		ret = min(ret, r0+r1)
		s += a[i]
	}
	ret += s + a[t]
	dp[f][t] = ret
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N+1)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	ret := solve(0, N-1, a)
	out(ret)
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[100005];
ll memo[4005][4005];
ll prefix[100005];
ll getcost(int left,int right)
{
    return prefix[right+1]-prefix[left];
}
ll solve(int left,int right)
{
    if(left>=right) return 0;
    
    if(memo[left][right]!=-1) return memo[left][right];
    ll ret=1e18;
    for(int i=left;i<right;i++)
    {
        ret=min(solve(left,i)+solve(i+1,right)+getcost(left,i)+getcost(i+1,right),ret);
    }
    
    return memo[left][right]=ret;
    
}
int main()
{
    memset(memo,-1,sizeof(memo));
    int n;
    cin>>n;
    prefix[0]=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        prefix[i+1]=prefix[i]+arr[i];
    }
    
    ll ans=solve(0,n-1);
    printf("%lld\n",ans);
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int H,W; cin >> H >> W;
    int a[H][W]; REP(i,H)REP(j,W) cin >> a[i][j];

    VVI ans;
    REP(i,H){
        if(i%2){
            REP(j,W-1){
                if(a[i][W-j-1]%2){
                    a[i][W-j-1]--;
                    a[i][W-j-2]++;
                    ans.emplace_back(vector<int>{i+1,W-j,i+1,W-j-1});
                }
            }
            if(i<H-1){
                if(a[i][0]%2){
                    a[i][0]--;
                    a[i+1][0]++;
                    ans.emplace_back(vector<int>{i+1,1,i+2,1});
                }
            }
        }
        else{
            REP(j,W-1){
                if(a[i][j]%2){
                    a[i][j]--;
                    a[i][j+1]++;
                    ans.emplace_back(vector<int>{i+1,j+1,i+1,j+2});
                }
            }
            if(i<H-1){
                if(a[i][W-1]%2){
                    a[i][W-1]--;
                    a[i+1][W-1]++;
                    ans.emplace_back(vector<int>{i+1,W,i+2,W});
                }
            }
        }
    }

    cout << ans.size() << endl;
    REP(i,ans.size()){
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl;
    }
    return 0;
}

Measured memory_bytes: 9904
#include <bits/stdc++.h>
using namespace std;
#define var auto
#define Max std::max
#define Min std::min

#ifdef _MSC_VER
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#define fseek_unlocked fseek
#endif

inline uint16_t read()
{
	uint16_t x = 0;
	int k;
	while (true)
	{
		k = getchar_unlocked();
		if (k < '0') break;
		x = x * 10 + k - '0';
	}
	return x;
}

inline void writeline(uint16_t x) {
	int s = 0;
	char f[4];
	while (x) {
		f[s++] = x % 10;
		x /= 10;
	}
	while (s--)
		putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}

uint16_t rowMax[2000];
uint16_t columnAccum[2000];
int main()
{
	int h = read(), w = read();
	uint16_t max = 0;
	for (uint16_t i = 0; i < h; i++)
	{
		uint16_t currentChain = 0;
		for (uint16_t j = 0; j < w; j++)
		{
			if (getchar_unlocked() & 1)
			{
				max = std::max<uint16_t>(max, columnAccum[j] + rowMax[j]);
				for (uint16_t k = j - currentChain; k < j; k++)
					rowMax[k] = std::max<uint16_t>(rowMax[k], currentChain);
				currentChain = 0;
				rowMax[j] = 0;
				columnAccum[j] = 0;
			}
			else
			{
				currentChain++;
				columnAccum[j]++;
			}
		}
		for (uint16_t j = w - currentChain; j < w; j++)
			rowMax[j] = std::max<uint16_t>(rowMax[j], currentChain);
		getchar_unlocked();
	}
	for (uint16_t i = 0; i < w; i++)
		max = std::max<uint16_t>(max, columnAccum[i] + rowMax[i]);
	writeline(max - 1);
	return 0;
}


Measured memory_bytes: 256
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using i64 = boost::multiprecision::cpp_int;

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


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(std::vector<i64> t, std::vector<i64> a, std::vector<i64> b){
    vector<i64> v{(a[0] - b[0]), (a[1] - b[1])};
    if(t[0] * v[0] == - t[1] * v[1]){
        cout << "infinity" << endl;
        return;
    }
    if((v[0] >= 0) == (v[1] >= 0)){
        cout << 0 << endl;
        return;
    }
    if(a[0] > b[0]){
        swap(a[0], b[0]);
        swap(a[1], b[1]);
    }

    if(a[0] * t[0] + a[1] * t[1] < b[0] * t[0] + b[1] * t[1]){
        cout << 0 << endl;
        return;
    }

i64 ok = 0, ng = INF;

    auto f = [&](i64 k){
        i64 t1 = t[0] * a[0] + k * (t[0] * a[0] + t[1] * a[1]);
        i64 t2 = t[0] * b[0] + k * (t[0] * b[0] + t[1] * b[1]);
        return t1 <= t2;
    };

    while(abs(ok - ng) > 1){
        i64 mid = (ok + ng) >> 1;
        (f(mid) ? ok : ng) = mid;
    }
    i64 t1 = t[0] * a[0] + ok * (t[0] * a[0] + t[1] * a[1]);
    i64 t2 = t[0] * b[0] + ok * (t[0] * b[0] + t[1] * b[1]);
    i64 ans = 2 * ok + 1;
    if(t1 == t2){
        --ans;
    }
    cout << (long long)(ans) << endl;
}


signed main(){
    std::vector<long long> T(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&T[i]);
    }
    std::vector<long long> A(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&B[i]);
    }
    vector<i64> t(2), a(2), b(2);
    for(int i = 0 ; i < 2 ; i++){
        t[i] = T[i];
        a[i] = A[i];
        b[i] = B[i];
    };
    solve(std::move(t), std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 384
#include <stdlib.h>
#include <iostream>
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if(a == b){
		cout << "Draw" << endl;
	}else{
		if(a == 1 || (b != 1 && a > b)){
			cout << "Alice" << endl;
		}else{
			cout << "Bob" << endl;
		}
	}
	return 0;
}


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

using namespace std;
#define ll long long
#define M 1000000007
vector<ll>arr[100005];
vector<ll>mark(100005,0);
vector<ll>topo;

int main()
{
    ll n,m;
    cin>>n>>m;
    vector<char>maze[n];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            char ch;
            cin>>ch;
            maze[i].push_back(ch);
        }
    }
    ll dp[n+1][m+1];
    for(ll i=0;i<=n;i++)
        for(ll j=0;j<=m;j++)
            dp[i][j]=0;
    dp[1][1]=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(!(i==1 && j==1))
            if(maze[i-1][j-1]=='.')
            {
                ll left=0,up=0;
                if(i-1 > 0)
                    up=dp[i-1][j];
                if(j-1 >0)
                    left=dp[i][j-1];
                dp[i][j]=(left+up)%M;
            }
        }
    }
    cout<<dp[n][m];
   
}

Measured memory_bytes: 12288
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().ToCharArray();
        var text = new List<char>();
        foreach (var i in s)
        {
            if (i == '1') text.Add('1');
            else if (i == '0') text.Add('0');
            else if (i == 'B' && text.Count != 0) text.RemoveAt(text.Count - 1);
        }
        Console.WriteLine(new String(text.ToArray()));
    }
}



Measured memory_bytes: 11092
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#define INF 1e8
using namespace std;
#define ll long long

#define MAX 100020
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#define INF 1e8
using namespace std;
#define ll long long

#define MAX 100020

int main(){
string a,b;

int n;
string s;
cin>>n>>a>>b;

for(int i=0;i<n;i++){
   cout<<a[i]<<b[i] ;
}
}

Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;

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

const int MAXN = 110, N = 0, E = 1, NE = 2, EN = 3;
unsigned int dp[MAXN][MAXN][4];
unsigned int UB = 100000;

int main()
{
    int w, h;
    while(cin >> w >> h && w || h)
    {
        memset(dp, 0, sizeof(dp));
        dp[0][0][N] = 1; dp[0][0][E] = 1;

        rep(i,w - 1) dp[i+1][0][E] = dp[i][0][E];
        rep(j,h - 1) dp[0][j+1][N] = dp[0][j][N];

        rep(i,w) rep(j, h)
        {
            dp[i+1][j+1][E] = (dp[i][j+1][E] + dp[i][j+1][NE]) % UB;
            dp[i+1][j+1][N] = (dp[i+1][j][N] + dp[i+1][j][EN]) % UB;
            dp[i+1][j+1][EN] = dp[i+1][j][E];
            dp[i+1][j+1][NE] = dp[i][j+1][N];
        }
        /*rep(j, h)rep(i,w)
        {
            dp[i][j][N] %= UB; dp[i][j][E] %= UB; dp[i][j][NE] %= UB; dp[i][j][EN] %= UB;
            dp[i+1][j][NE] =  dp[i][j][N];
            dp[i+1][j][E] =  dp[i][j][NE] + dp[i][j][E];
            dp[i][j+1][EN] = dp[i][j][E];
            dp[i][j+1][N] =  dp[i][j][EN] + dp[i][j][N];
        
        }*/
        /*rep(j, h)rep(i,w)
        {
            dp[i+1][j][NE] = ( dp[i+1][j][NE] + dp[i][j][N]) % UB;
            dp[i+1][j][E] = (dp[i+1][j][E] + dp[i][j][NE] + dp[i][j][E]) % UB;
            dp[i][j+1][EN] = (dp[i][j+1][EN] + dp[i][j][E]) % UB;
            dp[i][j+1][N] = (dp[i][j+1][N] + dp[i][j][EN] + dp[i][j][N]) % UB;
        }*/
        int ans = 0;
        REP(4){ ans = (ans + dp[w-1][h-1][i]) % UB; }
        cout << ans << endl;

    }

    return 0;
}

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

using namespace std;
#define int long long
const int N = 6666;
int n,arr[N];
int check(int a,int b,int c){
	if((a+b>c)&&(a+c>b)&&(b+c>a)&&a!=b&&a!=c&&c!=b) return 1;else return 0;
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>arr[i];
	sort(arr+1,arr+1+n);
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			for(int k=j+1;k<=n;k++){
				if(check(arr[i],arr[j],arr[k])){
					ans++;
				}
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)

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

void Main(){
  string S_, T; cin >> S_ >> T;
  int N, M;
  N = S_.size();
  M = T.size();
  vector<string> LIST;
  for(int i = N - M; i >= 0; i--){
    string S = S_;
    bool ok = true;
    for(int j = 0; j < M; j++){
      if(S[i + j] != T[j] && S[i + j] != '?') ok = false;
    }
    if(ok){
      for(int j = 0; j < M; j++){
        S[i + j] = T[j];
      }
      for(int j = 0; j < N; j++){
        if(S[j] == '?') S[j] = 'a';
      }
      LIST.push_back(S);
    }
  }
  if(LIST.size() == 0){
    cout << "UNRESTORABLE" << endl;
  }else{
    sort(all(LIST));
    cout << LIST[0] << endl;
  }
  return;
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


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

int main() {
  long long cnt[5], n;
  string tmp;

  cin >> n;

  rep(i, 5) cnt[i] = 0;

  rep(i, n) {
    char x;
    cin >> tmp;
    x = tmp[0];
    if (x == 'M') {
      cnt[0]++;
    } else if (x == 'A') {
      cnt[1]++;
    } else if (x == 'R') {
      cnt[2]++;
    } else if (x == 'C') {
      cnt[3]++;
    } else if (x == 'H') {
      cnt[4]++;
    }
  }


  long long ans = 0;
  rep(i, 5) {
    for (int j = i+1; j < 5; j++) {
      for (int k = j+1; k < 5; k++) {
        ans += cnt[i] * cnt[j] * cnt[k];
      }
    }
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll      long long int   
#define ld      long double
#define pii     pair<int ,int>
#define pld     pair<ld ,ld>
#define all(v)  v.begin(),v.end()
#define F       first
#define S       second
#define mod     1000000007
#define pb      push_back
#define MP      make_pair
#define mset(x) memset(x, 0, sizeof(x));
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf     1000000000000000007
const int N=100006;
ll gcd(ll x,ll y){
    if(!y) return x;
    return gcd(y,x%y);
}
void run(){
   
ll a,b;
cin>>a>>b;
ll g=gcd(a,b);
ll i,ans=1;
for(i=2;i*i<=g;i++)
{
    if(g%i==0)
    {
        ans++;
        while(g%i==0) g/=i;
    }
}
if(g!=1) ans++;
cout<<ans;



}
 
 
void setup(){
    ios;
    //cout << setprecision(20);
    // #ifndef ONLINE_JUDGE
    // freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    // #endif
}
 
signed main(){
    setup();
    int tests = 1;
    //cin >> tests;
    for(int i = 1; i <= tests; i++) run();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S,T = map(str,input().split())
ans = []
j = 0
k = 0
for i in range(2*N):
    if i%2 == 0:
        ans.append(S[j])
        j += 1
    else:
        ans.append(T[k])
        k += 1

print("".join(ans))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n, k;
    ll l, r;
    cin >> n >> k >> l >> r;
    ll a[n];
    rep (i, 0, n) cin >> a[i];

    vector<vector<ll>> L (k + 1), R (k + 1);
    for (int bit = 0; bit < (1 << (n / 2)); bit++) {
        ll sum = 0;
        if (__builtin_popcount (bit) > k) continue;
        for (int i = 0; i < n / 2; i++) {
            if (bit & (1 << i)) {
                sum += a[i];
            }
        }
        L[__builtin_popcount (bit)].push_back (sum);
    }
    rep (i, 0, k + 1) {
        sort (L[i].begin(), L[i].end());
        // cout << L[i].size() << "\n";
    }
    for (int bit = 0; bit < (1 << (n - n / 2)); bit++) {
        ll sum = 0;
        if (__builtin_popcount (bit) > k) continue;
        for (int i = 0; i < n - n / 2; i++) {
            if (bit & (1 << i)) {
                sum += a[n / 2 + i];
            }
        }
        R[__builtin_popcount (bit)].push_back (sum);
    }
    ll ans = 0;
    rep (i, 0, k + 1) {
        rep (j, 0, R[i].size()) {
            if (R[i][j] > r) continue;
            ll sum =
                upper_bound (L[k - i].begin(), L[k - i].end(), r - R[i][j]) -
                lower_bound (L[k - i].begin(), L[k - i].end(), l - R[i][j]);
            ans += sum;
        }
    }
    cout << ans << "\n";
}


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

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

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

using namespace std;

int mat[3][3];
int vis[3][3];

int main() {

	for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) scanf("%d", &mat[i][j]);
	int n;
	scanf("%d", &n);
	while(n--) {
		int x;
		scanf("%d", &x);
		for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) if(mat[i][j] == x)
			vis[i][j] = 1;
	}

	for(int i = 0; i < 3; i++) {
		int a = 0, b = 0;
		for(int j = 0; j < 3; j++) {
			a += vis[i][j];
			b += vis[j][i];
		}
		if(a == 3 or b == 3) return printf("Yes\n"), 0;
	}
	if(vis[0][0] + vis[1][1] + vis[2][2] == 3 or vis[0][2] + vis[1][1] + vis[2][0] == 3)
		return printf("Yes\n"), 0;
	printf("No\n");
}


Measured memory_bytes: 256
call :: Int -> [Int]
call n = f 1
    where
        f x
            | x > n = []
            | x `mod` 3 == 0 = x: f (x+1)
            | any ((== 3) . (`mod` 10)) . takeWhile (/= 0 ) . iterate (`div` 10) $ x
                = x: f(x+1)
            | otherwise = f (x+1)
 
main = readLn >>= putStrLn . concatMap ((' ':) . show) . call

Measured memory_bytes: 4092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int a, b, x;
  cin >> a >> b >> x;

  bool isok = x >= a && x <= a+b;
  if (isok) puts("YES");
  else puts("NO");
  return 0;
}

Measured memory_bytes: 256