akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int H = nextInt();
        int W = nextInt();
        int h = nextInt();
        int w = nextInt();
        if (H % h == 0 && W % w == 0) {
            out.println("No");
        } else {
            out.println("Yes");
            int s = 0;
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    int c = 1000;
                    if (i % h == h - 1 && j % w == w - 1) {
                        c = -1000 * (h * w - 1) - 1;
                    }
                    s += c;
                    out.print(c + " ");
                }
                out.println();
            }
            System.err.println(s);
        }

    }

    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

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

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 46692
N,A,B,K=gets.split.map &:to_i;M=998244353;I=[1,1];*F=I;*R=I;2.upto(N){|i|I<<z=(M-M/i)*I[M%i]%M;F<<i*F[-1]%M;R<<z*R[-1]%M};r=0;0.upto(N){|a|b,_=(K-A*a).divmod B;0<=b&&b<=N&&_<1&&r=(r+F[N]**2*R[a]*R[N-a]*R[b]*R[N-b])%M};p r

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 400400;
const int N = 100100;
const int A = 27;

char pool[M * (A + 2) * 8];
char* ptr = pool;

struct Node {
  Node *to[A];
  int sz;
  int fin;

  Node() {
    fill(to, to + A, nullptr);
    sz = 0;
    fin = 0;
  }

  void* operator new(size_t size) {
    void* res = ptr; 
    ptr += size;
    return res;
  }

  void operator delete(void* ptr) {
    assert(ptr);
  }
};

Node *root;

int cnt[N][A][A], low[N];
int n;
string s[N];


void add(string s) {
  Node* cur = root;
  for (char c : s) {
    int x = c - 'a';
    cur->sz++;
    if (cur->to[x] == nullptr)
      cur->to[x] = new Node();
    cur = cur->to[x];
  }
  cur->sz++;
  cur->fin++;
}

void calc(string s, int id) {
  Node *cur = root;
  for (char c : s) {
    int x = c - 'a';

    for (int k = 0; k < A; ++k)
      if (cur->to[k]) 
        cnt[id][x][k] += cur->to[k]->sz;

    low[id] += cur->fin;
    cur = cur->to[x];
  }
}

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


void kill() {
  root = new Node();
  for (int i = 0; i < n; ++i)
    add(s[i]);
  for (int i = 0; i < n; ++i)
    calc(s[i], i);

  int q;
  cin >> q;
  while (q--) {
    int k;
    string ord;
    cin >> k >> ord;
    --k;
    int ans = low[k];
    for (int i = 0; i < (int) ord.length(); ++i)
      for (int j = 0; j < i; ++j) {
        int x = ord[i] - 'a';
        int y = ord[j] - 'a';
        ans += cnt[k][x][y];
      }
    cout << ans + 1 << "\n";
  }
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 317312
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  rep(i, n){
    cin >> a[i];
    sum += a[i];
  }
  sort(rall(a));

  if(a[m-1] < (sum+(4*m)-1)/(4*m)){
    cout << "No" << endl;
  }
  else cout << "Yes" << endl;


  return 0;
}


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

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(v1, v2)     cout << v1 << " " << v2 << endl
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << endl
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << endl

//----------------------------------------------------------------

ll r, s, p;

char win_hand(char x){
  if(x=='r'){
    return 'p';
  } else if(x=='p'){
    return 's';
  } else if(x=='s'){
    return 'r';
  } else {
    return '0';
  }
}

char other_hand(char x){
  if(x=='r'){
    return 'r';
  } else if(x=='p'){
    return 'p';
  } else if(x=='s'){
    return 's';
  } else {
    return '0';
  }
}

ll get_score(char x){
  if(x=='r'){
    return r;
  } else if(x=='p'){
    return p;
  } else if(x=='s'){
    return s;
  } else {
    return 0;
  }
}

