akhauriyash/Code-Regression huggingface dataset:
import sys
mod = 1000000007
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline()
def main():
    n = int(input())
    a = get_array()
    m = 1
    for e in a: m *= e
    s = 0
    for e in a: s  += m // e
    print(m/s)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];
int prim(){
    int minv;
    int d[MAX],color[MAX];
    for(int i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    d[0]=0;
    color[0]=GRAY;
    while(1){
        minv=INFTY;
        int u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1)break;
        color[u]=BLACK;
        for(int v=0;v<n;v++){
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
             if(d[v]>d[u]+M[u][v]){
                 d[v]=d[u]+M[u][v];
                 color[v]=GRAY;
               }
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<i<<" "<<(d[i]==INFTY ? -1: d[i])<<endl;
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j]=INFTY;
        }
    }
    int k,c,u,v;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }
    prim();
    return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define int long long
#define MM(a,b) memset(a,b,sizeof(a))
const ll MOD = 1000000007;
using namespace std;



int32_t main(){
    vaibhavv06;
	int n; cin>>n;
	
	string a;
	string b;
	for(int i=0;i<n;i++) {
		char x; cin>>x;
		a+=x;
	}
	for(int i=0;i<n;i++) {
		char x; cin>>x;
		b+=x;
	}
	string s;
	for(int i=1;i<=n;i++){
		s+=(i+'0');
	}
	int pa=0,pb=0;
	int cnt=0;
	if(s==a) pa=cnt;
	if(s==b) pb=cnt;
	// cout<<a<<" "<<b<<endl;
	while(next_permutation(s.begin(),s.end())){
		cnt++;
		// cout<<s<<endl;
		if(s==a){
			pa=cnt;
		}
		if(s==b){
			pb=cnt;
		}
	}
	// cout<<pa<<" "<<pb<<endl;
	cout<<abs(pa-pb)<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    int n;cin>>n;
    ll a[n];
    ll sum=0;
    ll mi=inf;
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
        mi=min(mi,a[i]);
    }
    if(n%2==1){
        if(sum%2==1)cout<<"First"<<endl;
        else cout<<"Second"<<endl;
        return 0;
    }
    if(mi%2==1){
        cout<<"First"<<endl;
        return 0;
    }
    ll sum2=0;
    rep(i,0,n)sum2+=a[i]-mi;
    if(sum2%2==1)cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}


Measured memory_bytes: 4640
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	string s;
	cin>>s;
	rep(i,s.size()){
		if(s[i]=='C'){
			rep(j,i,s.size()){
				if(s[j]=='F'){
					cout<<"Yes"<<endl;
					return;
				}
			}
		}
	}
	cout<<"No"<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

int main(){
 	int n;
  	cin >> n;
  	int dig7 = 0;
  	while(n>0){
     	int d = n%10;
      	n/=10;
      if(d==7)
        dig7=1;
    }
  cout << (dig7?"Yes":"No") << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C,D,price;
  price = 0;
  cin >> A >> B >> C >> D;
  
  if(A > B) price += B;
  else price += A;
  if(C > D) price += D;
  else price += C;
  
  cout << price << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)

/////////////////////////////////////////////////////////

