akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=2*100000+10;

string s;

vector<string> vec(5);

int main(){
  cin>>s;
  for(ll i=0;i<5;i++){
    vec[i]="";
  }
  for(ll i=1;i<6;i++){
    for(ll j=0;j+i<=s.length();j++){
      string sub=s.substr(j,i);
//      cout<<sub<<endl;
      if(sub!=vec[0]&&sub!=vec[1]&&sub!=vec[2]&&sub!=vec[3]&&sub!=vec[4]){
        if(vec[0]==""||sub<vec[0]){
          vec[4]=vec[3];
          vec[3]=vec[2];
          vec[2]=vec[1];
          vec[1]=vec[0];
          vec[0]=sub;
        }
        else if(vec[1]==""||sub<vec[1]){
          vec[4]=vec[3];
          vec[3]=vec[2];
          vec[2]=vec[1];
          vec[1]=sub;
        }
        else if(vec[2]==""||sub<vec[2]){
          vec[4]=vec[3];
          vec[3]=vec[2];
          vec[2]=sub;
        }
        else if(vec[3]==""||sub<vec[3]){
          vec[4]=vec[3];
          vec[3]=sub;
        }
        else if(vec[4]==""||sub<vec[4])vec[4]=sub;
      }
    }
  }

  ll K;
  cin>>K;
  cout<<vec[K-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8

class Card:
    def __init__(self, card, initial):
        self.mark = card[0]
        self.number = int(card[1])
        self.initial = initial

def partition(A, p, r):
    x = A[r].number
    i = p-1
    for j in range(p,r):
        if A[j].number <= x:
            i += 1
            A[i],A[j] = A[j],A[i]
    A[i+1],A[r] = A[r],A[i+1]
    return i+1

def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q-1)
        quickSort(A, q+1, r)
        
def isStable(A, n):
    flag = True
    for i in range(n-1):
        if A[i+1].number == A[i].number and A[i+1].initial < A[i].initial:
            flag = False
    return flag

def printCards(A, n):
    for i in range(n):
        print(A[i].mark, end=" ")
        print(A[i].number)

n = int(input().rstrip())
cards = []
for i in range(n):
    cards.append(Card(input().rstrip().split(), i))
quickSort(cards, 0, n-1)
if isStable(cards, n):
    print("Stable")
else:
    print("Not stable")

printCards(cards, n)


Measured memory_bytes: 29928
import java.util.Scanner;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while (true) {
			String str = sc.nextLine();
			if("0".equals(str)){
				break;
			}
			char[] c = str.toCharArray();
			int sum = 0;
			for (int i = 0; i < c.length; i++) {
				sum += c[i] - '0';
			}
			ln(sum);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

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

int Soma(int N)
{
	
	int J = N;
	while(true)
	{
		
	
		if( J % 2 == 0 && J % N == 0 ){
			return J;
		}
			J = J+N;
	}
}
int main()
{
	int N;
	
	cin>>N;
	cout<<Soma(N)<<endl;
	
	
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 105
using namespace std;
int n;
int l[maxn<<1];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)scanf("%d",&l[i]);
    sort(l+1,l+1+2*n);
    int ans=0;
    for(int i=1;i<=2*n;i+=2){
        ans+=l[i];
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int p1_cnt, p2_cnt;
	p1_cnt = (c+(b-1))/b;
	p2_cnt = (a+(d-1))/d;
	if((p1_cnt < p2_cnt) || (p1_cnt==p2_cnt)){
		println("Yes");
	}else{
		println("No");
	}

	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define N 3
#define M 9
struct Puzzle{
  int f[M];
  int space;
  string path;
  bool operator < (const Puzzle &p) const{
    for(int i=0;i<M;i++){
      if(f[i]==p.f[i]) continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};
static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};
bool kansuu(Puzzle p){
  for(int i=0;i<M;i++){
    if(p.f[i]!=(i+1))return false;
  }
  return true;
}
string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;
  while(!Q.empty()){
    u=Q.front();
    Q.pop();
    if(kansuu(u))return u.path;
    int sx=u.space/N;
    int sy=u.space%N;
    for(int r=0;r<4;r++){
      int tx=sx+dx[r];
      int ty=sy+dy[r];
      if(tx<0||ty<0||tx>=N||ty>=N)continue;
      v=u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
    	V[v]=true;
    	v.path+=dir[r];
    	Q.push(v);
      }
    }
  }
  return "unsolvable";
}
int main(){
  Puzzle in;
  for(int i=0;i<M;i++){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]=M;
      in.space=i;
    }
  }
  string ans=bfs(in);
  cout << ans.size() << endl;
  return 0;
}



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

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

    vector<int> P(N), pos(N), len(N, 1);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
        pos[P[i]] = i;
    }
    for (int i = N - 2; i >= 0; i--) {
        if (pos[i] > pos[i + 1]) len[i] = 1; 
        else len[i] = 1 + len[i + 1];
    }

    int ans = (1 << 28);
    for (int i = 0; i < N; i++) {
        ans = min(ans, i + (N - i) - len[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
const MOD: usize = 1000000007;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    // var... 変数の識別子, $t...型を一つよむ
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        //ここで繰り返し
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    //
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    // 配列の最後のNestではここで型が指定されてparseされる
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn walk(p: (usize, usize), a: &mut Vec<Vec<char>>) {
    a[p.0][p.1] = '.';
    if p.0 + 1 < a.len() && a[p.0 + 1][p.1] == '#' {
        walk((p.0 + 1, p.1), a);
    } else if p.1 + 1 < a[0].len() && a[p.0][p.1 + 1] == '#' {
        walk((p.0, p.1 + 1), a);
    }
}

fn main() {
    input! {
        h: usize,
        w: usize,
        a: [chars;h],
    }
    let mut a = a;
    walk((0, 0), &mut a);
    // println!("{:?}", a);
    for i in 0..h {
        for j in 0..w {
            if a[i][j] == '#' {
                println!("Impossible");
                std::process::exit(0);
            }
        }
    }
    println!("Possible");
    // let mut ans = std::usize::MAX;
    // for i in (0..(n - k + 1)) {
    //     ans = std::cmp::min(h[i + k - 1] - h[i], ans);
    // }
    // println!("{}", ans);
}


Measured memory_bytes: 4352
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

MOD = 10 ** 9 + 7
N, K = nm()


def solve():
    ans = 0
    tbl = [0] * (K + 1)
    for i in range(K, 0, -1):
        m = K // i
        p = pow(m, N, MOD)

        j = 2
        while j * i <= K:
            p += MOD - tbl[j * i] % MOD
            p %= MOD
            j += 1
        tbl[i] = p

        ans += i * p % MOD
        ans %= MOD
    return ans


print(solve())


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

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	cin >> n;
	ll temp = n-2;
	ll total = 0;
	for (int z=0;z<n/2 && temp > 0;z++){
		total += 2*temp;
		temp -= 2;
	}
	cout << total << endl;
	for (int z=1;z<=n;z++){
		for (int x=z;x<=n;x++){
			if (n&1 && (x == z || x == n-z)) continue;
			if (!(n&1) && (x == z || x == n-z+1)) continue;
			cout << z << " " << x << endl;
		}
	}
	cin >> n;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int y1 = sc.nextInt(), m1 = sc.nextInt(), d1 = sc.nextInt();
		int y2 = sc.nextInt(), m2 = sc.nextInt(), d2 = sc.nextInt();
		boolean mdsame = m1==m2 && d1==d2;
		int diff = Math.abs(y1-y2)+1;
		if(mdsame) {
			System.out.println(diff-1);
			return;
		}
		if(y1 < y2) {
			if(dmcomp(m1,d1,m2,d2)) {
				//
			} else {
				diff-=1;
			}
		} else if(y1 > y2) {
			if(!dmcomp(m1,d1,m2,d2)) {
				//
			} else {
				diff-=1;
			}
		} else if(y1==y2) {
			System.out.println(1);
			return;
		}

		System.out.println(diff);
	}

	static boolean dmcomp(int m1,int d1,int m2,int d2) {
		return 100*m1+d1 < 100*m2+d2;
	}
}


Measured memory_bytes: 26372
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <utility>
#include <valarray>

using namespace std;

int main()
{
    int N;
    scanf("%d\n", &N);
    vector<char> propositions(N);
    for (int i = 0; i < N; ++i){
        propositions[i] = (getchar() == 'o');
    }
    vector<char> states(N);
    auto judge = [&](bool s0, bool s1){
        states[0] = s0;
        states[1] = s1;
        for (int i = 2; i < N; ++i){
            states[i] = (states[i - 2] == (propositions[i - 1] == states[i - 1]));
        }
        if ((propositions[N - 1] == states[N - 1]) == (states[N - 2] == states[0]) &&
            (propositions[0] == states[0]) == (states[N - 1] == states[1])){
            for (int j = 0; j < N; ++j) printf("%c", (states[j]) ? 'S' : 'W');
            puts("");
            return true;
        }
        return false;
    };
    if (judge(true, true)) return 0;
    if (judge(true, false)) return 0;
    if (judge(false, true)) return 0;
    if (judge(false, false)) return 0;
    puts("-1");
}


Measured memory_bytes: 512
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

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

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int a, b, fac[N];
int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> a >> b;
	fac[0] = 1;
	for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * 1ll * i % MOD;
	if (max(a, b) - min(a, b) > 1) return cout << 0, 0;
	if (a == b) cout << (fac[a] * 1ll * fac[b] % MOD) * 2ll % MOD;
	else cout << (fac[a] * 1ll * fac[b]) % MOD;











	return 0;
}


