akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin >> n >> k;
  bool possess[n];
  memset(possess, false, sizeof(possess));
  int d;
  for(int i=0; i<k; i++){
    cin >> d;
    int a;
    for(int j=0; j<d; j++){
      cin >> a;
      possess[a-1] = true;
    }
  }

  int ans=0;
  for(int i=0; i<n; i++) if(!possess[i]) ans++;
  cout << ans << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

int main(void) {
    string S;
	cin >> S;

    vector<ll> members; // 項の集合

    for(int bit = 0; bit < (1 << S.length()-1); bit++) {
        int current_index = 0;

        for(int i = 0; i < S.length() - 1; i++) {
            if(bit & (1 << i)) {
                int previous_index = current_index;
                current_index = i + 1;

                members.push_back(stoll(S.substr(previous_index, current_index - previous_index)));
            }
        }

        members.push_back(stoll(S.substr(current_index, S.length() - current_index)));
    }

    cout << accumulate(members.begin(), members.end(), 0LL) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll N,A,B;
	cin>>N>>A>>B;
	if((N==1&&A!=B)||(A>B)){
		cout<<"0"<<endl;
	}
	else{
		cout<<B*(N-2)-A*(N-2)+1<<endl;
	}
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int a[222222], b[222222];
int main() {
	int n, m;
	cin >> n;
	rep(i, n)cin >> a[i];
	cin >> m;
	rep(i, m)cin >> b[i];
	rep(i, m) {
		if (!binary_search(a, a + n, b[i])) {
			puts("0");
			return 0;
		}
	}
	puts("1");
	return 0;
}


Measured memory_bytes: 4580
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)

import operator

N,H,W = map(int,readline().split())
m = map(int,read().split())
RCA = sorted(zip(m,m,m),key=operator.itemgetter(2),reverse=True)

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(x):
    y = root[x]
    if x == y:
        return x
    path = [x]
    while y != root[y]:
        path.append(y)
        y = root[y]
    for p in path:
        root[p] = y
    return y

def merge(x,y):
    x,y = find_root(x),find_root(y)
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy
    no_cycle[x] = no_cycle[x] and no_cycle[y]

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(x),find_root(y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(rx,ry)
    answer += A

print(answer)


Measured memory_bytes: 35576
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
sum = 0
bonus = 10**9
for i in range(N):
    sum += B[A[i]-1]
    if A[i] == bonus:
        sum += C[A[i]-2]
    bonus = A[i]+1
print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  ll A, B;
  cin >> A >> B;
  ll sub = B - A + 1;
  ll ans = 0LL;
  ll pwr = 1LL;
  for(int i=0; i<=50; i++) {
    ll tmp = 0LL;
    ll a, b;
    sub /= 2;

    tmp += sub * pwr;

    a = A % (2 * pwr);
    b = (B + 1) % (2 * pwr);
    if(a < b) {
      tmp += max(b, pwr) - max(a, pwr);
    } else if(a > b){
      tmp += (max(b, pwr) - pwr) + ((2 * pwr) - max(a, pwr));
    }
    // cout << i << ' ' << tmp << endl;
    ans += pwr * (tmp % 2);

    pwr *= 2;
  }

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

Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = string_to_int(inputs[0])
    rate = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199]
    rate_num = len(rate)

    counter_overs = 0
    rate_set = set()
    for a in A:
        if a >= 3200:
            counter_overs += 1
        else:
            hit = None
            for i, r in enumerate(reversed(rate)):
                if a <= r:
                    hit = i
            rate_set.add(hit)
    if len(rate_set) == 0:
        # max_num = counter_overs if counter_overs <= rate_num else rate_num
        max_num = counter_overs
        min_num = 1
    else:
        sum_all = len(rate_set) + counter_overs
        # max_num = sum_all if sum_all <= rate_num else rate_num
        max_num = sum_all
        min_num = len(rate_set)
    return "{} {}".format(min_num, max_num)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3804
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

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

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);
	swap(a, b);
	swap(a, c);
	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 256
import 'dart:io';
 
void main(List<String> args) {
  List<int> x = stdin.readLineSync().split(" ").map((i) => int.parse(i)).toList();
  int ans = 0;
  for(int i=1; i<=x[0]; ++i){
    int sum = i%10 + (i~/10)%10 + (i~/100)%10 + (i~/1000)%10 + (i~/10000)%10;
    if(x[1]<=sum && sum<=x[2]) ans += i;
  }
  print(ans);
}

Measured memory_bytes: 13064
def main():
    from builtins import int, map, list, print
    from collections import defaultdict
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    d = defaultdict(lambda: 0)
    N = input_number()
    for i in range(N):
        s = input()
        d[s] += 1
    print(f"AC x {d['AC']}")
    print(f"WA x {d['WA']}")
    print(f"TLE x {d['TLE']}")
    print(f"RE x {d['RE']}")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9484
