akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

u64 mypow(u64 x, u64 n);
void initprime(u64 x);
vector<bool> primes;
vector<u64> yakusuu;

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

    u64 N, P;
    cin >> N >> P;

    if (N == 1)
    {
        cout << P << "\n";
        return 0;
    }
    else if (N >= 40)
    {
        cout << "1\n";
        return 0;
    }

    u64 num = sqrt(P);
    primes.resize(num + 1, true);
    primes[0] = false; primes[1] = false;
    for (int i = 2; i < num; ++i)
    {
        if (!primes[i]) continue;
        int j = i + i;
        while (j < num)
        {
            primes[j] = false;
            j += i;
        }
    }

    u64 jou;
    u64 ret = 1;
    for (int i = 2; i <= primes.size(); ++i)
    {
        if (primes[i])
        {
            jou = 0;
            while (!(P % i))
            {
                jou++;
                P /= i;
            }
            if (jou >= N)
            {
                ret *= pow(i, jou / N);//mypow(i, jou / N);
            }
        }
    }

    cout << ret << "\n";

    return 0;
}

u64 mypow(u64 x, u64 n)
{
    u64 ret;
    if (n == 0) ret = 1;
    else if (n & 1) ret = x * mypow(x, n - 1);
    else ret = mypow(x * x, n >> 1);
    return ret;
}

void initprime(u64 x)
{

}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){ 
    string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]=='9'){
			cout<<"Yes"<<endl;
			return 0;
		} 
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
bulbs = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
cmb = [1] * 2 ** n

for i in range(2 ** n):
    on_off = [0] * n
    for j in range(n):
        if i >> j & 1:
            on_off[j] = 1
    
    for j in range(m):
        cnt = 0
        
        for k in bulbs[j][1:]:
            cnt += on_off[k - 1]
        
        if cnt % 2 != p[j]:
            cmb[i] = 0
            
print(sum(cmb))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
ll n, cnt_2, cnt_5;
 
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	if (n & 1) {
		cout << 0;
		return 0;
	}
	for (ll x = 2; x <= n; x *= 2)
		cnt_2 += n / x;
	for (ll x = 5; x <= n; x *= 5)
		cnt_5 += (n / x) / 2;
	cout << min(cnt_2, cnt_5);
}

Measured memory_bytes: 256
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

