akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <algorithm>
#define MAXN 100010
using namespace std;

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1];

int n,m,r1,r2;
int g[MAXN],nume,pre[MAXN],tag[MAXN];
int fa[MAXN];
int d[MAXN],delta;
int f1[MAXN],s1[MAXN];
int f2[MAXN],s2[MAXN];
int f3[MAXN],s3[MAXN];

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

int getfa(int x){
	if(fa[x]==x) return x;
	return fa[x]=getfa(fa[x]);
}

void dfs0(int x,int p){
	pre[x]=p;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			d[e[i].to]=!d[x];
			dfs0(e[i].to,x);
		}
}

void dfs1(int x,int p){
	if(d[x]) s1[x]=1;
	else s1[x]=-1;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			dfs1(e[i].to,x);
			s1[x]+=s1[e[i].to];
			f1[x]+=f1[e[i].to]+abs(s1[e[i].to]);
		}
}

void dfs2(int x,int p){
	if(d[x]) s2[x]=1;
	else s2[x]=-1;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to!=p && !tag[e[i].to]){
			dfs2(e[i].to,x);
			s2[x]+=s2[e[i].to];
			f2[x]+=f2[e[i].to]+abs(s2[e[i].to]);
		}
}

void dfs3(int x,int p){
	if(d[x]) s3[x]=1;
	else s3[x]=-1;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			dfs3(e[i].to,x);
			s3[x]+=s3[e[i].to];
			f3[x]+=f3[e[i].to]+abs(s3[e[i].to]);
		}
	if(x==r2) s3[x]+=delta;
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	memset(g,-1,sizeof g);
	scanf("%d%d",&n,&m);
	if(n&1){
		puts("-1");
		return 0;
	}
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		if(getfa(u)!=getfa(v)){
			fa[fa[u]]=fa[v];
			addEdge(u,v);
			addEdge(v,u);
		}else{
			r1=u; r2=v;
		}
	}
	if(!r1) r1=1;
	dfs0(r1,0);
	if(r2){
		for(int i=r2;i;i=pre[i])
			tag[i]=1;
	}
	int c1=0;
	for(int i=1;i<=n;i++)
		if(d[i]) c1++;
	if((n-2*c1)%2!=0){
		puts("-1");
		return 0;
	}
	delta=(n-2*c1)/2;
	if(!r2){
		if(delta!=0){
			puts("-1");
			return 0;
		}
		dfs1(r1,0);
		printf("%d\n",f1[r1]);
	}else if(d[r1]!=d[r2]){
		if(delta!=0){
			puts("-1");
			return 0;
		}
		static int b[MAXN];
		int numb=0;
		int ans=0,temp=0;
		for(int i=r2;i;i=pre[i]){
			dfs2(i,0);
			ans+=f2[i];
			temp+=s2[i];
			b[++numb]=-temp;
		}
		sort(b+1,b+numb+1);
		int d0=b[(numb+1)/2];
		for(int i=1;i<=numb;i++)
			ans+=abs(d0-b[i]);
		printf("%d\n",ans);
	}else{
		dfs3(r1,0);
		printf("%d\n",f3[r1]+abs(delta));
	}
	return 0;
}


Measured memory_bytes: 9472
inputs = readlines

n = inputs[0].to_i
as = Array.new(n)
bs = inputs[1].split(' ').map(&:to_i)

(0..n-2).each do |i|
  if as[i]
    as[i] = bs[i] if as[i] > bs[i]
  else
    as[i] = bs[i]
  end

  if as[i + 1]
    as[i + 1] = bs[i] if as[i + 1] > bs[i]
  else
    as[i + 1] = bs[i]
  end
end

puts as.inject(:+)



Measured memory_bytes: 1788
// CODING BEAST
/*******************************************************************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define Precision(a) cout << fixed << setprecision(a)

using ll = long long;
ll inf = 1e18;
using vb = vector<bool>; using vc = vector<char>; using vd = vector<double>; using vi = vector<int>; using vvi = vector<vi>;
using vll = vector<ll>; using vvll = vector<vll>; using pi = pair<int, int>; using pll = pair<ll, ll>;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i = 0; i < n; i++)
#define repc(i,a,n) for(ll i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define Blazing_fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trav(a,v) for(auto &a:v)
int a[8] = { -1, -1, -1, 0, 0, 1, 1, 1};
int b[8] = { -1, 0, 1, -1, 1, -1, 0, 1};
inline ll power(ll x, ll y)
{
    ll temp;
    if ( y == 0)
        return 1;
    temp = power(x, y / 2) ;
    if (y % 2 == 0)
        return (temp * temp) ;
    else
        return (x * temp * temp) ;
}
bool sortbysec(pll & a, pll & b) {
    return (a.second < b.second);
}
/*
ll fact(ll n)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
        res = (res * i) ;
    return res;
}

ll ncr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}
bool isprime(ll n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if ((n % 2 == 0) || (n % 3 == 0)) return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if ((n % i == 0) || (n % (i + 2) == 0)) return false;

    return true;
}*/
/*********************************************************************************************************************************************************/