void Main(){
  int N; cin >> N;
  vector<int> A1(N), A2(N);
  rep(i, 0, N) cin >> A1[i];
  rep(i, 0, N) cin >> A2[i];
  vector<int> C1(N), C2(N);
  C1[0] = A1[0];
  C2[N-1] = A2[N-1];
  rep(i, 1, N) C1[i] = C1[i-1] + A1[i];
  rep(i, 1, N) C2[N-i-1] = C2[N-i] + A2[N-i-1];
  int max = 0;
  rep(i, 0, N) if(C1[i] + C2[i] > max) max = C1[i] + C2[i];
  cout << max << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

int A,B,C;
inline void solve(){
  IN3(A,B,C);
  OUT(A==B?C:B==C?A:B);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#abc.py
X,Y,A,B,C = map(int,input().split())
P= sorted(list(map(int,input().split())),reverse=True)
Q= sorted(list(map(int,input().split())),reverse=True)
R= list(map(int,input().split()))
P=P[0:X]
Q=Q[0:Y]
R.extend(P)
R.extend(Q)
R=sorted(R,reverse=True)
ans = 0
for i in range(X+Y):
    ans+=R[i]
print(ans)


Measured memory_bytes: 23200
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn=1e5+233;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,a[5],ans=0,tp=0,mi=(ll)1e18;
	cin>>n;
	for(int i=0;i<5;i++)cin>>a[i],mi=min(mi,a[i]);
	cout<<4+(n+mi-1)/mi<<endl;
    return 0;
}


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

int main(){
	long long  d;
	while( cin >> d, d ){
		int n, m;
		cin >> n;
		cin >> m;
		vector<int> store(n+1), dist(m);
		store[0] = 0;
		for( int i = 1; i < n; i++ ) cin >> store[i];
		store[n] = d;
		for( int i = 0; i < m; i++ ) cin >> dist[i];
		sort( store.begin(), store.end() );
		long long sum = 0;
		for( int i = 0; i < m; i++ ){
			//cout << "a" << endl;
			int left = 0, right = n;
			while( 1 ){
				//cout << "b" << endl;
				int next = (left + right) / 2;
				if( next == left || next == right ) break;
				if( dist[i] < store[next] ) right = next;
				else left = next;
			}
			sum += min(abs(store[left]-dist[i]), abs(store[right]-dist[i]));
			//cout << sum << endl;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1532
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

dp = [[0] * 3] * N
for idx, val in enumerate(abc):
    a, b, c = val
    if idx == 0:
        dp[0] = val
    else:
        tmp = []
        tmp.append(max(dp[idx - 1][1] + a, dp[idx - 1][2] + a))
        tmp.append(max(dp[idx - 1][0] + b, dp[idx - 1][2] + b))
        tmp.append(max(dp[idx - 1][1] + c, dp[idx - 1][0] + c))
        dp[idx] = tmp
print(max(dp[-1]))


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

int main() {
  int n;
  std::string s;
  std::cin >> n >> s;

  int count = 0;
  for (size_t i = 0; i < s.size(); i++) {
    std::vector<int> b(26, 0), a(26, 0);

    for (size_t j = 0; j < s.size(); j++) {
      if (j < i) {
        b[s[j] - 'a']++;
      } else {
        a[s[j] - 'a']++;
      }
    }

    int now = 0;
    for (size_t j = 0; j < 26; j++) {
      if (a[j] != 0 && b[j] != 0) {
        now++;
      }
    }
    count = std::max(count, now);
  }

  std::cout << count << std::endl;
  return 0;
}

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

void WarshallFloyd(vector<vector<int>>&dist) {
  const int n = dist.size();
  rep(k, n) {
    rep(i, n) {
      rep(j, n) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  constexpr int INF = 1e9 + 10;
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> dist(n, vector<int>(n, INF));
  rep(i, n) dist[i][i] = 0;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    dist[a][b] = dist[b][a] = c;
  }
  WarshallFloyd(dist);

  vector<vector<int>> dist2(n, vector<int>(n, INF));
  rep(i, n) dist2[i][i] = 0;
  rep(i, n) {
    rep(j, n) {
      if (dist[i][j] <= l) dist2[i][j] = 1;
    }
  }
  WarshallFloyd(dist2);

  int q;
  cin >> q;
  vector<int> ans(q);
  rep(i, q) {
    int s, t;
    cin >> s >> t;
    --s; --t;
    ans[i] = dist2[s][t] - 1; 
    if (dist2[s][t] == INF) ans[i] = -1;
  }
  rep(i, q) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef vector<int> vi;
int N,d[190];
vector<vi> ans;
void dfs(vi vc,int l,int r,vi ex,int t){
	if(t==N*(N-1)/2){
		int a=d[0];
		rep(i,l) a-=vc[i];
		rep(i,r) a-=vc[N-2-i];
		if(a>0){
			vc[l]=a;
			ans.pb(vc);
		}
		return;
	}
	if(ex[d[t]]){
		ex[d[t]]--;
		dfs(vc,l,r,ex,t+1);
		return;
	}
	if(l+r==N-2) return;
	//left
	while(true){
		vi nvc=vc,nex=ex;
		int nl=l+1,nr=r;
		int a=d[0]-d[t];
		if(a<=0) goto en;
		nex[a]++;
		rep(i,l){
			a-=vc[i];
			if(a<=0) goto en;
			nex[a]++;
		}
		nvc[l]=a;
		a=d[t];
		rep(i,r){
			a-=vc[N-2-i];
			if(a<=0) goto en;
			nex[a]++;
		}
		dfs(nvc,nl,nr,nex,t+1);
		break;
	}
	en:
	//right
	while(true){
		vi nvc=vc,nex=ex;
		int nl=l,nr=r+1;
		int a=d[0]-d[t];
		if(a<=0) goto en2;
		nex[a]++;
		rep(i,r){
			a-=vc[N-2-i];
			if(a<=0) goto en2;
			nex[a]++;
		}
		nvc[N-2-r]=a;
		a=d[t];
		rep(i,l){
			a-=vc[i];
			if(a<=0) goto en2;
			nex[a]++;
		}
		dfs(nvc,nl,nr,nex,t+1);
		break;
	}
	en2:;
}
int main(){
	while(true){
		ans.clear();
		cin>>N;
		if(N==0) break;
		rep(i,N*(N-1)/2) cin>>d[i];
		dfs(vi(N-1,0),0,0,vi(401,0),1);
		sort(all(ans));
		ans.erase(unique(all(ans)),ans.end());
		for(vi vc:ans){
			rep(i,N-2) cout<<vc[i]<<" ";
			cout<<vc[N-2]<<endl;
		}
		puts("-----");
	}
}

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

long long dp[100] = {};

int main() {
  int N; cin >> N;
  long long lucas_nums[N + 1];
  
  lucas_nums[0] = 2; lucas_nums[1] = 1;
  for (int i = 2; i <= N; ++i) lucas_nums[i] = lucas_nums[i - 1] + lucas_nums[i - 2];
  
  cout << lucas_nums[N] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;

const int MAXN = 100000 + 10;

ll N, M;

struct Edge {
    ll to;
    ll weight;
    ll next;
};

vector<Edge> edges(MAXN);
vector<ll> head(MAXN, -1);
vector<ll> vis(MAXN, false);

ll cnt = 1;

void addEdge(ll from, ll to, ll weight) {
    edges[cnt].to = to;
    edges[cnt].weight = weight;
    edges[cnt].next = head[from];
    head[from] = cnt++;
}

void bfs(int s) {
    queue<int> que;
    que.push(s);
    while (!que.empty()) {
        auto p = que.front();
        que.pop();
        cout << p << endl;
        for (int i = head[p]; i != -1; i = edges[i].next) {
            int u = edges[i].to;
            if (!vis[u]) {
                que.push(u);
                vis[u] = true;
            }
        }
    }
}

void dfs(int s) {
    // vis[s] = true;
    cout << s << endl;
    for (int i = head[s]; i != -1; i = edges[i].next) {
        int u = edges[i].to;
        if (!vis[u]) {
            vis[u] = true;
            dfs(u);
        }
    }
}

int main() {
    int A, B, C, D;
    string s;
    cin >> s;
    A = s[0] - '0';
    B = s[1] - '0';
    C = s[2] - '0';
    D = s[3] - '0';
    int op1 = -1;
    int op2 = -1;
    int op3 = -1;
    int curr = A;
    for (int op1 = -1; op1 <= 1; op1 += 2) {
        for (int op2 = -1; op2 <= 1; op2 += 2) {
            for (int op3 = -1; op3 <= 1; op3 += 2) {
                curr = curr + op1 * B + op2 * C + op3 * D;
                if (curr == 7) {
                    cout << A << (op1 == 1 ? '+' : '-') << B << (op2 == 1 ? '+' : '-') << C << (op3 == 1 ? '+' : '-') << D << "=" << 7 << endl;
                    return 0;
                }
                curr = A;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4096
<?php
  $ary = array();
  $marks = array("S", "H", "C", "D");
  foreach ($marks as $val) {
    for ($i = 1; $i <= 13; $i++) {
      array_push($ary, ($val . " " . $i));
    }
  }
  $ary_2 = array();
  $a = trim(fgets(STDIN));
  for ($i = 1; $i <= $a; $i++) {
    array_push($ary_2, trim(fgets(STDIN)));
  }
  $ary_diff = array_diff($ary, $ary_2);
  if (empty($ary_diff)) {
    return;
  } else {
    print implode("\n", $ary_diff);
  }
?>

Measured memory_bytes: 6600
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vector<vpll> path;
void dfs(ll now) {
	stack<ll> S;
	S.push(now);
	flag[now] = 1;
	while (!S.empty()) {
		ll u = S.top();
		S.pop();
		for (ll i = 0; i < path[u].size(); i++) {
			ll v = path[u][i].first;
			if (D[v] == INF) {
				D[v] = D[u] + path[u][i].second;
			}
			else if(D[v]!=D[u]+path[u][i].second){
				//debug(u, v);
				cout << "No";
				exit(0);
			}
			if (flag[v] == 0) {
				dfs(v);
			}
		}
	}
}
int main() {
	cin >> N >> M;
	if (M == 0) {
		cout << "Yes";
		exit(0);
	}
	path.resize(N);
	flag.resize(N);
	D.resize(N);
	for (i = 0; i < N; i++) {
		D[i] = INF;
	}
	ll first = -1;
	for (i = 0; i < M; i++) {
		ll l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		path[l].push_back(mp(r, d));
		path[r].push_back(mp(l, -d));
		if (first == -1) first = l;
	}
	for (i = 0; i < N; i++) {
		if (!flag[i] && path[i].size()>0) {
			D[i] = 0;
			dfs(i);
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 85936
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct Node {
    int key;
    struct Node *prev;
    struct Node *next;
};
   
struct Node *note;
   
void insert(int key) {
    struct Node *x = (struct Node *)malloc(sizeof(struct Node));
    x->key = key;
    note->next->prev = x;
    x->next = note->next;
    note->next = x;
    x->prev = note;
}
   
struct Node* search(int key) {
    struct Node *x = note->next;
    while(x != note && x->key != key ) {
        x = x-> next;
    }
    return x;
}
   
void deleteNode(struct Node *t) {
    if (t == note) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
}
   
void deleteFirst() {
    deleteNode(note->next);
}
   
void deleteLast() {
    deleteNode(note->prev);
}
void deleteKey(int key) {
    deleteNode(search(key));
}
   
void print() {
    struct Node *x;
    x = note->next;
    int i = 0;
    while(1) {
        if (x == note) break;
        if(i++ > 0) printf(" ");
        printf("%d", x->key);
        x = x->next;
    }
    printf("\n");
}
   
   
int main(void) {
    int key, n;
    char order[20];
    scanf("%d", &n);
    note = (struct Node *)malloc(sizeof(struct Node));
    note->next = note;
    note->prev = note;
    for (int i = 0; i < n; i++) {
        scanf("%s%d",order, &key);
        if(order[0] == 'i') {
            insert(key);
        }else if(order[0] == 'd') {
            if(strlen(order) > 6) {
                if( order[6] == 'F') {
                    deleteFirst();
                }else if(order[6] == 'L') {
                    deleteLast();
                }
            }else {
                deleteKey(key);
            }
        }
    }
    print();
    return 0;
}

Measured memory_bytes: 36080
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const int N=1e5+5;

int n;

pair<int,int>p[N];

int main()
{
    cin >> n;
    for (int i=0;i<n;i++)
    {
        cin >> p[i].F;
        p[i].S=i+1;
    }
    sort(p,p+n);
    cout << p[0].S;
    for (int i=1;i<n;i++)
    {
        cout << ' ' << p[i].S;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1536
s=input()
cnta=0
cntb=0
cntc=0
for i in range(len(s)):
  if s[i]=='a':
    cnta+=1
  elif s[i]=='b':
    cntb+=1
  else:
    cntc+=1
if len(s)%3==0:
  if cnta==cntb==cntc:
    print('YES')
  else:
    print('NO')
else:
  if max(cnta,cntb,cntc)==min(cnta,cntb,cntc)+1:
    print('YES')
  else:
    print('NO')


Measured memory_bytes: 3188
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=1e9+6969;

int n,dp[R],t[R];

int main()
{
	scanf("%d", &n);
	for(int i=0;i<n;++i)
	{
		scanf("%d", &t[i+1]);
	}
	dp[1]=0;
	dp[0]=INF;
	for(int i=2;i<=n;++i)
	{
		int h=t[i];
		dp[i]=min(dp[i-1]+abs(t[i-1]-h),dp[i-2]+abs(t[i-2]-h));
	}
	printf("%d\n", dp[n]);
	return 0;
}


Measured memory_bytes: 4496
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define int64 long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

int gcd(int a, int b) {
    if (a < b) a, b = b, a;
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> M(H);
    rep(i, H) cin >> M[i];

    pair<int, int> c[H][W];
    rep(i, H) {
        vector<int> p;
        p.push_back(-1);
        rep(j, W) {
            if (M[i][j] == '#') p.push_back(j);
        }

        rep(k, p.size()) {
            if (k == p.size()-1) {
                reps(p[k]+1, j, W) c[i][j].second = W - p[k] - 1;
            } else {
                reps(p[k]+1, j, p[k+1]) c[i][j].second = p[k+1] - p[k] - 1;
            }
        }
    }

    rep(j, W) {
        vector<int> p;
        p.push_back(-1);
        rep(i, H) {
            if (M[i][j] == '#') p.push_back(i);
        }

        rep(k, p.size()) {
            if (k == p.size()-1) {
                reps(p[k]+1, i, H) c[i][j].first = H - p[k] - 1;
            } else {
                reps(p[k]+1, i, p[k+1]) c[i][j].first = p[k+1] - p[k] - 1;
            }
        }
    }

    // cout << endl;
    // rep(i, H) {
    //     rep(j, W) {
    //         cout << c[i][j].first << " " << c[i][j].second << ", ";
    //     }
    //     cout << endl;
    // }

    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            ans = max(ans, c[i][j].first + c[i][j].second);
        }
    }
    cout << ans - (ans != 0 ? 1 : 0) << endl;
}


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

int main(){
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    rep(i,N - 1){
        vec[i + 1] += vec[i];
    }
    vector<vector<int> > coloring(H, vector<int>(W));
    int count = 0;
    rep(i,H * W){
        if (i == vec[count]) count++;
        if ((i / W) % 2 == 0){
            coloring[i / W][i % W] = count + 1;
        }
        else{
            coloring[i / W][(W - 1) - i % W] = count + 1;
        }
    }
    rep(i,H){
        rep(j,W){
            cout << coloring[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 3620
s = int(input())
sl = list(str(s))
sl_n = len(sl) - 1
l = ['a','b']
def a_or_b(x):
    if len(list(str(x[0]))) == sl_n:
        return x
    else:
        ll = []
        for i in range(len(x)):
            ll.append(x[i] + 'a')
        for i in range(len(x)):
            ll.append(x[i] + 'b')
        x = ll
        return a_or_b(x)
    
lll = []
ans = 0

if len(sl) == 1:
    ans = s
else:
    lll = a_or_b(l)
    kkk = []
    for i in range(len(lll)):
        p = sl
        q = list(str(lll[i]))
        st = ''
        for j in range(len(p) - 1):
            if q[j] == 'a':
                st = st + p[j] +'+'
            else:
                st = st + p[j] + ''
        st = st + sl[-1]
        res = eval(st)
        ans += res
        
print(ans)

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
typedef vector<int> vint;
typedef vector<long long> vlint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<vector<long long>> vlint2;


lint gcd(lint x, lint y){
    if (x == 0) return y;
    return gcd(y % x, x);
};

lint lcm(lint x, lint y){
    return x * y / gcd(x, y);
};

lint powint(lint x, lint y){
    int ret = 1;
    for (int i=0; i < y; i++) ret *= x;
    return ret;
};

lint powmod(lint x, lint y, lint m){
    if (y == 0) return 1;
    return ((powint(powmod(x, y>>1, m), 2) % m) * powint(x, (y & 1))) % m;
};

lint comb(lint n, lint r, lint m){
    if (n < r) return 0;

    if (n-r < r) r = n-r;
    int ret = 1; int d = 1;
    for (int i = n-r+1; i < n+1; i++) ret = (ret * i) % m;
    for (int i = 1; i < r+1; i++) d = (d * i) % m;
    ret *= powmod(d, m-2, m);
    return ret % m;
};

lint min_arr(vector<lint> x){
    lint y = x[0];
    rep(i, x.size()){
        y = min(y, x[i]);
    }
    return y;
};

int mod = 1000000007;
vector<int> dx = {1, 0, 0, -1, 1, 1, -1, -1};
vector<int> dy = {0, -1, 1, 0, 1, -1, 1, -1};

map<char, long long> counter(string s){
    map<char, long long> count;
    rep(i, s.size()){
        count[s[i]] ++;
    }
    return count;
};

int main() {
    int k; cin >> k;
    lint ans = 0;
    For(a, 1, k+1){
        For(b, 1, k+1){
            lint r = gcd(a, b);
            For(c, 1, k+1){
                ans += gcd(r, c);
            }
        }

    }
    cout << ans << endl;
}



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

int main() {
    int64_t n;
    cin >> n;
    if (n % 2 == 1) {
        cout << 0 << endl;
    } else {
        int64_t div = 10;
        int64_t ans = 0;
        while (div <= n) {
            ans += n / div;
            div *= 5;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
const int MAX_V = 1000000;
int prime[MAX_V+1];
int sum, x, y, ans;
int main(){
 int i, k, v, n, left, right;
 for(i = 2; i <= MAX_V; i++){
  prime[i] = 1;
 }
 for(i = 2; i*i <= MAX_V; i++){
  if(prime[i]){
   for(k = 2 * i; k <= MAX_V; k += i){
    prime[k] = 0;
   }
  }
 }
 while(1){
  scanf("%d", &n);
  if(n == 0) break;
  for(i = 0; i<=n-2; i++){
   x = prime[i];
   y = prime[i + 2];
   if(x == 1 && y == 1){
    ans = i;
   }
  }
  printf("%d %d\n", ans, ans+2);
 }
 return 0;
}

Measured memory_bytes: 6660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    string s;
    cin >> s;
    if(s == "RRR") cout << 3 << endl;
    else if(s=="RSS" || s=="SRS" || s=="SSR" || s=="RSR") cout << 1 << endl;
    else if (s=="RRS" || s=="SRR") cout << 2 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 3592
using System;
using System.Linq;
using System.Collections.Generic;

namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int d = 0;
            for (d = 0; N != 0; d++) N >>= 1;

            Console.WriteLine($"{1 << (d-1)}");
            Console.ReadKey();
        }

    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

int n,m,k;
string s,t;
bool ok=true;

int main() {
  cin >> s;
  if(s!=string(s.rbegin(),s.rend())) ok=false;
  n=s.size(), m=(n-1)/2;
  t=s.substr(0,m);
  if(t!=string(t.rbegin(),t.rend())) ok=false;
  t=s.substr((n+3)/2-1);
  if(t!=string(t.rbegin(),t.rend())) ok=false;
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
PROGRAM-ID.                      ABC_052_A.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP     PIC X(23).
    01 A       PIC 9(5).
    01 B       PIC 9(9).
    01 C       PIC 9(5).
    01 D       PIC 9(9).
    01 ans     PIC X(9).

    01 ZS      PIC Z(10).
    01 DUMMY   PIC X(1).

PROCEDURE                        DIVISION.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO A B C D.

    MULTIPLY A BY B.
    MULTIPLY C BY D.

    COMPUTE B = FUNCTION MAX(B, D).
    MOVE B TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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

int main()
{
    int ht,st,ha,sa;
    cin>>ht>>st>>ha>>sa;
    int p=1;
    while(ht>0 || ha>0)
    {
        ha=ha-st;
        if(ha>0)
            ht=ht-sa;
        else
            break;
    }
    //cout<<ht<<" "<<ha<<endl;
   if(ht<=0){
        cout<<"No"<<endl;
   }
   else if(ht>0 && ha<=0)
    {
        cout<<"Yes"<<endl;
   }
    return 0;
}


Measured memory_bytes: 3604
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    int h[n+1];
    for(int i=1;i<=n;i++)
    cin>>h[i];
    vector <int> v[n+1];
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int l=v[i].size(),f=0;
        for(int j=0;j<l;j++)
        {
            if(h[v[i][j]]>=h[i])
            {
                f=1;
                break;
            }
        }
        if(f==0)
        ans++;
    }
    cout<<ans;
}

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

int main()
{
    string S;
    cin >> S;

    if (S == "SUN")
        cout << 7;
    if (S == "MON")
        cout << 6;
    if (S == "TUE")
        cout << 5;
    if (S == "WED")
        cout << 4;
    if (S == "THU")
        cout << 3;
    if (S == "FRI")
        cout << 2;
    if (S == "SAT")
        cout << 1;



    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
tru = 0
acount = Counter(a)
if n == 1:
         if acount[0] == 1 :
                  print(1)
         else:
                  print(0)
elif n % 2 == 1:
         for i in range (1,n//2+1):
                  if acount[i*2] != 2:
                           print(0)
                           exit()
         else:
                  if acount[0] != 1:
                           print(0)
                           exit()
                  else:
                           print((2 ** (n//2) ) % (10 ** 9 + 7))
else:
         for j in range(1,n//2+1):
                  if acount[j*2-1] != 2:
                           print(0)
                           exit()
         else:
                  print((2 ** (n//2) ) % (10 ** 9 + 7))


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

int main(void) {
    long long N, M, c;
    scanf("%lld%lld", &N, &M);
    if (M >= N*2LL) {
        c = (M-N*2LL)/4LL;
        if (N+c <= (M-c*2LL)/2) printf("%lld\n", N+c);
        else printf("%lld\n", (M-c*2LL)/2LL);
    } else {
        printf("%lld\n", M/2LL);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e-a>k) cout << ":(" << endl;
  else cout << "Yay!" << endl;
  return 0;
}

Measured memory_bytes: 256
sum[3<<17],cnt[3<<17];
N,i,acc,t,k,x;
char f[10];
main()
{
	for(;;)
	{
		k=getchar_unlocked();
		if(k<'0'||k>'9')break;
		N=N*10+k-'0';
	}
	for(i=0;i<N;i++)
	{
		x=0;
		for(;;)
		{
			k=getchar_unlocked();
			if(k<'0'||k>'9')break;
			x=x*10+k-'0';
		}
		++sum[cnt[x]++];
	}
	i=0;
	for(t=N;t>0;t--)
	{
		while(acc>=i*t)acc+=sum[i++];
		cnt[t]=i-1;
	}
	for(i=1;i<=N;i++)
	{
		if(!cnt[i])
		{
			putchar_unlocked('0');
		}
		else
		{
			if(cnt[i-1]!=cnt[i])
			{
				k=0;
				while(cnt[i])
				{
					f[k++]=cnt[i]%10;
					cnt[i]/=10;
				}
				acc=k;
			}
			else k=acc;
			while(k--)putchar_unlocked(f[k]+'0');
		}
		putchar_unlocked('\n');
	}
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


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

    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int d=60*(h2-h1)+m2-m1;
    cout << max(0,d-k) << endl;

    return 0; 
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
    int n,i,u,v,w,t;
    cin>>n;
    int c[n+1],vis[n+1];
    c[1]=0;
    t=n-1;
    for(i=0;i<=n;i++) vis[i]=0;
    vector<vector<pair<int,int>>> e(n+1);
    while(t--)
    {
      cin>>u>>v>>w;
      e[u].pb({v,w});
      e[v].pb({u,w});
    }
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=1;
        for(auto x:e[u])
        {
            if(!vis[x.first])
            {
            q.push(x.first);
            if(x.second%2) c[x.first]=1-c[u];
            else c[x.first]=c[u];
            }
        }
    }
    for(i=1;i<=n;i++) cout<<c[i]<<endl;
    return 0;
}

Measured memory_bytes: 7168
#include<iostream>
#include<algorithm>
using namespace std;
int a[200001];
int n;
int main(){
	while(cin>>n){
		bool flag=true;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n);
		for(int i=0;i<n-1;i++){
			if(a[i]==a[i+1]){
				flag=false;
			}
		}
		if(flag==true){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Numerics;
using System.Linq;

class D2
{
	static void Main()
	{
		var M = 1000000007;
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

		BigInteger c = a[0] - a[1] + 1;
		for (var i = 1; i <= a[1]; Console.WriteLine(c % M), c = c * (a[0] - a[1] + 2 - ++i) / i * (a[1] - i + 1) / (i - 1)) ;
	}
}


Measured memory_bytes: 13652
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

typedef pair<int,int> P;
typedef pair<P,int> PP;

#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)
#define INF 999999999

int w,h,s,t;
int f[102][102]; //eXÌèÌóµ
int d[102][102]; //e}X©çêÔß¢XÖÌÅ¬£
bool closed[102][102]; //Dæp

int dx1[] = { 0, 1, 1, 1, 0,-1}; //ïñ©çÌJÚ
int dy1[] = {-1,-1, 0, 1, 1, 0}; //ïñ
int dx2[] = {-1, 0, 1, 0,-1,-1}; //ôñ
int dy2[] = {-1,-1, 0, 1, 1, 0}; //ôñ

//flg : }bvðhé©hçÈ¢©
int draw(int x,int y,int id,bool flg){
	int res = 0;
	queue<PP> q;
	memset(closed,0,sizeof(closed));

	q.push(PP(P(x,y),0));

	while(!q.empty()){
		PP p = q.front(); q.pop();
		int x = p.first.first;
		int y = p.first.second;
		if(closed[y][x]) continue;
		closed[y][x] = true;

		if(d[y][x] == p.second && flg){
			f[y][x] = INF;
		}
		else if(d[y][x] > p.second){
			if(flg){
				f[y][x] = id;
				d[y][x] = p.second;
			}
			res++;
		}

		for(int i=0;i<6;i++){
			int nx = x + (y%2==1 ? dx1[i] : dx2[i]);
			int ny = y + (y%2==1 ? dy1[i] : dy2[i]);
			if(nx>=0 && nx<w && ny>=0 && ny<h){
				q.push(PP(P(nx,ny),p.second+1));
			}
		}
	}
	return res;
}

int main(void){
	while(cin>>w>>h,w){
		rep(i,h) rep(j,w) f[i][j] = d[i][j] = INF;

		//àÆ©ç éXÌèÌóµð}bvÉ«Þ
		cin>>s;
		rep(i,s){
			int p,q;
			cin>>p>>q;
			draw(p-1,q-1,i,true);
		}

		//eóânÉu¢½Æ«ÌóµðÀÛÉV~[g
		int ans = 0;
		cin>>t;
		rep(i,t){
			int p,q;
			cin>>p>>q;
			ans = max(ans,draw(p-1,q-1,i,false));
		}

		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919;
const int dd[]={0,-1,0,1,0};
using namespace std;
int a,b,c,d;
int p[50][26],q[26];
signed main(){
	int i=0,j=0;
	fill(q,q+26,inf);
	cin>>a;
	for(i=0;i<a;i++){
		string s;
		cin>>s;
		for(auto x:s)
			p[i][x-'a']++;
	}
	for(i=0;i<26;i++)
		for(j=0;j<a;j++)
			q[i]=min(q[i],p[j][i]);
	for(i=0;i<26;i++)
		for(j=0;j<q[i];j++)
			cout<<(char)(i+'a');
	cout<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, B, T = get_ints

count = 0
now = A
while now <= T
  count += B
  now += A
end

puts count


Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N, H;
	cin >> N >> H;
	vector<int> A(N), B(N);
	for(int i = 0; i < N; i ++){
		cin >> A[i] >> B[i];
	}
	sort(all(A));
	sort(all(B));
	int ans = 0, Bcnt = 0;
	while(H > 0){
		if(Bcnt < N && A[N - 1] < B[N - Bcnt - 1]){
			H -= B[N - Bcnt - 1];
			Bcnt ++;
			ans ++;
		}
		else{
			ans += H / A[N - 1];
			if(H%A[N - 1] != 0)ans ++;
			H = -1;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
/*Smile Please!*/
//hp1999
#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast() 	     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

void solve()
{
 int n,m;
 
 cin>>n>>m;
 
 vector<int> dp(n+1,1ll);
 int x;
 
 for(int i=0;i<m;++i)
 cin>>x,dp[x]=0ll;
 
 for(int i=2;i<=n;++i)
 {
  if(!dp[i]) 
  continue;

  dp[i]=(dp[i-1]%M +dp[i-2]%M )%M;

  if(!dp[i])
  {
   cout<<0;
   return;
  }
 }
 
 cout<<dp[n];
}

int32_t main()
{
 fast();

 int t=1;
 //cin>>t;
 while(t--)
 {
  solve();
 }

 return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#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 ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const ll MOD = 1e9+7;
const int MAXN = 1e5+5;

ll qpow(ll a, ll b)
{
    ll ans = 1;
    while (b){
        if (b&1)
            ans = (ans * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return ans;
}

ll comb(ll m, ll n)
{
    if (m < n) return 0;
    if (m == n) return 1;
    if (n > m - n) n = m - n;
    ll up = 1, down = 1;
    rep(i, 0, n-1){
        up = (up * (m-i)) % MOD;
        down = (down * (n-i)) % MOD;
    }
    return up * qpow(down, MOD-2) % MOD;
}

ll Lucas(ll m, ll n)
{
    ll ans = 1;
    while (n){
        ans = (ans * comb(m%MOD, n%MOD)) % MOD;
        m /= MOD;
        n /= MOD;
    }
    return ans;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    ll ans = (qpow(2, n)-1 - Lucas(n, a) - Lucas(n, b) + MOD*3) % MOD;
    cout << ans << endl;

    return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int N, A[200005];

int main() {
    cin >> N;
    for_(i,0,N) cin >> A[i];

    lint ans = 0;
    map<int, int> cnt;
    for_(i,0,N) {
        int x = i - A[i];
        ans += cnt[x];
        int y = A[i] + i;
        cnt[y]++;
    }
    cout << ans << endl;
}

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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP				make_pair

typedef pair<int, int> P;

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( a > b ) { a = b; return 1; } return 0; }

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

int cost[101][101];
int n, k;

signed main() {

	while( cin >> n >> k, n ) {
		fill( cost[0], cost[101], INF );
		REP( i, 101 ) {
			cost[i][i] = 0;
		}
		
		bool update = false;
		REP( i, k ) {
			int t, from, to;
			cin >> t;
			if( t ) {
				int fare;
				cin >> from >> to >> fare;
				from--; to--;
				if( chmin( cost[from][to], fare ) ) update = true;
				chmin( cost[to][from], fare );
				
/*
				REP( i, n ) {
					REP( j, n ) {
						cout << cost[i][j] << " ";
					}
					cout << endl;
				}
*/				
			} else {
				if( update ) {
					REP( k, n ) {
						REP( i, n ) {
							REP( j, n ) {
								chmin( cost[i][j], cost[i][k] + cost[k][j] );
							}
						}
					}
					update = false;
				}

				cin >> from >> to;
				from--; to--;
				if( cost[from][to] != INF ) cout << cost[from][to] << endl;
				else						cout << -1 << endl;
			}
		}
	}
}


Measured memory_bytes: 3132
#include<iostream>
using namespace std;
int main(){
 
 int a[10000],x=0,n,i,j,k=0,y=0,b;
 int mix=1000000;
 int min=-1000000;
 long long z=0; 
	cin>>n;
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		for(i=0;i<n;i++){
			for(j=i+1;j<n;j++){			
				if(a[j]<a[i]){
					b=a[i];
					a[i]=a[j];
					a[j]=b;				
			    }
			}
		}
		x=a[0];
		for(i=0;i<n;i++){
			for(j=i+1;j<n;j++){			
				if(a[i]<a[j]){
					b=a[i];
					a[i]=a[j];
					a[j]=b;				
			    }
			}
		}
		y=a[0];	
		for(i=0;i<n;i++){
			z=z+a[i];
		}
		cout<<x<<" "<<y<<" "<<z<<endl;
return 0;
} 

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

int main(){
    int n,k;
    cin >> n >> k;
    int dist = 0;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        dist += min(2*x,2*(k-x));
    }
    cout << dist << endl;
}

int min(int a,int b){
    if(a-b>0) return b;
    return a;
}

int max(int a,int b){
    if(a-b>0) return a;
    return b;
}

Measured memory_bytes: 256