akhauriyash/Code-Regression huggingface dataset:
// atcoder/abc17173/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  while (cin >> n) {
    vec<lli> a(n);
    cin >> a;
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    lli x = 0;
    priority_queue<pair<lli, lli>> q;
    each (i, a) {
      if (q.empty()) {
        q.push({i, i});
      } else {
        pair<lli, lli> p = q.top();
        x += min(p.first, p.second);
        q.pop();
        q.push({min(i, p.first), max(i, p.first)});
        q.push({min(i, p.second), max(i, p.second)});
      }
    }
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 9000
/* 
 * Project: AtCoder Beginners Contest 176 A - Takoyaki
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/22
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
using namespace std;

uint32_t n;
uint32_t x;
uint32_t t;

void solve() {

    uint32_t time = 0;
    if (n%x == 0)
        time = (n / x) * t;
    else
        time = (n / x + 1) * t;
    
    printf("%d\n", time);
}

int main() {

    scanf("%d", &n);
    scanf("%d", &x);
    scanf("%d", &t);

    solve();

}

Measured memory_bytes: 3228
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():

    n = input_int()
    A = input_int_list()
    cnt = defaultdict(int)
    for a in A:
        rank = a // 400
        if rank >= 8:
            rank = 8
        cnt[rank] += 1
    ans_min = 0
    ans_max = 0
    for k, v in sorted(cnt.items(), key=lambda x: x[0]):
        if k != 8:
            ans_min += 1
            ans_max += 1
        elif k == 8:
            if ans_min == 0:
                ans_min = 1
                ans_max = v
            else:
                ans_max += v
    print(ans_min, ans_max)

    return


if __name__ == "__main__":
    main()


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

using namespace std;
vector<char> v;
int main() {
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == 'S' || (v.empty() || v.back() == s[i]))
            v.push_back(s[i]);
        else v.pop_back();
    }
    cout << v.size() << "\n";
    return 0;
}

Measured memory_bytes: 788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    string s;cin>>s;
    int n=s.size();
    int a[n+1],b[n+1];
    a[0]=0,b[n]=0;
    for(int i=0;i<n;i++){
        if(s[i]=='<')a[i+1]=a[i]+1;
        else a[i+1]=0;
    }
    for(int i=n-1;i>-1;i--){
        if(s[i]=='>')b[i]=b[i+1]+1;
        else b[i]=0;
    }
    int ans=0;
    for(int i=0;i<n+1;i++){
        ans+=max(a[i],b[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static long cnt = 0;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] S = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            MergeSort(S, 0, n);
            
            Console.WriteLine(cnt);
        }

        static void MergeSort(int[] A, int left, int right)
        {
            if (left + 1 < right)
            {
                int mid = (left + right) / 2;
                MergeSort(A, left, mid);
                MergeSort(A, mid, right);
                Merge(A, left, mid, right);
            }
        }

        static void Merge(int[] A,int left,int mid,int right)
        {
            int n1 = mid - left;
            int n2 = right - mid;

            int[] L = new int[n1 + 1];
            int[] R = new int[n2 + 1];

            for (int i = 0; i < n1; i++) L[i] = A[left + i];
            for (int i = 0; i < n2; i++) R[i] = A[mid + i];

            L[n1] = int.MaxValue;
            R[n2] = int.MaxValue;

            int x = 0, y = 0;

            for(int i = left; i < right; i++)
            {
                if (L[x] <= R[y])
                {
                    A[i] = L[x];
                    x++;

                    cnt += y;
                }
                else
                {
                    A[i] = R[y];
                    y++;
                }
            }
        }
    }
}

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

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 emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n, d;
    cin >> n >> d;
    ll ans = 0;
    while(n > 0){
        n -= 2 * d + 1;
        ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3632
while True:
    n, p = map(int, input().split())
    if n == 0 and p == 0:
        break

    own = [0 for i in range(n)]
    stone = p
    flag = True
    while flag:
        for i in range(n):
            if stone == 0:
                stone += own[i]
                own[i] = 0
            else:
                own[i] += 1
                stone -= 1
            if stone == 0 and own[i] == p:
                print(i)
                flag = False
                break


Measured memory_bytes: 5600
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#define ull unsigned long long
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define FOR(i, stop) for(int i = 0; i < (stop); i++)
#define PI 3.141592653589793
using namespace std;

int main(){

  string n;
  cin >> n;

  int sum=0;

  FOR(i,(int)n.size())
    sum += n[i]-'0';

  if(sum%9 == 0) yes;
  else no;

  return 0;
}

Measured memory_bytes: 3748
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
int main() {
	ll K, N;
	cin >> K >> N;
	if (K % 2 == 0) {
		cout << K / 2;
		for (int i = 0; i < N - 1; i++) cout << " " << K;
		cout << endl;
		return 0;
	}
	vector<int> vec(N, (K + 1) / 2);
	for (int i = 0; i < N / 2; i++) {
		if (vec.back() == 1) {
			vec.pop_back();
		}
		else {
			vec.back()--;
			int sz = vec.size();
			for (int j = 0; j < N - sz; j++) vec.push_back(K);
		}
	}
	cout << vec[0];
	for (int i = 1; i < vec.size(); i++) cout << " " << vec[i];
	cout << endl;
}

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	int total = 0; int count = 1;
	while(count < b) {
		count += a - 1;
		total++;
	}
	cout << total;
}










Measured memory_bytes: 256
D=int(input())
c=[int(x) for x in input().split()]
s=[[0]*i for i in range(D)]
for i in range(D):
  s[i]=[int(x) for x in input().split()]
for i in range(D):
  contest=max(s[i])
  print(s[i].index(contest)+1)

Measured memory_bytes: 9984
import java.util.Scanner;

public class Main {

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


		int r=scan.nextInt();
		int g=scan.nextInt();
		int b=scan.nextInt();

		int q=0;


		if(r>=1 && r<=9 && g>=1 && g<=9 && b>=1 && b<=9 ) {
			r=r*100;
			g=g*10;

			q=r+g+b;
			if(q%4==0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}



		}else{


		}




	}

}

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

using namespace std;

int main(){
    vector<int> n(3); cin >> n[0] >> n[1] >> n[2];

    sort(n.begin(), n.end());

    if(n[0] == 5 && n[1] == 5 && n[2] == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include<math.h>

#include<stdio.h>

#include<string.h>

#include<vector>

#include<algorithm>



typedef long long lli;

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

#define rep1(i, n) for(int i=1; i < (int)(n); i++)

#define all(x) (x).begin(),(x).end()

#define fill(x,y) memset(x,y,sizeof(x))

#define debug1(i) cout << i << '\n'

#define debug2(i,j) cout << i << j << '\n'



using namespace std;



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

	cout << ((a==b)?(2*a):(max(a,b)*2-1));

}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);
        int count=0;
        while (true)
        {
            if (c % a == 0)  count = count+1; 
            a++;
            if (a > b) break;
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 17944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file freopen("out.out","w",stdout);
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REV(a) reverse(a.begin(),a.end())
#define SORT(a) sort(a.begin(),a.end())
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n;
vi g[111111];
int dfs(int x,int pre){
		int ret=0;
		int cnt=0;
		FOR(i,0,g[x].size()){
				int to=g[x][i];
				if(to==pre)continue;
				int ans=dfs(to,x);
				ret+=ans;
				cnt+=(ans!=0);
		}
		return ret+max(0,(int)g[x].size()-cnt-2);
}
int main() {
		fastio
		cin>>n;
		FOR(i,1,n){
				int a,b;
				cin>>a>>b;
				g[a].push_back(b);
				g[b].push_back(a);
		}
		int mx=0;
		FOR(i,1,n)if(g[i].size()>g[mx].size())mx=i;
		cout<<dfs(mx,-1)+1<<endl;
		return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
  int N,M;
  int max;
  cin >> N >> M;
  priority_queue<int> buy;
  for (int i=0; i<N; i++){
        int a;
        cin >> a;
        buy.push(a);
  }
  for (int i=0; i < M; i++){
      max=buy.top(); buy.pop();
      buy.push(max/2);
  }
  ll sum=0;
  for (int i=0; i < N ;i++){
      sum+=buy.top(); buy.pop();
  }
  cout << sum << endl;
}

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

int main(){
	int N,K,y=0,x;
	cin >>N>>K;
	for(int i=0;i<N;i++ ){
		cin >> x;
		if(x<K-x)
			y+=x+x;
		else
			y+=K+K-x-x;
	}
	cout << y << endl;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var inputValues = Console.ReadLine().Split(' ');
        var a = int.Parse(inputValues[0]);
        var b = int.Parse(inputValues[1]);
        var t = int.Parse(inputValues[2]);

        int biscuitCreateTiming = (int)(t + 0.5) / a;
        int biscuitSum = biscuitCreateTiming * b;

        Console.WriteLine(biscuitSum);
    }
}



Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
 
int main(){
    int i;
    long long n;
    long long temp;
    vector <long long> list;
    
    cin >> n;
    for (i=0; i<5; i++) {
        cin >> temp;
        list.push_back(temp);
    }
    
    sort(list.begin(), list.end());
    
    if (n / list[0] < 1) {
        cout << 5;
    } else {
        if ( n % list[0] == 0) {
            cout << n / list[0] - 1 + 5;
        } else {
            cout << n / list[0] + 1 - 1 + 5;
        }
    }
    
	return 0; 
}

Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val Array(x1, y1, x2, y2) = readLine.split(" ").map{_.toInt}
  val dx = x2 - x1
  val dy = y2 - y1
  val x3 = x2 - dy
  val y3 = y2 + dx
  val x4 = x3 - dx
  val y4 = y3 - dy
  println(s"$x3 $y3 $x4 $y4")
}

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

int main(){
  int n,m;
  while(cin>>n>>m,n){
    vector<int> c(m);
    for(int i=0;i<m;i++) cin>>c[i];
    vector<int> x(n);
    for(int i=0;i<n;i++) cin>>x[i];

    const int INF=1e9;
    vector<vector<int>> dp(n+1,vector<int>(256,INF));
    dp[0][128]=0;

    auto isrange=[](int x){return 0<=x && x<256;};
    auto square=[](int x){return x*x;};
    
    for(int i=0;i<n;i++){
      for(int j=0;j<256;j++){
	//renew dp[i+1][j];
	for(int k=0;k<m;k++){
	  if(isrange(j-c[k])) dp[i+1][j]=min(dp[i+1][j],dp[i][j-c[k]]+square(x[i]-j));
	  if(j==255){
	    for(int r=0;r<c[k];r++) dp[i+1][j]=min(dp[i+1][j],dp[i][j-r]+square(x[i]-j));
	  }
	  if(j==0){
	    for(int r=0;r<-c[k];r++) dp[i+1][j]=min(dp[i+1][j],dp[i][r]+square(x[i]-j));
	  }
	}
      }
    }
    cout<<*min_element(dp[n].begin(),dp[n].end())<<endl;
  }

  return 0;
}

Measured memory_bytes: 23700
#include <iostream>

using namespace std;

int main() {
  int D;
  cin >> D;
  
  if (D == 22) {
    cout << "Christmas Eve Eve Eve" << endl;
  } else if (D == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else if (D == 24) {
    cout << "Christmas Eve" << endl;
  } else if (D == 25) {
    cout << "Christmas" << endl;
  }
  
  return 0;
}


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

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;

int a[maxn];

map<int,int>mapa;

int main()
{
  ios::sync_with_stdio(0);
  int n,m;

  cin >> n >> m;
  int l = 1, r = m + 1;
  while(l < r)
    cout << l++ << ' ' << r-- << endl;

  l = m + 2, r = 2*m + 1;
  while(l < r)
    cout << l++ << ' ' << r-- << endl;

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
const long long INF = LLONG_MAX/2;
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

using namespace std;
ll ans = 0;

ll n, r, a, b;
vector<ll> v, w;

int main()
{
	while (true){
		cin >> n >> r;
		if (!n&&!r) return 0;
		w.resize(n);
		v.resize(n);
		FOR(i, 1, n + 1) v[i - 1] = n - i + 1;
		REP(i, r)
		{
			cin >> a >> b;
			REP(j, b)
			{
				w[j] = v[j + a - 1];
			}
			REP(j, a - 1)
			{
				w[j + b] = v[j];
			}
			FOR(j, a + b - 1, n)
			{
				w[j] = v[j];
			}
			v.clear();
			copy(w.begin(), w.end(), back_inserter(v));
		}
		cout << v[0] << endl;
	}
}

Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    string s;
    cin >> s;
    Int count = 0;
    for (Int i = 0; i < s.length(); ++i) {
        if (s[i] == '+') {
            count++;
        } else {
            count--;
        }
    }
    cout << count << endl;
    return 0;
}



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

using namespace std;

int main(){
    int n,k,ct = 0;
    cin >> n >> k;

    vector<int>v(n,0);

    for(int i = 0;i < k;i++){
        int d;
        cin >> d;

        for(int j = 0;j < d;j++){
            int a;
            cin >> a;
            v[a-1]++;
        }
    }

    for(int i = 0;i < v.size();i++){
        if(v[i]==0)ct++;
    }

    cout << ct << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=1e9+7;
/*
普通に解くなら
dp[i][j]:i人目までにj個配る時の配り方
dp[i+1][j]=sum(dp[i][j]~dp[i][j-a[i]])
これをiごとにjに関して累積和を取ってから遷移させることでO(NK)で解くんだと思う
でも今回は形式的冪級数で解くよ

問題は Π(1+x+...+x^a[i]) の x^K の係数が知りたいと言い換えられる
(1+x+...+x^a[i]) = (1-x^(a[i]+1))/(1-x)　なので、分母はN乗にしたあとnCkの形に変換できて
Π(1-x^(a[i]+1)) と Σ(nCk(n+N-1,N-1)x^n) の積の形になる
Π側のK以下の各係数が分かればよくて、これはO(NK)のdpの形になる
*/
int dp[123456];
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
std::vector<int> Factorial(5e6),Finverse(5e6);
void Cinit(){// limit is 5e6 /// write Cinit&pw /// this takes 792ms at AtCoder
  Factorial[0]=1;
  for(int i=1;i<5e6;i++)Factorial[i]=Factorial[i-1]*i%MOD;
  for(int i=0;i<5e6;i++)Finverse[i]=pw(Factorial[i],MOD-2);
}
int nCk(int n,int k){
  if(n<k)return 1;if(k<0)return 0;
  int res=Factorial[n];
  res*=Finverse[k];res%=MOD;
  res*=Finverse[n-k];res%=MOD;
  return res;
}

