akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.text.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
		int[] k = new int[6];

		for(int i = 0; i < k.length; i++){
			k[i] = sc.nextInt();
		}
		
		TwotwoMatrix p = TwotwoMatrix.inverse(new TwotwoMatrix(k[0], k[1], k[3], k[4]));
		
		double[] q = TwotwoMatrix.multiplytovector(p, k[2], k[5]);
		StringBuffer r = new StringBuffer();
		NumberFormat f = NumberFormat.getInstance();
		
		f.setMaximumFractionDigits(3);
		f.setMinimumFractionDigits(3);
		for(int i = 0; i < q.length; i++){
			String z = f.format(q[i]);
			if(z.equals("-0.000")){
				z = "0.000";
			}
			r.append(z);
			r.append(" ");
		}
		r.delete(r.length() -1, r.length());
		System.out.println(r);
		}
	}

}

class TwotwoMatrix{
	int aa, ab, ba, bb;
	double k;
	public TwotwoMatrix(int a1, int a2, int b1, int b2, double k0){
		aa = a1;
		ab = a2;
		ba = b1;
		bb = b2;
		k = k0;
	}

	public TwotwoMatrix(int a1, int a2, int b1, int b2){
		this(a1, a2, b1, b2, 1.0);
	}

	public static TwotwoMatrix multiply(TwotwoMatrix one, TwotwoMatrix two){
		return new TwotwoMatrix(
			(one.aa * two.aa + one.ab * two.ba),
			(one.aa * two.ab + one.ab * two.bb),
			(one.ba * two.aa + one.bb * two.ba),
			(one.ba * two.ab + one.bb * two.bb));
	}

	public static double[] multiplytovector(TwotwoMatrix p, int a, int b){
		double[] res = {(p.aa * a + p.ab * b) * p.k, (p.ba * a + p.bb * b) * p.k};
		return res;
	}

	public static TwotwoMatrix inverse(TwotwoMatrix p){
		int a1, a2, b1, b2;
		a1 = p.aa;
		a2 = p.ab;
		b1 = p.ba;
		b2 = p.bb;
		double n = 1 / (double)(a1 * b2 - a2 * b1) ;

		return new TwotwoMatrix(b2, -a2 , -b1, a1, n);
	}
}

Measured memory_bytes: 0
/**

author  :	 ©LoneWolfDON
Git     :    MahinHossainMunna

**/
/*

*/
#include <stdio.h>

