akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(ll i=a;i<b;i++)
#define bFor(i,a,b) for(ll i=a;i>=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 mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
int main(){
  ll N,x;
  cin>>N;
  set<ll> se;
  rep(i,N){
    cin>>x;
    se.insert(x);
  }
  x=N-se.size();
  if(x%2){
    cout<<se.size()-1<<endl;
  }else{
    cout<<se.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

struct Edge{
	int to,cap,rev;
	Edge(){}
	Edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
};

vector<Edge> G[210];
bool used[210];

void add_edge(int from,int to,int cap){
	G[from].push_back(Edge(to,cap,G[to].size()));
	G[to].push_back(Edge(from,0,G[from].size()-1));
}

int dfs(int v,int t,int f){
	if(v==t) return f;
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		Edge &e =G[v][i];
		if(!used[e.to]&&e.cap>0){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow=0;
	for(;;){
		for(int i=0;i<210;i++){
			used[i]=0;
		}
		int f=dfs(s,t,1e9);
		if(f==0)return flow;
		flow+=f;
	}
}

int main(){
	int n; cin >> n;
	vector<int> a(n),b(n),c(n),d(n);
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i];
	}
	for(int i=0;i<n;i++){
		cin >> c[i] >> d[i];
	}
	for(int i=0;i<n;i++){
		add_edge(2*n,i,1);
	}
	for(int i=0;i<n;i++){
		add_edge(n+i,2*n+1,1);
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(a[i]<c[j]&&b[i]<d[j])add_edge(i,n+j,1);
		}
	}
	cout << max_flow(2*n,2*n+1) << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
using namespace std;
#define inf (1<<27)
#define rep(i,n)for(int i=0;i<n;i++)
int cost[100][100];
int n,m,s,g1,g2,b1,b2,c;
int main() {
	while(scanf("%d %d %d %d %d",&n,&m,&s,&g1,&g2),n) {
		fill(cost[0],cost[0]+100*100,inf);
		rep(i,n)cost[i][i]=0;
		rep(i,m) {
			scanf("%d %d %d",&b1,&b2,&c);
			cost[b1-1][b2-1]=c;
		}
		rep(k,n)rep(i,n)rep(j,n) {
			cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
		}
		int res=inf;
		rep(k,n) {
			res=min(res,cost[s-1][k]+cost[k][g1-1]+cost[k][g2-1]);
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 1064
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long a,b,c,d,s=0,t=0,p=0,q=0,m=0,i=0,j=0,g=0,h=0,y=0,cnt=0;
	cin>>a>>b>>c>>d;
	s=(a-1)/c;
	t=b/c;
	p=(a-1)/d;
	q=b/d;
	i=c;
	j=d;
	  m=c%d;
	while(m!=0)
	{   
	   
		c=d;
		d=m;
		  m=c%d;
		  y++;		
	}

	g=i*j/d;
	h=b/g-(a-1)/g;	
	cout<<(b-a+1)-(t-s)-(q-p)+h;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int main(){
  char str[1111];
  int temp;

  scanf("%s",str);

  int len = strlen(str);

  for(int i=0;i<len;i++){
    temp = (int)str[i];
    if(temp > 'C'){
      temp = (temp + 23) % (int)('Z' + 1) + (int)'A';
    } else {
      temp = (temp + 23) % (int)'A' + (int)'A';
    }
    str[i] = (char)temp;
  }

  printf("%s\n",str);

  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cmath>
#define N 3
#define N1 16
using namespace std;
void func(int,int,int);
int n,k,data[N][N],memo[N1][N][N];
int dy[N+1]={-1,0,1,0};
int dx[N+1]={0,1,0,-1};
bool visited[N1][N][N];
char s,t,b;

int main(){
  while(1){
    cin >> n;
    if(!n) break;
    cin >> s >> t >> b;
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
	data[i][j]=0;
	for(int k=0;k<N1;k++){
	  memo[k][i][j]=0;
	  visited[k][i][j]=false;
	}
      }
    }
    data[(t-'A')/N][(t-'A')%N]=1;
    data[(b-'A')/N][(b-'A')%N]=-1;
    func((s-'A')/N,(s-'A')%N,0);
    k=pow(4,n);
    printf("%.8f\n",1.0*memo[0][(s-'A')/N][(s-'A')%N]/k);
  }
  return 0;
}

void func(int y,int x,int d){
  visited[d][y][x]=true;
  if(d==n){
    if(data[y][x]==1) memo[d][y][x]=1;
    return ;
  }
  for(int i=0;i<N+1;i++){
    int ny=y+dy[i],nx=x+dx[i];
    if(ny<0||nx<0||N<=ny||N<=nx||data[ny][nx]==-1){
      if(visited[d+1][y][x]==false) func(y,x,d+1);	
      memo[d][y][x]+=memo[d+1][y][x];
    }
    else{
      if(visited[d+1][ny][nx]==false) func(ny,nx,d+1);
      memo[d][y][x]+=memo[d+1][ny][nx];
    }
  }
}

Measured memory_bytes: 1228
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define maxn 100005
using namespace std;
typedef long long ll;
struct nod
{
	ll dis,id;
	nod(ll x,ll y)
	{
		dis=x;
		id=y;
	}
	nod(){}
};
bool operator<(nod a,nod b)
{
	return a.dis>b.dis;
}
int n,m,tot;
int head[maxn],nex[maxn<<2],to[maxn<<2],deg[maxn];
ll val[maxn<<2];
void add(int x,int y,ll z)
{
	to[++tot]=y; val[tot]=z; nex[tot]=head[x]; head[x]=tot;
}
ll dis[maxn];
bool vis[maxn],flag=true;
priority_queue<nod> q;
void spfa(int now)
{
//	q.push(nod(0,start)); dis[start]=0;
//
//	while(!q.empty())
//	{
//		int now=q.top().id; q.pop();
//		if(vis[now]) continue;
//		vis[now]=1;
//
//		for(int i=head[now];i;i=nex[i])
//		{
//			if(dis[to[i]]==-1 || dis[to[i]]>dis[now]+val[i])
//			{
//				dis[to[i]]=dis[now]+val[i];
//				q.push(nod(dis[to[i]],to[i]));
//			}
//		}
//	}
	if(!flag) return;
	if(vis[now]) return;
	vis[now]=1;
	for(int i=head[now];i;i=nex[i])
	{
		if(!vis[to[i]])
		{
			if(dis[to[i]]==-1 || dis[to[i]]!=dis[now]+val[i])
			{
				dis[to[i]]=dis[now]+val[i];
//				vis[to[i]]=1;
				spfa(to[i]);
			}
		}
		else
		{
			if(dis[to[i]]!=dis[now]+val[i])
			{
				flag=false;
				return;
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y; ll z;
		scanf("%d%d%lld",&x,&y,&z);
		add(x,y,z);
		add(y,x,-z);
	}

	memset(dis,-1,sizeof(dis));

	for(int i=1;i<=n;i++)
		if(dis[i]==-1)
		{
			spfa(i);
			if(!flag)
			return printf("No\n"),0;
		}

	for(int i=1;i<=n;i++)
	{
		for(int j=head[i];j;j=nex[j])
		{
			if(dis[to[j]]!=dis[i]+val[j])
			{
				return printf("No\n"),0;
			}
		}
	}

	printf("Yes\n");
}


Measured memory_bytes: 10368
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	VE a(n); rep(i, n)cin >> a[i];
	if (n <= k)cout << 1 << endl;
	else {
		int tmp = n - k; int tmp2 = k - 1;
		cout << (tmp + tmp2 - 1) / tmp2 + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
int n;
int a[207];
int ans;

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	bool flg = 1;
	for(int i = 1; i <= n; i++) {
		if(a[i] & 1) {
			flg = 0; break;
		}
	}
	while(flg) {
		ans++;
		for(int i = 1; i <= n; i++) {
			a[i] /= 2;
			if(a[i] & 1) {
				flg = 0; break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

typedef unsigned int uint;
#define BUF_SIZE (20)

int main(void)
{
	uint a;
	uint b;
	uint c;
	uint i;

	scanf("%d %d %d", &a, &b, &c);

	for(i=1; i<=b; i++){
		if(((a*i) % b) == c){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
    
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 100010;

int n, m;
vector<int> e[MAXN];
int bio[100][100], cnt, k, vis[MAXN], col[MAXN];
llint sol;
bool bip;
int bcomp, ncomp, tot_comp;

void dfs(int x) {
  for (int y : e[x]) {
    if (col[y] == -1) {
      col[y] = col[x] ^ 1;
      dfs(y);
    }
    else if (col[x] == col[y])
      bip = false;
  }
}

// void dfs(int a, int b) {
//   bio[a][b] = 1;
//   for (int x : e[a])
//     for (int y : e[b])
//       if (!bio[x][y])
// 	dfs(x, y);
// }

int main(void) {
  scanf("%d %d",&n,&m);
  REP(i, m) {
    int u, v;
    scanf("%d %d",&u,&v);
    --u;
    --v;
    e[u].push_back(v);
    e[v].push_back(u);
  }

  REP(i, n)
    if (e[i].empty())
      ++k;

  sol += k;
  sol += (llint)k * (k - 1);
  sol += 2 * (llint)k * (n - k);

  memset(col, -1, sizeof(col));
  REP(i, n) {
    if (e[i].empty()) continue;
    if (col[i] != -1) continue;

    bip = true;
    col[i] = 0;
    dfs(i);

    if (bip)
      ++bcomp;
    else
      ++ncomp;
    ++tot_comp;
  }

  //TRACE(sol _ bcomp _ ncomp);

  sol += (llint)tot_comp * tot_comp;
  sol += (llint)bcomp * bcomp;

  cout << sol << endl;
  
  return 0;
}


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

int main(){

  int n,k;
  scanf("%d %d",&n,&k);  
  double ans=0;

  for(int i=1;i<=n;i++){
    int now=i;
    double temp=1.0/n;
    while(now<k){
      now*=2;
      temp/=2;
    }
    ans+=temp;
  }
  printf("%.12f\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    int w,a,b;
    cin>>w>>a>>b;
    if(a<=b){
        if(a+w>=b) cout<<0<<endl;
        else cout<<b-a-w<<endl;
    }
    else{
        if(b+w>=a) cout<<0<<endl;
        else cout<<a-b-w<<endl;
    }
    getchar();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 5020;
const int mod=1e9+7;
typedef long long ll;
inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int sub(int a,int b){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}

int g[N][2];
int f[N][2];
int ans=0, n, a, b;

int main()
{
	cin >> n >> a >> b;
	if(a>b)swap(a,b);
	if(b>1){
		f[0][0]=f[0][1]=1;
		for(int i=1;i<=n;i++){
			for(int k=0;k<2;k++){
				for(int j=1;j<=i;j++){
					if(k==0&&j<a)continue;
					f[i][k]=add(f[i][k],f[i-j][k^1]);
				}
			}
		}
		f[0][0]=0;
		for(int i=1;i<n;i++){
			if(i<a)g[i][0]=add(g[i][0],1);
			for(int j=1;j<min(i,a);j++){
				g[i][0]=add(g[i][0], g[i-j][1]);
			}
			if(i<b)g[i][1]=add(g[i][1], add(f[i-1][0],f[i-1][1]));
			for(int j=1;j<min(i,b);j++){
				int w=j==1?1:add(f[j-2][0],f[j-2][1]);
				g[i][1]=add(g[i][1],1ll*g[i-j][0]*w%mod);
			}
			if(n-i<b)ans=add(ans, mul(g[i][0], add(f[n-i-1][0],f[n-i-1][1])));
			if(n-i<a)ans=add(ans, g[i][1]);
		}
	}
	cout << sub(qpow(2,n), ans) << endl;
}


Measured memory_bytes: 3656
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>
 
using namespace std;
 
 
 
int main(){
 
    int n,tmp,row_sum,col_sum[11];
 
    while(true){
        scanf("%d",&n);
        if(n == 0)break;
 
        for(int i=0; i < 11; i++)col_sum[i] = 0;
 
        for(int i=0; i < n; i++){
            row_sum = 0;
            for(int k=0; k < n; k++){
                scanf("%d",&tmp);
                printf("%5d",tmp);
                row_sum += tmp;
                col_sum[k] += tmp;
            }
            printf("%5d\n",row_sum);
            col_sum[n] += row_sum;
        }
        for(int i=0; i <= n; i++)printf("%5d",col_sum[i]);
        printf("\n");
    }
 
    return 0;
}


Measured memory_bytes: 2624
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    X,Y=map(int,input().split())
    c=0
    while X<=Y:
        c+=1
        X*=2
    print(c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <iostream>

using namespace std;

void solve()
{
	int coin[] = {1, 5, 10, 50, 100, 500};
	int sum = 0;
	for (int i = 0; i < 6; ++i)
	{
		int n;
		cin >> n;
		sum += n * coin[i];
	}
	if (sum >= 1000)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}
}

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

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

using num = modnum<998244353>;

vector<num> fact, ifact;
void init(int N) {
	fact.resize(N), ifact.resize(N);
	fact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = fact[i-1] * i;
	}
	ifact.back() = fact.back().inv();
	for (int i = N-1; i >= 1; i--) {
		ifact[i-1] = ifact[i] * i;
	}
}

num ncr(int n, int r) {
	return fact[n] * ifact[r] * ifact[n-r];
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n, m;
	cin >> n >> m;
	if (n < m) swap(n, m);
	const int N = n+m+10;
	init(N);
	num ev = 0;
	for (int i = 1; i <= m; i++) {
		num cur = ncr(n-i+m-i, n-i) * ncr(i+i, i);
		ev += cur;
	}
	ev /= 2;
	ev /= ncr(n+m, n);
	num ans = ev + n;
	cout << ans << '\n';
}


Measured memory_bytes: 11108
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s; cin >> s;
	if(s == "SAT") println("1");
	else if(s == "SUN") println("7");
	else if(s == "MON") println("6");
	else if(s == "TUE") println("5");
	else if(s == "WED") println("4");
	else if(s == "THU") println("3");
	else println("2");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

int main(){
  cout << fixed << setprecision(15);
  //int ans = 0;
  string ans = "No";

  int n; cin >> n;
  int odd = 0, four = 0;
  rep(i,n){
    int x; cin >> x;
    if (x % 4 == 0) four++;
    if (x % 2 == 1) odd++;
  }
  if (odd <= four) ans = "Yes";
  if (four + odd == n && four + 1 == odd) ans = "Yes";

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

Measured memory_bytes: 3632
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * Created on 2018/03/02 19:20.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        List<String> S = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            S.add(sc.next());
        }
        Collections.sort(S);
        System.out.println(String.join("", S));
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
	static_assert(D >= 1, "Vector dimension must be greater than zero!");
	template<typename... Args>
	Vec(int n, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template<typename T>
struct Vec<1, T> : public vector<T> {
	Vec(int n, const T& val = T()) : vector<T>(n, val) {}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int nbRow, nbCol;
	cin >> nbRow >> nbCol;
	Vec<2, int> grid(nbRow+1, nbCol+1, 0);
	int exitRow, exitCol;
	for (int row = 1; row <= nbRow; ++row) {
		for (int col = 1; col <= nbCol; ++col) {
			char c; cin >> c;
			if (c == 'o') grid[row][col] = 1;
			if (c == 'E') {
				exitRow = row;
				exitCol = col;
			}
		}
	}

	int mainRow = nbRow-exitRow, ecartRow = exitRow-1;
	if (mainRow < ecartRow) {
		swap(mainRow, ecartRow);
		reverse(1+all(grid));
	}

	int mainCol = nbCol-exitCol, ecartCol = exitCol-1;
	if (mainCol < ecartCol) {
		swap(mainCol, ecartCol);
		for (auto &x : grid) reverse(1+all(x));
	}

	for (int row = 1; row <= nbRow; ++row) {
		for (int col = 1; col <= nbCol; ++col) {
			grid[row][col] += grid[row-1][col]+grid[row][col-1]-grid[row-1][col-1];
		}
	}
	
	Vec<2, int> dp(nbRow+1, nbCol+1);
	int answer = 0;
	for (int debRow = 1; debRow <= nbRow-mainRow; ++debRow) {
		for (int debCol = 1; debCol <= nbCol-mainCol; ++debCol) {
			int endRow = debRow+mainRow, endCol = debCol+mainCol;
			auto get = [&] (int r1, int c1, int r2, int c2) {
				chmax(r1, debRow);
				chmax(c1, debCol);

				chmin(r2, endRow);
				chmin(c2, endCol);

				if (r1 > r2 || c1 > c2) return 0;
				--r1; --c1;
				return grid[r2][c2]-grid[r1][c2]-grid[r2][c1]+grid[r1][c1];
			};
			for (int row = debRow; row <= endRow; ++row) {
				for (int col = debCol; col <= endCol; ++col) {
					if (row == debRow && col == debCol) {
						dp[row][col] = 0; continue;
					}
					int &res = dp[row][col]; res = 1e5;
					if (col > debCol) {
						int under = get(row+1, col-1, endRow, col-1); 
						chmin(res, dp[row][col-1]+under);
					}
					if (row > debRow) {
						int slide = get(row-(ecartRow+1), col+(ecartCol+1), row-(ecartRow+1), 1e5); 
						chmin(res, dp[row-1][col]+slide);
					}
				}
			}
			chmax(answer, get(debRow,debCol,endRow,endCol) - dp[endRow][endCol]);
		}
	}
	cout << answer << "\n";
}


Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[100005];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	if(n==1){
		cout << 1 << endl;
		return 0;
	}
	int counter = 1;
	sort(a,a+n);
	int ans = 0;
	for(int i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			counter++;
		}
		if(a[i]!=a[i+1]){
			if(counter%2==1){
				ans = ans + 1;
			}
			counter = 1;
		}
	}
	if(counter%2==1){
		ans = ans + 1;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
int N,S;
cin >>N;
S=0;
rep(i,N){
  int l,r;
  cin>>l>>r;
  
S+=r-l+1;
  

}
cout<<S<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n, ans = 0;
  string s;
  cin >> n >> s;
  for(int i = 1; i < n-1; i++){
    set<char> a, b;
    for(int j = 0; j < i; j++){
      a.insert(s[j]);
    }
    for(int j = i; j < n; j++){
      b.insert(s[j]);
    }
    int cnt = 0;
    for(auto itr = a.begin(); itr != a.end(); itr++){
      if(b.count(*itr)){
        cnt++;
      }
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  system("pause");
}


Measured memory_bytes: 504
import sys
import itertools
readline = sys.stdin.readline

while True:
    N = int(readline())
    M = int(readline())
    if N == 0 and M == 0:
        break
    pairs = set()
    for _ in xrange(M):
        a, b = tuple(int(x) for x in readline().split())
        pairs.add((a, b))
        pairs.add((b, a))
    cnt = 0
    for i in xrange(2, N + 1):
        if (1, i) in pairs:
            cnt += 1
        else:
            for j in xrange(2, N + 1):
                if (1, j) in pairs and (j, i) in pairs:
                    cnt += 1
                    break
    print cnt

Measured memory_bytes: 6344
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,sum,b,min;
  sum=0; b=0;
  cin >> N;
  vector<long long> a(200009);
  for(long long i=0;i<N;i++){cin >> a[i];}
  for(long long i=0;i<N;i++){sum+=a[i];}
  min=100000000;
  if(N==2){min=abs(a[0]-a[1]);}
  else{
    for(long long i=0;i<N-2;i++){
      b+=a[i];
      if(min>abs(sum-2*b)){min=abs(sum-2*b);}
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {// Main
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n =sc.nextInt();
		long k = sc.nextLong();
		long[][] ar = input( n , n );
		
		ar = matrix_power(ar, k);
		long ans = 0 ;
		for(long[] key : ar) {
			for(long val : key) {
				ans += val %mod;
				ans %= mod;
			}
		}
		System.out.println(ans);
	}
		static long mod = 1000000007;
	public static long[][] matrix_power(long[][] ar , long k ){
		if(k==1) {
			return ar;
		}
		long [][] temp = matrix_power(ar, k/2);
		temp = matrix_exp(temp , temp);
		if(k%2==1) {
			temp = matrix_exp(temp, ar);
		}
		return temp;
	}
	public static long[][] matrix_exp(long[][] a , long[][]  b){
		int n = a.length;
		long[][] ans = new long[n][n];
		for(int i = 0 ;i < n;i++) {
			for(int j = 0 ;j < n;j++) {
				long temp =0  ;
				for(int k = 0 ;k < n;k++) {
					temp =(temp %mod +(a[i][k]*b[k][j] )%mod )%mod;
				}
				ans[i][j]=temp%mod;
			}
		}
		return ans;
	}
	public static long[][] input(int n, int m) throws Exception {

		long[][] arr = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {

				arr[i][j] = sc.nextInt();
			}
		}
		return arr;
	}


}



Measured memory_bytes: 42224
#include <stdio.h>
static void inc(char *pCh, int h, int w, int i, int j)
{
  if(i<0 || i>=h) return;
  if(j<0 || j>=w) return;
  *pCh = *pCh + 1;
}
int main(void)
{
  char in[50][51];
  char out[50][51]={0};
  int h,w;
  int i,j;
  scanf("%d %d",&h,&w);
  for(i=0;i<h;++i){
    scanf("%s", in[i]);
  }
  for(i=0;i<h;++i){
    for(j=0;j<w;++j){
    if(in[i][j]=='#'){
      int di,dj;
      for(di=-1;di<=1;++di){
        for(dj=-1;dj<=1;++dj){
          if(i+di<0 || i+di>=h) continue;
          if(j+dj<0 || j+dj>=w) continue;
          ++out[i+di][j+dj];
        }
      }
    }
    }
  }
  for(i=0;i<h;++i){
    for(j=0;j<w;++j){
      switch(in[i][j]){
        case '#':
          out[i][j]='#';
          break;
        case '.':
          out[i][j]+='0';
          break;
      }
    }
  }
  for(i=0;i<h;++i){
    printf("%s\n", out[i]);
  }
  return 0;
}


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n;
	cin >> n;
	n %= 10;
	if(n == 2 || n == 4 || n == 7 || n == 5 || n == 9) {
		finish("hon");
	} else if (n == 3) {
		finish("bon");
	} else {
		finish("pon");
	}
}


Measured memory_bytes: 3648
from collections import defaultdict

n = int(input())
edges = {}
connected_nodes = defaultdict(list)

for _ in range(n-1):
  u, v, w = map(int, input().split())
  if u > v:
    u, v = v, u
  edges[(u,v)] = w
  connected_nodes[u].append(v)
  connected_nodes[v].append(u)

#print(edges)
#print(connected_nodes)

color = {}
color[1] = 0

visiting = [1]

while edges:
  node = visiting.pop()
  #print('visiting node {0} with edges {1}, colors {2} '.format(node, edges, color))
  #es = list(map(lambda nn: (node, nn) if node < nn else (nn, node) ,connected_nodes[node]))
  for nn in connected_nodes[node]:
    edge = (node, nn) if node < nn else (nn, node)
    if edge in edges:
      w = edges[edge]
      del edges[edge]
      visiting.append(nn)
      if w % 2 == 0:
        color[nn] = color[node]
      else:
        color[nn] = 1 - color[node]

for node in sorted(color.keys()):
  print(color[node])
#def dfs(root, edges, connected_nodes, color):


Measured memory_bytes: 54860
import Control.Applicative
import Control.Monad
import Data.List
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve n <$> replicateM n f >>= print
    main
  where
    f = map read <$> words <$> getLine

solve :: Int -> [[Int]] -> Int
solve n xs = let tm = V.fromList . concat $ map f xs
                 cm = V.replicate (n * n) (-1) :: Vector Int
             in fst $ foldl' (g tm []) (0, cm) [0 .. n*n-1]
  where
    f (x:y:rs) = n * y + x : f rs
    f [] = []
    g tm ac (c, m) i
      | m ! i == (-1) = g tm (i:ac) (c, m // [(i, c)]) (tm ! i)
      | m ! i == c = (c + 1, m)
      | otherwise = (c, m // (map (\j -> (j, m ! i)) ac))



Measured memory_bytes: 15276
#include <cstdio>
#include <vector>

using namespace std;

struct Edge
{
    long a, b, y;
};

struct Merge
{
    Edge e;
    long za, zb, l;
};

bool operator<(const Edge& e1, const Edge& e2)
{
    if (e1.y != e2.y) return e1.y < e2.y;
    if (e1.a != e2.a) return e1.a < e2.a;
    if (e1.b != e2.b) return e1.b < e2.b;
    return false;
}

class UnionFind
{
public:
    explicit UnionFind(long n) : data_(n, -1) {}

    long root(long i) {
        return (data_[i] >= 0) ? (data_[i] = root(data_[i])) : i;
    }

    bool unify(long i, long j) {
        i = root(i);
        j = root(j);
        if (i == j)
            return false;
        if (-data_[i] >= -data_[j]) {
            data_[i] += data_[j];
            data_[j] = i;
        } else {
            data_[j] += data_[i];
            data_[i] = j;
        }
        return true;
    }

private:
    vector<long> data_;
};

int main()
{
    long n, m;
    scanf("%ld%ld", &n, &m);
    vector<long> x(n);
    for (long i = 0; i < n; i++)
        scanf("%ld", &x[i]);
    vector<Edge> e(m);
    for (long i = 0; i < m; i++) {
        scanf("%ld%ld%ld", &e[i].a, &e[i].b, &e[i].y);
        --e[i].a;
        --e[i].b;
    }

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

    vector<long> z = x;

    UnionFind uf(n);
    vector<Merge> merges;
    vector<long> last(n, -1);

    for (long i = 0; i < m; i++) {
        long a = uf.root(e[i].a);
        long b = uf.root(e[i].b);
        if (uf.unify(a, b)) {
            if (last[a] >= 0)
                merges[last[a]].l = merges.size();
            if (last[b] >= 0)
                merges[last[b]].l = merges.size();
            last[uf.root(a)] = merges.size();
            merges.push_back({e[i], z[a], z[b], -1});
            z[uf.root(a)] = z[a] + z[b];
        }
    }

    for (long i = merges.size() - 1; i >= 0; i--) {
        auto& mg = merges[i];
        if (mg.l >= 0 && merges[mg.l].za > 0)
            continue;
        if (mg.e.y <= mg.za + mg.zb)
            continue;
        mg.za = mg.zb = 0;
    }

    UnionFind uf2(n);
    for (auto& mg : merges) {
        if (mg.za > 0) {
            uf2.unify(mg.e.a, mg.e.b);
        }
    }
    vector<long> w(n, 0);
    for (long i = 0; i < n; i++)
        w[uf2.root(i)] += x[i];
    long ans = 0;
    for (long i = 0; i < m; i++)
        if (e[i].y > w[uf2.root(e[i].a)]) ++ans;
    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 13808
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    double a;
    double b;
    double h;
    double m;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        a = sc.nextDouble();
        b = sc.nextDouble();
        h = sc.nextDouble();
        m = sc.nextDouble();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        
        double m_deg = m * 6.0;
        double h_deg = 0.5 * (60.0 * h + m);
        double deg = 0;
        if (h_deg > m_deg) {
            deg = h_deg - m_deg;
        } else {
            deg = m_deg - h_deg;
        }

        if (deg > 180.0) {
            deg = 360 - deg;
        }

        double ans = Math.sqrt(Math.pow(a, 2.0) + Math.pow(b, 2.0) - (2.0 * a * b * Math.cos(Math.toRadians(deg))));

        System.out.println(ans);
    }
}

Measured memory_bytes: 37556
#include<bits/stdc++.h>
#define maxn 100010
using namespace std;

int a[maxn],n;
int main(){
	scanf("%d",&n);
	if(n<1200)
		puts("ABC");
	else if(n<2800)
		puts("ARC");
	else
		puts("AGC");
	
	return 0;
}

Measured memory_bytes: 256
S=list(map(int, list(input())))
N=len(S)

S1=[i%2 for i in range(N)]
S2=[(i+1)%2 for i in range(N)]

counter1=0
for i in range(N):
  if S[i]!=S1[i]:
    counter1+=1
    
counter2=0
for i in range(N):
  if S[i]!=S2[i]:
    counter2+=1
    
print(min(counter1, counter2))

Measured memory_bytes: 52744
class Bucket
  INF = 2 ** 31 - 1

  def initialize(n)
    @arr = Array.new(n){ INF }
    bucket_size = Math.sqrt(n).ceil
    @bucket = Array.new(bucket_size) { INF }
  end

  def update(i, val)
    @arr[i] = val
    bucket_idx = to_bucket_idx(i)

    if val < @bucket[bucket_idx]
      @bucket[bucket_idx] = val
    else
      @bucket[bucket_idx] = find_min(@arr, bucket_idx * @bucket.size, (bucket_idx + 1) * @bucket.size - 1)
    end
  end

  def query(i, j)
    i_bucket_idx = to_bucket_idx(i)
    j_bucket_idx = to_bucket_idx(j)

    return find_min(@arr, i, j) if (j_bucket_idx - i_bucket_idx) <= 2

    val = []
    val << find_min(@arr, i, (i_bucket_idx + 1) * @bucket.size - 1)
    val << find_min(@arr, (j_bucket_idx - 1) * @bucket.size, j)
    val << find_min(@bucket, i_bucket_idx + 1, j_bucket_idx - 1)

    val.min
  end

  private

  def find_min(arr, start_idx, end_idx)
    min = arr[start_idx]
    (start_idx..end_idx).each{|i| min = arr[i] if !arr[i].nil? && arr[i] < min }
    min
  end

  def to_bucket_idx(i)
    i / @bucket.size
  end
end

n, q = gets.split.map(&:to_i)
b = Bucket.new(n)

q.times do
  com, x, y = gets.split.map(&:to_i)

  case com
  when 0
    b.update(x, y)
  when 1
    puts b.query(x, y)
  end
end

Measured memory_bytes: 9648
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll r, g, b, n;
    cin >> r >> g >> b >> n;

    ll ans = 0;
    exrep(i, 0, n/r) {
        exrep(j, 0, n/g) {
            if(r*i + g*j > n) {
                continue;
            }
            ll x = n - (r*i + g*j);
            if(x%b == 0) {
                ans++;
            }
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long int
int main() {
   
   ll a,b;
   cin>>a>>b;
   
   string str1,str2;
   
   for(ll i=0;i<b;i++)
   str1+=(char)('0'+a);
   
   for(ll i=0;i<a;i++)
   str2+=(char)('0'+b);
   
   if(str1<str2)
   cout<<str1;
   else
   cout<<str2;
}

Measured memory_bytes: 256
n,m = list(map(int,input().split()))
fav_list = list()

for i in range(n):
    fav_list.append(list(map(int,input().split())))
    
common = fav_list[0][1:]
for i in range(len(fav_list) ):
    common = set(common) & set(fav_list[i][1:])
    
print(len(common))

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

using namespace std;

typedef long long int ll;

#define FOR(i,l,r) for(i=l;i<r;i++)

#define REP(i,n) FOR(i,0,n)

#define ALL(x) x.begin(),x.end()

#define P pair<ll,ll>

#define F first

#define S second

signed main(){

  ll N,i,D,ans=0,X,Y;cin>>N>>D;
  REP(i,N){
    cin>>X>>Y;
    if(X*X+Y*Y<=D*D)ans++;
  }

  cout<<ans<<endl;

  return 0;

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' ';pr(b);}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' ';pr(b,c);}
template<C T,C T2,C T3,C T4>void pr(T a,T2 b,T3 c,T4 d){cout<<a<<' ';pr(b,c,d);}
template<C T>void PR(T a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  int t[n],a[n];
  rep(i,n) R t[i];
  rep(i,n) R a[i];
  int d[n+1],M=0;
  rep(i,n) {
    d[i]=min(t[i],a[i]);
    M=max(M,max(t[i],a[i]));
  }
  d[n]=0;
  bool f=0;
  ll ans=1;
  rep(i,n) {
    if(d[i]==M) f=1;
  }
  if(!f) {
    pr(0);
    return;
  }
  REP(i,1,n) {
    if(d[i-1]==d[i]&&d[i]<=d[i+1]) {
      ans*=d[i];
      ans%=MAX;
    }
  }
  rrep(i,n-1) {
    if(d[i-1]>d[i]&&d[i]==d[i+1]) {
      ans*=d[i];
      ans%=MAX;
    }
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int a, b, w;
    cin >> w >> a >> b;
    if (a > b + w)
        cout << a - b - w << endl;
    else if (b > a + w)
        cout << b - a - w << endl;
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from heapq import heappop, heappush

bigger = []
smaller = []

def modify(bigger, smaller, a: int, b: int, mid: int, ans: int):
    if not bigger and not smaller:
        heappush(smaller, -a)
        mid = a
    elif not bigger:
        if a < -smaller[0]:
            heappush(bigger, -heappop(smaller))
            heappush(smaller, -a)

            ans += abs(-smaller[0] - mid)

        else:
            heappush(bigger, a)
    else:
        if a < -smaller[0]:
            tmp = -heappop(smaller)
            heappush(smaller, -a)
            if (len(smaller) + len(bigger)) % 2:
                ans += abs(-smaller[0] - mid)
        elif a > bigger[0]:
            tmp = heappop(bigger)
            heappush(bigger, a)
        else:
            tmp = a

        if len(smaller) == len(bigger):
            heappush(smaller, -tmp)
        else:
            heappush(bigger, tmp)

    ans += (abs(-smaller[0] - a) + b)
    mid = -smaller[0]

    return mid, ans

q = ni()
mid = ans = 0

for _ in range(q):
    # judge process
    query = ns()
    if query.startswith("1"):
        _, a, b = map(int, query.split())
        mid, ans = modify(bigger, smaller, a, b, mid, ans)

    else:
        print(mid, ans)

Measured memory_bytes: 11112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,a,maxa = 0,mina = 1000;
    cin >> n;
    rep(i, n){
        cin >> a;
        if (a < mina) {
            mina = a;
        }
        if (a > maxa) {
            maxa = a;
        }
    }
    cout << maxa - mina << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    int N;
    cin >> N;
    vector<string> S;
    string s;
    vector<string> ans_list;
    for(int i = 0;i < N;i++){
        cin >> s;
        S.push_back(s);
    }

    sort(S.begin(), S.end());
    string o = S.at(0);
    string t;
    int count = 0;
    int max_count = 0;
    for(int i = 1;i < N;i++){
        t = S.at(i);
        if(o == t){
            count++;
        }else{
            if(count == max_count){
                ans_list.push_back(o);
            }else if(count > max_count){
                ans_list.erase(ans_list.begin(), ans_list.end());
                ans_list.push_back(o);
                max_count = count;
            }
            count = 0;
        }
        o = t;
    }
    if(count == max_count){
        ans_list.push_back(o);
    }else if(count > max_count){
        ans_list.erase(ans_list.begin(), ans_list.end());
        ans_list.push_back(o);
    }
    sort(ans_list.begin(), ans_list.end());
    for(int i = 0;i < ans_list.size();i++){
        cout << ans_list.at(i) << endl;
    }


            
}

Measured memory_bytes: 16240
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# import numpy as np
# from itertools import *
# from collections import *

# S = input()
# N = int(input())
# K, N = [int(x) for x in input().split()]

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

a = [False] * len(A)
now = 1
arrive_list = []

while True:
    arrive_list.append(now)
    if a[now-1]:
        break
    else:
        a[now-1] = True
    now = A[now-1]

r = arrive_list.index(now)
K -= r

if K <= 0:
    print(arrive_list[K+r])
    exit(0)

K %= (sum(a)-r)
print(arrive_list[K+r])


Measured memory_bytes: 32328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 998244353;

// + - * / ^
int mod(int a)
{
	int res = a % MOD;
	if(res < 0) {
		return res + MOD;
	}
	return res;
}
int mul_mod(int a, int b)
{
	ll res = ((ll)a * (ll)b) % MOD;
	return mod((int)res);
}
int pow_mod(int a, int b)
{
	ll res = 1;
	while (b > 0) {
		if(b & 1) {
			res = res * (ll)a % (ll)MOD;
		}
		a = mul_mod(a, a);
		b >>= 1;
	}
	return (int)res;
}
int inv_mod(int a)
{
	return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
	return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 100000;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < FAC_MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll com_mod(int a, int b){
	if (a < b) return 0;
	if (a < 0 || b < 0) return 0;
	return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main(void)
{
	int n, d[100000], count[100001] = {};
	cin >> n;
	rep (i, n) cin >> d[i];
	if (d[0] != 0) {
		cout << 0 << endl;
		return 0;
	} else {
		repp (i, 1, n) {
			count[d[i]]++;
			if (d[i] == 0) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	int ans = 1;
	count[0] = 1;
	repp (i, 1, n) {
		ans = mul_mod(ans, pow_mod(count[i - 1], count[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024