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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

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

    vector<ll> dp(1<<N);
    for (int bits=0; bits<(1<<N); ++bits) {
        for (int i=0; i<N; ++i) {
            for (int j=i+1; j<N; ++j) {
                if ((bits & (1<<i)) && (bits & (1<<j))) dp[bits] += a[i][j];
            }
        }
        for (int sub=bits; sub>0; sub=bits&(sub-1)) {
            chmax(dp[bits], dp[sub] + dp[bits&~sub]);
        }
    }
    cout << dp.back() << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3704
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll a,b;

    cin >> a >> b;

    cout << max(0LL, a-2*b) << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Program
{
    public class ABC096D
    {
        static public void Main(string[] args)
        {
            var N = NextInt;
            var sosuAry = Prime(55555).Where(e => e % 10 == 1).ToArray();
            Console.WriteLine(string.Join(" ", sosuAry.Take(N).ToArray()));

        }

        static class Console_
        {
            private static Queue<string> param = new Queue<string>();
            public static string NextString()
            {
                if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
                return param.Dequeue();
            }
        }
        static int NextInt => int.Parse(Console_.NextString());
        static long NextLong => long.Parse(Console_.NextString());
        static string NextString => Console_.NextString();

        static IEnumerable<long> Prime(long x)
        {
            if (x < 2) yield break;
            yield return 2;
            var halfx = x / 2;
            var table = new bool[halfx + 1];
            var max = (long)(Math.Sqrt(x) / 2);
            for (long i = 1; i <= max; ++i)
            {
                if (table[i]) continue;
                var add = 2 * i + 1;
                yield return add;
                for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true;
            }
            for (long i = max + 1; i <= halfx; ++i) if (!table[i]) yield return 2 * i + 1;
        }
        static IEnumerable<long> Divisor(long x)
        {
            if (x < 1) yield break;
            var max = (long)Math.Sqrt(x);
            for (long i = 1; i < max; ++i)
            {
                if (x % i != 0) continue;
                yield return i;
                if (i != x / i) yield return x / i;
            }
        }
        static long GCD(long a, long b)
        {
            long tmpa = a, tmpb = b;
            while (tmpb > 0) { var tmp = tmpb; tmpb = tmpa % tmpb; tmpa = tmp; }
            return tmpa;
        }
    }
}


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

using namespace std;

int const N = 55;
int const MOD = 1000000007;