signed main(){
  Cinit();
  int n,k;cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  dp[0]=1;
  for(int i=0;i<n;i++)
    for(int j=k-v[i]-1;j>=0;j--)
      dp[j+v[i]+1]+=MOD-dp[j],dp[j+v[i]+1]%=MOD;
  int ans=0;
  for(int j=0;j<=k;j++)ans+=nCk(j+n-1,n-1)*dp[k-j],ans%=MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 79232
#include <stdio.h>
#include <vector>
#include <string>

int main(){

    int n, x;
    while(true) {
        scanf("%d %d", &n, &x);
        // end
        if (n == 0 && x == 0) break;

        int count = 0;
        for (int i = 1; i <= n; ++i) {
            if (x <= i) break;
            for (int j = i + 1; j <= n; ++j) {
                if (x <= i + j) break;
                for (int k = j + 1; k <= n; ++k) {
                    // printf("i:%d j:%d k:%d\n", i, j, k);
                    if (x < i + j + k) break;
                    if (i + j + k == x) count++;
                }
            }
        }
        printf("%d\n", count);        
    }

}


Measured memory_bytes: 2724
#include<stdio.h>
int main(void){
  long long int x,sum=0,money=100;
  scanf("%lld",&x);
  while(1){
    money*=1.01;
	sum+=1;
    if(money>=x){
      break;
    }
  }
  printf("%lld\n",sum);
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

bool ok[15];
int n,k;

inline bool valid(int x)
{
    while(x)
    {
        if(ok[x%10]==0)
            return 0;
        x/=10;
    }
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    for(int i=0;i<=9;i++) ok[i]=1;
    for(int i=1;i<=k;i++)
    {
        int x;
        cin>>x;
        ok[x]=0;
    }
    for(int i=n;1;i++)
        if(valid(i))
            cout<<i<<"\n", exit(0);
    return 0;
}
/**

**/


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

#define _for(i,j,N) for(int i = (j);i < (N);i++)

using namespace std;
const int maxn = 300005;

string s;

int w[maxn];
int e[maxn];

int main()
{
    int N;
    scanf("%d",&N);
    cin >> s;
    int cnt = 0;
    _for(i,0,N){
        if(s[i] == 'W'){
            w[i] = cnt++;
        }
        else{
            w[i] = cnt;
        }
    }

    cnt = 0;
    for(int i = N-1; i  >= 0;i--){
        if(s[i] == 'E'){
            e[i] = cnt++;
        }
        else{
            e[i] = cnt;
        }
    }

    int res = maxn;
    _for(i,0,N){
        res = min(w[i] + e[i],res);
    }

    printf("%d\n",res);

    return 0;
}


Measured memory_bytes: 2948
using System;
using System.Linq;

namespace ABC100_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NM[0];
            var M = NM[1];
            var cake = new long[N][];
            var value = new long[8][];

            for (int i = 0; i < 8; i++)
                value[i] = new long[N];

            for (int i = 0; i < N; i++)
            {
                cake[i] = Console.ReadLine().Split().Select(long.Parse).ToArray();
                
                value[0][i] = cake[i][0] + cake[i][1] + cake[i][2];
                value[1][i] = cake[i][0] + cake[i][1] - cake[i][2];
                value[2][i] = cake[i][0] - cake[i][1] + cake[i][2];
                value[3][i] = cake[i][0] - cake[i][1] - cake[i][2];
                value[4][i] = -1 * cake[i][0] + cake[i][1] + cake[i][2];
                value[5][i] = -1 * cake[i][0] + cake[i][1] - cake[i][2];
                value[6][i] = -1 * cake[i][0] - cake[i][1] + cake[i][2];
                value[7][i] = -1 * cake[i][0] - cake[i][1] - cake[i][2];
            }

            long mv = -10000000000;
            foreach (var v in value)
            {
                Array.Sort(v);
                Array.Reverse(v);
                var sum = v.Take(M).Sum();
                if (sum > mv)
                    mv = sum;
            }
            Console.WriteLine(mv);
        }
    }
}


