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

using namespace std;

int a[200001];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    long answer = n, sum = a[0];
    long l = 0, r = 0;
    while (l < n) {
        while (r < n - 1 && sum + a[r + 1] == (sum ^ a[r + 1])) {
            sum ^= a[++r];
        }
        answer += r - l;
        sum ^= a[l];
        ++l;
    }
    cout << answer << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)

using namespace std;



int main() {
	int i, j, k;
	int n;
	int s[100];
	cin >> n;
	rep(i, 0, n)
		cin >> s[i];
	sort(s, s + n);
	int ans = 0;
	int d = -1;
	rep(i, 0, n) {
		ans += s[i];
		if ((s[i] % 10 != 0)&(d == -1)) {
			d = s[i];
		}
	}
	if (d == -1) {
		cout << "0" << endl;
	}
	else if (ans % 10 != 0) {
		cout << ans << endl;
	}
	else {
		cout << ans - d << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	
	int n, p;
	string s;
	cin >> n >> p >> s;

	int gcd = __gcd(10, p);

	if(gcd != 1){
		// gcd is either, 2, 5
		assert(gcd == 2 || gcd == 5);
		ll res = 0;
		for(int i = 0; i < n; ++i){
			if((s[i] - '0') % gcd == 0)
				res += i + 1;
		}
		cout << res << endl;
		return 0;
	}

	unordered_map<int, int> mp;
	mp[0] = 1;
	ll res = 0;
	int cur = 0;
	int pw = 1;
	for(int i = n - 1; i >= 0; --i){
		cur = (cur + pw * (s[i] - '0')) % p;
		res += mp[cur];
		mp[cur]++;
		pw = (pw * 10) % p;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<(b);++i)
#define erep(i,a,b) for(ll i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
ll dp[600000], val[] = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};

ll solve(ll x) {
    if (dp[x] >= 0) return dp[x];
    ll t = INF;
    for (ll k : val) {
        if (x < k) break;
        t = min(solve(x-k) + 1, t);
    }
    return dp[x] = t;
}
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    cout << solve(n) << endl;
    return 0;
}


Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;
typedef long long ll;
double *dp;




void solve(){
	
	int  N;
	int ans = 1;
	string S;
	cin >> N >> S;

	char pre = S[0];
	
	for (int i = 1;i < N;i++) {
		if (pre != S[i]) {
			ans++;
			pre = S[i];
		}
	}
	cout << ans << endl;
	
}


int main() {
	solve();

}

Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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


int main(){fastio
    
    ll n,k;cin>>n>>k;
    ll ans=k;
    rep(i,1,n-1){
        ans=ans*(k-1);
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N <= 10^5
# Nは偶数
N = int(stdin.readline().rstrip())
d = list(map(int, stdin.readline().rstrip().split()))

d.sort()

right = N // 2
left = right - 1

print(d[right] - d[left])

Measured memory_bytes: 77904
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main (){
    
    /*?´???°???????´?????????????*/
    vector<int>Primenumber(MAX+1,0);
    /*?´???°???????´???????????????????*/
    int n;
    while(cin >> n){
        bv check(MAX+1,true);
    for(int i = 2; i<=n;i++){
        if(check[i]){
            /*true?????£?????¨???????????°????????????false??§*/
            for(int j = 2;i*j<=n;j++)
                check[i*j] = false;
        }
    }
    int ans = 0;
    for(int i = 2;i<=n;i++)
        if(check[i])
            ans++;
    cout << ans << endl;
    }
}

Measured memory_bytes: 6520
import math
a=int(input())
ans=0
c=[[0 for i in range(10)] for j in range(10)]
for i in range(1,a+1):
  aa=str(i)
  c[int(aa[0])][int(aa[-1])]+=1
for i in range(10):
  for j in range(10):
    ans+=c[i][j]*c[j][i]
print(ans)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    int N,A,B;
    cin >> N >> A >> B;
    int ans = min(A*N,B);
    cout << ans << 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++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

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

Measured memory_bytes: 3596
import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        System.out.println(calc(n));
    }
    
    private static String calc(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1;i <= n;i++) {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        }
        return sb.toString();
    }
    
    private static boolean isDiv(int n) { return n%3==0; }
    private static boolean isContain(int n) {
        String s = String.valueOf(n);
        String t = "3";
        for (int i = 0;i < s.length(); i++) {
            if (s.substring(i, i+1).equals(t)) return true;
        }
        return false;
    }
}

