akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
int A[200005];
int main() {
  ios::sync_with_stdio(false);
  int K, N;
  cin >> K >> N;
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  int ret = K;
  for (int i=0; i<N-1; i++) {
    ret = min(ret, K - (A[i+1] - A[i]));
  }
  ret = min(ret, K - (A[0] + K - A[N-1]));
  cout << ret << endl;
}

Measured memory_bytes: 1024
// C - Skill Up
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int N,M,X; cin>>N>>M>>X;
	VVL books(N, VL(M+1));
	rep(i, N) rep(j, M+1) cin>>books[i][j];
	ll inf, ans = inf = 1e18;
	rep(bit, 1<<N){ // [0,(2^N)-1] combination full search
		ll cost = 0;
		VL skill(M, 0);
		rep(book, N) // [0,N-1] book no.
			if(bit>>book & 1){ // buy
				cost += books[book][0]; // cost get
				rep(j, M) skill[j] += books[book][j+1]; // skill get
			}
		if(*min_element(skill.begin(), skill.end()) >= X) // skill check
			ans = min(ans, cost); // min cost
	}
	if(ans == inf) ans=-1; // exist?
	cout<< ans <<endl;
}


Measured memory_bytes: 3624
pln[14][14];
main(i,j,c,f){
    while(1){
        for(i=3;i<11;i++){
            for(j=3;j<11;j++)    pln[i][j]=getchar()-'0';
            if(getchar()==-1)   exit(0);
        }
        getchar();
 
        f=1;
        for(i=3;f&&i<11;i++)for(j=3;f&&j<11;j++)
            if(pln[i][j]){
                if     (pln[i+3][j])    c='B';
                else if(pln[i][j+3])    c='C';
                else if(pln[i+2][j-1])  c='D';
                else if(pln[i+1][j+2])  c='E';
                else if(pln[i+2][j+1])  c='F';
                else if(!pln[i+1][j+1]) c='G';
                else    c='A';
                f=0;
            }
        printf("%c\n",c);
    }
}

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

const int limits = 50;
int N,M;
bool visited[limits];
vector< vector<int> > adj(limits, vector<int>(limits, 0));

void clear(){
  for(int i = 0; i < N; i++){
    visited[i] = false;
  }
}

bool check(){
  bool flag = true;
  for(int i = 0; i < N; i++){
    if(visited[i] == false) flag = false;
  }
  return flag;
}

void dfs(int n){
  visited[n] = true;
  for(int i = 0; i < N; i++){
    if(adj[n][i] == 1 && visited[i] == false){
      dfs(i);
    }
  }
}

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

  int edge[M][2];
  int cnt = 0;
  for(int i = 0; i < M; i++){
    cin >> edge[i][0] >> edge[i][1];
    edge[i][0]--; edge[i][1]--;
    adj[edge[i][0]][edge[i][1]] = 1;
    adj[edge[i][1]][edge[i][0]] = 1;
  }
  
  for(int i = 0; i < M; i++){
    clear();
    adj[edge[i][0]][edge[i][1]] = 0;
    adj[edge[i][1]][edge[i][0]] = 0;
    dfs(0);
    // cout << "i= " << i + 1 << endl;
    // for(int j = 0; j < N; j++){
    //   if(visited[j]) cout << j + 1 << " ";
    // }
    // cout << endl;
    if(!check()){
       cnt++;
    //   cout << "Yes " << i + 1 << endl;
    } 
    adj[edge[i][0]][edge[i][1]] = 1;
    adj[edge[i][1]][edge[i][0]] = 1;
  }

  cout << cnt << endl;
  
}


Measured memory_bytes: 256
class Dice
  def initialize num_dict
    @num=num_dict

    @top=1
    @bottom=6
    @right=3
    @left=4
    @forward=5
    @backward=2

  end
  
  def to_s
    <<"EOS"
    top:      #{@num[@top]}
    bottom:   #{@num[@bottom]}
    right:    #{@num[@right]}
    left:     #{@num[@left]}
    forward:  #{@num[@forward]}
    backward: #{@num[@backward]}
