akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 7;

ll FactorialMOD(ll n)
{
    if (n == 1)
    {
        return 1LL;
    }
    else
    {
        return n * FactorialMOD(n - 1) % MOD;
    }
}

int main()
{
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if (abs(n - m) == 1)
    {
        ans = FactorialMOD(max(n, m)) * FactorialMOD(min(n, m)) % MOD;
    }
    else if (n == m)
    {
        ans = FactorialMOD(n);
        ans = ans * ans % MOD;
        ans = ans * 2LL % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
 
int main(){
  using std::cout;
  using std::endl;
  
  int n;
  std::cin >> n;
  
  //ゴリ押し
  if(n < 2) cout << 1 << endl;
  else if(n < 4) cout << 2 << endl;
  else if(n < 8) cout << 4  << endl;
  else if(n < 16) cout << 8 << endl;
  else if(n < 32) cout << 16 << endl;
  else if(n < 64) cout << 32 << endl;
  else cout << 64 << endl;
}

Measured memory_bytes: 256
N, A = [int(_) for _ in input().split()]
x = [int(_) for _ in input().split()]
 
dp = [[0] * (sum(x)+1) for j in range(N+1)]
 
dp[0][0] = 1
for i in range(1, N+1):
    for j in list(range(1, N+1))[::-1]:
        for k in list(range(x[i-1], sum(x[:i])+1))[::-1]:
            dp[j][k] += dp[j-1][k - x[i-1]]
 
print(sum([dp[i][i*A] for i in range(1, N+1) if i*A <= sum(x)]))

Measured memory_bytes: 4208
#include<iostream>
#include<string>
using namespace std;
int main () {
  int N, Q;
  cin >> N >> Q;
  int key[100001];
  key[0] = 0;
  string S;
  cin >> S;
  for (int i = 1; i < S.size(); i ++) {
    key[i] = key[i - 1];
    if (S[i - 1] == 'A' && S[i] == 'C') key[i] ++;
  }
  for (int i = 0; i < Q; i ++) {
    int l, r;
    cin >> l >> r;
    int ans = key[r - 1] - key[l - 1];
    cout << ans << endl;
  }
}
  




Measured memory_bytes: 1408
if __name__ == '__main__':
    n = int(input())
    h = list(map(int,input().split()))

    max_move = 0
    no_move = 0
    for i in range(n-1):
       if h[i] >= h[i+1]:
           # 移動できる
           no_move +=1
           max_move = max(max_move, no_move)
       else:
           # 移動できない
            no_move = 0
    print(max_move)


Measured memory_bytes: 14252
# -*- coding: utf-8 -*-
# A

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

a = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
a = a.split(sep=',')

K = int(input())
print(a[K-1])


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

int main(void) {
    double speed;
    while(cin >> speed) {
        double y = (speed / 2.0) * (speed / 9.8);
        double n = (y + 5) / 5.0;
        cout << ceil(n) << endl;
    }
    return(0);
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    unsigned x{},a,k;
    fr(_,n){
        cin>>a>>k;
        while(a>=k and a%k) a-=max(1u,a%k/(a/k+1))*(a/k+1);
        if(a%k==0) x^=a/k;
    }
    puts(x?"Takahashi":"Aoki");
}

Measured memory_bytes: 384
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

class SumSegTree {
private:

 ll _sum(ll a, ll b, ll k, ll l, ll r) {
  if (r <= a || b <= l)return 0;    // 交差しない
  if (a <= l && r <= b)return dat[k];   // a,l,r,bの順で完全に含まれる
  else {
   ll s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
   ll s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
   return s1 + s2;
  }
 }
public:
 ll n, height;
 vector<ll> dat;

 // 初期化（_nは最大要素数）
 SumSegTree(ll _n) {
  n = 1;
  height = 1;
  while (n < _n) {
   n *= 2;
   height++;
  }
  dat = vector<ll>(2 * n - 1, 0);
 }

 // 場所i(0-indexed)にxを足す
 void add(ll i, ll x) {
  i += n - 1; // i番目の葉ノードへ
  dat[i] += x;
  while (i > 0) { // 下から上がっていく
   i = (i - 1) / 2;
   dat[i] += x;
  }
 }

 // 区間[a,b)の総和。ノードk=[l,r)に着目している。
 ll sum(ll a, ll b) {
  return _sum(a, b, 0, 0, n);
 }
};

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

	ll h,w,a,b;
	cin>>h>>w>>a>>b;

	vector<string> s(h,string(w,'0'));

	REP(i,h){
		REP(j,w){
			if((j<a)^(i<b)) s[i][j]='1';
		}
	}

	for(auto i:s){
		cout<<i<<endl;
	}

	return 0;
}

Measured memory_bytes: 2304
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N = sc. nextInt

    val list = List.fill(N)(sc.nextDouble, sc.next)

    var sum: Double = 0

    for((x,u) <- list){
      if(u == "JPY") sum += x
      else sum += x * 380000
    }

    println(sum)
  }
}


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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  
  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