Measured memory_bytes: 29708
#!/usr/bin/env python3
# input

n = int(input())
ans = n * (n + 1) - 1  # 1とk 自信

i = 2
while i * i <= n:
    num = n // i
    min_i = i * i
    max_i = i * num
    ans += (num - i + 1) * (min_i + max_i)  # 自分自身
    ans -= min_i
    i += 1
print(ans)


Measured memory_bytes: 9068
# coding: utf-8
# Your code here!

n,a,b,c,d = [int(i)-1 for i in input().split()]
n+=1
s = input()

def check(x,y):
    ok = 1
    num = 0
    for moji in s[x:y]:
        if moji == "#":
            num+=1
        else:
            num = 0
        if num >= 2:
            ok = 0
            break
    return ok

def check3(x,y):
    ok = 0
    num = 0
#    print(s)
#    print(s[x-1:y+2],x,y)
    for moji in s[x-1:y+2]:
        if moji == ".":
            num+=1
        else:
            num = 0
        if num >= 3:
            ok = 1
            break
    return ok


if c < d:
    if check(a,c) and check(b,d):
        print("Yes")
    else:
        print("No")

else:
    if check3(b,d) and check(a,c):
        print("Yes")
    else:
        print("No")
    

Measured memory_bytes: 3572
#include <stdio.h>

int main()
{
    int in, n[3], out;
    int i;


    scanf("%d", &in);
    
    n[0] = in / 100;
    n[1] = in / 10 - n[0]*10;
    n[2] = in - (n[0]*100 + n[1]*10);
//printf("%d\n", in - (n[0]*100 + n[1]*10));

    for(i = 0 ; i < 3 ; i++){
        if(n[i] == 1)
        n[i] = 9;
        else if(n[i] == 9)
        n[i] = 1;
    }

out = n[0] * 100  + n[1]  * 10 + n[2];

    printf("%d", out);
    return 0;

}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の標準入力
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] xCityCoordinate = new int[n];
		int[] xDifference = new int[n];
		// 整数nの数だけ標準入力
		for(int i = 0; i < n; i++) {
			xCityCoordinate[i] = sc.nextInt();
			xDifference[i] = Math.abs(x - xCityCoordinate[i]);
		}
		Arrays.sort(xCityCoordinate);
		Arrays.sort(xDifference);
		for(int i = 0; i < n; i++) {
			if(xDifference[i] % xDifference[0] != 0) {
				while(true) {
					xDifference[0] = xDifference[0] - 1;
					if(xDifference[i] % xDifference[0] == 0) {
						break;
					}
				}
			}
		}
		System.out.println(xDifference[0]);
		sc.close();
	}
}

Measured memory_bytes: 62480
// Date: 2020-04-07

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, p[N];
pii a[N], b[N];

struct edge {
    int u, v, w;
    bool operator < (const edge& r) const { return w < r.w; }
} E[N];

int Find(int x) {
    return x == p[x] ? x : p[x] = Find(p[x]);
}

int main() {
    FIO;
    cin >> n;
    rep(i, 1, n) {
        p[i] = i;
        int u, v;
        cin >> u >> v;
        a[i] = mk(u, i);
        b[i] = mk(v, i);
    }
    sort(a+1, a+1+n);
    sort(b+1, b+1+n);
    int tot = 0;
    rep(i, 2, n) E[++tot] = {a[i].se, a[i-1].se, a[i].fi-a[i-1].fi}, E[++tot] = {b[i].se, b[i-1].se, b[i].fi-b[i-1].fi};
    sort(E+1, E+1+tot);
    LL ans = 0;
    rep(i, 1, tot) {
        int u = E[i].u, v = E[i].v;
        int fu = Find(u), fv = Find(v);
        if(fu != fv) p[fu] = fv, ans += E[i].w;
    }
    cout << ans;

    return 0;
}

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

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