int main(void) {
  int n, k;
  cin >> n >> k;
  cin >> r >> s >> p;
  string t;
  cin >> t;

  vector<string> opp(k);

  rep(i,n){
    opp[i%k].push_back(t[i]);
  }

  //debug
  //rep(i,k){prt(opp[i]);}

  ll ans=0;
  rep(i,k){
    char before_hand='0';
    rep(j,opp[i].size()){
      if(before_hand!=win_hand(opp[i][j])){
        ans += get_score(win_hand(opp[i][j]));
        before_hand=win_hand(opp[i][j]);
      } else if(j!=opp[i].size()-1){
        before_hand=other_hand(opp[i][j+1]);
      }
    }
  }

  prt(ans);


}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;cin>>N;
    int ans;ans=0;
    vector<int> L(N);
    for(int i=0;i<N;i++) {
        cin >> L[i];
    }
    sort(L.begin(),L.end());
    for(int i=0;i<N-2;i++) {
        for (int j = i + 1; j < N - 1; j++) {
            for (int k = j + 1; k < N; k++) {
                if (L[k] < (L[i] + L[j])) {
                    ans = ans + 1;
                } else {
                    break;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

int nr, N, A, B, d[15][15], mi[109][109], cod[2][109];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &A, &B);
for (int x=1; x<=A; x++)
    for (int y=1; y<=B; y++)
    {
        scanf ("%d", &d[x][y]);
        for (int i=0; i<=100; i++)
            for (int j=0; j<=100; j++)
            {
                int curr = d[x][y] - x * i - y * j;
                if (curr > mi[i][j])
                    mi[i][j] = curr;
            }
    }
for (int x=1; x<=A; x++)
    for (int y=1; y<=B; y++)
    {
        int mini = 1 << 30;
        for (int i=0; i<=100; i++)
            for (int j=0; j<=100; j++)
            {
                int curr = mi[i][j] + i * x + j * y;
                if (curr < mini)
                    mini = curr;
            }
        if (mini != d[x][y])
        {
            printf ("Impossible\n");
            return 0;
        }
    }
for (int i=0; i<2; i++)
    for (int j=0; j<=100; j++)
        cod[i][j] = ++nr;
printf ("Possible\n");
printf ("%d %d\n", nr, 101 * 101 + 200);
for (int i=0; i<2; i++)
{
    char c = (i == 0 ? 'X' : 'Y');
    for (int j=1; j<=100; j++)
        printf ("%d %d %c\n", cod[i][j - 1], cod[i][j], c);
}
for (int i=0; i<=100; i++)
    for (int j=0; j<=100; j++)
        printf ("%d %d %d\n", cod[0][i], cod[1][100 - j], mi[i][j]);
printf ("%d %d\n", cod[0][0], cod[1][100]);
return 0;
}


Measured memory_bytes: 384
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)


main :: IO ()
main = do
    s <- U.fromList <$> getLine
    let r = U.imap (\i c -> (odd (i+1) && c/='L') || (even (i+1) && c/='R')) s
    putStrLn $ if and (U.toList r) then "Yes" else "No"




Measured memory_bytes: 508
def main():
    n = int(input())
    a = list(map(int, input().split()))
    count = {}
    for aa in a:
        if aa in count:
            count[aa] += 1
        else:
            count[aa] = 1
    balls = list(count.items())
    all = 0
    for b in balls:
        all += b[1] * (b[1] - 1) // 2
    for aa in a:
        print(all - count[aa] + 1)


if __name__ == '__main__':
    main()



Measured memory_bytes: 28832
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include <cmath>
#include <string>

using namespace std;

bool if_prime(int n) {
    int sq = sqrt(n) + 1;
    for(int i = 2;i <= sq;i++) {
        if(n % i == 0)
            return false;
    }
    return true;
}

int main(void) {
    int n;
    cin >> n;
    for(int i = 2,count = 0;count < n;i++) {
        if(if_prime(i) && i % 5 == 1) {
            count++;
            cout << i;
            if(count != n)
                cout << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
struct edge{
  ll to,cost;
};
vector<vector<edge>>E(222222);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n-1;i++){
    ll a,b,c;cin>>a>>b>>c;
    E[--a].pb({--b,c});
    E[b].pb({a,c});
  }
  ll q,k;cin>>q>>k;
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<>>que;
  que.push(mp(0,k-1));
  vi dp(222222,llINF);
  dp[k-1] = 0;
  while(!que.empty()){
    ll now = que.top().S;
    que.pop();
    for(auto e:E[now]){
      if(dp[e.to] > dp[now] + e.cost){
	dp[e.to] = dp[now] + e.cost;
	que.push(mp(dp[e.to],e.to));
      }
    }
  }
  while(q--){
    ll x,y;cin>>x>>y;
    cout<<dp[x-1]+dp[y-1]<<endl;
  }
  return 0;
}


Measured memory_bytes: 15232
#include <iostream>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int n, t, i, j;
  cin >> n;

  int c[n], s[n], f[n];
  for(i=0; i<n-1; i++){
    cin >> c[i] >> s[i] >> f[i];
  }
  c[n]=c[n-1];
  s[n]=s[n-1];
  f[n]=f[n-1];

  for(i=0; i<n-1; i++){
    t=0;
    for(j=i; j<n-1; j++){
      if(s[j]<t){
	t=s[j]+c[j]+ceil((t-s[j])*1.0/f[j])*f[j];
	//	cout << i << " " << j << "pattern1 " << t << endl;
      }
      else{
	t=s[j]+c[j];
	//	cout << i << " " << j << "pattern2 " << t << endl;
      }
    }
    cout << t << endl;
  }
    cout << 0;
  return 0;
}

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

sl = list(S)

if sl[K-1] == "A":
    sl[K-1] = "a"
elif sl[K-1] == "B":
    sl[K-1] = "b"
elif sl[K-1] == "C":
    sl[K-1] = "c"    

ans = "".join(sl)
print(ans)

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

using namespace std;

int main(void) {
    int k, n, a;
    //string len;
    int ans = 9999999; 
    int all = 0;

    cin >> k >> n;

    vector<int> len(n);
    vector<int> dif(n);

    for(int i = 0; i < n; i++){
        cin >> a;
        len.at(i) = a;
        //cout << "len" << i << " " << len.at(i) << endl;
    }

    //ans = len.at(0);
    //cout << "ans0 " << ans << endl;
    for(int i = 0; i < (n - 1); i++){
        dif.at(i) = (len.at(i + 1) - len.at(i));
        all = all + dif.at(i);
        //cout << "dif" << i << " " << dif.at(i) << endl;
        //cout << "all " << all << endl;
    }
    //cout << "aa" << endl;
    dif.at(n - 1) = k - len.at(n - 1) + len.at(0);
    all = all + dif.at(n - 1);
    // cout << "n" << n << endl;
    // cout << "dif" << " " << dif.at(n-1)<< endl;
    // cout << "all " << all << endl;
    // cout << "k-" << k - len.at(n - 1) << endl;

    for(int i = 0; i < n; i++){
        int tem;
        tem = all - dif.at(i);
        ans = min(ans, tem);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
def check(y, conds):
    if len(y) != N:
        return False
    for digit, num in conds.items():
        if y[digit] != num:
            return False
    return True


N, M = map(int, input().split())
conds = {}
for _ in range(M):
    s, c = map(int, input().split())
    if s - 1 in conds:
        if conds[s - 1] != str(c):
            print(-1)
            exit()
    else:
        conds[s - 1] = str(c)

for y in range(1000):
    y_str = str(y)
    if check(y_str, conds):
        print(y_str)
        exit()
print(-1)

Measured memory_bytes: 38624
def get_n(a, line)
  l , r = line.split(' ')
  l = l.to_i - 1
  r = r.to_i - 1
  n = a[r] - a[l]
  return n
end

gets
s = gets.chomp
#acの個数の累積和を計算しておく
a = Array.new
followed_by_a = false
num = 0
s.each_char.each_with_index do |c, i|
  if followed_by_a
    if c == 'C'
      num = num + 1
    end
  end
  if c == 'A'
    followed_by_a = true
  else
    followed_by_a = false
  end
  a << num
end

while(line = gets)
  line = line.chomp
  n = get_n(a, line)
  puts n
end


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

int main(){
    int n;
    int point_t=0, point_h=0;
    string taro, hanako;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> taro >> hanako;
        if(taro > hanako) point_t += 3;
        else if(taro < hanako) point_h += 3;
        else{
            point_t++; point_h++;
        }
    }
    
    cout << point_t << " " << point_h << endl;
}


Measured memory_bytes: 3172
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main() {
    int n; cin >>n;
    map<string, int> s;
    string tmp;
    for (int i = 0; i < n; i++) {
        cin >>tmp;
        s[tmp] += 1;
    }

    int m; cin >>m;
    map<string, int> t;
    for (int i = 0; i < m; i++) {
        cin >>tmp;
        t[tmp] += 1;
    }

    int ret = 0;
    for (auto it: s) {
        ret = max(ret, it.second - t[it.first]);
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;

  bool a = true;

  for (int i = 0; i < S.size(); i++) {
      if (S.at(i) != T.at(i)) {
          a = false;
          break;
      }
  }

  if (a == true && T.size() == S.size() + 1) {
      cout << "Yes";
  }
  else {
      cout << "No";
  }
}

Measured memory_bytes: 3596
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
    long long nPk_modp(long long n, long long k, long long p);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {
  ll n;
  string s;
  cin >> n >> s;

  map<char,ll> m;
  rep(i,n)
  {
    m[s[i]]++;
  }

  ll ans = 1;
  ll mo = 1000000007;
  
  for(auto it: m)
  {
    ans = ans * (it.second + 1) % mo;
  }

  cout << ans - 1 << endl;
  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}

long long Combi::nPk_modp(long long n, long long k, long long p)
{
  ll ans = 1;
  for(long long i = k; i <= n; i++)
  {
    ans = (ans * i) % p;
  }

  return ans;
};

Measured memory_bytes: 512
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int H, W;
char mas[21][21];

int dfs(int x, int y) {
    static int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
    int ret = 1;
    mas[y][x] = '#';
    for(int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if(0 <= nx && nx < W && 0 <= ny && ny < H && mas[ny][nx] == '.') {
            ret += dfs(nx, ny);
        }
    }
    return ret;
}

int main() {

    while(cin >> W >> H, W) {

        int sx, sy;
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                cin >> mas[i][j];
                if(mas[i][j] == '@') sx = j, sy = i;
            }
        }
        cout << dfs(sx, sy) << endl;
    }
}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

bool solve(string& str) {
    int n = str.size();
    if (n == 0 || str[0] != 'A')
        return false;
    if (n < 3)
        return false;
    int num_c = 0;
    int occur_c = 0;
    int l = 2;
    int r = n - 2;
    if (l > r)
        swap(l ,r);
    for (int i = 0; i < n; i++) {
        if (str[i] == 'C') {
            num_c++;
        }
    }
    if (num_c != 1)
        return false;
    for (int i = l; i <= r; i++) {
        if (str[i] == 'C') {
            occur_c++;
        }
    }
    if (occur_c != 1)
        return false;
    for (int i = 0; i < n; i++) {
        if (str[i] != 'A' && str[i] != 'C') {
            if (!(str[i] >= 'a' && str[i] <= 'z')) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    string str;
    cin >> str;
    if (solve(str))
        cout << "AC" << endl;
    else
        cout << "WA" << endl;
    return 0;
}


Measured memory_bytes: 256
'use strict'

function main(input) {

    input = input.split(' ').map(x => +x)
    let b = input[1]
    let d = b - input[0]
    let c = 0
    for (let i = 1; i <= d; i++) {
        c += i
    }
    console.log(c - b)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        x: usize,
        y: usize,
    }

    for i in 0..x + 1 {
        if 2 * i + 4 * (x - i) == y {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


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

#define int long long int

void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif
//!

int32_t main()
{
	GO
	//fioe();
	int n,m;
	cin>>n>>m;
	int ans = (n*(n-1))/2 +(m*(m-1))/2;
	cout<<ans<<endl;	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN=1E4+10;
const int P=1E9+7;

template<typename T1,typename T2>
	void Inc(T1 &a,T2 b){a+=b;if(a>=P) a-=P;}

template<typename T1,typename T2>
	void Dec(T1 &a,T2 b){a-=b;if(a<0) a+=P;}

template<typename T1,typename T2>
	T1 Add(T1 a,T2 b){a+=b;return a>=P?a-P:a;}

template<typename T1,typename T2>
	T1 Sub(T1 a,T2 b){a-=b;return a<0?a+P:a;}

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

int n,siz[MAXN],rt,mxrt;
vector<int> T[MAXN];
ll fac[MAXN],ifac[MAXN],f[2][MAXN];

ll C(int n,int m){return fac[n]*ifac[n-m]%P*ifac[m]%P;}

ll A(int n,int m){return fac[n]*ifac[n-m]%P;}

void find_rt(int x,int fa)
{
	siz[x]=1;
	int mx=0;
	for(int v:T[x])
		if(v!=fa)
		{
			find_rt(v,x);
			siz[x]+=siz[v];
			mx=max(mx,siz[v]);
		}
	mx=max(mx,n-siz[x]);
	if(mx<mxrt)
		mxrt=mx,rt=x;
}

int main()
{
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++)
		scanf("%d%d",&u,&v),
		T[u].push_back(v),
		T[v].push_back(u);
	fac[0]=ifac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%P;
	ifac[n]=ksm(fac[n],P-2);
	for(int i=n-1;i;i--)
		ifac[i]=ifac[i+1]*(i+1)%P;
	mxrt=1<<30;
	find_rt(1,0);
	if(~n&1&&mxrt==n/2)
		return printf("%lld\n",fac[n/2]*fac[n/2]%P),0;
	find_rt(rt,0);
	int lst=0;
	f[lst][0]=1;
	for(int v:T[rt])
	{
		memcpy(f[!lst],f[lst],sizeof f[!lst]);
		for(int i=0;i<=n;i++)
			for(int j=1;j<=siz[v]&&i+j<=n;j++)
				Inc(f[!lst][i+j],f[lst][i]*A(siz[v],j)%P*C(siz[v],j)%P);
		lst^=1;
	}
	ll Ans=0;
	for(int i=0;i<=n;i++)
	{
		if(i&1)
			Dec(Ans,f[lst][i]*fac[n-i]%P);
		else
			Inc(Ans,f[lst][i]*fac[n-i]%P);
	}
	printf("%lld\n",Ans);
}


Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <map>
#include <iomanip> 
#include <ctime>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<string, int> P;

const double PI = 3.14159265358979323846;


int main(int argc, char *args[]) {
	int n; cin >> n;
	vector<int> x(n);
	rep(i, n)cin >> x[i];
	int ave = 0;
	rep(i, n) ave += x[i];
	int ave1 = ave / n;
	int ave2 = ave1 + 1;
	int ans = 0;
	int tmp = 0;
	rep(i, n) {
		tmp += (x[i] - ave1)*(x[i] - ave1);
	}
	rep(i, n) {
		ans += (x[i] - ave2)*(x[i] - ave2);
	}
	ans = min(ans, tmp);
	cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def rdp_trace(n: int, i: int) -> list:
    def loop(n: int, i: int) -> list:
        if n == 1:
            return []
        if i <= n // 2:
            rval = loop(n // 2, (n // 2) - i + 1)
            rval.append(i)
            return rval
        else:
            rval = loop(n // 2, i - (n // 2))
            rval.append(i)
            return rval
    return loop(2 ** n, i)

def rdp_connect() -> bool:
    global n, i, j
    n, i, j = map(int, input().split())
    if n == i == j == 0:
        return False
    return True

if __name__ == '__main__':
    while rdp_connect():
        rval = []
        for k, lv in zip(range(n), rdp_trace(n, i)):
            if (lv <= (2 ** (k + 1)) // 2):
                if (j <= (2 ** (n - k)) // 2):
                    rval.append('L')
                    j = (2 ** (n - k)) // 2 - j + 1
                else:
                    rval.append('R')
                    j = (2 ** (n - k)) - j + 1
            else:
                if (j <= (2 ** (n - k)) // 2):
                    rval.append('R')
                else:
                    rval.append('L')
                    j = j - (2 ** (n - k)) // 2
        print(''.join(rval))

Measured memory_bytes: 7784
#include<iostream>
#include<vector>
#include<map>
#include<numeric>
#define ll long long

using namespace std;

int main() {
  int n,m;
  string s,t;
  map<string,int> mp;
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> s;
    mp[s]++;
  }
  cin >> m;
  for(int i=0;i<m;++i){
    cin >> t;
    mp[t]--;
  }

  int ans=0; 
  for(auto itr=mp.begin();itr!=mp.end();itr++){
    if(ans<itr->second){
      ans=itr->second;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 888
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) comb(m, n int) int {
	p := [][]int{make([]int, m+1), make([]int, m+1)}
	p[0][0] = 1
	p[1][0] = 1
	for i := 1; i <= m; i++ {
		a := i & 1
		b := (i - 1) & 1
		for j := 1; j <= i; j++ {
			p[a][j] = p[b][j] + p[b][j-1]
		}
	}
	return p[m&1][n]
}

func (con *contest) main() error {
	var N, A, B int
	con.Scan(&N, &A, &B)
	v := make([]int, N)
	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		con.Scan(&v[i])
	}
	sort.Ints(v)
	for i := 1; i <= N; i++ {
		s[i] = s[i-1] + v[N-i]
	}
	maxa := 0.0
	maxi := 0
	for i := A; i <= B; i++ {
		a := float64(s[i]) / float64(i)
		if a > maxa {
			maxa = a
			maxi = i
		}
	}
	con.Println(maxa)
	c := 0
	for i := A; i <= B; i++ {
		if s[i]*maxi == s[maxi]*i {
			var m, n int
			for j := 0; j < N; j++ {
				if v[j] == v[N-i] {
					m++
					if j >= N-i {
						n++
					}
				}
			}
			c += con.comb(m, n)
		}
	}
	con.Println(c)
	return nil
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n;
  for(int i=n;;)
  {
      m=i/2;
      int flag=0;
      if(i==2)
      {
          cout<<i<<endl;
          break;
      }
      else
      {
          for(int j=2;j<=m;j++)
          {
              if(i%j==0)
              {
                  flag=1;
                  break;
              }

          }
          if(flag==0)
          {
              cout<<i<<endl;
              break;
          }
          else
          {
              i++;
          }
      }


  }
  return 0;




}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

vector<i64> fact;
void init_fact(i64 n,i64 m){
	fact.resize(n+1);
	fact[0]=fact[1]=1;
	for(i64 i=2; i<=n; ++i) fact[i]=(i*fact[i-1])%m;
}

i64 extgcd(i64 a,i64 b,i64 &x,i64 &y){
	i64 d=a;
	if(b!=0){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	} else {
		x=1; y=0;
	}
	return d;
}

i64 mod_inverse(i64 a,i64 m){
	i64 x,y;
	if(extgcd(a,m,x,y)==1) return (x+m)%m;
	return 0;
}

i64 rep_pow(i64 x,int64_t y,i64 mod){
	i64 res(1);
	while(y>0){
		if(y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}

vector<vector<i64>> comb;
void init_mod_comb(int n,int k,i64 mod){
	comb.resize(n+1);
	for(int i=0; i<=n; ++i){
		comb[i].resize(min(i+1,k+1));
		comb[i][0]=1;
		if(i<=k) comb[i][i]=1;
	}
	for(int i=1; i<=n; ++i){
		for(int j=1; j<=min(i-1,k); ++j){
			comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%mod;
		}
	}
}

void solve(){
	i64 mod=1000000007;
	init_mod_comb(1001,1001,mod);
	init_fact(1001*1001,mod);

	map<i64,i64> inv_table;
	auto inv=[&](i64 x){
		if(inv_table.find(x)!=inv_table.end()) return inv_table[x];
		return inv_table[x]=mod_inverse(x,mod);
	};

    i64 N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    static i64 dp[1024][1024];
    fill_n((i64*)dp,1024*1024,0);
    dp[A][0]=1;
    rep(i,C,D+1){
        if(A*i>N) break;
        dp[A][A*i]=comb[N][A*i]*fact[A*i]%mod*inv(fact[i]*rep_pow(fact[A],i,mod)%mod)%mod;
    }

	rep(i,A,B){
		rep(j,0,N+1){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			rep(k,C,D+1){
				if(j+(i+1)*k>N) break;
				dp[i+1][j+(i+1)*k]=(dp[i+1][j+(i+1)*k]+dp[i][j]*comb[N-j][(i+1)*k]%mod*fact[(i+1)*k]%mod*inv(fact[k]*rep_pow(fact[i+1],k,mod)%mod)%mod)%mod;
			}
		}
	}

	cout << dp[B][N] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 22400
N = int(input())
H = list(map(int, input().split()))
ans = 0
count = 0
for i in range(1, N):
    if H[i-1] >= H[i]:
        count += 1
    else:
        ans = max(ans, count)
        count = 0
ans = max(ans, count)
print(ans)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define ll long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define pb push_back
#define endl '\n'
#define IO ios::sync_with_stdio(false)
using namespace std;
const ll maxn = 1e6 + 5;
string str;
int main(){
    double l;
    cin >> l;
    printf("%.9lf",l * l * l / 27);
    return 0;
}


Measured memory_bytes: 256
/*
  AUTHOR:SOURABH
  CREATED:03:04:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,m,sum,ans,cri,i;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n>>m;
        vll a(n);
        sum=ans=0;
        fn(i,n)
        {
            cin>>a[i];
            sum+=a[i];
        }
        cri=sum/(4*m);
        if(sum%(4*m))
            cri++;
        fn(i,n)
        {
            if(a[i]>=cri)
                ans++;
        }
        if(ans>=m)
            cout<<"Yes";
        else
            cout<<"No";
    }
    return 0;
}















Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n,q,l,r;
	cin >> n>>q;
    string s;
    int a[n];
    int c=0;
    a[0]=0;
    cin >> s;
    fr(i,n-1){
      if(s.substr(i, 2)=="AC"){
        c++;
      }
      a[i+1]=c;
    }
    fr(i,q){
     cin >> l >> r;
      cout << a[r-1]-a[l-1] << endl;
   }
}


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

int main() {
  int n;
  long long d;
  int cnt = 0;
  std::cin >> n >> d;
  long long x;
  long long y;
  for (int i = 0; i < n; i++) {
    std::cin >> x >> y;
    if (x*x + y*y <= d*d) cnt++;
  }

 
  std::cout << cnt;
  return 0;
}



Measured memory_bytes: 3616
count_gift = int(input())
price_list = []
total_payment = 0

for _ in range(count_gift):
    price_list.append(int(input()))

price_list.sort(reverse=True)
total_payment = price_list.pop(0) // 2

for i in price_list:
    total_payment += i

print(total_payment)


Measured memory_bytes: 9100
import scala.io.StdIn.{readInt, readLine};
import scala.annotation.tailrec;
object Main {
    def main(args: Array[String]): Unit = {
        val size = readInt;
        val m = new Array[Array[Int]](size);
        (0 until size).foreach {  i => m(i) = readLine.trim.split(" ").map( a => if (a.toInt == -1) Int.MaxValue else a.toInt)}
        val g = new Graph(size, m);
        val (parent, distance) = g.prim;
        println(distance.sum)
    }
}
case class Graph(size: Int, matrix: Array[Array[Int]]) {
    val INFINITY = Int.MaxValue
    def prim(): (Array[Int], Array[Int]) = {
        // WHITE : 未訪問, GRAY: MST候補ノード, BLACK: MST追加済みノード
        val WHITE = 0; val GRAY = 1; val BLACK = 2;
        val color = new Array[Int](size); // 訪問状態リスト(WHITE, GRAY, BLACK)
        val distance = new Array[Int](size).map( e => INFINITY); //  重みリスト
        val parents = new Array[Int](size); //  親ノードリスト
        @tailrec
        def _prim(curr: Int): Unit = {
            // MSTに属する頂点の集合から最も近いノードの index を取得する
            val idx = (0 until size).foldLeft(-1) { (minidx, i) =>
                if (color(i) != BLACK) {
                    // curr の子ノードをMST候補ノードに追加
                    if (matrix(curr)(i) != -1) {
                        color(i) = GRAY;
                    }
                    if (color(i) == GRAY) {
                        // すでに登録されている重みよりも curr からの重みのほうが小さい場合は
                        // 親ノードと重みを更新する
                        if (matrix(curr)(i) < distance(i)) {
                            distance(i) = matrix(curr)(i);
                            parents(i) = curr;
                        }
                        if (minidx == -1 || distance(i) < distance(minidx)) i else minidx;
                    } else { // color(i) == WHITE
                        // 現時点のMSTに隣接していないノードは評価しない
                        minidx;
                    }
                } else { // color(i) == BLACK 
                    // すでにMSTに追加されているノードは評価しない
                    minidx;
                }
            }
            if (idx != -1){
                // MSTから最も距離の近いノードを追加
                color(idx) = BLACK;
                _prim(idx);
            }
        }
        distance(0) = 0;
        parents(0) = -1;
        color(0) = BLACK;
        _prim(0);
        (parents, distance);
    }
}


Measured memory_bytes: 50340
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<deque<int>> graph(N);
  for (int i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B, --A, --B;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }
  vector<int> ans(N, -1);
  queue<int> que;
  que.push(0);
  ans[0] = 0;
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int to : graph[v]) {
      if (ans[to] != -1) continue;
      ans[to] = v + 1;
      que.push(to);
    }
  }
  if (any_of(begin(ans), end(ans), [](int n) { return n == -1; }))
    cout << "No" << endl;
  else {
    cout << "Yes" << '\n';
    for (int i = 1; i < N; ++i) cout << ans[i] << '\n';
  }
}


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

//const Long MX = ;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	Long n;
	cin >> n;
	string ans = "";
	while(n > 0){
		n--;
		ans += char(n % 26 + 'a');
		n /= 26;
	}
	reverse(ans.begin(),ans.end());
	cout << ans << "\n";
	return 0;
}


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

int main(){
	int H,W,i,j;
		
	while(1){
		cin>>H>>W;
		if(H==0 && W==0)
			break;
		for(i=0;  i<H; i++){
			for(j=0;  j<W; j++){
				cout<<"#";
			}
			cout<<endl;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1152
N=int(input())
A=list(map(int,input().split()))
color=set()
over_3200=0
 
for i in range(N):
  if A[i]<=399:
    color.add(1)
  elif A[i]<=799:
    color.add(2)
  elif A[i]<=1199:
    color.add(3)
  elif A[i]<=1599:
    color.add(4)
  elif A[i]<=1999:
    color.add(5)
  elif A[i]<=2399:
    color.add(6)
  elif A[i]<=2799:
    color.add(7)
  elif A[i]<=3199:
    color.add(8)
  else:
    over_3200+=1

if len(color)==0:
  print(1,over_3200)
else:
  print(len(color),len(color)+over_3200)

Measured memory_bytes: 9092
#include<stdio.h>
#include<stdlib.h>

int main(void) 
{
	int t,h,m,s;
	
	scanf("%d", &t);
	h = t /3600;
	m = (t - h * 3600) / 60;
	s = t - (h * 3600) - (m * 60);
	printf("%d:%d:%d\n", h, m , s);
    return 0;
}


Measured memory_bytes: 2732
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans[ohara], a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i, n) {
    cin >> a >> b;
    rrep(j, a, b + 1) ans[j] = 1;
  }
  rep(i, ohara) {
    if (ans[i]) cnt++;
  }
  Cout(cnt);
  return 0;
}

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

using graph = vector<vector<int>>;

void dfs(const graph &to, vector<int64_t> &color, int v, int p, int k) {
  int c = k;
  if (v != 0) c--;
  for (int x : to.at(v)) {
    if (x == p) continue;
    c--;
    color.at(x) = c;
    dfs(to, color, x, v, k);
  }
}

int main()
{
  int n, k;
  cin >> n >> k;
  graph to(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to.at(a).push_back(b);
    to.at(b).push_back(a);
  }
  vector<int64_t> color(n);
  color.at(0) = k;
  dfs(to, color, 0, -1, k);
  int64_t ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= color.at(i);
    ans %= 1000000007;
  }
  cout << ans << endl;
}


Measured memory_bytes: 15396
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

const M: usize = std::usize::MAX / 10;
fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, a: [usize; n]);
    let mut g = vec![vec![]; n];
    for _ in 0..(n - 1) {
        parse!(it, a: usize, b: usize);
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }
    let mut ret = vec![0; n];
    let mut dp = vec![M; n];
    let mut seen = vec![false; n];
    seen[0] = true;
    dfs(&g, &mut ret, &mut dp, 0, &a, &mut seen);
    for r in ret {
        println!("{}", r);
    }
}
fn dfs(
    g: &Vec<Vec<usize>>,
    ret: &mut Vec<usize>,
    dp: &mut Vec<usize>,
    u: usize,
    a: &Vec<usize>,
    seen: &mut Vec<bool>,
) {
    let i = match dp.binary_search(&a[u]) {
        Ok(i) => i,
        Err(i) => i,
    };
    let previ = dp[i];
    dp[i] = a[u];
    ret[u] = dp.binary_search(&(M - 1)).unwrap_err();
    for &v in g[u].iter() {
        if !seen[v] {
            seen[v] = true;
            dfs(g, ret, dp, v, a, seen);
        }
    }
    dp[i] = previ
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 38212
#include <stdio.h>
#include <iostream>

using namespace std;
int main (void){
    int miha = 0,hami =0;
    cin >> miha >> hami;
    if ( miha > 9 || hami > 9 ){
        cout << "-1";
        return 0;
    }
    int X = 0;
    X = miha * hami;
    cout << X;
    return 0;
}


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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N,M;
    cin>>N>>M;
    vector<queue<ll>> A(N);
    REP(i,N){
        REP(j,M){
            ll a;
            cin>>a;
            a--;
            A[i].push(a);
        }
    }

    set<ll> st;
    REP(i,M) st.insert(i);

    ll ans=N;
    REP(i,M){
        vector<ll> cnt(M,0);
        REP(i,N){
            ll a=A[i].front();
            cnt[a]++;
        }

        ll idx=0;
        ll tmp=0;
        REP(i,M){
            if(cnt[i]>tmp){
                tmp=cnt[i];
                idx=i;
            }
        }

        ans=min(ans,tmp);

        st.erase(idx);
        REP(i,N){
            while(!A[i].empty()){
                ll a=A[i].front();
                if(st.count(a)) break;
                else A[i].pop();
            }
        }
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 4444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N=2e5+10,mod=1e9+7;
vector<int>e[N];
int sz[N],n,u,v;
ll dp[N],fac[N],Finv[N],inv[N],ans[N];
ll modpow(ll x,ll n,ll mod)
{
	ll res=1;
	for(;n;x=x*x%mod,n/=2)
	if(n&1)res=res*x%mod;
	return res;
}
ll get_inv(ll x)
{
    return modpow(x,mod-2,mod);
}
void init(int n)//n<N
{
    inv[1]=1;
    for(int i=2;i<=n;++i)inv[i]=((mod-mod/i)*inv[mod%i])%mod;
	fac[0]=Finv[0]=1;
	for(int i=1;i<=n;++i)fac[i]=fac[i-1]*i%mod,Finv[i]=Finv[i-1]*inv[i]%mod;
	//Finv[n]=modpow(jc[n],mod-2,mod);
	//for(int i=n-1;i>=1;--i)Finv[i]=Finv[i+1]*(i+1)%mod;
}
//视具体情况更改link/cut/leaf函数 
void dp_link(int rt1,int rt2)
{
	//因sz发生变化 除掉原来的(sz-1)! 乘上新的(sz-1)! 
    dp[rt1]=dp[rt1]*Finv[sz[rt1]-1]%mod;
    sz[rt1]+=sz[rt2];
    dp[rt1]=dp[rt1]*fac[sz[rt1]-1]%mod;
    //乘上dp[rt2]/(sz[rt2]!) 
    dp[rt1]=dp[rt1]*Finv[sz[rt2]]%mod;
    dp[rt1]=dp[rt1]*dp[rt2]%mod;
}
void dp_cut(int rt1,int rt2)
{
	//因sz发生变化 除掉原来的(sz-1)! 乘上新的(sz-1)!
    dp[rt1]=dp[rt1]*Finv[sz[rt1]-1]%mod;
    sz[rt1]-=sz[rt2];
    dp[rt1]=dp[rt1]*fac[sz[rt1]-1]%mod;
    //除掉dp[rt2]/(sz[rt2!] 
    dp[rt1]=dp[rt1]*fac[sz[rt2]]%mod;
    dp[rt1]=dp[rt1]*get_inv(dp[rt2])%mod;
}
void get_leaf(int rt)
{
    sz[rt]=1;
    dp[rt]=1;
}
///-----------------------------
void change_rt(int rt1,int rt2)//把根从rt1切换到rt2 
{
    dp_cut(rt1,rt2);// 使rt1失去儿子rt2 
    dp_link(rt2,rt1);//使rt2加上儿子rt1 
}
void dp_dfs(int x,int fa)
{
    get_leaf(x);
    for(auto &i:e[x])
    {
        if(i!=fa)
        {
            dp_dfs(i,x);
            dp_link(x,i);//回溯时 把x挂到i上 
        }
    }
    return;
}
void dfs(int x,int fa)
{
    ans[x]=dp[x];
    for(auto &i:e[x])
    {
        if(i!=fa)
        {
            change_rt(x,i);//根从x换到i 
            dfs(i,x);
            change_rt(i,x);//回溯 把根换回来 
        }
    }
    return;
}
int main()
{
    scanf("%d",&n);
    init(200000);
    for(int i=1;i<n;++i)
    {
        scanf("%d %d",&u,&v);
        e[u].pb(v),e[v].pb(u);
    }
    dp_dfs(1,-1);
    dfs(1,-1);
    for(int i=1;i<=n;++i)
    {
        printf("%lld\n",ans[i]);
    }
    return 0;
}

Measured memory_bytes: 22516