signed main() {
    ll n; cin >> n;
    vll v(n);
    ll ans = 0;
    rep(i, n) {
        cin >> v[i];
    }
    ll ma = v[0];
    for (ll i = 1; i < n; i++) {
        // ma=max(v[i],ma);
        if (v[i] < ma) {
            ans += abs(ma - v[i]);

        }
        else {
            ma = v[i];
        }
    }
    cout << ans << endl;
}




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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(v) (v).begin(), (v).end()
#define sp cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int h, n;
int a[10005], b[10005];
int dp[1005][10005];

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

    cin >> h >> n;
    rep(i, n) cin >> a[i] >> b[i];

    repe(j, h) dp[0][j] = ceil((double)j / a[0]) * b[0];
    // repe(i, n) {
    //     repe(j, h) { cout << dp[i][j] << " "; }
    //     cout << endl;
    // }
    // cout << endl;

    FOR(i, 1, n) {
        repe(j, h) { dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i]] + b[i]); }
    }

    // repe(i, n) {
    //     repe(j, h) { cout << dp[i][j] << " "; }
    //     cout << endl;
    // }

    cout << dp[n - 1][h] << endl;

    return 0;
}

Measured memory_bytes: 39424
N, K = map(int, input().split())
ABs = []
for i in range(N):
  a, b = map(int, input().split())
  ABs.append((a, b))
ABs.sort()
n = 0
for a, b in ABs:
  if n+b >= K:
    print(a)
    break
  n += b


Measured memory_bytes: 16940
s = input()
keta = len(s)
infi = 10 ** 10
dp = [[infi] * (2) for _ in range(keta + 1)]
dp[0][0] = 0
s = s[::-1]
for i in range(keta):
    for j in range(2):
        num = int(s[i])
        if j == 1:
            num += 1
        ni = i + 1
        if num == 10:
            nj = 1
            num = 0
            dp[ni][nj] = min(dp[ni][nj], dp[i][j] + num)
        elif num < 5:
            nj = 0
            dp[ni][nj] = min(dp[ni][nj], dp[i][j] + num)
        elif num > 5:
            nj = 1
            dp[ni][nj] = min(dp[ni][nj], dp[i][j] + 10 - num)
        else:
            nj = 0
            dp[ni][nj] = min(dp[ni][nj], dp[i][j] + num)
            nj = 1
            dp[ni][nj] = min(dp[ni][nj], dp[i][j] + 10 - num)
print(min(dp[keta][0], dp[keta][1] + 1))


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

using ll=long long;
//#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class d>
struct maxflow{
	struct E{
		int to,rev;
		d cap;
	};
	vvc<E> g;
	vi itr,lv;
	maxflow(int n):g(n),itr(n),lv(n){}
	void ae(int s,int t,d c){
		g[s].pb({t,(int)g[t].size(),c});
		g[t].pb({s,(int)g[s].size()-1,0});
	}
	void bfs(int s){
		fill(all(lv),-1);
		lv[s]=0;
		queue<int> q;
		q.push(s);
		while(q.size()){
			int v=q.front();q.pop();
			for(auto e:g[v])if(e.cap>0&&lv[e.to]==-1){
				lv[e.to]=lv[v]+1;
				q.push(e.to);
			}
		}
	}
	d dfs(int v,int t,d f){
		if(v==t)return f;
		d res=0;
		for(int&i=itr[v];i<(int)g[v].size();i++){
			E& e=g[v][i];
			if(e.cap>0&&lv[e.to]==lv[v]+1){
				d a=dfs(e.to,t,min(f,e.cap));
				if(a>0){
					e.cap-=a;
					g[e.to][e.rev].cap+=a;
					res+=a;
					f-=a;
					if(f<=0)break;
				}
			}
		}
		return res;
	}
	d calc(int s,int t){
		d f=0;
		while(1){
			bfs(s);
			if(lv[t]==-1)
				return f;
			fill(all(itr),0);
			f+=dfs(s,t,1e9);
		}
	}
};

pair<int,vi> cmp(vi p){
	int n=p.size(),s=0;
	vi res(n,-1);
	rep(i,n)if(res[i]==-1){
		int x=i;
		do{
			res[x]=s;
			x=p[x];
		}while(x!=i);
		s++;
	}
	return make_pair(s,res);
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n;cin>>n;
	vi p(n);rep(i,n)cin>>p[i];
	vi q(n);rep(i,n)cin>>q[i];
	
	int l=0,r=0;
	vi a,b;
	tie(l,a)=cmp(p);
	tie(r,b)=cmp(q);
	
	maxflow<int> mcf(1+l+r+1);
	int ans=n;
	rep(i,n){
		if(i==p[i]&&i==q[i])
			ans--;
		else if(i==p[i]){
			mcf.ae(1+l+b[i],1+l+r,1);
		}else if(i==q[i]){
			mcf.ae(0,1+a[i],1);
		}else{
			mcf.ae(1+l+b[i],1+a[i],1);
			if(p[i]==q[i])
				mcf.ae(1+a[i],1+l+b[i],1);
		}
	}
	int f=mcf.calc(0,1+l+r);
	ans-=f;
	cout<<ans<<endl;
}


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