int main() {
  int n ;
  cin >> n ;
  
  cout << n*(n+1)/2 ;


}


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

int main()
{
  long long a, b, c;
  cin >> a >> b >> c;
  long long af, bf, cf, count = 0;

  while(true)
  {
    if ((a % 2 == 1) || (b % 2 == 1) || (c % 2 == 1))
    {
      cout << count << endl;
      exit(0);
    }

    if (a == b && b == c)
    {
      cout << -1 << endl;
      exit(0);
    }

    count++;
    
    af = a / 2;
    bf = b / 2;
    cf = c / 2;

    a = (bf + cf);
    b = (cf + af);
    c = (af + bf);
  }

}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
res = 0

while True:
    if sum(h) == 0:
        break

    i = 0
    while i < n:
        if h[i] == 0:
            i += 1
        else:
            res += 1
            while i < n and h[i] > 0:
                h[i] -= 1
                i += 1

print(res)


Measured memory_bytes: 9096
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};


int main(){
    IOS;
    make(ll,n);
    ll m=n%1000;
    if(m==0) cout<<"0 \n";
    else cout<<1000-m<<endl;



    return 0;
}


Measured memory_bytes: 3496
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  for (int i = 0;i < s.size();i++){
  if (s.at(i) == t.at(i)){
  if (i == s.size()-1){
    cout << "Yes";
  }
  }
  else{
  cout << "No";
    break;
  }
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int H, W;
vector<vector<char>> S(60, vector<char>(60, '.'));

int Getnum(int y, int x){
    int sum = 0;
    for(int i = y; i <= y + 2; ++i){
        for(int j = x; j <= x + 2; ++j){
            if(i == y + 1 && j == x + 1) continue;
            if(S[i][j] == '#') ++sum;
        }
    }
    return sum;
}

int main(void){
    
    scanf("%d %d", &H, &W);
    for(int i = 1; i <= H; ++i){
        string s; cin >> s;
        for(int j = 1; j <= W; ++j) S[i][j] = s[j - 1];
    }
    
    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j){
            if(S[i][j] == '#') printf("#");
            else printf("%d", Getnum(i - 1, j - 1));
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 256
#define Z(x,i)(x[i]+x[n/2+i])
x[99],y[99],X,Y;
n,i;main(){
	for(gets(x);~scanf("%d %d",x+n,y+n);n++);
	if(!(n&1))for(X=Z(x,0),Y=Z(y,0);++i<n/2&&Z(x,i)==X&&Z(y,i)==Y;);
	printf(i==n/2?"%f %f\n":"NA\n",X/2.0,Y/2.0);exit(0);
}

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

int main() {
	int n;
	cin >> n;
	ll a[100005], b[100005], c[100005];
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n; i++) cin >> c[i];

	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);

	ll cnt_a[100005], cnt_b[100005];
	for (int i = 0; i < n; i++) {
		cnt_a[i] = (upper_bound(b, b + n, a[i]) - b);
		cnt_b[i] = ((c + n - 1) - upper_bound(c, c + n, b[i])) + 1;
	}
	ll sum = 0;
	for (int i = n - 1; i >= 0; i--) {
		sum += cnt_b[i];
		cnt_b[i] = sum;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (cnt_a[i] < n)
			ans += cnt_b[cnt_a[i]];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4096
MOD  = 1000000007

N = int(input())
S1 = input()
S2 = input()

if S1[0] == S2[0]:
  	ans, idx = 3, 1
else:
  	ans, idx = 6, 2

while idx < N:
    if S1[idx] == S2[idx]:
        if S1[idx-1] == S2[idx-1]:
            ans *= 2
        idx += 1
    else:
        if S1[idx-1] == S2[idx-1]:
            ans *= 2
        else:
            ans *= 3
        idx += 2
    ans %= MOD
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring> //memset
#include <cmath>
#include <limits>
#include <queue>
using namespace std;


int main()
{
	long long A, B, C;

	cin >> A >> B >> C;

	long long lastA = A - B;

	if (C <= lastA) {
		cout << 0 << endl;
	}
	else {
		cout << C - lastA << endl;
	}

	return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  std::string C;
  std::cin >> C;

  C[0]++;
  put(C);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define MOD 10000007
#define PB push_back
#define PI 3.14159265359
 
using namespace std;

int main(){


    double a;
    cin >> a;

    cout << a*PI*2 <<endl;
}


Measured memory_bytes: 3788
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut vv: [usize; n]
    };

    vv.sort();
    let mut cur = vv[0] as f64;
    for i in 1..n {
        cur = (cur + vv[i] as f64) / 2.0;
    }
    println!("{}", cur);
}


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

std::vector<int> vec;
int n, ans=0;

int main() {
    std::cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i%2 == 0)
            continue;
        int c = 0;
        for (int j = 1; j*j <= i; j++) {
            if (i%j == 0) {
                c++;
                if (i/j != j) {
                    c++;
                }
            }
        }
        if (c == 8) {
            ans++;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
vector<int> g[100005];
lint ar[100005];

void ng(){
  puts("NO");
  exit(0);
}

lint dfs(int v,int p){
  lint chsum=0;
  int ch=0;
  lint mxc=0;
  for(auto to:g[v]){
    if(to==p) continue;
    lint X=dfs(to,v);
    chsum+=X;
    chmax(mxc,X);
    ++ch;
  }
  if(ch==0) return ar[v];

  lint lb=max((chsum+1)/2,mxc),ub=chsum;
  if(ar[v]<lb || ub<ar[v]) ng();
  lint rev=ub-ar[v];
  return ub-rev*2;
}
int main(){
  cin>>n;
  REP(i,n) scanf("%lld",&ar[i]);
  if(n==2){
    if(ar[0]==ar[1]) puts("YES");
    else puts("NO");
    exit(0);
  }
  REP(i,n-1){
    int a,b;scanf("%d%d",&a,&b);--a;--b;
    g[a].pb(b);
    g[b].pb(a);
  }
  int R=-1;
  REP(i,n) if(g[i].size()>1) R=i;
  lint a=dfs(R,-1);
  puts(a==0?"YES":"NO");
  return 0;
}





Measured memory_bytes: 13568
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define mod 1000000007
#define MOD 99824435300000000
inline ll mul(ll a,ll b){
  a=(a+MOD)%MOD;
  b=(b+MOD)%MOD;
  ll c=a*b;
  c=(c+MOD)%MOD;
  return c;
}
inline ll add(ll a,ll b){
  a=(a+MOD)%MOD;
  b=(b+MOD)%MOD;
  ll ans=(a+b);
  ans=(ans+MOD)%MOD;
  return ans;
}

ll power(ll a,ll b,ll c){
  ll ans=1;
  while(b){
    if(b&1){
      ans=mul(ans,a);
    }
    a=mul(a,a);
    b=b/2;
  }
  return ans;
}
inline ll max(ll a,ll b){return a>b?a:b;}
inline ll min(ll a,ll b){return a<b?a:b;}
ll find(std::vector<std::vector<ll> > &v,int ind,int w,ll a[][2],int n){
  if(w<0)return -MOD;
  if(ind==n)return 0;
  if(v[ind][w]!=-1)return v[ind][w];
  ll xx=find(v,ind+1,w,a,n);
  ll yy=a[ind][1]+find(v,ind+1,w-a[ind][0],a,n);
  return v[ind][w]=max(xx,yy);
}
int main()
{
  ll n,w; cin>>n>>w;
  ll a[n][2];
  for(int i=0;i<n;++i)cin>>a[i][0]>>a[i][1];
  vector<vector<ll> > dp(101,vector<ll>(100001,INT_MAX));
  dp[0][0]=0;
  for(int i=1;i<=n;++i){
    for(int j=0;j<=100000;++j)dp[i][j]=dp[i-1][j];
    for(int j=0;j<=100000;++j){
      if(dp[i-1][j]!=INT_MAX){
        dp[i][j+a[i-1][1]]=min(dp[i][j+a[i-1][1]],a[i-1][0]+dp[i-1][j]);
      }

      }
    }
    ll ans=0;
    for(int i=1;i<=n;++i){
      for(int j=1;j<=100000;++j){
        if(dp[i][j]<=w)ans=max(ans,j);
      }
    }
    cout<<ans;
  return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

int A, B, C, D;

int main(int argc, char **argv) {
    std::cin >> A >> B >> C >> D;
    
    std::cout << std::max(A*B, C*D) << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int h, w; cin >> h >> w;
    vector<string> s(h);
    REP(i, h) cin >> s[i];
    for(int i = 0; i <= w + 1; i++) cout << '#';
    cout << endl;
    REP(i, h){
        cout << '#' << s[i] << '#' << endl;
    }
    for(int i = 0; i <= w + 1; i++) cout << '#';
    cout << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N,i,j,A[100],count = 0,temp,flag=1; 
   scanf("%d",&N);

   for(i = 0;i < N;i++){
     scanf("%d",&A[i]);
     
   }
 
  i=0;
  while(flag){
    flag = 0;
    for(j = N-1;j > i;j--){
      if(A[j] < A[j-1]){
        temp = A[j];
        A[j] = A[j-1];
        A[j-1] = temp;

        flag = 1;
        count++;
      }
     
    }i++;
  }

  for(i=0;i<N;i++){
    if(i!=0)printf(" ");
    printf("%d",A[i]);
    
  }
  printf("\n%d\n",count);
  /*for(i = 0;i < N-1;i++) printf("%d ",A[i]);
  printf("%d\n",A[i]);
 printf("%d\n",count);
  */
  return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
const int e[40]={0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,
                 5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8};
int main(void)
{
  int i,x;
  long long a=0,N;
  x=scanf("%lld",&N)-1;
  while(N%2==0){x++;N/=2;}
  a+=e[x];
  for(i=3;i<=1e6;i+=2)
  {
    x=0;while(!(N%i))x++,N/=i;
    a+=e[x];
  }
  if(N>1)a++;
  return printf("%lld\n",a),0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT32_MAX;

ll i,j;





int main(){
   string S;
   cin>>S;
   if(S[0]=='7'||S[1]=='7'||S[2]=='7')cout<<"Yes"<<endl;
   else cout<<"No"<<endl; 
}

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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("E.in", "r", stdin);
	freopen ("E.out", "w", stdout);
#endif
}

const int N = 1010;

int xs, ys, xt, yt;
int n, x[N], y[N], r[N];

double dis[N][N], d[N]; bitset<N> vis;

void Dijkstra() {
	For (i, 0, n) d[i] = 3e9;
	int u = 1; d[1] = 0;
	For (i, 1, n) {
		vis[u] = true;
		if (u == 2) return ;
		int v = 0;
		For (j, 1, n) {
			chkmin(d[j], d[u] + dis[u][j]);
			if (!vis[j] && d[j] < d[v]) v = j;
		}
		u = v;
	}
}

inline long long Sqr(int x) {
	return 1ll * x * x;
}

int main () {

	File();

	x[1] = read(); y[1] = read();
	x[2] = read(); y[2] = read();

	n = read() + 2;

	For (i, 1, n) {
		if (i > 2)
			x[i] = read(), y[i] = read(), r[i] = read();
		For (j, 1, i - 1) {
			dis[i][j] = dis[j][i] = max(.0, sqrt(Sqr(x[i] - x[j]) + Sqr(y[i] - y[j])) - (r[i] + r[j]));
	//		cout << i << ' ' << j << ' ' << dis[i][j] << endl;
		}
	}
	Dijkstra();
	
	printf ("%.10lf\n", d[2]);

	return 0;

}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

signed main(){
  ll H, W; cin >> H >> W;
  ll ans1, ans2, ans3 = 1e18, ans4 = 1e18;
  if(H % 3 == 0) ans1 = 0;
  else ans1 = W;
  if(W % 3 == 0) ans2 = 0;
  else ans2 = H;
  for(int i = 1; i < H; i++){
    vector<ll> x(3);
    if(i <= H / 2){
      x[0] = i * W;
      if(W % 2 == 0) x[1] = (H - i) * W / 2, x[2] = x[1];
      else x[1] = (H - i) * (W / 2), x[2] = x[1] + H - i;
    }
    else{
      x[0] = (H - i) * W;
      if(W % 2 == 0) x[1] = H * W / 2, x[2] = x[1];
      else x[1] = i * (W / 2), x[2] = x[1] + i;
    }
    sort(x.begin(), x.end());
    ans3 = min(ans3, x[2] - x[0]);
  }
  for(int j = 1; j < W; j++){
    vector<ll> x(3);
    if(j <= W / 2){
      x[0] = H * j;
      if(H % 2 == 0) x[1] = (W - j) * H / 2, x[2] = x[1];
      else x[1] = (W - j) * (H / 2), x[2] = x[1] + W - j;
    }
    else{
      x[0] = H * (W - j);
      if(H % 2 == 0) x[1] = j * H / 2, x[2] = x[1];
      else x[1] = j * (H / 2), x[2] = x[1] + j;
    }
    sort(x.begin(), x.end());
    ans4 = min(ans4, x[2] - x[0]);
  }
  vector<ll> ans = {ans1, ans2, ans3, ans4};
  cout << *min_element(ans.begin(), ans.end()) << endl;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  string s, t;
  cin >> s >> t;

  // 作れるか判定
  map<char, bool> tojo;
  for (int i = 0; i < s.size(); i++) tojo[s[i]] = true;
  for (int i = 0; i < t.size(); i++) {
    if (tojo[t[i]] != true) {
      cout << -1 << endl;
      return 0;
    }
  }

  ll dist[s.size()][26];  // 何文字先にabcd…があるか
  for (char c = 0; c < 26; c++) {
    ll count = INF;
    for (int i = s.size() - 1; i >= 0; i--) {  // 1周目
      dist[i][c] = count;
      if (s[i] - 'a' == c) count = 0;
      count++;
    }
    for (int i = s.size() - 1; i >= 0; i--) {  // 2周目
      dist[i][c] = count;
      if (s[i] - 'a' == c) count = 0;
      count++;
    }
  }

  ll ans = dist[s.size() - 1][t[0] - 'a'], now = dist[s.size() - 1][t[0] - 'a'] - 1;
  for (int i = 0; i < t.size() - 1; i++) {
    ans += dist[now][t[i + 1] - 'a'];
    now = (now + dist[now][t[i + 1] - 'a']) % s.size();
  }
  cout << ans << endl;
}


Measured memory_bytes: 20864
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter 
from itertools import combinations
def main():
    N = int(readline())
    S = readline().rstrip().decode()
    d = Counter(S)
    sg = d['R']*d['G']*d['B']
    cnt = 0
    for i, j in combinations([int(i) for i in range(N)], 2):
        if (i+j)%2 == 0:
            m = (i+j)//2
            if (S[i]!=S[j]) and (S[j]!=S[m]) and (S[m]!=S[i]):
                cnt += 1
    print(sg-cnt)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9460
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

const double pi = atan(1) * 4;
double a, b, x;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> a >> b >> x;
	cout << fixed << setprecision(8);
	double t = 2 * x / (a * a) - b;
	if (t > 0) cout << atan((b - t) / a) * 180/pi;
	else
	{
		t = 2 * x / a / b;
		cout << atan(b / t) * 180/pi;
	}
}

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

int main() {
    long long int n, cnt=0;
    cin >> n;
    while(n>=500) {
        n=n-500;
        cnt=cnt+1000;
    }
    while(n>=5) {
        n=n-5;
        cnt=cnt+5;
    }
    cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
//const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p, ll mod){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x, ll mod){return binpow(x, mod - 2, mod);}

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

	ll k, i, cnt = 0;
	cin >> k;
	if(k % 2 == 0 || k % 5 == 0)
	{
		cout << -1 << endl;
		return 0;
	}
	k *= 9;
	//ll y = modinv(9LL, k);
	//pr(y);
	// ll x = k;
	// while(x > 0)
	// {
	// 	cnt++;
	// 	x /= 10;
	// }
	//pr(cnt);
	rep(i, 1, 1e6 + 100)
	{
		if(((7LL * ((binpow(10, i, k) - 1LL + k) % k) % k)% k) == 0)
			break;
	}
	if(i == 1e6 + 100)
		cout << -1 << endl;
	else
		cout << i << endl;
}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int id1 = 0;
		int id2 = 0;
		int hantei = 0;
		for(int i =0;i<s.length();i++) {
			if(s.charAt(i) =='A' && hantei ==0) {
				hantei = 1;
				id1 =i;
			}
			if(s.charAt(i)=='Z' && hantei == 1) {
				id2 =i;
			}
		}
		System.out.println(id2-id1+1);
		
	}

}



Measured memory_bytes: 26764
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  int a[220000];
  for(i=1;i<=n;i++){
    cin >> a[i];
  }
  int current=1;
  int cheakpoint=1;
  int ans=0;
  bool flag=false;
  for(i=1;i<=n;i++){
    if(a[i]!=current){
      continue;
    }
    else if(a[i]==current){
      ans+=i-cheakpoint;
      cheakpoint=i+1;
      current++;
      flag++;
    }
  }
  ans+=n-cheakpoint+1;
  if(flag){
    cout << ans;
  }
  else{
    cout << "-1";
  }
  return(0);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  while(cin >> n && n) {
    int sum = 0;
    int b[500000] = {};
    rep(i, 0, n) cin >> b[i], sum += b[i];
    bool flg = false;
    rep(i, 1, 100000) {
      int calc = (i * (i + 1)) / 2;
      if(calc == sum) {
        flg = true;
        break;
      }
      if(calc > sum) break;
    }
    if(!flg) {
      cout << -1 << endl;
      continue;
    }
    bool success = false;
    int z = n + 1;
    rep(i, 0, 10000) {
      int nxt = 1;
      success = true;
      rep(j, 0, z) {
        if(b[j]) {
          if(b[j] == nxt) nxt++;
          else success = false;
        }
      }
      if(success) {
        cout << i << endl;
        break;
      }
      int b_sum = 0;
      int kix = 0;
      rep(j, 0, z) {
        if(b[j] > 0) {
          b[j]--;
          b_sum++;
          if(b[j] > 0) {
            b[kix] = b[j];
            kix++;
          }
        }
      }
      rep(j, kix, z) b[j] = 0;
      b[kix] = b_sum;
      z = kix + 1;
    }
    if(!success) {
      cout << -1 << endl;
    }
  }
}