EOS
  end

  def getTop
    @num[@top]
  end

  def moveE
    temp=@top
    @top=@left
    @left=@bottom
    @bottom=@right
    @right=temp
  end

  def moveW
    temp=@top
    @top=@right
    @right=@bottom
    @bottom=@left
    @left=temp
  end

  def moveN
    temp=@top
    @top=@backward
    @backward=@bottom
    @bottom=@forward
    @forward=temp
  end
  
  def moveS
    temp=@top
    @top=@forward
    @forward=@bottom
    @bottom=@backward
    @backward=temp
  end

  def rotate(char)
    case char
      when "E"
        moveE
      when "W"
        moveW
      when "N"
        moveN
      when "S"
        moveS
    end
  end

  def setBackwardandRight(backNum,rightNum)
    back=@num.key(backNum)
    right=@num.key(rightNum)
    3.times{
      break if @backward==back
      moveN
    }
    if @backward!=back
      moveE
      while @backward!=back
        moveN
      end
    end
 
    while @right!=right
      moveE
    end
  end
end

a,b,c,d,e,f=STDIN.gets.split(" ")
dice=Dice.new({1 => a.to_i , 2 => b.to_i , 3 => c.to_i , 4 => d.to_i , 5 => e.to_i , 6 => f.to_i})

orderNum=STDIN.gets.to_i
output=[]
orderNum.times do
  a,b=STDIN.gets.split(" ")
  dice.setBackwardandRight(a.to_i,b.to_i)
  output<<dice.getTop

end
output.each{|i|
  puts i
}

Measured memory_bytes: 8652
import sys
input = sys.stdin.readline

N, K = list(map(int, input().split()))

ans = 0
over = 0
down = 0
for i in range(N+1):
    over +=  N  - i
    down += i
    if i >= K-1:
        ans += over - down + 1
print(ans % (10 ** 9 + 7))


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int a[5];
  while(inputs(a, 5)) {
    int sum = 0;
    int mx = 0;
    REP(i,5) {
      sum += (a[i] + 9) / 10 * 10;
      int s = a[i] % 10;
      if (s) chmax(mx, 10 - s);
    }
    cout << sum - mx << endl;
  }
}


Measured memory_bytes: 384
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			if(n == 0)
			{
				break;
			}
			int count = 0;
			while(true)
			{
				if(n == 1)
				{
					break;
				}
				if(n % 2 == 0)
				{
					n /= 2;
				}
				else
				{
					n = 3 * n + 1;
				}
				++count;
			}
			System.out.println(count);
		}
	}
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b)
{
	int res = 1;

	while (b)
	{
		if (b & 1) res = (res * a);

		a = (a * a); 
		b >>= 1;
	}
	return res;
}

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

#define N 1000010
#define MOD 1000000007

