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

int main(){
    lli n, min, res = 5;
    vector<lli> v(5);
    cin >> n;
    
    for (int i = 0; i< 5; i++)
        cin >> v[i];
    
    min = v[0];
    for (int i = 1; i< 5; i++){
        if (v[i] < min)
            min = v[i];
    }   

    if (min >= n){ 
        cout << res << "\n";
        return 0;
    }   

    if (n % min == 0)
        res += (n / min) - 1;
    else    
        res += (n/min);
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc105/tasks/abc105_c

n = int(input())

if n == 0:
    print('0')
else:
    # Sの先頭は必ず1、つまり最大桁は1と決まっている。
    s = ''
    n *= -1
    while n:
        t = n % -2
        if t < 0:
            t *= -1
        s = str(t) + s
        n //= -2
    print(s)

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

int main() 
{
   int n, x, t;
   cin >> n >> x >> t;
   if(n%x == 0) {
   	cout << (n/x)*t;
   } else {
   	cout << (n/x + 1)*t;
   }
	return 0;
}


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数
ll d[1000000];
ll e[3000000];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
void hSwap(ll x[], int i, int j)
{
	ll temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}
void ShowData(ll x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%lld  ", x[i]);
	printf("\n");
}
void QSort(ll x[], int left, int right, int n) {
	int i, j;	//左端,右端
	ll pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

int main() {
	int x, y, z, k;
	ll a[1000], b[1000], c[1000];
	scanf("%d%d%d%d", &x, &y, &z, &k);
	REP(i, x) {
		scanf("%lld", &a[i]);
	}
	REP(i, y) {
		scanf("%lld", &b[i]);
	}
	REP(i, z) {
		scanf("%lld", &c[i]);
	}
	int cnt = 0;
	REP(i, x) {
		REP(j, y) {
			d[cnt++] = a[i] + b[j];
		}
	}
	cnt = 0;
	QSort(d, 0, x*y-1, 0);
	REP(i, Min(k,x*y)) {
		REP(j, z) {
			e[cnt++] = d[i] + c[j];
		}
	}
	QSort(e, 0, Min(k, x*y) *z-1, 0);
	REP(i, k) {
		PRINTL(e[i]);
	}
}

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

using namespace std;

int main(){
	int m;
	cin >> m;
	while(m--){
		int a, y, n, answer = 0;
		cin >> a >> y >> n;
		while(n--){
			int mode, f;
			double rate;
			cin >> mode >> rate >> f;
			if(mode){
				int v = a;
				for(int i = 0; i < y; ++i){
					v = static_cast<int>(v * rate) + v - f;
				}
				answer = max(v, answer);
			}else{
				int v = a, p = 0;
				for(int i = 0; i < y; ++i){
					p += static_cast<int>(v * rate);
					v -= f;
				}
				answer = max(v + p, answer);
			}
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
MOD = 10 ** 9 + 7
N, M = gets.split.map(&:to_i)
A = M.times.map { gets.to_i }

danger = Array.new(N + 10, false)
A.each do |a|
  danger[a] = true
end
dp = Array.new(N + 10, 0)
dp[0] = 1

0.upto(N - 1) do |i|
  if !danger[i + 1]
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD
  end

  if !danger[i + 2]
    dp[i + 2] = (dp[i + 2] + dp[i]) % MOD
  end
end

puts dp[N]


Measured memory_bytes: 4604
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

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

    vector <int> v(3);
    cin>>v[0]>>v[1]>>v[2];
    sort(v.begin(),v.end());
    if(v[0]==5&&v[1]==5&&v[2]==7)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    
    
    return 0;   
}


 
 


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

int main()
{
    ll N;
    cin >> N;
    ll A[N];
    ll Amax = 0;
    ll maxNum;
    for(ll i = 0; i < N; i++)
    {
        cin >> A[i];
        if(Amax < A[i])
        {
            Amax = A[i];
            maxNum = i;
        }
    }

    ll Asecond = 0;

    for(ll i = 0; i < N; i++)
    {
        if(i == maxNum)continue;
        Asecond = max(A[i],Asecond);
    }

    for(int i = 0; i < N; i++)
    {
        if(i == maxNum)
        {
            cout << Asecond << endl;
        }
        else
        {
            cout << Amax << endl;
        }
        
    }
    return 0;
}

Measured memory_bytes: 3200
#include<iostream> 
using namespace std; 
 
int* F(string n) 
{ 
    int p = n.size(), a = 0; 
    int* ar = new int[n.size()]; 
    while (a != p) 
    { 
        ar[a] = n[a] - '0'; 
        a++; 
    } 
    return ar; 
} 
  
int main() 
{ 
    string n;
    cin>>n; 
    int* arr = F(n); 
    int sum=0;
    for (int i = 0; i < n.size(); i++) 
        sum+=arr[i];
        if(sum%9==0)
        cout<<"Yes\n";
        else 
          cout<<"No\n";

    return 0; 
} 

Measured memory_bytes: 4480
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>

using namespace std;

int Algae(int r, int D, int x)
{
    return x * r - D;
}

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

    int L = 0;
    int R = 100010;
    int tmpL, tmpR;

    for (int i = 0; i < M; i++)
    {
        cin >> tmpL >> tmpR;
        L = max(tmpL, L);
        R = min(tmpR, R);
    }

    if (R - L < 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << R - L + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		scn.useDelimiter(",|\n");
		System.out.println(scn.next() + " " + scn.next() + " " + scn.next());
		scn.close();
	}
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
    int h,w,i,j,ok=1;
    char a[8][8];

    cin>>h>>w;

    for(i=1;i<=h;i++)
        for(j=1;j<=w;j++)
            cin>>a[i][j];

    a[h+1][w]='#';

    i=1;
    j=1;

    while(i<=h && j<=w){
            if(a[i][j]=='#' && a[i][j+1]=='#'){
                a[i][j]='.';
                j++;
            }

            else if(a[i][j]=='#' && a[i+1][j]=='#'){
                a[i][j]='.';
                i++;
            }

            else
                break;
    }


    for(i=1;i<=h;i++){
        for(j=1;j<=w;j++){
            if(a[i][j]=='#'){
                ok=0;
                break;
            }
        }
    }

    if(ok==1)
        cout<<"Possible";
    else
        cout<<"Impossible";

    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
trees = list(int(input()) for _ in range(N))
trees.sort()
ans = float("inf")
for i in range(N - K + 1):
    tmp_ans = trees[i + K - 1] - trees[i]
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)

Measured memory_bytes: 7496
/*à¥à¥*/
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different.
Change variable names or change some Data structres or anything just make sure MOSS do not
Detect Anything.
Yours Faithfully
Shobhit Yadav */

/* I do not fear this new challenge. Rather like a true warrior I will rise to meet it. 
                                       -Prince Vegeta  */

 /* â€œStrength is the only thing that matters in this world. Everything else is just a delusion for the weak.â€ â€“ Vegeta */

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



ll A,B;
/*ll freq[200005];*/
void solve(){
   /*memset(freq,0,sizeof(freq));*/
   cin>>A>>B;

   cout<<(A*B)/__gcd(A,B)<<'\n';


}



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

  return 0;
}

Measured memory_bytes: 3636
import math
A, B, N = list(map(int, input().split()))

ans = 0
if(B > N):
    ans = math.floor(A * N / B) - A * math.floor(N / B)

else:
    ans = math.floor(A * (B-1) / B) - A * math.floor((B-1)/B)

print(ans)

Measured memory_bytes: 61788
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	cin >> n;
	vector<vector<ll>> abc(n, vector<ll>(3));
	rep(i, n) {
		cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
	}
	vector<vector<ll>> dp(n+1, vector<ll>(3));
	rep(i, n) {
		rep(j, 3) {
			dp[i][j] = 0;
		}
	}
	rep(i, n) {
		rep(j, 3) {
			rep(k, 3) {
				if (j == k)continue;
				chmax(dp[i + 1][k], dp[i][j] + abc[i][k]);
			}
		}
	}
	ll res = 0;
	rep(i, 3) {
		chmax(res, dp[n][i]);
	}
	cout << res << endl;
}



Measured memory_bytes: 11136
#!/usr/bin/env pypy3

import itertools


def solve(a, b, c):
    for i in itertools.count():
        da, ma = divmod(a, 2)
        db, mb = divmod(b, 2)
        dc, mc = divmod(c, 2)
        if ma == 1 or mb == 1 or mc == 1:
            return i
        elif a == b == c:
            return -1
        a = db + dc
        b = dc + da
        c = da + db


def main():
    a, b, c = (int(x) for x in input().split())
    print(solve(a, b, c))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, K;
	cin >> N >> K;
	
	vector<int> P(N), C(N);
	REP(i, N) scanf("%d", &P[i]), --P[i];
	REP(i, N) scanf("%d", &C[i]);
	
	vector<bool> done(N);
	ll ans = -longINF;
	
	REP(s, N) {
		if (done[s]) continue;
		
		vector<int> cycle;
		auto dfs = [&](auto dfs, int x) {
			if (done[x]) return;
			done[x] = true;
			cycle.emplace_back(x);
			dfs(dfs, P[x]);
		};
		dfs(dfs, s);
		
		int sz = cycle.size();
		
		ll loopsum = 0;
		REP(i, sz) loopsum += C[P[cycle[i]]];
		
		REP(i, sz) {
			ll cur = 0;
			int p = cycle[i];
			
			for (int j = 0; j < sz; ++j, p = P[p], cur += C[p]) {
				if (j == 0) {
					if (sz > K) continue;
					if (loopsum > 0) chmax(ans, K / sz * loopsum);
					else chmax(ans, loopsum);
				}
				else {
					if (j > K) continue;
					if (loopsum > 0) chmax(ans, cur + (K - j) / sz * loopsum);
					else chmax(ans, cur);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4104
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):

    sup = 0
    for i in range(N):
        dish = A[i] - 1
        sup += B[dish]
        if i != 0:
            pre_dish = A[i - 1] - 1
            if pre_dish + 1 == dish:
                sup += C[pre_dish]
    print(sup)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(N-1) ]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()


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

A_list = []
B_list = []
dif_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)
    dif_list.append(A + B)

my_list = [[dif, a, b] for dif, a, b in zip(dif_list, A_list, B_list)]
my_list.sort(reverse=True)

takahashi_score = 0
aoki_score = 0

for i, list_items in enumerate(my_list):
    a = list_items[1]
    b = list_items[2]
    if i % 2 == 0:
        takahashi_score += a
    else:
        aoki_score += b

print(takahashi_score - aoki_score)


Measured memory_bytes: 25600
N = int(input())
x = 1
alphabet = {i-96:chr(i) for i in range(97, 97+26)}
if int(N) > 26:
    ans = ''
    while x != 0:
        x = N // 26
        mod = N%26
        #print(x, mod)
        if mod == 0:
            ans += 'z'
            #x -= x%26
            x -= 1
        else:
        #print(x, mod, alphabet[mod])
            ans += alphabet[mod]
        N = x
else:
    ans = alphabet[int(N)]
print(ans[::-1])

Measured memory_bytes: 9012
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LEN 100005
using namespace std;
typedef struct pp {
  char name [100];
  int t;
}p;
p Q[LEN];
int head,tail,n;
void enqueue(p x)
{
  Q[tail] = x;
  tail = (tail+1) % LEN;
}
p dequeue()
{
  p x = Q[head];
  head = (head + 1) % LEN ;
  return x;
}
int main ()
{
  int elaps = 0,c;
  int i ,q;
  p u;
  scanf("%d %d",&n,&q);
  for(i = 1;i<=n;i++)
  {
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head = 1;tail = n+1;
  while (head != tail)
  {
    u = dequeue();
     c = min(q,u.t);
     u.t -= c;
     elaps += c;
      if(u.t>0)
      enqueue(u);
      else {
        printf("%s %d\n",u.name,elaps);
      }
  }
  return 0;
}



Measured memory_bytes: 13240
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int t[n], t1[n];
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
    t1[i] = t[i];
  }
  int m;
  cin >> m;
  int p[m], x[m];
  for (int i = 0; i < m; ++i) {
    int sum = 0;
    cin >> p[i] >> x[i];
    t[p[i] - 1] = x[i];
    for (int j = 0; j < n; ++j) sum += t[j];
    for (int j = 0; j < n; ++j) t[j] = t1[j];
    cout << sum << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split(' '))

def alg(x,K):
  num = 0
  while x < K:
    num += 1
    x = x*2
  return num

ans = 0
for i in range(1,N+1):
  ans += (1/N) * (1/2)** alg(i,K)

print(ans)
  

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string S, T, S_; cin >> S;
    S_ = S;
    reverse(S.begin(), S.end());
    string X[] = {"maerd", "remaerd", "esare", "resare"};

    
    while(1){
        if(S.size() < 5) break;
        if(S.substr(0, 5) == X[0]){
            T += X[0];
            S = S.substr(5);
        }
        else if(S.substr(0, 7) == X[1]){
            T += X[1];
            S = S.substr(7);
        }
        else if(S.substr(0, 5) == X[2]){
            T += X[2];
            S = S.substr(5);
        }
        else if(S.substr(0, 6) == X[3]){
            T += X[3];
            S = S.substr(6);
        }
        else{
            break;
        }
        //cout << S.substr(0, 5) << endl;
    }
    reverse(T.begin(), T.end());
    if(S_ == T) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 696
"""
7
2 5 1 3 2 3 0
"""

def counting_sort(A, n, max):
    B = [0] * n
    C = [0] * (max + 1)
    # print(B)
    # print(C)

    for j in range(n):
        C[A[j]] += 1
    # print(C)

    for i in range(1, max+1):
        # print(i)
        C[i] = C[i] + C[i-1]
    # print("A", A)
    # print("B", B)
    # print("C", C)

    for j in reversed(range(n)):
        # print(j)
        # # print(j)
        # print(A[j])
        # print(C[A[j]])
        B[C[A[j]]-1] = A[j]
        # print(B)
        C[A[j]] -= 1

    B_str = []
    for b in B:
        B_str.append(str(b))
    print(" ".join(B_str))
    

if __name__=="__main__":
    n = int(input())
    A = list(map(int, input().split()))
    max = max(A)
    counting_sort(A, n, max)
    # print(B)
    # B_str = []
    # for b in B:
    #     B_str.append(str(b))
    # print(" ".join(B_str))


Measured memory_bytes: 251080
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

int main() {
    cin>>S;
    int a = -1, z;
    rep(i,S.size()){
        if(S[i] == 'A' && a == -1) a = i;
        if(S[i] == 'Z') z = i;
    }
    cout<<z - a + 1<<endl;
}

Measured memory_bytes: 640
def main():
    x=input()
    cnt=0
    ans=len(x)
    for i in range(len(x)):
        if(x[i]=='S'):
            cnt+=1
        else:
            if(cnt>0):
                cnt-=1
                ans-=2
    print(ans)
        
if __name__=="__main__":
    main()

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

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

using namespace std;

const int MAX_V = 1100;
int n,m,k,b,V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v){
  used[v] = true;
  rep(i,G[v].size()){
    int next = G[v][i];
    if( match[next] < 0 || ( !used[match[next]] && dfs(match[next]) ) ) {
      match[v] = next;
      match[next] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int matching = 0;
  memset(match,-1,sizeof(match));
  rep(i,n) if( match[i] < 0 ) {
    memset(used,0,sizeof(used));
    if( dfs(i) ) ++matching;
  }
  return matching;
}

int main(){
  scanf("%d %d",&n,&m);
  rep(i,n){
    scanf("%d",&k);
    rep(j,k){
      scanf("%d",&b); --b;
      add_edge(i,n+b);
    }
  }
  puts((bipartite_matching()==m)?"Bob":"Alice");
  return 0;
}

/*
  ?????§??????????????°???m??¨???????????¨???Bob?????????
  -> Alice???????????????????????????????????¶??¨Bob????????§??????????????°???????????????????????£???????????¨????????????????????????????????????????????????
  ??????Bob????????????????????????????????????????????°Bob??????????????????
  ????????§???????????°Alice????????????Bob??????????????????????????£??\???????????????????????¶
  ????????¨???????????¨????§????Bob????????§??????????????°?????????????????£???????????????????????????????????????????????????
  ??\????????°?????????????????????Bob?????????

  
  ????????§????????´??????
  ?????§??????????????°???m??¨???????????????
  ????????¨?????????????????¶?????????????????????
  1. Bob??????????????¨???????????£????????????Alice????????????????????¨??????
  => ????????????Alice?????????????????????????????°??????

  2. Bob????????????????????????????????????????????????????????¶??¨????????????????????????????????????????????¢???????????¨??????
  => ????????????Alice?????????????????????????????????????????????????????????????????????
  Bob?????????????????????????????????????????¶
  ?¬????Alice?????????????????°????????£????????????????????????????????°Alice?????????
  o---x1 ?????????????????§,x1???????????°x2?????????????????????
   \--x2 x2???????????°x1??????????????????????????´??????????????§??????????????????????????¨?????????????????°??????????????????????????§?????§??????????????°???m??§????????¨???????????¶????????????

  ?????£???Alice?????????
  intuitive????????????mac?????????????????????
 */

Measured memory_bytes: 3244
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;


using Graph = vector<vector<int>>;//グラフ型
void dfs(const Graph& G, int v/*根*/, vector<bool>& seen) {
	seen[v] = true;  //vを訪問済にする
	for (auto next_v : G[v]) { //訪問済にしたvとつながっている場所を順番に探す
		if (seen[next_v]) continue; //もし探索済みならスルー
		dfs(G, next_v, seen); //再帰的に探索
	}
}

void bfs(const Graph& G, queue<int>& que/*発見したが訪問はしていない*/, vector<int>& dist/*開始地点からの距離*/) {
	
	while (!que.empty()) {
		int v = que.front();//queのうち先頭のものからスタート
		que.pop();//先頭を削除

		for (int nv : G[v]) {//vとつながっている点を列挙
			if (dist[nv] != -1) continue;//発見済(=距離が格納されている)であればスルー
			dist[nv] = dist[v] + 1;//vとつながっている点に距離の情報を追加
			que.push(nv);//vとつながっている点を発見済にする
		}
	}
}

int main(void) {
	ll k, n;
	cin >> k >> n;
	vector<ll>a(n);
	ll l, max = 0;//直前との距離
	int p;//go
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (i != 0) {
			l = a[i] - a[i - 1];
			max = std::max(l, max);
		}
	}
	max = std::max(a[0] + k - a[n - 1], max);
	cout << k - max;
}

/*
2 1  1
3 3  2
4 6  3
5 10 4

*/

Measured memory_bytes: 1792
def S(i,x,y):
	w = max(x,y)
	return 2*w-A if 2*w >= A else min(S(i+1,x+a[i],y),S(i+1,x,y+a[i]))
while 1:
	n = input()
	if n == 0: break
	a = sorted(map(int,raw_input().split()))[::-1]
	A = sum(a)
	print S(1,a[0],0)

Measured memory_bytes: 4244
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int h,w;
  cin>>h>>w;
  char mp[h][w],red[h][w],blue[h][w];
  int redp=-1,bluep=0;
  rep(i,h){
    rep(j,w){
      cin>>mp[i][j];
      red[i][j]=blue[i][j]=mp[i][j];
      if(mp[i][j]=='#'){
	if(redp==-1) redp=i;
	bluep=max(bluep,i);
      }
    }
  }
  rep(i,w){
    red[0][i]='#';
    blue[h-1][i]='#';
  }
  rep(i,w){
    repi(j,1,h-1){
      if(i%2==0) red[j][i]='#';
      else blue[j][i]='#';
    }
  }
  rep(i,h){
    rep(j,w){
      cout<<red[i][j];
    }
    cout<<endl;
  }
  cout<<endl;
  rep(i,h){
    rep(j,w){
      cout<<blue[i][j];
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 1536
import numpy as np

N=int(input())
A=list(map(int,input().split()))
Q=int(input())

npdata = np.arange(10**5+1)

kosuu=np.zeros(10**5+1)
kosuumoto=kosuu
for i in range(N):
    a=A[i]
    kosuu[a]+=1
SUM=sum(A)

BC_list=[]

for i in range (Q):
    bc=list(map(int,input().split()))
    BC_list.append(bc)
S=SUM
for i in range(Q):
    b=BC_list[i][0]
    c=BC_list[i][1]
    minus=b*kosuu[b]
    plus=c*kosuu[b]
    kosuu[c]=kosuu[c]+kosuu[b]
    kosuu[b]=0
    S=S-minus+plus
    print(int(S))

    


Measured memory_bytes: 50908
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e9+1
vector<ll>wt;
vector<ll>val;

ll solve(ll n,  ll capacity){
    ll max_profit = n*1000;
    ll dp[n+1][max_profit+1];
    for (int j = 0; j <= max_profit; j++) dp[0][j] = inf;
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) dp[i][0] = 0;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= max_profit; j++) {
			if (val[i] <= j) dp[i][j] = min(wt[i] + dp[i - 1][j - val[i]], dp[i - 1][j]);
			else dp[i][j] = dp[i - 1][j];
		}
	}
	int ans = 0;
	for (int j = 0; j <= max_profit; j++)
		if (dp[n][j] <= capacity) ans = j;
	return ans;
}
int main(){
   ll n  , W;
   cin>>n>>W;
   wt.resize(n+1);
   val.resize(n+1);
   for(ll i=1 ; i<=n ; i++){
       cin>>wt[i]>>val[i];
   }
   cout<<solve(n , W);
   return 0;
}


Measured memory_bytes: 82556
/*---------------------------*\
____________Mari000____________         
________Mostafa  Shehab________    
\*---------------------------*/

#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
typedef long long ll;
typedef long double ld;
//template <class Type>

ll power(ll x,ll y,ll p);
int Bit(ll x);
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}