Measured memory_bytes: 7076
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const 
#define fr first 
#define se second
#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])
 
cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e18 + 1;
cs int base = 2333;
cs int M = 998244353;

int bs[ff], bs2[ff];
struct Node 
{
	int tr[ff], len[ff], tg[ff];
	void pushup(int now)
	{
		tr[now] = (tr[ls] * bs[len[rs]] % M + tr[rs]) % M;
		len[now] = len[ls] + len[rs];
//		cout << tr[now] << " " << len[now] <<"\n";
	}
	void psdd(int now, int va)
	{
		tr[now] = bs2[len[now]] * va % M;
		tg[now] = va;
	}
	void psd(int now)
	{
		if(!tg[now]) return;
		psdd(ls, tg[now]); psdd(rs, tg[now]);
		tg[now] = 0;
	}
	void build(int now, int l, int r)
	{
		if(l == r) { tr[now] = bs2[1]; len[now] = 1; return; }
		build(ls, l, mid); build(rs, mid + 1, r);
		pushup(now);
	}
	void modi(int now, int l, int r, int lc, int rc, int va)
	{
		if(l > rc || r < lc) return;
		if(lc <= l && r <= rc) return (void)(psdd(now, va));
		psd(now);
		modi(ls, l, mid, lc, rc, va);
		modi(rs, mid + 1, r, lc, rc, va);
		pushup(now);
	}
	int qry() { return tr[1]; }
}Seg;
int n, q;
void init()
{
	bs[0] = 1;
	rep(i, 1, 1e6) bs[i] = bs[i - 1] * 10 % M, bs2[i] = (bs2[i - 1] + bs[i - 1]) % M;
//	rep(i, 1, 4) cout <<bs2[i] <<"\n";
	int m; cin >> n >> m;
	Seg.build(1, 1, n);
//	cout << Seg.qry() << "\n";
	rep(i, 1, m)
	{
		int l, r, d;
		scanf("%lld %lld %lld", &l, &r, &d);
		Seg.modi(1, 1, n, l, r, d);
		cout <<Seg.qry() << "\n";
	}
}
signed main()
{
	int Ts = 1;
//	cin >> Ts;
	while(Ts--)
		init();
}

