akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for(ll i = a; i < (ll)(n); ++i)
#define repr(i, a, n) for(ll i = n - 1; (ll)a <= i; --i)
#define ENDL '\n'
typedef pair<int, int> Pi;
typedef pair<ll, ll> PL;
constexpr ll mod = 1000000007;  // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 + 99);
const ld PI = acos((ld)-1);
const vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T, typename U> inline bool chmin(T& t, const U& u) {
  if(t > u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T, typename U> inline bool chmax(T& t, const U& u) {
  if(t < u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template <typename T, typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(; n; n >>= 1) {
    if(n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T, typename Y>
ostream& operator<<(ostream& os, const pair<T, Y>& p) {
  return os << "{" << p.fs << "," << p.sc << "}";
}
template <typename T> ostream& operator<<(ostream& os, const V<T>& v) {
  os << "{";
  for(auto e : v) os << e << ",";
  return os << "}";
}
template <typename... Args> void debug(Args&... args) {
  for(auto const& x : {args...}) { cerr << x << ' '; }
  cerr << ENDL;
}


set<ll> prime;
bool pc = true;

std::vector<ll> sieve(int n) {
  std::vector<ll> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (int j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}

std::vector<ll> factor(int n, const std::vector<ll>& min_factor) {
  // min_factor は sieve() で得られたものとする
  std::vector<ll> res;
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}


signed main() {
  cin.tie(0);
  cerr.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;


  V<ll> v(n),er=sieve(1000010ll);
  rep(i, 0, n) cin >> v[i];
  ll g = v[0];
  rep(i, 1, n) g = gcd(g, v[i]);

  rep(i, 0, n) {
    V<ll> ps=factor(v[i],er);
    sort(all(ps));
    ps.erase(unique(all(ps)),ps.end());

    rep(j,0,siz(ps)){
      if(prime.count(ps[j]))pc=false;
      else prime.insert(ps[j]);
    }
  }

  if(pc)
    cout << "pairwise coprime" << ENDL;
  else if(g == 1)
    cout << "setwise coprime" << ENDL;
  else
    cout << "not coprime" << ENDL;
}
//! ( . _ . ) !
// CHECK overflow,vector_size,what to output?

Measured memory_bytes: 22300
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect
import heapq


MOD = 1000000007


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    H, W = get_inputs(int)
    # white: 1 / black: 0
    s = np.zeros((H, W), dtype=np.int)
    req_n_ops = np.empty((H, W), dtype=np.int)
    for i in range(H):
        row = get_input(str)
        for j, r in enumerate(row):
            if r == ".":
                s[i, j] = 1

    if s[0, 0] == 0:
        req_n_ops[0, 0] = 1
    else:
        req_n_ops[0, 0] = 0

    for l in range(1, W+H-1):
        for i in range(H):
            j = l - i
            if not(i >= 0 and i < H and j >= 0 and j < W):
                continue
            # print(i, j)
            if i >= 1:
                if s[i, j] == 0 and s[i-1, j] == 1:
                    x1 = req_n_ops[i-1, j] + 1
                else:
                    x1 = req_n_ops[i-1, j]
            else:
                x1 = 100000

            if j >= 1:
                if s[i, j] == 0 and s[i, j-1] == 1:
                    x2 = req_n_ops[i, j-1] + 1
                else:
                    x2 = req_n_ops[i, j-1]
            else:
                x2 = 100000

            req_n_ops[i, j] = min(x1, x2)


    # print(req_n_ops)
    print(int(req_n_ops[-1, -1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 21764
fun main(args:Array<String>) {
    var (h,a) = readLine()!!.split(" ").map(String::toInt)
    var ans:Int = 0
    for (gomikasushineeeeeewwwwwwwwwwwwwwwwwwwwwwwww in 1..1000000) {
        ans++
        h -= a
        if (h <= 0) {
            println(ans)
            return
        }
    }
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

int main(){
  int k;
  cin >> k;
  int m = 7 % k;
  REP(i,k) {
    if(m == 0) {
      cout << i << endl;
      return 0;
    }
    m = (m*10+7) % k;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 n, k;
    std::cin >> n >> k;
    std::vector<i64> p(n);
    for (auto &e : p) std::cin >> e;

    std::vector<i64> ss { std::accumulate(p.begin(), p.begin() + k, 0ll) };
    for (int i = 0; i + k < n; i++) ss.push_back(ss.back() - p[i] + p[i + k]);

    i64 ret = *std::max_element(ss.begin(), ss.end());
    std::cout << std::fixed << std::setprecision(10) << (ret + k) / 2.0 << std::endl;

    return 0;
}


Measured memory_bytes: 3956
using System;
using System.Collections.Generic;

namespace AtTest.ABC_105
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            input = Console.ReadLine().Split(' ');
            var array = new int[n];
            var sums = new int[n];
            string s = "";//, ss = "";
            for (int i = 0; i < n; i++)
            {
                array[i] = int.Parse(input[i]);
                if (i == 0)
                {
                    sums[i] = array[i] % m;
                }
                else
                {
                    sums[i] = (sums[i - 1] + array[i]) % m;
                }
                //s += array[i].ToString() + " ";
                //ss += sums[i].ToString() + " ";
            }

            var marginDict = new Dictionary<int, int>();
            marginDict.Add(0, 1);
            long cnt = 0;
            for(int i = 0; i < n; i++)
            {
                if (marginDict.ContainsKey(sums[i]))
                {
                    cnt += marginDict[sums[i]];
                    marginDict[sums[i]]++;
                }
                else
                {
                    marginDict.Add(sums[i], 1);
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 22112
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a > b ){
        int tmp = a;
        a =b;
        b = tmp;
    }
    if(a > c){
        int tmp = a;
        a = c;
        c = tmp;
    }
    if(b > c){
        int tmp = b;
        b = c;
        c =tmp;
    }
    cout << a << " " << b << " "<< c << endl;  
}  


Measured memory_bytes: 3084
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
	 ios::sync_with_stdio(false);
	 int n, i, j;
	 int sum;
	 while(cin>>n)
	 {
	 	sum=0;
	 	for(j=1;j<=n;j+=2)
	 	{  
		    int cnt=0;
	 		 for(i=1;i<=sqrt(j);i++)
	 	 	   if(j%i==0) 	
					 		cnt++;
			 if(cnt==4)
			   	sum++;			 
		 }
	 	 cout<<sum<<endl;
	 }
	 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;

int n;
int c[11][11];
int a[202][202];
int ans[11][11];
/*
int res(int i,int j){
if(i==j) return ans[i][j]= 0;

for (int k = 0; k < 10; k++)
{
    ans[i][j] = min(ans[i][j],res(i,k)+c[k][j]);
}

return ans[i][j];
}
*/

int main(){
    
    int h,w;cin>>h>>w;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin>>c[i][j];
            ans[i][j] = c[i][j];
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin>>a[i][j];
        }
    }

    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                ans[j][k] = min(ans[j][k],ans[j][i]+ans[i][k]);
            }
            
        }
    }
    int rec=0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(a[i][j]==-1) continue;
            rec += ans[a[i][j]][1];
        }
    }

    cout<<rec<<endl;
    return 0;
}

Measured memory_bytes: 384
x=int(input())
A=0
B=0
for i in range(1000):
  for j in range(i+1):
    a=pow(i,5)
    b=pow(j,5)
    if a-b==x:
      A=i
      B=j
for i in range(80):
  for j in range(80):
    a=pow(i,5)
    b=pow(j,5)
    if a+b==x:
      A=i
      B=-j
print(A,B)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
int main() {
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> board(H);
	rep(i,0,H) cin >> board[i];
	int si = -1, sj = -1;
	rep(i,0,H) rep(j,0,W) if (board[i][j] == 'S') si = i, sj = j;
	queue<pii> q;
	q.push(pii(si, sj));
	vector<vi> dists(H, vi(W, -1));
	dists[si][sj] = 0;
 
	vector<pii> onestep;
 
	while (!q.empty()) {
		pii pa = q.front();
		q.pop();
		int di = dists[pa.first][pa.second];
		if (di <= K) onestep.push_back(pa);
		rep(d,0,4) {
			pii pa2 = pa;
			if (d == 0) pa2.first++;
			if (d == 1) pa2.second++;
			if (d == 2) pa2.first--;
			if (d == 3) pa2.second--;
			if (pa2.first < 0 || pa2.second < 0 || pa2.first >= H || pa2.second >= W) continue;
			if (board[pa2.first][pa2.second] == '#') continue;
			if (dists[pa2.first][pa2.second] != -1) continue;
			dists[pa2.first][pa2.second] = di+1;
			q.push(pa2);
		}
	}
 
	dists.assign(H, vi(W, -1));
	trav(pa, onestep) {
		q.push(pa);
		dists[pa.first][pa.second] = 0;
	}
 
	while (!q.empty()) {
		pii pa = q.front();
		q.pop();
		int di = dists[pa.first][pa.second];
		rep(d,0,4) 
		{
			pii pa2 = pa;
			if (d == 0) pa2.first++;
			if (d == 1) pa2.second++;
			if (d == 2) pa2.first--;
			if (d == 3) pa2.second--;
			if (pa2.first < 0 || pa2.second < 0 || pa2.first >= H || pa2.second >= W) continue;
			// if (board[pa2.first][pa2.second] == '#') continue;
			if (dists[pa2.first][pa2.second] != -1) continue;
			dists[pa2.first][pa2.second] = di+1;
			q.push(pa2);
		}
	}
 
	int res = INT_MAX;
	rep(i,0,H) rep(j,0,W) {
		if (i == 0 || j == 0 || i == H-1 || j == W-1) {
			res = min(res, dists[i][j]);
		}
	}
 
	cout << (res + K-1) / K + 1 << endl;
 
	exit(0);
}


Measured memory_bytes: 15344
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a,b;
	cin >> a >> b;
	if(a-b==0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int mod = (int)1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<bool> dp(k+1,false);
	for(int i=1;i<=k;i++){
		for(int j=0;j<n;j++){
			if( i>=a[j] && !dp[i-a[j]] )
				dp[i] = true;
		}
	}
	cout<<(dp[k]?"First":"Second");
	
    return 0;
}









Measured memory_bytes: 256
def SearchCombination_RGB(Str):
    Sum_Comb = 0
    Num_R = 0
    Num_G = 0
    Num_B = 0
    for i in range(len(Str)):
        if(Str[i] =='R'):
            Num_R +=1
        elif(Str[i] == 'G'):
            Num_G += 1
        else:
            Num_B += 1
    Num_Comb = Num_R * Num_G * Num_B
    
    if(Num_Comb ==0):
        return 0
    for Pos1 in range(0, len(Str)-2):
        for Pos2 in range(Pos1+1, len(Str)-1):
            if(Str[Pos1] != Str[Pos2]):
                Pos3 = 2 * Pos2-Pos1
                if(Pos3 < len(Str) and Str[Pos3]!= Str[Pos1] and Str[Pos3] != Str[Pos2]):
                    Sum_Comb +=1

    return Num_Comb - Sum_Comb

Str = [input() for i in range(2)]
#print(Str, ", len = ", len(Str))


print( SearchCombination_RGB(Str[1].strip()) )


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

signed main(){
  int N,K;
  cin>>N>>K;
  std::vector<int> v(N*2,1e9);
  for(int i=0;i<N;i++)cin>>v[i];
  std::vector<int> dp(N*2,1e9);
  dp[0]=0;
  for(int i=0;i<N;i++)for(int j=0;j<K;j++)dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(v[i]-v[i+j+1]));
  cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 3328
from bisect import bisect_left, bisect_right
N = int(input())
A = sorted([int(_) for _ in input().split()])
B = sorted([int(_) for _ in input().split()])
C = sorted([int(_) for _ in input().split()])

ans = 0
for item in B:
    A_pos = bisect_left(A, item)
    C_pos = N - bisect_right(C, item)
    ans += A_pos * C_pos
print(ans)

Measured memory_bytes: 23240
package main

import (
	"fmt"
	"os"
)

func main(){
	var a, b int
	fmt.Fscanf(os.Stdin, "%d %d", &a, &b)
	total := 1
	i := 0
	for {
		if total >= b {
			break
		}
		i += 1
		total = total -1 + a
	}
	fmt.Println(i)
}


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

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d",x)
#define ps printf(" "); 
#define plint(x) printf("%lld",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define bg begin()
#define ed end()
#define Set(a, s) memset(a, s, sizeof (a))
#define mod 1000000007
#define tmod(k) if ((k) >= mod) k %= mod;
#define endl '\n'
#define nl printf("\n");
#define fors(i,n) for(int i=0; i<n; i++)
#define fore(i,n) for(int i=n-1; i>=0; i--)
#define forv(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

class node{
public:
	int id;
	int prio;
	int prd;
};

class compare{
public:
	bool operator()(node &n1, node &n2){
		if(n1.prio>n2.prio)//ascending
			return true;
		else if(n1.prio==n2.prio){
			return n1.id>n2.id;
		}
		return false;
	}
};
//priority_queue<node, vector<node>, compare> pq;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*#ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #else
    // online submission
    #endif*/
    
  int n,m; int2(n,m);
  vector<pair<int, int> > vpii;
  vi tv1,tv2;
  bool ch=true;
  fors(i,m){
      int s,e;
      int2(s,e);
      if(s==1) tv1.pb(e);
      if(e==n) tv2.pb(s);
      if(s==1&&e==n){ch=false; break;}
     vpii.pb(mp(s,e));
  }
  if(!ch){ printf("POSSIBLE"); return 0;}
  
  sort(tv1.bg,tv1.ed);
  sort(tv2.bg,tv2.ed);
  vi tev(1);
  vi::iterator it=set_intersection(tv1.bg,tv1.ed,tv2.bg,tv2.ed,tev.bg);
  if(it-tev.bg>0){
      printf("POSSIBLE");
  }
  else{
      printf("IMPOSSIBLE");
  }
  
  
  
    return 0;
}



Measured memory_bytes: 3444
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!
template <class INT_T>
vector<INT_T> enum_divisors(INT_T n){
  vector<INT_T> div;
  for(int i=1;i<(int)sqrt(n)+1;i++){
    if(n%i==0){
      div.push_back(i);
      if(i!=(n/i)) div.push_back(n/i);
    }
  }
  return div;
}
// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n, k; cin>>n>>k;
  vi a(n);
  int B = 0;
  rep(i,n){ cin>>a[i]; B += a[i]; }
  vi div = enum_divisors(B);
  sort(all(div), greater<int>());
  bool ok = false;
  int X;
  vi R(n,0); vi C(n+2,0); vi Cr(n+2,0); C[n+1] = -1;
  for(int i=0;i<div.size();++i){
    X = div[i];
    rep(j,n){
      R[j] = a[j]%X;
    }
    sort(all(R));
    int t = 0;
    rep(j,n){
      C[j+1] = C[j] + R[j];
      Cr[n-j-1] = Cr[n-j] + (X-R[n-j-1]);
    }

    dump(X,C,Cr,k);
    rep(j,n){
      if(C[j+1]==Cr[j+1] && C[j+1]<=k) {ok=true; break;}
    }

    if(ok) break;

    //if(err<=2*k) {ok = true; break;}
    //if(sum_l==sum_r && sum_l<=k) {ok = true; break;}
    //if(t<=k && (sumR-t)<=k) {ok = true; break;}
  }
  
  if(ok) cout << X << endl;
  else cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())
points = [tuple(map(int, input().split())) for _ in range(n)]
points.sort()

ans = 0
i = 0
days = 0
heap = []
while days <= m:
    while i < len(points) and points[i][0] <= days:
        d, p = points[i]
        heapq.heappush(heap, -p)
        i += 1

    days += 1
    if heap: ans += heapq.heappop(heap)

print(-ans)

Measured memory_bytes: 20676
lisa=[1,3,5,7,8,10,12]
lisb=[4,6,9,11]
lisc=[2]
x,y=map(int,input().split())
if (x in lisa)and(y in lisa):
    print("Yes")
elif (x in lisb)and(y in lisb):
    print("Yes")
elif (x in lisc)and(y in lisc):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9132
#include<cstdio>
#include<algorithm>
using namespace std;
int n, w[110], P;
long long r = 1;
int main(){
    int i, t = 0;
    scanf("%d%d",&n,&P);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
        if(w[i]%2==1)t = 1;
        r*=2;
    }
    if(t==0){
        if(P==0)printf("%lld\n",r);
        else printf("%lld\n",0);
    }
    else printf("%lld\n",r/2);
}

Measured memory_bytes: 128
#include<stdio.h>
typedef struct{
  int no;
  int b,c,d;
  int cal;
}P;
int main(){
  int n,i,flg;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    P tmp[n];
    P max;
    for(i=0;i<n;i++){
      scanf("%d %d %d %d",&tmp[i].no,&tmp[i].b,&tmp[i].c,&tmp[i].d);
      tmp[i].cal=(tmp[i].b+tmp[i].d)*4+tmp[i].c*9;
	}
    scanf("%d %d %d %d",&max.b,&max.c,&max.d,&max.cal);
  

    for(i=0,flg=0;i<n;i++){
      if(max.b>=tmp[i].b&&max.c>=tmp[i].c&&max.d>=tmp[i].d&&max.cal>=tmp[i].cal){
	printf("%d\n",tmp[i].no);
	flg=1;
      }
    }
    if(flg==0)printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 628
M,K = map(int,input().split())
if K>=2**M:
    print(-1)
else:
    if M==1:
        if K==1:
            print(-1)
        elif K==0:
            print("1 0 0 1")
    else:
        A = []
        for i in range(2**M-1,-1,-1):
            if i==K:continue
            A.append(i)
        A.append(K)
        for i in range(2**M):
            if i==K:continue
            A.append(i)
        A.append(K)
        print(*A)

Measured memory_bytes: 100888
if __name__ == '__main__':
    N, K = list(map(int, input().split(' ')))

    if K != 0:
        counter = 0
        for b in range(K+1, N+1):
            counter += (b - K) * ((N+1) // b)
            if N - ((N+1) // b) * b + 1>= K:
                counter += N - ((N+1) // b) * b - K + 1

        print(counter)
    else:
        print(N**2)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
Node root;
Node treeMi(Node a){
  while(a->left!=NIL)
   a=a->left;
  return a;
}
Node treeMa(Node a){
  while(a->right!=NIL)
    a=a->right;
  return a;
}
Node treeS(Node w, int r){
  while(w!=NIL&&r!=w->key){
    if(r<w->key)w=w->left;
    else w=w->right;
  }
  return w;
}
Node treeM(Node a){
  Node b;
  if(a->right!=NIL)
    return treeMi(a->right);
  b=a->parent;
  while(b!=NIL&&a==b->right){
    a=b;
    b=b->parent;
  }
  return b;
}
void treeN(Node c){
  Node a;
  Node b;
  if(c->left==NIL||c->right==NIL)b=c;
  else
    b=treeM(c);
  if(b->left!=NIL){
    a=b->left;
  }
  else{
    a=b->right;
  }
  if(a!=NIL){
    a->parent=b->parent;
  }
  if(b->parent==NIL){
    root=a;
  }
  else{
    if(b==b->parent->left){
      b->parent->left=a;
    }
    else{
      b->parent->right=a;
    }
  }
  if(b!=c){
    c->key=b->key;
  }
  free(b);
}
void insert(int k){
  Node a = root;
  Node b = NIL;
  Node c;
  c = malloc(sizeof(struct node));
  c->key = k;
  c->left = NIL;
  c->right = NIL;
  while(a!=NIL){
    b=a;
    if(c->key < a->key){
      a=a->left;
    }
    else{
      a=a->right;
    }
  }
  c->parent=b;
  if(b==NIL){
    root=c;
  }
  else{
    if(c->key < b->key){
      b->left=c;
    }
    else{
      b->right=c;
    }
  }
}
void inorder(Node n){
  if(n==NIL)
    return;
  inorder(n->left);
  printf(" %d",n->key);
  inorder(n->right);
}
void outorder(Node n){
  if(n==NIL)
    return;
  printf(" %d",n->key);
  outorder(n->left);
  outorder(n->right);
}
int main(){
  int i,n,a;
  char c[20];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='f'){
      scanf("%d",&a);
      Node r = treeS(root,a);
      if(r!=NIL)
	printf("yes\n");
      else printf("no\n");
    }
    else if(c[0] ==  'i'){
      scanf("%d",&a);
      insert(a);
    }
    else if(c[0] ==  'p'){
      inorder(root);
      printf("\n");
      outorder(root);
      printf("\n");
    }
    else if(c[0]=='d'){
      scanf("%d",&a);
      treeN(treeS(root,a));
    }
  }
  return 0;
}



Measured memory_bytes: 20532
N, A, B = input().split()
rank = input()

A, B = int(A), int(B)
count1 = 0
count2 = 1
for s in rank:
    if (s == 'a') and (count1 < A+B):
        print("Yes")
        count1 += 1
    elif (s == 'b') and (count1 < A+B) and (count2 < B+1):
        print("Yes")
        count1 += 1
        count2 += 1
    else:
        print("No")


Measured memory_bytes: 4040
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main() {
  unsigned short *A, *B;

  int C[VMAX + 1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ) {
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= VMAX; i++ )C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ) {
    if ( i > 1 ) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}



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

int main(void)
{
	int n = 0, max = -1000001, min = 1000001, a;
	long long sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		sum += a;
		if (a < min)
			min = a;
		if (a > max)
			max = a;
	}
	cout << min << " " << max << " " << sum << endl;
}



Measured memory_bytes: 3092
#include<stdio.h>
int dp[101][4][4];
int main(void)
{
	int n,d;
	int a,b;
	int i,j,k,l;
	int s=0;
	int pst[101];
	
	scanf("%d %d",&n,&d);
	for(i=1;i<=n;i++){
		pst[i]=0;
		for(j=1;j<=3;j++){
			for(k=1;k<=3;k++){
				dp[i][j][k]=0;
			}
		}
	}
	for(i=0;i<d;i++){
		scanf("%d %d",&a,&b);
		pst[a]=b;
	}
	if(pst[1]==0){
		for(i=1;i<=3;i++){
			for(j=1;j<=3;j++){
				dp[1][i][1]=1;
			}
		}
	}
	else {
		for(i=1;i<=3;i++){
			dp[1][pst[1]][1]=1;
		}
	}
	for(i=1;i<=3;i++){
		if(pst[1]==i || pst[1]==0){
			for(j=1;j<=3;j++){
				if(pst[2]==j || pst[2]==0){
					dp[2][j][i]+=1;
				}
			}
		}
	}
	for(i=2;i<n;i++){
		for(j=1;j<=3;j++){
			if(pst[i]==j || pst[i]==0){
				for(k=1;k<=3;k++){
					for(l=1;l<=3;l++){
						if(pst[i+1]==l || pst[i+1]==0){
							if(!(j==k && j==l)){
									dp[i+1][l][j]+=dp[i][j][k];
									dp[i+1][l][j]=dp[i+1][l][j]%10000;
							}
						}
					}
				}
			}
		}
	}
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++){
			s+=dp[n][i][j];
			s=s%10000;
		}
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 1028
def combinations_with_replacement(elements, N):
    for i, element in enumerate(elements):
        if N == 1:
            yield [element]
        else:
            for combination in combinations_with_replacement(elements[:i+1], N-1):
                combination.append(element)
                yield combination


N, M, Q = map(int, input().split())
a = [None for _ in range(Q)]
b = [None for _ in range(Q)]
c = [None for _ in range(Q)]
d = [None for _ in range(Q)]
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

ans = 0
elements = list(range(1, M+1))
for combination in combinations_with_replacement(elements, N):
    score = 0
    for i in range(Q):
        if combination[b[i]-1] - combination[a[i]-1] == c[i]:
            score += d[i]
    ans = max(score, ans)
print(ans)


Measured memory_bytes: 9136
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <cmath>
 
using namespace std;
 
#define F first
#define S second
 
#define X real()
#define Y imag()
 
#define EPS (1e-7)
 
typedef complex<double> Point;
typedef vector<Point> Polygon;
typedef pair<double, Point> Circle;
 
bool isPointInCircle(const Point& p, const Circle& c) {
  if(abs(p-c.S) < abs(c.F) + EPS) return true;
  return false;
}
 
double dot(const Point& a, const Point& b) {
  return a.X*b.X+a.Y*b.Y;
}
 
double cross(const Point& a, const Point& b) {
  return a.X*b.Y-a.Y*b.X;
}
 
typedef pair<Point, Point> Segment;
typedef Segment Line;
 
double distanceLP(Line l, Point p) {
  return abs(cross(l.S-l.F, p-l.F)) / abs(l.S-l.F);
}
 
double distanceSP(Segment s, Point p) {
  Point a = s.F, b = s.S;
   
  if(dot(b-a, p-a) < EPS) return abs(p-a);
  if(dot(a-b, p-b) < EPS) return abs(p-b);
  return distanceLP(s, p);
}
 
 
enum struct ECont { OUT, ON, IN };
ECont contains(const Polygon& poly, const Point& p) {
  bool in = 0;
  for(int i=0; i<poly.size(); i++) {
    Point a = poly[i] - p, b = poly[(i+1)%poly.size()] - p;
    if(a.imag() > b.imag()) swap(a, b);
    if(a.imag() <= 0 && 0 < b.imag()) {
      if(cross(a, b) < 0) in = !in;
    }
    if(cross(a, b) == 0 && dot(a, b) <= 0) return ECont::ON;
  }
   
  return in ? ECont::IN : ECont::OUT;
}
 
int main() {
   
  while(1) {
    Polygon points(3);
    Circle circle;
   
    for(int i=0; i<3; i++) {
      double x, y; cin >> x >> y;
      if(x == 0) return 0;
     
      points[i] = Point(x, y);
    }
   
    {
      double x, y; cin >> x >> y;
      circle.S = Point(x, y);
      cin >> circle.F;
    }
   
    bool ok = 1;
    for(int i=0; i<3; i++) {
      ok &= isPointInCircle(points[i], circle);
    }
    if(ok) {
      cout << 'b' << endl;
      continue;
    }
     
    int uncross = 0;
    for(int i=0; i<3; i++) {
      Segment seg = make_pair(points[(i+1)%3], points[i]);
      uncross += circle.F < distanceSP(seg, circle.S) + EPS;
    }
    if(uncross == 3 && contains(points, circle.S) == ECont::IN) {cout << 'a' << endl; continue;}
 
    int cross = 0;
    for(int i=0; i<3; i++) {
      Segment seg = make_pair(points[(i+1)%3], points[i]);
      cross += distanceSP(seg, circle.S) <= circle.F + EPS;
    }
    if(cross > 0) cout << 'c' << endl;
    else cout << 'd' << endl;
  }
   
  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define il inline
#define vd void
#define mod 1000000007
typedef long long ll;
il ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
il int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
int f[1000010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),H=gi(),D=gi(),N=0;
	int fact=1;
	for(int i=1;i<=n;++i)fact=1ll*fact*i%mod,N=(N+fact)%mod;
	f[0]=1;
	for(int i=1;i<=H;++i)
		f[i]=(f[i-1]+1ll*N*(f[i-1]-(i-D>0?f[i-D-1]:0)+mod))%mod;
	printf("%lld\n",1ll*(f[H]-f[H-1]+mod)*fact%mod*pow(N,mod-2)%mod);
	return 0;
}



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

const int N = 200000+9;

int dep[N],fa[N],in[N],pre[N],tot,n;
struct Data{
	int x,y;
	inline Data() {}
	inline Data(int a, int b):x(a),y(b) {}
	inline bool operator < (const Data &B) const {
		return x > B.x;
	}
};
priority_queue<Data> que;

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

int find(int w) {
	return w == fa[w]? w: fa[w] = find(fa[w]);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = tot = read();
	for (int i=1;i<=2*n;i++) fa[i] = i;
	for (int i=2;i<=n;i++) {
		pre[i] = read();
		in[pre[i]]++;
	}
	for (int i=1;i<=n;i++) {
		if (!in[i]) {
			que.push(Data(0, i));
		}
	}
	while (!que.empty()) {
		int w = que.top().y; que.pop(); 
		dep[++tot] = max(dep[find(pre[w])], dep[find(w)]) + 1;
		fa[fa[pre[w]]] = fa[fa[w]] = tot;
		if (!--in[pre[w]] && pre[w] != 1) que.push(Data(dep[tot], pre[w]));
	}
	printf("%d\n",dep[tot]);
	return 0;
}


Measured memory_bytes: 2680
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = a; i >= (b); --i)
#define repdl(i, a, b) for(ll i = a; i >= (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void writef(T ...tail) { write(tail...); cout << flush; }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  if (v.size()) {
    rep(i, 0, sz(v) - 1)
      out << v[i] << " ";
    out << v.back();
  }
  return out;
}
#endif
using namespace std;

