akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
//{{{ read()
inline ll read(){
	register ll x=0,f=1;
	register char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')	f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')	x=x*10+(ch^48),ch=getchar();
	return x*f;
}
//}}}
const int N=3005;
const int P=1e9+7;
const int Gi=(P+1)>>1;
int n,q,ans,fac,a[N],f[N][N],g[N][N];
void Add(int &x,int y){
	x+=y,x-=x>=P?P:0;
}
int main(){
	n=read(),q=read(),fac=1;
	for(int i=1;i<=n;i++)	a[i]=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i]<a[j])	f[i][j]=1;
	while(q--){
		int x=read(),y=read();
		for(int i=1;i<=n;i++)
			if(x!=i&&y!=i){
				f[x][i]=g[x][i]=1ll*f[x][i]*Gi%P,f[y][i]=g[y][i]=1ll*f[y][i]*Gi%P;
				f[i][x]=g[i][x]=1ll*f[i][x]*Gi%P,f[i][y]=g[i][y]=1ll*f[i][y]*Gi%P;
			}
		f[x][y]=g[x][y]=1ll*f[x][y]*Gi%P;
		f[y][x]=g[y][x]=1ll*f[y][x]*Gi%P;
		for(int i=1;i<=n;i++)
			if(i!=x&&i!=y){
				Add(f[y][i],g[x][i]),Add(f[i][y],g[i][x]);
				Add(f[x][i],g[y][i]),Add(f[i][x],g[i][y]);
			}
		Add(f[x][y],g[y][x]),Add(f[y][x],g[x][y]),Add(fac,fac);
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++) ans=(ans+1ll*f[j][i]*fac)%P;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int a[55555];
	fill(a, a + 55555, 0);
	vector<int> b;
	for (int i = 2; i < 55555; i++) {
		if (a[i] == 0) {
			if (i % 5 == 1) b.push_back(i);
			for (int j = i * 2; j < 55555; j += i) a[j] = 1;
		}
	}
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", b[i]);
	}
	printf("\n");
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);

  for (int i = 1; i < N; i++) {
    string X = vec.at(i - 1), Y = vec.at(i);
    if (X.at(X.size() - 1) != Y.at(0)) {
      cout << "No" << endl;
      return 0;
    }
  }

  sort(vec.begin(), vec.end());

  for (int i = 1; i < N; i++) {
    if (vec.at(i - 1) == vec.at(i)) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif
struct UF {
public:
  int N,G/* # of disjoint sets */;
  UF(int N): N(N) { init(N); }
  void init(int N) {
    par=vector<int>(N),sz=vector<int>(N,1);
    for(int i=0; i<N; ++i) par[i]=i,sz[i]=1;
    G=N;
  }
  int find(int x) { return par[x]==x?x:par[x]=find(par[x]); }
  int size(int x) { return sz[find(x)]; }
  bool sameset(int x, int y) { return find(x)==find(y); }
  int unite(int x, int y) {
    x=find(x),y=find(y);
    if(x==y) return x;
    int p=x,c=y;
    if(sz[p]<sz[c]) swap(p,c);
    G--,sz[p]=sz[c]=sz[p]+sz[c];
    par[c]=p;
    return p;
  }
private:
  vector<int> par,sz;
};
// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*

 6/22/2020

 21:17-

 */

const int MAX_N=1e6+1;
int N,M;

VI L[MAX_N];
void solve() {
  UF uf(N);
  REPE(i,M) REP(j,SZ(L[i])-1) uf.unite(L[i][j],L[i][j+1]);
  ///REP(i,N) dump(i,uf.find(i));
  //dumpc(L[6]);
  //dump(uf.G);
  cout<<(uf.G==1?"YES":"NO")<<endl;
}

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

  cin>>N>>M;
  REP(i,N) {
    int K; cin>>K;
    REP(j,K) {
      int l; cin>>l;
      L[l].push_back(i);
    }
  }
  solve();

  return 0;
}


Measured memory_bytes: 29040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100001][4];
ll arr[100001][4];
ll n;
int pro(ll a,ll b){
  ll mx=0;
  if(a==n)
  return 0;
  if(dp[a][b]!=-1)
  return dp[a][b];
  if(b==0){
    mx=max(mx,arr[a][1]+pro(a+1,1));
    mx=max(mx,arr[a][2]+pro(a+1,2));
    mx=max(mx,arr[a][3]+pro(a+1,3));
  }
  else if(b==1){
    mx=max(mx,arr[a][2]+pro(a+1,2));
    mx=max(mx,arr[a][3]+pro(a+1,3));
  }
  else if(b==2){
    mx=max(mx,arr[a][1]+pro(a+1,1));
    mx=max(mx,arr[a][3]+pro(a+1,3));
  }
  else if(b==3){
    mx=max(mx,arr[a][1]+pro(a+1,1));
    mx=max(mx,arr[a][2]+pro(a+1,2));
  }
  dp[a][b]=mx;
  return dp[a][b];
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=1;j<4;j++){
      cin>>arr[i][j];
    }
  }
  memset(dp,-1,sizeof(dp));
  cout<<pro(0,0)<<endl;
  return 0;
}


