akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

class ModCalc
{
    LLONG m_mod = MOD;
    vector<LLONG> m_fac;
    vector<LLONG> m_ifac;

public:
    ModCalc(const LLONG mod)
    {
        m_mod = mod;
    }

    // Combinationを計算したいときの前処理：O(max)
    ModCalc(const int max, const LLONG mod)
    {
        m_mod = mod;
        m_fac = vector<LLONG>(max + 1);
        m_ifac = vector<LLONG>(max + 1);
        m_fac[0] = m_ifac[0] = 1;
        for (int i = 0; i < max; ++i)
        {
            m_fac[i + 1] = m_fac[i] * (i + 1) % mod;    // n! (mod M)
            m_ifac[i + 1] = m_ifac[i] * ModPow(i + 1, mod - 2) % mod;   // k!^(M-2) (mod M)
        }
    }

    const LLONG ModAdd(LLONG a, LLONG b) const
    {
        return (a + b) % m_mod;
    }

    const LLONG ModSubtract(LLONG a, LLONG b) const
    {
        LLONG diff = a - b;
        return diff >= 0 ? diff : diff + m_mod;
    }

    const LLONG ModMulti(LLONG a, LLONG b) const
    {
        LLONG prod = a * b % m_mod;
        return prod >= 0 ? prod : prod + m_mod;
    }

    const LLONG ModDiv(LLONG a, LLONG b) const
    {
        LLONG c = m_mod, u = 1, v = 0;
        while (c)
        {
            LLONG t = b / c;
            b -= t * c; swap(b, c);
            u -= t * v; swap(u, v);
        }
        u %= m_mod;
        if (u < 0) u += m_mod;
        return (a % m_mod) * u % m_mod;
    }

    const LLONG ModPow(LLONG x, LLONG n) const
    {
        LLONG ret = 1;
        while (n != 0)
        {
            if (n & 1) ret = ret * x % m_mod;
            x = x * x % m_mod;
            n = n >> 1;
        }
        return ret;
    }

    const LLONG ModComb(LLONG n, LLONG r) const
    {
        if (n == 0 && r == 0) return 1;
        if (n < r || n < 0) return 0;
        LLONG tmp = m_ifac[n - r] * m_ifac[r] % m_mod;
        return tmp * m_fac[n] % m_mod;
    }
};

int main()
{
    LLONG N, M, K; cin >> N >> M >> K;
    ModCalc mod(200001, MOD);
    LLONG ans = 0;
    for (LLONG k = 0; k <= K; ++k)
    {
        LLONG tmp = mod.ModMulti(M, mod.ModPow(M - 1, N - (k + 1)));
        tmp = mod.ModMulti(tmp, mod.ModComb(N - 1, k));
        ans = mod.ModAdd(ans, tmp);
    }
    cout << ans << endl;
}

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


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

	int S,W;
	cin >> S >> W;
	if (S <= W)
	{
		cout<<"unsafe\n";
	}
	else
	{
		cout<<"safe\n";
	}
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define X first
#define Y second
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 200000+10;
const int maxm = 2222222+10;
const int mod = 1e9+7;
const double eps = 1e-9;
int r,c;
bool check(int x,int y){
    return x==0 || x==r || y==0 || y==c;
}
ll dist(int x,int y){
    return 1ll*x*x+1ll*y*y;
}
struct Point{
    int x,y,id;
    Point (int x=0,int y=0,int id=0):x(x),y(y),id(id){}
    bool operator < (const Point &rhs) const {
        return 1ll*x*rhs.y>1ll*rhs.x*y || 1ll*x*rhs.y==1ll*rhs.x*y && dist(x,y)<dist(rhs.x,rhs.y);
    }
}a[maxn];
bool in[maxn];
stack<int> stk;
int main() {
#ifdef local
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n; cin>>r>>c>>n;
    int tot=0,p=-1;
    for (int i=0;i<n;i++){
        int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
        if (check(x1,y1) && check(x2,y2)){
            if (p==-1 || (a[p].y>y1 || a[p].y==y1 && a[p].x>x1)) p=tot;
            a[tot++]=Point(x1,y1,i);
            if (p==-1 || (a[p].y>y2 || a[p].y==y2 && a[p].x>x2)) p=tot;
            a[tot++]=Point(x2,y2,i);
        }
    }
    if (~p){
        int dx=a[p].x,dy=a[p].y;
        for (int i=0;i<tot;i++){
            a[i].x-=dx;
            a[i].y-=dy;
        }
        sort(a,a+tot);
        for (int i=0;i<tot;i++){
            if (!in[a[i].id]){
                in[a[i].id]=true;
                stk.push(a[i].id);
            } else {
                if (stk.top()!=a[i].id){
                    cout<<"NO\n";
                    return 0;
                }
                stk.pop();
                in[a[i].id]=false;
            }
        }
    }
    cout<<"YES\n";
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    long long n;
    cin >> n;
    vector<int> a(n);
    long long count=0;
    if(n==1){
        count=1;
    }
    else{
        for(int i=1;i<=n;i++){
            if(i%3!=0&&i%5!=0){
                count+=i;
            }
        }
    }
        cout << count << endl;
}

Measured memory_bytes: 7108
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

