akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val ansList = mutableListOf<Pair<Int, Int>>()
    var ll = 1
    var lr = ll + m
    var rl = lr + 1
    var rr = rl + m - 1
    while (ll < lr) {
        ansList.add(Pair(ll++, lr--))
    }
    while (rl < rr) {
        ansList.add(Pair(rl++, rr--))
    }

    for (i in 0 until m) {
        println(ansList[i].first.toString() + " " + ansList[i].second)
    }
}

Measured memory_bytes: 61732
#include <bits/stdc++.h>
const int M = 1e9 + 7;
using namespace std;
int main()
{
    long long n,m,ans=1;
    cin>>n>>m; 
    if(abs(m-n)>1)
    {
        cout<<"0\n";
        return 0;
    }
    for(int i=1; i<=n; i++) 
        ans=ans*i%M; 
    for(int i=1; i<=m; i++)
        ans =ans*i%M; 
    cout<<(n!=m?ans:ans*2 % M) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l,sum;
    cin>>n>>l;
    sum=(n*(2*l+n-1))/2;
    if(l>0)sum-=l;
    else if(l+n-1<0)sum-=l+n-1;
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    for(int i=0;i<n;i++) cin>>p[i];

    int res=0;
    for(int i=1;i+1<n;i++){
        int minv=min({p[i-1],p[i],p[i+1]});
        int maxv=max({p[i-1],p[i],p[i+1]});
        if(minv!=p[i] && maxv!=p[i]) res++;
    }
    cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 256
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, = gi()
l = gi()
l = [(l[k], k + 1) for k in range(n)]
l.sort()
ans = [e[1] for e in l]
print(" ".join(map(str, ans)))

Measured memory_bytes: 68780
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N_MAX 200000

long long A[N_MAX];

int comp(const void *a, const void *b)
{
    long long v1 = *((long long *)a);
    long long v2 = *((long long *)b);

    if (v1 < v2) {
      return 1;
    } else if (v1 > v2) {
      return -1;
    } else {
      return 0;
    }
}

int main(void)
{
    int N;
    int i;
    int flag = 1;

    scanf("%d", &N);
    for ( i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    qsort(A, N, sizeof(long long), comp);

    for ( i = 0; i < ( N - 1 ); i++ ){
        if ( A[i] == A[i + 1]) {
            flag = 0;
            break;
        }
    }

    if ( flag == 1 ) {
        printf("YES");
    } else {
        printf("NO");
    }

    return 0;
}

Measured memory_bytes: 3324
#include <iostream>
using namespace std;
int main(){
    
    int N , Max = 0 , min = 2000 ;
    cin >> N ;
    
    int x[N] ;
    
    for(int i = 1 ; i <= N ; i++){
        cin >> x[i] ;
    }
    
    for(int j = 1 ; j <= N ; j++){
        if(Max <= x[j]){
            Max = x[j] ;
        }
        if(min >= x[j]){
            min = x[j] ;
        }
    }
    
    int S ;
    S = (Max - min + 1) / 2 ;
    
    cout << S << endl ;
}


Measured memory_bytes: 3084
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] a = new int[N];
	int max = 0;
	long result = 0;
	for(int i = 0; i<N; i++) {
	    a[i] = sc.nextInt();
	    max = Math.max(max, a[i]);
	    result += a[i] - 1;
	}
	System.out.println(result);
    }
}

Measured memory_bytes: 27316
#include <stdio.h>
int main(void)
{
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
{
scanf("%d",&a[n-i-1]);
}
printf("%d",a[0]);
for(int i=1;i<n;i++)
{
printf(" %d",a[i]);
}
printf("\n");
}


Measured memory_bytes: 2104
n, k = map(int, input().split())
p = list(map(int, input().split()))


def calc_mean(p):
    return (p + 1) / 2


max_value = 0
for i in range(k):
    max_value += calc_mean(p[i])

r = k
cur_value = max_value
for l in range(1, n - k + 1):
    cur_value = cur_value - calc_mean(p[l - 1]) + calc_mean(p[r])
    max_value = max(max_value, cur_value)
    r += 1

print(max_value)


Measured memory_bytes: 25060
x,n=map(int,input().split())
if n==0:
    print(x)
    quit()
p=list(map(int,input().split()))
if x not in p:
    print(x)
    quit()
i=0
while True:
    if x-i not in p:
        print(x-i)
        quit()
    elif x+i not in p:
        print(x+i)
        quit()
    i+=1

Measured memory_bytes: 9192
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        string S = ReadLine();
        int N = S.Length;
        int point = 0;
        int now = 0;
        int[] ans = new int[N];
        while (now < N)
        {
            int r = 0;
            int l = 0;
            while (now < N && S[now] == 'R')
            {
                r++;
                now++;
            }
            point = now;
            while (now < N && S[now] == 'L')
            {
                l++;
                now++;
            }

            if (point == 0)
            {
                ans[0] = l;
            }
            else if (point == N)
            {
                ans[point - 1] = r;
            }
            else
            {
                int f = r / 2 + r % 2 + l / 2;
                int s = r / 2 + l / 2 + l % 2;
                /*
                if (Max(f, s) % 2 == 0)
                {
                    swap(ref f,ref s);
                }
                */
                ans[point - 1] = f;
                ans[point] = s;
            }
        }
        WriteLine(string.Join(" ",ans));
    }
    static void swap(ref int f,ref int s)
    {
        var temp = f;
        f = s;
        s = temp;
    }
}


