akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int n;
int A[20];
int x[20][20];
int y[20][20];

bool check(int bit){
    //全ての証言を調べていく
    //i番目の人の証言について調べる
    for(int i = 0; i < n; i++){
        //i番目の人が不親切想定なら、証言は全て無意味なのでスキップ
        if(!(bit & (1 << i)))continue;
        //i番目の人の証言jについて調べる
        for(int j = 0; j < A[i]; j++){
            //bit >> x[i][j]でx[i][j]番目を一番右において、1と論理積を取ることでほかの桁を全て0にする
            //^はXOR演算子、どちらか片方だけが1の場合0を、両方1、もしくは両方0の場合1を返す
            if(((bit >> x[i][j]) & 1) ^ y[i][j])return false;
        }
    }
    return true;
}

int main(void){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        for(int j = 0; j < A[i]; j++){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int maxj = 0;
    for(int bit = 0; bit < (1 << n); bit++){
        //このbitが真実の1つなら、立っているフラグの数を数える(正直者の数を数える)
        if(check(bit)){
            maxj = max(maxj,__builtin_popcount(bit));
        }
    }
    cout << maxj << endl;
}

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

int main() {
	string S,T;
	cin >> S >> T;
	int ans =0;
	for(int i=0;i<S.size();i++){
		if(S.at(i)!=T.at(i)){
			ans++;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 3856
#include<iostream>
#include<vector>
#define rep(i,N) for(int i=0; i<N; i++)

using namespace std;

int main(){
  int N,L ; cin >> N >> L;
  vector<int>  a(N);
  int s = 0;
  rep(i,N){
    a[i] = L + i;
    s += a[i];
  }
  int ans = 1e9;
  rep(i,N){
    int t = s - a[i];
    if(abs(t-s) < abs(ans-s)) ans = t;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //int a = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            string ans;
            if (str == "Sunny") ans = "Cloudy";
            else if (str == "Cloudy") ans = "Rainy";
            else ans = "Sunny";
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
const Int M = 15;
Int dp[2][1<<M][M+1];
Int pp[1<<M];
Int dst[M];

Int ans[M*2];
Int ord[M];

Int ox[M];

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

  Int n;
  cin>>n;

  vector<Int> xs(n),ys(n),ps(n);
  for(Int i=0;i<n;i++) cin>>xs[i]>>ys[i]>>ps[i];

  const Int INF = 1e18;
  Int sz=1<<n;
  for(Int i=0;i<=n;i++)
    for(Int b=0;b<sz;b++)
      dp[0][b][i]=dp[1][b][i]=INF;

  pp[0]=0;
  for(Int i=1;i<sz;i++) pp[i]=pp[i>>1]+(i&1);


  for(Int k=0;k<2;k++){
    for(Int i=0;i<n;i++) ord[i]=i;
    sort(ord,ord+n,[&](Int i,Int j){
      return xs[i]!=xs[j]?xs[i]<xs[j]:i<j;
    });

    for(Int i=0;i<n;i++) ox[i]=xs[ord[i]];

    for(Int b=0;b<sz;b++){
      for(Int a=b;;a=(a-1)&b){
        for(Int i=0;i<n;i++) dst[i]=abs(xs[i]);
        Int lst;

        lst=-INF;
        for(Int i=0;i<n;i++){
          if((a>>ord[i])&1) lst=ox[i];
          chmin(dst[ord[i]],abs(ox[i]-lst));
        }

        lst=+INF;
        for(Int i=n-1;i>=0;i--){
          if((a>>ord[i])&1) lst=ox[i];
          chmin(dst[ord[i]],abs(ox[i]-lst));
        }

        Int res=0;
        for(Int i=0;i<n;i++)
          if((b>>i)&1) res+=dst[i]*ps[i];

        chmin(dp[k][b][__builtin_popcount(a)],res);
        if(a==0) break;
      }
    }
    for(Int i=0;i<n;i++) swap(xs[i],ys[i]);
  }

  for(Int i=0;i<=n;i++) ans[i]=INF;
  for(Int b=0;b<sz;b++)
    for(Int i=0;i<=n;i++)
      for(Int j=0;j<=n;j++)
        chmin(ans[i+j],dp[0][b][i]+dp[1][(sz-1)^b][j]);

  for(Int i=0;i<=n;i++) cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 12044
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
//using namespace boost;
//using namespace multiprecision;  

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

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

    vector<pii> pos(1000);
    vector<bool> flg(1000);
    int n;
    rep(i,3){
        rep(j,3){
            int a;
            cin >> a;
            pos[a] = pii(i,j);
            flg[a] = true;
        }
    }

    cin >> n;
    vector<vector<bool> > bingo(3,vector<bool>(3));

    rep(i,n){
        int b;
        cin >> b;
        int y,x;
        if(flg[b]){
            tie(y,x) = pos[b];
            bingo[y][x] = true;
        }
    }

    rep(i,3){
        rep(j,3){
            if(!bingo[i][j]) goto ng1;
        }
        return cout << "Yes\n",0;
ng1:;
    }

    rep(i,3){
        rep(j,3){
            if(!bingo[j][i]) goto ng2;
        }
        return cout << "Yes\n",0;
ng2:;
    }

    if((bingo[0][0] && bingo[1][1] && bingo[2][2]) || (bingo[0][2] && bingo[1][1] && bingo[2][0])){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 998244353;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

ll n , k ;
vector<ll> rui;

ll f(ll x){
    if(x<0) return 0;
    return rui[x];
}

int main(){
    cin >> n >> k;
    vector<pair<ll,ll>> a(0);
    rep(i,k){
        ll l,r; cin >> l >> r;
        a.emplace_back(make_pair(l,r));
    }
    rui.resize(n,0);
    rui[0] = 1;
    for(int i=1;i<n;i++){
        ll x = 0;
        rep(j,k){
            x = (x + f(i-a.at(j).first) - f(i-a.at(j).second -1)) %mod;
        }
        rui[i] = (rui[i-1] + x)%mod;
    }
    ll ans = (rui[n-1] - rui[n-2])%mod;
    if(ans<0) ans+=mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4836
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <limits>
#include <iomanip>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class B {
public:
	void solve(std::istream& in, std::ostream& out) {
	    string w;
	    map<char,int> m;
	    in>>w;
	    rep(i,w.size()){
	        m[w.at(i)]++;
	    }
	    bool isBeu=true;
	    for(const auto i:m){
	        if(i.second%2!=0) isBeu=false;
	    }
	    if(isBeu) out<<"Yes";
	    else out<<"No";

	}
};


int main() {
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int N, D;
    cin >> N >> D;
    int ans;
    if ((N / (2 * D + 1)) >= 1)
    {
        if ((N % (2 * D + 1)) == 0)
        {
            ans = (N / (2 * D + 1));
        }
        else
        {
            ans = (N / (2 * D + 1)) + 1;
        }
    }
    else
    {
        ans = 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = int(readline())

    COM_MAX = 2000

    fac, finv, inv = [0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1)
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1

    for i in range(2, COM_MAX + 1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    def com(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

    ans = 0
    for l in range(1, 2000):
        n = S - 3 * l
        if n < 0:
            break
        ans = (ans + com(n + l - 1, n)) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,m;
	cin >> n >> m;
	int a[n],b[n]={0};
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]/=2;
	}
	for(int i=0;i<n;i++){
		int t=a[i];
		while(t%2==0){
			t/=2;
			b[i]++;
		}
	}
	sort(b,b+n);
	if(b[0]!=b[n-1]){
		cout << 0;
		return 0;
	}
	int l=a[0];
	for(int i=1;i<n;i++){
		l=(l*a[i])/__gcd(l,a[i]);
	}
	l=m/l;
	cout << (l+1)/2;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long A, B ,C;
    cin >> A >> B >> C;
    if( A + B >=  C){
        printf("%lld\n", B+C);
    }
    else{
        printf("%lld\n", A+B+B+1);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1ll<<60;

int main(void)
{
    ll N, M;
    cin >> N >> M;
    int odd_m = M / 2 + M %2;
    int even_m = M / 2;
    int odd_l = 1;
    int odd_r = odd_m * 2;
    int even_l = odd_r + 1;
    int even_r = even_l + even_m * 2;
    while(odd_l < odd_r){
        cout << odd_l++ << " " << odd_r-- << endl;
    }
    while(even_l < even_r){
        cout << even_l++ << " " << even_r-- << endl;
    }
    return 0;
}

Measured memory_bytes: 3648
//#pragma comment(linker, "/STACK:1024000000,1024000000")
/* vim: set fdm=marker */
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int iinf = 0x7fffffff;
const ll linf = ~(1LL<<63);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;
template<typename T>
inline T gcd(T a, T b) {
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd( a,-b);
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll qpow(ll a, ll n, ll mod) {
	a %= mod;
	ll ans = 1LL;
	while(n) {
		if(n & 1) ans = (ans*a % mod);
		a = (a*a % mod);
		n >>= 1;
	}
	return ans;
}

inline ll rev(ll a, ll p) {
	return qpow(a, p - 2, p);
}

#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define rep(x, st, en) for(int x = st; x < en; x++)
#define pb push_back
#define mp make_pair
#define dbgm(msg, var) cerr<<#msg<<" "<<#var<<" = "<<var<<endl; 
#define dbg(var) cerr<<#var<<" = "<<var<<endl;
#define X first
#define Y second
inline int in() { int x; cin>>x; return x; }
#ifdef ALNDBG
namespace alndbg {
	clock_t s, e;
}
#endif

inline void tic() {
#ifdef ALNDBG
	alndbg::s = clock();
#endif
}

inline void toc() {
#ifdef ALNDBG
	alndbg::e = clock();
	cerr<<1000.0 * (alndbg::e - alndbg::s) / CLOCKS_PER_SEC<<" ms"<<endl;
#endif
}

//}}}

// -------------------- Spliters ------------------------

void printsmall(int N, int x) {
	if(N == 1) {
		cout<<"Yes"<<endl;
		cout<<1<<endl;
		return;
	}
	if(N == 3) {
		if(x == 2) {
			cout<<"Yes"<<endl;
			cout<<"1\n2\n3\n"<<endl;
		} else {
			cout<<"No"<<endl;
		}
		return;
	}
	if(N == 5) {
		if(x == 1 || x == 5) cout<<"No"<<endl;
		else {
			cout<<"Yes"<<endl;
			if(x == 2) {
				cout<<3<<'\n'<<1<<'\n'<<2<<'\n'<<4<<'\n'<<5<<endl;
			} else if(x == 4) {
				cout<<1<<'\n'<<2<<'\n'<<4<<'\n'<<5<<'\n'<<3<<endl;
			} else {
				cout<<"1\n2\n3\n4\n5"<<endl;
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	int N;
	int x;
	cin>>N>>x;
	N = 2 * N - 1;
	if(N <= 5) printsmall(N, x);
	else {
		if(x == 1 || x == N) cout<<"No"<<endl;
		else if(x == 2 || x == N - 1) {
			cout<<"Yes"<<endl;
			int l = (N - 3) / 2;
			int last = 0;
			rep(i, 1, N + 1) {
				if(x - 1 <= i && i <= x + 1) continue;
				if(l == 0) { last = i; break; }
				cout<<i<<endl;l--;
			}
			cout<<x - 1<<endl<<x<<endl<<x+1<<endl;
			for(int i = last; i <= N; i++) {
				if(x - 1 <= i && i <= x + 1) continue;
				cout<<i<<endl;
			}		
		}
		else {
			cout<<"Yes"<<endl;
			int l = (N - 5) / 2;
			int last = 0;
			for(int i = 1; i <= N; i++) {
				if(x - 2 <= i && i <= x + 2) continue;
				if(l == 0) { last = i; break; }
				cout<<i<<endl;
				l--;
			}
			cout<<x - 2<<endl
						  <<x + 1<<endl
							<<x<<endl
							<<x - 1<<endl
							<<x + 2<<endl;
			for(int i = last; i <= N; i++) {
				if(x - 2 <= i && i <= x + 2) continue;
				cout<<i<<endl;
			}
		}
	}
	return 0;
}
// --USE C++11
// *-USE O2


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int ans = h2 * 60 + m2 - h1 * 60 - m1 - k;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main()
{
    char s[3];
    scanf("%s", s);
    
    if(s[0]=s[1] && s[0]==s[2] && s[1]==s[2]){
    	puts("No");
	}
    else if(s[0]=s[1] && s[0]!=s[2] && s[1]!=s[2]){
    	puts("Yes");
	}
     else if(s[0]=s[2] && s[0]!=s[1] && s[1]!=s[2]){
		puts("Yes");
	}
     else if(s[1]=s[2] && s[0]!=s[1] && s[0]!=s[2]){
		puts("Yes");
        }
		
	return 0;
} 

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;




int main(){
   //ios::sync_with_stdio(0);
   // freopen("in.in","r",stdin);
    //freopen("out_1.out","w",stdout);

    int n,m;
    cin>>n>>m;
    
    int res = (n - 1) * (m - 1);
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)
 
signed main(){
  int A,B,C;
  cin>>A>>B>>C;
  int ans=max({A,B,C})-min({A,B,C});
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N=int(input())
S=input()

while True:
    x=''
    ans=''
    for i in S:
       if (x==''):
        x=i
        continue
       if x!=i:
        #print("p:",x,i,ans)
        ans+=x
        x=i
        #print("a:",x,i,ans)

    ans+=x
    #print('ans:',ans)
    if ans==S:
        break
    else:
        S=ans
print(len(ans))       

Measured memory_bytes: 9260
import Control.Monad
import Data.List

main = do
  [n, m, c] <- map read . words <$> getLine
  b <- (map read . words) <$> getLine
  as <- replicateM n (map read . words <$> getLine)
  print $ length $ filter (>0) $ map (func c b) as

func :: Int -> [Int] -> [Int] -> Int
func c b x = c + (foldr (+) 0 $ zipWith (*) b x )

Measured memory_bytes: 1020
#include<cstring>
#include<cstdio>
#include<cmath>
#include<memory.h>
#include<algorithm>
#include<map>
#define ll long long
#define ld long double
#define maxn 310
#define For(i,j,k)  for(ll i=j;i<=k;++i)
#define FOr(i,j,k)  for(ll i=j;i>=k;--i)
const ll inf=1e9;
const ld eps=1e-7;
using namespace std;
inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; }
inline void wrote(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) wrote(x/10);   putchar(x%10+'0');  }
void writeln(ll x){ wrote(x);   puts("");   }
const ll N=100010;
ll a[N],n;
ll dis(ll a,ll b){	return abs(a-b);	}
ll work(){
	ll sum=0,ans=0;
	For(i,1,n){
		sum+=a[i];
		if (i&1){
			if (sum<=0)	ans+=dis(1,sum),sum=1;
		}else{
			if (sum>=0)	ans+=dis(-1,sum),sum=-1;
		}
	}return ans;
}
int main(){
	n=read();
	For(i,1,n)	a[i]=read();
	ll ans1=work();
	For(i,1,n)	a[i]=-a[i];
	ll ans2=work();
	writeln(min(ans1,ans2));
}

Measured memory_bytes: 896
#define pb push_back
#define MX 1e3
#define mod 1000000009
#define ff first
#define ss second
#define for1(i,n) for(int i=1;i<=n;i++)
#define for0(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned  ll;

int main(int argc, char const *argv[]) {
  string a ,b;
  cin>>a>>b;
  if(a.size()>b.size()){
    cout<<"GREATER";
  }
  else if(a.size()<b.size()){
    cout<<"LESS";
  }
  else{
    for(int i=0;i<a.size();i++){
      if(a[i]>b[i]){
        cout<<"GREATER";
        return 0;
      }
      else if(a[i]<b[i]){
        cout<<"LESS";
        return 0;
      }
    }
    cout<<"EQUAL";
  }
  return 0;
}


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

int main()
{
    long long n ,ans = 2 ,N ,i;
    cin >> n;
    if(n == 2){
        cout << 1 << endl;
        return 0;
    }
    for(N,i=2; i*i<=n; i++){
        for(N=n; N%i==0; N/=i);
        ans += (N%i==1) + (n%i==1);
    }
    cout << ans-((i-1)*(i-1)==n-1) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N, M = map(int, input().split())
    ans = [None] * N
    for _ in range(M):
        S, C = map(int, input().split())
        S -= 1
        if ans[S] is None:
            ans[S] = C
        else:
            if ans[S] != C:
                print(-1)
                return

    if N != 1 and ans[0] == 0:
        print(-1)
        return

    if ans[0] is None:
        if N == 1:
            ans[0] = 0
        else:
            ans[0] = 1

    for i in range(1, N):
        if ans[i] is None:
            ans[i] = 0

    print(*ans, sep="")


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9736
#include <stdio.h>
int main(void){
    int n,m[100000]={},a,i,s[3]={};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        m[--a]=3-(m[a]?m[a]:2);
    }
    for(i=0;i<100000;s[m[i++]]++);
    printf("%d",s[1]+(s[2]/2)*2);
}

Measured memory_bytes: 512
// Test3.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	long n;
	long p[50];
	long i, j, chk_i, chk, tmp;

	scanf ("%ld", &n);

	for (i = 0; i < n; i++) {
		scanf ("%ld", &p[i]);
	}

	chk = 1;
	for (i = 0; i < (n - 1); i++) {
		if (p[i] > p[i + 1]) {
			 chk = 0;
			 chk_i = i;
			 break;
		}
	}
	if(chk) {
		printf("YES\n");
		return 0;
	}
	for (j = 0; j < chk_i; j++) {
		tmp = p[j];
		p[j] = p[chk_i];
		p[chk_i] = tmp;
		chk = 1;
		for (i = 0; i < (n - 1); i++) {
			if (p[i] > p[i + 1]) {
				 chk = 0;
				break;
			}
		}
		if(chk) {
			printf("YES\n");
			return 0;
		}
		tmp = p[j];
		p[j] = p[chk_i];
		p[chk_i] = tmp;
	}
	for (j = chk_i + 1 ; j < n; j++) {
		tmp = p[j];
		p[j] = p[chk_i];
		p[chk_i] = tmp;
		chk = 1;
		for (i = 0; i < (n - 1); i++) {
			if (p[i] > p[i + 1]) {
				chk = 0;
				break;
			}
		}
		if(chk) {
			printf("YES\n");
			return 0;
		}
		tmp = p[j];
		p[j] = p[chk_i];
		p[chk_i] = tmp;
	}

	printf("NO\n");
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 537427207;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n,m;cin>>n>>m;
    vector<ip> s(n);
    vector<ip> c(m);
    rep(i,n)cin>>s[i].first>>s[i].second;
    rep(i,m)cin>>c[i].first>>c[i].second;
    rep(i,n){
        ll x = s[i].first, y = s[i].second;
        ll eans, mnt = INF;
        rep(j,m){
            ll p = c[j].first, q = c[j].second;
            if(mnt>abs(x-p)+abs(y-q)){eans = j; mnt = abs(x-p)+abs(y-q);}
        }
        cout<<eans+1<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
#include<algorithm>

using namespace std;

main()
{
    int a, b;
    string str;
    stack<int> s;
    while (cin >> str) {
        if ('+' == str[0]) {
            a = s.top();    s.pop();
            b = s.top();    s.pop();
            s.push(a + b);
        }
        else if ('-' == str[0]) {
            a = s.top();    s.pop();
            b = s.top();    s.pop();
            s.push(b - a);
        }
        else if ('*' == str[0]) {
            a = s.top();    s.pop();
            b = s.top();    s.pop();
            s.push(a * b);
        }
        else {
            s.push(atoi(str.c_str()));
        }
    }
    cout << s.top() << endl;

    return 0;
}

Measured memory_bytes: 3144
#include<vector>
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
#include<algorithm>
#include<random>
#include<map>
#include<set>
#include <bitset>

using namespace std;

//int mod = 998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<char>vc;
typedef vector<string>vs;
typedef vector<vector<int>>vvi;
typedef vector<vector<char>>vvc;
typedef vector<vector<ll>>vvl;
typedef vector< pair<ll, ll>>vpll;
typedef vector< pair<ld, ld>>vpld;
typedef vector< pair<int, int>>vpi;
typedef pair<ld, ld>pld;
#define mp make_pair
#define pb push_back

int mod=998244353;
int sum(int a, int b)
{
	int c = a + b;
	if (c >= mod)
	{
		c -= mod;
	}
	return c;
}
int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)
	{
		c += mod;
	}
	return c;
}
int mlt(int a, int b)
{
	ll c = a * 1LL * b;
	return c % mod;
}
int ibit(int n, int i)
{
	return ((n >> i) & 1);
}
void outp(vvi &ou)
{
	for (int i = 0; i < ou.size(); i++)
	{
		for (int j = 0; j < ou[i].size(); j++)
		{
			cout << ou[i][j] << ' ';
		}
		cout << '\n';
	}
}
int bp(int x, int y)
{
	if (y == 0)
	{
		return 1;
	}
	int a = 0;
	if (!(y % 2))
	{
		a = bp(x, y / 2);
	}
	return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a);
}
int obr(int x)
{
	return bp(x, mod - 2);
}
const int maxn = 10000007;
int fact[maxn], ofact[maxn];
void prec()
{
	fact[0] = 1;
	ofact[0] = 1;
	for (int i = 1; i < maxn; i++)
	{
		fact[i] = mlt(fact[i - 1], i);
	}
	//cerr << "sdsds" << endl;
	ofact[maxn - 1] = obr(fact[maxn - 1]);
	for (int i = maxn - 2; i > 0; i--)
	{
		ofact[i] = mlt(ofact[i + 1], i + 1);
	}
}
int c(int a, int b)
{
	return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0;
}
int dp3[maxn], dp2[maxn];
void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	dp3[0] = 1;
	dp2[0] = 1;
	for (int i = 1; i < maxn; i++)
	{
		dp2[i] = mlt(dp2[i - 1], 2);
		dp3[i] = mlt(dp3[i - 1], 3);
	}
	int n;
	cin >> n;
	int sum = dp3[n];
	for (int i = (n)/2+1; i <= n; i++)
	{
		int val = c(i, n);
		val = mlt(val, dp2[n - i]);
		val = mlt(val, 2);
		sum = dif(sum, val);
	}
	cout << sum << endl;
}
int main()
{
	prec();
	cerr << "Here" << endl;
	solve();
	int n;
	cin >> n;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

const ld eps = 1e-12;

int main() {
	int N, Q; cin >> N >> Q;
	vector<ll> X(N), Y(N), Z(N), R(N), L(N);
	for (int i = 0; i < N; ++i) {
		cin >> X[i] >> Y[i] >> Z[i] >> R[i] >> L[i];
	}
	for (int q = 0; q < Q; ++q) {
		ll sx, sy, sz, dx, dy, dz; cin >> sx >> sy >> sz >> dx >> dy >> dz;
		ll a = dx - sx, b = dy - sy, c = dz - sz;
		if (a == 0 && b == 0 && c == 0) cout << 0 << endl;
		else {
			ll ans = 0;
			for (int i = 0; i < N; ++i) {
				int d = a * X[i] + b * Y[i] + c * Z[i];
				ll den = a*a + b*b + c*c;
				ll t = d - a * sx - b * sy - c * sz; // t / den
				ll x = den * sx + a * t; // x / den
				ll y = den * sy + b * t;
				ll z = den * sz + c * t;
				ll xx = den*X[i]-x, yy = den*Y[i]-y, zz = den*Z[i]-z;
				if ( 0 < t && t < den ) {
					ll rr = xx*xx + yy*yy + zz*zz;
					if (rr <= den*den*R[i]*R[i]) {
						ans += L[i];
					}
				}
				else {
					ll rr = (X[i]-sx)*(X[i]-sx) + (Y[i]-sy)*(Y[i]-sy) + (Z[i]-sz)*(Z[i]-sz);
					rr = min(rr, (X[i]-dx)*(X[i]-dx) + (Y[i]-dy)*(Y[i]-dy) + (Z[i]-dz)*(Z[i]-dz));
					if (rr < R[i]*R[i]) {
						ans += L[i];
					}
				}
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 1204
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (-v[x] < -v[y]) swap(x, y);
			v[x] += v[y]; v[y] = x;
		}
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int n;

void foo(int k, int x, int y, map<i_i, int>& m, union_find& uf) {
	for (int d = 0; d < 4; d++) {
		int _x = x + dx[d], _y = y + dy[d];
		if (!m.count(i_i(_x, _y))) continue;
		int _k = m[i_i(_x, _y)];
		uf.unite(k, _k);
		uf.unite(k + n * 2, _k + n * 2);
	}
}

int main() {
	for (;;) {
		cin >> n;
		if (n == 0) break;
		vector<int> X(n), Y(n);
		vector<string> dir(n);
		for (int i = 0; i < n; i++)
			cin >> X[i] >> Y[i] >> dir[i];
		map<i_i, int> m;
		union_find uf(n * 4);
		for (int i = 0; i < n; i++) {
			int x = X[i], y = Y[i];
			int _x, _y;
			if (dir[i] == "x") {
				_x = x + 1; _y = y;
			}
			else {
				_x = x; _y = y + 1;
			}
			int k = i * 2, _k = k + 1;
			uf.unite(k, _k + n * 2);
			uf.unite(k + n * 2, _k);
			foo(k, x, y, m, uf);
			foo(_k, _x, _y, m, uf);
			m[i_i(x, y)] = k;
			m[i_i(_x, _y)] = _k;
		}
		bool flag = true;
		for (int i = 0; i < n; i++) {
			int k = i * 2, _k = k + 1;
			if (uf.same(k, k + n * 2) || uf.same(_k, _k + n * 2))
				flag = false;
		}
		cout << (flag ? "Yes" : "No") << endl;
	}
}

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

namespace fastIO {
  #define BUF_SIZE 100000
  // fread -> read
  bool IOerror = 0;
  inline char nc() {
    static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
    if(p1 == pend) {
      p1 = buf;
      pend = buf + fread(buf, 1, BUF_SIZE, stdin);
      if(pend == p1) {
        IOerror = true;
        return -1;
      }
    }
    return *p1++;
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  inline void read(int &x) {
    char ch;
    while(blank(ch = nc()));
    if(IOerror) { x = -1; return ; }
    for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
  }
  #undef BUF_SIZE
};
using namespace fastIO;

using namespace std;
#define mp make_pair
#define pb push_back
#define debug(__, x) cerr << "Case #" << ++__ << ": " << x << endl
#define Debug(__, x, y) cerr << "Case #" << ++__ << ": " << x << " " << y << endl

typedef set<int, greater<int> > gset;
typedef set<int, greater<int> >::iterator gsetit;
typedef multiset<pair<int, int>, greater<pair<int, int> > > gpmset;
typedef multiset<pair<int, int>, greater<pair<int, int> > >::iterator gpmsetit;


int __ = 0;
const int inf = 0x3f3f3f3f;
const int Inf = INT_MAX;
const long long INF = LONG_LONG_MAX;
const long long mod = 1000000007;
// 欧拉常数, 调和级数求和 sigma(h_n) = GAMA + ln(n)
const double GAMA = 0.57721566490153286060651209; 
const double PI   = 3.14159265358979323846264338;

long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long quickPow(long long a, long long p, long long mod) {
  long long pro = 1LL;
  a %= mod;
  while(p) {
    if(p & 1) { pro = pro * a % mod; }
    a = a * a % mod;  p >>= 1;
  }
  return pro;
}

double fquickPow(double a, int p) {
  double pro = 1.0;
  while(p) {
    if(p & 1) {
      pro = pro * a;
    }
    a = a * a;
    p >>= 1;
  }
  return pro;
}

int main() {
  #ifdef Zonda_R
    freopen("data.in", "r", stdin);   // Windows 下最好用 "in.txt", "out.txt"
    freopen("data.out", "w", stdout);
  #endif
  long long  q, h, s, d, n;
  scanf("%lld %lld %lld %lld %lld", &q, &h, &s, &d, &n);
  long long ans = 0;
  long long t1 = min(s, min(2LL * h, 4LL * q));
  long long t2 = min(d, min(2LL * s, min(4LL * h, 8LL * q)));
  long long t = n / 2;
  ans += t * t2;
  if(n & 1) ans += t1;
  printf("%lld\n", min(ans, n * t1));
  // cerr << "Time Consumption: " << fixed << setprecision(6) << (double)clock() / CLOCKS_PER_SEC << " s." << endl;
  return 0;
}

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

vector<int> as;
set<int> seen;
int m = 0;

bool go(int K) {
    if (seen.count(K))
        return false;
    if (K == 0)
        return true;
    if (K > m)
        return false;
    seen.insert(K);
    for (int a : as) {
        if (go(abs(K - a)))
            return true;
    }
    return false;
}

signed main() {
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i], m = max(m, as[i]);
        if (K == as[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    if (K > m) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    unordered_set<int> diffs;
    for (int a : as) {
        diffs.insert(abs(a - K));
    }
    int t = 0;
    for (int a : as) {
        t = abs(t - a);
        if (diffs.count(t) || t == K) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


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

int main(void){
    long long n,a,b;
    cin >> n >> a >> b;
    
    long long sum = 0;
    if(a % 2 == b % 2)sum = (b-a)/2;
    else {
        sum = min(a-1,n-b)+((b-a-1)/2)+1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int solve(int n,int p){
	int* player=(int*)malloc(sizeof(int)*n);
	int wan=p;
	int i;
	memset(player,0,sizeof(int)*n);
	while(1){
		for(i=0;i<n;i++){
			int q;
			if(wan==0){
				wan=player[i];
				player[i]=0;
			}
			else {
				wan--;
				player[i]++;
				if(wan==0){
					int j,w=0;
					for(j=0;j<n;j++){
						if(i!=j){
							if(player[j]!=0){
								w=1;
							}
						}
					}
					if(w==0){
						return i;
					}
				}
			}
//			for(q=0;q<n;q++){
//				printf("%d ",player[q]);
//			}
//			puts("");
		}
		
	}
}

int main(){
	int n,p;
	while(1){
		scanf("%d %d",&n,&p);
		if(n==0&&p==0)break;
		printf("%d\n",solve(n,p));
	}
	return 0;
}

Measured memory_bytes: 460
#include "bits/stdc++.h"
#define allr(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define sp " "
#define double long double
#define pb push_back
#define ff first
#define int long long
#define ss second
#define vi vector<int>
#define mem(ara, a) memset(ara, a, sizeof(ara))
#define bruh freopen("bruh.txt", "r", stdin)
#define fo freopen("output.txt", "w", stdout)
#define pii pair<int, int>

long long inf = 2e18;
long long minf = -inf;

using namespace std;

signed main() {

#ifndef ONLINE_JUDGE
//	freopen("bruh.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n , k;
	cin >> n >> k;
	int ans = 0;
	while (n >0) {
		n /= k;
		ans++;
	}
	cout<<ans<<endl;



}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(),a.end(),0LL)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    ll n, m; cin >> n >> m;
    vector<ll> p(m), y(m);
    rep(i,m) cin >> p[i] >> y[i];

    map<pair<ll,ll>,ll> mp;
    for(int i = 0; i < m; i++){
        mp[make_pair(p[i],y[i])];
    }

    vector<ll> cnt(n,0);
    for(auto x:mp){
        cnt[x.first.first-1]++;
        mp[x.first] = cnt[x.first.first-1];
        //cout << x.first.first << " " << x.first.second << " " << x.second << endl;
    }

    for(int i = 0; i < m; i++){
        cout << setfill('0') << right << setw(6) << p[i];
        cout << setfill('0') << right << setw(6) << mp[make_pair(p[i], y[i])] << endl;
    }

    //for(auto x:mp) cout << x.first.first << " " << x.first.second << " " << x.second << endl;
    //for(auto x:cnt) cout << x << " "; cout << endl;
}

Measured memory_bytes: 11952
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

string a, b, c;

char slv(char now)
{
  string &p = (now == 'A') ? a : (now == 'B')? b : c;
  if (p.empty()) {
    return now;
  } else {
    char c = toupper(p.back());
    p.pop_back();
    return slv(c);
  }
}

signed main()
{
  cin >> a >> b >> c;
  reverse(ALL(a));
  reverse(ALL(b));
  reverse(ALL(c));

  cout << slv('A') << endl;

  return 0;
}



Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8')

const N: string = input.split('\n')[0]

const first = Number(N[0] + N[1])
const last = Number(N[2] + N[3])

if (first > 12 || first === 0) {
  if (last > 12 || last === 0) {
    console.log('NA')
  } else {
    console.log('YYMM')
  }
} else if (last > 12 || last === 0) {
  if (first === 0) {
    console.log('NA')
  } else {
    console.log('MMYY')
  }
} else if (first === 0 && last === 0) {
  console.log('NA')
} else {
  console.log('AMBIGUOUS')
}

Measured memory_bytes: 7372
W, H, x, y = map(int, input().split())

def calculate(W, H, x, y):
	way = 0
	area = W*H/2.0
	if(x==W/2 and y==H/2):
		way = 1
	return area, way

area, way = calculate(W, H, x, y)

print("%f %d" % (area, way))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main() {
    int N; cin>>N;
    int H[N];
    REP(i,N){
        cin>>H[i];
    }
    int ans=0;
    int tmp=0;
    for(int i=1;i<N;i++){
        if(H[i-1]>=H[i]){
            tmp++;
            ans=max({tmp,ans});
        }else{
            tmp=0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

static const int INF=100000000;
int main(void){
    int N,M;
    cin >> N >> M;
    vector<int> A(M);
    vector<int> B(M);
    vector<vector<int>> from(N,vector<int>());
    
    for(int i=0;i<M;i++){
        cin >> A.at(i) >> B.at(i);
        from.at(A.at(i)-1).push_back(B.at(i)-1);
        from.at(B.at(i)-1).push_back(A.at(i)-1);
    }
    
    vector<int> distance(N,INF);
    vector<int> whereisnext(N,-1);
    vector<bool> isgone(N,false);
    distance.at(0)=0;
    isgone.at(0)=true;
    int enternumber=1;
    
    queue<int> que;
    que.push(0);
    que.push(-1);
    int crtdist=1;
    
    while(que.front()!=-1){
        while(que.front()!=-1){
            int crt=que.front();
            for(int i=0;i<from.at(crt).size();i++){
                if(!isgone.at(from.at(crt).at(i))){
                    whereisnext.at(from.at(crt).at(i))=crt;
                    que.push(from.at(crt).at(i));
                    isgone.at(from.at(crt).at(i))=true;
                }
                if(distance.at(from.at(crt).at(i))>crtdist){
                    distance.at(from.at(crt).at(i))=crtdist;
                    enternumber++;
                }
            }
            que.pop();
        }
        que.pop();
        crtdist++;
        que.push(-1);
    }
    
    for(int i=1;i<N;i++){
        if(whereisnext.at(i)==-1){
            cout << "No" << endl;
            return 0;
        }
    }
    
    /*for(int i=0;i<N;i++){
        for(int j=0;j<from.at(i).size();j++){
            cout << from.at(i).at(j) << " " ;
        }
        cout << endl;
    }
    cout << "----------------" << endl;
    for(int i=0;i<N;i++){
        cout << distance.at(i) << endl;
    }
    cout << "----------------" << endl;*/
    cout << "Yes" << endl;
    for(int i=1;i<N;i++){
        cout << whereisnext.at(i)+1 << endl;
    }
}


Measured memory_bytes: 12168
k, n = map(int, input().split())

a = list(map(int, input().split()))

ans = []

diss = []
suma = 0

for i in range(len(a)-1):
    dis = a[i+1] - a[i]
    diss.append(dis)


diss.append(k-a[-1]+a[0])
diss.pop(diss.index(max(diss)))
print(sum(diss))


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

typedef long long int ll;

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

int main()
{
     fast;
	float r;
	float pi = 3.141592653;
    cin>>r;
  	cout<<2*pi*r<<endl;
     return 0;
}


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,,] personNumArray = new int[4, 3, 10];

            int infoNum;
            infoNum = int.Parse(Console.ReadLine());

            List<string> inputInfoList = new List<string>();

            for(int n=0; n<infoNum; n++)
            {
                inputInfoList.Add(Console.ReadLine());
            }

            foreach(var info in inputInfoList)
            {
                int[] inputInfoAarray = info.Split(' ').Select(int.Parse).ToArray();
                personNumArray[inputInfoAarray[0] - 1, inputInfoAarray[1] - 1, inputInfoAarray[2] - 1] += inputInfoAarray[3];
            }

            for(int b=0; b<4; b++)
            {
                for(int f=0; f<3; f++)
                {
                    for(int r=0; r<10; r++)
                    {
                        Console.Write(" " + personNumArray[b, f, r]);
                    }
                    Console.Write("\r\n");
                }
                if(b == 3)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("####################");
                }
                
            }

            Console.ReadKey();
        }
    }
}



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

int main(){
  int n;
  cin >> n;
  if(n < 10){
    cout << n;
  }
  else if(10 <= n&& 100 > n){
    cout << "9";
  }
  else if(100 <= n&& 1000 > n){
    cout << n - 100 + 1 + 9;
  }
  else if(1000 <= n&& 10000 > n){
    cout << "909";
  }
  else if(10000 <= n&& 100000 > n){
    cout << n - 10000 + 1 + 909;
  }
  else if(n == 100000){
    cout << 90909;
  }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

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

  string s;
  getline(cin, s);
  int n = SZ(s);
  REP(i,n){
    if(0 <= s[i]-'a' && s[i]-'a' < 26) cout << (char)(s[i] - 'a' + 'A');
    else if(0 <= s[i]-'A' && s[i]-'A' < 26) cout << (char)(s[i] - 'A' + 'a');
    else cout << s[i];
  }
  cout <<endl;



  return 0;
}



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

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');

            int n = int.Parse(word[0]);

            int x;

            x = (1 + n) * n / 2;

            Console.WriteLine(x);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>A(N);
    vector<int>B(N);
    rep(i, N) {
        cin >> A[i];
        B[A[i]-1] = i;
    }
    cout << B[0]+1;
    REP(i, N) cout <<" "<< B[i]+1;
    cout << endl;
}

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

int main(int argc, char *argv[])
{
  int a, b;
  cin >> a >> b;
  cout << a / b << " "  << a % b << " " << fixed << setprecision(12) << (double)a/b << endl;

  return 0;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<long, long>;

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

struct compare1 { 
    bool operator()(const pair<long, long>& value,  
                                const long& key) 
    { 
        return (value.first < key); 
    } 
    bool operator()(const long& key,  
                    const pair<long, long>& value) 
    { 
        return (key < value.first); 
    } 
}; 

int main()
{
    int K, N; cin >> K >> N;
    int A[200005];
    REP(i, N) cin >> A[i];
    int ans = 5000000;
    REP(i, N){
        if(i == 0)
            ans = min(ans, min(A[N-1] - A[0], K - A[1] + A[0]));
        else if(i == N-1)
            ans = min(ans, min(K - A[N-1] + A[N-2], A[N-1] - A[0]));
        else
            ans = min(ans, min(K - A[i] + A[i-1], K - A[i+1] + A[i]));
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 1024
x, n = map(int,input().split())
P = list(map(int,input().split()))
Q = []
ans = 100
for i in range(-100,101):
    if i+1 in P:continue
    else:
        Q.append(i+1)
for j in Q:
    d = abs(j - x)
    ans = min(d, ans)

l = x -ans
m = x + ans
if l in Q:
    print(l)
else:
    print(m)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(i%2 == 0)  cout << s.at(i);
    else if(i%2 == 1) continue;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
using namespace std;
int main(){
  int n,count=0;
  cin>>n;
  vector<int>p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  for(int i=0;i<n;i++){
    if(p[i]!=i+1) count++;
    }

    if(count==2) cout<<"YES";
    else if(count==0) cout<<"YES";
    else if(count!=2){
      if(count!=0) cout<<"NO";
    }
}


Measured memory_bytes: 256