akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	int q=a.size(),qq=q,f=0;
	for(int i=0;i<q;i++){
		if(a[i]=='C' and f==0)f=1;
		if(a[i]=='F' and f==1)f=2;
	}
	if(f==2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 500005 //ヒープの個数出すよ

int Left(int i){ //左の子のアドレス値だよ
  return 2*i;
}
 
int Right(int i){ //右の子のアドレス値だよ
  return 2*i+1;
}
 
void maxHeapify(int *A,int i,int n){ //大きいやつを上にもっていく関数やが、親子関係が成立するまで再帰。
  int l=Left(i),r=Right(i),largest,tmp;
 
  if(l<=n && A[l]>A[i]) largest=l;//もし自分（i）より左下の子が大きかったらlargestに保存するやが、そうじゃなかったらiを保存や
  else largest=i;
 
  if(r<=n && A[r]>A[largest])largest=r; //んでもし左の子より右の子が大きかったり、親より右の子が大きかったら、右の子をlargestに保存
 
  if(largest!=i){ //largestが自分じゃない場合な、入れ替えて再帰や。
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(A,largest,n);
  }
}

main(){
  int n,i;
  int A[N];
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++) scanf("%d",&A[i]); //for文回して頭も回すで
 
  for(i=n;i>=1;i--) maxHeapify(A,i,n); //buildMaxHeap関数作るんめんどい
 
  for(i=1;i<=n;i++) printf(" %d",A[i]);

  printf("\n");
 
  return 0;
}

Measured memory_bytes: 2552
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nq=arr[0].split(" ").map(Number);
var s = arr[1];
var a=[0,0];
var cnt=0;
for(var i=1;i<s.length;i++){
   if(s[i]=="C" && s[i-1]=="A")cnt++;
   a.push(cnt);
}
var str="";
for(var i=2;i<nq[1]+2;i++){
   var lr=arr[i].split(" ");
   str+=a[lr[1]-0]-a[lr[0]-0]+"\n";
}
console.log(str.trim());

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

#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define piii pair<ll, pair<ll, ll>>
#define debug(x) cout<<#x<<" = "<<x<<endl

using namespace std;
const int N = 200005;
ll t, n, m, k, q, a, b, x, y, ans, arr[N];
ll mod = 998244353;
string s;
bool vis[N];
vector<int> vec;
vector<pair<pii, pii>> qrs;

void gen(int last) {
    if (vec.size() == n) {
        ll cur = 0;
        for (auto &itr : qrs) {
            if (vec[itr.first.second] - vec[itr.first.first] == itr.second.first)
                cur += itr.second.second;
        }
        ans = max(ans, cur);
        return;
    }
    for (int i = last; i <= m; ++i) {
        vec.push_back(i);
        gen(i);
        vec.pop_back();
    }
}

int main() {
    io;
    t = 1;
//    cin >> t;
    while (t--) {
        cin >> n >> m >> q;
        while (q--) {
            cin >> a >> b >> x >> y;
            --a, --b;
            qrs.push_back({{a, b}, {x, y}});
        }
        gen(1);
        cout << ans << endl;
    }
    return 0;
}
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);


