akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<stdio.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define INF 1000000000000000
#define MAXN (int)(1e6)+1
#define MOD 1000000007
 
using namespace std;
 
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pwi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector< vector<pair<int,lli > > > wGraph;
typedef vector<vector<int> > graph;
//typedef vector<vector<int> > matrix;
 
string a,b;
int dp[3001][3001];

int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(4);
    
    cin>>a;
    cin>>b;
    
    if(b.size()>a.size()) swap(a,b);
    
    for(int i = 0;i<=a.size();++i){
        for(int j = 0;j<=b.size();++j){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }else if(a[i-1] == b[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    
    string res = "";
    int i = a.size();
    int j = b.size();
    int lcs = dp[a.size()][b.size()];
    while(i>0 && j>0){
        if(a[i-1] == b[j-1]){
            res = a[i-1]+res;
            i--;j--;lcs--;
        }else if(dp[i-1][j] > dp[i][j-1]){
            i--;
        }else{
            j--;
        }
    }
    
    cout<<res<<endl;   
           
    return 0;
 
}

Measured memory_bytes: 35456
#include <iostream>
using namespace std;
int main() {
	unsigned int r = 0;
	unsigned int D = 0;
	unsigned int x2000 = 0;
	unsigned int kekka = 0;
	cin >> r >> D >> x2000;
	unsigned int mae = x2000;
	
	for (int i = 0; i < 10; ++i) {
		kekka = r * mae - D;
		cout << kekka << endl;
		mae = kekka;
	}
  return 0;
}

Measured memory_bytes: 256
N,M,X,Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.sort()
y.sort()
if x[-1] >= Y or y[0] <= X or x[-1] >= y[0]:
  print("War")
else:
  print("No War")

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long A, long long B, long long C){

    cout<<min(B/A,C)<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    func(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 300300
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;
    //vector<tuple<long long, long long, long long>>vec;

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


    int main()
    {
        string A, B;
        cin >> A >> B;

        if (A == B) cout << "EQUAL";
        else if (A.length() > B.length()) cout << "GREATER";
        else if (A.length() < B.length()) cout << "LESS";
        else {
            int cnt = 0;

            while (A[cnt] == B[cnt])
            {
                cnt++; //桁の数字が同じならどんどんみていく
            }
            if(A[cnt] > B[cnt]) cout << "GREATER";
            else cout << "LESS";
        }

        return 0;
    }

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
height = list(map(int, input().split()))
add_set = defaultdict(int)
ans = 0
for i in range(n):
    add_set[i + height[i] + 1] += 1
    if i + 1 - height[i] in add_set:
        ans += add_set[i + 1 - height[i]]

print(ans)


Measured memory_bytes: 113800
import java.util.*;

public class Main {
    static int MOD = 1000000007;
    
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char c[] = str.toCharArray();
        int n = c.length;
        
        // dp[n][0] + dp[n][1] = n桁までで非0がm個ある数の個数
        long[][] dp = new long[n+1][2];
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int k = 0; k < 2; k++) {
                int d = c[i] - '0';
                
                if (k == 0) {
                    if (d == 0) {
                        dp[i+1][0] = (dp[i+1][0] + dp[i][k]) % MOD;
                    } else {
                        dp[i+1][0] = (dp[i+1][0] + (dp[i][k] * 2) % MOD) % MOD;
                        dp[i+1][1] = (dp[i+1][1] + dp[i][k]) % MOD;
                    }
                } else {
                    dp[i+1][1] = (dp[i+1][1] + (dp[i][k] * 3) % MOD) % MOD;
                }
            }
        }
        
        System.out.println((dp[n][0] + dp[n][1]) % MOD);
    }
}

Measured memory_bytes: 27820
#include <iostream>

using namespace std;

const int NMAX = 1000;
const int MOD = 1e9 + 7;

int N, M;
char s[NMAX + 2][NMAX + 2];

int dp[NMAX + 2][NMAX + 2];

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

    for(int i = 1; i <= N; i++)
        cin >> (s[i] + 1);

    dp[1][1] = 1;

    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= M; j++)
            if(s[i][j] == '.' && !(i == 1 && j == 1))
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;

    cout << dp[N][M] << '\n';

    return 0;
}


