akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static final long MOD = 1_000_000_007;

  public static void main(String[] args) {
    int N = sc.nextInt();
    int M = sc.nextInt();
    long[][][] dp = new long[2][N][N]; // dp[][can return to 1][on current path]
    dp[0][0][0] = 1;
    int t = 1;
    for (int i = 0; i < M; i++) {
      for (long[] a : dp[t]) {
        Arrays.fill(a, 0L);
      }
      for (int j = 0; j < N; j++) {
        for (int k = 0; j + k < N; k++) {
          dp[t][j + k][0] += dp[1 - t][j][k] * (1 + j); // go to city connected to 1
          dp[t][j + k][0] %= MOD;

          dp[t][j][k] += dp[1 - t][j][k] * k; // go to a city on current path
          dp[t][j][k] %= MOD;

          if (k < N - 1) {
            dp[t][j][k + 1] += dp[1 - t][j][k] * (N - 1 - j - k); // go to a city does not have a path to city 1
            dp[t][j][k + 1] %= MOD;
          }
        }
      }
      t = 1 - t;
    }
//      for (int j = 0; j < N; j++) {
//        System.out.println(Arrays.toString(dp[1-t][j]));
//      }
//      System.out.println();
    System.out.println(dp[1 - t][N - 1][0]);
  }
}


Measured memory_bytes: 12164
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut d: Vec<i64> = (0..n).map(|_| input()).collect();
    d.sort();
    d.dedup();
    println!("{}", d.len());
}


Measured memory_bytes: 4352
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,K = LI()
h = np.array(LI())
dp = np.full(N,10**10,dtype=int)
dp[0] = 0
for i in range(1,N):
    dp[i:i+K] = np.fmin(dp[i:i+K],dp[i-1]+np.abs(h[i:i+K]-h[i-1]))
print(dp[-1])


Measured memory_bytes: 22756
program answer
  implicit none

  integer :: X, i, ans
  integer :: b(40)

  read(*,*) X

  if(X==1) then
     write(*,*) 1
     stop
  end if

  b(1)=4
  b(2)=8
  b(3)=16
  b(4)=32
  b(5)=64
  b(6)=128
  b(7)=256
  b(8)=512
  b(9)=9
  b(10)=27
  b(11)=81
  b(12)=243
  b(13)=729
  b(14)=25
  b(15)=125
  b(16)=625
  b(17)=49
  b(18)=343
  b(19)=121
  b(20)=169
  b(21)=289
  b(22)=361
  b(23)=529
  b(24)=841
  b(25)=961
  b(26)=36
  b(27)=216
  b(28)=100
  b(29)=1000
  b(30)=144
  b(31)=196
  b(32)=225
  b(33)=324
  b(34)=400
  b(35)=441
  b(36)=484
  b(37)=576
  b(38)=676
  b(39)=784
  b(40)=900
  

  ans=b(1)
  do i = 2, 40
     if(b(i)>ans.and.b(i)<=X) then
        ans = b(i)
     end if
  end do

  write(*,*) ans

  stop
 end program answer

  


Measured memory_bytes: 2776
from itertools import accumulate
from bisect import bisect_right
def prime_factorize_dict(n):
    d = dict()
    while not n & 1:
        d[2] = d.get(2, 0) + 1
        n >>= 1
    f = 3
    while f * f <= n:
        if not n % f:
            d[f] = d.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = d.get(n, 0) + 1
    return d

N = int(input())
l = list(prime_factorize_dict(N).values())
L = list(accumulate(range(10 ** 6)))
print(sum(bisect_right(L, item) - 1 for item in l))

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

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> r(n, 0);
 
    int pos;
    if (k <= n) {
        pos = 0;
        rep(i, k)
            pos = a[pos] - 1;
    } else {
        int count1 = 0;
        int start;
        pos = 0;
        rep(i, n) {
            if (r[pos] != 0) {
                start = pos;
                break;
            }
            ++count1;
            r[pos] = count1;
            pos = a[pos] - 1;
        }
        int count2 = 0;
        rep(i, n) {
            count2++;
            pos = a[pos] - 1;
            if (pos == start) {
                break;
            }
        }

        int rem = (k - (count1 - count2)) % count2;

        pos = start;
        rep(i , rem) {
            pos = a[pos] - 1;
        }
    }
 
    cout << pos + 1 << endl;
 
    return 0;
}


Measured memory_bytes: 4844
import java.util.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);
		//String word_before = sc.next();
		//int K = sc.nextInt();
		
		int N = sc.nextInt();
		//int arr[] = new int[N];
		if (N%2==1) {
			System.out.println(N/2+1);
		} else {
			System.out.println(N/2);
		}
		
		
      	sc.close();
    }
		
		
}


Measured memory_bytes: 21844
from sys import stdin, stdout, stderr

mod = 10**9 + 7