Measured memory_bytes: 3664
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans;
    string s,t;
    cin >> s>>t;
    cout<<t<<s;

    return 0;

}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
int fact(int n){
    int m;
  if (n == 0)
      return 1;
  m = fact(n - 1);    
  return n * m;       
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
    int n;
    string s;
    cin>>n>>s;
    int si=s.size();
    string t;
    rep(i,si/2){
        t+=s[i];
    }
    cout<<(t+t==s ? "Yes" : "No")<<'\n';
  return(0);
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
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; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  cin >> n;
  string s;
  cin >> s;
  map<int,int>mp;
  rep(i,n){
    mp[s[i]-'a']++;
  }
  ll ans=1;
  for(auto p:mp){
    p.second++;
    p.second%=MOD;
    ans*=p.second;
    ans%=MOD;
  }
  ans--;
  ans%=MOD;
  cout << ans << endl;
  
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int R, G, B;
	int N;
	int con = 0;
	
	cin>>R>>G>>B>>N;
	
	
	for(int i = 0; ; i++){
		if(i*R > N) break;
		for(int j = 0; ; j++){
			
			if(i*R + j*G > N) break;
			
			int t = N - (i*R + j*G);
			
			// cout<<i<<" " <<j<<" "<<t<<endl;
			if(t%B == 0) con++;
		}
	}
	
	cout<<con<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
#define what(x) cerr << #x << " is " << x << endl;

int main(){
    int D, G;
    cin >> D >> G;
    vector<pair<int, int> > pc;
    for(int i = 0; i < D; ++i) {
        int p, c;
        cin >> p >> c;
        pc.emplace_back(p, c);
    }
    int ret = 1000;
    vector<int> points(D);
    for(int i = 0; i < D; ++i) {
        points[i] = pc[i].first * 100 * (i+1) + pc[i].second;
    }
    for(int i = 0; i < (1<<D); ++i) {
        int max_unused = -1;
        int temp = 0;
        int n_temp = 0;
        for(int j = 0; j < D; ++j) {
            if(i & (1<<j)) {
                temp += points[j];
                n_temp += pc[j].first;
            }
            else{
                max_unused = max(max_unused, j);
            }
        }
        int n_use = 0;
        if (temp < G) {
            while(temp < G) {
                n_use++;
                temp+=(max_unused+1)*100;
            }
            if(n_use >= pc[max_unused].first)
                continue;
        }
        ret = min(ret, n_temp + n_use);
    }
    cout << ret << endl;
    return 0;
}

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

int main() {
    int a[3],sum=0;
    string ans="win";

    rep(i,3) {
        cin>>a[i];
        sum+=a[i];
    }

    if (sum >= 22) ans="bust";

    cout << ans << endl;
}


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


int main(){
  
  long long asum=0, sum=0, N, i;
  cin>>N;
  vector<long long> A(N);
  for(i=0; i<N; i++){
    cin>>A[i];
    asum+=A[i];
  }
  for(i=0; i<N; i++){
    
    asum-=A[i];
    sum+=(A[i]*(asum%1000000007))%1000000007;
  }
  cout<<sum%1000000007<<endl;
  return 0;
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
  
  
int main(){
	ll N;
  	cin >> N;
  
  	vector<ll> a(N);
    for(int i = 0;i < N;i++){
		cin >> a[i];
    }
  
    ll tmp = a[0];
    ll ans = 0;
    
    for(int i = 1;i < N ;i++){
    	ans += max((ll)0,tmp - a[i]);
        tmp = max(tmp,a[i]);
    }
  
  	cout << ans << endl;
}


Measured memory_bytes: 4760
#include <stdio.h>
int main(void){
    long int a,b,k;
    scanf("%ld %ld %ld",&a,&b,&k);
    //printf("%ld,%ld\n",a,b);
    if(k>a){
        if(a+b-k>0){b=a+b-k;}else{b=0;};
        a=0;
    }else{
        a-=k;
    };
    printf("%ld %ld",a,b);
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<tuple<int, int, int>> hs;
    rep (i, n) {
        int x, y, h;
        cin >> x >> y >> h;
        hs.push_back(make_tuple(x, y, h));
    }

    rep (cx, 101) {
        rep (cy, 101) {
            int x, y, h;
            int H = 1000000000;

            rep (i, hs.size()) {
                tie(x, y, h) = hs[i];
                if (h == 0) {
                    H = min(H, abs(cx - x) + abs(cy - y));
                } else {
                    H = h + abs(cx - x) + abs(cy - y);
                }
            }

            bool ok = true;
            rep (i, hs.size()) {
                tie(x, y, h) = hs[i];
                if (h == 0) {
                    if (H > abs(cx - x) + abs(cy - y)) {
                        ok = false;
                        break;
                    }
                } else {
                    if (h != H - abs(cx - x) - abs(cy - y)) {
                        ok = false;
                        break;
                    }
                }
            }
            if (ok) {
                cout << cx << ' ' << cy << ' ' << H << endl;
                return 0;
            }
        }
    }

    return 0;
}


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

int main(){
  int N;
  cin>>N;
  
  vector<string> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  
  bool ans=true;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(a.at(i)==a.at(j)){
        ans=false;
      }
    }
  }
  
  for(int i=1;i<N;i++){
    if((a.at(i)).at(0)!=(a.at(i-1)).back()){
      ans=false;
    }
  }
  
  if(ans==true){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
vector<complex<double> >A;
complex<double>j=sqrt(-1),p1,p2,p3,p4,v;
double a,b;
int n;
int f(int m){
	int i,s1=2,s2=2;
	double c=acos(a/2);
	p3=polar(1.0,b+c)+p1;
	p4=polar(1.0,b-c)+p1;
	for(i=0;i<n;i++){
		if(A[i]==p1||A[i]== p2)continue;
		if(abs(A[i]-p3)-1<1e-6)s1++;
		if(abs(A[i]-p4)-1<1e-6)s2++;
	}
	if(m<s1)m=s1;
	if(m<s2)m=s2;
	return m;
}
int main(){
	int m,i,i1;
	char c;
	while(cin>>n,n!=0){
		A.clear();A.resize(n);
		for(i=0;i<n;i++){
			cin>>a>>c>>b;
			A[i]=complex<double>(a,b);
		}
		m=1;
		for(i=0;i<n;i++){
			p1=A[i];
			for(i1=i+1;i1<n;i1++){
				p2=A[i1];
				v=p2-p1;
				a=abs(v);b=arg(v);
				if(a<=2)m=f(m);
			}
		}
		cout<<m<<endl;
	}
}

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

#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
//vector<tuple<ll,ll,ll>> vec;//素因数，指数，使った個数
vector<tuple<ll,ll,ll>> res;
void prime_factorize(long long N) {
    
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex,0});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1,0});
}
int main(){
  ll N,cnt=0;cin >> N;
  bool flag = true;
  prime_factorize(N);
  for(ll i=0;i<res.size();i++){
    flag = true;
    while(flag){
      if(get<1>(res[i]) < (get<2>(res[i]) + 1)) {flag = false;break;}
      get<1>(res[i])-=get<2>(res[i]) + 1;
      get<2>(res[i])+=1;
     // cout << get<0>(res[i]) << ":" << get<1>(res[i]) << ":"<< get<2>(res[i]) << endl;
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

int main() {
	ll x, y;
	cin >> x >> y;

	if (abs(x - y) > 1) {
		cout << "Alice" << endl;
	} else {
		cout << "Brown" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
vector<pair<ll, ll>> vp;

struct union_find {
	ll par[MAX_N];
	ll Size[MAX_N];
	union_find(ll n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
			Size[i] = 1;
		}
	}
	ll root(ll x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	bool same(ll x, ll y) {
		return root(x) == root(y);
	}
	void unite(ll x, ll y) {
		if (same(x, y))return;
        if(Size[root(x)] < Size[root(y)]) swap(x, y);
		Size[root(x)] += Size[root(y)];
		par[root(y)] = root(x);
	}
};

int main(){
    ll n;
    cin>>n;
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    ll ans=INF;
    vp.resize(n);
    for(ll i=0;i<n;i++) cin>>vp[i].first>>vp[i].second;
    sort(vp.begin(), vp.end());
    for(ll i=0;i<n-1;i++){
        for(ll j=i+1;j<n;j++){
            pair<ll, ll> p=make_pair(vp[j].first-vp[i].first,vp[j].second-vp[i].second);
            struct union_find U(n);
            for(ll k=0;k<n-1;k++){
                for(ll m=k+1;m<n;m++){
                    if(p.first==vp[m].first-vp[k].first && p.second==vp[m].second-vp[k].second){
                        U.unite(m,k);
                    }
                }
            }
            vector<bool> used(n,0);
            ll sub=0;
            for(int k=0;k<n;k++){
                if(!used[U.root(k)]){
                    used[U.root(k)]=true;
                    sub+=1;
                }      
            }
            ans=min(ans,sub);
        }
    }
    cout<<ans<<endl;
}


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

int N;
vector<vector<int> > adj;
vector<int> ind;
vector<int> tin, bck, id;
vector<int> sz;
stack<int> st;
int timer = 0, scnt = 0;

void dfs0(int u) {
    tin[u] = timer++;
    bck[u] = tin[u];
    st.push(u);
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(tin[v] == -1) {
            dfs0(v);
            bck[u] = min(bck[u], bck[v]);
        }
        else if(id[v] == -1) {
            bck[u] = min(bck[u], tin[v]);
        }
    }
    if(bck[u] == tin[u]) {
        while(1) {
            int t = st.top(); st.pop();
            id[t] = scnt;
            if(t == u) break;
        }
        scnt++;
    }
}

vector<int> col;

void dfs1(int u) {
    vector<int> chk(adj[u].size() + 1, 0);
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(sz[ id[v] ] > 1) continue;
        dfs1(v);
        if(col[v] <= adj[u].size()) chk[ col[v] ] = 1;
    }
    for(int i = 0; i <= adj[u].size(); i++) {
        if(!chk[i]) {
            col[u] = i;
            break;
        }
    }
    //cout << u << ' ' << col[u] << endl;
}

int main() {
    scanf("%d", &N);
    adj.resize(N);
    ind = vector<int>(N, -1);
    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        t--;
        adj[t].push_back(i);
        ind[i] = t;
    }

    tin = bck = id = vector<int>(N, -1);
    for(int i = 0; i < N; i++) if(tin[i] == -1) dfs0(i);

    sz = vector<int>(scnt, 0);
    for(int i = 0; i < N; i++) {
        sz[ id[i] ]++;
    }
    col = vector<int>(N, -1);
    for(int i = 0; i < N; i++) if(sz[ id[i] ] > 1) {
        dfs1(i);
    }
    int mpos = -1;
    for(int i = 0; i < N; i++) if(sz[ id[i] ] > 1) {
        if(mpos == -1 || col[mpos] > col[i]) mpos = i;
    }

    if(1) {
        col[mpos]++;
        int u = ind[mpos];
        int la;
        while(u != mpos) {
            vector<int> chk(adj[u].size() + 1, 0);
            for(int i = 0; i < adj[u].size(); i++) {
                int v = adj[u][i];
                if(col[v] <= adj[u].size()) chk[ col[v] ] = 1;
            }
            for(int i = 0; i <= adj[u].size(); i++) {
                if(!chk[i]) {
                    col[u] = i;
                    break;
                }
            }
            la = col[u];
            u = ind[u];
        }
        if(la == col[mpos] - 1) {
            printf("POSSIBLE");
            return 0;
        }
        col[mpos]--;
    }

    //cout << mpos << endl;

    int u = ind[mpos];
    int la;
    while(u != mpos) {
        vector<int> chk(adj[u].size() + 1, 0);
        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i];
            if(col[v] <= adj[u].size()) chk[ col[v] ] = 1;
        }
        for(int i = 0; i <= adj[u].size(); i++) {
            if(!chk[i]) {
                col[u] = i;
                break;
            }
        }
        la = col[u];
        u = ind[u];
    }
    if(col[u] == la) printf("IMPOSSIBLE");
    else printf("POSSIBLE");
}