first = np.array([int(i) for i in input().split()])
second = np.array([int(i) for i in input().split()])
fstsum = np.cumsum(first)
scdsum = np.cumsum(second[::-1])[::-1]
result = 0
for i in range(N):
    res = fstsum[i] + scdsum[i]
    if result < res:
        result = res
print(result)

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

public class Main {
    public static void main(String[] args) throws Exception {
        // 入力
        MyScanner sc = new MyScanner(System.in);
        int[] line1 = sc.nextIntArray();
        int N = line1[0];
        int K = line1[1];
        int[] h = sc.nextIntArray();

        // 初期化
        int[] dp = new int[N];
        dp[0] = 0;

        // 主処理
        for(int i = 1; i < N; i++) {
            if(i == 1) {
                dp[i] = Math.abs(h[i] - h[i-1]);
            } else {
                // 最大値で仮定する
                dp[i] = Integer.MAX_VALUE;
                for(int j = 1; j < Math.min(i+1, K+1); j++) {
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
                }
            }
        }

        // 出力
        System.out.println(dp[N-1]);
    }

    static class MyScanner {
        BufferedReader br;
        MyScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        // 標準入力を文字列で取得
        public String nextString() throws IOException {
            return br.readLine();
        }
        // 標準入力を文字列の配列で取得
        public String[] nextStringArray() throws IOException {
            return nextString().split(" ");
        }
        // 標準入力を数値で取得
        public int nextInt() throws IOException {
            return Integer.parseInt(nextString());
        }
        // 標準入力を数値の配列で取得
        public int[] nextIntArray() throws IOException {
            String[] strArr = nextStringArray();
            int[] intArr = new int[strArr.length];
            for(int i = 0; i < strArr.length; i++) {
                intArr[i] = Integer.parseInt(strArr[i]);
            }
            return intArr;
        }
    }
}


Measured memory_bytes: 35548
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N;
    cin >> N;
    string back;
    set<string> word_list;
    bool ans = true;
    for(int i = 0; i < N; i++){
        string W;
        cin >> W;
        if(i && back.back() != W[0]){
            ans = false;
        }
        if(word_list.find(W) != word_list.end()){
            ans = false;
        }
        back = W;
        word_list.insert(W);
    }
    Yes(ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[200010],b[200010];
int main()
{
	scanf("%d",&n);for (int i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
	sort(a+1,a+1+n);
	for (int i=1;i<=n;i++)
	{
		if (b[i]<=a[n/2]) printf("%d\n",a[n/2+1]);
		else printf("%d\n",a[n/2]);
	}
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=2e5+5;

int n;
int a[N], b[N];
set<int> v[N];

int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=i)
		{
			cout<<"-1";
			return 0;
		}
	}
	for(int i=1;i<=n-1;i++)
	{
		if(a[i]<a[i+1]-1)
		{
			cout<<"-1";
			return 0;
		}
	}
	int ans=0, cur=0;
	for(int i=n;i>=2;i--)
	{	
		if(a[i]==0)
			continue;
		int left=i-(a[i]-1);
		v[left].insert(i);
	}	
	for(int i=1;i<=n;i++)
	{
		if(!v[i].size())
			continue;
		ans+=(*(v[i].rbegin()) - i + 1);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 22272
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int mx = max(a,b);
    if(a==b)
        cout<<a+b<<'\n';
    else
        cout<<2*mx-1<<'\n';
    return 0;
}


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

namespace AtCoder_solve
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] data = Console.ReadLine().Split(' ');
            long a = long.Parse(data[0]);
            long b = long.Parse(data[1]);
            long k = long.Parse(data[2]);

            /*for (ulong i = 0; i < k; i++)
            {
                if(a>0)
                {
                    a--;
                }else if (b > 0)
                {
                    b--;
                }
                else
                {

                }
            }*/

            if (k < a )
            {
                Console.WriteLine((a - k) + " " + b);
            }else if (a <=k)
            {
                if (a + b - k > 0)
                {
                    Console.WriteLine(0 + " " + (b + a - k));

                }else if (a + b - k <= 0)
                {
                    Console.WriteLine(0 + " " + 0);
                }
            }


            


        }
    }
}


