akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#ifdef Rahul
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define error(...) 42;
#endif
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/
const int N = 1e6 + 42;
int dp[2][N];
int32_t main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  string s;
  cin >> s;
  int n = SZ(s);
  dp[1][n + 1] = MOD;
  dp[0][n + 1] = 0;
  for (int i = n; i > 0; --i) {
    int d = s[i - 1] - '0';
    dp[0][i] = d + dp[0][i + 1];
    dp[1][i] = 10 - d + dp[0][i + 1];
    if (d + 1 < 10) {
      uin(dp[0][i], d + 1 + dp[1][i + 1]);
      uin(dp[1][i], (10 - d - 1) + dp[1][i + 1]);
    } else {
      uin(dp[1][i], dp[1][i + 1]);
    }    
  }
  //~ Nerr = 3;
  //~ error(dp[0], dp[1]);
  cout << min(dp[0][1], 1 + dp[1][1]) << '\n';
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, m;
    cin>> n;
    if(n== 0)
    {
        cout<<  "No\n";
        return 0;

    }
    if(n%4== 0 || n%7== 0)
    {
        cout<<  "Yes\n";
        return 0;
    }

    m= n/ 7;


    while (m> 0)
    {
        if((n- (m*7)) % 4== 0)
        {
            cout<<  "Yes\n";
            return 0;
        }
        m--;
    }
    cout<<  "No\n";

    return 0;
}




Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
char S[8][10][10]={
{},{},{},{},
{
	"aaca",
	"bbca",
	"acbb",
	"acaa"
},
{
	"aabba",
	"bcc.a",
	"b..cb",
	"a..cb",
	"abbaa"
},
{
	"aabc..",
	"ddbc..",
	"..aabc",
	"..ddbc",
	"bc..aa",
	"bc..dd"
},
{	
	"aabbcc.",
	"dd.dd.a",
	"..d..da",
	"..d..db",
	"dd.dd.b",
	"..d..dc",
	"..d..dc"
}
};
char s[1005][1005];
void solve(int &x,int N){
	for(int i=0;i<N;++i)
		for(int j=0;j<N;++j)
			s[x+i][x+j]=S[N][i][j];
	x+=N;
}
int main(){
	int n;
	cin>>n;
	if(n<=2) return puts("-1"),0;
	if(n<=3) return puts("add"),puts("a.c"),puts("bbc"),0;
	int tmp=1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			s[i][j]='.';
	solve(tmp,n%4+4);
	while(tmp<=n) solve(tmp,4);
	for(int i=1;i<=n;++i,puts(""))
		for(int j=1;j<=n;++j)
			cout<<s[i][j];
	return 0; 
} 