Measured memory_bytes: 22304
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#define int long long
#define endl "\n";
#define debug(x) cerr << #x << " is " << x << endl;
using namespace std;
int gcd(int a, int b) {
	if (!b) return a;
	return gcd(b, a % b);
}
void solve(){
	int a, b;
	cin >> a >> b;
	cout << a * b;


}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(15);
	int t;
	t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
    int n, l ;
    cin >> n >> l ;
    vector<int> vec (n) ;
    rep(i, n) vec[i] = i + 1 ;
    rep(i , n){
        vec[i] = vec[i] + l - 1 ;
    }
    int t = 200000 ;
    int num ; 
    rep(i, n){
        if(t > abs(vec[i])){
            t = abs(vec[i]) ;
            num = i ;
        }
    }
    int tot = 0;
    rep(i, n){
        if(i == num){
            continue ;
        }
        else {
            tot += vec[i] ;
        }
    }
    cout << tot << endl ;
}

Measured memory_bytes: 3580
import java.util.*;

public class Main {
	public static void main(String[] args) {
	
   Scanner sc = new Scanner(System.in);
   
    int N = sc.nextInt();
    Integer a[] = new Integer[N];
	for (int i=0; i<N; i++) {
		a[i] = sc.nextInt();
	}
	Integer b[] = new Integer[N];
	for (int j=0; j<N; j++) {
		b[j] = sc.nextInt();
	}
	Integer c[] = new Integer[N-1];
	for (int i=0; i<N-1; i++) {
		c[i] = sc.nextInt();
	}
	int m = 0;
	for(int i = 0; i<N; i++) {
		m += b[a[i] - 1];
	}
      for(int j = 0; j<N-1; j++){
        if(a[j] + 1  == a[j + 1]) {
			m += c[a[j] - 1];
		} 
      }
      System.out.println(m);
}
}