Measured memory_bytes: 13140
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    ans = 1

    if 0 in a:
        print(0)
        exit()

    for ai in a:
        ans *= ai

        if ans > 10 ** 18:
            print(-1)
            exit()

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21604
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;

    cin >> s;

    int cnt = 0;
    int total = 0;

    for (int i = 0; i < s.length()/2; i++) {
        total += 1;
        if (s[i] == s[s.length()-1-i]) {
            cnt += 1;
        }
    }

    cout << total - cnt << endl;

    return 0;
}


Measured memory_bytes: 888
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef vector<pii>vip;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;
 
void task(){
 	int l,r,d; cin >> l >> r >> d;
 	int cnt =0;
 	rep1(i,l,r){
 		if(i%d==0)cnt++;
 	}
 	cout << cnt << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1; //cin >> T;
        while(T--){
            task();
        }
        
return 0;
}




Measured memory_bytes: 3600
#include <vector>
#include <cstdint>
#include <cstddef>
#include <string>

template<std::uint_fast64_t B = 524287>
struct rolling_hash {
	using u32 = std::uint_fast32_t;
	using u64 = std::uint_fast64_t;
	using i128 = __int128_t;
	using size_type = std::size_t;

private :
	static constexpr u64 base = B;
	static constexpr u64 mod = (1UL << 61) - 1;

	std::vector<u64> hash, pow;

	u64 mul (const i128 &a, const i128 &b) const noexcept {
		i128 value = a * b;
		value = (value >> 61) + (value & mod);
		return (value < mod ? value : value - mod);
	}

	u32 xorshift (u32 value) const noexcept {
		value ^= value << 13;
		value ^= value >> 17;
		value ^= value << 5;
		return value;
	}

public :
	constexpr rolling_hash () = default;

	template<class InputIterator>
	constexpr rolling_hash (InputIterator first, InputIterator last) noexcept {
		build(first, last);
	}

	template<class InputIterator>
	void build (InputIterator first, InputIterator last) noexcept {
		const size_type n = (last - first);
		hash.assign(n + 1, 0);
		pow.assign(n + 1, 1);
		for (size_type i = 0; first != last; first++, i++) {
			hash[i + 1] = mul(hash[i], base) + xorshift((*first) + 1);
			pow[i + 1] = mul(pow[i], base);
		}
	}

	u64 get(size_type first, size_type last) const noexcept {
		if (first > last) std::swap(first, last);
		u64 value = hash[last] + mod - mul(hash[first], pow[last - first]);
		return (value < mod ? value : value - mod);
	}

};


#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <set>
 
int main() {
	int n;
	std::string s;
	std::cin >> n >> s;
	
	rolling_hash rh(s.begin(), s.end());
	
	auto f = [&] (int x) -> bool {
		std::set<std::uint_fast64_t> set;
		for (int i = n - x; i >= 0; i--) {
			if (i + x + x <= n) set.emplace(rh.get(i + x, i + x + x));
			if (set.count(rh.get(i, i + x))) return true;
		}
		return false;
	};
	
	int ok = 0, ng = n;
	while (std::abs(ok - ng) > 1) {
		int mid = (ok + ng) >> 1;
		if (f(mid)) ok = mid;
		else ng = mid;
	}
	
	std::cout << ok << '\n';
	
	return 0;
}

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