fn meg_binary_search<T: Ord>(key: T, a: &[T]) -> usize {
    let mut ok = -1;
    let mut ng = a.len() as i64;

    while (ok - ng).abs() > 1 {
        let mid = (ok + ng) / 2;
        if a[mid as usize] < key {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ok as usize
}

fn main() {
    input! {
        n: usize,
        l: [u64;n],
    }

    let mut l = l;
    l.sort();

    let mut ans = 0;

    for i in 0..n - 2 {
        for j in i + 1..n - 1 {
            ans += meg_binary_search(l[i] + l[j], &l) - j;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

int accumulate(int* a,int n){
    return accumulate(a,a+n,0LL);
}

int accumulate(vector<int> a){
    return accumulate(a.begin(),a.end(),0LL);
}

signed main(){ 
   int n,m,k;
   cin>>n>>m>>k;

   int resutl=0;
   vector<int> A(n,0); vector<int> B(m,0);

   for(int i=0;i<n;i++){
     int ai; cin>>ai;
     A[i]+=ai;
     if(i!=0) A[i]+=A[i-1];
   }

   for(int i=0;i<m;i++){
     int bi; cin>>bi;
     B[i]+=bi;
     if(i!=0) B[i]+=B[i-1];
   }

   sort(all(A));
   sort(all(B));

   int a_sma=upper_bound(all(A),k)-A.begin();
   int result=0;

   if(a_sma==0){
     int b_sma=upper_bound(all(B),k)-B.begin();
     result=b_sma;
   }else{
     for(int i=0;i<=a_sma;i++){
       int ki=k;
       int res=i;
       if (i!=0) ki-=A[i-1];
       int b_sma=upper_bound(all(B),ki)-B.begin();
       //cout<<res<<" "<<b_sma<<endl;
       res+=b_sma;
       result=max(result,res);
     }
   }


   cout<<result<<endl;
}  

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

int main() {
  int n, i, sum = 0, keep = 0, a, b;
  cin >> n;
  
  vector<int> w(n), x(n);
  for(i = 0; i < n; i++){
    cin >> w.at(i);
    sum += w.at(i);
  }
  
  for(i = 0; i < n; i++){
    keep += w.at(i);
    x.at(i) = abs(sum - 2 * keep);
  }
  
  sort(x.begin(), x.end());
  
  cout << x.at(0) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 26 17:52:43 2019

@author: nakamuratakayuki
"""

S = list(input())
c1 = 0
c2 = 0
for i in range(len(S)):
    if i%2 == 0:
        if S[i] == '0':
            c1 += 1
    else:
        if S[i] == '1':
            c1 += 1
for i in range(len(S)):
    if i%2 == 0:
        if S[i] == '1':
            c2 += 1
    else:
        if S[i] == '0':
            c2 += 1
print(min(c1,c2))

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,k,t,ans=0;
int visited[1000005]; 

signed main()
{
	cin>>n>>k;
	for (int i=1;i<=k;i++)
	{
		cin>>t;
		for (int i=1;i<=t;i++)
		{
			int tmp;
			cin>>tmp;
			visited[tmp]=1;
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (visited[i]==0)  ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int temp;
    for (int i = 0; i < m; i++)
    {
        cin >> temp;
        n -= temp;
    }
    cout << max(-1, n) << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 入力
		int N = sc.nextInt();                
		int K = sc.nextInt();

		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
        Arrays.sort(h);
		// 答えを出力
        int ans = 0;
        int sum = 0;
        boolean first = true;
		for (int i = 0; i <= N-K; i++) {
          sum = h[i+K-1] - h[i];
          if (first || sum < ans) {
            ans = sum;
            first = false;
          } 
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 50384
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	string a,b;
	cin>>a>>b;
	string tem="";
	for(int i = (int)a.length()-(int)b.length();i>=0;i--) {
		bool h = true;
		REP(j,0,(int)b.length()-1) {
			if(b[j]!=a[i+j]&&a[i+j]!='?') {
				h=0;
				break;
			}
		}
		if(h) {
			tem = a;
			REP(j,0,(int)b.length()-1) {
				tem[i+j]=b[j];
			}
			REP(j,0,(int)a.length()-1){
				if(tem[j]=='?')tem[j]='a';
			}
			cout<<tem;
			return;
		}
	}
	if(tem!=""){
		cout<<tem;
	} else
	cout<<"UNRESTORABLE";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <list>

std::string getFizzBuzz(int n)
{
	if (n % 15 == 0)
	{
		return "FizzBuzz";
	}
	else if (n % 5 == 0)
	{
		return "Buzz";
	}
	else if (n % 3 == 0)
	{
		return "Fizz";
	}
	else
	{
		return std::to_string(n);
	}
}

void fizzbuzz(int m, int n)
{
	std::list<int> lst;

	for (int i = 1; i <= m; ++i)
	{
		lst.push_back(i);
	}

	for (int i = 1; i <= n; ++i)
	{
		std::string rem;
		std::cin >> rem;

		if (lst.size() <= 1)
		{
			continue;
		}

		int player = *(lst.begin());
		lst.pop_front();

		std::string ret = getFizzBuzz(i);

		if (rem == ret)
		{
			lst.push_back(player);
		}
	}

	lst.sort();
	for (auto itr = lst.begin(); itr != lst.end(); ++itr)
	{
		if (itr != lst.begin())
		{
			std::cout << " ";
		}
		std::cout << *itr;
	}
	std::cout << std::endl;

	return;
}

int main(void)
{
	int m;
	int n;

	while (std::cin >> m >> n && m != 0 && n != 0)
	{
		fizzbuzz(m, n);
	}
	return 0;
}



Measured memory_bytes: 3268
def f(W):
    if len(set(W)) != len(W):
        return False
    return all(w1[-1] == w2[0] for w1, w2 in zip(W, W[1:]))

N = int(input())
W = tuple(input() for _ in range(N))
print('Yes' if f(W) else 'No')

Measured memory_bytes: 3060
#line 1 "main_a.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

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

  std::string s;
  std::cin>>s;

  if(s.back()=='s')s+="es";
  else s+="s";

  std::cout<<s<<"\n";
  
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define cps2(x, y) sort(all(x), y), (x).erase(unique(all(x)), end(x))
#define mem(x, y) memset(& x, y, sizeof(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int a[103], b[103];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	int n; cin >> n;
	ll ans =0 ;
	for (int i = 1; i <= n; i++)
		ans += (n - i + (i - 1)) / i;
	cout << ans;
}


Measured memory_bytes: 3652
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):  # 区間 [1, i]の和
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):  # iにxを加算
        while i <= self.size:
            self.tree[i] += x
            i += i & -i  
    def pos(self, idx):  # idxの値を取得
        return self.sum(idx) - self.sum(idx-1)
    def lower_bound(self, w):  # w以上の値を持つ最小のidxを検索
        if w <= 0:
            return 0
        idx = 0
        k = 1
        while k*2 <= self.size:
            k *= 2
        while k > 0:
            if idx+k <= self.size and self.tree[idx+k] < w:
                w -= self.tree[idx+k]
                idx += k
            k //= 2
        return idx+1

N, Q = MAP()
c = LIST()
ps = [[] for _ in range(N+1)]
qs = [[] for _ in range(N+1)]
for i in range(Q):
    l, r = MAP()
    qs[l].append((r, i))

checked = [-1]*(N+1)
for i, x in enumerate(c):
    if checked[x] != -1:
        ps[checked[x]].append(i+1)
    checked[x] = i+1

ans = [-1]*Q
bit = Bit(N)

for x in range(N, 0, -1):
    for y in ps[x]:
        bit.add(y, 1)
    for r, i in qs[x]:
        ans[i] = r-x+1-bit.sum(r)

print(*ans, sep="\n")


Measured memory_bytes: 229048
#include<stdio.h>
int a[200001];
int main()
{
	int n,i,j;
	scanf("%d",&n);
	int t;
	for(i=1;i<n+1;i++)
    {
    	scanf("%d",&t);
    	if(n%2==0)
    	{
    		if(i%2==1)
    		a[n/2+i/2]=t;
    		else
    		a[n/2-i/2]=t;
		}
		else
		{
			if(i%2==1)
			a[n/2-i/2]=t;
			else
			a[n/2+i/2]=t; 
		}
	}
	for(i=0;i<n;i++)
	    printf("%d ",a[i]);
	return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int DP[60][2600];

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

	int N, A;
	int X[60];

	cin >> N >> A;
	rep(i, 0, N)
	{
		cin >> X[i];
	}

	DP[0][0] = 1;

	rep(k, 0, N)
	{
		rrep(i, 0, N)rrep(j, 0, 2600)
		{
			if (DP[i][j] == INF)continue;
			DP[i + 1][j + X[k]] += DP[i][j];
		}
	}

	int ans = 0;
	rep(i, 1, N + 1)
	{
		if (DP[i][A*i] != INF)
		{
			ans += DP[i][A*i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <cmath>
#include <string.h>
#include <stdio.h>

using namespace std;

int main(){

  int N;
  string S;
  
  cin >> N >> S;
  
  int cnt =0;
  for(int i=0; i<N; i++){
    if(i<2)
      continue;
    if(S.at(i-2)== 'A' && S.at(i-1)== 'B' && S.at(i) == 'C')
       cnt++;
  }
  
  
  cout << cnt << endl;
  

  
  return 0;
  
}


Measured memory_bytes: 3160
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int64_t n, d;
	cin >> n >> d;

	d *= d;
	int res = n;
	while(n--) {
		int64_t x, y;
		cin >> x >> y;
		x *= x;
		y *= y;
		res -= ((x + y) > d);
	}
	cout << res << '\n';
}

Measured memory_bytes: 3620
//GCD FREQUENCY COUNTER WITH INC-EXC BY ADANCITO

//WHAT DOES THIS ALGORITHM DO?
/*
 
 imagine that for every ordered pair (i, j), 0 <= i, j <= maxN, we did
 res[gcd(i, j)] += one[i] * two[j]
 
 this algorithm calculates the final value of res in O(nlgn)
 
 remember to call precalculations() at the beginning of the program
 
 */

#include <iostream>
#include <string.h>
#include <ctime>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <set>
#include <map>
#include <vector>

using namespace std;
const int maxN = 1e5 + 9, MOD = 1e9 + 7;

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

int n, arr[maxN];

int gcd(int a, int b){
    if(a == 0) return b;
    return gcd(b % a, a);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    cin >> n;
    cin >> arr[n++];
    
    for(int i = 0; i + 1 < n; i++){
        cin >> arr[i];
    }
    
    sort(arr, arr + n);
    
    int ans = 0;
    
    for(int i = 1; i < n; i++){
        ans = gcd(ans, arr[i] - arr[i - 1]);
    }
    
    cout << ans << '\n';
    
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
using namespace  std;
using ll = long long;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define ALL(a) (a).begin(),(a).end()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

int main(){
    ll N, K;
    cin>>N>>K;
    vector<ll> A(N);
    ll S = 0;
    REP(i, N){
        cin>>A[i];
        S += A[i];
    }
    vector<ll> fac;
    for(int i=1; i*i<=S; i++){
        if(S%i==0){
            fac.emplace_back(i);
            if(i*i!=S) fac.emplace_back(S/i);
        }
    }
    ll res = 0;
    vector<ll> R(N);
    vector<ll> CS(N+1);
    for(auto &d: fac){
        REP(i, N){ R[i] = A[i] % d; }
        sort(ALL(R));
        REP(i, N) CS[i+1] = CS[i] + R[i];
        bool ok = false;
        if(R[N-1]==0) ok = true;
        for(int i=1; i<N and !ok; i++){
            if(CS[i]<=K and CS[i] == (N-i)*d-(CS[N]-CS[i])){
                ok = true;
                break;
            }
        }
        if(ok) res = max(res, d);
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  for (int i = A; i <= A * B; i+=A) {
    if (i % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
vvv = list(map(int, input().split()))
vvv.sort()

new_vvv = vvv
for _ in range(N - 1):
    merged = sum(new_vvv[:2]) / 2
    new_vvv = [merged] + new_vvv[2:]
    new_vvv.sort()

print(new_vvv[0])


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
#include <math.h>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007
#define NIL -1


int main(){
  int N;
  ll T=1,A=1;
  ll t,a;

  cin>>N;

  ll j;
  rep(i,N){
    ll x,y;
    cin>>x>>y;
    if(A%x==0) a=A/x;
    else a=A/x+1;
    if(T%y==0) t=T/y;
    else t=T/y+1;
    j=max(a,t);
    A=x*j;
    T=y*j;
  }
  print(A+T);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;


int main()
{
    int A,B,C;
    cin>>A>>B>>C;
    if( (A==5 && B==7 && C==5)||
        (A==5 && B==5 && C==7)||
        (A==7 && B==5 && C==5) ) cout<<"YES\n";
    else cout<<"NO\n"; 

    return 0;
}

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

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

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

    sort(a.rbegin(), a.rend());

    ll w = 0, h = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i-1] == a[i]) {
            if (w == 0) {
                w = a[i];
                i++;
            }
            else if (h == 0) {
                h = a[i];
                break;
            }
        }
    }

    cout << w * h << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=105;
const int inf=1e9+9;
int tab[MAX][MAX];
int f[MAX][MAX];
int32_t main()
{
  BOOST;
  int n,m;
  cin>>n>>m;
  for (int i=1;i<=n;i++)
  	for (int j=1;j<=m;j++)
  		cin>>tab[i][j];
  for (int i=0;i<=100;i++)
    for (int j=0;j<=100;j++)
       for (int k=1;k<=n;k++)
         for (int l=1;l<=m;l++)
           f[i][j]=max(f[i][j],tab[k][l]-i*k-j*l);
           
  for (int i=1;i<=n;i++)
    for (int j=1;j<=m;j++)
    {
    	int mini=inf;
    	for (int k=0;k<=100;k++)
    	  for (int l=0;l<=100;l++)
    	    mini=min(mini,f[k][l]+i*k+j*l);
    	if (mini!=tab[i][j])cout<<"Impossible",exit(0);
    }
   
    cout<<"Possible\n";
  cout<<"202 "<<"10401\n";
  for (int i=1;i<=100;i++)cout<<i<<" "<<i+1<<" "<<"X"<<"\n";
  for (int i=102;i<=201;i++)cout<<i<<" "<<i+1<<" "<<"Y"<<"\n";
  for (int i=0;i<=100;i++)
    for (int j=0;j<=100;j++)
      cout<<i+1<<" "<<202-j<<" "<<f[i][j]<<"\n";
  cout<<"1 "<<"202";
  
  return 0;
}



Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<iostream>
#define ll long long
using namespace std;
char s[100007];
int ans;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%s",s);
	int l=strlen(s);
	for(int i=0;i<l;i++) 
		if(s[i]!=s[l-1-i])	
			ans++;
	printf("%d\n",ans/2);
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.algorithm, std.array;


void main()
{
        long xs[100010];
        long n, k;

        scanf("%ld %ld", &n, &k);

        for (int i = 0; i < n; i++) {
                int a, b;

                scanf("%d %d", &a, &b);
                xs[a] += b;
        }

        int i = -1;
        while (k > 0) {
                i++;
                k -= xs[i];
        }
        writeln(i);
}

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

int main(){
	int N, M; std::cin >> N >> M;
	std::vector<int> A(M);
	std::vector<int> B(M);
	for (int i = 0; i < M; ++i)
		std::cin >> A[i] >> B[i];
	for (int num = 0; num < N; ++num) {
		int count = 0;
		for (int j{ 0 }; j < M; ++j) {
			if (A[j] == num + 1) ++count;
			if (B[j] == num + 1) ++count;
		}
		std::cout << count << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
import sys

NO = "IMPOSSIBLE"  # type: str


def solve(A: int, B: int):
    K = (A + B) // 2
    return K if abs(A-K) == abs(B-K) else NO

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(A, B))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
//   __                    .__              ________ .________ ________   ______  
//  |  | __  ____    ______|  |__   __ __  /  _____/ |   ____//   __   \ /  __  \ 
//  |  |/ /_/ __ \  /  ___/|  |  \ |  |  \/   __  \  |____  \ \____    / >      < 
//  |    < \  ___/  \___ \ |   Y  \|  |  /\  |__\  \ /       \   /    / /   --   \
//  |__|_ \ \___  >/____  >|___|  /|____/  \_____  //______  /  /____/  \______  /
//       \/     \/      \/      \/               \/        \/                  \/ 

#include<bits/stdc++.h>
#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int n;

int indx[1010][1010];

int eges[1010][1010];

vi graph[1000010];

int indeg[1000010];

int vis[1000010];

map<ii,bool> m;

int color[1000010];

bool dfs(int v){
	color[v] = 1;
	for(auto u:graph[v]){
		if(color[u]==0){
			if(dfs(u))
			  return true;
		}
		else if(color[u]==1)
			return true;
	}
	color[v] = 2;
	return false;
}

int dp[1000010];

void diam(int v){
	vis[v] = 1;
	for(int u:graph[v]){
		if(vis[u]==0)
			diam(u);
		dp[v] = max(dp[v],dp[u] + 1);
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	cin>>n;
	int loli = 1;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			indx[i][j] = loli;
			indx[j][i] = loli;
			loli++; 
		}
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<n;j++){
			int x;
			cin>>x;
			int index = indx[i][x];
			eges[i][j] = index; 
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j+1<n;j++){
			ii point1 = {eges[i][j],eges[i][j+1]};
			if(m.find(point1)==m.end()){
				m[point1] = 1;
				graph[eges[i][j]].pb(eges[i][j+1]);
				indeg[eges[i][j+1]]+=1;
			}
		}
	}
	for(int i=1;i<loli;i++){
		if(indeg[i]==0){
			graph[0].pb(i);
		}
	}
	if(dfs(0)==true){
		cout<<-1;
		return 0;
	}
	diam(0);
	if(dp[0]==0){
		cout<<-1;
		return 0;
	}
	cout<<dp[0]<<endl;
	return 0;
}


Measured memory_bytes: 125312
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a+b < c+d) cout << "Right" << endl;
    else if(a+b > c+d) cout << "Left" << endl;
    else cout << "Balanced" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
    using namespace std;
    #define N 1050000
    #define mod 1000000007
    int dp[N][2],n,s[N],las[N],k=20,sn;
    int main()
    {
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++)scanf("%d",&s[i]);
    	for(int i=0;i<1<<k;i++)dp[i][0]=1;
    	for(int i=1;i<n;i++)
    	{
    		s[i]^=s[i-1];
    		dp[s[i]][0]=(dp[s[i]][0]+1ll*dp[s[i]][1]*(sn-las[s[i]]))%mod;
    		dp[s[i]][1]=(dp[s[i]][1]+dp[s[i]][0])%mod;
    		las[s[i]]=sn;
    		if(s[i]==0)sn++;
    	}
    	s[n]^=s[n-1];
    	if(s[n])
    	{
    		int ans=0;
    		dp[s[n]][0]=(dp[s[n]][0]+1ll*dp[s[n]][1]*(sn-las[s[n]]))%mod;
    		printf("%d\n",dp[s[n]][0]);
    	}
    	else
    	{
    		int ans=0;
    		for(int i=1;i<1<<k;i++)
    		ans=(ans+dp[i][1])%mod;
    		int tp=1;
    		for(int i=1;i<=sn;i++)tp=tp*2%mod;
    		printf("%d\n",(ans+tp)%mod);
    	}
    }

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

#include <vector>
#include <iostream>

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

using namespace std;

typedef long long ll;

/*
vector.push_back()
vector<int> hoge(3,-1); {-1,-1,-1}
vector<vector<int>> hogehoge(2,vector<int>(2,-1)); {{-1,-1},{-1,-1}} 
cin >>temp;
scanf("%d %d %d",&A,&B,&Q);
sort(a.begin(),a.end());
a.push_back(4000000000000);
a.insert(a.begin(),-1000000000000);
upper_bound(a.begin(),a.end(),x); // list[i] > x のイテレータ取得. *itrで数値化 
    std::priority_queue<
      int,
      std::vector<int>,
      decltype(compare) // 比較関数オブジェクトを指定
    > que(comp);
*/
template <typename T> void debug(T arr);
template <typename T> void debug (T arr, int dim);



int main(void){
    vector<ll> arr(4);
    rep(i,4){
        scanf("%lld",&arr[i]);
    }
    vector<ll> tar;
    tar.push_back(1);
    tar.push_back(7);
    tar.push_back(9);
    tar.push_back(4);

    bool flag = true;
    rep(i,4){
        ll count = 0;
        rep(j,4){
            if(tar[i] == arr[j]){
                count += 1;
            }
        }
        if (count != 1){
            flag = false;
        }
    }
    if (flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }



};


template <typename T> void debug(T arr){
    for (auto col:arr){
        cout << col << " ";
    }
    cout <<endl;
};

template <typename T> void debug (T arr, int dim){
    for (auto raw:arr){
        for(auto col:raw){
            cout << col << " ";
        }
        cout << endl;
    }
};


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

A = [0]*N

for i in range(N):
    if i==0:
        A[i] = B[i]
    elif i==N-1:
        A[i] = B[i-1]
    else:
        A[i] = min(B[i],B[i-1])

print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
int main() 
{
    ll n,m,x=0,sum=0;
    cin>>n>>m;
    ll a[n];
    rep(i,n)cin>>a[i],sum+=a[i];
    rep(i,n)x+=(a[i]*4*m>=sum);
    yn(x>=m);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <iomanip>




using namespace std;



using ll = long long;
const ll INF = 1e18L + 5;
const int mod = 1e9 + 7;

ll dp[2100000];// < 2^21
ll n;
int tab[40][40];

int main(){

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> tab[i][j];
        }
    }
    
    dp[0] = 1;
    //for(int a = 0; a < n; a++){
    for(int mask = 0; mask < (1 << n) - 1; mask++){// 1 << n all possibilities
        int a = __builtin_popcount(mask);
        for(int b = 0; b < n; b++){
            if(tab[a][b] && !(mask & (1 << b))){
                int m2 = mask ^ (1 << b);//sprawdzic czy & tez bd dzialac
                
                dp[m2] += dp[mask];
                if(dp[m2] >= mod){
                    dp[m2] -= mod;
                }
            }
        }
    }
    
    
    cout << dp[(1 << n) - 1];
}



Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)

const long double PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);

int n, ans = 1e9;

int sumacif(int q){
    int s = 0;
    while (q){
        s += q%10;
        q /= 10;
    }
    return s;
}

int main(){
    //ifstream cin ("date.in");
    cin >> n;
    for (int i=1; i<=n/2; i++) ans = min(ans, sumacif(i) + sumacif(n-i));
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin>>n;
    vector <long long> edge;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        edge.push_back(a);
    }
    int x=0;
    vector <long long> tmp(2,0);
    sort(edge.begin(),edge.end());
    reverse(edge.begin(),edge.end());
    for(int i=0;i<edge.size()-1;i++){
        //cout<<edge[i]<<endl;
        if(edge[i]==edge[i+1]){
            tmp[x++]=edge[i];
            i++;
        }
        if(x==2) break;
    }
    cout<<tmp[0]*tmp[1]<<endl;
}


Measured memory_bytes: 1400
import sys

lines = sys.stdin.readlines()
for line in lines:
    a, b, c, d, e, f = map(float, line.split())
    A = a * e - b * d
    if A == 0:
        break
    x = (c * e - b * f) / A
    y = (a * f - c * d) / A
    print('{:.3f} {:.3f}'.format(x+0, y+0))

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

cnt = 0
L = [0] * (N + 1)
for a in A:
    L[a] += 1

for l in L:
    cnt += l * (l - 1) // 2

for a in A:
    ans = cnt - (L[a] * (L[a] - 1) // 2) + ((L[a] - 1) * (L[a] - 2) // 2)
    print(ans)

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

int main() {

  double L;
  cin >> L;

  double num = L/3;
  double ans = num * num * num;

  cout << fixed << setprecision(8) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
	int n;
	int i,j,count=0;
	scanf("%d",&n);
	int a[n];
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		for(j=2;j<sqrt(a[i])+1;j++){
			if(a[i]==2){
				break;
			}
			if(a[i]%j==0){
				count++;
				break;
			}
		}
	}
	
	printf("%d\n",n-count);
	
	return 0;
	
}

Measured memory_bytes: 1808
N=int(input())
A=[int(i) for i in input().split()]
count=0
for i in range(N):
    min=i
    for j in range(i,N):
        if A[j] < A[min]:
            min=j
    if i<min:
        count+=1
        A[i],A[min]=A[min],A[i]
for k in range(N):print(A[k],end=' \n'[k+1==N])
print(count)


Measured memory_bytes: 5612
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

a,b = map(int,input().split())
if a*b<0:
    print("Zero")
if a>0:
    print("Positive")
if b<0:
    cnt = b-a + 1
    if cnt %2 == 1:
        print("Negative")
    else:
        print("Positive")

Measured memory_bytes: 21540
# ABC116c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
h = list(map(int, input().split()))

ans = 0
mode = 0

for i in h:
    while i > mode:
        mode += 1
        ans += 1
    while i < mode:
        mode -= 1
print(ans)


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

int main() {
  int n; cin>>n;
  vector<int> l(n), r(n);
  rep(i, n) cin>>l[i]>>r[i];
  ll ans = 0;
  rep(i, n) ans+=r[i]-l[i]+1;
  cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 5000
#define MOD 1000000007

int main(){
  int N,M;
  cin>>N>>M;
  vector<ll> A(N);
  vector<pair<ll,ll>> CB(M);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<M;i++){
    cin>>CB.at(i).second>>CB.at(i).first;
  }
  sort(A.begin(),A.end());
  sort(CB.begin(),CB.end());
  reverse(CB.begin(),CB.end());

  int k=0;
  for(int i=0;i<M;i++){
    bool flag=false;
    for(int j=0;j<CB.at(i).second;j++){
      if(A.at(k)<CB.at(i).first){
        A.at(k)=CB.at(i).first;
        k++;
        if(k==N){
          flag=true;
          break;
        }
      }else{
        flag=true;
        break;
      }
    }
    if(flag){
      break;
    }
  }

  ll ans=0;
  for(int i=0;i<N;i++){
    ans+=A.at(i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
contain_5_7_5 :: [Int] -> Bool
-- Implement code below
contain_5_7_5 arr = cnt 5 arr == 2 && cnt 7 arr == 1
cnt x = length.filter (==x)




-- IO related, you don't have to modify it.
main = getLine >>= putStrLn. f. contain_5_7_5. map read. words
  where f True = "YES"
        f False = "NO"


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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        String S;
        S = sc.next();

        final Solver solver = new Solver();
        solver.solve(N, S);
    }
}

class Solver {
    public void solve(long N, String S) {
        for (int i = 0; i < S.length(); i++) {
            int up = (int) ((S.charAt(i) - 'A' + N) / 26);
            char alpha = (char) (S.charAt(i) + N - up * 26);

            System.out.print(alpha);
        }
        System.out.println();
    }
}



Measured memory_bytes: 25812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll modpow(ll a, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }

    return res;
}

ll comb(ll a, ll b) {
    ll ans = 1;

    for(ll i = a; i > a - b; i--) {
        ans = ans * i % mod;
    }
    for(ll i = 1; i <= b; i++) {
        ans = (ans * modpow(i, mod - 2)) % mod;
    }
    return ans;
}

int main() {
  ll N;
  cin >> N;
  ll num[10][10];
  for(int i = 0; i < 10; i++) {
      for(int j = 0; j < 10; j++) {
          num[i][j] = 0;
      }
  }
  for(ll i = 1; i <= N; i++) {
     string str = to_string(i);
     int size = str.size();
     const char* cstr = str.c_str();
     string f(cstr, 0, 1);
     string e(cstr, size - 1, 1);
    int a = stoi(f);
    int b = stoi(e);
      num[a][b] += 1;
  }
    ll ans = 0;
  for(int i = 1; i <= N; i++) {
    string str = to_string(i);
     int size = str.size();
     const char* cstr = str.c_str();
     string f(cstr, 0, 1);
     string e(cstr, size - 1, 1);
    int a = stoi(f);
    int b = stoi(e);
      
      ans += num[b][a];
  }

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n, a[50000], m, sum;
int main() {
	while (true) {
		sum = 0;
		cin >> n >> m;
		if (n == 0 && m == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (a[i] + a[j]>m) { sum += n - j; break; }
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1220
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<cctype>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll i;
    ll tmp=1,A;
    for(i=0;i<N;i++){
        cin >> A;
        if(A%2==0)tmp*=2;
    }
    cout << pow(3,N)-tmp;
    return 0;
}

Measured memory_bytes: 384
INF = 10**10
while(True):
    N, M = [int(n) for n in input().split()]
    if N + M == 0:
        break
    chair = ["#" for _ in range(N)]
    for i in range(M):
        a = str(input())
        if a == "A":
            for i in range(N):
                if chair[i] == "#":
                    chair[i] = "A"
                    break
        elif a == "B":
            OK = False
            for i in range(N-1, -1, -1):
                if chair[i] == "#":
                    if i != 0 and chair[i-1] == "A":
                        continue
                    if i != N-1 and chair[i+1] == "A":
                        continue
                    chair[i] = "B"
                    OK = True
                    break
            if OK:
                continue
            for i in range(N):
                if chair[i] == "#":
                    chair[i] = "B"
                    break
        elif a == "C":
            if chair.count("#") == N:
                chair[(N)//2] = "C"
                continue
            OK = False
            for i in range(N):
                if chair[i] != "#":
                    if i != N-1 and chair[i+1] == "#":
                        chair[i+1] = "C"
                        OK = True
                        break
                    if i != 0 and chair[i-1] == "#":
                        chair[i-1] = "C"
                        OK = True
                        break
        elif a == "D":
            if chair.count("#") == N:
                chair[0] = "D"
                continue
            start = False
            distmap = [0 for _ in range(N)]
            dist = 0
            for i in range(N):
                if chair[i] != "#":
                    dist = 0
                    distmap[i] = dist
                    start = True
                elif start:
                    dist += 1
                    distmap[i] = dist
                else:
                    distmap[i] = INF
            start = False
            for i in range(N-1, -1, -1):
                if chair[i] != "#":
                    dist = 0
                    distmap[i] = min(dist, distmap[i])
                    start = True
                elif start:
                    dist += 1
                    distmap[i] = min(dist, distmap[i])
            target = max(distmap)
            for i in range(N):
                if distmap[i] == target and chair[i] == "#":
                    chair[i] = "D"
                    break
    print("".join(chair))



Measured memory_bytes: 5620
import sys
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
d = dict()

for a in A:
   d[a] =  d.get(a,0) + 1

for _ in range(M):
    b,c = [int(x) for x in input().split()]
    d[c] = d.get(c,0) + b


T = list(d.items())
T = sorted(T,reverse=True)

ans = 0
cnt = 0
for k,v in T:
    for _ in range(v):
        ans += k
        cnt += 1
        if cnt == N:
            print(ans)
            sys.exit(0)


Measured memory_bytes: 42400
from math import atan2,pi

a,b,x = map(int,input().split())
S = x/a #平面の面積

if a*b == S:
    ans = 0
elif S <= a*b/2:
    a = S/(b/2)
    ans = atan2(b,a)*180/pi
else:
    bu = 2*S/a-b
    b = b-bu
    S -= a*bu
    ans = atan2(b,a)*180/pi
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    #ifdef TarekHasan
        freopen("input.txt","r",stdin);
    #endif // TarekHasan

    int v,e; cin >> v >> e;
    unordered_map< int , vector< int > > adjacentList;
    for(int i=0;i<e;i++)
    {
        int u,v; cin >> u >> v;
        adjacentList[u].push_back(v);
        adjacentList[v].push_back(u);
    }
    int parent[v+1];
    int visited[v+1];

    for(int i=1;i<=v;i++)
    {
        parent[i]=-1;
        visited[i]=0;
    }

    queue< int > q;
    q.push(1);
    visited[1]=1;
    parent[1]=1;

    while(!q.empty())
    {
        int top = q.front();
        q.pop();

        for(int x : adjacentList[top])
        {
            if(visited[x]==0)
            {
                visited[x]=1;
                parent[x]=top;
                q.push(x);
            }
        }
    }

    bool possible = true;

    for(int i=2;i<=v;i++)
    {
        if(parent[i]==-1)
        {
            possible = false;
            break;
        }
    }

    if(possible)
    {
        cout << "Yes\n";
        for(int i=2;i<=v;i++)
            cout << parent[i] << endl;
    }
    else
        cout << "No\n";
    return 0;
}


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


#define REP(var, init, num) for(int var = init ; var < num; var ++)

int main(){
    string n;
    int k;

    cin >> n;
    cin >> k;

    int dig = n.size();
    int dp0[dig+1][k+2];
    int dp1[dig+1][k+2];
    
    memset(dp0, 0, sizeof(int)*(dig+1)*(k+2));
    memset(dp1, 0, sizeof(int)*(dig+1)*(k+2));
    dp1[0][0] = 1;

    for(int i=1; i<=dig; i++){
        int hi = stoi(n.substr(i-1,1));

        for(int j=0; j<=9; j++){
                if(j < hi){
                    if(j == 0){
                        REP(jj, 0, k+2) {
                            dp0[i][jj] += dp0[i-1][jj];
                            dp0[i][jj] += dp1[i-1][jj];
                        }
                    }else{
                        REP(jj, 0, k){
                            dp0[i][jj+1] += dp0[i-1][jj];
                            dp0[i][jj+1] += dp1[i-1][jj];
                        }
                        dp0[i][k+1] += dp0[i-1][k+1];
                        dp0[i][k+1] += dp1[i-1][k+1];
                    }
                }else if(j == hi){
                    if(j == 0){
                        REP(jj, 0, k+2) {
                            dp0[i][jj] += dp0[i-1][jj];
                            dp1[i][jj] += dp1[i-1][jj];
                        }
                    }else{
                        REP(jj, 0, k){
                            dp0[i][jj+1] += dp0[i-1][jj];
                            dp1[i][jj+1] += dp1[i-1][jj];
                        }
                        dp0[i][k+1] += dp0[i-1][k+1];
                        dp1[i][k+1] += dp1[i-1][k+1];
                    }
                }else{
                    REP(jj, 0, k) {
                        dp0[i][jj+1] += dp0[i-1][jj];
                    }
                    dp0[i][k+1] += dp0[i-1][k+1];
                }
            
        }
    }

    cout << (dp0[dig][k] + dp1[dig][k]) << endl;

    return 0;
}

Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())

c *= 2
t = 0

if a+b > c:
  v = min([x,y])
  t = v * c
  x, y = x-v, y-v

  if x>0:
    if a<c:
      t = t + a*x
    else:
      t = t + c*x
  elif y>0:
    if b<c:
      t = t + b*y
    else:
      t = t + c*y
else:
  t = a*x + b*y

print(t)


Measured memory_bytes: 9216