Measured memory_bytes: 4400
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int main() {

	ll N, T;
	ll t[200005];
	ll ans = 0;

	cin >> N >> T;
	for (int i = 1; i <= N; i++) {

		cin >> t[i];

	}
	
	for (int i = 1; i < N; i++) {

		if (t[i + 1] - t[i] >= T) {

			ans += T;

		}
		else {

			ans += t[i + 1] - t[i];

		}

	}
	ans += T;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		Array.Sort(s);
		if(s[0]==s[1]&&s[1]!=s[2]){
			Console.WriteLine("Yes");
		}
		else if(s[0]!=s[1]&&s[1]==s[2]){
			Console.WriteLine("Yes");
		}
		else{
			Console.WriteLine("No");
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(i,n)cin >> a[i];

    srep(i,k,n){
        if(a[i] > a[i-k])yn;
    }

    return 0;
}




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

int main()
{
    /*char a,b;
    cin >> a >> b ;
    if(a == 'H' && b == 'H') cout << "H\n" ;
    else if(a == 'D' && b == 'D') cout << "H\n" ;
    else if(a == 'H' && b == 'D') cout << "D\n" ;
    else
        cout << "D\n" ;*/
         int  w,a,b;
        cin >> w >> a >> b ;
        cout << max(0,(abs(b-a)-w)) << endl;
    return 0;
}


Measured memory_bytes: 256
l = input().split()
N = int(l[0])
L = int(l[1])

T = [L + x for x in range(N)]
# print(N, L, T)
candidate = sum(T)
# print(candidate)
ans = 100000000
index = 0
for i in range(N):
   t = candidate - (L + i)
   d = abs(candidate - t)
   if d <= ans:
        index = i
        ans = d

# print(candidate, index)
print(candidate - (L + index))
# if L < 0 and L + N >= 0:
#     print(candidate)
# elif L + N - 1 <= 0:
#     print(candidate - (L + N - 1))
# else:
#     print(candidate - (L))


Measured memory_bytes: 38384
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,h,m,s;
	char z;
	int aut[3],cnt[3];
	while(true){
	cin>>n;
	if(n==0)break;
	for(int i=0;i<3;i++)aut[i]=0,cnt[i]=0;
	for(int u=0;u<n;u++){
		cin>>h>>z>>m>>s;
		if(h>=11&&h<=14){aut[0]++;int x=s-m;if(x<0)x+=60;if(x<=8)cnt[0]++;}
		if(h>=18&&h<=20){aut[1]++;int x=s-m;if(x<0)x+=60;if(x<=8)cnt[1]++;}
		if(h>=21||h<=1){aut[2]++;int x=s-m;if(x<0)x+=60;if(x<=8)cnt[2]++;}
	}
	string f[3]={"lunch","dinner","midnight"};
	for(int i=0;i<3;i++){
		cout<<f[i]<<" ";
		if(aut[i]==0)cout<<"no guest"<<endl;
		else cout<<100*cnt[i]/aut[i]<<endl;
	}
	}
	return 0;
}

