akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    cins(all(a));
    ll l = 0,r = INF;
    while (r-l > 1){
        ll m = (l+r)/2;
        ll cnt = 0;
        rep(i,n){
            if (a[i]%m == 0) cnt += a[i]/m-1;
            else cnt += a[i]/m;
        }
        if (cnt <= k){
            r = m;
        }
        else{
            l = m;
        }
    }
    PRINT(r);
}


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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v)
{
    for (auto& e : v) {
        is >> e;
    }
    return is;
}

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


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> p(2 * N);
    for (int i = 0; i < 2 * N; i++) {
        cin >> p[i];
    }
    sort(p.begin(), p.end(), greater<ll>{});
    long double sum = 0;
    for (int i = 0; i < 2 * N; i++) {
        sum += (long double)(2 * N - i - 1) / (2 * N - 1) * p[i];
    }
    cout << fixed << setprecision(15) << sum << endl;


    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#define pb push_back
     
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
     
bool debug = false;
     

struct state
{
    ll a,b,c;

    state(ll a, ll b, ll c) : a(a), b(b), c(c)
    {

    }

  bool operator==(const state &other) const
  { return (a == other.a
            && b == other.b
            && c == other.c);
  }
};


struct KeyHasher
{
    size_t operator()(const state& k) const
  {
    //using std::size_t;
    //using std::hash;
    //using std::string;

    return ((hash<ll>()(k.a)
               ^ (hash<ll>()(k.b) << 1)) >> 1)
               ^ (hash<ll>()(k.c) << 1);
  }
};  


void solve(ll casen)
{
    ll res = 0;
    
    cout << "Case #" << casen << ": " << res << endl;
}

int main()
{
    // $ g++ -std=c++14 -Wshadow -Wall -o c C.cpp

    // !!! Here, unordered map was too slow!!!
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    
   ll a,b;
   cin >> a >>b;
   cout << a*b << endl;
  

    return 0;
}

Measured memory_bytes: 3636
#include<algorithm>
#include<iostream>
#define STR 1000
using namespace std;

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

Measured memory_bytes: 3588
// by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