def solve():
    def binom(n, k):
        res = (modfact[n] * factinv[k]) % mod
        res = (res * factinv[n - k]) % mod
        return res

    h, w, a, b = map(int, input().split())
    ans = 0
    modfact = [1] * (h + w)
    factinv = [1] * (h + w)

    for i in range(1, h + w):
        modfact[i] = (i * modfact[i - 1]) % mod
        factinv[i] = (pow(i, mod - 2, mod) * factinv[i - 1]) % mod

    for i in range(h - a):
        ans += (binom(b + i - 1, i) * binom(w + h - b - i - 2, h - i - 1)) % mod
        ans %= mod

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 42608
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    int a[N];
    rep(i, N) {
        cin >> a[i];
    }

    int ans = -N;
    rep(i, N) {
        ans += a[i];
    }
    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
const ll MAX_N = 3000;
/**/
int main() {
	// 入力
	ll N,K;cin>>N>>K;
	ll A[N];
	REP(i,N)A[i] = 0;
	REP(i,K){
		ll d;cin>>d;
		REP(j,d){
			ll idx;cin>>idx;idx--;
			A[idx]++;
		}
	}
    
	// 解法
	ll ans = 0;
	REP(i,N){
		if (A[i]==0)ans++;
	}
	
	//出力
	printf("%lld\n", ans);
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define INF 1e15
#define MOD 1e9+7
int n, x[1111], y[1111];
char c[1111][1111];
bool flag, check[1111];
signed main() {
	cin >> n;
	int ans = INF;
	int cnt = 0;
	rep(i, n) {
		rep(j, n) {
			cin >> c[i][j];
			if (c[i][j] == '#')flag = 1;
			else if (!check[j])check[j] = 1, cnt++;
		}
	}
	if (!flag) {
		puts("-1");
		return 0;
	}
	rep(i, n) {
		bool b = 0;
		rep(j, n)if (c[j][i] == '#')b = 1;
		int memo = 0;
		rep(j, n)if (c[i][j] == '.')memo++;
		if (!b)memo++;
		ans = min(ans, memo);
	}
	cout << ans + cnt << endl;
	return 0;
}


Measured memory_bytes: 768
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }


int main(){
    int N;
    cin>>N;
    vector<ll> a;
    ll a_;
    rep(i, N){
        cin>>a_;
        a.push_back(a_);

    }
    vector<ll> b;
    rep(i, N){
        cin>>a_;
        b.push_back(a_);

    }
    int s=0;
    rep(i, N){
        if(a[i]>b[i]){
            s+=a[i]-b[i];
        }
    }
    cout<<s<<endl;

    return 0;

}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.string;

T binarySearch(T)(T[] haystack, T needle) {
  auto min = 0UL;
  auto max = haystack.length - 1;

  while (min <= max) {
    auto mid = (min + max) / 2;
    if (haystack[mid] == needle) {
      return needle;
    } else if (haystack[mid] < needle) {
      min = mid + 1;
    } else {
      max = mid - 1;
    }
  }
  return -1;
}

void main() {
  auto n = readln.chomp.to!int;
  auto s = readln.chomp.split.map!(to!int).array;
  auto q = readln.chomp.to!int;
  auto t = readln.chomp.split.map!(to!int).array;

  auto c = 0;

  foreach (e_t; t) {
    if (binarySearch(s, e_t) == e_t) {
      c++;
    }
  }

  c.writeln;
}

Measured memory_bytes: 6676
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  ll r,d,x;
  cin>>r>>d>>x;
  for(int i=1;i<=10;i++){
    x=r*x-d;
    cout<<x<<endl;
  }
}


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

const int N=2e5+5;


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int p[n];
        for(int i=0;i<n;i++)
        {
            cin>>p[i];
        }
        sort(p,p+n);
        int s=0;
        for(int i=0;i<k;i++)
        {
            s+=p[i];
        }
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long int C[51][51]; // C[n][k] -> nCk

void combTable(int N) {
  for(int i = 0; i <= N; ++i) {
    for(int j = 0; j <= i; ++j) {
      if(j == 0 || j == i) C[i][j] = 1LL;
      else C[i][j] = (C[i-1][j-1] + C[i-1][j]);
    }
  }
}