s = input()
chrlis = []
for i in range(len(s)):
  if s[i]=="A" or s[i]=="C" or s[i]=="G" or s[i]=="T":
    start = i
    for j in range(i,len(s)):
      if s[j]=="A" or s[j]=="C" or s[j]=="G" or s[j]=="T":
        end = j
      else:
        break
  else:
    continue
  chrlis.append(s[start:end+1])

ans = 0
for i in range(len(chrlis)):
  tmp = len(chrlis[i])
  if tmp>ans:
    ans = tmp
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
using ll = long long;

int main(){
        ll l,r,w,i,j,ans=2019;
        cin >> l >> r;
        w = r - l;
        if(w>2018) ans = 0;
        else for(i=0;i<w+1;++i) for(j=i+1;j<w+1;++j) ans = min(ans, ((l+i)*(l+j))%2019);
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3612
#include<iostream>

#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define MAX 100001
typedef long long ll;

int main(){
	int n;
	cin >> n;
	//メモリを動的に確保する(かpush_backとかね)
	//int a[MAX]={},b[MAX]={},c[MAX]={};
	int *a = new int[MAX];
	int *b = new int[MAX];
	int *c = new int[MAX];
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	rep(i,n) cin >> c[i];
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);

	ll cnt = 0;
	rep(i,n){
		ll up = upper_bound(a,a+n,b[i]-1) - a;
		ll low = c+n-lower_bound(c,c+n,b[i]+1);
		cnt += up * low;
	}
	cout << cnt << endl;
	return 0;
}
	


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

#define rep(i, n) for(long int i = 0 ; i < n ; i ++)
#define loop(i, n, m) for(long int i = n ; i < m ; i ++)
#define vi vector<int>

int main(void){
  char c[3][3];
  rep(i,3)rep(j,3)cin>>c[i][j];
  rep(i,3)cout<<c[i][i];
  cout<<endl;
}


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

using namespace std;

int main(){
    string a;
	
	cin >> a;
    int ans;
    if(a == "RRR") ans = 3;
    if(a == "RRS") ans = 2;
    if(a == "RSR") ans = 1;
    if(a == "SRR") ans = 2;
    if(a == "RSS") ans = 1;
    if(a == "SRS") ans = 1;
    if(a == "SSR") ans = 1;
    if(a == "SSS") ans = 0;

    cout << ans;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <iostream>
#include <cstring>
 
using namespace std;
 
int num[108];
 
void decode(int l, int k[200], char s[108], char alph[56])
{   
    for(int i = 0; i < l; i++){
        if(s[i] >= 'a' && s[i] <= 'z'){
            num[i] = s[i] - 'a';
        }
        else{
            num[i] = s[i] - 'A' + 26;
        }
        if(num[i] - k[i] < 0){
            num[i] += 52 - k[i];
        }
        else{
            num[i] -= k[i];
        }
        cout << alph[num[i]];
    }
    puts("");
}
 
 
int main()
{
    int n, m, l;
    int k[200];
    char s[108];
    char alph[56];
     
    for(int i = 0; i < 26; i++){
        alph[i] = 'a' + i;
    }
    for(int i = 0; i < 26; i++){
        alph[i + 26] = 'A' + i;
    }
 
     
    while(scanf("%d", &n) != EOF){
        if(n == 0) break;
        for(int i = 0; i < n; i++){
            cin >> k[i];
        }
        cin >> s;
         
        m = n;
        l = strlen(s);
        while(l > m){
            for(int i = 1; i <= n; i++){
                k[m + i - 1] = k[i - 1];
            }
            m += n;
        }
        decode(l, k, s, alph);
    }
    return 0;
}   

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

using namespace std;

void solve(void)
{
	int n, m = 5000*5000;
	cin >> n;
	vector<int> xs(3), ys(3);
	for (int&x : xs) cin >> x;
	for (int&y : ys) cin >> y;
	vector<long> dp(n+1), dp2(m+1);
	for (int i = 1; i <= n; i++)
	{
		dp[i] = i;
		for (int j = 0; j < 3; j++)
		{
			if (i - xs[j] >= 0)
			{
				dp[i] = max(dp[i], dp[i-xs[j]] + ys[j]);
			}
		}
	}
	for (int i = 1; i <= m; i++)
	{
		dp2[i] = i;
		for (int j = 0; j < 3; j++)
		{
			if (i - ys[j] >= 0)
			{
				dp2[i] = max(dp2[i], dp2[i-ys[j]] + xs[j]);
			}
		}
	}
	cout << dp2[dp.back()] << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  int x=1;
  for(int i=0; i<n; i++){
    if(x>n){
      break;
    }

    x*=2;
   
  }

  cout << x/2;
}

    
  
  
  
      

  

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
A - F
https://beta.atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_a

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    a, b = map(int, input().split())
    if a + b == 15:
        print('+')
    elif a * b == 15:
        print('*')
    else:
        print('x')


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
N = gets.to_i
a = gets.split.map(&:to_i)
even = a.select(&:even?)
four = even.select {|i| i % 4 == 0 }
x = four.size
y = even.size - x
z = a.size - x - y
if x * 2 + 1 >= N || x * 2 + y >= N
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 10116
S=input()
s=list(S)
left=int(s[0])*10+int(s[1])
right=int(s[2])*10+int(s[3])
if 1<=left<=12:
    if 1<=right<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1<=right<=12:
        print("YYMM")
    else:
        print("NA")

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

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

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


struct player
{
    string name;
    int time;
    int total;
    vector<int> points;
};

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, l, a, t;
    cin >> n >> l;
    int num[n];
    deque<PII> deq;

    rep(i, n)
    {
        cin >> a;
        t = l + i;
        while (!deq.empty())
        {
            if (deq.front().second <= i)
                deq.pop_front();
            else
                break;
        }
        while (!deq.empty())
        {
            if (deq.back().first >= a)
                deq.pop_back();
            else
                break;
        }
        deq.push_back(make_pair(a, t));

        if (i >= l - 1)
        {
            cout << deq.front().first;
            if (i != n - 1)
                cout << " ";
            else
                cout << endl;
        }
        // for (auto z : deq)
        //     cout << z.first << " ";
        // cout << endl;
    }
    
    return 0;
}


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