int main()
{
    int A,B,C,D;
    scanf("%d%d%d%d",&A,&B,&C,&D);

    for (int i = 0;;i++)
    {
        if(i%2 == 0)
            C -= B;
        else
            A -= D;

        if(A <= 0)
        {
            printf("No\n");
            break;
        }
        if(C <= 0)
        {
            printf("Yes\n");
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////

bool prime(ll n) {
	for (ll i = 2; i<=sqrt(n); i++) {
		if (n%i == 0) { return false; }
	}

	return true;
}


	
int main() {

	ll N;
	cin >> N;

	ll c = 11;

	rep(i,N){
		while (1 == 1) {
			if (prime(c)) { cout << c<<" "; break; }
			c += 5;
		}
		c += 5;
	}
	


	system("PAUSE");
}

Measured memory_bytes: 504
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    if(x == 3 || x == 5 || x == 7){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define REP(i, k, n) for (signed long long int i = (signed long long int)(k); i < (signed long long int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define loop(n) rep(looping, n);
#define rREP(i, k, n) for (signed long long int i = (signed long long int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) std::sort(all(x))
#define REV(x) std::reverse(all(x))
#define UNIQUE(x) x.erase(std::unique(all(x)), x.end());
#define MAX(x) *std::max_element(all(x))
#define MIN(x) *std::min_element(all(x))
#define LOWitr(x, n) std::lower_bound(all(x), n)
#define UPRitr(x, n) std::upper_bound(all(x), n)
#define cii(x) int x; std::cin >> x
#define cill(x) signed long long int x; std::cin >> x
#define cis(x) std::string x; std::cin >> x
#define co(x) std::cout << x << "\n"
#define pb push_back
#define mp std::make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) if(DEBUG) std::cout<<#x<<" : "<<(x)<<"\n"
using std::cin;
using std::cout;
using std::string;
using std::min;
using std::max;
using std::abs;
using std::next_permutation;
template<class T>using V = std::vector<T>;
template<class T>using VV = std::vector<std::vector<T>>;
template<class T>using Q = std::queue<T>;
template<class T>using PQ = std::priority_queue<T>;
template<class T,class U>using P = std::pair<T, U>;
template<class T,class U>using M = std::map<T, U>;
template<class T,class U>using UM = std::unordered_map<T, U>;
using LL = signed long long int;
using VL = V<LL>;
using VVL = V<VL>;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f; //1061109567
const LL LLINF = 0x3f3f3f3f3f3f3f3fLL; //4557430888798830399
const double PI = M_PI;
template<class T,class U>inline LL min(T a, U b){return std::min((LL)a, (LL)b);}
template<class T,class U>inline LL max(T a, U b){return std::max((LL)a, (LL)b);}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T>inline void vcin(T &v){for(auto&& i : v) std::cin >> i;}
template<class T>inline void dumpv(const T& v, std::ostream& os = std::cout){
    if(DEBUG){
        os<<"{";std::for_each(all(v),[&os](typename T::value_type p){os<<p<<',';});os<<"}\n";
    }
}

void Main(){
    rep(i, 5){
        cii(a);
        if (a==0){
            co(i+1);
            return;
        }
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3652
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break

    for i in range(H):
        c = "#" if i%2 == 0 else "."

        for j in range(W):
            print(c, end="")

            if c == "#":
                c = "."

            else:
                c = "#"
        print()

    print()


Measured memory_bytes: 7008
#include<stdio.h>
#include<string.h>
int main()
{
 char a[15],b[15];
 scanf("%s",a);
 scanf("%s",b);
 	b[strlen(b)-1]='\0';
 	if(strlen(b)==strlen(a)&&strcmp(a,b)==0)
 	printf("Yes");
 	else
 	printf("No");
 	
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;
string s ;

int main(){fast ;
	int n,k ;
	cin >> n ;
	vector<int>a(n) ;
	vector<int>L(n+1,0) , R(n+1,0) ;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	int res = 0 ;
	for(int i = 1 ; i <= n ; i++){
		L[i] = __gcd(L[i-1] , a[i-1] );
		R[n-i] = __gcd(R[n-i+1] , a[n-i]) ;
	}
	for(int i = 0 ; i < n ; i++)
		res = max(res, __gcd(L[i], R[i+1])) ;
	
	cout << res << endl ;
}

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

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

  int N; cin >> N;

  long long gc = 0;
  vector<long long> A(N + 1);
  for (int i = N; ~i; --i) cin >> A[i], gc = __gcd(abs(A[i]), gc);
  auto test = [&](int p) {
    if (A[0] % p) return false;
    vector<long long> B(A.begin() + 1, A.end());
    for (int i = N - 1; i >= p - 1; --i) {
      assert(B.size() == i + 1);
      (B[i - p + 1] += B[i]) %= p;
      B.pop_back();
    }
    for (int i = 0; i < p - 1; ++i) if (B[i] % p) return false;
    return true;
  }; 
  set<int> ans;
  vector<int> sieve(N + 1, 1);
  for (int p = 2; p <= N; ++p) if (sieve[p]) {
    if (test(p)) ans.insert(p);
    for (int n = 2 * p; n <= N; n += p) sieve[n] = 0;
  }

  for (int p = 2; p * p <= gc; ++p) while (gc % p == 0) ans.insert(p), gc /= p;
  if (gc != 1) ans.insert(gc);
  for (auto a : ans) cout << a << '\n';
}


Measured memory_bytes: 512
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    d = {}
    for _ in range(N):
        a, b = map(int, readline().rstrip().split())
        d.setdefault(a, 0)
        d[a] += b
    
    keys, vals = d.keys(), d.values()
    z = zip(keys, vals)
    z = sorted(z)
    keys, vals = zip(*z)
    s = 0
    for k, v in zip(keys, vals):
        if s + v < K:
            s += v
        else:
            ans = k
            break
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 20068
<?php
$numbers = fgets(STDIN);
$n = intval($numbers);
// print $n;

$array = [];
for ($i=0; $i < $n; $i++) {
    $numbers = preg_split("/[\s,]+/", rtrim(fgets(STDIN)));
    $o = $numbers[0];
    $p = $numbers[1];
    if ($o == 0){
        $q = $numbers[2];
        $array[$p] = $q;
        // print_r($array);
    } else { // 1の場合
        echo $array[$p];
        echo PHP_EOL;
    }
}


Measured memory_bytes: 47776
#include<bits/stdc++.h>
using namespace std;
#define N 400001
#define M 400001
#define forw(i,x) for(int i=fir[x];i;i=ne[i])
#define PER(i,a,b) for(int i=a;i<=b;i++)
int n,m;
int ne[M],fir[M],val[M],to[M],root,fa[M],dfn[M],low[M];
int u,v;
int ans,cnt=1;
bool vis[M];
void add(int u,int v)
{
    to[++cnt]=v;ne[cnt]=fir[u];fir[u]=cnt;
}
void dfs(int df,int no,int fae)
{
    dfn[no]=df;
    vis[no]=1;
    low[no]=df;
    forw(i,no)
    {
        if(!vis[to[i]])
        {
            dfs(df+1,to[i],i);
            low[no]=min(low[no],low[to[i]]);
            if(low[to[i]]>dfn[no]) ans++;
        }
        else
        {
            if(i!=(fae^1))
            low[no]=min(low[no],low[to[i]]);
        }
    }
}
//滚粗啊！一开始把边的编号搞到了vis上，直接伪：论邻接表的常见问题
int main()
{
    scanf("%d%d",&n,&m);
    PER(i,1,m)
    {
        scanf("%d%d",&u,&v);
        add(u,v);add(v,u);
    }
    root=1;
    dfs(1,root,-1);
    cout<<ans<<endl;
}


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

int A, B, D;

int ansx, ansy;
void setans(int x, int y){
	if(x + y < ansx + ansy){
		ansx = x;
		ansy = y;
	}else if(x + y == ansx + ansy && x * A + y * B < ansx * A + ansy * B){
		ansx = x;
		ansy = y;
	}
}
int main(){
	while(cin >> A >> B >> D, A){
		ansx = 100000;
		ansy = 100000;
		for(int i = 0; i <= 10000; i++){
			int val = D - A * i;
			if(val >= 0 && val % B == 0){
				setans(i, val / B);			
			}
			val = A * i - D;
			if(val >= 0 && val % B == 0){
				setans(i, val / B);			
			}

			val = D + A * i;
			if(val >= 0 && val % B == 0){
				setans(i, val / B);			
			}
		}
		cout << ansx << " " << ansy << endl;
	}
}

Measured memory_bytes: 3052
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
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; }
const int INF = 1001001000;
const int MOD = 1000000007;

typedef pair<int, int> P;
int myAbs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく
int N;
bool E[100][100];
vector<bool> seen;
typedef pair<int, int> P;
int D[100];
int F[100];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[100];
int find_time = 0;

void dfs_search(int u) {
    //出発点を訪問済みにする＆行きのタイムスタンプを記録
    int v;
    
    color[u] = 1;
    D[u] = ++find_time;
    //cout << u+1 << " " << color[u] << " " << endl;
    for (v = 0; v < N; v++) {
        //出発点からvへの辺があるか
        if (!E[u][v]) continue;
        //辺がある&&未訪問なら発見した頂点を出発点にして再帰
        if (color[v] == 0) dfs_search(v);
    }
    //今回訪問した頂点より深い未訪問の頂点がない時にその頂点を完了する。
    color[u] = 2;
    F[u] = ++find_time;
}

void dfs() {
    int u;
    find_time = 0;
    for (int i = 0; i < N; i++) color[i] = 0;
    for (u = 0; u < N; u++) {
        //未訪問のuを出発点にしてDFS
        if (color[u] == 0 || color[u] == 1) dfs_search(u);
    }
    //出力
    for (int i = 1; i <= N; i++) {
        cout << i << " " << D[i-1] << " " << F[i-1] << endl;
    }
}

int main() {
    int N; cin >> N;
    vector<int> retu(N);
    for (int i = 0; i < N; i++) {
        cin >> retu.at(i);
    }
    vector<int> dp(N + 1,INF);

    for (int i = 0; i < N; i++) {
        *lower_bound(dp.begin(), dp.end(), retu.at(i)) = retu.at(i);
    }
    int count = 1;
    for (int i = 1; i <= N; i++) {
        //cout << dp.at(i) << endl;
        if (dp.at(i-1) != INF) {
            count = i;
        }
        else break;
    }
    cout << count << endl;
    
}



Measured memory_bytes: 3640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next(), T = sc.next();
    int ans = 0;
    for (int i = 0; i < 3; i++)
      if (S.charAt(i) == T.charAt(i)) ans++; 
    System.out.println(ans);
  }
}


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

const int MAX = 1000000;
const int MOD = 1000000007;

signed main() {
 int n;
 cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int k=1,ans=0;
for(int i=1;i<n;i++){
    if(a[i]!=a[i-1]){
        ans+=k/2;
        k=1;
    }else k++;
}
ans+=k/2;
cout<<ans;

return 0;
}


Measured memory_bytes: 256
mod=1000000007
ans=0
n=int(input())
a=[int(i) for i in input().split()]
x=[[0]*63 for i in range(n+1)]
l=[(2**i)%mod for i in range(63)]

for i in range(n):
    d=a[i]
    cnt=0
    for j in range(63):
        if d&1:
            x[i+1][cnt]=x[i][cnt]+1
        else:
            x[i+1][cnt]=x[i][cnt]
        cnt+=1
        d=d>>1

for i in range(1,n):
    for j in range(63):
        p=x[i][j]-x[i-1][j]
        if p:
            ans+=l[j]*((n-i)-(x[-1][j]-x[i][j]))
        else:
            ans+=l[j]*(x[-1][j]-x[i][j])
        ans%=mod
print(ans)

Measured memory_bytes: 207308
#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long

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

    int n;
    cin >> n;
    double x;
    priority_queue<double , vector<double> , greater<double> > pq;
    for(int i = 0 ; i < n ; i++) cin >> x , pq.push(x);

    while(pq.size() > 1)
    {
        double f = pq.top();
        pq.pop();
        double s = pq.top();
        pq.pop();
        pq.push((f + s) / 2);
    }
    cout << fixed << setprecision(5) << pq.top();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, w;
int utezi[2][111];
long long dp[111][100011] = {{0}};
int main(){
	cin>>n>>w;
	for(int i = 0; i < n; i++){
		cin>>utezi[0][i]>>utezi[1][i];
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= w; j++){
			if(utezi[0][i - 1] > j) dp[i][j] = dp[i - 1][j];	
			else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - utezi[0][i - 1]] + utezi[1][i - 1]);
		}
	}
	cout<<dp[n][w];
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int a, b, c;

  cin >> a >> b >> c;

  int result = c - (a - b);

  if (result < 0) {
    result = 0;
  }

  cout << result << endl;
}

Measured memory_bytes: 256
// C++ program to find the longest repeated 
// non-overlapping substring 
#include<bits/stdc++.h> 
using namespace std; 
#define int long long

// Returns the longest repeating non-overlapping 
// substring in str 
int longestRepeatedSubstring(string str) 
{ 
  int n = str.length(); 
  int LCSRe[n+1][n+1]; 

  // Setting all to 0 
  memset(LCSRe, 0, sizeof(LCSRe)); 

  string res; // To store result 
  int res_length = 0; // To store length of result 

  // building table in bottom-up manner 
  int i, index = 0; 
  for (i=1; i<=n; i++) 
  { 
    for (int j=i+1; j<=n; j++) 
    { 
      // (j-i) > LCSRe[i-1][j-1] to remove 
      // overlapping 
      if (str[i-1] == str[j-1] && 
        LCSRe[i-1][j-1] < (j - i)) 
      { 
        LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 

        // updating maximum length of the 
        // substring and updating the finishing 
        // index of the suffix 
        if (LCSRe[i][j] > res_length) 
        { 
          res_length = LCSRe[i][j]; 
          index = max(i, index); 
        } 
      } 
      else
        LCSRe[i][j] = 0; 
    } 
  } 

  // If we have non-empty result, then insert all 
  // characters from first character to last 
  // character of string 
  if (res_length > 0) 
    for (i = index - res_length + 1; i <= index; i++) 
      res.push_back(str[i-1]); 

  return res.size(); 
} 

// Driver program to test the above function 
int32_t main() 
{ 

  long n;
  cin >> n;
  string str;
  cin >> str; 
  cout << longestRepeatedSubstring(str); 
  return 0; 
} 


Measured memory_bytes: 195712
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int mod = 1e9+7;
const int N = 1e5+5;
int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    string s, t;

    cin >> s >> t;

    int n = s.size();

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

        string tmp;

        tmp+=s[n-1];
        tmp+=s.substr(0, n-1);

        s = tmp;

        if (s == t) {

            cout << "Yes";
            return 0;
        }
    }

    cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
    vector<int> a(3,0);
    cin>>a[0]>>a[1]>>a[2];
    sort(a.begin(),a.end());
    if(a[0]==5 && a[1]==5 && a[2]==7){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
   
    return 0;
    // Your code here!
    
}


Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;

  lll n;

  cin >> n;
  lll ans;

  ans = 0;

  //for(jj=1;jj<=n;jj++){
  //  for(ii=1;ii<=n;ii++){
  //    if(ii % jj == 0){
  //      ans += ii;
  //    }
  //  }
  //}

  ans = 0;
  
  lll k,x;
  lll sum;

  for(ii=1;ii<=n;ii++){

    k = ii;
    x = n/ii;

    sum = k * ( x * ( x + 1) / 2 );

    ans += sum;
    
  }
  
  cout << ans << endl;

  return 0;

}


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