Measured memory_bytes: 4636
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	cc=[0]*len(al)
	rsum=0
	for i, v in enumerate(al):
		rsum += v
		cc[i] = rsum
	#pa(cc)
	dd = collections.defaultdict(lambda : 0)
	dd[0]=1
	for v in cc:
		dd[v] += 1
	
	ret = 0
	for k in dd:
		n = dd[k]
		ret += n * (n-1) // 2
	return ret
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 112976
#include<iostream>
using namespace std;
int main(){
  int A, B, S;
  S = 0;
  cin >> A >> B;
  for(int i = A; i <= B; i++){
    if(((i/10000)==(i%10)) && (((i/1000)%10)==((i/10)%10))){
      S += 1;
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
from collections import deque
N = int( input())
E = [[] for _ in range(N)]
V = [0]*N
for _ in range(N-1):
    a, b = map( int, input().split())
    a, b = a-1, b-1
    E[a].append(b)
    E[b].append(a)
    V[a] += 1
    V[b] += 1
C = list(map( int, input().split()))
C.sort(reverse=True)
for i in range(N):
    if V[i] == 1:
        s = i
        break
q = deque([s])
V = [0]*N
l = 0
for l in range(N):
    t = q.popleft()
    V[t] = C[l]
    for v in E[t]:
        if V[v] == 0:
            q.append(v)
print( sum(C) - C[0])
print( " ".join( map( str, V)))


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

signed main(void)
{
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << endl;
	return 0;
}


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

using namespace std;

int main(){
	int v[5];
	int i;
	for(i = 0; i < 5; i++){
		cin >> v[i];
	}
	
	for(i = 0; i < 5; i++){
		if(v[i] == 0){
		 cout << i+1 << endl;
		 break;
		 }
	}

	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    ll n = s.length();
    ll ans = 0;
    rep(i,n){
        ans += (int)s[i] - 48;
    }
    if(ans%9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3840
N = int(input())
if N == 1:
    print(1)
else:
    xy = [tuple(int(e) for e in input().split()) for _ in range(N)]
    xy.sort()
    d = {}
    for i in range(N):
        for j in range(i + 1, N):
            p = xy[i][0] - xy[j][0]
            q = xy[i][1] - xy[j][1]
            if (p, q) in d:
                d[(p, q)] += 1
            else:
                d[(p, q)] = 1
    print(N - max(d.values()))

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		cout << n*n*n << "\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n,r;
  
  scanf("%d%d", &n, &r);
  
  if (  n >= 10) {
    printf("%d\n", r);
  }
  else {
     printf("%d\n", r+(10-n)*100);
  }
  
  return 0;
}


Measured memory_bytes: 128
S = input()
n = len(S)
dp = {0:1}
q = 1
p = 0
for i in range(n):
    p += int(S[n-1-i])*q
    q *= 10
    q = q % 2019
    p = p % 2019
    if p not in dp:
        dp[p] = 1
    else:
        dp[p] += 1
print(sum(dp[i]*(dp[i]-1)//2 for i in dp))

Measured memory_bytes: 9316
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

const long long MOD = 1000000007;

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

    vector<long long> dp(s + 1, 0);
    for(int i = 0; i < 3 && i <= s; i++){
        switch(i){
            case 0:
                dp[i] = 1;
                break;
            default:
                dp[i] = 0;
                break;
        }
    }
    
    for(int i = 3; i <= s; i++){
        dp[i] = dp[i - 3] + dp[i - 1];
        if(dp[i] >= MOD) dp[i] %= MOD;
    }

    auto ans = dp[s];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
def f(a, b):
    return max(len(str(a)), len(str(b)))

n = int(input())

ans = 11
for a in range(1, int(n ** 0.5) + 1):
    b = n // a 
    if n % a == 0 and f(a, b) < ans:
        ans = f(a, b)

print(ans)

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto A=vecin(N);
	set<ll> S;

	int K=1<<N;
	REP(i,K){
		int V=i;
		int sum=0,index=0;
		while(V){
			if(V&1) sum+=A[index];
			V/=2;
			index++;
		}
		S.emplace(sum);
	}

	int Q=in();
	auto M=vecin(Q);
	for(auto& x:M){
		out(S.find(x)==S.end()?"no":"yes");
	}
	
	return 0;
}



Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    vector<int> vc;
    int n,nc,p;
    int sum=0;
    int hp=0;
    int spsum=0;
    int ans=0;
    cin >> n;
    nc=n;
    while(nc--) {
		int x;
		cin >> x;
        sum+=x;
        spsum+=pow(x,2);
		vc.push_back(x);
	}
    p = (sum+(n/2))/n;
    ans=n*pow(p,2)-2*sum*p+spsum;
    cout<<ans;
}

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

using namespace std;

int H, W;
vector<string> MapData;
int Result[100][100];

void solve() {

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (Result[i][j] == -1) {
				continue;
			}
			for (int k = j + 1; k < W; ++k) {
				if (Result[i][k] == 0) {
					j = k - 1;
					break;
				}
				Result[i][k] = Result[i][k - 1] + 1;
			}
		}
	}

	for (int i = 0; i < H; ++i) {
		cout << Result[i][0];
		for (int j = 1; j < W; ++j) {
			cout << " " << Result[i][j];
		}
		cout << endl;
	}
}

int main() {
	string str;

	cin >> H >> W;
	fill(Result[0], Result[0] + 100 * 100, -1);
	for (int i = 0; i < H; ++i) {
		cin >> str;
		MapData.push_back(str);
		for (int j = 0; j < W; ++j) {
			if (MapData[i][j] == 'c') {
				Result[i][j] = 0;
			}
		}
	}
	solve();
	
	return 0;
}


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

int main() {
  string s;	/*配列として受け取る*/
  int a;	/*answer*/
 	
  cin >> s;
  
  if(s[0] == '1') ++a;
  if(s[1] == '1') ++a;
  if(s[2] == '1') ++a;
  
  cout << a << endl;
}

Measured memory_bytes: 256
N, A, B=map(int, input().split())

numbers = list(range(1, N + 1))
digit_sums = [0] * N

for i in range(N):
    j = i + 1
    while j != 0:
        digit_sums[i] += j % 10
        j = int(j / 10)

digit_sums = [0 if (i < A or i > B) else 1 for i in digit_sums]
ans = [i * j for (i, j) in zip(numbers, digit_sums)]
print(sum(ans))

Measured memory_bytes: 3956
s = list(input())

cnt = 0
prev_cnt = 0
result = 0
for i in range(len(s)):
    if s[i] == "B":
        cnt += 1
    if s[i] == "W":
        cnt += prev_cnt
        result += cnt
        prev_cnt = cnt
        cnt = 0
print(result)


Measured memory_bytes: 4840
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

const long long MOD = (long long)(1e9 + 7);

long long powerf(long long a, long long b) {
    long long res = 1;
    while(b > 0) {
        if((b%2 == 1)) {
            res = (res * a) % MOD;
        }
        a = (a * a) % MOD;
        b/=2;
    }
    return res;
}


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n, -1);
    for(int i=0; i<m; i++) {
        int s, c;
        cin >> s >> c;
        if((v[s-1] != c) && (v[s-1]!=-1)) {
            cout << "-1\n";
            return 0;
        } else {
            v[s-1] = c;
        }
    }
    if((n!=1) && (v[0] == 0)) {
        cout << "-1\n";
        return 0;
    }
    for(int i=n-1; i>=0; i--) {
        if(v[i] == -1) {
            if(n == 1) {
                v[0] = 0;
            } else if(i == 0) {
                v[i] = 1;
            } else {
                v[i] = 0;
            }
        }
    }
    for(int i=0; i<n; i++) cout << v[i];
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long sm=0;
    for(int i=1; i<=n; i++){
        if(i%3==0 && i%5==0){
        }else if(i%3==0){
        }else if(i%5==0){
        }else{
            sm = sm + i;
        }
    }
    cout << sm << endl;
}




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

