akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int num[100010]={};
int L[100010]={};
int R[100010]={};

int main(){
    int N,M;


    int min=2000000;
    int max=-2000000;
    cin>>N>>M;

bool no_flag=false;
    for(int i=0;i<M;i++){
            cin>>L[i]>>R[i];
            if(R[i]<max||L[i]>min){
                no_flag=true;
                break;
            }


            if(max<L[i])max=L[i];
            if(min>R[i])min=R[i];

    }
    if(no_flag)cout<<0;
    else cout<<min-max+1;

  /*  int sum=0;
    for(int i=1;i<=N;i++){
        bool flag_all=true;
        for(int j=0;j<M;j++){
            if(i<L[j]||i>R[j]){
                flag_all=false  ;
                break;
            }
        }


        if(flag_all)sum++;
    }
    cout<<sum;*/
  /*  for(int i=0;i<M;i++){
        int L,R;
        cin>>L>>R;

        for(int j=L;j<=R;j++){
            num[j]++;
        }

    }



    int sum=0;
    for(int i=1;i<=N;i++){
        if(num[i]==M)sum++;
    }
    cout<<sum;*/
    return 0;
}

Measured memory_bytes: 1024
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
d = c.most_common()

ans = 0
for i in range(len(d)):
  num = d[i][0]
  cnt = d[i][1]
  if num > cnt:
    ans += cnt
  elif num < cnt:
    ans += cnt-num
print(ans)

Measured memory_bytes: 25856
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{
    auto s = readln.chomp;
    auto abc = "ABC";
    auto mod = 10 ^^ 9 + 7;

    long[][4] dp;
    foreach (ref row; dp)
        row = new long[](s.length + 1);

    dp[3][$ - 1] = 1;

    foreach_reverse (i; 0 .. s.length)
        if (s[i] == '?')
            dp[3][i] = dp[3][i + 1] * 3 % mod;
        else
            dp[3][i] = dp[3][i + 1];

    foreach_reverse (i; 0 .. s.length)
        foreach (j; 0 .. 3)
        {
            if (s[i] == '?')
                dp[j][i] = dp[j][i + 1] * 3 % mod;
            else
                dp[j][i] = dp[j][i + 1];
            if (s[i] == '?' || s[i] == abc[j])
                dp[j][i] = (dp[j][i] + dp[j + 1][i + 1]) % mod;
        }

    // foreach (r; dp)
    //     writeln(r);

    dp[0][0].writeln;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int A, B;
    cin >> A >> B;
    if(A >= 13) cout << B << endl;
    else if(A >= 6) cout << B / 2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
swap = 0
while True:
    _continue = False
    for i in range(N - 1):
        if A[i] > A[i + 1]:
            swap += 1
            _continue = True
            A[i], A[i + 1] = A[i + 1], A[i]
    if not _continue:
        break
print(*A)
print(swap)



Measured memory_bytes: 5604
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (Scanner s = new Scanner(System.in)) {
            final int K = s.nextInt();
            final String S = s.next();
            System.out.println(S.length() > K ? S.substring(0, K) + "..." : S);
        }
    }
}


Measured memory_bytes: 38708
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	
	vector<int> h(n);

	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		h[i] = tmp;
	}

	std::sort(h.begin(), h.end(), [](int a, int b) {return a < b;});

	int num = INT_MAX;

	for (int i = 0; i < n - k + 1; i++) {
		int tmp = h[i + k - 1] - h[i];
		if (num > tmp) num = tmp;
	}

	cout << num << endl;
	
	return 0;
}

Measured memory_bytes: 640
N, L = map(int, input().split())

ans = 0
s = N*L + N*(N-1)//2
dif = int(1e+9)
for i in range(N):
    tmp = 0
    for j in range(N):
        if j != i:
            tmp += L+j
    if abs(s-tmp) < dif:
        ans = tmp
        dif = abs(s-tmp)

print(ans)

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int h, w, i, j;
	cin >> h >> w;
	if (h % 3 == 0 || w % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = min(w, h);
	for (i = max(h / 3 - 5, 1); i < min(h / 3 + 5, h); i++) {
		for (j = max(w / 2 - 5, 1); j < min(w / 2 + 5, w); j++) {
			ll a, b, c;
			a = w*i;
			b = (h - i)*j;
			c = (h - i)*(w - j);
			ll M = max(a, max(b, c));
			ll m = min(a, min(b, c));
			ans = min(ans, M - m);
		}
	}
	for (i = max(w / 3 - 5, 1); i < min(w / 3 + 5, w); i++) {
		for (j = max(h / 2 - 5, 1); j < min(h / 2 + 5, h); j++) {
			ll a, b, c;
			a = h*i;
			b = (w - i)*j;
			c = (w - i)*(h - j);
			ll M = max(a, max(b, c));
			ll m = min(a, min(b, c));
			ans = min(ans, M - m);
		}
	}
	cout << ans << endl;
}

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