Measured memory_bytes: 1204
N,K= map(int,input().split())
h=[1000000000]+list(map(int,input().split()))
dp=[0]*(N+1)

dp[1]=0
dp[2]=abs(h[2]-h[1])

if N>=3:
  for i in range(3,N+1):
    mini=1000000000
    for j in range(1,K+1):
      if i-j <1:
        pass
      else:
        mini=min(mini, dp[i-j] + abs(h[i]-h[i-j]) )
    dp[i]=mini
    
#print(dp)
print(dp[-1])

Measured memory_bytes: 53088
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define MOD 1000000007

int main()
{  
  
  ll n,k;
  cin>>n>>k;
  ll x[n+1];
  for(ll i=1;i<=n;i++)
    cin>>x[i];
  ll dp[n+1]={0};
  for(ll i=2;i<=n;i++)
  {  
       ll t1=INT_MAX;
     for(ll j=i-1;j>=max((ll)1,i-k);j--)
     {
       t1=min(t1,dp[j]+abs(x[i]-x[j]));
     }

       dp[i]=t1;
  }
  cout<<dp[n]<<endl;
  
   

 }
  
              
              

  

  
  
          
      
    







  
 

Measured memory_bytes: 1792
st = input()
skpe = int(input())
st_len = len(st)
count = (st_len // skpe) + 1
top_list = []
s = ""

for i in range(count):
    top_list.append(st[skpe * i:skpe * i + skpe])


for x in top_list:
    try:
        s += x[0]
    except IndexError:
        pass
print(s)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

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

	ll x, y;
	cin >> x >> y;

	ll cnt = 0;
	while (x <= y) {
		cnt++;
		x *= 2;
	}

	out(cnt);

	return 0;
}

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

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

  string s;
  cin>>s;
  
  int ans = 1;
  
  for(int i=1;i<n;i++) ans += s[i] != s[i-1];
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll a,b,c,d;
ll lcm(ll x,ll y)
{
    return (x*y)/__gcd(x,y);
}
int main()
{
    go;
    cin>>a>>b>>c>>d;
    ll x=lcm(c,d);
    ll y=b/c+b/d-b/x;
    ll z=(a-1)/c+(a-1)/d-(a-1)/x;
    //cout<<y<<" "<<z<<endl;
    ll ans=b-a+1-y+z;
    cout<<ans;
    return 0;
}


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