struct Hist {
  int dist, i, j;
  const bool operator<(const Hist& h) const {
    return dist > h.dist;
  }
};

char mp[1005][1005];
int md[1005][1005];
priority_queue<Hist> q;
int h, w;
const int inf = 0x3f3f3f3f;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  read(h, w);
  rep(i, 0, 1005) rep(j, 0, 1005) md[i][j] = inf;
  int ch, cw, dh, dw; read(ch, cw, dh, dw);
  md[ch][cw] = 0;
  q.push(Hist { 0, ch, cw });
  cin >> skipws;
  rep(i, 1, h + 1) rep(j, 1, w + 1) read(mp[i][j]);
  while (!q.empty()) {
    Hist hi = q.top(); q.pop();
    int i = hi.i, j = hi.j;
    if (hi.dist > md[i][j]) continue;
    rep(dx, -2, 3) rep(dy, -2, 3) {
      int ni = i + dx, nj = j + dy;
      int dd = (abs(dx) + abs(dy) == 1) ? 0 : 1;
      if (1 <= ni && ni <= h && 1 <= nj && nj <= w) {
        if (md[ni][nj] > md[i][j] + dd && mp[ni][nj] != '#') {
          md[ni][nj] = md[i][j] + dd;
          q.push(Hist { md[ni][nj], ni, nj });
        }
      }
    }
  }
  if (md[dh][dw] == inf)
    write(-1);
  else
    write(md[dh][dw]);
}