Measured memory_bytes: 13652
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    int D = sc.nextInt();
    String S = "";
    switch (D) {
      case 22: S = "Christmas Eve Eve Eve"; break;
      case 23: S = "Christmas Eve Eve"; break;
      case 24: S = "Christmas Eve"; break;
      case 25: S = "Christmas"; break;
    }

    System.out.println(S);

  }
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> p(n);
	rep(i,n) cin >> p.at(i);
	vector<int> a(n),b(n);
	int m=500000000/n;
	for(int i=1;i<=n;++i){
		a.at(i-1)=i*m;
		b.at(i-1)=(n-i+1)*m;
	}
	int k=1;
	rep(i,n){
		a.at(p.at(i)-1)+=k;
		b.at(p.at(i)-1)+=k;
		k++;
	}
	rep(i,n){
		if(i!=n-1) cout << a.at(i) << ' ';
		else cout << a.at(i) << endl;
	}
	rep(i,n){
		if(i!=n-1) cout << b.at(i) << ' ';
		else cout << b.at(i) << endl;
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

// AtCoder Beginner Contest 138
//オーバーフローに注意！！
//焦らずに！！
int main(){

    int n; cin >> n;
    long double ans = 0;
    rep(i, n){
        long double a; cin >> a;
        ans += 1. / a;
    }

    cout << setprecision(15) << 1. / ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define pq priority_queue
using namespace std;
pll item[105];
vector<ll> clas[5];
ll dp[2][105][105][105];
int main () {
	ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%lld %lld", &a, &b);
	for (i = 1; i <= a; i++) {
		scanf("%lld %lld", &c, &d);
		item[i] = {c, -d};
	}
	sort(item + 1, item + a + 1);
	e = item[1].fi;
	for (i = 0; i <= 3; i++) clas[i].pb(0);
	for (i = 1; i <= a; i++) clas[item[i].fi - e].pb(-item[i].se);
	SET(dp, 0); n = 0;
	f = 0;
	for (i = 0; i < clas[0].size(); i++) {
		if (f > b) break;
		g = 0;
		for (j = 0; j < clas[1].size(); j++) {
			if (f + g > b) break;
			h = 0;
			for (k = 0; k < clas[2].size(); k++) {
				if (f + g + h > b) break;
				m = 0;
				for (l = 0; l < clas[3].size(); l++) {
					if (f + g + h + m > b) break;
					if (i > 0) {
						dp[i & 1][j][k][l] = max(dp[i & 1][j][k][l], dp[!(i & 1)][j][k][l] + clas[0][i]);
					}
					if (j > 0) {
						dp[i & 1][j][k][l] = max(dp[i & 1][j][k][l], dp[i & 1][j - 1][k][l] + clas[1][j]);
					}
					if (k > 0) {
						dp[i & 1][j][k][l] = max(dp[i & 1][j][k][l], dp[i & 1][j][k - 1][l] + clas[2][k]);
					}
					if (l > 0) {
						dp[i & 1][j][k][l] = max(dp[i & 1][j][k][l], dp[i & 1][j][k][l - 1] + clas[3][l]);
					}
					n = max(n, dp[i & 1][j][k][l]);
					m += e + 3;
				}
				h += e + 2;
			}
			g += e + 1;
		}
		f += e;
	}
	printf("%lld\n", n);
	return 0;
}

Measured memory_bytes: 18304
using System;
 
namespace ITP1_6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var Length = int.Parse(Console.ReadLine());
            var inputs = Console.ReadLine().Split(' ');
            int[] numbers = new int[Length];
            for(int i=0 ; i<Length ; i++)
            {
                numbers[i] = int.Parse(inputs[i]);
            }
 
            for(int i=0 ; i<Length ; i++)
            {
                Console.Write("{0}",numbers[Length-i-1]);
                if(i!=Length-1) Console.Write(" ");
            }
            Console.WriteLine("");
        }
    }
}

