akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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

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



int N, Q;
string s;
vector<int> kouho;


int main () {
  cin >> N >> Q;
  cin >> s;


  Rep(i, N-1) {
    if (s[i] == 'A' && s[i+1] == 'C') {
      kouho.push_back(i+1);
    }
  }

  Rep(i, Q) {
    int l, r;
    cin >> l >> r;

    auto iter1 = lower_bound(All(kouho), l);
    auto iter2 = lower_bound(All(kouho), r);

    cout << iter2 - iter1 << "\n";
  }
}

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

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var A = ReadLine().Split().Select(long.Parse).ToArray();

        Array.Sort(A);
        Array.Reverse(A);
        PriorityQueue<long> que = new PriorityQueue<long>(N,(x,y)=>-x.CompareTo(y));
        que.Push(A[0]);
        long ans = 0;
        for (int i = 1; i < N; i++)
        {
            var t = que.Pop();
            ans += t;
            que.Push(A[i]);
            que.Push(A[i]);
        }

        WriteLine(ans);
    }
}
public class PriorityQueue<T>
{
    public long Size { get; private set; } = 0;
    public long MaxSize { get; private set; } = 0;
    public T[] m_heap;
    private Comparison<T> Comp = null;

    public PriorityQueue(long maxSize, Comparison<T> comp)
    {
        if (maxSize <= 0)
            throw new Exception();
        MaxSize = maxSize;
        m_heap = new T[maxSize];

        Comp = comp;
    }

    public void Push(T x)
    {
        if (Size == MaxSize)
        {
            T[] new_heap = new T[MaxSize << 1];
            Array.Copy(m_heap, new_heap, MaxSize);
            m_heap = new_heap;
            MaxSize <<= 1;
        }

        long i = Size++;
        while (i > 0)
        {
            long p = (i - 1) / 2;
            if (Comp(m_heap[p], x) <= 0)
                break;
            m_heap[i] = m_heap[p];
            i = p;
        }
        m_heap[i] = x;
    }

    public T Pop()
    {
        if (Size == 0)
            throw new Exception("Queue is empty.");

        T result = m_heap[0];
        T x = m_heap[--Size];
        long i = 0;
        while (i * 2 + 1 < Size)
        {
            long c1 = i * 2 + 1, c2 = i * 2 + 2;
            if (c2 < Size && Comp(m_heap[c2], m_heap[c1]) < 0)
                c1 = c2;
            if (Comp(m_heap[c1], x) >= 0)
                break;
            m_heap[i] = m_heap[c1];
            i = c1;
        }
        m_heap[i] = x;

        return result;
    }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int keep = 5000;
  for (int i = 5000; i >= 1; i--) {
    if ((i + 1) * i / 2 >= n) keep = i;
    else break;
  }
  
  vector<int> ans;
  int sum = 0;
  for (int i = keep; i >= 1; i--) {
    if (sum + i <= n) {
      ans.emplace_back(i);
      sum += i;
    }
    else continue;
  }
  
  for (int i = ans.size() - 1; i >= 0; i--) cout << ans.at(i) << '\n';
}

Measured memory_bytes: 384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A_max = copy(A)
    A_max.sort(reverse=True)

    for a in A:
        if a == A_max[0]:
            print(A_max[1])
        else:
            print(A_max[0])


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long;


int main() { 
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++)cin >> A[i];
    
    sort(A.begin(), A.end(), std::greater<int>());

    ll ans = 0;
    for(int i=0; i<N-1; i++){
        ans += A[(i+1)/2];
    }
    cout << ans << endl; 
}

Measured memory_bytes: 4828
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int a[105];
signed main(void)
{
  int K, T;
  cin >> K >> T;
  REP(i, T) {
    cin >> a[i];
  }
  sort(a, a+T, greater<int>());

  int sum = 0;
  FOR(i, 1, T) {
    sum += a[i];
  }
  cout << max(1, a[0] - sum) - 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(ll i=k;i<n;i++)
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define xx first
#define yy second
#define MOD 1000000007
#define pb push_back
typedef long long ll;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}


int t[100000][2];
int dp[100001];
int n,k;