const int N=1e5 + 5;
int arr[N];
int n,m,cnt;
int a,b,c,d;
unordered_map<int,int> mp;
bool flage[101];

int main(){
	scanf("%d",&n);
	
	while(n--){
		scanf("%d",&m);
		cnt+=(!flage[m]);
		flage[m]=true;
	}

	printf("%d",cnt);
		

}










ll power(ll x,ll y,ll p){ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    while (y > 0){ 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;
    }
    return res; 
}


int Bit(ll x){
	if(!x)
		return 0;
	return 1+Bit(x>>1);
}


















Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let xs: Vec<usize> = sc.vec(n);

    let mut ones = vec![0; 62];
    let mut zeros = vec![0; 62];

    for &x in xs.iter() {
        for i in 0..62 {
            if x & (1 << i) > 0 {
                ones[i] += 1;
            } else {
                zeros[i] += 1;
            }
        }
    }

    let mut ans: i64 = 0;
    for i in 0..62 {
        ans += (((ones[i] * zeros[i]) % M) * ((1 << i) % M)) % M;
        ans %= M;
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 30968
from math import ceil
n,k = map(int,input().split())
a = list(map(int,input().split()))

def cut(x):
  t = 0
  for i in a:
    if i <= x:
      continue
    t += ceil(i / x) - 1
  return t <= k

l,r=0,10**9
while l+1 < r:
  x = l + (r-l)//2
  if cut(x):
    r = x
  else:
    l = x
print(r)

Measured memory_bytes: 31172
require 'prime'
N = gets.to_i

MOD = 10**9+7

hash = {}
1.upto(N) do |n|
  n.prime_division.each do |p|
    hash[p[0]] ||= 0
    hash[p[0]] += p[1]
  end
end

res = 1
hash.values.each do |v|
  res *= v + 1
  res %= MOD
end

p res


Measured memory_bytes: 2300
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M, D;
    cin >> M >> D;
    cin >> M >> D;
    if (D == 1) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
        
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solveA();
		// new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		String line = "";

		try {
			scanner = new Scanner(System.in);
			line = scanner.next();

			System.out.println(line.replaceAll("2017", "2018"));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

using namespace std;

#define int long long
#define double long double
#define mod 998244353ll
#define INF 1000000000000000000ll

#define MAX_N 5000010

int silnia[MAX_N];

void init() {
    silnia[0] = 1;
    for (int i = 1; i < MAX_N; i++) {
        silnia[i] = silnia[i - 1] * i % mod;
    }
}

int pot(int n, int k = mod - 2) {
    int res = 1;

    while (k) {
        if (k % 2) {
            res = res * n % mod;
        }
        n = n * n % mod;
        k /= 2;
    }

    return res;
}

int dwumian(int n, int k) {
    if (k > n || k < 0) return 0;
    return (silnia[n] * pot(silnia[n - k]) % mod) * pot(silnia[k]) % mod;
}

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

    init();

    int res = 0;
    int n, m;
    cin >> n >> m;
    //cout << dwumian(n, m);
    for (int i = m; 2 * i <= 3 * m; i++) {
        int a = dwumian(n - 1 + i, i);
        res += a * dwumian(n, 3 * m - 2 * i);
        res %= mod;
        //cout << a * dwumian(n, 3 * m - 2 * i) << " " << i  << endl;
    }

    for (int i = 2 * m + 1; i <= 3 * m; i++) {
        int a = n * dwumian((n - 1) + (3 * m - i) - 1, (n - 1) - 1) % mod;
        res = (res + mod - a) % mod;
    }

    cout << res;

    return 0;
}
/*

*/


Measured memory_bytes: 39296
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>
#include <ctime>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    cin >> A >> B >> C;
    REP(i, N) {
        A[i]--;
    }

    int sum = 0;
    REP(i, N) {
        sum += B[A[i]];
        if (i - 1 >= 0 && A[i - 1] + 1 == A[i]) {
            sum += C[A[i - 1]];
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>


using namespace std;
using ll=long long;


int main(void)
{
	int n, m;


	while(scanf("%d%d", &n, &m)==2)
	{
		vector<map<int,int>> v(n+1);
		map<int,ll> ans;

		for(int i=0;i<m;i++)
		{
			int p, y;

			scanf("%d%d", &p, &y);
			v[p][y]=i;
		}
		for(int j=1;j<=n;j++)
		{
			auto&mv=v[j];
			auto it=mv.begin();
			for(int i=1;it!=mv.end();++it,i++)
			{
				ans[it->second]=j*1000000LL+i;
			}
		}
		for(auto&mans:ans)
		{
			printf("%012lld\n", mans.second);
		}
	}

	return 0;
}


Measured memory_bytes: 17152
#include <cstdio>
#include <algorithm>
using namespace std;
int a,b;
int main(){
  while(scanf("%d %d",&a,&b)!=EOF){
    for(int i=min(a,b);i>0;i--){
      if(a%i==0 && b%i==0){
        printf("%d\n",i);
        break;
      }
    }
  }
return 0;
}

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

#define int long long

const int MOD = 1000000007;

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> cum(n);
    cum[n - 1] = a[n - 1];
    for(int i = n - 2; i >= 0; i--) cum[i] = (cum[i + 1] + a[i]) % MOD;

    int ans = 0;
    for(int i = 0; i < n - 1; i++) {
        ans += (a[i] * (cum[i + 1] % MOD)) % MOD;
    }

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


Measured memory_bytes: 6364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	map<string,ll> cnt;
	rep(i,n){
		string s;
		cin>>s;
		sort(begin(s),end(s));
		cnt[s]++;
	}
	ll ans=0;
	for(auto itr:cnt){
		if(itr.se>=2){
			ans+=(itr.se)*(itr.se-1)/2;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11264
import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String res = "";
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            String c = s.substring(i, i+1);
            if (c.equals("B")) {
                if (res.length() > 0) {
                    res = res.substring(0, res.length()-1);
                }
            } else {
                res += c;
            }
        }
        System.out.println(res);
    }
}


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

typedef long long llong;

int main()
{
    llong n;
    cin>>n;
    llong ans=n-1;
    for(llong i=1;i*i<=n;i++)
    {
        if(n%i==0)
            ans=min(ans,n/i+i-2);
    }
    cout<<ans<<endl;
    return 0;
}


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

ll N;

vector<ll> dijkstra(int start, vector<vector<vector<ll>>> &Graph) {
    vector<ll> dist(N, 10e13);  // 0始まり
    priority_queue<P, vector<P>, greater<P>> pq;

    dist.at(start) = 0;
    pq.emplace(dist.at(start), start);  //最初の要素をキューに追加

    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int cur = p.second;
        if (dist.at(cur) < p.first) continue;
        for (auto &x : Graph.at(cur)) {
            if (dist.at(x[0]) > dist.at(cur) + x[1]) {
                dist.at(x[0]) = dist.at(cur) + x[1];
                pq.emplace(dist.at(x[0]), x[0]);  //要素をキューに追加
            }
        }
    }
    return dist;
}

int main() {
    cin >> N;

    vector<vector<vector<ll>>> Graph(N);  // 0始まり
    for (int i = 0; i < N - 1; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        Graph[a].push_back({b, c});
        Graph[b].push_back({a, c});  //無向グラフに距離cも追加
    }

    const auto &res = dijkstra(2, Graph);

    rep(i, N) cout << res[i] % 2 << endl;
}


Measured memory_bytes: 18928
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vii;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 5;

void solve(){
    int a,b;
    cin>>a>>b;
    cout<<max(max(a+b,a-b),a*b);
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int n = 10;
int m, a[n][n];
const int sz[] = {5, 9, 13};
const int dy[][13] = {
	{-1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
	{-1, -1, -1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
	{-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2}
};
const int dx[][13] = {
	{0, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{-1, 0, 1, -1, 0, 1, -1, 0, 1, 0, 0, 0, 0},
	{0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}
};

vector<pi> v;

inline bool can(int y, int x, int t, int nul = 0){
	if(nul) rep(d, sz[t]){
		int ny = y + dy[t][d], nx = x + dx[t][d];
		if(ny < 0 || nx < 0 || ny >= n || nx >= n) continue;
		a[ny][nx] += nul;
	}
	else rep(d, sz[t]){
		int ny = y + dy[t][d], nx = x + dx[t][d];
		if(ny < 0 || nx < 0 || ny >= n || nx >= n) continue;
		if(!a[ny][nx]) return 0;
	}
	return 1;
}
inline void fill(bool ok[n][n], int y, int x, int t){
	rep(d, sz[t]){
		int ny = y + dy[t][d], nx = x + dx[t][d];
		if(ny < 0 || nx < 0 || ny >= n || nx >= n) continue;
		ok[ny][nx] = 1;
	}
}

inline void rec(int m, int y, int x){
	if(m == 0){
		rep(i, n) rep(j, n) if(a[i][j]) return;
		rep(i, v.size()) cout << v[i].first / 10 << " " << v[i].first % 10 << " " << v[i].second << endl;
		exit(0);
	}
	bool ok[n][n] = {};
	vector<pi> cand;
	
	rep(i, n) rep(j, n) if(i > y || i == y && j >= x)
	if(a[i][j]) for(int t = 2; i >= 0; t--){
		if(can(i, j, t)){
			fill(ok, i, j, t);
			cand.pb(mp(t, i * 10 + j));
			break;
		}
	}
	rep(i, n) rep(j, n) if(a[i][j] && !ok[i][j]) return;
	
	rep(ii, cand.size()){
		int i = cand[ii].second / 10, j = cand[ii].second % 10;
		int t = cand[ii].first;
		
		for(; t >= 0; t--){
			//if(i >= 3 && t < cand[ii].first) break;
			can(i, j, t, -1);
			v.pb(mp(j * 10 + i, t + 1));
			rec(m - 1, i, j);
			v.pop_back();
			can(i, j, t, 1);
		}
	}
}

int main(){
	cin >> m;
	rep(i, n) rep(j, n) cin >> a[i][j];
	rec(m, 0, 0);
	return 0;
}

Measured memory_bytes: 1212
s=int(input())
a=[s]
cnt=1
t=False
    
while True:
    cnt+=1
    if s%2==0:
        seven=int(s/2)
        s=seven
        for i,ai in enumerate(a):
            if ai==s:
                t=True
                break
        if t==False:
            s=seven
            a.append(seven)
        else:
            break
    else:
        sodd=int(s*3+1)
        s=sodd
        for i,ai in enumerate(a):
            if ai==s:
                t=True
                break
        if t==False:
            s=sodd
            a.append(sodd)
        else:
            break

print(cnt)


Measured memory_bytes: 3064
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer n = scan.nextInt();
        Integer m = scan.nextInt();

        if(n==m)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      }
}


Measured memory_bytes: 23252
# coding=utf-8

a, b = map(int, input().split())
if a > b:
    big_num = a
    sml_num = b
else:
    big_num = b
    sml_num = a

while True:
    diviser = big_num % sml_num
    if diviser == 0:
        break
    else:
        big_num = sml_num
        sml_num = diviser

print(sml_num)

Measured memory_bytes: 7628
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            var C = int.Parse(Console.ReadLine());
            var X = int.Parse(Console.ReadLine());
            var answer = 0;
            for (var a = 0; a <= A; a++)
            {
                for (var b = 0; b <= B; b++)
                {
                    for (var c = 0; c <= C; c++)
                    {
                        var val = 500 * a + 100 * b + 50 * c;
                        if (val == X) answer++;
                        if (val > X) break;
                    }
                }
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13140
import math

A = []
N = int(input())
for i in range(5):
    a = int(input())
    A.append(a)
min_t = min(A)
"""
if N % min_t == 0:
    a = N // min_t
else:
    a = N // min_t + 1
"""
a = math.ceil(N / min_t)
print(a + 4)


Measured memory_bytes: 3060