using namespace std;


int main(){

    string s;
    cin >> s;
    int w_od = 0, b_od = 0;
    int w_ev = 0, b_ev = 0;
    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            if (s[i] == '0') {
                b_ev++;
            }
            else {
                w_ev++;
            }
        }
        else {
            if (s[i] == '0') {
                b_od++;
            }
            else {
                w_od++;
            }
        }
    }

    cout << min(w_od + b_ev, w_ev + b_od) << '\n';
}


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

const int mod = 1e9+7;
const int INF = 200000000;

int N,M,X;
ll ans = INF;
int A[15][15],C[15];

void dfs(int n, vector<int> p, ll count) {
    if(n == N) {
        vector<int> g(M,0);
        for(int c:p)
            for(int i=0;i<M;++i) g[i] += A[c][i];
        for(int s:g) if(s < X) return;
        ans = min(ans, count);
        return;
    }
    dfs(n+1, p, count);
    p.push_back(n);
    dfs(n+1, p, count+C[n]);
}

int main() {
    cin >> N >> M >> X;
    int a;
    for (int i = 0; i < N; i++){
        cin >> C[i];
        for (int j = 0; j < M; ++j) cin >> A[i][j];
    }
    vector<int> P;
    dfs(0,P,0);
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

double getTime() { 
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int n; read(n);
  map <int, ll> mp1, mp2;
  map <pair <int, int>, ll> cnt;
  for(int i = 1; i <= n; i++) {
    string s = to_string(i);
    mp1[s[0] - '0']++;
    mp2[s.back() - '0']++;
    cnt[{s[0] - '0', s.back() - '0'}]++;
  }
  ll ans = 0;
  for(int i = 1; i <= 9; i++) {
    for(int j = 1; j <= 9; j++) {
      ans += cnt[{i, j}] * cnt[{j, i}];
    }
  }
  print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int x;
  cin >> x;

  ll sum = 0;
  int t = 1;
  while (true)
  {
    sum += t;
    if (sum >= x) break;
    t++;
  }
  cout << t << endl;
  
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a<c && c<b) co("Yes");
  else if(b<c && c<a) co("Yes");
  else co("No");
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int c[] = {500,100,50,10,5,1};

int solve(){
  int x,ans = 0;
  scanf("%d",&x);
  if(x==0) return 1;
  x = 1000-x;
  for(int i=0;i<6;i++){
    ans+=x/c[i];
    x%=c[i];
  }
  printf("%d\n",ans);
  return 0;
}

int main(){
  while(true) if(solve()) return 0;
}

Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n;
  cin >> n;
  ll t[n];
  ll a[n];
  rep(i,n)cin >> t[i];
  rep(i,n)cin >> a[i];
  ll mi[n];
  ll ma[n];
  mi[0]=t[0];
  ma[0]=t[0];
  if(t[n-1]!=a[0]){
    cout << 0 << endl;
    return 0;
  }
  rep(i,n-1){
    if(t[i]==t[i+1]){
      mi[i+1]=1;
      ma[i+1]=t[i];
    }
    else{
      mi[i+1]=t[i+1];
      ma[i+1]=t[i+1];
    }
  }
  ll ans=1;
  ll p=1000000007;
  rep(i,n-1){
    int y=n-1-i;
    ll mii,maa;
    if(a[y]==a[y-1]){
      mii=1;
      maa=a[y];
    }
    else{
      mii=a[y-1];
      maa=a[y-1];
    }
    if(mii>ma[y-1]||mi[y-1]>maa){
      cout << 0 << endl;
      return 0;
    }
    else{
      ans=(ans*max((ll)0,(1+min(min(ma[y-1]-mii,maa-mi[y-1]),min(maa-mii,ma[y-1]-mi[y-1])))))%p;
      //cout << y-1 <<  " " <<  ans << endl;
    }
  }
  cout << ans << endl;
  /*ll m=8848;
  ll z=3776;
  cout << m*m*m%p*z%p << endl;*/
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
#include<queue>
#include <utility>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

typedef queue<int> IntQueue;

int H,W;
const int MAX=1024;
int c[MAX][MAX];
int d[MAX][MAX];

void BFS(){
  cin>>H>>W;
  int c[H][W];
  int d[H][W];
  IntQueue Qx;
  IntQueue Qy;
  char a;
  rep(i,H){
    rep(j,W){
      cin>>a;
      if (a=='#'){
        c[i][j]=1;
        d[i][j]=0;
        Qx.push(i);
        Qy.push(j);
      }
      else c[i][j]=0;
    }
  }
  int ux,uy;
  while (!Qx.empty()){
    ux=Qx.front();
    uy=Qy.front();
    Qx.pop();
    Qy.pop();
    IntQueue adjx;
    IntQueue adjy;
    int px[4]={0,1,0,-1};
    int py[4]={1,0,-1,0};
    int push_cnt=0;
    int vx,vy;
    rep(i,4){
      vx=ux+px[i];
      vy=uy+py[i];
      if (vx>=0 && vx<H && vy>=0 && vy<W){
        adjx.push(vx);
        adjy.push(vy);
        push_cnt++;
      }
    }
    rep(i,push_cnt){
      vx=adjx.front();
      vy=adjy.front();
      adjx.pop();
      adjy.pop();
      if(c[vx][vy]==0){
        c[vx][vy]=1;
        d[vx][vy]=d[ux][uy]+1;
        Qx.push(vx);
        Qy.push(vy);
      }
    }
  }
  int max_d=0;
  rep(i,H){
    rep(j,W){
      if (max_d<d[i][j])max_d=d[i][j];
    }
  }
  cout<<max_d<<endl;
  return;
}

int main(){
  BFS();
  return 0;
}


Measured memory_bytes: 16256
import sys
from string import digits

sys.setrecursionlimit(10**6)
def calc(S, MOD):
    L = len(S)
    S = S + "$"
    ok = 1
    cur = 0
    def expr():
        nonlocal cur
        op = "+"
        res = 0
        while cur < L:
            val = term()
            if op == "+":
                res += val
            else: # '-'
                res -= val
            res %= MOD
            if S[cur] not in "+-":
                break
            op = S[cur]
            cur += 1 # '+' or '-'
        return res % MOD
    def term():
        nonlocal cur, ok
        op = "*"
        res = 1
        while cur < L:
            val = factor()
            if op == "*":
                res *= val
            else: # '/'
                if val == 0:
                    ok = 0
                res *= pow(val, MOD-2, MOD)
            res %= MOD
            if S[cur] not in "*/":
                break
            op = S[cur]
            cur += 1 # '*' or '/'
        return res
    def factor():
        nonlocal cur
        if S[cur] == '(':
            cur += 1 # '('
            val = expr()
            cur += 1 # ')'
            return val
        return number()
    def number():
        nonlocal cur
        val = 0
        while S[cur] in digits:
            val = (10*val + int(S[cur])) % MOD
            cur += 1 # '0123456789'
        return val
    res = expr()
    return res if ok else -1

while 1:
    S = input()
    if S == '0:':
        break
    p, S = S.split(":")
    p = int(p)
    S = S.replace(" ", "")
    res = calc(S, p)
    if res == -1:
        print("NG")
    else:
        print("%s = %d (mod %d)" % (S, res, p))



Measured memory_bytes: 7592
#include <stdio.h>
#include <stdlib.h>

int top=0,S[1000];

void push(int);
int pop(void);

int main()
{
  int i,a,b;
  char s[100];
  

  while(scanf("%s",s)!=EOF)
    {
      if(s[0]=='+'){
	a=pop();
	b=pop();
	push(a+b);
      }

      else if(s[0]=='-'){
	a=pop();
	b=pop();
	push(b-a);
      }

      else if(s[0]=='*'){
	a=pop();
	b=pop();
	push(a*b);
      }

      else {
	a=atoi(s);
	push(a);
      }
    }

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

  return 0;
}

void push(int n){
  S[++top]=n;
}

int pop(void){
  top--;
  return S[top+1];
}


Measured memory_bytes: 2108
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


signed main() {
	ios::sync_with_stdio(false);
	int n;
	int a[105];
	cin >> n;
	int i;
	int ans = 0;
	rep(i, n) cin >> a[i];
	int mn = a[0];
	int mx = a[0];
	FOR(i,1, n) {
		mn = min(mn, a[i]);
		mx = max(mx, a[i]);
	}
	cout << (mx - mn) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int N): par(N) {
        for (int i=0;i<N;i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<pair<int,int>> E;
    for (int i=0;i<M;i++) {
        int a, b;
        cin >> a >> b;
        E.emplace_back(a-1,b-1);
    }
    int cnt = 0;
    for (int i=0;i<M;i++) {
        UnionFind V(N);
        pair<int,int> P;
        P = E.front();
        E.erase(E.begin());
        for (auto itr: E) {
            V.unite(itr.first,itr.second);
        }
        set<int> root;
        for (int j=0;j<N;j++) {
#ifdef DEBUG
            cout << V.root(j) << endl;
#endif
            root.insert(V.root(j));
        }
        if (root.size() != 1) cnt++;
        E.push_back(P);
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e6 + 10; 

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

vector<pair<int, int>> G[N];

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int h,w;
   cin >> h >> w;
   int ch,cw;
   cin >> ch >> cw;
   --ch,--cw;
   int dh,dw;
   cin >> dh >> dw;
   --dh,--dw;
   string s[h];
   for(int i = 0; i < h; ++i){
      cin >> s[i];
   }
   int n = h, m = w;
   auto chk = [&](int x,int y){
      return x >= 0 and x < n and y >= 0 and y < m and s[x][y] == '.';
   };
   for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
         int nd = i*w+j;
         // debug(i,j);
         for(int k = 0; k < 4; ++k){
            int x = dx[k]+i;
            int y = dy[k]+j;
            if(chk(x,y)){
               // cout << x << ' ' << y << '\n';
               G[nd].push_back({x*m+y,0});
            }
         }
         for(int k = max(0ll,i-2); k <= min(n,i+2); ++k){
            for(int l = max(0ll,j-2); l <= min(m,j+2); ++l){
               if(abs(l-j)+abs(k-i) > 1){
                  if(chk(k,l)){
                     // cout << k << ' ' << l << '\n';
                     G[nd].push_back({k*m+l,1});
                  }
               }
            }
         }
      }
   }

   int INF = 1e15;
   int ss = ch*m+cw;
   // debug(ss);
   vector<int> d(N, INF);
   d[ss] = 0;
   deque<int> q;
   q.push_front(ss);
   while (!q.empty()) {
       int v = q.front();
       q.pop_front();
       for (auto edge : G[v]) {
           int u = edge.first;
           int w = edge.second;
           if (d[v] + w < d[u]) {
               d[u] = d[v] + w;
               if (w == 1)
                   q.push_back(u);
               else
                   q.push_front(u);
           }
       }
   }

   int r = d[dh*m+dw];
   if(r == INF){
      cout <<  -1;
   }else{
      cout << r;
   }
   return 0;
} 

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

using namespace std;

#define ll long long
#define lop(a, b) for(int i = a; i < b; i++)
#define lopj(a, b) for(int j = a; j < b; j++)

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

    //freopen("input.txt", "r", stdin)

    char c;

    cin >> c;

    if(c >= 'A' and c <= 'Z')
        cout << 'A' << endl;
    else
        cout << 'a' << endl;

    return 0;
}



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

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

	if(a==0) 
		cout << 1 << endl;
	else if(b==0)
		cout << 2 << endl;
	else if(c==0) 
		cout << 3 << endl;
	else if(d==0) 
		cout << 4 << endl;
	else if(e==0) 
		cout << 5 << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define str string
