akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate

n, c = (int(x) for x in input().split())
X = []
V = []
D = []
prev_x = 0
for _ in range(n):
    x, v = (int(x) for x in input().split())
    X.append(x)
    D.append(x - prev_x)
    V.append(v)
    prev_x = x
D.append(c - X[-1])
rev_D = list(reversed(D))
rev_V = list(reversed(V))

ans = 0
# 時計回り
A = [0] * n
for i in range(n):
    A[i] = V[i] - D[i]
acc_A = list(accumulate(A))
ans = max(ans, max(acc_A))

# 反時計回り
B = [0] * n
for i in range(n):
    B[i] = rev_V[i] - rev_D[i]
acc_B = list(accumulate(B))
ans = max(ans, max(acc_B))

max_acc_A = [acc_A[0]]
max_acc_B = [acc_B[0]]
for i in range(1, n):
    max_acc_A.append(max(max_acc_A[-1], acc_A[i]))
    max_acc_B.append(max(max_acc_B[-1], acc_B[i]))

# 時計回りからの反時計回り i個まで食べて向きを変える
tmp = 0
for i in range(n - 1):
    tmp_cal = acc_A[i] - X[i]  # 食べて原点まで戻った時点のカロリー
    tmp = max(tmp, tmp_cal + max_acc_B[n - i - 2])
ans = max(ans, tmp)

# 反時計回りからの時計回り
tmp = 0
for i in range(n - 1):
    tmp_cal = acc_B[i] - (c - X[-i - 1])  # 食べて原点まで戻った時点のカロリー
    tmp = max(tmp, tmp_cal + max_acc_A[n - i - 2])
ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 118996
n = int(input())
a = [int(c) for c in input().split(' ')]
#a = [1 ,2 ,1 ,2 ,1 ,2 ,1 ,2 ,1]
l = len(a)
prev = None
c = 1
inc = None

for i in range(l):
    current = a[i]
    if i == 0 :
        continue
    if inc == None:
        if a[i] > a[i-1] :
            inc = True
        elif             a[i] < a[i - 1]:
            inc = False
        else:
            continue 
    elif inc == True:
        if a[i-1] < a[i]:
            pass
        elif a[i -1] > a[i]:
            c += 1
            inc = None
    elif inc == False:
        if a[i-1] > a[i]:
            pass
        elif a[i - 1] < a[i]:
            c += 1
            inc = None
print(c)


Measured memory_bytes: 14224
fun main(args: Array<String>) {
    val iLine = readLine()!!.split(" ").map(String::toInt)
    val numH = iLine[0]
    val numW = iLine[1]
    var result = "Yes"
    val paintModel = mutableListOf<List<String>>()

    for(i in 0 until numH){
        paintModel.add(readLine()!!.split("").drop(1).dropLast(1))
    }

    run loop@{
        for(i in 0 until numH){
            for(j in 0 until numW){
                if(paintModel[i][j] == "#"){
                    var cond1 = false
                    var cond2 = false
                    var cond3 = false
                    var cond4 = false
                    if(i < 1 || paintModel[i - 1][j] == "."){
                        cond1 = true
                    }
                    if(j < 1 || paintModel[i][j - 1] == "."){
                        cond2 = true
                    }
                    if(i >= numH - 1 || paintModel[i + 1][j] == "."){
                        cond3 = true
                    }
                    if(j >= numW - 1 || paintModel[i][j + 1] == "."){
                        cond4 = true
                    }
                    if(cond1 && cond2 && cond3 && cond4){
                        result = "No"
                        return@loop
                    }

                }
            }
        }
    }

    println(result)
}

Measured memory_bytes: 36084
#include<iostream>
#include<vector>
#include<unordered_map>
#include<map>
using namespace std;
const long long MOD = 1e9 + 7;

int main(void){
    string SS;
    cin >> SS;
    int n = SS.length();
    vector<char> S = vector<char>(n + 2);
    for(int i = 1; i <= n; i++) S[i] = SS[i - 1];

    vector<vector<long long> > dy = vector<vector<long long> >(4, vector<long long>(n + 2, 0));

    dy[3][n + 1] = 1;
    for(int i = n; i >= 0; i--){
        long long m1 = (S[i] == '?')? 3 : 1;
        dy[3][i] = (dy[3][i + 1] * m1) % MOD;
    }

    for(int i = 2; i >= 0; i--){
        for(int j = n; j >= 0; j--){
            if(S[j] == '?'){
                dy[i][j] = (dy[i][j + 1] * 3LL) % MOD;
                dy[i][j] = (dy[i][j] % MOD + dy[i + 1][j + 1] % MOD) % MOD;
            } else if(S[j] == ('A' + i)){
                dy[i][j] = (dy[i][j + 1] % MOD + dy[i + 1][j + 1] % MOD) % MOD;
            } else {
                dy[i][j] = dy[i][j + 1] % MOD;
            }
        }
    }

    /*
    for(int i = 0; i <= 3; i++){
        for(int j = 0; j <= n; j++){
            cout << dy[i][j] << ' ';
        }
        cout << endl;
    }
    */
    cout << dy[0][0] % MOD << endl;
    return 0;
}