char str[N];
int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);

	string s;
	cin >> s;

	int n = s.size();
	int i = 0;
	while (i < n)
	{
		if (i + 1 < n && s[i] == 'h' && s[i + 1] == 'i')
		{
			i += 2;
		}
		else
		{
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y,ans=INF;
  cin>>x>>y;
  if((-y)-(-x)>=0)ans=min(ans,(-y)-(-x)+2);
  if((-y)-x>=0)ans=min(ans,(-y)-x+1);
  if(y-(-x)>=0)ans=min(ans,y-(-x)+1);
  if(y-x>=0)ans=min(ans,y-x);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll X;
    cin >> X;
    for (ll B = -200; B <= 200; B++) {
        for (ll A = -200; A <= 200; A++) {
            if (pow(A, 5) == X + pow(B, 5)) {
                cout << A << " " << B << endl;
                return 0;
            }
        }
        
    }
   
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
double mean(double m) { return (m+1) / 2; }
/* main */
int main(){
    int N;
    double K;
    cin >> N >> K;
    vector<double> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < N; i++) a[i] = mean(a[i]);
    vector<double> sum(N+1);
    for (int i = 0; i < N; i++) sum[i+1] = sum[i] + a[i];
    double mx = 0.0;
    for (int i = 0; i <= N - K; i++) {
        mx = max(mx, sum[i+K] - sum[i]);
    }
    cout << fixed << setprecision(8) << mx << '\n';

}


Measured memory_bytes: 6464
o = input()
e = input()
ans = ""
if len(o) == len(e):
	for i in range(len(o)):
		ans += (o[i]+e[i])
elif len(o) > len(e):
	for i in range(len(e)):
		ans += (o[i]+e[i])
	ans += o[-1]
elif len(e) > len(o):
	for i in range(len(o)):
		ans += (o[i]+e[i])
	ans += e[-1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int K, N, A[202020];

void solve() {
    int ans = INF;
    FOR(i, 0, N - 1) {
        chmin(ans, K - (A[i + 1] - A[i]));
    }
    chmin(ans, -A[0] + A[N - 1]);
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> K >> N;
    FOR(N)
    cin >> A[i];


    solve();
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		if(S.charAt(0) == S.charAt(1) && S.charAt(1) == S.charAt(2) && S.charAt(0) == S.charAt(2)){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 35572
zzz::[Int] -> String
zzz (w:h:x:y:r)
  | _x && _y && __x && __y = "Yes"
  | otherwise = "No"
  where _x = w >= (x + head r)
        _y = h >= (y + head r)
        __x = 0 <= (x - head r)
        __y = 0 <= (y - head r)



main = do
  a <- getLine
  putStrLn $ zzz $ map (\x -> read x::Int) $ words a


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
#define MOD 1000000007

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}

const int INF=1e9;
const double eps=0.0000000001;

int main(){
  int n,k;
  cin >> n >> k;
  int d[100];
  FOR(i,k){
    cin >> d[i];
  }
  int c[100];

  for(int i=n;i<n*10;i++){
    int num=i;
    bool e=0;
    while(num){
      FOR(j,k){
        if(d[j]==num%10)e=1;
      }
      num/=10;
      
    }
    if(!e){
      cout << i << endl;
      break;
    }
  }
  
}

Measured memory_bytes: 256
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        long a = sc.NextLong();
        long b = sc.NextLong();
        long k = sc.NextLong();

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

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 13140
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LS()
A_Bub = []
A_Sel = []
for i in range(N):
    A_Bub.append([A[i][0], int(A[i][1]), i])
    A_Sel.append([A[i][0], int(A[i][1]), i])

#BubleSort(C, N)
def BubleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if C[j][1] < C[j - 1][1]:
                a = C[j]
                b = C[j - 1]
                C[j] = b
                C[j - 1] = a

#SelectionSort(C, N)
def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        a = C[i]
        b = C[minj]
        C[i] = b
        C[minj] = a

def Check(C, N):
    for i in range(1, N):
        if C[i][1] == C[i - 1][1]:
            if C[i][2] < C[i - 1][2]:
                return 'Not stable'
    return 'Stable'
BubleSort(A_Bub, N)
ans_Bub = []
for i in range(N):
    b = [A_Bub[i][0], A_Bub[i][1]]
    ans_Bub.append(''.join(map(str, b)))
print(' '.join(map(str, ans_Bub)))
print(Check(A_Bub, N))


SelectionSort(A_Sel, N)
ans_Sel = []
for i in range(N):
    s = [A_Sel[i][0], A_Sel[i][1]]
    ans_Sel.append(''.join(map(str, s)))
print(' '.join(map(str, ans_Sel)))
print(Check(A_Sel, N))


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

using namespace std;

typedef long long ll;

ll n, a[200010];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] += a[i - 1];
	}
	ll m = a[n];
	for (int i = 2; i <= n - 2; i++) {
		ll s1 = a[i], s2 = a[n] - a[i];
		ll m1 = (s1 - 1) / 2, m2 = (s2 - 1) / 2 + a[i];
		int j = lower_bound(a + 1, a + i, m1) - &a[1] + 1;
		ll d1 = a[j], d2 = a[i] - a[j];
		ll MM1 = max(d1, d2);
		ll mm1 = min(d1, d2);
		if (j > 1) {
			j--;
			d1 = a[j], d2 = a[i] - a[j];
			if (max(d1, d2) < MM1) {
				MM1 = max(d1, d2);
				mm1 = min(d1, d2);
			}
		}
		j = lower_bound(a + i + 1, a + n - 1, m2) - &a[i + 1] + 1;
		d1 = a[i + j] - a[i], d2 = a[n] - a[i + j];
		ll MM2 = max(d1, d2);
		ll mm2 = min(d1, d2);
		if (j > 1) {
			j--;
			d1 = a[i + j] - a[i], d2 = a[n] - a[i + j];
			if (max(d1, d2) < MM2) {
				MM2 = max(d1, d2);
				mm2 = min(d1, d2);
			}
		}
		m = min(m, max(MM1, MM2) - min(mm1, mm2));
	}
	cout << m << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << "NO" << endl;return 0
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N,M;
    vector<pair<int,int>> AB;
    cin >> N >> M;
    int a,b;
    int Ans=0;
    REP(i,N){
        cin >> a >> b;
        AB.push_back({a,-b});
    }
    sort(AB.begin(),AB.end());
    REP(i,N){AB[i].second*=-1;}
    priority_queue<int> P;
    int now=0;
    REP(i,M){
        while(now<N){
            if(AB[now].first<=i+1){
                P.push(AB[now].second);
                now++;
            }else{
                break;
            }
        }
        if(!P.empty()){
            Ans+=P.top();
            P.pop();
        }
        
    }
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 3568
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) System.out.println(2);
        else if (n % 2 == 0) System.out.println(n);
        else System.out.println(n*2);
    }
}