int main() {
  string S;
  cin>>S;
  int L=S.size();
  bool Ans=true;
  rep(i,L/2){
if(S.at(i)!=S.at(L-1-i)){
Ans=false;
break;
}
  }
  rep(j,(L-1)/4){
    if(S.at(j)!=S.at((L-1)/2-j-1)||S.at((L+3)/2-1+j)!=S.at(L-j-1)){
Ans=false;
break;
    }
  }
  if(Ans==true){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 2100

int N;
int x;
int a[MAX];
int mi[MAX][MAX];

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int ans = INF;
	
	cin>>N>>x;
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
	}
	int xx = 0;
	
	for(int i = 0; i < N; i++){
		int mii = INF, minj = 0;
		for(int j = 0; j < N; j++){
			if(mii > a[(i+N-j)%N]){
				mii = a[(i+N-j)%N];
				minj = j;
			}
			mi[i][j] = minj;
			// cout<<i<<" "<<j<<" "<<mi[i][j]<<endl;
		}
		
		xx = max(minj,xx);
	}
	
	for(int i = 0; i < N; i++){
		int temp = 0;
		for(int j = 0; j < N; j++){
			temp  += a[(j+N-mi[j][i])%N];
		}
		// cout<<i<<"  "<<ans<<" "<<temp+x*i<<endl;
		ans = min(temp+x*i,ans);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

using namespace std;

int main()
{
    unsigned long long n, min_dist = LONG_LONG_MAX;
    cin >> n;
    long long sqr = sqrtl(n);
    for (int i = 1; i <= sqr; i++)
    {
        if (n % i == 0)
        {
            min_dist = min(min_dist, i - 1 + n / i - 1);
        }
    }
    // cout << "No" << endl;
    cout << min_dist << endl;
}

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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())
#define mp            make_pair
#define pb            push_back


typedef long long ll;

using namespace std;

int main(){
  int n;
  cin >> n;
  rep(i, 110/4){
    rep(j, 110/7){
      if(4*i + 7*j == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
class UnionFind {
  public:
    vector<int> parent;
    UnionFind(int n) {
        parent = vector<int>(n, -1);
    }
    int root(int a) {
        if (parent[a]<0) return a;
        return parent[a] = root(parent[a]);
    }
    int size(int a) {
        return -parent[root(a)];
    }
    bool connect(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) {
            return false;
        }
        if (size(a)<size(b)) swap(a, b);
        parent[a] += parent[b];
        parent[b] = a;
        return true;
    }
};
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    UnionFind U(N);
    int x, y, z;
    while (M--) {
        cin >> x >> y >> z;
        U.connect(x-1, y-1);
    }
    map<int, int> R;
    for (int i = 0; i<N; i++) {
        R[U.root(i)]++;
    }
    printf("%d\n", (int)R.size());
    return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

const ll INF = 1LL << 50;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];
    vector<ll> cumsum(N);
    rep(i, 0, N) {
        cumsum[i] = A[i] + (i == 0 ? 0 : cumsum[i - 1]);
    }
    ll ans = INF;
    rep(i, 0, N - 1) {
        // i番目までの区間を左の要素とする.
        ll left_len = cumsum[i];
        ll right_len = cumsum[N - 1] - cumsum[i];
        ans = min(ans, abs(left_len - right_len));
    }
    cout << ans << endl;
    return 0;
}

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


#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
// User defined sizeof macro
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))