Measured memory_bytes: 17888
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    vector<int> a(3);
    REP(i, 3) cin >> a[i];
    sort(All(a));
    if(a[0] == 5 && a[1] == 5 && a[2] == 7){
        cout << "YES" << endl ;
    }else{
        cout << "NO" << endl ;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>
int main(){
	int n;
	bool enable=false;
	scanf("%d", &n);
	for (int i = 1; i < 10; i++) {
		if((n%i==0)&&(n/i<10)){
			enable=true;
		}
	}
	if(enable){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
# coding: utf-8
# Your code here!

from math import sqrt
X=int(input())
sqrt_X=int(sqrt(X))
ans=1

for b in range(sqrt_X):
    for p in range(sqrt_X - 1):
        now_num = (b+1)**(p+2)
        if now_num <= X and ans <= now_num:
            ans =now_num
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

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

  // cout << a * b / 2 << endl;

  double s = (a + b + c) / 2.;
  double S = sqrt(s * (s - a) * (s - b) * (s - c));

  cout << (int)S << endl;

  return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
R = [0]*N
c = 0
for k in range(N):
    if S[k] == "R":
        c += 1
    else:
        R[k-1] = c
        c = 0

L = [0]*N
c = 0
for k in range(N-1,-1,-1):
    if S[k] == "L":
        c += 1
    else:
        L[k+1] = c
        c = 0

A = [0]*N
for k in range(N):
    if R[k] != 0:
        temp = R[k]+L[k+1]
        if temp%2 == 0:
            A[k] = temp//2
            A[k+1] = temp//2
        else:
            if R[k]%2 == 0:
                A[k] = temp//2
                A[k+1] = 1+temp//2
            else:
                A[k] = 1+temp//2
                A[k+1] = temp//2

print(*A)


Measured memory_bytes: 49468
#N = int(input())
N, M =  map(int,input().split())
#W =list(map(int,input().split()))
a = [(int(input())) for i in range(M)]

import sys
sys.setrecursionlimit(100000)

memo  =[-1]*(N+2)
memo[0] = 1
memo[1] = 1
def stair_count(n):
    for j in range(2,n+1):
        memo[j] = memo[j-1] + memo[j-2]

start = 0
answer = 1
dif = []
for i in a:
    if i == start:
        print(0)
        exit()
    else:
        n = i-1-start
        dif.append(n)
        start = i+1
dif.append(N-start)
stair_count(max(dif))
for i in dif:
        answer = (answer * memo[i])

print(answer%1000000007)


Measured memory_bytes: 471288
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e15;
const ll MOD=1000000007;

int main(){
    int a,b,c;cin>>a>>b>>c;
    if(a+b+c>=22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;



const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,t,res,di=1,a[5000],b[5000],dp[3200][3200][2]={};
long long int escape_dp[3200][3200][2]={};

string str;


int main() {
	cout << fixed << setprecision(10);
    cin>>n>>t;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=t-1;j>=0;j--){
            dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][0]+b[i]);
            if(j>=a[i]){dp[i][j-a[i]][0]=max(dp[i][j-a[i]][0],dp[i-1][j][0]+b[i]);}
            dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][0]);
            
            if(j>=a[i]){dp[i][j-a[i]][1]=max(dp[i][j-a[i]][1],dp[i-1][j][1]+b[i]);}
            dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][1]);
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=t-1;j>=0;j--){
            //cout<<dp[i][j][1]<<",";
        }
        //cout<<endl;
    }
    cout<<dp[n][0][1];
} 