// DELETE the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int N_MAX = 100003;
std::pair<int, int> seg[N_MAX], pre[N_MAX], suf[N_MAX];
bool cmp(std::pair<int, int> x, std::pair<int, int> y) {
  return x.first != y.first ? x.first < y.first : x.second > y.second;
}
std::pair<int, int> operator+(const std::pair<int, int> &x,
                                     const std::pair<int, int> &y) {
  return std::make_pair(std::max(x.first, y.first), std::min(x.second, y.second));
}
int calc(std::pair<int, int> x) {
  return std::max(0, x.second - x.first + 1);
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &seg[i].first, &seg[i].second);
  std::sort(seg + 1, seg + n + 1, cmp);
  pre[1] = seg[1];
  for (int i = 2; i <= n; ++i)
    pre[i] = pre[i - 1] + seg[i];
  suf[n] = seg[n];
  for (int i = n - 1; i > 0; --i)
    suf[i] = suf[i + 1] + seg[i];
  
  int ans = 0;
  for (int i = 1; i < n; ++i)
    ans = std::max(calc(pre[i]) + calc(suf[i + 1]), ans);
  for (int i = 2; i < n; ++i)
    ans = std::max(calc(pre[i - 1] + suf[i + 1]) + calc(seg[i]), ans);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] D = new int[n];
		for(int i = 0; i < n; i++) {
			D[i] = sc.nextInt();
		}
		int m = sc.nextInt();	
		int[] T = new int[m];
		for(int i = 0; i < m; i++) {
			T[i] = sc.nextInt();
		}
		Arrays.sort(D);
		Arrays.sort(T);
		int count = 0;
		for(int i = 0; i < n; i++) {
			if(D[i] == T[count] ) count++;
			if(count == m) {
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
		
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

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


Measured memory_bytes: 103164
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

bool IsPrime(int num);

int main(){
    vector<int> prime;
    //O(N√N)
    for(int i=2;i<=5555;i++){
        if(IsPrime(i) && i%5==1){prime.push_back(i);}
    }
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        if(i==N-1){cout<<prime[i];}
        else{cout<<prime[i]<<" ";}
    }
    cout<<endl;

    return 0;
}

//O(√N)
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

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

    // 素数である
    return true;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;

int idx = 0;
vector<int> val(4, 0);
string eval_str = "";
bool exec_str() {
    bool ret;
    if (eval_str[idx] == '-') {
        idx++;
        bool v = exec_str();
        ret = !v;
    } else if (eval_str[idx] == '(') {
        idx++;
        bool left = exec_str();
        char op = eval_str[idx++];
        bool right = exec_str();
        if (op == '*') ret = left & right;
        else ret = left ^ right;
        idx++;
    } else if (eval_str[idx] == '0' || eval_str[idx] == '1') {
        ret = eval_str[idx++] - '0';
    } else {
        int pos = 0;
        for (int i = 0; i < 4; i++) {
            if ("abcd"[i] == eval_str[idx]) {
                pos = i;
                break;
            }
        }
        ret = val[pos];
        idx++;
    }
    return ret;
}

int calc_str(string s, bool debug = false) {
    int ret = 0;
    eval_str = s;
    for (int i = 0; i < (1 << 4); i++) {
        idx = 0;
        for (int j = 0; j < 4; j++) {
            val[j] = (bool)(i & (1 << j));
            if (debug) cout << val[j] << " ";
        }
        bool flag = exec_str();
        if (debug) cout << "= " << flag << endl;
        if(flag) {
            ret = ret | (1 << i);
        }
    }
    return ret;
}

int main() {
    string s;
    while (cin >> s, s != ".") {
        int corr_val = calc_str(s, false);

        vector<string> exp[50];
        exp[1] = {"0", "1", "a", "b", "c", "d"};
        map<int, string> done;
        for (auto x : exp[1]) {
            int v = calc_str(x);
            done[v] = x;
        }
        for (int i = 1; i <= 16; i++) {
            for (auto left : exp[i]) {
                // not <E>
                string not_str = "-" + left;
                int not_val = calc_str(not_str);
                if (!done.count(not_val) || i + 1 < done[not_val].size()) {
                    done[not_val] = not_str;
                    exp[i + 1].push_back(not_str);
                }
                for (int j = 1; j <= i; j++) {
                    if (i + j + 3 > 16) continue;
                    for (auto right : exp[j]) {
                        // (<E> ^ <E>)
                        string xor_str = "(" +left + "^" + right + ")";
                        int xor_val = calc_str(xor_str);
                        if (!done.count(xor_val) || i + j + 3 < done[xor_val].size()) {
                            done[xor_val] = xor_str;
                            exp[i + j + 3].push_back(xor_str);
                        }
                        // (<E> * <E>)
                        string and_str = "(" +left + "*" + right + ")";
                        int and_val = calc_str(and_str);
                        if (!done.count(and_val) || i + j + 3 < done[and_val].size()) {
                            done[and_val] = and_str;
                            exp[i + j + 3].push_back(and_str);
                        }
                    }
                }
            }
        }
        cout << done[corr_val].size() << endl;
    }
}


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

using namespace std;

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

	vector<int> b(n);
	

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

	int ans = 0;

	ans += b[0] + b[n - 2];

	for (int i = 0; i < n - 2; i++) {
		ans += min(b[i], b[i + 1]);
	}

	cout << ans;

	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int data[10000];
	int cnt = 0;
	int i;
	
	do {
		scanf("%d", &data[cnt]);
		cnt++;
	} while (data[cnt-1] != 0);
	
	for(i = 0; i < cnt-1; i++) {
		printf("Case %d: %d\n", i+1, data[i]);
	}
	
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int main(){
	while(true){	
		int n,m;
		cin >> n >> m;
		if(n==0&&m==0){
			break;
		}
		int masu[n];
		for(int aa=0;aa<n;aa++){
			cin >> masu[aa];
		}
		int t=0;
		int d;
		int k=0;
		for(int bb=0;bb<m;bb++){
			cin >> d;
			if(k==0){
				t+=d;
				if(t>=n-1){
					printf("%d\n",bb+1);
					k=1;
				}
				t+=masu[t];
				if(k==0&&t>=n-1){
					printf("%d\n",bb+1);
					k=1;
				}
			}
			
		}
	}
}


Measured memory_bytes: 3156
use std::io;

fn main() {
    let mut n = String::new();
    io::stdin().read_line(&mut n);

    let n : u32 = n.trim().parse().expect(" ");
    let ans : u32 = {
        (n + 999) / 1000
    };
    let ans : u32 = ans * 1000 - n;
    println!("{}",ans);
}


Measured memory_bytes: 2080
def data_input():
    D = int(input())
    C = tuple(map(int, input().split()))

    S = []
    for i in range(D):
        s = tuple(map(int, input().split()))
        S.append(s)

    return D, C, S


def score(D, C, S, T):
    """入力D, C, Sと出力Tからスコアを計算する関数"""

    last = [0] * 26  # 0で初期化されている

    def decrease(d, last):
        """d日めにiを開催した時の満足度の減少を返す関数"""
        res = 0
        for i in range(26):
            ith = C[i] * (d+1 - last[i])
            res -= ith
        return res

    V = []  # V[d]はd日めの満足度を表す
    for d, i in enumerate(T):
        if d == 0:
            v = 0
        last[i] = d + 1
        v += S[d][i] + decrease(d, last)
        V.append(v)
    return V

D, C, S = data_input()

T = []
for i in range(D):
    t = int(input()) - 1
    T.append(t)

V = score(D, C, S, T)

for v in V:
    print(v)

Measured memory_bytes: 9360
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_166_A_C
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();
            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else if (s == "ARC")
            {
                Console.WriteLine("ABC");
            }

            // 整数の入力
            //long n = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            //var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();



            //string result = "";

            //Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25856
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using ll = long long;

const int nmax = 50;
int n, m;
int A[nmax], B[nmax];
bool graph[nmax][nmax];
bool visited[nmax];

void dfs(int v) {
	visited[v] = true;
	for (int v2=0; v2<n; v2++) {
		if (graph[v][v2]==false) continue;
		if (visited[v2]==true) continue;
		dfs(v2);
	}
}

int main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
		graph[A[i]][B[i]] = graph[B[i]][A[i]] = true;
	}
	int ans = 0;
	for (int i=0; i<m; i++) {
		graph[A[i]][B[i]] = graph[B[i]][A[i]] = false;
		rep(v, n) visited[v] = false;
		dfs(0);
		bool bridge = false;
		rep(v, n) {
			if (visited[v]==false) bridge = true;
		}
		if (bridge) ans++;
		graph[A[i]][B[i]] = graph[B[i]][A[i]] = true;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3640
a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))