int main()

{
    optimize();
    int n;
    string s;
    cin>>n;
    for(int i=0;i<n ;i++)
        {
            s+="ACL";


        }
        cout<<s;













    return 0;
}





Measured memory_bytes: 3652
import java.util.*;

class Main {
    static int f(int[]e){
        int m=24;
        for(int i=0;i<24;++i)
            for(int j=0;j<24;++j)
                if(i!=j&&e[i]>0&&e[j]>0)
                    m=Math.min(m,Math.min((i-j+24)%24,(j-i+24)%24));
        return m;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();
        int[]d=new int[13];
        d[0]=1;
        for(int i=0;i<n;++i){
            d[scan.nextInt()]++;
        }
        for(int i=0;i<=12;++i)
            if(((i==0||i==12)&&d[i]>=2)||(i!=0&&i!=12&&d[i]>=3)){
                System.out.println(0);
                return;
            }
        int[]e=new int[24];
        int s=0;
        for(int i=0;i<=12;++i){
            if(d[i]==0)continue;
            if(((i==0||i==12)&&d[i]==1)||(i!=0&&i!=12&&d[i]==2)){
                e[i]=e[(24-i)%24]=1;
                continue;
            }
            s|=1<<i;
        }
        int m=0;
        for(int t=0;t<=s;++t){
            if((t|s)!=s)continue;
            for(int i=1;i<=11;++i)
                if((t&1<<i)!=0)e[i]=1;
                else if((s&1<<i)!=0)e[24-i]=1;
            m=Math.max(m,f(e));
            for(int i=1;i<=11;++i)
                if((s&1<<i)!=0)e[i]=e[24-i]=0;
        }
        System.out.println(m);
    }
}


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