Measured memory_bytes: 151808
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
const int N=505;
int n;
vector <int> vp;
LL g[N][N];
LL gcd(LL x,LL y){
	return y?gcd(y,x%y):x;
}
LL lcm(LL x,LL y){
	if (!x||!y)
		return x+y;
	return x/gcd(x,y)*y;
}
int check(int n){
	for (int i=2;i*i<=n;i++)
		if (n%i==0)
			return 0;
	return 1;
}
map <int,int> mp1,mp2;
int g1(int x){
	if (!mp1[x])
		mp1[x]=vp.back(),vp.pop_back();
	return mp1[x];
}
int g2(int x){
	if (!mp2[x])
		mp2[x]=vp.back(),vp.pop_back();
	return mp2[x];
}
int main(){
	n=read();
	if (n==2){
		puts("4 7");
		puts("23 10");
		return 0;
	}
	for (int i=2;vp.size()<n*2;i++)
		if (check(i))
			vp.push_back(i);
	reverse(vp.begin(),vp.end());
	mp1.clear(),mp2.clear();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if ((i+j)%2==0)
				g[i][j]=g1(i+j);
	for (int i=n;i>=1;i--)
		for (int j=n;j>=1;j--)
			if ((i+j)%2==0)
				g[i][j]*=g2(i-j);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if ((i+j)%2==1){
				g[i][j]=lcm(g[i-1][j],lcm(g[i+1][j],lcm(g[i][j-1],g[i][j+1])))+1;
				assert(g[i][j]<=1000000000000000LL);
			}
	for (int i=1;i<=n;i++,puts(""))
		for (int j=1;j<=n;j++)
			printf("%lld ",g[i][j]);
	return 0;
}