Measured memory_bytes: 4352
//コンパイラ最適化用
#pragma GCC optimize("O3")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

vector<ll> mincost;
vector<vector<vector<ll>>> Edges;
vector<bool> ncycle;
deque<ll> bfsrec;

//負閉路検出
void bfs(){
    ll s=SIZE(bfsrec);
    REP(i,s){
        ll now=bfsrec.front();
        for(const auto& edge:Edges[now]){
            if(ncycle[edge[0]]==false){
                ncycle[edge[0]]=true;
                bfsrec.PB(edge[0]);
            }
        }
        bfsrec.pop_front();
    }
    if(s)bfs();
}

bool bellmanford(ll n){
    //(l1-1)(普通のbellman)+1(検出)
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(mincost[j]!=INF){
                for(const auto& edge:Edges[j]){
                    ll new_mincost=mincost[j]+edge[1];
                    if(mincost[edge[0]]>new_mincost){
                        mincost[edge[0]]=new_mincost;
                        if(i==n-1){
                            ncycle[edge[0]]=true;//負の閉路があればtrue
                            bfsrec.PB(edge[0]);
                        }
                    }
                }
            }
        }
    }
    bfs();
    if(ncycle[n-1]==true)return true;
    return false;//Nを含む負の閉路がなければfalse
}


signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    ll n,m,p;cin>>n>>m>>p;
    mincost.resize(n);mincost[0]=0;
    FOR(i,1,n-1)mincost[i]=INF;
    Edges.resize(n);
    ncycle.resize(n);
    REP(i,n)ncycle[i]=false;
    //コストをpでマイナスしてそれを符号逆に
    REP(i,m){
        ll a,b,c;cin>>a>>b>>c;
        Edges[a-1].PB({b-1,p-c});
        //cout<<p-c<<endl;
    }
    //このもとでの最小を考える
    bool check=bellmanford(n);
    if(check or mincost[n-1]==INF){
        cout<<-1<<endl;
    }else{
        cout<<max(-mincost[n-1],ll(0))<<endl;
    }
}

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

struct UnionFind {
  std::vector<int> parent;
  int __size;
  UnionFind(int n) : parent(n, -1), __size(n) {}
  void unite(int x, int y) {
    if ((x = root(x)) != (y = root(y))) {
      if (parent[y] < parent[x]) {
        std::swap(x, y);
      }
      parent[x] += parent[y];
      parent[y] = x;
      __size--;
    }
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  int size(int x) { return -parent[root(x)]; }
  int size() { return __size; }
};

int main() {
  int N, M;
  std::cin >> N >> M;

  UnionFind uf_tree(N);

  for (int i = 0; i < M; i++) {
    int A, B;
    std::cin >> A >> B;
    A--, B--;
    uf_tree.unite(A, B);
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    ans = std::max(ans, uf_tree.size(i));
  }
  std::cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 4032
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int s[] = new int[10];
        int g[] = new int[5];

        while (true) {
            int k;
            int goal = 0;
            int A = 0;

            s[0] = scan.nextInt();
            s[1] = scan.nextInt();
            if (s[0] + s[1] == 0) {
                break;
            }

            for (int i = 2; i < 10; i++) {
                s[i] = scan.nextInt();
            }

            for (k = 0; k < 5; k++) {
                g[k] = s[2 * k] + s[2 * k + 1];
                if (k > 0) {
                    if (g[k] > A) {
                        A = g[k];
                        goal = k;
                    }
                }
                if (k == 0) {
                    A = g[k];
                }
             
            }
            
            switch (goal) {
                case 0:
                    System.out.println("A " + g[0]);
                    break;
                case 1:
                    System.out.println("B "+ g[1]);
                    break;
                case 2:
                    System.out.println("C " + g[2]);
                    break;
                case 3:
                    System.out.println("D " + g[3]);
                    break;
                case 4:
                    System.out.println("E " + g[4]);
                    break;
            }
        }
    }

}



Measured memory_bytes: 30080
from collections import defaultdict

S = input()
T = input()

dic_S = defaultdict(int)
dic_T = defaultdict(int)

for s, t in zip(S, T):
    dic_S[s] += 1
    dic_T[t] += 1

S_count = list(dic_S.values())
T_count = list(dic_T.values())

S_count.sort()
T_count.sort()

