akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int qqq; cin>>qqq;
    rep(qqqqqqqqqqqqq,qqq){
        ll a,b; cin>>a>>b;
        ll ro=sqrt(a*b), ans=0;
        vector<int> candi;
        if(a==b){
            cout<<(ro-1)*2<<endl;
        }else{
            ll ans=0;
            if((a*b-1)/ro==ro){
                ans=ro*2-1;
            }else if(a*b==ro*ro) {
                ans=ro*2-2;
            }else{
                ans=ro*2;
            }
            ans--;
            b=max(a,b);
            ll kari=(a*b-1)/b;
            if(kari!=0){
                kari=(a*b-1)/kari;
                if(kari==b) ans--;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>

int main()
{
    int w;  scanf("%d", &w);
    int h;  scanf("%d", &h);
    int n;  scanf("%d", &n);
    int minx = 0;
    int miny = 0;


    int i;
    for(i = 0; i < n; i++){
        int tmpx;   scanf("%d", &tmpx);
        int tmpy;   scanf("%d", &tmpy);
        int a;  scanf("%d", &a);
        switch(a){
            case 1 : if(minx < tmpx) minx = tmpx;   break;
            case 2 : if(tmpx < w) w = tmpx;     break;
            case 3 : if(miny < tmpy) miny = tmpy;   break;
            case 4 : if(tmpy < h) h = tmpy;     break;
        }
    }

    int s;
    if(w > minx){
        s = ((w - minx) * (h - miny) > 0) ? ((w - minx) * (h - miny)) : 0;
    }
    else{
        s = 0;
    }

    printf("%d", s);

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	long r,D,x;
	scanf("%ld%ld%ld",&r,&D,&x);
	int a;
	for(a=0;a<10;a++){
		x=r*x-D;
		printf("%ld\n",x);
	}
return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define ABSIZE 2000000
#define CSIZE 10000

int A[ABSIZE], B[ABSIZE], C[CSIZE];

void Counting_Sort(int n)
{
    int i, j;
    for(i = 0; i < CSIZE; i++){
        C[i] = 0;
    }
    for(j = 0; j < n; j++){
        C[A[j]] = C[A[j]]+1;
    }
    /* C[i]??????i???????????属????即???????????????????*/
    for(i = 1; i < CSIZE; i++){
        C[i] = C[i] + C[i-1];
    }
    /* C[i]??????i??\????????属???????????属????即???????????????????*/
    for(j = n-1; 0 <= j; j--){
       B[C[A[j]]-1] = A[j];
       C[A[j]] = C[A[j]]-1;
    }
}

int main()
{
  int n, i;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }

  Counting_Sort(n);

  for(i = 0; i < n-1; i++){
    printf("%d ", B[i]);
  }
  printf("%d\n", B[i]);

  return(0);
}

Measured memory_bytes: 16264
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;
using pr  = pair<ll, ll>;

const ll MOD = 998244353;

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

	map<ll, ll> mp;

	ll ans = 0;

	for (ll i = 0; i < N; ++i)
	{
		ll A; cin >> A;

		ans += mp[i - A];

		mp[i + A]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 26384
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

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

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

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	long long l = 1;
	long long t;
	for (int i = 0; i < n; ++i) {
		cin >> t;
		l = lcm(l, t);
	}

	cout << l << "\n";

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

struct edge {
  int from, to, cost;

  edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};

int lg2(int n) {
  int temp = 0;
  while (n) {
    temp++;
    n /= 2;
  }
  temp--;
  return temp;
}

int pw2(int n) {
  int temp = 1;
  rep(i, n) {
    temp *= 2;
  }
  return temp;
}

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

  vector<edge> ans;
  rep(i, 19) {
    ans.pb(edge(i + 1, i + 2, 0));
  }

  int c = 1;
  rep(i, lg2(L)) {
    ans.pb(edge(20 - i - 1, 20 - i, c));
    c *= 2;
  }

  L -= pw2(lg2(L));

  while (L) {
    int lg = lg2(L);
    ans.pb(edge(1, 20 - lg, c));
    c += pw2(lg);
    L -= pw2(lg);
  }

  int M = sz(ans);
  cout << 20 << ' ' << M << endl;
  rep(i, M) {
    printf("%d %d %d\n", ans[i].from, ans[i].to, ans[i].cost);
  }
}

Measured memory_bytes: 384
void main(){
	char alph = _scan!char();
	( ('a'<=alph && alph<='z') ? 'a' : 'A').writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	
	int x=a+b, y=b+c, z=a+c;
	
	int p=min(x, y);
	int q=min(y, z);
	
	cout << min(p, q);
	return 0;
 } 

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 2e5+50;
const int inf = 1e9;

ll fact[maxn];
ll inv_fact[maxn];
ll inv[maxn];

ll get_inv(ll x)
{
    if (x == 1) return inv[x] = 1;
    return inv[x] = get_inv(mod % x) * (mod - mod/x) % mod;
}

ll C(int n, int m)
{
    return fact[n] * inv_fact[m] % mod * inv_fact[n-m] % mod;
}

void init()
{
    for (int i = 1; i < maxn; ++i)
        if (!inv[i]) get_inv(i);
    fact[0] = inv_fact[0] = 1;
    for (int i = 1; i < maxn; ++i)
    {
        fact[i] = fact[i-1] * i % mod;
        inv_fact[i] = inv_fact[i-1] * inv[i] % mod;
    }
}

int k[maxn];

int main()
{
    int n, m;
    cin >> n >> m;
    init();
    ll ans = 1;
    int u = sqrt(m);
    int tmp = m;
    int cnt = 0;
    for (int i = 2; i <= u; ++i)
    {
        if (tmp % i == 0)
        {
            while (tmp % i == 0) 
            {
                k[cnt] ++;
                tmp /= i;
            }
            cnt ++;
        }
    }
    //printf("%d\n", cnt);
    if (tmp > 1) k[cnt++] = 1;
    for (int i = 0; i < cnt; ++i)
        ans = ans * C(k[i]+n-1, k[i]) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<sstream>
using namespace std;
int main()
{
char str[100000];
int j,i,t,s1,cnt=0;

scanf("%d",&t);
for(i=1;i<=t;i++){
   stringstream ss;
   ss<<i;
   string s;
   ss>>s;
   j=0;
   s1=0;
   while(s[j]!='\0'){
    j++;
    s1++;
   }
       if(s1%2!=0){
        cnt++;
    }
}
printf("%d\n",cnt);

    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  AISING2020B

#include <iostream>
using namespace std;
using ll = long long;int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int a[110]={};
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int ans=0;
    for(int j=1;j<=n;j+=2){
        if(a[j]%2==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3176
#n, a, b = map(int, input().split())
n = int(input())
a = input()
b = input()
c = input()

ans = 0
for i in range(n):
    if a[i] == b[i] and b[i] == c[i]:
        continue
    if a[i] == b[i] or b[i] == c[i] or c[i] == a[i]:
        ans += 1
        continue
    ans += 2

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a,b;
	cin>>a>>b;
    if(a<=b)
    {
        int t=a;
        a=b;
        b=t;
    }
    for(int i=0;i<a;i++)
    {
        cout<<b;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>


using namespace std;

const int MAX = 100005;
const int LIM = 10;
double dp[MAX][LIM];
double ans[MAX];

void make(){
  memset(dp,0,sizeof(dp));
  dp[1][1] = 1;
  
  for(int i = 1; i < MAX-1; i++){
    // cout << i << endl;
    double p = 1.0;
    for(int j = 1; j < LIM; j++){
      p/=2;
      if(j < LIM-1) dp[i+1][j+1] += dp[i][j]*p;
      dp[i+1][0] += dp[i][j]*(1.0-p);
    }
    dp[i+1][1] += dp[i][0];
  }
  
  double tmp = 0;
  for(int i = 0; i < MAX; i++){
    for(int j = 1; j < LIM; j++) tmp += dp[i][j];
    ans[i] = tmp;
  } 
}


int main(){
  make();
  int n;
  while(cin >> n && n) printf("%.8f\n",ans[n]);
  return 0;
}

Measured memory_bytes: 9788
# coding: utf-8

N = int(input())
x = [None] * N
u = [None] * N
for i in range(N):
    a, b = input().split()
    x[i] = float(a)
    u[i] = b

output = 0
for i in range(N):
    if u[i] == "JPY":
        output += x[i]
    else:
        output += x[i] * 380000

print(output)


Measured memory_bytes: 3060
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

"""
全ての場所を一度だけ通り巡回する通りの数
bit(1 << N)を小さい順から探索する
①bit & (1 << 0)
最初に0を踏んでないということだから飛ばす
②現在の場所sを探すためN個探索する
③次の場所tを探すためN個探索する
④渡すdpする
"""

N, M = getNM()
G = [[0] * N for i in range(N)]
for i in range(M):
    a, b = getNM()
    G[a - 1][b - 1] = 1 # a ~ bのエッジが存在する
    G[b - 1][a - 1] = 1

# 状態bitから次の状態へ渡すdpするというのはよくやる
# [0](001) → [0, 1](011) → [0, 1, 2](111)
#          → [0, 2](101) → [0, 1, 2](111)
def counter(sta):
    # dp[bit][i]これまでに踏んだ場所がbitであり、現在の場所がiである
    dp = [[0] * N for i in range(1 << N)]
    dp[1 << sta][sta] = 1

    for bit in range(1, 1 << N):
        if not bit & (1 << sta):
            continue
        # s:現在の場所
        for s in range(N):
            # sを踏んだことになっていなければ飛ばす
            if not bit & (1 << s):
                continue
            # t:次の場所
            for t in range(N):
                # tを過去踏んでいない and s → tへのエッジがある
                if (bit & (1 << t)) == 0 and G[s][t]:
                    dp[bit|(1 << t)][t] += dp[bit][s]

    return sum(dp[(1 << N) - 1])

print(counter(0))

Measured memory_bytes: 83800
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int D; cin >> D;
    vector C(26, 0);
    rep(i,26) cin >> C.at(i);
    vector S(D, vector(26, 0));
    rep(i, D) rep(j, 26) cin >> S[i][j];
    vector T(D, 0);
    rep(i,D) cin >> T.at(i);
    vector last(26, 0);
    int sat = 0;
    rep(d, D) {
        int j = T[d] - 1;
        last[j] = d + 1;
        rep(i,26) sat -= (d + 1 - last[i]) * C[i];
        sat += S[d][j];
        cout << sat << endl;
    }
}

Measured memory_bytes: 3676
#include <algorithm>
#include <iostream>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    int N;
    cin >> N;
    vector<long> L(N);
    repeat(i, N) cin >> L[i];
    sort(L.begin(), L.end());
    long res = 0L;
    repeat(i, N) {
        repeat_from(j, i + 1, N) {
            if (L[i] == L[j]) continue;
            repeat_from(k, j + 1, N) {
                if (L[j] == L[k] || L[i] + L[j] <= L[k]) continue;
                ++res;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  VI A(n, 1), B(n, 1), C(n, 1);
  REP(i, n)
  {
    if (a[i] == b[i]) {A[i]++; B[i]++;}
    if (b[i] == c[i]) {B[i]++; C[i]++;}
    if (c[i] == a[i]) {C[i]++; A[i]++;}
  }
  int ans = 0;
  REP(i, n)
  {
    if (A[i] == 2 || B[i] == 2 || C[i] == 2) ans++;
    else if (A[i] == 1) ans += 2;
  }
  cout << ans << endl;

  return 0;
}

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



int main()
{
  using PII = pair<int, int>;
  string s,t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  vector<vector<int>> lcs(n + 1, vector<int>(m + 1));
  vector<vector<PII>> parent(n + 1, vector<PII>(m + 1));
  for (int i = 1; i <= s.size(); ++i) {
    for (int j = 1; j <= t.size(); ++j) {
      lcs[i][j] = lcs[i-1][j];
      parent[i][j] = {i-1, j};
      if (lcs[i][j-1] > lcs[i-1][j]) {
        lcs[i][j] = lcs[i][j-1];
        parent[i][j] = {i, j-1};
      }
      if (s[i-1] == t[j-1]) {
        lcs[i][j] = lcs[i-1][j-1] + 1;
        parent[i][j] = {i - 1, j - 1};
      }
    }
  }
 // cout << lcs[n][m] <<'\n';
  string res;
  int i = n, j = m;
  while (i > 0 and j > 0) {
    if (parent[i][j] == make_pair(i-1, j-1))
      res += s[i-1];
    auto p = parent[i][j];
    i = p.first;
    j = p.second;
  }
  reverse(res.begin(), res.end());
  cout << res << '\n';


  return 0;
}


Measured memory_bytes: 105984
#include <bits/stdc++.h>
#define ll long long
#define mem( f, x ) memset( f, x, sizeof( f ) )
#define INF 0x3f3f3f3f
#define pii pair<int, int>
#define mk( x, y ) make_pair(x, y)
#define pk push_back
#define fi first
#define se second
using namespace std;
const int M = 15;
const int N = 15;
const int MAXN = 15;
ll m, n, x;
ll c[N], mp[N][N];
ll ret[N];
ll ans;

void DFS( int cur, ll sum ){
    bool flag = 0;
    for( int i = 1; i <= m; i++ ){
        if( ret[i] > 0 ){
            flag = 1;
            break;
        }
    }
    if( !flag ){
        ans = min( ans, sum );
        return;
    }
    for( int i = cur+1; i <= n; i++ ){
        for( int j = 1; j <= m; j++ )
            ret[j] -= mp[i][j];
        DFS( i, sum+c[i] );
        for( int j = 1; j <= m; j++ )
            ret[j] += mp[i][j];
    }
}

int main( ){
    while( scanf( "%lld %lld %lld", &n, &m, &x ) != EOF ){
        for( int i = 1; i <= m; i++ )
            ret[i] = x;
        for( int i = 1; i <= n; i++ ){
            scanf( "%lld", c+i );
            for( int j = 1; j <= m; j++ )
                scanf( "%lld", *(mp+i)+j );
        }
        ans = INF;
        DFS( 0, 0 );
        if( ans == INF )
            printf( "-1\n" );
        else
            printf( "%lld\n", ans );
    }
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/

int main(){
    ll N;
    string S;
    cin >> N >> S;
    ll ans = 0;
    for(ll i = 1;i <= N - 1;i++){
        string l = S.substr(0,i),r = S.substr(i,N - i);
        map<char,ll> lem;
        map<char,ll> rim;
        rep(j,i){
            lem[l[j]]++;
        }
        rep(j,N - i){
            rim[r[j]]++;
        }
        ll cnt = 0;
        for(auto x : lem){
            if(rim[x.first] != 0){
                cnt++;
            }
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 11

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

	int a, b;
	cin >> a >> b;
	if(a >= 13)
		cout << b << "\n";
	else if(a >= 6 && a <= 12)
		cout << b/2 << '\n';
	else
		cout << 0 << "\n";
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

#define MAX 100000

typedef struct{
  int p;
  int l_child;
  int r_child;
} node;

int depth[MAX], height[MAX];
node T[MAX];

void getDepth(int,int);

int main(){
  int c,i,n,r,p,id,left,right,sib,deg;
    
  scanf("%d",&n);

  for(i=0;i<n;i++) T[i].p=T[i].l_child=T[i].r_child=-1;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&left,&right);
    T[id].l_child=left;
    T[id].r_child=right;
    if(left!=-1) T[left].p=id;
    if(right!=-1) T[right].p=id;
  }

  for(i=0;i<n;i++){
    if(T[i].p==-1)r=i;
    if(T[i].l_child==-1 && T[i].r_child==-1){ 
      height[i]=0;
      p=T[i].p;
      c=1;
      while(1){
	if(p==-1)break;
	if(height[p]<c) height[p]=c;
	c++;
	p=T[p].p;
      }
    }
  }

  getDepth(r,0);

  

  for(i=0;i<n;i++){
    p=T[i].p;
    if(p==-1) sib=-1;
    else{
      if(T[p].l_child==i) sib=T[p].r_child;
      else sib=T[p].l_child;
    }

    deg=0;
    if(T[i].l_child!=-1) deg++;
    if(T[i].r_child!=-1) deg++;
    
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T[i].p,sib,deg,depth[i],height[i]);

    if(T[i].p==-1) printf("root\n");

    else if(T[i].l_child==-1 && T[i].r_child==-1) printf("leaf\n");
      
    else printf("internal node\n");
  }

  return 0;
}

void getDepth(int u,int p){
  int right,left;
  depth[u]=p;
  if(T[u].r_child!=-1) getDepth(T[u].r_child,p+1);
  if(T[u].l_child!=-1) getDepth(T[u].l_child,p+1);
}



Measured memory_bytes: 2112
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
char mine[55][55];
int dx[8] = { 1,-1,0,0,-1,-1,1,1};
int dy[8] = { 0,0,1,-1,-1,1,-1,1 };
int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> mine[i][j];
		}
	}
	int dist[55][55];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			dist[i][j] = inf;
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int count = 0;
			if (mine[i][j] == '.') {
				for (int k = 0; k < 8; k++) {
					int newx = j + dy[k];
					int newy = i + dx[k];
					if (newx >= 0 && newx < w && newy >= 0 && newy < h && mine[newy][newx] == '#') {
						count++;
					}
				}
			dist[i][j] = count;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (j % w == 0) {
				cout << endl;
			}
			if (dist[i][j] == inf) {
				cout << "#";
			}
			else {
				cout << dist[i][j];
			}
		}
	}
	return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] l = new int[2*n];
        for (int i = 0 ; i < 2*n ; i++) {
            l[i] = sc.nextInt();
        }
        Arrays.sort(l);
        int sum = 0;
        for (int i = 0; i < n ; i++) {
            sum += l[2 * i];
        }
        System.out.println(sum);

    }

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int count = 0;
    for(int i = 0;i < (int)S.size() / 2;i++){
        if(S[i] != S[S.size() - i - 1])
            count++;
    }
    cout << count << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())
int F[100][15];
int main(void) {
	int N, w=1;
	std::string s;
	std::cin >> s;
	for (size_t i = 0; i < s.size()-1; i++) {
		if (s[i] != s[i + 1]) {
			w++;
		}
	}
	std::cout << w-1 << std::endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int x = (n+1000-1)/1000;
    int ans = x * 1000 - n;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
#include<string.h>
#include<math.h>
#define INF 0x3f3f3f3f
#define N 100001
int min(int x , int y)
{
	return (x < y) ? x : y;
}
int main()
{
	int dp[N];
	int h[N];
	int n,k;
	int tmp;
	while (scanf("%d %d", &n, &k) != EOF)
	{
		for (int i = 1; i <= n; i++)
			scanf("%d", &h[i]);
		memset(dp, 0x3f, sizeof(dp));
		dp[1] = 0;
		for (int i = 2; i <= k; i++)
			dp[i] = fabs(h[i] - h[1]);
		for (int i = k + 1; i <= n; i++)
			for (int j = i - k; j < i; j++)
				dp[i] = min(dp[j] + fabs(h[i] - h[j]), dp[i]);
		printf("%d\n", dp[n]);
	}
	return 0;
}

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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, W;
  cin >> n >> W;
  map<int, vector<int>> mp;
  for (int i = 0; i < n; i++) {
    int w, v;
    cin >> w >> v;
    mp[w].push_back(v);
  }
  vector<long long> ws;
  for (auto& it : mp) {
    ws.push_back(it.first);
    sort(it.second.rbegin(), it.second.rend());
    for (int j = 1; j < (int) it.second.size(); j++) {
      it.second[j] += it.second[j - 1];
    }
  }
  int ans = 0;
  if (ws.size() == 1) {
    for (int i = 0; i <= mp[ws[0]].size(); i++) {
      if (i * ws[0] > W) {
        break;
      }
      ans = max(ans, i == 0 ? 0 : mp[ws[0]][i - 1]);
    }
  } else if (ws.size() == 2) {
    for (int i = 0; i <= mp[ws[0]].size(); i++) {
      for (int j = 0; j <= mp[ws[1]].size(); j++) {
        if (i * ws[0] + j * ws[1] > W) {
          break;
        }
        ans = max(ans,
          (i == 0 ? 0 : mp[ws[0]][i - 1])
          + (j == 0 ? 0 : mp[ws[1]][j - 1])
        );
      }
    }
  } else if (ws.size() == 3) {
    for (int i = 0; i <= mp[ws[0]].size(); i++) {
      for (int j = 0; j <= mp[ws[1]].size(); j++) {
        for (int k = 0; k <= mp[ws[2]].size(); k++) {
          if (i * ws[0] + j * ws[1] + k * ws[2] > W) {
            break;
          }
          ans = max(ans,
            (i == 0 ? 0 : mp[ws[0]][i - 1])
            + (j == 0 ? 0 : mp[ws[1]][j - 1])
            + (k == 0 ? 0 : mp[ws[2]][k - 1])
          );
        }
      }
    }
  } else if (ws.size() == 4) {
    for (int i = 0; i <= mp[ws[0]].size(); i++) {
      for (int j = 0; j <= mp[ws[1]].size(); j++) {
        for (int k = 0; k <= mp[ws[2]].size(); k++) {
          long long cur_w = i * ws[0] + j * ws[1] + k * ws[2];
          long long rem_w = W - cur_w;
          if (rem_w < 0) {
            continue;
          }
          int l = min(n - i - j - k, (int) (rem_w / ws[3]));
          if (l < 0 || l > (int) mp[ws[3]].size()) {
            continue;
          }
          if (i * ws[0] + j * ws[1] + k * ws[2] + l * ws[3] > W) {
            continue;
          }
          ans = max(ans, 
            (i == 0 ? 0 : mp[ws[0]][i - 1]) 
            + (j == 0 ? 0 : mp[ws[1]][j - 1]) 
            + (k == 0 ? 0 : mp[ws[2]][k - 1]) 
            + (l == 0 ? 0 : mp[ws[3]][l - 1])
          );
        }
      }
    }
  } else {
    assert(false);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3620
from sys import stdin, setrecursionlimit
from collections import deque


def main():

    setrecursionlimit(2000001)

    n, q = [int(x) for x in stdin.readline().split()]

    tree = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        a, b = [int(x) for x in stdin.readline().split()]
        tree[a].append(b)
        tree[b].append(a)

    count = [0] * (n + 1)
    for _ in range(q):
        parent, x = [int(x) for x in stdin.readline().split()]
        count[parent] += x

    queue = deque([])
    visited = [False] * (n + 1)

    queue.append((0, 1))

    while len(queue) > 0:
        parent, current = queue.pop()
        visited[current] = True
        count[current] += count[parent]
        for child in tree[current]:
            if not visited[child]:
                queue.append((current, child))

    print(*count[1:])


main()


Measured memory_bytes: 58512
N,M = map(int, input().split())
ans = [-1 for i in range (N)]
exist = True
for i in range(M):
    s,c = map(int, input().split())
    if ans[s-1] == -1:
        ans[s-1] = c
    else:
        if ans[s-1] != c:
            exist = False
            break

if ans[0] == 0 and len(ans) > 1:
    exist = False
elif ans[0] == -1 and len(ans) > 1:
    ans[0] = 1
elif ans[0] == -1 and len(ans) == 1:
    ans[0] = 0

if exist:
    ans = [0 if i == -1 else i for i in ans]
    print(''.join([str(i) for i in ans]))
else:
    print(-1)

Measured memory_bytes: 3064
// abc118_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

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

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int A, B;
    cin >> A >> B;

    if (B % A == 0){
        print(A + B);
    } else {
        print(B - A);
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.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, a[1000];
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  int ans = 0;
  rep(i, 1, n) {
    if(a[i] == a[i - 1]) {
      a[i] = -1;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Numerics;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());

            var dp = new int[s + 1];
            dp[0] = 1;
            
            for(int i = 1; i < s + 1; i++)
            {
                for(int j = 0; j < i - 3 + 1; j++)
                {
                    dp[i] += dp[j];
                    dp[i] %= Mod;
                }
            }
            Console.WriteLine(dp[s]);
        }
        static public int Mod = 1000000007;
    }
}


Measured memory_bytes: 27480
output = 0
try:
    while True:
        n = int(input())
        a = 0
        while a < 10 :
            b = 0
            while b < 10 :
                c = 0
                while c < 10 :
                    d = 0
                    while d < 10 :
                        if a + b + c + d == n :
                            output += 1
                        d += 1
                    c += 1
                b += 1
            a += 1
        print(output)
        output = 0
except EOFError:
    pass


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int A,B,N;
    cin>>A>>B>>N;

    int mi=LLONG_MAX;

    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            if((B*i)%j)continue;
            int a=B*i/j;
            chmin(mi,abs(A-a));
        }
    }
    cout<<mi<<endl;

    return 0;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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

void Main(){
    ll N; cin >> N;
    VL A(N); REP(i,N) cin >> A[i];
    VL B;
    if(A[0]<A[1]) B.push_back(A[0]);
    REP(i,N-2){
        if(A[i]<=A[i+1]&&A[i+1]>=A[i+2]) B.push_back(A[i+1]);
        else if(A[i]>=A[i+1]&&A[i+1]<=A[i+2]) B.push_back(A[i+1]);
    }
    if(A[N-2]<A[N-1]) B.push_back(A[N-1]);

    bool flag = true;
    ll ans = 1000, n = 0;
    int K = B.size();
    REP(i,K-1){
        if(B[i]==B[i+1]) continue;
        if(B[i]<B[i+1]){
            n += ans/B[i];
            ans -= ans/B[i]*B[i];
        }
        else{
            ans += n*B[i];
            n = 0;
        }
    }
    if(n>0 && !B.empty()) ans += n*B.back();
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
using namespace std;
int main() {
	int a = 0, b = 0;
	cin >> a >> b;
	int counto[55] = {};
	int c = 0, d = 0;
	for (int i = 0; i < b; i++) {
		cin >> c >> d;
		counto[c - 1]++;
		counto[d - 1]++;
	}
	for (int i = 0; i < a; i++) {
		cout << counto[i] << endl;
	}
	return 0;
}

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

using namespace std;

int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}


#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)
typedef long long ll;
const ll MOD = 1000000007;


/*
int main(){
    int n,m,x;
    cin >> n >> m >> x;

    vector<vector<int>> a(n+1, vector<int>(m+1));
    vector<int> x(m+1);
    rep1(i,n){
        rep(j,m+1) cin >> a[i][j];
    }

    rep1(i,n){

    }


}*/

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

    vector<int64_t> a(n+1);
    vector<int64_t> b(n+1);
    vector<int64_t> c(n+1);
    rep1(i,n){
        cin >> a[i];
        b[i]=0;
        c[i]=0;
    }

    int64_t cnt=1,p_i=1,l=0;

    while(cnt<=k){
        if(b[a[p_i]]==0){
            if(cnt==k){
                break;
            }else{
                b[a[p_i]]++;
                c[a[p_i]] = cnt;
                p_i = a[p_i];
                cnt++;
            }
        }else{
            l=1;
            break;
        }
    }
    int64_t loop = 0,ans=0;

    if(l==0){
        cout << a[p_i] << endl;
    }else{
        loop = cnt - c[a[p_i]];
        ans = (k-cnt-1)%loop;
        if(ans==0) ans =loop;
        rep1(i,ans+1) p_i = a[p_i];

        cout << a[p_i] << endl;
    }
}

Measured memory_bytes: 8012
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int kabe[201];

main(){
	int W,Q;
	
	while(cin>>W>>Q){
		if(W==0 && Q==0)break;
		
		for(int i=0;i<101;i++){
			kabe[i]=-1;
		}
		
		for(int i=0;i<Q;i++){
			char c;
			cin>>c;
			
			if(c=='s'){
				int id,w;
				cin>>id>>w;
				
				int f=0,b=0;
				
				for(int i=0;i<W;i++){
					int haba=0,b=i;
					
					for(;haba+i<W;++haba){
						if(kabe[haba+i]!=-1){
							break;
						}
					}
					
					if(haba>=w){
						cout<<b<<endl;
						for(int i=0;i<w;i++){
							kabe[b+i]=id;
						}
						f=1;
						break;
					}
				}
				if(f==0)puts("impossible");
			}else{
				int id;
				cin>>id;
				for(int i=0;i<=W;i++){
					if(kabe[i]==id)kabe[i]=-1;
				}
			}
		}
		puts("END");
	}
}

Measured memory_bytes: 0
# import sys;input = lambda : sys.stdin.readline()
s = input()
A, Z = None, None
for i in range(len(s)):
    if s[i] == "A":
        A = i
        break
for i in range(len(s) - 1, -1, -1):
    if s[i] == "Z":
        Z = i
        break
print(Z - A + 1)


Measured memory_bytes: 9216
#include <iostream>
using namespace std;
int main(){
	int n;
	int a[200000];
	int a2;
	cin >> n;
	for(int i = 0;i < n;i++){
		a[i] = 0;
	}
	for(int i = 0;i < n - 1;i++){
		cin >> a2;
		a[a2 - 1]++;
	}
	for(int i = 0;i < n;i++){
		cout << a[i] << endl;
	}
}


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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	if(s=="zyxwvutsrqponmlkjihgfedcba"){puts("-1");return 0;}
	//if(sz(s)==26);{puts("-1");return 0;}
	int ck[27] ={};
	for(auto x: s) ck[x-'a']++;
	if(sz(s)<26){
		rep(j,26) if(ck[j]==0){
			cout << s << char('a'+j) <<"\n";
			return 0;
		}
	}
	/*
	repr(i,25,0){
		repr(j,i-1,0){
			if(s[i] > s[j]){
				swap(s[i], s[j]);
				cout << s.substr(0,j+1) <<"\n";
				return 0;
			}
		}
	}
	*/
	
	auto ws =s;
	int c=0;
	do {
		c++;
		if(c==2) break;
	} while ( next_permutation(ws.begin(), ws.end()) );

	
	//cout <<ws <<endl;
	rep(i,sz(s)){
		if(ws[i]==s[i]) cout << s[i];
		else{
			cout <<ws[i] <<"\n";
			break;
		}
	}
	return 0;
	
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
B - Palindromic Numbers
https://beta.atcoder.jp/contests/abc090/tasks/abc090_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(A, B):
    ans = 0
    for i in range(A, B+1):
        s1 = str(i)
        s2 = s1[::-1]
        if s1 == s2:
            ans += 1
    return ans


def main(args):
    A, B = map(int, input().split())
    ans = solve(A, B)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

ll dp[110][100010] = {0};

int main() {
  int N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      dp[i + 1][j] = dp[i][j];
      if (j - w[i] >= 0) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
      }
    }
  }
  
  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a[101000];
    long long k,m,n;
    cin>>a;
    n=strlen(a);
    for(int i=0;i<n;i++){
        if(a[i]=='e'){
            if(a[i+1]=='r'&&a[i+2]=='a'&&a[i+3]=='s'&&a[i+4]=='e'){
                if(a[i+5]=='r'){
                    i+=5;
                }else{
                    i+=4;
                }
            }
        }else if(a[i]=='d'){
            if(a[i+1]=='r'&&a[i+2]=='e'&&a[i+3]=='a'&&a[i+4]=='m'){
                if(a[i+5]=='e'&&a[i+6]=='r'&&a[i+7]=='a'&&a[i+8]=='s'&&a[i+9]=='e'){
                    i+=4;
                }else{
                    if(a[i+5]=='e'&&a[i+6]=='r'){
                        i+=6;
                    }else{
                        i+=4;
                    }
                }
            }
        }else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

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

const int MAXN = 200010;
const int MAXM = 26;

int C[MAXN],F[MAXN][MAXM],A[MAXN];
string st;
int N;
char ch;

void output(int p, int c){
  if(c == 0) return;
  for(int i = 0; i < MAXM; i++) {
    if(F[p][i] == 0){
      printf("%c",'a'+i);
      return;
    }
    if(C[F[p][i]] < C[p]) {
      printf("%c",'a'+i);
      output(F[p][i],c-1);
      return;
    }
  }
}

int main(){
  cin >> st;
  N = st.length() + 1;
  for(int i = 1; i < N; i++) {
    A[i] = st[i-1] - 'a';
  }

  C[0] = 0;
  for(int i = N - 1; i >= 0; i--) {
    if(i < N - 1) {
      for(int j = 0; j < MAXM; j++){
        F[i][j] = F[i+1][j];
      }
      F[i][A[i + 1]] = i + 1;
    }
    C[i] = N;
    for(int j = 0; j < MAXM; j++) {
      int v = C[F[i][j]];
      if(F[i][j] == 0) {
        v = 0;
      }
      if (C[i] > v + 1) {
        C[i] = v + 1;
      }
    }
  }
  output(0,C[0]);
  return 0;
}


Measured memory_bytes: 22524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int r,p,s;
int score(char x){
    if (x == 'r') return p;
    else if (x == 'p') return s;
    else return r;
}
int main(){
    int n,k;
    scanf("%d%d%d%d%d",&n,&k,&r,&s,&p);
    string t;
    cin >> t;
    int ans[n]; memset(ans,0,sizeof(ans));
    for (int i = 0; i < n; i++){
        int sc = score(t[i]);
        ans[i] = sc;
        if (i >= k){
            if (t[i] != t[i-k]) ans[i] = ans[i-k]+sc;
            else {
                ans[i] = max(ans[i],ans[i-k]);
                if (i >= 2*k){
                    ans[i] = max(ans[i],ans[i-2*k]+sc);
                }
            }
        }

    }
    //for (int i = 0; i < n; i++) printf("%d ",ans[i]);
    int sum = 0;
    for (int i = n-1; i > n-1-k; i--) sum += ans[i];
    printf("%d",sum);
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)
#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)
#define pb push_back
#define all(v) ((v.begin()),(v.end()))
#define memset(c, value) memset(c, (int)value, sizeof(c))
using namespace std;
typedef long long ll;
const int oo = 1e9;
const ll MOD =1e9+7;
void fast(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int n;
int h[100005];
bool valid (int r,int c){
    return (r < n && r >= 0 && c >= 0 && c < n);
}
int row[] = {0 , 1 , 0, -1};
int column[] = {1 , 0, -1, 0};
int vis[100002];
int dp(int i){
    if(i == n-1)
        return 0;
    int &ret = vis[i];
    if(ret != -1)
        return ret;

    int path1 = abs(h[i]-h[i+1]) + dp(i+1);
    if(i+2 < n)
        path1 =min(path1, abs(h[i]-h[i+2]) + dp(i+2));
    return ret = path1;
}

int main()
{
    fast();
    memset(vis, -1);
    cin>>n;
    f(i,0,n)
        cin>>h[i];
    cout<<dp(0)<<'\n';
    return 0;
}


Measured memory_bytes: 9064
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <utility>
#include <queue>
#define ull unsigned long long
#define ll long long
#define mod 1000000007
using namespace std;



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

    vector <int> s(n+1, 0);
    int c1;
    int c2;
    for (int i=0;i<n;i++){
        int a;
        cin>>a;

        if ( i == 0 ) c1 = a;
        if ( i == 1 ) c2 = a;
        if ( !i ) s[i] = a;
        else s[i]+=s[i-1] + a;
    }

    if ( n == 2 ){
        cout<<abs(c1-c2)<<endl;
        return 0;
    }

    int minn = 2e9;
    for (int i=1;i<n;i++){
        int d1 = s[i];
        int d2 = s[n-1] - s[i];
        minn = min(minn, abs(d1-d2));
    }

    cout<<minn<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		long[] A = new long[N];
		for(int i = 0;i < N;i++) {
			A[i] = scn.nextLong();
		}
		long[] ans = new long[N];
		boolean plus = true;
		for(int i = 0;i < N;i++) {
			ans[0] += plus?A[i]:-A[i];
			plus = !plus;
		}
		for(int i = 1;i <N;i++) {
			ans[i] = 2 * (A[i-1] - ans[i-1]/2);
		}
		for(int i = 0;i < N;i++) {
			System.out.print(((i==0)?"":" ") + ans[i]);
		}
	}

}

Measured memory_bytes: 67368
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>

using namespace std;




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

	string s;
	cin >> s;

	s.erase(--s.end());
	if (s.length() % 2 == 1)
		s.erase(--s.end());
	
	int n = s.length()/2;
	for (int i = 0; i < n; ++i)
	{
		if (s.substr(0, s.length() / 2) == s.substr(s.length() / 2, s.length()))
		{
			break;
		}
		s.erase(--s.end());
		s.erase(--s.end());
	}
	cout << s.length() << "\n";

	return 0;
}


Measured memory_bytes: 256