int main() {
  int N, A, B; cin >> N >> A >> B;
  vector<long long int> v(N);
  long long int ans = 0LL;
  for(int i = 0; i < N; ++i) {
    cin >> v[i];
  }
  combTable(N);
  sort(v.begin(), v.end()); reverse(v.begin(), v.end());

  double maxAve = 0.0;
  for(int i = 0; i < A; ++i) {
    maxAve += v[i];
  }
  maxAve /= A;

  int AthValNum = 0, AthValPos = 0;
  for(int i = 0; i <N; ++i) {
    if(v[i] == v[A-1]) {
      AthValNum++;
      if(i < A) {
        AthValPos++;
      }
    }
  }
  long long cnt = 0LL;
  if(AthValPos == A) {
    for(AthValPos = A; AthValPos <= B; ++AthValPos) {
      cnt += C[AthValNum][AthValPos];
    }
  } else {
    cnt += C[AthValNum][AthValPos];
  }
  cout.precision(10);
  cout << fixed << maxAve << endl;
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
# a〜z
l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

s=list(input())
K=int(input())

l2=[]

a=''
for x in l:
  if x in s:
    a=x
    for i in range(len(s)):
      if s[i]==a:
        for j in range(6):
          l2.append(''.join(s[i:i+j]))

l2=list(set(l2))
l2.remove('')
l2.sort()
print(l2[K-1])


Measured memory_bytes: 5084
n, k = map(int, input().split())
r, s, p = map(int, input().split())
points = {'r': p, 's': r, 'p': s}
t = input()
ans = 0
for i in range(k):
  f = t[i::k]
  ans += points[f[0]]
  cnt = 1
  for j in range(1, len(f)):
    if f[j] != f[j-1]:
      ans += points[f[j]]
      cnt = 1
    else:
      cnt += 1
      if cnt % 2 == 1:
        ans += points[f[j]]
print(ans)

Measured memory_bytes: 3316
import numpy as np

n,c=map(int,input().split())
x0=[]
v0=[0]
for _ in range(n):
	i,j=map(int,input().split())
	x0.append(i)
	v0.append(j+v0[_])
x=np.array([0]+x0)
y=np.full_like(x,c)-np.array(x0+[c])
v=np.array(v0)
w=np.full_like(v,v[n])-v

s=v-x
t=w-y
k=x.searchsorted(-((-c)//2))
a0=[np.max(t[k-1:])]
for i in range(k-1)[::-1]:
	a0.append(max(a0[-1],t[i]))
b0=[np.max(s[:k])]
for i in range(k,n+1):
	b0.append(max(b0[-1],s[i]))
print(max(np.max(s[:k]-x[:k]+np.array(a0)[::-1]),
	np.max(t[k-1:]-y[k-1:]+np.array(b0))))


Measured memory_bytes: 30676
import math

def main():
  n = int(input())
  cities = []
  for i in range(0, n):
    inputs = input().split(" ")
    cities.append([int(inputs[0]), int(inputs[1])])
  
  result = 0
  for i in range(0, n-1):
    for j in range(i+1, n):
      result += distance(cities[i], cities[j])
  
  print(result*factorial(n-1)*2/factorial(n))

def factorial(n):
  if n <= 0:
    return 0
  if n == 1:
    return 1
  else:
    return factorial(n-1) * n

def distance(pos1, pos2):
  return math.sqrt(math.pow(pos1[0] - pos2[0], 2) + math.pow(pos1[1] - pos2[1], 2))

main()


Measured memory_bytes: 3064
function Main(input){
var K = input.trim();
K =parseInt(K,10);
var a,b;
if(K%2==1){
  a = Math.floor(K/2);
  b = K - a;
  console.log(a*b);
}else{
  console.log((K*K)/4);
}
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));



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

#define ED return 0;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) long(pow(x,y))
const long long int mod = 1000000007;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    vector<int> vec (N);
    for(int i = 0;i < N;i++){
        int dummy;
        cin >> dummy;
        vec.at(i) = abs(X - dummy);
    }
    int g = vec.at(0);
    for(int i = 1;i < N;i++){
        g = gcd(g,vec.at(i));
    }
    cout << g << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
using namespace std;
#define int long long
#define fr(i,n) for (int i = 0; i < n; i++)
#define fro(i,m,n) for (int i = m; i < n; i++)
#define pb push_back
#define iter ::iterator
#define fi first
#define se second


void io(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
}

void solve(){
  //io();
  int n,k;
  cin>>n>>k;
  int a[n];
  fr(i,n){
    cin>>a[i];
  }
  int dp[n+1]={0};
  int mi;
  //std::cout << k << '\n';
  fro(i,1,n){
    mi=INT_MAX;
    for(int j=1;j<=k&&((i-j)>=0);j++){
      mi=min(mi,dp[i-j]+abs(a[i]-a[i-j]));
      //std::cout <<j << '\n';
    }
    dp[i]=mi;
  }
  std::cout << dp[n-1] << '\n';
}



int32_t main(){
  std::ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 5132
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int a[300000], b[300000];
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		a[p] = i;
	}
	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] < a[i + 1])b[i] = b[i - 1] + 1;
		ans = max(ans, b[i]);
	}
	cout << n - ans - 1 << endl;
}

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

using namespace std;

int whtcnt,blkcnt,blk,lasti,lastj;
char G[105][105];

struct point{int x,y;}p[505];

inline void add(int x,int y){
	for(int i=-1;i<=1;++i){
		for(int j=-1;j<=1;++j)
			G[x+i][y+j]='#';
	}
	G[x][y]='.';
}

