akhauriyash/Code-Regression huggingface dataset:
import sys
input=lambda :sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**8)

class LCA(object):
    def __init__(self, to, root=0):
        self.__n = len(to)
        self.__to = to
        self.__logn = (self.__n - 1).bit_length()
        self.__depth = [-1] * self.__n
        self.__dist = [-1] * self.__n
        self.__depth[root] = 0
        self.__dist[root] = 0
        self.__parents = [[-1] * self.__n for _ in range(self.__logn)]
        self.__dfs(root)
        self.__doubling()

    def __dfs(self, v):
        for u, c, d in self.__to[v]:
            if self.__depth[u] != -1: continue
            self.__parents[0][u] = v
            self.__depth[u] = self.__depth[v] + 1
            self.__dist[u] = self.__dist[v] + d
            self.__dfs(u)

    def __doubling(self):
        for i in range(1, self.__logn):
            for v in range(self.__n):
                if self.__parents[i - 1][v] == -1: continue
                self.__parents[i][v] = self.__parents[i - 1][self.__parents[i - 1][v]]

    @property
    def depth(self):
        return self.__depth

    @property
    def dist(self):
        return self.__dist

    def get(self, u, v):
        dd = self.__depth[v] - self.__depth[u]
        if dd < 0:
            u, v = v, u
            dd *= -1
        for i in range(self.__logn):
            if dd & (2 ** i):
                v = self.__parents[i][v]
        if v == u: return v
        for i in range(self.__logn - 1, -1, -1):
            pu = self.__parents[i][u]
            pv = self.__parents[i][v]
            if pu != pv: u, v = pu, pv
        return self.__parents[0][u]

def resolve():
    n, q = map(int, input().split())
    to = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b, c, d = map(int, input().split())
        a -= 1; b -= 1
        to[a].append((b, c, d))
        to[b].append((a, c, d))

    G = LCA(to)
    Query = [[] for _ in range(n)]
    for i in range(q):
    # idx, color, mag, coef
        x, y, u, v = map(int, input().split())
        u -= 1; v -= 1
        c = G.get(u, v)
        Query[u].append((i, x, y, 1))
        Query[v].append((i, x, y, 1))
        Query[c].append((i, x, y, -2))

    ans = [0] * q
    S = [[0, 0] for _ in range(n)]

    def dfs(v, p=-1):
        for idx, color, mag, coef in Query[v]:
            x = G.dist[v]
            x -= S[color][1]
            x += mag * S[color][0]
            ans[idx] += x * coef
        for nv, color, d in to[v]:
            if nv == p: continue
            S[color][0] += 1
            S[color][1] += d
            dfs(nv, v)
            S[color][0] -= 1
            S[color][1] -= d
    dfs(0)
    print(*ans, sep="\n")

resolve()

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