#define sonic ios_base::sync_with_stdio(0)
using namespace std;
int main(){
	sonic;
	ll n,m;
	cin>>n>>m;
	if(n>=10 ||  m>=10){
		cout<<-1;
		return 0;
	}	
	cout<<n*m;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

#define _CRT_SECURE_NO_WARNINGS

int N = 0;
int M = 0;
int main() {
	scanf("%d%d", &N,&M);
	if(N>M){
printf("%d\n",N-1);
}else{
	printf("%d\n",N);
}	
return 0;
}



Measured memory_bytes: 128
#include <stdio.h>

int main() {
  int n, x;
  int i, j, k;
  int cnt;
  
  while (1) {
    scanf("%d%d", &n, &x);
    if (n==0 && x==0) break;
    cnt=0;
    for (i = 1; i <= n-2; i++)
      for (j = i+1; j <= n-1; j++)
	for (k = j+1; k <= n; k++)
	  if (i+j+k == x) cnt++;
    
    printf("%d\n", cnt);
  }
  

  return 0;
}



Measured memory_bytes: 2076
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int L[]=new int[N];
        for(int i=0; i<N; i++){
            L[i]=sc.nextInt();
        }
        int res = 0;
        for(int i=0; i<N-2; i++){
            for(int j=i+1; j<N-1; j++){
                for(int k=j+1; k<N; k++){
                    if(L[i]==L[j] || L[j]==L[k] || L[k]==L[i]){
                        continue;
                    }else{
                        int max = Math.max(L[k],Math.max(L[i],L[j]));
                        if(max<L[i]+L[j]+L[k]-max){
                            res++;
                        }

                    }

                }
            }
        }
		System.out.println(res);
	}
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    for (int i = 0;  i < N;  i++){
        cin >> x.at(i);
    }
    int d = 0, min_d = 1000000000;
    for (int i = 0;  i <= N - K;  i++){
        d = x.at(K - 1 + i) - x.at(i);
        d += min(abs(x.at(K - 1 + i)), abs(x.at(i)));
        min_d = min(min_d, d);
    }
    cout << min_d << endl;
}

