akhauriyash/Code-Regression huggingface dataset:
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    ll a,b,c;
    map<ll,ll>maps;
    cin>>a>>b>>c;
    maps[a]++;
    maps[b]++;
    maps[c]++;
    if(maps[5]==2 && maps[7]==1){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3668
n=int(input())
s=input()
l,r=0,n-1
ans=0
while l<r:
  cnt=0
  while r>=0 and s[r]=='W':r-=1
  while l<n and s[l]=='R':l+=1
  if l>=r:break
  while s[r]=='R':
    cnt+=1
    r-=1
  cm=cnt
  while cnt:
    if s[l]=='W':cnt-=1
    l+=1
    if l>r:break
  ans+=cm-cnt
print(ans)

Measured memory_bytes: 68244
s=list(input())
n=len(s)
lis1=['0' for i in range(n)]
lis2=['1' for i in range(n)]
for i in range(0,n,2):
    lis1[i]='1'
    lis2[i]='0'
ans1=0
ans2=0
for i in range(n):
    if lis1[i]!=s[i]:
        ans1+=1
    if lis2[i]!=s[i]:
        ans2+=1
print(min(ans1,ans2))

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

using namespace std;

typedef long long ll;

const ll mod=1e9+7;
const ll maxn=5e5+5;

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

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int L = A + B, R = C + D; 
  
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L == R) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int n,ans=0;

int main()
{	cin>>s;
	n=s.size();
	for(int i=0;i<n/2;++i)
		if(s[i]!=s[n-i-1])
			++ans;
	cout<<ans<<endl;
	return 0;
} 

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

i = 0
ans = 0

while i < N - 1:
    if A[i + 1] == A[i]:
        if i < N - 2:
            A[i + 1] == A[i] + A[i + 2]
        if i == N - 1:
            A[i + 1] += 1
        i += 1
        ans += 1
    i += 1

print(ans)
        


Measured memory_bytes: 3060
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
#define rep2(i, N, s) for(int (i) = (s); (i) < (N) + (s); (i) ++)
#define rrep(i, N) for(int (i) = (N) - 1; (i) >= (0); (i) --)
#define rrep2(i, N, s) for(int (i) = (s); (i) >= (s) - (N) + 1; (i) --)
#define INF 1e9

#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
typedef  pair<int, int> pint;

