akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n, ans = 0;
    string s;
    cin >> n >> s;
    vector<vector<int> > dp(n+1, vector<int>(n+1,0));
    for(int i=0;i<n;i++){
        for(int j=0;i+j<n;j++){
            if(s[j] == s[i+j]){
                dp[i][j+1] = dp[i][j] + 1;
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=n;j++){
            ans = max(ans, min(i,dp[i][j]));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 98816
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	int N;
	cin >> N;
	vector<lli>v(N);
	map<lli, lli>m;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		m[v[i]]++;
	}
	sort(v.rbegin(), v.rend());
	lli ansA = 0,ansB = 0;
	for (int i = 0; i < N; i++) {
		if (m[v[i]] >= 2) {
			if (ansA == 0) {
				ansA = v[i];
				m[v[i]] -= 2;
			}
			else{
				ansB = v[i];
				break;
			}
		}
	}
	cout << ansA * ansB << endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    V<> a(n+2);
    a[0] = a[n+1] = 0;
    for(int i = 1; i <= n; i++) cin >> a[i];
    ll sum = 0;
    for(int i = 0; i < n + 1; i++) {
        sum += abs(a[i] - a[i + 1]);
    }
    for(int i = 1; i <= n; i++) {
        ll ans = sum;
        ans -= abs(a[i - 1] - a[i]);
        ans -= abs(a[i + 1] - a[i]);
        ans += abs(a[i - 1] - a[i + 1]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    string s,t;
    cin>>s>>t;
    ll ans = 0;
    REP(i,s.size()){
        if (s[i] != t[i]){
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3912
#include <algorithm>
    #include <bits/stdc++.h>
    #include <cctype>
    #include <cmath>
    #include <cstdio>
    #include <iomanip>
    #include <iostream>
    #include <list>

    #include <stack>
    #include <string>
    #include <vector>
    #include <bits/stdc++.h>
    #define INFINI (1000 * 1000 * 1000)

    using namespace std;
    //#define s(T) scanf("%d", &T)
    #define sl(T) scanf("%lld", &T)
    #define fill(a, val) memset(a, val, sizeof(a))
    #define mp make_pair
    #define pb push_back
    #define all(x) x.begin(), x.end()
    #define DREP(x) sort(all(x)); x.erase(unique(all(x)), x.end())
    #define INDEX(a, val) (lower_bound(all(a), val) - a.begin())
    #define mod ll(1e9+7)
    typedef long long ll;


    bool compare_first(pair<ll,ll >a,pair<ll,ll >b)
    {
        return a.first<b.first;
    }

     bool compare_second(pair<int,pair<int , int> > a,pair<int,pair<int , int> > b)
    {
        return a.second.first<b.second.first;
    }


    ll min(ll a,ll b)
    {
        if(a>b)return b;
        return a;
    }


    int main() {
      ios::sync_with_stdio(false);


 int n,l;
 cin>>n>>l;
 string s[n];
 for(int index=0;index<n;index++)
    cin>>s[index];

 sort(s,s+n);
 for(int index=0;index<n;index++)
    cout<<s[index];
    cout<<endl;

return 0;
    }


/*

 }
 */


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int c0=0,c1=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0')c0++;
        else c1++;
    }
    if(c1==0||c0==0){
        cout<<0<<endl;
    }
    else if(c1==c0){
        cout<<c1*2<<endl;
    }else cout<<min(c1,c0)*2<<endl;
    
}


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

string a,b;

int main(){
  cin>>a>>b;
  int al=a.length(),bl=b.length();
  if(al>bl) printf("GREATER");
  else if(al<bl) printf("LESS");
  else{
    if(a>b) printf("GREATER");
    else if(a<b) printf("LESS");
    else printf("EQUAL");
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
map<int, char>mp;
int nxt[202020];
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
 
	string S;
	cin >> S;
	int Q;
	cin >> Q;
 
	int tp = -1;
	int bk = -2;
	int cnt = 0;
	for (int i = 0; i < Q; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			swap(tp, bk);
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			mp[cnt] = c;
			if (f == 1) { nxt[cnt] = tp; tp = cnt; }
			else { nxt[cnt] = bk; bk = cnt; }
			cnt++;
		}
	}
 
	int fl = 0;
	string s1, s2;
	while (1) {
		if (tp < 0) {
			if (tp == -2)fl = 1;
			break;
		}
		s1.pb(mp[tp]);
		tp = nxt[tp];
	}
	while (1) {
		if (bk < 0)break;
		s2.pb(mp[bk]);
		bk = nxt[bk];
	}
	string ans;
	ans += s1;
	if(fl == 1)reverse(all(S));
	ans += S;
	reverse(all(s2));
	ans += s2;
	puts(ans);
 
	return 0;
}

Measured memory_bytes: 11440
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int N; cin >> N;
  int odd_cnt = 0;
  rep(i,N) {
    int a; cin >> a;
    if(a%2==1)odd_cnt++;
  }

  bool can = odd_cnt%2 != 1;

  if(can)cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    int M = 1 << N;
    vector<vector<int>> dp(M, vector<int>(51, INF));
    dp[0][0] = 0;
    rep(bit, M) {
        // 何枚使ったか
        int cnt = 0;
        rep(i, N) {
            if (bit >> i & 1) cnt++;
        }

        // 残っているカード
        vector<P> card;
        int ni = cnt;
        rep(i, N) {
            if (!(bit >> i & 1)) {
                card.emplace_back(i, ni++);
            }
        }

        for (P p : card) {
            int oi = p.first, ni = p.second;

            rep(s, 51) {
                if (dp[bit][s] == INF) continue;

                if (oi % 2 == cnt % 2 && s <= A[oi]) {
                    dp[ bit | (1 << oi) ][ A[oi] ] = min(dp[ bit | (1 << oi) ][ A[oi] ], dp[bit][s] + ni - cnt);
                } else if (oi % 2 != cnt % 2 && s <= B[oi]) {
                    dp[ bit | (1 << oi) ][ B[oi] ] = min(dp[ bit | (1 << oi) ][ B[oi] ], dp[bit][s] + ni - cnt);
                }
            }
        }
    }

    int ans = INF;
    rep(i, 51) {
        ans = min(ans, dp[(1 << N) - 1][i]);
    }
    if (ans != INF) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 63872
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from heapq import*\n"
"I=lambda:list(map(int,input().split()))[::-1]\n"
"k,n=I()\n"
"q=[]\n"
"v=i=T=A=0\n"
"l=[0]*-~n\n"
"for b,a in sorted(I()for _ in[0]*n)[::-1]:\n"
" if i<k:\n"
"  if l[a]:heappush(q,b)\n"
"  else:T+=v*2+1;v+=1\n"
"  T+=b\n"
" elif l[a]^1and q:T+=b+v*2+1-heappop(q);v+=1\n"
" A=max(A,T);i+=1;l[a]=1\n"
"print(A)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 21996
n,a,b=map(int,input().split())
if n==1:
    if a==b:
        print(1)
        exit()
    else:
        print(0)
        exit()
if a>b:
    print(0)
    exit()
mini=a+b+(n-2)*a
maxi=a+b+(n-2)*b
print(maxi-mini+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

static const int MX = 100005;

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

  pair<bool,int> solve[MX]; //ACflag, WAカウンタ
  REP(i,MX) solve[i].first = false;

  REP(i,m){
    int p;
    string s;
    cin >> p >> s;
    if(s == "AC"){
      solve[p].first = true;
    }
    else{
      if(solve[p].first != true) ++solve[p].second;
    }
  }

  int ac = 0;
  int wa = 0;
  REP(i,MX){
    if(solve[i].first == true){
      ++ac;
      wa += solve[i].second;
    }
  }


  cout << ac << " " << wa << endl;
  return 0;
}

Measured memory_bytes: 4396
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	for(int i=0; i<n; i++){
		cin >> p[i];
	}
	int count=0;
	for(int i=1; i<n-1; i++){
		if(p[i-1]<p[i]){
			if(p[i]<p[i+1])count++;
		}
		else if(p[i-1]>p[i]){
			if(p[i]>p[i+1])count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    int v[4] = {s[0] - '0', s[1] - '0', s[2] - '0', s[3] - '0'};

    uint_fast8_t b;
    for (b = 0; b <= static_cast<uint_fast8_t>(0b111); ++b) {
        int a = v[0];
        for (int i = 1; i < 4; ++i) {
            if (b & static_cast<uint_fast8_t>(1U << (i - 1)))
                a -=  v[i];
            else
                a += v[i];
        }

        if(a == 7)
            break;
    }

    cout << v[0] << ((b & static_cast<uint_fast8_t>(0b1)) ? '-' : '+')
            << v[1] << ((b & static_cast<uint_fast8_t>(0b10)) ? '-' : '+')
            << v[2] << ((b & static_cast<uint_fast8_t>(0b100)) ? '-' : '+')
            << v[3] << "=7" << endl;

    return 0;
}


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

#define pi                            acos(-1.0)
#define fastio                        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout << setprecision(12)
#define rep(i,a,n)                    for (ll i=a;i<n;i++)
#define per(i,a,n)                    for (ll i=n-1;i>=a;i--)
#define pb                            push_back
#define all(x)                        (x).begin(),(x).end()
#define fi                            first
#define se                            second
#define SZ(x)                         ((ll)(x).size())
#define cin1(x)                       cin >> x
#define cin2(x, y)                    cin >> x >> y
#define cin3(x, y, z)                 cin >> x >> y >> z
#define cin4(x, y, z, _)              cin >> x >> y >> z >> _
#define cin5(x, y, z, p, q)           cin >> x >> y >> z >> p >> q
#define cin6(x, y, z, p, q, r)        cin >> x >> y >> z >> p >> q >> r
#define cou(x)                        cout << x
#define cous(x)                       cout << x << " "
#define coul(x)                       cout << x << "\n"
#define ret(x)                        return x
#define MAX                           1000007
#define start                         int main() {   fastio
#define finish                        ret(0); }
#define Test                          ll _t; cin1(_t); rep(w, 0, _t)
#define fans(x)                       if ( x  ) coul("YES");  else coul("NO")


typedef long long ll;
const ll mod=1000000007;
const ll mx = 3e5 + 7;
const double eps = 1e-7;

// head collected
// Don't use variable name as --> prev, time, _t, w, y1
// Don't use ceil and pow function


ll n, a, b, _, ans, c, _1, _2, m, an, k, need, shuru, _3, _c, _a, _b, way, _0, mex, q;
double d;
ll ar[ mx ], co[ mx ];
string st, st1, st2, isGood;
vector < pair < ll, ll > > vs;
map < string, ll > mm;
set < string > ss;
pair < ll, ll > pr;
bool ok;
char ch;
vector <ll> sie;
ll spf[ MAX + 7 ];
ll prime[ MAX ], ultraPrime[ MAX ], sumOfPrimeArray[ MAX ];



void helpPlz( )
{
    cin3( a, b, c );

    coul( b / c - ( a - 1 ) / c );
}


start;         // Md. Inzamam-ul Haque

    helpPlz();


finish






Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<cstring> 
using namespace std;
char s[100010];
int main ()
{
	int i,n,ans;
	scanf("%s",s);
	n=strlen(s);
	ans=n;
	for(i=1;i<n;++i)
	  if(s[i-1]!=s[i]) ans=min(ans,max(i,n-i));
	printf("%d",ans);
}

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

int main(){
    int N;cin>>N;
    long long  a[N];
    for(int i=0;i<N;i++) cin>>a[i];
    
    map<int,long long> b;
    int j=1;
    for(int i=2;i<1000000000;i*=2){
        b[j] = i;
        j++;
    }
    

    // cout<<b[N] << ' '<<(*b.end())<<endl;
	
    // for(auto it=b.rbegin();it!=b.rend();it++){
    //     cout<< it->first <<' ';
    //     cout<< it->second <<endl;
    // }
    int ans=0;
    // for(int i=0;i<N;i++){
    //     for(auto it=b.end();it!=b.begin();it--){
    //         if(a[i] >= it->second){
    //             ans+=(it->first);
    //             a[i] /= (it->second);
    //             if(a[i] %2 == 1) break;
    //             while(a[i]>=2 && a[i]%2==0 ){
    //                 a[i]/=2;
    //                 ans++;
    //             }
    //         }
    //     }
    // }

    // for(auto it = b.end();it!=b.begin();it--){
    //     for(int i=0;i<N;i++){
    //         if((it->second) <= a[i] && a[i]%2 == 0 ){
    //             ans+=it->first;
    //             cout<<(*it)<<' '<<ans<<endl;
    //             a[i]/=2;
    //         }    
    //     }
    // }
    for(auto i=b.rbegin();i!=b.rend();i++){
        for(int j=0;j<N;j++){
            if( a[j] >= (i->second) && a[j] % (i->second) ==0 ){
                ans += i->first;
                a[j] /= i->second;
            }
        }
        // cout << ans<<' ';
    }
    // cout<<endl;
    

    // cout<<(*b.first())<<endl;

    cout<<ans<<endl;
    return 0;
}

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

int main(){
	int n,i,a,j,b;
	string digit[10] = { "0111111","0000110","1011011","1001111","1100110","1101101","1111101","0100111","1111111","1101111" },str;
	while(1){
		str == "";
		cin >> n;
		if(n == -1) break;
		for(i = 0;i < n;++i){
			cin >> a;
			if(i == 0){
				cout << digit[a];
				str = digit[a];
			}
			else {
				for(j = 0;j < 7;++j){
					b = (int)(digit[a][j] - str[j]);
					if(b < 0) b *= -1;
					cout << b;
				}
				str = digit[a];
			}
			cout << "\n";
		}
	}
	return 0;
}

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

using namespace std;

int main(void){
	string word, str;
	int count = 0;

	cin >> word;
	transform(word.begin(), word.end(), word.begin(), ::tolower);
	while (cin >> str) {
		transform(str.begin(), str.end(), str.begin(), ::tolower);
		if (str == word) {
			count++;
		}
	}

	cout << count << "\n";
	return 0;
}

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

int gcd(int p, int q){
    if(p%q == 0) return q;
    return gcd(q,p%q);
}

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

    int G = 0;
    for(int a=1;a<=K;a++){
        for(int b=1;b<=K;b++){
            for(int c=1;c<=K;c++){
                G += gcd(gcd(a,b),c);
            }
        }
    }

    cout << G << endl;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    int minv = n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        minv = min(minv, a);
        if (a == minv) ans++;
    }
    cout << ans << "\n";
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

template <class T, class Op>
class SegmentTree {
private:
    const Op op;
    const T id;
    std::vector<T> vec;
    int sz;

public:
    explicit SegmentTree(int n, Op op, T id) noexcept
        : op(op), id(id) {
        sz = 1;
        while (sz < n) sz <<= 1;
        vec.assign(sz * 2, id);
    }
    explicit SegmentTree(const std::vector<T>& vec, Op op, T id) noexcept
        : op(op), id(id) {
        int n = vec.size();
        sz = 1;
        while (sz < n) sz <<= 1;
        vec.assign(sz * 2, id);
        set_array(vec);
    }

    void set_value(int idx, T val) noexcept {
        vec[idx + sz] = val;
    }

    template <class RandomIt>
    void set_array(RandomIt _begin, RandomIt _end) noexcept {
        std::copy(_begin, _end, vec.begin() + sz);
    }
    void set_array(const std::vector<T>& vec) noexcept {
        set_array(vec.begin(), vec.end());
    }

    void build() noexcept {
        for (int i = sz - 1; i > 0; i--) {
            vec[i] = op(vec[i * 2], vec[i * 2 + 1]);
        }
    }

    void update(int idx, T val) noexcept {
        idx += sz;
        vec[idx] = val;
        for (idx >>= 1; idx > 0; idx >>= 1) {
            vec[idx] = op(vec[idx * 2], vec[idx * 2 + 1]);
        }
    }

    // Query [l, r)
    T query(int l, int r) const noexcept {
        T l_val = id, r_val = id;
        l += sz, r += sz - 1;
        for (; l <= r; l >>= 1, r >>= 1) {
            if (l & 1) l_val = op(l_val, vec[l++]);
            if (!(r & 1)) r_val = op(r_val, vec[r--]);
        }
        return op(l_val, r_val);
    }

    const T& operator[](int idx) const noexcept {
        return vec[idx + sz];
    }

    void reset() noexcept {
        std::fill(vec.begin(), vec.end(), id);
    }
};

void solve() {
    ll N, Q;
    cin >> N >> Q;
    auto op = [](int a, int b) { return a + b; };
    SegmentTree<ll, decltype(op)> seg(N, op, 0ll);
    while (Q--) {
        int mode;
        cin >> mode;
        if (mode == 0) {
            ll x, y;
            cin >> x >> y;
            --x;
            seg.update(x, seg[x] + y);
        }
        else if (mode == 1) {
            ll x, y;
            cin >> x >> y;
            --x, --y;
            cout << seg.query(x, y + 1) << "\n";
        }
        else {
            seg.reset();
        }
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 4944
n = gets.to_i
task = []
n.times do
  task << gets.split.map(&:to_i)
end
task.sort_by!{|a| [a[1],a[0]]}

t = 0
flg = true
task.each do |a,b|
  t += a
  if t > b
    flg = false
    break
  end
end

puts flg ? "Yes" : "No" 

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

int main() {
  int A, B, C; cin >> A >> B >> C;
  int count = 0;

  if (A == B) {
    count++;
  }
  if (A == C) {
    count++;
  }
  if (B == C) {
    count++;
  }

  if (count == 1) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
        int[] input = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray();

        int i = 0;
        while (i < 10000)
        {
            if ((input[0] * i - input[2]) % input[1] == 0) {
                Console.WriteLine("YES");
                return;
            }
            i++;
        }

        Console.WriteLine("NO");
	}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> A(3);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[a-1]++;
  }
  vector<vector<vector<long double>>> B(N+2,vector<vector<long double>>(N+2,vector<long double>(N+2,0)));
  B[0][0][0]=0;
  for(int k=0;k<=N;k++){
    for(int j=0;j<=N;j++){
      for(int i=0;i<=N;i++){
        if(i)B[i][j][k]+=B[i-1][j][k]*i;
        if(j)B[i][j][k]+=B[i+1][j-1][k]*j;
        if(k)B[i][j][k]+=B[i][j+1][k-1]*k;
        if(i+j+k)B[i][j][k]=(B[i][j][k]+N)/(i+j+k);
      }
    }
  }
  cout<<fixed<<setprecision(16)<<B[A[0]][A[1]][A[2]]<<endl;
}

Measured memory_bytes: 438572
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  if(a+b>=10){
    cout << "error" << endl;
  }else{
    cout << a+b << endl;
  }
  return 0;
}


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

using namespace std;

int upcmp(const void *p,const void *q){
    return *(int*)p-*(int*)q;
}

int downcmp(const void *p,const void *q){
  return *(int*)q-*(int*)p;
}

int main(void){
  int N,check=0;
  cin >> N;
  int H[N];
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  for(int i=N-1;i>0;i--){
    if(H[i-1]>H[i]+1){
      cout << "No" << endl;
      check=1;
      break;
    }
    else if(H[i-1]>H[i]){
      H[i-1]--;
    }
  }
  if(check==0){
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] heap = new int[n];
        for(int i = 0; i < n; i++) {
            heap[i] = input.nextInt();
        }
        for(int i = 0; i < n; i++) {
            print(i+1, heap);
            System.out.println();
        }
    }

    public static void print(int node, int[] heap) {
        System.out.print("node " + node + ": key = " + heap[node-1] + ", ");
        if(Math.floor(node/2) != 0) {
            System.out.print("parent key = " + heap[(int)Math.floor(node/2)-1] + ", ");
        }
        if(2 * node <= heap.length) {
            System.out.print("left key = " + heap[2*node-1] + ", ");
        }
        if(2 * node + 1 <= heap.length) {
            System.out.print("right key = " + heap[2*node] + ", ");
        }
    }
}



Measured memory_bytes: 26996
# ABC141D - Powerful Discount Tickets
from heapq import heapify, heappop, heappush


def main():
    N, M, *A = map(int, open(0).read().split())
    H = [-i for i in A]
    heapify(H)
    replace = lambda: heappush(H, -(-heappop(H) // 2))
    for _ in range(M):
        replace()
    ans = -sum(H)
    print(ans)


if __name__ == "__main__":
    main()

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


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

	if ((a == (b+c)) || (b == (a+c)) || (c == (a+b))) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
dp = [[float("inf")]*w for _ in range(h)]
if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for i in range(h):
    for j in range(w):
        if i+1 < h:
            count1 = dp[i][j]
            if s[i][j] == "." and s[i+1][j] == "#":
                count1 += 1
            dp[i+1][j] = min(dp[i+1][j], count1)
        if j+1 < w:
            count2 = dp[i][j]
            if s[i][j] == "." and s[i][j+1] == "#":
                count2 += 1
            dp[i][j+1] = min(dp[i][j+1], count2)
print(dp[h-1][w-1])


Measured memory_bytes: 43248
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;

int k, x;

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    read(k), read(x);
    if (k * 500 >= x) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
int32_t main(){
    IOS;
    ll i,j,k,a,b,c, cnt=0;
    cin >> a >> b >> c >> k;
    while(a>=b) {
        cnt++;
        b *= 2;
    }  
    while(b>=c){
        cnt++;
        c *= 2;
    }
    if(cnt<=k) cout <<"Yes\n";
    else cout <<"No\n";
} 

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

void Main() {
    // input
    string s;
    cin >> s;


    // translate
    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '1') {
            ans++;
        }
    }


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

//Restaurant
public class Main{

	class R implements Comparable<R>{
		int oid, id;
		public R(int oid, int id) {
			this.oid = oid;
			this.id = id;
		}
		public int compareTo(R o) {
			return oid!=o.oid?oid-o.oid:p[id]!=p[o.id]?p[o.id]-p[id]:id-o.id;
		}
	}

	int n, m;
	int[] p, limit, T, K, res;
	Map<String, Integer> ref;
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		for(boolean head = true;;head = false){
			n = sc.nextInt(); m = sc.nextInt();
			if((n|m)==0)break;
			if(!head)System.out.println();
			ref = new HashMap<String, Integer>();
			limit = new int[n];
			p = new int[n];
			T = new int[m];
			K = new int[m];
			for(int i=0;i<n;i++){
				ref.put(sc.next(), i);
				limit[i] = sc.nextInt();
				p[i] = sc.nextInt();
			}
			List<R>[] l = new List[m];
			for(int i=0;i<m;i++){
				l[i] = new ArrayList<R>();
				T[i] = sc.nextInt();
				K[i] = sc.nextInt();
				for(int j=0;j<K[i];j++)l[i].add(new R(i, ref.get(sc.next())));
			}
			res = new int[m];
			int f = 0, t = 0;
			LinkedList<R> list = new LinkedList<R>();
			while(f<m||!list.isEmpty()){
				while(f<m&&T[f]<=t){
					list.addAll(l[f++]);
				}
				if(list.isEmpty()&&f<m){
					t = T[f]; list.addAll(l[f++]);
				}
				Collections.sort(list);
				R r = list.get(0);
				t += p[r.id];
				int L = limit[r.id];
				for(int i=0;i<list.size()&&0<L;i++){
					R d = list.get(i);
					if(d.id!=r.id)continue;
					--L;
					if(--K[d.oid]==0)res[d.oid] = t;
					list.remove(i--);
				}
			}
			for(int r:res)System.out.println(r);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main(){
    int a, b, c, k, cnt=0;
    cin >> a >> b >> c >> k;

    while(a>=b){
        b *= 2;
        cnt++;
    }

    while(b>=c){
        c *= 2;
        cnt++;
    }

    if(a<b && b<c && cnt<=k){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int inf = 1e9;
typedef pair<int, int> P;
// ダイクストラO(elogv)
struct edge{
  int to, cost;
  edge(int t, int c) {
    to = t, cost = c;
  }
};
int N, M;
vector<edge> G[603030];
int d[603030];
map<P, int> ID;
int maxid;
int PP[200005], Q[200005], C[200005];
void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> >que;
  FOR(i,0,maxid+N+1) d[i] = inf;
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto &e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int getid(int a, int b) {
  if(ID.count(P(a, b))) return ID[P(a, b)];
  return ID[P(a, b)] = maxid++;
}
// 同じ路線をつなぐ
void addEdge(int p, int q, int c) {
  int id1 = getid(p, c);
  int id2 = getid(q, c);
  G[id1].push_back(edge(id2, 0));
  G[id2].push_back(edge(id1, 0));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  FOR(i,0,M) {
    cin >> PP[i] >> Q[i] >> C[i];
    addEdge(PP[i], Q[i], C[i]);
  }
  // 駅〜改札まではコスト1
  FOR(i,0,M) {
    G[ID[P(PP[i], C[i])]].push_back(edge(maxid + PP[i], 1));
    G[maxid + PP[i]].push_back(edge(ID[P(PP[i], C[i])], 1));
    G[ID[P(Q[i], C[i])]].push_back(edge(maxid + Q[i], 1));
    G[maxid + Q[i]].push_back(edge(ID[P(Q[i], C[i])], 1));
  }
  dijkstra(maxid + 1);
  cout << (d[maxid + N] == inf ? -1 : d[maxid + N] / 2) << endl;
  return 0;
}

Measured memory_bytes: 65144
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "c.cpp"

int main() {
  ll k, n;
  cin >> k >> n;
  vl a(n);
  cin >> a;

  ll ans = k;

  rep(i, n-1) {
    cmin(ans, k-(a[i+1]-a[i]));
  }
  cmin(ans, k-(a[0]+k-a[n-1]));

  cout << ans << endl;
}


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

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second

ll n;

bool solve(ll x , ll tmp)
{
    while(tmp>1)
    {
        if (tmp%x)
        {
            ll cnt = tmp/x;
            tmp -= cnt*x;
            return (tmp==1);
        }
        else
        {
            tmp /= x;
        }
    }
    return (tmp==1);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n;

    ll ans = 0;
    for(ll i=1; i*i<=n; i++)
    {
        if (n%i==0)
        {
            if (i != 1 && solve(i , n)) ans++;
            if (n/i != i && solve(n/i , n)) ans++;
        }
    }

    n--;
    for(ll i=1; i*i<=n; i++)
    {
        if (n%i==0)
        {
            if (i!=1 && solve(i , n+1)) ans++;
            if (n/i != i && solve(n/i , n+1)) ans++;
        }
    }

    cout << ans << '\n';

    return 0;
}

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

	using namespace std;
	#define PI              3.1415926536

	#define ff              first
	#define ss              second
	#define int             long long
	#define pb              push_back
	#define mp              make_pair
	#define pii             pair<int,int>
	#define vi              vector<int>
	#define mii             map<int,int>
	#define pqb             priority_queue<int>
	#define pqs             priority_queue<int,vi,greater<int> >
	#define setbits(x)      __builtin_popcountll(x)
	#define zrobits(x)      __builtin_ctzll(x)
	#define mod 1000000007
	#define inf             1e18
	#define ps(x,y)         fixed<<setprecision(y)<<x
	#define mk(arr,n,type)  type *arr=new type[n];
	#define w(x)            int x; cin>>x; while(x--)
	#define REP(i,n) for(i=0;i<n;i++)
	#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
	mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


	void c_p_c()
	{
	#ifndef  ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	}

	void solve()
	{
		int n, s;

		cin >> n >> s;

	}

	int32_t main()
	{
		//c_p_c();
		FIO;

		int n, m;
		cin >> n >> m;

		char ch[n + 1][m + 1];

		int dp[n + 1][m + 1];

		int i, j;

		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= m; j++)
			{
				cin >> ch[i][j];

			}
		}
		// for (i = 1; i <= n; i++)
		// {
		// 	for (j = 1; j <= m; j++)
		// 	{
		// 		cout << ch[i][j];

		// 	}
		// 	cout << endl;
		// }

		for (i = n; i >= 1; i--)
		{
			for (j = m; j >= 1; j--)
			{
				if (i == n && j == m)
				{
					dp[i][j] = 1;
				}
				else
				{
					int o1 = (i == n) ? 0 : dp[i + 1][j];

					int o2 = (j == m) ? 0 : dp[i][j + 1];

					dp[i][j] = (o1 + o2) % mod;

					if (ch[i][j] == '#')
						dp[i][j] = 0;
				}


			}
		}
		// for (i = 1; i <= n; i++)
		// {
		// 	for (j = 1; j <= m; j++)
		// 	{
		// 		cout << dp[i][j] << " ";
		// 	}
		// 	cout << endl;
		// }
		cout << dp[1][1];


	}

Measured memory_bytes: 12444
import sys
from collections import deque
def serp(s):
  prev = [-1]*n
  q=deque([s])
  while q:
    v = q.pop()
    for nv in e[v]:
      if nv==s: prev[nv]=v; return(s,prev)
      if prev[nv]<0: q+=nv,; prev[nv] =v
  return(-1,prev)
n,m,*t=map(int,open(0).read().split())
e,ab = [[] for i in range(n)],[]
for a,b in zip(*[iter(t)]*2):
  e[a-1]+= b-1,
  ab += [(a-1,b-1)]
for v in range(n):
  v0,prev = serp(v)
  if v0>=0: break
if v0<0: print(-1); sys.exit()
c=set()
c.add(v0)
pv = prev[v0]
while pv!=v0:
  c.add(pv)
  pv=prev[pv]
for a,b in ab:
  if a in c and b in c and prev[b]!=a:
    pv = prev[b]
    while pv !=a:
      c.remove(pv)
      pv=prev[pv]
    prev[b]=a
print(len(c))
for i in c: print(i+1)

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

int main() {

	string a, b, c;
	cin >> a >> b >> c;

	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


	return 0;



}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) lower_bound(ALL(c),x)
#define UB(c,x) upper_bound(ALL(c),x)
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

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

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}

void dijkstra(const vector< vector<edge> >& G, vector<int>& d, int s)
{
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()) {
    int temp_cost = que.top().first;
    int from = que.top().second;
    que.pop();
    if (d[from] < temp_cost) continue;
    for (int i = 0; i < G[from].size(); i++) {
      edge e = G[from][i];
      if (d[e.to] > d[from] + e.cost) {
        d[e.to] = d[from] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

signed main()
{
  int K; cin >> K;
  vector< vector<edge> > G(K);

  rep(i, 0, K) {
    G[i].push_back((edge){ (i+1) % K, 1 });
    G[i].push_back((edge){ (10*i) % K, 0 });
  }

  vector<int> d(K);
  dijkstra(G, d, 1);

  cout << d[0] + 1 << endl;

  return 0;
}


Measured memory_bytes: 9208
N=int(input())
A=[int(input()) for _ in range(N)]

ans=0
if A[0]!=0:
    print(-1)
    exit()
for i in range(N-1,0,-1):
    l,a=A[i-1],A[i]
    if a>l+1:
        print(-1)
        exit()
    elif a==l+1:
        ans+=1
    elif a!=0:
        ans+=a
print(ans)

Measured memory_bytes: 59224
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    
    string C1, C2, C3;
    cin >> C1 >> C2 >> C3;
    cout << C1.at(0) << C2.at(1) << C3.at(2) << endl;
    
    return 0;
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


int main(){
	int t;
	cin>>t;
	while(t--){
		int n,d;
		cin>>n>>d;
		
		int res;
		if(n%2==1)res = d;
		else res = d^127;
		
		cout<<127*(n-1)+res<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  ll n,a=1;
  cin>> n;
  string s[n];
  for(ll i=0;i<n;i++){
    cin>>s[i];
  }
  sort(s,s+n);
  for(ll i=0;i<n-1;i++){
    if(s[i]!=s[i+1]){
      a++;
    }
  }
  cout << a<< endl;
}

Measured memory_bytes: 9884
#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const int mod = 1e9 + 7;

int main (){
    int a, b;

    cin >> a >> b;

    cout << (a>b? "safe" : "unsafe") << endl;
  
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

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

  cout << 800*N - (N/15)*200 << endl;
}


Measured memory_bytes: 256