Measured memory_bytes: 5120
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
    if a[i] % 2 == 1:
        continue
    if a[i] % 3 != 0 and a[i] % 5 != 0 :
        print('DENIED')
        exit()
print('APPROVED')


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);

int main(){
  string s;
  cin >> s;
  int p=0;
  int q=s.size()/2-1;
  for(int i = s.size()/2-1; i >0; i--){
    if(s.substr(p, i) == s.substr(q, i)){
      cout << i*2 << endl;
      exit(0);
    }
    q--;
  }

}

Measured memory_bytes: 256
N = int(input())
v_list = sorted(list(map(int, input().split())))
v_len = len(v_list)

sum = v_list[0] / (2 ** (N - 1))
for i in range(v_len - 1):
  sum += v_list[i+1] / (2 ** (N - 1 - i))
  
print(sum)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        sc.close();


        System.out.printf("%.10f", 1.0 / RegistersInParallel(N, 0, A));
    }
    public static double RegistersInParallel(int N, int index, int[] A) {
        if (N <= index) {
            return 0.0;
        }
        return (1.0 / A[index]) + RegistersInParallel(N, index + 1, A);
    }
}


Measured memory_bytes: 21716
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			double [] ax = new double[2];
			double [] ay = new double[2];
			double [] bx = new double[2];
			double [] by = new double[2];
			for(int i=0; i < 2; i++){
				ax[i] = sc.nextDouble();
				ay[i] = sc.nextDouble();
			}
			for(int i=0; i < 2; i++){
				bx[i] = sc.nextDouble();
				by[i] = sc.nextDouble();
			}
			boolean flg = true;

			if(bx[1] < ax[0] || ax[1] < bx[0])
				flg = false;
			if(ay[1] < by[0] || by[1] < ay[0])
				flg = false;

			if(flg)
				System.out.println("YES");
			else
				System.out.println("NO");
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 0
WHITE = '.'
BLACK = '#'