using namespace std;
static const int INF = (1 << 21);

int E[8][8 ] = { { 0 } };
long long int N;
int c = 0;
int flag[8] = { 0 };

int F(int a,int b) {
	int cnt1 = 0,cnt2=0;
	while (1) {
		a /= 10;
		cnt1++;
		if (a == 0) break;
	}
	while (1) {
		b /= 10;
		cnt2++;
		if (b == 0) break;
	}
	return max(cnt1, cnt2);
}

int main() {
	cin >> N;
	int m = 11;
	for (long long int i = 1;i <=min(N,(long long)100000);i++) {
		if (N%i == 0) {
			long long int a=i, b=N/i;
			m = min(F(a, b), m);
			if (a == b || a > b) break;
		}
	}

	cout << m << endl;
}

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

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

int main(){
string w;
cin>>w;
map<char,int>m;
rep(i,w.size()){
  m[w[i]]++;
}

for(auto i:m){
  if(i.second%2!=0){
    cout<<"No"<<endl;
    return 0;
  }
}
cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) {
        String alphabets = "abcdefghijklmnopqrstuvwxyz";
        String S;
        Scanner sc = new Scanner(System.in);
        S = sc.nextLine(); //"cdefghnoprstuvwxy"; //sc.nextLine();
        absAlpha(alphabets , S);
    }

    private static void absAlpha(String alphabets, String input) {
        TreeSet<Character> inputset = new TreeSet<>();
        boolean found = false;
        for (int i=0; i<alphabets.length(); i++){
            String str = String.valueOf(alphabets.charAt(i));
            if (!input.contains(str)){
                System.out.println(str);
                found = true;
                break;
            }
        }
        if (!found)
            System.out.println("None");
    }
}



Measured memory_bytes: 26188
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;
using P = pair<int,int>;