Measured memory_bytes: 8584
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }

struct edge{int to, cost;};

class Graph
{
public:
    int V;
    vector<vector<edge>> G;

    Graph(int V): V(V){
        G = vector<vector<edge>>(V, vector<edge>(0));
    }

    void add_edge(int from, int to, int cost){
        G[from].push_back(edge({to, cost}));
    }

    void add_edge2(int v1, int v2, int cost){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }

    //bool dfs(int v, bools used){
    //    used
    //}

};

signed main(){

    vec a(3), b(3);
    vec cnt(4, 0);
    REP(i, 3){
        cin >> a[i] >> b[i];
        cnt[a[i] - 1]++;
        cnt[b[i] - 1]++;
    }
    vec v(4);
    REP(i, 4) v[i] = cnt[i];
    Sort(v);
    Ans(v[0] == 1 && v[1] == 1 && v[2] == 2 && v[3] == 2, "YES", "NO");

    return 0;
}


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

using namespace std;

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

int main() {
	long long a, b;
	int ans;
	cin >> a >> b;
	
	if (a == 0 || b == 0 || (a < 0 && b > 0))
		ans = 0;
	else if (a < 0) {
		if (a == b)
			ans = 1;
		else
			ans = ((b - a) & 1) ? 1 : 2;
	}
	else
		ans = 1;
	
	switch (ans) {
		case 0: puts("Zero"); break;
		case 1: puts("Positive"); break;
		case 2: puts("Negative"); break;
	}
	return 0;
}

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

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