nums = {0}

for i in range(a):
    p = nums.copy()
    for j in p:
        nums.add(b[i])
        nums.add(j+b[i])

for i in range(c):
    if d[i] in nums:
        print('yes')
    else:
        print('no')



Measured memory_bytes: 5704
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int h,w,k;
char table[810][810];
int dist[810][810];
int si,sj;
int ml,mr,mu,md;
int dxy[5] = {0,1,0,-1,0};
string sinput;

signed main(){
    cin >> h >> w >> k;
    REP(i,h) {
        cin >> sinput;
        REP(j,w){
            table[i+1][j+1] = sinput[j];
            if (table[i+1][j+1] == 'S'){
                si = i+1; sj = j+1;
            }
        }
    }
    REP(i,810) REP(j,810) dist[i][j] = 1145141919LL;
    dist[si][sj] = 0;

    deque<pi> q;
    q.emplace_back(si,sj);
    while(!q.empty()){
        auto p = q.front();
        int d = dist[p.first][p.second];
        q.pop_front();
        REP(i,4) if(table[p.first + dxy[i]][p.second + dxy[i+1]] == '.'){
            dist[p.first + dxy[i]][p.second + dxy[i+1]] = d+1;
            if (d+1 <= k){
                q.emplace_back(p.first+ dxy[i],p.second + dxy[i+1]);
            }
            table[p.first + dxy[i]][p.second + dxy[i+1]] = 'S';
        }
    }

    ml = 1000; mr = -1;
    mu = 1000; md = -1;
    REP(i,h) REP(j,w){
        if (dist[i+1][j+1] <= k){
            ml = min(ml, j); mr = max(mr, j);
            mu = min(mu, i); md = max(md, i);
        }
    }
    int ans = 1145141919LL;
    ans = min(ans, (ml+k-1)/k);
    ans = min(ans, (mu+k-1)/k);
    ans = min(ans, ((w-1-mr)+k-1)/k);
    ans = min(ans, ((h-1-md)+k-1)/k);
    cout << ans+1 << endl;
}

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

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

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

    vector<int> order(n+1);
    for(int i=1; i<=n; i++){
        order[a[i]] = i;
    }

    for(int i=1; i<=n; i++){
        cout << order[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 1536
N = $stdin.gets.chomp.to_i
D, X = $stdin.gets.chomp.split(' ').map(&:to_i)
A = []
N.times do |i|
    A[i] = $stdin.gets.chomp.to_i
end

sum = X
A.each do |a|
    sum += 1 + (D - 1) / a
end

print sum

Measured memory_bytes: 1788
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int n = S.size();

  vector<vector<int64_t>> count(2, vector<int64_t>(2019, 0));
  int64_t answer = 0;
  for (int i = 0; i < n; ++i) {
    int cur = S[i] - '0';
    for (int j = 0; j < 2019; ++j) {
      int k = j * 10 + cur;
      count[i % 2][k % 2019] = count[(i + 1) % 2][j];
    }
    count[i % 2][cur]++;
    answer += count[i % 2][0];
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define sll(n) scanf("%lld",&n)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define REP(i,x,y) for(ll i = x;i <= y;++i)
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z))
        ;
    return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
void localTest() {
    #ifndef ONLINE_JUDGE
        freopen("inp", "r", stdin);
        freopen("out", "w", stdout);
    #endif      
}
ll a, b, n;
ll getAns(ll x) {
    ll ans = floor(a * x / b) - a * floor(x / b);
    return ans;
}
int main() {

    localTest();
    sll3(a, b, n);
    ll x = (n + 1) / b, ans = getAns(n);
    x = x * b - 1;
    // debug(x);
    if(x >= 0 && x <= n) ans = max(ans, getAns(x));
    
    printf("%lld\n", ans); 
    

    return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL, *x = root, *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    }
    else {
      x = x->right;
    }
  }

  z->parent = y;
  if (y == NIL) {
    root = z;
  }
  else {
    if (z->key < y->key) {
      y->left = z;
    }
    else {
      y->right = z;
    }
  }
}