template <class T>
using lim = numeric_limits<T>;

const int maxn = 1e5;

ll a[maxn];
ll prefix[maxn];
int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	
	int N, M;
	cin >> N >> M;
	
	for (int i = 0; i < N; i++){
		cin >> a[i];
		if (i==0) prefix[i] = a[i]%M;
		else prefix[i] = (prefix[i-1]+a[i])%M;
	}
	
	unordered_map<int, int> counters;
	for (int i = 0; i < N; i++){
		counters[prefix[i]]++;
	}
	
	ll total = counters[0];
	for (auto it : counters){
		ll n = it.second;
		total += (n*(n-1))/2;
	}
	
	cout << total << endl;
}



Measured memory_bytes: 5260
#include <stdio.h>
#include <algorithm>
#include <list>
using namespace std;
list <int> to[9];
int arr[9];
int node,edge;
int ans=0;
int where(int in,int what)
{
    for (list<int>::iterator it = to[in].begin();it!=to[in].end();it++)
    {
        if (*it == what)
        {
            return 1;
        }
    }
    return 0;
}
void calcu(int arr[])
{
    for (int i=1;i<node;i++)
    {
        if (where(arr[i],arr[i+1])==0)
        {
            return;
        }
    }
    ans++;
    return;
}
main()
{
    scanf("%d %d",&node,&edge);
    for (int i=0;i<edge;i++)
    {
        int one,two;
        scanf("%d %d",&one,&two);
        to[one].push_back(two);
        to[two].push_back(one);
    }
    for (int i=1;i<=node;i++)
    {
        arr[i]=i;
    }
    do
    {
        calcu(arr);
    }
    while (next_permutation(arr+2,arr+node+1));
    printf("%d",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long s[365][26]; 
int main() {
  int d;
  cin >>d;
  //int d=365;
  vector<int>c(26);
  vector<int>last(26,0);
  //vector<int>hinichi(26,0);
  long long wa=0;
  for(int i=0;i<26;i++){
    cin>>c[i];
    wa+=c[i];
  }
  for(int i=0;i<d;i++){
    for(int j=0;j<26;j++){
      cin>>s[i][j];
    }
  }
  vector<int>t(d);
  for(int i=0;i<d;i++)cin>>t[i];
  long long kotae=0;
  int hinichi=0;
  long long hikukazu=0;
  for(int i=0;i<d;i++){
    long long atai=0;
    for(int j=0;j<26;j++){
      if(atai<s[i][j]){
        atai=s[i][j];
        hinichi=j;
      }
    }
    hikukazu+=wa-c[hinichi]*(i+1-last[hinichi]);
    last[hinichi]=i+1;
    kotae+=atai-hikukazu;
    //cout<<wa<<" "<<c[hinichi]<<" "<<hikukazu<<" "<<s[i][hinichi]<<endl;
    cout<<hinichi+1<<endl;
  }
  return 0;
}
  


Measured memory_bytes: 3704
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		char s[] = in.readString().toCharArray(); 
		int ans = 0; 
		for(int i = 0; i<s.length-1; i++) {
			if(s[i] == '0') {
				if(s[i+1] == '1') {
					continue; 
				}
				else {
					s[i+1] = '1'; 
					ans++; 
				}
				
			}
			else {
				if(s[i+1] == '0') {
					continue; 
				}
				else {
					s[i+1] = '0';
					ans++; 
				}
			}
		}
		System.out.println(ans); 
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, days = 0, m, c = 0, j, i;
	bool is;
	cin >> n;
	vvi tm(n + 1, vi(n - 1));
	vi pos(n + 1), match;
	for (i = 1; i <= n; i++) {
		for (j = 0; j < n - 1; j++)
			cin >> tm[i][j];
	}
	m = (n * (n - 1)) / 2;
	while (c < m) {
		match = vi(n + 1);
		is = false;
		for (i = 1; i <= n; i++) {
			if (pos[i] < n - 1) {
				j = tm[i][pos[i]];
				if (pos[j] < n - 1 and i == tm[j][pos[j]] and match[i] == 0 and match[j] == 0) {
					pos[i]++, pos[j]++;
					match[i] = 1, match[j] = 1;
					c++;
					is = true;
				}
			}
		}
		if (!is)
			break;
		days++;
	}
	if (c < m)
		cout << -1 << "\n";
	else
		cout << days << "\n";
	return 0;
}

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


int main() {
	
	int N;
	cin >> N;
	set<char> s;
	for(int i=0; i<N; i++){
		char t;
		cin >> t;
		s.insert(t);
	}
	if(s.count('Y')) cout << "Four" << endl;
	else cout << "Three" << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
 int n,c;
 n=0;
 c=0;
 while(1){
  c = c+1;
  scanf("%d",&n);
  if(n == 0) break;
  printf("Case %d: %d\n",c,n);
 }
return 0;
}

Measured memory_bytes: 600
'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' ').map(Number))

  const N = input[0][0]
  const B = input[1]
  // B.push(10e6)
  const A = [...Array(N)].map(v => 0)

  A.push(B[0])
  for (let i = 0; i < N - 2; i++) {
    A[i] = Math.min(B[i], B[i + 1])
  }
  A.push(B[N - 2])
  console.log(A.reduce((a, b) => a + b))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(int a, int b){
   return b ? GCD(b, a%b) : a;
}

int LCM(int a, int b){
   return (a * b)/(GCD(a, b));
}

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

int main(){
   string s;
   cin >> s;

   int cnt = 0;
   for(int i = 0; i < s.size(); i++){
      for(int j = 0; j < s.size(); j++){
         if(s[i] == s[j] and i != j){
            cnt++;
         }
      }
   }

   cout << (cnt == 4 ? "Yes" : "No") << endl;

   return 0;
}

Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        String T = sc.nextLine();
        PriorityQueue<String> q = new PriorityQueue<String>();

        for (int i = S.length() - T.length(); i >= 0; i--) {
            String sub = S.substring(i, i + T.length());
            int k;
            int cnt = 0;
            for (k = 0; k < T.length(); k++) {
                if (sub.charAt(k) == '?') {
                    cnt++;
                    continue;
                }
                if (sub.charAt(k) != T.charAt(k))
                    break;
            }
            if (k == T.length()) {
                String ans = S.substring(0, i).replace('?', 'a');
                ans += T;
                ans += S.substring(i + T.length()).replace('?', 'a');;
                q.add(ans);
            }
        }
        if (q.peek() != null) {
            System.out.println(q.peek());
        } else {
            System.out.println("UNRESTORABLE");
        }
    }
}

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