int main() {
	string s, t,u;
	int a, b;

	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	int a_a, a_b;
	if (s == u) {
		a_a = a -1;
		a_b = b;
	} else {
		a_a = a;
		a_b = b - 1;
	}
	cout << a_a << " " << a_b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define why(n, x)                                                              \
  int n;                                                                       \
  while (cin >> n, n != x)
#define iFOR(i, x, n) for (int i = x; i < n; i++)
#define fin << '\n'
#define __ << " " <<
#define ___ << " "
#define bash push_back
#define ALL(x) x.begin(), x.end()
#define SWAP(a, b) ((a != b) && (a += b, b = a - b, a -= b))
//#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vit;
typedef map<string, int> mstit;
typedef vector<pii> vpi;
typedef greater<pii> gpi;
typedef priority_queue<pii, vpi, gpi> dijk;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
static const signed int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}
template <class T> T abs(T &x) { return x < 0 ? -x : x; }
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 qp(int a, ll b, int mo) {
  int ans = 1;
  do {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

ll bug[55], ps[55];

ll dp(ll i, ll j) {
  if (!i)
    return 1;
  if (j == 1)
    return 0;
  if (bug[i] == j)
    return ps[i];
  if (j == bug[i - 1] + 2)
    return ps[i - 1] + 1;
  if (j < bug[i - 1] + 2)
    return dp(i - 1, j - 1);
  return ps[i - 1] + 1 + dp(i - 1, j - bug[i - 1] - 2);
}

inline void solve() {

  ll n, x;

  cin >> n >> x;

  bug[0] = ps[0] = 1;

  for (int i = 1; i <= n; i++) {
    bug[i] = bug[i - 1] * 2 + 3;
    ps[i] = ps[i - 1] * 2 + 1;
  }

  cout << dp(n, x) << endl;
}
struct xyz {
  xyz() {
    cin.tie(0), ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
  };
} xyzzy;
signed main() {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <complex>

using namespace std;

typedef complex<int> Point;

namespace std {
    bool operator < (const Point &p1, const Point &p2) {
        if(p1.real() != p2.real()) return p1.real() < p2.real();
        return p1.imag() < p2.imag();
    }
};

int main() {
    while(true) {
        int m;
        cin >> m;
        if(!m) break;

        vector<Point> targets;
        set<Point> stars;

        for(int i = 0; i < m; ++i) {
            int x, y;
            cin >> x >> y;
            targets.push_back(Point(x, y));
        }

        int n;
        cin >> n;
        for(int i = 0; i < n; ++i) {
            int x, y;
            cin >> x >> y;
            stars.insert(Point(x, y));
        }

        for(int i = 0; i < m; ++i) {
            for(set<Point>::iterator it = stars.begin(); it != stars.end(); ++it) {
                Point diff = *it - targets[i];
                bool ok = true;
                for(int j = 0; j < m; ++j) {
                    if(stars.find(targets[j]+diff) == stars.end()) {
                        ok = false;
                        break;
                    }
                }
                if(ok) {
                    cout << diff.real() << ' ' << diff.imag() << endl;
                    goto end;
                }
            }
        }
end:
        ;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define len(x) ((int)(x).size())

using namespace std;

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

  string input;

  cin >> input;

  if(input=="SSS")cout << 0 << endl;
  else if(input=="SRR"||input=="RRS")cout << 2 << endl;
  else if(input=="RRR")cout << 3 << endl;
  else cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 3552
L = 12

def delete(field, x, y)
  field[y][x] = "0"
  [[1, 0], [0, -1], [-1, 0], [0, 1]].each do |dx, dy|
    x1 = x + dx
    y1 = y + dy
    if !(x1 < 0 or x1 >= L or y1 < 0 or y1 >= L) and field[y1][x1] == "1"
      delete(field, x1, y1)
    end
  end
end

$<.readlines.map(&:chomp).chunk {|st| st.empty?}.reject {|a| a.first}.map {|a| a.last}.each do |field|
  co = 0
  L.times do |y|
    L.times do |x|
      if field[y][x] == "1"
        co += 1
        delete(field, x, y)
      end
    end
  end
  puts co
end


Measured memory_bytes: 7092
/*input
6 10
4 4 1 1 1 7
3 5 19
2 5 20
4 5 8
1 6 16
2 3 9
3 6 16
3 4 1
2 6 20
2 4 19
1 2 9
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, j, k)  for(int i = j; i <  k; ++i)
#define RREP(i, j, k) for(int i = j; i >= k; --i)
#define F first
#define S second
#define mp make_pair
#define pb emplace_back
#define PII pair<int , int>
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100009
#define INF 0x3f3f3f3f

struct djs{
    int x[MAX] , v[MAX] , siz[];
    void init(){ REP(i , 0 , MAX) x[i] = i; }
    int Find(int now){ return x[now] == now ? now : Find(x[now]); }
    void Union(int a , int b){
        a = Find(a) , b = Find(b);
        if(v[a] > v[b]) swap(a , b);
        x[a] = b;
        v[b] += v[a];
    }
    int operator[](int now){ return Find(now); }
} ds;

int n , m , e[MAX][3] , x[MAX] , in[MAX] , s[MAX];
int cut[MAX][2] , rrr[MAX][2] , is[MAX];
int cmp(int a , int b){ return e[a][2] < e[b][2]; }
int32_t main(){
    IOS;
    cin >> n >> m;
    REP(i , 1 , n + 1) cin >> x[i];
    REP(i , 1 , m + 1) REP(j , 0 , 3) cin >> e[i][j];
    REP(i , 1 , m + 1) s[i] = i;
    sort(s + 1 , s + 1 + m , cmp);
    
    ds.init();
    REP(i , 1 , n + 1) ds.v[i] = x[i];

    REP(idx , 1 , m + 1){ int i = s[idx];
        int v1 = e[i][0] , v2 = e[i][1];

        if(ds[v1] != ds[v2]){
            is[i] = 1;
            rrr[i][0] = ds[v1];
            cut[i][0] = ds.v[ds[v1]];
            rrr[i][1] = ds[v2];
            cut[i][1] = ds.v[ds[v2]];
            ds.Union(v1 , v2);
        }
                // cout << "\t\t\t"; REP(i , 1 , n + 1) cout << ds.x[i] << " "; cout << endl;
                // cout << "\t\t\t"; REP(i , 1 , n + 1) cout << ds.v[i] << " "; cout << endl;
    }
    int ans = 0;
    RREP(idx , m , 1){ int i = s[idx];
        int v1 = e[i][0] , v2 = e[i][1];
        // DB4("edge " , e[i][2] , "vs = " , ds.v[ds[v1]]);
        //         DB4(rrr[i][0] , cut[i][0] , rrr[i][1] , cut[i][1]);
        if(ds[v1] != ds[v2]) ans ++;// , DBGG("HERE" , "");
        else if(ds.v[ds[v1]] < e[i][2]){
            ans ++;
            if(is[i]){
                ds.x[rrr[i][0]] = rrr[i][0] , ds.v[rrr[i][0]] = cut[i][0];
                ds.x[rrr[i][1]] = rrr[i][1] , ds.v[rrr[i][1]] = cut[i][1];
                // cout << "\t\t\t"; REP(i , 1 , n + 1) cout << ds.x[i] << " "; cout << endl;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    long[] a = new long[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();
    for (int i = 1; i < N; i++) a[i] += a[i - 1];
    long res = Long.MAX_VALUE;
    for (int i = 0; i < N - 1; i++) {
      long diff = Math.abs(a[N - 1] - a[i] - a[i]);
      res = Math.min(diff, res);
    }
    System.out.println(res);
  }
}


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

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

  if(n%2==1)cout<<0<<endl;
  else{
    long long ans=0LL;
    for(int i=1; i<26; ++i){
      ans+=n/((long long)pow(5, i)*2);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
# N//m=N%m
# (N-N%m)/m=N%m
# N=(N%m)(m+1)

n=int(input())

def make_divisor(x):
    ret=[]
    for i in range(1,int(x**.5)+1):
        q,m=divmod(x,i)
        if m==0:
            ret.append(i)
            if i==q:continue
            ret.append(q)
    return ret

ans=[]
d=make_divisor(n)

for e in d:
    if e==1:continue
    m=e-1
    k=n%m
    if k*e==n:
        ans.append(m)
print(sum(ans))

Measured memory_bytes: 3316
#include<stdio.h>
int main(){
  int m,f,r,p;
  while(1){
    scanf("%d %d %d",&m,&f,&r);
    if(m==-1&&f==-1&&r==-1){
      break;
    }
    p=m+f;
    if(m==-1||f==-1){
      printf("F\n");
    }else  if(p>=80){
      printf("A\n");
    }else if(p>=65&&p<80){
      printf("B\n");
    }else if(p>=50&&p<65){
      printf("C\n");
    }else if(p>=30&&p<50){ 
      if(r>=50){
	printf("C\n");
      }
      else if(p>=30&&p<50){
	printf("D\n");
      }
    }else if(p<30){
      printf("F\n");
    }
  }
  return (0);
}

Measured memory_bytes: 584
//Contribted By - Rahul Roy
import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
	
	static long M = (long)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		int h = sc.nextInt();
		int n = sc.nextInt();
		ArrayList<pair> al = new ArrayList<>();
		for(int i=0;i<n;i++){
			pair p = new pair();
			p.health = sc.nextInt();
			p.cost = sc.nextInt();
			al.add(p);
		}
		int dp[] = new int[h+1];
		int mark[] = new int[h+1];
		Arrays.fill(dp,Integer.MAX_VALUE);
		dp[h]=0;
		mark[h]=1;
		for(int i=h;i>=1;i--){
			for(int j=0;j<n;j++){
				if(mark[i]==1){
					pair p = al.get(j);
					dp[Math.max(0,i-p.health)] = Math.min(dp[Math.max(0,i-p.health)], dp[i]+p.cost);
					mark[Math.max(0,i-p.health)]=1;
				}
			}
		}
		System.out.println(dp[0]);
	}
	
	public static class pair{
		int health =0 ;
		int cost = 0;
	}
	
	
	
	
		
		
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;


		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
}
/* class Triplet{
	int threeSumClosest(ArrayList<Integer> arr, int target) {
        int flag=0,n = arr.size();
        int res=0;
        
        Collections.sort(arr);
		
        for(int i = 0 ; i < n-2 ; ++ i ) {  
            
            int j = i+1, k = n-1;
            
            while(j<k) {
                int sum=arr.get(i)+arr.get(j)+arr.get(k);   // get the sum of the triplet
                
                if(flag==0){  // if its your 1st triplet updated res
                    res=sum;
                    flag=1;
                }
                
                if(Math.abs(sum-target)<=Math.abs(res-target)) {   // compare the difference if sum is closer to target then res
                    if(Math.abs(sum-target)==Math.abs(res-target)){
                        if(res<sum)
                            res=sum;
                    }
                    else
                        res=sum;
                }
                
                if(target>sum)  // if sum is smaller than target
                    j++;
                else        // if sum is greater than target
                    k--;
            }
        }
        return res; // return the answer 
    }
} */

Measured memory_bytes: 22100
n = int(input())
hl = list(map(int, input().split()))

curr = hl[0]-1
for i in range(1,n):
    if hl[i] > curr:
        curr = hl[i]-1
    elif hl[i] == curr:
        pass
    else:
        print('No')
        break
else:
    print('Yes')

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

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> can_reach_from_1(n + 1, 0);
    vector<int> can_reach_to_n(n + 1, 0);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        if (b == n)can_reach_to_n[a] = 1;
        if (a == 1)can_reach_from_1[b] = 1;
    }

    bool ans = false;
    for (int i = 1; i <= n; i++) {
        if (can_reach_from_1[i] == 1 && can_reach_to_n[i] == 1) ans = true;
    }

    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;


    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n;
    cin >> n;

    reps(m, n) {
        int ans = 0;
        for (int i = 1; i * i <= m; ++i)
            for (int j = 1; i * i + j * j + i * j < m; ++j) {
                int b = i + j;
                int c = -(m - i * i - j * j - i * j);
                int tmp = sqrt(b * b - 4 * c);
                if (tmp * tmp != b * b - 4 * c) continue;
                if ((-b + tmp) % 2 == 0 && (-b + tmp) / 2 > 0) ++ans;
                if ((-b - tmp) % 2 == 0 && (-b - tmp) / 2 > 0) ++ans;
            }
        cout << ans << '\n';
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3576
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let mut a: Vec<i32> = vec![1;5];
    for i in 0..5{
	let n: i32 = read();
	a[i as usize] = n;
    }
    let k: i32 = read();
    for i in 0..5{
	for j in i..5{
	    if a[j as usize]-a[i as usize] > k {
		println!(":(");
		return;
	    }
	}
    }
    println!("Yay!");
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val yesN = IntArray(1000) { (it * (it + 1)) / 2 }//条件を満たすnの一覧
    val groupSize = yesN.indexOf(n)
    if (groupSize > 0) {
        println("Yes")
        val groupNum = groupSize + 1
        println(groupNum)
        val ans = Array(groupNum) { Array(groupSize) { 0 } }
        var num = 1
        var lastGroupIndex = 0
        for (i in 0 until groupSize) {
            for (j in 0 until groupSize) {
                if (j == groupSize - i) {
                    for (k in 0..i) {
                        ans[i][j + k - 1] = ans[i - k][j - 1]
                    }
                    break
                }
                ans[i][j] = num++
            }
            ans[groupNum - 1][lastGroupIndex++] = num - 1
        }
        ans.forEach { println("$groupSize " + it.joinToString(" ")) }
    } else {
        println("No")
    }
}


Measured memory_bytes: 50880
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(int n){
   if(n < 10)  return n;
   return digit(n/10) + n%10;
}
int main(){
  int N;
  cin>>N;
  string S="No";
  if(N%digit(N)==0) S="Yes";
  cout<<S;
return 0;}


Measured memory_bytes: 3596
def comb(n, k, MOD):
    if n < k:
        return 0
    if n - k < k:
        k = n - k
    comb = 1
    for x in range(n - k + 1, n + 1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, k + 1):
        d = (d * x) % MOD
    comb *= pow(d, MOD - 2, MOD)
    return comb % MOD

N, a, b = map(int, input().split())
mod = 10 ** 9 + 7
t = pow(2, N, mod) - 1
t -= comb(N, a, mod)
t %= mod
t -= comb(N, b, mod)
t %= mod
print(t)

Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int A,B,C;cin>>A>>B>>C;
    cout<<((A<=C && C<=B)?"Yes":"No")<<endl;
}

Measured memory_bytes: 3600
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
ans = float('inf')
for i in range(N-K+1):
    n = x[i+K-1]-x[i]
    ans = min(ans, n+abs(x[i]), n+abs(x[i+K-1]))
print(ans)


Measured memory_bytes: 62576
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, y) = get!(i64, i64);

    for m in 0..n+1 {
        for g in 0..n+1 {
            let s = n - m - g;
            if s < 0 { continue; }
            if m * 10000 + g * 5000 + s * 1000 == y {
                println!("{} {} {}", m, g, s);
                std::process::exit(0);
            }
        }
    }
    println!("{} {} {}", -1, -1, -1);
}


Measured memory_bytes: 4352
//Name-Deepesh Bhatt
//Institute-IIT Dhanbad

#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 lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
ll combination(ll x)
{
    if(x==0||x==1)
        return 0;
    return (x*(x-1))/2;
}
int main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll>v(n);
    ll ans[n+1]={0};
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
        ans[v[i]]++;
    }
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        sum+=combination(ans[i]);
    }
    for(int i=0;i<n;i++)
    {
        cout<<sum-(ans[v[i]]-1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		for(int i = 0; i < n; i++) t[i] = sc.nextInt();
		int m = sc.nextInt();
		int[] p = new int[m];
		int[] x = new int[m];
		for(int i = 0; i < m; i++){
			p[i] = sc.nextInt();
			x[i] = sc.nextInt();
			p[i]--;
		}
		sc.close();

		int[] ans = new int[m];
		int sum = 0;
		for(int i = 0; i < n; i++){
			sum += t[i];
		}

		for(int i = 0; i < m; i++){
			System.out.println(sum - t[p[i]] + x[i]);
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

ll v[51];
ll C[51][51];

ll Comb(int n, int r)
{
	if (r == 0 || r == n)
	{
		if (C[n][r] < 0)
		{
			C[n][r] = 1;
		}
		return C[n][r];
	}
	else if (r == 1)
	{
		if (C[n][r] < 0)
		{
			C[n][r] = n;
		}
		return C[n][r];
	}
	if (C[n - 1][r - 1] < 0)
	{
		C[n - 1][r - 1] = Comb(n - 1, r - 1);
	}
	if (C[n - 1][r] < 0)
	{
		C[n - 1][r] = Comb(n - 1, r);
	}
	return C[n - 1][r - 1] + C[n - 1][r];
}

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	REP(i, N)
	{
		cin >> v[i];
	}
	sort(v, v + N, [](ll a, ll b) {return a > b; });

	ll m = v[A - 1];
	int s = -1, e = -1;
	double ave = 0.0;
	REP(i, N)
	{
		if (i < A)
		{
			ave += (double)v[i];
		}
		if (v[i] == m)
		{
			e = i;
			if (s == -1)
			{
				s = i;
			}
		}
	}
	cout << std::setprecision(10)<< ave / (double)A << endl;
	memset(C, -1, sizeof(C));

	if (s != 0)
	{
		cout << Comb(e - s + 1, A - s) << endl;
		return 0;
	}

	ll ans = 0;
	for (int i = A; i <= std::min(e + 1, B); ++i)
	{
		ans += Comb(e + 1, i);
	}
	cout << ans << endl;
	return 0;
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
int B[110];

int main()
{
    cin >> N;
    rep(i, N - 1)
    {
        cin >> B[i];
    }

    int ans = 0;
    rep(i, N + 1)
    {
        if (i == 0)
        {
            ans += B[0];
        }
        else if (i == N)
        {
            ans += B[N - 2];
        }
        else
        {
            ans += min(B[i - 1], B[i]);
        }
    }
    cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    int ans = 0, num, cmp, ccmp;
    ccmp = N - (N / 100) * 100;
    cmp = ccmp - (ccmp / 10) * 10;
    ccmp /= 10;
    if (N / 100 < cmp || N / 100 < ccmp) {
        num = N / 100 + 1;
    }
    else num = N / 100;
    ans += num * 111;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define sz(A) int(A.size())
#define FIFO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(A) begin(A),end(A)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<pair<int,int>> vii;
int main() {
	long double a, b;
	cin >> a >> b;
	long double c = (a * b);
	ll x = c;
	cout << x << "\n";
	return 0;
}


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

public class Main 
{
	public static void main(String[] args) { new Main(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);
	
	int n, min, arr[];
	
	Main() {
		arr = new int[n = in.nextInt()];
		for (int i = 0; i < n; arr[i++] = in.nextInt());

		min = 400_000*n;
		for (int j = -100; j <= 100; j++) {
			int cost = 0;
			for (int i = 0; i < n; i++)
				cost += (arr[i] - j)*(arr[i] - j);
			min = min(min, cost);
		}
		out.println(min);
		out.close();
	}
	
	int min(int a, int b) {
		if (a < b)
			return a;
		return b;
	}
	
	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


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

using namespace std;

int P[200005], M[200005];

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> P[i];
	}
	int cnt = 1;
	M[1] = P[1];
	for (int i = 2; i <= n; ++i) {
		M[i] = min(M[i - 1], P[i]);
		if (P[i] <= M[i]) cnt++;
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	ll n, i, tmp;
	cin >> n;
	unordered_map<ll, ll> mp, patterns;
	vector<ll> a(n);
	vector<ll> answer(n);
	
	ll pattern = 0;

	for (i = 0; i < n; i++) {
		cin >> tmp;
		a[i] = tmp;
		if (mp.find(tmp) == mp.end()) 
			mp[tmp] = 1;
		else
			mp[tmp]++;
	}

	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		patterns[itr->first] = itr->second * (itr->second - 1) / 2;
		pattern += patterns[itr->first];
	}

	for (i = 0; i < n; i++) {
		tmp = pattern - patterns[a[i]];
		tmp += (mp[a[i]] - 1) * (mp[a[i]] - 2) / 2;
		cout << tmp << endl;
	}
		
	return 0;
}


Measured memory_bytes: 17608