int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i < N + 1; i += 2){
        int cnt = 0;
        for(int j = 1; j < i + 1; j += 2){
            if(i % j == 0){
                cnt ++;
            }
        }
        if(cnt == 8){
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    S = input()
    MOD = 10 ** 9 + 7
    a = 0
    ab = 0
    abc = 0
    # ?によって分岐する文字列の総数
    total = 1
    for s in S:
        if s == 'A':
            a += total
        elif s == 'B':
            ab += a
        elif s == 'C':
            abc += ab
        else:
            # abc実施しないと、足し算がおかしくなる
            abc = abc * 3 + ab
            ab = ab * 3 + a
            a = a * 3 + total
            total *= 3
        a %= MOD
        ab %= MOD
        abc %= MOD
        total %= MOD
    
    print(abc)


main()

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

int sum(int x){
	int s = 0;
	do{
		int r = x % 10;
		s += r;
		x /= 10;
	}while(x);
	return s;
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, ans = 0;
	cin >> n;
	for(int a = 1; a < n; ++a){
		int b = n - a;
		int t = sum(a) + sum(b);
		if(a == 1 || t < ans) ans = t;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

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

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

void func(vvl &G, vl &col, vl &max_use, ll c, ll now, ll d) {
  if (max_use[now] < d) {
    if (col[now] == 0)
      col[now] = c;
    max_use[now] = d;
    AUTO(x, G[now]) { func(G, col, max_use, c, x, d - 1); }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M, Q;
  cin >> N >> M;
  vvl G(N);
  REP(i, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cin >> Q;
  vl V(Q), D(Q), C(Q);
  REP(i, Q) {
    cin >> V[i] >> D[i] >> C[i];
    V[i]--;
  }
  vl col(N, 0);
  vl max_use(N, -1);
  RREP(i, Q) { func(G, col, max_use, C[i], V[i], D[i]); }
  REP(i, N) cout << col[i] << endl;

  return 0;
}


Measured memory_bytes: 10868
#include<cstdio>
#define maxn 3005
#define ll long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
ll dp[maxn][maxn];
ll a[maxn];
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	scanf("%lld",&a[i]),dp[i][i]=n&1?a[i]:-a[i];
	for (int i=2;i<=n;i++){
		for (int l=1;l<=n;l++){
			int r=l+i-1;
			if ((n-i+1)&1)dp[l][r]=max(dp[l+1][r]+a[l],dp[l][r-1]+a[r]);else
				dp[l][r]=min(dp[l+1][r]-a[l],dp[l][r-1]-a[r]);
		}
	}
	printf("%lld\n",dp[1][n]);
	return 0;
}
/*

*/
 

Measured memory_bytes: 70656
H,W=gets.split.map(&:to_i)
HH=H+2;WW=W+2
ss = [[0]*WW] + (0...H).map{ [0]+gets.chomp.split("").map{ |s| s == "#" ? "#" : 0 }+[0] } + [[0]*WW]
(1..H).each{ |i|
  (1..W).each{ |j|
    next if ss[i][j] != "#"
    [-1,0,+1].product([-1,0,+1]).each{ |a,b|
      next if ss[i+a][j+b] == "#"
      ss[i+a][j+b] += 1
    }
  }
}
puts ss[1...-1].map{ |r| r[1...-1].join }

Measured memory_bytes: 2172
#include <bits/stdc++.h>
#include <vector>
#define ll long long
using namespace std;
int main() {
    int n,q;
    cin >>n>>q;
    string s;
    cin >> s;
    vector<int> l(q);
    vector<int> r(q);
    vector<int> t(n);
    for (int i = 0;i < q;i++){
        cin >> l[i] >> r[i];
    }
    for (int i=0;i<n-1;i++){
        if((s[i] == 'A')&&(s[i+1]=='C')){
            t[i] = 1;
        }else{
            t[i] = 0;
        }
    }
    t[n-1] = 0;
    vector<int> ans(n+1);
    int count = 0;
    ans[0] = 0;
    for (int i=0;i<n;i++){
        if (t[i] == 1){
            count += 1;
        }
        ans[i+1] = count;
        //cout << i+1 << ans[i+1] <<endl;
    }
    for(int i=0;i<q;i++){
        cout << ans[r[i]-1] - ans[l[i]-1]<<endl;
    }
    //0011223
  return 0;
}

Measured memory_bytes: 2688
<?php
 
function input($func = null)
{
    if ($func === null) {
        return trim(fgets(STDIN));
    } else {
        return $func(trim(fgets(STDIN)));
    }
}

function input_array($func = null)
{
    if ($func === null) {
        return explode(' ', input());
    } else {
        return array_map(function ($v) use ($func) {
            return $func($v);
        }, explode(' ', input()));
    }
}

list($N, $K) = input_array('intval');

$r = $N % $K;

$candidate_1 = $r;
$candidate_2 = $K - $r;

if ($candidate_1 <= $candidate_2) {
    echo $candidate_1 . "\n";
} else {
    echo $candidate_2 . "\n";
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a[N+1];
  int b[N+1];
  for(int i = 1;i<=N;i++){
    cin>>a[i];
    b[i] = 0;
  }
  int temp;
  int p;
  int ans = 0;
  for(int i = N;i>0;i--){
    p = 2;
    temp = 0;
    while((i*p)<=N){
      temp += b[i*p];
      p++;
    }
    if((temp%2) == a[i]){
      b[i] = 0;
    }
    else{
      b[i] = 1;
    }
    ans+=b[i];
  }
  cout << ans << endl;
  for(int i = 1;i<N+1;i++){
    if(b[i] == 1){
      cout << i << " ";
    }
  }
  cout << endl;
  return 0;
}
  

Measured memory_bytes: 2432
#include<stdio.h>
#include<string.h>
#define ll long long
#define M 1000002//task
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return ( 1 + key ) % ( M - 1 ); }

int find(char str[]){
  ll a; 
  int i = 0;
  ll b = getKey(str);
 
  while(1){
    a = ( h1(b) + i * h2(b) ) % M;
    if( strcmp(H[a], str) == 0 ) return 1;
    if( H[a][0] == '\0' ) return 0;
    i++;
  }
  return 0;
}

int insert(char str[]){
  int i = 0;
  ll a;
  ll b = getKey(str);
  
  while(1){
    a = ( h1(b) + i * h2(b) ) % M;
    if( H[a][0] == '\0' || strcmp(H[a],str) == 0){
      strcpy(H[a], str);
      break;
    }
    i++;
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n ; i++ ){
	    scanf("%s %s", com, str);
	
	    if ( com[0] == 'i' ){
	     insert(str);
	    } else {
	      if (find(str)){
		      printf("yes\n");
	      } else {
	      	printf("no\n");
	      }
	    }
    }

    return 0;
}



Measured memory_bytes: 15412
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String strs[] = sc.nextLine().split("");
        String old = "";
        for (String str : strs) {
            if ((!old.equals("")) && old.equals(str)) {
                System.out.println("Bad");
                return;
            }
            old = str;
        }
        System.out.println("Good");
    }
}


Measured memory_bytes: 22868
#include <iostream>
#include <vector>
#include <algorithm>
#include <regex>
using namespace std;
typedef long long ll;
int inf = 1<<29;
int main(void){
    string s;cin >> s;
    if(regex_match(s,regex("(dream(er)?|eraser?)*"))) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 40960
use std::cmp;

fn main() {
    let (n, k): (usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let p: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse::<usize>().unwrap() - 1).collect()
    };

    let c: Vec<i64> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut ans = std::i64::MIN;
    for mut i in 0..n {
        let mut v = vec![0; n + 1];
        let mut w = vec![0; n];
        let mut check = vec![false; n];
        let mut d = 0;
        for j in 0..n {
            check[i] = true;
            v[j + 1] = v[j] + c[p[i]];
            w[j] = c[p[i]];
            i = p[i];
            if check[i] {
                d = j + 1;
                break;
            }
        }

        let res = {
            if k <= d {
                (1..=(cmp::min(k, d)))
                .fold(std::i64::MIN, |acc, j| cmp::max(acc, v[j]))
            } else if v[d] <= 0 {
                (1..=(cmp::min(k, d)))
                    .fold(std::i64::MIN, |acc, j| cmp::max(acc, v[j]))
            } else {
                let p = (k - d) % d;
                let (mut max, mut sum) = (0, 0);
                for j in 0..d {
                    sum += w[(j + p) % d];
                    max = cmp::max(max, sum);
                }
                v[d] * ((k - d) / d) as i64 + v[p] + max
            }
        };
        ans = cmp::max(ans, res);
    }
    println!("{}", ans);
}

Measured memory_bytes: 2368
#include<bits/stdc++.h>
using ll = long long;
const ll INF_LL = 1000000000000;
#define fir first
#define sec second
using namespace std;
/*

int main()
{
    ll n,q,s,t;
    cin >> n >> q >> s >> t;
    vector<ll> high(n + 1);
    vector<ll> L(q),R(q),X(q);
    for(int i = 0; i <= n; i++)cin >> high[i];
    for(int i = 0; i < q; i++)cin >> L[i] >> R[i] >> X[i];

    ll cur = 0;
    for(int i = 1; i <= n; i++){
        if(high[i] > high[i - 1]){
            cur -= s * (high[i] - high[i - 1]);
        }else{
            cur += t * (high[i - 1] - high[i]);
        }
    }
    
    for(int i = 0; i < q; i++)
    {
        ll l = L[i], r = R[i], x = X[i];
        ll ch = 0;
        ch = (x >= 0 ? s : t) * x;
        if(r == n)continue;



        cout << cur << endl;
    }

}
*/

int main()
{
    int n;
    cin >> n;
    if(n < 1000)cout << "ABC" << endl;
    else        cout << "ABD" << endl;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#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;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w;
	cin >> h >> w;
	ll ans = INF*INF;
	FOR(i,1, h) {
		vl v(3);
		v[0] = i*w;
		v[1] = w / 2 * (h - i);
		v[2] = (w + 1) / 2 * (h - i);
		sort(ALL(v));
		ans = min(ans, v[2]-v[0]);
	}
	FOR(i,1, w) {
		vl v(3);
		v[0] = i*h;
		v[1] = h / 2 * (w - i);
		v[2] = (h + 1) / 2 * (w - i);
		sort(ALL(v));
		ans = min(ans, v[2] - v[0]);
	}
	ans = min(ans, (h + 2) / 3 * w - h / 3 * w);
	ans = min(ans, (w + 2) / 3 * h - w / 3 * h);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	
	VAR(int, n, m);
	set< int > from, to;
	REP(i, m) {
		VAR(int, a, b);
		if (a == 1) from.insert(b);
		if (b == n) to.insert(a);
	}

	bool ok = false;
	EACH(fi, from) {
		ok |= (to.count(fi) > 0);
	}
	OUT(ok ? "POSSIBLE" : "IMPOSSIBLE")BR;
	
  return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main(){
  while(1){
    int n;
    cin>>n;
    double s[n],a=0;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>s[i];
      a+=s[i];
    }
    double b=0;
    for(int i=0;i<n;i++){
      b+=pow(a/n-s[i],2.0);
    }
    cout<<fixed<<setprecision(6);
    cout<<sqrt(b/n)<<endl;
  }
  return 0;
}



Measured memory_bytes: 3228
from collections import deque
def resolve():
    N = int(input())
    C = input()
    deq = deque(C)
    count = 0
    while deq:
        if deq[-1]=='W':
            deq.pop()
        if len(deq)==0:
            break

        if deq[0]=='R':
            deq.popleft()
        if len(deq)==0:
            break
        
        if deq[0]=="W" and deq[-1]=='R':
            deq.pop()
            deq.popleft()
            count +=1
    print(count)
resolve()

Measured memory_bytes: 82896
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int d,e;
	while(cin >> d >> e,d){
		double ans = 1e9;
		REP(i,d/2 + 1){
			ans = min(ans,fabs(sqrt(i*i + (d-i)*(d-i)) - e));
		}
		cout << ans << endl;
	}
  return 0;
}

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

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> maze(h);
  for(int i=0;i<h;i++) {
    cin >> maze.at(i);
  }
  vector<vector<int>> num(h, vector<int>(w,1e9));
  queue<pair<int,int>> q;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(maze.at(i).at(j)=='#') {
        q.push(pair<int,int> (i,j));
        num.at(i).at(j)=0;
      }
    }
  }
  vector<int> idy={1,0,-1,0};
  vector<int> idx={0,1,0,-1};
  while(q.size()) {
    pair<int,int> temp=q.front();
    q.pop();
    for(int i=0;i<4;i++) {
      int ny=temp.first+idy.at(i);
      int nx=temp.second+idx.at(i);
      if(ny>-1&&nx>-1&&ny<h&&nx<w) {
        if(num.at(ny).at(nx)==1e9) {
          num.at(ny).at(nx)=num.at(temp.first).at(temp.second)+1;
          q.push(pair<int,int> (ny,nx));
        }
      }
    }
  }
  int ans=0;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      ans = max(ans,num.at(i).at(j));
    }
  }
  cout << ans;
}