void preorder(Node *u) {
  if (u == NIL) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}

void print() {
  inorder(root);
  cout << endl;
  preorder(root);
  cout << endl;
}

int main() {
  int q, k;
  cin >> q;
  string com;
  rep(i, q) {
    cin >> com;
    if (com[0] == 'i') {
      cin >> k;
      insert(k);
    }
    else print();
  }


  
  return 0;
}


Measured memory_bytes: 26600
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)|(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define PI (acos(-1))
#define M_E (2.718281828459045)
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 101
ii v[asz];
ll dp[asz][100005];
ll solve(ll val,ll ind)
{
    if(ind==-1)
    {
        if(val)return INF;
        else return 0;
    }
    if(dp[ind][val]!=-1)return dp[ind][val];
    dp[ind][val]=solve(val,ind-1);
    if(val>=v[ind].se)dp[ind][val]=min(solve(val-v[ind].se,ind-1)+v[ind].fi,dp[ind][val]);
    return dp[ind][val];
}
int main()
{
    fastread;
    ll n,w;
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        cin>>v[i].fi>>v[i].se;
    }
    memset(dp,-1,sizeof dp);
    for(ll i=100000;i>=0;i--)
    {
        if(solve(i,n-1)<=w)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 79232
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int sum = 0;
        for (int i = 0; i < N; i++) {
            sum += Integer.parseInt(sc.next()) - 1;
        }

        System.out.println(sum);

    }
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for (int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for (int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
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 main()
{
	int N, M;
	cin >> N >> M;

	vector<int> X(max(N, M), 0);
	repeat(i, M)
	{
		int x = 0;
		cin >> x;
		X[i] = x;
	}

	int result = 0;
	vector<int> diff(M-1, 0);
	sort(X.begin(), X.end());
	if (M >= N) {
		repeat(i, M-1) {
			diff[i] = abs(X[i] - X[i+1]);
		}
		sort(diff.begin(), diff.end(), greater<int>());

		result = accumulate(diff.begin(), diff.end(), 0);

		repeat(i, N - 1) {
			result -= diff[i];
		}
	}

	cout << result << endl;
	return 0;
}


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

using namespace std;

int main() {
	int r, c;
	cin >> r >> c;
	int sum=0;
	vector < vector<int>> m(r, vector<int>(c));
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> m[i][j];
			sum += m[i][j];
		}
	}
	vector<int> sumr(r);
	vector<int> sumc(c);

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			sumr[i] += m[i][j];
		}
	}
	for (int j = 0; j < c; j++) {
		for (int i = 0; i < r; i++) {
			sumc[j] += m[i][j];
		}
	}

	for (int i = 0; i < r + 1; i++) {
		for (int j = 0; j < c + 1; j++) {

			if (i < r&&j < c) {
				cout << m[i][j] << " ";
			}
			else if (j == c&&i<r) {
				cout << sumr[i] << endl;
			}
			else if (i == r&&j<c) {
				cout << sumc[j] << " ";
			}
			else if (i == r && j == c) {
				cout << sum<<endl;
			}


		}
	}



	return 0;
}


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