Measured memory_bytes: 17592
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
	char a,b,c,d,e,f,g,h,i;
	cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
	cout<<a<<e<<i<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = (1 << 30) - 1;
const ll LINF = (1L << 62) - 1;
const ll MOD = 1000000007;
template <class T> inline void chmin(T& a, T& x) { a = a < x ? a : x; }
template <class T> inline void chmax(T& a, T& x) { a = a > x ? a : x; }

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

  int n;
  cin >> n;
  auto cmp = [](P a, P b) { a.first == b.first ? a.second > b.second : a.first > b.first; };
  priority_queue<P> plus, minus;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int mi = 0, sum = 0;
    for (int i = 0; i < s.size(); ++i) {
      sum += s[i] == '(' ? 1 : -1;
      chmin(mi, sum);
    }
    if (sum >= 0) {
      plus.push(P(mi, sum));
    } else {
      minus.push(P(mi - sum, -sum));
    }
  }
  int curL = 0;
  while (!plus.empty()) {
    P x = plus.top();
    plus.pop();
    if (curL + x.first < 0) {
      cout << "No" << endl;
      return 0;
    }
    curL += x.second;
  }
  int curR = 0;
  while (!minus.empty()) {
    P x = minus.top();
    minus.pop();
    if (curR + x.first < 0) {
      cout << "No" << endl;
      return 0;
    }
    curR += x.second;
  }
  cout << (curL == curR ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 11208
N, M = map(int, input().split())
nodes = [i for i in range(N)]


def root(x):
    if nodes[x] == x:
        return x
    else:
        nodes[x] = root(nodes[x])
    return nodes[x]


def same(x, y):
    return root(x) == root(y)


def unite(x, y):
    if not same(x, y):
        nodes[root(x)] = root(y)


for _ in range(M):
    X, Y, Z = map(int, input().split())
    unite(X-1, Y-1)


ans = 0
for i in range(len(nodes)):
    if nodes[i] == i:
        ans += 1

print(ans)


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

int main()
{
	int N;
	cin >> N;
	vector<int> An(N, 0);
	bool judge = true;
	rep(i, N) {
		cin >> An[i];
		if (An[i] % 2 == 0) {
			if (An[i] % 3 != 0 && An[i] % 5 != 0) {
				judge = false;
			}
		}
	}

	if (judge) {
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}

	return 0;
} 

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,asum=0,bsum=0,ans=0;cin>>n;
  vector<ll> avec(n),bvec(n);
  rep(i,n) {cin>>avec[i];asum+=avec[i];}
  rep(i,n) {cin>>bvec[i];bsum+=bvec[i];}
  if(bsum>asum) ans=-1;
  else {
    ll m=0,sum=0,pos=n-1;vector<ll> p(n,0);
    rep(i,n) {
      if(avec[i]>bvec[i]) p[i]=avec[i]-bvec[i];
      if(avec[i]<bvec[i]) {m+=bvec[i]-avec[i];ans++;}
    }
    sort(p.begin(),p.end());
    while(sum<m) {sum+=p[pos];ans++;pos--;}
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
	int n,max2=0,maxx=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]>=a[maxx]) max2=maxx,maxx=i;
		else if(a[i]>a[max2]) max2=i;
	}
	for(int i=1;i<=n;i++)
	{
		if(maxx==i) printf("%d\n",a[max2]);
		else printf("%d\n",a[maxx]);
	}
}


Measured memory_bytes: 2432
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll              long long
#define ull             unsigned long long
#define fastread()      (ios_base:: sync_with_stdio(false),cin.tie(NULL));

using namespace std;
int main()
{
    fastread();
    int n,zero = 0;
    ll prod =1,a[100005];

    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        if(a[i] == 0){
            cout<<0<<endl;
            return 0;
        }
    }
    for(int i=0; i<n; i++){
        if(a[i] <= 1000000000000000000/prod){
            prod *=a[i];
        }
        else{
            cout<<-1<<endl;
            return 0;
        }
    }

    cout<<prod<<endl;

    return 0;
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

ll ans=0;
void eat(ll X, ll N){
  ll sum = pow(2,N+2)-3;
  if(X >= sum/2 + 1){
    ans += pow(2, N);
    X -= sum/2;
    //    cout << ans << endl;
  }
  X-=1;
  if(N!=0 && X!=0){
    N-=1;
    eat(X, N);
  }
}




