akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    string n; cin>>n;
    ll sum=0;
    rep(i,0,n.size()){
        sum+=n[i]-'0';
    }
    if(((stoi)(n))%sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main()
{
	int n;cin>>n;
	vector<int> v,b;
	for(int i=0;i<n;i++)
	{
		int p;cin>>p;
		v.push_back(p);
	}
	int count=0,cnt=0,a=0;
	b.push_back(0);
	b.push_back(abs(v[1]-v[0]));
	for(int i=2;i<n;i++)
	{
		int k=min(b[i-1]+abs(v[i]-v[i-1]),b[i-2]+abs(v[i]-v[i-2]));
		b.push_back(k);
	}
	cout<<b[b.size()-1];
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A , C;
  cin >> N >> A ;
  C = N%500;
  
  if (C <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}


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

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

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

    for(int i=0; i<n-1; i++){
        if(a[i] == a[i+1]) {
            cout << "NO" << endl; 
            return 0;
        }
    }

    cout << "YES" << endl; 
    return 0;

}

Measured memory_bytes: 4840
#include<stdio.h>
int main()
{
	int n;
	int a[1000];
	while(scanf("%d",&n)!=EOF&&n){
	int sum=0;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		sum+=x-1;
	}

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	vector<vector<int>> dp(h, vector<int>(w, 105));
	vector<string> s(h);
	rep(snip_i, h) cin >> s.at(snip_i);
	if(s.at(0)[0] == '#') dp.at(0).at(0) = 1;
	else dp.at(0).at(0) = 0;
	rep(i, h){
		rep(j, w){
			if(i == 0 && j == 0) continue;
			char c = s.at(i)[j];
			int u, l;
			u = l = 1001;
			if(i > 0){
				u = dp.at(i-1).at(j);
				if(s.at(i-1)[j] == '.' && c == '#') u++;
			}
			if(j > 0){
				l = dp.at(i).at(j-1);
				if(s.at(i)[j-1] == '.' && c == '#') l++;
			}
			dp.at(i).at(j) = min(u, l);
		}
	}
	cout << dp.at(h-1).at(w-1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
typedef unsigned long long ull;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "

deque<int> power(ll x)
{
  if (x < 1) assert(false);
  else if (x == 1) return deque<int>();
  else if (x % 2 == 0)
    {
      auto tmp = power(x/2);
      tmp.pb(tmp.size()+1);
      return tmp;
    }
  else
    {
      auto tmp = power(x-1);
      tmp.push_front(tmp.size()+1);
      return tmp;
    }
}
int main()
{
  ll n; cin >> n;
  deque<int> ans = power(n+1);
  int sz = ans.size();
  for (int i = 1; i <= sz; ++i) ans.pb(i);
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i)
    cout << ans[i] << " \n"[i+1==ans.size()];
}


Measured memory_bytes: 256
N,M=gets.split.map(&:to_i)
S=gets.chomp.reverse
cnt=0
a=Array.new
while true
  ex=false
  M.downto(1) do |i|
    if N<=cnt+i
      a.push(N-cnt)
      cnt=N
      ex=true
      break
    elsif S[cnt+i]=="0"
      a.push(i)
      cnt+=i
      break
    end
    if i==1
      puts -1
      exit
    end
  end
  break if ex
end
puts a.reverse.join(" ")
     
    

Measured memory_bytes: 4092
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 2097153, M = N * 19;
char S[N];
int n,k,Len[N],cnt,dp[N][21],deg[N][21],sta1[M],top;
short sta2[M];
#define bh(s,l) ((s)+(1<<(l)))
inline void getnxt(int len, int s, int l, int &x, int &y, bool v) {
	per(pos,len,1) if (((s>>(pos-1))&1)==v) {
		y=pos-1;
		x=bh(((((s>>len)<<1)+v)<<(pos-1))|(s&((1<<(pos-1))-1)),l-len+pos); 
		return;
	}
	x=0;y=0;
}
int main() { //freopen("1.in","r",stdin);
	read(n);read(k);
	rep(i,0,n){
		scanf("%s",S+1);
		rep(j,1,1<<i) Len[++cnt]=i,dp[cnt][i]=(S[j]=='1');
	}
	rep(now,1,cnt) rep(len,1,Len[now]) {
		int l=Len[now],s=now-(1<<l);
		int x=bh(s>>len,l-len),y=0; ++deg[x][y];
	//	printf("nxt[%d,%d]=%d,%d\n",now,len,x,y);
		getnxt(len,s,l,x,y,0); ++deg[x][y];
	//	printf("nxt[%d,%d]=%d,%d\n",now,len,x,y);
		getnxt(len,s,l,x,y,1); ++deg[x][y];
	//	printf("nxt[%d,%d]=%d,%d\n",now,len,x,y);
	}
	rep(now,1,cnt) rep(len,1,Len[now]) if (!deg[now][len]) sta1[++top]=now,sta2[top]=len;
	while (top) {
		int now=sta1[top],len=sta2[top--]; if (!(now>=1&&len>=1)) continue; //len>=1
		int l=Len[now],s=now-(1<<l),val=dp[now][len];
		int x=bh(s>>len,l-len),y=0; if (!(--deg[x][y])) sta1[++top]=x,sta2[top]=y; dp[x][y]+=val;
		getnxt(len,s,l,x,y,0); if (!(--deg[x][y])) sta1[++top]=x,sta2[top]=y; dp[x][y]+=val;
		getnxt(len,s,l,x,y,1); if (!(--deg[x][y])) sta1[++top]=x,sta2[top]=y; dp[x][y]+=val;
	}
	int ans=1; rep(i,2,cnt) if (dp[i][0]>=k&&(Len[i]>Len[ans])) ans=i;
//	rep(i,1,cnt) printf("%d : %d\n",i,dp[i][0]);
//	printf("ans = %d\n",ans);
	per(i,Len[ans],1) printf("%d",((ans-(1<<Len[ans]))>>(i-1))&1);
	return 0;
}


Measured memory_bytes: 370944
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int main(){
  int n;
  map<int,int> mp;
  cin >> n;
  while(n--){
    int a;
    cin >> a;
    mp[a] += 1;
  }
  string s;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    if (itr->second > 1){
      s = "NO";
      break;
    }else{
      s = "YES";
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 9728
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int x, y, z, k;

    cin >> x >> y >> z >> k;

    vector<ll> a(x), b(y), c(z), ab, ans;

    for (int i = 0; i < x; i++)
    {
        cin >> a[i];
    }

    for (int i = 0; i < y; i++)
    {
        cin >> b[i];
    }

    for (int i = 0; i < z; i++)
    {
        cin >> c[i];
    }

    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            ab.push_back(a[i] + b[j]);
        }
    }

    sort(ab.rbegin(), ab.rend());

    for (int i = 0; i < min(k, x * y); i++)
    {
        for (int j = 0; j < z; j++)
        {
            ans.push_back(ab[i] + c[j]);
        }
    }

    sort(ans.rbegin(), ans.rend());

    for (int i = 0; i < k; i++)
    {
        cout << ans[i] << endl;
    }
}

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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<pair<double, double>> p(n);
	rep(i, 0, n - 1)cin >> p[i].first >> p[i].second;
	double ans = 0;
	sort(all(p));
	do
	{
		rep(i, 1, n - 1)
		{
			ans += sqrt(pow(p[i - 1].first - p[i].first, 2) + pow(p[i - 1].second - p[i].second, 2));
		}
	} while (next_permutation(all(p)));
	rep(i, 2, n)
	{
		double x = i;
		ans /= x;
	}
	printf("%.6f", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <queue>

#define gc (c = getchar())
#define gi(x) scanf("%d",&x)
#define gid(x, y) scanf("%d%d",&x,&y)
#define gll(x) scanf("%lld",&x);

#define pi(x) printf("%d\n",&x)

#define pll(x) printf("%lld\n",&x)
#define dbg(x) std::cerr << #x << " " << x << std::endl

inline long long max(long long x, long long y) { return x > y ? x : y; }

inline long long min(long long x, long long y) { return x > y ? y : x; }

int cnt(long long n){
    int ret = 0;
    while(n){
        ret ++;
        n /= 10;
    }
    return ret;
}

int main(){
    long long n;
    std::cin >> n;
    long long ret=  0;
    for(int o = 1; o <= n;++ o) {
        if (cnt(o) & 1) ret ++;
    }
    std::cout <<ret << std::endl;
}


Measured memory_bytes: 256
N = int(input())
a = [int(i)-1 for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
cnt = 0
temp = N
for i in a:
  cnt += b[i]
  if temp+1 == i:
    cnt += c[i-1]
  temp = i
print(cnt)

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

int main(void) {
  int r, D, x_2000;
  cin >> r >> D >> x_2000;
  int before = x_2000;
  for(int i = 1; i <= 10; i++) {
    int next = r * before - D;
    cout << next << endl;
    before = next;
  }
  return 0;
}

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

using namespace std;

int main()
{
    int N;
    vector<int> W;

    cin >> N;

    W.resize(N);

    int min = 0;

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

        min += W[i];
    }

    for(int T=0; T<N; T++){
        int S1 = 0;
        int S2 = 0;
        for(int i=0; i<N; i++){
            if(i<=T){
                S1 += W[i];
            }
            else{
                S2 += W[i];
            }
        }

        if(min > abs(S1-S2)){
            min = abs(S1-S2);
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 1000000
#define NIl (-1)
#define L 14

char x[M][L];

int getChar(char );
long long getkey(char *);
int h1(int );
int h2(int );
int find(char *);
int insert(char *);

int main(){
    int i,n,h;
    char str[L],com[9];
    for(i=0;i<M;i++) x[i][0]='\0';
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%s %s",com,str);
        
        if(com[0]=='i'){
            insert(str);
        }else{
            if(find(str)){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    return 0;
}


int getChar(char c){
    if(c=='A') return 1;
    else if(c=='C') return 2;
    else if(c=='G') return 3;
    else if(c=='T') return 4;
    else return 0;
}

long long getkey(char str[]){
    long long sum=0,p=1,i;
    for(i=0;i<strlen(str);i++){
        sum += p*(getChar(str[i]));
        p *=5;
    }
    return sum;
}

int h1(int key){
    return key%M;
}

int h2(int key){
    return 1 + (key%(M-1));
}

int find(char str[]){
    long long key ,i,h;
    key = getkey(str);
    for(i=0;;i++){
        h=(h1(key) + i * h2(key)) % M;
        if(strcmp(x[h],str) == 0) return 1;
        else if(strlen(x[h])==0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key,i,h;
    key = getkey(str);
    for(i=0;;i++){
        h=(h1(key) + i * h2(key)) % M;
        if( strcmp(x[h],str)==0) return 1;
        else if(strlen(x[h])==0){
            strcpy(x[h],str);
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 15408
import java.math.BigInteger;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		String[] substr = str.split(" ", 0);

		String ns = substr[0];
		String ks = substr[1];
		sc.close();

		BigInteger ans = new BigInteger(ns);
		BigInteger buf = new BigInteger(ns);

		BigInteger n = new BigInteger(ns);
		BigInteger k = new BigInteger(ks);

		ans = n.mod(k);
		buf = ans.subtract(k).abs();
		if (ans.compareTo(buf)>0) {
			ans = buf;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
N = int(input())
a = list(map(int, input().split()))

count_a = {}
for n in range(N):
    if a[n] in count_a.keys():
        count_a[a[n]] += 1
    else:
        count_a[a[n]] = 1

result = 0
for n in list(count_a.keys()):
    if count_a[n] != n:
        result = result + count_a[n] if count_a[n] < n else result + count_a[n] - n

print(result)


Measured memory_bytes: 17780
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
typedef long long ll;
ll gcd(ll x,ll y) {return y?gcd(y,x%y):x;}
int main() {
	ll a,b;
	cin>>a>>b;
	cout<<a*b/gcd(a,b)<<'\n';
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    long ans = 0;
    for(int i = 0;i < N;++i){
        ans += i;
    }
    cout << ans << endl;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (int)(s); i < (int)(e); ++i)
#define per(i,s,e) for(int i = (int)(s)-1; i >= (int)(e); --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int n;
vector<vector<int>> graph;

int Count(int x){
  int chil_size = (int)(graph[x].size());
  vector<int> chil_depth(chil_size);
  rep(i,0,chil_size) ChangeMax(chil_depth[i],Count(graph[x][i]));
  sort(chil_depth.begin(),chil_depth.end(),greater<int>());
  int val = 0;
  rep(i,0,chil_size) ChangeMax(val, chil_depth[i]+i+1);
  return val;
}

int main(){  
  cin >> n;
  graph.resize(n);
  rep(i,1,n){
    int x; cin >> x; x--;
    graph[x].push_back(i);
  }

  cout << Count(0) << endl;
  return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <string>
using namespace std;
string s;

bool getSs(int l,int r){
	for(int i=l,j=r;i<j;i++,j--)
		if(s[i] != s[j])
			return false;
	int mid = (l+r)/2;
	for(int i=l,j=mid-1;i<j;i++,j--)
		if(s[i] != s[j])
			return false;
	for(int i=mid+1,j=r;i<j;i++,j--)
		if(s[i] != s[j])
			return false;
	return true;
}

int main(){
	cin>>s;
	cout<<(getSs(0,s.length()-1) ? "Yes" : "No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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

	
	int N;
	cin >> N;
	int P[100001] = {};
	rep1(i, N) {
		int p;
		cin >> p;
		P[p] = i;
	}
	int kotae = 0;
	rep1(i, N) {
		if (P[i] == i) {
			kotae++;
			i++;
		}
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 640
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct
  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    let left i = 2*i in
    let right i = 2*i + 1 in
    let rec max_heapify i =
      let l = left i in
      let r = right i in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m <> i then begin
        let tmp = t.node.(i) in t.node.(i) <- t.node.(m); t.node.(m) <- tmp;
        max_heapify m
      end
    in
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    max_heapify 1;
    ret

  let push x t =
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      if i > 1 && M.compare t.node.(parent i) t.node.(i) < 0 then begin
        let tmp = t.node.(i) in t.node.(i) <- t.node.(parent i); t.node.(parent i) <- tmp;
        doit (parent i)
      end
    in
    doit t.size
end

module H = MakeBinaryHeap(struct type t = (int * int) let compare x y = fst x - fst y end)

let split str delim =
  let rec doit s acc =
    match
      try Some (String.rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s1 (s2 :: acc)
  in
  doit str []

let dijkstra g n =
  let h = H.make 100000 (0, 0) in
  let d = Array.make n max_int in
  let b = Array.make n false in
  d.(0) <- 0;
  b.(0) <- true;
  H.push (0, 0) h;
  let rec duduwa u = function
    | [] -> ()
    | (v, _) :: tl when b.(v) = true -> duduwa u tl
    | (v, c) :: tl when d.(v) <= d.(u) + c -> duduwa u tl
    | (v, c) :: tl -> begin
        d.(v) <- d.(u) + c;
        H.push ((-d.(v)), v) h;
        duduwa u tl
      end
  and doit () =
    if not (H.empty_p h) then begin
      let (x, u) = H.pop h in
      b.(u) <- true;
      if d.(u) >= (-x) then duduwa u g.(u);
      doit ()
    end
  in
  doit ();
  d

let () =
  let n = read_int () in
  let g = Array.make n [] in
  let rec read i =
    if i < n then begin
      match List.map int_of_string (split (read_line ()) ' ') with
      | u :: _ :: l -> begin
          let rec make_pair acc = function
            | [] -> acc
            | f :: t :: tl -> make_pair ((f, t) :: acc) tl
            | _ -> exit 1
          in
          g.(u) <- make_pair [] l;
          read (i + 1)
        end
      | _ -> exit 1
    end
  in
  read 0;
  let d = dijkstra g n in
  Array.iteri (fun i e -> Printf.printf "%d %d\n" i e) d

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

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define pb push_back
#define mp make_pair
#define x first
#define y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <typename X> inline X abs(const X &a) {return a < 0 ? -a : a;}
template <typename X> inline X sqr(const X &a) {return a * a;}

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;
const ld PI = acosl(ld(-1));

mt19937 mt(time(NULL));

const int N = 100 + 3;
const int M = 10 * 1000 + 13;
int m, n;
int a[N];

inline bool read() {
	if (scanf ("%d%d", &m, &n) != 2)
		return false;
		
	forn (i, n)
		assert(scanf ("%d", &a[i]) == 1);

	return true;
}

inline void solve() {
	int maxVal = -1;
	int sum = 0;
	forn (i, n)
	{
		maxVal = max(maxVal, a[i]);
		sum += a[i];
	}
		
	cerr << maxVal << ' ' << sum << endl;

	cout << max(0, maxVal - (sum - maxVal) - 1) << endl;
}

int main() {
#ifdef SU2_PROJ
	assert(freopen("input.txt", "r", stdin));
	assert(freopen("output.txt", "w", stdout));
#endif

	cout << setprecision(25) << fixed;
	cerr << setprecision(10) << fixed;
	
	assert(read());
	solve();

#ifdef SU2_PROJ
	cerr << "TIME: " << clock() << endl;
#endif
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n, a[10000], p;

void yakusuu(int p) {
	int cnt = 0;
	for (int i = 1; i <= p; i++) {
		if (p%i == 0) {
			cout << i << endl; cnt++;
		}
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	p = a[0];
	for (int i = 1; i < n; i++) {
		p = __gcd(p, a[i]);
	}
	yakusuu(p);
	return 0;
}

Measured memory_bytes: 1172
N=int(input())
A=list(map(int,input().split()))
ans="APPROVED"

for i in range(N):
    if A[i]%2==0:
        if A[i]%3==0 or A[i]%5==0:
            pass
        else:
            ans="DENIED"
    else:
        pass

print(ans)

Measured memory_bytes: 3060
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])


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

int main(){
  int a,b,c,x,y,ans;
  cin>>a>>b>>c>>x>>y;
  
  if(x>=y){
    ans=min(2*x*c,2*y*c+(x-y)*a);}
  if(x<y){
    ans=min(2*y*c,2*x*c+(y-x)*b);}
  
  ans=min(ans,a*x+b*y);
  
  cout<<ans;}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S; int N, K;
ll DP1[105][4], DP2[105][4];

int main(){
  cin >> S >> K;
  N = S.length();

  DP2[0][0] = 1;

  for (int i = 1; i <= N; i++){
    for (int j = 0; j <= K; j++){
      DP1[i][j] += DP1[i-1][j];
      DP1[i][j] %= MOD;
    }
    for (int j = 0; j < K; j++){
      DP1[i][j+1] += DP1[i-1][j] * 9;
      DP1[i][j+1] %= MOD;
    }

    if (S[i-1] == '0'){
      for (int j = 0; j <= K; j++){
        DP2[i][j] = DP2[i-1][j];
      }
    }else{
      ll num = S[i-1] - '1';
      for (int j = 0; j <= K; j++){
        DP1[i][j] += DP2[i-1][j]; DP1[i][j] %= MOD;
      }
      for (int j = 0; j < K; j++){
        DP1[i][j+1] += DP2[i-1][j] * num;
        DP1[i][j+1] %= MOD;
        DP2[i][j+1] = DP2[i-1][j];
      }
    }
  }

  cout << (DP1[N][K] + DP2[N][K]) % MOD << endl;

  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin>>n;
    long c[5]={0,0,0,0,0};
    for(int i=0; i<n; i++){
        string s_temp;
        cin>>s_temp;
        if(s_temp[0]=='M')      c[0]++;
        else if(s_temp[0]=='A') c[1]++;
        else if(s_temp[0]=='R') c[2]++;
        else if(s_temp[0]=='C') c[3]++;
        else if(s_temp[0]=='H') c[4]++;
        //cout<<s_temp[0]<<c[0]<<c[1]<<c[2]<<c[3]<<c[4]<<endl;
    }
    long ans;
    ans = c[0]*c[1]*c[2] + c[0]*c[1]*c[3] + c[0]*c[1]*c[4] + c[0]*c[2]*c[3] + c[0]*c[2]*c[4] + c[0]*c[3]*c[4] + c[1]*c[2]*c[3] + c[1]*c[2]*c[4] + c[1]*c[3]*c[4] + c[2]*c[3]*c[4];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 200000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	ll cost;
	edge(int _t, ll _cost) : t(_t)
		, cost(_cost) {
	}
};
bool isPrime(int n) {

	if (n == 1) return false;
	for (ll i = 2; i * i <= n; i++)
	{
		if (n % i == 0) return false;
	}
	return true;
}
void Solve() {
	
	int k, t;
	cin >> k >> t;
	int a[105];
	for (size_t i = 0; i < t; i++)
	{
		cin >> a[i];
	}

	int bef = -1;
	int res = 0;
	for (size_t i = 0; i < k; i++)
	{
		int ma = -1;
		int now = -1;
		for (size_t j = 0; j < t; j++)
		{
			if (bef != j && a[j] > 0) {
				if (ma < a[j]) {
					now = j;
					ma = a[j];
				}
			}
		}

		if (ma == -1) {
			res = a[bef];
			break;
		}

		a[now]--;
		bef = now;
	}

	cout << res << endl;
}
int main() {
	Solve();
	return 0;
}



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

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define output_to_error freopen("error.txt" , "w" ,stderr)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

int arr[4][4];
bool f[4][4];

int main()
{
	#ifdef LOCAL
        input_from_file;
        output_to_file;
        output_to_error;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	for(int i = 1 ; i <= 3 ; ++i)
		for(int j = 1 ; j <= 3 ; ++j)
			cin >> arr[i][j];
	int n, x ; cin >> n ; 
	for(int k = 1 ; k <= n ; ++k)
	{
		cin >> x ;
		for(int i = 1 ; i <= 3 ; ++i)
			for(int j = 1 ; j <= 3 ; ++j)
				if(x == arr[i][j]) 
					{
						f[i][j] = 1;
						goto loop;
					}
		loop : ;
	}
	for(int i = 1 ; i <= 3 ; ++i)
		if(f[i][1])
		{
			if(f[i][2] && f[i][3])
				return cout << "Yes" , 0;
		}
	for(int i = 1 ; i <= 3 ; ++i)
		if(f[1][i])
		{
			if(f[2][i] && f[3][i])
				return cout << "Yes" , 0;
		}
	if(f[1][1] && f[2][2] && f[3][3])
		return cout << "Yes" , 0;
	if(f[3][1] && f[2][2] && f[1][3])
		return cout << "Yes" , 0;

	return cout << "No" , 0;
}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    string s;
    cin >> s;

    // 処理
    vector<char> c;
    for (int i = 97; i < 123; i++) {
        if (count(all(s), (char)i) == 0) c.push_back((char)i);
    }
    sort(all(c));
    // 出力
    if (c.size() == 0)
        cout << "None" << endl;
    else
        cout << c[0] << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s;
    cin >> s;
    int m = 753, ans = 1e9;
    REP(i,s.length()-2){
        string t = s.substr(i, 3);
        int x = stoi(t);
        ans = min(ans, abs(x - m));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
a = [0] + list(map(int,input().split()))

journey = [1]

for i in range(2*N+1000):
    nxt = a[journey[-1]]
    journey.append(nxt)

if K <= N:
    print(journey[K])
    exit()

loop_start = N-1
loop_end   = N
 
while(journey[loop_start] != journey[loop_end]):
    loop_start -= 1
    
period = loop_end - loop_start

K %= period
while K < N:
  K += period

print(journey[K])


Measured memory_bytes: 32232
function Main(input){
    const num = input.split(' ').map(Number);
    let count = 0;
    for(let i=num[0]; i<=num[1]; i++){
        if(i % num[2] == 0) count++;
    }
    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    for (int A = 1; A <= N; A++) {
        ans += (N - 1) / A;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3632
A,B,C=(int(i) for i in input().split())
counter=0

#BとCから
if C>=B:
  counter+=B*2
  C=C-B
  B=0
  if C>A:
    counter+=A+1
  else:
    counter+=C
  
else:
  counter+=C*2
  B-=C
  C=0
  counter+=B
  
print(counter)


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

void solve(string s, int k) {
    if(s.size() == N) {
        cout << s << '\n';
        return;
    } else {
        for(int i=0; i<=k+1; ++i) {
            solve(s + (char)((int)'a' + i), max(k, i));
        }
    }
}

int main() {
    cin >> N; solve("a", 0);
}

Measured memory_bytes: 1536
#include<stdio.h>

int main(void){
    int a,b,i;
    scanf("%d%d",&a,&b);
    if(a<b){
        for(i=0;i<b;i++)
        printf("%d",a);
    }
    else{
        for(i=0;i<a;i++)
        printf("%d",b);
    }
    return 0;
}


Measured memory_bytes: 128
alphabetlist=['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=input()
T=input()
Sdata=[[] for i in range(26)]
for i in range(0,len(S)):
    Sdata[alphabetlist.index(S[i])].append(i)
ans=0
for i in range(len(T)):
    if Sdata[alphabetlist.index(T[i])]==[]:
        ans=-1
if ans!=-1:
    sequence=0
    number=-1
    for i in range(0,len(T)):
        x=T[i]
        n=alphabetlist.index(x)
        start=0
        end=len(Sdata[n])-1
        while end-start>1:
            test=(end+start)//2
            if Sdata[n][test]>number:
                end=test
            else:
                start=test
        if Sdata[n][start]>number:
            number=Sdata[n][start]
        elif Sdata[n][end]>number:
            number=Sdata[n][end]
        else:
            sequence+=1
            number=Sdata[n][0]
    ans=sequence*len(S)+number+1
print(ans)

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

using namespace std;

void kun (int x){
    if(x >= 400 && x<= 599){
        cout << "8";
    } else if (x >= 600 && x<= 799){
        cout << "7";
    } else if (x >= 800 && x<= 999){
        cout << "6";
    } else if (x >= 1000 && x<= 1199){
        cout << "5";
    } else if (x >= 1200 && x<= 1399){
        cout << "4";
    } else if (x >= 1400 && x<= 1599){
        cout << "3";
    } else if (x >= 1600 && x<= 1799){
        cout << "2";
    } else if (x >= 1800 && x<= 1999){
        cout << "1";
    }
}

int main (){

    int n; 
    cin >> n;

    kun(n);

return 0;
}

Measured memory_bytes: 3612
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
vector<int> O[10];
P sg[10];
int d[1005][1005]={};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int fi[1005][1005];
int ans[1005][1005]={};
bool graph[55][55];
bool visited[55];
int a[55],b[55];
bool num[10];
bool ok(int x){
    while(x){
        if(num[x%10])return false;
        x/=10;
    }
    return true;
}

signed main(){
    int n,k,a;cin>>n>>k;
    rep(i,10)num[i]=false;
    rep(i,k){
       cin>>a;num[a]=true;
    }
    while(!ok(n))n++;
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll k = t.size();
    
    vector<string> v;  // 鍵の候補を入れるvector
    rep(i, n-k+1) {
        string u = s;  // sをuにコピーする
        bool ok = true;  // u[i]からu[i+k-1]文字目にtを一致させられるならtrue
        exrep(j, i, i+k-1) {
            if(u[j] != '?' && u[j] != t[j-i]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            exrep(j, i, i+k-1) {
                u[j] = t[j-i];
            }
            rep(i, n) {
                if(u[i] == '?') {
                    u[i] = 'a';
                }
            }
            v.pb(u);
        }
    }

    if(v.size() == 0) {
        out("UNRESTORABLE");
    }
    else {
        sort(all(v));
        out(v[0]);
    }

    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
const int NINF=-1e9-5;
int main()
{
	int n;scanf("%d",&n);
	vector<int> c(3,0);
	vector<int> dp(3,0);
	for(int i=0;i<n;i++)
	{
		for(int& i:c)			scanf("%d",&i);
		vector<int>dp0(3,0);
		
		for(int i=0;i<3;i++){// i represents the already maximised solution for the previous day
			for(int j=0;j<3;j++){
				if(i!=j){//j represents the current day cost to maximise
					dp0[j]=max(dp0[j],dp[i]+c[j]);
				}
			}
		}
		dp=dp0;
		dp0.clear();
	}
	
	cout<<max({dp[0],dp[1],dp[2]})<<endl;
	return 0;
}


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

int main(){

  int n, c, k;
  cin >> n >> c >> k;

  int num[n+5];
  for(int i=0; i<n; i++) cin >> num[i];
  sort(num, num+n);

  int ans = 0;
  int left = 0, right = 0;
  while(left < n){
    ans++;

    while(right+1 < n && num[right+1] <= num[left]+k && (right+1 - left+1 <= c))
      right++;
    
    left = right+1;
    right = left;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
function Main(input) {
    input = input.split(" ");
    var a = parseInt(input[0]);
    var b = parseInt(input[1]);
    var c = parseInt(input[2]);

    if (a < b && b < c) {
       console.log ("Yes")
    }else {
       console.log("No") 
    }

    
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug() {
    var input = document.getElementById("input").value;
    Main(input);
}

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15352
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

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

  map<int, int> a_map;
  rep(i, N) { int a; cin >> a; a_map[a]++; }
  int result=0;
  for (auto x: a_map) { 
    if (x.first>x.second) result += x.second;
    else result += x.second - x.first;
  }
  cout << result << endl;
  return 0;
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

void printv(vector<auto> const& s) {
  REP(i, s.size()) {
    cout << s[i] << endl;
  }
}

void print(auto const s) {
  cout << s << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  int mean = 0;
  vi a(n);
  REP(i, n) {
    cin >> a[i];
    mean += a[i];
  }
  REP(i, n) {
    a[i] *= n;
  }
  P p;
  p.fi = abs(mean - a[0]);
  p.se = 0;
  FOR(i, 1, n) {
    if(p.fi > abs(mean - a[i])) {
      p.fi = abs(mean - a[i]);
      p.se = i;
    }
  }

  print(p.se);
}


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

int main()
{
    int n, k, ans = -1;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &&e : v)
        cin >> e;
    for (int a = 0; a <= k; a++)
    {
        for (int b = 0; b <= k - a; b++)
        {
            if (a + b > n)
                break;
            int sum = 0;
            vector<int> tmp;
            tmp.reserve(n);
            for (int i = 0; i < a; i++)
            {
                tmp.emplace_back(v[i]);
            }
            for (int i = n - 1; i >= n - b; i--)
            {
                tmp.emplace_back(v[i]);
            }
            sort(begin(tmp), end(tmp));

            int m = k - a - b;
            for (auto &p : tmp)
            {
                if (m <= 0)
                    break;
                if (p < 0)
                {
                    p = 0;
                    m--;
                }
            }
            ans = max(ans, accumulate(begin(tmp), end(tmp), 0));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#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;
	cin >> N;
	vector<int> d(N);
	rep(i, N) cin >> d[i];
	int ans = 0;
	for (int i = 0; i < N-1;i++){
		for (int j = i+1; j < N; j++){
			ans += d[i]*d[j];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
import numpy as np
import math
pi = math.pi
a,b, h, m = map(int, input().split())
hkakudo = h*2*pi/12 + m*2*pi/720
mkakudo = m*2*pi/60
theta = abs(hkakudo-mkakudo)
print(np.sqrt(a**2 + b**2 - 2*a*b*np.cos(theta)))

Measured memory_bytes: 27196
#include <cstdio>
#include <algorithm>

int n;
int f[100];
int p[100][11];
long long int ans = -1e10;

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; ++i)
		for(int j=0; j<10; ++j){
			int t;
			scanf("%d", &t);
			f[i] += t << (9 - j);
		}
/*	for(int i=0; i<n; ++i)
		printf("%d\n", f[i]);
*/	for(int i=0; i<n; ++i)
		for(int j=0; j<11; ++j)
			scanf("%d", &p[i][j]);
	for(int i=1; i<(1<<10); ++i){
		long long int pr = 0;
		for(int j=0; j<n; ++j){
			int t = 0;
			for(int k=0; k<10; ++k)
				if((((i >> k) & 1) == 1) && (((f[j] >> k) & 1) == 1))
					++t;
			pr += p[j][t];
		}
		ans = std::max(ans, pr);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }
  return 0; }

int main(void){
  ll a,b,c,k; cin >> a >> b >> c >> k;
  ll ans = 0;
  if(a > k){
    cout << k << endl;
  }
  else if(a+b >= k){
    cout << a << endl;
  }
  else cout << a-(k-a-b) << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
using namespace std;
int main (int argc, const char * argv[])
{
    double r;
    double pi;
    pi=3.14159265358979323;
    cin >>r;
    printf("%.6lf  ",r*r*pi);
    printf("%.6lf  ",2*r*pi);
    

    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<int>>s(m);
    REP(i,m){
        int k;
        cin >> k;
        s[i].resize(k,0);
        REP(j,k){
            cin >> s[i][j];
        }
    }
    vector<int>p(m,0);
    REP(i,m) cin >> p[i];
    int cnt= 0;
    for(int i=0; i<(1<<n); i++){
        int light[n]= {0};
        for(int j=0; j<n; j++){
            if(i & 1<<j){
                light[j]= 1;
            }
        }
        int f= 1;
        REP(j,m){
            int cc= 0;
            REP(k,s[j].size()){
                if(light[s[j][k]-1]==1) cc++;
            }
            if(cc%2!=p[j]){
                f= 0;
                break;
            }
            if(f==0) break;
        }
        if(f) cnt++;
    }
    cout << cnt << endl;
}


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

int main(){
	string s;cin >> s;
	for(int mask=0;mask<(1<<3);++mask){
		int sum=s.at(0)-'0';
		for(int i=0;i<3;++i){
			if(mask & (1<<i)){
				sum+=s.at(i+1) - '0';
			}
			else{
				sum-=s.at(i+1) - '0';
			}
		}
		if(sum==7){
			string ans="";
			ans+=s.at(0);
			for(int i=0;i<3;++i){
				if(mask & (1<<i)) ans+='+';
				else ans+='-';
				ans+=s.at(i+1);
			}
			ans+="=7";
			cout << ans << endl;
			break;
		}
	}
}

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

void add_list(vector<vector<int>> &S, char C, int n){
  char moji = 'a';
  for (int i = 0; i < 26; i++){
    if (C == moji) S.at(i).push_back(n);
    moji++;
  }
}

void add_f(vector<vector<int>> &S_list, char C, int &N){
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < S_list.at(i).size(); j++){
      S_list.at(i).at(j) = S_list.at(i).at(j) + 1;
    }
  }
  add_list(S_list, C, 0);
  N++;
}

char conv(int i){
  char C = 'a';
  for (int j = 0; j < 26; j++){
    if (i == j) return C;
    C++;
  }
}

int main() {
  string S;
  int Q;
  cin >> S >> Q;
  int T, F;
  char C;
  
  int N = S.size();
  vector<vector<int>> S_list(26);
  for (int i = 0; i < N; i++){
    add_list(S_list, S.at(i), i);
  }
  
  int rev = 0;
  int n_max = N - 1;
  int n_min = 0;
  for (int i = 0; i < Q; i++){
    cin >> T;
    if (T == 1){
      rev++;
    }
    if (T == 2){
      cin >> F >> C;
      if ((F + rev) % 2 == 1){
        n_min--;
        add_list(S_list, C, n_min);
      }
      else if ((F + rev) % 2 == 0){
        n_max++;
        add_list(S_list, C, n_max);
      }
    }
  }
  
  N = n_max - n_min + 1;
  string Sa(N, 'a');
  if (rev % 2 == 0){
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < S_list.at(i).size(); j++){
        Sa.at(S_list.at(i).at(j) - n_min) = conv(i);
      }
    }
  }
  else{
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < S_list.at(i).size(); j++){
        Sa.at(N - (S_list.at(i).at(j) - n_min) - 1) = conv(i);
      }
    }
  }
  
  cout << Sa << endl;
}

Measured memory_bytes: 2688
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <bitset>

using namespace std;
typedef long long LL;
const int maxn = 200005;
const int mod = 1e9+7;

int x[maxn],v[maxn],ord[maxn],ord2[maxn],n;
int dp[maxn],sum[maxn],L[maxn],R[maxn];
void modify(int x,int v) {for (int i=x+1;i<=n+1;i+=i&-i) (sum[i]+=v)%=mod;}
int query(int x) {int res=0;for (int i=x;i;i-=i&-i) (res+=sum[i])%=mod;return res;}
int query(int l,int r) {return (query(r+1)-query(l))%mod;}
bool compx(int a,int b) {return x[a]<x[b];}
bool compv(int a,int b) {return v[a]<v[b];}
int main()
{
	#ifdef Amberframe
		freopen("agc015e.in","r",stdin);
		freopen("agc015e.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d %d",&x[i],&v[i]),ord[i]=ord2[i]=i;
	
	sort(ord+1,ord+n+1,compx);
	sort(ord2+1,ord2+n+1,compv);
	R[ord[1]]=v[ord[1]];
	L[ord[n]]=v[ord[n]];
	for (int i=2;i<=n;i++) R[ord[i]]=max(R[ord[i-1]],v[ord[i]]);
	for (int i=n-1;i>=1;i--) L[ord[i]]=min(L[ord[i+1]],v[ord[i]]);
	
	dp[0]=1;modify(0,1);
	for (int p=1,q=1,i=1;i<=n;i++)
	{
		while (v[ord2[p]]!=L[ord[i]]) p++;
		while (v[ord2[q]]!=R[ord[i]]) q++;
		
		int w=query(p-1,q);
		dp[q]=(dp[q]+w)%mod;
		modify(q,w);
	}
	printf("%d",dp[n]<0?dp[n]+mod:dp[n]);
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 100000000000007
using namespace std;
using pii=pair<int,int>;

int main(){
    int64_t n;
    cin>>n;
    int64_t ans=0;
    for(int64_t l=1;l<=n;l++){
        int64_t a=n/l;
        ans+=l*a*(a+1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>

using namespace std;

typedef long long lli;

const int DIGITS = 1000;
const int BASE = 100000;
const int BD = 5;

class BigNum{
  lli val[DIGITS], tmp[DIGITS];
  int dig;
public:
  BigNum(){
    dig = 1;
    memset(val, 0, sizeof(val));
  }
  BigNum(lli x){
    dig = 0;
    for(int i=0;i<DIGITS;++i){
      if(x == 0) val[i] = 0;
      else{
        ++dig;
        val[i] = x % BASE;
        x /= BASE;
      }
    }
  }

  void operator + (const lli x){
    val[0] += x;
    for(int i=0;i<DIGITS;++i){
      val[i+1] += val[i] / BASE;
      val[i] %= BASE;
      if(val[i]) dig = i + 1;
    }
  }

  void operator * (const lli x){
    for(int i=0;i<DIGITS;++i) val[i] *= x;
    for(int i=0;i<DIGITS;++i){
      val[i+1] += val[i] / BASE;
      val[i] %= BASE;
      if(val[i]) dig = i + 1;
    }
  }

  void print(){
    vector<char> t;
    for(int i=0;i<dig;++i){
      for(int j=0;j<BD;++j){
        t.push_back(val[i]%10 + '0');
        val[i] /= 10;
      }
    }
    while(t.back() == '0') t.pop_back();
    reverse(t.begin(), t.end());
    for(int i=0;i<t.size();++i) cout << t[i];
    cout << endl;
  }
};

main(){
  int n;
  cin >> n;
  BigNum x = BigNum(1);
  for(int i=2;i<=n+1;++i) x * i;
  x + 2;
  x.print();
  for(int i=0;i<n;i++) cout << i+2 << endl;
}

Measured memory_bytes: 1252
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n];
        for(int i=0; i<n; i++){
            d[i] = sc.nextInt();
        }
        
        int ans = 0;
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                ans += d[i]*d[j];
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844