inline void build(int cnt){
	for(int i=3;i<=98;i+=4){
		for(int j=3;j<=98;j+=4){
			p[++blk]=(point){i,j};
			add(i,j);
			if(--cnt==0){
				lasti=i,lastj=j;
				return;
			}
		}
	}
}

inline void deal_more(){
	int dta=blkcnt+1-whtcnt;
	if(dta>0){
		for(int i=1;i<=dta;++i)
			G[p[i].x][p[i].y]='#';
	}
	else if(dta<0){
		lasti+=4,lastj+=4;
		int tmp=0;
		for(int j=lastj;j<=98;j+=4){
			p[++blk]=(point){lasti-4,j};
			add(lasti-4,j);
			++tmp;
			if(++dta==0){
				break;
			}
		}
		if(dta<0){
			for(int i=lasti;i<=98;i+=4){
				for(int j=3;j<=98;j+=4){
					p[++blk]=(point){i,j};
					add(i,j);
					++tmp;
					if(++dta==0){
						goto nex;
					}
				}
			}
			nex:;
		}
		for(int i=3;i<=95;i+=4){
			for(int j=3;j<95;j+=4){
				G[i][j+2]='#';
				if(--tmp==0) return;
			}
			G[i+2][3]='#';
			if(--tmp==0) return;
		}
	}
}

inline void rev(){
	for(int i=1;i<=100;++i){
		for(int j=1;j<=100;++j){
			if(G[i][j]=='#') G[i][j]='.';
			else G[i][j]='#';
		}
	}
}