int main(){
  int N,M;
  cin>>N>>M;
  int L,R;
  int Lm=1,Rm=N;
  for(int i=0;i<M;i++){
    cin>>L>>R;
    Lm=max(Lm,L);
    Rm=min(Rm,R);
  }
  cout<<max(0,Rm-Lm+1)<<endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
map<ll,ll> p;
ll a[200005];
int main(){
    ll n,ans=0;
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    p[1+a[1]]++;
    for(ll i=2;i<=n;i++){
        ans+=p[i-a[i]];
        p[i+a[i]]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 27828
#include<string>
#include<iostream>
#include<cctype>
#include<algorithm>

int main() {
	std::string s;
	std::cin >> s;

	auto b = s[0] == 'A'
		&& std::count(std::begin(s) + 2, std::end(s)-1, 'C') == 1;

	
	if (b) {
		b &=
			s.size()-2
			==
			std::count_if(
				std::begin(s)
				,std::end(s)
				, [](char c) {
					return std::islower(c)!= 0;
				}
			);
	}
	
	std::cout << (b ? "AC" : "WA") << "\n";

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;



class Main{


    public static void main(String[] a){


        Scanner sc = new Scanner(System.in);

        int j = sc.nextInt();

        for(int i = 0; i < j; i++){


        	int[] d = new int[3];


        	for(int k = 0; k < 3; k++){
	        	d[k] = sc.nextInt();
	        }

        	Arrays.sort(d);

        	if(d[2] * d[2] == d[0] * d[0] + d[1] * d[1]){
        		System.out.println("YES");
        	}else{
        		System.out.println("NO");
        	}

        }

        sc.close();

   }


}

Measured memory_bytes: 33172
#include <cstdio>

int a, b, c, d;

int main()
{
    scanf("%d%d%d%d", &a, &b, &c, &d);

    if (a + b > c + d) {
        printf("Left\n");
    } else if (a + b == c + d) {
        printf("Balanced\n");
    } else {
        printf("Right\n");
    }

    return 0;
};

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

int main(){
    int a,b;
    cin>>a>>b;
    if(b==1){
        cout<<0;
        return 0;
    }
    int sum=a;
    int cnt=1;
    while(sum<b){
        sum+=(a-1);
        cnt+=1;
    }
    cout<<cnt;
}


Measured memory_bytes: 3584
//coded by: pranonrahman-------------------------------------
//-----------------------------------------------------------
//-----------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;


#define O_O ios_base::sync_with_stdio(0); cin.tie(NULL)
#define endl '\n'
#define PI acos(-1.0)
#define CASE(n) cout << "Case " << n << ": "
#define CASE_(n) cout << "Case " << n << endl
#define FIXED(n) cout << fixed << setprecision(n)
#define MOD 1000000007

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


int main()
{
    O_O;
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
#endif
    long long t=1;
    //cin >> t;
    long long T = t;
    while(t--)
    {
        //write your code here
        long long n,a,b;
        cin >> n >>  a >> b;
        if(n==1)	
        {
        	if(a==b)	cout << 1 << endl;
        	else 		cout << 0 << endl;
        }
        else 
        {
        	if(a==b)	cout << 1 << endl;
        	else if(a<b)
        	{
        		cout << (b-a)*(n-2) +1 <<endl;
        	}
        	else 	cout << 0 << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 107;
int n, m, cnt, c1, c2, g1, g2;
int a[N], b[N], mark[N], t[N];
int main() {
#ifndef ONLINE_JUDGE
#endif
	n = gi(), m = gi();
	rep(i, 1, m) {
		t[i] = gi();
		if(t[i] & 1) {
			mark[i] = 1;
			if(!g1) g1 = t[i];
			else g2 = t[i];
			++cnt;
		}
	}
	if(m == 1) {
		if(n == 1)
			printf("1\n1\n1\n");
		else
			printf("%d\n2\n%d 1\n", t[1], t[1] - 1);
		return 0;
	}
	if(cnt > 2) return puts("Impossible"), 0;
	if(g1) a[++c1] = g1;
	rep(i, 1, m) if(!mark[i]) a[++c1] = t[i];
	if(g2) a[++c1] = g2;
	
	if(a[1] > 1)
		b[++c2] = a[1] - 1;
	rep(i, 2, c1 - 1) b[++c2] = a[i];
	b[++c2] = a[c1] + 1;
	
	rep(i, 1, c1) printf("%d%c", a[i], i == c1 ? '\n':' ');
	printf("%d\n", c2);
	rep(i, 1, c2) printf("%d%c", b[i], i == c2 ? '\n':' ');
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();

		int[] p = new int[n];
		int[] pSum = new int[n + 1];
		pSum[0] = 0;

		int i;
		for(i = 0; i < n; i++) {
			p[i] = scan.nextInt();
			pSum[i + 1] = pSum[i] + p[i];
		}

		double max = Double.MIN_VALUE;
		int index = 0;
		for(i = k; i < n + 1; i++) {
			double temp = pSum[i] - pSum[i - k];
			if(temp > max) {
				max = temp;
				index = i;
			}
		}

		double ans = 0;
		for(i = 0; i < k; i++) {
			double temp = pSum[index - i] - pSum[index - i - 1];
			ans += (temp + 1) * (temp / 2) / temp;
		}
		System.out.println(ans);
	}
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; ++i)
        cin >> h[i];
    long long dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for (int i = 2; i<n; ++i)
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int main() {
	//code

	    int h,w;
	    cin>>h>>w;
	    int arr[h][w];
	    char ch;
	    for(int i=0;i<h;i++)
	    {
	        for(int j=0;j<w;j++)
            {
                cin>>ch;
                if(ch=='.')
                    arr[i][j]=1;
                else
                    arr[i][j]=0;

            }

	    }
	    ll dp[h][w];
	    memset(dp,0,sizeof(dp));
	    dp[0][0]=1;
	    for(int i=1;i<h;i++)
        {
            if(arr[i][0]==0)
                break;
            dp[i][0]=dp[i-1][0];

        }

	    for(int i=1;i<w;i++)
        {
            if(arr[0][i]==0)
                break;
            dp[0][i]=dp[0][i-1];
        }
        for(int i=1;i<h;i++)
        {

            for(int j=1;j<w;j++)
            {
                if(arr[i][j])
                dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;

            }
        }
        cout<<dp[h-1][w-1]<<endl;









	}



Measured memory_bytes: 11904
#include<bits/stdc++.h>
#include<unordered_map>	
#include<unordered_set>
#define pb emplace_back
#define rt(v) return cout<<v,0
#define sz(v) (int)(v.size())
#define all(a) a.begin(),a.end()
#define endl '\n'
#define space " "
typedef long long ll;
typedef unsigned long long ull;
const int N = 10 + 1e5;
const int mod = 1e9 + 7;
/*

███╗   ███╗███████╗███╗   ███╗███████╗    ██╗      ██████╗ ██████╗ ██████╗
████╗ ████║██╔════╝████╗ ████║██╔════╝    ██║     ██╔═══██╗██╔══██╗██╔══██╗
██╔████╔██║█████╗  ██╔████╔██║█████╗      ██║     ██║   ██║██████╔╝██║  ██║
██║╚██╔╝██║██╔══╝  ██║╚██╔╝██║██╔══╝      ██║     ██║   ██║██╔══██╗██║  ██║
██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║███████╗    ███████╗╚██████╔╝██║  ██║██████╔╝
╚═╝     ╚═╝╚══════╝╚═╝     ╚═╝╚══════╝    ╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝

*/

using namespace std;
void Ferrari() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main() {
	Ferrari();
	int d, a; cin >> d >> a;
	int s = 0;
	for (int i = 0; i < a; ++i) {
		int y; cin >> y;
		s += y;
	}
	cout << (d < s ? -1 : d - s);
	return 0;
}


	


/* stuff you should look for
	* keepin sharp mind.
	* int overflow, array bounds.
	* special cases (n=1?), set tle , make sure you understand the proble correctly.
	* don`t stuck in a problem.
	* test the idea on samples.
	*/

Measured memory_bytes: 3612
n=int(input())
a0=list(map(int,input().split()))
a=[0]
a[1:1]=a0
a.append(0)
base=0
for i in range(n+1):
  base+=abs(a[i]-a[i+1])
#print(a)
#print(base)
for i in range(1,n+1):
  base0=base
  base0-=abs(a[i]-a[i-1])+abs(a[i]-a[i+1])
  base0+=abs(a[i-1]-a[i+1])
  print(base0)


Measured memory_bytes: 14048
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
#define mall (nxd*)mallxc(sizexf(nxd))
using namespace std;
typedef long long ll;
int main(void)
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=max(max(a*c,a*d),max(b*c,b*d));
	cout<<ans;
}

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

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;
    UnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
        }
    }
    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
    Abel weight(int x) { root(x); return diff_weight[x]; }
    bool issame(int x, int y) { return root(x) == root(y); }
    // weight(y) - weight(x) = w となるように merge
    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        if ((x = root(x)) == (y = root(y))) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x; diff_weight[y] = w;
        return true;
    }
    Abel diff(int x, int y) { return weight(y) - weight(x); }
};

int main() {
    int N, M; cin >> N >> M;
    UnionFind<int> uf(N);
    for (int i = 0; i < M; i++) {
        int l, r, d; cin >> l >> r >> d; --l, --r;
        if (uf.issame(l, r)) {
            int diff = uf.diff(l, r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            uf.merge(l, r, d);
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

vector<int> par;
vector<int> sze;

void makeSets(int n) {
    par.resize(n);
    sze.resize(n);
    for(int i=0; i<n; i++) {
        par[i] = i;
        sze[i] = 1;
    }
}

int find(int x) {
    if(x != par[x]) par[x] = find(par[x]);
    return par[x];
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int size(int x) {
    return sze[find(x)];
}

void unite(int xp, int yp) {
    int x = find(xp);
    int y = find(yp);
    if(x == y) return;
    if(size(x) > size(y)) {
        sze[x] += size(y);
        par[y] = x;
    } else {
        sze[y] += size(x);
        par[x] = y;
    }
}


int main() {
    long long N,M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    for(int i=0; i<M; ++i) {
        cin >> A[i] >> B[i];
        --A[i];
        --B[i];
    }
 
    makeSets(N);
    vector<long long> res(M + 1);
    res[M] = N * (N - 1) / 2;
 
    for(int i=M-1; i>=1; --i) {
        if(same(A[i], B[i])) res[i] = res[i + 1];
        else res[i] = res[i + 1] - size(A[i]) * size(B[i]);
        unite(A[i], B[i]);
    }
 
    for(int i=1; i<=M; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll a,p;
  cin >> a >> p;
  p+=a*3;
  pr(p/2);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
int n;
int fie[11][11];
pair<int,int> sxy[11];
int dx[]={2,2,2,1,1,0,0,-1,-1,-2,-2,-2};
int dy[]={-1,0,1,2,-2,2,-2,2,-2,-1,0,1};
struct state{
  int x,y,co;
  state(int x,int y,int co):x(x),y(y),co(co){}
};
void fiemake(int co){
  int x=sxy[co].first;
  int y=sxy[co].second;
  memset(fie,0,sizeof(fie));
  int fx[]={1,0,-1,0,1,-1,1,-1,0};
  int fy[]={0,1,0,-1,-1,1,1,-1,0};
  for(int i=0;i<9;i++){ 
    if(x+fx[i] < 0 || x + fx[i] >=10 || y+fy[i] < 0 || y + fy[i] >=10 ) continue;
    fie[x+fx[i]][y+fy[i]]=1; 
  }
  /*  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++) cout << fie[j][i];
    cout << endl;
    }*/
}
int solve(int x,int y){
  queue <state> q;
  q.push( state(x,y,0) );
  int co;
  while(!q.empty()){
    state p = q.front(); q.pop();
    co = p.co;
    if(co>=n) return n;
    fiemake(co);
    for(int i=0;i<12;i++){
      int nx = p.x + dx[i];
      int ny = p.y + dy[i];
      //cout << nx <<" "<< ny << endl;
      if(nx < 0 || nx >=10 || ny < 0 || ny>=10) continue;
      if(fie[nx][ny]==0) continue;
      q.push( state(nx,ny,co+1) );
      //  cout << nx <<" "<< ny << endl;
    }
    // sleep(1);
  }
  return co;
}
main(){
  while(1){
    int px,py;
    cin >> px >> py;
    if(px==0 && py==0) break;
    cin >> n;
    for(int i=0;i<n;i++) cin >> sxy[i].first >> sxy[i].second;
    int res=solve(px,py);
    if(res < n) printf("NA\n");
    else printf("OK\n");
  }
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

/*
  convert n(10-base) to res('base'-base)

  when you want to convert 150(10-base) into x(-2-base) call convert(150,2)
 */

string convert(long long n, int base){
  string res;
  if(n==0) return "0";
  long long a,b;
  int t=0;
  for(;n;t++){
    t=t&1;
    a=n/base;
    b=n-a*base;
    if(b<0&&t==0){
      b+=base; a-=1;
    }else if(t==1&&b>0){
      b-=base; a+=1;
    }
    if(b<0)b=-b;
    res=" "+res;
    res[0]=b+'0';
    n=a;
  }
  return res;
}

int main(){
  int n;
  while(cin >> n && n){
    cout << convert(n,10) << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL n, k;
  cin >> n >> k;
  LL cnt = 0;
  if (k == 0) {
    cnt=n*n;
  } else {
    REPC(b, k + 1, n) {
      LL div = n / b;
      LL first = (b - k) * div;
      cnt += first;
      LL start = b * div;
      LL bound = div * b + k;
      LL end = n;
      DUMP("  ", start, bound, end);
      LL second = (end >= bound ? end - bound + 1 : 0);
      cnt += second;
      DUMP(b, cnt, (b - k) * div, first, second);
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;

main(){
    int t1=in(),t2=in();
    ll a1=lin(),a2=lin(),b1=lin(),b2=lin();
    if(a1<b1){
        swap(a1,b1);swap(a2,b2);
    }
    if(a2>b2){
        cout<<0;return 0;
    }
    ll a=a1-b1,b=a2-b2;
    ll c=a*t1+b*t2;
    if(c>0){
        cout<<0;
    }
    else if(c==0){
        cout<<"infinity";
    }
    else{
        if(a==0){
            cout<<"infinity";
        }
        else{
            if(a*t1%(-c)==0)cout<<(a*t1/(-c))*2;
            else cout<<(a*t1/(-c))*2+1;
            // cout<<a*t1/c+1;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int m;
  cin >> m;
  if(m % 2 == 0)
  {
    if(m <= n * 4 && m >= n * 2){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int dp[31] = {};
    dp[0] = 1;
    dp[1] = 1;
    dp[2] = 2;
    rep(i, 31) if (i > 2) dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
    int n;
    while(cin >> n, n) {
        int ans = dp[n];
        // cout << ans << endl;
        ans = (ans / 10 + 365) / 365;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3004
#include <stdio.h>

int main(){
   int H, W, x, y;
   scanf("%d %d", &H, &W);

   while( H+W ){
      for(x=0; x<H ; x++){
         for(y=0; y<W; y++){
            if( (x+y) % 2 == 0 ){
               printf("#");
            }  else {
                  printf(".");
               }
         }
         printf("\n");
      }
      printf("\n");
      scanf("%d %d", &H, &W);
   }
   return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

ll c2(ll n) {
  if (n <= 2) {
    return n;
  }
  return n * (n - 1) / 2;
}

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

  int N;
  cin >> N;
  map<ll, set<ll>> L;
  map<ll, set<ll>> R;
  ll a;
  for (ll i = 1; i <= N; ++i) {
    cin >> a;
    ll l = i + a;
    ll r = i - a;

    if (L.find(l) == L.end()) {
      set<ll> s;
      s.insert(i);
      L.insert(make_pair(l, s));
    } else {
      L.at(l).insert(i);
    }

    if (r > 0) {
      if (R.find(r) == R.end()) {
        set<ll> s;
        s.insert(i);
        R.insert(make_pair(r, s));
      } else {
        R.at(r).insert(i);
      }
    }
  }

  ll ans = 0;
  for (auto const &it : L) {
    if (R.find(it.first) != R.end()) {
      ans += it.second.size() * R.at(it.first).size();
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 46644
#include <stdio.h>
int main(void)
{
int a,b;
scanf ("%d %d",&a,&b);
if (a>=-1000 && a<=1000 && b>=-1000 && b<=1000){
if (a>b){
printf ("a > b\n");
} else if(a < b){
printf ("a < b\n");
} else {
printf ("a == b\n");
}
}
return 0;
}

Measured memory_bytes: 2592
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N, M, C;
    cin >> N >> M >> C;
    int B[M], A[N][M];
    REP(i, M) cin >> B[i];
    REP(i, N) REP(j, M) cin >> A[i][j];

    int nAC = 0;
    REP(i, N) {
        int t = C;
        REP(j, M) t += A[i][j] * B[j];
        if (t > 0) nAC++;
    }
    cout << nAC << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll  long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
#define pii pair<int, int>
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */

int main(){
	int n; scanf("%d", &n);
	int a[n], prev;
	for (int i=0; i<n; ++i) scanf("%d", a+i);
	bool ans=1;
	prev = a[0]-1;
	for (int i=1; i<n; ++i) {
		if (a[i] < prev) {ans=0; break;}
		prev = max(a[i]-1, prev);
	}
	printf("%s\n", ans? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
const int INF=1e9;
ll dp[10010][20000];
void solve()
{
	int h,n;
	cin>>h>>n;
	vector<int>a(n);
	vector<int>b(n);
	rep(i,n){
		cin>>a[i]>>b[i];
	}
	int ma=*max_element(all(a));
	rep(i,n)rep(j,h+ma+1)dp[i][j]=INF;
	dp[0][0]=0;
	rep(i,n)rep(j,h+1+ma){
		dp[i+1][j]=min(dp[i][j],dp[i+1][j-a[i]]+b[i]);
	}
	ll ans=1e9;
	rep(i,ma+1)
	ans=min(ans,dp[n][h+i]);
	cout<<ans<<endl;

}

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


Measured memory_bytes: 157056
package main

// https://ja.wikipedia.org/wiki/%E3%83%9D%E3%83%A9%E3%83%BC%E3%83%89%E3%83%BB%E3%83%AD%E3%83%BC%E7%B4%A0%E5%9B%A0%E6%95%B0%E5%88%86%E8%A7%A3%E6%B3%95

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func gcd(x, y int) int {
	for {
		if x < y {
			tmp := x
			x = y
			y = tmp
		}
		if x%y == 0 {
			return y
		}
		x = x % y
	}
}

func g(x, n int) int {
	return (x*x + 1) % n
}

func getOneOfPrimeFactors(n int) int {
	x := 2
	y := 2
	d := 1
	for d == 1 {
		// fmt.Println(x, n)
		x = g(x, n)
		y = g(g(y, n), n)
		// fmt.Println(x, y)
		if x == y {
			break
		}
		d = gcd(abs(x-y), n)
	}
	if d == n-1 {
		return 1
	}
	return d
}

func appendPrimeFactors(primeFactors map[int]int, n int) {
	for i := 2; i <= n; i++ {
		for {
			if n%i != 0 {
				break
			}
			cnt, ok := primeFactors[i]
			if ok {
				primeFactors[i] = cnt + 1
			} else {
				primeFactors[i] = 1
			}
			n = n / i
		}
	}
}

func main() {
	scanner.Split(bufio.ScanWords)

	n, _ := nextInt()
	nOrig := n
	primeFactors := map[int]int{}

	for {
		// fmt.Println("n =", n)
		if n == 0 || n == 1 {
			break
		}
		f := getOneOfPrimeFactors(n)
		if f == 1 {
			appendPrimeFactors(primeFactors, n)
			break
		}
		// fmt.Printf("n=%v, f=%v\n", n, f)
		appendPrimeFactors(primeFactors, f)
		// fmt.Println(primeFactors)
		n = n / f
	}

	phi := float64(nOrig)
	nReconstructed := 1.0
	for i, primeFactor := range primeFactors {
		if primeFactor > 0 {
			// fmt.Println(i, primeFactors[i], phi)
			phi = phi * float64(i-1) / float64(i)
			nReconstructed *= math.Pow(float64(i), float64(primeFactor))
		}
		if int(nReconstructed) >= nOrig {
			break
		}
	}
	fmt.Printf("%.0f\n", phi)
}



Measured memory_bytes: 1172
#include<iostream>

using namespace std;

int main(void) {
	int a , b ,c,d[11];
	cin >> a;
	cin >> b;
	cin >> c;

	d[0] = c;

	for (int i = 1; i <= 10; i++) {
		d[i] = a*d[i - 1] - b;
		cout << d[i] <<endl;
	}

	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
Ai = list(map(int,input().split()))

A = {}

sumup = abs(Ai[0])

count = 0
while count < len(Ai)-1:
    A[(count,count+1)]=abs(Ai[count]-Ai[count+1])
    sumup += A[(count,count+1)]
    count += 1

A[(count,0)]=abs(Ai[count])
sumup += abs(Ai[-1])

temp = sumup - abs(Ai[0]) - A[(0,1)] + abs(Ai[1])
print(temp)

count = 1
while count < len(A)-1:
    temp = sumup - A[(count,count+1)]-A[(count-1,count)]+abs(Ai[count+1]-Ai[count-1])
    print(temp)
    count+=1

temp = sumup - A[(count,0)]-A[(count-1,count)]+abs(Ai[count-1])
print(temp)


Measured memory_bytes: 31416
import copy
N,M = [int(i) for i in input().split()]
l=[]
for i in range(N):
    tmp = [int(j) for j in input().split()]
    l.append(tmp)

for i in range(N):
    if i == 0:
        nokori_food = copy.deepcopy(l[0][1:])
    else:
        nokori_food_next = []
        for j in nokori_food:
            for k in l[i][1:]:
                if j==k:
                    nokori_food_next.append(k)
        nokori_food = copy.deepcopy(nokori_food_next)
print(len(nokori_food))

Measured memory_bytes: 3444
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  int H,W;cin>>H>>W;
  vint cnt(26,0);
  repeat(i,H){
    string a;cin >>a;
    repeat(j,W){
      cnt[a[j]-'a'] = (cnt[a[j]-'a']+1)%4;
    }
  }
  int odd=0,two=0;
  repeat(i,26){
    if(cnt[i]&1)odd++;
    if(cnt[i]%4==2)two++;
  }
  bool isok = (H&W&1&&odd==1)||(!(H&W&1)&&odd==0);
  isok &= two<=(W&1)*(H/2)+(H&1)*(W/2);
  cout << (isok? "Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[3],b[2];
	cin>>a[0]>>a[1]>>a[2]>>b[0]>>b[1];
	sort(a,a+3);
	sort(b,b+2);
	cout<<a[0]+b[0]-50<<endl;
}	



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

#define ll long long
#define mp make_pair

const ll mx=200009;
ll s[mx],p[mx];
ll ara[mx];
vector<ll> m,c;

bool bad(ll f1, ll f2, ll f3)
{
  return 1.0*(c[f3]-c[f1])*(m[f1]-m[f2])<=1.0*(c[f2]-c[f1])*(m[f1]-m[f3]);
}

void add(ll m1, ll c1)
{
  m.push_back(m1);
  c.push_back(c1);
  ll sz=m.size();
  while(sz>=3&&bad(sz-3,sz-2,sz-1))
  {
    m.erase(m.end()-2);
    c.erase(c.end()-2);
    sz--;
  }
}

ll value(ll ind, ll x)
{
  return m[ind]*x+c[ind];
}

ll query(ll x)
{
  ll low=0,high=(ll)m.size()-1;
  ll ans=LLONG_MAX;
  while(low<=high)
  {
    ll mid1=low+(high-low)/3;
    ll mid2=high-(high-low)/3;
    if(value(mid1,x)<=value(mid2,x))
    {
      ans=value(mid1,x);
      high=mid2-1;
    }
    else
    {
      ans=value(mid2,x);
      low=mid1+1;
    } 
  }
  return ans;
}

int main(){
  ll n,cc;
  cin>>n>>cc;
  for(ll i=1;i<=n;i++)
  {
    cin>>ara[i];
  }
  add(-2*ara[1],ara[1]*ara[1]);
  ll ans=0;
  for(int i=1;i<=n;i++)
  {
    ans=query(ara[i])+ara[i]*ara[i]+cc;
    add(-2*ara[i],ara[i]*ara[i]+ans);
  }
  cout<<ans;


}

Measured memory_bytes: 5100
def main():
    n = int(input())
    s = input()

    sum_count = s.count('R') * s.count('G') * s.count('B')

    r_list = set()
    g_list = set()
    b_list = set()

    for i in range(n):
        if s[i] == 'R':
            r_list.add(i)
        elif s[i] == 'G':
            g_list.add(i)
        elif s[i] == 'B':
            b_list.add(i)

    for r in r_list:
        for g in g_list:
            L = g - r
            if g + L in b_list:
                sum_count -= 1
            if r - L in b_list:
                sum_count -= 1
            if L % 2 == 0 and L//2 + r in b_list:
                sum_count -= 1

    print(sum_count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9576
#include <iostream>
#include <iomanip>
using namespace std;
using ll = long long;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

int main(){
      int n;
      cin>>n;
      double a[n];
      rep0(i,n){
            cin>>a[i];
      }
      double ans=0;
      rep0(i,n){
            ans+=(1/a[i]);
      }
      cout<<setprecision(10)<<1/ans<<endl;
      return 0;
}

Measured memory_bytes: 256
while True:
    a = input()
    h, w = a.split(' ')
    h, w = int(h), int(w)
    
    if h == 0 and w == 0:
        break;
    
    for i in range(h):
        str = ''
        for j in range(w):
            if i == 0 or i == h - 1 or j == 0 or j == w - 1:
                str += '#'
            else:
                str += '.'
        print(str)
    print()


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

int main() {
    int N; cin >> N;
    deque<int> deq;
    rep(i, 0, N) {
        int a; cin >> a;
        if(i%2) deq.push_back(a);
        else deq.push_front(a);
    }
    if(N%2 == 0) reverse(deq.begin(), deq.end());
    for(auto p : deq) cout << p << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define int long long
#define REP(i,a,n) for(int i=a;i<(n);i++)
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,a[100001],ans=0,fushu=0,zero=0;
	cin>>n;
	REP(i,0,n){
		cin>>a[i];
		fushu+=a[i]<0;
		zero+=!a[i];
		a[i]=abs(a[i]);
		ans+=a[i];
	}
	sort(a,a+n);
	if(!zero&&fushu%2)ans-=2*a[0];
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4420
n = int(input())
t = n
c = 0
while t > 0:
    t //= 10
    c += 1
ans = 0
for i in range(1, c+1, 2):
    if i == c:
        ans += n - 10 ** (i-1) + 1
    else:
        ans += (10**i - 10**(i-1))
print(ans)

Measured memory_bytes: 3060