using namespace std;

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

  string s[10];
  s[2] = s[4] = s[5] = s[7] = s[9] = "hon";
  s[0] = s[1] = s[6] = s[8] = "pon";
  s[3] = "bon";
  cout << s[N % 10] << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;


int main(){
  int n,k;cin>>n>>k;
  int ans = 0;
  for(int i=0;i<n;i++){
    int tmp;cin>>tmp;
    ans += min(2*abs(tmp-k),2*abs(tmp));
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
vec = []
for i in 1..n do
  vec.push(0)
end
for i in 0..n-1 do
  vec[a[i]-1] += 1
end
sum = 0
for i in 0..n-1 do
  sum += vec[i] * (vec[i]-1) / 2
end
for i in 0..n-1 do
  puts sum - (vec[a[i]-1]*(vec[a[i]-1]-1)/2) + ((vec[a[i]-1]-2)*(vec[a[i]-1]-1)/2)
end

Measured memory_bytes: 23236
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<long long,long long>
#define ppii pair<long long,pair<long long,long long>>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef vector<vector<long long>> vii;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint 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; }
lint 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 };
long long INF = 1e14;
const int MAX_N = 1 << 17;
const int cf = 100010;
///////////////////////////////////////////////////////////////////////////////
lint x[cf],d[cf];
int main() {
	lint n, a, b; cin >> n >> a >> b;
	rep(n) cin >> x[i];
	rep(n - 1)d[i] = x[i + 1] - x[i];
	lint ans = 0;
	rep(n - 1) ans += min(b, a*d[i]);
	cout << ans << endl; return 0;
}

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

int main(){
    int N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    string S;
    cin>>S;
    int fstoneA=0,fstoneB=0;
    
    for(int i=A-1; i<C-1; i++){
        if(S[i]=='#'&&S[i+1]=='#')fstoneA=1;
    }
    for(int i=B-1; i<D-1; i++){
        if(S[i]=='#'&&S[i+1]=='#')fstoneB=1;
    }
    if(fstoneA||fstoneB){
        cout<<"No";
        return 0;
    }
    if(C<=B||C<=D){
        cout<<"Yes";
        return 0;
    }
    int flag=0;
    for(int i=B-1; i<=D-1; i++){
        if(S.substr(i-1,3)=="...")flag=1;
    }
    if(flag==1)cout<<"Yes";
    else cout<<"No";

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    long long X, t;
    cin >> X >> t;
    cout << max(X - t, 0LL) << endl;
    return 0;
}


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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define CON_MAX 214514
const long long int MOD = 998244353LL;

int main() {

	long long int inv[ CON_MAX ] = {};
	inv[1] = 1;
	for ( long long int i = 2; i <= CON_MAX; i++ ) {
		inv[i] = MOD - ( MOD / i ) * inv[ MOD % i ] % MOD;
	}

    long long int n, m, k;
    cin >> n >> m >> k;

    long long int cnt[ 214514 ] = {};
    cnt[1] = m;
    for ( long long int i = 2; i <= n; i++ ) {
        cnt[i] = cnt[i-1] * ( m - 1 );
        cnt[i] %= MOD;
    }

    long long int ans = 0;
    long long int cmb = 1;

    for ( long long int i = 0; i <= k; i++ ) {
        ans += cnt[ n - i ] * cmb;
        ans %= MOD;
        cmb *= n - 1 - i;
        cmb %= MOD;
        cmb *= inv[ i + 1 ];
        cmb %= MOD;
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 6988
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int test=1;
  //cin>>test;
  while(test--){
    int n,m;
    string s,t;
    cin>>s>>t;
    n=sz(s), m=sz(t);
    int L[n+1][m+1];
    rep(i,0,n+1) L[i][0]=0;
    rep(i,0,m+1) L[0][i]=0;

    rep(i,1,n+1){
      rep(j,1,m+1) {
        if(s[i-1]==t[j-1]) L[i][j]=L[i-1][j-1]+1;
        else L[i][j]=max(L[i-1][j],L[i][j-1]);
      }
    }
    /*rep(i,1,n+1){
      rep(j,1,m+1) cout<<L[i][j]<<" ";
      cout<<endl;
    }*/
    int cnt=L[n][m];
    int a1=n,a2=m;
    string ans;
    while(cnt){
      //cout<<a1<<" "<<a2<<endl;
      if(a1>=2 && L[a1-1][a2]==L[a1][a2]) a1--;
      else if(a2>=2 && L[a1][a2-1]==L[a1][a2]) a2--;
      else if(L[a1][a2]=L[a1-1][a2-1]+1) {
        a1--;
        a2--;
        ans.pb(s[a1]);
        cnt--;
      }
    }
    reverse(all(ans));
    cout<<ans;
  }



}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


// ★DP 漸化式
// wの合計がlimit_w以下となるvの最大値を求める
#define MAX_N (100)
#define MAX_W (10000)
int N, W;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_N + 1][MAX_W + 1];

int main() {

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

	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			//i番目が採用できるか否かを判定
			if (j < w[i]) {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				//i番目が採用できるとき、iを使うケースと使わないケースの最大を取る

//				dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]); // 個数制約なし(iを複数つかえる)
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); // 個数制約あり
			}
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}