Measured memory_bytes: 21716
#include<stdio.h>
int main() {
	long long int n, m,j,k,a=0,b=0;
	scanf("%lld %lld",&n, &m);
	for (j = 1; j <= n; j++) {
		scanf("%lld", &k);
		a += k;
	}
	for (j = 1; j <= m; j++) {
		scanf("%lld", &k);
		b += k;
	}
	printf("%lld\n", a*b);
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.IntStream;

public class Main {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = in.nextInt();
            y[i] = in.nextInt();
        }
        int[] d = new int[n];
        int[] p = new int[n];
        Arrays.fill(d, Integer.MAX_VALUE);
        for (int i = 0; i < m; i++) {
            int px = in.nextInt();
            int py = in.nextInt();
            for(int j = 0; j < n; j++) {
                int dist = Math.abs(px - x[j]) + Math.abs(py - y[j]);
                if(dist < d[j]) {
                    d[j] = dist;
                    p[j] = i + 1;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.println(p[i]);
        }
    }
}


class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}

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

int n, a, b;

inline void solve()
{
    scanf( "%d%d", &a, &b );
    if( a > b ) swap( a, b );
    ll product = ll(a) * b;

	if( b - a <= 1 ) {
		printf( "%d\n", ( a - 1 ) * 2 ); return;
	}

    ll _max = sqrt( product );
    if( _max * _max == product ) _max --;
    ll ans = _max * 2;
    
    if( _max * ( _max + 1 ) >= product ) ans --;
    
    if( a <= _max ) ans --;
	if( b <= _max ) ans --;

    printf( "%lld\n", ans );
}

