akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main() {
  string str;
  cin >> str;
  char c = str[0];

  REP(i, 3) {
    if (str[i] != c) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

da = NextIntList()
print(da.index(0)+1)

Measured memory_bytes: 9408
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  int N;
  cin >> N;
  int x = N / 2;
  int y = N - x;
  double ans = (double)y / N;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    ll H;
    cin >> H;
    ll ans = 0;
    while(H){
        H/=2;
        ans += ans+1;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  ll L, R;
  cin >> L >> R;
  ll a = 2019;
  ll ans;
  if (R - L > 3000) ans = 0;
  else {
    ll min_ans = 2018;
    for (ll i = L ; i < R; i++){
      for (ll j = i+1; j < R+1; j++){
        min_ans = min(min_ans, (i * j) % a);
      }
    }
    ans = min_ans;
  }
  cout << ans << endl;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=5000000000000000000;
ll MOD=1000000007;

int main() {
    int n;
    cin >> n;
    vector<pp> a(n),b(n);
    rep(i,n) cin >> a.at(i).first >> a.at(i).second;
    rep(i,n) cin >> b.at(i).first >> b.at(i).second;
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    vector<int> c(n);
    int ans=0;
    rep(i,n) c.at(i)=0;
    for (int i=0;i<n;i++){
        int x=a.at(i).first,y=a.at(i).second;
        int t=0,q,h=inf;
        for (int j=0;j<n;j++){
            if (x>b.at(j).first) break;
            if (c.at(j)==1) continue;
            if (y<b.at(j).second && h>b.at(j).second) {
                h=b.at(j).second;
                t=1;
                q=j;
            }
        }
        if (t==1) {
            c.at(q)=1;
            ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int k, s;
    cin >> k >> s;

    ll cnt = 0;
    rep(x, k+1){
        rep(y, k+1){
            if(0 <= s - x - y && s - x - y <= k) ++cnt;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
template <class T>
using vt = std::vector<T>;

int main(){
  int n;
  std::cin >> n;
  vt<int> t(n), x(n), y(n);
  rep(i,n)  std::cin >> t[i] >> x[i] >> y[i];

  /*t[i] -> t[i+1]　が可能ならば、０ -> t[i+1]　が可能である
    2個目ifは目的地に到着してから偶数回余った場合他の場所に移動し
    て再び戻ることができる                                 */
  rep(i,n) {
    int to = x[i] + y[i];
    if(to <= t[i]){
      if((t[i] - to)%2 != 0){
        std::cout << "No" << '\n';
        return 0;
      }
    }
    else{
      std::cout << "No" << '\n';
      return 0;
    }
  }

  std::cout << "Yes" << '\n';
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
vector<int>d;
vector<pii>ed;
vector<int>G[100010];
map<int,int>mm;
int dp[100010];
int cnt[100010];
bool vis[100010];
int sz[100010];
int ans[100010];
void dfs(int x,int pr=-1LL){
	cnt[x]++;
	vis[x]=1;
	for(auto to:G[x])if(to!=pr){
		if(vis[to])puts("-1"),exit(0LL);
		dfs(to,x);
		dp[x]+=dp[to]+cnt[to];
		cnt[x]+=cnt[to];
	}
}
void dfs2(int x,int pr=-1LL,int w=0LL){
	ans[x]=dp[x]+w;
	w+=dp[x];
	for(auto to:G[x])if(to!=pr)dfs2(to,x,w-dp[to]-cnt[to]+(n-cnt[to]));
}
signed main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=0LL;i<n;i++){
		int x;
		cin>>x;
		d.pb(x);
		mm[x]=i;
	}
	for(auto x=mm.rbegin();x!=mm.rend();x++){
		int node=x->S,val=x->F;
		sz[node]++;
		int op=n-sz[node];
		if(!op)continue;
		int nxt=val+sz[node]-op;
		if(mm.count(nxt)){
			int ne=mm[nxt];
			sz[ne]+=sz[node];
			G[ne].pb(node);
			G[node].pb(ne);
			if(ne>node)swap(ne,node);
			ed.pb(mp(ne+1LL,node+1LL));
		}
	}
	dfs(0LL);
	dfs2(0LL);
	for(int i=0;i<n;i++){
		if(!vis[i])return puts("-1"),0;
		if(ans[i]!=d[i])return puts("-1"),0;
	}
	for(auto x:ed)cout<<x.F<<' '<<x.S<<endl;
	return 0;
}


Measured memory_bytes: 23792
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rrep(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

int dp[3050][3050];
char a[1050][1050];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h,w; cin >> h >> w;
  m0(dp);
  rep2(i,1,h+1)rep2(j,1,w+1) cin >> a[i][j];
  dp[1][1] = (a[1][1] == '.');
  rep2(i,1,h+1)rep2(j,1,w+1){
      if(i==1 && j==1) continue;
      if(a[i][j] == '.') dp[i][j] = dp[i-1][j] + dp[i][j-1];
      dp[i][j] %= MOD;
  }
  cout << dp[h][w] << endl;
  return 0;
}

Measured memory_bytes: 37632
/**
    __author__ : srv_twry
**/

#include<bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}

bool ge(const ll& a, const ll& b) { return a >= b; }
bool le(const ll& a, const ll& b) { return a <= b; }
bool eq(const ll& a, const ll& b) { return a == b; }
bool gt(const ll& a, const ll& b) { return a > b; }
bool lt(const ll& a, const ll& b) { return a < b; }
int sgn(const ll& x) { return le(x, 0) ? eq(x, 0) ? 0 : -1 : 1; }
/*----------------------------------------------------------------------*/

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 	int k,v; cin>>k;
 	int n = (1 << k);
 	multiset<int> ms;
 	FOR(i, 0, n) {
 		cin>>v;
 		ms.insert(-1*v);
 	}
 	vi vals; vals.push_back(*ms.begin());
 	ms.erase(ms.begin());

 	FOR(iter, 0, k) {
 		vi newslimes;
 		for(int sl : vals) {
 			auto itr = ms.upper_bound(sl);
 			if(itr == ms.end()) {
 				cout<<"No"; return 0;
 			}
 			newslimes.push_back(*itr);
 			ms.erase(itr);
 		}

 		for(int sl : vals) newslimes.push_back(sl);

		vals = newslimes;
		sort(vals.begin(), vals.end());
 	}
 	cout<<"Yes";
    return 0;
}

Measured memory_bytes: 14088
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;cin>>N;
    vector <string> S(100010);
    map<char,ll>mp;
    for(int i=0;i<N;i++){
        cin>>S[i];
        mp[S[i][0]]++;
    }
    char c[5];
    c[0]='M',c[1]='A',c[2]='R',c[3]='C',c[4]='H';
    ll ans=0;
    for(int i=0;i<=2;i++){
        for(int j=i+1;j<=3;j++){
            for(int k=j+1;k<=4;k++)
                ans+=mp[c[i]]*mp[c[j]]*mp[c[k]];
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

const ll INF = 1E+18;

int main() {
    ll X;
    cin >> X;

    ll time = 0;
    ll longest = 0;
    while (longest < X) {
        time++;
        longest += time;
    }

    cout << time << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#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 all(x) (x).begin(),(x).end()
int f(string st){
    int res=0;
    REP(i,st.size()){
        res+=stoi(st.substr(i,1));
    }
    return res;
}
int main(){
    string st;
    cin>>st;
    int ans=f(st);
    REP(i,st.size()){
        string temp=st;
        if(temp[i]=='0'){
            continue;
        }
        temp[i]--;
        FOR(j,i+1,temp.size()){
            temp[j]='9';
        }
        cerr<<temp<<endl;
        ans=max(ans,f(temp));
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main()
{   int  a, b, c;
    cin >> a >> b >> c;
    if (((a == 5) && (b == 5) && (c == 7)) || ((a == 5) && (b == 7) && (c == 5)) || ((a == 7) && (b == 5) && (c == 5)))
        cout << "YES";
    else
        cout << "NO";
}




Measured memory_bytes: 3520
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const ll &a, const ll &b){
    return abs(a)>abs(b);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e6;

int main(){
    IOS;
    make2(ll,n,m);
    makevec(ll,a,m);
    sort(a.begin(),a.end());
    ll x=a[m-1]-a[0];
    vector <ll> v;
    for(ll i=1;i<m;i++){
        v.push_back(a[i]-a[i-1]);
    }
    sort(v.rbegin(),v.rend());
    ll s=0;
    fr(i,min(m-1,n-1)) s+=v[i];
    cout<<x-s<<endl;





    return 0;
}



Measured memory_bytes: 4956
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  int N,b;
  cin>>N;
  vector<tuple<string,int,int>>X(N);
  for(int i=0;i<N;i++){
    cin>>a>>b;
    X.at(i)=make_tuple(a,100-b,i+1);
  }
  sort(X.begin(),X.end());
  for(int i=0;i<N;i++){
    tie(ignore,ignore,b)=X.at(i);
    cout<<b<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int> 
#define pb push_back
#define st string
#define pairi pair<int,int>
#define INF 1000000007 

bool isPrime(int n){
	if(n<=1) return false;
	if(n<=3) return true;
	if(n%2==0 || n%3==0) return false;
	for(int i=5;i*i<=n;i+=6){
		if(n%i==0 || n%(i+2)==0) return false;
	}
	return true;
}

ll sum(ll n){
	ll sum=n*(n+1);
	return sum/2;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
   ll a,b,c,d;cin>>a>>b>>c>>d;
   ll x=max({a*c,a*d,b*c,b*d});
   cout<<x<<endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  string N; cin >> N;
  string ans = "No";
  if(N[0] == N[1] && N[1] == N[2]) ans = "Yes";
  if(N[1] == N[2] && N[2] == N[3]) ans = "Yes";
  cout << ans << endl;
}

Measured memory_bytes: 3652
#include <stdio.h>

#define MAX 100000
typedef long long ll;

int total,track;
ll T[MAX];

int check(ll P){
    int count = 0; //荷物を数える．
    for (int i = 0; i < track; i++){
        ll now = 0;
        while (now + T[count] <= P){
            now +=  T[count];
            count++;
            if (count == total) return total;
        }
    }
    return count;
}


int solve(){
    ll left = 0;
    ll right = 10000*100000;
    ll mid;  //最小積載量の候補
    while (right - left > 1){
        mid = (left + right) / 2;
        int v = check(mid); //どれだけ余裕があるか確認
        if(v >= total) right = mid;
        else left = mid;
    }
    return right;
}

int main(){
    ll ans= 0;
    scanf("%d%d" ,&total ,&track);
    for(int i = 0 ; i < total ; i++){
        scanf("%lld" ,&T[i]);
    }
    ans = solve();
    printf("%lld\n" ,ans);
    return 0;
}


Measured memory_bytes: 2624
n = int(input())

testimonies = []
for i in range(n):
	a = int(input())
	temp = []
	for _ in range(a):
		x, y = map(int, input().split())
		temp.append([x-1, y])
	testimonies += [temp]

count = 0
for bit in range(2 ** n):
	honest_table = [(bit >> i) & 1 for i in range(n)]

	flag = True
	for person in range(n):
		if honest_table[person] == 1:
			for x, y in testimonies[person]:
				if honest_table[x] != y:
					flag = False

	if flag == True:
		count = max(count, honest_table.count(1))
		
print(count)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

// array pointer = *a, num of element = n, key key
int lower_bound(int *a, int n, int key){
    int ng, mid, ok;
    ng = -1, ok = n-1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (key <= a[mid]){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if (a[ok] >= key)return ok;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]) % mod;
        }
    }
}*/
long long mod = 1000000007;

//x ^ n
long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}




int main(void){
    int n;
    scanf("%d", &n);
    printf("%d\n", n/3);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

#include <algorithm>

using namespace std;

struct BIT{
    vector<int> bit;
    
    BIT(int n){
        for(int i = 0;i <= n;i++) bit.push_back(0);
    }
    
    int sum(int i){
        int s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    
    void add(int i,int x){
        while(i <= bit.size()){
            bit[i] += x;
            i += i & -i;
        }
    }
};

long long bubblecount(vector<long long> a){
    long long result = 0;
    vector<long long> sorted;
    copy(a.begin(),a.end(),back_inserter(sorted));
    sort(sorted.begin(),sorted.end());
    BIT bit(a.size());
    for(int i = 0;i < a.size();i++){
        int index = lower_bound(sorted.begin(),sorted.end(),a[i]) - sorted.begin() + 1;
        result += bit.sum(index);
        bit.add(index,1);
    }
    return result;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<long long> a(n),sa(n+1);
    sa[0] = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        a[i] -= k;
        sa[i+1] = sa[i] + a[i];
    }
    cout << bubblecount(sa) << endl;
}

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

using namespace std;

int n,m,sum;
int a[110];

bool cmp(int x,int y)
{
    return x>y;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sort(a+1,a+n+1,cmp);
    if(a[m]*1.0>=sum*1.0/(4*m))
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
A = [int(i) for i in input().split()]

B = [A[0]]
for i in range(1, N):
    if A[i] < B[-1]:
        B.append(A[i])
    else:
        B.append(B[-1])
        
A.reverse()
C = [A[0]]
for i in range(1, N):
    if A[i] > C[-1]:
        C.append(A[i])
    else:
        C.append(C[-1])
C.reverse()

ans = [[C[1] - B[0]]]
for i in range(1, N - 1):
    if B[i] < B[i - 1]:
        ans.append([C[i + 1] - B[i]])
        
x = max(ans)
print(ans.count(x))

Measured memory_bytes: 15508
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let mut s: Vec<char> = read::<String>().chars().collect();

    let mut ans = 0;
    let mut prev = String::new();
    let mut now = String::new();

    while let Some(c) = s.pop() {
        now.push(c);
        if now == prev {
            if s.len() == 0 && prev.len() == 1 && now.len() == 0 {
                ans -= 1;
            }
            continue;
        } else {
            ans += 1;
            prev = now.clone();
            now.clear();
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1e9+7
#define MOD 1e9+7
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

string s;
int n;
int y, x, M[9][9];
int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };

void solve(int y, int x){
	M[y][x] = 0;

	for (int i = 0; i < 4; i++){
		for (int j = 1; j <= 3; j++){
			int ny = y + dy[i] * j, nx = x + dx[i] * j;
			if (ny >= 0 && ny < 8 && nx >= 0 && nx < 8){
				if (M[ny][nx] == 1)solve(ny, nx);
			}
		}
	}
}

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 8){
			cin >> s;
			REP(k, 8){
				M[j][k] = s[k] - '0';
			}
		}
		cin >> x >> y;
		solve(y - 1, x - 1);
		cout << "Data " << i + 1 << ":" << endl;
		REP(j, 8){
			REP(k, 8){
				cout << M[j][k];
			}
			cout << endl;
		}
	}
}

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

int main(){
  int N;
  cin >> N;
  map<int,int> m;
  int max=0;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    m[tmp]++;
    if(max < tmp){
      max = tmp;
    }
  }
  
  int ans=0;
  for(auto p : m){
    int a = p.first;
    int b = p.second;
    //cout << a << " " << b << endl;
    if(a <= b){
      ans += b-a;
    }else{
      ans += b;
    }
  }
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 4736
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repr(i,a,b) for(int i=a,i > b;--i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)

#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (ll)V.size()
#define _ <<" "<<

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <iterator>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <limits.h>
#include <iomanip>
#include <cctype>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef pair <double, double> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<int> vii;

vi a(50);

int main(){
	int n;
	cin>>n;
	rep(i,0,n) cin>>a[i];
	int maxi=-1e7,mini=1e7;
	rep(i,0,n) {
		maxi=max(maxi,a[i]);
		mini=min(mini,a[i]);
	}
	if(maxi >= 0 && mini >=0){
		cout << n-1<<endl;
		rep(i,1,n){
			cout<<i<<" "<<i+1<<endl;
		}
	}
	else if(maxi <= 0 && mini <=0){
		cout<<n-1<<endl;
		for(int i=n;i>1;i--){
			cout<<i<<" "<<i-1<<endl;
		}
	}
	else {
		if(abs(maxi) >= abs(mini)){
			cout<<2*n-2<<endl;
			int idx;
			rep(i,0,n){if(a[i]==maxi) idx=i;}
			idx++;
			for(int i=1;i<=n;i++) if(i!=idx) cout<<idx<<" "<<i<<endl;
			for(int i=1;i<n;i++)  cout<<i<<" "<<i+1<<endl;	
		}
		else{
			cout<<2*n-2<<endl;
			int idx;
			rep(i,0,n){if(a[i]==mini) idx=i;}
			idx++;
			for(int i=1;i<=n;i++) if(i!=idx) cout<<idx<<" "<<i<<endl;
			for(int i=n;i>1;i--)  cout<<i<<" "<<i-1<<endl;	
		}
	}
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int n, w; cin >> n >> w;
  vector<ll> weights(n, 0);
  vector<ll> values(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> weights[i] >> values[i];
  }

  vector<vector<ll> > dp(n+1, vector<ll>(w+1, 0));

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= w; j++) {
      if (weights[i-1] > j)
        dp[i][j] = dp[i-1][j];
      else
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-weights[i-1]] + values[i-1]);
    }
  }

  cout << dp[n][w] << endl;

  return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
string solve(string s1,string s2,int m,int n)
{
      int dp[m+1][n+1];
      memset(dp,0,sizeof(dp));
      for(int i=1;i<=m;i++)
      {
          for(int j=1;j<=n;j++)
          {
              if(s1[i-1]==s2[j-1])
              dp[i][j]=dp[i-1][j-1]+1;
              else
              dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
          }
      }
      int i=m,j=n;
      string ans="";
      while(i>0 && j>0)
      {
          if(s1[i-1]==s2[j-1])
          {
              ans+=s1[i-1];
              i--; j--;
          }
          else
          {
              if(dp[i-1][j] > dp[i][j-1])
              i--;
              else
              j--;
          }

      }
      reverse(ans.begin(),ans.end());
      return ans;
}
int main() 
{
      string s1,s2;
      cin>>s1>>s2;
      int m=s1.length();
      int n=s2.length();
      cout<<solve(s1,s2,m,n);
}


Measured memory_bytes: 38804
#include<stdio.h>
int main(){
int a,b,c,i;
int sum = 0;
scanf("%d%d%d", &a, &b, &c);
for(i=a; i<=b; i++){
  if(c%i == 0)
   sum++;
}

printf("%d\n", sum);

return 0;

}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,q;
  cin >> n >> q;
  vec a(n),sum(n+1),sum2(n+1);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    sum[i+1]=sum[i]+a[i];
    sum2[i+1]=(i?sum2[i-1]:0)+a[i];
  }
  vec x(q);
  for(ll i=0;i<q;i++) cin >> x[i];
  for(ll i=0;i<q;i++) {
    ll lb=0,ub=n+1;
    while(ub-lb>1) {
      ll t=(lb+ub)>>1;
      if(abs(a[n-(t+1)/2]-x[i])>=abs(a[n-t]-x[i])) {
        lb=t;
      }
      else {
        ub=t;
      }
    }
    cout << sum2[max(n-lb-(lb&1),0LL)]+(sum[n]-sum[n-(lb+1)/2]) << endl;
  }
}

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

using namespace std;
 
int main() {
    int N,s;cin >> N;
    long long r = 0;
    int max;
    cin >> max;
    

    for (int i = 0;i < N-1;i++){
        cin >> s;
        if (max < s){
            max = s;
        }
        else{
            r += max-s;
        }
    }

    cout << r << endl;
}

Measured memory_bytes: 3636
s = input().split()

a = int(s[0])
b = int(s[1])

height = []
p = 1
for i in range(999):
    height.append(p)
    p += 1

c = b - a
sum_num = 0

for i in range(c):
    sum_num += height[i]

answer = sum_num - b

print(answer)



Measured memory_bytes: 9088
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int main(){
    char *s,*t;
    s=(char*)malloc(sizeof(char)*101);
    t=malloc(sizeof(char)*101);
    scanf("%s",s);
    scanf("%s",t);
    int n=0;
    while(s[n]!=NULL){
        n++;
    }
    F(i,0,n){
        F(j,0,n){
            if(s[(i+j)%n]!=t[j]) break;
            if(j==n-1){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    free(s);
    free(t);
    return 0;
}

Measured memory_bytes: 128
n, c, k = map(int,input().split())
tl = []
for i in range(n):
    tl.append(int(input()))
tl.sort()

if c == 1:
    print(n)
    exit()

end = tl[0] + k
passenger_cnt = 1
bus_cnt = 0
for i in range(1,n):
    # 間に合う場合
    if end >= tl[i]:
        passenger_cnt += 1
        if i == n-1:
            if passenger_cnt <= c:
                bus_cnt += 1
                break
            else:
                bus_cnt += 2
                break
        elif passenger_cnt == c:
            bus_cnt += 1
            passenger_cnt = 0
            end = tl[i+1]+k

    # 間に合わない場合
    else:
        if i == n-1:
            bus_cnt += 2
            break
        bus_cnt += 1
        end = tl[i] + k
        passenger_cnt = 1

print(bus_cnt)

Measured memory_bytes: 13236
#include <bits/stdc++.h>
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++)
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int n,k;
    cin>>n>>k;
    
    if(k>(n-1)*(n-2)/2){
        cout<<-1<<endl;
        return 0;
    }

    ll m = n-1+(n-1)*(n-2)/2-k;
    cout<<m<<endl;

    for(int i=2;i<=n;i++){
        cout<<1<<" "<<i<<endl;
    }
    int cnt =0;

    bool fl = false;
    for(int i=2;i<n;i++){
        for(int j=i+1;j<=n;j++){
            if(cnt == (n-1)*(n-2)/2-k){
                fl=true;
            }
            if(fl) break;
            cout<<i<<" "<<j<<endl;
            cnt++;
        }
        if(fl) break;
    }

    return 0;
}

Measured memory_bytes: 256
import math

n,m = map(int,input().split())
    
if abs(n-m) <= 1:
    if n == m:
        print((math.factorial(n)**2)*2% 1000000007)
    else:
        print(math.factorial(n)*math.factorial(m)% 1000000007)
        
else:
    print(0)

Measured memory_bytes: 54640
#include <iostream>
#include <string>
using namespace std;
int main(){
    int x;
    cin >> x;
    if(x==22)
        cout << "Christmas Eve Eve Eve" << endl;
    else if(x==23)
        cout << "Christmas Eve Eve" << endl;
    else if (x == 24)
        cout << "Christmas Eve" << endl;
    else if (x == 25)
        cout << "Christmas" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long

using namespace std;
typedef pair<int,int> P;

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

    map<int,int> emap;
    map<int,int> omap;

    for(int i=0;i<n;i++){
        if(i%2==0){
            emap[a[i]]++;
        }else{
            omap[a[i]]++;
        }        
    }
    vector<P> epairs;
    vector<P> opairs;
    for(const auto& item:emap){
        epairs.emplace_back(item.second,item.first);
    }    
    
    for(const auto& item:omap){
        opairs.emplace_back(item.second,item.first);
    }
    epairs.emplace_back(0,0);
    opairs.emplace_back(0,0);

    sort(epairs.begin(),epairs.end(),greater<>());  
    sort(opairs.begin(),opairs.end(),greater<>());   
    if(opairs[0].second==epairs[0].second){
        cout<<n-max(epairs[0].first+opairs[1].first,epairs[1].first+opairs[0].first)<<endl;
    }else{
        cout<<n-epairs[0].first-opairs[0].first<<endl;  
    }          
    
    return 0;
}

Measured memory_bytes: 6520
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL<<60;

int main()
{
  int H, W;cin>>H>>W;
  string board[H];
  rep(i,H)cin>>board[i];

  rep(i, H) {
    rep(j, W) {
      if (board[i][j] == '.') {
        board[i][j] = '0';
        for(int dy = -1; dy < 2; dy ++) {
          for(int dx = -1; dx < 2; dx++) {
            int ny = i+dy, nx = j+dx;
            if (ny >= 0 && ny < H && nx >= 0 && nx < W) {
              if (board[ny][nx] == '#') board[i][j]++;
            }
          }
        }
      }
    }
  }

  rep(i, H) cout << board[i] << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s; int n; cin >> n >> s;
    rep(i,s.size()) {
        s[i] += n;
        while (s[i] >= '[') { // '[' == 91
            s[i] -= 'Z'-'A'+1;
        }
    }
    cout << s << endl;
    return 0;
}

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

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int ans=0;
  if(c<=b+1){
    cout << c+b << endl;
  }
  else if(c<=a+b+1){
    cout << c+b << endl;
  }
  else{
    cout << b*2+a+1 << endl;
  }
}


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

using namespace std;

int main(){

    int a,n,t;
    cin >> n >> t >> a;

    long d=10000000,h,tem,pos=0;
    for(int i=0;i<n;i++){
        cin >> h;
        tem=abs(a-(t-h*0.006))*1000;
        if(d>tem){
            d=tem;
            pos=i+1;
        }
    }
    cout << pos << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

// 最小公約数
long lcm(long a, long b) {
	return a / gcd(a, b) * b;
}*/

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

	int n;
	cin >> n;
	set<int> s;
	rep(i, n) {
		int d;
		cin >> d;
		s.insert(d);
	}

	cout << s.size() << endl;

	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    int n = s.size();
    rep (i,n) {
        if (s[i] == '?') {
            s[i] = 'D';
        }
    }
    cout << s << endl;
    
    return 0;
}



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

int main() {
	int N, X, Y;
	cin >> N >> X >> Y;
	vector<int> ANS(N + 1, 0);
	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			int D = 0;
			if (j <= X) D = j - i;
			else if (Y <= i) D = j - i;
			else if (i <= X && Y <= j) D = j - Y + X - i + 1;
			else if (X <= i && j <= Y) D = min(j - i, Y - j + i - X + 1);
			else if (X <= i && i <= Y && Y <= j) D = min(i - X + 1, Y - i) + j - Y;
			else if (i <= X && X <= j && j <= Y) D = min(Y - j + 1, j - X) + X - i;
			ANS[D]++;
		}
	}
	for (int i = 1; i < N; i++) cout << ANS[i] << endl;
}

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

int main(){
  
  int k,n;
  cin >> k >> n;
  
  vector<int> a(n);
  
  for(int i=0; i<n ; i++){
    
    cin >> a.at(i);
    
  }
  
  int num=0;
  
  
  for(int i=0; i<n ; i++){
    
    if(i==n-1){
      num = max(num, k+a.at(0)-a.at(n-1));
    }
    else
      num = max(num, a.at(i+1)-a.at(i));
  }
  
  
    
  
  cout << k - num << endl;
  
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
 
class Main{
 
    public static void main(String[] args){
 
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        Map<Integer, Integer> map1 = new HashMap<>();
        Map<Integer,HashMap<Integer,Integer>> map2 = new HashMap<>();
        for(int i=1; i<=n; i++){
            map1.put(i, scanner.nextInt());
        }
        List<Integer> alist = new ArrayList<>();
        List<Integer> blist = new ArrayList<>();
        for(int i=0; i<m; i++){
            alist.add(scanner.nextInt());
            blist.add(scanner.nextInt());
        }
        scanner.close();
        for(int i=0; i<m; i++){
            map2.put(alist.get(i), new HashMap<Integer,Integer>());
            map2.put(blist.get(i), new HashMap<Integer,Integer>());
        }
        for(int i=0; i<m; i++){
            map2.get(alist.get(i)).put(blist.get(i),0);
            map2.get(blist.get(i)).put(alist.get(i),0);
        }
        int count = 0;
        for (int val1 : map2.keySet()) {
            int tmp = 0;
            for (int val2 : map2.get(val1).keySet()) {
                if(map1.get(val1)<=map1.get(val2)){
                    tmp = 1;
                }
            }
            if(tmp==0){
                count+=1; 
            }
        }
        System.out.println(count+n-map2.size());
    }
 
}

Measured memory_bytes: 83964
import sys

input=sys.stdin.readline

N,M=map(int,input().split())
interval=[[] for i in range(0,N)]
for i in range(0,M):
    l,r,a=map(int,input().split())
    interval[l-1].append((r-1,a))

# N: 処理する区間の長さ
INF = 10**30-1

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0

# 区間[l, r)にxを加算
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])