Measured memory_bytes: 27512
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const int inf = 0x3f3f3f3f;
int t;
int n,m; 
int a[1005];
int b[1005];
int dp[(1<<14)];
int main()
{
	scanf("%d%d",&n,&m);
	int tmp;
	for(int i=0;i<m;++i)
	{
		scanf("%d%d",&a[i],&tmp); 
		b[i] = 0;
		int x;
		while(tmp--)
		{
			scanf("%d",&x); --x;
			b[i]|=(1<<x);
		}
	}
	int N = (1<<n);
	for(int i=0;i<N;++i) dp[i] = inf;
	dp[0] = 0;
	for(int j=0;j<m;++j)
	{
		for(int i=0;i<N;++i)
		{
			dp[i|b[j]] = min(dp[i|b[j]],dp[i]+a[j]);
		}
	}
	if(dp[N-1]==inf){
		puts("-1"); return 0;
	}
	printf("%d\n",dp[N-1]);
}


Measured memory_bytes: 256
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
const int MYINF = 1e9+7;

int main(int argc, char **argv)
{
	int m, f, r;

	for (;;) {
		int mf;
		char res = 'F';
		scanf("%d %d %d", &m, &f, &r);
		mf = m + f;
		if (m < 0 && f < 0 && r < 0) break;
		else if (m < 0 || f < 0) res = 'F';
		else if (mf >= 80) res = 'A';
		else if (mf >= 65) res = 'B';
		else if (mf >= 50 || r >= 50) res = 'C';
		else if (mf >= 30) res = 'D';

		printf("%c\n", res);
	}
	return 0;
}

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

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

Measured memory_bytes: 3636
N = int(input())

def base_10_to_n(X, n):
    if (int(X/n)):
        return base_10_to_n(int(X/n), n)+str(X%n)
    return str(X % n)

def convert(X):
    T = base_10_to_n(X, 3)
    R = ''
    for t in str(T):
        t = int(t)
        if t == 0:
            R += '3'
        elif t == 1:
            R += '5'
        elif t == 2:
            R += '7'
    return R[1:]

ans = 0
searched = set()
for i in range(27, 200000):
    r = convert(i)
    if r in searched:
        continue
    if int(r) > N:
        break
    if len(set(list(r))) == 3:
        searched.add(r)
        ans += 1

print(ans)