int main() {
	int n, m;
	
	while(cin >> n >> m) {
		if(n == 0 && m == 0) break;

		vector<P> v(m);
		rep(i, m) {
			v[i].first = 0;
			v[i].second = -i;
		}

		rep(i, n) {
			rep(j, m) {
				int x;
				cin >> x;

				if(x == 1) v[j].first++;
			}
		}

		sort(v.begin(), v.end(), greater<P>());
		rep(i, m) {
			cout << -v[i].second + 1;

			if(i == m-1) cout << endl;
			else cout << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 1200
import numpy as np
N,M=map(int,input().split())
A=set([int(input()) for _ in range(M)])

mod=10**9+7

dp=np.zeros(N+1)
dp[0]=1
if 1 not in A:
    dp[1]=1
else:
    dp[1]=0

for i in range(2,N+1):
    if i in A:
        continue
    dp[i]=dp[i-1]+dp[i-2]
    dp[i]%=mod

print(int(dp[N]))

Measured memory_bytes: 37120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,n,T,t,tnew,ans=0;cin>>n>>T;
  vector<P> stores;
  lvector B;
  rep(i,n) {
    cin>>a>>b;
    if(a>0) stores.emplace_back(P(a,b));
    else B.push_back(b);
  }  
  sort(stores.begin(),stores.end(),
      [](P x,P y) {return y.first*(x.second+1)<x.first*(y.second+1);});
  sort(B.begin(),B.end());
  ll l=stores.size(),num=min(n+1,30ll);
  lvector dp(num+10,T+1);dp[0]=0;
  rep(i,l) {
    a=stores[i].first;
    b=stores[i].second;
    for(ll j=num;j>-1;--j) {
      ll val=(dp[j]+1)*(a+1)+b;
      if(val<T+0.5) dp[j+1]=min(dp[j+1],val);
    }
  }
  rep(i,num+1) {
    if(dp[i]>T) continue;
    ll t_tmp=dp[i],ans_=i;
    for(ll j:B) {
      if(t_tmp+j+1<T+0.5) {t_tmp+=j+1;ans_++;}
      else break;
    }
    ans=max(ans,ans_);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 6384
#import <stdio.h>
void G(){
    printf("GREATER");
    exit(0);
}
void L(){
    printf("LESS");
    exit(0);
}
void E(){
    printf("EQUAL");
    exit(0);
}
int main(){
    char a[105] = {'\0'};
    char b[105] = {'\0'};
    scanf("%s %s", a,b);
    int la = strlen(a);
    int lb = strlen(b);
    if (la>lb) {
        G();
    }
    if (la<lb) {
        L();
    }
    int h = strcmp(a,b);
    if (h>0) {
        G();
    }
    if (h<0) {
        L();
    }
    E();
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  vector<int> a(n);
  int first, second, which;
  first = 0;
  second = 0;
  for (int i=0; i<n; i++) {
    cin >> a.at(i);
    if (a.at(i) >= first) {
      second = first;
      first = a.at(i);
      which = i;
    }
    else if (a.at(i) > second) {
      second = a.at(i);
    }
  }
  for (int i=0; i<n; i++) {
    if (which == i) {
      cout << second << endl;
    }
    else {
      cout << first << endl;
    }
  }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast")
using namespace std;

typedef unsigned long long ll;
typedef pair<int, int> pii;

#define f(i, l, r) for (int i = l; i <= r; i++)
#define rf(i, r, l) for (int i = r; i >= l; i--)
#define all(x) (x).begin(), (x).end()
#define sf(a) scanf("%d", &a)
#define llsf(a) scanf("%lld", &a)
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
//#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))
#define mod1(x) ((x>=mod)&&(x-=mod))
#define mod2(x) ((x<0)&&(x+=mod))

const int inf = 2e9 + 7;
const ll INF = INT64_MAX;
double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const double pi = acos(-1.0);

int a[N];
ll mx[N];
ll num[N];

int main() {
#ifdef local
	int start = clock();
	freopen("in.txt", "r", stdin);
#endif
	bool flag = 1;
	int n; sf(n);
	f(i, 0, n) {
		sf(a[i]);
	}
	if (n == 0 && a[0] == 1) {
		cout << 1; return 0;
	}
	ll last, now;
	if (a[0] == 0)last = 1; else last = 0;
	f(i, 1, n) {
		now = 2 * last;
		if (i < n) {
			mx[i] = now - a[i];
			last = now - a[i];
		}
		else {
			mx[i] = now;
		}
	}

	if (mx[n] < a[n])flag = 0;
	ll res = a[n];
	ll down = a[n];
	mx[0] = 1;
	rf(i, n - 1, 0) {
		ll miup = (down + 1) / 2;
		if (miup > mx[i])flag = 0;
		now = min(mx[i], down);
		now += a[i];
		res += now;
		num[i] = now;
		down = now;
	}
	f(i, 0, min(n, 30)) {
		if (num[i] > pow(2, i))flag = 0;
	}
	if (flag) {
		cout << res;
	}
	else cout << -1;
	cout << '\n';
#ifdef local
	int end = clock();
	cout << '\n' << end - start << "ms";
#endif* /
}


Measured memory_bytes: 6084
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <set>

using namespace std;
#define mk make_pair
typedef long long ll;
typedef pair<int,int> P;
const int maxn=100100;
const int mod=1000000007;
const ll INF=1000000000;

int a[maxn];

int main()
{
    string s;
    cin>>s;
    int r=0,l=0,k,flag=1,len=s.size()-1;
    for(int i=0; i<s.size()-1; i++)
    {
        if(s[i]=='R')
        {
            if(flag)
            {
                r++;
            }
            else
            {
                r++;
                int sum=(l+1)/2;
                a[k]=a[k]+sum;
                a[k-1]=a[k-1]+l-sum;
            }
            //cout<<r<<endl;
            flag=1;
            l=0;
        }
        else
        {
            if(!flag)
            {
                l++;
            }
            else
            {
                l++;
                k=i;
                int sum=(r+1)/2;
                a[i-1]=a[i-1]+sum;
                a[i]=a[i]+r-sum;
            }
            flag=0;
            r=0;
        }
    }
    if(s[len]=='L'){
        if(s[len-1]=='R'){
            int sum=(r+1)/2;
            a[len-1]=a[len-1]+sum;
            a[len]=a[len]+r-sum+1;
        }
        else{
            l++;
            int sum=(l+1)/2;
            a[k]=a[k]+sum;
            a[k-1]=a[k-1]+l-sum;
        }
    }
    for(int i=0;i<=len;i++){
        if(i==0)
            printf("%d",a[i]);
        else{
            printf(" %d",a[i]);
        }
    }
    return 0;
}

/*
 2598708396863
*/


Measured memory_bytes: 1024
#include<stdio.h>

int main(void) {
	int w, h, x, y, r;
	
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	
	if(x+r > w || x-r < 0 || y+r > h || y-r < 0) {
		printf("No\n");
	} else {
		printf("Yes\n");
	}
	
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string S;
    cin >> S;
    int len = S.size();
    int ans = 0;
    rep(i,len - 1){
        if (S[i] != S[i + 1]) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define INF int(1e-6)
#define MAX int(1e9)
typedef long long ll;



int main (){
	int k,x,i;
	cin >> k >> x;
	int aux = k-1;
	int ini = x-aux;
	int fim = x+aux;
	for(i = ini; i<fim; i++){
		printf("%d ",i);
	}
	printf("%d\n",i);
	return 0;

}



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

int a, b, c, ans;

int main() {
	cin >> a >> b >> c;
	while (ans <= 2e7) {
		if (a % 2 || b % 2 || c % 2)
			return cout << ans << '\n', 0;

		int t = a / 2, tt = b / 2, ttt = c/ 2;
		a = tt + ttt;
		b = t + ttt;
		c = t + tt;
		ans++;
	}
	cout << -1 << '\n';
	return 0;
}



Measured memory_bytes: 256
N, K  = list(map(int, input().split()))
p_sum = 0.0
for i in range(1, N + 1):
    score = i
    counter = 0
    while 1 <= score and score <= K - 1:
        score = score * 2
        counter += 1
    p = (0.5 ** counter) / N
    p_sum += p
print(p_sum)


Measured memory_bytes: 2940
#include<cstdio>

using namespace std;
int main(void)
{
	double t,v,y,i;
	while(scanf("%lf",&v) != EOF)
	{
		t = v / 9.8;
		y = 4.9 * t *t;

		for(i = 0;;i++)
		{
			if(5*i-5 >= y) break;
		}
		printf("%.0lf\n",i);
	}
	return 0;
}

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

int H = 0, W = 0;

bool check(int nx, int ny, char *A) {
  if ((nx>=W) || (ny>=H)) {
    return false;
  } else if (A[nx+ny*W]=='#') {
    return true;
  } else {
    return false;
  }
}

int main() {
  cin >> H >> W;
  char A[W*H];
  char buf;
  int sh = 0;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> buf;
      A[j+i*W] = buf;
      if (buf == '#') {
        sh++;
      }
    }
  }
  

  int cnt = 1;
    for (int x = 0, y = 0; x < W && y < H;){
      if (check(x+1,y,A)) {
        x++;
        cnt++;
      } else if (check(x,y+1,A)) {
        y++;
        cnt++;
      } else {
        if (x == W-1 && y == H-1 && cnt == sh) {
          cout << "Possible" << endl;
          return 0;
        } else {
          cout << "Impossible" << endl;
          return 0;
        }
      }
  }
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 int main(){
string S;
cin >> S;
S.at(5) = ' ';
S.at(13) = ' ';
print(S);
 }

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

count = 0
is_continue = True
while(True):
    for i in A:
        if(i % 2 != 0):
            is_continue = False
            break
        if(i == 0):
            is_continue = False
            break

    if(is_continue == False):
        break
    else:
        counter = 0
        for i in A:
            A[counter] = i/2
            counter+=1   
    count += 1    
    
print(count)

Measured memory_bytes: 9208
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

VI g[55];
int m[55];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, x, d;
  cin >> n >> x >> d;
  cin >> m[0];
  FOR(i, 1, n) {
    int p;
    cin >> m[i] >> p;
    g[p-1].PB(i);
  }

  // 頂点iの部分木を取ったときのコストXと価値Yを求める
  VI X(n), Y(n);
  function<void(int)> dfs = [&](int v) {
    X[v] = m[v], Y[v] = 1;
    for(int i: g[v]) {
      dfs(i);
      X[v] += X[i];
      Y[v] += Y[i];
    }
  };
  dfs(0);

  VI Z(n); Z[0] = INF;
  FOR(i, 1, n) Z[i] = d;

  VI idx(n);
  REP(i, n) idx[i] = i;
  // Y[x]/X[x] >= Y[y]/X[y] ⇔ Y[x]*X[y] >= Y[y]*X[x] でソート
  sort(ALL(idx), [&](int x, int y){return Y[x]*X[y]>Y[y]*X[x];});

  const int maxy = 50;
  VI dp(maxy*maxy*maxy+5, INF);
  dp[0] = 0;
  REP(i, n) {
    int num = min(maxy, Z[idx[i]]);
    for(int k=1; num; k<<=1) {
      int mul = min(k, num);
      for(int j=maxy*maxy*maxy; j>=0; --j) {
        if(j+mul*Y[idx[i]] <= maxy*maxy*maxy) {
          chmin(dp[j+mul*Y[idx[i]]], dp[j] + mul*X[idx[i]]);
        }
      }
      num -= mul;
    }
  }

  int ans = 0;
  REP(i, maxy*maxy*maxy+1) {
    // 価値iとして残りをgreedyに決める
    if(dp[i]>x) continue;
    int ret=i, w = x-dp[i];
    REP(j, n) {
      // cnt個取る
      int cnt = Z[idx[j]] - min(maxy, Z[idx[j]]);
      chmin(cnt, w/X[idx[j]]);
      ret += cnt*Y[idx[j]];
      w -= cnt*X[idx[j]];
    }
    chmax(ans, ret);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1280
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		String a = "";
		String s1 = "", s2 = "";
		int x = 0;
		for (int i=0;i<n;i++) a += sc.nextInt();
		for (int j=0;j<m;j++) {
			for (int k=0, p=sc.nextInt();k<p;k++) {
				s1 += x; s2 += 1 -x;
			}
			x = 1-x;
		}
		
		System.out.println(min(len(a, s1), len(a, s2)));
	}
	
	int len (String a, String b) {
		int l = a.length(), n = 0;
		int[] A = new int[l], B = new int[l];
		for (int i=0;i<l;i++) A[i] = a.charAt(i) - '0';
		for (int i=0;i<l;i++) B[i] = b.charAt(i) - '0';
		for (int i=0;i<l;i++) {
			if (A[i] == 1) n++;
			if (B[i] == 1) n--;
		}
		if (n != 0) return INF;
		int cnt = 0;
		for (int i=0;i<l;i++) {
			if(A[i] == B[i])
				continue;
			
			for (int j=i;j<l;j++) {
				if (B[i] == A[j]) {
					int tmp = A[i];
					A[i] = A[j];
					A[j] = tmp;
					break;
				} else {
					cnt++;
				}
			}
//			debug(A, B);
		}
//		debug(A, B, cnt);
		return cnt;
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main()
{
    int n, i, count=0;
    scanf("%d", &n);
    int x[n+5], y[n+5];

    for(i=1; i<=n; i++)
        scanf("%d%d", &x[i], &y[i]);

    for(i=1; i<=n-2; i++)
    {
        if(x[i]==y[i])
        {
            if(x[i+1]==y[i+1])
            {
                if(x[i+2]==y[i+2])
                {
                    count=1;
                    break;
                }
            }
        }
    }

    if(count==0)
        printf("No\n");
    else
        printf("Yes\n");

    return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#include <queue>

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
	int n, k;
	double ans = 0;
	cin >> n >> k;
	rep(i, 1, n+1) {
		int a = i;
		double b = 0;
		while (a < k) {
			a *=2;
			b++;
		}
		ans += pow(0.500, b) / n;
	}
	printf("%.12lf\n", ans);
	return 0;
}

Measured memory_bytes: 384
N = int(input())
S = input()
Rcount = 0
Gcount = 0
Bcount = 0
for i in S:
    if i == "R":
        Rcount += 1
    if i == "G":
        Gcount += 1
    if i == "B":
        Bcount += 1

sum2 = Rcount * Gcount * Bcount

for i in range(1, len(S) // 2 + len(S) % 2):
    for j in range(len(S)-(i*2)):
        #print(j, j+i, j+i*2)
        if S[j] != S[j + i] and S[j] != S[j + (i * 2)] and S[j+i] != S[j+(i*2)]:
            sum2 -= 1
print(sum2)


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


int main(){
	
	int a,b;

	scanf("%d %d", &a, &b);
	
	if (a == 1 && b != 1 )
		printf("Alice\n");
	else if (a != 1 && b == 1)
		printf("Bob\n");
	else if (a > b)
		printf("Alice\n");
	else if (a < b)
		printf("Bob\n");
	else
		printf("Draw\n");

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

struct Rdata {
	int idx, score;
	string city;
	bool operator<(Rdata r) {
		return (city < r.city) | (city == r.city) & (score > r.score);
	}
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	
	vector<Rdata> rst(N);
	for (int i = 0; i < N; i++){
		cin >> rst[i].city >> rst[i].score;
		rst[i].idx = i + 1;
	}
	sort(rst.begin(), rst.end());

	for (auto& ele : rst) cout << ele.idx << "\n";

	return 0;	
}

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

using namespace std;

typedef long long ll;
const int MAXN = 1005;

const int INF = (int)1e9;
vector<int> G[MAXN];

vector<int> bfs(int start, int n) {
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  queue<int> q;
  dist[start] = 0;
  q.push(start);
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u: G[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }

  pair<int, int> best(INF, -1);
  for (int v = 0; v < n; ++v) {
    if (v == start) continue;
    for (int u: G[v]) {
      if (u == start) {
	best = min(best, make_pair(dist[v], v));
      }
    }
  }

  if (best.first == INF) return vector<int>(n + 1);
  int v = best.second;
  vector<int> res;
  res.push_back(v);
  while (v != start) {
    v = pre[v];
    res.push_back(v);
  }
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
  }

  vector<int> ans(n + 1);
  for (int s = 0; s < n; ++s) {
    vector<int> cur = bfs(s, n);
    if (cur.size() < ans.size()) ans = cur;
  }

  if ((int)ans.size() == n + 1) {
    puts("-1");
  } else {
    cout << ans.size() << endl;
    for (int i = (int)ans.size() - 1; i >= 0; --i) {
      cout << ans[i] + 1<< endl;
    }
  }
  return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
#include <iomanip>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する

#define MAX_PAS 50 //最大の第一引数
ll pascal[MAX_PAS + 1][MAX_PAS + 1];

void calcPascal() {
    REP(i, 1, MAX_PAS + 1) {
        pascal[i][i] = 1;
        pascal[i][0] = 1;
    }
    REP(i, 1, MAX_PAS + 1) {
        REP(j, 1, i) {
            if (pascal[i][j] == 0)pascal[i][j] = pascal[i - 1][j - 1] + pascal[i - 1][j];
        }
    }

}


int main() {
    calcPascal();
    int A;
    int B;
    int N;
    cin >> N >> A >> B;
    vector<ll> v(N + 1);
    REP(i, 1, N + 1) {
        cin >> v[i];
    }

    sort(v.begin() + 1, v.end(), greater<ll>());

    int k = 1;
    REP(i, 1, v.size()) {
        if (v[1] != v[i]) break;
        k = i;
    }
//    cout << k << endl;

    if (k <= A) {
        int m = 0;
        int l = -1;
        REP(i, 1, v.size()) {
            if (v[A] == v[i]) {
                if (l == -1) {
                    l = i;
                }
                m++;
            }
        }
        ll sum = 0;
        REP(i, 1, A+1) {
            sum += v[i];
        }
        double ave = (double) sum / A;
//        cout << ave << endl;
        cout << fixed << setprecision(7) << ave << endl;
        cout << pascal[m][A - l + 1] << endl;
    } else {
        double ave = (double) v[1];
        ll combi = 0;
        REP(i, A, min(B, k) + 1) {
            combi += pascal[k][i];
        }
//        cout << ave << endl;
        cout << fixed << setprecision(7) << ave << endl;
        cout << combi << endl;
    }

    return 0;
}





Measured memory_bytes: 256
from bisect import bisect_right


def main():
    """
    4 <= N <= 2 * 10^5
    1 <= Ai <= 10^9
    """
    N = int(input())
    *A, = map(int, input().split())

    ans = f(N, A)
    # ans = TLE(N, A)

    print(ans)


def test_ans():
    NA_ans = [
        (5, [3, 2, 4, 1, 2], 2),
        (10, [10, 71, 84, 33, 6, 47, 23, 25, 52, 64], 36),
        (7, [1, 2, 3, 1000000000, 4, 5, 6], 999999994),
    ]

    for N, A, ans in NA_ans:
        assert TLE(N, A) == ans
        assert f(N, A) == ans


def f(N, A):
    ans = float("inf")
    S = A[::]
    for i in range(1, N):
        S[i] += S[i-1]

    for mid in range(2, N-1):
        # 均等
        x = S[mid-1] / 2
        left = bisect_right(S, x)
        if abs(S[left-1] - x) < abs(S[left] - x):
            left -= 1

        y = (S[-1] + S[mid-1]) / 2
        right = bisect_right(S, y)
        if abs(S[right-1] - y) < abs(S[right] - y):
            right -= 1

        p = S[left]
        q = S[mid-1] - S[left]
        r = S[right] - S[mid-1]
        s = S[-1] - S[right]
        sums = (p, q, r, s)
        ans = min(ans, max(sums) - min(sums))

    return ans


def TLE(N, A):
    ans = float("inf")
    for b in range(1, N-2):
        for c in range(b+1, N-1):
            for d in range(c+1, N):
                B = A[:b]
                C = A[b:c]
                D = A[c:d]
                E = A[d:]
                print(B, C, D, E)

                *sums, = map(sum, [B, C, D, E])
                x = abs(max(sums) - min(sums))
                ans = min(ans, x)

    return ans


if __name__ == '__main__':
    main()


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

int const BASE = 998244353;

ll f(int n, int m) {
  ll ans = 1;
  REP(i, m) { ans = ans * n % BASE; }
  return ans;
}

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

  cin >> N;
  vector<int> D(N);
  REP(i, N) { cin >> D[i]; }

  if (D[0] != 0) {
    cout << 0 << endl;
    return 0;
  }

  sort(D.begin(), D.end());
  ll ans = 1;
  int parent_count = 1;
  int children_count = 1;

  REPI(i, 0, N - 1) {
    if (D[i] == 0 && i > 0) {
      cout << 0 << endl;
      return 0;
    }

    if (D[i] != D[i + 1]) {
      if (D[i + 1] != D[i] + 1) {
        cout << 0 << endl;
        return 0;
      } else {
        ans = ans * f(parent_count, children_count) % BASE;
        parent_count = children_count;
      }
      children_count = 1;
    } else {
      ++children_count;
    }
  }

  ans = ans * f(parent_count, children_count) % BASE;

  cout << ans % BASE << endl;

  return 0;
}


Measured memory_bytes: 640
if __name__ == "__main__":
    N = int(input())
    if N == 1:
        print("Yes")
        exit()
    for i in range(1, min(N, 10)):
        n1 = N % i
        n2 = N // i
        if n1 == 0 and n2 < 10:
            print("Yes")
            exit()

    print("No")

Measured memory_bytes: 3060
from math import cos, pi

A, B, H, M = map(int, input().split())

SA = 30 * H + M / 2
LA = 6 * M

DA = abs(SA - LA)
DA = min(DA, 360 - DA)

C2 = A ** 2 + B ** 2 - 2 * A * B * cos(DA / 360 * 2 * pi)
print(C2 ** 0.5)


Measured memory_bytes: 9560
n, k = io.read("*n", "*n", "*l")
s = io.read()
pos = 1
poslist = {}
cnt = 0
p1, p2 = string.find(s, "1+", pos)
while(p1 ~= nil) do
  cnt = cnt + 1
  poslist[cnt] = {}
  poslist[cnt].fst, poslist[cnt].lst = p1, p2
  pos = p2 + 1
  p1, p2 = string.find(s, "1+", pos)
end

if(#poslist < k) then
  print(n)
else
  res = 0
  for i = 1, #poslist - k do
   res = math.max(res, poslist[i + k].lst - poslist[i].fst + 1)
  end
  res = math.max(res, poslist[k].lst)
  res = math.max(res, n - poslist[#poslist - k + 1].fst + 1)
  print(res)
end


Measured memory_bytes: 5596
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; 
bool complare(int a,int b);
int main()
{
	char blue[105][105],red[105][105];
	int max = 0,cnt;
	int i,n,m,j;
	scanf("%d",&n);
	for(i = 0;i < n; i++)
		scanf("%s",blue[i]);
		scanf("%d",&m);
		for(i = 0;i < m; i++)
			scanf("%s",red[i]);
			for(i = 0;i < n; i++)
			{
				cnt = 0;
				for(j = 0;j < n; j++)
				{
					if(strcmp(blue[i],blue[j]) == 0)
						cnt++;
				}
				for(j = 0;j < m; j++)
				{
					if(strcmp(blue[i],red[j]) == 0)
						cnt--;
				}
				if(max < cnt)
					max = cnt;
			}
			printf("%d\n",max);
			return 0;
}

				


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  int a;
  cin >> a;
  a%=10;
  if(a==3){
    cout << "bon" << endl;
  }
  else if(a==0||a==1||a==6||a==8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3728
from collections import defaultdict,deque
import sys


M = [list(map(int,input().split())) for _ in range(3)]

start = 0
for i in range(3):
    for j in range(3):
        start += M[i][j]*10**((2-i)*3 + (2-j))
start = "{:0>9}".format(start)

def make_next_states(h,w,s):
    ret = []
    x = [-1,0,1,0]
    y = [0,-1,0,1]
    for i in range(4):
        nh,nw = h+y[i],w+x[i]
        if (0<=nh<=2) and (0<=nw<=2):
            swap_ind = nh*3 + nw
            char = s[swap_ind]
            next_s = s.replace(char,"x").replace("0",char).replace("x","0")
            ret.append(next_s)
    return ret

finished = defaultdict(bool)
finished[start] = True

q = deque()
q.append([start,0])
while 1:
    s,n = q.popleft()
    finished[s] = True
    if s == "123456780":
        break
    null = s.index("0")
    null_h = null//3
    null_w = null%3
    next_states = make_next_states(null_h,null_w,s)
    for next_s in next_states:
        if not finished[next_s]:
            q.append([next_s,n+1])

print(n)
    









Measured memory_bytes: 41196
use std::io::*;
use std::str::FromStr;

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

const MOD: usize = 1e+9 as usize + 7;

fn calc(
    depth: usize,
    upper_l: usize,
    lower_r: usize,
    rev: usize,
    l: usize,
    r: usize,
    memo: &mut Vec<Vec<Vec<Vec<usize>>>>,
) -> usize {
    if memo[upper_l][lower_r][rev][depth] != MOD {
        return memo[upper_l][lower_r][rev][depth];
    }
    let bit = 1 << depth;
    if bit > r || (bit * 2 > r && bit <= r && lower_r == 0) {
        return 0;
    }
    let mut ret = 0;
    if rev == 0 && (bit > l || (bit * 2 > l && bit <= l && upper_l == 1)) {
        ret = 1;
    }
    for i in 0..2 {
        let nlower_r = if (r & bit) > 0 {
            i == 0 || lower_r == 1
        } else {
            i == 0 && lower_r == 1
        };
        let nlower_r = if nlower_r { 1 } else { 0 };
        for j in 0..2 {
            if i == 0 && j == 1 {
                continue;
            }
            let nupper_l = if (l & bit) > 0 {
                j == 1 && upper_l == 1
            } else {
                j == 1 || upper_l == 1
            };
            let nupper_l = if nupper_l { 1 } else { 0 };
            let nrev = if i < j || (rev == 1 && i == j) { 1 } else { 0 };
            ret = (ret + calc(depth + 1, nupper_l, nlower_r, nrev, l, r, memo)) % MOD;
        }
    }
    memo[upper_l][lower_r][rev][depth] = ret;
    // println!("{} {} {} {} {}", depth, upper_l, lower_r, rev, ret);
    return ret;
}

fn main() {
    let l = read::<usize>();
    let r = read::<usize>();
    let mut memo = vec![vec![vec![vec![MOD; 70]; 2]; 2]; 2];
    let ans = calc(0, 1, 1, 0, l, r, &mut memo);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int>d(n);
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    sort(d.begin(),d.end());
    int cnt=0;
    if(d[n/2]-d[n/2-1]<=0){
        cout<<0<<endl;
    }else{
        cout<<d[n/2]-d[n/2-1]<<endl;
    }
   return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
int main(){
    int a;
    cin >> a;
    for(int i = 3; i <= a; i++)
        if(i%3 == 0)
            cout << ' ' << i;
        else{
            int num = i;
            while(num != 0)
                if(num % 10 == 3){
                    cout << ' ' << i;
                    break;
                }
                else
                    num /= 10;
        }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N, T, S, M[3001]={};
	cin >> N >> T >> S;
	for(int n=0; n<N; n++){
		int mise_fun, mise_time;
		cin >> mise_fun >> mise_time ;
		for(int t=T; t>=mise_time; t--)
			if(t<=S || t >= S  + mise_time) M[t] = max(M[t], M[t - mise_time] + mise_fun);
	}
	cout << *max_element(M+1, M+T+1) << endl;
	return 0;
}

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



int main()
{
   int A,B;
   cin >> A >> B;

   if (A > 0 , B>0 , A<14 , B<14){
    if (A==B){
        cout << "Draw " << endl;
    } else if(B==1){
    cout << "Bob" << endl;}
    else if(A==1){
   cout << "Alice " << endl;}
   else if(A>B){
    cout << "Alice " << endl;
   } else if(B>A){
   cout << "Bob" << endl;}
   }
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	int n;
	cin>>n;
	int l[n];
	rep(i,n)cin>>l[i];
	sort(l,l+n);
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				int a=l[i];
				int b=l[j];
				int c=l[k];
				if(a==b||b==c||a==c)continue;
				if(a<b+c&&a+b>c&&a+c>b)ans++;
			}
		}
	}
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        int n = Integer.parseInt(br.readLine());
        for (int i=0; i<= n/4+1;i++){
            for (int j=0; j<= n/7+1; j++){
                if ((4*i+7*j) == n){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");

    }

}



Measured memory_bytes: 32664
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int n,m,K,i,j;cin>>n>>m>>K;
	vector<int>col(1+K,-1);//その色を持つ最小値
	vector<int>tai(n);
	for(i=0;i<n;i++){tai[i]=i;}
	int nok=K-1;
	for(i=0;i<n;i++){
		int c;cin>>c;if(c==0){continue;}
		if(col[c]==-1){col[c]=i;}
		else{tai[i]=col[c];}
	}
	vector<tuple<llint,int,int>>hen(m);
	for(i=0;i<m;i++){
		int a,b;llint w;cin>>a>>b>>w;a--;b--;
		hen[i]=mt(w,tai[a],tai[b]);
	}
	vector<int>oya(n);
	vector<int>ran(n);
	for(i=0;i<n;i++){oya[i]=i;}
	sort(hen.begin(),hen.end());
	int mita=0;llint ans=0;
	while(nok>0){
		if(mita==hen.size()){cout<<-1<<endl;return 0;}
		int a,b;llint w;tie(w,a,b)=hen[mita];
		mita++;
		while(a!=oya[a]){a=oya[a];}
		while(b!=oya[b]){b=oya[b];}
		if(a==b){continue;}
		nok--;ans+=w;
		if(ran[a]<ran[b]){swap(a,b);}
		if(ran[a]==ran[b]){ran[a]++;}
		oya[b]=a;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, L;
    cin >> n >> L;
    vector <int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }   
    for (int i = 0; i + 1 < n; ++i) {
        if (a[i] + a[i + 1] >= L) {
            cout << "Possible" << endl;
            for (int j = 0; j < i; ++j) {
                cout << j + 1 << endl;
            }   
            for (int j = n - 2; j >= i; --j) {
                cout << j + 1 << endl;
            }   
            exit(0);
        }   
    }   
    cout << "Impossible" << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int x = (A + B) / 2;
  
  if((A + B) % 2 == 0){
    cout << x << endl;
    }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
}


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

struct StCond                  // 材料質量・限界量
{
  StCond() : m_nWaterA(0), m_nWaterB(0),
             m_nSugerC(0), m_nSugerD(0),
             m_nConcE(0),  m_nLimitF(0) { }

  int m_nWaterA, m_nWaterB;
  int m_nSugerC, m_nSugerD;
  int m_nConcE;
  int m_nLimitF;
};

struct StAmt                   // 使用量
{
  StAmt() : m_nAmtA(0), m_nAmtB(0), m_nAmtC(0), m_nAmtD(0) { }

  int m_nAmtA, m_nAmtB, m_nAmtC, m_nAmtD;
};

struct StReslt                  // 出力結果
{
  StReslt() : m_nAllMass(0), m_nSugerMass(0) { }

  int m_nAllMass, m_nSugerMass;
};

void fnInput(StCond& roCond)
{
  cin >> roCond.m_nWaterA >> roCond.m_nWaterB >> roCond.m_nSugerC >> roCond.m_nSugerD;
  cin >> roCond.m_nConcE  >> roCond.m_nLimitF;
}

int fnAmtSumup(string sProc, const StCond& cnroCond, const StAmt& cnroAmt)
{ 
  if      (sProc == "A")
    return  (cnroCond.m_nWaterA * cnroAmt.m_nAmtA) * 100;
  if      (sProc == "A+B")
    return  (cnroCond.m_nWaterA * cnroAmt.m_nAmtA + cnroCond.m_nWaterB * cnroAmt.m_nAmtB) * 100;
  else if (sProc == "A+B+C")
    return  (cnroCond.m_nWaterA * cnroAmt.m_nAmtA + cnroCond.m_nWaterB * cnroAmt.m_nAmtB) * 100 
          + (cnroCond.m_nSugerC * cnroAmt.m_nAmtC);
  else if (sProc == "A+B+C+D")
    return  (cnroCond.m_nWaterA * cnroAmt.m_nAmtA + cnroCond.m_nWaterB * cnroAmt.m_nAmtB) * 100 
          + (cnroCond.m_nSugerC * cnroAmt.m_nAmtC + cnroCond.m_nSugerD * cnroAmt.m_nAmtD);
  else           // "C+D" 
    return  (cnroCond.m_nSugerC * cnroAmt.m_nAmtC + cnroCond.m_nSugerD * cnroAmt.m_nAmtD);
}

double fnConcCalc(const StCond& cnroCond, const StAmt& cnroAmt)
{
  static double stnLimtConc = 0.0;
  double nNowConc = 0.0;

  if (!stnLimtConc)
    stnLimtConc = cnroCond.m_nConcE / (100.0 + cnroCond.m_nConcE);

  if ( fnAmtSumup("A+B+C+D", cnroCond, cnroAmt) )
  {
    nNowConc =  (double)fnAmtSumup("C+D", cnroCond, cnroAmt)
               /        fnAmtSumup("A+B+C+D", cnroCond, cnroAmt);
    if (stnLimtConc < nNowConc)
      return -1.0;
    else
      return nNowConc;
  }
  else
    return -1.0;
}

void fnConcCheck(const StCond& cnroCond, StReslt& roReslt)
{
  StAmt oAmt;
  double nMaxConc = -1.0;
  
  for ( oAmt.m_nAmtA = 0; 
        fnAmtSumup("A", cnroCond, oAmt) <= cnroCond.m_nLimitF; oAmt.m_nAmtA++ )
  {
    for ( oAmt.m_nAmtB = 0; 
          fnAmtSumup("A+B", cnroCond, oAmt) <= cnroCond.m_nLimitF; oAmt.m_nAmtB++ )
    {
      for ( oAmt.m_nAmtC = 0; 
            fnAmtSumup("A+B+C", cnroCond, oAmt) <= cnroCond.m_nLimitF; oAmt.m_nAmtC++ )
      {
        for ( oAmt.m_nAmtD = 0;
              fnAmtSumup("A+B+C+D", cnroCond, oAmt) <= cnroCond.m_nLimitF; oAmt.m_nAmtD++ )
        {
          double nNowConc = fnConcCalc(cnroCond, oAmt);
          if (nMaxConc < nNowConc)
          {
            nMaxConc = nNowConc;
            roReslt.m_nAllMass = fnAmtSumup("A+B+C+D", cnroCond, oAmt);
            roReslt.m_nSugerMass = fnAmtSumup("C+D", cnroCond, oAmt);
          }
        }
      }
    }
  }
}

int main()
{
  StCond oCond;
  StReslt oReslt;

  fnInput(oCond);
  fnConcCheck(oCond, oReslt);
  cout << oReslt.m_nAllMass << " " << oReslt.m_nSugerMass << endl;

  return 0;
}

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

int K, N;
vector<int> A;
int res = 10000000;
int partmax = 0;

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

  int a;
  for(int i = 0; i < N; i++){ 
    cin >> a;
    A.push_back(a);
  }

  sort(A.begin(), A.end());

  partmax = K+A[0]-A[N-1];

  for(int i = 0; i < N-1; i++)
    partmax = max(partmax, A[i+1]-A[i]);

  cout << K-partmax << endl;
  return 0;
}



Measured memory_bytes: 1400