Measured memory_bytes: 13456
N = int(input())
con = 0
list_s = []

while True:
  con = con + 1
  s = input()
  list_s.append(s)
  if con == N:
    break

ac = list_s.count('AC')
wa = list_s.count('WA')
tle = list_s.count('TLE')
re = list_s.count('RE')

print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 16292
/*
１秒毎に変化する距離は v - wである
v - wが負であるならば, 鬼は絶対に相手に追いつけない

v  > wのとき:
1sごとに, 鬼と相手の距離は v - wだけ縮まる.
t秒間では, t * (v-w)だけ鬼と相手の距離は縮まる
t * (v-w)が, もともとの距離の差, |a-b|以上であれば鬼は相手に追いつける
そうでなければ, 鬼は相手に追いつけない.
*/

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main(void){
    
    long long  a, v;
    cin >> a >> v;
    
    long long b, w;
    cin >> b >> w;
    
    long long t;
    cin >> t;
    
    if (w >= v){
        cout << "NO" << endl;
        return 0;
    }
    
    // 浮動小数点の演算を回避する
    if (abs(a-b) <= (v-w) * t){ // ここで()*tがint型の最大値を越える可能性に注意せよ
        cout << "YES" << endl;
        return 0;
    }
    else{
        cout << "NO" << endl;
        return 0;
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


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

    int n;cin >> n;
  if(n<=999)cout << "ABC" << endl;
  else cout << "ABD" << endl;
}

Measured memory_bytes: 3632
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500+b*100+c*50 == X:
                count += 1

print(count)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
vector <int> vec;
priority_queue <int> qua;
char s[maxx];
char ans[maxx];

int main() {
	int res = Inf;
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	for(int i = 1; i <= n; i++) {
		if(i & 1) ans[i] = '1';
		else ans[i] = '0';
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(ans[i] != s[i]) cnt++;
	}
	res = min(res, cnt);
	memset(ans, 0, sizeof(ans));
	cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(i & 1) ans[i] = '0';
		else ans[i] = '1';
	}
	for(int i = 1; i <= n; i++) {
		if(ans[i] != s[i]) cnt++;
	}
	res = min(res, cnt);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 384
w,h = list(map(int,input().split()))
pq = []
for i in range(w):
    pq.append((int(input()),0))
for i in range(h):
    pq.append((int(input()),1))
pq.sort()
res = 0
w+=1
h+=1
dic = {0:w,1:h}

for x in pq:
    res += dic[1-x[1]]*x[0]
    dic[x[1]] -= 1

print(res)


Measured memory_bytes: 24540
import copy

def warshall_floyd(V, E):
    INF = 10 ** 9
    d = [[[INF, 0] for j in range(V + 1)] for i in range(V + 1)]
    for i, j, c in E:
        d[i][j] = [c, 0]
        d[j][i] = [c, 0]
    for k in range(1, V + 1):
        for i in range(1, V):
            for j in range(i, V + 1):
                dk = d[i][k][0] + d[k][j][0]
                if d[i][j][0] > dk:
                    d[i][j] = [dk, k]
                    d[j][i] = [dk, k]
    return d

def find_path(i, j, d, E):
    k = d[i][j][1]
    if k == 0:
        E[i][j] += 1
        E[j][i] += 1
        return E
    E = find_path(i, k, d, E)
    E = find_path(k, j, d, E)
    return E

n, m = map(int, input().split())
E = [[None for j in range(n + 1)] for i in range(n + 1)]
E_list = []
for i in range(m):
    a, b, c = map(int, input().split())
    E_list.append([a, b, c])
    E[a][b] = 0
    E[b][a] = 0
d = warshall_floyd(n, E_list)
ans = 0
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        E = find_path(i, j, d, E)
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        if E[i][j] == 0:
            ans += 1
print(ans)


Measured memory_bytes: 4820
import kotlin.system.measureTimeMillis
import kotlin.time.measureTime

class Sieve(n: Int) {
    private val f = IntArray(n + 1)
    private val primes = mutableListOf<Int>()

    init {
        f[0] = -1
        f[1] = -1
        for (i in 2..n) {
            if (f[i] > 0) continue
            primes.add(i)
            f[i] = i
            if (i.toLong() * i.toLong() > n) continue
            for (j in i * i..n step i) {
                if (f[j] == 0) f[j] = i
            }
        }
    }

    fun factor(x: Int): MutableMap<Int, Int> {
        val r = mutableMapOf<Int, Int>()
        var x1 = x
        while (x1 != 1) {
            r[f[x1]] = r.getOrElse(f[x1]) { 0 } + 1
            x1 /= f[x1]
        }
        return r
    }
}

fun main() {
    val sieve = Sieve(10000000)
    val n = readLine()!!.toInt()
    var ans = 0L
    for (i in 1..n) {
        var x = 1L
        for ((k, v) in sieve.factor(i)) {
            x *= (v + 1)
        }
        ans += i * x
    }
    println(ans)
}


Measured memory_bytes: 126872
#include<iostream>
#include<algorithm>

using namespace std ;

int main()
{
	int n ,k ;
	while( cin >> n >> k ,k )
	{
		bool space_card[ 3 ] = { false } ,card[ 100000 ] = { false } ;
		for( int i = 0 ; i < k ; i++ )
		{
			int m ;
			cin >> m ;
			if( m )
			{
				card[ m ] = true ;
			}
			else
			{
				space_card[ 0 ] = space_card[ 1 ] = space_card[ 2 ] = true ;
				continue ;
			}
		}
		int ans = 0 ,cnt = 0 ;
		int p = 0 ;
		for( int i = 0 ; i <= n ; i++ )
		{
			if( card[ i ] )
			{
				cnt++ ;
			}
			else if( card[ i + 1 ] & space_card[ 0 ] & space_card[ 1 ] )
			{
				count :
				cnt++ ;
				p = cnt ;
				space_card[ 0 ] = space_card[ 2 ] = false ;
			}
			else
			{
				ans = max( ans ,cnt ) ;
				if( card[ i ] == false && card[ i + 1 ] == false )
				{
					cnt = 0 ;
				}
				else
				{
					cnt -= space_card[ 1 ] ? p : cnt ;
				}
				space_card[ 0 ] = true ;
				if( card[ i + 1 ] & space_card[ 0 ] & space_card[ 1 ] )
				{
					goto count ;
				}
			}
		}
		if( cnt + 1 == k & space_card[ 2 ] )
		{
			cnt++ ;
		}
		cout << max( ans ,cnt ) << endl ;
	}
	return 0 ;
}

Measured memory_bytes: 3104
h, w = map(int, input().split())

grid = []
grid.append(['.'] * (w + 2))
for _ in range(h):
    word = '.' + input() + '.'
    grid.append([i for i in word])
grid.append(['.'] * (w + 2))

for i in range(1, h):
    for j in range(1, w):
        if grid[i][j] == '#':
            if grid[i][j-1] == '#' or grid[i-1][j] == '#' or grid[i][j+1] == '#' or grid[i+1][j] == '#':
                pass
            else:
                print('No')
                exit()

print('Yes')

Measured memory_bytes: 3064
import sys

N,K=map(int,input().split())
ZET=N
b=(10**18)
c=N
b1=N
for i in range(int(b)):
  if K==1:
    b1=0
    break
  if N>10**17 and K<10**9:
    b1=N%K
    c=abs(b1-K)
    if b1>c:
      b1=c
    break
  c=abs(b1-K)
  if int(b)<=c:
    break
  b1=c
  b=c
print(b1)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N; cin >> N ;
    vector<ll> A;
    map<ll,ll> cnt;
    rep(i,N){
        ll inp; cin >> inp;
        A.pb(inp);
        cnt[inp]++;
    }
    
    rmsame(A);
    
    ll ans = 0;
    rep(i,A.size()){
        if(cnt[A[i]] % 2 == 0) ans ++;
    }

    cout << A.size() - (ans%2) << endl;
    ans = -2;
    
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 7284
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int gcd(int a, int b){
	if(a==0){
		return b;
	}else if(b==0){
		return a;
	}else if(a > b){
		return gcd(a%b, b);
	}else{
		return gcd(a, b%a);
	}	 
}

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  int a = gcd(A, B);

  vector<int> divisor;

  for(int i=a;i>0;i--){
  	if(a%i==0) divisor.push_back(i);
  }

 /* int l = divisor.size();

  for(int i=0;i<l;i++) cout << divisor[i] << ' ';
  cout << endl; */

  cout << divisor[K-1] <<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		for(int i = 2; i < 200; i += 2) {
			S = S.substring(0, S.length() - 2);
			int l = S.length();
			String s1 = S.substring(0, l / 2);
			String s2 = S.substring(l / 2, l);
			if(s1.equals(s2)) {
				System.out.println(l);
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 23124
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
 
 
 
class Solve
{
    public Solve() { }
    public static int Main()
    {
        new Solve().calc();
        return 0;
    }
 
 
    Scanner cin;
 
    void calc()
    {
        cin = new Scanner();
        int len = cin.nextInt();
        int[] num = new int[len];
        for(int i=0; i<len; i++)
        {
            num[i] = cin.nextInt();
        }

        int correctCount = 0;
        for(int i=0; i<len-2; i++){
            int result = (num[i]-num[i+1]) * (num[i+2] - num[i+1]);
            if(result < 0) {
                correctCount++;
            }
        }


        Console.WriteLine(correctCount.ToString());
    }
}
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
#include <stdio.h>

int diff(int a, int b){
	return a - b > 0 ? a - b : b - a;
}

int main(void){
	int n;
	scanf("%d", &n);
	int t[n], x[n], y[n];
	for(int i = 0; i < n; i++){
		scanf("%d %d %d", &t[i], &x[i], &y[i]);
	}

	if((t[0] < x[0] + y[0]) || diff(t[0], x[0] + y[0]) % 2 != 0){
		printf("No\n");
		return 0;
	}

	for(int i = 0; i < n - 1; i++){
		int timed = t[i + 1] - t[i];
		int moved = diff(x[i + 1], x[i]) + diff(y[i + 1], y[i]);
		if(timed == moved){
			continue;
		}else if(timed >= diff(timed, moved) && diff(timed, moved) % 2 == 0){
			continue;
		}else{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}


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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

ll p[500000],q[500000],r[500000],eat[500000];
int main() {
   ll i,j,k;
   ll x,y,a,b,c,ans=0;
   cin >>x>>y>>a>>b>>c; 
   for(i=0; i<a; i++)
   {
     cin>>p[i];
   }
   for(i=0; i<b; i++)
   {
     cin>>q[i];
   }
   for(i=0; i<c; i++)
   {
     cin>>r[i];
   }
   
   sort(p+0,p+a);
   sort(q+0,q+b);
   sort(r+0,r+c);
   for(i=0; i<x; i++)
   {
     eat[i]=p[a-i-1];
   }
    for(i=0; i<y; i++)
   {
     eat[x+i]=q[b-i-1];
   }

   sort(eat+0,eat+x+y);
   for(i=0; i<c; i++)
   {
     if(eat[i]<r[c-1-i])
     {
       eat[i]=r[c-1-i];
     }
   }

   for(i=0; i<x+y; i++)
   {
     ans+=eat[i];
   }
   cout<<  ans<<endl;
}

Measured memory_bytes: 13952
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,s,w,x,y,ans = 0;
	//string	s;

	cin >> s >> w;
	
	if (w>=s) {
		cout << "unsafe" << endl;
	} else {
		cout << "safe" << endl;
	}

	

}


Measured memory_bytes: 3600
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Edge{
  int src, dst;
  Edge() {}
  Edge(int u, int v) : src(u), dst(v) {}
};
typedef vector<Edge> Node;
typedef vector<Node> Graph;
bool used[100];
int dfs(int u, Graph& G){
  used[u] = true;
  int res = 0;
  bool tmp_used[100];
  memcpy(tmp_used, used, sizeof(used));
  FORIT(e, G[u]) if(!used[e->dst]){
    res = max(res, 1 + dfs(e->dst, G));
    memcpy(used, tmp_used, sizeof(used));
  }
  return res;
}

int main(){
  int N;
  const int M = 100;
  while(cin >> N && N){
    Graph G(M);
    REP(i, N){
      int u, v; cin >> u >> v;
      u--; v--;
      G[u].push_back(Edge(u, v));
      G[v].push_back(Edge(v, u));
    }
    int ans = 0;
    REP(root, M){
      memset(used, 0, sizeof(used));
      ans = max(ans, dfs(root, G) + 1);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
/*********************************************JMD**********************************************/
//                                  |\  |     | |   |   /\                                   //
    //                              | \ |     | |---|  /--\                              //
        //                          |  \| |___| |   | /    \1999                     //
/*******************************************************************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define mem(x,val) memset(x,val,sizeof(x))
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define f(i,n) forr(i,0,n)
#define sz(x) ll((x).size())
#define all(x) ((x).begin(),(x).end())
#define asc(x) ((int)(x))
#define precision(x) cout<<fixed<<setprecision((x));

const ll mod=1e9 + 7;

/*******************************************************************************************/

void solve()
{
    ll k,n;
    cin>>k>>n;

    ll a[n];
    f(i,n) cin>>a[i];
    sort(a,a+n);

    ll ans=a[n-1]-a[0];
    //ans=min(ans,k-ans);

    for(ll i=1;i<n;i++)
    {
        ans=min(ans,k-(a[i]-a[i-1]));
    }
    cout<<ans<<"\n";

    return;
}

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

    ll t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 1792
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << #i <<" "<<i<<std::endl;
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;


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

  ll n;
  std::cin>>n;

  std::vector<ll> a(n);
  rep(i,0,n)std::cin>>a[i];

  ll cnt=0,max=0;

  rep(i,0,n){
    if(a[i]==max+1){
      max++;
    }else{
      cnt+=a[i]/(max+1)-((a[i]%(max+1)==0)?1:0);
      chmax(max,1);
    }
  }

  std::cout<<cnt;

  return 0;
}





Measured memory_bytes: 1024
//tt89 ;)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
void testcase(int t) { cout<<"Case #"<<t<<": "; }
void online() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif //ONLINE_JUDGE
}
const int mod= 1e9+7;

int main() {
    fastIO;
    int n; cin>>n;
    string s; cin>>s;
    int c=0;
    int l=0,r=n-1;

    while(l<r) {
        if(s[r]=='R' && s[l]=='W') { l++; r--; c++; }
        else if(s[r]=='R') l++;
        else if(s[r]=='W') r--;
    }

    cout<<c<<endl;

    return 0;
}

Measured memory_bytes: 3732
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	a := []int{}
	for i := 0; i < N; i++ {
		a = append(a, nextInt())
	}
	sort.Ints(a)
	var alice int
	var bob int
	for i := N - 1; i > -1; i-- {
		alice += a[i]
		i--
		if i == -1 {
			break
		}
		bob += a[i]
	}
	fmt.Println(alice - bob)
}


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

int main()
{
    int N, M;
    vector<string> A;
    vector<string> B;

    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        A.push_back(s);
    }
    for (int i = 0; i < M; i++)
    {
        string s;
        cin >> s;
        B.push_back(s);
    }

    for (int i = 0; i <= N - M; i++)
    {
        for (int j = 0; j <= N - M; j++)
        {
            bool flg = true;
            for (int k = 0; k < M; k++)
            {
                for (int l = 0; l < M; l++)
                {
                    if (A[i + k][j + l] != B[k][l])
                    {
                        flg = false;
                        break;
                    }
                }
                if (!flg)
                {
                    break;
                }
            }
            if (flg)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
#define RER(i, n) for(int i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;

signed main(){
	cin >> n;
	cout << n*n*n << endl;
    return 0;
}

Measured memory_bytes: 256
import sys; readline = sys.stdin.readline
from collections import deque


N = int(readline())
A = list(map(int, readline().split()))
P = 10**9 + 7


a = 1
state = [0, 0, 0]

for i in range(N):
    c = state.count(A[i]) 
    a *= c
    a %= P
    if c == 0:
        print(0)
        exit(0)
    state[state.index(A[i])] = A[i] + 1

print(a)

Measured memory_bytes: 53084
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
vector<vector<LL>> job;//i日後にjの報酬がもらえる仕事をjob[i][j]とおく
 
LL ans = 0;

void solve(){
	priority_queue<LL> job_candidate;
	//ある日にちd(1<=d<=M-1)に
	//(M-1)-d日後に報酬がもらえる仕事のうち、最大の報酬がもらえるものを受ければ良い
	for(int i=1;i<=M;i++){
		for(LL v : job[i]){
			job_candidate.push(v);
		}
		if(job_candidate.empty()) continue;
		ans += job_candidate.top();
		job_candidate.pop();
	}
}

int main(){
    cin >> N >> M;
    job = vector<vector<LL>>(M+1);
    for(int i=0;i<N;i++){
    	LL a,b;cin >> a >> b;
    	if(a<=M) job[a].push_back(b);
    }
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
//15-2 ??????????????????????????£???
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    int target[100];
    for(int i=0; i<M; i++){
        cin >> target[i];
    }
    
    int point[100] = {};
    for(int i=0; i<M; i++){
        int hazure = 0;
        for(int l=0; l<N; l++){
            int tmp;
            cin >> tmp;
            if(tmp == target[i]){
                point[l]++;
            }
            else{
                hazure++;
            }
        }
        point[target[i]-1] += hazure;
    }

    for(int i=0; i<N; i++){
        cout << point[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        long[] a = sc.nextLongArray(n);
        long[] b = sc.nextLongArray(n);
        long cnt = 0;
        long rem = 0;
        for(int i = 0; i < n; i++){
            rem += b[i]-a[i];
            cnt += Math.max(0,(long)Math.ceil(((double)b[i]-(double)a[i])/2d));
        }
        System.out.println(rem >= cnt ? "Yes" : "No");
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 26068