Measured memory_bytes: 640
H,W,K=map(int,input().split());m=10**9+7;a,c=0,1;H+=W;mul=lambda x,y:(x*y)%m
for i in range(H-1,H-K,-1): c=c*i %m;
v=pow(H-1,m-2,m);temp1=mul(H,mul((K*(K+1)//2)%m,c));c=mul(c,v);u=((K*(K**2-1))//6)%m;temp2=mul(2*(H-W)*W,mul(u,c));c=mul(c,H-1);ans=mul(K,mul(H,c));ans=(ans+temp1+temp2)%m;print(ans)

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

int main() {
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;  // 初期状態
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  // 1-index にしておく

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;  // dist と dt の偶奇は一致する必要あり！
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>

using namespace std;
using ll = long long;

ll dp[3001][3001];

int main()
{
    ll N, S;
    array<ll, 3001> A;

    cin >> N >> S;
    for (ll i = 1; i <= N; i++) cin >> A[i];

    dp[0][0] = 1;
    for (ll j = 1; j <= S; j++) dp[0][j] = 0;

    for (ll i = 1; i <= N; i++) for (ll j = 0; j <= S; j++)
    {
        dp[i][j] = 0;
        dp[i][j] += 2 * dp[i - 1][j];
        if (j >= A[i]) dp[i][j] += dp[i - 1][j - A[i]];
        dp[i][j] %= 998244353;
    }

    cout << dp[N][S] << endl;
}

Measured memory_bytes: 73984
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		long[] A = new long[N];
		for(int i = 0;i < N;i++) {
			A[i] = scn.nextLong();
		}
		long ans = 0;
		for(int i = 0;i < N;i++) {
			ans = ans^A[i];
		}
		System.out.println(ans==0?"Yes":"No");
	}

}

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

const long long int MOD = 1e9 + 7;
long long int dp[100005][2];

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

	string s;

	cin >> s;

	int n = s.length();

	memset(dp,0,sizeof(dp));

	dp[0][1] = 2;
	dp[0][0] = 1;

	for(int i=1;i<n;i++)
	{
		if(s[i]=='1')
		{
			dp[i][1] = ((dp[i][1]%MOD) + ((dp[i-1][1]*2)%MOD)%MOD)%MOD;
			dp[i][1]%=MOD;
			dp[i][0] = ((dp[i][0]%MOD) + ((dp[i-1][1]%MOD)%MOD)%MOD)%MOD;
			dp[i][0]%=MOD;
			dp[i][0] = ((dp[i][0]%MOD) + ((dp[i-1][0]*3)%MOD)%MOD)%MOD;
			dp[i][0]%=MOD;
		}
		else
		{
			dp[i][1] = ((dp[i][1]%MOD) + (dp[i-1][1]%MOD)%MOD)%MOD;
			dp[i][1]%=MOD;
			dp[i][0] = ((dp[i][0]%MOD) + ((dp[i-1][0]*3)%MOD)%MOD)%MOD;
			dp[i][0]%=MOD;
		}
	}

	long long int res = dp[n-1][0]%MOD;
	res = ((res%MOD) + (dp[n-1][1]%MOD)%MOD);
	res%=MOD;
	cout << res << '\n';

	
	/*
	int cnt = 0;
	for(int i=0;i<=1500;i++)
	{
		for(int j=0;j<=1500;j++)
		{
			int x = i + j;
			int y = i^j;
			if(x==y && x<=1244)
			{
				cnt++;
			}
		}
	}

	cout <<cnt << '\n';
	*/
	
	return 0;
}


Measured memory_bytes: 2000
def I(): return int(input())
N = I()
ans = 0
if N>=105:
    for i in range(105,N+1):
        yakusuu = []
        if i%2==1:
            for j in range(1,int(i**0.5)+1):
                if i%j==0:
                    yakusuu.append(j)
                    yakusuu.append(i//j)
        if len(yakusuu)==8:
            ans += 1
print(ans)

Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll n;
    cin>>n;
    vector<ll> v(n);
    ll sum=0;
    FOR(i,0,n){
      cin>>v[i];
      sum += v[i];
    }

    vector<ll> v1 = v;
    FOR(i,1,n){
      if(v[i-1]*v[i] == 0){

      }
      else{
        ll x = min(v[i], v[i-1]);
        v[i-1] -= x;
        v[i] -= x;
      }
    }

    FOR(i,2,n){
      if(v1[i-1]*v1[i] == 0){

      }
      else{
        ll x = min(v1[i], v1[i-1]);
        v1[i-1] -= x;
        v1[i] -= x;
      }
    }
    ll x = min(v1[0], v1[1]);
    v1[0] -= x;
    v1[1] -= x;



    ll sum1 = sum;

    FOR(i,1,n-1){
      sum+=v[i];
      sum1+=v1[i];
    }

    cout<<min(sum,sum1)<<endl;

}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define fto(i,a,b) for(int i=a; i<=b;++i)
#define fdto(i,a,b) for(int i=a; i>=b;--i)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define ll long long
#define maxn 300009
#define gb(i,j) ((i>>j)&1)
#define name "a"
#define endl '\n'
#define int ll
using namespace std;
int b[5009],a[5009][209],xd[209];

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    for(int i=2; i<=n; ++i) cin >> b[i];
    ll res=0;
    fto(i,1,n)
        fto(j,1,m)cin >> a[i][j];
    fto(xp,1,n){
        ll sum=0;
        fto(j,1,m) sum+=a[xp][j],xd[j]=xp;
        int t=m;
        res=max(res,sum);
        fto(i,xp+1,n){
            sum-=b[i];
            fto(j,1,m)if(a[i][j]>a[xd[j]][j]){
                sum=sum-a[xd[j]][j]+a[i][j];
                if(xd[j]==xp)--t;
                xd[j]=i;

            }
            if(!t)break;
            res=max(res,sum);
        }
    }
    cout << res;

    return 0;
}


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

