akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
# 整数の入力


def main():
    # n
    n = int(input())
    print(process(n))


def process(n):
    first = n % 10
    second = (n - first) % 100
    third = (n - first - second) % 1000
    forth = (n - first - second - third) % 10000
    fifth = (n - first - second - third - forth) % 100000
    sixth = (n - first - second - third - forth - fifth) % 1000000
    if sixth != 0:
        return 9 + 900 + 90000
    if fifth != 0:
        return 9 + 900 + (n - 9999)
    if forth != 0:
        return 9 + 900
    if third != 0:
        return 9 + (n - 99)
    if second != 0:
        return 9
    if first != 0:
        return n


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

/*
vector<int> solve(vector<int> v,int n){

int bit[n+1];
for(int i=0;i<n;i++){
    add(i,1);
}
pair<int,int> x[n];
for(int i=0;i<n;i++){
    x[i]=make_pair(v[i],i);
}
sort(x,x+n,greater<pair<int,int> >);




}*/



int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h,w,a,b;
cin>>h>>w>>a>>b;
for(int i=0;i<b;i++){
    for(int j=0;j<a;j++)
        cout<<0;
    for(int j=a;j<w;j++)
        cout<<1;
    cout<<endl;



}
for(int i=b;i<h;i++){
    for(int j=0;j<a;j++)
        cout<<1;
    for(int j=a;j<w;j++)
        cout<<0;
    cout<<endl;


}




}













Measured memory_bytes: 1280
#include<stdio.h>
#include<math.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a == b + c || b == c + a || c == a + b){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
import sys

global stamp, counter
stamp = {}
counter=0

def dfs(key, GRAPH):
    global stamp, counter
    if stamp[key][0]==0:
        counter += 1
        stamp[key][0] = counter
    elif stamp[key][1] !=0:
        return

    for e in GRAPH[key]:
        try:
            if stamp[e][0] == 0:
                dfs(e, GRAPH)
        except:
            pass
    counter += 1
    stamp[key][1] = counter
    return

n = int(raw_input())
x = {}
for i in range(n):
    seq = map(int,raw_input().split())
    key = seq[0]
    if key != 0:
        x[key] = seq[2:]
    else:
        x[key]=[]
    stamp[key]=[0,0]

for e in x.keys():
    dfs(e, x)

for e in x.keys():
    print e, stamp[e][0],stamp[e][1]

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define MAX 200005

vector<int> nxt(MAX), vtm(MAX);
vector<bool> vis(MAX, false);
int tmm = 1;

int dfs(int n, int k){
	if( k == 0 )
		return n;
	if( vis[n] == true ){
		int df = tmm - vtm[n];
		k = k%df;
		while( k ){
			n = nxt[n];
			k--;
		}

		return n;
	}

	vis[n] = true;
	vtm[n] = tmm++;
	return dfs(nxt[n], k-1);
}

int32_t main(){
	IOS;
	int n, k, nx;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> nxt[i];

	cout << dfs(1, k) << endl;
	return 0;
}

Measured memory_bytes: 6236
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int X = int.Parse(s[0]);
        int t = int.Parse(s[1]);
        Console.WriteLine(Math.Max(X - t, 0));
    }
}


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

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 1000000007;

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

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}


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

  int n,k;
  cin >> n >> k;
  vi a(n);
  rep(i,n)cin >> a[i];

  sort(all(a));
  int l = 0, r = a[n-1];

  while(l < r){
    int m = (l+r)/2;
    if(m == 0)m = 1;
    int cnt = 0;
    rep(i,n){
      int c = a[i]/m;
      if(a[i]%m > 0)c++;
      cnt += (c-1);
    }
    if(cnt > k){
      if(r - l == 1)l = r;
      else l = m;
    }
    else{
      if(m == 1 && l == 0) r = l = 1;
      else r = m;
    }
  }

  cout << l << endl;
}

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

#define ll long long
#define p pair<ll, ll>
using namespace std;