int main(){

  int N, a;
  cin >> N;
  int ans = 0;

  vector<P> p(N);
  for (int i = 0; i < N; i++) {
    cin >> a;
    p[i].first = i+1;
    p[i].second = a;
  }

  int cnt = 0;
  int i = 0;
  while (cnt <= N){
    if(p[i].second == 2){
      cnt++;
      cout << cnt << endl;
      return 0;
    }

    i = p[i].second-1;
    cnt++;
  }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 4052
S=input()

if S=='SUN':
    print('7')

elif S=='MON':
    print('6')

elif S=='TUE':
    print('5')

elif S=='WED':
    print('4')

elif S=='THU':
    print('3')

elif S=='FRI':
    print('2')

elif S=='SAT':
    print('1')

Measured memory_bytes: 9060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 998244353

int main() {
	int a, b;
	cin >> a >> b;
	if ((a*b) % 2)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main()
{
    long long int n,b,c,k,d;
    unsigned long long int sum=0;

    cin>>n>>k>>d;
    if(n>=0){
    b = n/d;

    if(b<=k){
    c = n - (d*b);
    k-=b;
    sum=k%2;
    }
    else{
    c = n - (d*k);
    k-=k;
    }

    if(sum==1){c = min(abs(c-d),(c+d));}


    cout<<c<<endl;
    }

    else{
    b = abs(n)/d;

    if(b<=k){
    c = n + (d*b);
    k-=b;
    sum=k%2;
    }

    else {
    c = n + (d*k);
    k-=k;
    }

    if(sum==1){c = min(abs(c-d),abs(c+d));}


    cout<<abs(c)<<endl;
    }


    return 0;
}





Measured memory_bytes: 3564
n,m = map(int, input().split())

if n > m:
    n,m = m,n

if n==1 and m==1:
    print(1) 
elif n==1:
    print(m-2)
elif n==2 or m==2:
    print(0)
else:
    print((m-2)*(n-2))


Measured memory_bytes: 9068
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N,ans;
    cin>>N;
    string s;
    cin>>s;
    int i=1;
    while(1){
        if(s[i]=='\0')break;
        if(s[i]==s[i-1]){
            s.erase(i-1,1);
            i--;
        }
        i++;
    }
    ans=s.size();
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int a;
  int K;
  cin >> a;
  vector<int> v(a+1);
  int tmp;
  for (int i = 0; i < a-1; i++){
    cin >> tmp;
    K=v.at(tmp)+1;
    v.at(tmp)=K; 
  }
   for (int i = 1; i < a+1; i++){
    cout << v.at(i) << endl;
   }
}


Measured memory_bytes: 4008
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long a = sc.nextLong();
			long b = sc.nextLong();
			long k = sc.nextLong();

			if (a + b <= k) {
				System.out.println("0 0");
			} else {
				long resultA = 0;
				long resultB = 0;
				if (a <= k) {
					resultB = b - k + a;
				} else {
					resultA = a - k;
					resultB = b;
				}
				System.out.println(resultA + " " + resultB);
			}
		}
	}
}


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