Measured memory_bytes: 8436
#include <bits/stdc++.h>
using namespace std;
#define trace(x) cerr << (#x) << " is " << x << '\n';
int t;
#define double long double
double dp[301][301][301];
double solve(int one,int two,int three) {
  if (one+two+three==0) return 0.0;
  double &res = dp[one][two][three];
  if (res>0) return res;
  int sum = one+two+three;
  double no_of_waste = t/(double)sum;
  
  // cerr << "Solution of {" << one << ' ' << two << ' ' << three << "} is " << no_of_waste << '\n';
  // cerr << "t: " << t << '\n';
  // double p = t*1.0/sum;
  if (one > 0) res += (one/(double)sum)*(no_of_waste + solve(one-1,two,three));
  // if (one ==1 and two==1) {
  //   trace(res);
  //   trace(sum);
  // }
  if (two > 0) res += (two/(double)sum)*(no_of_waste + solve(one+1,two-1,three));
  if (three > 0) res += (three/(double)sum)*(no_of_waste + solve(one,two+1,three-1));
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cin >> t;
  short a[3] = {0};
  for(int i=0;i<t;i++) {
    int x; cin >> x;
    a[x-1]++;
  }
  cout << setprecision(10) << solve(a[0],a[1],a[2]);
  return 0;
}

Measured memory_bytes: 426368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
}