using namespace std;

#define sd(x) scanf("%d", &x)
#define boost ios_base::sync_with_stdio(false);
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define f first
#define s second
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef pair <int, int> pii;
typedef long long ll;
typedef vector <vector <ll>> matrix;

const int mod = 1000000007;
const int inf = 50000000;
const int maxn = 100010;

int n, cnxtA[maxn], cnxtB[maxn], dp[maxn][2];
ll a, b, S[maxn];

int add(int x, int y) {
	x = (x + y) % mod;
	return x;
}

int solve(int x, int y) {
	if (x > n) {
		return 1;
	}
	if (dp[x][y] != -1) {
		return dp[x][y];
	}
	int ret = 0;
	if (y == 0) {
		if (S[x] - S[x - 1] >= a) {
			ret = add(ret, solve(x + 1, y));
		}
		int idx = max(x + 1, (int)(lower_bound(S + 1, S + n + 1, S[x - 1] + a) - S));
		if (cnxtB[x] >= idx) {
			ret = add(ret, solve(idx, 1));
		}
	}
	else {
		if (S[x] - S[x - 1] >= b) {
			ret = add(ret, solve(x + 1, y));
		}
		int idx = max(x + 1, (int)(lower_bound(S + 1, S + n + 1, S[x - 1] + b) - S));
		if (cnxtA[x] >= idx) {
			ret = add(ret, solve(idx, 0));
		}	
	}
	return dp[x][y] = ret;
}

int main() {
	// freopen("i.txt", "r", stdin);
	// freopen("o.txt", "w", stdout);
	memset(dp, -1, sizeof(dp));
	scanf("%d %lld %lld", &n, &a, &b);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &S[i]);
	}
	cnxtA[n] = cnxtB[n] = n + 1;
	for (int i = n - 1; i >= 1; i--) {
		if (S[i + 1] - S[i] < a) {
			cnxtA[i] = i + 1;
		}
		else {
			cnxtA[i] = cnxtA[i + 1];
		}
		if (S[i + 1] - S[i] < b) {
			cnxtB[i] = i + 1;
		}
		else {
			cnxtB[i] = cnxtB[i + 1];
		}
	}
	int ans = add(solve(2, 0), solve(2, 1));
	printf("%d\n", ans);
	return 0;
}


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

