akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<String> ans = new ArrayList<String>();
		Map <String, Integer> hm = new HashMap<String,Integer>();
		
		int n = Integer.parseInt(sc.next());
		
		for(int i = 0; i < n ;i++) {
			String s = sc.next();
			if(!hm.containsKey(s)) {
				hm.put(s, 1);
			}
			else {
				hm.put(s,hm.get(s)+1);
			}
		}
		
		int max = 0; 
		for(String s : hm.keySet()) {
			max = Math.max(max,hm.get(s));
		}
		int num = 0;
		for(String s : hm.keySet()) {
			if(max == hm.get(s)) {
				ans.add(s);
				num++;
			}
		}
		Collections.sort(ans);
		
		for(int i = 0 ;i < num ;i++) {
			System.out.println(ans.get(i));
		}
	}
}


Measured memory_bytes: 88928
if __name__ == '__main__':
	n = int(input())
	x = [int(x) for x in input().split(' ')]

	sx = sorted(x)
	med = sx[int(n/2)]
	medl = sx[int(n/2-1)]

	for i in range(n):
		if x[i] < med:
			print(med)
		else:
			print(medl)

Measured memory_bytes: 25556
import sys
import math

x,y,t = 0,0,0

for s in sys.stdin:
    a,b = map(int,s.split(','))
    if a==0 and b==0:
        break
    x += a*math.sin(math.radians(t))
    y += a*math.cos(math.radians(t))
    t += b

print(int(x))
print(int(y))


Measured memory_bytes: 5716
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>

using namespace std;
struct Point{
	int layer;
	int64_t pos;
};
bool operator<(const Point& a,const Point& b){
	if(a.pos==b.pos){
		return a.layer<b.layer;
	}else{
		return a.pos>b.pos;
	}
}
int main() {
	int64_t n;
	cin>>n;
	vector<Point> ptr;
	ptr.reserve(3*n);
	for(int64_t i1=0;i1<n;i1++){
		int64_t temp;
		cin>>temp;
		ptr.push_back(Point{0,temp});
	}
	for(int64_t i1=0;i1<n;i1++){
		int64_t temp;
		cin>>temp;
		ptr.push_back(Point{1,temp});
	}
	for(int64_t i1=0;i1<n;i1++){
		int64_t temp;
		cin>>temp;
		ptr.push_back(Point{2,temp});
	}
	sort(ptr.begin(),ptr.end());
	int64_t ans[3];
	for(int i1=0;i1<3;i1++){
		ans[i1]=0;
	}
	for(auto i1=ptr.begin();i1!=ptr.end();i1++){
		switch(i1->layer){
		case 0:
			ans[0]+=ans[1];
			break;
		case 1:
			ans[1]+=ans[2];
			break;
		case 2:
			++ans[2];
		}
	}
	cout<<ans[0]<<endl;

}

Measured memory_bytes: 4992
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
temp = []
for i in h:
    temp.append(t - i*0.006)
m = float('inf')
ans = 0
for i,j in enumerate(temp):
    if m > abs(j-a):
        m = abs(j-a)
        ans = i
print(ans+1)


Measured memory_bytes: 3060
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n ;
   cin >> n ;
   int h[n] ;
   for(int i=0;i<n;i++) cin >> h[i] ;
  
   bool ans = 1 ;
   for(int i=0;i<n-1;i++)
   {
    if(h[i]<=h[i+1]) continue;
    else if(h[i]==(h[i+1]+1)){
     h[i+1]+= 1;
     continue;
    }
    else ans = 0 ;
   }
    if(ans)
     cout << "Yes" << endl;
    else
     cout << "No" << endl;
      
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s;