Measured memory_bytes: 6968
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N,K;
    string S;
    cin>>N>>K>>S;
    if(S.at(K-1)=='A'){
        S.at(K-1)='a';
    }
    if(S.at(K-1)=='B'){
        S.at(K-1)='b';
    }
    if(S.at(K-1)=='C'){
        S.at(K-1)='c';
    }
    cout<<S<<endl;
}

Measured memory_bytes: 256
x = int(input())

if x >= 1800:
  print(1)
elif x >= 1600:
  print(2)
elif x >= 1400:
  print(3)
elif x >= 1200:
  print(4)
elif x >= 1000:
  print(5)
elif x >= 800:
  print(6)
elif x >= 600:
  print(7)
else:
  print(8)

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		ans += a - 1;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a[4],b[4], hit, blow;
  bool flag[4];
  while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]){
    hit = 0; 
    blow = 0;
    for(int i=0; i<4; i++)
      flag[i] = false;

    for(int i=0; i<4; i++){
	if(a[i] == b[i]){
	  hit++;
	  flag[i] = true;
	}
	for(int j=0; j<4; j++){
	  if( a[i] == b[j] &&  flag[i] != true){
	    blow++;
	  }
	}
    }
    cout << hit << " " << blow << endl;
  }
}

Measured memory_bytes: 0
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
const LL mod = 1e9 + 7;
const int N = 17;
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(int x) {
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

LL f[1 << N];
LL jc[1 << N], inv[1 << N];
int a[N], bin[N], cnt[1 << N];

LL pow_mod(LL a, int k) {
	LL ans = 1;
	while(k) {
		if(k & 1) (ans *= a) %= mod;
		(a *= a) %= mod; k /= 2;
	} return ans;
}

LL C(int n, int m) {
	if(n < m) return 0;
	return jc[n] * inv[m] % mod * inv[n - m] % mod;
}

int main() {
	int n = read(), m = read();
	for(int i = 1; i <= m; i++) a[i] = read();
	bin[0] = 1; for(int i = 1; i <= n; i++) bin[i] = bin[i - 1] * 2;
	jc[0] = inv[0] = 1; for(int i = 1; i <= bin[n]; i++) jc[i] = jc[i - 1] * i % mod;
	inv[bin[n]] = pow_mod(jc[bin[n]], mod - 2); for(int i = bin[n] - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
	cnt[0] = 0; for(int i = 1; i <= bin[n]; i++) cnt[i] = cnt[i >> 1] + (i & 1);
	f[0] = 1; sort(a + 1, a + m + 1);
	for(int i = m; i >= 1; i--) {
		for(int j = bin[n] - 1; j >= 0; j--) {
			for(int k = 0; k < n; k++) if(bin[k] & j){
				(f[j] += f[j ^ bin[k]] * C(bin[n] - a[i] - j + bin[k], bin[k] - 1) % mod * jc[bin[k]]) %= mod;
			}
		}
	} LL ans = 0;
	for(int i = 0; i < bin[n]; i++) {
		f[i] = f[i] * jc[bin[n] - i - 1] % mod;
		cnt[i] & 1 ? ans = (ans - f[i] + mod) % mod : ans = (ans + f[i]) % mod;
	} printf("%d\n", ans * bin[n] % mod);
	return 0;
}


Measured memory_bytes: 1920