int main(){
	for(int i=1;i<=100;++i){
		for(int j=1;j<=100;++j)
			G[i][j]='.';
	}
	scanf("%d%d",&whtcnt,&blkcnt);
	bool flag=false;
	if(whtcnt<blkcnt) swap(whtcnt,blkcnt),flag=true;
	build(blkcnt);
	deal_more();
	if(flag) rev();
	puts("100 100");
	for(int i=1;i<=100;++i){
		for(int j=1;j<=100;++j)
			putchar(G[i][j]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    string S;
    cin>>S;
    string c=S.substr(5,2);
    int a=stoi(c);
    if(a<=4)cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

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

    vector<ll> T(N);
    rep(i, N) cin >> T[i];

    ll lcm = 1;
    rep(i, N) {
        lcm = lcm / __gcd(lcm, T[i]) * T[i];
        // cout << i << ": " << lcm << endl;
    }

    cout << lcm << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

long long f(long long b, long long n) {
    long long ans = 0;

    while (n) {
        ans += n % b;
        n /= b;
    }

    return ans;
}

int main() {
    long long n, s;

    cin >> n >> s;

    if (n == s) {
        cout << n+1 << endl;
        return 0;
    }

    if (n > s) {
        for (long long i = 2; i <= sqrt(n); i++) {
            if (f(i, n) == s) {
                cout << i << endl;
                return 0;
            }
        }

        for (long long i = sqrt(n); i > 0; i--) {
            if ((n-s+i) % i == 0 && s-i < (n-s+i) / i 
                && s-i >= 0 && (n-s+i) / i > sqrt(n)) {
                cout << (n-s+i) / i << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int a[n+1][3];
	for(int i=0;i<=n;i++)
	{
		a[i][0]=0;a[i][1]=0;a[i][2]=0;
	}
	for(int i=n-1;i>=0;i--)
	{
		if(s[i]=='R')
			a[i][0]=a[i+1][0]+1,a[i][1]=a[i+1][1],a[i][2]=a[i+1][2]; 
		else if(s[i]=='G')
			a[i][1]=a[i+1][1]+1,a[i][2]=a[i+1][2],a[i][0]=a[i+1][0];
		else
			a[i][2]=a[i+1][2]+1,a[i][1]=a[i+1][1],a[i][0]=a[i+1][0];
	}
	ll sum=0;
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			if(s[i]!=s[j])
			{
				if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))
				{
					sum+=a[j+1][2];
					if(s[j+j-i]=='B')sum--;
				}
				else if((s[i]=='R'&&s[j]=='B')||(s[j]=='R'&&s[i]=='B'))
				{
					sum+=a[j+1][1];
					if(s[j+j-i]=='G')sum--;
				}
				else{
					sum+=a[j+1][0];
					if(s[j+j-i]=='R')sum--;	
				}
			}
		}
	}
	cout<<sum;
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 3700
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#include<iomanip>

#define LLI long long int

using namespace std;

int main(){
	string S,T;cin>>S>>T;
	int ans=0;
	for(int i=0;i<3;i++)if(S[i]==T[i])ans++;
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//setprecision(15)有効数字15桁
//-std=c++14
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; }
int n, m;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> n>>r;
    if(n>=10){
        cout<<r<<"\n";
    }
    else{
        cout<<r+100*(10-n)<<"\n";
    }
    
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
#define ll long long int
#define f(i, n) for (ll i = 0; i < n; i++)
#define ff(i, n) for (ll i = 1; i <= n; i++)




//ll dp[2003][2003];vector<ll>w,v;

ll dp[101][100001];vector<ll>w,v;


int main() {

    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

    ll n,we;cin>>n>>we;ll t=0;

    f(i,n)
    {
        ll x,y;cin>>x>>y;
        w.push_back(x);
        v.push_back(y);
        t+=y;
    }
   // cout<<t<<" ";
    f(i,v.size()+1) {
        f(j, t+1) {
dp[i][j]=INT_MAX;
        }
    }
    dp[1][v[0]]=w[0];
    for(ll i=2;i<=v.size();i++)
    {
        ff(j,t)
        {
            ll p=0;
           //   cout<<v[i]<<" ";
            if(v[i-1]<j)
                dp[i][j]=min(dp[i-1][j],w[i-1]+dp[i-1][j-v[i-1]]);
            else if(v[i-1]==j)
                dp[i][j]=min(dp[i-1][j],w[i-1]);
                else
                    
                dp[i][j]=dp[i-1][j];
//cout<<dp[i][j]<<" ";
        }
//cout<<"\n";
    }
    ll ans=0;
   for(ll i=t;i>=0;i-- )
   {
       ff(j,v.size())
       {
           if(dp[j][i]<=we)
           {
               ans=i;
               goto p;
           }

       }

   }
   p:
    cout<<ans;
return 0;
}


Measured memory_bytes: 79232
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF=100000001,ID_MAX=20;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}

const int N=50;
char s[N],t[N],m[N+1],x[N+1];


int main(){
    int i;
    memset(m,'z',sizeof(m));
    
    //入力
    cin>>s;
    cin>>t;
    //処理
    int s_l=strlen(s),t_l=strlen(t);
    bool tof=true;
    rep(i,s_l-t_l+1){
        memset(x,0,sizeof(x));
        tof=true;
        rep(j,s_l){
            if(i<=j&&j<=i+t_l-1){
                if(s[j]!='?'&&s[j]!=t[j-i]){
                    tof=false;
                    break;
                }
                if(s[j]=='?'){
                    x[j]=t[j-i];
                }else{
                    x[j]=s[j];
                }
            }else{
                if(s[j]=='?')x[j]='a';
                else x[j]=s[j];
            }
        }
        if(tof){
            if(strcmp(x,m)<0)strcpy(m,x);
        }
    }
    //出力
    memset(x,'z',sizeof(x));
    if(strcmp(x,m))cout<<m<<endl;
    else cout<<"UNRESTORABLE"<<endl;
}


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

using namespace std;


template <class T>
std::istream& operator>>(std::istream& in, std::vector<T>& data) {
    for (auto& item : data) {
        in >> item;
    }
    return in;
}

template <class T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& data) {
    bool first = true;
    for (const auto& item : data) {
        if (!first) {
            out << " ";
        }
        out << item;
        first = false;
    }
    return out;
}


int main() {
#ifdef LOCAL
    freopen("atcoder/2/input.txt", "r", stdin);
#endif

    int a, b, k;

    cin >> a >> b;

    if ((a + b) % 2 == 1) {
        cout << "IMPOSSIBLE" << "\n";
    } else {
        cout << (a + b) / 2 << "\n";
    }



    return 0;
}











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

int main() {
  int N;
  cin >> N;
  int a[110];
  
  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }
  
  sort(a, a + N);
  
  cout << a[N-1] - a[0] << endl;
}

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

int main()
{
  cin>>N;

  vector<ll> v;
  for(int i=0; i<=N; i++){
    if(i==0)  v.push_back(2);
    else if(i==1)  v.push_back(1);
    else{
      ll num = v[i-1] + v[i-2];
      v.push_back(num);
    }
  }
  cout<<v[N]<<endl;
}


Measured memory_bytes: 256
// cout << "Case #" << k << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
vector<ll> divisor(ll n) {
    vector<ll> ret;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}
int main() {
    ll n;
    cin >> n;
    if(n == 2) {
        cout << 1 << endl;
        return 0;
    }
    ll ans = 0;
    auto res = divisor(n - 1);
    ans += res.size() - 1;
    res = divisor(n);
    for(auto e : res) {
        if(e == 1) {
            continue;
        }
        ll a = 1;
        while(n % (a * e) == 0) {
            a *= e;
            if(a * e == 0) {
                break;
            }
        }
        ll m = n / a;
        if(m % e == 1) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

for i in range(N-1):
    A[i+1] += A[i]

for i in range(N-1)[::-1]:
    B[i] += B[i+1]

ans = 0
for i in range(N):
    ans = max(ans, A[i]+B[i])

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
int n;
double x[10], y[10];
double ans = 0;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", x + i, y + i);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ans += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		}
	}
	ans *= 2;
	ans /= n;
	printf("%lf\n", ans);
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}