Measured memory_bytes: 23252
import java.lang.*
import java.math.BigInteger
import java.util.LinkedHashMap

fun main(args: Array<String>) {
    val (A,B) = readLine()!!.split(" ").map(String::toInt)

    var baisuA = getBaisu(A)
    val baisuB = getBaisu(B)

    for(key in baisuB.keys){
        if(baisuA.containsKey(key)){
            baisuA[key] = Math.max(baisuA[key]!!,baisuB[key]!!)
        }else{
            baisuA[key] = baisuB[key]!!
        }
    }

    var answer = BigInteger.ONE
    for(key in baisuA.keys){
        var n = BigInteger(key.toString())
        answer = answer.multiply(n.pow(baisuA[key]!!))
    }

    println(answer)
}

fun getBaisu(A : Int,baisu : LinkedHashMap<Int,Int> = LinkedHashMap()) : LinkedHashMap<Int,Int>{

    if(A == 1){
        return baisu
    }

    for(i in 2..A){
        if((A%i)==0){
            if(!baisu.containsKey(i)){
                baisu[i] = 1
            }else{
                baisu[i] = baisu[i]!!+1
            }
            return getBaisu(A/i,baisu)
        }
    }

    return baisu
}

Measured memory_bytes: 37876
n, m = map(int, raw_input().split())

A = [raw_input() for _ in xrange(n)]
B = [raw_input() for _ in xrange(m)]

for r in xrange(n-m+1):
    for c in xrange(n-m+1):
        f = True
        for x in xrange(m):
            for y in xrange(m):
                if A[r+x][c+y] != B[x][y]:
                    f = False
                    break
            if not f:
                break
        if f:
            print "Yes"
            exit()
print "No"