Measured memory_bytes: 31724
#include <stdio.h>
 
int main(void)
{
    int house[4][3][10] = {};
    int i, j, k;
    int n;
 
    scanf("%d", &n);
    while (n--){
        int b, f, r, v;
        scanf("%d %d %d %d", &b, &f, &r, &v);
        b--, f--, r--;
        house[b][f][r] += v;
    }
    for (i = 0; i < 4; i++){
        if (i){
            for (j = 0; j < 20; j++) printf("#");
            puts("");
        }
        for (j = 0; j < 3; j++){
            for (k = 0; k < 10; k++){
                printf(" %d", house[i][j][k]);
            }
            puts("");
        }
    }
    return (0);
}

Measured memory_bytes: 612
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int d, n;
    cin >> d >> n;
    int count = 0;
    int a = 1;
    while (1){
        if (a%100 != 0) count++;
        if (count == n) break;
        a++;
    }
    cout << (int)pow(100, d)*a << endl;
    return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    while(true){
        double R0, W0, C, R; cin >> R0 >> W0 >> C >> R;
        if(R0 == 0) break;
        //R0 + XR = C(W0 + Y)なる最小の非負整数X
        //X = (C(W0+Y)-R0)/R
        cout << max(0, (int) ceil((C*W0-R0)/R)) << endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 998244353;
#define pival 3.14159265358979323846264338327950L
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
        __f(comma+1, args...);
    }
