akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main()
{
    boost;
    ll n,i,j,x,t,m;
    string s;
    map<ll,ll>ac,wa;
    cin>>n>>m;
    while(m--){
        cin>>x>>s;
        if(s=="AC") {
            if(ac[x]==0) ac[x]++;
        }
        else {
            if(ac[x]==0) wa[x]++;
        }
    }
    ll a,w;
    a=w=0;
    for(i=1;i<=n;i++){
        if(ac[i]>0){
            a++;
            w+=wa[i];
        }
    }
    cout<<a<<" "<<w;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
ll ceil1(ll a,ll b)
{	if(a%b==0)
		return a/b;
	else
		return a/b+1;}

void solve()
{
	string s;
	cin>>s;
	int as=0,ans=0;
	for(int i=0;i<=2;i++)
	{
		if(s[i]=='R')
			ans++;
		else
			as=max(as,ans),ans=0;
	}
	cout<<max(ans,as);
	return;
}

int main()
{
	fast;
	ll q=1;
	// cin>>q;
	while(q--)
		solve();
	return 0;
}



Measured memory_bytes: 3624
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [a, b, c, x] = stdin.split('\n').map(Number)

const ans = () => {
  let count = 0

  for (let i = 0; i <= a; i++) {
    for (let j = 0; j <= b; j++) {
      for (let v = 0; v <= c; v++) {
        const sum = i * 500 + j * 100 + v * 50

        if (sum === x) {
          count++
        }
      }
    }
  }

  console.log(count)
}

ans()


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

int root(int a) {
	int res = 1;

	while (res * res < a)
		++res;

	if (res * res == a)
		return 1;
	else
		return 0;
}

int main() {
	int n, d, x[10][10], cou = 0;
	int p = 0;

	cin >> n >> d;
	for (int N = 0; N < n; ++N)
		for (int D = 0; D < d; ++D)
			cin >> x[N][D];

	for(int i = 0; i < n-1; ++i)
		for (int j = i+1; j < n; ++j) {
			for (int k = 0; k < d; ++k) {
				p += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}

			if (root(p))
				++cou;
			p = 0;
		}

	cout << cou << endl;

	return 0;
}

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

int x,y,z,k;

bool inc(tuple<int,int,int>& t,int i){
    if(i==0){
        if(get<0>(t)==x-1)return false;
        get<0>(t)++;
    }
    else if(i==1){
        if(get<1>(t)==y-1)return false;
        get<1>(t)++;
    }
    else{
        if(get<2>(t)==z-1)return false;
        get<2>(t)++;
    }
    return true;
}

void dec(tuple<int,int,int>& t,int i){
    if(i==0)get<0>(t)--;
    else if(i==1)get<1>(t)--;
    else get<2>(t)--;
}

int main(){
    cin>>x>>y>>z>>k;
    ll a[1000],b[1000],c[1000];
    for(int i=0;i<x;i++)cin>>a[i];
    for(int i=0;i<y;i++)cin>>b[i];
    for(int i=0;i<z;i++)cin>>c[i];
    sort(a,a+x,greater<ll>());
    sort(b,b+y,greater<ll>());
    sort(c,c+z,greater<ll>());
    priority_queue<pair<ll,tuple<int,int,int>>> pq;
    set<tuple<int,int,int>> set;
    pq.push(make_pair(a[0]+b[0]+c[0],make_tuple(0,0,0)));
    set.insert(make_tuple(0,0,0));
    for(int i=0;i<k;i++){
        auto t=pq.top();
        pq.pop();
        cout<<t.first<<endl;
        auto u=t.second;
        for(int j=0;j<3;j++){
            if(!inc(u,j))continue;
            if(set.find(u)==set.end()){
                pq.push(make_pair(a[get<0>(u)]+b[get<1>(u)]+c[get<2>(u)],u));
                set.insert(u);
            }
            dec(u,j);
        }
    }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using vl = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;
const ll inf = 1000000000000000;

#define pi acos(-1)
#define pb push_back
#define test int TEST;cin>>TEST;while(TEST--)
#define vsort(xx) sort(xx.begin(),xx.end())
#define vrevsort(xx) sort(xx.rbegin(),xx.rend())
ull f_u(ull n) 
{ 
    
    ull count = 0; 
  
    for ( ull i = 5; n / i >= 1; i *= 5) 
        count += n / i; 
  
    return count; 
} 


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ull n;cin>>n;
    ull ans=0;
    if(n%2==1) ans=0;
    
    else{
    ans=f_u(n/2);
        
    
    }
    
    cout<<ans;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#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 pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n;
string s;
string ss[4] = {"AC","WA","TLE","RE"};
int a[5];
void solve(){
	rep(i,0,n-1){
		cin >> s;
		if(s == ss[0]) a[0]++;
		else if(s == ss[1]) a[1]++;
		else if(s == ss[2]) a[2]++;
		else if(s == ss[3]) a[3]++;
	}
	rep(i,0,3){
		printf("%s x %d\n",ss[i].c_str(),a[i]);
	}
	return;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	solve();	
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 3736
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string K;
  ll D;
  cin >> K >> D;
  vll digits(0);
  ll count=0;

  REP(i, K.size()){
    digits.push_back((ll)(K[i]-'0'));
    count++;
  }

  vector<vvll> dp(count+1, vvll(D, vll(2, 0)));
  dp[0][0][0] = 1;
  FOR(i, 0, count){
    FOR(j, 0, D){
      FOR(k, 0, 10){
        if(k<digits[i]){
          dp[i+1][(j+k)%D][1] = (dp[i+1][(j+k)%D][1]+dp[i][j][0])%MOD;
        }else if(k==digits[i]){
          dp[i+1][(j+k)%D][0] = (dp[i+1][(j+k)%D][0]+dp[i][j][0])%MOD;
        }
        dp[i+1][(j+k)%D][1] = (dp[i+1][(j+k)%D][1]+dp[i][j][1])%MOD;
      }
    }
  }

  ll ans = dp[count][0][0] + dp[count][0][1];
  ans--;
  while(ans<0) ans+=MOD;

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 55424
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        String s = sc.next();
        int cnt = 0;

        for (int i=0; i<s.length(); i++) {
            int tmp = s.charAt(i) - 48;
            cnt += tmp;
        }

        if (cnt % 9 ==0) System.out.println("Yes");
        else System.out.println("No");
    }


}



Measured memory_bytes: 40156
#include <iostream>
#include <stack>

using namespace std;

int main ()
{
	stack<int> st;
	int a;

	while ( cin >> a ) {
		if (a == 0) {
			cout << st.top() << endl;
			st.pop();
		} else {
			st.push(a);
		}
	}
	return 0;
}




Measured memory_bytes: 3080
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
#include<bitset> 
#include<type_traits>
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

const int mod = 1000000007;
const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
}