int main() {
    ll k,x;
    std::cin >> k>>x;
    if(k==1){
        std::cout << x << std::endl;
        return 0;
    }
    
    for (int i = x-(k-1); i < x+(k-1); i++) {
        std::cout << i << " ";
    }
    std::cout << x+k-1 << std::endl;
}
 

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const ll MOD = 1000000007;
const int MSIZE = 100007;
const double Pi = 3.14159265358979323146;

int main(){
  int n, m; cin >> n >> m;
  vector<vi> route(n+1);
  vector<int> ans(n+1, -1);
  ans[0]=0;
  ans[1]=0;
  REP(i, m){
    int a, b; cin >> a >> b;
    route[a].emplace_back(b);
    route[b].emplace_back(a);
  }

  {
    queue<int> floor;
    floor.push(1);
    while(!floor.empty()){
      int room = floor.front();
      floor.pop();
      //cout << room << "is pop" << endl;
      REP(i, route[room].size()){
        if(ans[route[room][i]]==-1){
          //cout << route[room][i] << "is push" << endl;
          ans[route[room][i]]=room;
          floor.push(route[room][i]);
        }
      }
    }
  }
  if(find(ALL(ans), -1)!=ans.end()){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for(int i=2; i<=n; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 10284
package main

import (
	"fmt"
)

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	fmt.Println(lcm(a, b))
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;

    ll ans = 0;

    if(a+b < 2*c) ans += (a+b) * (min(x,y));
    else ans += 2*c*(min(x,y));

    if(x > y){
        if(a < 2*c) ans += a*(x-y);
        else ans += 2*c*(x-y);
    }
    if(x < y){
        if(b < 2*c) ans += b*(y-x);
        else ans += 2*c*(y-x);
    }

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


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include<stdio.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

using namespace std;

int main(){
	int n, m, p;
	int x[100];
	while (cin >> n >> m >> p) {
		if (n == 0 && m == 0 && p == 0) {
			break;
		}
		int total = 0;
		int get = 0;
		int haito = 0;
		REP(i, n) {
			cin >> x[i];
			total += x[i];
		}
		get = total*100 * (100-p) / 100;
		if (x[m - 1] != 0) {
			haito = get / x[m - 1];
		}
		else {
			haito = 0;
		}
		cout << haito << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

int main() {
	int n, q;
	while(cin >> n >> q, n||q) {
		int cnt[100] = {};
		rep(i, n) {
			int m;
			cin >> m;
			rep(j, m) {
				int d;
				cin >> d;
				cnt[d]++;
			}
		}
		int res = 0;
		for(int i=1; i<100; i++) {
			if(cnt[i]>=q && cnt[res]<cnt[i]) {
				res = i;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
N, M = map(int, input().split())

Switches = [None] + [ list([0]) for _ in range(N) ]
Ss = [list(map(lambda x: Switches[int(x)], input().split()[1:])) for _ in range(M)]
for coil, S in zip(map(int, input().split()), Ss):
    S.append([coil])

cnt = 0
for L in range(pow(2, N)):

    for i, onoff in enumerate(((L & (1 << x)) != 0 for x in range(N))):
        Switches[i+1][0] = onoff

    if sum((sum((1 for si in sji for siv in si if siv)) % 2 != 0 for sji in Ss)) <= 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    rep(i, 0, s.size()) {
        cout << 'x';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
readline=sys.stdin.readline
read=sys.stdin.read

h,w=map(int,readline().split())
wb={'#':0,'.':1}
s=[wb[g] for g in read() if g!='\n']
dist=[0]*(h*w)
dist[0]=1
stack=deque([(0,0)])
while stack:
  cg=stack.popleft()
  for i in range(4):
    ng=(cg[0]+(1-2*(i&1))*(i>>1),cg[1]+(1-2*(i&1))*(1-(i>>1)))
    fcg=w*cg[0]+cg[1]
    fng=w*ng[0]+ng[1]
    if 0<=ng[0]<=h-1 and 0<=ng[1]<=w-1 and \
        s[fng] and dist[fng]==0:
      stack.append(ng)
      dist[fng]=dist[fcg]+1
if dist[-1]:
  print(sum(s)-dist[-1])
else:
  print(-1)


Measured memory_bytes: 9368
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000000000LL;
const int MAX=100001;
const double EPS=1e-10;
vector<int> G[100010];
int co[100010];
bool dp[100010][11];
void dfs(int v,int d,int c){
    if(dp[v][d]){
        return;
    }
    dp[v][d]=true;
    if(!co[v]){
        co[v]=c;
    }
    if(d==0){
        return;
    }
    
    for(const auto& e:G[v]){
        dfs(e,d-1,c);
    }
}
int main(){
    memset(co,0,sizeof(co));
    memset(dp,false,sizeof(dp));
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int v[100010],d[100010],c[100010];
    int q;cin>>q;
    for(int i=0;i<q;i++){
        int vv,dd,cc;
        cin>>vv>>dd>>cc;
        v[i]=vv;d[i]=dd;c[i]=cc;
    }
    for(int i=q-1;i>=0;i--){
        dfs(v[i],d[i],c[i]);
    }
    for(int i=1;i<=n;i++){
        cout<<co[i]<<endl;
    }
}


Measured memory_bytes: 9080
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

const int MOD = 1000000007;

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

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

    vector<int> d(n + 1);
    d[0] = 1;
    map<int, int> s;
    for (int i = 0; i < n; i++) {
        if (i == 0 || a[i] != a[i - 1]) {
            s[a[i]] = (s[a[i]] + d[i]) % MOD;
        }
        d[i + 1] = s[a[i]];
    }
    cout << d[n];

    return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
const int L = 1000006;
ll spf[L+10];
map <ll,ll> x;
void soe()
{
	ll i,j;
	for(i=1;i<=L;i++)
		spf[i]=i;
	for(i=2;i*i<=L;i++)
	{
		if(spf[i]==i)
		{
			for(j=i*i;j<=L;j+=i)
			{
				if(spf[j]==j)
					spf[j]=i;
			}
		}
	}
}
vector <ll> factorise(ll x)
{
	vector <ll> v;
	while(x!=1)
	{
		v.pb(spf[x]);
		x=x/spf[x];
	}
	return v;
} 
int main()
{
	ios_base::sync_with_stdio(false);
	ll n,i;
	soe();
	cin>>n;
	ll a[n+2];
	for(i=0;i<n;i++)
		cin>>a[i];
	ll gcd=a[0];
	for(i=1;i<n;i++)
		gcd = __gcd(gcd, a[i]);
	// for(i=1;i<L;i++)
	// {
	// 	factorise(i);
	// }
	for(i=0;i<n;i++)
	{
		vector <ll> sub = factorise(a[i]);
		for(auto y:sub)
		{
			x[y]++;
		}
	}
	ll ff=0;
	for(i=0;i<n;i++)
	{
		vector <ll> sub = factorise(a[i]);
		map <ll,ll> subb;
		for(auto it:sub)
			subb[it]++;
		ll f=0;
		for(auto y:subb)
		{
			ll p = x[y.ff] - y.ss;
			if(p!=0)
			{
				f=1;
				break;
			}
		}
		if(f==1)
		{
			ff=1;
			break;
		}
	}
	if(ff==0)
		cout<<"pairwise coprime";
	else if(gcd==1)
		cout<<"setwise coprime";
	else
		cout<<"not coprime";
	cout<<nl;
	return 0;
}

Measured memory_bytes: 24124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;

signed main(){
   int n,m,x;
   cin>>n>>m>>x;
   int book[n][m+1];
   rep(i,n)rep(j,m+1){
       cin>>book[i][j];
   }
   int num=1<<n;
   int ans=INT_INF;
   rep(s,num){
       int i=s;
       int flag=1;
       int tmp[m+1]={};
        for(int j=0;j<n;i>>=1,j++){
           if(i&1){
               rep(k,m+1)tmp[k]+=book[j][k];
           }
        }
       for(int l=1;l<m+1;l++){
           if(tmp[l]<x){
               flag=-1;break;
           }
       }
       if(flag>0)ans=min(ans,tmp[0]);
   }
   if(ans<INT_INF){
    cout<<ans<<endl;
   }else{
       cout<<"-1"<<endl;
   }
    return 0;
}

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

int main() {
    int a, b; cin >> a >> b;
    int count = 0;
    for(int i = a; i <= b; i++) {
        int k[5];
        int n = i;
        for(int j = 0; j < 5; j++) {
            k[j] = n % 10;
            n /= 10;
        }
        if(k[0] == k[4] && k[1] == k[3]) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
def Ics(X, Y):
    m = len(X)
    n = len(Y)
    c1 = [0] * (n + 1)
    for i in range(m):
        d = X[i]
        c2 = c1[:]
        for j in range(n):
            if (d == Y[j]):
                c1[j + 1] = c2[j] + 1
            elif (c1[j + 1] < c1[j]):
                c1[j + 1] = c1[j]
    return (c1[-1])

q = int(input().rstrip())
t = []
for i in range(q):
    s1 = input().rstrip()
    s2 = input().rstrip()
    t.append(Ics(s1, s2))
print(*t, sep = "\n")

Measured memory_bytes: 7800
/// wa ^3^

#pragma GCC optimize("O3")

#include<bits/stdc++.h>
                           
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

void stndrtn() {
#ifdef accepted
    freopen(".in", "r", stdin);
#endif        
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    long double n;
    cin >> n;
    long double x = n/3.0;
    cout << setprecision(6) << fixed << x*x*x;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define PI 3.14159265358979323846264338327950L
 
int main(){
  long long a;
  cin >> a;
  long double b;
  cin >> b;

  long double t = a * b;
  long long ans = floor(t);
  cout << ans << endl;


  }


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

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        cout << A[i] << " ";
    }
    cout << endl;
}

inline void solve() {
    LL X;
    cin >> X;

    LL cur = 100;
    int res = 0;

    while (cur < X) {
        cur = (LL)(cur * 1.01);
        res++;
    }

    cout << res << endl;

}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    int t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        // solve();
        string s;
        cin >> s;
        if (s == "ABC") cout << "ARC" << endl;
        else cout << "ABC" << endl;
    }

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  string s, t;
  cin >> s >> t;

  int cnt = 0;

  rep(i,s.size()) {
    if (s[i] != t[i]) cnt++;
  }

  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair

int main(){
    int n; cin >> n;
    int df[10][10];
    rep(i,10) rep(j,10) df[i][j] = 0;

    rep(i,n){
        int x = i+1;
        string s = to_string(x);
        int head = s[0] - '0';
        int tail = s[s.size()-1] - '0';

        df[head][tail]++;
    }
    int ans = 0;

    rep(i,9){
        rep(j,9){
            ans += df[i+1][j+1] * df[j+1][i+1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ka = [list(map(int, input().split())) for _ in range(n)]

a = 0

for i in range(m):
    loved = True
    for j in range(n):
        if ka[j][1:].count(i+1) == 1:
            continue
        else:
            loved = False
            break

    if loved:
        a += 1

print(a)


Measured memory_bytes: 3060
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            long A = long.Parse(str[0]);
            long B = long.Parse(str[1]);
            long K = long.Parse(str[2]);

            if (A >= K) A = A - K;
            else
            {
                K = K - A;
                B = B - K;
                if (B < 0) B = 0;
                A = 0;
            }
            Console.WriteLine($"{A} {B}");
        }
       
    }
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = long.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();

string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
 */
/*
      static long func(long n)
      {
          long d = 0;
          for (long i = 0; i < 10; i++)
          {
              if (n / longPow(10, i) == 0)
              {
                  d = i;
                  break;
              }
          }
          long ret = A * n + B * d;
          return ret;
      }
      static long longPow(long a, long n)
      {
          long b = 1;
          for (long i = 0; i < n; i++) b = b * a;
          return b;
      }
      */


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

string s;

int main() {
  cin >> s;
  int n = (int)s.size();

  long long res = 0;
  long long a_count = 0;
  // int res = 0;
  // int a_count = 0;
  bool prev_is_b = false;
  for(int i = 0; i < n; i++) {
    switch(s[i]) {
      case 'A':
        if(prev_is_b)
          a_count = 0;
        a_count++;
        prev_is_b = false;
        break;
      case 'B':
        if(prev_is_b)
          a_count = 0;
        prev_is_b = true;
        break;
      case 'C':
        if(prev_is_b)
          res += a_count;
        else
          a_count = 0;
        prev_is_b = false;
        break;
    }
  }
  cout << res << endl;
}

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

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


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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> X(N);
    for (int i = 0; i < N; ++i) {
        cin >> X[i];
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += min(X[i], K - X[i]) * 2;
    }

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

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return True
    ans = 0
    K1 = K % 10
    t = K
    while t:
        # print(ans)
        for i in range(10):
            if (t + K1 * i) % 10 == 7:
                break
        else:
            ans = -1
            break
        t = t + K * i
        while t % 10 == 7:
            t //= 10
            ans += 1
            
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9108
N = int(input())
a = [int(s) for s in input().split()]
b = int(0)

for i in range(N-1):
  if a[i] <= a[int(i+1)]:
    pass
  else:
    b = b + (a[i] - a[int(i+1)])
    a[int(i+1)] = a[i]

print(b)

Measured memory_bytes: 32136
#include<bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
typedef long long ll;
int a[200005];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	ll sum=0;
	for(int i=1;i<n;i++){
		if(a[i]<a[i-1]){
			sum+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<sum;
	return 0;
} 

Measured memory_bytes: 4412