int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, X;
  cin >> N >> X;
  eat(X,N);
  cout << ans << endl;
  
  return 0;
  

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  string s;
  string out = "";
  int len = -1;

  cin >> s;
  // s = "011BBB111";

  for (size_t i = 0; i < s.size(); i++){
    if (len>=0 && s[i]=='B'){
      out = out.erase(len);
      len--;
      continue;
    }else if (s[i]=='0'){
      out = out + "0";
      len++;
      continue;
    }else if (s[i]=='1'){
      out = out + "1";
      len++;
      continue;
    }
  }
  cout << out << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	vector<int>d(10001, 0);
	rep(i, 0, N)d[v[i]]++;
	vector<int>ans;
	rep(i, 0, d.size()) {
		while (d[i]--)ans.emplace_back(i);
	}
	rep(i, 0, ans.size())cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 18952
import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
for h, w in itertools.product(range(H), range(W)):
    if A[h][w] == 'S':
        break
visited = A
res = K - 1
Q = collections.deque([[h - 1, w, res], [h + 1, w, res], [h, w - 1, res],
                       [h, w + 1, res]])
sH = set([h])
sW = set([w])
while Q:
    h, w, res = Q.popleft()
    if 0 <= h < H and 0 <= w < W and A[h][w] == '.' and visited[h][w] != '#':
        visited[h][w] = '#'
        sH.add(h)
        sW.add(w)
        if res:
            res -= 1
            Q += [[h - 1, w, res], [h + 1, w, res], [h, w - 1, res],
                  [h, w + 1, res]]
print(1 +
      math.ceil(min([min(sH), H - 1 - max(sH),
                     min(sW), W - 1 - max(sW)]) / K))


Measured memory_bytes: 101212
#include <iostream>
using namespace std;
long long N, Q;
long long trees[500005] = {0};

void update(int idx, long long value){
    idx = idx + 1;
    while( idx<=N+1 ){
        trees[idx]+= value;
        idx += idx&(-idx);
    }
}

long long getSum(int idx){
    idx = idx + 1;
    long long  s= 0;
    while(idx > 0){
        s += trees[idx];
        idx -= idx&(-idx);
    }

    return s;
}

int main(){
    scanf("%lld%lld",&N,&Q);
    for(int i = 1; i <= N; ++i){
        long long a;
        scanf("%lld",&a);
        update(i,a);
    }

    for(int i = 0 ; i < Q; ++i){
        long long x1,x2,x3;
        scanf("%lld%lld%lld",&x1,&x2,&x3);
        if (x1 == 0){
            update(x2+1,x3);
        }else{
            printf("%lld\n",getSum(x3)-getSum(x2));
        }
    }
}