int main(){
	int a;
	string s;
	cin>>a>>s;
	if(a<3200){
		cout<<"red"<<endl;
	}else{
		cout<<s<<endl;
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(100);
  bool n =true;
  for (int i=0;i<N;i++){
    cin >> A.at(i);
    if (A.at(i)%2==1){
      continue;
    }
    else{
      if(A.at(i)%3==0||A.at(i)%5==0){
        continue;
      }
      else{
        n = false;
        break;
      }
    }
  }
  if(n==true){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}


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


using namespace std;

int main() {
	int n;
	cin >> n;
	
	bool ans = false;
	
	for(int i = 1; i < 10; i++){
		if(n / i < 10 && n % i == 0) {
			ans = true;
		}
	}
	if (ans) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
typedef unsigned long long ll;
using namespace std;

int main(void) {
    string S, T; cin >> S >> T;
    
    for (int i = 0; i < S.length(); i++) {
        char tmp;
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        }
        tmp = S[S.length()-1];
        S.pop_back();
        S.insert(S.begin(), tmp);
    }
    cout << "No" << endl;
    return 0;
}

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

#define ll              long long
#define mod             1000000007
#define inf             1e18

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n;
    cin>>n;

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

    int dp[n];
    for(int i=1; i<n; i++)      dp[i] = mod;

    dp[0] = 0;

    for(int i=0; i<n; i++){
        int j;

        j = i+1;
        if(j < n)       dp[j] = min( dp[j], dp[i] + abs(a[i] - a[j]) );
        
        j = i+2;
        if(j < n)       dp[j] = min( dp[j], dp[i] + abs(a[i] - a[j]) );
        
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int32 n;
vector<int64> a;
vector<int64> asum;  //2-indexed

map<pll,int64> memo;

int64 dfs(int64 i, int64 x){  //i以降からx個使う
  if(x == 0)return 0;
  if(memo.count(pll(i,x)) >= 1)return memo[pll(i,x)];
  if(n - i == x * 2 - 1){
    return memo[pll(i,x)] = asum[n+1] - asum[i];
  }
  // if(n - i == x * 2){
  //   int64 ret = -LLINF;
  //   REP(j,x+1){
  //     int64 y = asum[i+2*j] - asum[i] + asum[n+1] - asum[2*j+1];
  //     // cout << j << " " << y << endl;
  //     ret = max(ret,y);
  //   }
  //   return ret;
  // }
  int64 ret = -LLINF;
  for(int32 j = 0;;++j){
    if(n-i-j < x * 2 - 1)break;
    ret = max(ret, a[i+j] + dfs(i+j+2,x-1));
  }
  return memo[pll(i,x)] = ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  a.resize(n);
  REP(i,n)cin >> a[i];
  asum.resize(n+2,0);
  REP(i,n)asum[i+2] += asum[i] + a[i];
  int64 ans = -LLINF;
  // if(n % 2 == 0){
  //   REP(i,n/2+1){
  //     int64 x = asum[2*i] + asum[n+1] - asum[2*i+1];
  //     // cout << i << " " << x << endl;
  //     ans = max(ans,x);
  //   }
  // }else{

  // }
  ans = dfs(0,n/2);
  ANS(ans);
  return 0;
}

Measured memory_bytes: 39116
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    long long ans = 0;
    for (int bit = 0; bit < (1 << (n - 1)); bit++)
    {
        long long tmp = 0;
        for (int i = 0; i < n - 1; i++)
        {
            tmp *= 10;
            tmp += s[i] - '0';
            if (bit & (1 << i))
            {
                ans += tmp;
                tmp = 0;
            }
        }
        tmp *= 10;
        tmp += s.back() - '0';
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

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

void f(const int N, string s, int n, int a) {
    if (n == N) {
        cout << s << "\n";
        return;
    }
    for (int i = 0; i <= a; i++) {
        string t = s;
        t.push_back('a' + i);
        f(N, t, n + 1, max(a, i + 1));
    }
}

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

    int N; cin >> N;
    string s;
    f(N, s, 0, 0);
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
signed main(){
  int A,B,K;
  cin>>A>>B>>K;
  int count=0;
  for(int i=min(A,B);0<=i;i--){
    if(A%i==0&&B%i==0){
      count++;
      if(count==K){
        cout<<i<<endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
inline int power(int a, int b) {
    long long res = a, ans = 1;
    for (; b; b >>= 1, res = res * res % mod) if (b & 1) ans = ans * res % mod;
    return ans;
}
int n, k;
int fac[500010], facinv[500010];
inline int C(int n, int m) {
    if (m > n || m < 0) return 0;
    return 1ll * fac[n] * facinv[m] % mod * facinv[n - m] % mod;
}
int main() {
    scanf("%d%d", &n, &k);
    fac[0] = 1;
    for (int i = 1; i <= k; i++) fac[i] = 1ll * i * fac[i - 1] % mod;
    facinv[k] = power(fac[k], mod - 2);
    for (int i = k; i --> 0; ) facinv[i] = 1ll * facinv[i + 1] * (i + 1) % mod;
    int ans = 0;
    for (int r = n; r <= k; r++) {
        int b = k - r;
        if (r < b) continue;
        if (r == b) b--;
        int t = r - n + 1;
        ans = (0ll + ans + C(r + b, r) - C(r + b, r + t)) % mod;
    }
    return cout << ans << endl, 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 f;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin >> n;
    ll x0 = 0, y0 = 0, x1, y1, x2, y2;
    if (n > 1000000000){
        ll l = 1, r = 1000000000, m = 0;
        while (l <= r){
            m = (l + r) / 2;
            if (m * 1000000000 - n < 0) l = m + 1;
            else if (m * 1000000000 - n > 1000000000) r = m - 1;
            else break;
        }
        //cout << "m = " << m << " n - m * m = " << n - m * m << endl;
        x1 = 1000000000;
        y2 = m;
        y1 = 1;
        x2 = m * 1000000000 - n;
        cout << x0 << " " << y0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
        //cout << x1 * y2 - x2 * y1 << endl;
    }else cout << "0 0 " << "0 " << n << " " << "1 0" << endl;
    return 0;
}


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

typedef long long ll;

int main() {
    int N, M, Q, ans = 0;
    cin >> N >> M >> Q;
    vector<int> a(Q), b(Q), c(Q), d(Q), A(10);
    rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    for (A[0] = 1; A[0] <= M; A[0]++) {
        for (A[1] = A[0]; A[1] <= M; A[1]++) {
            for (A[2] = A[1]; A[2] <= M; A[2]++) {
                for (A[3] = A[2]; A[3] <= M; A[3]++) {
                    for (A[4] = A[3]; A[4] <= M; A[4]++) {
                        for (A[5] = A[4]; A[5] <= M; A[5]++) {
                            for (A[6] = A[5]; A[6] <= M; A[6]++) {
                                for (A[7] = A[6]; A[7] <= M; A[7]++) {
                                    for (A[8] = A[7]; A[8] <= M; A[8]++) {
                                        for (A[9] = A[8]; A[9] <= M; A[9]++) {
                                            int s = 0;
                                            rep(i, Q) {
                                                if (A[b[i] - 1] - A[a[i] - 1] == c[i]) s += d[i];
                                            }
                                            ans = max(ans, s);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << "\n";
}

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

using namespace std;

class node
{
public:
    int key,p;
    node *L,*R;
    node(int K=0,int P=0)
    {
        key=K;p=P;
        L=R=NULL;
    }
};

node *root=NULL;

node* RR(node *t)
{
    node *s=t->L;
    t->L=s->R;
    s->R=t;
    return s;
}

node* LR(node *t)
{
    node *s=t->R;
    t->R=s->L;
    s->L=t;
    return s;
}

node* Insert(node *t,int K,int P)
{
    if(t==NULL)
    {
        node *p=new node(K,P);
        return p;
    }else if(K==t->key)
    {
        return t;
    }

    if(K<t->key)
    {
        t->L=Insert(t->L,K,P);
        if(t->p<t->L->p)
        {
            t=RR(t);
        }
    }else
    {
        t->R=Insert(t->R,K,P);
        if(t->p<t->R->p)
        {
            t=LR(t);
        }
    }

    return t;
}

node* _Delete(node *,int);
node* Delete(node *t,int K)
{
    if(t==NULL)
    {
        return NULL;
    }else if(K<t->key)
    {
        t->L=Delete(t->L,K);
    }else if(K>t->key)
    {
        t->R=Delete(t->R,K);
    }else
    {
        return _Delete(t,K);
    }
    return t;
}

node* _Delete(node *t,int K)
{
    if(t->L==NULL&&t->R==NULL)
    {
        return NULL;
    }else if(t->L==NULL)
    {
        t=LR(t);
    }else if(t->R==NULL)
    {
        t=RR(t);
    }else
    {
        if(t->L->p>t->R->p)
        {
            t=RR(t);
        }else
        {
            t=LR(t);
        }
    }
    return Delete(t,K);
}

void pre(node *t)
{
    if(t==NULL)
    {
        return;
    }
    printf(" %d",t->key);
    pre(t->L);
    pre(t->R);
}

void in(node *t)
{
    if(t==NULL)
    {
        return;
    }
    in(t->L);
    printf(" %d",t->key);
    in(t->R);
}

node* Find(node *t,int K)
{
    if(t==NULL)
    {
        return NULL;
    }else if(K<t->key)
    {
        return Find(t->L,K);
    }else if(K>t->key)
    {
        return Find(t->R,K);
    }else
    {
        return t;
    }
}

void ins()
{
    int a,b;
    cin>>a>>b;
    root=Insert(root,a,b);
}

void fnd()
{
    int a;
    cin>>a;
    if(Find(root,a))
    {
        cout<<"yes"<<endl;
    }else
    {
        cout<<"no"<<endl;
    }
}

void del()
{
    int a;
    cin>>a;
    root=Delete(root,a);
}

void print()
{
    in(root);cout<<endl;
    pre(root);cout<<endl;
}

int main()
{
    int n;

    cin>>n;

    map<string,int> mp;
    mp["insert"]=1;
    mp["find"]=2;
    mp["delete"]=3;

    while(n--)
    {
        string s;
        cin>>s;

        switch(mp[s])
        {
            case 1:ins();break;
            case 2:fnd();break;
            case 3:del();break;
            default:print();
        }
    }


    return 0;
}



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



int main()
{
    ll n;
    cin>>n;
    ll l1[n+1];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
    }
    for(int i=n;i>=1;i-=2){
        cout<<l1[i]<<" ";
    }
    if(n&1){
        for(int i=2;i<=n;i+=2)cout<<l1[i]<<" ";
    }
    else for(int i=1;i<=n;i+=2)cout<<l1[i]<<" ";

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  for(int i=0; i<N; i++){
    string Si;
    cin >> Si;
 
    if (Si == "Y") {
      cout << "Four" << endl;
      break;
    }
    
    else if((i+1) == N){
      cout <<  "Three" << endl;
    }
  }
}

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

#define           mx              100005
#define           sf              scanf
#define           pf              printf
#define           READ            freopen("in.txt", "r", stdin);

using namespace std;

typedef             long long int          ll;

ll weight[mx], cost[mx], dp[105][mx];

int main()
{
	// READ
	
	ll n, w;

	sf("%lld %lld", &n, &w);

	for(int i = 0; i < n; i++) sf("%lld %lld", weight+i, cost+i);
	
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j <= w; j++)
		{
			if(j<weight[i])
			{
				if(i==0) dp[i][j] = 0;
				else dp[i][j] = dp[i-1][j];
			}
			else
			{
				if(i==0) dp[i][j] = cost[i];
				else dp[i][j] = max(dp[i-1][j], cost[i]+dp[i-1][j-weight[i]]);
			}
		}
	}

	ll ans = dp[n-1][w];

	pf("%lld\n", ans);


	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<double, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v, int idx)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        if (i == idx)
        {
            cout << "[" << v[i] << "]"
                 << " \n"[i == sz - 1];
            continue;
        }
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    ll N, W;
    cin >> N >> W;
    vector<ll> v(N), w(N);
    vector<P> p;
    for (int i = 0; i < N; i++)
    {
        cin >> v[i] >> w[i];
        p.push_back(P(double(v[i]) / double(w[i]), i));
    }
    sort(p.rbegin(), p.rend());
    double res = 0;
    for (int i = 0; i < N; i++)
    {
        double per = p[i].first;
        int idx = p[i].second;
        if (W >= w[idx])
        {
            res += v[idx];
            W -= w[idx];
        }
        else
        {
            res += per * W;
            break;
        }
    }
    cout << fixed << setprecision(10) << res << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
using Graph = vector<vector<ll>>;
#define all(x) (x).begin(), (x).end() //string の sort とかはこれ
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18
const double PI = 3.14159265;
const ll MAX = 1e6;
long long fac[MAX], finv[MAX], inv[MAX];

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
//最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//最小公倍数

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

// テーブルを作る前処理
void COMinit() //MODは素数じゃないとだよ！！
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind
{
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N)
  { //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x)
  { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y)
  {                   // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry)
      return;     //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y)
  { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main()
{
  // COMinit();
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, k, l, ans = 0;
  ll a, b;
  cin >> a >> b;

  ans = lcm(a, b);
  cout
      << ans << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, Z, W, A[2005];

int main(){
  scanf("%d%d%d", &N, &Z, &W);
  for (int i = 0; i < N; i++) scanf("%d", A + i);

  int ans = abs(A[N - 1] - W);
  if (N > 1){
    ans = max(ans, abs(A[N - 1] - A[N - 2]));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;

import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.nextLine());
		int[] A = new int[n];
		int[] B = new int[n];
		String tmp = scan.nextLine();
		for (int i = 0; i < n; i++) {
			A[i] = Integer.parseInt(tmp.split(" ")[i]);
		}
		tmp = scan.nextLine();
		for (int i = 0; i < n; i++) {
			B[i] = Integer.parseInt(tmp.split(" ")[i]);
		}
		double tmpRes = 0;
		for (int j = 1; j <= 1000; j++) {
			double res = 0, sum = 0;
			for (int i = 0; i < n; i++) {
				sum += Math.pow(Math.abs((double) A[i] - (double) B[i]), j);
			}
			res = Math.pow(sum, (double) 1 / j);
			if (j <= 3) {
				System.out.println(res);
				tmpRes = res;
				continue;
			}
			if (tmpRes - res < 0.0001) {
				if (Double.isInfinite(res)) {
					System.out.println((double) (int) tmpRes);
				} else {
					System.out.println((double) (int) res);
				}
				return;
			}
			tmpRes = res;
		}
	}
}



Measured memory_bytes: 29352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;vector<char> v;string n="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?",k=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ",m[]={"101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"},s,r;void F1(char z){int a,b=32;rep(i,32)if(n[i]==z)a=i;rep(i,5){v.push_back('0'+(a%b>=b/2));b/=2;if(b==1)break;}}int main(){while(getline(cin,s)){r="";v.clear();rep(i,s.size())F1(s[i]);rep(i,v.size()){r.push_back(v[i]);rep(j,32){if(m[j]==r){cout<<k[j];r="";}}}cout<<endl;}return 0;}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  if (A+B == C+D){cout <<"Balanced" << endl;}
  else if (A+B >= C+D){cout << "Left" <<endl;}
  else if (A+B <= C+D){cout << "Right" << endl;}
}

Measured memory_bytes: 256
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
m = abs(a-b)
if a>b:
  if (v-w)*t>=m:
    print("YES")
  else:
    print("NO")
else:
  if (v-w)*t>=m:
    print("YES")
  else:
    print("NO")
  

Measured memory_bytes: 9188
#include <iostream>

int main(int argc, const char * argv[]) {
    
    std::string w, ch ;
    
    int counter = 0 ;

    std::cin >> w ;
    
    while (std::cin >> ch) {
        if (ch == "END_OF_TEXT") break ;
        
        std::string checkStr = "" ;
        
        for (auto c: ch) {
            bool flag = false ;
            for (char alf='A'; alf<='Z'; alf++) {
                if (alf == c) {
                    checkStr += (alf-('A'-'a')) ;
                    flag = true ;
                    break ;
                }
            }
            if ( !flag ) checkStr += c ;
        }
        
        counter += ( checkStr == w ) ;
    }
    
    
    
    printf("%d\n", counter) ;
    
    return 0 ;
}



Measured memory_bytes: 3264
#include <iostream>
#include <memory>
#include <cmath>

constexpr int max_size()
{
    return static_cast<int>(1e+6);
}

int insert(int* a, const int i, const int gear)
{
    if (i < gear) {
        return 0;
    }

    if (a[i - gear] <= a[i]) {
        return 0;
    }

    std::swap(a[i - gear], a[i]);
    return 1 + insert(a, i - gear, gear);
}

int insertion_sort(int* arr, const int n, const int gear)
{
    int insert_count = 0;
    for (int i = 0; i < n; i += gear) {
        insert_count += insert(arr, i, gear);
    }
    return insert_count;
}

int pow(const int a, const int x) {
    return x == 0 ? 1 : a * pow(a, x - 1);
}

void print(int* arr, const int n, const int i, char const delim) {
    if (i == n - 1) {
        std::cout << arr[i];
        return;
    }

    std::cout << arr[i] << delim;
    print(arr, n, i + 1, delim);
}

void print(int* arr, const int n, char const delim) {
    int i = 0;
    for (; i < n - 1; ++i) {
        std::cout << arr[i] << delim;
    }
    std::cout << arr[i];
}

void shell_sort(int* arr, const int n) {
    static const double log3 = std::log(3);
    const int gear_index = static_cast<int>(std::log(2 * n + 1) / log3 - 1);
    int gear = (pow(3, gear_index + 1) - 1) >> 1;

    int gear_cache[100];
    int cache_idx = 0;
    int insert_count = 0;

    for (; gear > 0; gear = (gear - 1) / 3) {
        gear_cache[cache_idx] = gear;
        for (int i = 0; i < gear; ++i) {
            insert_count += insertion_sort(arr + i, n - i, gear);
        }
        ++cache_idx;
    }

    std::cout << cache_idx << std::endl;
    print(gear_cache, cache_idx, ' ');
    std::cout << std::endl;
    std::cout << insert_count << std::endl;

    return;
}

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

    int n;
    std::cin >> n;

    constexpr int N = max_size();
    const auto r = std::make_unique<int[]>(N);
    for (int i = 0; i < n; ++i) {
        std::cin >> r[i];
    }

    shell_sort(r.get(), n);
    print(r.get(), n, '\n');
    std::cout << std::endl;

    return 0;
}

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

int main()
{
    int n,m;
    cin >> n >> m;
    int left = 0;
    int right = numeric_limits<int>::max();
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        left = max(left, a);
        right = min(right, b);
    }
    cout << max(0, right - left + 1);
    return 0;
}


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

const ll INF = 1e18;

int main(){
  ll N, K; cin >> N >> K;
  vector<ll> A(N), F(N), M(N);
  for(ll i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  
  for(ll i = 0; i < N; i++){
    cin >> F[i];
  }
  sort(F.begin(), F.end(), greater<ll>());
  
  ll ma = 0;
  for(int i=0; i<N; i++){
    M[i] = A[i] * F[i];
    ma = max(ma, M[i]);
  }
  ll high = ma, low = 0LL;
  ll mid = (high - low) / 2 + low;
  
  while(high > low){
    ll cnt = 0LL;
    ll tmp = 0;
    for(ll i = 0; i < N; i++){
      if(M[i] <= mid) {tmp = max(tmp, M[i]);}
      else{
        ll sub = (M[i] - mid - 1) / F[i] + 1;
        cnt += sub;
        tmp = max(tmp, M[i] - sub * F[i]);
      }
    }
    if(cnt > K){
      low = mid+1;
    }else if(cnt < K){
      high = mid;
    }else{
      cout << tmp << endl;
      return 0;
    }
    mid = (high - low) / 2 + low;
  }
  cout << high << endl;
}

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

int main(void) {
	int a,b,c;
	cin >> a >> b >> c;

	int result = (a - (b + c));
	if (result > 0)
	{
		cout << 0;
	}
	else
	{
		cout << abs(a - (b + c));
	}
}

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

const int N = 2e5 + 10, mod = 1e9 + 7, base = 2e3 + 2;
typedef long long ll;
ll n, a[N], b[N], ans;
ll fac[N], f[4010][4010], inv[N];

ll quick_pow(ll a, ll b) {
    ll ret = 1;
    for (; b; b >>= 1) {
        if (b & 1) ret = ret * a % mod;
        a = a * a % mod;
    } return ret;
}

void pre(int n) {
    fac[0] = inv[0] = 1;
    rep(i, 1, n) fac[i] = fac[i - 1] * i % mod;
    inv[n] = quick_pow(fac[n], mod - 2);
    for (int i = n - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll n, ll m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }

void upd(ll &x, ll y) { x = (x + y) % mod; }

int main() {
    cin >> n;
    rep(i, 1, n) {
        scanf("%lld%lld", &a[i], &b[i]);
        f[-a[i] + base][-b[i] + base] += 1;
    }
    pre(10000);
    rep(i, 1, 4002)
        rep(j, 1, 4002)
            upd(f[i][j], (f[i - 1][j] + f[i][j - 1]) % mod);
    rep(i, 1, n)
        upd(ans, f[a[i] + base][b[i] + base] - C(2 * a[i] + 2 * b[i], 2 * a[i]) + mod);
    ans = ans * quick_pow(2, mod - 2) % mod;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 132436
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1e9 + 7;
const int MOD2 = 998244353;

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}
template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
        os << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    ll x , y;
    cin >> x >> y;
    ll ans = 0;

    while(x<=y){
        x *= 2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 998244353;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	long inf = LMAX / 2 - MAX;

	void doIt() {
		int N = sc.nextInt();
		int num[] = new int[100001];
		Arrays.fill(num, 0);
		long sum = 0;
		for(int i = 0; i < N; i++) {
			int A = sc.nextInt();
			sum += A;
			num[A]++;
		}
		int Q = sc.nextInt();
		for(int i = 0; i < Q; i++) {
			int B = sc.nextInt();
			int C = sc.nextInt();
			int d = C - B;
			sum += d * num[B];
			num[C] += num[B];
			num[B] = 0;
			System.out.println(sum);
		}
	}

	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 60296
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

vector<P> vp;

int main(){
    ll n, k;
    cin >> n >> k;
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        vp.push_back({a,b});
    }
    sort(vp.begin(), vp.end());

    ll cnt = 0;

    rep(i, n){
        cnt += vp[i].second;
        if (cnt >= k){
            cout << vp[i].first << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 5296
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define MOD 1000000007
typedef long long ll;

ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1LL;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2LL;
  }
  return res;
}

ll gcd(ll x, ll y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}

int main() {
  int n, flag = 1;
  ll a[10000], ans = 0LL, x = 1LL, b[10000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    b[i] = a[i];
  }
  for (ll i = 2; i <= 1000; i++) {
    flag = 1;
    while (flag == 1) {
      flag = 0;
      for (int j = 0; j < n; j++) {
        if (a[j] % i == 0) {
          flag = 1;
          a[j] /= i;
        }
      }
      if (flag) {
        x *= i;
        x %= MOD;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != 1) {
      x *= a[i];
      x %= MOD;
      for (int j = i + 1; j < n; j++) {
        if (a[i] == a[j]) {
          a[j] /= a[i];
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    ll y = x * mod_pow(b[i], MOD - 2LL, MOD);
    y %= MOD;
    ans += y;
    ans %= MOD;
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 256
s = input()
x, y = map(int, input().split())
y = abs(y)

f = s.find('T')
if f >= 0:
    x = abs(x - f)
    s = s[f:]
else:
    if x == len(s) and y == 0:
        print('Yes')
    else:
        print('No')
    exit()

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    if x == sx:
        return True

    goal = (sx - x) // 2
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 70336
n, a, b = readline.split(' ').map(&:to_i)

results = (1..n).to_a.map do |num|
  wa = num.to_s.split('').map(&:to_i).reduce(&:+)
  if a <= wa && wa <= b
    num
  else
    0
  end
end

puts results.reduce(&:+)


Measured memory_bytes: 2172
#include<iostream>
using namespace std;
int s[1000],k[1000][4];
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++){
		cin>>s[i];
		for(int j=0;j<3;j++)
			cin>>k[i][j];
		k[i][3]=4*(k[i][0]+k[i][2])+9*k[i][1];
	}
	int f[4];
	for(int i=0;i<4;i++)
		cin>>f[i];
	bool na=true;
	for(int i=0;i<n;i++){
		bool t=true;
		for(int j=0;j<4;j++){
			if(k[i][j]>f[j])
				t=false;
		}
		if(t==true){
			na=false;
			cout<<s[i]<<endl;
		}
	}
	if(na==true)
		cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#define rep(i, n) for (int i=0; i<n; i++)
#define ll long long
using namespace std;

void print(int *A, int N) {
    rep(i, N) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << "\n";
}

void insertionSort(int *A, int N) {
    for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        print(A, N);
    }
}

int main() {
    int N;
    cin >> N;
    int A[N];
    rep(i, N) {
        cin >> A[i];
    }
    print(A, N);
    insertionSort(A, N);
}


Measured memory_bytes: 3080
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	ll s;
  	cin >> s;
  	if(s==1 || s==2) {
    	cout << 4 << endl;
      	return;
    }
  	auto f = [&](ll x){
    	if(x%2==0) return x/2;
      	else return 3*x+1;
    };
  	
  	ll i = 1;
  	while(s!=1){
		s = f(s);
      	i++;
    }
  	
  	cout << i+1 << endl;
	return;
}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
using namespace std;
int n, a[100000], dp[100000];
int calc(int i) {
	if (i == n - 1) return 0;
	if (dp[i] != -1) return dp[i];
	int res = calc(i + 1) + abs(a[i] - a[i + 1]);
	if (i + 2 < n) res = min(res, calc(i + 2) + abs(a[i] - a[i + 2]));
	return dp[i] = res;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	memset(dp, -1, sizeof(dp));
	int ans = calc(0);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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


int main(){
    long long h,n;
    cin>>h>>n;
    long long sum=0;
    long long tmp;
    rep(i,n){
        cin>>tmp;
        sum+=tmp;
    }

    if(h>sum){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author yoshizaki
 * ABC 132
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int len = scanner.nextInt();
        int[] numbers = new int[len];
        for(int i = 0; i < len ; i++) {
            numbers[i] = scanner.nextInt();
        }
        int answer = 0;
        for (int i = 1; i < len - 1 ; i++) {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long ans=0;
  for(int i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0){
      ans+=i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
import sys
input = sys.stdin.readline

w, a, b = map(int, input().split())
if a < b:
    if b-(a+w) < 0:
        ans = 0
    else:
        ans = b-(a+w)
else:
    if a-(b+w) < 0:
        ans = 0
    else:
        ans = a-(b+w)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int dfs(int vertex,const vector<vector<int>>& adj,vector<bool>& visited)
{
    visited[vertex]=true;
    int cur=1;
    for(auto const &e:adj[vertex])
    {
        if(!visited[e])
            cur+=dfs(e,adj,visited);
    }
    return cur;
}
int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<int>> adj(n);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<bool> visited(n,false);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(!visited[i])
        {
            ans=max(ans,dfs(i,adj,visited));
        }
    }
    cout<<ans<<"\n";
    return 0;
}

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

public class Main {

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

}


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

int main(){
	string s;cin>>s;
	long long int n=s.size();long long int c=0;
	long long int ans=0;
	for (int i = 0; i < n; ++i)
	{
		if(s[i]=='W')
		{
		ans+=i-c;
		c++;
		}
	}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 640
n = int(input())
a, b = [list(map(int, input().split())) for i in range(2)]

ap = bp = 0
for i in range(n):
        if a[i]>b[i]: bp += a[i]-b[i]
        else:
                if (b[i]-a[i])%2: bp += 1
                ap += (b[i]-a[i]+1)//2
print("YNeos"[ap<bp::2])

Measured memory_bytes: 4596
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#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 (b < a) { a = b; return 1; } return 0; }
#pragma endregion

int main() {
  IN(int, N);
  IN(string, S);
  int count = 0;
  REP(i, 10) {
    REP(j, 10) {
      REP(k, 10) {
        bool left = false, center = false, right = false;
        REP(l, N) {
          if (!left) {
            if (S.at(l) == i + '0') left = true;
          } else if (!center) {
            if (S.at(l) == j + '0') center = true;
          } else if (!right) {
            if (S.at(l) == k + '0') {
              right = true;
              break;
            }
          }
        }
        if (right) count++;
      }
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3616
import numpy as np

n = int(input())
s = np.array([list(ord(e) - ord("a") for e in input()) for _ in range(n)], np.int8)
s = np.hstack((s, s))

ans = 0
for b in range(n):
    t = s[:, b:b+n]
    if (t == t.T).all():
        ans += 1

ans *= n
print(ans)


Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
map<string,ll>mp;
map<ll,string>mp1;
vector<ll>v;
int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    string s,d;
    cin>>a>>s;
    b=s.size();
    for(i=0;i<b;i++)
    {
        k=s[i]-'A';
        for(j=1;j<=a;j++)
        {
            k++;
            if(k==26)
            {
                k=0;
            }
        }
        s[i]=char(k+65);
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define pii         pair<int, int>
#define dint        long double

bool cmp1(pair<int, pii> a, pair<int, pii> b) {
    return (a.second.first < b.second.first);
}

bool cmp2(pair<int, pii> a, pair<int, pii> b) {
    return (a.second.second > b.second.second);
}

void solve() {
    int n; cin >> n;
    vector<pair<int, pii>> pos, neg;
    string S[n];
    for(int i=0; i<n; i++) {
        string s; cin >> s;
        S[i] = s;
        int A = 0, B = 0, a = 0, b = 0;
        int m = s.size();
        for(int j=0; j<m; j++) {
            a += (s[j] == ')');
            b += (s[j] == '(');
            A = max(A, a - b);
        }
        a = 0, b = 0;
        for(int j=m-1; j>=0; j--) {
            a += (s[j] == ')');
            b += (s[j] == '(');
            B = max(B, b - a);
        }
        if(A <= B) {
            pos.push_back({i, {A, B}});
        } else {
            neg.push_back({i, {A, B}});
        }
    }
    sort(pos.begin(), pos.end(), cmp1);
    sort(neg.begin(), neg.end(), cmp2);
    string K = "";
    for(auto it : pos) {
        int index = it.first;
        for(char c : S[index]) K.push_back(c);
    }
    for(auto it : neg) {
        int index = it.first;
        for(char c : S[index]) K.push_back(c);
    }
    int bal = 0;
    for(char c : K) {
        bal += (c == '(');
        bal -= (c == ')');
        if(bal < 0) {
            cout << "No" << endl; return;
        }
    }
    // cout << K << endl;
    if(bal) {
        cout << "No" << endl; return;
    }
    cout << "Yes" << endl;
}

signed main() {

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

    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve();
    }
    return 0;

}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,M;
    int a[100005],b[100005],c[100005];
    int min_a = INF,min_b = INF,min_sum;
    cin >> A >> B >> M;
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    rep(i,M){
        int x,y,discount;
        cin >> x >> y >> discount;
        c[i] = a[x-1] + b[y-1] - discount;
    }
    rep(i,A) min_a =min(a[i],min_a);
    rep(i,B) min_b =min(b[i],min_b);
    min_sum = min_a + min_b;
    
    rep(i,M) min_sum = min(min_sum,c[i]);
    
    cout << min_sum << endl;
    
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    long long int n,count=0;
    cin>>n;
    
    long long int a[n];
    unordered_map<long long int,long long int> mp,mp1;
    for(long long int i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    
    for(long long int i=0;i<n;i++)
    {
        if(mp1[a[i]]==0)
        {
            count=count+(mp[a[i]]*(mp[a[i]]-1))/2;
            mp1[a[i]]=1;
        }
    }
    
    for(long long int i=0;i<n;i++)
    {
        long long int ans=count-(mp[a[i]]*(mp[a[i]]-1))/2+((mp[a[i]]-2)*(mp[a[i]]-1))/2;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 16072
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

int dp[2005][2005];

bool solve() {
	int n,m; cin>>n>>m;
	vi s(n),t(m);
	REP (i,n) cin>>s[i];
	REP (i,m) cin>>t[i];
	REP (i,2005) REP (j,2005) dp[i][j] = 1;
	REP (i,n) {
		REP (j,m) {
			dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j];
			if (s[i] != t[j]) {
				dp[i+1][j+1] -= dp[i][j];
				dp[i+1][j+1] += mod;
			}
			dp[i+1][j+1] %= mod;
		}
	}
	cout << dp[n][m] << endl;
}

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

Measured memory_bytes: 33024