N = gets.chomp.to_i
S = gets.chomp

whites = S.count(WHITE)


# 全部白パターンの要変更数
cumulative = [whites]

N.times do |i|
  cumulative[i + 1] =
    if S[i] == BLACK
      cumulative[i] + 1
    else
      cumulative[i] - 1
    end
end

puts cumulative.min


Measured memory_bytes: 3916
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

s=list(ss())
chk=True
if s!=list(reversed(s)):
    chk=False

if s[0:(len(s)-1)//2] != list(reversed(s[0:(len(s)-1)//2])):
    chk=False
if s[(len(s)+3)//2 -1:1+(len(s)-1)] != list(reversed(s[(len(s)+3)//2-1:1+(len(s)-1)])):
    chk=False
    
if chk==False:
    print("No")
else:
    print("Yes")



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

int main() {
  int n;
  cin >> n;
  vector<int> P(n);
  rep (i, n)  cin >> P[i];// P[i]=p(i+1)
  int sum = 0;
  
  for (int i = 1; i < n-1; i++) {
    if (P[i-1] > P[i] && P[i] > P[i+1]) sum++;
    else if (P[i+1] > P[i] && P[i] > P[i-1]) sum++;
  }
      

  cout << sum << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*/
#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
    vector <string> v;
    stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x);
    return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
    cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
    err(++it, args...);
}

int ini() {int x; scanf("%d", &x); return x;}
long long inl() { long long x; scanf("%lld", &x); return x;}
double ind() {double x; scanf("%lf", &x); return x;}
#define Iin ini();
#define Lin inl();
#define Din ind();

int set_1(int n, int pos) {return n = (n | (1 << pos));}
int reset_0(int n, int pos) {return n = n & ~(1 << pos);}
bool check_bit(int n, int pos) {return n = n & (1 << pos);}

int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;

int a[N];



int reverse(int x) {
    int r = 0;
    while (x > 0) {
        r = r * 10 + x % 10;
        x /= 10;
    }
//   printf("%d\n", r);
    return r;
}

std::map<pii, int> m;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1, te = 0;

    // cin>>t;
    while (t--) {
        int n;
        cin >> n;

        ll res = 0ll;
        int f, l;
        for (int i = 1; i <= n; ++i) {
            int r = reverse(i);
            f = i % 10;
            l = r % 10;
            m[{f,l}]++;
            //  printf("%d %lld\n", i,res);
        }

        for (int i = 1; i <= n; ++i) {
            int r = reverse(i);
            f = i % 10;
            l = r % 10;
            res+=m[{l,f}];
            //  printf("%d %lld\n", i,res);
        }

        printf("%lld\n", res);

        //printf("Case %d: ",++te);
    }
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repv(i, v) for (int (i)(0); (i)<(v.size()); ++(i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define all(v) (v).begin(), (v).end()

using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

int main(){
	int N;
	cin >> N;
	int sum = 0;
	rep(i, 0, N) {
		int j;
		cin >> j;
		while (j % 2 == 0) {
			j /= 2;
			++sum;
		}
	}
	cout << sum << endl;
}


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int l = 1, c = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1]) {
      c += l / 2;
      l = 0;
    }
    ++l;
  }
  cout << c << endl;
  return 0;
}



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