int main()
{
    scanf( "%d", &n );

    while( n -- ) 
        solve();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
char easytolower(char in);

int main(){
    string b;
    int num[26] = {0};
    while(cin >> b){
        string a = b;
        transform(a.begin(),a.end(), b.begin(),::tolower);
        for(int i = 0; i < b.length(); ++i){
            num[int(b[i]) - int('a')]++;
        }
    }

    for(int i = 0; i < 26; ++i){
        cout << (char)('a' + i ) << " : " << num[i] << endl;
    }
    return 0;
}

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

int main() {
  long long N, D;
  cin >> N >> D;

  long long ans = 0;
  for (long long i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    if (a * a + b * b <= D * D) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3616
from string import*
from itertools import*
b = ascii_lowercase
s = input()
if len(s) < 26:
    print(s + sorted(set(b) - set(s))[0])
else:
    d = -[p*len(list(k)) for p, k in groupby([i < j for i, j in zip(s[-1::-1], s[-2::-1])])][0] - 2
    print(-(d < -26) or s[:d] + sorted(set(s[d+1:]) - set(b[:ord(s[d]) - 97]))[0])

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

ll n, q, a[MAX_N], cum[MAX_N], eve[MAX_N];

int main() {
    cin >> n >> q;
    REP(i,n)cin >> a[i];
    REP(i,n){
        cum[i+1] += cum[i]+a[i];
        eve[i+1] += eve[i]+(i%2?a[i]:0ll);
    }
    REP(i,q){
        ll x, ok = 0, ng = n-n/2+1, ans = 0, k;
        cin >> x;
        k = lower_bound(a,a+n,x) - a;
        ng = min(ng, n-k+1);
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2, l, r;
            l = max(0ll,n-2*mid+1);
            r = n-mid;
            //cout << a[l] << " " << a[r] << endl;
            if( (x-a[l] <= a[r]-x)){
                ok = mid;
            }
            else{
                ng = mid;
            }
        }
        //cout << "ok" << ok << endl;
        ans += cum[n]-cum[n-ok];
        if(n%2) ans += cum[n-2*ok] - eve[n-2*ok];
        else ans += eve[n-2*ok];
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    long long int ans = 0;
    ll n, k;
    cin >> n >> k;
    for(ll i = k; i <= n+1; i++){
        ll x = i*(i-1)/2;
        ll y = i*(2*n-i+1)/2;
        //cout << y-x+1 << endl;
        ans += y-x+1;
        ans = ans%1000000007;
    }
    cout << ans << endl;
}

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

int main() {

    int n; cin >> n;
    bool four = false;
    for (int i = 0; i < n; i++) {
        char tmp; cin >> tmp;
        if (tmp == 'Y') four = true;
    }

    if (four) cout << "Four" << endl;
    else cout << "Three" << endl;
    return 0;
}

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

using i8  = int8_t;using i16 = int16_t;using i32 = int32_t;using i64 = int64_t;using u8  = uint8_t;using u16 = uint16_t;using u32 = uint32_t;using u64 = uint64_t;using f32 = float;using f64 = double;
using vi32 = vector<i32>;using vi64 = vector<i64>;using vvi32 = vector<vi32>;using vvi64 = vector<vi64>;using pi32 = pair<i32,i32>;using pi64 = pair<i64,i64>;

#define FOR(i,a,b) for(i64 i=(a), i##_len=(b); i<i##_len; ++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,x) for(i64 i=1;i<=(i64)(x);i++)
#define RREPS(i,x) for(i64 i=((i64)(x));i>0;i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define SZ(x) ((i64)(x).size())
#define CLR(ar,val) memset(ar, val, sizeof(ar))
#define cauto const auto&
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

i32 dx[4]={1,0,-1,0};
i32 dy[4]={0,1,0,-1};
const i32 INF32 = 0x3F3F3F3F;
const i64 INF64 = 0x3F3F3F3F3F3F3F3F;

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

void Main();
i32 main() {cin.tie(nullptr);ios_base::sync_with_stdio(false);cout << fixed << setprecision(15);Main();return 0;}

void Main() {
    //-------------------------------------------------------------------------
    i64 n; cin >> n;
    i64 arr[n];
    REP(i,n) cin >> arr[i];
    bool flag = true;
    i64 ans = 0;
    while (flag) {
        flag = false;
        for (i64 j = n-1; j >= 1; j--) {
            if (arr[j] < arr[j-1]) {
                ans++;
                arr[j] ^= arr[j-1] ^= arr[j] ^= arr[j-1];
                flag = true;
            }
        }
    }
    for (i64 i = 0; i < n; i++) cout << arr[i] << (i == (n - 1) ? '\n' : ' ');
    cout << ans << endl;
    //-------------------------------------------------------------------------
}


Measured memory_bytes: 3224
<?php

fscanf(STDIN, "%d", $n);
$array = explode(' ', trim(fgets(STDIN)));
$array1 = str_split($array[0]);
$array2 = str_split($array[1]);

$answer = '';
for ($i=0; $i < $n; $i++) {
  $answer .= $array1[$i] . $array2[$i];
}

echo $answer;


Measured memory_bytes: 4856
#include<iostream>
#include<vector>



int main() {
	int n, m;
	std::cin >> n >> m;
	std::vector<bool>used(m, 0);
	std::vector<int>a(m), b(m);
	for (int i = 0; i < m; i++)std::cin >> a[i] >> b[i];
	for (int i = 0; i < m; i++)a[i]--, b[i]--;
	int point = 0,ans = 0;
	for (int i = 0; i < m; i++) {
		int min = 1 << 30;
		for (int j = 0; j < m; j++) {
			if (used[j])continue;
			if (a[j] < point) { 
				used[j] = true;
				continue;
			}
			min = min > b[j] ? b[j] : min;
		}
		bool flag = true;
		for (int j = 0; j < m; j++)flag &= used[j];
		if (flag)break;
		ans++;
		point = min;
	}

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

Measured memory_bytes: 1024
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

ABCDE = [a, b, c, d, e]
ABCDE_next = [int(math.ceil(abcde/10)*10) for abcde in ABCDE]

ans = 99999999
for i in range(len(ABCDE)):
    time = sum(ABCDE_next) - ABCDE_next[i] + ABCDE[i]
    ans = min(ans, time)
    
print(ans)

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int n;
    cin>>n;
    vi a(n);
    vl s(n+1);
    rep(i,n){
        cin>>a[i];
        s[i+1]=(s[i]+a[i])%MOD;
    }

    ll ans=0;

    repa(i,1,n){
        ll tmp=(a[i]*s[i])%MOD;
        ans=(ans+tmp)%MOD;
    }

    cout<<ans<<"\n";

    return 0;

}

Measured memory_bytes: 5632
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
using namespace std;
int gcd(int a,int b);
int main(int argc,char** argv){
  int n;
  cin >> n;
  int x[n+1];
  for(int i = 0;i < n+1;i++){
    cin >> x[i];
  }
  int d[n];
  for(int i = 0; i < n; i++){
    d[i] = abs(x[i+1] - x[i]);
  }
  int r = gcd(d[0],d[0]);
  for(int i = 1;i < n; i++){
    r = gcd(r,d[i]);
  }
  cout << r << endl;
  return 0;
}

int gcd(int a,int b){
  int r;
  if(b>a){
    int t = a;
    a = b;
    b = t;
  }
  while((r = a % b) != 0){
    a = b;
    b = r;
  }
  return b;
}


Measured memory_bytes: 1024
def isprime(x):
    if x == 2:
        return True

    if ((x < 2) or
        (x % 2 == 0)):
        return False

    i = 3
    while i ** 2 <= x:
        if x % i == 0:
            return False
    
        i = i + 2
    
    return True


n = int(input())

cnt = 0

for _ in range(n):

    num_input = int(input())

    if isprime(num_input):
        cnt += 1


print(cnt)



Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <vector>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, i, t, s;
    const int rg[4] = { 2,3,4,6 };
    vector<int> ans;

    scanf("%d", &n);

    if (n <= 5) {
        printf("2 5 63");
        if (n >= 4) {
            printf(" 20");
        }
        if (n >= 5) {
            printf(" 30");
        }
        printf("\n");
        return 0;
    }

    t = 0;
    s = 0;
    for (i = 0; i < n; i++) {
        ans.push_back(t / 4 * 6 + rg[t % 4]);
        s += t / 4 * 6 + rg[t % 4];
        t++;
    }

    if (s % 6 == 0) {
        for (i = 0; i < n; i++) {
            printf("%d ", ans[i]);
        }
        printf("\n");
        return 0;
    }

    if (s % 6 == 2) {
        for (i = 0; i < n; i++) {
            if (ans[i] != 8) {
                printf("%d ", ans[i]);
            }
        }
        printf("%d\n", t / 4 * 6 + 6);
        return 0;
    }

    if (s % 6 == 5) {
        for (i = 0; i < n; i++) {
            if (ans[i] != 9) {
                printf("%d ", ans[i]);
            }
        }
        printf("%d\n", t / 4 * 6 + 4);
        return 0;
    }

    if (s % 6 == 3) {
        for (i = 0; i < n; i++) {
            if (ans[i] != 9) {
                printf("%d ", ans[i]);
            }
        }
        printf("%d\n", t / 4 * 6 + 6);
        return 0;
    }

    return 0;
}

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

int main()
{
	int S = 0;
	int s = 0, m = 0, h = 0;
	cin >> S;
	s = S % 60;
	S -= s;
	S /= 60;
	m = S % 60;
	h = S / 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


Measured memory_bytes: 3112
a1 = list(map(lambda x: int(x), input().split()))
a2 = list(map(lambda x: int(x), input().split()))
a3 = list(map(lambda x: int(x), input().split()))
card = [a1, a2, a3]

n = int(input())

number = []
for num in range(0, n):
  b = int(input())
  number.append(b)

def bingo(bingolist):
  x = 0
  for n in bingolist:
    if n in number:
      x += 1
  if x == 3:
    print("Yes")
    exit()

bingo(a1)
bingo(a2)
bingo(a3)
for num in range(0, 3):
	bingo([a1[num], a2[num], a3[num]])

bingo([a1[0], a2[1], a3[2]])
bingo([a1[2], a2[1], a3[0]])
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b, s;
	cin >> a >> b;
	s = 0;

	if (a > b) s += a, a--;
	else s += b, b--;

	if (a > b) s += a, a--;
	else s += b, b--;

	cout << s << "\n";

	return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s = iterator.next().unwrap();
    let t = iterator.next().unwrap();

    return format!("{}{}", t, s);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


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

  list<int> list;
  auto it=list.end();
  int q;
  cin>>q;
  while(q--){
    int t;
    cin>>t;
    if(t==0){
      int x;
      cin>>x;
      it=list.insert(it,x);
    }else if(t==1){
      int x;
      cin>>x;
      rep(i,-x) it--;
      rep(i,x) it++;
    }else{
      it=list.erase(it);
    }
  }

  for(int x:list){
    cout<<x<<endl;
  }




}


Measured memory_bytes: 18660
#include <cstring>
#include <iostream>
#include <algorithm>

#pragma warning(disable : 4996)

#define mod 1000000007

using namespace std;

long long N, D, X, inv[2001]; long long dp[2001][2001];

int ncr(long long n, long long r)
{
	if (n < r) { return 0; }

	long long ret = 1;

	for (int i = 0; i < r; i++)
	{
		ret = n-- % mod * ret % mod;
	}
	
	for (int i = 1; i <= r; i++)
	{
		ret = ret * inv[i] % mod;
	}

	return ret;
}

int main()
{
	inv[1] = 1;

	for (int i = 2; i <= 2000; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
	
	while (true)
	{
		scanf("%lld", &N);
		scanf("%lld", &D);
		scanf("%lld", &X);

		if (N == 0 && D == 0 && X == 0) { break; }

		memset(dp, 0, sizeof(dp));

		dp[0][0] = 1;

		for (int i = 1; i <= N; i++)
		{
			for (int j = i; j <= N; j++)
			{
				if (j < X)
				{
					dp[i][j] = (dp[i][j] + dp[i][j - 1] + dp[i - 1][j - 1]) % mod;
				}
				else
				{
					dp[i][j] = (dp[i][j] + dp[i][j - 1] + dp[i - 1][j - 1] - dp[i - 1][j - X] + mod) % mod;
				}
			}
		}

		long long ret = 0;

		for (int i = 1; i <= N; i++)
		{
			ret = (ret + ncr(D, i) * dp[i][N]) % mod;
		}

		printf("%lld\n", ret);
	}

	return 0;
}

Measured memory_bytes: 34464
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll N, A[101010];
ll fac[101010];
ll MOD = 1e9 + 7;
ll sum[101010];
ll res = 1;

ll modpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

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

	cin >> N;
	for (int i = 1; i <= N; i++)cin >> A[i];
	fac[0] = 1;
	for (int i = 1; i <= N; i++) {
		fac[i] = fac[i-1] * i;
		fac[i] %= MOD;
	}

	sum[1] = 1;
	for (int i = 2; i < 101010; i++) {
		sum[i] = sum[i - 1] + modpow(i,MOD-2);
		sum[i] %= MOD;
	}

	ll ans = 0;
	for (int i = 1; i <= N;i++) {
		ll temp = sum[i] + sum[N - i + 1] - 1 + MOD;
		temp %= MOD;
		temp *= A[i];
		temp %= MOD;
		ans += temp;
		ans %= MOD;
	}
	ans *= fac[N];
	ans %= MOD;
	puts(ans);
	return 0;
}



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

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	int sum = 0;
	for (int i = 0; i < k; i++)
		sum += a[i];
	cout << sum << '\n';
}



Measured memory_bytes: 3668
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
from heapq import heappop,heappush
r=[]
heappush(r,-a[0])
ans=0
for i in range(1,n):
	heappush(r,-a[i])
	heappush(r,-a[i])
	ans-=heappop(r)
print(ans)

Measured memory_bytes: 98772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

int main(){
    double w,h,x,y; cin>>w>>h>>x>>y;
    if(x == w/2 && y == h/2){
        cout << w*h/2.0<< " " << 1 <<endl;
    }
    else cout << w*h/2.0 << " " << 0 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double a[200005]; 
int main(){
	int n,i,j;
	double k,sum=0.0,mx=0.0;
	cin>>n>>k;
	for(i=1;i<k;i++){
		cin>>a[i];
		sum+=a[i];
	}
	for(i=k;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
		sum-=a[(int)(i-k)];
		if(sum>mx) mx=sum;
	}
	cout<<fixed<<setprecision(10)<<(mx+k)/2;
	return 0;
}

Measured memory_bytes: 1792
N,K = map(int,input().split())

#(ex)K=4
#a%4=1,b%4=2はありえない->なぜならc%4=3かつc%4=2となることはないから
#以上よりa%K = b%K = c%K -> 2つ合わせたらKの倍数より
#mod K で(a,b,c) = (K/2,K/2,K,2) or (a,b,c) = (0,0,0)の2パターンのみ
#1 ~ Nのうち
#1: mod K:K/2 となるものがp個 -> 組み合わせ:p*p*p = p^3通り
#2: mod K:0 となるものがq個 -> 組み合わせ:q*q*q = q^3通り
#ans = p^3 + q^3
p,q = 0,0
if(K%2 == 0):
 for i in range(1,N+1):
  if(i%K == K//2): p += 1
  elif(i%K == 0): q += 1
else:
 for i in range(1,N+1):
  if(i%K == 0): q += 1
ans = p**3 + q**3
print(ans)

Measured memory_bytes: 3060
import java.util.*;


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		//入力
		
		String a=sc.next();
		String b=sc.next();



		//計算





		//出力
		if(a.equals("D")){
			if(b.equals("D")) System.out.println("H");
			else System.out.println("D");
		}else{
			if(b.equals("H")) System.out.println("H");
			else System.out.println("D");
		}
		
	}
}


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{ 
  ll N, K;
  cin >> N >> K;
  
  vector<ll> A(N);
  REP(i, N) { 
      cin >> A[i];
  }
  ll point = 1;
  REP(i, K) {
    point *= A[i];
  }
  FOR(i, K, N) {
    if (A[i-K] < A[i]) {
      PRINT("Yes");
    } else {
      PRINT("No");
    }
  }
  return 0;
} 


Measured memory_bytes: 4904
a = -118;
c = 0;
d = 0;
x = int(input());

while a <= 119:
    b = -118
    while b <= 119:
        y = a**5 - b**5;
        if y == x :
            c = a;
            d = b;
        b = b + 1;
    
    a = a + 1;


print(c, d);

Measured memory_bytes: 9116
function main(inputData) {
    var output = [];
    for(var i = 0; i < inputData.length; i++) {
        if(0 != inputData[i]) {
            output.push('Case ' + (i + 1) + ': ' + inputData[i]);
        }
    }
    console.log(output.join('\n'));
  }
  
  process.stdin.resume();
  var input = '';  
  process.stdin.setEncoding('utf-8');
  process.stdin.on('data', function(chunk) {
    input += chunk;
  });
  process.stdin.on('end', function() {
    var inputData = input.split('\n');
    main(inputData);
  });

Measured memory_bytes: 19484
#include<stdio.h>
#include<math.h>
int main() {
	int a,b,op;
	while(1) {
		scanf("%d %c %d",&a,&op,&b);
		if ( op == '+' ) {
			printf("%d\n",a + b);
		} else if ( op == '-' ) {
			printf("%d\n",a - b);
		} else if ( op == '*' ) {
			printf("%d\n",a * b);
		} else if ( op == '/' ) {
			printf("%d\n",a / b);
		} else break;
	}
	return 0;
}

Measured memory_bytes: 1820
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include<ios>
#include <vector>
using namespace std;
using ll = long long;
const ll INF=INT64_MAX>>3;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    ll n;
    string s;
    cin >> n >> s;
    vector<vector<int>> a(n+1,vector<int>(3,0));
    for(int i = n-1; i >= 0; i--) {
        rep(j,3) a[i][j] = a[i+1][j];
        if(s[i] == 'R') a[i][0]++;
        if(s[i] == 'G') a[i][1]++;
        if(s[i] == 'B') a[i][2]++;
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) {
        int k = 2*j-i;
        if(s[i] == s[j]) continue;
        if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
            ans += a[j][2];
            if(k < n) if(s[k] == 'B') ans--;
        }
        if((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
            ans += a[j][1];
            if(k < n) if(s[k] == 'G') ans--;
        }
        if((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')) {
            ans += a[j][0];
            if(k < n) if(s[k] == 'R') ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716