akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(int i = a; i < n; ++i)
#define pb push_back
#define mp make_pair
#define f first
//#define sex second

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <set>
#include <ostream>
#include <queue>
#include <functional>
#include <sstream>
#include <map>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#pragma comment(linker, "/STACK:228228000")
const ll mod = 9982443530;

ll a, b;

int main()
{
	/*

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	*/

	cin >> a >> b;
	if (a < 9 && b < 9)
		cout << "Yay!";
	else
		cout << ":(";


	return 0;
}

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

int main(void) {
  int a,b,c;
  std::cin>> a >> b >> c;
  if(b/a>c){std::cout << c << std::endl;}
  else{std::cout << b/a << std::endl;}


  // ここにプログラムを追記
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon Oct  8 14:30:54 2018
ABC074C
@author: maezawa
"""

a, b, c, d, e, f = list(map(int, input().split()))

pos_water = set([])
pos_sugar = set([])
max_water = f
max_sugar = f*e//100

for i in range(max_water//100//a+1):
    for j in range(max_water//100//b+1):
        if 100*(i*a + j*b) > max_water:
            break
        else:
            pos_water.add(100*(i*a + j*b))

for i in range(max_sugar//c+1):
    for j in range(max_sugar//d):
        if i*c + j*d > max_sugar:
            break
        else:
            pos_sugar.add(i*c + j*d)

water = list(pos_water)
water.sort()
sugars = list(pos_sugar)
sugars.sort()
water.remove(0)

#print(water)
#print(sugars)

ans_weight = water[0]
ans_sugar = 0
max_conc = 0
for w in water:
    for s in sugars:
        conc = s/(s+w)
        weight = s+w
        #print(w, s, conc, weight)
        if weight > f:
            break
        if conc > e/(100+e):
            break
        if conc > max_conc:
            max_conc = conc
            ans_weight = weight
            ans_sugar = s

print(ans_weight, ans_sugar)
        
        

Measured memory_bytes: 3188
n = int(input())
a_lst = list(map(int, input().split()))
maximum = a_lst[0]
h_lst = []
for i in range(n):
    maximum = max(maximum, a_lst[i])
    h_lst.append(maximum - a_lst[i])
sum1 = sum(h_lst)
print(sum1)

Measured memory_bytes: 32220
H, W, K = map(int, input().split())
C = []
for _ in range(H):
    C.append(list(input()))

ans = 0
for h in range(2 ** H):
    for w in range(2 ** W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if ( h >> i ) & 1 == 0 and ( w >> j ) & 1 == 0:
                    if C[i][j] == "#":
                        cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Measured memory_bytes: 9200
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
e=[0]*(n//2)#偶数番号
o=[0]*(n//2)#奇数番号
ans=0
for i in range(n):
    if i%2==0:
        e[i//2]=v[i]
    else:
        o[(i-1)//2]=v[i]
a=Counter(e)
b=Counter(o)
c=a.most_common(2)
d=b.most_common(2)
if c[0][0]!=d[0][0]:#一番多い数が違う
    ans=n-c[0][1]-d[0][1]
else:#同じ→どちらかは2番目の方に揃える
    if len(c)==1:#偶数列が1種類の数から
        if len(d)==1:
            ans=n//2
        else:
            ans=len(d)-d[1][1]
    elif len(d)==1:#奇数列が1種類の数から
        if len(c)==1:
            ans=n//2
        else:
            ans=len(c)-c[1][1]
    else:
        if c[0][1]>d[0][1]:
            ans=n-c[0][1]-d[1][1]
        elif c[0][1]==d[0][1]:
            ans=min(n-c[0][1]-d[1][1],n-c[1][1]-d[0][1])
        else:
            ans=n-c[1][1]-d[0][1]
print(ans)

Measured memory_bytes: 19040
x,n=map(int,input().split())
p = list(map(int,input().split()))

if not x in p:
    print(x)
    exit()
for i in range(1,200):
    if not x-i in p:
        print(x-i)
        exit()
    elif not x+i in p:
        print(x+i)
        exit()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
// #include <limits>
//auto std::numeric_limits<float>::infinity() { return __builtin_huge_valf(); }
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)

int main()
{
    //A
    /*
    int N, R, x;
    cin >> N >> R;

    if (N >= 10)
    {
        x = R;
    }
    else
        x = R + 100 * (10 - N);
    cout << x << endl;
    */
    //B
    /*
    int N, K, a = 0;
    cin >> N >> K;

    while (N >= K)
    {
        N /= K;
        a++;
    }
    cout << a + 1 << endl;
    */
    //C
    int N;
    cin >> N;
    vector<int> X(N);
    vector<int> Y(100, 0);
    rep(i, 0, N) cin >> X[i];
    //int min = 1000000;
    rep(i, 1, 101)
    {
        rep(j, 0, N)
        {
            Y[i - 1] += pow((X[j] - i), 2);
        }
    }
    sort(Y.begin(), Y.end());
    cout << Y[0] << endl;
}

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

string divide[4]={"dream","dreamer","erase","eraser"};
int main() {
    
    string S;
    cin>>S;
    reverse(S.begin(),S.end());
    rep(i,4)reverse(divide[i].begin(),divide[i].end());
    
    bool can=true;
    for(int i=0;i<S.size();){
      bool can_divide=false;
      for(int j=0;j<4;j++)
      {
        string d=divide[j];
        if(S.substr(i,d.size())==d){
          can_divide=true;
          i+=d.size();
        }
        
      }
      if(!can_divide)
      {
        can=false;
        break;
      }
    }
    if(can)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  
    return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
int flag=0,pd;
int main(){
    int k,t;
    int a[1001];
    cin>>k>>t;
    for(int i=0;i<t;i++) cin>>a[i],flag+=a[i];
    for(int i=0;i<t;i++){
        pd=a[i]*2-flag-1;
        if(pd>=0){
            cout<<pd<<endl;
            return 0;
        }
    }
    cout<<"0"<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
int dp[101][10];
int main(){
	cin>>N;
	rep(i,N+1) rep(j,10) dp[i][j]=-1;
	dp[0][0]=0;
	rep(i,N){
		int s;
		cin>>s;
		rep(j,10) if(dp[i][j]!=-1){
			chmax(dp[i+1][j],dp[i][j]);
			chmax(dp[i+1][(j+s)%10],dp[i][j]+s);
		}
	}
	int ans = 0;
	rep1(j,9) chmax(ans,dp[N][j]);
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N,K;
	cin >> N >> K;

	cout << N - K + 1 << endl;
	return 0;
}



Measured memory_bytes: 764
N = int(input())
S = [str(input()) for i in range(N)]

a = b = c = d = 0

for i in range(N):
    if S[i] == 'AC':
        a += 1
    elif S[i] == 'WA':
        b += 1
    elif S[i] == 'TLE':
        c += 1
    elif S[i] == 'RE':
        d += 1

print('AC x ' + str(a))
print('WA x ' + str(b))
print('TLE x ' + str(c))
print('RE x ' + str(d))

Measured memory_bytes: 16324
S = input()
lens = len(S)

A = {}
for s in S:
    if s not in A:
        A[s] = 1
    else:
        A[s] += 1

B = [(a, A[a]) for a in A]
B.sort(reverse=True, key=lambda x: x[1])
# print(B)

if len(B) == 1:
    print(0)
    exit()

max_num = B[0][1]

if max_num == 1:
    print(lens // 2)
    exit()

ans = 100
for i in range(len(B)):
    b = B[i][0]
    count = 0
    sub_ans = 0
    for s in S:
        if s != b:
            count += 1
        else:
            sub_ans = max(sub_ans, count)
            count = 0
    else:
        sub_ans = max(sub_ans, count)
    ans = min(sub_ans, ans)
print(ans)


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
	int A,B,C, ans = 0;
	scanf("%d %d %d", &A,&B,&C);
  ans = C - A + B;
  if (ans < 0) {
    ans = 0;
  }
  printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    int N; cin >> N;
    vector<ll> h(N);
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }
    //int ans = 0;
    for (int i = N-1; i >= 1; i--){
        if (h[i-1] <= h[i]){
            continue;
        } else if (h[i-1] == h[i]+1){
            h[i-1]--;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
// atcoder/abc158/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

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

using namespace std;

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

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

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

int di[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dj[] = {1, 0, 0, -1, 1, -1, -1, 1};
constexpr lli mod = 1e9 + 7;

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

  int a, b;
  while (cin >> a >> b) {
    int x = -1;
    for (int i = 0; i < 1e7; ++i) {
      int p = i * 8 / 100;
      int q = i / 10;
      if (p == a && q == b) {
        x = i;
        break;
      }
    }
    cout << x << endl;
  }

  return 0;
}


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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

struct Combination {
  vector<ModInt<>> _fact, _rfact, _inv;
  Combination(long long nsize = 5000000)
      : _fact(nsize + 1), _rfact(nsize + 1), _inv(nsize + 1) {
    _fact[0] = _rfact[nsize] = _inv[0] = 1;
    for (int i = 1; i <= nsize; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[nsize] /= _fact[nsize];
    for (int i = nsize - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for (int i = 1; i <= nsize; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
  inline ModInt<> fact(int k) const { return _fact[k]; }

  inline ModInt<> rfact(int k) const { return _rfact[k]; }

  inline ModInt<> inv(int k) const { return _inv[k]; }

  ModInt<> P(int n, int r) const {
    if (r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  ModInt<> C(int p, int q) const {
    if (q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
  // n types,choose r
  ModInt<> H(int n, int r) const {
    if (n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

int main() {
  long long n;
  cin >> n;
  cout << ModInt<>(10).pow(n) - ModInt<>(9).pow(n) * 2 + ModInt<>(8).pow(n)
       << endl;
  return 0;
}

Measured memory_bytes: 3588
#include<cstdio>
#include<iostream>
#include<cctype>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
int d[1300200];
struct Edge{
	int u,v,w,next;
};
Edge e[1300200];
int inq[1300200];
int h[1300200];
int in[1300200];
int h2[1300200];
Edge e2[1400200];
queue<int>q;
void spfa(int s){
	memset(d,0x3f,sizeof(d));
	memset(inq,0,sizeof(inq));	
	d[s]=0;q.push(s);
	inq[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		inq[u]=0;
		for(int i=h[u];i!=-1;i=e[i].next){
			int v=e[i].v;
			int w=e[i].w;
			if(d[v]>d[u]+w){
				d[v]=d[u]+w;
				if(inq[v]==0){
					q.push(v);
					inq[v]=1;
				}
			}
		}
	}
}
void spfa2(int s){
	memset(d,0x3f,sizeof(d));
	memset(inq,0,sizeof(inq));	
	d[s]=0;q.push(s);
	inq[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		inq[u]=0;
		for(int i=h2[u];i!=-1;i=e2[i].next){
			int v=e2[i].v;
			int w=e2[i].w;
			if(d[v]>d[u]+w){
				d[v]=d[u]+w;
				if(inq[v]==0){
					q.push(v);
					inq[v]=1;
				}
			}
		}
	}
}
int main(){
		memset(h,-1,sizeof(h));memset(h2,-1,sizeof(h2));
		int n;
		cin>>n;
		for(int i=1;i<=n-1;i++){
			int u,v,w;
			cin>>u>>v>>w;
			e[i]=(Edge){u,v,w,h[u]};h[u]=i;
			e2[i+n-1]=(Edge){v,u,w,h2[v]};h2[v]=i+n-1;
			e2[i]=(Edge){u,v,w,h2[u]};h2[u]=i;
			in[v]++;
		}
		for(int i=0;i<n;i++){
			if(in[i]==0){
				spfa(i);
				break;
			}
		}
		
		long long maxx=-1;
		long long cur;
		for(int i=0;i<n;i++){
			if(d[i]>maxx&&d[i]!=d[n+1]){
				maxx=d[i];
				cur=i;
			}
		}
		int use=d[cur];
		spfa2(cur);
		int ans=-1;
		for(int i=0;i<n;i++){
			if(d[i]>ans){
				ans=d[i];				
			}
		}
		cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 28660
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func ufRoot(e []int, x int) int {
	for {
		if e[x] == x {
			return x
		}
		x = e[x]
	}
}

func ufUnite(e []int, x int, y int) {
	rx := ufRoot(e, x)
	ry := ufRoot(e, y)
	if rx != ry {
		e[rx] = ry
		e[x] = ry
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	m := nextInt()
	t := make([]int, n)
	for i := 0; i < n; i++ {
		t[i] = i
	}

	for i := 0; i < m; i++ {
		x := nextInt()
		y := nextInt()
		_ = nextInt()
		x--
		y--
		ufUnite(t, x, y)
	}
	//fmt.Printf("%v\n", t)
	count := 0
	for i := 0; i < n; i++ {
		if t[i] == i {
			count++
		}
	}
	_, _ = fmt.Fprintf(writer, "%d", count)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 2944
function Main(input){
  	var tmp = input.split(" ");
	var range = tmp[0];
  	var min = tmp[1];
  	var max = tmp[2];
  	var sum = 0;
  
  	for(var i=1; i<=range; i++){
        i_str = String(i);// 各桁を加算するため一度String型にする
        var sum_digits = 0;
        for(var j=0; j<i_str.length; j++){
          	sum_digits += parseInt(i_str[j], 10);
        }
      	// 指定範囲内であれば
      	if(min<=sum_digits&&sum_digits<=max){
           	sum += i;
        }
    }
	console.log(sum);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 12352
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	result := make(map[int]int)
	for i := 1; i <= n; i ++ {
		result = merge(result, factoring(i, 2))
	}
	// 75
	// 3 * 5 * 5
	// 15 * 5
	// 25 * 3
	n_75 := num(result, 75-1)
	n_25 :=num(result,25-1)
	n_15 := num(result,15-1)
	n_5 := num(result, 5-1)
	n_3 := num(result, 3-1)
	fmt.Println(n_75+n_5*(n_5-1)*(n_3-2)/2+n_15*(n_5-1)+n_25*(n_3-1))
}
func factoring(num , pnum int) map[int]int{
	result := make(map[int]int)
	if pnum * pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num % pnum == 0 {
		num /= pnum
		result[pnum] ++
	} else {
		pnum ++
	}
	 return merge(result , factoring(num, pnum))
}

func merge(m1, m2 map[int]int) map[int]int {
	ans := map[int]int{}
	for k, v := range m1 {
		ans[k] += v
	}
	for k, v := range m2 {
		ans[k] += v
	}
	return ans
}

func num(t map[int]int, n int) int {
	var num int
	for _, value := range t {
		if value >= n {
			num ++
		}
	}
	return num
}

Measured memory_bytes: 768
import 'dart:io';

void main() {
  List nxt = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  int i = (nxt[0] / nxt[1]).floor();
  int minute;
  if (nxt[0] % nxt[1] == 0)
    minute = (i) * nxt[2];
  else
    minute = (i + 1) * nxt[2];
  print(minute);
}

Measured memory_bytes: 13216
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 2e5;

LL n, m, a[MaxN + 5], sum, k, l[MaxN + 5], r[MaxN + 5];

int main() {
	scanf("%lld", &n);
	for(LL i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	l[1] = a[1];
	for(LL i = 2; i <= n; i++)
		l[i] += l[i - 1] + a[i];
	r[n] = a[n];
	for(LL i = n - 1; i > 0; i--)
		r[i] += r[i + 1] + a[i];
	LL m = (1ll << 60);
	for(LL i = 1; i < n; i++)
		m = min(abs(l[i] - r[i + 1]), m);
	printf("%lld\n", m);
	return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=200000 +117;
const int MM=100000 +117;
const int mod=1e9+7;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("river.in","r",stdin);
	//freopen("river.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
LL lv[NN]={};
int	vcnt,xcnt;
struct node{
	int x,v;
}a[NN];
struct in{
	int l,r;
}t[NN];
bool cmp(node a,node b){
	return a.x<b.x;
}
bool cmpi(in a,in b){
	return a.r<b.r||(a.r==b.r&&a.l<b.l);
}
LL dp[NN]={};
int main(){
	//open();
	n=read();
	for(int i=1;i<=n;++i){
		a[i].x=read();
		a[i].v=read();
		lv[++vcnt]=(LL)a[i].v*2000000000+a[i].x;
	}
	sort(lv+1,lv+1+vcnt);
	vcnt=unique(lv+1,lv+1+vcnt)-lv-1;
	for(int i=1;i<=n;++i){
		a[i].v=lower_bound(lv+1,lv+1+vcnt,(LL)a[i].v*2000000000+a[i].x)-lv;
	}
	sort(a+1,a+1+n,cmp);
	int lm=a[n].v;
	for(int i=n;i>=1;--i){
		lm=min(lm,a[i].v);
		t[i].l=lm;
	}
	int rm=a[1].v;
	for(int i=1;i<=n;++i){
		rm=max(rm,a[i].v);
		t[i].r=rm;
	}
	sort(t+1,t+1+n,cmpi);
	dp[0]=1;
	int pos=1;
	for(int i=1;i<=n;++i){
		dp[i]=dp[i-1];
		while(t[pos].r<i)++pos;
		while(t[pos].r==i){
			if(t[pos].l!=1)dp[i]+=dp[i]-dp[t[pos].l-2];
			else dp[i]+=dp[i];
			dp[i]%=mod;
			++pos;
		}
	}
	printf("%lld\n",(dp[n]-dp[n-1]+3ll*mod)%mod);
	close();
	return 0;
}

Measured memory_bytes: 6528
import sys

sys.setrecursionlimit(10 ** 7)

n, u, v = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)


ftakahasi = [-1 for i in range(n)]
faoki = [-1 for i in range(n)]


def dfst(i, n):
    ftakahasi[i] = n
    for sg in g[i]:
        if ftakahasi[sg] == -1:
            dfst(sg, n + 1)


def dfsa(i, n):
    faoki[i] = n
    for sg in g[i]:
        if faoki[sg] == -1:
            dfsa(sg, n + 1)


dfst(u - 1, 0)
dfsa(v - 1, 0)
res1 = 0
for i in range(n):
    pt = ftakahasi[i]
    pa = faoki[i]
    if pt < pa:
        tres = pa - 1
        res1 = max(res1, tres)
print(res1)


Measured memory_bytes: 101736
#include <bits/stdc++.h>
using namespace std;
const int maxN = 705;
bool a[maxN][maxN];
int n, m;
vector < pair < int, int > > cli;
int can = 0;
bool used[maxN];
void solve(vector < int > &all) {
    if (all.empty()) return;
    for (int i = 1; i <= n; i++) used[i] = true;
    vector < int > cur[2];
    int ind1 = -1;
    int ind2 = -1;
    for (int i = 0; i < all.size(); i++) {
        used[all[i]] = false;
        for (int j = i + 1; j < all.size(); j++) {
            if (a[all[i]][all[j]] == false) {
                ind1 = all[i];
                ind2 = all[j];
                break;
            }
        }
    }
    if (ind1 == -1) {
        can = all.size();
        return;
    }
    cur[0].push_back(ind1);
    cur[1].push_back(ind2);
    queue < pair < int, int > > q;
    q.push(make_pair(ind1, 0));
    q.push(make_pair(ind2, 1));
    used[ind1] = true;
    used[ind2] = true;
    while (!q.empty()) {
        auto t = q.front();
        q.pop();
        int part = t.second;
        int v = t.first;
        for (int i = 1; i <= n; i++) {
            if (v == i) continue;
            if (a[v][i]) continue;
            if (used[i]) continue;
            q.push(make_pair(i, 1 - part));
            used[i] = true;
            cur[1 - part].push_back(i);
        }
    }
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < cur[i].size(); j++) {
            for (int k = j + 1; k < cur[i].size(); k++) {
                if (!a[cur[i][j]][cur[i][k]]) {
                    cout << -1;
                    exit(0);
                }
            }
        }
    }
    cli.push_back(make_pair(cur[0].size(), cur[1].size()));
    vector < int > ne;
    for (int i = 0; i < all.size(); i++) {
        if (used[all[i]]) continue;
        ne.push_back(all[i]);
    }
    solve(ne);
}
bool dp[705][705];
int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        a[x][y] = true;
        a[y][x] = true;
    }
    vector < int > all;
    for (int i = 1; i <= n; i++) all.push_back(i);
    solve(all);
    dp[0][0] = true;
    for (int i = 0; i < cli.size(); i++) {
        for (int j = 0; j <= n; j++) {
            if (dp[i][j] == false) continue;
            dp[i + 1][j + cli[i].first] = true;
            dp[i + 1][j + cli[i].second] = true;
        }
    }
    int near = 0;
    for (int i = 0; i <= n; i++) {
        if (dp[cli.size()][i] == true) {
            for (int j = 0; j <= can; j++) {
                int p = i + j;
                if (abs((n / 2) - p) < abs((n / 2) - near)) {
                    near = p;
                }
            }
        }
    }
    int p = near;
    cout << ((p * (p - 1) / 2)) + ((n - p) * (n - p - 1) / 2);
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define mp  make_pair
#define SIZE 101
bool marked[SIZE];
// bool check(ll arr[],n){
// 	bool is=false;
// 	for(ll i=0;i<n;++i){
// 		is=is&&marked[i];
// 	}
// 	return is;
// }
int main(){
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif
	ll n;
	cin>>n;
	ll arr[n],t[n];
	set<ll> s;
	set<ll> :: iterator itr;
	for(ll i=0;i<n;++i){
		cin>>t[i];
		s.insert(t[i]);
		arr[i]=0;
	}
	ll steps=0,preve=0;
	while(!s.empty()){
		itr=s.begin();	
		ll e=*itr;
		s.erase(itr);
		bool prev=true;
		for(ll i=0;i<n;++i){
			bool curr=marked[i];
			if(curr!=prev){
				if(curr==false)
					steps+=e-preve;
				prev=curr;
			}
			if(!marked[i]){
				arr[i]=e;
				if(t[i]==e)
					marked[i]=true;
			}
			// cout<<arr[i]<<" ";
		}
		preve=e;
		// cout<<endl;
	}
	cout<<steps<<endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [a[0]]
for i in range(n-1):
    b.append(b[i]+a[i+1])
s = b
for i in range(n-1):
    for j in range(i,n-1):
        s.append(b[j+1]-b[i])
s.sort(reverse=True)
l = len(bin(s[0]))-2
d = 1<<l-1
t = 0
while d>0:
    s1 = []
    if s[k-1] >= d:
        t += d
        for i in s:
            if i >= d:
                s1.append(i)
            else:
                s=s1
                break
    if len(s) < k:
        break
    for i in range(len(s)):
        if s[i] >= d:
            s[i] -= d
        else:
            s.sort(reverse=True)
            break
    if len(s) == k:
        t2 = d-1
        for i in s:
            t2 = t2&i
        t = t|t2
        break
    d = d>>1
print(t)

Measured memory_bytes: 27440
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    class P
    {
        public int key;
        public List<int> ad;
        public Dictionary<int, int> weights;
        public int Weight;
        public P Parent;
        public P(int key)
        {
            this.key = key;
            ad = new List<int>();
            weights = new Dictionary<int, int>();
        }
    }
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var gr = new P[num];
        for (var i = 0; i < num; i++)
            gr[i] = new P(i);
        for(var i = 0; i < num; i++)
        {
            var inp = Array.ConvertAll(ReadLine().Trim().Split(' '), int.Parse);
            for (var j = 0; j < num; j++)
            {
                if (inp[j] != -1)
                {
                    gr[i].ad.Add(j);
                    gr[i].weights[j] = inp[j];
                }
            }
        }
        for (var i = 0; i < num; i++)
            gr[i].Weight = int.MaxValue;
        gr[0].Weight = 0;
        var set = new HashSet<int>();
        while (true)
        {
            var minVal = int.MaxValue;
            var u = new P(-1);
            for(var i = 0; i < num; i++)
            {
                if (!set.Contains(i) && minVal > gr[i].Weight)
                {
                    minVal = gr[i].Weight;
                    u = gr[i];
                }
            }
            if (minVal == int.MaxValue) break;
            set.Add(u.key);

            foreach (var ad in u.ad)
            {
                if (!set.Contains(ad) && gr[ad].Weight > u.weights[ad])
                {
                    gr[ad].Weight = u.weights[ad];
                }
            }
        }
        WriteLine(gr.Sum(p => p.Weight));
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 18720
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;
 
 int main()
 {
   int arr[1005]={0};
   int arr2[1005]={0};
   map<int,int> mm;
   map<int,int>::iterator iter;
   string s;
   bool change=false;
   while(getline(cin,s))
   {
     //if(s=="0")  break;
     int num,d;
     char temp;
     if(s=="")
     {
       change=true;
       continue;
     }
     if(!change)
     {
       sscanf( s.c_str(), "%d,%d", &num, &d );
       //cin>>num>>temp>>d;
       mm[num]++;    
       arr[num]=1;     
     }
     else
     {
        sscanf( s.c_str(), "%d,%d", &num, &d );
       //cin>>num>>temp>>d;
       mm[num]++;    
       arr2[num]=1;   
     }     
   }
   for(iter=mm.begin();iter!=mm.end();++iter)
   {
     if(arr[iter->first]&&arr2[iter->first])
     {
       cout<<iter->first<<" "<<iter->second<<endl;                                       
     }                                          
   } 
   //while(1);
   return 0;
 }

Measured memory_bytes: 3208
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    N = sc.intarr()[0]
    for i in range(50000):
        inTax = int(i * 1.08)
        if inTax < N:
            continue
        elif inTax == N:
            print(i)
            return
        elif inTax > N:
            print(":(")
            return


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()


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

int main(){
    long long int entr[6], temp[7], i, n, count = 0;
    cin >> n;
    for(i = 0; i < 6; i++)temp[i] = 0;
    temp[0] = n;
    for(i = 0; i < 5; i++)cin >> entr[i];
    while(1){
        if(temp[5] != 0)break;
        for(i = 5; i > 0; i--){
            if(temp[i-1] >= entr[i-1]){
                temp[i] += entr[i-1];
                temp[i-1] -= entr[i-1];
            }else{
                temp[i] += temp[i-1];
                temp[i-1] = 0;
            }
        }
        count++;
    }
    if(temp[5] != n){
        count += (n/(temp[5]));
        if(!(n%temp[5]))count--;
    }
    cout << count;
	return 0;
}

Measured memory_bytes: 3632
// ※※※ 解答不能 ※※※
// https://atcoder.jp/contests/acl1/submissions/16928592
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int a[202020], b[202020], x[202020], y[202020], ans[202020];

int main(){
    
    int N;
    scanf("%d", &N);
    repx(i, 1, N + 1){
        scanf("%d %d", &x[i], &y[i]);
        a[x[i]] = y[i];
    }
    int M = N + 1, k = 0;
    repx(i, 1, N + 1){
        M = min(M, a[i]);
        if(M == N - i + 1) b[++k] = i;
    }
    repx(i, 1, N + 1) repr(j, b[i], b[i - 1] + 1) ans[j] = b[i] - b[i - 1];
    repx(i, 1, N + 1) printf("%d\n", ans[x[i]]);
    return 0;
    
}

Measured memory_bytes: 6948
MOD=10**9+7
class Integer
  def mod_add(x)
    (self + x) % MOD
  end
  def mod_sub(x)
    (self - x) % MOD
  end
  def mod_mul(x)
    (self * x) % MOD
  end
  
  # a.mod_div(b) => a / b
  def mod_div(x)
    (self * x.mod_inv) % MOD
  end
  
  # a.mod_pow(b) => a ** b
  def mod_pow(x)
    a = self
    res = 1
    while x > 0
      res = res * a % MOD if x[0] == 1
      a = a * a % MOD
      x >>= 1
    end
    res
  end
  
  # for prime mod
  def mod_inv()
    self.mod_pow(MOD - 2)
  end
  
  def mod_comb(n, k)
    a = 1
    b = 1
    k.times do |i|
      b *= i + 1
      b %= MOD
    end
    k.times do |i|
      a *= n - i
      a %= MOD
    end
    a * b.mod_inv % MOD
  end
end

#初期値を配列に入れておく
class ModCombination
  attr_reader :fac, :finv
  
  def initialize(n)
    @fac = Array.new(n+1)
    @finv = Array.new(n+1)
    @fac[0] = 1
    1.upto(n) do |i|
      @fac[i] = (@fac[i-1] * i) % MOD
    end
    
    @finv[n] = @fac[n].mod_inv;
    n.downto(1) do |i|
      @finv[i-1] = (@finv[i] * i) % MOD
    end
  end
 
  def combination(n, k)
    return 0 if k < 0 || k > n
    return (@fac[n] * @finv[k] * @finv[n-k]) % MOD
  end
end

N,K=gets.split.map(&:to_i)

mc1 = ModCombination.new(K-1)
mc2 = ModCombination.new(N-K+1)

ans=Array.new(K,0)
(1..K).each do |m|
  ans[m-1] = (mc1.combination(K-1, m-1) * mc2.combination(N-K+1, m)) % MOD
end
puts ans


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#include <string>
#define MAX 100007
#define scn1(a) scanf("%d", &a);
#define scn2(a, b) scanf("%d %d", &a, &b);
#define scn3(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define lscn1(a) scanf("%lli", &a);
#define lscn2(a, b) scanf("%lli %lli", &a, &b);
#define lscn3(a, b, c) scanf("%lli %lli %lli", &a, &b, &c);
#define prnt(a) printf("%d\n", a);
#define for0(a, n) for(int i=a;i<n;i++)
#define forn(a, n) for(int i=a;i<=n;i++)
typedef unsigned long long int ll;
using namespace std;


int main()
{
//	#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//	#endif
	int tt=1;
//	scn1(tt);
	while(tt--)
    {
        int i, ans=0;
        string a;
        cin >> a;
        int l=a.size();
//        cout << l << endl;
        for(i=0; i < l/2; i++)
            if(a[i]!=a[l-i-1])
            {
//                cout << a[i] << " " << a[l-i-1] << endl;
                ans++;
            }
//        cout << --i << endl;
        printf("%d\n", ans);
    }
    return 0;
}



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

int main(){
  int n,W,w[201],sum[201]={};
  cin>>n>>W;
  for(int i=0;i<n;i++)cin>>w[i];
  sort(w,w+n,greater<int>());
  sum[n-1]=w[n-1];
  for(int i=n-2;i>=0;i--) sum[i]=w[i]+sum[i+1];

  ll dp[20011]={1},ans=0;  
  for(int i=0;i<n;i++){
    
    for(int j=0;sum[i+1]+j<=W;j++)
      if(sum[i+1]+j+w[i]>W) ans=(ans+dp[j])%mod;
    
    for(int j=W;j>=0;j--)dp[j+w[i]]=(dp[j+w[i]]+dp[j])%mod;
  }
  
  cout << max(1LL,ans)<<endl;
  return 0;
}

Measured memory_bytes: 1340
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int a, b, c, k; cin >> a >> b >> c >> k;
  for(int i=0; i<k; i++) {
    if (a >= b) b *= 2;
    else if (b >= c) c *= 2;
  }

  if (a < b && b < c) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

// EOF

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

int n,k;
int h[100000];
//dp[i]: i번쨰부터 출발해서 도착할 때 까지 걸리는 최소 비용
int dp[100000];

int solve(int i){
	int& ret=dp[i];
	if(ret!=-1) return ret;
	if(i==n-1) return ret=0;
	ret=1000000000;
	for(int j=i+1;j<min(i+k+1,n);j++){
		ret=min(ret,abs(h[i]-h[j])+solve(j));
	}
	return ret;
}

int main(){
	cin>>n>>k;
	for(int i=0; i<n; i++){
		scanf("%d",h+i);
	}
	memset(dp, -1, sizeof(dp));
	cout<<solve(0);
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
using namespace std;
//using namespace __gnu_pbds;
#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
double PI=3.1415926535897932384626;
//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream fin("input.txt")
//#define of1 ofstream fout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll arr[5];
	for(int i=0;i<5;i++)
	{
		cin>>arr[i];
	}
	ll k;
	cin>>k;
	ll x,y;
	x=*min_element(arr,arr+5);
	y=*max_element(arr,arr+5);
	if(y-x<=k)
		cout<<"Yay!"<<endl;
	else
		cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    string s,t;
    int ans=0;
    cin >> s >> t;
    int len = s.length();
    // cout << len << endl;
    rep(i,len) if(s[i] != t[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3844
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main(){
    ll h,w;
    cin >> h >> w;
    vector<vector<ll>> c(10,vector<ll>(10));
    rep(i,10){
        rep(j,10){
            cin >> c[i][j];
        }
    }
    rep(k,10){
        rep(i,10){
            rep(j,10){
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    ll ans=0;
    rep(i,h){
        rep(j,w){
            ll a;
            cin >> a;
            if(a==-1) continue;
            ans+=c[a][1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include <stdio.h>
 
int main(void) {
    char eibun[1100];
    int i;
    fgets(eibun,sizeof(eibun),stdin);
    for(i=0;eibun[i+4]!=0;i++) {
        if(eibun[i]=='a' && eibun[i+1]=='p' && eibun[i+2]=='p' &&
            eibun[i+3]=='l' && eibun[i+4]=='e') {
            eibun[i]='p';
            eibun[i+1]='e';
            eibun[i+2]='a';
            eibun[i+3]='c';
            eibun[i+4]='h';
            continue;
        }
        if(eibun[i]=='p' && eibun[i+1]=='e' && eibun[i+2]=='a' &&
            eibun[i+3]=='c' && eibun[i+4]=='h') {
            eibun[i]='a';
            eibun[i+1]='p';
            eibun[i+2]='p';
            eibun[i+3]='l';
            eibun[i+4]='e';
        }
    }
    printf("%s",eibun);
    return 0;
}

Measured memory_bytes: 520
from functools import reduce
import math
import copy
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S_dash = list(_ for _ in input())
    T = list(_ for _ in input())
    S_dash = S_dash[::-1]
    T = T[::-1]
    for i in range(len(S_dash)-len(T)+1):
        flag = False
        for j in range(i,i+len(T)):
            if S_dash[j] == T[j-i] or S_dash[j] == '?':
                flag = True
            else:
                flag = False
                break
        if flag:
            for j in range(i,i+len(T)):
                S_dash[j] = T[j-i]
            break

    S = ''.join(S_dash[::-1]).replace('?','a')

    if S.count(''.join(T[::-1])) == 0:
        print('UNRESTORABLE')
        return
    print(S)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<stdio.h>
int main()
{
    double w,h,x,z;
    double s;
    int acm;
    while(~scanf("%lf%lf%lf%lf",&w,&h,&x,&z))
    {
        acm=0;
        s=w*h/2;
        if(x==w/2&&z==h/2)
            acm=1;
        printf("%8.6lf %d\n",s,acm);
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <queue>
using namespace std;
int main(){
	int N, M;
	long long temp, sum = 0;
	priority_queue <long long> pq;
	cin >> N >> M;
	for(int i = 0 ; i<N ; i++){
		cin >> temp;
		pq.push(temp);
	}
	while(M--){
		temp = pq.top();
		pq.pop();
		temp /= 2;
		pq.push(temp);
	}
	while(N--){
		temp = pq.top();
		pq.pop();
		sum += temp;
	}
	cout << sum << endl;


}

Measured memory_bytes: 3912
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
		
		String[] matrixStr = input.readLine().split(" ");
		
		int row = Integer.parseInt(matrixStr[0]);
		
		int rowCol = Integer.parseInt(matrixStr[1]);
		
		int column = Integer.parseInt(matrixStr[2]);
		
		int[][] matrixA = new int[row][rowCol];
		
		int[][] matrixB = new int[rowCol][column];
		
		long[][] matrixC = new long [row][column];
		
		//行列Aの作成
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			for(int rowColNum = 0; rowColNum < rowCol; rowColNum++)
			{
				matrixA[rowNum][rowColNum] = Integer.parseInt(rowStr[rowColNum]);
			}
		}
		
		//行列Bの作成
		for(int rowColNum = 0; rowColNum < rowCol; rowColNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				matrixB[rowColNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
			}
		}
		
		//行列Cの作成
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				long sum = 0;
				
				for(int rowColNum = 0; rowColNum < rowCol; rowColNum++)
				{
					sum = sum + matrixA[rowNum][rowColNum] * matrixB[rowColNum][columnNum];
				}
				
				matrixC[rowNum][columnNum] = sum;
			}
		}
		
		//行列Cの表示
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				System.out.print(matrixC[rowNum][columnNum]);
				if(columnNum != column - 1)
				{
					System.out.print(" ");
				}
			}
			
			System.out.println();
		}
	}
}



Measured memory_bytes: 35852
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T &u, const T z)
{
    if (u < z)
    {
        u = z;
        return true;
    }
    else
        return false;
}
template <typename T>
bool chmin(T &u, const T z)
{
    if (u > z)
    {
        u = z;
        return true;
    }
    else
        return false;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
bool is_prime(int x)
{
    if (x <= 1)
        return false;
    for (int i = 2; i * i <= x; i++)
        if (x % i == 0)
            return false;
    return true;
}
int a[100010];
int kazu[100010];
int main()
{
    int q;
    cin >> q;
    for (int i = 2; i <= 100000; i++)
    {
        if (is_prime(i) == true && is_prime((i + 1) / 2) == true)
        {
            a[i] = 1;
        }
    }
    rep(i, 100001)
    {
        if (i == 0)
            kazu[i] = a[i];
        else
            kazu[i] = a[i] + kazu[i - 1];
    }
    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        int ans = kazu[r] - kazu[l - 1];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4404
n = int(input())
point_dict1 = {}
point_dict2 = {}
for i in range(n):
    x, y = map(int, input().split())
    point_dict1[x + y] = (x, y)
    point_dict2[y - x] = (x, y)
min_point1 = min(point_dict1)
max_point1 = max(point_dict1)
min_point2 = min(point_dict2)
max_point2 = max(point_dict2)
print(max(max_point1 - min_point1, max_point2 - min_point2))


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

using namespace std;
int N;
string s[4] = {"SS","SW","WW","WS"};
string tmp;

int main() {
  cin >> N >> tmp;

  for(int i = 0; i < 4; i++) {
    string ans = s[i];
    for(int j = 1; j <= N;j++) {
      if(tmp[j%N] == 'o') {
	if(ans[j] == 'S') {
	  if(ans[j-1] == 'S') ans.push_back('S');
	  else ans.push_back('W');
	}
	else {
	  if(ans[j-1] == 'S') ans.push_back('W');
	  else ans.push_back('S');
	}
      }
      else {
	if(ans[j] == 'S') {
	  if(ans[j-1] == 'S')ans.push_back('W');
	  else ans.push_back('S');
	}
	else {
	  if(ans[j-1] == 'S')ans.push_back('S');
	  else ans.push_back('W');
	}
      }
    }
    bool is = false;
    /*for(int i = N-1; i <=N; i++) {
      if(tmp[i%N] == 'o') {
	if(ans[i] == 'S'){
	  if(ans[i-1] == ans[i+1])continue;
	}
	else {
	  if(ans[i-1] != ans[i+1])continue;
	}
      }
      else {
	if(ans[i] == 'S'){
	  if(ans[i-1] != ans[i+1])continue;
	}
	else {
	  if(ans[i-1] == ans[i+1])continue;
	}
      }
      is = false;
      }*/
    if(ans[0] == ans[ans.length()-2] && ans[1] == ans[ans.length()-1])
      is = true;
    
   
    // cout << ans <<endl;
    if(is) {
     
      cout << ans.substr(0,ans.length()-2) <<endl;
      return 0;
    }
  

  }
    
    cout <<"-1"<<endl;
}
  


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

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


Measured memory_bytes: 256