int main(){
	cin>>s;
	int t=0;
	for(int i=0;i<4;i++) t+=(s[i]=='+'?1:-1);
	cout<<t<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

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

int main(){
    ll n;
    ll m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> sum(n+1);
    sum[0] = 0;
    map<ll, ll> mp;
    rep(i, n) {
        sum[i+1] = (sum[i]+a[i]) % m;
    }
    ll ans = 0;
    rep(i, sum.size()) {
        ans += mp[sum[i]];
        ++mp[sum[i]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
//087B
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<=n; i++)
using namespace std;
int main(void){
    int A,B,C,X;
    cin >> A >> B >> C;
    cin >> X;
    int cnt=0;
    rep(i, A){
        rep(j, B){
            rep(k, C){
                if(500*i + 100*j + 50*k==X) cnt+=1;;
            }
        }
    }
    cout << cnt << endl;
}

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


int main(){
	int n;
	cin >> n;
	vector <double> x(n);
	vector <double> y(n);
	for(int i=0;i<n;i++) cin >> x[i];
	for(int i=0;i<n;i++) cin >> y[i];
	double one=0, two=0, three=0, inf=0;
	for(int i=0;i<n;i++){
		one += abs(x[i]-y[i]);
		two += pow((x[i]-y[i]), 2);
		three += pow(abs(x[i]-y[i]), 3);
		if(abs(x[i]-y[i])>inf) inf = abs(x[i]-y[i]);
	}
	two = sqrt(two); three = pow(three, 1.0/3);
	cout << fixed << setprecision(12) << one << endl << two << endl << three << endl << inf << endl;
	return 0;
}

Measured memory_bytes: 1332
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

LINT hugou(LINT x, LINT y, LINT z, int occ){
  switch(occ){
    case 0: return x+y+z; break;
    case 1: return x+y-z; break;
    case 2: return x-y+z; break;
    case 3: return x-y-z; break;
    case 4: return -x+y+z; break;
    case 5: return -x+y-z; break;
    case 6: return -x-y+z; break;
    case 7: return -x-y-z; break;
    default: return 0; break;
  }
}

int main(){
  int N, M;
  cin >> N >> M;
  LINT x[N], y[N], z[N];
  REP(i, N){
    cin >> x[i] >> y[i] >> z[i];
  }
  LINT ans=0;
  LINT value[N];
  LINT trial;
  REP(k, 8){
    REP(i, N){
      value[i] = hugou(x[i], y[i], z[i], k);
    }
    sort(value, value+N, greater<LINT>());
    trial=0;
    REP(i, M) trial += value[i];
    ans = max(ans, trial);
  }


  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    char S[4];
    scanf("%s",S);
    int i,c=0;
    for(i=0;i<strlen(S);i++)
    {
    if(S[i]=='R')
    c++;
    if(S[i]=='S'&&c>0)
    break;
    }
    printf("%d",c);
    return 0;
}

Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
using ll = long long;
using namespace std;
const int INF = 1e9;

int main() {

    int N;
    cin >> N;
    vector<pair<int, int>> X(N);
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        X[i].first = a + b;
        X[i].second = a - b;
    }
    sort(X.begin(), X.end());
    

    int ans = 0, now = -INF;
    rep(i, N) {
        if (now <= X[i].second) {
            ans++;
            now = X[i].first;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

#define HASH 200003

typedef struct List {
	struct List *next;
	char *s;
	int l;
} list;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int hash_string(char* s)
{
	int i, x = 0;
	for (i = 0; s[i] != 0; i++) x = (x * 31 + s[i] - 'a') % HASH;
	return x;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int i, j, l[200001], N;
	char *S[200001], T[1000001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", T);
		for (l[i] = 0; T[l[i]] != 0; l[i]++);
		S[i] = (char*)malloc(sizeof(char) * (l[i] + 1));
		for (j = 0; j <= l[i]; j++) S[i][j] = T[j];
	}
	
	int h[200001];
	list *p, *hash[HASH], d[200001];
	for (i = 1; i <= N; i++) {
		h[i] = hash_string(&(S[i][1]));
		d[i].s = S[i];
		d[i].l = l[i];
		d[i].next = hash[h[i]];
		hash[h[i]] = &(d[i]);
	}
	
	int k, dp[26];
	long long ans = 0, tmp, pow[32];
	const long long inv = div_mod(1, 31, HASH);
	for (k = 1, pow[0] = 31; k < 32; k++) pow[k] = pow[k-1] * pow[k-1] % HASH;
	for (i = 1; i <= N; i++) {
		if (l[i] <= 1) continue;
		for (j = 0; j <= l[i]; j++) T[j] = S[i][j];
		for (j = l[i] - 2, k = 0, tmp = 1; j > 0; j >>= 1, k++) if ((j & 1) == 1) tmp = tmp * pow[k] % HASH;
		h[i] = (h[i] - tmp * (T[1] - 'a') % HASH + HASH) % HASH;
		for (j = 0; j < 26; j++) dp[j] = 0;
		dp[S[i][0] - 'a'] = 1;
		for (j = 1; j < l[i]; j++) {
			dp[S[i][j] - 'a'] = 1;
			for (k = 0; k < 26; k++) {
				if (dp[k] == 0) continue;
				T[j] = 'a' + k;
				for (p = hash[h[i]]; p != NULL; p = p->next) if (p->l == l[i] - j && p->s[0] == T[j] && lex_smaller(p->s, &(T[j])) == 0) break;
				if (p != NULL) ans++;
			}
			tmp = tmp * inv % HASH;
			h[i] = (h[i] - tmp * (T[j+1] - 'a') % HASH + HASH) % HASH;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 17288
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func main() {
	week := []string{ "SUN","MON","TUE","WED","THU","FRI","SAT" }
	s := getString()
	index := -1
	for i, day := range week {
		if s == day {
			index = i
			break
		}
	}

	fmt.Println(7 - index)
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


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

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

    string s;
    cin >> s;

    long long g, p = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'g') g++;
        else p++;
    }

    long long ans = 0;
    long long my_p = s.size() / 2;
    long long my_g = s.size() - my_p;

    if (my_p > g) {
        ans += g;
        ans -= my_g;
    } else {
        ans += my_p;
        ans -= p;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>

using namespace std;

int main(){
    int s;
    int w;
    cin >> s >> w;
    if(w >= s){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    for(auto &a:A){
        cin >> a;
    }
    for(auto &b:B){
        cin >> b;
    }

    ll suma,sumb;
    suma=sumb=0;
    for(int i=0; i<N; i++){
        ll a=A[i];
        ll b=B[i];
        if(a>b){
            sumb+=(a-b);
        }else{
            suma+=(b-a)/2+(b-a)%2;
            sumb+=(b-a)%2;
        }
    }
    //cout << suma << ' ' << sumb << endl;
    if(suma<sumb){
        cout << "No\n";
        return 0;
    }else{
        cout << "Yes\n";
        return 0;
    }
}

Measured memory_bytes: 3688
use proconio::{input, fastout};
use std::collections::HashSet;

#[fastout]
fn main() {
    input! {
        h: usize, w: usize,
        arr: [proconio::marker::Chars; h],
    }

    let mut dots_col = vec![0; w];
    let mut rows_to_remove: HashSet<usize> = HashSet::new();
    for (i, chars) in arr.iter().enumerate() {
        let mut dot_cnt = 0;
        for (j, c) in chars.iter().enumerate() {
            if c == &'.' {
                dot_cnt += 1;
                dots_col[j] += 1;
            }
        }
        if dot_cnt == w { rows_to_remove.insert(i); }
    }

    let arr2 = arr.into_iter().enumerate()
        .filter(|(i,_)| !rows_to_remove.contains(i))
        .map(|(_,c)| c).collect::<Vec<Vec<char>>>();

    let omit_idx = dots_col.iter().enumerate()
        .filter(|(_,e)| e==&&h).map(|(i,_)| i).collect::<HashSet<usize>>();

    for chars in arr2 {
        for (i, c) in chars.iter().enumerate() {
            if !omit_idx.contains(&i) { print!("{}", c) }
        }
        println!();
    }
}

Measured memory_bytes: 2184
s = input()
q = int(input())
adv = ''
bac = ''
Flag = True
for i in range(q):
    xxx = input()
    if len(xxx) == 1:
        if Flag == True:
            Flag = False
        else:
            Flag = True
    else:#T=2
        T,F,C=xxx.split()
        F = int(F)
        if F == 1:
            if Flag == True:
                adv +=C
            else:
                bac +=C
        else:#F=2
            if Flag == True:
                bac +=C
            else:
                adv +=C
if Flag == True:
    s = adv[::-1] + s + bac
    print(s)
else:
    s = bac[::-1] + s[::-1] + adv
    print(s)


Measured memory_bytes: 4340
#include <stdio.h>

int main(void){
    int N = 0;
    int A[100000] = {0};
    scanf("%ld", &N);
    for(int i = 0; i < N; i++){
        scanf("%ld", &A[i]);
    }
    int last = 0; 
    while(1){
        int min = 1000000000; int minno = 0;
        int flag = 0;
        for(int i = 0; i < N; i++){
            if(min > A[i]){
                min = A[i];
                minno = i;
            }
        }

        for(int i = 0; i < N; i++){
            if(A[i] % min != 0){
                flag = 1;
                break;
            }
        }

        if(flag == 0){
            last = min;
            break;
        }else {
            for(int j = 0; j < N; j++){
                if(j == minno){

                }else if(A[j] == min){

                }else {
                    A[j] -= min;
                }
            }
        }
    }
    printf("%d\n", last);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
using namespace std;


int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> ac(N), pena(N);
    for (int i = 0; i < M; ++i){
        int P;
        string s;
        cin >> P >> s;
        --P;
        if( ac[P])
            continue;
        if( s == "AC" ){
            ac[P] = 1;
        }else{
            pena[P]++;
        }
    }

    int AC = 0,PENA = 0;
    for (int i = 0; i < N; ++i){
        AC += ac[i];
        if( ac[i] ){
            PENA += pena[i];
        }
    }
    cout << AC << " "s << PENA;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main (void){

int W,H,x,y,r;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if(W<(x+r))printf("No\n");
  else if(W<(x-r))printf("No\n");
  else if(0>(x+r))printf("No\n");
  else if(0>(x-r))printf("No\n");
  else if(H<(y+r))printf("No\n");
  else if(H<(y-r))printf("No\n");
  else if(0>(y+r))printf("No\n");
  else if(0>(y-r))printf("No\n");
  else printf("Yes\n");






return 0;
}

Measured memory_bytes: 2684
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<climits>
#include<cstring>
#include<iomanip>
#include<string>
#include<bitset>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<algorithm>
#include<functional>
#include<chrono>
#include<random>

#define y0 asdahsdlkahsdad
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define taskname "A"
#define BeztDonkey

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

template <typename T> inline void Cin(T &x)
{
    register char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar());
    for (x = 0; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
}

int n, x, y, t, nx, ny, nt;

int main()
{
    #ifdef BeztDonkey
    auto start = chrono::steady_clock::now();
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);

    Cin(n);
    x = y = t = 0;
    for (int i = 1; i <= n; ++i)
    {
        Cin(nt); Cin(nx); Cin(ny);
        int timeleft = nt - t - (abs(nx - x) + abs(ny - y));
        if (timeleft < 0 || timeleft & 1) return cout << "No", 0;
        x = nx; y = ny; t = nt;
    }
    cout << "Yes";

    #ifdef BeztDonkey
    auto end = chrono::steady_clock::now();
    cerr << "In milliseconds : "
         << chrono::duration_cast<chrono::milliseconds>(end - start).count();
    cerr << '\n' << "In seconds : "
         << chrono::duration_cast<chrono::seconds>(end - start).count() << '\n';
    #endif
    return 0;

}


Measured memory_bytes: 256
import sys
a = int(input())
a_list = []
for i in range(a):
    a_list.append(int(input()))
max_num = max(a_list)
if a_list.count(max_num) != 1:
    for i in range(a):
        print(max_num)
else:
    sec_num = sorted(a_list)[-2]
    for i in a_list:
        if i == max_num:
            print(sec_num)
        else:
            print(max_num)

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

long long n,out;
long long have[10][10]; 

int main()
{
	cin>>n;
	for(long long i = 1;i <= n;i++)
	{
		long long f,l;
		l = i % 10;
		f = i;
		while(f / 10 > 0)
		f /= 10;
		out += have[l][f] * 2;
		have[f][l]++;
		if(f == l) out += 1;
	}
	cout<<out;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 ) {
				if (a[i] % 5 != 0)  {
					cout << "DENIED" << endl;
					return 0;
				}
			}
			if (a[i] % 5 != 0) {
				if (a[i] % 3 != 0) {
					cout << "DENIED" << endl;
					return 0;
				}
			}
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    vector<vector<ll>>d(n,vector<ll>(n,INF));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ll a;cin >>a;
            d[i][j]=a;
        }
    }
    bool flg=false;
    vector<vector<bool>>ch(n,vector<bool>(n,true));
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if(i!=k&&j!=k) {
                    if (d[i][j] == d[i][k] + d[k][j]) {
                        ch[i][j]=false;
                    }
                    if(d[i][j]>d[i][k]+d[k][j]) {
                        flg = true;
                    }
                }
            }
        }
    }
    ll ans=0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(ch[i][j]) {
                ans += d[i][j];
            }
        }
    }
    ans/=2;
    if(flg)ans=-1;
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;


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

    vector<pair<long long int, long long int> > shops;
    for(int i = 0; i < n; i++){
        long long int a,b;
        cin >>a >>b;
        shops.push_back(make_pair(a,b));
    }

    sort(shops.begin(), shops.end());

    unsigned long long int cost = 0;
    long long int purchased = 0;
    for(int i = 0; i < n; i++){
        if(purchased + shops[i].second > m){
            cost += shops[i].first * (m - purchased);
            break;
        }else{
            purchased += shops[i].second;
            cost += shops[i].second * shops[i].first;
        }
    }

    printf("%lld\n", cost);

    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string s;
	cin >> s;
	
	for(char c : s) {
		if( c == ',' ) cout << " ";
		else cout << c;
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 3576
(n,m)=map(int, input().split())
matrix = [[0]*m for x in range(n)]
vector = [0]*m
ans = [0]*n

for i in range(n):
    matrix[i][0:m]=map(int,input().split())
for j in range(m):
    vector[j] = int(input())

for i in range(n):
    for j in range(m):
        ans[i]+= matrix[i][j]*vector[j]
    print(ans[i])


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

using namespace std;

string A(string& S) {
	unordered_set<char> s(S.begin(), S.end());
	return (s.size() > 1) ? "Yes" : "No";
}

int main() {
	string S;
	cin >> S;
	cout << A(S);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  int N;
  cin >> N;
  int A[N];
  rep(i, N)
    cin >> A[i];
  //

  sort(A, A+N);

  map<int, int> m;

  int j;
  rep(i, N){
    for(j=1; j<=sqrt(A[i]); j++){
      if(A[i] % j == 0)   
	if(m[j] == 0 && m[ A[i]/j ] == 0)
	  continue;
	else
	  break;
    } // j
    if(j > sqrt(A[i]) || m[ A[i] ] == 1)
      m[ A[i] ]++;
  } // i

  int count = 0;
  for(auto map : m){
    if(map.second == 1)
      count++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 33408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
int main() {
    long double a,b,h,m;
    cin >> a >> b >> h >> m;
    complex<long double> ho = polar(a,(h+m/60.0)*2.0*PI/12.0);
    complex<long double> mi = polar(b,m*2.0*PI/60.0);
    DCOUT(abs(mi-ho), 30);
}


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

n = int(input().strip())
S_list = [input().strip() for _ in range(n)]
#-----

share_s=set(S_list[0])
for s in S_list[1:]:
   share_s = share_s & set(s)

cnt_share_word={ w:50 for w in share_s}
for s in S_list:
    for word in share_s:
        cnt_share_word[word] = min(cnt_share_word[word], s.count(word))

ans=""
for k,i in cnt_share_word.items():
    ans += k*i

print(*sorted(ans),sep="")


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

int main() {
    int n;
    cin >> n;
    long long int a[n], b[n];
    for(int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    long long int push_sum = 0;
    for(int i = n-1; i >= 0; --i) {
        if((push_sum + a[i])%b[i] != 0) 
            push_sum += b[i] - (push_sum + a[i])%b[i];
    }

    cout << push_sum << '\n';

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int D;
    cin>>D;
    int c[26];
    rep(i,26){
        cin>>c[i];
    }
    int s[D][26];
    rep(i,D){
        rep(j,26){
            cin>>s[i][j];
        }
    }
    int t[D];
    rep(i,D){
        cin>>t[i];
        t[i]--;
    }
    int ans=0;
    map<int,int> m;
    rep(i,D){
        ans+=s[i][t[i]];
        rep(j,26){
            if(j==t[i]){
                m[t[i]]=0;
            }else{
                m[j]++;
                ans-=m[j]*c[j];
            }
        }
        cout << ans << endl;
    }


    



}


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main(){
	long long N, K, sum, max_sum, index, zero_n;
	char prev, c, first_c;
	vector<long long> vec;
	cin >> N >> K;
	prev = 'a';
	index = -1;
	for(long long i=0; i<N; i++){
		cin >> c;
		if(i==0){
			first_c = c;
		}
		if(c != prev){
			vec.push_back(1);
			index++;
			prev = c;
		}else{
			vec[index]++;
		}
	}
//	
	sum = 0;
	max_sum = 0;
	if(first_c == '0'){
		zero_n = vec.size()/2 + (vec.size()%2==1);
		if(K >= zero_n){
			cout << N << endl;
			return 0;
		}
		max_sum = accumulate(vec.begin(), vec.begin()+2*K, 0);
		for(long long i=1; i+2*K<vec.size(); i+=2){
			sum = accumulate(vec.begin()+i, vec.begin()+2*K+i+1, 0);
			max_sum = max(max_sum, sum);
		}
		if(vec.size()%2 == 1){
			sum = accumulate(vec.end()-2*K, vec.end(), 0);
			max_sum = max(max_sum, sum);
		}
	}else{
		zero_n = vec.size()/2;
		if(K >= zero_n){
			cout << N << endl;
			return 0;
		}
		for(long long i=0; i+2*K<vec.size(); i+=2){
			sum = accumulate(vec.begin()+i, vec.begin()+2*K+i+1, 0);
			max_sum = max(max_sum, sum);
		}
		if(vec.size()%2 == 0){
			sum = accumulate(vec.end()-2*K, vec.end(), 0);
			max_sum = max(max_sum, sum);
		}
	}
	cout << max_sum << endl;
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
long long int a[200005],b[200005];
long long int ans=0;
int main()
{   long long int n;
    cin>>n;
    for(int i=0;i<n;i++)
         cin>>a[i],b[a[i]]++;
    for(int i=0;i<200004;i++)
    {
        ans=ans+b[i]*(b[i]-1)/2;
    }
    //printf("ans=%d\n",ans);
    for(int i=0;i<n;i++)
    {   printf("%lld\n",ans-b[a[i]]+1);
    }



    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
 
    string s;
    cin >> s;
    int n = s.size();
 
    int end = n;
    for(int i = n-1; i >= 0; --i){
        if(s[i] == 'B') --end;
        if(s[i] == 'W') break;
    }
    n = end;
 
    ll res = 0;
    rep(i, n){
        if(s[i] == 'B') {
            res += end - i - 1;
            --end;
        }
    }
 
    cout << res << endl;
 
    return 0;
}

Measured memory_bytes: 720
s = input()
n = len(s)
key = dict()
for i in range(n):
  if s[i] not in key:
    key[s[i]] = 1
  else:
    key[s[i]] += 1
ans = True
for value in key.values():
  if value%2 == 1:
    print("No")
    ans = False
    break
if ans:
  print("Yes")

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

int main(){
    int H,W,k; cin >> H >> W >> k;
    vector<string> maze(H);
    rep(i,H) cin >> maze[i];
    int n=0;
    rep(i,H){
        rep(j,W){
            if(maze[i][j]=='#') n++;
        }
    }
    int ans = 0;
    for(int bit=0;bit<(1<<(H+W));++bit){
        int res = 0;
        vector<vector<bool> > seen(H,vector<bool>(W,false));
        rep(i,H+W){
            if(bit & 1<<i){
                if(i<H){
                    rep(j,W){
                        if(maze[i][j]=='#' && !seen[i][j]){
                            res++;
                            seen[i][j] = true;
                        }
                    }
                }else{
                    rep(j,H){
                        if(maze[j][i-H]=='#' && !seen[j][i-H]){
                            res++;
                            seen[j][i-H] = true;
                        }
                    }
                }
            }
        }
        if(n-res == k) ans++;;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  std::vector<ll> A(N), B(N);
  multimap<ll, ll> mp;
  for(int i=0;i<N;i++) std::cin >> A[i];
  for(int i=0;i<N;i++) {
    std::cin >> B[i];
    mp.emplace(B[i], i);
  }
  ll count=0;
  bool flag = true;
  while(mp.size()!=0){
    auto itr = mp.end();
    itr--;
    ll num = (*itr).first;
    ll i = (*itr).second;

    ll x = B[(i==N-1?0:i+1)]+B[(i==0?N-1:i-1)];
    if((num-A[i])%x==0){
      count+=(num-A[i])/x;
      num = A[i];
    }else{
      int precount=count;
      count+=num/x;
      num = num%x;
      if(A[i]>num){
        count-=(A[i]-num)/x+((A[i]-num)%x==0?0:1);
        num+=x*((A[i]-num)/x+((A[i]-num)%x==0?0:1));
      }
      if(precount==count){
        count+=1;
        num-=x;
      }
    }
    if(num < A[i]) {
      flag = false;
      break;
    }
    B[i] = num;
    mp.erase(itr);
    if(num!=A[i]) mp.emplace(num, i);
  }
  if(flag) std::cout << count << '\n';
  else std::cout << -1 << '\n';
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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 vis[1000000],dis[1000000];
vvi g(1000000);

int dfs(int v){
    if(vis[v]==2)return dis[v];
    vis[v]=1;
    for(auto x:g[v]){
        if(vis[x]==1)return -1;
        int y=dfs(x);
        if(y==-1)return -1;
        dis[v]=max(dis[v],y+1);
    }
    vis[v]=2;
    return dis[v];
}

int main(){
    int n;cin>>n;
    mem(dis,0);
    mem(vis,0);
    rep(i,n){
        int last=0;
        rep(j,n-1){
            int a;
            cin>>a;
            a--;
            int x=min(i,a),y=max(i,a);
            if(last==0){
                last=y+1000*x;
                g[0].PB(last);
                continue;
            }
            g[last].PB(y+1000*x);
            last=y+1000*x;
        }
    }
    dis[0]=-1;
    cout<<dfs(0)<<endl;
}


Measured memory_bytes: 47232
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;



int main(void) {
  int i,j;
  int n,y;
  while(1){
    cin>>n;
    if(n==0)break;
    cin>>y;
    vi b(n),r(n),t(n);
    rep(i,n)cin>>b[i]>>r[i]>>t[i];
    double m=0,tmp;
    int ans=0;
    rep(i,n){
      if(t[i]==1)tmp=1+y*r[i]*0.01;
      else{
        tmp=1;
        rep(j,y)tmp*=1+r[i]*0.01;
      }
      if(tmp>m)ans=i,m=tmp;
    }
    cout<<b[ans]<<endl;
  }
}

Measured memory_bytes: 3088
#include <stdio.h>

int x[4]={0};

int main(){
    int N;
    char s;
    int ans=3;

    scanf("%d",&N);
    for (int i=0;i<N;i++){
	scanf("%c",&s);
	if (s == 'Y'){
	    ans=4;
	}
    }

    if (ans == 3) printf("Three\n");
    else printf("Four\n");

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

/*
 * Dependencies: typedef long long ll
 * Headers: iostream
 * Verified by: ARC099-F
 *              https://beta.atcoder.jp/contests/arc099/submissions/2743855
 */

template<ll mod = (ll)1e9 + 7>
struct ModInt {
  ll x;
  ModInt(void): x(0) {}
  ModInt(ll x): x(x % mod){}
  ModInt(const ModInt &x): x(x.x) {}
  ModInt operator+(ModInt o) const {
    ll y = x + o.x;
    if (y >= mod) y -= mod;
    return ModInt(y);
  }
  ModInt operator-(ModInt o) const {
    ll y = x - o.x + mod;
    if (y >= mod) y -= mod;
    return ModInt(y);
  }
  ModInt operator*(ModInt o) const {
    return ModInt((x * o.x) % mod);
  }
  void operator+=(ModInt o) { *this = *this + o; }
  void operator-=(ModInt o) { *this = *this - o; }
  void operator*=(ModInt o) { *this = *this * o; }
  ModInt operator-(void) const { return ModInt() - *this; }
  ll to_ll() const {
    return x;
  }
  bool operator<(ModInt o) const {
    return x < o.x;
  }
  ModInt pow(ll e) {
    assert (e >= 0);
    ModInt sum = 1;
    ModInt cur = *this;
    while (e > 0) {
      if (e % 2) {
        sum = sum * cur;
      }
      cur = cur * cur;
      e /= 2;
    }
    return sum;
  }
  ModInt inv(void) {
    return pow(mod - 2);
  }
};

template<ll mod>
ostream &operator<<(ostream &os, ModInt<mod> mi) {
  return os << mi.x;
}

const int N = 400000;
ModInt<> fac[N], invfac[N];

void init(void) {
  fac[0] = 1;
  REP(i, 1, N) fac[i] = fac[i - 1] * i;
  invfac[N - 1] = fac[N - 1].inv();
  for (int i = N - 2; i >= 0; i--) {
    invfac[i] = invfac[i + 1] * (i + 1);
  }
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  int n;
  ll k;
  cin >> n >> k;
  ModInt<> tot;
  REP(i, 0, min((ll) n, k + 1)) {
    ModInt<> comb = fac[n] * invfac[n - i] * invfac[i];
    tot += comb * fac[n - 1] * invfac[i] * invfac[n - i - 1];
  }
  cout << tot << endl;
}


Measured memory_bytes: 6656
n, m, x = map(int, input().split())
ca = []
for _ in range(n):
    ca.append(list(map(int , input().split())))


import itertools
INF = 10 ** 10
ans = INF
for bi in itertools.product([0, 1], repeat=n):
    xx = [0] * m
    cc = 0
    for i, j in enumerate(bi):
        if j == 1:
            for k in range(m):
                xx[k] += ca[i][k+1]
            cc += ca[i][0]
    allok = True
    for i in range(m):
        if xx[i] < x:
            allok = False
    if allok:
        ans = min(ans, cc)
if ans == INF:
    print(-1)
    exit()
print(ans)

Measured memory_bytes: 9236
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,m;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    long long ans = 1;
    if(n > m)    swap(n,m);
    if(m - n > 1)
	{
	    cout << "0" << endl;
    	return 0;
    }
	for(int i=1;i<=m;i++)
    {
    	if(i<=n)
    	    ans = (ans*i)%mod;
    	ans = (ans*i)%mod;
	}
	if(m==n)
	    ans = (ans*2)%mod;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
int n,m,i,j,k,count1=0,count2=0;
using namespace std;
void ABC120(void);
void ABC121(void);
void ABC122(void);
void ABC123(void);
void ABC124(void);
void ABC125(void);
void ABC126(void);
void ABC127(void);
void ABC128(void);
void ABC129(void);

int main(void){
    ABC128();
}

void ABC128(){
    cin>>n;
    vector<tuple<string,int,int>>list(n);
    string s;
    int x;
    for(i=0;i<n;i++){
        cin>>s>>x;
        list.at(i)=make_tuple(s,-x,i+1);
    }
    sort(list.begin(),list.end());
    for(i=0;i<n;i++){
        cout<<get<2>(list.at(i))<<endl;
    }
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){ 
    int n,c;
    cin>>n>>c;
    int sum=0;
    n++;
    rep(i,0,c){
        int x; cin>>x; sum+=x;
    }
    if(sum%n==0)cout<<sum/n<<endl;
    else cout<<sum/n+1<<endl;
    
}


/*
abcdea

/root
a.txt
bunp.html
/desktop
r.txt
fsharp.cs
dp.cpp
/users
bison.txt

root r.txt
users r.txt
users a.txt

desktop/r.txt
../r.txt
../../a.txt
*/



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int T, M, K, N[3];

int main(void){
	//IO("test.in", "test.out");
	scanf("%d%d%d%d", &N[0], &N[1], &N[2], &K);
	for(int i = 0; i < 3; i++){
		T = 0;
		if(i == 0) T = N[0] * (1 << K) + N[1] + N[2];
		else if(i == 1) T = N[0] + N[1] * (1 << K) + N[2];
		else T = N[0] + N[1] + N[2] * (1 << K);
		if(T > M) M = T; 
	}
	printf("%d\n", M);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
/*inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}*/
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RANK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
char a[355];
int n,ans=0;
map<pair<string,int>,int> mp;
int main(){
	n = rd();
	Rep(i,1,2*n){
		a[i] = gc();
		while(a[i] <'a'||a[i]>'z')a[i]=gc();
	}
	rep(i,0,1<<n){
		string sa = "",sb = "";
		int cnt = 0;
		Rep(j,1,n){
			if(i>>(j-1)&1){
				sa = sa + a[j];
				cnt++;
			} else{
				sb = sb + a[j];
			}
		}
		reverse(sb.begin(),sb.end());
		mp[make_pair(sa+sb,cnt)]++;
//		cout << sa+sb << endl;
	}
	ll ans=0;
	rep(i,0,1<<n){
		string sa = "",sb = "";
		int cnt = 0;
		Dep(j,2*n,n+1){
			if(i>>(j-n-1)&1){
				sa = sa + a[j];
				cnt++;
			} else{
				sb = sb + a[j];
			}
		}
		reverse(sb.begin(),sb.end());
		ans += mp[make_pair(sa+sb,cnt)]; 
	} 
	writeln(ans);
}


Measured memory_bytes: 67328
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int grid[1010][1010];
pair<int, int> dp[1000010];
pair<int, int> c[1010000];
int is_prime[1010000];
int visited[1010000];
int main() {
    int yy = 505, xx = 505;

    c[1] = make_pair(yy, xx);
    int cnt = 2;

    for (int i = 0; i < 1010; ++i) {
        for (int j = 0; j < 1010; ++j) {
            grid[i][j] = INF<int>;
        }
    }
    grid[yy][xx] = 1;
    xx++;
    for (int i = 0; i < 500; ++i) {
        for (int j = 0; j < 2*i+1; ++j) {
            c[cnt] = make_pair(yy, xx);
            grid[yy][xx] = cnt;
            yy--; cnt++;
        }
        for (int j = 0; j < 2*i+2; ++j) {
            c[cnt] = make_pair(yy, xx);
            grid[yy][xx] = cnt;
            xx--; cnt++;
        }

        for (int j = 0; j < 2*i+2; ++j) {
            c[cnt] = make_pair(yy, xx);
            grid[yy][xx] = cnt;
            yy++; cnt++;
        }
        for (int j = 0; j < 2*i+3; ++j) {
            c[cnt] = make_pair(yy, xx);
            grid[yy][xx] = cnt;
            xx++; cnt++;
        }
    }
    int n, m;
    fill_n(is_prime, 1000010, 1);
    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i <= 1000010; ++i) {
        if(!is_prime[i]) continue;
        for (int j = i*2; j <= 1000010; j += i) {
            is_prime[j] = 0;
        }
    }
    while(cin >> n >> m, n){
        int sy, sx; tie(sy, sx) = c[m];
        fill_n(visited, n+1, 0);
        fill_n(dp, n+1, make_pair(-MOD, 0));
        dp[m] = make_pair(is_prime[m], (is_prime[m] ? m : 0));
        queue<pair<int, int>> q;
        q.emplace(sy, sx);
        pair<int, int> ans;
        visited[m] = 1;
        while(!q.empty()){
            int y, x; tie(y, x) = q.front(); q.pop();
            int num1 = grid[y][x];
            for (int i = -1; i <= 1; ++i) {
                int num2 = grid[y+1][x+i];
                if(num2 > n){
                    if(dp[num1] > ans){
                        ans = dp[num1];
                    }
                }else {
                    dp[num2] = max(dp[num2], make_pair(dp[num1].first+is_prime[num2],
                                                       (is_prime[num2] ? num2 : dp[num1].second)));
                    if(!visited[num2]){
                        q.emplace(y+1, x+i);
                        visited[num2] = 1;
                    }
                }
            }
        }

        printf("%d %d\n", ans.first, ans.second);
    }
    return 0;
}


Measured memory_bytes: 30660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

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

  ll ans = 0;
  FOR(i,1,n+1){
    if(i%3 == 0 || i%5 == 0) continue;
    else{
      ans += (ll)i;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636