int main(){

  int n,a,b=0;
  cin>>n>>a>>b;
	
  string S;
  
  cin>>S;
  
  int countpass=0;
  int abroad=0;
  rep(i,n){

   
    if(S[i]=='a' && countpass<(a+b)){
	
      cout<<"Yes"<<endl;
      countpass++;
      
    }
    
    else if(S[i]=='b' && countpass<(a+b) && abroad<b){

      cout<<"Yes"<<endl;
      countpass++;
      abroad++;
      
    }
    
    else{

      cout<<"No"<<endl;

    }
        
    
  }

}

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

ll powLL(ll x) {
    return x * x * x * x * x;
}

ll isFifthPower(ll p) {
    for (ll i = 1; powLL(i) <= abs(p); ++i) {
        if (powLL(i) == p) return i;
        if (-powLL(i) == p) return -i;
    }
    return 1001001001001001001;
}

int main() {
    ll x;
    cin >> x;
    for (ll i = 0; ; ++i) {
        if (isFifthPower(powLL(i) - x) != 1001001001001001001) {
            cout << i << " " << isFifthPower(powLL(i) - x) << endl;
            break;
        }
    }
}


Measured memory_bytes: 3644
#define DEBUG 0

/**
 * File    : F.cpp
 * Author  : Kazune Takahashi
 * Created : 5/19/2019, 9:28:18 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

ll M, K;

int main()
{
  cin >> M >> K;
  if (!(0 <= K && K < (1 << M)))
  {
    cout << "-1" << endl;
    return 0;
  }
  if (M == 0)
  {
    cout << "0 0" << endl;
  }
  else if (M == 1)
  {
    if (K == 0)
    {
      cout << "0 0 1 1" << endl;
    }
    else
    {
      cout << "-1" << endl;
    }
  }
  else
  {
    vector<int> V;
    vector<int> W;
    for (auto i = 0; i < (1 << M); i++)
    {
      if (i == K)
      {
        continue;
      }
      V.push_back(i);
      W.push_back(i);
    }
    reverse(W.begin(), W.end());
    for (auto x : V)
    {
      cout << x << " ";
    }
    cout << K << " ";
    for (auto x : W)
    {
      cout << x << " ";
    }
    cout << K << endl;
  }
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 1e7
#define dsec 86400

using namespace std;
typedef long long int ll;
typedef tuple<int,int,int> tii;
typedef tuple<long long int,long long int,long long int> tll;
typedef tuple<double,double,double> tdd;



int main()
{
   double a,b,x; cin >> a >> b >> x;
   if(2*x <= a*a*b)
   {
       double y = atan(a*b*b/(2*x));
       cout << fixed << setprecision(10) << y*180 / 3.1415926535 << endl;
   }
   else
   {
       double y = atan(2*(b/a - (x / (a*a*a))));
       cout << fixed << setprecision(10) << y*180 / 3.1415926535 << endl;
   }
}

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int p[maxn],cnt;
char s[maxn];
int ans[maxn];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    p[++cnt]=0;
    for(int i=1;i<n;i++)if(s[i]=='L'&&s[i+1]=='R')p[++cnt]=i;
    p[++cnt]=n;
    for(int i=1;i<cnt;i++){
        int l=p[i]+1,r=p[i+1];
        int t1=0;while(s[l]=='R')l++,t1++;
        int t2=0;while(s[r]=='L')r--,t2++;
        if((t1+t2)%2==0)ans[l-1]=(t1+t2)/2,ans[r+1]=(t1+t2)/2;
        else{
            int k1=(t1+t2)/2;int k2=t1+t2-k1;
            if(t1%2==1)ans[l-1]=k2,ans[r+1]=k1;
            else ans[l-1]=k1,ans[r+1]=k2;
        }
    }
    for(int i=1;i<=n;i++)printf("%d%c",ans[i],i==n?'\n':' ');
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

int sb[100010],
    tb[100010];

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

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') sb[i] = 2;
        else sb[i] = 1;

        if (i > 0) sb[i] += sb[i - 1];
    }

    for (int i = 0; i < t.size(); i++) {
        if (t[i] == 'A') tb[i] = 2;
        else tb[i] = 1;

        if (i > 0) tb[i] += tb[i - 1];
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--; c--; d--;

        int s_cnt = sb[b], t_cnt = tb[d];
        if (a > 0) s_cnt -= sb[a - 1];
        if (c > 0) t_cnt -= tb[c - 1];

        if (s_cnt % 3 == t_cnt % 3) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   //IOS;
   string s;
   cin >> s;
   if(s=="ABC") cout<<"ARC";
   else cout << "ABC";
}


Measured memory_bytes: 3624
#include <stdio.h>

void sort01(int data[], int n);
int maxindex00(int data[], int from, int to);

int main()
{
	int input[100];
	int i;
	for(i=0; i<5; i++){
		scanf("%d", &input[i]);
	}
	sort01(input, 5);
	printf("%d", input[0]);
	for(i=1; i<5; i++){
		printf(" %d", input[i]);
	}
	puts("");
	return 0;
}


void sort01(int data[],int n)
{
	int i,work,maxindex;
	for(i=0;i<n;i++){
		maxindex=maxindex00(data,i,n);
		work=data[i];
		data[i]=data[maxindex];
		data[maxindex]=work;
	}
	return;
}

int maxindex00(int data[], int from, int to)
{
	int i;
	int result=from;
	for(i=from;i<to;i++){
		if(data[result]<data[i]){
			result=i;
		}
	}
	return result;
}

Measured memory_bytes: 608
#include <stdio.h>
#include <math.h>
int main()
{
    long int N,i,a;
    scanf("%ld",&N);
    for(i=1;i<=(long int)sqrt(N);i++){
        N%i==0?a=N/i:0;
    }
    printf("%d\n",(int)log10(a)+1);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N,ans = 0;
    cin >> N;

    vector<int> V(N+10),C(N+10);

    for(int i = 0;i < N;i++){
        cin >> V.at(i);
    }

    for(int i = 0;i < N;i++)
        cin >> C.at(i);

    for(int i = 0;i < N;i++){
        if(V.at(i) > C.at(i))
            ans += V.at(i) - C.at(i);
    }

    cout << ans << endl;




}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main()
{
  int A,B,C,D;

  cin >> A >> B>> C >> D;

  if(A*B > C*D)
    cout << A*B;
  else if(C*D>A*B)
    cout << C*D;
  else
    cout << A*B;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 300

int main(void){
    int H[MAX],W[MAX];
    int i=0,j,w,h,check;
    for (i=0; i<MAX; i++) {
        scanf("%d %d",&H[i],&W[i]);
        if(H[i]==0&&W[i]==0){
            break;
        }
        else{
            if(H[i]<1||W[i]<1||300<H[i]||300<W[i]){
                return 0;
            }
        }
    }
    
    for(j=0;j<i;j++){
        for(h=0;h<H[j];h++){
            if(h%2==0){
                check=0;
            }
            else{
                check=1;
            }
            for(w=0;w<W[j];w++){
                if(check%2==0){
                    printf("#");
                }
                else{
                    printf(".");
                }
                check++;
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2104
import java.util.Scanner;
class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		
		for (int num = 1;; num++ ){
			int x = scanner.nextInt();
			if (x == 0) {
			    break;
			}		
		    System.out.println("Case "+ num +": "+x);
	    }
	}	

}

Measured memory_bytes: 42516
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin>>a>>b;
  if(a==1){
    if(b==1)
      cout<<"Draw"<<endl;
    else
      cout<<"Alice"<<endl;
  }
  else if(b==1)
    cout<<"Bob"<<endl;
  else{
    if(a>b)
    cout<<"Alice"<<endl;
    if(a==b)
      cout<<"Draw"<<endl;
    if(a<b)
      cout<<"Bob"<<endl;
  }
}

Measured memory_bytes: 256
import sys, math, itertools, bisect, copy, re

from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

# 10倍速いらしい
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

T1 = [0] * N
T2 = [0] * N

for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            T1[i] += 1

for i in range(N):
    for j in range(0, N):
        if A[i] > A[j]:
            T2[i] += 1

ans = sum(T1) * K
ans %= MOD
ans += sum(T2) * K * (K - 1) // 2
ans %= MOD

print(ans)
# print(T1)
# print(T2)


Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
int H,W,A;
int sy,sx;
char t[200][200];
int d[200][200][11][4];

int solve(){
  memset(d,-1,sizeof(d));
  queue<int> qy,qx,qa,qd;
  qy.push(sy);
  qx.push(sx);
  qa.push(0);
  qd.push(2);
  d[sy][sx][0][2]=0;

  while(!qy.empty()){
    int y=qy.front();qy.pop();
    int x=qx.front();qx.pop();
    int a=qa.front();qa.pop();
    int dir=qd.front();qd.pop();
    int b=d[y][x][a][dir]-a;

    if(t[y][x]=='_'&&dir==0)continue;
    int ny=y,nx=x,na,nb;
    while(1){
      ny+=dy[dir];
      nx+=dx[dir];
      if(ny<0||nx<0)break;
      if(ny>=H||nx>=W)break;
      if(t[ny][nx]=='#')break;
      if(t[ny][nx]=='S')continue;
      
      if(t[ny][nx]=='G')return d[y][x][a][dir];
      for(int i=0;i<4;i++){
        if(i==dir||i==(dir+2)%4)continue;

        na=a,nb=b;
        if(i%2==0&&i==(dir+1)%4)na=a+1;
        else if(i%2==1&&i==(dir+3)%4)na=a+1;
        else nb=b+1;
        if(na>A||nb>A)continue;
        
        if(d[ny][nx][na][i]!=-1)continue;
        d[ny][nx][na][i]=d[y][x][a][dir]+1;
        qy.push(ny);
        qx.push(nx);
        qa.push(na);
        qd.push(i);
      }
    }
  }
  return -1;
}

int main(){
  cin>>H>>W>>A;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>t[i][j];
      if(t[i][j]=='S'){
        sy=i,sx=j;
      }
    }
  }
  for(int i=sy+1;i<H;i++){
    if(t[i][sx]=='#'||t[i][sx]=='G')break;
    t[i][sx]='_';
  }
  cout<<solve()<<endl;
  return 0;
}

Measured memory_bytes: 8268
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define DEC(i,a,b) for(int i=(a);i>=(b);--i)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
template<typename T,typename U> inline bool smax(T&x,const U&y){return y>x?(x=y,1):0;}
template<typename T,typename U> inline bool smin(T&x,const U&y){return y<x?(x=y,1):0;}
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second
inline int read(){
	int w=0,p=0;char c;
	while(!isdigit(c=getchar()))if(c=='-')p=1;
	while(isdigit(c))w=(w<<1)+(w<<3)+(c^'0'),c=getchar();
	return p?-w:w;
}
const int N=2e5+7;
int n,a[N],x[N];
ll y[N];
int main(){
	n=read();
	REP(i,1,n)a[i]=read(),x[i]=x[i-1]^a[i],y[i]=y[i-1]+a[i];
	ll ans=0;int ri=0;
	REP(i,1,n){
		int l=i,r=n;
		while(l<r){
			int mid=l+r+1>>1;
			if((x[mid]^x[i-1])==y[mid]-y[i-1])l=mid;else r=mid-1;
		}
	//	dbg("%d %d\n",i,l);
		
		if(l>ri)ans+=1ll*(l-i+1)*(l-i+2)/2-1ll*(ri-i+1)*(ri-i+2)/2;
		smax(ri,l);
	//	i=l==i?l:l-1;
	}
	//ans+=1ll*(n-last+1)*(n-last)/2;
//	dbg("%d %d\n",n,last);
	cout<<ans;
	return 0;
}


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

const int N = 100005; 

using namespace std; 

int n, a[N];  

int main() {

	cin >> n; 
	for(int i=1; i<=n; ++i) cin >> a[i]; 

	int moveT = 0; 
	for(int i=1; i<n; ++i) 
		if(a[i] == i) {
			swap(a[i+1], a[i]); 
			++moveT; 
		}

	moveT += (a[n] == n); 

	cout << moveT << endl; 

	return 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll n, a;
    cin >> n >> a;
    if (n % 500 <= a)
        ce("Yes");
    else
        ce("No");
}

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

using namespace std;


bool checkUru(const int y){

	//if(y%4==0&&y%100!=0){
	//	return true;
	//}
	//else if(y%400==0){
	//	return true;
	//}
	//else
	//	return false;

	if(y==0)
		return false;
	if(y%4==0){
		if(y%100==0){
			if(y%400==0){
				return true;
			}
			else{
				return false;
			}
		}
		else
			return true;
	}
	else
		return false;
}

typedef long long ll;

const int md[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

ll calcDays(const ll y,const ll m,const ll d){
	ll sum=0;
	for(ll i = 0; i < y; i++){
		if(checkUru(i)){
			sum+=366;
		}
		else
			sum+=365;
	}
	for(ll i = 1; i < m; i++){
		if(checkUru(y)&&i==2){
			sum+=md[i]+1;
		}
		else
			sum+=md[i];
	}
	sum+=d;
	return sum;
}

int main(){

	ll y1,m1,d1,y2,m2,d2;
	while(cin>>y1>>m1>>d1>>y2>>m2>>d2&&(y1>=0&&m1>=0&&d1>=0&&y2>=0&&m2>=0&&d2>=0)){
		ll sum=calcDays(y2,m2,d2)-calcDays(y1,m1,d1);
		cout<<sum<<endl;
	}

	return 0;
}

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

using std::cin;
using std::cout;
using std::vector;
using std::unique;
using std::for_each;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for_each(v.begin(),v.end(),[](int &_e){cin >> _e;});
	auto last = unique(v.begin(),v.end());
	v.erase(last,v.end());
	int i = 1;
	for_each(v.begin(),v.end(),[&i,v](int _e){cout << _e << (i++ == v.size() ? "\n" : " ");});
}


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

using namespace std;

int main()
{
  int n; 
  long long t[101], max_t=0;
  bool flag[101];
  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >> t[i];
    max_t = max(t[i], max_t);
    flag[i] = 0;
  }
  
  int j;
  long long time=0;
  long long i=1;
  while(1){
    time = max_t * i;
    //printf("maxt %lld  i %lld  time %lld\n", max_t, i, time);
    bool all = 1;
    for(j=0; j<n; j++){
      if(!flag[j]){
	    if(time % t[j] != 0){
    	    all = 0;
        }
      	else{
        	flag[j] = 1;
          	max_t = time;
          	i = 0;
        }
      }
    }
    if(all)
      break;
    
    i++;
  }
  
  cout << time << endl;
  
  return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end



int main(){
   int n,l; cin>>l>>n;
   vector<int> a(n);
   rep(i,0,n)cin>>a[i];
   sort(ALL(a));
   int ma=a[0]+l-a[n-1];
   rep(i,0,n-1)chmax(ma,a[i+1]-a[i]);
   cout<<l-ma<<endl;
   return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
const int MAXW = 1e5 + 10;

long long knapsack[MAXW];
int N,W;
int main() {
	
	cin >> N >> W;

	for(int item = 1;item<=N;item++){
		int w,v;
		cin >> w >> v;
		for(int i = W;i>=w;i--) knapsack[i] = max(knapsack[i-w] + v,knapsack[i]);
	}

	long long best = 0;
	for(int i = 0;i<=W;i++) best = max(best,knapsack[i]);
	cout << best << endl;

	return 0;
}

Measured memory_bytes: 4408
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
def permutations_count(n, r):
    if not n>=r>=0:
        return(0)
    else:
        return factorial(n) // factorial(n - r)
def combinations_count(n, r):
    if not n>=r>=0 or n<0:
        return(0)
    elif r==0:
        return(1)
    else:
        return factorial(n) // (factorial(n - r) * factorial(r))
N=input()
K=int(input())
length=len(str(N))
count=0
count3=0
flag=1
for i in range(length):
    if N[i]!="0":
        if K-count3 >=1:count+=combinations_count(length-1-i,K-count3)*(9**(K-count3))
        if K-count3-1 >=0:count+=combinations_count(length-1-i,K-count3-1)*(9**(K-1-count3))*(int(N[i])-1)
        count3+=1
    if K-count3==0:
        count+=1
        #count+=int(N[i])
        break
print(count)


Measured memory_bytes: 66028
#include <stdio.h>
#include <iostream>

using namespace std;


int main(int argc, char const *argv[])
{
    int num;
    for (int i = 1;; i++)
    {
        cin >> num;
        if (num == 0)
        {
            break;
        }
        printf("Case %d: %d\n", i, num);
    }


    return 0;
}


Measured memory_bytes: 3056
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;
int main() {
	int N;
	cin >> N;
	cout << (N - 2) * 180 << endl;
	return 0;
}


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

using namespace std;

int vec[123456];
int dp[123456];

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

    for (int i =0; i < n; i++) {
        cin >> vec[i];
    }
    //vector <int> dp(n+2,INT_MAX);
    dp[0] = 0;

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

        dp[i] = dp[i-1] + abs(vec[i]-vec[i-1]);
        if (i-2 >= 0){
            dp[i] = min(dp[i], dp[i-2] + abs(vec[i]-vec[i-2]));
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
# a=sorted(a)
l=[]
c=abs(n-m)
if n%m==0:
    c=0
    print(c)
else:
    c=n%m
    d=abs(m-c)
    l.append(c)
    l.append(d)
    l=sorted(l)
    print(l[0])


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int m = sc.nextInt();

        UnionFind unifin = new UnionFind(n);
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;

            unifin.unite(a, b);
        }

        int ans = unifin.count() - 1;
        System.out.println(ans);
    }

    static class UnionFind {
        // Parents[i]:iの親の番号 or 根だった場合、ついているノードの数N(-N)
        static List<Integer> Parents = new ArrayList<>();

        // 最初はすべてが根であるとして初期化
        public UnionFind(int N) {
            for (int i = 0; i < N; i++) {
                Parents.add(-1);
            }
        }

        // データが属する木の根を再帰で得る
        public int root(int x) {
            if (Parents.get(x) < 0)
                return x;
            Parents.set(x, root(Parents.get(x)));
            return Parents.get(x);
        }

        // xとyの木を併合
        public void unite(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            if (rx == ry)
                return;

            // yの方が大きい場合は入れ替える
            if (size(rx) < size(ry)) {
                int tmp = rx;
                rx = ry;
                ry = tmp;
            }

            Parents.set(rx, Parents.get(rx) + Parents.get(ry));
            Parents.set(ry, rx);
        }

        // 2つのデータx, yが属する木が同じならtrueを返す
        public boolean same(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            return rx == ry;
        }

        // 頂点の数を返す
        public int size(int x) {
            if (x >= 0)
                x = root(x);
            return Parents.get(x);
        }

        // 根の数
        public int count() {
            int cnt = 0;
            for (int i : Parents) {
                if (i < 0)
                    cnt++;
            }
            return cnt;
        }
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 60220
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	int a,b,c;
	cin >> a >> b >> c;
	set<int>s;
	s.insert(a);
	
	s.insert(b);
	
	s.insert(c);
	if(s.size()==2){
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    BufferedReader rd;

    Main() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        char[] c = rd.readLine().toCharArray();
        int n = c.length;
        int p = 0;
        int g = 0;
        int score = 0;
        for(int i=0;i<n;i++) {
            if(c[i] == 'g') {
                if(p+1 <= g) {
                    p++;
                    score++;
                } else {
                    g++;
                }
            } else {
                if(p+1 <= g) {
                    p++;
                } else {
                    g++;
                    score--;
                }
            }
        }
        out(score);
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new Main();
    }
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int N, K;
    cin >> N >> K;
    map<int, int> m;
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            m[a]++;
        }
    }

    int ans = 0;
    for (int k = 0; k < N; k++) {
        if (m.count(k + 1) == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
import sys
sys.setrecursionlimit(10**6)

# 入力
N = int(input())
adj = [[] for _ in range(N)]
ans = [None] * N

# グラフ探索で解いてみる
# c: 頂点vの色(0or1)
def dfs(v,parent,c):
    ans[v] = c
    for u,w in adj[v]:
        if u == parent:
            continue
        dfs(u,v,1-c) if w & 1 else dfs(u,v,c)

def main():
    for i in range(N-1):
        u, v, w = map(int, input().split())
        adj[u-1].append((v-1,w))
        adj[v-1].append((u-1,w))
    
    dfs(0,-1,1)
    [print(v) for v in ans]

if __name__ == "__main__":
    main()


Measured memory_bytes: 84456
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)
#include <math.h> 

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  ll x;
  cin >> x;
  for(ll i=x; i<10000000000000000000; i++)
  if(IsPrime(i)){
    cout << i << endl;
    break;
  }
}

Measured memory_bytes: 3660