akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <limits.h>
#include <memory.h>


using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef vector<double> vec;
typedef vector<vec> mat;

ll n,t;
ll a,b;

int main() {

	cin>>n>>t;
	cin >> a;
	ll ans=t;
	FORI(1,n){
		cin>>b;
		ans += min(t,b-a);
		a=b;
	}
	cout << ans << endl; 
	return 0;
}




Measured memory_bytes: 256
N, M = map(int, input().split())
A = [list(input()) for i in range(N)]

B = [list(input()) for i in range(M)]
temp = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        for row in range(M):
            for col in range(M): 
                if A[i+row][j+col] == B[row][col]:
                    temp +=1
                    if temp == M*M:
                        print('Yes')
                        exit()
                    continue
                else:
                    temp = 0
                    break
     
            
print('No')


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

int main(){
	int i, j, k ,n,m,l,f;
	char s;
	cin >> s;
	if(s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u') cout << "vowel" << endl;
	else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K,sum=0,ans=0;
  cin>>N>>K;
  vector<int>a(N);
  vector<int>num(200000,0),count(200000,0);
  for(int &i:a)cin>>i;
  for(int i=0;i<N;i++)num.at(a.at(i))++;
  sort(num.begin(),num.end());
  reverse(num.begin(),num.end());
  for(int i=0;i<200000;i++){
    if(i>(K-1)&&num.at(i)>0){
      while(num.at(i)>0){
        sum++;
        num.at(i)--;
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 2560
// I am Varun Das from Jadavpur University
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define dbg(x) cerr << #x << " = " << x << endl
#define INF LLONG_MAX
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<fixed<<setprecision(12);
int n;
cin>>n;
int a[13];
loop(i,0,n) cin>>a[i];
sort(a,a+n);
int sum=0;
loop(i,0,n-1) sum+=a[i]; 
(a[n-1] < sum) ? cout<<"Yes" : cout<<"No";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())

def z_algorithm(S):
    N = len(S)
    A = [0] * N
    i = 1
    j = 0
    A[0] = l = len(S)
    while i < l:
        while i + j < l and S[j] == S[i + j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l - i > k < j - A[k]:
            A[i + k] = A[k]
            k += 1
        i += k
        j -= k
    tmp = 0
    for index, a in enumerate(A):
        if a <= index:
            tmp = max(tmp, a)
    # print (A)
    return tmp

ans = 0
for i in range(N):
    ans = max(ans, z_algorithm(S[i:]))

print (ans)

Measured memory_bytes: 50140
import math
a, b = map(int, input().split())
A = 0
if b <10:
  A = a * 10 + b
elif b < 100:
  A = a * 100 + b
else:
  A = a * 1000 + b
A_sq = math.ceil(math.sqrt(A))
Ans = "No"
for i in range (1, A_sq+2):
  if i**2 == A:
    Ans = "Yes"
print(Ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

string S, T;


int main(void) {

	cin >> S >> T;

	int N = S.size();

	int ans = 0;

	for (int i = 0; i < N; i++) {
		if (S[i] != T[i]) { ans++; }
	}

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

Measured memory_bytes: 3844
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;



#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define int ll
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+10;


int32_t main()
{

  int x;
  cin>>x;
  int ans  = (x/500)*1000 + ((x%500)/5)*5;
  cout<<ans<<endl;
  
  








}


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

#define int 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; }

int val[70][100010];
int nxt[70][100010];

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


	for(int i = 0;i < m;i++){
		val[0][i] = i;
		nxt[0][i] = (i*i) % m;
	}


	for(int b = 1;b <= 60;b++){
		for(int i = 0;i < m;i++){
			val[b][i] = val[b-1][i] + val[b-1][nxt[b-1][i]];
			nxt[b][i] = nxt[b-1][nxt[b-1][i]];
		}
	}

	int ans = 0;
	int idx = x;
	for(int b = 0;b <= 60;b++){
		if(n & (1ll << b)){
			ans += val[b][idx];
			idx = nxt[b][idx];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 98936
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

using S = ll;
using F = ll;
S op(S a, S b){ return max(a, b); }
S e(){ return 0LL; }
S mapping(F f, S x){ return max(x,f); }
F composition(F f, F g){ return max(f,g); }
F id(){ return 0; }

ll N,K;
ll A[300010];

int main(){
    cin >> N >> K;
    ll M = -1;
    rep(i,N){
        cin >> A[i];
        M = max(M,A[i]);
    }
    vector<ll> B(M+10,0LL);
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(B);
    rep(i,N){
        seg.apply(A[i],seg.prod(max(0LL,A[i]-K),min(M+1,A[i]+K+1))+1LL);
        /*rep(j,M+1){
            cout << seg.get(j) << ' ';
        }
        cout << endl;*/
    }
    cout << seg.prod(0,M) << endl;
}




Measured memory_bytes: 20192
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        long L = scanner.nextLong();
        long R = scanner.nextLong();

        long min = Long.MAX_VALUE;
        for (long i = L; i < R; i++) {
            for (long k = i+1; k <= R; k++) {
                long result = mod2019(i * k);
                if (result < min) {
                    min = result;
                    if (min <= 0) {
                        System.out.println("0");
                        return;
                    }
                }
            }
        }
        System.out.println(min);
    }

    private static long mod2019(long hoge) {
        return hoge % 2019;
    }
}

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

using ll=long long;

using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;

int main() {
  double D,T,S; cin >>D >>T >>S;
  cout <<((D/S)<=T ? "Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3716
#include <stdio.h>

int main(){
  int A[100],i,j,minj,temp,N,count=0,n;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])minj=j;
    }
    temp=A[i];
    A[i]=A[minj];
    A[minj]=temp;
    if(i!=minj) count++;
  }

  for(n=0;n<N-1;n++){
    printf("%d ",A[n]);
  }
   printf("%d",A[N-1]);
   printf("\n%d\n",count);

  return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  stack<int> n;
  int a;
  while(cin >> a){
    if(a != 0)n.push(a);
    else{
      cout << n.top()<<endl;
      n.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 3104
# -*- coding: utf-8 -*-
# abc126/abc126_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))


def main():
    S = i2s()
    front = int(S[:2])
    back = int(S[2:])
    if MM(front) and MM(back):
        print('AMBIGUOUS')
    elif MM(front) and not MM(back):
        print('MMYY')
    elif not MM(front) and MM(back):
        print('YYMM')
    else:
        print('NA')

def MM(num):
    return 1 <= num <= 12

main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#define ll long long 

using namespace std;




int main(){
	string s;
	cin >> s;
	ll sum = 0;
	for (int i = 0; i < 1 << (s.length() - 1); ++i)
	{
		string tmp;
		for (int j = 0; j < s.length(); ++j)
		{
			tmp.push_back(s[j]);
			if(i >> j & 1){
				tmp.push_back('+');
			}
		}
		// cout << tmp << endl;
		int tmp_count = 0;
		for (int j = tmp.length()-1; j >= 0 ; --j)
		{
			if(tmp[j] != '+'){
				sum += ((ll)(tmp[j] - '0') * pow(10, tmp_count));
				// cout << ((int)(tmp[j] - '0') * pow(10, tmp_count)) << endl;
				tmp_count++;
			}else{
				tmp_count = 0;
			}
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 512
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//関係性は隣接行列で記録
//過半数：N/2.0で判定
//ある量からある量を引く系の問題：端から定義してやる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll 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;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N, K; cin >> N >> K;

	map<ll,ll> p;
	rep(i, K) {
		ll d; cin >> d;
		vector<ll> A(d);
		rep(i, d) {
			cin >> A[i];
			p[A[i]] = 1;
		}
	}

	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		if (p[i] == 0) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 10916
import sys
sys.setrecursionlimit(10**6)

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

ans = 0

for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        ans += 1
        
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

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

    int n;
    string s;
    vector<int> ans;

    int fb = -1;
    int cw = 0, cb = 0;

    cin >> n;
    cin >> s;

    vector<int> ss(n+1);
    ss[0] = 0;
    for (int i = 0; i < n; i++)
    {
        ss[i+1] = ss[i] + (s[i] == '#');
    }

    for (int i = 0; i < n; i++)
    {
        if (s[i] == '#')
        {
            // for (int j = 0; j < n; j++)
            // {
            //     if (s[j] == '#')
            //     {
            //         if (j < i)
            //             lb++;
            //         else
            //             rb++;
            //     }
            // }
            int lb;
            if(i==0)
                lb = 0;
            else
                lb = ss[i] - ss[0];
            const int rb = ss[n] - ss[i];

            const int ln = i, rn = n - i;
            const int lw = ln - lb, rw = rn - rb;
            const int ww = lb + rb;
            const int wb = lb + rw;
            const int bb = lw + rw;
            ans.push_back(min(min(ww, wb), bb));
        }
    }

    if (ans.empty())
        cout << 0 << endl;
    else
        cout << *min_element(ans.begin(), ans.end())<<endl;

    return 0;
}


Measured memory_bytes: 2448
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <stack>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

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

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }


int main()
{
	string s; cin >> s;
	const ll n = s.size();
	s = '*' + s;

	auto fail = []() {
		cout << -1 << endl;
		exit( 0 );
	};

	if ( s[1] == '0' || s[n] == '1' )
		fail();
	reps( i, n - 1 ) if ( s[i] != s[n - i] ) fail();

	s[n] = '1';
	queue<ll> q;
	reps( i, n )
	{
		if ( s[i] == '1' )
			q.push( i );
	}

	reps( i, n - 1 )
	{
		if ( i == q.front() )
			q.pop();
		cout << i << " " << q.front() << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 4088
#include<iostream>
using namespace std;
int a[109],n;
int main(){
  cin>>n;
  int cnt=0;
  for(int i=1,t;i<=n;i++)cin>>t,a[t]=i,cnt+=(i!=t);
  if(cnt==0||cnt==2)puts("YES");
  else puts("NO");
  return 0;
}

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

map<string, int> pre;

std::vector<string> splitAll(string s,string t){
  std::vector<string> v;
  for(int p=0; (p = s.find(t)) != s.npos; ){
    v.push_back(s.substr(0,p));
    s=s.substr(p+t.size());
  }
  v.push_back(s);
  return v;
}

int significantFigure(string num) {
    int p = 0;
    bool fp = false;
    while(num[p] == '0' || num[p] == '.') {
        if(num[p] == '.') fp = true;
        p++;
    }
    return num.length()-p-((num.find('.')!=string::npos && !fp)?1:0);
}

string normalize(string num, string prefix, int sigF) {
    int p,np,power;
    stringstream ss;
    assert(sigF > 0);

    for(np=0; np<num.length(); ++np) if(num[np] != '0' && num[np] != '.') break;
    for(p=0; p<num.length(); ++p) if(num[p] == '.') break;

    
    power = p-np;
    if(p > np) power--;

    num = num.substr(np);
    for(int i=0; i<num.length(); ++i) {
        if(num[i] == '.') {
            num = num.substr(0,i) + num.substr(i+1);
            break;
        }
    }
    //cout<<num<<" "<<sigF<<" "<<power<<endl;
    ss << power + pre[prefix];
    if(num.length() == 1 && sigF == 1) return num + " * 10^" + ss.str();
    else return num.substr(0,1) + "." + num.substr(1) + " * 10^" + ss.str();
}

int main() {
    int n;
    double cc;
    string input,prefix,unit,num;

    pre["yotta"] = 24; pre["zetta"] = 21; pre["exa"] = 18;
    pre["peta"] = 15; pre["tera"] = 12; pre["giga"] = 9;
    pre["mega"] = 6; pre["kilo"] = 3; pre["hecto"] = 2;
    pre["deca"] = 1; pre["deci"] = -1; pre["centi"] = -2;
    pre["milli"] = -3; pre["micro"] = -6; pre["nano"] = -9;
    pre["pico"] = -12; pre["femto"] = -15; pre["ato"] = -18;
    pre["zepto"] = -21; pre["yocto"] = -24; pre[""] = 0;

    cin>>n; cin.ignore();

    for(int i=0; i<n; ++i) {
        getline(cin, input);
        vector<string> splited = splitAll(input, " ");
        num = splited[0];
        if(splited.size() >= 3) {
            prefix = splited[1];
            unit = splited[2];
        }else{
            prefix = "";
            unit = splited[1];
        }

        int sigF = significantFigure(num);
        //cout<<num<<" "<<unit<<" -> "<<sigF<<endl;
        num = normalize(num, prefix, sigF);
        cout<<num<<" "<<unit<<endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 100100;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL<<60;
const string YES = "Yes";
const string NO = "No";
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse!」


int main() {
  string s;
  cin>>s;
  if(s=="SUN"){
    cout<<7<<endl;
  }
  if(s=="MON"){
    cout<<6<<endl;
  }
  if(s=="TUE"){
    cout<<5<<endl;
  }
  if(s=="WED"){
    cout<<4<<endl;
  }
  if(s=="THU"){
    cout<<3<<endl;
  }
  if(s=="FRI"){
    cout<<2<<endl;
  }
  if(s=="SAT"){
    cout<<1<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include "string"
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i=0;i<n;++i)

typedef long long ll;
using namespace std;
int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> p;
    vector<double> num;
    for(ll i=0;i<n;i++){
        ll x;
        cin >> x;
        if(i!=0){
            p.push_back(x * p[p.size()-1]);
            num.push_back((1.+x)/2. + num[num.size()-1]);
        } else {
            p.push_back(x);
            num.push_back((1.+x)/2.);
        }
    }
    ll sum[1001] = {};
    for(int i=1;i<=1000;i++){
        for(int j=1;j<=i;j++){
            sum[i] += j;
        }
    }

    vector<double> res;
    for(int i=0;i+k<=n;i++){
        if(i!=0){
            // double ans = p[i+k-1]/p[i-1];
            double ans = (num[i+k-1]-num[i-1]);
            res.push_back(ans);
        } else {
            // double ans = p[i+k-1];
            double ans = (num[i+k-1]);
            res.push_back(ans);
        }
    }
    sort(res.begin(), res.end());
    printf("%7.6f\n", res[res.size()-1]);
    return 0;
}

Measured memory_bytes: 6500
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main ()
{
	ll a, b, c, z;
	cin>>a>>b>>c;
	z = min(b-1 , c);
	cout<<floor(a*z/b)-a*(z/b)<<endl;
	return 0;
}

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

using namespace std;
typedef long long int ll;


int main(){

    string s;
    cin >> s;
    vector<char > S;
    for(ll i = 0; i < s.length(); i++){
        S.push_back(s[i]);
    }
    ll K;
    cin >> K;

    vector<ll > vec;
    for(ll i = 0; i < S.size();){
        ll j = i;
        //一緒の間ループを回し続けて，切れ目を探す
        while(j < S.size() && S[j] == S[i]){
            ++j;
        }
        vec.push_back(j - i);
        //次の始点へすっ飛ばす
        i = j;
    }



    ll ans = 0;

    bool f = false;
    for(ll i = 1; i < S.size();){
        if(S[i - 1] == S[i]){
            ans++;
            S[i] = '1';
            i += 2;
        }else{
            i++;
        }
    }

    if(S[0] == S[S.size()-1]){
        //初めと終わりが一緒
        if(vec.size() == 1){
            if(K % 2 == 0){
                ans = (ans * (K / 2)) + ((ans + 1) * (K / 2));
            }else{
                ans = (ans * ((K / 2) + 1)) + ((ans + 1) * (K / 2));
            }
            cout  << ans << endl;
            return 0;
        }else{
            if(vec[0] == 1 && vec[vec.size()] == 1){
                ans++;
                ans *= K;
                cout  << ans << endl;
                return 0;
            }else if(vec[0] % 2 == 1){
                ans = ans + ((ans + 1) * (K - 1));
                cout  << ans << endl;
                return 0;          
            }else if(vec[0] % 2 == 0){
                ans *= K;
            }
        }
        if(s.size() % 2 );
    }else{
        //初めと終わりが異なっている
        ans *= K;
    }
    
    /*
    if(S[0] == S[S.size()-1]){
        ans++;
    }
    */
    
    cout  << ans << endl;

}

Measured memory_bytes: 256
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    L = list(map(int, input().split()))
    logging.info("Hello!")

    L_sorted = sorted(L)

    counter = 0
    diff = []
    for i in range(N):
        if L[i] != L_sorted[i]:
            counter += 1
            if counter == 3:
                print("NO")
                exit()
            else:
                diff.append(L[i])

    print("YES")

            
if __name__ == "__main__":
    main()


Measured memory_bytes: 4212
#include<iostream>
#include<cstdio>
using namespace std;
int inSort(int A[],int n,int g){
  int i,j,v;
  int cnt=0;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j-=g;
      ++cnt;
    }
    A[j+g]=v;
  }
  return cnt;
}
void shSort(int A[],int n){
  int i,j,k,l,G[20];

  int m=0; for(i=1;i<=n;i=i*3+1) G[m++]=i;

  int c=0; for(i=m-1;0<=i;i--) c+=inSort(A,n,G[i]);

  cout<<m<<endl;
  cout<<G[m-1];  for(i=m-2;0<=i;i--) cout<<' '<<G[i];  cout<<endl;
  cout<<c<<endl;
  for(i=0;i<n;i++) printf("%d\n",A[i]);
}
int main(){
  int i,n,A[1000000];
  cin>>n;
  for(i=0;i<n;i++) cin>>A[i];
  shSort(A,n);
  return 0;
}

Measured memory_bytes: 7124
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

typedef long long ll;
const ll MAXN = 2e5+10;
const ll MOD = 1e9+7;

ll H, W, A, B, ans = 0, fac[MAXN], inv[MAXN];

int main() {
    scanf("%lld%lld%lld%lld", &H, &W, &A, &B);
    inv[1] = inv[0] = 1;
    fac[1] = fac[0] = 1;
    for (ll i = 2; i <= MAXN - 10; i++) {
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
        fac[i] = fac[i-1] * i % MOD;
    }
    for (ll i = 2; i <= MAXN - 10; i++) {
        inv[i] = inv[i-1] * inv[i] % MOD;
    }
    for (ll i = 1; i <= H-A; i++) {
        ll tem = (B - 1) + (i - 1);
        ll tql = (W - B - 1) + (H - i);
        ll len = W - B - 1;
        ll now = ((((fac[tem] * inv[i-1] % MOD) * inv[tem-(i-1)] % MOD) % MOD) * (((fac[tql] * inv[len] % MOD) * inv[tql - len] % MOD) % MOD)) % MOD;
        ans = (ans + now) % MOD;
    }
    printf("%lld\n", ans % MOD);
    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj_list(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        adj_list[a].push_back(b);
        adj_list[b].push_back(a);
    }
    if (m % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> dfs_num(n);
    vector<int> dfs_order;
    vector<bool> visited(n, false);
    vector<vector<int>> dfs_children(n);
    function<void (int)> dfs = [&](int i) {
        visited[i] = true;
        dfs_num[i] = (int) dfs_order.size();
        dfs_order.push_back(i);
        for (int j : adj_list[i]) {
            if (!visited[j]) {
                dfs(j);
                dfs_children[i].push_back(j);
            }
        }
    };
    dfs(0);
    vector<vector<int>> adj_list_2(n);
    for (int i = 0; i < n; ++i) {
        for (int j : adj_list[i]) {
            if (dfs_num[i] < dfs_num[j]) {
                adj_list_2[i].push_back(j);
            }
        }
    }
    vector<int> edge_count(n, 0);
    function<void (int)> count_edges = [&](int i) {
        int count = (int)adj_list_2[i].size();
        for (int j : dfs_children[i]) {
            count_edges(j);
            count += edge_count[j];
        }
        edge_count[i] = count;
    };
    count_edges(0);
    set<pair<int, int>> reversed_edges;
    for (int i = 0; i < n; ++i) {
        for (int j : dfs_children[i]) {
            if (edge_count[j] % 2 == 1) {
                reversed_edges.insert(make_pair(i, j));
            }
        }
    }
    vector<pair<int, int>> result;
    for (int i = 0; i < n; ++i) {
        for (int j : adj_list_2[i]) {
            if (reversed_edges.find(make_pair(i, j)) == reversed_edges.end()) {
                result.push_back(make_pair(i, j));
            } else {
                result.push_back(make_pair(j, i));
            }
        }
    }
    for (auto edge : result) {
        cout << edge.first+1 << " " << edge.second+1 << "\n";
    }
    return 0;
}


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

using namespace std;

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

int W, H;
vector<string> G;
vector<tuple<int, int, int>> Ps;// y, x, dir

string const DIRS = "ENWS";
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

bool in_range(int y, int x) {
  return 0<=y&&y<H && 0<=x&&x<W;
}

bool adjacent(int i, int j, int y, int x, int dir) {
  const int ny = y + dy[dir], nx = x + dx[dir];
  if(i == ny && j == nx) return true;
  return false;
}

int get_dir(int i, int j, int y, int x) {
  // precondition adjacent = 1;
  rep(k, 4) {
    int ni = i + dy[k], nj = j + dx[k];
    if(ni == y && nj == x) {
      return k;
    }
  }
  assert(false);
}

void move_person(int pid) {
  int y, x, d; tie(y, x, d) = Ps[pid];
  Ps[pid] = make_tuple(y + dy[d], x + dx[d], d);
}

bool is_on_exit(int pid) {
  int y, x, _; tie(y, x, _) = Ps[pid];
  if(G[y][x] == 'X') return true;
  return false;
}

int simulate() {
  
  int ans = 0;
  
  while(!Ps.empty() && ans <= 180) {
#if 0
    rep(i, Ps.size()) {
      cout << "pid: " << i << endl;
      int y, x, d; tie(y, x, d) = Ps[i];
      cout << "(" << y << ", " << x << ", " << d << ")" << endl;
    }
    cout << "------" << endl;
#endif

    set<int> pset;
    vector<pair<int, int>> V;

    vector<tuple<int, int, int>> nps = Ps;
    
    rep(i, Ps.size()) {
      int y, x, dir; tie(y, x, dir) = Ps[i];
      int ndir = -1;
      for(int k=dir+3; k<dir+7; k++) {
	int ny = y + dy[k%4], nx = x + dx[k%4];
	if(!in_range(ny, nx)) continue;
	if(G[ny][nx] == '#') continue;
	
	bool ng = 0;
	rep(pid, Ps.size()) {
	  if(pid == i) continue;
	  int yy, xx, dd; tie(yy, xx, dd) = Ps[pid];
	  int ny = y + dy[k%4], nx = x + dx[k%4];
	  if(yy == ny && xx == nx) ng = 1;
	}
	if(ng) continue;
	
	ndir = k%4;
	break;
      }
      if(ndir != -1) {
	nps[i] = make_tuple(y, x, ndir);
	V.emplace_back(y+dy[ndir], x+dx[ndir]);
      }
    }
    
    Ps = nps;

    set<int> movers;
    
    rep(ii, V.size()) {
      int i = V[ii].first, j = V[ii].second;
      vector<pair<int, int>> vs; 
      rep(pid, Ps.size()) {
	int y, x, dir; tie(y, x, dir) = Ps[pid];
	if(adjacent(i, j, y, x, dir)) {
	  vs.emplace_back(get_dir(i, j, y, x), pid);
	}
      }
      
      if(!vs.empty()) {
	sort(vs.begin(), vs.end());
	int pid = vs[0].second;
	movers.insert(pid);
      }
    }

    for(auto && e: movers) {
      move_person(e);
    }

    vector<tuple<int, int, int>> NPs;
    rep(i, Ps.size()) {
      if(!is_on_exit(i)) {
	NPs.push_back(Ps[i]);
      }
    }
    Ps = NPs;
    ans ++;
  }

  if(ans > 180) return -1;
  
  return ans;
}

int main() {
  
  while(cin >> W >> H && (W | H)) {
    G.clear();
    G.resize(H);
    rep(i, H) {
      cin >> G[i];
    }
    
    Ps.clear();
    
    rep(i, H) rep(j, W) {
      if(DIRS.find(G[i][j]) != string::npos) {
	int dir = DIRS.find(G[i][j]);
	int y = i, x = j;
	Ps.emplace_back(y, x, dir);
      }
    }
    
    int r = simulate();
    if(r == -1) {
      cout << "NA" << endl;
    } else {
      cout << r << endl;
    }
  }
  
  return 0;
}

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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){

    long long N,r_sum=0,max=-1000,tmp;

    cin>>N;

    vector<long long>A(N+5),sum(N+5,0);

    for(long long i=0;i<N;i++){
        cin>>A[i];
    }

    max=A[0];
    for(long long i=1;i<N;i++){
        if(max<A[i]){
            max=A[i];
        }else if(max >A[i]){
            tmp=max-A[i];
            r_sum+=tmp;
        }
    }

    cout<<r_sum<<endl;




    return 0;
}



Measured memory_bytes: 6424
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 5000000;


int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	string s; cin >> s;
	if (s[2] == s[3] and s[4] == s[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3548
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

class UnionFind{
public:
	vector<int> parent;
	UnionFind(){}
	UnionFind(int n){
		this->parent = vector<int>(n,-1);
	}
	int root(int x){
		if (this->parent[x] < 0) return x;
		this->parent[x] = root(this->parent[x]);
		return this->parent[x];
	}
	int unite(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		if (rx == ry) return false;
		if (this->parent[rx] > this->parent[ry]) swap(rx, ry);
		this->parent[rx] += this->parent[ry];
		this->parent[ry] = rx;
		return true;
	}
	int same(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		return rx == ry;
	}
	int size(int x){
		return -this->parent[this->root(x)];
	}
};

int kruskal(int n, priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> que){
	UnionFind uf(n);
	int weight = 0;
	while(!que.empty()){
		vector<int> now = que.top();
		que.pop();
		if (!uf.same(now[1],now[2])){
			uf.unite(now[1],now[2]);
			weight += now[0];
		}
	}
	return weight;
}


int main(){
	int v, e; cin >> v >> e;
	priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> que;
	for (int i = 0; i < e; i++){
		int s, t, w; cin >> s >> t >> w;
		que.push({w,s,t});
	}
	
	cout << kruskal(v,que) << endl;
	return 0;
}



Measured memory_bytes: 13888
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<par<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi x(n),y(n),h(n);
    rep(i,n)cin>>x[i]>>y[i]>>h[i];
    rep(cx,101){
        rep(cy,101){
            int H;
            rep(i,n){
                if(h[i]){
                    H=h[i]+abs(x[i]-cx)+abs(y[i]-cy);
                    if(H)break;
                }
            }
            bool f=true;
            rep(i,n){
                if(max(H-abs(x[i]-cx)-abs(y[i]-cy),0ll)!=h[i]){
                    f=false;
                    break;
                }
            }
            if(f){
                cout<<cx<<sp<<cy<<sp<<H<<endl;
                return;
            }
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){

	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = a; i <= b; i++)
		if (c%i == 0)
			ans++;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3116
def call(n):
    s = ''
    for i in range(1,n+1):
        x = i
        if x%3 == 0:
            s += ' '+str(i)
            continue
        while x > 0:
            if x%10 == 3:
                s += ' '+str(i)
                break
            x //= 10
    print(s)

n = int(input())
call(n)


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

using namespace std;

using ll = long long;

int mvx[] = {0, 1}, mvy[] = {1, 0};

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n + 2, vector<int>(m + 2));
  vector<vector<bool>> vv(n + 2, vector<bool>(m + 2));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char c;
      cin >> c;
      if (c == '#')
        v[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (i == 1 && j == 1) {
        if (v[i + 1][j] + v[i][j + 1] == 1) {
          continue;
        }
      } else if (i == n && j == m) {
        if (v[i - 1][j] + v[i][j - 1] == 1) {
          continue;
        }
      }
      if (v[i][j]) {
        if (v[i - 1][j] + v[i][j - 1] == 1 && v[i + 1][j] + v[i][j + 1] == 1) {
          continue;
        }
        cout << "Impossible" << endl;
        return 0;
      }
    }
  }
  cout << "Possible" << endl;
}


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

int n,bil,sum;

int factortwo(long long bil){
	int result = 0;
	if(bil == 1){
		return 0;
	}else{
		for(int i = 1;i <= 30;i++){
			if(bil % 2 == 0){
				result++;
				bil = bil / 2;
			}else break;
		}
		return result;
	}
}

int main(){
	cin>>n;
	for(int i = 1;i <= n;i ++){
		cin>>bil;
		sum = sum + factortwo(bil);
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate
import copy

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N = int(input())
    M = 101
    offset = M//2
    cnt = [[0]*M for _ in range(M)]
    p = [None for _ in range(N)]
    for i in range(N):
        A = input()
        n = len(A)
        tmp = [0,0]# 2と5の数を調べる。-は不足
        if '.' in A:
            tmp[0] -= n-1-A.index('.')
            tmp[1] -= n-1-A.index('.')
        A = int(A.replace('.',''))
        while A % 2 == 0:
            A //= 2
            tmp[0] += 1
        while A%5 == 0:
            A //= 5
            tmp[1] += 1
        cnt[offset+tmp[0]][offset+tmp[1]] += 1
        p[i] = (tmp[0]+offset, tmp[1]+offset)
    # print(cnt)
    cnt2 = copy.deepcopy(cnt)

    # 累積和をとる
    for i in range(M-1,-1,-1):
        for j in range(M-1,-1,-1):
            if j < M-1:
                cnt[i][j] += cnt[i][j+1]
    
    for i in range(M-1,-1,-1):
        for j in range(M-1,-1,-1):
            if i < M-1:
                cnt[i][j] += cnt[i+1][j]
    
    # print(cnt)
    ans = 0
    for i in range(M):
        for j in range(M):
            if cnt2[i][j]==0: continue
            ans += cnt2[i][j]*cnt[offset*2-i][offset*2-j]
            # print(p[i])
            # print(cnt[offset*2-p[i][0]][offset*2-p[i][1]])
            # ans += cnt[offset*2-p[i][0]][offset*2-p[i][1]]
            # print(i,j,cnt2[i][j],ans)
    print((ans-cnt[offset][offset])//2)

if __name__ == "__main__":
    main()


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

int main() {
	int N, X, Q = 0;;
	cin >> N >> X;

	vector<int> m(N);

	for (int i = 0; i < N;i++) {
		cin >> m[i];
		Q += m[i];
	}

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

	if (X - Q == 0) {
		cout << N << endl;
	}
	else cout << (X - Q) / m[0] + N << endl;
}

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

int X;
vector<int> p={2};

int main(){
    cin>>X;

    if(X==2){
        cout<<2;
        return 0;
    }

    bool b=true;
    int n=2;
    while(b){
        n++;
        bool prime;
        for(int i=0;i<p.size();i++){
            if(n%p[i]==0){
                prime=false;
                break;
            }else{
                prime=true;
            }
        }
        if(prime){
            p.push_back(n);
            if(n>=X){
                b=false;
            }
        }
    }

    cout<<n;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <cstdlib>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-9
#define mod 1000000007
#define N 100010
LL read()
{
	LL x = 0; char ch = getchar();
	for(;ch<'0'||ch>'9';ch = getchar());
	for(;ch>='0'&&ch<='9';ch = getchar()) x = (x<<3)+(x<<1)+(ch^48);
	return x;
}
int n;
LL A,B,a[N];
int sum[N<<4];
#define lc u<<1
#define rc u<<1|1
void update(int u,int l,int r,int p,int v)
{
	if(l == r)
	{
		sum[u] += v;
		if(sum[u] >= mod) sum[u] -= mod;
		return;
	}
	int mid = (l+r)>>1;
	if(p<=mid) update(lc,l,mid,p,v);
	else update(rc,mid+1,r,p,v);
	(sum[u] = sum[lc] + sum[rc])%=mod;
}
int query(int u,int l,int r,int L,int R)
{
	if(L<=l && r<=R) return sum[u];
	int mid = (l+r)>>1;
	int ans = 0;
	if(L<=mid) (ans += query(lc,l,mid,L,R))%=mod;
	if(mid<R) (ans += query(rc,mid+1,r,L,R))%=mod;
	return ans;
}
int f[N],l,r;
int main()
{
	n = read(); A = read(); B = read(); if(A<B) swap(A,B);
	for(int i=1;i<=n;i++) a[i] = read();
	a[0] = -A; a[n+1] = a[n] + A;
	f[0] = 1; update(1,0,n,0,f[0]);
	l = r = 0;
	for(int i=1;i<=n+1;i++)
	{
		while(a[i] - a[r+1] >= A) r++;
		if(i>=2 && a[i-1] - a[i-2] < B) l = i-2;
		if(a[i] - a[i-1] >= A) f[i] = f[i-1];
		if(l<=min(i-2,r)) (f[i] += query(1,0,n,l,min(i-2,r)))%=mod;//cout<<i<<endl;
		if(f[i] >= mod) f[i] -= mod;
		if(i<=n && a[i+1] - a[i-1] >= B) update(1,0,n,i,f[i]);
	}
	cout<<(f[n+1]+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 2432
/////////////////////////   _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 1005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n , m;

char mas[N][N];
queue < pair<int,int> > q;

int d[N][N];

int dx[10] = {1 , -1 , 0 , 0};
int dy[10] = {0 , 0 , 1 , -1};

int main() {
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf(" %c",&mas[i][j]);
            d[i][j] = -1;
            if(mas[i][j] == '#'){
                d[i][j] = 0;
                q.push(make_pair(i , j));
            }
        }
    }
    while(!q.empty()){
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for(int i=0;i<4;i++){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 1 || ny < 1 || nx > n || ny > m)continue;
            if(d[nx][ny] == -1){
                d[nx][ny] = d[x][y] + 1;
                q.push(make_pair(nx , ny));
            }
        }
    }
    int answ = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            answ = max(answ , d[i][j]);
        }
    }
    cout << answ << endl;
	return 0;
}


Measured memory_bytes: 13328
#include<iostream>
#include<string>
using namespace std;
int main(){
	for(;;){
		int H,W;
		cin>>H>>W;
		if(H==0&&W==0)break;
		else{
			for(int a=0;a<H;a++){
				for(int b=0;b<W;b++){
					if((a+b)%2==0){
						cout<<"#";
					}else{
						cout<<".";
					}
				}
				cout<<endl;
			}
			cout<<endl;
		}
	}
}


Measured memory_bytes: 3108
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main(void){
while(1){
int n,r;
cin>>n>>r;
if(n==0)break;
vector<int> a(n);
for(int i=0;i<n;i++)a[i]=n-i;
for(int i=0;i<r;i++){
int p,c;
cin>>p>>c;
vector<int> temp(p+c-1);
for(int j=0;j<c;j++)temp[j]=a[p+j-1];
for(int j=c;j<c+p-1;j++)temp[j]=a[j-c];
for(int j=0;j<c+p-1;j++)a[j]=temp[j];
//for(int j=0;j<n;j++)cout<<a[j]<<endl;
	}	
cout<<a[0]<<endl;
}
return 0;
}



Measured memory_bytes: 3076