int main() {
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<string> S(n);
    rep(i, n) cin >> S[i];
    map<char, int> mp;
    mp['A'] = a;
    mp['B'] = b;
    mp['C'] = c;
    vector<char> ans(n);
    rep(i, n) {
        int l = mp[S[i][0]], r = mp[S[i][1]];
        if (l==0 && r==0) {
            cout << "No" << endl;
            return 0;
        }
        if (l==0) {
            ans[i] = S[i][0];
            ++mp[S[i][0]]; --mp[S[i][1]];
        } else if (r==0) {
            ans[i] = S[i][1];
            --mp[S[i][0]]; ++mp[S[i][1]];
        } else if (i < n-1) {
            if (S[i][0]==S[i+1][0] || S[i][0]==S[i+1][1]) {
                ans[i] = S[i][0];
                ++mp[S[i][0]]; --mp[S[i][1]];
            } else {
                ans[i] = S[i][1];
                --mp[S[i][0]]; ++mp[S[i][1]];
            }
        } else {
            ans[i] = S[i][0];
            ++mp[S[i][0]]; --mp[S[i][1]];
        }
    }
    cout << "Yes" << endl;
    rep(i, n) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class T>
inline void out(T a) {
	cout<<a<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N,K,Q;
intvec AC;

void input() {
	cin>>N>>K>>Q;
	AC.resize(N,0);
}

void solve() {
	for(int i=0; i<Q; i++) {
		int A; cin>>A; A--;
		AC[A]++;
	}

	for(int i=0; i<N; i++) {
		if(Q-AC[i] < K) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3716
import sys
fin = sys.stdin.readline
from heapq import heappop, heappush
from operator import itemgetter

# assuming that the vertices are 0, 1, ..., N - 1
# if V^2 >> E, use a hashmap representation of w
# time complexity: O(ElgE)
# space complexity: O(E)
def prim(adj, w):
    num_vertices = len(adj)
    # initialize
    min_cost = [float('inf')] * num_vertices
    min_cost[0] = 0
    used = [False] * num_vertices
    priority_queue = [(0, 0)]
    total_cost = 0

    while priority_queue:
        cost, vertex = heappop(priority_queue)
        if cost > min_cost[vertex] or used[vertex]:
            continue
        used[vertex] = True
        total_cost += cost

        for neighbor in adj[vertex]:
            cost_v_to_n = w[(vertex, neighbor)]
            if min_cost[neighbor] > cost_v_to_n:
                min_cost[neighbor] = cost_v_to_n
                heappush(priority_queue, (cost_v_to_n, neighbor))

    return total_cost


N = int(fin())
coords = [[int(elem) for elem in fin().split()] + [i] for i in range(N)]

adj = [set() for _ in range(N)]
w = {}

# sort coords in increasing order of x
# coords.sort(key=lambda x: x[0])
coords.sort(key=itemgetter(0))
for i, (x, _, vertex) in enumerate(coords[:-1]):
    next_x, _, next_vertex = coords[i + 1]
    adj[vertex].add(next_vertex)
    adj[next_vertex].add(vertex)
    weight = next_x - x
    if (vertex, next_vertex) not in w or w[(vertex, next_vertex)] > weight:
        w[(vertex, next_vertex)] = weight
    if (next_vertex, vertex) not in w or w[(next_vertex, vertex)] > weight:
        w[(next_vertex, vertex)] = weight

# sort coods in increasing order of y
# coords.sort(key=lambda x: x[1])
coords.sort(key=itemgetter(1))
for i, (_, y, vertex) in enumerate(coords[:-1]):
    _, next_y, next_vertex = coords[i + 1]
    adj[vertex].add(next_vertex)
    adj[next_vertex].add(vertex)
    weight = next_y - y
    if (vertex, next_vertex) not in w or w[(vertex, next_vertex)] > weight:
        w[(vertex, next_vertex)] = weight
    if (next_vertex, vertex) not in w or w[(next_vertex, vertex)] > weight:
        w[(next_vertex, vertex)] = weight

print(prim(adj, w))


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

typedef long long ll;
typedef pair<int, int> ii;

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

    const char *str[] = {"AC", "WA", "TLE", "RE"};
    int cnt[4] = {0};
    for (int i = 0; i < n; i++) {
        char inp[100];
        scanf("%s", inp);

        for (int j = 0; j < 4; j++) {
            if (strcmp(inp, str[j]) == 0) {
                cnt[j]++;
                break;
            }
        }
    }

    for (int i = 0; i < 4; i++) {
        printf("%s x %d\n", str[i], cnt[i]);
    }

    return 0;
}


Measured memory_bytes: 3824