int main(){
    int N,M;cin >> N >> M;

    vector<P_ii> vec(M);

    REP(i,M) cin >> vec[i].second >> vec[i].first;

    sort(all(vec));

    int cur = 0;
    int ans = 0;
    REP(i,M){
        P_ii p = vec[i];

        if(cur <= p.second) {
            cur = p.first;
            ans++;
        }
    }

    pl(ans)

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200100
using namespace std;
int a[maxn];
int  main()
{
	int o=1;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	a[0]--;
	for(int i=1;i<n;i++)
	{
		if(a[i]<a[i-1])
			o=0;
		if(a[i]>a[i-1])
			a[i]--;
	}
	if(o)
		printf("Yes\n");
	else
		printf("No\n");
		
}

		

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main () {
  int n, a, b;
  cin >> n >> a >> b;
  vi x(n);
  rep(i,n) cin >> x[i];
  
  int pos = x[0];
  ll ans = 0;
  for (int i = 1; i < n; ++i) {
    int dis = x[i] - pos;
    if (dis*a < b) ans += (ll)dis*a;
    else ans += (ll)b;
    pos = x[i];
  }

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

Measured memory_bytes: 1024
N = int(input())
A = []
for _ in range(N):
    b = int(input())
    A.append(b)

B = sorted(A)
mfirst = B[-1]
msecond = B[-2]

for i in range(N):
    if A[i] == mfirst:
        print(msecond)
    else:
        print(mfirst)


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    string A, B;
    cin >> A >> B;
    if(sz(A)>sz(B)){
        puts("GREATER");
    }
    else if(sz(A)<sz(B)){
        puts("LESS");
    }else{
        if(A>B){
        puts("GREATER");
        }
        else if(A<B){
            puts("LESS");
        }else{
            puts("EQUAL");
        }
    }

    return 0;
}

Measured memory_bytes: 256
/*
* @author:  codancer
* @createTime:  2020-04-12, 20:06:24
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
int main(){
	int k;
	cin>>k;
	ll ans=0;
	rep(i,1,k){
		rep(j,1,k){
			rep(d,1,k){
				ans+=__gcd(i,__gcd(j,d));
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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



int main() {

	ll N, Z, W;
	cin >> N >> Z >> W;

	vector<ll> a(N + 1);

	repn(i, N) cin >> a[i];

	a[0] = W;

	vector<ll> dpX(N), dpY(N);

	dpX[N - 1] = abs(a[N - 1] - a[N]);
	dpY[N - 1] = dpX[N - 1];

	for (int i = N - 2; i >= 0; i--) {
		dpX[i] = abs(a[N] - a[i]);
		for (int j = i+1; j <= N - 1; j++) {
			dpX[i] = max(dpX[i], dpY[j]);
		}

		dpY[i] = abs(a[N] - a[i]);
		for (int j = i + 1; j <= N - 1; j++) {
			dpY[i] = min(dpY[i], dpX[j]);
		}
	}

	cout << dpX[0];

	system("PAUSE");

	

}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (ll i = 0; i < (ll)(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;
}
const long long INF = 1LL << 60;

ll n;
int main()
{
    int x;
    cin >> x;
    if (x > 0)
        cout << 0 << endl;
    else
        cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

#define MAX_N 200005

class UnionFind
{
public:
  int par[MAX_N];
  int depth[MAX_N];
  int nGroup[MAX_N];

  UnionFind(int n) {
    init(n);
  }

  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }

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

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

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  UnionFind uf(n);
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    uf.unite(x, y);
  }
  map<int, vector<int>> mp;
  rep(i, n) {
    mp[uf.root(i)].push_back(i);
  }
  priority_queue<pair<int, int>> q;
  for(auto& ele: mp) {
    q.push({ele.second.size(), ele.first});
  }
  priority_queue<ll, vector<ll>, greater<ll>> q2;
  ll ans = 0;
  int root = mp[q.top().second].front();
  for(int i: mp[q.top().second]) q2.push(A[i]);
  q.pop();
  while(!q.empty()) {
    if(q2.empty()) break;
    auto ele = q.top(); q.pop();
    priority_queue<ll, vector<ll>, greater<ll>> q3;
    for(int i: mp[ele.second]) q3.push(A[i]);
    ans += q2.top() + q3.top();
    uf.unite(root, mp[ele.second].front());
    q2.pop(); q3.pop();
    while(!q3.empty()) {
      q2.push(q3.top());
      q3.pop();
    }
  }
  bool ok = true;
  rep(i, n) {
    if(uf.root(i) != uf.root(root)) ok = false;
  }
  if(ok) cout << ans << "\n";
  else cout << "Impossible" << "\n";
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#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 inf 9000000000000000000
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto& a : x)

bool mysort(ii x, ii y){
  return x.first+x.second > y.first+y.second;
}

int main(){
  ios::sync_with_stdio(0);
  ll n;
  vii a;
  cin >> n;
  a.assign(n,{0,0});
  rep(i,0,n) cin >> a[i].first >> a[i].second;
  sort(all(a),mysort);
  ll res = 0;
  rep(i,0,n){
    if (i%2 == 0) res += a[i].first;
    else res -= a[i].second;
  }
  cout << res << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	string s;
	cin>>s;
	int a=0,b=0;
	for (int i=0;i<s.length();i++)
	{
		if (s[i]=='+')
		a++;
		else
		b++;
	}
	cout<<a-b;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << '\n'

typedef int64_t Int;
const double pi = M_PI;

using namespace std;

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

    string a, b;

    for (int i = 1; i < n.size(); i++) {
        if ((n.size() - i) % 2 == 0) {
            a = n.substr(0, (n.size() - i) / 2);
            b = n.substr((n.size() - i) / 2, (n.size() - i) / 2);

          
            if (a == b) {
                cout << n.size() - i << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        
        //int x = stdIn.nextInt();
        int num[] = new int[n];
        //String s = stdIn.next();
        //String t = stdIn.next();
        //char c[] = s.toCharArray();
        //int sum = 0;
        //boolean flag = true;
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        }
        
        int q = stdIn.nextInt();
        
        for(int i = 0; i < q; i++){
            int com = stdIn.nextInt();
            int b = stdIn.nextInt();
            int e = stdIn.nextInt();
            
            if(com == 0){
                int min = 1000000001;
                for(int j = b; j < e; j++){
                    if(num[j] < min){
                        min = num[j];
                    }
                }
                System.out.println(min);
            }else{
                int max = -1000000001;
                for(int j = b; j < e; j++){
                    if(num[j] > max){
                        max = num[j];
                    }
                }
                System.out.println(max);
            }
        }
        //System.out.println(sum);

        //System.out.println();
        //System.out.print();

        stdIn.close();
    }
}




Measured memory_bytes: 34908
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[][] ball = new int[2][n];
		for (int i = 0; i < n; i++) {
			int num = Integer.parseInt(sc.next());
			ball[0][i] = num;
			ball[1][num - 1]++;
		}
		long defans = 0;
		for (int i = 0; i < n; i++) {
			defans += ((long) ball[1][i] * (ball[1][i] - 1)) / 2;
		}
		defans++;
		for (int i = 0; i < n; i++) {
			System.out.println((long) defans - ball[1][ball[0][i] - 1]);
		}
	}
}

Measured memory_bytes: 73392
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(Math.Min(abc[1] / abc[0], abc[2]));
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e4+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;


vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}
lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}
int dx[4]={-1,0,0,1}, dy[4]={0,1,-1,0};

// ---- コーディングはここから！ ('-')7
struct Line {
	mutable lli k, m, p;
	bool operator<(const Line& o) const { return k < o.k; }
	bool operator<(lli x) const { return p < x; }
};

struct LineContainer: multiset<Line,less<>>{
	lli div(lli a, lli b){return a/b -((a^b)<0 and a%b);}

	bool isect(iterator x, iterator y){
		if(y==end()){x->p=INF;return false;}
		if(x->k==y->k)x->p=x->m>y->m?INF:-INF;
		else x->p = div(y->m-x->m,x->k-y->k);
		return x->p>=y->p;
	}

	void add(lli k, lli m){
		auto z = insert({k,m,0}),y=z++,x=y;
		while(isect(y,z))z=erase(z);
		if(x!=begin() and isect(--x,y))isect(x,y=erase(y));
		while((y=x)!=begin() and (--x)->p>=y->p)isect(x,erase(y));
	}

	lli query(lli x){
		assert(!empty());
		auto l =*lower_bound(x);
		return l.k*x+l.m;
	 }
};
void solve(){
	lli n,c; cin>>n>>c;
	vl h(n); fore(i,0,n)cin>>h[i];
	vl dp(n,INF);
	LineContainer cht;
	dp[0]=0;
	cht.add(2*h[0], -1* h[0] * h[0]);
	fore(i,1,n){
		dp[i]= c+h[i]*h[i]-cht.query(h[i]);
		cht.add(2*h[i], -(dp[i]+ h[i] * h[i]));
	}
	cout<<dp[n-1]<<ENDL;
}

int main(){_
	//int t; cin>>t; fore(tt,0,t)

	solve();
}


Measured memory_bytes: 18716
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, K;
	cin >> N >> K;
	VI P(N);
	REP(i, N)cin >> P[i];
	//rSORT(P);

	double ans = 0;

	vector<double>tmp(N);

	REP(i, N) {
		double cnt = P[i] * (P[i] + 1) / 2;
		cnt /= P[i];
		tmp[i] = cnt;
	}
	
	REP(i, K) {
		ans += tmp[i];
	}
	double op = ans;
	FOR(i, K, N) {
		op -= tmp[i - K];
		op += tmp[i];
		ans = max(ans, op);
	}


	printf("%.9f\n", ans);

	return 0;
}



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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

int main(){
  string s;
  cin>>s;
  int cnt(0);
  for(int i(0);i<int(s.size());i++){
    if(s[i] == '1') cnt++;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3556
n = int(raw_input())
for i in range(n):
	s = raw_input()
	length = len(s)
	organize_set = set([s, s[::-1]])
	for j in range(1,length):
		f = s[:j]
		frev = f[::-1]
		b = s[j:]
		brev = b[::-1] 
		organize_set.add(f + brev)
		organize_set.add(b + f)
		organize_set.add(brev + f)
		organize_set.add(frev + b)
		organize_set.add(frev + brev)
		organize_set.add(b + frev)
	print len(organize_set)

Measured memory_bytes: 4264
#include <cassert>
#include <iostream>
#include <functional>
#include <iomanip>
#include <set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <deque>
#include <algorithm>
#include  <cstring>
#include <string>
#include <cmath> 
using namespace std;
typedef long long LL;
const int MAX = 210000;
const LL base = 1e9 + 7;


struct Node {
	int x, y, w;
};

int zz[MAX][3];
int dp[MAX][3];
void solve() {

	int result = 0;
	int n;

	cin >> n;
	for (int i=0; i<n; ++i) {
		for (int j=0; j<3; ++j) 
			cin >>zz[i][j];
	}
	for (int j=0; j<3; ++j)  {
		dp[0][j] = zz[0][j];
	}

	for (int i=1; i<n; ++i) {
		for (int j=0; j<3; ++j)  {
			for (int k=0; k<3; ++k) {
				if (j==k) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][k]);
			}
			dp[i][j] += zz[i][j];
		}
	}
	for (int j=0; j<3; ++j)  {
		result = max(result, dp[n-1][j]);
	}	
	cout << result << endl;

}

int main() {
	const int inId = 0;
	const int outId = 0;
	if (inId>0) {
		cerr << "redirect stdin to input " << inId << endl;
		string s = "input";
		s += to_string(inId);
		s += ".txt";
		auto r = freopen(s.c_str(), "r", stdin);	
		if (r == nullptr) {
			cerr<< "invalid input file "<< s;
		}
	}
	if (outId>0) {
		cerr << "redirect stdout to stdout " << outId << endl;
		string s = "stdout";
		s += to_string(outId);
		s += ".txt";
		auto r = freopen(s.c_str(), "w", stdout);
		if (r == nullptr) {
			cerr<< "invalid output file "<< s;
		}		
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // close sync between cout and printf
	cout.precision(10);
	solve();
}
 

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b)
    cout << c << endl;
  else if (b == c)
    cout << a << endl;
  else
    cout << b << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
#define MAXN 1000000007
 
 
int main() {
	ll a,b;
	cin>>a>>b;
	if ((a+b)==3) {
		cout<<3;
	}
	if ((a+b)==4) {
		cout<<2;
	}
	if ((a+b)==5) {
		cout<<1;
	}
}

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

namespace ABC098A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, x;

            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);

            x = A + B;
            if (x < A - B) x = A - B;
            if (x < A * B) x = A * B;


            Console.WriteLine(x);
            Console.ReadKey();

        }
    }
}


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

int main() {
  int A,B,C;

  cin >> A >> B >> C;

  int x = max({A,B,C});
  int y = min({A,B,C});

  if((x==7 && y==5) && ((A+B+C)-(x+y) == 5)){
      cout << "YES";
  }

  else
    cout << "NO";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int N, buf;
    std::vector<int> bucket(9);
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> buf;
        if(buf >= 3200){
            bucket[8]++;
        }else{
            bucket[buf/400]++;
        }
    }
    int cnt =0;
    for(int i=0; i<8; i++){
        if(bucket[i]>0)cnt++;
    }
    if( cnt ==0 ){
        cout << "1 " << bucket[8] << endl;
    }else{
        cout << cnt << " " << cnt+bucket[8] << endl;
    }
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

ll n;
vector<ll> A;
vector<ll> B;

bool judge(ll a){
    ll rem=A[0]-a/2;
    for(int i=1;i<n;i++){
        rem=A[i]-rem;
    }
    return rem>=a/2;
}


int main(){
    cin>>n;
    A.resize(n);
    cin>>A;
    ll l=0,r=1e16;
    while(r-l>5){
        ll m=(l+r)>>1;
        if(judge(m*2)){l=m;}
        else{r=m;}
    }
    ll ans=-1;
    for(ll i=r;i>=l;i--){
        if(judge(i*2)){
            ans=i*2;
            break;
        }
    }
    vector<ll> B;
    for(ll i=0;i<n;i++){
        B.push_back(ans);
        ans=(A[i]-ans/2)*2;
    }
    cout<<B<<endl;
    
    
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

ll N;
ll A[100005];
vector<vll> G(100005);
bool ok = true;

ll dfs(ll v, ll prev) {
        if (G[v].size() == 1) return (A[v]);
        ll sum = 0ll;
        int cnt = 0;
        ll maxv = 0;
        for (auto &u : G[v]) {
                if (u != prev) {
                        ll val = dfs(u, v);
                        if (val > 0) {
                                cnt++;
                                sum += val;
                                maxv = max(maxv, val);
                        }
                }
        }

        if (cnt == 0) return (A[v]);
        if (cnt == 1) {
                if (sum != A[v]) ok = false;
                return (A[v]);
        }
        
        if (sum < A[v]) ok = false;
        if (sum > A[v] * 2 || maxv > A[v]) ok = false;
        return (A[v] * 2 - sum);
}

int main() {
        cin >> N;
        for (int i = 0; i < N; i++) {
                cin >> A[i];
        }
        for (int i = 0; i < N - 1; i++) {
                int a, b;
                cin >> a >> b; --a, --b;
                G[a].push_back(b);
                G[b].push_back(a);
        }
        if (N == 2) {
                if (A[0] == A[1]) cout << "YES" << endl;
                else cout << "NO" << endl;
                return (0);
        }
        for (int i = 0; i < N; i++) {
                if (G[i].size() > 1) {
                        ll a = dfs(i, -1);
                        if (ok && a == 0) cout << "YES" << endl;
                        else cout << "NO" << endl;
                        break;
                }
        }
    return (0);
}

Measured memory_bytes: 13184
K = input()
D = int(input())
L = len(K)
MOD = 10**9+7
dp = [[[0]*D for j in range(2)] for i in range(L+1)] #dp[i][less][modD]
dp[0][0][0] = 1
for i,c in enumerate(K):
    for less in range(2):
        lim = 9 if less else int(c)
        for r in range(D):
            for d in range(lim+1):
                dp[i+1][less or d < lim][(r+d)%D] += dp[i][less][r]
                dp[i+1][less or d < lim][(r+d)%D] %= MOD

print((dp[-1][0][0] + dp[-1][1][0] - 1) % MOD)

Measured memory_bytes: 62812
N = gets.to_i
P = N.times.map{gets.to_i} + [0]*6

move = [nil]*(N+6)


(N+6).times do |i|
    ptr = i
    stack = []
    while move[ptr] == nil
        if P[ptr] == 0
            move[ptr] = ptr
            break
        end
        move[ptr] = -1
        stack << ptr
        ptr = ptr + P[ptr]
    end
    if move[ptr] == false || move[ptr] < 0
        stack.each do |j|
            move[j] = false
        end
    else
        t = move[ptr]
        stack.each do |j|
            move[j] = t
        end
    end
end


dp = [10101010]*(N+6)
dp[0] = 0

queue = [[0,0]]

while !queue.empty?
    i,step = queue.shift
    1.upto(6) do |hop|
        to = move[i+hop]
        if to && step+1 < dp[to]
            dp[to] = step+1
            queue.push([to, step+1])
            if to == N-1
                queue = []
                break
            end
        end
    end
end


p dp[N-1]



Measured memory_bytes: 10140
#include<bits/stdc++.h>
using namespace std;
    
int main() {
    int n, l;
  	cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n; i++) {
        cout << s[i];
    }
        return 0;
}

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

int main(){
    int64_t H;
    cin >> H;
    int64_t num = 1, ans = 0;
    while(H > 0){
        ans += num;
        num *= 2;
        H /= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;


class city {
    public:
        city(unsigned long i, unsigned long y);
        unsigned long i, y;
};


city::city(unsigned long i, unsigned long y)
    : i(i), y(y)
{
}


int main()
{
    unsigned long N, M;
    cin >> N >> M;

    vector<vector<city *>> ps(N+1);

    for (unsigned long i = 1; i <= M; i++) {
        unsigned long p, y;
        cin >> p >> y;
        ps[p].push_back(new city(i, y));
    }

    for (unsigned long i = 1; i <= N; i++) {
        sort(ps[i].begin(), ps[i].end(),
                [](const city *x, const city *y) { return x->y < y->y; });
    }

    vector<unsigned long> ids(M+1);
    for (unsigned long i = 1; i <= N; i++) {
        for (unsigned long j = 0; j < ps[i].size(); j++) {
            ids[(ps[i][j])->i] = (i * 10e5) + (j + 1);
        }
    }

    for (unsigned long i = 1; i <= M; i++) {
        printf("%012lu\n", ids[i]);
    }
}


Measured memory_bytes: 10880
//Catchharsh
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (int x,int n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    vector<ll> seve;
    void  seveprime()
    {
      int prime[1000000]={0};
      for(int i=2;i*i<1000000;i++)
       {
        if(prime[i]==0)
         {
      	  for(int j=i*2;j<=1000000;j+=i)
           prime[j]=1;
         }
       }
       for(int i=2;i<=1000000;i++)
       {
       	if(prime[i]==0)
       		seve.pb(i);
       }
    }
             int dp[100000+1];
    int main()
    {   
         IOS;
         int i,j,k,n,m;
         cin>>n>>k;

         vector<int> v(n);
          for(i=0;i<n;i++)
          	cin>>v[i];
          sort(v.begin(),v.end());
          for(i=0;i<v[0];i++)
          	dp[i]=0;  //0 for lose and 1 for win.
          for(i=v[0];i<=k;i++)
          {
          	  for(j=0;j<n;j++)
          	  {
          	  	if(i-v[j]>=0&&dp[i-v[j]]==0)
          	  	{
          	  		dp[i]=1;
          	  		break;
          	  	}
          	  }
          }
          if(dp[k]==0)
          	cout<<"Second";
          else
          	cout<<"First";
    }

Measured memory_bytes: 640
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    int N;
    string str;
    cin>>N;
    cin>>str;
    string s[120];
    for(int i = 0;i < N;i++){
        cin>>s[i];
    }

    int cnt = 0;
    for(int i = 0;i < N;i++){
        for(int j = 0;j < s[i].length();j++){
            if(s[i][j] == str[0]){
                for(int k = 1;k < s[i].length();k++){
                    for(int l = 1;l < s[i].length();l++){
                        if(j + (k * l) >= s[i].length())break;
                        if(s[i][j + (k * l)] != str[l])break;
                        //cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;
                        if(l == str.length()-1){
                            cnt++;
                            goto next;
                        }
                    }
                }
            }
        }
        next:;
    }
    cout<<cnt<<endl;


    return 0;
}

Measured memory_bytes: 1224
// うまくいくかどうかテスト
#include <iostream>
using namespace std;
int main(void) {
  int n;
  float x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> n;
  while (n--) {
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
    if ((y1 - y2) / (x1 - x2) == (y3 - y4) / (x3 - x4)) {
      cout << "YES";
    } else {
      cout << "NO";
    }
    cout << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	map<int, long long> m;
	long long ans = 0;
	for (int i = 1; i <= n; i++)
		m[i % k]++;
	for (int a = 0; a < k; a++)
		if (2 * a % k == 0)
			ans += m[a] * m[a] * m[(k - a) % k];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
using namespace std;
int main()
{
	char a,b;
	cin>>a>>b;
	if(a=='H')
	{
		if(b=='H')
		{
			cout<<"H";
		}
		else
		{
			cout<<"D";
		}
	}
	else
	{
		if(b=='D')
		{
			cout<<"H";
		}
		else
		{
			cout<<"D";
		}
	}
	return 0;
}

Measured memory_bytes: 256
'''بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ'''
#codeforces
gi = lambda : list(map(int,input().split()))
s, t = input(), input()
if s == t[:len(s)]:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(c, i, n) for (int i = c; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S;
    ll Q;
    cin >> S >> Q;
    ll T, F;
    ll count = 0;
    char x;
    char y;
    rep(0, i, Q)
    {
        cin >> T;
        if (T == 1)
        {
            count++;
        }
        else
        {
            cin >> F;
            if (F == 1 + count % 2)
            {
                cin >> x;
                S.insert(S.begin(), x);
            }
            else
            {
                cin >> y;
                S += y;
            }
        }
    }
    if (count % 2 == 1)
    {
        reverse(all(S));
    }
    cout << S << endl;
}

Measured memory_bytes: 900
from collections import deque
N,M = map(int,input().split())
adj = [ [] for _ in range(N) ]
for _ in range(M):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  adj[a].append(b)

S,T = map(int,input().split())
S -= 1
T -= 1

INF = float('inf')
dist = [ [INF]*3 for _ in range(N) ]
q = deque([(S,0)])
dist[S][0] = 0

while q:
  n,d = q.popleft()
  for v in adj[n]:
    nd = (d+1)%3
    if dist[v][nd] != INF: continue
    dist[v][nd] = dist[n][d]+1
    q.append((v,nd))

if dist[T][0] == INF:
  print(-1)
else:
  print(dist[T][0]//3)

Measured memory_bytes: 101772