int main() {
    int n, m, from, to;
    cin >> n >> m >> from >> to;
    from--;
    to--;

    vector<vector<vector<ll>>> graph(n);
    for (int i = 0; i < m; i++) {
        int u, v, y, s;
        cin >> u >> v >> y >> s;
        u--;
        v--;
        graph[u].push_back({v, y, s});
        graph[v].push_back({u, y, s});
    }


    priority_queue<p, vector<p >, greater<>> que;
    vector<ll> ycost(n, 1145141919810364364);
    ycost[from] = 0;
    que.push(p(from, 0));

    while (!que.empty()) {
        p now = que.top();
        que.pop();
        int nowv = now.first;
        if (ycost[nowv] < now.second)continue;
        for (auto next:graph[nowv]) {
            if (ycost[next[0]] > ycost[nowv] + next[1]) {
                ycost[next[0]] = ycost[nowv] + next[1];
                que.push(p(next[0], ycost[next[0]]));
            }
        }
    }


    que = priority_queue<p, vector<p >, greater<>>();
    vector<ll> scost(n, 1145141919810364364);
    scost[to] = 0;
    que.push(p(to, 0));

    while (!que.empty()) {
        p now = que.top();
        que.pop();
        int nowv = now.first;
        if (scost[nowv] < now.second)continue;
        for (auto next:graph[nowv]) {
            if (scost[next[0]] > scost[nowv] + next[2]) {
                scost[next[0]] = scost[nowv] + next[2];
                que.push(p(next[0], scost[next[0]]));
            }
        }
    }

    vector<ll> dis(n);
    dis[n - 1] = ycost[n - 1] + scost[n - 1];
    for (int i = n - 2; i >= 0; i--)
        dis[i] = min(dis[i + 1], ycost[i] + scost[i]);

    for (int i = 0; i < n; i++) {
        ll ret = 1e15;
        cout << ret - dis[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 23676
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

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

	cout << a * a * a + a * a + a << endl;

	return 0;
}


Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define int lint
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
signed main()
{
    string s;
    cin >> s;
    int ans = LLONG_MAX;
    rep(i, s.size() - 2)
    {
        string t = s.substr(i, 3);
        ans = min(ans, abs(753 - stoll(t)));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def solve(string):
    n = len(string)
    ans = [0] * n

    def op(string, ans, forward=True):
        count = 0
        check = "R" if forward else "L"
        for i, a in enumerate(string[::2 * forward - 1]):
            if a == check:
                count += 1
                continue
            if count > 0:
                if forward:
                    ans[i] += count // 2
                    ans[i - 1] += (count + 1) // 2
                else:
                    ans[n - i - 1] += count // 2
                    ans[n - i] += (count + 1) // 2
                count = 0
        return ans

    ans = op(string, ans, True)
    return " ".join([str(a) for a in op(string, ans, False)])


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 10492
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define foref(i, a, b) for (int i = b - 1, to = a; i >= to; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
void solve() {
  Long x, y;
  cin >> x >> y;
  fore(i, 0, x + 1) {
    Long val = 2 * i + 4 * (x - i);
    if (val == y) {
      cout << "Yes\n";
      return;
    }
  }
  cout << "No\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int t = 1;
  //cin >> t;
  while (t--) solve();

  return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


int main() {
    // freopen("input.txt","r",stdin);
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    vs ans(h, string(w, '0'));

    for (ll y = 0; y < 2 * a; ++y) {
        for (ll x = 0; x < h; ++x) {
            ans[x][y] = ((x < b) ^ (y % 2 == 1) ? '1' : '0');
        }
    }

    ll cnt = b;
    for (ll x = 0; x < h; ++x) {
        char ch = (cnt-- > 0) ? '1' : '0';
        for (ll y = 2 * a; y < w; ++y) {
            ans[x][y] = ch;
        }
    }

    for (ll i = 0; i < h; ++i) {
        cout << ans[i] << "\n";
    }
    cout << endl;

    return 0;
}




Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	ll res=1;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(i==0&&x!=0) res=0;
		a[x]++;
	}
	for(int i=1;i<n;i++){
		if(a[i]){
			for(int j=0;j<a[i];j++) (res*=a[i-1])%=mod;
		}
	}
	if(a[0]!=1) res=0;
	cout<<res<<endl;
} 

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll dp[310][310][310];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    const ll INF = (1ll<<60);

    REP(i, 310)REP(j, 310)REP(k, 310) dp[i][j][k] = INF;
    dp[1][0][0] = 0;

    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    REP(i, N) cin >> H[i];
    //cout << H << endl;

    H.insert(H.begin(), 0);

    for(int i=1;i<=N;i++){
        REP(j, N+1){
            REP(k, N+1){
                if(dp[i][j][k]<0) continue;

                // not erase
                ll val = dp[i][j][k] + max(H[i]-H[j], 0ll);
                dp[i+1][i][k] = min(dp[i+1][i][k], val);

                // erase
                dp[i+1][j][k+1] = min(dp[i+1][j][k+1], dp[i][j][k]);
                
            }
        }
    }

    ll mi = INF;
    REP(j, N+1)REP(k, K+1) mi = min(mi, dp[N+1][j][k]);
    cout << mi << endl;
    return 0;
}

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

int N, M;
int m[100050];
int length[100050];
int main() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        cin >> m[i];
    }
    m[M + 1] = N + 1;
    //length[1] = m[1] - 1;
    for(int i = 2; i <= M + 1; i++) {
        int delta = m[i] - m[i - 1];
        length[delta-1]++;
        //cout << delta << endl;
        //length[1] += 1;
        //length[delta+1] -= delta;
        //length[delta+2] += delta;
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << " " << length[i] << endl;
    }
    for(int i = N-1; i >= 1; i--) {
        length[i] += length[i+1];
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << " " << length[i] << endl;
    }
    for(int i = N-1; i >= 1; i--) {
        length[i] += length[i+1];
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << " " << length[i] << endl;
    }
    for(int i = 1; i <= N; i++) {
        length[i] += m[1] - 1;
        //cout << i << " " << length[i] << endl;
    }
    int Q;
    cin >> Q;
    while(Q--) {
        int l;
        cin >> l;
        if(length[N] > l) {
            cout << -1 << endl;
            continue;
        }
        int ok = N;
        int ng = 0;
        while(ok - ng > 1) {
            int mid = (ok + ng) / 2;
            if(length[mid] <= l) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }
    return 0;
}


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

int main(void)
{
  string s;
  cin>>s;
  int j=1;
  int d=0;
  for(int i=0;i<s.size();i++){
    if(j==s.size())
      break;
    else if(s[i]=='A'&&s[j]=='C'){
      d=1;
    }
    j++;
  }
  if(d==1)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <cstdio>
#include <cstdint>
#define READINTA(X) while((ct=readchar())>='0')(X)=(X)*10+ct-'0';
#define READINTB(X) while((ct=*ci++)>='0')(X)=(X)*10+ct-'0';
using namespace std;

uint_fast16_t d;
uint_fast32_t M = 0;
uint_fast64_t c, sd = 0, sc = 0;
constexpr uint_fast32_t cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;

inline char readchar() {
    if(ci-cn==cm){fread_unlocked(cn,1,cm,stdin);ci=cn;}
    return *ci++;
}

int main() {
    READINTA(M);
    while(M--) {
        c = 0;
        if(ci-cn+22>cm) {
            d = readchar() - '0';
            readchar();
            READINTA(c);
        } else {
            d = *ci++ - '0';
            ci++;
            READINTB(c);
        }
        sc += c;
        sd += c * d;
    }
    printf("%lld\n", --sc + --sd / 9);
	return 0;
}

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

using namespace std;
using ll = long long;
int a[200005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin>>n>>k;

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

    int l=1, r=1e9;
    int ans;
    while(l<=r){
        int mid = (l+r)/2;
        ll val = 0;
        for(int i=0;i<n;i++){
            val += (a[i]-1)/mid;
        }
        if(val<=k){
            ans = mid;
            r = mid-1;
        }else{
            l = mid+1;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
const ll mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

vector<int> to[100005];
mint ans(1);
ll k;

void dfs(int x, int p = -1) {
    mint res(1);
    if (x==0) {
        ans *= k;
    }
    ll num = 2;
    if (x==0) num = 1;
    ll now = k - num;
    for (int e : to[x]) {
        if (e==p) {
            continue;
        }
        ans *= now;
        now--;
        dfs(e, x);
    }
    
}

int main(){
    int n;
    cin >> n >> k;
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }
    
    dfs(0);
    
    
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 13740
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	int n, i, j=0, cnt = 0;
	cin >> n >> s;

	for(i = 0; i < n; i++){
		if(s[i] == 'R')
			cnt++;
	}

	for(i = 0; i <= cnt-1; i++)
		if (s[i] == 'W')
			j++;

	cout << j << endl;
	return 0;
}


Measured memory_bytes: 3720
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=200010;

int n,c[maxn],num[maxn];
bool vis[maxn];
char s[maxn];
vector<int>v[30];
void modify(int x,int k){for(int i=x;i<=n;i+=lowbit(i))c[i]+=k;}
int query(int x){int ans=0;for(int i=x;i>=1;i-=lowbit(i))ans+=c[i];return ans;}
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i++)num[s[i]-'a']++,v[s[i]-'a'].push_back(i);
    int ok=0;
    for(int i=0;i<26;i++){
    	if(num[i]%2)ok++;
    }
    if(ok>1){printf("-1");return 0;}
    for(int i=1;i<=n+1;i++)modify(i,1);
    ll ans=0;
	for(int i=1;i<=n;i++)if(!vis[i]){
		int c=s[i]-'a';
		int x=v[c][v[c].size()-1];
		if(i==x){
			ans+=(query(n)-query(i))/2;
		}
		else{
			ans+=(query(n)-query(x));
		}
		modify(i,-1);modify(x,-1);
		vis[i]=vis[x]=1;
		v[c].erase(v[c].end()-1);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2424
number, taste_base = map(int, input().split(' '))

pie_all = int(number * ((number + 1) / 2 + taste_base - 1))

taste_range = range(taste_base, taste_base + number)
taste_range_abs = [abs(i) for i in taste_range]
abs_min = min(taste_range_abs)
minimum = 0

if abs_min in taste_range:
    minimum = abs_min
else:
    minimum = -abs_min

print(pie_all - minimum)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define gc getchar
#define ll long long
#define db double
#define pii pair<int,int>
#define fi first
#define se second
#define Vi vector<int>
#define Vp vector<pii>

using namespace std;

inline void cmax(int &x,int y){y>x?x=y:0;}
inline void cmin(int &x,int y){y<x?x=y:0;}

int read(){
	char ch=gc(); int x=0,op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}

const int N=1100;
int n,cnt[N]; char s[N];

int main(){
	scanf("%s",s+1); n=strlen(s+1);
	rep (i,1,n) cnt[s[i]]|=1;
	if ((cnt['S']||cnt['N'])&&(cnt['S']^cnt['N'])||
		(cnt['W']||cnt['E'])&&(cnt['W']^cnt['E'])) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int N=sc.nextInt();
		long[] kosu=new long[10];
		Arrays.fill(kosu, 0);
		HashMap<Long,Integer> dots=new HashMap<Long,Integer>();	//多分Longしか使わない
		kosu[0]=((long)H-2)*((long)W-2);
		//pl(kosu[0]);
		long MOD=1_000_000_007;
		for(int i=0; i<N; i++) {
			int y=sc.nextInt();
			int x=sc.nextInt();
			Long coord=x*MOD+y;
			long[] mae=new long[10];
			long[] ato=new long[10];
			Arrays.fill(mae, 0);
			Arrays.fill(ato, 0);
			for(int k=-1; k<=1; k++) {
				for(int l=-1; l<=1; l++) {
					//中心
					if(x+k>1 && x+k<W) {
						if(y+l>1 && y+l<H) {
							int tmp=0;
							for(int m=-1; m<=1; m++) {
								for(int n=-1; n<=1; n++) {
									if(dots.containsKey((x+k+m)*MOD+(y+l+n))){
										tmp++;
									}
								}
							}
							mae[tmp]++;
						}
						else {
							//continue;
						}
					}
					else {
						//continue;
					}
					//
				}
			}
			dots.put(coord, 0);
			for(int k=-1; k<=1; k++) {
				for(int l=-1; l<=1; l++) {
					//中心
					if(x+k>1 && x+k<W) {
						if(y+l>1 && y+l<H) {
							int tmp=0;
							for(int m=-1; m<=1; m++) {
								for(int n=-1; n<=1; n++) {
									if(dots.containsKey((x+k+m)*MOD+(y+l+n))){
										tmp++;
									}
								}
							}
							ato[tmp]++;
						}
						else {
							//continue;
						}
					}
					else {
						//continue;
					}
					//
				}
			}
			for(int l=0; l<10; l++) {
				kosu[l]-=mae[l];
				kosu[l]+=ato[l];
			}
		}
		for(int i=0; i<10; i++) {
			pl(kosu[i]);
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	public static void pl() {
		System.out.println();
	}
}


Measured memory_bytes: 141276
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
          int n = int.Parse(Console.ReadLine());
        int[] a = Read.ints();
        int ans = a[1];
        for (int j = 0; j < n; j++)
        {
            int u = int.Parse(Read.Str());
            for (int i = 1; i <= a[0]; i += u)
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
        Console . ReadLine();

    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static string Reverse(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13268
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        an:[i64;n],
    }
    let mut sum_v = vec![0];
    for i in 0..n {
        let sub = sum_v[i];
        sum_v.push(an[i] + sub);
    }
    let mut map = HashMap::new();
    for &v in &sum_v {
        *map.entry(v).or_insert(0) += 1;
    }
    let calc = |x:i64| {
        if x == 2{
            1
        } else if x > 2 {
            (x*(x-1))/2
        } else {
            0
        }
    };
    let ans:i64 = map.into_iter().map(|(_,v)| calc(v)).sum();
    println!("{}",ans);
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 20628
#include<stdio.h>

int main(void){

    long int a,b,k,tmp = 0;

    scanf("%ld %ld %ld",&a,&b,&k);

    if(a<=k){
        tmp = b-(k-a);
        a = 0;
        if(tmp<0) b = 0;
        else b = tmp;
    }else a = a-k;
    printf("%ld %ld",a,b);
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define G 9.8

int main() {
	double v;
	while (cin >> v) {
		double y = v*v/G/2;
		int cnt=1;
		int h = 0;
		while (1) {
			if (y <= h) break;
			cnt++;
			h += 5;
		}

		cout << cnt << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    long long n,x,sum = 1,num = 1,ans = 0;
    cin >> n >> x;
    for(int i = 1; i < n; i ++)
    {
        sum = sum * 2 + 1;
        num = num * 2 + 3;
    }
    while(sum > 1)
    {
        if(x > num + 2)
        {
            ans += sum + 1;
            x -= (num + 1);
        }
        else if(x == num + 2)
        {
            ans += sum + 1;
            cout << ans << endl;
            return 0;
        }
        else if(x >= num + 1)
        {
            ans += sum;
            cout << ans << endl;
            return 0;
        }
        num = (num - 3) / 2;
        sum = (sum - 1) / 2;
        x --;
    }
    if(x == 0) cout << ans << endl;
    else cout << ans + min(3 * 1ll,x - 1) << endl;
    return 0;
}

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

using namespace std;

#define int long long
string s;
int n;

bool check(string a) {
    int id = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == a[id]) ++id;
        if (id == a.size()) break;
    }
    return id == a.size();
}

void solve() {
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < 1000; ++i) {
        string ts = "";
        ts += '0' + i / 100;
        ts += '0' + (i % 100) / 10;
        ts += '0' + i % 10;
        //cout << i << ' ' << ts << '\n';
        if (check(ts)) ++ans;
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 512
'''
奇数距離の場合、偶数回の移動は不可能
偶数距離の場合、奇数回の移動は不可能
'''
N = int(input())
L =[]
for i in range(N):
	t,x,y = input().split(' ')
	L.append([int(t),int(x),int(y)])

now = [0,0,0]
for i in range(N):
	time = L[i][0] - now[0]
	sub_x = abs(now[1] - L[i][1])
	sub_y = abs(now[2] - L[i][2])
	dist = sub_x + sub_y
	if dist%2 == 0:
		if time < dist or time%2 == 1:
			print('No')
			quit()
		else:
			now = L[i]
	else:
		if time < dist or time%2 == 0:
			print('No')
			quit()
		else:
			now = L[i]


print('Yes')

Measured memory_bytes: 19572
#include<iostream>
#include<string>

using namespace std;

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

	int S;
	cin >> S;
	int MM = S % 100;
	int YY = S / 100;

	if ((MM < 1 || 12 < MM) && (YY < 1 || 12 < YY)) {
		cout << "NA" << endl;
	}
	else if ((1 <= MM && MM <= 12) && (YY < 1 || 12 < YY)) {
		cout << "YYMM" << endl;
	}
	else if ((1 > MM || MM > 12) && (1 <= YY && YY <= 12)) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "AMBIGUOUS" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;

int main() {
	int N, Y;
	cin >> N >> Y;
	for (int i = 0; i <= N; i++) {
		int n = N - i;
		int y = Y - i * 10000;
		for (int j = 0; j <= n; j++) {
			if (j * 5000 + (n - j) * 1000 == y) {
				cout << i <<" "<< j<<" "<< n - j;
				return 0;
			}
		}
	}
	cout << -1<<" " << -1<<" " << -1;
	return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

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

    vector<ll> tel;
    vector<ll> visit(n + 10, 0);

    tel.push_back(1);
    visit[1] = 1;
    ll cnt = 1;
    ll nt = 0;

    for (ll i = 0; i < 2 * n; ++i) {
        ll next = a[tel[tel.size() - 1] - 1];

        if (visit[next] == 1) {
            tel.push_back(next);
            nt = a[tel[tel.size() - 1] - 1];
            cnt++;
            break;
        }

        tel.push_back(next);
        visit[next] = 1;
        cnt++;
    }

    ll pos = 0;
    for (auto t : tel) {
        if (t == nt) break;
        pos++;
    }

    ll roop = cnt - pos;

    if (k - pos >= 0) {
        ll idx = (k - pos) % roop;

        cout << tel[pos + idx] << endl;
    } else {
        cout << tel[k] << endl;
    }
}

Measured memory_bytes: 8456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    string s;
    cin >> s;
    int a=0,b=0,c=0,d=0;
    rep(i,s.length()){
        if(s[i] == 'N') a++;
        if(s[i] == 'S') b++;
        if(s[i] == 'W') d++;
        if(s[i] == 'E') c++;
    }

    if(a == 0 && b == 0) a++,b++;
    if(c == 0 && d == 0) c++,d++;
    cout << (a*b*c*d!=0 ? "Yes":"No") << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    ll n;
    cin >> n;
    
    vl v;
    for(ll i = 1; i <= sqrt(n); i++){
        if(n%i==0){
            v.pb(i-1+(n/i)-1);
        }
    }
    sort(all(v));
    cout << v[0];

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<int> a(n), b(n);
    vector<T> sum(n);
    for(int i=0; i<n; i++){
        cin>>a[i]>>b[i];
        sum[i]=T(a[i]+b[i], a[i], b[i]);
    }

    sort(sum.begin(), sum.end(), greater<T>());

    ll ans=0;
    for(int i=0; i<n; i++){
        if(i%2==0) ans+=get<1>(sum[i]);
        else ans-=get<2>(sum[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(void)
{
	int n, x, i,l,cnt=0;
	scanf("%d%d", &n, &x);
	for (i = 1;i <= n;i++) {
		scanf("%d",&l);
		cnt += l;
		if (cnt > x)
			break;
	}
	printf("%d", i);
	return 0;
}


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

using namespace std;

struct Node{
    int parent,left_child,right_brother,depth;
};

void GetNodeType(const Node &currentNode,string &str){
    if(currentNode.parent == -1) str = "root";
    else if(currentNode.left_child == -1) str = "leaf";
    else str = "internal node";
}

void printChildren(const int id,const vector<Node> &Tree){
    int child = Tree[id].left_child;
    while(child != -1){
        if(Tree[child].right_brother == -1) printf("%d",child);
        else printf("%d, ",child);
        child = Tree[child].right_brother;
    }
} 

void SetDepth(int id,vector<Node> &Tree,int depth){
    Tree[id].depth = depth;
    if(Tree[id].right_brother != -1) SetDepth(Tree[id].right_brother,Tree,depth);
    if(Tree[id].left_child != -1) SetDepth(Tree[id].left_child,Tree,depth+1);
}

int main(){
    int num_node;
    int id,k,child,pre_child = -1;
    int root;
    scanf("%d",&num_node);

    vector<Node> Node_array(num_node,Node{-1,-1,-1,0});
    
    for(int i = 0;i < num_node;i++){
        scanf("%d %d",&id,&k);

        // ----- Set tree ------ //

        for(int j = 0;j < k;j++){
            scanf("%d",&child);
            if(j == 0){
                Node_array[id].left_child = child;
                Node_array[child].parent   = id; 
                pre_child = child;
            }else{
                Node_array[pre_child].right_brother = child;
                Node_array[child].parent = id;
                pre_child = child;
                if(j == k-1){
                    Node_array[child].right_brother = -1;
                }
            }  
        }
    }

    for(int i = 0;i < num_node;i++){
        if(Node_array[i].parent == -1) root = i;
    }
    SetDepth(root,Node_array,0);
    for(int id = 0; id < num_node;id++){
         // ------ print infomation ------ //
        string node_type;
        GetNodeType(Node_array[id],node_type);
        
        printf("node %d: parent = %d, depth = %d, %s, [" ,id, Node_array[id].parent, Node_array[id].depth, node_type.c_str());
        printChildren(id,Node_array);
        printf("]\n");
    }

    return 0;   
}



Measured memory_bytes: 7548
use proconio::{fastout, input, marker::Chars};
use std::collections::VecDeque;
#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        ch: i32,
        cw: i32,
        dh: i32,
        dw: i32,
        s:[Chars; h]
    }
    let ch = ch - 1;
    let cw = cw - 1;
    let dh = dh - 1;
    let dw = dw - 1;
    let mut q: VecDeque<[i32; 2]> = VecDeque::new();
    q.push_back([ch, cw]);
    let idh: [i32; 4] = [1, 0, -1, 0];
    let idw: [i32; 4] = [0, 1, 0, -1];
    let mut m: Vec<Vec<i32>> = vec![vec![-1; w as usize]; h as usize];
    m[ch as usize][cw as usize] = 0;

    while !q.is_empty() {
        let qq = q.pop_front().unwrap();
        let hh = qq[0] as usize;
        let ww = qq[1] as usize;
        let v = m[hh][ww];
        idh.iter().zip(idw.iter()).for_each(|(&eh, &ew)| {
            let nh = eh + hh as i32;
            let nw = ew + ww as i32;
            if nh >= 0
                && nh < (h as i32)
                && nw >= 0
                && nw < (w as i32)
                && s[nh as usize][nw as usize] == '.'
                && (m[nh as usize][nw as usize] == -1 || m[nh as usize][nw as usize] > v)
            {
                m[nh as usize][nw as usize] = v;
                q.push_front([nh, nw]);
            }
        });
        (-2 as i32..=2).for_each(|x| {
            (-2 as i32..=2).for_each(|y| {
                let ni = x + hh as i32;
                let nj = y + ww as i32;
                if ni >= 0
                    && nj >= 0
                    && ni < h as i32
                    && nj < w as i32
                    && s[ni as usize][nj as usize] == '.'
                    && m[ni as usize][nj as usize] == -1
                    && (x != 0 || y != 0)
                {
                    q.push_back([ni, nj]);
                    m[ni as usize][nj as usize] = v + 1;
                }
            })
        });
    }
    println!("{}", m[dh as usize][dw as usize]);
}


Measured memory_bytes: 10940
def min_candies(li, x):
    result = 0
    for i in range(len(li) - 1):
        num = li[i] + li[i + 1]
        if num > x:
            result += num - x
            li[i + 1] = li[i + 1] - (num - x)
            if li[i + 1] < 0:
                li[i + 1] = 0

    return result

boxes, x = map(int, input().split())
li = list(map(int, input().split()))
print(min_candies(li, x))

Measured memory_bytes: 14052
//compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
int solve(string x, string y){
	int xl = x.length() - 1;
	int yl = y.length() - 1;
	int dp[1250][1250];
		for(int i=0;i<=xl;i++) dp[i][0] = 0;
		for(int i=1;i<=yl;i++) dp[0][i] = 0;
	if(x == y) return max(xl, yl);
	for(int i=1;i<=xl;i++){
		for(int j=1;j<=yl;j++){
			if(x[i] == y[j]) dp[i][j] = dp[i-1][j-1] +1;
			else dp[i][j] =max(dp[i-1][j], dp[i][j-1]);
		}
	}
	return dp[xl][yl];
}

int main(){
	int q;
	string x, y;
	int i;
	cin >> q;
	rep(i, q){
		cin >> x >> y;
		cout << solve(x = " " + x, y = " " + y) <<endl;
	}


}



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

void run(int N, int R) {
    int innerRating = R;
    if(N < 10){
        // 内部レーティングは特殊計算のケース
        innerRating = R + 100 * (10 - N);
    }
    std::cout << innerRating << std::endl;
}

int main(){
    int a, b;
    std::cin >> a >> b;
    run(a, b);
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    if s[2] == s[3] && s[4] == s[5] {
        println!("{}","Yes");
    } else {
        println!("{}","No");
    }
}


Measured memory_bytes: 4352
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
        int N, K;
    while(cin >> N >> K) {

        vector<LL> A(N);
        REP(i, N) cin >> A[i];

        vector<LL> sum(N + 1);
        REP(i, N) sum[i+1] = sum[i] + A[i];

        vector<LL> sumL(N+1);
        vector<LL> sumR(N+1);

        REP(i, N) {
            sumL[i+1] = sumL[i] + max(0LL, A[i]);
            sumR[N-1-i] = sumR[N-i] + max(0LL, A[N-1-i]);
        }

        LL ans = 0;
        REP(i, N - K + 1) {
            int l = i;
            int r = i + K;
            ans = max(ans, sumL[l] + sumR[r] + max(sum[r] - sum[l], 0LL));
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3456
#include <stdio.h>

int main() {
	int x, a, b;
	scanf ("%d%d%d", &x, &a, &b);
	int xa, xb;
	
	if (x > a) {
		xa = x - a;
	}
	else if (x < a) {
		xa = a - x;
	}
	
	if (x > b) {
		xb = x - b;
	}
	else if (x < b) {
		xb = b - x;
	}
	
	if (xa > xb) {
		printf ("B\n");
	}
	else {
		printf ("A\n");
	}
	return 0;	
}

Measured memory_bytes: 1644
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def WF(mat, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                mat[i][j] = min(mat[i][j], mat[i][k]+mat[k][j])
    return mat


N, M, L = map(int, input().split())
roads = [[float('inf')]*N for _ in range(N)]
kyuyu = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    roads[a-1][b-1] = c
    roads[b-1][a-1] = c

roads = WF(roads, N)
for i in range(N):
    for j in range(i+1, N):
        if roads[i][j] <= L:
            kyuyu[i][j] = 1
            kyuyu[j][i] = 1
kyuyu = WF(kyuyu, N)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    dist = kyuyu[s][t]
    if dist == float('inf'):
        print(-1)
    else:
        print(dist-1)


Measured memory_bytes: 125660
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N;
    private int M;
    private const int Mod = (int)1e9 + 7;

    public void Solve()
    {
        var line = Console.ReadLine().Split(' ');
        N = int.Parse(line[0]);
        M = int.Parse(line[1]);
        if (N < M)
        {
            var T = N;
            N = M;
            M = T;
        }
        if (N - 1 > M)
        {
            Console.WriteLine(0);
            return;
        }
        if (N - 1 == M)
        {
            long d = 1;
            long f = 1;
            for (int i = 1; i <= N; i++)
            {
                d *= i;
                d %= Mod;

            }
            for (int i = 1; i <= M; i++)
            {
                f *= i;
                f %= Mod;
            }
            Console.WriteLine(f * d % Mod);
        }
        if (N == M)
        {
            long d = 1;
            for (int i = 1; i <= N; i++)
            {
                d *= i;
                d %= Mod;

            }
            Console.WriteLine((d * d) % Mod * 2 % Mod);
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

/**
 * 完全二分木
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_A&lang=ja">ALDS1_9_A</a>
 */
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n + 1];

		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			sb.append("node ").append(i).append(": key = ").append(a[i]).append(", ");
			if (parent(i) >= 1) sb.append("parent key = ").append(a[parent(i)]).append(", ");
			if (left(i) <= n) sb.append("left key = ").append(a[left(i)]).append(", ");
			if (right(i) <= n) sb.append("right key = ").append(a[right(i)]).append(", ");
			sb.append("\n");
		}

		System.out.print(sb.toString());

		sc.close();

	}

	private static int parent(int i) {
		return i / 2;
	}

	private static int left(int i) {
		return 2 * i;
	}

	private static int right(int i) {
		return 2 * i + 1;
	}

}



Measured memory_bytes: 26248
#include<bits/stdc++.h>
using namespace std;
int k[2020],f[2000005],a[2000005],g[2000005];
long long sum;
int main() {
string s;
cin>>s;
int n=s.size();
for(int i=0;i<n;i++){
a[i+1]=s[i]-'0';
}
int l=1; 
for(int i=n;i>=1;i--){ 
g[i]=l;
l*=10;
l%=2019;
}
for(int i=n;i>=1;i--){ 
f[i]=(f[i+1]+a[i]*g[i])%2019;
k[f[i]]++;
}
sum=k[0];
sum+=(k[0]*(k[0]-1)/2);
for(int i=1;i<=2018;i++){
sum+=(k[i]*(k[i]-1)/2);
}
cout<<sum;
return 0;
}

Measured memory_bytes: 6044