int main()
{
    int n, m; cin >> n >> m;
    int ans= 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            ans++;
        }
    }
    for(int i = 0; i < m; i++) {
        for(int j = i+1; j < m; j++) {
            ans++;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

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


int x,y,z, k;
i64 a[1010], b[1010], c[1010];
i64 d[1010*1010], e[3030*1010];

int main(){
	cin >> x >> y >> z >> k;
	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++){
			d[i*y+j] = a[i]+b[j];
		}
	}
	sort(d,d+x*y, greater<i64>());
	
	for(int i = 0; i < min(k,x*y); i++){
		for(int j = 0; j < z; j++){
			e[i*z+j] = d[i]+c[j];
		}
	}
	
	sort(e,e+min(k,x*y)*z, greater<i64>());
	for(int i = 0; i < k; i++){
		cout << e[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 32128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 4e3+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int N;
char s[MAXN];
LL ans=0;
int cntr[MAXN],cntg[MAXN],cntb[MAXN];

char cal(char x,char y){
    if(x!='R'&&y!='R') return 'R';
    if(x!='G'&&y!='G') return 'G';
    if(x!='B'&&y!='B') return 'B';
}

void work(){
    scanf("%d",&N);
    scanf("%s",s+1);
    for(int i=N;i>=1;i--){
        cntr[i]=cntr[i+1];
        cntg[i]=cntg[i+1];
        cntb[i]=cntb[i+1];
        if(s[i]=='R'){
            cntr[i]++;
        }
        if(s[i]=='G'){
            cntg[i]++;
        }
        if(s[i]=='B'){
            cntb[i]++;
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=i+1;j<=N;j++){
            if(s[i]==s[j]) continue;
            char d=cal(s[i],s[j]);
            if(d=='R'){
                ans+=cntr[j];
            }
            if(d=='G'){
                ans+=cntg[j];
            }
            if(d=='B'){
                ans+=cntb[j];
            }
            if(j+j-i<=N&&s[j+j-i]==d) ans--;
        }
    }
    printf("%lld\n",ans);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}






Measured memory_bytes: 3844
let readInt () = Scanf.scanf " %d" (fun x -> x)

type graph = {n: int; m: int; e: (int * int) array; adj: (int list) array}
type spanningTree = {root: int; p: int array; ch: (int list) array}

let fullRep (n, m, e0) : graph = let res = {
  n;
  m;
  e=Array.init (2*m) (fun i ->
    let (u, v) = e0.(i/2) in
    if i mod 2 = 0 then (u, v)
    else (v, u))
  ;
  adj=
    let adj = Array.make n [] in
    for i=0 to m-1 do
      let (u, v) = e0.(i) in
      adj.(u) <- (2*i) :: adj.(u);
      adj.(v) <- (2*i+1) :: adj.(v)
    done;
    adj
}
in
Array.iteri (fun u is -> List.iter (fun i -> let (u', v) = res.e.(i) in assert (u' = u); assert (List.mem (i lxor 1) res.adj.(v))) is) res.adj;
for i=0 to 2*m-1 do
  let (u, v) = res.e.(i) in
  assert (res.e.(i lxor 1) = (v, u))
done;
res

let root (rt : int) ({n; e; adj} : graph) : spanningTree =
  let p = Array.make n (-1) in
  let ch = Array.make n [] in
  let vis = Array.make n false in
  let rec go u i =
    vis.(u) <- true;
    p.(u) <- i;
    List.iter
      (fun j ->
        let (_, v) = e.(j) in
        if not vis.(v) then begin
          ch.(u) <- j :: ch.(u);
          go v (j lxor 1)
        end)
      adj.(u)
  in
  go rt (-1);
  Array.iteri (fun u is -> List.iter (fun i -> let (u', v) = e.(i) in assert (u' = u); assert (p.(v) = (i lxor 1))) is) ch;
  {root=rt; p; ch}

type edgeSet = {h: (int, unit) Hashtbl.t; outDeg: bool array}
let addEdge s g i =
  Hashtbl.add s.h i ();
  let (u, _) = g.e.(i) in s.outDeg.(u) <- not s.outDeg.(u)

let solve (g : graph) : (edgeSet option) =
  if g.m mod 2 = 1 then None
  else
  let t = root 0 g in
  let te = Hashtbl.create (g.n-1) in
  let rec dfs u =
    List.iter
      (fun i ->
        Hashtbl.add te (i/2) ();
        let (_, v) = g.e.(i) in dfs v)
      t.ch.(u)
  in
  dfs 0;
  let inTree i = Hashtbl.mem te i in
  let ans = {h=Hashtbl.create g.m; outDeg = Array.make g.n false} in
  for i=0 to g.m-1 do
    if not (inTree i) then addEdge ans g (2*i)
  done;
  let rec dp u =
    List.iter
      (fun i ->
        let (_, v) = g.e.(i) in
        dp v;
        if ans.outDeg.(v) then addEdge ans g (i lxor 1)
        else addEdge ans g i)
      t.ch.(u)
  in
  dp 0;
  assert (not ans.outDeg.(0));
  Some ans

let main () =
  let n = readInt () in
  let m = readInt () in
  let e0 = Array.init m (fun _ -> (readInt () - 1, readInt () - 1)) in
  let g = fullRep (n, m, e0) in
  match solve g with
    | None -> Printf.printf "-1\n"
    | Some es ->
        Hashtbl.iter
          (fun i () ->
            let (u, v) = g.e.(i) in
            Printf.printf "%d %d\n" (u+1) (v+1))
          es.h

let () = main ()


Measured memory_bytes: 47228
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n, p[100005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> p[i];
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (p[i] == i && p[i+1] == i+1) {
			swap(p[i], p[i+1]);
			cnt++;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (p[i] == i) {
			swap(p[i], p[i+1]);
			cnt++;
		}
	}
	if (p[n-1] == n-1) {
		swap(p[n-1], p[n-2]);
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  double n, x, t;
  cin >> n >> x >> t;
  cout << (ll)((ceil)(n/x)*t) << endl;
  return 0;
}

Measured memory_bytes: 3644
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var l = Console.ReadLine().Split()
                .Select(int.Parse).ToArray();
            int result = 0;

            for (int i = 0; i < n - 2; i++) 
            {
                for (int j = i + 1; j < n - 1; j++)
                {
                    for(int k = j + 1; k < n; k++)
                    {
                        if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i])
                            continue;
                        else
                        {
                            if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j])
                                result++;
                        }
                    }
                }
            }
            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 28324
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
//typedef long long int i64;
typedef int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