int main() {
  string s;
  int y, m, d;

  while (cin >> s >> y >> m >> d) {
    if (s == "#") {
      return 0;
    }

    pair< int, pair< int, int > > p(y, pair< int, int >(m, d)), h(31, make_pair(4, 30));

    if (p <= h) {
      cout << s << " " << y << " " << m << " " << d << endl;
    } else {
      cout << "?" << " " << y - 30 << " " << m << " " << d << endl;
    }
  }
}



Measured memory_bytes: 3168
#include <stdio.h>

int main(void)
{
	int n, m;
	int in[1000][100];
	int countF[100], countS[100];
	int ans[100], used[100];
	int i, j;
	
	while (1){
		scanf("%d %d", &n, &m);
		
		if (n == 0 && m == 0){
			break;
		}
		
		for (i = 0; i < 1000; i++){
				for (j = 0; j < 100; j++){
				in[i][j] = 0;
			}
		}
		
		for (i = 0; i < 100; i++){
			countF[i] = 0;
			countS[i] = 0;
			ans[i] = used[i] = 0;
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < m; j++){
				scanf("%d", &in[i][j]);
				
				if (in[i][j] == 1){
					countF[j]++;
					countS[j]++;
				}
			}
		}
		
		for (i = 0; i < m - 1; i++){
			for (j = 0; j < m - i - 1; j++){
				if (countS[j] < countS[j + 1]){
					countS[j] += countS[j + 1];
					countS[j + 1] = countS[j] - countS[j + 1];
					countS[j] -= countS[j + 1];
				}
			}
		}
		
		for (i = 0; i < m; i++){
			for (j = 0; j < m; j++){
				if (countS[i] == countF[j] && used[j] == 0){
					ans[i] = j + 1;
					used[j] = 1;
					break;
				}
			}
		}
		
		for (i = 0; i < m; i++){
			if (i != 0){
				printf(" ");
			}
			
			printf("%d", ans[i]);
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 1424
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M; cin >> N >> M;
  vector<ll> A(N);
  vector<pair<ll, ll>> BC;
  BC.resize(M);
  rep(i,N) cin >> A[i];
  rep(i,M) {
    cin >> BC[i].second >> BC[i].first;
  }
  sort(A.begin(), A.end());
  sort(BC.begin(), BC.end());
  ll j = 0;
  for(ll i=BC.size()-1; i>=0;) {
    if(BC[i].first > A[j] && BC[i].second > 0) {
      A[j] = BC[i].first;
      BC[i].second--;
      ++j;
    } else {
      --i;
    }
  }
  ll ans = 0;
  rep(i, N) ans += A[i];
  cout << ans << endl;
}

Measured memory_bytes: 2560
use std::io::stdin;
use std::collections::HashMap;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let _n = st.trim().parse::<i32>().unwrap();
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s:Vec<char> = st.trim().chars().collect();
    let mut map:HashMap<&char, i64> = HashMap::new();
    for i in &s {
        let count = map.entry(i).or_insert(1);
        *count += 1;
    };
    let mo = 1000000007;
    let mut result:i64 = 1;
    for (_i, j) in map.iter() {
        result = (result*j)%mo;
    };
    println!("{}", result-1);
}

Measured memory_bytes: 4352
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=1e6+5;
int n,m;
int V,x[maxn],R[maxn][25],L[maxn][25];
int S1[maxn],S2[maxn];
int minL[maxn];
int main(){
	read(n);read(V);
	if(n>2e5)assert(0);
	rep(i,1,n)read(x[i]);
	while((1<<m)<=V)m++;m++;
	rep2(i,0,m){
		R[n+1][i]=n;
		per(j,n,1)
			if(x[j+1]-x[j]<=(V>>i))R[j][i]=R[j+1][i];
			else R[j][i]=j;
		L[0][i]=1;
		rep(j,1,n)
			if(x[j]-x[j-1]<=(V>>i))L[j][i]=L[j-1][i];
			else L[j][i]=j;
	}
	rep2(i,0,1<<m)S2[i]=n+1;
	rep2(i,0,1<<m)rep2(j,0,m)if(!(i&(1<<j))){
		S1[i|(1<<j)]=max(S1[i|(1<<j)],R[S1[i]+1][j]);
		S2[i|(1<<j)]=min(S2[i|(1<<j)],L[S2[i]-1][j]);
	}
	rep(i,0,n)minL[i]=n+2;
	rep2(i,0,1<<m)if(!(i&1))minL[S1[i]]=min(minL[S1[i]],S2[((1<<m)-1)^i^1]);
	per(i,n-1,0)minL[i]=min(minL[i],minL[i+1]);
	rep(i,1,n){
		if(minL[L[i][0]-1]<=R[i][0]+1)puts("Possible");
		else puts("Impossible");
	}
	return 0;
}