# 区間[l, r)内の最小値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

Max=[0 for i in range(0,N)]
for i in range(N-1,-1,-1):
    for j in range(0,len(interval[i])):
        r,a=interval[i][j]
        update(i,r+1,-a)
    Max[i]=max(-query(0,N),0)
    if i>0:
        update(i-1,i,-Max[i])

print(Max[0])


Measured memory_bytes: 129592
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	ll X,K,D;
	scan(X>>K>>D);
	X=abs(X);
	ll kaisu=X/D;
	if(K>=kaisu){
		K-=kaisu;
		ll now=X-X/D*D;
		if(K%2){
			prin(abs(now-D));
		}
		else{
			prin(now);
		}
	}
	else{
		prin(X-K*D);
	}
	return 0;
}


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

int main(){
    int H, W;
    
    while(1){
        cin >> H >> W;
        
        if (H == 0 && W == 0) break;
        for (int i = 1; i <= H; i++){
            for (int j = 1; j <= W; j++){
                if((i+j)%2 == 1){
                    printf(".");
                }
                else{
                    printf("#");
                }
            }
            printf("\n");
        }
        cout << endl;
    }
    return 0;
}


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



int main() {  
  int N , A ;  
  cin >> N >> A ;
  
  
  int Q = N % 500 ;
  
  if (Q <= A) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    rep(i, a + b + 1){
        bool num = false;
        for(char c = '0'; c <= '9'; c++){
            if(s[i] == c) num = true;
        }
        if(i == a){
            if(num){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(!num){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

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

typedef long long ll;

int main()
{
    int n,i;
    cin >> n;
    vector<vector<int>> c(10,vector<int>(10,0));
    for(i = 1;i <= n;++i){
        int a = i%10;
        if(a == 0){
            continue;
        }
        int b = i;
        while(b >= 10){
            b /= 10;
        }
        ++c.at(a).at(b);
    }
    int j;
    ll ans = 0; 
    for(i = 1;i < 10;++i){
        for(j = 1;j < 10;++j){
            ans += c.at(i).at(j)*c.at(j).at(i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int d[1001],val[1001];
int dp[1001][(1<<12)],n,m,sz,x;
int fun(int idx,int mask)
{
    if(mask==(1<<n)-1) return 0;
    if(idx==m) return 1e9;
    int &ret=dp[idx][mask];
    if(~ret) return ret;
    return ret=min(val[idx]+fun(idx+1,mask|d[idx]),fun(idx+1,mask));
}
signed main()
{

    memset(dp,-1,sizeof dp);
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {

       scanf("%d%d",&val[i],&sz);
        while(sz--)
        {
            scanf("%d",&x);
            d[i]|=(1<<(x-1));
        }
    }
    int ans=fun(0,0);
    printf("%d",(ans>=1e9?-1:ans));
	return 0;
}


Measured memory_bytes: 19924
import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl read
  solve n <$> replicateM n (getl $ map read . words) >>= print

solve :: Int -> [[Int]] -> Int
solve n xs = f 0 as bs
  where
    [as, bs] = map reverse $ transpose xs
    f c [] [] = c
    f c (y:ys) (z:zs) = f (c+d) ys zs
      where
        d = if (y+c) `mod` z == 0 then 0 else z - (y+c) `mod` z
        
getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 183676