const double PI = 3.141592653589793238463;

using namespace std;

const int MAXN = 1000500;
const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;

i64 mod = 1e9 + 7;

i64 T, n, m, k, q;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.precision(16);

	string s;

	cin >> s;

	if (s == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}


	return 0;
}

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

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

    vector<vector<int>> F(N, vector<int>(10));
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < 10; ++j){
            cin >> F[i][j];
        }
    }
    
    vector<vector<int64_t>> P(N, vector<int64_t>(11));
    for(int i = 0; i < N; ++i){
        for(int j = 0; j <= 10; ++j){
            cin >> P[i][j];
        }
    }
    
    int64_t ans = -100000000000;
    for(int i = 1; i < (2 << 9); ++i){
        int64_t sum = 0;
        for(int j = 0; j < N; ++j){
            int cnt = 0;
            for(int k = 0; k < 10; ++k){
                if((i >> k) & F[j][k]){
                    cnt++;
                }
            }
            sum += P[j][cnt];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

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

int n;
string s;

int main(void){
	cin >> n >> s;
	int x = 0;
	int ans = 0;
	for(auto i : s){
		if(i == 'I') x++;
		else if(i == 'D') x--;
		ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は２つの値の組を表せる

int main(){
    int boo[3][3];
    int A[3][3];
    
    rep(i,3)rep(j,3){
        int a; cin >> a;
        A[i][j]=a;
        boo[i][j]=false;
    }
    
    int N; cin >> N;
    rep(i,N){
        int b; cin >> b;
        rep(j,3)rep(k,3){
            if (A[j][k]==b) boo[j][k]=true;
        }
    }
    
    bool ans=false;
    rep(i,3){
        if (boo[i][0] && boo[i][1] && boo[i][2]) ans=true;
        if (boo[0][i] && boo[1][i] && boo[2][i]) ans=true;
    }
    if (boo[0][0] && boo[1][1] && boo[2][2]) ans=true;
    if (boo[0][2] && boo[1][1] && boo[2][0]) ans=true;
    
    if(ans) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>
#include <map>

#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 <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n + 1);
	rep1(i, n) { cin >> a[i]; }
	if (n % 2 == 0)
	{
		for (int i = n; i >= 2; i -= 2) cs(a[i]);
		for (int i = 1; i <= n - 1; i += 2) cs(a[i]);
	}
	else
	{
		for (int i = n; i >= 1; i -= 2) cs(a[i]);
		for (int i = 2; i <= n - 1; i += 2) cs(a[i]);
	}
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
					<< #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
						<< #x << "=" << x << "\n" \
						<< #y << "=" << y << "\n";
#define w(x)  \
	int x;    \
	cin >> x; \
	while (x--)

int32_t main()
{

	int n;
	cin >> n;
	string s;
	cin >> s;

	int r[n + 1], g[n + 1], b[n + 1];
	if (s[0] == 'R')
		r[0] = 1;
	if (s[0] == 'G')
		g[0] = 1;
	if (s[0] == 'B')
		b[0] = 1;

	for (int i = 1; i < n; i++)
	{
		if (s[i] == 'R')
			r[i] = r[i - 1] + 1;
		else
		{

			r[i] = r[i - 1];
		}
	}
	for (int i = 1; i < n; i++)
	{
		if (s[i] == 'G')
			g[i] = g[i - 1] + 1;
		else
		{

			g[i] = g[i - 1];
		}
	}
	for (int i = 1; i < n; i++)
	{
		if (s[i] == 'B')
			b[i] = b[i - 1] + 1;
		else
		{
			b[i] = b[i - 1];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (s[i] == s[j])
				continue;
			if ((s[i] == 'R' || s[j] == 'R') && (s[i] == 'B' || s[j] == 'B'))
			{
				ans += g[j] - g[i];
				if (((j - i) % 2 == 0) && s[(i + j) / 2] == 'G')
					ans--;
			}
			else
			{
				if ((s[i] == 'R' || s[j] == 'R') && (s[i] == 'G' || s[j] == 'G'))
				{
					ans += b[j] - b[i];
					if (((j - i) % 2 == 0) && s[(i + j) / 2] == 'B')
						ans--;
				}
				else
				{
					if ((s[i] == 'G' || s[j] == 'G') && (s[i] == 'B' || s[j] == 'B'))
					{
						ans += r[j] - r[i];
						if (((j - i) % 2 == 0) && s[(i + j) / 2] == 'R')
							ans--;
					}
				}
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N;
  cin>>N;
  ll ans=0;
  rep(i,N-1){
    if(N%(i+1)) ans+=N/(i+1);
    else ans+=N/(i+1)-1;
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 3632
using System;

class Test
{
    static void Main()
    {
        string[] ss = Console.ReadLine().Split(' ');
        int a = Convert.ToInt32(ss[0]);
        int b = Convert.ToInt32(ss[1]);

        Console.WriteLine("{0} {1}", a * b, (a + b) * 2);
    }
}



Measured memory_bytes: 18016
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
typedef long double db;
using namespace std;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n;
db d0, delta, ans;

inline db calc(db d0, db delta, db len) {
	return len * d0 + delta * len * (len + 1) / 2;
}

int main() {
	
	n = ri(), d0 = ri(), delta = ri(), d0 -= delta;
	per (i, n, 1) {
		ans += calc(d0, delta, 2 * i) / (2 * i);
		d0 = (2 * i + 2) * d0 + 3 * delta;
		delta *= (2 * i + 4);
		d0 /= 2 * i;
		delta /= 2 * i;
	}

	printf("%.15Lf\n", ans);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
int a,b; cin >> a >> b;
int ans = -1;
if(1 <= a && a <= 9 && 1 <= b && b <= 9) ans = a*b;
std::cout << ans << '\n';
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

vector<pair<ll, ll>> factorial(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0) continue;
        ll ex = 0;
        while(N % i == 0){
            ex++;
            N /= i;
        }
        res.push_back({i, ex});
    }
    if(N != 1) res.push_back({N, 1});
    return res;
}
int main(){

    ll n;
    cin >> n;
    vector<ll> v(n+1, 0);
    for(ll i = 2; i <=n; i++){
        const auto &pf = factorial(i);
        for(auto p : pf) {
            v[p.first] += p.second;
        }
    }
    ll res = 1;
    for(ll i = 2; i <=n; i++){
        res *= (v[i] + 1);
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 202020;
ll in[NM];
ll dist[NM];



void solve() {
    ll N,K;
    cin >> K >> N;
    for (ll i = 0; i < N; i++) {
        cin >> in[i];
    }
    ll sum=0;
   
    ll edge = K - in[N-1] + in[0];

    ll max = 0;
    ll maxind = 0;
    for (ll i = 0; i < N-1; i++) {
        dist[i] = in[i + 1] - in[i];
        if (max < dist[i]) {
            max = dist[i];
            maxind = i;
        }
    }
    dist[N-1] = edge;
    if (max < dist[N-1]) {
        max = dist[N-1];
        maxind = N-1;
    }

    for (ll i = 0; i < N ; i++) {
        if (i == maxind) {
            continue;
        }
        sum += dist[i];
    }
    cout << sum;
}




int main() {
    solve();
    return 0;
}







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

using namespace std;

int main(void) {
  string S;
  cin >> S;
  int N = S.size(), MOD = 1e9 + 7;

  long long dp[100010][4] = {};
  for(int i = N; i >= 0; i--) {
    for(int j = 3; j >= 0; j--) {
      if(i == N) {
	dp[i][j] = (j == 3 ? 1 : 0);
      } else {
	dp[i][j] = dp[i + 1][j] * (S[i] == '?' ? 3LL : 1LL);
	if(j < 3 && (S[i] == '?' || S[i] == "ABC"[j])) {
	  dp[i][j] += dp[i + 1][j + 1];
	}
	dp[i][j] %= MOD;
      }
    }
  }
  //  for(int i = 0; i < 3; i++) {
  //    cout << "ABC"[i] << endl;
  //  }
  cout << dp[0][0] << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


signed main(void) 
{
    ll n;
    cin >>n;
    vll a(n);
    ll c = 0;
    rep (i, n) {
        cin >>a[i];
        if (a[i] != i+1) {
            c++;
        }
        if (c > 2) {
            mes("NO");
            re0;
        }
        
    }
    mes("YES");
    
    
   
}


Measured memory_bytes: 3552
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int m, d; cin >> m >> d;
  int ans = 0;
  FOR(month, 1, m + 1) FOR(day, 1, d + 1) {
    if (day / 10 >= 2 && day % 10 >= 2) {
      if ((day / 10) * (day % 10) == month) ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
class PriorityQueue
  def initialize
    @n = 0
    @heap = []
  end
  
  def maxHeapify x
    l = 2*x
    r = 2*x+1
    if l <= @n && @heap[l] > @heap[x]
      largest = l
    else
      largest = x
    end
    if r <= @n && @heap[r] > @heap[largest]
      largest = r
    end
    if largest != x
      @heap[x], @heap[largest] = @heap[largest], @heap[x]
      maxHeapify(largest)
    end
  end
   
  def extract
    key = @heap[1]
    @heap[1] = @heap[@n]
    @n -= 1
    maxHeapify(1)
    key
  end
   
  def insert key
    @n += 1
    @heap[@n] = key
    i = @n
    while i > 1 && @heap[i/2] < @heap[i]
      @heap[i], @heap[i/2] = @heap[i/2], @heap[i]
      i /= 2
    end
  end
end

pq = PriorityQueue.new
while l = gets
  break if l.chomp == "end"
  if l.chomp == "extract" then puts pq.extract
  else pq.insert(l.split[1].to_i)
  end
end 

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

int h, w, d;
char color[] = {'Y', 'R', 'G', 'B'};

int main() {
    cin >> h >> w >> d;

    if (d == 1) {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((i + j) % 2 == 0) {
                    cout << 'B';
                }
                else {
                    cout << 'R';
                }
            }
            cout << endl;
        }
    }
    else {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int y = (i - j + 3000) / d;
                int x = (i + j + 3000) / d;
                cout << color[y % 2 * 2 + x % 2]; 
            }
            cout << '\n';
        }
    }
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
 
int n,coords;
 
int main() {
    
    cin >> n;
    cin >> coords;
    int max = coords;
    int min = coords;
    for(int i = 0; i < n-1; i++){
      cin >> coords;
      if(coords > max){
        max = coords;
      }
      else if(coords < min){
        min = coords;
      }

    }
    cout << max-min;

}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n,a,b;cin>>n>>a>>b;
  if(a>b||(n==1&&a!=b)){
    out(0);
    return 0;
  }

  if(a==b){
    out(1);
  }else{
    out((n-2)*(b-a)+1);
  }

  return 0;
}
// 1000000000 1 1000000000 , 999999997000000003
// 983475623 23876555 237894565 , 210481495289934211


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> x(n+1), y(n+1), t(n+1);
  for(int i=1;i<n+1;i++)
    cin >> t[i] >> x[i] >> y[i];

  bool ans = true;
  for(int i=1;i<n+1;i++) {
    int ti = t[i]-t[i-1];
    int d = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]);
    if(ti < d || (ti-d) % 2 == 1) {
     ans = false;
     break;
    }
  }
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 1408