Measured memory_bytes: 56448
import sys
t={'o':1,'x':-1,'s':0}
for l in sys.stdin:
 d=[t[s]for s in l.strip()]
 a=[sum(d[0:3]),sum(d[3:6]),sum(d[6:]),sum(d[0::3]),sum(d[1::3]),sum(d[2::3]),sum(d[0::4]),sum(d[2:8:2])]
 print('o'if 3 in a else'x'if -3 in a else'd')

Measured memory_bytes: 5564
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;

#define INF 1e18
#define int long long

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

    int n = s.size();
    vector<int> v(3, 0);
    for(int i = 0; i < n; i++) {
        int idx = s[i] - 'a';
        v[idx]++;
    }

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

    if(v[0] - 1 <= v[2] && v[2] <= v[0]) {
        if(v[0] - 1 <= v[1] && v[1] <= v[0]) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
import itertools
n,m,q = map(int, input().split())
p=[[0,0,0,0]]
for i in range(q):
    p.append(list(map(int, input().split())))

ans=0

for tmp in itertools.combinations_with_replacement(range(1,m+1),n):
    tokuten=0
    for gyou in range(1,q+1):
        if tmp[p[gyou][1]-1]-tmp[p[gyou][0]-1]==p[gyou][2]:
            tokuten+=p[gyou][3]
    ans=max(ans,tokuten)

print(ans)

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


 int cnt_digits(ll N){
 int digits=0;

 while(N>0){
 N/=10;
digits++;
}
 return digits;
}

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

 int ans=cnt_digits(N); // 1*N=N max(cnt_digits(1),cnt_digits(N))=cnt_digits(N)

for(ll A=1LL;A*A<=N;++A){
if(N%A!=0) continue;
 const ll B=N/A;

 const int cur=max(cnt_digits(A),cnt_digits(B));

 if(ans>cur){
 ans=cur;
 }
 }

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

Measured memory_bytes: 256
//  Copyright 2019 Nikita Golikov

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

struct restaurant {
  std::string city;
  int score;
  int index;
};

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  std::vector<restaurant> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].city >> a[i].score;
    a[i].index = i;
  }
  std::sort(a.begin(), a.end(), [](auto const& a, auto const& b) {
    return std::make_pair(a.city, -a.score) < std::make_pair(b.city, -b.score);
  });
  for (auto const& x : a) {
    cout << x.index + 1 << "\n";
  }
  return 0;
}


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

#define int long long

using namespace std;

const int MAXN = 1e5 + 100;

int arr[MAXN];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    int sum = 0;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	arr[n]++;
    	sum += n;
    }

   	int Q;
   	cin >> Q;

   	for(int i = 0 ; i < Q ; i++)
   	{
   		int b, c;
   		cin >> b >> c;
   		int temp = arr[b];
   		arr[b] = 0;
   		sum -= temp*b;
   		sum += temp*c;
   		arr[c] += temp;
   		cout << sum << '\n';
   	}

    return 0;
}

Measured memory_bytes: 4364
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long INF = 1L<<59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto D = s[1].to!long;
    auto A = readln.split.map!(to!long).array;

    auto dist = new long[](2*N);
    auto color = new int[](2*N);
    auto pq = new BinaryHeap!(Array!(Tuple!(int, int, long)), "a[2] > b[2]");
    foreach (i; 0..N) pq.insert(tuple(i, i, 0L));
    dist[] = 1L << 59;


    while (!pq.empty) {
        auto n = pq.front[0];
        auto c = pq.front[1];
        auto d = pq.front[2];
        pq.removeFront;
        if (dist[n] <= d) continue;
        dist[n] = d;
        color[n] = c;

        if (n < N) {
            int m = n + N;
            long nd = d + A[n];
            if (dist[m] > nd) {
                pq.insert(tuple(m, c, nd));
            }
        } else {
            foreach (k; [-1, 1]) {
                int m = n + k;
                if (m < N || m >= 2*N) continue;
                long nd = d + D;
                if (dist[m] > nd) {
                    pq.insert(tuple(m, c, nd));
                }
            }
        }
    }


    long ans = 0;

    foreach (i; N..2*N) {
        if (color[i] != color[i-N]) {
            ans += abs(color[i] - color[i-N]) * D + A[color[i]] + A[color[i-N]];
        }
        if (i < 2*N-1 && color[i] != color[i+1]) {
            ans += abs(color[i] - color[i+1]) * D + A[color[i]] + A[color[i+1]];
        }
    }

    ans.writeln;
}


Measured memory_bytes: 22576
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int K = scan.nextInt();
        int N = scan.nextInt();
        int first = 0;
        int last = 0;
        int prev = 0;
        int curr = 0;
        int maxD = 0;
        first = scan.nextInt();
        prev = first;
        for(int i = 1; i < N; i++) {
            curr = scan.nextInt();
            maxD = Math.max(maxD, curr - prev);
            prev = curr;
            if(i == N-1)
                last = curr;
        }
        maxD = Math.max(maxD, K + first - last);
        os.println(K-maxD);
    }
}

Measured memory_bytes: 64704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}

};