Measured memory_bytes: 72408
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(int i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(i) bit & (1<<i)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back


#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T = int>
void print(vec<T> v){ cout << "["; for (T item: v) { cout << item << ", "; } cout << "]" << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

void Main() {
    //code here
    int n = gi, m = gi;
    vec<vec<int>> switchPatterns;
    REP(i,m) {
        int k = gi;
        switchPatterns.add(gim(k));
    }
    vec<int> switchConditions = gim(m);


    int resCount = 0;
    BITSEARCH(bit, n) {
        bool res = true;
        REP(i, m) {
            int count = 0;
            for (int p: switchPatterns[i]) {
                if (isOne(p-1)) count++;
            }
            if (count%2 != switchConditions[i]) {
                res = false;
                break;
            }
        }
        if (res == true) {
            resCount ++;
        }
    }
    print(resCount);
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<double>   vd;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;

int main(){

	int n;
	sf1(n);


	printf("0\n");
	fflush(stdout);

	string s;
	cin >> s;

	if(s == "Vacant"){
		return 0;
	}

	bool b = (s != "Male");


	int l = 1;
	int r = n-1;

	while(1){

		string s;
		int mid = (l+r)/2;
		printf("%d\n",mid );
		fflush(stdout);
		cin >> s;


			if(s == "Vacant")
				return 0;
			bool b1 = (s != "Male");

			if((b != b1 and !(mid % 2)) or (b == b1 and (mid % 2))){
				r = mid-1;
			}
			else
				l = mid+1;
		
	}


}	


Measured memory_bytes: 852
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll N;
  cin >> N;

  vector<ll> cnt(N+1,0);
  for(int i=1;i<N+1;i++){
    for(int j=i;j<N+1;j+=i){
      cnt.at(j)++;
    }
  }
  ll ans=0;
  for(int i=1;i<N+1;i++){
    ans+=i*cnt.at(i);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 81336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iH = int.Parse(sS[0]);
            int iW = int.Parse(sS[1]);
            List<List<string>> lstGrid = new List<List<string>>();
            for (int i = 0; i < iH; i++)
            {
                string s2 = Console.ReadLine().Trim();
                List<string> oneUsr = new List<string>();
                for (int j = 0; j < s2.Length; j++)
                {
                    oneUsr.Add(s2.Substring(j, 1));
                }
                lstGrid.Add(oneUsr);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstGrid.RemoveAll((x) => !x.Contains("#"));             // 行削除これは1行で書けて楽
            List<int> lstDelCol = new List<int>();                  // 列削除これは1列ずつ調査して後で削除で面倒
            for (int j = 0; j < lstGrid[0].Count; j++)              // 左列から調査
            {
                Boolean bEx = false;
                for (int i = 0; i < lstGrid.Count; i++)             // 行ごとに調査
                {
                    if (lstGrid[i][j] == "#") { bEx = true; break; }
                }
                if (!bEx) { lstDelCol.Add(j); }                      // 削除予定列IndexNo
            }
            lstDelCol.Reverse();                                    // IndexNoを大きい順に
            for (int i = 0; i < lstGrid.Count; i++)                 // 行ごとに削除
            {
                for (int k = 0; k < lstDelCol.Count; k++)           // 行ごとに削除
                {
                    lstGrid[i].RemoveAt(lstDelCol[k]);              // ListのIndexNoの大きい方から削除しないと矛盾発生
                }
            }

            // 出力
            for (int i = 0; i < lstGrid.Count; i++)
            {
                System.Console.WriteLine("{0}", string.Join("", lstGrid[i]).ToString().Trim());
            }

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 11348
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

const int INF = 0x3f3f3f3f;
const double EPS = 1e-9; 
const int MAXN = 100000 + 10;
const int MOD = 1e9 + 7;

int inv[2 * MAXN + 10];
int pro[2 * MAXN + 10];
int sum_inv[2 * MAXN + 10];

void Prepare_pro(int n) {
    pro[0] = 1;
    for (int i = 1; i <= n; ++i) {
        pro[i] = (long long)pro[i - 1] * i % MOD;
    }
}

void Prepare_inv(int n, int M) //处理从1-n的逆元，模为M
{
    inv[1] = 1; //1 的逆元是1
    for (int i = 2; i <= n; i++)
        inv[i] = (long long)(M - M / i) * inv[M % i] % M;
}

void Prepare_sum(int n) {
    sum_inv[0] = 1;
    sum_inv[1] = 1;
    for (int i = 2; i <= n; ++i) {
        sum_inv[i] = (long long)sum_inv[i - 1] * inv[i] % MOD;
    }
}

int C(int n, int m) {
    return  ((long long)pro[n] * sum_inv[m] % MOD) * sum_inv[n - m] % MOD; 
}

int H, W, A, B;

void solve() {
    scanf("%d%d%d%d", &H, &W, &A, &B);
    int ans = (long long)C(H - A - 1 + B, H - A - 1) * C(A + W - B - 1, A) % MOD;
    for (int i = B + 2; i <= W; ++i) {
        ans =((long long)C(H - A - 2 + i - 1, H - A - 2) * C(A + W - i, A) % MOD + ans) % MOD;
    }
    printf("%d\n", ans);
}

int main() {
    Prepare_inv(2 * MAXN, MOD);
    Prepare_pro(2 * MAXN);
    Prepare_sum(2 * MAXN);
    solve();
    return 0;
}

Measured memory_bytes: 2560
#include"bits/stdc++.h"
using namespace std;
struct point{
	double x,y;
}p[10000];
double n;
int num=0;
double ans=0;
int a[10],flag[10];
void dfs(int now){
    if(now==n){
    	num++;
        for(int i=0;i<n-1;i++){
        	//cout<<"    "<<a[i];
        	//cout<<sqrt((double)(p[a[i]].x-p[a[i]+1].x)*(p[a[i]].x-p[a[i]+1].x)+(double)(p[a[i]].y-p[a[i]+1].y)*(p[a[i]].y-p[a[i]+1].y))<<endl;
            ans+=(double)sqrt((double)(p[a[i]].x-p[a[i+1]].x)*(p[a[i]].x-p[a[i+1]].x)+(double)(p[a[i]].y-p[a[i+1]].y)*(p[a[i]].y-p[a[i+1]].y));
        }
        return;
    }
    for(int i=1;i<=n;i++){
        if(flag[i]==0){
            flag[i]=1;
            a[now]=i;
            dfs(now+1);
            flag[i]=0;
        }
    }
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%lf%lf",&p[i].x,&p[i].y);
	}
	dfs(0);
	printf("%.10f",ans/num);
return 0;
} 

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

#define clean(x,y) memset(x,y,sizeof(x));
#define pb push_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define ALL(v) v.begin(),v.end()
#define PI acos(-1.0)
#define EPS 1e-9
#define INF (1 << 30)
#define MOD 1000000007
#define MAX 100005
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define dbg(x) cout<<(#x)<<"="<<(x)<<":\n"
#define CS(i) cout<<"Case "<<i<<": "
#define tin ll T; cin>>T; while(T--)

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bool isPalindrome(string s)
{
    string rev=s;
    reverse(ALL(rev));
    return rev==s;
}


int main()
{
    FAST

    string s;
    int i,j,x,y,len;
    cin>>s;
    len=s.size();
    if(len%2==0)
    {
        cout<<"No\n";
        return 0;
    }
    if(isPalindrome(s))
    {
        x=(len-1)/2;
        y=(len+3)/2-1;
        string s1 = s.substr(0,x);
        string s2 = s.substr(y);
        if(isPalindrome(s1) && isPalindrome(s2))
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    else
    {
        cout<<"No\n";
    }



    return 0;
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan =new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        
        int c = Integer.parseInt(a + b);
        for(int i = 0; i <1000;i++){
            if ((i*i) == c){
                System.out.println("Yes");
                return;
            }
            
        }
        
        System.out.println("No");
        
    }
}


Measured memory_bytes: 21972
// Vicfred
// https://atcoder.jp/contests/abc176/tasks/abc176_d
// dfs, bfs, flood fill
#include <iostream>
#include <deque>
#include <vector>
#include <string>
#include <utility>
#include <tuple>

using namespace std;

const int INF = 1<<30;

int main() {
    int H, W;
    cin >> H >> W;

    int ch, cw, dh, dw;

    cin >> ch >> cw;
    cin >> dh >> dw;

    ch -= 1;
    cw -= 1;
    dh -= 1;
    dw -= 1;

    vector<string> s(H);
    for(auto &row: s)
        cin >> row;

    vector<vector<int>> dist(H, vector<int>(W, INF));
    deque<pair<int,int>> q;
    q.push_back({ch, cw});
    dist[ch][cw] = 0;

    int dir[] = {1, 0, -1, 0, 1};

    while(!q.empty()) {
        int cx, cy;
        tie(cx, cy) = q.front();
        q.pop_front();
        for(int i = 0; i < 4; i++) {
            int nx = cx + dir[i];
            int ny = cy + dir[i + 1];
            if(nx < 0 or ny < 0 or nx >= H or ny >= W)
                continue;
            if(s[nx][ny] == '#')
                continue;
            if(dist[nx][ny] > dist[cx][cy]) {
                dist[nx][ny] = dist[cx][cy];
                q.push_front({nx, ny});
            }
        }

        for(int i = -2; i <= 2; i++) {
            for(int j = -2; j <= 2; j++) {
                int nx = cx + i;
                int ny = cy + j;
                if(nx < 0 or ny < 0 or nx >= H or ny >= W)
                    continue;
                if(s[nx][ny] == '#')
                    continue;
                if(dist[nx][ny] > dist[cx][cy] + 1) {
                    dist[nx][ny] = dist[cx][cy] + 1;
                    q.push_back({nx, ny});
                }
            }
        }
    }

    if(dist[dh][dw] == INF)
        dist[dh][dw] = -1;

    //for(int i = 0; i < H; i++) {
    //    for(int j = 0; j < H; j++) {
    //        cout << dist[i][j] << " ";
    //    } cout << endl;
    //}

    cout << dist[dh][dw] << endl;

    return 0;
}



Measured memory_bytes: 9448
#include <iostream>
 
int main(){
  unsigned int A;
  unsigned int B;
  std::cin >> A;
  std::cin >> B;
  unsigned int N = 1u;
  unsigned int answer = 0u;
  while(N < B){
    ++answer;
    N += A - 1;
  }
  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
R, S, P = [int(i) for i in input().split()]
T = input()
ans = 0
for i in range(K):
    p = ""
    for j in range(i, N, K):
        if T[j] == p:
            p = ""
        else:
            if T[j] == "r":
                ans += P
            elif T[j] == "s":
                ans += R
            else:
                ans += S
            p = T[j]
print(ans)



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

using namespace std;

typedef long long ll;

const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();
const int MOD = 1000000007;

ll modpow(ll x, ll n) {
        ll ans = 1;
        while(n) {
                if(n & 1) ans = (ans * x) % MOD;
                x = (x * x) % MOD;
                n>>=1;
        }
        return ans;
}

ll COM(int n, int k) {
	ll ret = 1;
	ll div = 1;
	for (int i=0; i<k; i++) {
		ret = (ret * (n - i)%MOD)%MOD;
		div = (div * (i + 1)) % MOD;
	}
	div = modpow(div, MOD-2)%MOD;
	return (ret * div)%MOD;
}

int main(int, char**) {
	ll n, a, b;
	cin >> n >> a >> b;
	ll ret = modpow(2, n) - 1;
	ret += MOD - COM(n, a);
	ret %= MOD;
	ret += MOD - COM(n, b);
	ret %= MOD;

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <string>
using namespace std;
int main()
{
    int cnt{0};
    string a,b;
    cin>>a>>b;

    int x=a.size();
    for(int i=0;i<x;i++)
    {
        if(a[i]==b[i])
            cnt++;
    }
    if(cnt==x)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;

#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
int main() {
  int in(N); ll in(M);

  vi A(N);
  rep(i, N) cin >> A[i];
  all(sort, A);
  vl sum(N+1, 0);
  rep(i, N) {
    sum[i+1] = sum[i] + A[i];
  }

  auto f = [&](ll mid) {
    // mid以上がいくつあるか？
    ll count = 0;
    rep(i, N) {
      count += A.end() - all(lower_bound, A, mid - A[i]);
    }
    return count < M;
  };
  // 上からM個取りたい
  // -> 上からM番目を探す
  ll ng = 0, ok = 1800000000000000000ll; // okの数字は上からM番目の数以上
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (f(mid))
      ok = mid;
    else
      ng = mid;
  }
  ll ans = 0;
  ll count = 0;
  rep(i, N) {
    ans += sum[N] - sum[(int)(all(lower_bound, A, ok - A[i]) - A.begin())];
    ans += 1ll * (int)(A.end() - all(lower_bound, A, ok - A[i])) * A[i];
    count += A.end() - all(lower_bound, A, ok - A[i]);
  }
  ans += ng * (M - count);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
 
using namespace std;
 
#define eb emplace_back
#define pb push_back
#define MP make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define rep(i,j,n) for (int i = j; i < n; ++i)
#define repn(i,j,n) for (int i = j; i <= n; ++i)
#define revn(i,j,n) for (int i = j; i >= n; --i)
#define sz(i) i.size()
#define mem(i,v) memset(i,v,sizeof(i))
#define all(v) v.begin(), v.end()
#define endl '\n'
#define int long long
#define INF 1e18
#define ss second
#define ff first

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int mod=1e9+7;
//const int mod=998244353;
const int up=1e5+10;
const int MAXN=1e6+10;

using T = tuple<int,int,int>;

vector<T> adj[55];
int dp[55][2505];
priority_queue<T,vector<T>,greater<T>>q;

int ans=0,c[55],d[55];
void solve()
{
    int n,m,s,u,v,a,b;
    cin>>n>>m>>s;
    s=min(s,2499LL);
    fill(dp[0], dp[50], INF);
    rep(i,0,m)
    {
        cin>>u>>v>>a>>b;
        u--;
        v--;
        adj[u].eb(v,a,b);
        adj[v].eb(u,a,b);
    }
    rep(i,0,n)
    {
        cin>>c[i]>>d[i];
    }
    
    q.push({dp[0][s]=0,0,s});
    while(!q.empty())
    {
        auto[cost,town,coin]=q.top();
        q.pop();
        if(dp[town][coin]<cost)
            continue;
        for(auto[nxtown,coin2,cost2]:adj[town])
        {
            if(coin2>coin)
                continue;
            if(dp[nxtown][coin-coin2]>cost+cost2)
            {
                q.push({dp[nxtown][coin - coin2] = cost + cost2, nxtown, coin - coin2});
            }
        }
        if(coin + c[town] < 2500)
        {
            if(dp[town][coin + c[town]] > cost + d[town])
            {
                q.push({dp[town][coin + c[town]] = cost + d[town], town, coin + c[town]});
            }
        }
    }
    for(int i=1; i<n; i++)
    {
        ans = INF;
        rep(j,0,2500) 
        {
            ans = min(ans, dp[i][j]);
        }
        cout<<ans<<endl;
    }
}

int32_t main()
{
    fast_cin();
    int t;
    // memset(prime, true, sizeof(prime)); 
    // sieve();
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    //cout<<ans<<endl;
}



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

using namespace std;

typedef long long ll;
ll k,a,b,ans1,ans2,ans3;

int main()
{
    scanf("%lld%lld%lld",&k,&a,&b);
    if (a >= b)
        printf("%lld\n",k + 1);
    else
    {
        if (k < a + 1)
            printf("%lld\n",k + 1);
        else
        {
            ll tk = k;
            tk -= (a + 1);
            ans1 = b;
            ll temp = tk / (a + 2);
            ans1 += temp * b;
            tk -= temp * (a + 2);
            ans1 += tk;

            tk = k;
            tk -= (a + 1);
            ans2 = b;
            ans2 += tk;

            tk = k;
            tk -= (a + 1);
            ans3 = b;
            temp = tk / 2;
            ans3 += temp * (b - a);
            tk -= temp * 2;
            ans3 += tk;
            printf("%lld\n",max(k + 1,max(ans1,max(ans3,ans2))));
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
    int n; cin >> n;
    vector<int> h(n);
    repeat (i, n) cin >> h[i];
    
    int mh = 0;
    int cnt = 0;
    repeat (i, n) {
        if (h[i] >= mh) ++cnt;
        mh = max(h[i], mh);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
    int T;
    cin >> T;
    for(int loop = 0; loop < T; loop++){
        long long int h, w;
        cin >> h >> w;
        long long int G = GCD(h, w);
        h /= G;
        w /= G;
        if(h == w){
            cout << 1 << " " << 0 << endl;
            continue;
        }
        if(h % 2 == 0 || w % 2 == 0){
            cout << 1 << " " << 1 << endl;
            continue;
        }
        cout << h * w / 2 + 1 << " " << h * w / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int d;
		if (a > b) {
			d = a - (b + w);
		} else {
			d = b - (a + w);
		}
		if (d < 0) {
			d = 0;
		}
		System.out.println(d);
	}
}


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

int main() {

  int H, W;
  cin >> H >> W;

  char a[H][W];

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

  // ----------

  int out_H = H+2;
  int out_W = W+2;

  for (int y=0; y<out_H; y++) {
	for (int x=0; x<out_W; x++) {
	  if (y == 0 || y == out_H-1 || x == 0 || x == out_W-1 ) {
		cout <<  '#';
	  } else {
		cout << a[y-1][x-1];
	  }
	}
	cout << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int nbElem, distMax;
	cin >> nbElem >> distMax;
	vector<vector<int>> child(nbElem);
	int res = 0;
	for (int i = 0; i < nbElem; ++i) {
		int dir; cin >> dir; --dir;
		if (i == 0 && dir > 0) ++res;
		if (i > 0) { child[dir].push_back(i); }
	}
	function<int(int, int)> dfs = [&] (int node, int par) {
		int md = 1;
		for (int nei : child[node]) {
			chmax(md, dfs(nei,node)+1);
		}
		if (node && md == distMax+(par==0)) {
			++res; return 0;
		}
		return md;
	};
	dfs(0,-1);
	cout << res << "\n";
}


Measured memory_bytes: 17992
main=do
 getLine
 xyh<-map(map read.words).lines<$>getContents
 let[sx,sy,sh]=head$filter((>0).(!!2))xyh
 putStrLn$unwords$map show$head[[x,y,h]|x<-[0..100],y<-[0..100],let h=sh+(abs$sx-x)+(abs$sy-y),ok x y h xyh]
ok sx sy sh[]=True
ok sx sy sh([x,y,h]:xyh)
 |max(sh-(abs$sx-x)-(abs$sy-y))0==h=ok sx sy sh xyh
 |otherwise=False

Measured memory_bytes: 1020
import fractions as math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B, C, D = (int(x) for x in input().split())

Cu = B//C       #Cの上限
Cd = -(-A//C)   #Cの下限
Du = B//D       #Dの上限
Dd = -(-A//D)   #Dの下限

#Least common multiple
LCMu = B//(lcm(C,D))
LCMd = -(-A//lcm(C,D))


C_num = Cu - Cd + 1
D_num = Du - Dd + 1
LCM_num = LCMu - LCMd + 1

C_D_num = C_num + D_num - LCM_num
A_B_num = B - A  + 1

ans = A_B_num - C_D_num
print(ans)


Measured memory_bytes: 5076
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define inf    0x3f3f3f3f
#define ll long long
#define pb push_back
#define upperlimit 1000100
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]

int main(){

 ll n; cin>>n;
   int v[n];

   for(int i=0;i<n;i++)
     cin>>v[i];

  int cnt[3] = {0};

 for(int i=0;i<n;i++)
 {
       if(v[i]&1) cnt[0]++;
       else if(v[i]&3) cnt[1]++;
       else cnt[2]++;
 }

 if(cnt[1] == 0){
      if(cnt[0] <= cnt[2]+1)
            cout<<"Yes"<<endl;
       else
            cout<<"No"<<endl;
 }
 else {

   if(cnt[0] <= cnt[2]) cout<<"Yes"<<endl;
   else
      cout<<"No"<<endl;
 }

 return 0 ;
}

Measured memory_bytes: 3952
from typing import List


def main():
    nums = [int(n) for n in input().split(' ')]

    if si(nums):
        print('Yes')
    else:
        print('No')


def si(nums: List[int]) -> bool:
    result = False
    a, b, c = nums

    if 4 * a * b < (c - a - b) ** 2 and (c - a - b) > 0:
        result = True

    return result


if __name__ == '__main__':
    main()


Measured memory_bytes: 10292
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

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

	int n;
	cin >> n;
	cout << (n + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define io  ios_base::sync_with_stdio(false), cin.tie(NULL),cout.tie(NULL)
int mod=1e9+7;const int N=55;
int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	return (a+b)%m;}
int sub(int a,int b,int m=mod){	return (a-b+m)%m;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
bool chk(int x,int y,int n,int m)
{
    return x>=0 && x<n && y>=0 && y<m;
}
int32_t main()
{
   int a,b,c,k;
   cin>>a>>b>>c>>k;
   if(k<=a)
    cout<<k;
   else if(k<=(a+b))
    cout<<a;
   else
    cout<<a-(k-a-b);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S = "";
    cin >> S;
    //vector<bool> num(30, false);
    bool num[26] = {false};
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    for (int i = 0; i < S.size(); ++i) {
        for (int j = 0; j < 26; ++j) {
            if (S.at(i) == alpha.at(j)) {
                num[j] = true;
                break;
            }
        }
    }
    string result = "None";
    for (int i = 0; i < 26; ++i) {
        if(num[i] == false) {
            result = alpha.at(i);
            break;
        }
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
    char s[1001],t[1001];
    int n=0,max_n=0,max_s,max_t;
    scanf("%s%s",s,t);

    for(int a=0;;a++){
        if(s[a]=='\0'){
        max_s=a;
        break;
        }
    }
    for(int a=0;;a++){
        if(t[a]=='\0'){
            max_t=a;
            break;
        }
    }
    
    for(int i=0;i<max_s-max_t+1;i++){
        n=0;
        for(int j=0;j<max_t;j++){
            if(s[i+j]==t[j])n++;
        }
        if(n>max_n)max_n=n;
    }
    printf("%d",max_t-max_n);
    return 0;
}





Measured memory_bytes: 1708
/*
 * ----------------------------------------------------------------------------
 (: Bismillahir Rahmanir Rahim :) 
 * File: /root/Programming/Atcoder/C_Traveling_Salesman_around_Lake.cpp
 * Project: /root/Programming/Atcoder
 * Created Date: Saturday, March 28th 2020, 6:14:57 pm
 * Author: Grim Firefly :)
 * Author Mail : GrimFirefly1@gmail.com
 * -----
 * Last Modified: Sat Mar 28 2020
 * Modified By: Grim Firefly :)
 * -----
 * ----------------------------------------------------------------------------
 */

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

//constant
#define PI acos(-1.0)

//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned un;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef map<int, int> mii;
typedef map<char, char> mcc;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<ll, ll> mll;

//defined for loop

// defined for taking input
#define gl(x) getline(cin, x)
#define sf scanf
#define sfi(x) sf("%d", &x)
#define sfc(x) sf("%c", &x)
#define sfl(x) sf("%lld", &x)
#define sflu(x) sf("%llu", &x)
#define sfii(x, y) sf("%d %d", &x, &y)
#define sfll(x, y) sf("%lld %lld", &x, &y)
#define sfiii(x, y, z) sf("%d %d %d", &x, &y, &z)
#define sflll(x, y, z) sf("%lld %lld %lld", &x, &y, &z)

//defined for printing
#define pf printf
#define pfn pf("\n")
#define pfcas pf("Case %d: ", cas)
#define pfyes pf("YES")
#define pfno pf("NO")
#define pfi(x) pf("%d", x)
#define pfl(x) pf("%lld", x)

//Defined for loop
//increament
#define loopi(i, j, k) for (int i = j; i < k; i++)
#define loopl(i, j, k) for (ll i = j; i < k; i++)
#define loopc(i, j, k) for (char i = j; i < k; i++)
#define looplu(i, j, k) for (ull i = j; i < k; i++)
//decreament
#define loopri(i, j, k) for (int i = j; i > k; i--)
#define looprl(i, j, k) for (ll i = j; i > k; i--)
#define looprlu(i, j, k) for (ull i = j; i > k; i--)
#define looprc(i, j, k) for (char i = j; i > k; i--)
#define wa(t) while (t--)

//testcases
#define testc(t) for (char cas = 1; cas <= t; cas++)
#define testi(t) for (int cas = 1; cas <= t; cas++)
#define testl(t) for (ll cas = 1; cas <= t; cas++)

//some cmd
#define pb push_back
#define ppb pop_back
#define mp make_pair

//Main Function Start

int main()
{
    int k, n;
    sfii(k, n);
    int ara[n];
    int ans = 0;
    int dist[n];
    loopi(i, 0, n)
    {
        sfi(ara[i]);
        if (i)
        {
            dist[i - 1] = ara[i] - ara[i - 1];
        }
    }
    dist[n-1]=k-ara[n-1]+ara[0]-0;
    sort(dist,dist+n);
    cout << accumulate(dist,dist+n-1,0)<< endl;
    return 0;
}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int ans=0,z=0,o=0;
    string s; cin >> s;
   
    rep(i,0,s.size()) {
        if(s[i]=='1') o++;
        else z++;
    }
    ans=2*min(o,z);
    cout << ans << endl;
    
 }    


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a*b)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 1e+7
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
using namespace std;

void A(){
  string s;
  cin >> s;
  if(s[2] == s[3] and s[4] == s[5]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

void B(){
  int Yen;
  cin >> Yen;
  ll Happiness = 0;
  while(Yen >= 500){
    Happiness += 1000;
    Yen -= 500;
  }
  while(Yen >= 5){
    Happiness += 5;
    Yen -= 5;
  }

  cout << Happiness << endl;
}

void C(){
  int K,N;
  cin >> K >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  ll min = A[N-1] - A[0];
  for(int i = 1; i < N; i++){
    ll temp = K - (A[i] - A[i-1]);
    temp < min ? min = temp:1;
  }

  cout << min << endl;
}
int main(){
  C();
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

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

typedef long long ll;

using namespace std;

int main() {
    
    string s,t;
    cin >> s >> t;
    
    int l = s.size();
    
    int ans=0;
    if(s==t){
        ans=1;
    }
    FOR(i, 0, l-1){
        vector<char> tmp(l);
        FOR(j, 0, l){
            tmp[j] = s[j];
        }
        FOR(j, 0, l-1){
            s[0] = tmp[l-1];
            s[j+1] = tmp[j];
        }
        
        // cout << s << endl;
        if(s==t){
            ans=1;
        }
    }
    
    if(ans==1){
        cout <<  "Yes" << endl;
    }else{
        cout <<  "No" << endl;
    }
    return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    for(int i=0; i<10000; i++){

        if(8*i/100 == a && i*10/100 == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3668
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,r;
int main(void) 
{
	scanf("%d%d",&n,&r);
	if(n<=10)
		printf("%d\n",1000-100*n+r);
	else
		printf("%d\n",r);
    return 0;
}

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

int main(){
    int a, b, c, cnt=0, tmp=0;
    cin >> a >> b >> c;
    if(a==5) ++cnt;
    else tmp = a;
    if(b==5) ++cnt;
    else tmp = b;
    if(c==5) ++cnt;
    else tmp = c;
    if(cnt==2){
        if(tmp==7){
            cout << "YES" << endl;
        }
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
template <ll mod = MOD>
class ModCombination
{
public:
    ModCombination(const int n) : fact(n + 1, 1), inv(n + 1, 1), inv_fact(n + 1, 1)
    {
        for (ll i = 2; i <= n; i++) { fact[i] = (fact[i - 1] * i) % mod, inv[i] = ((mod - (mod / i)) * inv[mod % i]) % mod, inv_fact[i] = (inv_fact[i - 1] * inv[i]) % mod; }
    }
    ll combination(const int n, const int k) const { return n == -1 and k == -1 ? 1LL : 0 <= k and k <= n ? (((fact[n] * inv_fact[k]) % mod) * inv_fact[n - k]) % mod : 0LL; }

private:
    vector<ll> fact, inv, inv_fact;
};
int main()
{
    const ModCombination<> mod(6000000);
    while (true) {
        int A, B, C, SX, SY;
        cin >> A >> B >> C >> SX >> SY;
        if (A == 0 and B == 0 and C == 0 and SX == 0 and SY == 0) { break; }
        const int ADV = SX - SY;
        if ((SX + SY + ADV) % 2 == 1) {
            cout << 0 << endl;
            continue;
        }
        ll ans = 0;
        for (int a = max({A, B + ADV}); a <= SX; a++) {
            const int b = a - ADV;
            const int r = (SX + SY - a - b) / 2, c = A + B + C;
            (ans += (mod.combination(a - 1, A - 1) * mod.combination(b - 1, B - 1) % MOD) * mod.combination(r + c - 1, c - 1) % MOD) %= MOD;
        }
        cout << (ans * mod.combination(A + B + C, A) % MOD) * mod.combination(B + C, B) % MOD << endl;
    }
    return 0;
}



Measured memory_bytes: 143312
local n, k = io.read("*n", "*n")
local cnt = 0
local mm = math.max
for b = k + 1, n do
  cnt = cnt + (n // b) * (b - k)
  local rem = n % b
  if(0 < rem) then
    if(k == 0) then cnt = cnt + rem
    else cnt = cnt + mm(0, rem - k + 1)
    end
  end
end
print(cnt)


Measured memory_bytes: 256
X = int(input())


def iroot(x, n):
    lo, hi = 0, x
    while lo <= hi:
        mi = (lo + hi) // 2
        if pow(mi, n) > x:
            hi = mi - 1
        elif pow(mi, n) < x:
            lo = mi + 1
        else:
            return (mi, True)
    return (None, False)


for b in range(X + 1):
    A, f = iroot(X + pow(b, 5), 5)
    if f:
        print(A, b)
        break
    A, f = iroot(X - pow(b, 5), 5)
    if f:
        print(A, -b)
        break


Measured memory_bytes: 9216
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		// 標準入力から数列と整数N（数列の長さ）を読み込み
		int n = Integer.parseInt(scanner.nextLine());    // 数列の長さ
		String[] array = scanner.nextLine().split(" ");  // 数列
		
		// 初期状態の配列状態を出力
		System.out.println(String.join(" ", array));
		
		for (int i = 1; i < n; i++) {
			int v = Integer.parseInt(array[i]);
			int j = i - 1;
			while(j >= 0 && Integer.parseInt(array[j]) > v) {
				array[j + 1] = array[j];
				j--;
			}
			array[j + 1] = Integer.toString(v);
			
			// 途中経過の配列状態を出力
			System.out.println(String.join(" ", array));
		}
		
		scanner.close();
	}
}



Measured memory_bytes: 29000
import queue
K = int(input())

q = queue.Queue()
[q.put(i) for i in range(1, 10)]
for _ in range(K):
    num = q.get()
    mod = num % 10
    deca = num * 10 + mod 
    if mod != 0:
        q.put(deca - 1)
    q.put(deca)
    if mod != 9:
        q.put(deca + 1)
        
print(num)

Measured memory_bytes: 12492
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
 
public class AtCoder20171111D
{
  static void Main(string[] args)
  {
    var line = Console.ReadLine();
    var ret = Math.Pow(int.Parse(line), 3);
    
    System.Console.WriteLine(ret.ToString());    
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	double n;
	cin>>n;
	double cnt = 0.0;
	for(int i=1;i<=n;i++)
		if(i%2 == 1)
			cnt++;
	cout<<(cnt/n)<<endl;
	return 0;
}

Measured memory_bytes: 256
numbers = [int(e) for e in input()]

for i in range(8):
    cand = format(i, 'b').zfill(3)
    res = numbers[0] + sum([n if b == '1' else -n for n, b in zip(numbers[1:], cand)])
    if res == 7:
        break

ope = ['+' if b == '1' else '-' for b in cand] + ['']
res = ''

for n, o in zip(numbers, ope):
    res += str(n) + o

print(res+'=7')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define forn(i,n) for(ll i=0;i<(n);i++)
#define maxx ((ll)1e6+5)
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  ll ans=maxx;
  forn(i,n){
  cin>>a[i];}
  forn(i,120)
  {
  	ll s=0;
  	forn(j,n)
  	s+=pow(abs(i-a[j]),2);
  	ans=min(ans,s);
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256