vector<int> buf;
vector<int> tmp = {100, 101, 102, 103, 104, 105};

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

  // DPで解く
  int dp[X + 1000];
  dp[0] = 1;
  dp[1] = 0;
  int a[6] = {100, 101, 102, 103, 104, 105};

  for(int i = 0; i < 6; ++i) {
    for(int k = 0; k < X; ++k) {
      if(dp[k] == 1) dp[k + a[i]] = 1;
    }
  }

  cout << dp[X] << endl;
}

Measured memory_bytes: 640
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	
	ll  a , b , c ;
	cin>> a>> b >> c ;
	ll a1=4*a*b ;
	// cerr<<a1<<endl;
	ll b1 = (c-a-b)*(c-a-b);
	if(a1<b1 && (c-a-b)>0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long int
#define int long long
#define f(i,l,n) for(int i=l;i<n;i++) 
#define E "\n"

#define pi 3.141592653589793
int solve()
{
	int a,b,h,m;
	cin >> a >> b >> h >> m;

	ld an1=h*30;
	an1+=m/2.0;
	ld an2=m*6;

	ld an=abs(an1-an2);
	an=(an*pi)/180.0;


	ld ans=a*a+b*b-2*a*b*cos(an);
	ans=sqrt(ans);
	cout<<fixed<<setprecision(24)<<ans<<E;
	
	return 0;	
}


int32_t main()
{
     int t = 1;
    // cin >> t;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<ll, ll> pint;
#define mp make_pair

int main() {
    ll n;
    cin >> n;
    vector<pint> people(n);
    for (ll i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        people[i] = mp(x, i);
    }
    sort(people.rbegin(), people.rend());
    priority_queue<ll> pq;
    pq.push(people.front().first);
    ll ans = 0;
    for (ll i = 0; i < n - 1; ++i) {
        ans += pq.top();
        pq.pop();
        pq.push(people[i + 1].first);
        pq.push(people[i + 1].first);
    }
    cout << ans << endl;
}


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

 int N, A, B,x;

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

   if (A*N < B) {
    x = A*N; 
    cout << x << endl;
   }

   else if (A*N >= B) cout << B << endl; 
  
 return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  string S; cin >> S;
  int ans = 0;
  rep(i, 4){
    if(S.at(i) == '+'){
      ans++;
    } else if(S.at(i) == '-'){
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include <climits>
#include<string>
#include <vector>
using namespace std;

string LCS(string s1, string s2, int l1, int l2){
	int dp[l1+1][l2+1];

	for(int i = 0; i <= l1; i++){
		for(int j = 0; j <= l2; j++){
			if(i == 0 || j == 0){
				dp[i][j] = 0;
			}else if(s1[i-1] == s2[j-1]){
				dp[i][j] = 1 + dp[i-1][j-1];
			}else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	string ans = "";
	int x = l1, y = l2;
	while(x > 0 && y > 0){
		if(s1[x-1] == s2[y-1]){
			ans += s1[x-1];
			x--;
			y--;
		}else if(dp[x-1][y] > dp[x][y-1]){
			x--;
		}else{
			y--;
		}
	}
	int start = 0;
	int end = ans.length()-1;
	while(start <= end){
		swap(ans[start++], ans[end--]);
	}

	return ans;
}

int main(){



	string s1, s2;
	getline(cin, s1);
	getline(cin, s2);

	cout<<LCS(s1, s2, s1.length(), s2.length())<<'\n';

	return 0;
}

Measured memory_bytes: 38136
#include <cstdio>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

#define rep(i,a,n) for(int (i)=a;(i)<(int)(n);(i)++)
#define rrep(i,a,n) for(int (i)=(n)-1;(i)>=a;(i)--)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

const int INF = 1e9;

int main() {
	int n;
	cin >> n;
	int a[n];
	rep(i,0,n) cin >> a[i];
	reverse(a, a + n);

	rep(i,0,n) {
		if (i>0) cout << " ";
		cout << a[i];
	}
	cout << endl;
}

Measured memory_bytes: 3060
//#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define DEBUG(...)
#else
template <typename T>
void _debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void _debug(T value, Ts... args) {
  std::cerr << value << ", ";
  _debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    _debug(__VA_ARGS__);               \
    cerr << endl;                      \
  } while (0)
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<i64> A(N);
  vector<pair<i64, int>> S(N);
  i64 total = 0;
  REP(i, N) {
    cin >> A[i];
    S[i] = {A[i], -i};
    total += A[i];
  }
  DEBUG(total);
  sort(S.rbegin(), S.rend());
  vector<i64> ans(N);
  int pos = 0;
  i64 remaining = total;
  i64 prev_level = 0;
  while (remaining > 0) {
    DEBUG(pos, N - 1 - pos, remaining);
    int ix = -S[pos].second;
    if (ix == 0) {
      ans[ix] += remaining;
      remaining = 0;
      break;
    }
    int sm_pos = pos + 1;
    while (sm_pos < N && -S[sm_pos].second > ix) {
      sm_pos++;
    }
    assert(sm_pos != N);
    DEBUG(val, ix, sm_pos);
    i64 next_val = S[sm_pos].first;
    if (prev_level > next_val) {
      i64 d = (prev_level - next_val) * pos;
      ans[ix] += d;
      remaining -= d;
    }
    for (int i = pos; i < sm_pos; ++i) {
      i64 d = S[i].first - next_val;
      ans[ix] += d;
      remaining -= d;
      prev_level = next_val;
    }
    pos = sm_pos;
  }
  for (int x = 0; x < N; ++x) {
    cout << ans[x] << '\n';
  }
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

long f[2000001];
void pre(long n) {
  f[0] = 1;
  for (int i = 0; i < n; ++i) {
    f[i + 1] = f[i] * (i + 1) % mod;
  }
}

long pmod(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return b * pmod(b, e - 1) % mod;
  long t = pmod(b, e / 2);
  return t * t % mod;
}

long inv(long n) {
  return pmod(n, mod - 2);
}

long comb(long n, long r) {
  return f[n] * inv(f[r] * f[n - r] % mod) % mod;
}

int main() {
  int k;
  string s;
  cin >> k >> s;
  long n = s.size();
  pre(n + k);
  
  long sum = 0;
  long base = 1;
  for (int i = 0; i <= k; ++i) {
    long res = comb(n + k, i) % mod * base % mod;
    sum = (sum + res) % mod;
    base = base * 25 % mod;
  }
  cout << sum << endl;
}

Measured memory_bytes: 20092
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#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(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#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 bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

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>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    string S; cin >> S;
    map<char, int> m;
    REP(i, 4){
        m[S[i]] += 1;
    }
    vec v;
    for(auto p: m) v.pb(p.s);
    Ans(SZ(v) == 2 && v[0] == 2 && v[1] == 2, "Yes", "No");

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut a = read_vec::<i64>();
    // a.sort();
    let mut opes = vec![];
    for i in 0..m {
        let v = read_vec::<i64>();
        let (b, c) = (v[0] as usize, v[1]);
        opes.push((c, b));
    }
    opes.sort();
    opes.reverse();

    let mut alts = vec![];

    for (c, b) in opes {
        for _ in 0..b {
            if alts.len() == n {
                break;
            }
            alts.push(c);
        }
    }
    // debug!(alts);
    a.extend(alts);
    a.sort();
    a.reverse();
    let ans = a.iter().take(n).sum::<i64>();
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 5816
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()

int main() {
  int h, a;
  cin >> h >> a;
  cout << (h + a - 1) / a << endl;
}


Measured memory_bytes: 256
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
long long int arr[200200];
bool desc(long long int a, long long int b)
{
    return abs(a) < abs(b);
}
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m,inc=1;
    cin >> n;
    int neg = 0;
    long long int rose = 0;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&arr[i]);
        rose += abs(arr[i]);
        neg += (arr[i] < 0);
    }
    sort(arr+1,arr+n+1,desc);
    if(neg % 2 == 1)
    {
        rose -= 2*abs(arr[1]);
    }
    printf("%lld\n",rose);
    return 0;
}


Measured memory_bytes: 1024
d = {}
max_value = 1
n = int(input())
for i in range(n):
    t = input()
    if t in d.keys():
        d[t] += 1
        if d[t] > max_value:
            max_value = d[t]
    else:
        d.setdefault(t, 1)
#print(f"d = {d}")
#print(f"max_value = {max_value}")
#print(f"d.keys() = {d.keys()}")
#print(f"d.values() = {d.values()}")
d = sorted(d.items())
#print(d)
for k, v in d:
    if v == max_value:
        print(k)



Measured memory_bytes: 42332
#include<iostream>
#include<iomanip>
#include<cmath>
#include<math.h>
using namespace std;

long double A, B, X;

long double solve(){
    long double sinTheta;
    if(X < A*A*B/2.0){ //水の体積がボトルの体積の半分より小さい.
        long double x = 2.0*X/A/B;
        sinTheta = B / sqrt(x*x + B*B);
    }
    else{
        long double x = 2.0*B - 2.0*X/A/A;
        sinTheta = x / sqrt(A*A + x*x);
    }
    return min(abs(asin(sinTheta))*(180.0/M_PI), 180.0 - abs(asin(sinTheta))*(180.0/M_PI));
}

int main(){
    cin >> A >> B >> X;
    cout << std::setprecision(16) << solve() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	ll n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	
	ll Min = min({ a,b,c,d,e });
	ll ans = ((n + Min - 1) / Min) + 4;//切り上げ
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
from heapq import heappop, heappush

X,Y,Z,K = map(int, input().split())
xs = [int(x) for x in input().split()]
ys = [int(y) for y in input().split()]
zs = [int(z) for z in input().split()]
xs.sort()
xs.reverse()
ys.sort()
ys.reverse()
zs.sort()
zs.reverse()

# print(xs)

def bfs(max = 3000):
    count = 0
    pq = []
    checked = {}

    heappush(pq, (-(xs[0]+ys[0]+zs[0]), (0,0,0)))
    checked[(0,0,0)] = 1
    while count < max:
        value, (x, y, z) = heappop(pq)
        print(-value)
        count += 1
        if x+1 < X and not (x+1, y, z) in checked:
            checked[(x+1, y, z)] = 1
            heappush(pq, (-(xs[x+1]+ys[y]+zs[z]), (x+1, y, z)))
        if y+1 < Y and not (x, y+1, z) in checked:
            checked[(x, y+1, z)] = 1
            heappush(pq, (-(xs[x]+ys[y+1]+zs[z]), (x, y+1, z)))
        if z+1 < Z and not (x, y, z+1) in checked:
            checked[(x, y, z+1)] = 1
            heappush(pq, (-(xs[x]+ys[y]+zs[z+1]), (x, y, z+1)))

bfs(K)


Measured memory_bytes: 5032
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
char s[maxn];

int main(){
    int ans = 1,n;

    cin >> n ;
    scanf("%s" , s + 1);
    char lst = s[1];

    for(int i =2 ;i <= n; i++){
        if(s[i] != lst){
            lst = s[i];
            ans ++;
        }
    }
    cout << ans << endl;
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

int const N = 300, md = 998244353;
int n, m, p2[N + 1];
vector<bitset<N> > g;

void ad(bitset<N> v){
	int j = 0;
	f(i, 0, g.size()){
		if (v.none())return;
		while (!v[j] && !g[i][j])++j;
		if (g[i][j] && v[j])v ^= g[i];
		else if (v[j]){
			g.insert(g.begin() + i, v);
			return;
		}
	}
	if (v.any())g.push_back(v);
}

int main(){
	p2[0] = 1;
	f(i, 1, N + 1)p2[i] = (ll)p2[i - 1] * 2 % md;
	scanf("%d%d", &n, &m);
	f(i, 0, n){
		bitset<N> v;
		f(j, 0, m){
			int t;
			scanf("%d", &t);
			if (t)v[j] = true;
		}
		ad(v);
	}
	int an = p2[n] - p2[n - g.size()] + md;
	an = (ll)an * p2[m - 1] % md;
	printf("%d\n", an);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;
const long double E = 0.00000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int q = 0; q < n; q++){
        cin >> a[q];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int q = 0; q < k; q++){
        ans += a[q];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end()) //vector
int n,k,arr[100005],dp[100005],minn;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>arr[i];
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        minn=INT_MAX;
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0) minn=min(minn,abs(arr[i]-arr[i-j])+dp[i-j]);
        }
        dp[i]+=minn;
    }
    // for(int i=0;i<n;i++) cout<<dp[i]<<" ";
    // cout<<endl;
    cout<<dp[n-1]<<endl; 
}

Measured memory_bytes: 1024
n = int(input().strip())
a = [int(a) for a in input().strip().split()]
a.sort()

cnt = 0
for x in a:
    if x > 0:
        break
    cnt += 1

if cnt % 2 == 0:
    print(sum(abs(x) for x in a))
else:
    y = [abs(x) for x in a]
    y.sort()
    print(sum(y[1:]) - y[0])


Measured memory_bytes: 14260
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
struct Edge { LL to, cost; };
LL h, w, n, m, s[100000], t, k, p, q, ans = 0, a, b, c, d[100001];
int main() {
	cin >> n >> m;
	cout << (n %m == 0 ? -1 : n) << endl;
	return 0;
}


Measured memory_bytes: 768
import itertools
import copy
H, W, K = map(int, input().split())

c = []
for i in range(H):
    c.append(input())
a = []
for i in c:
    b = []
    for j in i:
        if j == '#':
            b.append(1)
        else:
            b.append(0)
    a.append(b)

col = []
r = list(range(H))
for i in range(H+1):
    col += itertools.combinations(r, i)

row = []
r = list(range(W))
for i in range(W+1):
    row += itertools.combinations(r, i)

ans = 0
for i in col:
    for j in row:
        tar = copy.deepcopy(a)
        for k in i:
            tar[k] = [0] * W
        for k in j:
            for t in tar:
                t[k] = 0
        n = 0
        for t in tar:
            for k in t:
                n += k
        if n == K:
            ans += 1

print(ans)

Measured memory_bytes: 9360