int main() {
	int n, m;
	cin >> n >> m;
	int in1, in2;
	vi a(m),b(m);
	vector<vector<tuple<int, int>>> vv(n + 1);
	rep(i, m) {
		cin >> in1 >> in2;
		a[i]=in1;
		tuple<int, int> t;
		t = make_tuple(i + 1, in2);
		vv[in1].push_back(t);
	}
	
	rep(i, n + 1) {
		sort(all(vv[i]), compare());
		rep(j, vv[i].size()) {
			b[get<0>(vv[i][j])-1] = j + 1;
		}
	}
	rep(i, m) {
		printf("%06d%06d\n", a[i], b[i]);
	}
}

Measured memory_bytes: 7808
#pragma GCC optimize("Ofast")

// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
// #define NP next_permutation;
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
// typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
// using vvvi=vector<vvi>;
/*
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
*/
template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
// template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
/*
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10); x/=10;} reverse(all(res)); return res;}
*/
void solve() {
  ll n,k,q; cin>>n>>k>>q;
  vi AC(n,0);
  // vi A(q); rep(i,q) cin>>A[i];
  rep(i,q){
    ll p; cin>>p;
    AC[p-1]++;
  }
  rep(i,n){
    if(q-AC[i]<k) out("Yes");
    else out("No");
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

void solve(vector<int> &v, vector<vector<int>> &ans, int k) {

    if (v.size() < 2) return;

    vector<int> a, b;
    int n = v.size();
    rep(i, n) {
        if (i % 2 == 0) a.push_back(v[i]);
        else b.push_back(v[i]);
    }

    for (int x : a) {
        for (int y : b) {
            ans[x][y] = k;
            ans[y][x] = k;
        }
    }

    solve(a, ans, k + 1);
    solve(b, ans, k + 1);

}

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

    vector<vector<int>> ans(n, vector<int>(n, -1));
    vector<int> v;
    rep(i, n) v.push_back(i);

    solve(v, ans, 0);

    rep(i, n) {
        rep(j, n) {
            if (i >= j) continue;
            cout << ans[i][j] + 1 << ' ';
        }
        cout << endl;
    }

}


Measured memory_bytes: 4608
'use strict';
(function(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  const N=input.shift();
  const K=input.shift();
  const M=Math.pow(10,9)+7;
  const a=input;
  const dp=new Array(N).fill(0).map(x=>new Array(K+1).fill(0));
  //dp[i][k]で添字0~iの子供だけで考えた、飴玉0~k個を消費する場合の数の総和
  
  dp[-1]=new Array(K+1).fill(1);
  for(let i=-1;i<N;i++)dp[i][-1]=0;
  
  for(let i=0;i<N;i++){
    for(let k=0;k<=a[i];k++)
      dp[i][k]=(dp[i][k-1]+dp[i-1][k])%M;
    for(let k=a[i]+1;k<=K;k++)
      dp[i][k]=(dp[i][k-1]+dp[i-1][k]-dp[i-1][k-a[i]-1])%M;
  }
  
  //console.log(dp);
  const ans=(dp[N-1][K]-dp[N-1][K-1]+M)%M;
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    string S;
    cin >> S;
    int res = INT_MAX;
    for(char c='a';c<='z';c++){
        int ma = 0;
        int count = 0;
        for(char C : S){
            if(C == c){
                ma = max(ma,count);
                count = 0;
                continue;
            }
            count++;
        }
        if(ma){
            ma = max(ma,count);
            res = min(res,ma);
        }
    }

    cout << (res > 100 ? 0 : res);

    return 0;
} 

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

int main(){
  string S;
  cin >> S;
  
  vector<int> R;
  for(int i=0; i<S.size()-1; i++){
    if(S.at(i)=='R'&&S.at(i+1)=='L'){
      R.push_back(i);
    }
  }
  R.push_back(S.size()+1);
  
  vector<int> RL;
  int i=0;
  while(i<S.size()){
    RL.push_back(0);
    while(S.at(i)=='R'){
      RL.back()++;
      i++;
    }
    RL.push_back(0);
    while(i<S.size()&&S.at(i)=='L'){
      RL.back()++;
      i++;
    }
  }
  
  int r=0,rl=0;
  for(i=0; i<S.size(); i++){
    if(i>R[r]+1){
      r++;
      rl+=2;
    }
    if(i<R[r]){
      cout << "0";
    }
    if(i==R[r]){
      cout << (RL[rl]+1)/2+RL[rl+1]/2;
    }
    if(i==R[r]+1){
      cout << RL[rl]/2+(RL[rl+1]+1)/2;
    }
    
    if(i<S.size()-1){
      cout << ' ';
    }
  }
  cout << endl;
}

Measured memory_bytes: 1340
import sys
input = sys.stdin.readline

n = int(input())
a = tuple(map(int,input().split()))
const = 10**9 + 7

ans = 0

zero = [0] * 60
one = [0] * 60

for i in range(60):
    for j in range(n):
        if a[j] >> i & 1:
            one[i] += 1
        else:
            zero[i] += 1

ans = 0

for i in range(60):
    ans += one[i] * zero[i] * 2**i
    ans %= const

print(ans)

Measured memory_bytes: 123132