void add(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

int dp[N][4][4];
int s[4][N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      int c = getchar();
      while (c <= 32) c = getchar();
      s[i][j] = c;
    }
  }
  dp[0][3][3] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 3; j++) {
      for (int k = 0; k <= 3; k++) {
        int val = dp[i][j][k];
        if (val == 0) continue;
        for (int nj = 0; nj < 3; nj++) {
          for (int nk = 0; nk < 3; nk++) {
            if ((s[0][i] == s[1][i]) != (nj == nk)) continue;
            if (i > 0 && (s[0][i] == s[0][i - 1]) != (nj == j)) continue;
            if (i > 0 && (s[1][i] == s[1][i - 1]) != (nk == k)) continue;
            add(dp[i + 1][nj][nk], val);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      add(ans, dp[n][i][j]);
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

std::string C;

int main()
{
  std::cin >> C;
  ++C[0];

  std::cout << C << std::endl;

  return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

ll N;

ll F(ll A, ll B)
{
   string s1 = to_string(A); 
   string s2 = to_string(B);
   return max(s1.length(), s2.length());
}

void solve()
{
    cin >> N;
    ll ans;
    for(ll i = 1; i * i <= N; i++)
    {
        if(N % i == 0) ans = i;
    }
    cout << F(ans, N / ans) << endl;
}

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

    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define _USE_MATH_DEFINES
#define mp       make_pair
#define pb       push_back
#define fst      first
#define snd      second
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int D, G;
int p[10], c[10], s[10];
bool used[10];

int all_search(int d, int g)
{
    if(g >= G)
        return 0;

    if(d == D) {
        int m;
        for(m = D-1; used[m] && m >= 0; m--)
            ;
        if(m < 0 || g + 100*(m+1)*(p[m]-1) < G)
            return INF;

        return (int)ceil((double)(G-g) / (100 * (m+1)));
    }

    int ans = all_search(d+1, g);
    used[d] = true;
    ans = min(all_search(d+1, g+s[d])+p[d], ans);
    used[d] = false;

    return ans;
}

int main()
{
    cin >> D >> G;
    rep(i, D) {
        cin >> p[i] >> c[i];
        s[i] = 100*(i+1)*p[i] + c[i];
        used[i] = false;
    }

    cout << all_search(0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n);

  for (int i=0; i<n; i++) {
    cin >> v[i];
  }

  int i=0, cnt=0, j=0;
  while (j<n+1) {
    if (v[i]==2) {
      cnt++;
      printf("%d\n", cnt);
      return 0;
    } else {
      i=v[i]-1;
      cnt++;
      j++;
    }
  }
  printf("%d\n", -1);
  return 0;
}

Measured memory_bytes: 640
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
double dist(ll i, ll j)
{
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main()
{
  ll a,b;cin>>a>>b;
  if((a+b)%2==0)cout<<(a+b)/2;
  else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define v vector
#define mp make_pair
typedef long long ll;
typedef pair<int, int > pii;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
// E
int N, M;
v<pii> adj[100000];

int color[100000];
int ok[100000];
int contr;

int getc(int col, int z){
	if(z==1) return (col==1?2:1);
	else return col;
}
void dfs(int x, int c){
	color[x] = c;
	for(auto e : adj[x]){
		if(color[e.first]!=0){
			int supp = getc(c, e.second);
			if(color[e.first]!=supp)
				contr++;
		}
		else{
			dfs(e.first, getc(c, e.second));
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> N >> M;
	FOR(i,0,M){
		int x,y,z;
		cin >> x >> y >> z;
		x--, y--, z %=2;
		adj[x].push_back({y,z});
		adj[y].push_back({x,z});
	}
	int ans = 0;
	FOR(i,0,N) if(color[i]==0){
		contr = 0;
		dfs(i, 1);
		if(contr==0) ok[i]++;
	}
	memset(color, 0, sizeof color);
	FOR(i,0,N) if(color[i]==0){
		contr = 0;
		dfs(i, 2);
		if(contr==0) ok[i]++;
		if(ok[i]==0) assert(0);
		else if(ok[i]==1) ans += 0;
		else ans += 1;
	}
	cout << ans << "\n";
}



Measured memory_bytes: 9216
#include<stdio.h>

int main()
{
    int i,h,a[100000],n,sum=0;

    scanf("%d %d",&h,&n);

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

        sum = sum + a[i];
    }

    if((h-sum)<=0)
        printf("Yes");
    else
        printf("No");


    return 0;
}


Measured memory_bytes: 2068
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int p[] = new int[N];
		double expectedValue[] = new double[N];

		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			expectedValue[i] = (double)(0.5*p[i]*(p[i]+1))/p[i];
		}

		double maxValue = 0;
		for (int i = 0; i < K; i++) {
			maxValue += expectedValue[i];
		}

		double tmp = maxValue;
		for (int i = 0; i <N; i++) {
			if (K + i < N) {
				tmp = tmp - expectedValue[i] + expectedValue[K + i];
			}
			if (maxValue < tmp) maxValue = tmp;
		}

		System.out.println(maxValue);
	}
}

Measured memory_bytes: 86044
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, m = LI()
    ab = LIR_(m)
    def Dijkstra(num, start, vedge):
        """ vedge は DAG の 重みとして vedge[from] = (to, value)　としておくこと """
        """ DAGでない場合は vedge[from] と vedge[to] の両方を作ること """
        """ dist[i] は start から i までの最短距離 """

        dist = [float("inf") for i in range(num)]
        dist[start] = 0
        q = [[dist[start], start]]
        while q:
            du, u = heappop(q)
            for j, k in vedge[u]:
                if dist[j] > du + k:
                    dist[j] = du + k
                    heappush(q, [dist[j], j])
        return dist
    edg = defaultdict(list)
    for a, b in ab:
        edg[a].append((b,1))
        edg[b].append((a,1))
    dist = Dijkstra(n, 0, edg)
    if inf in dist:
        print("No")
        return
    print("Yes")
    ans = [None] * n
    q = deque()
    q.append(0)
    while q:
        p = q.popleft()
        for e, _ in edg[p]:
            if ans[e] == None:
                if dist[p] + 1 == dist[e]:
                    ans[e] = p
                    q.append(e)
    for i in ans[1:]:
        print(i+1)
    return


#main
if __name__ == '__main__':
    solve()


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

int main(){
    string S;
    cin >> S;
    vector<int> row(S.size()+1);
    for(int i=0;i<row.size();i++){
        row.at(i) = 0;
    }


    for(int i=0;i<S.size();i++){
        if(S.at(i) == '<'){
            row.at(i+1) = max(row.at(i)+1, row.at(i+1));
        }
    }

    for(int i=(S.size()-1);i>=0;i--){
        if(S.at(i) == '>' && row.at(i) <= row.at(i+1)){
            row.at(i) = row.at(i+1) + 1;
        }
    }

    long long sum = 0;
    for(auto &x:row){
        sum += x;
    } 

    cout << sum;

    return 0;
}


Measured memory_bytes: 2820
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF=2305843009213693951;//巨大な定数
const int dx[]={0,1,0,-1};//x方向のベクトル
const int dy[]={1,0,-1,0};//y方向のベクトル
 
int main(){
    //入力
    ll h,w,ch,cw,dh,dw;
    cin>>h>>w>>ch>>cw>>dh>>dw;
    vector<vector<char>> S(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>S[i][j];
        }
    }
 
    //1-indexedなので0-indexedに直す
    ch--;
    cw--;
    dh--;
    dw--;
 
    //BFS用のqueue
    //HとWには移動1で行けるH座標とW座標
    //H2とW2には移動2でH座標とW座標
    queue<ll> H,H2,W,W2;
 
    //初期地点をH,Wに追加
    H.push(ch);
    W.push(cw);
 
    //最低何回の魔法でたどり着けるかを記録する
    //巨大な数INFで初期化する
    vector<vector<ll>> T(h,vector<ll>(w,INF));
 
    //初期地点は0回の魔法でたどり着く
    T[ch][cw]=0;
 
    //BFSをする
    while(!H.empty()){
        while(!H.empty()){
            //現在の座標
            ll nh=H.front();
            ll nw=W.front();
            //queueから削除
            H.pop();
            W.pop();
 
            //移動A
            for(int i=0;i<4;i++){
                //移動先の座標
                ll th=nh+dx[i];
                ll tw=nw+dy[i];
 
                //範囲外になってないかチェック
                if(th>=h||th<0||tw>=w||tw<0){
                    continue;
                }
 
                //壁かチェック
                if(S[th][tw]=='#'){
                    continue;
                }
 
                //魔法の回数が多い場合更新
                if(T[th][tw]>T[nh][nw]){
                    T[th][tw]=T[nh][nw];
                    H.push(th);
                    W.push(tw);
                }
            }
            if(T[dh][dw]!=INF) break;
            //移動B
            for(int i=-2;i<=2;i++){
                for(int j=-2;j<=2;j++){
                    //移動先の座標
                    ll th=nh+i;
                    ll tw=nw+j;
 
                    //範囲外になってないかチェック
                    if(th>=h||th<0||tw>=w||tw<0){
                        continue;
                    }
 
                    //移動先が壁かチェック
                    if(S[th][tw]=='#'){
                        continue;
                    }
 
                    //魔法の回数が多い場合更新
                    if(T[th][tw]>T[nh][nw]+1){
                        T[th][tw]=T[nh][nw]+1;
                        H2.push(th);
                        W2.push(tw);
                    }
                }
            }
        }
        //
        swap(H,H2);
        swap(W,W2);
    }
 
    //ゴールに到達出来ない場合
    if(T[dh][dw]==INF){
        cout<<-1<<endl;
    }
    
    //到達できる場合
    else{
        cout<<T[dh][dw]<<endl;
    }
}

Measured memory_bytes: 12444
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,K; string S; cin >> N >> K >> S;
	char &X = S[K-1];
	if(X == 'A'){
		X = 'a';
	}else if(X == 'B'){
		X = 'b';
	}else{
		X = 'c';
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define mod 1000000007
#define inf 1e18
#define w(x) int x; cin>>x; while(x--)
using namespace std;
bool sieve[100007];
void sieve_make() 
{
	memset(sieve,true,sizeof(sieve));
	sieve[0]=sieve[1]=false;
	for(int i=2;i*i<=100006;i++)
	{
		if(sieve[i])
		{
			for(int j=2*i;j<=100006;j+=i)
				sieve[j]=false;
		}
	}
}

int max(int a,int b)
{
	if(a>b)
		return a;
	return b;
}
int min(int a,int b)
{
	if(a<b)
		return a;
	return b;
}
int modexp(int a,int b,int c)
{
	if(a==0) return 0;
	if(b==0) return 1;

	int ans;
	if(b%2==0)
	{
		int small=modexp(a,b/2,c);
		ans=(small*small)%c;
	}
	else
	{
		int small=modexp(a,b-1,c);
		ans=(a%c);
		ans=(small*ans)%c;
	}
	return (ans+c)%c;
}

string rev(string s)
{
	reverse(s.begin(), s.end());
	return s;
}
bool sign(int x)
{
	if(x>0)
		return true;
	return false;
}

int base3(string b)
{
	int ans=0,c=0;
	for(int i=b.length()-1;i>=0;i--)
	{
		ans+=(b[i]-'0')*pow(3,c++);
	}
	return ans;
}
vector<int>adj[100005];
int dp[100005];

int dfs(int u)
{
	int ans=0;
	if(dp[u]!=-1)
		return dp[u];
	for(auto i:adj[u])
	{
		dp[i]=dfs(i);
		ans=max(ans,dp[i]+1);
	}
	return ans;
}
int32_t main()
{
	ios::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
	
	
	int n,m;
	cin>>n>>m;
	memset(dp,-1,sizeof dp);
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		adj[a-1].push_back(b-1);
	}
	int ans=0;
	for(int i=0;i<n;i++)
		ans=max(ans,dfs(i));
	cout<<ans<<endl;
	

}

Measured memory_bytes: 8576
#include <iostream>

typedef long long ll;

#define P 1000000007
#define N_MAX 1001

using namespace std;

ll inv[N_MAX];
ll fac[N_MAX];
ll finv[N_MAX];
ll finv_pow[N_MAX][N_MAX];
ll dp[N_MAX][N_MAX];

void init(){
    inv[1] = 1;
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    
    for(int i = 2; i < N_MAX; i++){
        fac[i] = (fac[i-1]*i)%P;
        inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
        finv[i] = (finv[i-1]*inv[i])%P;
    }

    for(int i = 0; i < N_MAX; i++){
        finv_pow[i][0] = 1;
    }

    for(int i = 0; i < N_MAX; i++){
        for(int j = 1; j < N_MAX; j++){
            finv_pow[i][j] = (finv_pow[i][j-1]*finv[i])%P;
        }
    }
    //init dp
    for(int i = 0; i < N_MAX; i++){
        dp[i][0] = 1;
    }
}

int main(){
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    init();
    for(int i = A; i <= B; i++){
        for(int j = 1; j <= N; j++){
            dp[i][j] = dp[i-1][j];
            for(int k = 0; j-i*k >= 0; k++){
                if(k >= C && k <= D){
                    dp[i][j] = (dp[i][j] + (((dp[i-1][j-i*k]*finv[k])%P)*finv_pow[i][k])%P)%P;
                    //cout << finv[k] << ' ' << finv_pow[i][k] << endl;
                    //cout << i << ' ' << j << ' ' << k <<  ' ' << dp[i][j] << ' ' << dp[i-1][j-i*k] << endl;
                }
            }
        }
    }
    //cout << (finv_pow[3][1]*6)%P << endl;
    //cout << (fac[N]*dp[B-1][N])%P << endl;
    cout << (fac[N]*dp[B][N])%P << endl;
}

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

int main(){
  int n,r;
  std::cin >> n>>r;
  if(n>=10)std::cout << r << '\n';
  else std::cout << r+(100*(10-n)) << '\n';


  return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 10000009
#define ll long long
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

void solve(){
	ll k;
	cin>>k;
	string ans;
	while(k--){
		ans+="ACL";
	}
	cout<<ans;
}

int main()
{
	FIO;
	solve();
	return 0;
}




Measured memory_bytes: 3608
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

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


//#define int ll

class CDigitsInMultiplication {
public:
void solve(std::istream& cin, std::ostream& cout) {
    ll N;
    cin >> N;
    int mi =  11;
    rep(i,1ll,(ll)sqrt(N)+1){
        if(N % (ll)i == 0)mi = min (mi , (int)log10(N/i+.5)+1);
    }
    cout << mi << endl;

}
};


#undef int
int main() {
	CDigitsInMultiplication solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<i64> data(n);
	i64 sum = 0;
	ff(i, 0, n) {
		cin >> data[i];
		sum += data[i];
	}
	i64 ans = giant;
	i64 pre = 0;
	ff(i, 0, n) {
		pre += data[i];
		if (i!=n-1) {
			ans = min(abs(sum - 2 * pre), ans);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  multiset<int> ms;

  rep(i, N)
  {
    int a;
    cin >> a;
    ms.insert(a);
  }

  int ans = 0;

  while (!ms.empty())
  {
    auto it = --ms.end();
    int v = *it;
    ms.erase(it);

    int b = 1;
    while (b <= v)
      b *= 2;

    auto jt = ms.find(b - v);
    if (jt != ms.end())
    {
      ans++;
      ms.erase(jt);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 9600
N = int(input())
S = input()
ans = 0
for i in range(0,1000):
    pin = str(i).zfill(3)
    #print(pin)
    first = False
    second = False
    for s in S:
        if (not first) and s == pin[0]:
            first = True
        elif first and (not second) and s == pin[1]:
            second = True
        elif second and s == pin[2]:
            ans += 1
            break
print(ans)

Measured memory_bytes: 42588
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	bool flg = false;
	if (a == 7) {
		if (b == 5 && c == 5) {
			flg = true;
		}
	}
	if (b == 7) {
		if (a == 5 && c == 5) {
			flg = true;
		}
	}
	if (c == 7) {
		if (b == 5 && a == 5) {
			flg = true;
		}
	}
	if (flg) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,c=0,i;
	scanf("%d",&n);
	int arr[n];
	for(i=1;i<=n;i++)
	{
		scanf("%d",&arr[i]);
		if(i%2==1&&arr[i]%2==1)
		{
			c++;
			}	
			}
	printf("%d\n",c);
	
}

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

const int MAX_N = 1 << 17;
const int def = 0;


struct SumSegTree2 {
	int n;
	ll all[2 * MAX_N - 1], part[2 * MAX_N - 1];
	void init(int n_) {
		n = 1;
		while(n < n_) n *= 2;
		for(int i = 0; i < 2 * n - 1; i++) all[i] = 0, part[i] = 0;
	}

	void add(int a, int b, ll x) { add(a, b, x, 0, 0, n); }

	void add(int a, int b, ll x, int k, int l, int r) {
		if(a <= l && r <= b) {
			all[k] += x;
		}
		else if(l < b && a < r) {
			part[k] += (min(b, r) - max(a, l)) * x;
			add(a, b, x, k * 2 + 1, l, (l + r) / 2);
			add(a, b, x, k * 2 + 2, (l + r) / 2, r);
		}
	}

	ll query(int a, int b) { return query(a, b, 0, 0, n); }

	ll query(int a, int b, int k, int l, int r) {
		if(r <= a || b <= l) return 0;
		if(a <= l && r <= b) return all[k] * (r - l) + part[k];
		ll v = 0;
		v += (min(b, r) - max(a, l)) * all[k];
		v += query(a, b, k * 2 + 1, l, (l + r) / 2);
		v += query(a, b, k * 2 + 2, (l + r) / 2, r);
		return v;
	}
};


typedef pair<int, int> P;
vector<P> G[100010];

SumSegTree2 st;

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


	int N, M;
	cin >> N >> M;
	st.init(M + 1);

	for(int i = 0; i < N; i++) {
		int l, r;
		cin >> l >> r;
		G[r - l + 1].push_back({ l, r });
	}

	int sum = N;
	for(int i = 1; i <= M; i++) {
		int ans = sum;
		for(int p = 0; p <= M; p += i) {
			ans += st.query(p, p + 1);
		}
		cout << ans << endl;

		for(auto v : G[i]) {
			int l = v.first, r = v.second;
			st.add(l, r + 1, 1);
			sum--;
		}
	}
}

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

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

  vector<int> X(N, 0);
  vector<int> Y(N, 0);
  rep(i, N) cin >> X[i] >> Y[i];
  
  int ans = 0;
  rep(i, N) {
    if (pow(X[i], 2) + pow(Y[i], 2) <= pow(D, 2)) ans++;
  }
  cout << ans;
}

Measured memory_bytes: 4812
#include <stdio.h>

int main(int argc, char const *argv[])
{
  char a, b;
  a = getchar();
  getchar();
  b = getchar();

  if(a=='H') {
    if(b=='H')
      printf("H\n");
    else
      printf("D\n");
  } else {
    if(b=='H')
      printf("D\n");
    else
      printf("H\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string S;
  cin >> S;
  int ans = 0;
  for (char c : S)
  {
    if (c == '1')
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long

int main() {
    IO;

    string f,s;
    int ans = 0;
    cin>>f>>s;

    for(int i=0;i<f.size();i++){
        if(f[i]!=s[i])
            ans++;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3780
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n,k;
    cin >> n >> k;
    vi a(n);
    rep(i,n) cin >> a[i];

    vector<vi> dp(n+1,vi(k+1));
    dp[0][k] = 1;
    for(int i = 1; i <= n; i++){
        vi sum(k+1);
        rep(j,k+1)sum[j] = dp[i-1][j];
        rep(j,k)(sum[j+1] += sum[j]) %= MOD;
        //rep(j,k+1)cout << " " << sum[j];cout << endl;
        for(int j = 0; j <= k; j++){
            /*
            for(int x = 0; x <= a[i-1] && j + x <= k; x++){
                (dp[i][j] += dp[i-1][j+x]) %= MOD;
            }
            */
            //dp[i][j]に 0 <= x <= min(a[i-1],k-j)をみたす dp[i-1][j+x]をたす
            //つまりdp[i-1][j]からdp[i-1][j+min(a[i-1],k-j)]の和をたす
            int tmp = sum[j+min(a[i-1],k-j)];
            if(j)(tmp += MOD - sum[j-1]) %= MOD;
            (dp[i][j] += tmp) %= MOD;
        }
    }

    cout << dp[n][0] << endl;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  string s;
  cin >> s;
  rep(i, 3) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3624
import scala.io.StdIn.{readInt, readLine}
case class Node[T](data: Option[T], var prev: Node[T], var next: Node[T])
case class DoublyLinkedList[T]() {
    val n = new Node[T](None, null, null)
    def isEmpty(): Boolean = if (n.prev == null && n.next == null) true else false
    def insert(e: T): Unit = {
        if (isEmpty) {
            val newNode = new Node(Option(e), n, n)
            n.next = newNode
            n.prev = newNode
        } else {
            val newNode = new Node(Option(e), n, n.next)
            n.next.prev = newNode
            n.next = newNode
        }
    }
    def find(e: T, node: Node[T]): Node[T] = node.next match {
        case a if a.data.isEmpty => null
        case a if a.data.get == e => a 
        case a => find(e, a)
    }
    def delete(e: T): Unit = {
        if (!isEmpty) {
            val target = find(e, n)
            if (target != null) {
                val targetNext = target.next
                val targetPrev = target.prev
                if (targetNext eq targetPrev) {
                    n.prev = null
                    n.next = null
                } else {
                    targetPrev.next = targetNext
                    targetNext.prev = targetPrev
                }
            }
        }
    }
    def deleteFirst(): Unit = {
        if (!isEmpty) {
            val targetNext = n.next.next
            if (n eq targetNext) {
                n.prev = null
                n.next = null
            } else {
                n.next = targetNext
                targetNext.prev = n
            }
        }
    }
    def deleteLast(): Unit = {
        if (!isEmpty) {
            val targetPrev = n.prev.prev
            if (n eq targetPrev) {
                n.prev = null
                n.next = null
            } else {
                n.prev = targetPrev
                targetPrev.next = n
            }
        }
    }
    def printList(): Unit = {
        if (isEmpty) {
            println()
        } else {
            def go(node: Node[T], list: List[T]): List[T] = node.prev match {
                case a if a.data.isEmpty => list
                case a => go(a, a.data.get :: list)
            }
            println(go(n, Nil).mkString(" "))
            
        }
    }
}
object Main {
    def main(args: Array[String]): Unit = {
        val list = DoublyLinkedList[String]()
        for (i <- (1 to readInt)) {
            val input = readLine.split(" ") 
            if (input(0) == "insert") list.insert(input(1))
            else if (input(0) == "delete") list.delete(input(1))
            else if (input(0) == "deleteFirst") list.deleteFirst()
            else if (input(0) == "deleteLast") list.deleteLast()
        }
        list.printList()
    }
}


Measured memory_bytes: 535836
n,m,l=map(int, input().split())

A = []
for i in range(n):
    A.append(list(map(int, input().split())))

B = []
for i in range(m):
    B.append(list(map(int, input().split())))

ci = []
for i in range(n):
    cij = []
    for k in range(l):
        s = 0
        for j in range (m):
            s += A[i][j] * B[j][k]
        cij.append(s)
    print(" ".join(map(str,cij)))

Measured memory_bytes: 8464
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i=0; i<n; i++) cin >> v[i];

    int ans = 0;
    for (int i=0; i<=k; i++) {
        for (int j=0; j<=k; j++) {
            if (i+j > n || i+j > k) continue;
            int sum = 0;
            priority_queue<int,vector<int>,greater<>> pq;
            for (int l=0; l<i; l++) {
                sum += v[l];
                if (v[l] < 0) pq.emplace(v[l]);
            }
            for (int l=0; l<j; l++) {
                sum += v[n-1-l];
                if (v[n-1-l] < 0) pq.emplace(v[n-1-l]);
            }

            for (int l=i+j; l<k; l++) {
                if(pq.empty()) break;
                sum -= pq.top(); pq.pop();
            }
            ans = max(ans, sum);
        }
    }

    cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    string out = "";
    for(int i =0; i < s.length(); i++) {
        if(i == 5 || i == 13) {
            out +=" ";
        } else {
            out +=s[i];
        }
    }
    cout << out;
    return 0;
}

Measured memory_bytes: 764
import math


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def prime_fact(x):
    prime_pow = {}
    check_ceil = math.ceil(math.sqrt(x))
    for p in range(2, check_ceil + 1):
        p_cnt = 0
        while x % p == 0:
            x //= p
            p_cnt += 1
        if p_cnt:
            prime_pow[p] = p_cnt
    if x > 1:
        prime_pow[x] = 1
    return prime_pow


def submit():
    a, b = map(int, input().split())
    g = gcd(a, b)
    # gcdの素因数分解して素因数の数を求める
    p = prime_fact(g)
    print(len(p) + 1)


if __name__ == "__main__":
    submit()


Measured memory_bytes: 38512
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var a = cin.ReadIntArray(N).OrderBy(x => x).ToArray();
            var ans = int.MaxValue;
            for (int i = a[0]; i <= a[N - 1]; ++i)
                ans = Min(a.Select(x => (int)Pow((x - i), 2)).Sum(), ans);
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; }}
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int n[100];
  for(int i=1; i<=100; i++){
    if(a%i == 0 && b%i == 0){
      n[i-1] = i;
    }
    else{
      n[i-1] = 0;
    }
  }
  sort(n, n+100, greater<int>());
  
  cout << n[k-1] << endl;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
sum = a.inject(:+) - a[0]
sum2 = a[0]
min = (sum2 - sum).abs
if n > 2
	(1...n-1).each do |i|
      sum -= a[i]
      sum2 += a[i]
      diff = (sum - sum2).abs
      min = diff if diff < min
	end
else
  	sum = a[-1]
  	sum2 = a[0]
	min = (sum2 - sum).abs
end
puts min

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

typedef long long ll;

int main(){
  string S;
  cin >> S;
  int cnt=0;
  for (int i = 0; i < S.size()-1; i++) {
    if (S.at(i)!=S.at(i+1)) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	fio;
	string s;
	cin >> s;
	if (s[1] == 'B')
		cout << "ARC";
	else
		cout << "ABC";
}

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

int main()
{
  int N; cin >> N;
  vector<long> enemies;
  vector<long> heroes;
  for (int i=0; i<N+1; i++) {
    long A;cin>>A;
    enemies.push_back(A);
  }
  for (int i=0; i<N; i++) {
    long B;cin>>B;
    heroes.push_back(B);
  }

  long defeatTotalCount = 0;
  for (int i=0; i<N; i++) {
      long defeatCount = min(enemies[i], heroes[i]);
      long defeatCountOfNextCity = (heroes[i] > enemies[i]) 
      ? min(heroes[i] - enemies[i], enemies[i+1]) : 0;
      defeatTotalCount += defeatCount + defeatCountOfNextCity;
      enemies[i+1] -= defeatCountOfNextCity;
  }

  cout << defeatTotalCount << endl;
}

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


int main(){
    int n;
    cin >> n;
    int a = n / 100;
    int b = n % 100;
    
    if(a>=1 && a<=12 && b>=1 && b<=12) cout << "AMBIGUOUS" << endl;
    else if(a>=1 && a<=12) cout << "MMYY" << endl;
    else if(b>=1 && b<=12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}


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

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

int main() {
  int64_t A,B;
  cin>>A>>B;
  
  int64_t d=A*B;
  cout<<d/gcd(A,B)<<endl;
 
  
}


Measured memory_bytes: 256
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    string s;
    cin >> s;
    int N = s.size();
    int first, last;
    REP(i, N) {
        if (s[i] == 'A') {
            first = i;
            break;
        }
    }
    for (int i = N - 1; i >= 0; i--) {
        if (s[i] == 'Z') {
            last = i;
            break;
        }
    }
    printAns(last - first + 1);
}


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

int main(){
  int Q, q;
  unsigned long long bit = 0, count, b;

  cin>>Q;

  for(int j = 0, i; j < Q; j++){
    cin>>q;
    switch(q){
    case 0:
      cin>>i;
      cout<<!!((1ll<<i)&bit)<<endl;
      break;
    case 1:
      cin>>i;
      bit |= 1ll<<i;
      break;
    case 2:
      cin>>i;
      bit &= ~(1ll<<i);
      break;
    case 3:
      cin>>i;
      bit ^= 1ll<<i;
      break;
    case 4:
      cout<<(bit == ~0)<<endl;
      break;
    case 5:
      cout<<(!!bit)<<endl;
      break;
    case 6:
      cout<<(!bit)<<endl;
      break;
    case 7:
      for(count = 0, b = bit; b;b &= b - 1) count++;
      cout<<count<<endl;
      break;
    case 8:
      cout<<bit<<endl;
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 3096
# -*- coding: utf-8 -*-

"""
・自力AC
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

x, y = MAP()

# x, yの大小、正負をまたぐかどうかで場合分け
if x <= y:
    if x >= 0 or y <= 0:
        ans = y - x
    else:
        ans = abs(abs(x)-abs(y))+1
else:
    if x > 0 and y > 0 or x < 0 and y < 0:
        ans = x - y + 2
    else:
        ans = abs(abs(x)-abs(y))+1
print(ans)


Measured memory_bytes: 5280
#include <bits/stdc++.h>
using namespace std;
int main(){
	int d;
	while(true){
		cin>>d;
		if(d==0)	return 0;
		int n,m;	cin>>n>>m;
		vector<int> shop(n+1);	shop[0]=0,shop[n]=d;
		for(int i=1;i<n;i++){
			int dist;	cin>>dist;
			shop[i]=dist;
		}
		sort(shop.begin(),shop.end());
		long long ans=0;
		for(int i=0;i<m;i++){
			int k;	cin>>k;
			vector<int>::iterator it=lower_bound(shop.begin(),shop.end(),k);
			long long tmp1=*it-k;
			if(it!=shop.begin())	it--;
			long long tmp2=k-*it;
			ans+=min(tmp1,tmp2);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1524
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(s[0]!='A'){
        cout<<"WA"<<endl;
        return 0;
    }
    int cnt=0;
    rep(i,n-3){
        if(s[i+2]=='C')cnt++;
        else if('A'<=s[i+2]&&s[i+2]<='Z'){
            cout<<"WA"<<endl;
            return 0;
        }
}
        if(cnt!=1){
            cout<<"WA"<<endl;
            return 0;
        }
    if('A'<=s[n-1]&&s[n-1]<='Z')cout<<"WA"<<endl;
else    if('A'<=s[1]&&s[1]<='Z')cout<<"WA"<<endl;
    else cout<<"AC"<<endl;
   return 0;
}


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

struct Ps{
  int r,c;
  Ps():r(0),c(0){}
  Ps(int r,int c):r(r),c(c){}
  Ps operator+(const Ps&p)const
  { return Ps(r+p.r,c+p.c);  }
  friend istream& operator>>(istream&is,Ps&p)
  {is >> p.r >> p.c; return is;  }
};

int main(){
  int h,w; cin >> h >> w;
  Ps s,g; cin >> s >> g;
  s = s+Ps(-1,-1);
  g = g+Ps(-1,-1);
  bitset<1000> mz[1000];
  for(int i = 0; i < h; ++i)for(int j = 0; j < w; ++j)
      mz[i][j] = []{char c; cin >> c; return c;}() == '.';
  optional<int> distance[1000][1000];
  deque<pair<Ps,int>> dq;
  dq.emplace_front(s,0);
  constexpr int mr[] = {0,0,1,-1};
  constexpr int mc[] = {1,-1,0,0};
  constexpr int nr[] = {-2,-2,-2,-2,-2,-1,-1,-1,-1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2};
  constexpr int nc[] = {-2,-1, 0, 1, 2,-2,-1, 1, 2,-2, 2,-2,-1, 1, 2,-2,-1, 0, 1, 2};
  while(!dq.empty()){
    auto [ps,di] = dq.front();
    dq.pop_front();
    if(distance[ps.r][ps.c])continue;
    distance[ps.r][ps.c] = di;
    if(ps.r==g.r && ps.c==g.c)break;
    for(int i = 0; i < 4; ++i){
      Ps nps = ps + Ps(mr[i],mc[i]);
      if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
      if(!mz[nps.r][nps.c])continue;
      if(distance[nps.r][nps.c])continue;
      mz[nps.r][nps.c] = 0;
      dq.emplace_front(move(nps),di);
    }
    for(int i = 0; i < 20; ++i){
      Ps nps = ps + Ps(nr[i],nc[i]);
      if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
      if(!mz[nps.r][nps.c])continue;
      if(distance[nps.r][nps.c])continue;
      dq.emplace_back(move(nps),di+1);
    }
  }
  cout << (distance[g.r][g.c] ? distance[g.r][g.c].value() : -1) << endl;
}


Measured memory_bytes: 11960