int main()
{
	char str[5];
	cin>>str;
	
	int sum=0;
	for (int i=0;i<4;i++)
	{
		if (str[i]=='+')
			sum++;
		else
			sum--;
	}
	
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MOD = 1e9 + 7;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll sum = 0LL, ans = 0LL;
	rep(i, n){
		(ans += (a[i] * sum) % MOD) %= MOD;
		sum += a[i];
		if(sum >= MOD) sum -= MOD;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    char ch;
  cin>>ch;
  char ch1=ch+1;
  cout<<ch1<<e;
}


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 < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
ll F(ll a, ll b) {
  int keta1 = 0, keta2 = 0;
  while (0 < a) {
    keta1++;
    a /= 10;
  }
  while (0 < b) {
    keta2++;
    b /= 10;
  }
  return max(keta1, keta2);
}
int main() {
  ll N;
  cin >> N;
  queue<pair<ll, ll>> q{};
  for (ll i = 1; i <= (sqrt(N)); i++) {
    ll j = N / i;
    if (i * j == N) {
      q.push(pair<ll, ll>(i, j));
    }
  }
  ll mn = 1e+15;
  while (!q.empty()) {
    pair<ll, ll> p = q.front();
    q.pop();
    mn = min(mn, F(p.first, p.second));
  }
  cout << mn << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int n;
    cin >> n;
    int z = 1;
    map<string,int> m;
    for(int i = 0;i < n;i++){
        string a;
        cin >> a;
        auto itr = m.find(a);
        if(itr == m.end()){
            m.insert(make_pair(a,1));
        }else{
            m[a]++;
            z = max(z,m[a]);
        }
    }
    for(auto i = m.begin();i != m.end();i++){
        if(i->second == z){
            cout << i->first << endl;
        }
    }
}



Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  vector<string> s(110),t(110);
  
  cin >> N;
  for(int i=0;i<N;i++)
    cin >> s.at(i);
  cin >> M;
  for(int i=0;i<M;i++)
    cin >> t.at(i);
  int score = 0;
  for(int i=0;i<N;i++){
    int count = 0;
    for(int j=0;j<N;j++){
      if(s.at(i) == s.at(j))
        count++;
    }
    for(int j=0;j<M;j++){
      if(s.at(i) == t.at(j))
        count--;
    }
    score = max(score,count);
  }
  cout << score << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,N,H,W,ans;
  string s;
  cin>>s;
  if(s[0]=='S'){
    if(s[1]=='U'){ans=7;}
    else {ans=1;}
  }else if(s[0]=='M'){
    ans=6;
  }else if(s[0]=='T'){
    if(s[1]=='U'){ans=5;}
    else{ ans=3;}
  }else if(s[0]=='W'){
    ans=4;
  }else{
    ans=2;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  set<string> s;
  string p;
  for(int i=0;i<n;i++)
  {
    cin>>p;
    s.insert(p);
  }
  cout<<s.size();
}


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

namespace ABC144A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] AB = Console.ReadLine().Split(' ');
            int A = int.Parse(AB[0]);
            int B = int.Parse(AB[1]);
            if (A < 10 && B < 10)
            {
                Console.WriteLine(A * B);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


Measured memory_bytes: 27516
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;
	
	static final int MOD = 1_000_000_007;
	
	public static long modPow(long x, long n, long mod) {
		long res = 1;
		while (n > 0) {
			if ((n&1) == 1) res = res * x % mod;
			x = x * x % mod;
			n >>= 1;
		}
		return res;
	}

	static void solve() {
		int n = in.nextInt();
		int[] a = new int[n];
		int[] x = new int[n];
		
		for (int i=0; i<n; i++) {
			a[i] = in.nextInt();
			if ((n+1)%2 != a[i]%2) {
				out.println(0);
				return;
			}
			x[a[i]]++;
			if (x[a[i]] > 2) {
				out.println(0);
				return;
			}
		}
		
		if (x[0] > 1) {
			out.println(0);
			return;
		}
		
		out.println(modPow(2, n/2, MOD));
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 49016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,K; cin >> N >> K;
    N%=K;
    cout << min(N,abs(N-K)) << endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m = readline() |> split |> parseMap
	f = zeros(Int,n)
	a = ones(Int,n)
	f[1] = 1
	for i in 1:m
		x,y = readline() |> split |> parseMap
		a[x]-=1
		a[y]+=1
		if f[x]==1
			f[y] = 1
			if a[x]==0
				f[x] = 0
			end
		end
	end
	println(sum(f))
end

main()

Measured memory_bytes: 153496
import sys

n = int(input())
d = list(map(int, input().split()))
dic = {}
val = 0

for i in range(n):
    if d[i] in dic.keys():
        dic[d[i]] += 1
    else:
        dic[d[i]] = 1

dic = sorted(dic.items())

if len(dic) == 1:
    print(0)
    sys.exit() 

for i in range(len(dic) - 1):
    val += dic[i][1]
    if val == n//2:
        ans = (dic[i][0], dic[i+1][0])
        print(ans[1] - ans[0])
        break
    elif val > n//2:
        print(0)
        break


Measured memory_bytes: 15712
#include<iostream>
#include<fstream>

int main(){
  //std::ifstream in("input.txt");
  //std::cin.rdbuf(in.rdbuf());
  
  int K, X;
  std::cin >> K >> X;
  
  if(500 * K >= X){
    std::cout << "Yes" << std::endl;
  }else{
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for j in range(h)]

dx = [-1, 1, 0, 0]
dy = [ 0, 0,-1, 1]

q = deque([(0, 0, 0)])
used = {(0, 0)}
res = None

while q:
    i, j, cost = q.popleft()
    if i == w - 1 and j == h - 1:
        res = cost
        break
    for k in range(4):
        if not (0 <= i + dx[k] < w):
            continue
        if not (0 <= j + dy[k] < h):
            continue

        if s[j + dy[k]][i + dx[k]] == '#':
            continue
        if (i + dx[k], j + dy[k]) in used:
            continue

        used.add((i + dx[k], j + dy[k]))
        q.append((i + dx[k], j + dy[k], cost + 1))

if res:
    ans = h * w - cost - 1
    for j in range(h):
        ans -= s[j][:].count('#')
    print(ans)
else:
    print(-1)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}


struct RollingHash{
  typedef unsigned long long ull;
  string S;
  ull B;
  int len;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(string S_,ull B_=1000000007LL):
    S(S_),B(B_),len(S.length()),hash(len+1),p(len+1){
    hash[0]=0;p[0]=1;
    for(int i=0;i<len;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l,r)
  ull find(int l,int r){
    return hash[r]-hash[l]*p[r-l];
  }
};

unordered_map<uint64, int32> mpf, mpb, mp; // 前が欠けてる，後ろが欠けてる, 欠けてない
RollingHash r;
int main(void){
	int32 N, M;
	cin >> N >> M;

	REP(i, N){
		string s;
		cin >> s;
		r = RollingHash(s);
		mp[r.find(0, s.size())]++;
		FOR(j, 1, s.size()){
			mpf[r.find(j, s.size())]++;
			mpb[r.find(0, j)]++;
		}
	}
	REP(i, M){
		string s;
		cin >> s;
		int32 cq = -1, ca = -1;
		REP(j, s.size()){
			if(s[j] == '?') cq = j;
			if(s[j] == '*') ca = j;
		}
		int32 res = 0;
		for(char c = 'a';c <= 'z';c++){
			if(cq != -1) s[cq] = c;
			r= RollingHash(s);
			if(ca == -1){
				res += mp[r.find(0, s.size())];
			}else if(ca == 0){
				res += mpf[r.find(1, s.size())];
				res += mp[r.find(1, s.size())];
			}else{
				res += mpb[r.find(0, s.size()-1)];
				res += mp[r.find(0, s.size()-1)];
			}
			if(cq == -1) break;
		}
		cout << res << endl;
	}
}



Measured memory_bytes: 248664
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define INF 1e15
int main()
{
string s;cin>>s;
ll hash[1000]={0};
for(int  i=0;i<s.length();i++)
hash[s[i]-'0']++;

ll count=0;
ll n=s.length();
for(int i=0;i<1000;i++)
count+=(hash[i]*(hash[i]-1))/2;

ll res=(((n*(n-1))/2))-count+1;
cout<<res<<endl;;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e6+9;
ll x,y;
int main()
{
    FASTINOUT;
    cin>>x>>y;
    for (ll i=0;i<=x;i++){
        for (ll j=0;j<=x;j++){
            ll m=10000*i+1000*j;

            if (m<=y&&(y-m)%5000==0 &&i+j+(y-m)/5000==x)
            {
                cout<<i<<" "<<(y-m)/5000<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s;cin>>s;
  int q;cin>>q;
  string ans=s;
  bool order=true;
  rep(i,q){
    int t;cin>>t;
    if(t==1){
      order=!order;
    }else{
      int f;cin>>f;
      char c;cin>>c;
      bool begin=false;
      if((f==1&&order)||(f==2&&!order)){
        begin=true;
      }
      if(begin){
        ans.insert(0,1,c);
      }else{
        ans.push_back(c);
      }
    }
  }
  if(!order){
    reverse(ans.begin(),ans.end());
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1084