akhauriyash/Code-Regression huggingface dataset:
S=list(input())
count=0
for i in range(len(S)):
    if i%2==0:
        if S[i]=="R" or S[i]=="U" or S[i]=="D":
            count=1
        else:
            count=0
            break
    else:
        if S[i]=="L" or S[i]=="U" or S[i]=="D":
            count=1
        else:
            count=0
            break
if count==1:
    print("Yes")
else:
    print("No")

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n;
void solve(){
	cin>>n;
	cout<<n*(n+1)/2-3*(n/3)*(n/3+1)/2-5*(n/5)*(n/5+1)/2+15*(n/15)*(n/15+1)/2<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
import Control.Applicative
import Control.Monad

import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

import Data.List

import Data.Char (isSpace)
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  [n, m] <- f
  unless (n == 0 && m == 0) $ do
    solve n m <$> f >>= putStrLn
    main
  where
    f = readil B.readInt <$> B.getLine

solve :: Int -> Int -> [Int] -> String
solve n m xs = maybe "NONE" show $ foldl' f Nothing $ do
  i <- [0 .. n - 2]
  j <- [i+1 .. n - 1]
  return (i, j)
  where
    v = V.fromList xs
    f mx (i, j)
      | v ! i + v ! j > m = mx
      | otherwise = case mx of
                     Nothing -> Just $ v ! i + v ! j
                     Just y -> Just $ max y (v ! i + v ! j)

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')



Measured memory_bytes: 124460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl

int main(){
    int H, N; cin>>H>>N;
    int A[N];
    int sum=0;
    for(int i=0; i<N; i++){
        cin>>A[i];
        sum+=A[i];
    }
    if(H>sum){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}


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


int main() {
int a,b,c;
cin >> a>>b >>c;

if(-min(b,c)-a+max(b,c) < 0){
	cout << 0 <<endl;
}
else{
	cout << -min(b,c)-a+max(b,c) <<endl;
}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string S;
    string T = "CODEFESTIVAL2016";
    cin >> S;
    int ans = 0;
    rep(i,S.size()){
        if(S[i]!=T[i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  string a, b;
  int i=0;
  cin>>a>>b;

  if(a.size()>b.size()){
    cout<<"GREATER"<<endl;
  }else if(a.size()<b.size()){
    cout<<"LESS"<<endl;
  }else{
    while(i!=a.size()){
      if(a[i]>b[i]){
        cout<<"GREATER"<<endl;
        break;
      }else if(a[i]<b[i]){
        cout<<"LESS"<<endl;
        break;
      }else{
        i +=1;
      }
    }
    if(i==a.size()){
      cout<<"EQUAL"<<endl;
    }
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# モジュールのインポート
import copy

# 標準入力の取得
N = int(input())
T_list = list(map(int, input().split()))
M = int(input())
PX_list = [list(map(int, input().split())) for i in range(M)]

# 求解
# 各ドリンク毎に、リストを作成し、その総和を出力する
for m in range(M):
    drunk_t_list = copy.deepcopy(T_list)
    drunk_t_list[PX_list[m][0] - 1] = PX_list[m][1]
    print(sum(drunk_t_list))

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

bool to[15][15];
bool asked[15][15];

int main(){
  int N; cin >> N;
  for(int i = 0; i < N; i++){
    int a; cin >> a;
    for(int j = 0; j < a; j++){
      int x,y; cin >> x >> y; 
      x--;
      if(y){ to[i][x] =  true;}
      else{ to[i][x] = false;}
      asked[i][x] = true;
    }
  }
  
  int ans = 0;
  
  for(int bit = 0; bit < (1<<N); bit++){ 
    //立っていたら親切と仮定
    
    
    bool flag = true;
    
    for(int i = 0; i < N; i++){ 
      
      if( (bit >> i ) & 1){ //i番目の人の証言は全て正しくなければならない
                        
        for(int j = 0; j < N; j++){ 
          
          if( !asked[i][j]){ continue;}
          
          if( to[i][j] && !( (bit >> j) & 1)){ 
            //正直者のiが,jを正直者という(jはbitに含まれていないのに）はおかしい
            flag = false; break;
          }
          if( !to[i][j] && ( (bit >> j) & 1)){ 
            // こっちも同じくおかしい
            flag = false; break;
          }
        }//j
      }//if
    }//i
    
    
    if(flag){ 
      
      int cnt = 0;
      
      for(int i = 0; i < N; i++){
        if( (bit >> i) & 1){ cnt++;}
      }
      
      ans = max(ans, cnt);
   }//flag
  }//bit
  
  cout << ans << endl; return 0;
}
    

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;


struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}

	int left,right;
};


int main(){

	char buf[100],ans[100];
	int ans_index;

	while(true){
		scanf("%s",buf);
		if(buf[0] == '.')break;

		ans_index = 0;
		int div = 0,tmp;

		for(int i = 0; buf[i] != '\0'; i++){
			if(buf[i] == '+'){
				div++;
			}else if(buf[i] == '-'){
				div--;
			}else if(buf[i] >= 'A' && buf[i] <= 'Z'){
				if(div == 0){
					ans[ans_index++] = buf[i];
				}else{
					tmp = buf[i] - 'A';
					if(tmp + div > 25){
						while(tmp+ div > 25){
							div -= 26;
						}
						ans[ans_index++] = buf[i] + div;
					}else if(tmp+div < 0){
						while(tmp+div<0){
							div += 26;
						}
						ans[ans_index++] = buf[i] + div;
					}else{
						ans[ans_index++] = buf[i] + div;
					}
					div = 0;
				}
			}else if(buf[i] == '?'){
				ans[ans_index++] = 'o';
				div = 0;
			}else if(buf[i] == '['){
				ans[ans_index++] = '[';
			}else{ //buf[i] == ']'
				ans[ans_index++] = ']';
			}
		}
		ans[ans_index] = '\0';

		queue<Info> Q;
		int max_depth,depth,calc_left,calc_right;

		while(true){

			max_depth = -1;
			depth = 0;

			for(int i = 0; ans[i] != '\0';i++){
				if(ans[i] == '['){
					depth++;
					max_depth = max(max_depth,depth);
				}else if(ans[i] == ']')depth--;
			}

			depth = 0;

			for(int i = 0; ans[i] != '\0';i++){
				if(ans[i] == '['){
					depth++;
					if(depth == max_depth){
						calc_left = i;
					}
				}else if(ans[i] == ']'){
					if(depth == max_depth){
						Q.push(Info(calc_left,i));
					}
					depth--;
				}
			}


			if(Q.empty())break;

			while(!Q.empty()){

				calc_left = Q.front().left;
				calc_right = Q.front().right;
				Q.pop();

				ans[calc_left] = 'x';
				ans[calc_right] = 'x';

				for(int k = 0; calc_left+1+k < calc_right-1-k;k++){
					swap(ans[calc_left+1+k],ans[calc_right-1-k]);
				}
			}
		}

		for(int i = 0; i < ans_index; i++){
			if(ans[i] == 'x')continue;
			else if(ans[i] == 'o')printf("A");
			else{
				printf("%c",ans[i]);
			}
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 3100
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        int[] A=new int[N];
        int[] ASUM=new int[N+1];
        ASUM[0]=0;
        
        for(int i=0;i<N;i++){
            A[i]=sc.nextInt();
            A[i]=A[i]%M;
        }
        
        int sum=0;
        
        for(int i=0;i<N;i++){
            sum=(sum+A[i])%M;
            ASUM[i+1]=sum;
        }
        
        Arrays.sort(ASUM);
        long ANS=0L;
        int idx=0;
        
        long same=1L;
        
        for(int i=idx;i<N;i++){
            if(ASUM[i]==ASUM[i+1]){
                same++;
            }else{
                ANS+=(same*(same-1))/2;
                same=1L;
            }
        }
        
        ANS+=(same*(same-1))/2;
        
        System.out.println(ANS);
        
    }
}

Measured memory_bytes: 59700
def comp(i,j):
    # i < j <-> 1
    # i > j <-> -1
    # i == j <-> 0
    if len(i) < len(j):
        return 1
    elif len(i) > len(j):
        return -1
    for x in range(len(i)):
        if i[x] == j[x]:
            continue
        elif i[x] > j[x]:
            return -1
        else:
            return 1
    return 0



def bisect_left(array, i):
    __bisect_array = array
    def _bisect_left(i, left, right):
        n = right - left + 1
        mid = (left+right) // 2
        if n == 1:
            if comp(__bisect_array[mid],i) == 1:
                return 1
            else:
                return 0
        if comp(i, __bisect_array[mid]) >= 0:
            return _bisect_left(i,left,mid)
        else:
            return (mid-left+1) + _bisect_left(i,mid+1,right)
    return _bisect_left(i, 0, len(array)-1)

def bisect_right(array, i):
    __bisect_array = array
    def _bisect_right(i, left, right):
        n = right - left + 1
        mid = (right+left) // 2
        if n == 1:
            if comp(i, __bisect_array[mid]) == 1:
                return 0
            else:
                return 1
        if comp(__bisect_array[mid] ,i) >= 0:
            return  (mid-left+1) + _bisect_right(i,mid+1,right)
        else:
           return _bisect_right(i,left,mid)
    return _bisect_right(i, 0, len(array)-1)

N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    l = list(map(str,sorted(l)))
    L.append(l)
ans = 0
for x in L[1]:
    n = bisect_left(L[0],x)
    m = bisect_right(L[2],x)
    m = N - m
    ans += n*m
print(ans)

Measured memory_bytes: 126132
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int X;
    cin >> X;
    int ans = -1;
    for(int i = 0; i <= X; i++){
        if(int(i * 1.08) == X){
            ans = i;
            cout << ans;
            return 0;
        }
    }
    
    cout << ":(" << "\n";
    return 0;
}


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

int main(){
  int N,T;
  cin >>N>>T;
  int can=0,cost=1001;
  int i,c,t;
  for(i=0;i<N;i++){
    cin>>c>>t;
    if(t<=T){
      can=1;
      if(c<cost){
        cost=c;
      }
    }
  }

  if(can==1){
    cout << cost <<endl;
  }else{
    cout << "TLE" <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define pii pair <int,int>
#define vpii vector< pair<int,int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int n, i;
	cin >> n;
	int arr[n + 1];
	foe(i, 1, n)
	cin >> arr[i];
	map <int, int> mp;
	int cnt = 0;
	foe(i, 1, n){
		if(arr[i] == 1){
			if(mp[1] == 0){
				mp[1] = i;
				cnt++;
			}
			continue;
		}
		if(mp[arr[i] - 1] != 0){
			if(mp[arr[i]] == 0){
				cnt++;
				mp[arr[i]] = i;
			}
		}
	}
	cout << (mp[1] == 0 ? -1 : n - cnt);
}

Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int a[2];

signed main() {
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] * a[1] / 2 << endl;
	getchar(); getchar();
	return 0;
}

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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, a, b;
    scan(n, a, b);

    auto ans = powmod(2, n);

    long na = f(n, a);
    long nb = f(n, b);

    ans -= (na + nb) % mod;
    if (ans < 0) ans += mod;
    ans--;
    if (ans < 0) ans += mod;
    writeln(ans);
}

long f(int n, int a) {
    long res = 1;
    foreach (i ; 0 .. a) {
        res *= (n - i);
        res %= mod;
        res *= powmod(a - i, mod - 2);
        res %= mod;
    }
    return res;
}


long powmod(long x, long y) {
    return y > 0 ? powmod(x, y >> 1)^^2 % mod * x^^(y & 1) % mod : 1L;
}


struct ModComb {
    int _N;
    long[] _fact, _factinv;
    long _mod;

    this(int n, long mod = 1_000_000_007L) {
        _N = n;
        _fact = new long[](_N + 1);
        _factinv = new long[](_N + 1);
        _mod = mod;

        _fact[0] = 1;
        foreach (i ; 1 .. _N + 1) {
            _fact[i] = (_fact[i-1] * i) % mod;
        }

        _factinv[_N] = _powmod(_fact[_N], mod - 2);
        foreach_reverse (i ; 0 .. _N) {
            _factinv[i] = (_factinv[i+1] * (i+1)) % mod;
        }
    }

    long c(int n, int k) {
        if (k < 0 || k > n) return 0;
        return f(n) * finv(n - k) % _mod * finv(k) % _mod;
    }

    long p(int n, int r) {
        if (r < 0 || r > n) return 0;
        return f(n) * finv(n - r) % _mod;
    }

    long f(int n) {
        return _fact[n];
    }

    long finv(int n) {
        return _factinv[n];
    }

    long _powmod(long x, long y) {
        return y > 0 ? _powmod(x, y>>1)^^2 % _mod * x^^(y & 1) % _mod : 1;
    }
}

unittest {
    auto mc = ModComb(1_000_000);
    assert(mc.c(5, 2) == 10);
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define eb emplace_back
#define mp make_pair
using namespace std;
const int MAX_N=82;
const int INF=MAX_N*MAX_N;
short a[MAX_N][MAX_N],n,m,b[MAX_N][MAX_N];
bool dp1[MAX_N][MAX_N][INF],dp2[MAX_N][MAX_N][INF];
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>b[i][j];
            a[i][j]-=b[i][j];
            a[i][j]=abs(a[i][j]);
        }
    }
    dp1[0][0][a[0][0]]=dp2[0][0][a[0][0]]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            for(int k=0;k<INF;k++){
                if(dp1[i][j][k]){
                    if(k+a[i+1][j]<INF){
                        dp1[i+1][j][k+a[i+1][j]]=1;
                    }
                    if(k-a[i+1][j]<0){
                        dp2[i+1][j][a[i+1][j]-k]=1;
                    }else{
                        dp1[i+1][j][k-a[i+1][j]]=1;
                    }
                    if(k+a[i][j+1]<INF){
                        dp1[i][j+1][k+a[i][j+1]]=1;
                    }
                    if(k-a[i][j+1]<0){
                        dp2[i][j+1][a[i][j+1]-k]=1;
                    }else{
                        dp1[i][j+1][k-a[i][j+1]]=1;
                    }
                }
                if(dp2[i][j][k]){
                    if(k+a[i+1][j]<INF){
                        dp2[i+1][j][k+a[i+1][j]]=1;
                    }
                    if(k-a[i+1][j]<0){
                        dp1[i+1][j][a[i+1][j]-k]=1;
                    }else{
                        dp2[i+1][j][k-a[i+1][j]]=1;
                    }
                    if(k+a[i][j+1]<INF){
                        dp2[i][j+1][k+a[i][j+1]]=1;
                    }
                    if(k-a[i][j+1]<0){
                        dp1[i][j+1][a[i][j+1]-k]=1;
                    }else{
                        dp2[i][j+1][k-a[i][j+1]]=1;
                    }
                }
            }
        }
    }
    for(int i=0;i<INF;i++){
        if(dp1[n-1][m-1][i]||dp2[n-1][m-1][i]){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int h,w,cnt;
string s;

main() {
    cin >> h >> w;
    rep(j,h) {
        cin >> s;
        rep(i,w) if (s[i]=='#') cnt++;
    }
    if (cnt==h+w-1) ct("Possible")
    else ct("Impossible"
    )
}


Measured memory_bytes: 256
<?php
list($s) = strs();
$t = 'CODEFESTIVAL2016';
$cnt = 0;
for ($i = 0; $i < strlen($s); ++$i)
    if ($s[$i] !== $t[$i]) ++$cnt;
echo $cnt . PHP_EOL;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 16228
#!/usr/bin/env python3
from collections import Counter
# from numba import njit

# input = stdin.readline

# @njit
def solve(n,v):
  if all(x == v[0] for x in v):
    return n//2
  v_even = v[::2]
  v_odd  = v[1::2]

  d_even = list(sorted(Counter(v_even).items(),key=lambda x: x[1],reverse=True))
  d_odd  = list(sorted(Counter(v_odd).items(),key=lambda x: x[1],reverse=True))
  e0 = d_even[0]
  o0 = d_odd[0]
  if e0[0] != o0[0]:
    return n - e0[1] - o0[1]
  e1 = d_even[1]
  o1 = d_odd[1]
  return min(n-e0[1]-o1[1],n-e1[1]-o0[1])



def main():
  N = int(input())
  # N,M = map(int,input().split())
  v = list(map(int,input().split()))
  print(solve(N,v))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 25644
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	ll n,m; cin>>n>>m;
	vvl g(n,vl(0));
	rep(i,0,m){
		ll a,b; cin>>a>>b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector<bool> seen(n);
	seen[0]=true;
	vl dist(n);
	dist[0]-0;
	queue<ll> q;
	q.push(0);
	while(!q.empty()){
		ll k=q.front(); q.pop();
		for(ll c:g[k]){
			if(seen[c])continue;
			seen[c]=true;
			dist[c]=dist[k]+1;
			q.push(c);
		}
	}
	if(dist[n-1]==2)cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	
	
	
	return 0;
}

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

l = 1
r = n
cnt = 0
dp = [False] * (n+1)
while cnt < m:
    if dp[r-l]: r -= 1
    if r-l == (l-r)%n: r-=1
    print(l,r)
    dp[r-l] = True
    dp[(l-r)%n] = True
    r -= 1
    l += 1
    cnt += 1 
    

Measured memory_bytes: 10380
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    long long int n, h, sum = 0, max_a = 0;
    cin >> n >> h;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0;i<n;i++){
        cin >> a[i] >> b[i];
        if(a[i]>max_a) max_a = a[i];
    }
    sort(b.begin(),b.end(),greater<int>());
    for(int i = 0;i<n;i++){
        if(max_a > b[i]) break;
        h -= b[i];
        sum++;
        if(h<=0){
            cout << sum << endl;
            return 0;
        }
    }
    // while(h>0){
    //     h -= max_a;
    //     sum++;
    //     if(h<=0){
    //         cout << sum << endl;
    //         return 0;
    //     }
    // }
    sum += h/max_a + (h%max_a == 0 ? 0 : 1);
    cout << sum << endl;
    return 0;
}

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

using namespace std;

int main(){
    string s; cin >> s;
    int pre = s.find('A');
    int sur;
    for(int i = s.size() -1; i >= 0; --i){
        if(s[i] == 'Z'){
            sur = i;
            break;
        }
    }
    int ans = sur - pre +1;
    cout << ans << endl;

	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
const int inf = 1e9;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	vector<vector<bool> > used(n, vector<bool>(n, false));
	int ans = 0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(used[i][j]) continue;
			used[i][j] = true;
			int diff = a[j] -a[i];
			int sub = 2;
			int prev = j;
			for(int k=a[j]+diff; ; k+=diff){
				auto itr = lower_bound(a.begin(), a.end(), k);
				if(itr == a.end() || *itr != k) break;
				used[prev][itr-a.begin()] = true;
				prev = itr-a.begin();
				sub++;
			}
			ans = max(ans, sub);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6312
#include<bits/stdc++.h>
using namespace std;
long long pd,n,s,p[200005],loc,num,l,r,ss;
long long ans,val[200005];
int main(){
//	freopen("go home.in","r",stdin);
//	freopen("go home.out","w",stdout);
	scanf("%lld%lld",&n,&s);
	pd=0;l=1;r=n+1;
	for (long long i=1;(i<=n);i++){
		scanf("%lld%lld",&loc,&num);
		if(pd==0)
			if (loc>=s){
				p[i]=s;val[i]=0;pd=1;ss=i;
			}
		p[i+pd]=loc;val[i+pd]=num;
	} 
	if (pd==0) p[n+1]=s;
	while (true){
		if (p[l]>=p[ss]){
			
			ans+=p[r]-p[l];
			printf("%lld",ans);
			return 0;
		}
		if (p[r]<=p[ss]){
			
			ans+=p[r]-p[l];
			printf("%lld",ans);
			return 0;
		}
		ans+=p[r]-p[l];
		if (val[l]>=val[r]){
			while (val[l]>=val[r]){
				val[l]+=val[r];
				r--;
				if (p[r]==p[ss]) break;
			}
			
		} else{
			while (val[r]>val[l]){
				val[r]+=val[l];
				l++;
				if (p[l]==p[ss]) break;
			}
		}
		
	}
	//fclose(stdin);fclose(stdout);
	return 0;
}

Measured memory_bytes: 1792
class Node:
    def __init__(self, data):
        self.data = data
        self.neighbors = list()
        self.find_time = 0
        self.end_time = 0

N = int(input())
work_id = 0
nodes = list()
nodes.append(Node(0))


for _ in range(N):
    tmp_list = list( map(int, input().split()) )
    node = Node(tmp_list[0])
    for i in range(tmp_list[1]):
        node.neighbors.append(tmp_list[i+2])
    nodes.append(node)
    nodes[0].neighbors.append(node.data)

# for node in nodes:
#     print(node.data, ":", node.neighbors)


def search(node):
    global work_id

    if node.find_time != 0:
        return
    
    if node.data != 0:
        work_id += 1
        node.find_time = work_id

    if len(node.neighbors) > 0:
        for neighbor in node.neighbors:
            search(nodes[neighbor])
    
    if node.data != 0:
        work_id += 1
        node.end_time = work_id

search(nodes[0])

for node in nodes:
    if node.data == 0: continue
    print(node.data, node.find_time, node.end_time)



Measured memory_bytes: 5652
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

class UnionFind :
    def __init__(self, size) :
        """
        Parameters
        ---
        size : int
            頂点数
        """
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        """
        親のインデックスの取得

        Parameters
        ---
        index : int
            取得する頂点のインデックス

        Returns
        ---
        rootIndex : int
            指定した頂点の根のインデックス
        """
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        """
        木の結合

        Parameters
        ---
        index1 : int
        index2 : int
            結合する頂点のインデックス
        """
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        """
        同じ木に属するかを判定する

        Parameters
        ---
        index1 : int
        index2 : int

        Returns
        ---
        boolean
        """
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        """
        指定した頂点の属する木の大きさを取得する
        """
        return self.size[self.root(index)]

    def getComponent(self) :
        """
        連結成分数を取得する
        """
        return self.component


def sol():
    N, M = map(int, input().split())

    tree = UnionFind(N + M)

    for person in range(N):
        line = list(map(int, input().split()))
        for lang in line[1:]:
            tree.union(person, N + lang - 1)

    rootList = set()
    for person in range(N):
        rootList.add(tree.root(person))

    if len(rootList) == 1:
        print('YES')
    else:
        print('NO')

sol()

Measured memory_bytes: 66924
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

x,y=get_i
ans=0
while x<=y
    x*=2
    ans+=1
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<climits>
#include<cstring>

using namespace std;

int main() {
	int n; cin >> n;
	int a[n], b[n], c[n];

	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	int dp[n+1][3];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = a[0];//a
	dp[0][1] = b[0];//b
	dp[0][2] = c[0];//c

	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
		dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
		dp[i][2] = max(dp[i - 1][1] + c[i], dp[i - 1][0] + c[i]);
	}
	cout << max({ dp[n - 1][0],dp[n - 1][1],dp[n - 1][2] });
}

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

int main(){
    int N; cin >> N;
    pair<int, int> p[N];
    for(int i = 0; i < N; i++){
        int A, B; cin >> A >> B;
        p[i] = make_pair(B, A);
    }
    sort(p, p + N);
    int time = 0;
    bool judge = true;
    for(int i = 0; i < N; i++){
        time += p[i].second;
        if(time > p[i].first) judge = false;
    }
    cout << (judge ? "Yes" : "No") << endl;
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

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

  vector<int> dp(n,0),dp2(n,0);
  dp[0] = a[0];
  dp2[n-1] = a[n-1];
  for(int i = 1; i < n; i++){
    dp[i] = max(dp[i-1],a[i]);
  }
  for(int i = n-2; i >= 0; i--){
    dp2[i] = max(dp2[i+1],a[i]);
  }

  for(int i = 0; i < n; i++){
    if(i == 0) cout << dp2[i+1] << endl;
    else if(i == n-1) cout << dp[n-2] << endl;
    else cout << max(dp[i-1],dp2[i+1]) << endl;
  }

  return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 2e5 + 5, inf = 1e9;
const ll INF = 1e18, mod = 1e9 + 7;
const ld PI = 3.1415926535897932384626433832795;

int cnt[MAXN], n;
ll dp[MAXN], h[MAXN], a[MAXN];
bool vis[MAXN], used[MAXN];

vector<int> G[MAXN];
vector<ll> V;
set<ll> S;
map<ll, int> M;
stack<ll> St;
queue<ll> Q;

ll Tree[2 * 1024 * 1024], Base = 1;

void chTree(int node, ll v) {
    node += Base;
    Tree[node] = v;
    while (node /= 2) {
        Tree[node] = max(Tree[2 * node], Tree[2 * node + 1]);
    }
}

ll read(int node, int lo, int hi, int l, int r) {
    if (r < lo or hi < l) {
        return 0;
    }
    if (l <= lo and hi <= r) {
        return Tree[node];
    }

    int mid = (lo + hi) / 2;
    return max(read(2 * node, lo, mid, l, r), read(2 * node + 1, mid + 1, hi, l, r));
}

ll f(ll j,  ll i) {
    return dp[j] + (h[i] - h[j]) * (h[i] - h[j]);
}

ld g(ll i, ll j) {
    return (ld) (h[j] * h[j] + dp[j] - h[i] * h[i] - dp[i]) / ((ld)(2 * h[j] - 2 * h[i]));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

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

    ll C;
    cin >> n >> C;
    for (int i = 1; i<= n; i++) {
        cin >> h[i];
    }
    h[n + 1] = h[n] + 1;

    dp[1] = 0;
    deque<int> Q = {1};
    for (int i = 2; i <= n; i++) {
        while (Q.size() > 1 and f(Q[1], i) < f(Q[0], i)) {
            Q.pop_front();
        }

        dp[i] = f(Q[0], i) + C;

        while (Q.size() > 1 and g(Q[Q.size() - 2], i) <= g(Q[Q.size() - 2], Q.back())) {
            Q.pop_back();
        }
        Q.push_back(i);
    }

    cout << dp[n] << "\n";
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int a[52][52];
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int cnt[4];
/* ??????.->0 ?????§??£??\B,W,B&W->1,2,3 ???B,W->10,20 ?£?->30 */

void paint(int y,int x,int color){
    if(a[y][x]>=3 || a[y][x]==color)return;
    cnt[a[y][x]]--;
    a[y][x] |= color;
    cnt[a[y][x]]++;
    rep(i,4)paint(y+dy[i],x+dx[i],a[y][x]);
}

int main(void){
    int h,w;
    char c;
    while(cin>>w>>h, w|h){
        rep(i,4)cnt[i]=0;
        rep1(y,h){
            rep1(x,w){
                cin>>c;
                if(c=='.')a[y][x] = 0;
                else a[y][x] = (c=='B' ? 10 : 20);
            }
        }
        rep(y,h+2)a[y][0]=a[y][w+1] = 30;
        rep(x,w+2)a[0][x]=a[h+1][x] = 30;

        rep1(y,h)rep1(x,w)if(a[y][x]>=10)rep(i,4)paint(y+dy[i],x+dx[i],a[y][x]/10);

        cout<<cnt[1]<<" "<<cnt[2]<<endl;
    }

    return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
const int md=1e9+7;
int n,st;
string s[2];
long long dp[55];
int main()
{
	cin>>n;
	cin>>s[0];
	cin>>s[1];
	if(s[0][0]==s[1][0])
	{
		st=1;
		dp[0]=3;
	}
	else
	{
		st=2;
		dp[1]=6;
	}
	for(int i=st;i<n;i++)
	{
		if(s[0][i]==s[1][i])
		{
			if(s[0][i-1]==s[1][i-1])dp[i]=dp[i-1]*2%md;else dp[i]=dp[i-1];
		}
		else
		{
			if(s[0][i-1]==s[1][i-1])dp[i+1]=dp[i-1]*2%md;else dp[i+1]=dp[i-1]*3%md;
			i++;
		}
	}
	printf("%lld\n",dp[n-1]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
using namespace std;
vector <int> V;
int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  int c=a;
  if(b<10)
  {
    c*=10;
    c+=b;
  }
  if(b<100 and b>=10)
  {
    c*=100;
    c+=b;
  }
  if(b==100)
  {
    c*=1000;
    c+=b;
  }
  //cout << c;
  for(int i=1;i<=10000;i++)
  {
    if(i*i==c)
    {
      printf("Yes");
      return 0;
    }
  }
  printf("No");
}


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

using namespace std;

int main() {
    double d;
    cin >> d;
    int d1 = d*1000;
    double ans = sqrt(2)*d;
    ans = max<double>(ans, (int)(d)+1);
    printf("%.10lf\n", ans);
    return 0;
}

Measured memory_bytes: 3176
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int main() {
  string cls;
  int am, pm;
  rep (i,9) {
    cin >> cls >> am >> pm;
    cout << cls << " " << am + pm << " " << am * 200 + pm * 300 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = 1000000005;
const int MAX = 300000;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------
int N, X, Y;

void bfs(int s, const vector<vector<int>> &G, vector<vector<int>> &d) {
    vector<bool> visit(N, 0);
    queue<P> que;
    visit[s] = 1;
    d[s][s] = 0;
    que.push({s, d[s][s]});
    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (auto nv : G[p.first]) {
            if (visit[nv]) {
                continue;
            }
            visit[nv] = 1;
            d[s][nv] = p.second + 1;
            que.push({nv, d[s][nv]});
        }
    }
}

int main(void) {
    // code here
    cin >> N >> X >> Y;
    vector<vector<int>> G(N + 1);
    vector<vector<int>> d(N + 1, vector<int>(N + 1, 0));
    for (int i = 0; i < N; i++) {
        if (i == N - 1) {
            continue;
        }
        G[i].push_back(i + 1);
        G[i + 1].push_back(i);
    }
    X--;
    Y--;
    G[X].push_back(Y);
    G[Y].push_back(X);
    vector<int> ans(N + 1, 0);
    for (int i = 0; i < N; i++) {
        bfs(i, G, d);
        for (int j = 0; j < N; j++) {
            if (i < j) {
                //cout << '(' << i << ',' << j << ')' << '=' << d[i][j] << endl;
                ans[d[i][j]]++;
            }
        }
    }
    for (int k = 1; k < N; k++) {
        cout << ans[k] << endl;
    }
}


Measured memory_bytes: 16128
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int count = 0;
    for (int num = a; num <= b; num++) {
      if (isPalindromicNumbers(num)) count++;
    }
    System.out.println(count);
  }
  public static boolean isPalindromicNumbers(int num) {
    String strNum = Integer.toString(num);
    for (int i = 0; i < strNum.length() / 2; i++) {
      if (strNum.charAt(i) != strNum.charAt(strNum.length() - i - 1)) return false;
    }
    return true;
  }
}

Measured memory_bytes: 28884
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl

int K,k=0;

int out(int R){
    cout << R << endl;
    k++;
    if(k>=K){
        return -1;
    }else{
        return 0;
    }
}


signed main(void){
    cin >> K;
    
    int s=1,t=9,u=1;
    REP(l,3){
        for(int i=s;i<=t;i+=u){
            if(out(i)==-1){
                return 0;
            }
        }
        s=s*10+9;
        t=t*10+9;
        u=10*u;
    }
    
    int r=99;
    int i=20;
    while(1){
        i=min(i,100LL);
        for(int j=10;j<i;j++){
            cout << j;
            if(out(r)==-1){
                return 0;
            }
        }
        for(int j=i+9;j<=99;j+=10){
            cout << j;
            if(out(r)==-1){
                return 0;
            }
        }
        i+=10;
        if(log10(r)>=11)break;
        r=r*10+9;
    }
    for(int j=100;j<=108;j++){
        cout << j;
        if(out(r)==-1){
            return 0;
        }
    }
    r=r*10+9;
    
    for(int j=10;j<=99;j++){
        cout << j;
        if(out(r)==-1){
            return 0;
        }
    }
    
    
    return 0;
}

/* 考察につかったコード　いちおう残すくにきあ
int S(int x){
    int r=0;
    while(x){
        r+=x%10;
        x/=10;
    }
    return r;
}

signed main(void){
    setdouble(10);
    int K;
    cin >> K;
    int mx1=1000000000000,mx2=1;
    for(int j=1e6;j>0;j--){
        int i=(j+1)*100000000-1;
        //cout << i << " "<<(double)((i+0.0)/(double)S(i)) << endl;
        if(i*mx2<=mx1*S(i)){
            //cout << i << " "<<(double)((i+0.0)/(double)S(i)) << endl;
            cout << i << endl;
            mx1=i;
            mx2=S(i);
        }
    }
    
    
    return 0;
}*/


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            String input = Console.ReadLine();
            int num = int.Parse(Console.ReadLine());

            HashSet<String> set = new HashSet<String>();

            int max_len = 5;

            for (int i = 1; i <= max_len; i++)
            {
                for (int j = 0; j <= input.Length - i; j++)
                {
                    set.Add(input.Substring(j, i));
                }
            }
            Console.WriteLine(set.OrderBy(s => s).ElementAt(num - 1));

        }
    }
}


Measured memory_bytes: 14816
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int k,n;
    cin>>k>>n;
    VII arr(n);
    for(auto &x:arr)cin>>x;
    int mx=arr[n-1],mn=arr[0];
    int ans=k;
    for(int i=0;i<n;++i)
    {
        ans=min({ans,(arr[i]-mn)*2+(mx-arr[i]),(mx-arr[i])*2+(arr[i]-mn)});
        if(i-1>=0)
        ans=min(ans,k-(arr[i]-arr[i-1]));
        if(i+1<n)
        ans=min(ans,k-(arr[i+1]-arr[i]));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
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 chmax(a, b) a = max(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;
using P = pair<ll, ll>;

int main(){
  int n;
  cin>>n;
  vector<P>a(n);
  rep(i,n){
    ll x;
    cin>>x;
    a[i]=P(x,i);
  }
  sort(a.rbegin(),a.rend());

  vector<vector<ll>>dp(n+1,vector<ll>(n+1));
  rep(i,n){
    rep(j,i+1){
      int k=i-j;
      chmax(dp[j+1][k],dp[j][k]+a[i].fi*(a[i].se-j));
      chmax(dp[j][k+1],dp[j][k]+a[i].fi*(n-k-1-a[i].se));
    }
  }
  ll ans=0;
  rep(i,n+1){
    chmax(ans,dp[i][n-i]);
  }
  /*rep(i,n+1){
    rep(j,n+1){
      cout<<dp[i][j]<<' ';
    }
    cout<<endl;
  }*/
  cout<<ans<<endl;
  return(0);
}


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

int main() {
  int x, y;
  cin>>x>>y;
  for (int i=0; i<=x; i++) {
    if (y == 2 * i + 4 * (x - i)) {
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3672
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int sum = 0, d = 1;
  while (d <= n) {
    if (d == n) {
      sum += 10;
    } else {
      sum += (n / d) % 10;
    }
    d *= 10;
  }
  cout << sum << endl;
}

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

int main() {
    //
    string str;
    int n = 3;
    int cnt = 0;
    cin >> str;

    vector<int> vec(4);

    for (int i = 0; i < 4; i++) vec.at(i) = str.at(i) - '0';

    for (int bit = 0; bit < (1 << n); bit++) {
        int calc = vec.at(0);
        string str = to_string(vec.at(0));

        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) {
                calc += vec.at(i + 1);
                str +=  "+" + to_string(vec.at(i + 1));
            } else {
                calc -= vec.at(i + 1);
                str += "-" + to_string(vec.at(i + 1));
            }
        }

        if (calc == 7) {
            cout << str + "=7";
            return 0;
        }
    }
    //
}


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

int main(){
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000 % 10;
  b = N / 100 % 10;
  c = N / 10 % 10;
  d = N % 10;
  if((a == b && b == c) || (b == c && c == d )){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}
  
  


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

 
int main(){
  int H,N;
  cin >> H >> N;
  int s = 0;
  int tmp;

  for(int i=0;i<N;i++){
    cin >> tmp;
    s += tmp;
  }

  if(s >= H){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] W = new int[N];
        string[] s = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
        {

            W[i] = int.Parse(s[i]);
        }

        List<int> list = new List<int>();
        int S = 0;
        for (int l = 0; l < N; l++)
        {
            S = S + W[l];
        }
        for (int j = 0; j < N; j++)
        {
            int Sa = 0;
            int Sb = 0;
           
            for (int k = 0; k <= j; k++)
            {
                Sa = Sa + W[k];
            }

            Sb = S - Sa;
            int D = Sa - Sb;
            if (D < 0) { D =-D; }

            list.Add(D);
            list.Sort();

           
        }
        Console.WriteLine(list[0]);
    }
}


Measured memory_bytes: 11220
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> gr[114514];
lint dp[114514],a[114514];
string out="YES";
void dfs(int v,int u){
	lint ls=0,lm=0,c=0;
	rep(i,gr[v].size()){
		int w=gr[v][i];
		if(w==u) continue;
		dfs(w,v);
		ls+=dp[w];lm=max(lm,dp[w]);
		c++;
	}
	if(c==0){
		dp[v]=a[v];return;
	}
	//hi[v]=a[v];lo[v]=max(0LL,a[v]-hs);
	if(max(ls/2,lm)>a[v]){
		out="NO";
	}
	if(ls<a[v]) out="NO";
	dp[v]=a[v]*2-ls;
	//cout<<v<<' '<<u<<' '<<dp[v]<<endl;
}
int main()
{
	int n,x,y;
	cin>>n;
	rep(i,n) cin>>a[i];
	rep(i,n-1){
		cin>>x>>y;x--;y--;
		gr[x].pb(y);gr[y].pb(x);
	}
	if(n==2){
		if(a[0]==a[1]){
			cout<<"YES"<<endl;
		}
		else cout<<"NO"<<endl;
		return 0;
	}
	rep(i,n){
		if(gr[i].size()>1){
			dfs(i,-1);
			//cout<<dp[i]<<endl;
			if(dp[i]!=0) out="NO";
			break;
		}
	}
	cout<<out<<endl;
}


Measured memory_bytes: 15616