int main(){
	FAST
	cin >> n >> k;
	rep(i,n) cin >> t[i][0] >> t[i][1];
	memset(dp,-1,sizeof(dp));
	dp[0] = 0;
	rep(j,n){
		for(int i = 100000;i - t[j][1] >= 0;i--){
			if(dp[i-t[j][1]] != -1){
				if(dp[i] == -1){if(dp[i-t[j][1]] + t[j][0] <= k) dp[i] = dp[i-t[j][1]] + t[j][0];}
				else if(dp[i-t[j][1]] + t[j][0] <= dp[i]) dp[i] = dp[i-t[j][1]] + t[j][0];
			}
		}
	}	
	for(int i = 100000;i >= 0;i--){
		if(dp[i] != -1)
		return cout << i <<endl,0;
	}
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var xylst = new List<List<long>>();
            for(var i=0;i<N;++i)
                xylst.Add(Slist());
            var p = AllPermutation(Enumerable.Range(1, (int)N).ToArray());
            var dst = 0D;
            foreach (var pl in p)
            {
                for (var i = 0; i < pl.Length-1; ++i)
                {
                    var from = xylst[pl[i] - 1];
                    var to = xylst[pl[i + 1] - 1];
                    dst += Math.Sqrt(
                        (from[0] - to[0]) * (from[0] - to[0]) +
                            (from[1] - to[1]) * (from[1] - to[1])
                            );
                }
            }
            var ave = dst / p.Count();
            WriteLine(ave);

            //Out.Flush();
        }
        //https://webbibouroku.com/Blog/Article/cs-permutation
        static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable
        {
            var a = new List<T>(array).ToArray();
            var res = new List<T[]>();
            res.Add(new List<T>(a).ToArray());
            var n = a.Length;
            var next = true;
            while (next)
            {
                next = false;

                // 1
                int i;
                for (i = n - 2; i >= 0; i--)
                {
                    if (a[i].CompareTo(a[i + 1]) < 0) break;
                }
                // 2
                if (i < 0) break;

                // 3
                var j = n;
                do
                {
                    j--;
                } while (a[i].CompareTo(a[j]) > 0);

                if (a[i].CompareTo(a[j]) < 0)
                {
                    // 4
                    var tmp = a[i];
                    a[i] = a[j];
                    a[j] = tmp;
                    Array.Reverse(a, i + 1, n - i - 1);
                    res.Add(new List<T>(a).ToArray());
                    next = true;
                }
            }
            return res;
        }
    }
}

Measured memory_bytes: 22360
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define rep(I, N) for (int I = 1; I <= (N); ++I)
#define repp(I, N) for (int I = 0; I < (N); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORR(I, A, B) for (int I = (A); I >= (B); I--)
#define SORT_UNIQUE(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
const int N = 2e5 + 5;
const double eps = 1e-7;
const int mod = 1e9 + 7;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
LL gcd(LL a, LL b) { return b > 0 ? gcd(b, a % b) : a; }
LL ksm(LL a, LL b)
{
    LL ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}