int main()
{
  string s;
  int a=0,b=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A')a=1;
    if(s[i]=='B')b=1;
  }
  if(a==1&&b==1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

int main()
{
  int x, n;
  cin >> x >> n;
  int ans = 0;
  set<int> data;

  if(n == 0)
  {
    int tmp;
    cout << fixed << x << endl;
    return 0;
  }

  repl(i, n)
  {
    int tmp;
    cin >> tmp;
    data.insert(tmp);
  }

  int v = x;
  rep(i, 100){
      v = x - i;
      if(data.find(v) == data.end())
      {
        cout << fixed << v << endl;
        break;
      }

      v = x + i;
      if(data.find(v) == data.end())
      {
        cout << fixed << v << endl;
        break;
      }
  }

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	int x, n;
	cin >> x >> n;
	vector<bool> have(102, false);
	rep(i, n) {
		int p; cin >> p;
		have[p] = true;
	}
	P ans(9999, -1);
	rep(i, 102) {
		if (have[i]) continue;
		int dist = abs(x-i);
		ans = min(ans, P(dist, i));
	}
	cout << ans.second << endl; 
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    if (a%2==1){
      System.out.println(((a/2)+1)*(a/2));
    } else {
      System.out.println((a/2)*(a/2));
    }
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n,m,d;

int main(){
	cin>>n>>m>>d;
	if(d==0){
		printf("%.10f\n",(double)(m-1)/n);
	}else{
		printf("%.10f\n",(double)(2*(n-d)*(m-1))/(n*n));
	}
	return 0;
}

Measured memory_bytes: 256
import sys

x = int(sys.stdin.readline())

if 400 <= x and x <= 599:
    print(8)
elif 600 <= x and x <= 799:
    print(7)
elif 800 <= x and x <= 999:
    print(6)
elif 1000 <= x and x <=1199:
    print(5)
elif 1200  <= x and x <=1399:
    print(4)
elif 1400  <= x and x <=1599:
    print(3)
elif 1600  <= x and x <=1799:
    print(2)
elif 1800  <= x and x <=1999:
    print(1)


Measured memory_bytes: 9184
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(){
    char s[105], t[105];
    int bla=0;
    scanf("%s %s", s, t);
    for(int i=0;s[i] != '\0' ;++i){
    	if (s[i]!=t[i]){
			bla=1;
    		break;
    	}	
    }
    if(bla==0)
    	printf("Yes");
    else
    	printf("No");
    printf("\n");

    	

   
    return 0;
	
}


Measured memory_bytes: 1728
N,Y = map(int, input().split())

y = Y//1000
d = y - N
k = min(d//4, (N+d)//5)

if 9*k >= 2*d:
    print(d-4*k, -2*d+9*k, N+d-5*k)
else: print(-1,-1,-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MAXN = 55;
ll binom[MAXN][MAXN];
int main() {
	for (int i = 0; i < MAXN; ++i)
		for (int j = 0; j <= i; ++j)
			if (!j || j == i) binom[i][j] = 1;
			else binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j];
	int n, k, S, T;
	scanf("%d%d%d%d", &n, &k, &S, &T);
	vector<int> A(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	if ((T & S) != S) {
		printf("0\n");
		return 0;
	}
	vector<int> bits;
	for (int j = 0; j < 18; ++j) {
		if ((T & (1 << j)) && !(S & (1 << j))) bits.push_back(j);
	}
	int s = bits.size();
	vector<int> B;
	for (int i = 0; i < n; ++i) {
		if (~T & A[i]) continue;
		if ((S & A[i]) != S) continue;
		int b = 0;
		for (int j = 0; j < s; ++j) {
			if (A[i] & (1 << bits[j])) b |= 1 << j;
		}
		B.push_back(b);
	}
	int req = (1 << s);
	int m = B.size();
	ll ans = 0;
	for (int i = 0; i < m; ++i) {
		vector<int> V;
		for (int j = i + 1; j < m; ++j) {
			int d = B[j] ^ B[i];
			V.push_back(d);
		}
		// 0..K-1 things ORing to req-1.
		for (int b = 0; b < req; ++b) {
			int cnt = 0;
			for (int x : V) {
				if (x & b) continue;
				++cnt;
			}
			ll t = 0;
			for (int i = 0; i < k; ++i) t += binom[cnt][i];
			if (__builtin_popcount(b) & 1) ans -= t;
			else ans += t;
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3784
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
//	cut here before submit 
//	freopen ("testcase.SA", "r", stdin );
	ll sumv = 0LL, sump = 0LL;
	string str = "";
	int cnt = 0;
	while (getline (cin, str ) ){
		if (str.empty() ) break;
		while (str.find(',') != string::npos ) str = str.replace(str.find(','), 1, " ");
		int volume, prices;
		stringstream ss (str );
		ss >> prices >> volume;
		sumv += (ll)volume; sump += (ll)volume*prices;
		cnt++;
	} // end loop

	printf ("%lld\n", sump );
	printf ("%d\n", (int)((double)sumv/cnt+0.5) );
	
	return 0;
}

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

using namespace std;

int n, q;
vector<vector<int> > v(311111);
long long point[311111];
bool ischecked[311111];

void dfs(int n, int p) {
  if (ischecked[n]) return;
  ischecked[n] = true;
  point[n] += p;
  for (int j = 0; j < v[n].size(); j++) {
    // cout << n << " " << v[n][j] << " " << point[n] << endl;
    dfs(v[n][j], point[n]);
  }
}

int main() {
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x;
    p--;
    point[p] += x;
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < v[i].size(); j++) {
  //     cout << i << " " << v[i][j] << endl;
  //     if (v[i][j] < i) continue;
  //     point[v[i][j]] += point[i];
  //   }
  // }
  dfs(0, 0);
  for (int i = 0; i < n; i++) {
    cout << point[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 23936
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] xCity = new int[N+1];
		int[] yCity = new int[M+1];
		xCity[0] = sc.nextInt();
		yCity[0] = sc.nextInt();
		for(int i=1; i<=N; i++) {
			xCity[i] = sc.nextInt();
		}
		for(int i=1; i<=M; i++) {
			yCity[i] = sc.nextInt();
		}
		Arrays.sort(xCity);
		Arrays.sort(yCity);
		if(xCity[N] < yCity[0]) {
			System.out.println("No War");
		} else {
			System.out.println("War");
		}
			
		
	}

}


Measured memory_bytes: 36260
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define hell 1000000007
#define PI 3.14159265358979323846
using namespace std;

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

   // cin>>t;
    while(t--)
    {
       ll k,x;
       cin>>k>>x;
       if(500*k>=x)
        cout<<"Yes";
       else
        cout<<"No";

    }
}


Measured memory_bytes: 3576
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
# pragma  comment(linker,"/STACK:102400000,102400000")
using namespace std;
# define LL          long long
# define pr          pair
# define mkp         make_pair
# define lowbit(x)   ((x)&(-x))
# define PI          acos(-1.0)
# define INF         0x3f3f3f3f3f3f3f3f
# define eps         1e-8
# define MOD         1000000007

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
# define MX 10005
/**************************/

int main()
{
    int n= scan();
    int all=0;
    while(n--)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        all+=b-a+1;
    }
    printf("%d\n",all);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

bool cmp(const P &a, const P &b){
    if (a.second == b.second){
        return a.first < b.first;
    } else {
        return a.second < b.second;
    }
}

int main()
{
    int n;
    cin >> n;
    vector<P> work(n);
    rep(i, n){ cin >> work[i].first >> work[i].second;}

    sort(work.begin(), work.end(), cmp);

    // rep(i, n){
    //     cout << work[i].first << work[i].second << endl;
    // }

    int now = 0;
    rep(i, n){
        now += work[i].first;
        if (now > work[i].second){
            cout << "No" << endl; return 0;
        }
    }
    cout << "Yes" << endl; return 0;
}



Measured memory_bytes: 1792
H, W = map(int, input().split())

L, side, ver = [], [], []

for i in range(H):
    a = list(input())
    L.append(a)

def check(n, inlist, outlist):
    """[summary]
    全て白マスの行を削除する
    転置行列を返すので列の判定にも対応可能
    Args:
        n ([type]): 配列サイズ
        inlist ([type]): 入力する二次元配列
        outlist ([type]): 出力する二次元配列

    Returns:
        [list]: 不要な要素を削除して転置して返す
    """    
    for i in range(n):
        if ('#' in inlist[i]) == True:
            outlist.append(inlist[i])
    return list(map(list, zip(*outlist)))

side = check(H, L, side)
ver = check(len(side), side, ver)

for i in range(len(ver)):
    print(''.join(ver[i]))

Measured memory_bytes: 9156
open Printf
open Scanf

let id x = x
             
module Dice =
  struct
    type t = {tp:int; ft:int; lt:int; rt:int; bk:int; bm:int}

    let create x1 x2 x3 x4 x5 x6 =
      {tp = x1; ft = x2; lt = x3; rt = x4; bk = x5; bm = x6}

    let roll d = function
        'S' -> {d with tp = d.bk; ft = d.tp; bm = d.ft; bk = d.bm}
      | 'E' -> {d with tp = d.rt; lt = d.tp; bm = d.lt; rt = d.bm}
      | 'W' -> {d with tp = d.lt; rt = d.tp; bm = d.rt; lt = d.bm}
      | 'N' -> {d with tp = d.ft; bk = d.tp; bm = d.bk; ft = d.bm}
      | _ -> failwith "roll"

    let rollx d dirs =
      let rd = ref d in
      String.iter (fun c -> rd := roll !rd c) dirs;
      !rd

    let equal d1 d2 =
      let ht = Hashtbl.create 100 in
      let rec dfs d =
        if Hashtbl.mem ht d then false
        else
          if d1 = d then true
          else begin
              Hashtbl.add ht d true;
              List.fold_left (fun b c ->
                              if b then b
                              else dfs (roll d c)
                             ) false ['N';'E';'W';'S']
            end
      in dfs d2
          
    let top d = d.tp
    let front d = d.ft
    let left d = d.lt
  end

let () =
  let d1 = scanf "%d %d %d %d %d %d " Dice.create in
  let d2 = scanf "%d %d %d %d %d %d " Dice.create in
  printf "%s\n" (if Dice.equal d1 d2 then "Yes" else "No")

Measured memory_bytes: 2320
#include <cassert>
#include <algorithm>
#include <cctype>
#include <complex>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <typeinfo>
#include <unordered_set>
#include <unordered_map>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REPD(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define PB(e) push_back(e)
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;

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) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}

void dfs(const vector<vector<int>> &RG, int v, vector<int> &visit, vector<int> &vs) {
  visit[v] = true;
  for (int w: RG[v]) {
    if (!visit[w]) {
      dfs(RG, w, visit, vs);
    }
  }
  vs.push_back(v);
}

int main(int argc, char *argv[])
{
  int N, M;
  cin >> N >> M;
  vector<int> A(N + M - 1), B(N + M - 1);
  vector<vector<int>> RG(N + M);

  vector<int> visit(N + M);
  REP(i, N + M - 1) {
    cin >> A[i] >> B[i];
    RG[B[i]].push_back(A[i]);
  }
  vector<int> vs;
  REP2(v, 1, N + 1) {
    if (!visit[v]) {
      dfs(RG, v, visit, vs);
    }
  }

  vector<int> res(N);
  vector<int> d(N + 1, -1);
  REP2(i, 1, N + 1) {
    int v = vs[i - 1];
    // cout << i - 1 << " " << v << " :"<< endl;
    for (int w: RG[v]) {
      // cout << v << " " << w << endl;
      assert(d[w] >= 0);
      d[v] = max(d[w] + 1, d[v]);
    }
    if (RG[v].size() == 0) {
      res[v - 1] = 0;
      d[v] = 0;
      continue;
    }

    for (int w: RG[v]) {
      if (d[w] == d[v] - 1) {
        res[v - 1] = w;
      }
    }
  }
  REP(i, N) {
    cout << res[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 12788
#include <iostream>

using namespace std;

int dis[10];

bool f(int s){
  while( s != 0 && dis[s%10]==0 )
    s/=10;

  return s==0;
}

int main(){
  int n, k;
  dis[10]={0};
  cin >> n >> k;
  while(k-->0){
    int a;
    cin>>a;
    dis[a]=1;
  }
  int sol = n;
  while(!f(sol)){
    //cout << sol << endl;
    sol++;
  }

  cout << sol << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	string s, t, ans;
	ll n, m, i, j;
	cin >> s >> t;
	n = s.size(), m = t.size();
	vector <vll> dp(n + 1);
	dp[0].resize(m + 1, 0);
	for(i = 1; i <= n; i++)
	{
		dp[i].resize(m + 1, 0);
		for(j = 1; j <= m; j++)
		{
			if(s[i - 1] == t[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			dp[i][j] = max({dp[i - 1][j], dp[i][j - 1], dp[i][j]});
		}
	}
	ll l = dp[n][m];
	for(i = n; i >= 1; i--)
	{
		for(j = m; j >= 1; j--)
			if(dp[i][j] == l && s[i - 1] == t[j - 1] && dp[i - 1][j - 1] == l - 1)
			{
				ans += s[i - 1];
				l--;
				break;
			}
	}
	reverse(all(ans));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70784
#include <stdio.h>

int main(void){
	int N;
	char S[110];
	int R,B;

	scanf("%d",&N);
	scanf("%s",S);
	R=0;B=0;
	for(int i=0; i<N; i++){
			if(S[i]=='R'){ R++; }
			if(S[i]=='B'){ B++; }
	}

	if(R>B){ printf("Yes\n");}
	else{ printf("No\n");}
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int add[12] = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};
	queue<int> que;
	map<int, int> m;
	for (int i = 0; i < 12; i++)
	{
		m[add[i]] = 1;
		que.push(add[i]);
	}
	while (que.size() && m[n] == 0)
	{
		int q = que.front();
		que.pop();
		for (int i = 0; i < 12; i++)
			if (m[q + add[i]] == 0)
			{
				m[q + add[i]] = m[q] + 1;
				que.push(q + add[i]);
			}
	}
	cout << m[n] << endl;

	return 0;
}


Measured memory_bytes: 23808
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
import Debug.Trace

solve :: Int -> String -> Int -> [Int] -> [Int]
solve n s q ks = map count ks
  where

  sv = VU.fromList s

  count k = countSub 0 0 0 0 0
    where
    countSub !acc !i !numD !numM !numDM
      | i == n = acc
      | otherwise = countSub newAcc (i+1) newNumD newNumM newNumDM
      where
      cur  = sv VU.! i
      left = sv VU.! (i-k)
      numDf | i-k < 0     = numD
            | left == 'D' = numD - 1
            | otherwise   = numD
      numMf | i-k < 0     = numM
            | left == 'M' = numM - 1
            | otherwise   = numM
      numDMf | i-k < 0     = numDM
             | left == 'D' = numDM - numM
             | otherwise   = numDM
      newNumD | cur == 'D' = numDf + 1
              | otherwise  = numDf
      newNumM | cur == 'M' = numMf + 1
              | otherwise  = numMf
      newNumDM | cur == 'M' = numDMf + numDf
               | otherwise  = numDMf
      newAcc | cur == 'C'   = acc + numDMf
             | otherwise    = acc

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> [Int]
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      [bs_s]:remLines2 = remLines1
      s = B.unpack bs_s
      [bs_q]:remLines3 = remLines2
      q = readBInt bs_q
      line4:remLines4 = remLines3
      ks = map readBInt line4
  in solve n s q ks

outAnswer :: [Int] -> IO ()
outAnswer xs = putStr $ unlines $ map show xs

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 16764
#include<bits/stdc++.h>
#define Add 300300
#define MS multiset
using namespace std;
MS<int> D[1001000],U[1001000];
MS<int> L[1001000],R[1001000];
MS<int> Main[1001000][4],Sub[1001000][4];//L0 R1 U2 D3
int X[200200],Y[200200];
char Dir[200200];
int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		scanf("%d %d %c",X+i,Y+i,Dir+i);
		if(Dir[i]=='U')
		{
			U[X[i]].insert(Y[i]);
			Main[X[i]+Y[i]][2].insert(X[i]);
			Sub[X[i]-Y[i]+Add][2].insert(X[i]);
		}
		if(Dir[i]=='D')
		{
			D[X[i]].insert(Y[i]);
			Main[X[i]+Y[i]][3].insert(X[i]);
			Sub[X[i]-Y[i]+Add][3].insert(X[i]);
		}
		if(Dir[i]=='L')
		{
			L[Y[i]].insert(X[i]);
			Main[X[i]+Y[i]][0].insert(X[i]);
			Sub[X[i]-Y[i]+Add][0].insert(X[i]);
		}
		if(Dir[i]=='R')
		{
			R[Y[i]].insert(X[i]);
			Main[X[i]+Y[i]][1].insert(X[i]);
			Sub[X[i]-Y[i]+Add][1].insert(X[i]);
		}
	}
	int Ans=100000000;
	for(int i=0;i<N;i++)
	{
		if(Dir[i]=='U')
		{
			MS<int>::iterator it=D[X[i]].lower_bound(Y[i]);
			if(it==D[X[i]].end())
				continue;
			Ans=min(Ans,(*it-Y[i])*5);
		}
		if(Dir[i]=='D')
		{
			MS<int>::iterator it=U[X[i]].lower_bound(Y[i]);
			if(it==U[X[i]].begin())
				continue;
			it--;
			Ans=min(Ans,(Y[i]-*it)*5);
		}
		if(Dir[i]=='L')
		{
			MS<int>::iterator it=R[Y[i]].lower_bound(X[i]);
			if(it==R[Y[i]].begin())
				continue;
			it--;
			Ans=min(Ans,(X[i]-*it)*5);
		}
		if(Dir[i]=='R')
		{
			MS<int>::iterator it=L[Y[i]].lower_bound(X[i]);
			if(it==L[Y[i]].end())
				continue;
			Ans=min(Ans,(*it-X[i])*5);
		}
	}
	for(int i=0;i<N;i++)
	{
		if(Dir[i]=='U')
		{
			MS<int>::iterator it=Sub[X[i]-Y[i]+Add][0].lower_bound(X[i]);
			if(it!=Sub[X[i]-Y[i]+Add][0].end())
			{
				Ans=min(Ans,(*it-X[i])*10);
			}
			it=Main[X[i]+Y[i]][1].lower_bound(X[i]);
			if(it!=Main[X[i]+Y[i]][1].begin())
			{
				it--;
				Ans=min(Ans,(X[i]-*it)*10);
			}
		}
		if(Dir[i]=='D')
		{
			MS<int>::iterator it=Main[X[i]+Y[i]][0].lower_bound(X[i]);
			if(it!=Main[X[i]+Y[i]][0].end())
				Ans=min(Ans,(*it-X[i])*10);
			it=Sub[X[i]-Y[i]+Add][1].lower_bound(X[i]);
			if(it!=Sub[X[i]-Y[i]+Add][1].begin())
			{
				it--;
				Ans=min(Ans,(X[i]-*it)*10);
			}
		}
		if(Dir[i]=='L')
		{
			MS<int>::iterator it=Sub[X[i]-Y[i]+Add][2].lower_bound(X[i]);
			if(it!=Sub[X[i]-Y[i]+Add][2].begin())
			{
				it--;
				Ans=min(Ans,(X[i]-*it)*10);
			}
			it=Main[X[i]+Y[i]][3].lower_bound(X[i]);
			if(it!=Main[X[i]+Y[i]][3].begin())
			{
				it--;
				Ans=min(Ans,(X[i]-*it)*10);
			}
		}
		if(Dir[i]=='R')
		{
			MS<int>::iterator it=Sub[X[i]-Y[i]+Add][3].lower_bound(X[i]);
			if(it!=Sub[X[i]-Y[i]+Add][3].end())
				Ans=min(Ans,(*it-X[i])*10);
			it=Main[X[i]+Y[i]][2].lower_bound(X[i]);
			if(it!=Main[X[i]+Y[i]][2].end())
				Ans=min(Ans,(*it-X[i])*10);
		}
	}
	if(Ans==100000000)
		puts("SAFE");
	else	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 596496
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
     
    struct UnionFind {
        vector<int> d ;
        UnionFind(int n = 0): d(n, -1) {} 
        int find(int x){
            if(d[x] < 0) return x ;
            return find(d[x]) ;
        }
        bool unite(int x, int y) {
            x = find(x) ; y = find(y) ;
            if(x == y) return false ;
            if(d[x] > d[y]) swap(x, y) ;
            d[x] += d[y] ;
            d[y] = x ;
            return true ;
        }
        bool same (int x, int y){
            return find(x) == find(y) ;
        }
        int size(int x){return -d[find(x)]; }
    };



int main () {
    int n, m ;
    cin >> n >> m ;
    int ans = 0 ;
    vector<P> edge  ;
    rep(i, m){
        int a, b ;
        cin >> a >> b ;
        a-- ;  b-- ;
        edge.push_back(P(a, b))  ;
    }
    rep(i, m){
        UnionFind uf(n) ;
        bool can = true ;
        rep(j, m){
            if(j == i){
                continue ;
            }
            else {
                int x = edge[j].first ;
                int y = edge[j].second ;
                uf.unite(x, y) ;
            }
        }
        int st = edge[i].first ;
        int gt = edge[i].second ;
        if(!uf.same(st, gt)){
            ans++ ;
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

const ll mod = 1e9+7;

int main()
{
    ll t, i, j, k, ans, n, m, sum = 0, x;

    //cin>>t;
    t = 1;
    while (t--)
    {
        cin>>n;
        ll cnt[10][10] = {0};

        rep(p,1,n+1)
        {
            ll l = p%10;

            k = p;
            while(k/10)k/=10;
            ll f = k;
            cnt[f][l]++;
        }

        ans=0;
        rep(p,1,10)
        {
            rep(q,0,10)
            {
                ans += (cnt[p][q] * cnt[q][p]);
            }
        }

        cout<<ans;
    }

    return 0;
}


Measured memory_bytes: 3628
N = int(input())
persons = list(map(int,input().split()))
stool_height = 0
for i in range(1,N):
    if persons[i] < persons[i-1]:
        height_req = abs(persons[i] - persons[i-1])
        persons[i] = persons[i]+height_req
        stool_height += height_req
print(stool_height)

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

int main(){
    int M, D, d1, d2;
    int count=0;
    cin >> M >> D;
    for(int j=1;j<=M;j++){
        for(int i=1;i<=D;i++){
            d2=i%10;
            d1=(i-d2)/10;
            if(d1>=2 && d2>= 2 &&j==d1*d2) count++;
        }
    }
    cout << count;
    
    
    
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
# from heapq import heappop, heappush
# from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
# import math
# from itertools import product, accumulate, combinations, product
# import bisect
# import numpy as np
# from copy import deepcopy
#from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())

def run():
    N = int(sysread())
    count = 0
    for i in range(N):
        a,b = mapline()
        if a == b:
            count += 1
        else:
            count = 0
        if count == 3:
            print('Yes')
            return
    print('No')


if __name__ == "__main__":
    run()


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

int main() {
	int d;
while(cin>>d){
	int a=600/d;
	int sum  = 0;
	for (int k=1;k<=a;k++){
		sum=sum+d*(((k-1)*d)*((k-1)*d));
	
}
cout<<sum<<endl;
}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int R =sc.nextInt();
		if (N >=10) {
			System.out.println(R);
		}else {
			System.out.println(R+((10 - N) * 100));
		}
	}
}

Measured memory_bytes: 34980
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class E {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<ll> a(n);
      rep(i, n) {
        cin >> a[i];
      }
      if (n%2==1) {
        ll sum = 0;
        rep(i, n) sum += a[i];
        if (sum%2==0) {
          cout << "Second" << endl;
        } else {
          cout << "First" << endl;
        }
      } else {
        ll sum = 0;
        ll mi = LLONG_MAX;
        rep(i, n) {
          sum += a[i];
          chmin(mi, a[i]);
        }
        if (mi%2 == 0 && sum%2 == 0) {
          cout << "Second" << endl;
        } else {
          cout << "First" << endl;
        }
      }
    }
};

signed main() {
  E solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 4384
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC161
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__


void solve(void){
  
  ll K;
    
  cin >> K;
  
  vector<ll> A[11];
  vector<ll> B;
    
  if(K<10){cout << K << endl;return;}
  
  
  REP(i,9){
    A[0].push_back(i+1);
  }
  
  B=A[0];

  REP2(i,1,11){
    for(auto j: A[i-1]){
      int d1=j%10;
      ll d=j*10+d1;
      if(d1>0){A[i].push_back(d-1);}
      A[i].push_back(d);
      if(d1<9){A[i].push_back(d+1);}
    }
    B.insert(B.end(), ALL(A[i]));
  }
  /*
  for(auto v:B){
    cout << v << " ";
  }
  cout << endl;
  */
  cout << B[K-1] << endl;
 
  return;
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {
  
    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}



Measured memory_bytes: 12188
import java.util.*;
import java.io.*;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[]a= sc.nextIntArr(n);
        Arrays.sort(a);
        int ans =0;
        for (int i =0;i<n;i++){
            for (int j =i+1;j<n;j++)
                if (a[i]!=a[j])
                for (int k =j+1;k<n;k++){
                if (a[i]==a[k]||a[k]==a[j])
                    continue;
                    if (a[i]+a[j]>a[k])
                        ans++;
                }
        }
        pw.println(ans);

        pw.close();

    }



    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = Integer.parseInt(next());
            }
            return arr;
        }

    }

}

Measured memory_bytes: 33568
#include <cstdio>
using namespace std;

const int MAXN = 100005;

int N;
int a[MAXN];

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
	
	int sol = 0;
	for (int i = 1; i <= N; i++)
		sol += a[a[i]] == i;
	
	printf("%d\n", sol / 2);
	
	return 0;
}

Measured memory_bytes: 512
import heapq

N, M = tuple(map(int, input().split()))
A = list(map(lambda a: -1*int(a), input().split()))
heapq.heapify(A)

for _ in range(M):
    x = heapq.heappop(A)
    heapq.heappush(A, -(-x//2))

print(-1*sum(A))

Measured memory_bytes: 72216
import math
def cmb(n, r):
    if n<2:
        return 0

    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    print(cmb(M,2)+cmb(N,2))


main()


Measured memory_bytes: 2940
N, M = map(int, input().split())
x = [None] * N
y = [None] * N
z = [None] * N

for i in range(N):
    x[i], y[i], z[i] = map(int, input().split())

ans = 0

for xs in [1, -1]:
    for ys in [1, -1]:
        for zs in [1, -1]:
            D = [xs*x[i] + ys*y[i] + zs*z[i] for i in range(N)]
            D.sort(reverse=True)
            ans = max(ans, sum(D[:M]))

print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
  long n,k,box,set,ans,khiku;
  box=0;
  set=0;
  ans=0;
  cin>>n>>k;
  vector<long> vec(n);
  for (long i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  
  for (long i = 0; i < n-1; i++) {
    for (long j = i+1 ; j < n; j++) {
      if(vec.at(i)>vec.at(j)){
        box=box+1;
      }
    }
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (long i = 0; i < n-1; i++) {
    for (long j = i+1 ; j < n; j++) {
      if(vec.at(i)>vec.at(j)){
        set=set+1;
      }
    }
  }
  khiku=k-1;
  ans=ans+(((khiku*k/2)%1000000007)*set)%1000000007;
  ans=ans+(box*k)%1000000007;
  ans=ans%1000000007;
  cout<<ans;
}

Measured memory_bytes: 256