Measured memory_bytes: 2568
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N, K;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;

    ll ans = 0;

    int m0 = 0;
    rep(i, 1, N + 1) if (i % K == 0) m0++;
    ans = 1LL * m0 * m0 * m0;

    if (K % 2 == 0) {
        int c = 0;
        rep(i, 1, N + 1) if (i % K == K / 2) c++;
        ans += 1LL * c * c * c;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=1000;

int Eans[N+3][N+3];

int main(){
	int r,c,Va,Vb;scanf("%d%d%d%d",&r,&c,&Va,&Vb);
	if(Va==0){
		for(int i=1;i<=r;i++){
			for(int j=1;j<=c;j++)
				if(i<=Vb) printf("1");
				else printf("0");
			printf("\n");
		}
	}else if(Vb==0){
		for(int i=1;i<=r;i++){
			for(int j=1;j<=c;j++)
				if(j<=Va) printf("1");
				else printf("0");
			printf("\n");
		}
	}else{
		for(int i=1;i<=r;i++){
			for(int j=1;j<=c;j++){
				if((1<=i && i<=Vb)==(1<=j && j<=Va)) printf("1");
				else printf("0");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1152
// g++ -std=c++11 -O2 -Wall -Wl,--stack=268435456

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

typedef vector< int >      vi;
typedef vector< vi >       vvi;
typedef pair<int, int>     pi;
typedef vector< pi >       vpi;

typedef long long          ll;
typedef vector<ll>         vl;
typedef vector< vl >      vvl;

#define LARGE_INT     1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = (int)(a); i < (int)(b); i++)

const long LARGE_LONG = 1L << 62;

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int  n;
    cin >> n;
    vl  ps(n+1);
    vvl dp(n, vl(n,LARGE_LONG));  // dp[i][j]: minimal cost to combine j to j+i
    
    ps[0] = 0;
    REP(j, 0, n) { 
        ll a;
        cin >> a;
        ps[j+1] = ps[j] + a;
        dp[0][j] = 0;   // no cost from individual
    }
    REP(i, 1, n) REP(j, 0, n-i) {
        REP(k, 0, i) {
            dp[i][j] = min(dp[i][j], dp[k][j] + dp[i-k-1][j+k+1]);
        }
        dp[i][j] += ps[i+j+1] - ps[j];
    }
    cout << dp[n-1][0] << endl;
    return 0;
}

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

int main(){
  int n; cin >> n;
  vector<int> h(n);
  for(int i =0; i < n; i++){
    cin >> h.at(i);
  }
  bool ok = true;
  for(int i = 0; i < n - 1; i++){
    if(h.at(i + 1) > h.at(i)){
      h.at(i + 1)--;
      continue;
    }
    else if(h.at(i) == h.at(i + 1)) continue;
    else{
      ok = false;
      break;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <math.h>
#define N_MAX 10000

int isPrime(int x)
{
  int i;
  if (x <= 3) {
    return 1;
  } else if (x % 2 == 0) {
    return 0;
  } else {
    for (i = 3; i <= sqrt(x); i = i + 2) {
      if (x % i == 0) {
        return 0;
      }
    }
    return 1;
  }
}

int main(int argc, char *argv[])
{
  int i, j, n, x;
  int answer = 0;
  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    if(i < n)break;
  }
  
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    answer = answer + isPrime(x);
  }
  printf("%d\n", answer);
  return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables ***************/
int N, W;
vector<int> v, w;
int dp[105][10005];
/**********************************************/

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

    cin >> N >> W;
    v.assign(N, 0);
    w.assign(N, 0);
    REP(i, N) cin >> v[i] >> w[i];

    REP(i, 10005) dp[0][i] = 0;
    REP(i, N+1){
        REP(j, W+1){
            if(w[i] <= j) dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    cout << dp[N][W] << endl;
}



Measured memory_bytes: 7208
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  cin>>n;
  vector<int> t(n),a(n);
  rep(i,n)cin>>t[i];
  rep(i,n)cin>>a[i];
  int tmax=(-1)*INF,amax=(-1)*INF;
  int ttop,atop;
  vector<int> hoge(n);
  rep(i,n){
    if(tmax<t[i]){
      tmax=t[i];
      ttop=i;
    }
    if(amax<a[n-1-i]){
      amax=a[n-1-i];
      atop=n-1-i;
    }
    if(t[i]<a[i])hoge[i]=t[i];
    if(t[n-1-i]>a[n-1-i])hoge[n-1-i]=a[n-1-i];
    if(t[i]==a[i])hoge[i]=t[i];
  }
  if(tmax!=amax){
    cout<<0<<endl;
    return 0;
  }
  if(ttop>atop){
    cout<<0<<endl;
    return 0;
  }
  int ans=1,minall=hoge[0];
  if(hoge[0]>hoge[n-1])minall=hoge[n-1];
  rep(i,ttop){
    if(i==0)continue;
    if(hoge[i]==hoge[i-1]){
      ans*=hoge[i];
      ans%=MOD;
    }
  }

  for(int i=n-1;i>atop;i--){
    if(i==n-1)continue;
    if(hoge[i]==hoge[i+1]){
      ans*=hoge[i];
      ans%=MOD;
    }
  }
  int sub=atop-ttop-1;
  rep(i,sub){
    ans*=tmax;
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int n,m;
  cin>>n>>m;

  vector<vector<int>> edge(n);
  vector<int> iny = vector<int>(n,0);
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    x -= 1;
    y -= 1;
    edge[x].push_back(y);
    iny[y]++;
  }

  vector<int> d = vector<int>(n, 0);
  queue<int> st;
  for(int i=0;i<n;i++){
    if(iny[i]==0){
      st.push(i);
    }
  }

  while(st.size()>0){
    int s = st.front();
    st.pop();
    for(int j=0;j<edge[s].size();j++){
      int v = edge[s][j];
      if(iny[v]>0){
        iny[v]--;
      }
      if(iny[v]==0){
        d[v] = max(d[v], d[s]+1);
        st.push(v);
      }
    }
  }

  int res = 0;
  for(int i=0;i<d.size();i++){
    res = max(res, d[i]);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 6528
import java.util.Arrays;
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int[] P = new int[N];
        for(int i = 0; i < N; i++) {
            P[i] = scanner.nextInt();
        }
        Arrays.sort(P);
        int sum = 0;
        for(int i = 0; i < K; i++) {
            sum += P[i];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 38688
s = input().split()
ans = []
for i in s:
    if i[-1] == ',' or i[-1] == '.':
        if 4 <= len(i) <=7:
            ans.append(i[:-1])
    else:
        if 3 <= len(i) <= 6:
            ans.append(i)

print(*ans)


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

int main() {
  string N;
  cin >> N;
  string N2 = N;
  N2[0]--;
  for (int i = 1; i < N2.size(); i++) {
    N2[i] = '9';
  }
  int a1 = 0, a2 = 0;
  for (int i = 0; i < N.size(); i++) {
    a1 += N[i] - '0';
    a2 += N2[i] - '0';
  }
  cout << max(a1, a2) << endl;
}

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

int main()
{
  int n,m; cin>>n>>m;
  int sum=0;
  vector<int> a(n); for(int i=0;i<n;i++){ cin>>a[i]; sum+=a[i];}
  double min = (double)sum/(4*m);
  sort(a.begin(),a.end(),greater<int>());
  if(a[m-1]<min) cout<<"No";
  else cout<<"Yes";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
 
class TEST{
	static void Main(){
	while(true){
		var s=Console.ReadLine().Split(' ');
		if(s[0]=="0" && s[1]=="0")break;
		Sol mySol=new Sol(int.Parse(s[0]),int.Parse(s[1]));
		mySol.Solve();
	}
	}
}
 
 
class Sol{
	 
	static int[] Table;
	static int[] ScoreTable;
	 
	static int n;
	static int U;
 
	public Sol(int n_,int U_){
		n=n_;U=U_;
		ScoreTable=new int[n];
		Table=new int[n];
		for(int i=0;i<n;i++)Table[i]=0;
		 
		for(int i=0;i<n;i++){
			var d=Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));
			ScoreTable[i]=d[0];
			for(int j=0;j<d[1];j++){
				Table[i]=Table[i]|(0x1<<d[j+2]);
			}
		}
	}
	 
	public void Solve(){
		ClassSet[] ToGet=new ClassSet[n];
		for(int i=0;i<n;i++){
			ToGet[i]=new ClassSet(search(i));
//Console.Write("{0}-th",i);for(int j=0;j<n;j++){if((ToGet[i].State&(0x1<<j))>0)Console.Write(" {0}",j);}Console.WriteLine("");
		}
 
		HashSet<int>[] Hash=new HashSet<int>[n+1];
		 
		ClassSet C=null;
		int ans=21;
		 
		Hash[0]=new HashSet<int>();
		Hash[0].Add(0);
		for(int i=0;i<n;i++){
			Hash[i+1]=new HashSet<int>();
			foreach(int ss in Hash[i]){
				Hash[i+1].Add(ss);
				//if((ss&(0x1<<i))==0){
					C=new ClassSet(ss|ToGet[i].State);
					if(C.Score>=U && C.Count<ans)ans=C.Count;
					if(C.Score<U)Hash[i+1].Add(C.State);
				//}
			}
//Console.WriteLine("Hash[{0}].Count={1}",i+1,Hash[i+1].Count);
		}
		 
		Console.WriteLine(ans);
 
	}
	 
	int search(int d){
 
		//dをとるのに必要な全科目を調べる
		int ret=0x1<<d;
		for(int i=0;i<n;i++){
			if((Table[d]&(0x1<<i))>0)ret=ret|search(i);
		}
		return ret;
	}
	 
 
	class ClassSet:IComparable<ClassSet>{
		int state;
		public int State{
			get{return state;}
		}
		public int Count{
			get{
				int i=state;
				i=(i&0x55555555)+((i>>1)&0x55555555);
				i=(i&0x33333333)+((i>>2)&0x33333333);
				i=(i&0x0F0F0F0F)+((i>>4)&0x0F0F0F0F);
				i=(i&0x00FF00FF)+((i>>8)&0x00FF00FF);
				i=(i&0x0000FFFF)+((i>>16)&0x0000FFFF);
				return i;
			}
		}
 
 
		public int Score{
			get{
				int score=0;
				int s=state;
				int i=0;
				for(;s>0;s=s>>1){
					score+=(s&0x1)*ScoreTable[i++];
				}
				return score;
			}
		}
		public ClassSet(int state_){
			state=state_;
		}
 
		public int CompareTo(ClassSet T){
			//単位数多い方が優先度高い(+)
			if(this.Score!=T.Score)return this.Score-T.Score;
			//単位数同じなら科目数少ない方が優先度高い
			return T.Count-this.Count;
		}
	}
}
 
 
static class dbg{
	public static void w(String s){
		Console.WriteLine(s);
	}
	public static void w(int d){
		Console.WriteLine(d);
	}
	public static void w(long d){
		Console.WriteLine(d);
	}
}

Measured memory_bytes: 92900
s = input()

s1 = int(s[:2])
s2 = int(s[2:])

mm_flag = False
yy_flag = False

result = 'No'

# yymm / mmyyに当てはまるかの判定を行ってから、結果によって場合分けを行う。
#
if 12 >= s1 > 0:
    mm_flag = True
if 12 >= s2 > 0:
    yy_flag = True

if mm_flag and yy_flag:
    print('AMBIGUOUS')
elif mm_flag and not yy_flag:
    print('MMYY')
elif not mm_flag and yy_flag:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int 
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int n,m;
    cin>>n>>m;
    vector<int> v(n);
    int lc=1;
    rep(i,0,n){
        cin>>v[i];
        v[i] = v[i]/2;
        lc = (lc*v[i]/__gcd(lc,v[i]));
    }
    // cout<<"LCM: "<<lc<<endl;
    rep(i,0,n){
        if((lc/v[i])%2==0){
            cout<<"0"<<endl;
            return;
        }
    }
    cout<<(int)ceil(floor((1.0*m)/lc)/2);
}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 1152
h,w,k = gets.split.map &:to_i
s = Array.new(h){ gets.chomp.chars.map &:to_i }

cs = Array.new(h){ [0] * (w+1) }
h.times do |y|
  s[y].each_with_index do |v, i|
    cs[y][i + 1] = cs[y][i] + s[y][i]
  end
end

# p [h,w,k,s,cs]
# p cs.map{|a|a[-1]}

# 縦の分割パターンがbitのとき
# left,rightで分割したときの
# ホワイトチョコの最大値を返す
def count(bit,left,right,cs,h)
  ans = 0
  cnt = 0
  h.times do |y|
    # p [left,right,cs]
    # exit
    cnt += cs[y][right] - cs[y][left]
    if bit[y] == 1 # 分割あり
      ans = cnt if ans < cnt
      cnt = 0
    end
  end
  ans = cnt if ans < cnt
  return ans
end

# p count(0, 0, 3, cs, h)
$c = 0
ans = 10**9
(2**(h-1)).times do |bit|
  # p [bit]
  left = 0
  right = 1
  div = bit.to_s(2).count("1") # 分割数
  while right <= w
    ret = count(bit, left, right, cs, h)
    if ret > k # && left < right # 超える前のrightを採用
      if left + 1 == right
        div = 10**9
        break # whileを抜けて、left=0, right=1からやり直し
      else
        div += 1
        left = right - 1
      end
    else
      right += 1
    end
    # p [bit,left,right,ret,k,div]
  end
  ans = div if ans > div
end

puts ans

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    if (N==1){
        cout << M << "\n";
        return 0;
    }
    vector<int> div;
    for (int i=1;i*i<=M;i++){
        if (M%i == 0){
            div.push_back(i);
            if (i*i!=M){
                div.push_back(M/i);
            }
        }
    }
    sort(div.begin(),div.end());
    int p = 0;
    for (int i=0;i<div.size();i++){
        if ((ll)div[i]*(ll)N>(ll)M) {
            p = i;
            break;
        }
    }
    int ans;
    ans = div[p-1];
    cout << ans << "\n";
}

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

int main() {

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

    int n;
    cin >> n;
    vector<int> v(n);

    for (int i = 0; i < n; i++) {
        cin >> v[i];
        v[i] -= 1;
    }

    long long int s = 0;
    for (int i = 0; i < n; i++) {
        s += v[i];
    }

    cout << s << endl;
}

Measured memory_bytes: 256
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

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


int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(N);
    REP(i,N){
        cin>>A[i];
    }
    //inputend;
    int twopow=0;//全体が2の何乗となっているかを確認
    int a0=A[0];
    while(a0%2==0){
        a0/=2;
        twopow+=1;
    }
    int beta=pow(2,twopow);
    REP(i,N){
        if(A[i]%beta!=0||A[i]%(beta*2)==0){
            cout<<0<<endl;
            return 0;
        }else{
            A[i]/=beta;
        }
    }
    //データ整理終了
    //最小公倍数を求める
    ll X=A[0];
    REPi(i,1,N){
        ll alfa=gcd(X,A[i]);
        X=X/alfa*A[i];
        if(X>M){
            cout<<0<<endl;
            return 0;
        }
    }
    X*=pow(2,twopow-1);
    //Xは最小のXである．
    if(X>M){
        cout<<0<<endl;
    }else{
        cout<<int(floor((M-X)/(2*X))+1)<<endl;
    }   
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
using namespace std;
using lint = long long;
using ld = long double;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(lint i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int n;
vector<vector<int>> tree;

pint dfs(int pos, int par, int dpt) {
	pint ret = {dpt, pos};
	REP(i, tree[pos].size()) {
		if(tree[pos][i] == par) continue;
		ret = max(ret, dfs(tree[pos][i], pos, dpt + 1));
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	tree.resize(n);
	REP(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		tree[a].pb(b);
		tree[b].pb(a);
	}
	pint tmp1 = dfs(0, -1, 0);
	pint tmp2 = dfs(tmp1.second, -1, 0);
	vector<char> dp(202020, false);
	dp[0] = true;
	dp[1] = false;
	FOR(i, 2, 202020) {
		if(!dp[i - 1] || !dp[i - 2]) dp[i] = true;
	}
	if(dp[tmp2.first]) {
		cout << "First" << endl;
	} else {
		cout << "Second" << endl;
	}
	return 0;
}
/* --------------------------------------- */


Measured memory_bytes: 30208
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
a=[0]*5
a[0]=A
a[1]=B
a[2]=C
a[3]=D
a[4]=E
b=[0]*5
for x in range(5):
  if a[x]%10!=0:
    b[x]=a[x]%10
  else:
    b[x]=10
t=min(b)
ti=b.index(t)
ans=0
for i in range(5):
  if i!=ti:
    if a[i]%10!=0:
      ans+=a[i]+(10-a[i]%10)
    else:
      ans+=a[i]
ans+=a[ti]
print(ans)


Measured memory_bytes: 9224
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
  ll n, k;
  cin >> n >> k;
  vll x(n);
  ll posi = n-1;
  rep(i, n){
    cin>>x[i];
  }
  ll a;
  ll b;
  ll ans = 2*pow(10, 9) +1;
  rep(i, n-k+1){
    a = x[i];
    b = x[i+k-1];
    if (b <= 0){
      ans = min(-1*a, ans);
    }
    else if (a >= 0){
      ans = min(b, ans);
    }
    else{
      ans = min(ans, min(2*(-1*a)+b, 2*b-a));
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

N = int(input())
G = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a].append((b, i))
    G[b].append((a, i))


def get_path(u, v):
    stack = [u]
    prev = [None] * (N+1)
    visited = [False] * (N+1)
    visited[u] = True
    while stack:
        node = stack.pop()
        for next, i in G[node]:
            if not visited[next]:
                visited[next] = True
                prev[next] = (node, i)
                stack.append(next)
    path = 0
    node = v
    while node != u:
        p, i = prev[node]
        node = p
        path += 1 << i
    return path


def count(bits, N):
    cnt = 0
    for i in range(N):
        if ((bits >> i) & 1) == 1:
            cnt += 1
    return cnt


M = int(input())
uv = [tuple(map(int, input().split())) for _ in range(M)]
paths = [get_path(u, v) for u, v in uv]
ans = 2**(N-1)
for bit in range(1, 1 << M):
    cnt = 0
    tmp = 0
    for i in range(M):
        if ((bit >> i) & 1) == 1:
            cnt += 1
            tmp |= paths[i]
    ans += (-1)**cnt * 2**(N-1-count(tmp, N-1))
print(ans)


Measured memory_bytes: 42348
#include<bits/stdc++.h>
using namespace std;
int main(){
int i,a,b,c,d,e,f;
cin>>a;
b=a%10;
c=a/10;
d=c%10;
e=c/10;
f=e%10;
if(b==7 || d==7 || f==7){
    cout<<"Yes"<<endl;}
else
    cout<<"No"<<endl;
return 0;}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int n;
    cin >> n;
    vector<int> vec(n);
    els(vec) {
        cin >> el;
    }
    int res = 0;
    for (int i = 1; i < n - 1; ++i) {
        int mn = min(vec[i - 1], vec[i + 1]);
        int mx = max(vec[i - 1], vec[i + 1]);
        if (vec[i] < mx && vec[i] > mn) {
            ++res;
        }
    }
    cout << res << endl;
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
	auto nm = readNums!int;
	if(nm[0] == nm[1]){
		writeln("Yes");
	} else {
		writeln("No");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i,a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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()
{
    string s;
    cin >> s;
    REP(i,3){
        if(s[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
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() {
    int n; cin >> n;
    cout << ceil((double)n/2) << endl;
}



Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 1000020
using namespace std;
LL read(){
	LL nm=0,fh=1;char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
LL n,m,D,p[M],F[M],ans,pre[M],suf[M];
void solve(){
	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+p[i];
	for(int i=n;i;i--) suf[i]=suf[i+1]+D-p[i];
	for(int i=1;i<=n;i++){
		LL lt,rt,now=0;
		lt=((n+i)>>1),rt=lt+1;
		now=((pre[lt]-pre[i-1]+suf[rt])<<1);
		if((n-i-1)%2==0) now-=D-p[rt];
		else now-=p[lt];
		ans=max(ans,now);
	}	
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	D=read(),n=read(); 
	for(int i=1;i<=n;i++) p[i]=read();
	ans=max(D-p[1],p[n]),solve();
	for(int i=1;i<=n;i++) p[i]=D-p[i]; reverse(p+1,p+n+1);
	solve(),printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 12032