#else
#define debug(...)
#endif
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
set <pll> as;
const ll L = 2e5 + 5;
ll dp[L];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    ll k, v1, v2;
    cin >> k;
    for (ll i = 0; i < k; i++) {
        cin >> v1 >> v2;
        as.insert({v1, v2});
    }
    dp[n] = 1;
    for (ll i = n - 1; i >= 1; i--) {
        ll temp = 0;
        for (auto it : as) {
            ll l = min(n + 1, i + it.fi);
            ll r = min(n + 1, i + it.se);
            ll res = (dp[l] - dp[r + 1] + mod) % mod;
            temp = (temp + res) % mod;
        }
        dp[i] = (dp[i + 1] + temp) % mod;
    }
    ll ans = (dp[1] - dp[2] + mod) % mod;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5204
#include<stdio.h>

int n;
int a[10001];
int i;
int j;
int k;


int main(void){

	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		if(i%3==0){
			a[j] = i;
			j++;
		}else{
		if(i%10==3){
			a[j] = i;
			j++;
		}else{
		if(i/10%10==3){
			a[j] = i;
			j++;
		}else{
		if(i/100%10==3){
			a[j] = i;
			j++;

		}else{
		if(i/1000%10==3){
			a[j] = i;
			j++;
			}
		}
	}			
}
}
}
	for(k=0;k<j;k++){
printf(" %d",a[k]);
}

printf("\n");

return 0;

}


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


using namespace std;

int main(void){
    
    int n;
    cin>>n;
    int a[110];
    int max=0;
    int min=1100;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>max) max=a[i];
        if(a[i]<min) min=a[i];
    }
    cout<<max-min<<endl;
}

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


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

    vector<int> w(N+1,-1);

    for(int i=1;i<=N;i++){
        if(i%64==0) w[i]=6;
        else if(i%32==0) w[i]=5;
        else if(i%16==0) w[i]=4;
        else if(i%8==0) w[i]=3;
        else if(i%4==0) w[i]=2;
        else if(i%2==0) w[i]=1;
        else w[i]=0;
    }

    int ans;
    int tmp = -1;
    for(int i=1;i<=N;i++){
        if(w[i]>tmp){
            tmp=w[i];ans=i;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256