int main()
{
    init();
    int n;
    cin >> n;
    vector<int> data(n + 1, 0);
    int ans;
    for (int x = 1; x <= 100; x++)
    {
        for (int y = 1; y <= 100; y++)
        {
            for (int z = 1; z <= 100; z++)
            {
                ans = x * x + y * y + z * z + x * y + y * z + z * x;
                if (ans <= n)
                    data[ans]++;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << data[i] << endl;
    }
}


Measured memory_bytes: 3644
int main(){
double r,a,c;
scanf("%lf",&r);
a=(double)3.141592653589793238462643383279502884197169399375105820974944592307816406286*r*r;
c=(double)3.141592653589793238462643383279502884197169399375105820974944592307816406286*2*r;
printf("%.5f %.5f\n",a,c);
return 0;
}

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

int main(){
  int n, left, right;
  long sum;
  cin >> n;
  vector<int> city(n+1), hero(n);
  rep(i, n+1, 0) cin >> city[i];
  rep(i, n, 0) cin >> hero[i];
  
  sum = 0;
  for(int i=0; i<n; i++){
    left = min(city[i], hero[i]);
	city[i] -= left;
	hero[i] -= left;
	sum += left;
	
	right = min(city[i+1], hero[i]);
	city[i+1] -= right;
	hero[i] -= right;
	sum += right;
  }
  cout << sum << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int A,B;

int main()
{
   cout << fixed << setprecision(10);
   cin >> A >> B;
   bool isBad[] = {0, 0, 0};
   isBad[A-1] = 1;
   isBad[B-1] = 1;
   REP(i, 3) {
      if (!isBad[i]) {
         cout << i + 1 << endl;
      }
   }
   return 0;
}



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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < n; i++)
#define REP(n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using INT64 = long long;
using UINT64 = unsigned long long;
#define MOD 1000000007


int main(void)
{
    IOS
    double w,h,x,y;
    cin >> w >> h >> x >> y;

    int ans = (x*2==w && y*2 ==h) ? 1:0;

    cout << w*h/2 << " " << ans << endl;



    return 0;
}


Measured memory_bytes: 384
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

ll extGCD(ll a, ll  b, ll &x, ll &y){
  if(b==0){
    x = 1;
    y = 0;
    return a;
  }
  ll d = extGCD(b,a%b,y,x);
  y -= (a/b)*x;
  return d;
}

ll gen(int c){
  ll res,x,y,hosei;
  hosei = extGCD(MOD,c,x,y);
  res = y;

  if(res<0)res += MOD;
  return res;
}

ll nijou(ll x){
  if(x==1)return 2;
  ll res;
  if(x%2){
    res = 2*nijou(x-1);
  }else{
    res = nijou(x/2)*nijou(x/2);
  }
  return res%MOD;
}

int main() {
  int n,a,b;
  cin >> n >> a >> b;

  ll resa,resb;
  resa = 1;
  resb = 1;
  ll a1,b2,nn;
  nn = n;
  a1 = 1;
  b2 = 1;
  while(nn>=n-a+1 || a1<=a){
    resa = (resa*nn)%MOD;
    resa = (resa*gen(a1))%MOD;
    nn--;
    a1++;
  }
  nn = n;
  while(nn>=n-b+1 || b2<=b){
    resb = (resb*nn)%MOD;
    resb = (resb*gen(b2))%MOD;
    nn--;
    b2++;
  }

  ll all = nijou(n);
  //cout << all << endl;
  ll ans = all-resa-resb-1;
  ans %= MOD;
  if(ans < 0)ans += MOD;
  //if(ans < 0) ans += MOD;
  //cout <<  resa << " " << resb << endl;
  //cout  << nijou << endl;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int f[3010][3010];
int n;
string s;

inline void work() {
    cin >> n >> s;
    f[1][1] = 1;
    for (int i = 2; i <= n; ++i) {
        int prev = 0;
        if (s[i - 2] == '<') {
            for (int j = 2; j <= i; ++j) {
                prev += f[i - 1][j - 1];
                prev %= mod;
                f[i][j] = prev;
            }
        }
        else {
            for (int j = i - 1; j >= 1; --j) {
                prev += f[i - 1][j];
                prev %= mod;
                f[i][j] = prev;
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += f[n][i];
        ans %= mod;
    }
    cout << ans << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 34304
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
cnt=0
dis=0
if d==1:
    print(n*(n-1)//2)
else:
    for i in range(n-1):
        for j in range(i+1,n):
            distance=0
            dis=0
            for k in range(d):
                dis+=(x[i][k]-x[j][k])**2
            distance=math.sqrt(dis)   
            if distance.is_integer()==True:
                cnt+=1
    print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF (1e9)
#define N 105
#define M 16
using namespace std;
typedef pair<int,int> P;
int n,m,k,d[M],G[N][N],dp[(1<<M)];
map<int,int> to;

int bfs(){
  queue<P> q;
  fill(dp,dp+(1<<M),INF);
  dp[0]=0;
  q.push(P(0,0));
  while(!q.empty()){
    P t=q.front(); q.pop();
    int cost=t.first,node=t.second;
    if(node==(1<<m)-1)return cost;
    if(dp[node]<cost)continue;
    for(int i=0;i<k;i++){
      int next=(1<<m)-1;
      for(int j=0;j<m;j++)
	if(!(node&(1<<j))&&to.count(G[d[j]][i]))
	  next=next&~(1<<to[G[d[j]][i]]);
      if(dp[next]>cost+1){
	dp[next]=cost+1;
	q.push(P(dp[next],next));
      }
    }
  }
}

int main(){
  cin>>n>>m>>k;
  for(int i=0;i<m;i++){
    cin>>d[i]; d[i]--;
    to[d[i]]=i;
  }
  for(int i=0;i<n;i++)
    for(int j=0;j<k;j++){
      cin>>G[i][j];
      G[i][j]--;
    }
  cout<<bfs()<<endl;
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    long long N;
    cin >> N;
    
    long long copy_N = N;
    long long left;
    long long keta=0;
    while(copy_N>0){
        keta++;
        left = copy_N % 10;
        copy_N = copy_N / 10;
    }
    
    long long ketaage=1;
    for(int i=1; i<keta; i++){
        ketaage*=10;
    }
    
    long long ans;
    
    if(keta==1){
        ans = N;
    }
    else if(ketaage-(N%ketaage)==1){
        ans = ((keta-1) * 9) + left;
    }
    else{
        ans = ((keta-1) * 9) + (left-1);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len = s.length();
    int k = s[len-1]-'0';
 //   cout<<k;
    if(k==3) puts("bon");
    else if(k==0 || k==1 || k==6 || k==8) puts("pon");
    else puts("hon");
}


Measured memory_bytes: 3644
#include<stdio.h>
int main(void)
{
	char S[20];
	scanf("%s",&S);
	if(S[0]=='S') 
	{
		printf("Cloudy\n");
	}
	else if(S[0]=='C')
	{
		printf("Rainy\n");
	}
	else if(S[0]=='R') 
	{
		printf("Sunny\n");
	}
	return 0;
}

Measured memory_bytes: 128
data = input().rstrip().split(" ")
people = int(data[0])
kind = int(data[1])
ans = [i+1 for i in range(people)]
for j in range(kind):
    empty = input()
    have = input().rstrip().split(" ")
    for k in have:
        if int(k) in ans:
            delete = ans.index(int(k))
            del ans[delete]
print(len(ans))


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

int main() {
  string s_dush, t, s, ans_store;
  cin >> s_dush >> t;
  int ques_len = 0;
  int temp;
  vector<string> ans;
  rep (i, s_dush.size() - t.size() + 1) {
    rep (j, t.size()) {
      if (t[j] != s_dush[i+j] && s_dush[i+j] != '?') {
        break;
      }
      if (j == t.size() - 1) {
        ans_store = s_dush;
        rep (k, ans_store.size()) {
          if (i <= k && k <= i + j) ans_store[k] = t[k-i];
          if (ans_store[k] == '?') ans_store[k] = 'a';
        }
        ans.push_back(ans_store);
      }
    }
  }
  sort(ans.begin(), ans.end());
  if (ans.size() == 0) {
    s = "UNRESTORABLE";
  }else{
    s = ans[0];
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <list>

#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 1000;
const int inf = 1e9 + 5;
const long double eps = 1e-8;

string a[MAXN];
int d[MAXN][MAXN];
int p[MAXN][MAXN];
int n, m;

bool go(pii s) {
    return (s.first >= 0 && s.first < n && s.second >= 0 && s.second < m);
}

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

    int k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    pii s;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            d[i][j] = inf;
            if (a[i][j] == 'S') {
                s.first = i;
                s.second = j;
            }
        }
    d[s.first][s.second] = 0;

    list<pii> q;
    q.push_front(s);

    while (!q.empty()) {
        pii s = q.front();
        if (d[s.first][s.second] == k)
            break;
        q.pop_front();
        pii s1;

        s1.first = s.first;
        s1.second = s.second + 1;
        if (go(s1) && d[s1.first][s1.second] == inf) {
            if (a[s1.first][s1.second] == '.') {
                q.push_back(s1);
                d[s1.first][s1.second] = d[s.first][s.second] + 1;
            }
        }

        s1.first = s.first;
        s1.second = s.second - 1;
        if (go(s1) && d[s1.first][s1.second] == inf) {
            if (a[s1.first][s1.second] == '.') {
                q.push_back(s1);
                d[s1.first][s1.second] = d[s.first][s.second] + 1;
            }
        }

        s1.first = s.first + 1;
        s1.second = s.second;
        if (go(s1) && d[s1.first][s1.second] == inf) {
            if (a[s1.first][s1.second] == '.') {
                q.push_back(s1);
                d[s1.first][s1.second] = d[s.first][s.second] + 1;
            }
        }

        s1.first = s.first - 1;
        s1.second = s.second;
        if (go(s1) && d[s1.first][s1.second] == inf) {
            if (a[s1.first][s1.second] == '.') {
                q.push_back(s1);
                d[s1.first][s1.second] = d[s.first][s.second] + 1;
            }
        }
    }

    int ans = inf;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (d[i][j] == inf)
                continue;
            int minDist = min({i, n - 1 - i, j, m - 1 - j});
            if (minDist % k == 0)
                minDist = minDist / k;
            else
                minDist = (minDist / k) + 1;
            ans = min(ans, minDist);
        }

    cout << ans + 1;

    return 0;
}

Measured memory_bytes: 6144
use std::io;
use std::cmp::max;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s:Vec<char> = buf.trim().chars().collect();
	let mut left = 0;
	let mut right = 0;
	for i in 0..s.len() {
		if s[i] == 'A' {
			left = i;
			break;
		}
	}
	for i in (0..s.len()).rev() {
		if s[i] == 'Z' {
			right = i;
			break;
		}
	}
	println!("{}", right - left + 1);
}

Measured memory_bytes: 4352
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair <int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const char nl = '\n';

void solve() {
    string s;
    cin >> s;
    int l = s.length();
    int cnt(0);
    for(int i = 0; i < l - 1; ++i){
        if(s[i] != s[i + 1]){
            cnt++;
        }
    }
    cout << cnt << nl;
}
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define Mod 1000000007
#define Maxn 2010
 
int n;
long long f[Maxn];
 
int main()
{
	scanf("%d", &n);
	if (n < 3) puts("0");
	else
	{
		for (int i=1; i<=n; i++) f[i]=1ll;
		for (int i=6; i<=n; i++)
			for (int j=3; j<=i-3; j++)
				f[i]=(f[i]+f[i-j])%Mod;
		// for (int i=1; i<=n; i++) printf("%d ", f[i]); puts("");
		printf("%lld\n", f[n]);
	}
}

Measured memory_bytes: 3804
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

int a[100005];
void solve(){  
	int n;
	cin>>n;
	rep(i,0,n) cin>>a[i];
	int ans=0,cur=0;
	rep(i,0,n){
		if(i==0 or a[i]>a[i-1]){
			cur=0;
		}
		else ++cur;
		ans=max(ans,cur);
	}
	cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

cnt = 0
while True: 
    odd_flag = False
    for i in range(N):
        if A[i] % 2 == 1:
            odd_flag = True
    if odd_flag:
        break
    for i in range(N):
        A[i] = A[i] // 2
    cnt += 1

print(cnt)

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

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N, D;
    cin >> N >> D;
    vector<vector<ll>> X(N, vector<ll>(D));
    REP(i,0,N) {
        REP(j,0,D) cin >> X[i][j];
    }

    ll d;
    ll cnt = 0;
    REP(i,0,N) {
        REP(j,i+1,N) {
            d = 0;
            REP(k,0,D) {
                d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            REP(k,0,1000) {
                if(d == k*k) {
                    ++cnt;
                    break;
                }
            }
        }
    }
    _PR(cnt);

    return 0;
}

/*



*/

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

using namespace std;

int n;
vector<vector<int>> edges(150000 + 10);

void read() {
    cin >> n;
    for(int i = 1; i <= n - 1; i++) {

        int x, y;
        cin >> x >> y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
}

int par[150000 + 10], co[150000 + 10];
double expected[150000 + 10], result[150000 + 10];

double dfs(int node, int parent) {
    par[node] = parent;
    for(int son : edges[node]) {
        if(son != parent)
        dfs(son, node);
    }
    for(int son : edges[node]) {
        if(son != parent) {
                co[node]++;
        }
    }
    if(co[node])
    for(int son : edges[node]) {
        if(son != parent)
        expected[node] += (1 + expected[son]) / (double)co[node];
    }
}


void dfs1(int node, int parent) {
    if(node == 1) {
        result[1] = expected[1];
    }
    else{
    result[node] = ((double) co[node]/ ((double) (co[node] + 1))) * expected[node];
    if(par[node] != 1) {
        double res = (double) result[par[node]] * (co[par[node]] + 1) - expected[node] - 1;
        res = res / (double)(co[par[node]]);
        res++;
        result[node] += 1/((double)(co[node] + 1)) * res;
    } else {
        if(par[node] == 1 && co[1] >= 2) {
            double res = (double) result[par[node]] * (co[par[node]]) - expected[node] - 1;
            res = res / (double)(co[par[node]] - 1);
            res++;
            result[node] += 1/((double)(co[node] + 1)) * res;
        } else {
            result[node] += 1/(double)(1 + co[node]);
        }
    }
    }
    for(int i : edges[node]) {
        if(i != parent) {
            dfs1(i, node);
        }
    }
}

void solve() {
    dfs1(1, 0);
    for(int i = 1; i <= n; i++) {
        cout << setprecision(15) << result[i] << endl;
    }

}

int main()
{
    read();
    dfs(1, 0);
    solve();
    return 0;
}


Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 n; scanf("%lld", &n); std::vector<i64> g(2), s(2), b(2);
	const int A = 0, B = 1;
	scanf("%lld%lld%lld", &g[A], &s[A], &b[A]);
	scanf("%lld%lld%lld", &g[B], &s[B], &b[B]);
	
	// pre
	std::vector<i64> weight_1 = {g[A], s[A], b[A]};
	std::vector<i64> weight_2 = {g[B], s[B], b[B]};

	// solve
	for(int loop = 0; loop < 2; loop++) {
		std::vector<i64> dp(n + 1, 0);
		for(int i = 0; i < weight_1.size(); i++) {
			i64 w = weight_1[i], v = weight_2[i] - weight_1[i];
			if(v <= 0) continue;

			for(int j = 0; j < dp.size(); j++) {
				i64 to = j + w, nxt = dp[j] + v;
				if(to >= dp.size()) break;
				
				dp[to] = std::max(dp[to], nxt);
			}
		}

	//	cout << loop << ": ";
	//	for(auto v: dp) cout << v << " "; cout << endl;

		weight_1.swap(weight_2);
		n += *std::max_element(begin(dp), end(dp));
	}

	printf("%lld\n", n);
	return 0;
}


Measured memory_bytes: 195584
#pragma region Header

#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
#include <bitset>
#include <cstdint>
#include <stdexcept>
using namespace std;

// 整数型

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

// [0,n)を昇順/降順でループ

#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)

// [a,b)を昇順/降順でループ

#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)

template <typename T>
int SZ(T x)
{
    return static_cast<int>(x.size());
}

#pragma endregion

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

    string s;
    cin >> s;
    int n = s.size();
    vector<vector<int>> dp(n + 1, vector<int>(2, 0)); // dp[i][b] = ((上からi桁) + b に対する ans)
    dp[0][0] = 0;
    dp[0][1] = 1;
    rep(i, n)
    {
        // dp[i + 1] の更新
        int x = s[i] - '0';
        {
            dp[i + 1][0] = min(dp[i][0] + x, dp[i][1] + 10 - x);
        }
        if (x == 9)
        {
            dp[i + 1][1] = dp[i][1];
        }
        else
        {
            dp[i + 1][1] = min(dp[i][0] + x + 1, dp[i][1] + 10 - x - 1);
        }
    }
    cout << dp[n][0] << endl;

    return 0;
}


Measured memory_bytes: 58728
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int n = sc.nextInt();
        final int m = sc.nextInt();
        final int x = sc.nextInt();

        final int[] c = new int[n];
        final int[][] a = new int[n][m];

        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < (1 << n); i++) {
            int cost = 0;
            int[] d = new int[m];
            for (int j = 0; j < n; j++) {
                if ((i>>j & 1) == 1) {
                    cost += c[j];
                    for (int k = 0; k < m; k++) {
                        d[k] += a[j][k];
                    }
                }
            }

            boolean ok = true;

            for (int j = 0; j < m; j++) {
                if (d[j] < x) ok = false;
            }

            if (ok) {
                ans = Math.min(ans, cost);
            }
        }

        System.out.println(ans != Integer.MAX_VALUE ? ans : -1);
    }
}


Measured memory_bytes: 37400
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s;
  cin >> s;
  vector<int> dp(SIZE(s), 0);
  dp[0] = (s[0] != 'A' and s[0] != 'C' and s[0] != 'G' and s[0] != 'T');

  repz(i, 1, SIZE(s)) {
    dp[i] = dp[i - 1] +
            (s[i] != 'A' and s[i] != 'C' and s[i] != 'G' and s[i] != 'T');
  }
  int temp = dp[0] == 0;
  int res = -1;
  repz(i, 1, SIZE(s)) {
    if (dp[i - 1] == dp[i])
      temp++;
    else {
      res = max(res, temp);
      temp = 0;
    }
  }
  res = max(res, temp);
  cout << res << endl;
  ret;
}


Measured memory_bytes: 3596
# from sys import exit
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
L = len(S)
# T = str(input())
# exit()
# print(S[2:])
YYMM = 0 < int(S[2:]) <= 12

# print(S[:2])
MMYY = 0 < int(S[:2]) <= 12
if MMYY & YYMM:
    print("AMBIGUOUS")
elif not (MMYY or YYMM):
    print("NA")
else:
    print("YYMM" if YYMM else "MMYY")
# if(S[2:])


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

using namespace std;

#ifdef LOCAL_DEFINE
  #include "../../library/DEBUG.hpp"
#else
  #define debug(...) 0
#endif

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> x >> n;
  vector<int> arr(n);
  vector<bool> app(102, false);
  vector<int> na;
  na.push_back(-1);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    app[arr[i]] = true;
  }
  for (int i = 0; i < 102; i++) {
    if (!app[i]) {
      na.push_back(i);
    }
  }
  int pos = lower_bound(na.begin(), na.end(), x) - na.begin();
  int ans;
  if (abs(x - na[pos - 1]) <= abs(x - na[pos])) {
    ans = na[pos - 1];
  } else {
    ans = na[pos];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int X;
            string b;
            var word = Console.ReadLine().Split(' ');
            X = int.Parse(word[0]);
           
                if (X == 3 || X == 5 || X == 7) { b = "YES"; }
                else { b = "NO"; }
            
            Console.WriteLine(b);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<math.h>
int main(){
  int s[5],c[5],N,M,answer,i,j;
  answer=0;
  scanf("%d%d",&N,&M);
  for(i=0;i<M;i++){
    scanf("%d%d",&s[i],&c[i]);
    if(s[i]==1 && c[i]==0 &&N!=1){
      printf("-1\n");
      return 0;
    }
  }
  for(i=0;i<M;i++){
    for(j=i+1;j<M;j++){
      if(s[i]==s[j]){
        if(c[i]==c[j])
          c[j]=0;
        else{
        printf("-1\n");
        return 0;
        }
      }
    }
  }
  for(i=0;i<M;i++){
    answer=answer+c[i]*pow(10,N-s[i]);}
  if(N>1 && answer<pow(10,N-1))
    answer=answer+pow(10,N-1);
  printf("%d\n",answer);
  return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N, K;
int sum[2][100010];
int num[100010];

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

	cin >> N >> K;

	int C = 0;

	for (int i = 1; i <= N;)
	{
		int j = N / i;
		if (i <= j)num[C++] = 1, i++;
		else num[C++] = N / j - i + 1, i = N / j + 1;
	}

	rep(j,0,C)sum[1][j] = 1;

	int t;
	rep(i, 0, K)
	{
		rep(j, 0, C)
		{
			t = (sum[(i + 1) % 2][C - j - 1] * num[j]) % MOD;
			sum[i % 2][j] = t;
			if (0 < j)sum[i % 2][j] = (sum[i % 2][j] + sum[i % 2][j - 1]) % MOD;
		}
	}

	cout << sum[(K - 1) % 2][C - 1] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

#define f first
#define s second

typedef pair<int, int> P;

int main(){
  int a, b;
  while(cin >> a >> b){
    if(a == 0 && b == 0) break;
    vector<P> aa;
    for(int i = 1 ; i*i <= a ; i++){
      if(a % i == 0){
	aa.push_back(make_pair(i, a/i));
      }
    }
    vector<P> bb;
    for(int i = 1 ; i*i <= b ; i++){
      if(b % i == 0){
	bb.push_back(make_pair(i, b/i));
      }
    }

    int ans = (1<<29);
    int res[4];
    for(int i = 0 ; i < aa.size() ; i++){
      for(int j = 0 ; j < bb.size() ; j++){
	res[0] = aa[i].f, res[1] = aa[i].s;
	res[2] = bb[j].f, res[3] = bb[j].s;
	sort(res, res+4);
	int t = 0;
	for(int i = 0 ; i < 3 ; i++){
	  t += (res[i]-res[i+1]) * (res[i]-res[i+1]);
	}
	ans = min(ans, t);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

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

void test() {
    int k;
    cin >> k;
    string ans;
    for (int i = 0; i < k; ++i) {
        ans += "ACL";
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; ++i) {
        test();
    }
    return 0;
}


Measured memory_bytes: 3616
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Ferris Wheel
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b;
  scanf("%d%d", &a, &b);

  printf("%d\n", (a >= 13) ? b : (a >= 6) ? b / 2 : 0);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  while(cin >> n >> m && n) {
    int c[m],a[n];
    rep(i,m) R c[i];
    rep(i,n) R a[i];
    int dp[2][500];
    rep(i,2)rep(j,500)dp[i][j]=MAX;
    dp[0][128]=0;
    rep(i,n) {
      rep(j,500) {
        if(dp[0][j]!=MAX) {
          rep(k,m) {
            int x=j+c[k];
            if(x<0) x=0;
            if(x>255) x=255;
            dp[1][x]=min(dp[1][x],dp[0][j]+(a[i]-x)*(a[i]-x));
          }
        }
      }
      rep(j,500) {
        dp[0][j]=dp[1][j];
        dp[1][j]=MAX;
      }
    }
    int ans=MAX;
    rep(i,500) ans=min(ans,dp[0][i]);
    pr(ans);
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (int i = 0; i < n; i++)
#define repc(i, n) for (int i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long
#define printarray(arr, n) for(int i= 0;i<n;i++) cout<<a[i]<<' '; cout<<endl;
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define initdp(a) memset(a, -1, sizeof(a));

using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}



signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<max(max(a*c, a*d), max(b*c, b*d))<<endl;
    return 0;
}

Measured memory_bytes: 3632
import numpy as np

h, w = map(int, input().split())
grid = [[False for j in range(w)] for i in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == '.':
            grid[i][j] = 1
        else:
            grid[i][j] = 0

grid = np.array(grid)

L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)

for j in range(w):
    if j == 0:
        L[:, j] = grid[:, j]
    else:
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j]


for j in range(w - 1, -1, -1):
    if j >= w - 1:
        R[:, j] = grid[:, j]
    else:
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j]

for i in range(h):
    if i <= 0:
        U[i, :] = grid[i, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * grid[i, :]


for i in range(h - 1, -1, -1):
    if i >= h - 1:
        D[i, :] = grid[i, :]
    else:
        D[i, :] = (D[i + 1, :] + 1) * grid[i, :]

print(np.max(L + R + U + D - 3))


Measured memory_bytes: 231332
def even(num):
    return int(num / 2)


def odd(num):
    return 3 * num + 1


def main():
    s = int(input())
    tmp = s
    list = [s] * 1
    i = 0
    
    while True:
        i += 1
        if tmp % 2 == 0:
            tmp = even(tmp)
        else:
            tmp = odd(tmp)
        if tmp in list:
            break
        list.append(tmp)
    
    ans = i + 1
    print(ans)


if __name__ == '__main__':
    main()


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


ll ncr(ll n, ll r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    ll ans = 1;
    for (ll i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}

int main() {
    ll N, A, B; cin >> N >> A >> B;
    map<ll,ll,greater<ll>> M;
    rep(i,N) {
        ll v; cin >> v;
        M[v]++;
    }


    ll sum = 0; 
    ll way = 0;
    ll left = A;
    ll kind = 0;
    bool first = true;
    double prev;
    for (auto x : M) {
        kind++;
        if (x.second < left) {
            left -= x.second;
            sum += x.first * x.second;
        } else {
            sum += x.first * left;
            way += ncr(x.second, left);
            if (first) {
                first = false;
                prev = (double) sum / A;
                /*
                cout.precision(20);
                cout << fixed << prev << endl;;
                */
                printf("%.6f\n", prev);
            }
            if (kind > 1) break;
            assert(left == A);
            for (ll i = A+1; i <= B; i++) {
                if (i > x.second) goto END;
                way += ncr(x.second, i);
            }
            goto END;
        }
    }
END:
    cout << way << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e16;

/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll K; cin >> K;
	vector<ll> A(K);
	for (auto& in : A) cin >> in;
	if (A[K - 1] != 2) {
		cout << -1 << endl;
		return 0;
	}
	ll l = 2, r = 3;
	for (int i = K - 1; i >= 0; i--) {
		if (l / A[i] == r / A[i]) {
			if (l % A[i] != 0) {
				cout << -1 << endl;
				return 0;
			}
		}
		ll tmp1 = l / A[i];
		if (l%A[i] != 0) tmp1++;

		ll nextl = tmp1 * A[i];
		if (nextl > r) {
			cout << -1 << endl;
			return 0;
		}
		l = nextl;

		ll tmp2 = r / A[i];
		r = (tmp2 + 1)*A[i] - 1;
	}
	cout << l << " " << r << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  int a[n][3],b[n][3];
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
    cin>>a[i][j];
      if(i==0)
      {
        b[i][j]=a[i][j];
      }
      
    if(i>0)
    {
      b[i][j%3]=a[i][j%3]+max(b[i-1][(j+1)%3],b[i-1][(j+2)%3]);
    }
    }
  }
  int y=b[n-1][0];
 for(int i=1;i<3;i++){
     if(y<b[n-1][i])
     y=b[n-1][i];
 }
    cout<<y;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  set<int>AA;
  set<int>BB;
  set<int>CC;
  AA.insert(1);
  AA.insert(3);
  AA.insert(5);
  AA.insert(7);
  AA.insert(8);
  AA.insert(10);
  AA.insert(12);
  BB.insert(4);
  BB.insert(6);
  BB.insert(9);
  BB.insert(11);
  CC.insert(2);
  int x,y;
  cin>>x>>y;
  if(AA.count(x)==true&&AA.count(y)==true){
    cout<<"Yes"<<endl;
  }
  else if(BB.count(x)==true&&BB.count(y)==true){
    cout<<"Yes"<<endl;
  }
  else if(CC.count(x)==true&&CC.count(y)==true){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
  
    

Measured memory_bytes: 256