Measured memory_bytes: 8264
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 = new int[5][3];
		int min = 10;
		int minp = 0;
		int sum = 0;

		for (int i = 0; i < 5; i++) {
			n[i][0] = sc.nextInt();
			n[i][1] = n[i][0] % 10;
			if (n[i][1] == 0) {
				n[i][2] = n[i][0];
			} else {
				n[i][2] = (n[i][0] + 10) / 10 * 10;
				if (n[i][1] < min) {
					min = n[i][1];
					minp = i;
				}
			}
			

		}
		
		for(int k=0; k<5;k++){
			sum += n[k][2];
		}
		sum = sum - n[minp][2] + n[minp][0];
		System.out.println(sum);
		

	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N;
  int D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int> (D));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int sum = 0;
      for (int d = 0; d < D; d++) {
        sum += pow(X[i][d] - X[j][d], 2);
      }
      float dist = sqrt(sum);
      if (dist == floor(dist)) count++;
    }
  }
  cout << count << endl;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    vector<vector<ll>> a(n, vector<ll>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }

    vector<vector<ll>> dp(n, vector<ll>(n, linf));
    for (int i = 0; i < n; i++) dp[i][i] = 0;
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (k == i || k == j) continue;
                dp[i][j] = min(dp[i][j], a[i][k] + a[k][j]);
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i][j] < dp[i][j]) ans += a[i][j];
            if (a[i][j] > dp[i][j]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4772
n = int(input())
dif = list(map(int,input().split()))
new_dif = list(sorted(dif))
if new_dif[n//2-1] == new_dif[n//2]:
  print(0)
  
else:
  print(new_dif[n//2]-new_dif[n//2-1])

Measured memory_bytes: 20832
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        (a, b): (u128, String)
    };

    let b = b.replace(".", "");
    let b: u128 = b.parse().unwrap();
    let ans = a * b / 100;

    println!("{}", ans);
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int fun(int ar[],int n)
{
	if(n==1)
		return 0;
	if(n==2)
		return abs(ar[n]-ar[n-1]);
	return min(abs(ar[n]-ar[n-1])+fun(ar,n-1),abs(ar[n]-ar[n-2])+fun(ar,n-2));
}
int main()
{
	int n,i;
	scanf("%d",&n);
	int ar[n+1];
	for(i=1;i<=n;i++)
		scanf("%d",ar+i);
	int dp[n+1];
	dp[1]=0;
	dp[2]=abs(ar[2]-ar[1]);
	for(i=3;i<=n;i++)
		dp[i]=min(abs(ar[i]-ar[i-1])+dp[i-1],abs(ar[i]-ar[i-2])+dp[i-2]);
	printf("%d\n",dp[n]);
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N + 1, 0);
    vector<int> B(N + 1, 0);
    for(int i = 1; i <= N; i++)cin >> A[i];
    
    for(int i = N; i > 0; i--){
        int see = i;
        int sum = 0;
        while(see <= N){
            sum += B[see];
            see += i;
        }
        if(sum % 2 != A[i])B[i]++;
    }
    
    int cnt = 0;
    vector<int> ans;
    for(int i = 1; i <= N; i++){
        if(B[i] > 0){
            cnt++;
            ans.push_back(i);
        }
    }
    
    cout << cnt << endl;
    for(auto a : ans)cout << a << endl;
    return 0;
}

Measured memory_bytes: 3064
X, K, D = map(int, input().split())
ans = 10 ** 19
X = abs(X)
if X >= K * D:
    print(X - K * D)

else:
    c = X // D
    if (K - c) % 2 == 0:
        print(X - c * D)
    else:
        print(D * (c + 1) - X)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
string n;
int a,i;
int main()
{
    cin>>n;
    a=n.length();
   for(i=0;i<a;i++)
   {
       if(n[i]==',')
       cout<<" ";
       else
       cout<<n[i];
   }
   cout<<endl;
    return 0;
}

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


int main () {
  int K, o = 0, e = 0, count = 1;
  cin >> K;
  while (count <= K) {
    e += 1;
    count += 2;
  }
  count = 2;
  while (count <= K) {
    o += 1;
    count += 2;
  }
  cout << e * o << endl;
}


Measured memory_bytes: 3572
n,m=map(int,input().split())
count=0
s=[0]*(n+1)
L=0
R=10**5
 
for i in range(m):
  l,r=map(int,input().split())
  L=max(l,L)
  R=min(r,R)
  
if (R-L+1)>=0:
  print(R-L+1)
else:
  print(0)

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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int start=101;
    int n;
    cin>>n;
    int sum=0;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i=1;i<n;i++)
    {
        if(v[i]==v[i-1])
        {
            v[i]=start++;
            sum++;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<ll,pll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define pb push_back
const ll inf = 2e18 + 7;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 7;
const ld pi = 3.14159265358979;

void solve() {
    ll n;
    cin>>n;
    vector<ll> a(n),b(n);
    for(int i=0;i<n;i++) {
        cin>>a[i]>>b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll lb,ub;
    if(n%2) {
        lb = a[(n/2)];
        ub = b[(n/2)];
    }
    else {
        lb = a[(n/2)]+a[(n/2)-1];
        ub = b[(n/2)]+b[(n/2)-1];
    }
    cout<<ub-lb+1;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--) {
        solve();
        // cout<<"\n";
    }
    return 0; 

}


Measured memory_bytes: 6372
#include <stdio.h>
#include <math.h>

int main(void) {
	long long x;
	scanf("%lld", &x);
	long long a = 100;
	int year = 0;
	while (a < x) {
		 a = floor(a * 1.01);
		year = year + 1;
	}
	printf("%d", year);

	return 0;
}

Measured memory_bytes: 2200
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var input = lines[0].split(' ');
 var num = input[1];
 var inst = lines[1].split('');

inst[num-1] = inst[num-1].toLowerCase();
console.log(inst.join(''));
 
});

Measured memory_bytes: 7500
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    S = input()
    """
    0, 1番目を決定すればそこから先は一意に確定するのでO(4N)で愚直にチェック可能
    """
    ans = [0] * N
    for i in range(4):
        ans[0] = i % 2
        ans[1] = i // 2
        for j in range(1, N - 1):
            if S[j] == 'o' and ans[j] == 1:
                ans[j + 1] = ans[j - 1]
            elif S[j] == 'o' and ans[j] == 0:
                ans[j + 1] = 1 - ans[j - 1]
            elif S[j] == 'x' and ans[j] == 1:
                ans[j + 1] = 1 - ans[j - 1]
            else:
                ans[j + 1] = ans[j - 1]
        if S[-1] == 'o' and ans[-1] == 1 and ans[-2] != ans[0]: continue
        if S[-1] == 'o' and ans[-1] == 0 and ans[-2] == ans[0]: continue
        if S[-1] == 'x' and ans[-1] == 1 and ans[-2] == ans[0]: continue
        if S[-1] == 'x' and ans[-1] == 0 and ans[-2] != ans[0]: continue
        if S[0] == 'o' and ans[0] == 1 and ans[-1] != ans[1]: continue
        if S[0] == 'o' and ans[0] == 0 and ans[-1] == ans[1]: continue
        if S[0] == 'x' and ans[0] == 1 and ans[-1] == ans[1]: continue
        if S[0] == 'x' and ans[0] == 0 and ans[-1] != ans[1]: continue
        t = ''
        for a in ans: 
            if a == 0:
                t += 'W'
            else:
                t += 'S'
        print(t)
        return
    print(-1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 93904
n=int(input())
a=list(map(int,input().split()))

a.sort()
amx=max(a)+1
l=[True]*amx
ans=0

for i in range(n-1):
    if l[a[i]]:
        for j in range(a[i],amx,a[i]):
            l[j]=False
        if a[i]<a[i+1]:
            ans+=1

if l[-1]:
    ans+=1

print(ans)

Measured memory_bytes: 32368
import sys
import os
import math
N = int(input())
A = list(map(int,input().split()))

cost = 0
ave = sum(A)/N
if math.ceil(ave)-ave < 0.5:
    ave = math.ceil(ave)
else:
    ave = math.floor(ave)
for a in A:
    cost += (a-ave)**2
print(cost)


Measured memory_bytes: 3060
s=input()
a,b,c,d=0,0,0,0
for i in range(len(s)):
 if s[i]==">":
  c=0;b+=1
  if b<=d:a+=b-1
  else:a+=b
 else:b=0;c+=1;a+=c;d=c
print(a)

Measured memory_bytes: 9940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)

int m, n, k, x[200005], y[200005], N;
bool u[2][200005], sw, T;
map<int, int> r[100005], c[100005];
ll D;
pq<pair<pair<ll, int>, bool> > q;
int main(){
    scanf("%i%i%i", &m, &n, &k);
    fox(l, k){
        scanf("%i%i", &y[l], &x[l]);
        r[x[l]][y[l]]=l;
        c[y[l]][x[l]]=l;
        if (x[l]==1 && y[l]==1) sw=1;
    }
    x[k]=n; y[k]=m;
    x[k+1]=1; y[k+1]=1;
    r[n][m]=k; c[m][n]=k;
    q.push(mp(mp(0, k+1), 1));
    //cout << x[0] << ' ' << y[0] << endl;
    while(!q.empty()){
        N=q.top().x.y; D=-q.top().x.x; T=q.top().y; q.pop();
        if (u[T][N]) continue;
        u[T][N]=1;
        if (N!=k+1 || sw)
        q.push(mp(mp(-D-1, N), !T));
        //cout << N << ' ' << T << ' ' << D << endl;
        if (N==k){
            cout << D << endl;
            return 0;
        }
        if (T){
            c[y[N]].erase(x[N]);
            //cout << N << ' ' << y[N] << ' ' << c[y[N]].size() << endl;
            //for (auto i:c[y[N]]) cout << i.x << ' '; cout << endl;
            if (c[y[N]].lb(x[N])!=c[y[N]].end())
                q.push(mp(mp(-D-(c[y[N]].lb(x[N])->x-x[N]), c[y[N]].lb(x[N])->y), T));
            if (c[y[N]].lb(x[N])!=c[y[N]].begin())
                q.push(mp(mp(-D-(x[N]-(--c[y[N]].lb(x[N]))->x), (--c[y[N]].lb(x[N]))->y), T));
        } else {
            r[x[N]].erase(y[N]);
            //cout << r[x[N]].size() << endl;
            if (r[x[N]].lb(y[N])!=r[x[N]].end()){
                q.push(mp(mp(-D-(r[x[N]].lb(y[N])->x-y[N]), r[x[N]].lb(y[N])->y), T));
            }
            if (r[x[N]].lb(y[N])!=r[x[N]].begin())
                q.push(mp(mp(-D-(y[N]-(--r[x[N]].lb(y[N]))->x), (--r[x[N]].lb(y[N]))->y), T));
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 36032
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 3000+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

string s1, s2, res;

int dp[maxn][maxn];

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	// 
	cin >> s1 >> s2;
	for (int i = 0; i < s1.length(); i++)
		for (int t = 0; t < s2.length(); t++) {
			if (i)
				dp[i][t] = max(dp[i][t], dp[i - 1][t]);
			if (t)
				dp[i][t] = max(dp[i][t], dp[i][t - 1]);
			if (s1[i] == s2[t]) {
				if (i == 0 || t == 0)
					dp[i][t] = max(dp[i][t], 1);
				else
					dp[i][t] = max(dp[i][t], dp[i - 1][t - 1] + 1);
			}
		}
	//
	//cout << dp[s1.length() - 1][s2.length() - 1] << "\n";
	int x = s1.length() - 1, y = s2.length() - 1;
	int ans = dp[x][y];
	while (ans && min(x, y) >= 0) {
		if (x && dp[x - 1][y] == dp[x][y]) {
			x--;
			continue;
		}
		if (y && dp[x][y - 1] == dp[x][y]) {
			y--;
			continue;
		}
		res = s1[x] + res;
		ans--;
		x--;
		y--;
	}
	cout << res << "\n";
	//
}



Measured memory_bytes: 35584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;
const int Mo=998244353;
map <string,int> f;
inline int solve(string s) {
    if(s.empty()) return 1;
    if(f.count(s)) return f[s];
    int &ret=f[s],n=s.size();
    ret=solve(s.substr(1));
    if(s[0]=='1') ret=(ret+ret)%Mo;
    for(int i=1;i<n;i++) {
	string x=s.substr(0,i);
	for(int j=i;j+i<=n;j+=i) {
	    for(int k=0;k<i;k++)
		if(s[j+k]=='0') x[k]='0';
	    ret=(ret+1LL*solve(x)*solve(s.substr(j+i)))%Mo;
	}
    }
    return ret;
}
int main() {
    string s;
    cin>>s;
    cout<<solve(s);
    return 0;
}

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(long long N) {
  ll S = 0LL;
  ll Norg = N;
  while(N>0){
    S += (N%10);
    N/=10;
  }
  bool ok = Norg % S==0;
  yesno(ok);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long N;
  std::cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

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



int main(){
    int a,b; cin >> a >> b;
    
    int ans=-1;
    
    if (a<=9 && b<=9 && 1 <= a && 1 <= b) {
        ans = a*b;
    }
    
    cout << ans << endl;
    return 0;
    
}



Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int t[64];
int d[100100];
ll rec(int num) {
	if (num == 0) return 0;
	return rec(num - 1) + num;
}

void Solve() {

	ll q, h, s, d;
	cin >> q >> h >> s >> d;
	ll n;
	cin >> n;
	ll uq, uh, ud;
	uq = q * 4;
	uh = h * 2;
	ll md = 2 * min(uq, min(uh, s));
	ll res = 0;
	if (md < d) {
		res += (n / 2) * md;
	}
	else {
		res += (n / 2) * d;
	}
	res += (n % 2 == 0) ? 0 : md / 2;
	cout << res << endl;
}


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



Measured memory_bytes: 6016
#include <iostream>

using namespace std;

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

    int ans;
    if      (N <  2) ans = 1;
    else if (N <  4) ans = 2;
    else if (N <  8) ans = 4;
    else if (N < 16) ans = 8;
    else if (N < 32) ans = 16;
    else if (N < 64) ans = 32;
    else             ans = 64;

    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
ais = list(map(int, input().split()))
bis = list(map(int, input().split()))
cis = list(map(int, input().split()))
sat = bis[ais[0]-1]
for i in range(1, n):
  sat += bis[ais[i]-1]
  if ais[i] == ais[i-1] + 1:
    sat += cis[ais[i]-2]
print(sat)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    ll a[20], x[20][20], y[20][20];
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        for(ll j = 0; j < a[i]; j++)
            cin >> x[i][j] >> y[i][j];
    }
    ll ans = 0;
    for(ll bin = 0; bin < (1<<n); bin++){
        bool ok = true;
        for(ll i = 0; i < n; i++){
            if(!(bin&(1<<i))) continue;
            for(ll j = 0; j < a[i]; j++){
                if(((bin>>x[i][j]-1)&1)^y[i][j])ok=false;
            }
        }
        ll count = 0;
        if(ok==true){
            for(ll i = 0; i < n; i++){
                if(bin&(1<<i)) count++;
            }
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
char str[50][51];
int a[50][27];
int ans[27];
int size=0;
int main(void){
    int n,i,j;
    scanf("%d",&n);
    FOR(i,0,27) ans[i]=INF;
    FOR(i,0,n){
        scanf("%s",str[i]);
    }
    FOR(i,0,n){
        for(j=0;str[i][j]!='\0';j++){
            a[i][str[i][j]-'a']++;
        }
        FOR(j,0,27) ans[j] = MIN(ans[j],a[i][j]);
    }
    FOR(i,0,27){
        if(ans[i]!=INF){
            while(ans[i]-->0) printf("%c",'a'+i);
        }
    }
    puts("");
    return 0;
}




Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
ans = [0 for i in range(8)]
over = 0
for i in range(n):
  if a[i] >= 3200:
    over += 1
  else:
    ans[a[i]//400] = 1

    

print(str(max(1, sum(ans))) + " " + str(sum(ans)+over))
  


Measured memory_bytes: 3060
A, B, Q = map(int, input().split())

MY_INF = 10 ** 18

s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
x = [int(input()) for _ in range(Q)]

s = [-MY_INF] + s + [MY_INF]
t = [-MY_INF] + t + [MY_INF]

import bisect

for i, xi in enumerate(x):
    ans = 10 ** 18
    #
    # s -> r
    idx_s = bisect.bisect_left(s, xi)
    #
    s_l = s[idx_s - 1]
    idx_tl = bisect.bisect_left(t, s_l)
    #
    t_ll = t[idx_tl - 1]
    ans_tmp = abs(s_l - xi) + abs(t_ll - s_l)
    ans = min(ans, ans_tmp)
    t_lr = t[idx_tl]
    ans_tmp = abs(s_l - xi) + abs(t_lr - s_l)
    ans = min(ans, ans_tmp)
    #
    s_r = s[idx_s]
    idx_tr = bisect.bisect_left(t, s_r)
    #
    t_rl = t[idx_tr - 1]
    ans_tmp = abs(s_r - xi) + abs(t_rl - s_r)
    ans = min(ans, ans_tmp)
    #
    t_rr = t[idx_tr]
    ans_tmp = abs(s_r - xi) + abs(t_rr - s_r)
    ans = min(ans, ans_tmp)
    #
    # t -> r
    idx_t = bisect.bisect_left(t, xi)
    #
    t_l = t[idx_t - 1]
    idx_sl = bisect.bisect_left(s, t_l)
    #
    s_ll = s[idx_sl - 1]
    ans_tmp = abs(t_l - xi) + abs(s_ll - t_l)
    ans = min(ans, ans_tmp)
    s_lr = s[idx_sl]
    ans_tmp = abs(t_l - xi) + abs(s_lr - t_l)
    ans = min(ans, ans_tmp)
    #
    t_r = t[idx_t]
    idx_sr = bisect.bisect_left(s, t_r)
    #
    s_rl = s[idx_sr - 1]
    ans_tmp = abs(t_r - xi) + abs(s_rl - t_r)
    ans = min(ans, ans_tmp)
    #
    s_rr = s[idx_sr]
    ans_tmp = abs(t_r - xi) + abs(s_rr - t_r)
    ans = min(ans, ans_tmp)
    #
    print(ans)


Measured memory_bytes: 16784
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BAToZString solver = new BAToZString();
        solver.solve(1, in, out);
        out.close();
    }

    static class BAToZString {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            String s = in.string();
            out.println(s.lastIndexOf('Z') - s.indexOf('A') + 1);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



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

int main() {
  
  int N;
  cin >> N;
  
  if(N==1){
    cout << "Hello World" << endl;
  }
  else{
    int A,B;
    cin >> A >> B;
    cout << (A+B) << endl;
  }


}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        --A[i];
    }

    map<int, int> used;
    vector<int> path;
    int now = 0;
    while(used.count(now) == 0) {
        path.push_back(now);
        used[now]++;
        now = A[now];
    }

    int s = find(path.begin(), path.end(), now) - path.begin();
    int r = path.size() - s;

    if (K < s) {
        cout << path[K] + 1 << endl;
        return 0;
    } else {
        cout << path[(K-s) % r + s] + 1 << endl;
        return 0;
    }
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<vll> dp(2002,vll(2002,0));

void solve(){
	int s;
	cin>>s;
	fr(i,3,s+1){
		dp[i][1]=1;
	}
	vll sum(2002,0);
	fr(i,6,s+1){
		fr(j,1,2002){
			sum[j]=(sum[j]+dp[i-3][j])%MOD;;
			dp[i][j]=(dp[i][j]+sum[j-1])%MOD;
		}
	}
	ll total=0;
	fr(i,0,2002){
		total=(total+ dp[s][i])%MOD;
	}
	cout<<total<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

Measured memory_bytes: 35028
k = int(input())
n = 10
cnt = 1
if k%2 == 0:
    print(-1)
elif k%5 == 0:
    print(-1)
else:
    if k%7== 0:
        x = 9*k//7
        while True:
            if n%x == 1:
                print(cnt)
                break
            else:
                n = n%x*10%x
                cnt += 1
    else:
        x = 9*k
        while True:
            if n%x == 1:
                print(cnt)
                break
            else:
                n = n%x*10%x
                cnt += 1

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

int main() {
	int N;
	cin >> N;
	string C;
	cin >> C;
	int R = 0, W = 0;
	for (int i = 0; i < N; i++) (C[i] == 'W' ? W : R)++;
	int ans = 0;
	for (int i = 0; i < R; i++) ans += (C[i] == 'W');
	cout << ans << endl;
}


Measured memory_bytes: 3740
from numpy import*;B,I=searchsorted,lambda:int32(input().split());input();a,b=I(),I();c=0
for k in range(29):l=2**k;h=l*2;x,y=a%h,sort(b%h);y=hstack((y-h,y));c+=sum(B(y,h-x)-B(y,l-x))%2*l
print(c)

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

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

    string s, t;
    cin >> s >> t;

    for(int i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int stay,border;
  int X,Y;
  int accomodation_fee=0;
  int i;
  scanf("%d %d %d %d",&stay,&border,&X,&Y);
  for(i=0;i<stay;i++){
    if(i<border){
      accomodation_fee+=X;
    }
    else{
      accomodation_fee+=Y;
    }
  }
  printf("%d",accomodation_fee);
  return 0;
}

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

#define ull unsigned long long int
#define ll long long

using namespace std;

long long A[100000+1];

int main() {
    
    int a[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    int x, y;
    cin>>x>>y;
    cout<<(a[x] == a[y] ? "Yes" : "No")<<"\n";
    
    return 0;
}

Measured memory_bytes: 256
s = gets.chomp

t = s
flag = true
while t.length > 0 && flag == true do
  flag = false
  if s.end_with?("dream") then
    t.slice!(t.length-5, 5)
    flag = true
  elsif s.end_with?("dreamer") then
    t.slice!(t.length-7, 7)
    flag = true
  elsif s.end_with?("erase") then
    t.slice!(t.length-5, 5)
    flag = true
  elsif s.end_with?("eraser") then
    t.slice!(t.length-6, 6)
    flag = true
  end
end

if t.length == 0 && flag == true then
  print("YES\n")
elsif t.length > 0 && flag == false then
  print("NO\n")
end

Measured memory_bytes: 1916
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		int x = in.nextInt();
		int y = in.nextInt();
		
		while (y != 0)
		{
			int temp = y;
			y = x % y;
			x = temp;
		}
		
		System.out.println(x);
		
	}

}


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

int main(void) {
	int n;
	long long ago = 0, a[5] = { 0,0,0,0,0 };
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		if (s[i][0] == 'M') a[0]++;
		else if (s[i][0] == 'A') a[1]++;
		else if (s[i][0] == 'R') a[2]++;
		else if (s[i][0] == 'C') a[3]++;
		else if (s[i][0] == 'H') a[4]++;
	}
	for (int i = 0; i < 3; i++) {
		for (int j = i+1; j < 4; j++) {
			for (int k = j+1; k < 5; k++) {
				ago += a[i] * a[j] * a[k];
			}
		}
	}
	cout << ago << endl;
	return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  string s; cin >> s;
  set<char> ss{s.begin(), s.end()};
  for (char c = 'a'; c <= 'z'; ++c) {
    if (ss.find(c) == ss.end()) {
      cout << c << CRLF;
      return;
    }
  }
  cout << "None" << CRLF;
  return;
}

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

  solve();

  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

using namespace std;

#define MAXN 400

ll dp[MAXN+1][MAXN+1];

int main(){
  int n;cin>>n;
  vector<ll>a(n);
  rep(i, n)cin>>a[i];

  vector<ll> suma(n+1, 0);
  rep(i, n)suma[i+1]+=suma[i]+a[i];

  rep1(l, n)rep(i, n){
    int j = i+l;
    if(i>=j || j>=n)continue;
    dp[i][j]=INF;

    ll sum = suma[j+1]-suma[i];
    for(int m=i; m<=j; m++){
      dp[i][j] = min(dp[i][j], dp[i][m]+dp[m+1][j]+sum);
    }
//    cout<<i<<' '<<j<<' '<<dp[i][j]<<' '<<sum<<endl;
  }

  cout<<dp[0][n-1]<<endl;

  return 0;
  rep(i, n+1){
    rep(j, n+1)cout<<dp[i][j]<<' ';
    cout<<endl;
  }

  return 0;
}

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

struct Edge{int node, id;};//Edge(辺)のノードと  Edge(辺)の色

int main() {
  int N;
  cin >> N;
  vector<int> B(N-1), A(N, 0);//Bの最小値が0なので0で初期化しておく
  for(int i=0; i<N-1; i++){
    cin >> B.at(i);
  }
  
  A.at(0) = B.at(0);//最初だけ入れとかんと0になる
  for(int i=0; i<N-1; i++){
    if(B.at(i) < A.at(i)) A.at(i) = B.at(i);
    A.at(i+1) = B.at(i);
  }
  //for(int i=0; i<A.size(); i++){
  //  cout << "A.at(" << i << "): "<< A.at(i) << endl;
  //}
  cout << accumulate(A.begin(), A.end(), 0) << endl;
}


Measured memory_bytes: 256