LL dp[N][100];
char s[N];
int main()
{
    scanf("%s", s + 1);
    dp[0][0] = 1;
    int n = strlen(s + 1);
    for (int i = 1;i <= n;i++)
    {
        if (s[i] >= '0' && s[i] <= '9')
        {
            for (int j = 0; j < 13; j++)
            {
                dp[i][(j * 10 + s[i] - '0') % 13] = (dp[i][(j * 10 + s[i] - '0') % 13] + dp[i - 1][j])%mod;
            }
        }
        else
        {
            for (int j = 0; j < 13;j++)
            {
                for (int k = 0; k <= 9;k++)
                {
                    dp[i][(j * 10 + k) % 13] = (dp[i][(j * 10 + k) % 13] + dp[i - 1][j]) % mod;
                }
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}


Measured memory_bytes: 80000
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	cin >> s;
	n = s.size() - 1;
	ll res = 0;
	for (ll i = n; i >= 0; i--) {
		if (s[i] == 'B') {
			res += n - i;
			--n;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    int h, w;
	cin >> h >> w;

	string field[h];
	char ans[h][w];

	int i, j;
	for(i = 0; i < h; i++){
		cin >> field[i];
	}

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

	for(i = 0; i < h; i++){
		for(j = 0; j < w; j++){
			if (field[i][j] == '#'){
				ans[i][j] = '#';
				continue;
			}
 
			int num = 0;
			for (int d = 0; d < 8; ++ d) {
				int ni = i + dy[d];
				int nj = j + dx[d];
 
				if (ni < 0 or h <= ni) continue;
				if (nj < 0 or w <= nj) continue;
				if (field[ni][nj] == '#') num++;
			}
 
			ans[i][j] = char(num + '0');
		}
	}

	for (i = 0; i < h; ++i){
		for(j = 0; j < w; j++){
			cout << ans[i][j];
		}
		cout << endl;
	}
}
	


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

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

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    ll N = S.length();

    cout << S[0];
    cout << N-2;
    cout << S[N-1];
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(void)
{
	int i,N, X,min,total, m[100],ans;

	scanf("%d%d", &N, &X);
	
	min = 1001;
	total = 0;

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

	for (i = 0; i < N; i++)
	{
		if (m[i] < min)
			min = m[i];

		total += m[i];
	}

	X -= total;
	ans = N;

	ans += X / min;

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
import numpy as np
n = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = sum(X[i]**2 for i in range(n))
m = np.floor(a/n)
if m + 1/2 <= a/n:
  m += 1
s = n*(m**2) - 2*a*m + b
print(int(s))


Measured memory_bytes: 21540
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

using ll = long long;
using VI = vector<int>;
using PI = pair<int, int>;

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

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 gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
    int N, K;
    cin >> N >> K;
    int ans = 0;
    rep(i, N)
    {
        int h;
        cin >> h;
        if (h >= K) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> t3;


#define X first
#define Y second
using namespace std;
typedef long long ll;
const ll inf = 1e18;

ll n;
pair<ll,ll> a[200005];

int main()
{
    ll n,m;
    cin >> n >> m;
    vector<ll> x(n);
    vector<ll> y(m);
    for(int i = 0;i < n;i++)
    {
        cin >> x[i];
    }
    for(int i = 0;i < m;i++)
    {
        cin >> y[i];
    }
    const ll mod = 1e9 + 7;
    ll w = 0;
    for(int i = 0;i < n;i++)
    {
        ll unit = x[i] * (i - (n - 1 - i));
        unit %= mod;
        w += unit;
        w %= mod;
    }
    ll h = 0;
    for(int i = 0;i < m;i++)
    {
        ll unit = y[i] * (i - (m - 1 - i));
        unit %= mod;
        h += unit;
        h %= mod;
    }
    ll s = (w * h) % mod;
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1792
a1 = [1,3,5,7,8,10,12]
a2 = [4,6,9,11]
a3 = [2]
x,y=map(int, input().split())
if x in a1 and y in a1:
    print('Yes')
elif x in a2 and y in a2:
    print('Yes')
elif x in a3 and y in a3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n;
string a, b;
int main(){
    cin >> n >> a >> b;
    for(int i=0;i<=n;i++){
        bool f = 1;
        for(int j=0;j<(int)a.size();j++) if(a[j]!='0' && b[j]!='0' && a[j]!=b[j]) f = 0;
        if(f) return cout << n+i, 0;
        a = a+'0';
        b = '0'+b;
    }
}

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

using namespace std;

typedef long long ll;

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

ll cnt(ll p, ll c, ll d)
{
  return p - p / c - p / d + p / (c * d / gcd(c, d));
}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll sol = cnt(b, c, d) - cnt(a - 1, c, d);
  cout << sol << "\n";


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std ;
int fun (int,int);
int main()
{
int a,b;
cin>>a>>b;
int w=a+b;
int y=a-b;
int z=a*b;
cout <<fun(fun(y,z),w);
return 0 ;
}
int fun(int a,int b)
{
    if(a>b)return a;
    else return b;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int dp[1<<12];
int n,m;
int a[12],b[12];
int f(int A,int B)
{
	int s=abs(A-B);
	return s*(s-30)*(s-30);
}
main()
{
	while(cin>>n>>m,n)
	{
		if(n>=m)
		{
			for(int i=0;i<n;i++)cin>>a[i];
			for(int j=0;j<m;j++)cin>>b[j];
		}
		else
		{
			for(int i=0;i<n;i++)cin>>b[i];
			for(int j=0;j<m;j++)cin>>a[j];
			swap(n,m);
		}
		for(int i=0;i<1<<n;i++)dp[i]=0;
		int ans=0;
		for(int i=1;i<1<<n;i++)
		{
			int t=__builtin_popcount(i)-1;
			if(t>=m)continue;
			int now=0;
			for(int j=0;j<n;j++)
			{
				if(i&1<<j)
				{
					now=max(now,dp[i&~(1<<j)]+f(a[j],b[t]));
				}
			}
			ans=max(ans,dp[i]=now);
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3112
#include <iostream>
using namespace std;
int n, x, y;
long long s;

int main()
{
   cin>>n;
   cin>>x;
   for(int i=2; i<=n; i++)
   {
       cin>>y;
       if(y<x) s+=(x-y), y=y+(x-y);
       x=y;

   }
   cout<<s;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
using namespace std;

double abs2(const double n){
	if (n < 0) return -(n);
	return n;
}

int main(){
	double a, b, c, d, e, f;
	double x, y;
	double A, B, C;
	const double p = 0.00000001;

	while (cin >> a >> b >> c >> d >> e >> f){
		A = (a*e) - (b*d);
		B = (c*e) - (b*f);
		C = (a*f) - (c*d);

		x = B / A;
		y = C / A;
		
		if (abs2(x) < p) x = 0;
		if (abs2(y) < p) y = 0;

		printf("%.3lf %.3lf\n", x, y);
	}
	
	return 0;
}

Measured memory_bytes: 3208
#include <stdio.h>

int main(void)
{
    int H,W;
    int i,j,k,count;

    int a[100][2];

    for(count=0;;count++){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0){
            break;
        }

        a[count][0]=H;
        a[count][1]=W;
    }

    for(i=0;i<count;i++){
        /* 長方形 */
        for(j=0;j<a[i][0];j++){
            /* 横一列 */
            for(k=0;k<a[i][1];k++){
                if((j+k)%2 == 0){
                    printf("#");
                }
                else{
                    printf(".");
                }

            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2680
n, k = map(int, input().split())
l = list(map(int, input().split()))

l = [c-1 for c in l]
 
l = [0] + l
from itertools import accumulate
cum =list(accumulate(l))
cum = [c%k for c in cum]

from collections import deque
ans = 0
d = {}
q = deque()
for i in range(n+1):
  if cum[i] not in d:
    d[cum[i]] = 1
  else:
    ans += d[cum[i]]
    d[cum[i]] += 1
  q.append(cum[i])
  if len(q) == k:
    rem = q.popleft()
    d[rem] -= 1
print(ans)

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

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

  vector<vector<int>> start(n,vector<int>(2));
  for(int i=0;i<n;i++){
    cin>>start.at(i).at(0)>>start.at(i).at(1);
  }
  vector<vector<int>> goal(m,vector<int>(2));
  for(int i=0;i<m;i++){
    cin>>goal.at(i).at(0)>>goal.at(i).at(1);
  }

  for(int i=0;i<n;i++){
    int mindis=1e+9;
    int next=-1;
    for(int j=0;j<m;j++){
      int dis=abs(start.at(i).at(0)-goal.at(j).at(0))+abs(start.at(i).at(1)-goal.at(j).at(1));
      if(dis<mindis){
        mindis=dis;
        next=j+1;
      }
    }
    cout<<next<<endl;
  }
}


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

const ll INF = 1LL << 60;

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

    string s[105];

    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            if (i < 50) {
                s[i].push_back('.');
            } else {
                s[i].push_back('#');
            }
        }
    }

    // 上半分 . -> # に変更する B を増やす (B - 1回)
    int cnt = 0;
    for (int i = 0; i < 50; i += 2) {

        if (B - 1 == cnt) break;

        for (int j = 0; j < 100; j += 2) {
            if (B - 1 == cnt) break;
            s[i][j] = '#';

            cnt++;
        }
    }

    // 下半分 # -> . に変更する A を増やす (A - 1回)
    cnt = 0;
    for (int i = 51; i < 100; i += 2) {

        if (A - 1 == cnt) break;

        for (int j = 0; j < 100; j += 2) {
            if (A - 1 == cnt) break;
            s[i][j] = '.';
            cnt++;
        }
    }

    cout << 100 << " " << 100 << endl;
    rep(i, 100) {
        cout << s[i] << endl;
    }

}

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

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int k = Integer.parseInt(br.readLine());
		int x = Integer.parseInt(br.readLine());
		int y = Integer.parseInt(br.readLine());

		if (n < k) {
			System.out.println(n * x);
		} else {
			System.out.println((k * x) + ((n - k) * y));
		}
	}
}


Measured memory_bytes: 21204
#include<stdio.h>
#include<string.h>
int main(){
	int N;
	int harshad = 0;
	char N_str[10];
	scanf("%s", &N_str);
 	
	N = atoi(&N_str);

	for(int i = 0; i < strlen(N_str); i++){
		harshad += N_str[i] - '0';
	}
	if(N % harshad == 0) {
	printf("Yes\n");
	} else {
	printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<cstdio>


using namespace std ;


int sports[ 1000 + 1 ] ;

int cnt[ 1000 + 1 ] ;
int CNT[ 1000 + 1 ] ;

int cmp ;

int N ,M ;


int ans()
{
	sort( cnt + 1 ,cnt + N + 1 ) ;

	return ( find_if( CNT ,CNT + N + 1 ,[]( int cmpair ){ return cmpair == cnt[ N ] ; } ) - CNT ) ;
}



int main( void )
{
	scanf( "%d %d" ,&N ,&M ) ;

	int i ;
	for( i = 1 ; i <= N ; ++i )
	{
		scanf( "%d" ,&cmp ) ;

		sports[ i ] = cmp ;
	}

	for( i = 0 ; i < M ; ++i )
	{
		scanf( "%d" ,&cmp ) ;

		++cnt[ ( find_if( sports + 1 ,sports + N + 1 ,[]( int cmpair){ return cmp >= cmpair ; } ) - sports ) ] ;
	}


	copy( cnt ,cnt + N + 1 ,CNT ) ;


	printf( "%d\n" ,ans() ) ;


	return 0 ;
}

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


bool binarySearch(int arr[], int low, int high, int value) {
  int p = low + (high-low)/2;
  if (high < low) return false;

  if (arr[p] == value) {
    return true;
  } else if(arr[p] > value) {
    return binarySearch(arr, 0, p-1, value);
  } else {
    return binarySearch(arr, p+1, high, value);
  }
}

int main() {
  int n, S[100000];
  int q, T;
  int ans = 0;

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

  cin >> q;
  for(int i=0; i < q; i++) {
    cin >> T;
    if (binarySearch(S, 0, n-1, T)) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main(void){

    int n;
    long long int total = 0;

    cin >> n;

    vector<int> A(n);
    vector<int> B(n-1);
    vector<int> C(n);

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

    C[0] = B[0];

    for(int i = 1;i <= n-1;i++){
        C[i] = min(B[i-1], B[i]);
    }

    C[n-1] = B[n-2];

    for(int i = 0;i < n;i++){
        total += C[i];
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
from collections import Counter, deque, defaultdict

N = int(input())
S = input()

mi = 10000000

c = Counter(S)
A = N - c["#"]
B = N - c["."]

l = 0
r = c["."]

for i in range(0, N):

    if S[i] == "#":
        l += 1
    else:
        r -= 1
    a = l + r
    if mi > a:
        mi = a

print(min(mi, A, B))

Measured memory_bytes: 3880
package main

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

func main() {
	N := getStdinInt()

	switch {
	case (N%10 == 2) ||
		(N%10 == 4) ||
		(N%10 == 5) ||
		(N%10 == 7) ||
		(N%10 == 9):
		fmt.Printf("hon\n")
	case (N%10 == 0) ||
		(N%10 == 1) ||
		(N%10 == 6) ||
		(N%10 == 8):
		fmt.Printf("pon\n")
	case (N%10 == 3):
		fmt.Printf("bon\n")
	}
}

var sc = bufio.NewScanner(os.Stdin)

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}


Measured memory_bytes: 1772
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    while (1) {
        int a,L;
        scan(a,L);
        if (!L) return;
        solve(a,L);
    }
}

void solve(int a, int L) {
    auto as = new int[](21);
    as[0] = a;

    foreach (i ; 1 .. 21) {
        as[i] = calmax(as[i-1], L) - calmin(as[i-1], L);

        foreach (j ; 0 .. i) {
            if (as[i] == as[j]) {
                writeln(j, " ", as[i], " ", i-j);
                return;
            }
        }
    }
}

int calmax(int x, int L) {
    auto cnt = new int[](10);

    while (x > 0) {
        cnt[x % 10]++;
        x /= 10;
    }

    cnt[0] += max(0, L - cnt.sum);

    int res;
    foreach_reverse (i ; 0 .. 10) {
        foreach (j ; 0 .. cnt[i]) {
            res *= 10;
            res += i;
        }
    }

    debug {
        writeln(res);
    }

    return res;
}

int calmin(int x, int L) {
    auto cnt = new int[](10);

    while (x > 0) {
        cnt[x % 10]++;
        x /= 10;
    }

    cnt[0] += max(0, L - cnt.sum);
    
    int res;
    foreach (i ; 0 .. 10) {
        foreach (j ; 0 .. cnt[i]) {
            res *= 10;
            res += i;
        }
    }

    debug {
        writeln(res);
    }

    return res;
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 2464
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
}


Measured memory_bytes: 256
while True :
    x,y=input().split()
    if int(x)==0 and int(y)==0 : break
    i=0
    while i<int(x) :
        k=0
        while k<int(y) :
            print("#", end="")
            k=k+1
        print("")
        i=i+1
    print("")


Measured memory_bytes: 7008
#include<bits/stdc++.h>
#define pb push_back
#define INF (ll)1e9
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define fixed setprecision(9)
using namespace std;
using ll = long long;

int main(){
	string s,t;
	cin>>s;
	t= s;
	int n = s.size();
	for(int i=0;i<n;i++)
	{
		t[i] ='x';
	}
	cout<<t;
	
	return 0;
}




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

int main() {
	int N;
	cin >> N;
	int a[100];

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

	int tempmin = a[0];
	int tempmax = a[0];

	for (int i = 0; i < N; i++) {
		/* 最大値求める */
		if (a[i]>tempmax)
			tempmax = a[i];
		/* 最小値求める */
		if (a[i]<tempmin)
			tempmin = a[i];
	}
	
	cout << (tempmax - tempmin) << endl;
	
	
}

Measured memory_bytes: 256
#include<iostream>
#include<ctype.h>
using namespace std;
int main()
{ int f=1;
string s;
  getline(cin,s);
 int n;
  n=s.size();
 
for (int i=0;i<n;i+=1)
{
   if ((s[i]!='R'&& s[i]!='D'&& s[i]!='U')&& i%2==0)
   {
     f=0;
     break;
   }
  if ((s[i]!='L'&&s[i]!='U'&&s[i]!='D'&& i%2!=0))
   {
     f=0;
     break;
   }


}
if (f==1)
  cout<<"Yes";
 else 
   cout<<"No";
  

return 0;
}










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

using namespace std;
using ll = long long;
int main() {
    int n;cin>>n;
    int h=0;
    int ans=0;
    for(int i = 0;i < n;++i) {
        int t;
        cin>>t;
        if(t>=h)++ans;
        h=max(t,h);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut sum = 0;
    let n = read::<usize>();

    for _ in 0..n {
        let a = read::<usize>();
        if is_prime(a) {
            sum += 1;
        }
    }

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

fn is_prime(x: usize) -> bool {
    if x == 2 { return true; }
    if x < 2 || x % 2 == 0 { return false; }

    let mut i = 3;
    while i as f64 <= (x as f64).sqrt() {
        if x % i == 0 { return false; }
        i += 2;
    }
    return true
}

/// 標準入力から一行を読み取り、指定の型に変換する関数
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}



Measured memory_bytes: 5036
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a,b,c;
	cin>>a>>b;
	c=a-b*2;
	if(c<=0)
		cout<<0<<endl;
	else
		cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)]

def dfs(a_l):
  if len(a_l)==n:
    global ans
    t_ans=0
    for a,b,c,d in l:
      a-=1
      b-=1
      if (a_l[b]-a_l[a]==c):
        t_ans+=d
    ans=max(ans,t_ans)

    return

  a_last=a_l[-1]
  for i in range(a_last,m+1):
    dfs(a_l+[i])

ans=0
for i in range(1,m+1):
  dfs([i])

print(ans)

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

int main () {
  long long K , A , B ;
  cin >> K >> A >> B ;
  long long ans = 0 ;
  
  if(A>=B-2){
    cout << K + 1 << endl ;
  } else {
    if(K <= A-1){
      cout << K + 1 << endl ;
    }else {
      long long pre = K - A + 1  ;
      if(pre%2==0) {
        cout << pre / 2 * (B-A) + A << endl ;
      } else {
        cout <<  (pre-1) / 2  * ( B - A ) + 1 + A << endl ;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const int maxn=2e5+10;
bool vis[maxn];
ll a[maxn];
vector<ll>num;
int main()
{
	ll n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	num.push_back(1ll);
	memset(vis,1,sizeof(vis));
	ll index=a[1];
	vis[1]=0;
	while(vis[index]){
		vis[index]=0;
		num.push_back(index);
		index=a[index];
	}
	if(k<num.size()){
		cout<<num[k]<<endl;
	}else{
		ll tmp,len=num.size();
		for(ll i=0;i<len;i++){
			if(num[i]==index){
				tmp=i;
				break;
			}
		}
		
		ll in=len-tmp;
		//cout<<"len="<<in<<endl;
		cout<<num[tmp+(k-len)%in]<<endl;
	}
 	return 0;
}

/*
5 100
2 3 4 5 1 
*/





Measured memory_bytes: 7068
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	map<string, int> s;
	int maxS = 0;
	for (auto i = 0; i < N; ++i)
	{
		string S;
		cin >> S;
		++s[S];
		maxS = max(maxS, s[S]);
	}

	for (auto& p : s)
	{
		if (p.second == maxS)
		{
			cout << p.first << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int x; cin >> x;
	cout << ((x * 360)/__gcd(x, 360))/x;

	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define N 100
#define M 26
using namespace std;
string s;
int p,l;
   
string bnf(){
  string r;
  int c=0;
  while(p!=l){
    char t=s[p];
    if(t=='+')p++,c++;
    if(t=='-')p++,c--;
    if('A'<=t&&t<='Z')
      r+=((s[p++]+c+M*N)-'A')%M+'A',c=0;
    if(t=='?')r+=s[p++],c=0;
    if(t=='[')p++,r+=bnf();
    if(t==']'){
      p++;
      reverse(r.begin(),r.end());
      break;
    }
  }  
  return r;
}
   
int main(){
  while(1){
    cin>>s;
    if(s==".")break;
    l=s.size();
    p=0;
    string a=bnf();
    for(int i=0;i<a.size();i++)
      if(a[i]=='?')a[i]='A';
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int n=s.length();
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]!=t[i])
		cnt++;
	}
	cout<<cnt<<endl;
}


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

using namespace std;

int used[100];
int main(void){
vector<pair<int,int> >red;
vector<pair<int,int> >blue;
int n;
int result=0;
cin >> n;
for(int i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    red.push_back({a,b});

}
for(int i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    blue.push_back({a,b});

}

sort(blue.begin(),blue.end());
for(int i=0;i<n;i++){
    int ch=-1;
    int what=-1;
    for(int j=0;j<n;j++){
        if(used[j])continue;
        if(blue[i].first<red[j].first)continue;
        if(blue[i].second<red[j].second)continue;
        if(red[j].second>ch){
            ch=red[j].second;
            what=j;
        }
    }
    if(what==-1)continue;
    used[what]=1;
    result++;
}
cout << result;
}



Measured memory_bytes: 256
#include<queue>
#include<string>
#include<iostream>

#define	mp	make_pair

using namespace std;

typedef	pair<int,int>	pii;

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

int main(){
	for(int w,h;cin>>h>>w,h;){
		char grid[20][21];
		int px,py,qx,qy;
		for(int i=0;i<h;i++){
			cin>>grid[i];
			for(int j=0;j<w;j++){
				if(grid[i][j]=='A')	px=j,py=i,grid[i][j]='.';
				if(grid[i][j]=='B')	qx=j,qy=i,grid[i][j]='.';
			}
		}
		string cmd;	cin>>cmd;

		int girlcost[20][20];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)	girlcost[i][j]=1<<30;
		girlcost[py][px]=0;
		queue< pair<int,pii> > qu;	qu.push(mp(0,mp(px,py)));
		while(!qu.empty()){
			pair<int,pii> a=qu.front();	qu.pop();
			int cost=a.first,x=a.second.first,y=a.second.second;
			for(int i=0;i<4;i++){
				int xx=x+dx[i],yy=y+dy[i];
				if(0<=xx && xx<w && 0<=yy && yy<h && grid[yy][xx]!='#'){
					int nextcost=cost+1;
					if(nextcost<girlcost[yy][xx]){
						qu.push(mp(nextcost,mp(xx,yy)));
						girlcost[yy][xx]=nextcost;
					}
				}
			}
		}

		int ans=1<<30,ansx,ansy;
		int len=cmd.length();
		bool visited[20][20][10]={};
		for(int t=0,i=0;;t++,i=(i+1)%len){
			if(t>w*h && visited[qy][qx][i])	break;
			visited[qy][qx][i]=true;

			if(girlcost[qy][qx]<=t){
				ans=t;
				ansx=qx;
				ansy=qy;
				break;
			}

			switch(cmd[i]){
				case '2':	if(qy<h-1)	qy++; break;
				case '4':	if(qx>0)	qx--; break;
				case '6':	if(qx<w-1)	qx++; break;
				case '8':	if(qy>0)	qy--; break;
			}
		}

		if(ans<(1<<30))	cout<<ans<<' '<<ansy<<' '<<ansx<<endl;
		else			cout<<"impossible"<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
N = int(input())
S = []
for _ in range(N):
    S.append(input())
for i in range(N):
    S[i] = sorted(S[i])
S = sorted(S)
ans = 0
sa = 1
for i in range(N):
    if i == N-1:
        if sa == 1:
            break
        else:
            ans += int(sa * (sa - 1) / 2)
            break
    if S[i] == S[i+1]:
        sa += 1
    else:
        if sa == 1:
            continue
        else:
            ans += int(sa * (sa - 1) / 2)
            sa = 1
print(ans)

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

	reverse(S.begin(), S.end());
	for (int i  = 0; i < 4; ++i){
		reverse(divide[i].begin(), divide[i].end());
	}

    bool can = true;
    for (int i = 0; i < S.size();) {
        bool can2 = false;
        for (int j = 0; j < 4; ++j) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2) {
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
from math import gcd
import itertools
K=int(input())
res=0
li=[]
for x in itertools.product(range(1,K+1),repeat=2):
    li.append(gcd(x[0],x[1]))
for x,y in itertools.product(range(1,K+1),li):
    res+=gcd(x,y)
print(res)

Measured memory_bytes: 9620
# Belongs to : midandfeed aka asilentvoice
import string
s = ""
while(1):
	try:
		s += str(input()).lower()
	except:
		break
		
alphabet = string.ascii_lowercase
ans = [0]*26
for x in s:	
	if x in alphabet:
		ans[ ord(x)-ord('a') ] += 1

for i in range(len(ans)):
	print("{} : {}".format(chr(i+ord('a')), ans[i]))

Measured memory_bytes: 8096
#include <bits/stdc++.h>
using namespace std;
bool kaibun(string s){
	for(int i = 0; i < s.length() / 2; i++){
		if(s[i] != s[s.length() - 1 - i]){
			return false;
		}
	}
	return true;
}
int main(){
	int a, b, cnt = 0;
	cin >> a >> b;
	for(int i = a; i <= b; i++){
		if(kaibun(to_string(i))) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

a, b = sys.stdin.buffer.readline().decode().rstrip().split()
ans = Decimal(a) * Decimal(b)
print( int(ans))


Measured memory_bytes: 27212
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative

readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

f (a,b) = if aLength <= bLength then bLength else aLength
  where
    aLength = length . show $ a
    bLength = length . show $ b

divisor' n = loop 1
  where
    loop d
      | n < d^2 = []
      | n == d^2 = [f (d,d)]
      | otherwise = if r == 0 then f (d,q) : loop (d+1) else loop (d+1)
      where (q,r) = n `divMod` d


divisor'' n = loop 1
  where
    loop d
      | n < d^2 = 10
      | n == d^2 = f (d,d)
      | otherwise = if r == 0 then min (f (d,q)) (loop (d+1)) else loop (d+1)
      where (q,r) = n `divMod` d

main = do
  n <- readLn :: IO Int
  print $ divisor'' n


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

bool custom (vector<int> &a, vector<int> &b) {
  return (a.size() < b.size());
}

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> r(n);
  vector<pair<int, int>> b(n);
  vector<vector<int>> rpp(n);
  vector<vector<int>> bpp(n);
  for(int i=0;i<n;i++) {
    cin >> r[i].first >> r[i].second;
  }
  for(int i=0;i<n;i++) cin >> b[i].first >> b[i].second;
  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {
      if(r[i].first < b[j].first && r[i].second < b[j].second) {
        rpp[i].emplace_back(j);
        bpp[j].emplace_back(i);
      }
    }
  }

  vector<vector<int>> rp = rpp;
  vector<vector<int>> bp = bpp;

  sort(rp.begin(), rp.end(), custom);

  int ans = 0;
  vector<bool> used(n);
  for(int i=0;i<n;i++) {
    int partner = -1;
    int minSize = 101;
    for(int j=0;j<rp[i].size();j++) {
      if(used[rp[i][j]]) continue;
      if(bp[rp[i][j]].size() < minSize) {
        partner = rp[i][j];
        minSize = bp[rp[i][j]].size();
      }
    }
    if(partner == -1) continue;
    ans++;
    used[partner] = true;
  }

  sort(bp.begin(), bp.end(), custom);

  int ans2 = 0;
  vector<bool> used2(n);
  for(int i=0;i<n;i++) {
    int partner = -1;
    int minSize = 101;
    for(int j=0;j<bp[i].size();j++) {
      if(used2[bp[i][j]]) continue;
      if(rpp[bp[i][j]].size() < minSize) {
        partner = bp[i][j];
        minSize = rpp[bp[i][j]].size();
      }
    }
    if(partner == -1) continue;
    ans2++;
    used2[partner] = true;
  }

  cout << max(ans, ans2) << endl;
}

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

int main() {
  ll MOD = 1000000007;
  ll N;
  cin >> N;
  ll a=1,b=2,c=1;
  for (int i = 0; i < N; i++) {
    a = (a*10)%MOD;
    b = (b*9)%MOD;
    c = (c*8)%MOD;
  }
  ll ans = (a-b+c)%MOD;
  if (ans < 0) ans += MOD;
  cout << ans << endl;
}

Measured memory_bytes: 3552
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scan(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
//------------------------------------------------------
int n;
vector<int> a;
void input(){
    cin>>n;
    scan(n,a);
}
void src(){
    int count=0;
    int eq=0;
    rep(i,n-1){
        if(a[i]==a[i+1]){
            eq++;
        }else{
            count += (eq+1)/2;
            eq=0;
        }
    }
    count += (eq+1)/2;
    eq=0;
    cout<<count;
}   
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

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

int main()
{
  int x,y,n;
  n=0;
  cin>>x>>y;

  for(int i=x;i<=y;i++)
  {
    int a,b,d,e;
    a=i/10000;
    b=(i%10000)/1000;
    d=(i%100)/10;
    e=i%10;

    if(a==e&&b==d)
    {
      n++;
    }
  }
  cout<<n<<endl;
}


Measured memory_bytes: 256