if S_count == T_count:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4144
#include<stdio.h>
#define X 1000000007

int main(){
  long long alpha[26] = {};
  char str[100010] = {};
  long long n = 0;
  long long i = 0;
  long long cnt = 1;
  scanf("%lld",&n);
  scanf(" %s",str);
  for(i=0;i<n;i++){
    alpha[str[i]-'a']++;
  }
  for(i=0;i<26;i++){
    cnt = (cnt *((alpha[i] + 1) % X))%X;
  }
  if(cnt==0){
    cnt = X - 1;
  }else{
    cnt--;
  }
  printf("%lld",cnt);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
// #define int long long

int main(){
    int n,k;
    cin >> n >> k;
    int p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    sort(p, p+n);
    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += p[i];
    }
    cout << ans << endl;
}

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

int main(){
  int l,r;
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  l = a+b;
  r = c+d;
  if(l==r)
    cout <<"Balanced"<<endl;
  else if(l>r)
    cout << "Left" << endl;
  else
    cout << "Right" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 100001
int nine[MAXN];
int six[MAXN];
int main () {
    int n;
    cin >> n;
    int min = MAXN;
    for (int i = 0; i <= n; i++) {
        int count = 0;
        int i1 = i;
        while (i1) {
            count += i1 % 9;
            i1 /= 9;
        }
        nine[i] = count;
    }
    for (int i = 0; i <= n; i++) {
        int count = 0;
        int i1 = i;
        while (i1) {
            count += i1 % 6;
            i1 /= 6;
        }
        six[i] = count;
    }
    for (int i = 0; i <= n; i++) {
        if (min > six[i] + nine[n - i]) {
            min = six[i] + nine[n - i];
        }
    }
    cout << min << endl;
    return 0;
}

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

using ll = long long;
static const ll INF = 1e18;

struct edge {
  int to;
  ll cap, cost;
  int rev;
};

vector<ll> h, d; // ポテンシャル, 最短距離
vector<int> prevv, preve; // 直前の頂点と辺

void add_edge(vector<vector<edge>> &G, int from, int to, ll cap, ll cost) {
  G[from].emplace_back((edge) {to, cap, cost, (int) G[to].size()});
  G[to].emplace_back((edge) {from, 0, -cost, (int) G[from].size() - 1});
}

// sからtへの流量fの最小費用流(流せない場合は-1)
ll min_cost_flow(vector<vector<edge>> &G, int s, int t, ll f) {
  ll res = 0;
  h.assign(G.size(), 0);
  prevv.assign(G.size(), 0);
  preve.assign(G.size(), 0);
  while (f > 0) {
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    d.assign(G.size(), INF);
    d[s] = 0;
    pq.push(make_pair(0, s));
    while (!pq.empty()) {
      pair<ll, int> p = pq.top();
      pq.pop();
      int v = p.second;
      if (d[v] < p.first) continue;
      for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && d[e.to] > d[v] + e.cost + h[v] - h[e.to]) {
          d[e.to] = d[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          pq.push(make_pair(d[e.to], e.to));
        }
      }
    }
    if (d[t] == INF) return -1;
    for (int i = 0; i < G.size(); i++) h[i] += d[i];
    
    // s-t間最短路に流す
    int nowf = f;
    for (int i = t; i != s; i = prevv[i]) {
      nowf = min<ll>(nowf, G[prevv[i]][preve[i]].cap);
    }
    f -= nowf;
    res += nowf * h[t];
    for (int i = t; i != s; i = prevv[i]) {
      edge &e = G[prevv[i]][preve[i]];
      e.cap -= nowf;
      G[i][e.rev].cap += nowf;
    }
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;
    
    ll sum = 0;
    vector<vector<ll>> v(n, vector<ll>(3));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        cin >> v[i][j];
      }
      sort(v[i].begin(), v[i].end());
      sum += v[i][0] * v[i][1] * v[i][2];
    }
    
    int vs = 2 * n, vt = 2 * n + 1; // フローの始点と終点
    vector<vector<edge>> G(2 * n + 2);
    for (int i = 0; i < n; i++) {
      add_edge(G, vs, i, 1, 0);
      add_edge(G, i + n, vt, 1, 0);
      for (int j = 0; j < n; j++) {
        if (v[i][0] > v[j][0] && v[i][1] > v[j][1] && v[i][2] > v[j][2]) {
          add_edge(G, i, j + n, 1, -v[j][0] * v[j][1] * v[j][2]);
        }
      }
    }
    add_edge(G, vs, vt, n, 0);
    ll fl = min_cost_flow(G, vs, vt, n);
    cout << sum + fl << '\n';
  }
}


Measured memory_bytes: 3304
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
int main(){
    int A,B,C,D;
    scanf("%d %d %d %d", &A, &B, &C, &D);

    int t = (C + (B - 1)) / B;
    int a = (A + (D - 1)) / D;
    if(t <= a){
        printf("Yes");
    }
    else{
        printf("No");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
#define ll long long
ll dp[100005][2];
int mod=1e9 +7;
vector<vector<int>>v(100005);
#define MAX 1e18+5;
void dfs(int x,int parent)
{
  dp[x][0]=1;
  dp[x][1]=1;
  for(int i=0;i<v[x].size();i++)
  {
    if(v[x][i]!=parent)
    {
      dfs(v[x][i],x);
      dp[x][0]=(dp[x][0]*((dp[v[x][i]][0]+dp[v[x][i]][1])%mod))%mod;
      dp[x][1]=(dp[x][1]*dp[v[x][i]][0])%mod;
    }
  }
}
int main()
{
  fin;
  int n,x,y,i;
  cin>>n;
  for(i=0;i<n-1;i++)
  {
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1,-1);
  cout<<(dp[1][0]+dp[1][1])%mod;
}


Measured memory_bytes: 11520
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    md = 10 ** 9 + 7
    n, k = map(int, input().split())
    aa = list(map(int, input().split()))
    dp = [[0] * (k + 1) for _ in range(n + 1)]
    dp[0][0] = 1
    for i in range(n):
        a = aa[i]
        s = 0
        for j in range(k + 1):
            s += dp[i][j]
            if j - a - 1 >= 0: s -= dp[i][j - a - 1]
            s %= md
            dp[i + 1][j] = s
    # p2D(dp)
    print(dp[n][k])

main()


Measured memory_bytes: 117744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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 MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n, k;
	cin >> n >> k;
	int r,s,p;
	cin >> r >> s >> p;
	string t;
	cin >> t;
	vector<char> hand(n);
	ll ans = 0;
	rep(i,n){
		if(i<k){
			if(t[i]=='r') ans += p, hand[i] = 'p';
			else if(t[i]=='s') ans += r, hand[i] = 'r';
			else ans += s, hand[i] = 's';
		}else{
			if(t[i]=='r'){
				if(hand[i-k]!='p') ans += p,hand[i]='p';
				else if(i+k<n){
					if(t[i+k]=='r') hand[i] = 'r';
					else if(t[i+k]=='s') hand[i] = 's';
					else hand[i] = 'p';
				}
			}
			if(t[i]=='s'){
				if(hand[i-k]!='r') ans += r,hand[i]='r';
				else if(i+k<n){
					if(t[i+k]=='r') hand[i] = 'r';
					else if(t[i+k]=='s') hand[i] = 's';
					else hand[i] = 'p';
				}
			}
			if(t[i]=='p'){
				if(hand[i-k]!='s') ans += s,hand[i]='s';
				else if(i+k<n){
					if(t[i+k]=='r') hand[i] = 'r';
					else if(t[i+k]=='s') hand[i] = 's';
					else hand[i] = 'p';
				}
			}
		}

	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int m,d;
    cin >> m >> d;
    int cnt=0;
    FOR(i,1,d+1)
    {
        int res = (i/10)*(i%10);
        if(res<=m && res>0 && (i/10)>=2 && (i%10)>=2 && (i/100)==0)
        {
            // cout << (i/10)  << " " << (i%10) << endl;
            cnt++;
        }
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

template<ll mod>
struct ModInt{
  using M=ModInt;
  ll a;
  M& put(ll v){
    a=(v<mod)?v:v-mod;
    return *this;
  }
  ModInt(ll v=0){put(v%mod+mod);}
  M operator+(M x){return M().put(a+x.a);}
  M operator-(M x){return M().put(a+mod-x.a);}
  M operator*(M x){return M().put(a*x.a%mod);}
  M operator/(M x){return x.inv()*a;}
  M& operator+=(M x){return *this=*this+x;};
  M& operator-=(M x){return *this=*this-x;};
  M& operator*=(M x){return *this=*this*x;};
  M& operator/=(M x){return *this=*this/x;};
  bool operator==(M x){return a==x.a;}
  M pow(ll m) {
    M x=*this,res=1;
    while(m){
      if(m&1)res*=x;
      x*=x;
      m>>=1;
    }
    return res;
  }
  M inv(){return pow(mod-2);}
};
using mint = ModInt<MOD>;

int N;
int P[514514];
int l[514514];
int BIT[514514];
mint t[514514];
mint fact[514514];

void Add(int k, int x) {
  k++;
  while (k < 514514) {
    BIT[k] += x;
    k += k&-k;
  }
}

int Get(int k) {
  ++k;
  int ret = 0;
  while (k > 0) {
    ret += BIT[k];
    k -= k&-k;
  }
  return ret;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N;
  reps(i, 1, N+1) {
    cin >> P[i];
  }

  fact[0] = 1; 
  reps(i, 1, N+1) {
    fact[i] = fact[i-1] * i;
  }

  int m = 0;
  set<int> bs;
  reps(i, 1, N+1) {
    if (P[i] != 0) bs.insert(P[i]);
    else m++;
  }

  int rem = 0;
  int prev = -1;
  int cnt = 0;
  mint bsum = 0;
  for (int b : bs) {
    Add(b, 1);
    bsum += mint(b-prev-1) * rem;
    rem++;
    l[b] = b-rem;
    prev = b;
  }
  bsum += mint(N-prev) * rem;

  rreps(i, 1, N+1) {
    t[i] = t[i+1];
    t[i] += (P[i] == 0);
  }
  
  mint mc2 = mint(m)*(m-1)/2;
  mint ans = 0;
  reps(i, 1, N) {
    if (P[i] != 0) {
      ans += fact[N-i] * t[i+1] * fact[m-1] * l[P[i]];
      int idx = Get(P[i]-1);
      ans += fact[N-i] * idx * fact[m];
      bsum -= m-l[P[i]];
      --rem;
      Add(P[i], -1);
    } else {
      if (m >= 2) ans += fact[N-i] * fact[m-2] * t[i+1] * mc2;
      if (m >= 1) ans += fact[N-i] * fact[m-1] * bsum;
    }
    //cout << "bsum=" << bsum.a << endl;
    //cout << i << ": " << ans.a << endl;
  }
  ans += fact[m];
  cout << ans.a << endl;
}


Measured memory_bytes: 37760
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n, a;
	cin >> n >> a;
	if (n % 500 <= a) cout << "Yes";
	else cout << "No";
}

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

went_town = set()
now = 1
turn_town = [0]
while True:
    if now-1 in went_town:
        break
    else:
        went_town.add(now-1)
        now = A[now-1]
        turn_town.append(now-1)

for i in range(len(turn_town)-1):
    if turn_town[i] == turn_town[-1]:
        roop_index = i

if K-1 <= len(turn_town)-1:
    print(turn_town[K]+1)
else:
    K -= roop_index+1
    turn_town = turn_town[roop_index+1 : len(turn_town)]
    K %= len(turn_town)
    print(turn_town[K]+1)


Measured memory_bytes: 40472
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef int ss;
#define int long long

typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;

ll a,b,c;

bool ok(ll a,ll b,ll c){
  return a + b > c && b + c > a && c + a > b;
}

ss main()
{
  cin>>a>>b>>c;
  if(a == b && b==c){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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



#define rep(n) for(int i=0;i<n;i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
const int MOD = 1000000007;
const int INF = 1 << 29;

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	if (n % 2)cout << n / 2 << endl;
	else cout << n / 2 - 1 << endl;
	return 0;
	
}


Measured memory_bytes: 256
n=int(input())
cards=sorted(map(int, input().split()), reverse=True)
a=1
b=0
Alice=0
Bob=0
for i in cards:
    if a == 1 and b == 0:
       Alice+=i
       a=0
       b=1
    elif a == 0 and b == 1:
       Bob+=i
       a=1
       b=0
print(Alice-Bob)

Measured memory_bytes: 38256
#include<stdio.h>
int main(){
  int a=0;
  char s[3];
  scanf("%s",s);
  for(int i = 0;i<3;i++){
    if(s[i] == 'a')
      a += 1;
    if(s[i] == 'b')
      a += 2;
    if(s[i] == 'c')
      a += 3;
  }
  if(a == 6)
    printf("Yes");
  else
    printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

#define REP(i,n) for(i=0;i<n;i++)

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int dfs(int v, int n, int *visited, int table[n][n]) {
    int all_visited = 1, i;

    REP(i,n) {
        if (!visited[i]) {
            all_visited = 0;
            break;
        }
    }

    if (all_visited) {
        return 1;
    }

    int count = 0;

    REP(i,n) {
        if (!table[v][i]) continue;
        if (visited[i]) continue;

        visited[i] = 1;
        count += dfs(i, n, visited, table);
        visited[i] = 0;
    }

    return count;
}

int main() {
    int n = iin(), i, a, b;
    long long k = llin();
    long long c[1000000];
    memset(c, 0, sizeof c);
    REP(i, n) {
        a = iin(), b = iin();
        c[a] += b;
    }
    long long count = 0;
    i = 0;
    while(count < k) {
        i++;
        count += c[i];
    }
    iout(i);
    return 0;
}


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

using namespace std;

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

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second

int n; vector<pair<int, ll>> a;

ll dp(int i, int w, vector<vl> &memo) {
    if (memo[i][w] != -1) return memo[i][w];
    if (w == 0) memo[i][w] = 0;
    else if (i == n) memo[i][w] = 0;
    else if (a[i].f > w) memo[i][w] = dp(i + 1, w, memo);
    else memo[i][w] = max(dp(i + 1, w, memo), a[i].s + dp(i + 1, w - a[i].f, memo));
    return memo[i][w];
}

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

    int w;
    cin >> n >> w;
    a.resize(n);
    for (auto &x : a) cin >> x.f >> x.s;
    vector<vl> memo(n + 1, vl(w + 1, -1));

    cout << dp(0, w, memo) << endl;
}

/*
USE LONG LONG!!!!

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)    
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/

Measured memory_bytes: 80256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#ifndef bhartiya
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
 
 
typedef long long ll;
typedef pair<ll, ll> pll;
typedef gp_hash_table<long long, long long> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> oset;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;
 
#define inf 200000000000000ll
#define mod 1000000007ll
#define eps 1e-7
#define PI 3.1415926535897932385
// #define PI acos(-1)
 
#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
 
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) memset(ar, val, sizeof(ar))
 
#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
 
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
inline bool equals(double a, double b) {return fabs(a - b) < 1e-9;}
ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }
 
const ll maxn = 500005;
ll n;
 
int main() 
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(10); //cout<<fixed;
    cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        ll w,h,x,y;
        cin>>w>>h>>x>>y;
        double ans = w*h;
        ans/=2.0;
        cout<<ans<<" ";
        if(x*2 == w && y*2 == h){
            cout<<1;
        }
        else{
            cout<<0;
        }
    }
    end_routine();
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    if (A+B <= C*2) {
        print(A * X + B * Y);
    } else {
        if (X > Y) {
            print(min(C * 2 * Y + (X-Y) * A, C * 2 * X));
        } else if (X < Y) {
            print(min(C * 2 * X + (Y-X) * B, C * 2 * Y));
        } else {
            print(C * 2 * X);
        }
    }
    return 0;
}

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

class ModInt
{
  public const long Mod = 998244353;

  public long num;

  public ModInt(long n) { num = n; }

  public override string ToString() { return num.ToString(); }
  public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
  public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
  public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
  public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

  public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

  public static ModInt Pow(long v, long k)
  {
    long ret = 1;
    for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
      if ((k & 1) == 1) ret = ret * v % Mod;
    return new ModInt(ret);
  }

  public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}

class Combination
{
  ModInt[] fact, ifact;
  public Combination(int n)
  {
    fact = new ModInt[n + 1];
    ifact = new ModInt[n + 1];

    fact[0] = 1;
    for (int i = 1; i <= n; ++i) { fact[i] = fact[i - 1] * i; }
    ifact[n] = ModInt.Inverse(fact[n]);
    for (int i = n; i >= 1; --i) { ifact[i - 1] = ifact[i] * i; }
  }
  public ModInt Val(int n, int k)
  {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
}

public class AtCoder
{
  public static void Main()
  {
    var nmk = Console.ReadLine().Trim().Split().Select(e => int.Parse(e)).ToArray();
    var n = nmk[0];
    var m = nmk[1];
    var k = nmk[2];

    var c = new Combination(200005);

    ModInt ans = 0;
    ModInt col = m;
    for (var x = n - 1; x >= 0; --x)
    {
      ModInt now = col;
      now *= c.Val(n - 1, x);
      if (x <= k) ans += now;
      col *= m - 1;
    }

    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 54828
#include <bits/stdc++.h>
 
using namespace std;
 
#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)

struct Point{
  double x,y;

  Point(){}
  Point(double x,double y) : x(x),y(y) {}

  Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
  Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
  Point operator * (const double &k)const{ return Point(x*k,y*k); }
  Point operator / (const double &k)const{ return Point(x/k,y/k); }
};

double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double norm(const Point &p){ return dot(p,p); }

istream &operator >> (istream &is,Point &p){ 
  return is >> p.x >> p.y;
}

typedef Point Vector;

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
typedef Point Vector;

int ccw(Point p0,Point p1,Point p2){
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(cross(a,b) > EPS){ return COUNTER_CLOCKWISE; }
  if(cross(a,b) < -EPS){ return CLOCKWISE; }
  if(dot(a,b) < -EPS){ return ONLINE_BACK; }
  if(norm(a) < norm(b)){ return ONLINE_FRONT; }
  return ON_SEGMENT;
}



int main(){
  Point p0,p1,p2;
  int Q;
  cin >> p0 >> p1 >> Q;
  while(Q--){
    cin >> p2;
    switch(ccw(p0,p1,p2)){
    case COUNTER_CLOCKWISE:
      puts("COUNTER_CLOCKWISE");
      break;
    case CLOCKWISE:
      puts("CLOCKWISE");
      break;
    case ONLINE_BACK:
      puts("ONLINE_BACK");
      break;
    case ONLINE_FRONT:
      puts("ONLINE_FRONT");
      break;
    default:
      puts("ON_SEGMENT");
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<vector<long long> > vals;
  for(int i = 0; i < n; i++){
    vector<long long> now(3);
    for(auto & v : now) cin >> v;
    vals.push_back(now);
  }
  long long ans = 0;
  for(int i = 0; i < 8; i++){
    vector<long long> has;
    for(int j = 0; j < n; j++){
      long long sum = 0;
    	for(int k = 0; k < 3; k++)
          if(i&(1<<k)) sum += vals[j][k];
      	  else sum -= vals[j][k];
      has.push_back(sum);
    }
    long long now = 0;
    sort(has.begin(), has.end());
    for(int j = 0; j < m; j++) now += has[j];
    ans = max(ans, abs(now));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n, d = map(int, input().split())
x = []
cnt = 0
sum = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        l = 1
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        while (l ** 2 <= sum):
            if l ** 2 == sum:
                cnt += 1
            l += 1

print(cnt)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

int main()
{
    int n, m;
    while(cin >> n >> m && n)
    {
        vector<int> t, h;
        int p, hsum = 0, tsum = 0;

        REP(n){cin >> p; t.push_back(p); tsum += p;}
        REP(m){cin >> p; h.push_back(p); hsum += p;}

        sort(t.begin(), t.end());
        sort(h.begin(), h.end());

        int ct = n,ch = m;

        rep(i,n)rep(j,m)
            if(tsum + h[j] - t[i] == hsum + t[i] - h[j] &&(ct == n || ch == m || t[i] + h[j] < t[ct]+ h[ch]))
            {
                ct = i;
                ch = j;
            }

        if(ct == n || ch == m) {cout << -1<< endl; continue;}
        cout << t[ct] << " " << h[ch] << endl;
            

    }
    return 0;
}

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

using namespace std;
typedef long long int ll;

int main()
{
    int n,q;
    cin >> n;
    vector<int>s(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    cin >> q;
    vector<int>t(q);
    for(int i = 0; i < q; i++) cin >> t[i];
    int ans = 0;
    for(int i = 0; i < q; i++)
    {
        if(binary_search(s.begin(),s.end(),t[i])) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3292
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

//////////////////////////


int main(){fastio
    ll n;cin>>n;
    char s[n*2];
    ll a[n*2];
    ll posw[n];
    ll posb[n];
    rep(i,0,2*n-1){
        cin>>s[i]>>a[i];a[i]--;
        if(s[i]=='W'){
            posw[a[i]]=i;
        }else{
            posb[a[i]]=i;
        }
    }
    ll w[n][n+1];
    rep(i,0,n-1){
        ll val=posw[i];
        rep(j,0,i-1){
            if(posw[j]<posw[i])val--;
        }
        w[i][0]=val;
        rep(j,0,n-1){
            if(posb[j]<posw[i])val--;
            w[i][j+1]=val;
        }
    }
    
    
    ll b[n][n+1];
    rep(i,0,n-1){
        ll val=posb[i];
        rep(j,0,i-1){
            if(posb[j]<posb[i])val--;
        }
        b[i][0]=val;
        rep(j,0,n-1){
            if(posw[j]<posb[i])val--;
            b[i][j+1]=val;
        }
    }
    /*
    rep(i,0,n-1){
        rep(j,0,n)cout<<w[i][j]<<" ";cout<<endl;
    }cout<<endl;
    rep(i,0,n-1){
        rep(j,0,n)cout<<b[i][j]<<" ";cout<<endl;
    }cout<<endl;
    */
    ll dp[n+1][n+1];
    rep(i,0,n)rep(j,0,n)dp[i][j]=inf;
    rep(i,0,n)rep(j,0,n){
        if(i==0&&j==0){dp[i][j]=0;continue;}
        if(i-1>=0)chmin(dp[i][j],dp[i-1][j]+b[i-1][j]);
        if(j-1>=0)chmin(dp[i][j],dp[i][j-1]+w[j-1][i]);
    }
    /*
    rep(i,0,n){
        rep(j,0,n)cout<<dp[i][j]<<" ";cout<<endl;
    }*/
    cout<<dp[n][n];
    
    return 0;
}


Measured memory_bytes: 94080
input = gets.chomp.split(" ")
n = input[0].to_i
m = input[1].to_i

div = 1000000007

a = []
for i in 1..m do
    a.push(gets.chomp.to_i)
end

p0 = [0, 1]
for i in 2..n do
    p0.push((p0[i-1] + p0[i-2])% div)
end

if m == 0
    p (p0[n]+p0[n-1])%div
else
a.uniq!
step = [a[0]]
for i in 1..a.size-1
    step.push(a[i]-a[i-1]-1)
end
step.push(n-a[a.size-1])


ans = 1

for i in 1..step.size do
    ans *= p0[step[i-1]]
    ans = ans % div
end

p ans
end

Measured memory_bytes: 10748
#
import sys
import math
import numpy as np
import itertools


n = int(input())

# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()] 

mi=1000000001
ma=0
for i in range(n):
    if a[i] > ma:
        ma = a[i]
    if a[i] < mi:
        mi = a[i]

print(ma-mi)





Measured memory_bytes: 27068
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vi a(n);
    cin >> a;
    vi b(m),c(m);
    rep(i,m) cin >> b[i] >> c[i];
    map<int,int> ma;
    for(int i : a) ma[i]++;
    rep(i,m) ma[c[i]] += b[i];
    ll ans = 0;
    auto it = ma.end();
    it--;
    while(n > 0) {
        ans += (ll)it->first*min(it->second,n);
        n -= it->second;
        it--;
    }
    cout << ans << endl;
}


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

typedef long long ll;
const int mod = 1e9 + 7;
ll N, M;

int main() {
    cin >> N >> M;
    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    string S;
    cin>>S;
    char ans[200000];
    for(int i=0;i<S.size();i++){
        if(S[i]=='?')cout<<'D';
        else cout<<S[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3724
n, d = map(int, input().split())
l = []
for i in range(n):
    l.append(list(map(int, input().split())))
ans = 0

for i in range(n):
    dist = (l[i][0]**2 + l[i][1]**2) ** (1/2)
    if dist <= d:
        ans += 1

print(ans)


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

using namespace std;

const int MAXN = 1E5 + 10;

int n;
int a[MAXN];

int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	bool flag = false;
	while (true){
		auto odd = [](int t){return t & 1;};
		int cnt = count_if(a, a + n, odd), t = find_if(a, a + n, odd) - a;
		if (cnt > 1 || a[t] == 1 || accumulate(a, a + n, 0ll) - n & 1)
			break;
		flag ^= 1;
		--a[t];
		transform(a, a + n, a, bind2nd(divides<int>(), accumulate(a, a + n, 0, __gcd<int>)));
	}
	flag ^= accumulate(a, a + n, 0ll) - n & 1;
	puts(flag ? "First" : "Second");
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i;
  string S;
  cin >> S;
  for(i=0;i<S.size();i++){
      if(i%2==0){
          if(S[i] =='L'){
              cout << "No" <<endl;
              break;
          }
      }else{
          if(S[i] =='R'){
              cout << "No" << endl;
              break;
          }
        
      }
  }
  if(i==S.size()){
      cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
import sys

def printlist(lst):
	for l in lst:
		print(l),
	print

N = int(sys.stdin.readline().strip())
A = sys.stdin.readline().strip().split(" ")

A = map(lambda x:int(x),A)
for i in range(0,N):
	temp = A[i]
	j = i-1
	while j>=0 and A[j]>temp:
		A[j+1] = A[j]
		j-=1
	A[j+1]=temp
	printlist(A)

Measured memory_bytes: 6452
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,N=2e5+5;
struct node
{
	int x,y;
}a[N];
int f[N],b[N],tree[N],n,ans,t;
void Add(int &x,int y)
{
	x+=y;
	if(x<0)x+=mod;
	else if(x>=mod)x-=mod;
}
void add(int x)
{
	while(x<=n)tree[x]++,x+=x&-x;
}
int sum(int x)
{
	int ans=0;
	while(x)ans+=tree[x],x-=x&-x;
	return ans;
}
int cmp(node x,node y)
{
	return x.y<y.y;
}
int main()
{
	scanf("%d",&n);
	f[0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
		b[i]=a[i].x;
		f[i]=(f[i-1]<<1)%mod;
	}
	sort(a+1,a+n+1,cmp);
	sort(b+1,b+n+1);
	ans=1ll*n*(f[n]-1)%mod;
	for(int i=1;i<=n;i++)
	{
		a[i].x=lower_bound(b+1,b+n+1,a[i].x)-b;
		Add(ans,-f[i-1]+1);
		Add(ans,-f[n-i]+1);
		Add(ans,-f[i-1]+1);
		Add(ans,-f[n-i]+1);
		t=sum(a[i].x);
		Add(ans,f[t]-1);
		Add(ans,f[i-t-1]-1);
		add(a[i].x);
	}
	memset(tree,0,sizeof tree);
	for(int i=n;i;i--)
	{
		t=sum(a[i].x);
		Add(ans,f[t]-1);
		Add(ans,f[n-i-t]-1);
		add(a[i].x);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4096