akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    int A, B;
    cin >> A >> B;

    for (int i = 1; i <= 1500; ++i) {
        if ((int)(i * 0.08) == A && (int)(i * 0.10) == B) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
  while(1)
    {
      int a[2][4],hits = 0, blow = 0, i, j;
      for(i = 0; i < 2; ++i)
	{
	  for(j = 0; j < 4; ++j)
	    {
	      if(scanf("%d", &a[i][j]) == EOF)
		return 0;
	    }
	}
      for(i = 0; i < 4; ++i)
	{
	  for(j = 0; j < 4; ++j)
	    {
	      if(a[0][i] == a[1][j])
		{
		  i == j ? ++hits : ++blow;
		}
	    }
	}
      printf("%d %d\n", hits, blow);
    }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
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; }
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    int k; cin >> k;
    int a, b; cin >> a >> b;
    bool y = false;
    for(int i = a; i <= b; i++){
        if(i % k == 0) y = true;
    }
    if(y) cout << "OK" << endl;
    else cout << "NG" << endl;
}


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define ten(n) ((int)1e##n)
#define fst first
#define snd second
using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
ll ri(){ll l;cin>>l;return l;} string rs(){string s;cin>>s;return s;}
template<class T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
ostream&operator<<(ostream&o,const vb&t){forr(e,t)o<<"#."[e];return o;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";forr(e,t)o<<e<<",";o<<"}"<<endl;return o;}
#ifdef LOCAL
vs s_p_l_i_t(const string&s,char c){vs v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vs::iterator it){cerr<<endl;}
template<class T,class... Args>void e_r_r(vs::iterator it,T a,Args... args){cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it,args...);}
#define out(args...){vs a_r_g_s=s_p_l_i_t(#args,',');e_r_r(a_r_g_s.begin(),args);}
#else
#define out(args...)
#endif

void panic() {
  cout << "inf" << endl;
  exit(0);
}

ll solve() {
  int n = ri();
  int m = ri();

  vi uu(m), vv(m), ww(m);
  rep(i, m) {
    int u = ri() - 1;
    int v = ri() - 1;
    int w = -ri();
    uu[i] = u;
    vv[i] = v;
    ww[i] = w;
  }

  const ll inf = 1e18;
  vl D(n, inf);
  D[0] = 0;

  rep(_, n) {
    rep(i, m) {
      amin(D[vv[i]], D[uu[i]] + ww[i]);
    }
  }

  /*
  rep(i, m) {
    if (D[vv[i]] > D[uu[i]] + ww[i]) {
      // 負閉路検出
    }
  }
  */

  ll dd = D[n-1];

  rep(_, n) {
    rep(i, m) {
      amin(D[vv[i]], D[uu[i]] + ww[i]);
    }
  }

  ll dd2 = D[n-1];
  if (dd != dd2) panic();

  return -D[n-1];
}

void Main() {
  cout << solve() << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,x,t,ans=0,i;
    string s;
    cin>>s;
  for(i=0;i<s.size();i++)
  {
      ans+=s[i]-48;
  }
    if(ans%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define vll vector<ll>
#define pll pair<ll , ll>
#define vpll vector<pair<ll, ll> >
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define N 100001
#define HOLE 1000000007

ll fn(ll x,ll rn[])
{
    if(rn[x]==x) return x;
    else return rn[x]=fn(rn[x],rn);
}

void un(ll x,ll y,ll rn[],ll sz[])
{
    x=fn(x,rn);
    y=fn(y,rn);
    if(x==y) return;
    if(sz[x]<sz[y]) swap(x,y);
    sz[x]+=sz[y];
    rn[y]=x;
    return;
}

ll power(ll x,ll y)
{
    ll res = 1; // Initialize result

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x)%HOLE;

        // n must be even now
        y = y >> 1; // y = y/2
        x = (x * x)%HOLE; // Change x to x^2
    }
    return res;
}

vector <ll> adjl[N];
ll marked[N]={0};
vector <ll> order;

void dfs (ll x){

    if(marked[x])
        return;
    marked[x]=1;

    REP(i,0,adjl[x].size()){

    }

    return;
}

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

    ll q=1;
    //cin>>q;
    while(q--){

        ll n;
        cin>>n;

        ll sum=0;


        REP(i,1,n+1){

            REP(j,1,n+1){

                REP(k,1,n+1){

                    sum= sum+ __gcd(i,__gcd(j,k));

                }

            }

        }

        cout<<sum<<endl;


    }

return 0;
}


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


int main() {

  string s;
  cin>>s;

  int money=700;

  for(int i=0;i<s.size();i++){
    if(s.at(i)=='o')
      money+=100;
  }

  cout<<money<<endl;

  return 0;
}



Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include <unordered_map>   
#define waru 1000000000+7

using namespace std;

int main(){
        int n;
    cin >> n;
    vector<double> v(n);
    rep(i,n){
        int buf;
        cin >> buf;
        v[i] = buf;
    }
    sort(all(v));
    // double res = 0;
    double mae = v[0];
    for(int i = 1; i < n; i++){
        mae = (mae+v[i])/2.0;
    }
        printf("%.6f"  ,mae);

   }

Measured memory_bytes: 256
N = int(input())
a = [int(x) for x in input().split()]

summary = {}
for x in a:
    if x not in summary.keys():
        summary[x] = 1
    else:
        summary[x] += 1

res = 0
for k, v in summary.items():
    if k > v:
        res += v
    else:
        res += min(v - k, v)

print(res)

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

int main()
{
	int N = 0;
	int count = 0;
	std::cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		std::cin >> A[i];
	}
	while (1) {
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 1)goto end;
			A[i] = A[i] / 2;
		}
		count++;
	}
end:
	std::cout << count;
	return 0;
}

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


using namespace std;

int main()
{
	int N, M, p, x, sum = 0;
	cin >> N;

	vector<int> T(N);

	for (int i = 0; i < N; i++)
	{
		cin >> T[i];
		sum += T[i];
	}

	cin >> M;

	vector<int> ans(M);

	for (int i = 0; i < M; i++)
	{
		cin >> p >> x;
		ans[i] = sum - (T[p - 1] - x);
	}

	for (int i = 0; i < M; i++)
		cout << ans[i] << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
#define P pair<int, int>
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
int n;
vector<vector<int>> patterns;
void buildPattern(vector<int>);

int main()
{
	cin >> n;
	vector<double>x(n), y(n);
	rep(i, n)cin >> x[i] >> y[i];
	vector<vector<double>>dist(n, vector<double>(n));
	rep(i, n)rep(j, n)
	{
		double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		dist[i][j] = d;
	}
	vector<int> a(1, 0);
	rep(i, n)
	{
		a[0] = i;
		buildPattern(a);
	}

	double ave = 0;
	rep(i, patterns.size())
	{
		double l = 0;
		rep(j, patterns[i].size() - 1)
		{
			l += dist[patterns[i][j]][patterns[i][j + 1]];
		}
		ave += l;
	}
	double fact = patterns.size();
	ave /= fact;
	cout << setprecision(12);
	co(ave);
	return 0;
}

void buildPattern(vector<int> v)
{
	if (v.size() == n)
	{
		patterns.push_back(v);
	}
	else
	{
		rep(i, n)
		{
			auto result = find(ALL(v), i);
			if (result == v.end())
			{
				auto u = v;
				u.push_back(i);
				buildPattern(u);
			}
		}
	}
}

Measured memory_bytes: 3384
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

vi bfs(vv &e,ll s)
{
    ll n=sz(e);
    queue <ll> q;
    vi dis(n,-1);
    
    q.push(s);
    dis[s]=0;
    while(!q.empty())
    {
        ll u=q.front();
        q.pop();
        for(ll v:e[u])
        {
            if(dis[v]==-1)
            {
                dis[v]=dis[u]+1;
                q.push(v);
            }
        }
    }
    return dis;
}
int main()
{
    fast();
    ll n;
    cin>>n;
    vv e(n);
    for(ll i=0;i<n-1;i++)
    {
        ll u,v;
        cin>>u>>v;
        u--;
        v--;
        e[u].pb(v);
        e[v].pb(u);
    }
    vi d1=bfs(e,0);
    vi d2=bfs(e,n-1);
    
    trv(d1);trv(d2);
    ll a=0,b=0;
    for(ll i=0;i<n;i++)
    {
        if(d1[i]<=d2[i])
            a++;
        else
            b++;
    }
    if(a>b)
    {
        cout<<"Fennec\n";
    }
    else
        cout<<"Snuke\n";
}


Measured memory_bytes: 10756
using System;
using System.Text;
using System.Collections.Generic;

namespace Prog {
	struct Process {
		internal string name;
		internal int time;
	}

	public class Prog {
		public static void Main() {
			string[] a = Console.In.ReadLine().Split();
			int n = Int32.Parse(a[0]);
			int q = Int32.Parse(a[1]);
			
			const int maxsize = 500000;
			int size = (n < maxsize) ? n : maxsize;
			string[] text = Console.In.ReadToEnd()
			                    .Split(new char[]{}, StringSplitOptions.RemoveEmptyEntries);
			var queue = new Queue<Process>(size);
			Process p;
			int textlen = text.Length;
			
			if (textlen >= 3 && text[2] == "") {
				// ?????????CR + LF
				if (textlen % 3 == 1)
					textlen = textlen - 1;
				for (int i = 0; i < textlen; i += 3) {
					p.name = text[i];
					p.time = Int32.Parse(text[i + 1]);
					queue.Enqueue(p);
				}
			} else {
				// ?????????CR?????????LF
				if (textlen % 2 == 1)
					textlen = textlen - 1;
				for (int i = 0; i < textlen; i += 2) {
					p.name = text[i];
					p.time = Int32.Parse(text[i + 1]);
					queue.Enqueue(p);
				}
			}
			
			int elapsed = 0;
			var b = new StringBuilder(size * 20);
			int queue_count = 0;
			do {
				do {
					var proc = queue.Dequeue();
					if (proc.time <= q) {
						elapsed += proc.time;
						b.Append(proc.name)
							.Append(' ')
							.Append(elapsed)
							.AppendLine();
					} else {
						elapsed += q;
						proc.time -= q;
						queue.Enqueue(proc);
					}
					queue_count = queue.Count;
				} while (queue_count % size != 0);
				Console.Out.Write(b.ToString());
				b.Length = 0;
			} while (queue_count != 0);
		}
	}
}

Measured memory_bytes: 21432
#include <iostream>
using namespace std;
int main(){
  int m,d;
  cin >> m >> d;
  int cnt = 0;
  for(int i=4;i<=m;i++){
    for(int j=22;j<=d;j++){
      if(i==(j/10)*(j%10) && j/10>1 && j%10>1) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int degree,number,num,count;
	cin>>degree;
	int arr[100][100];
	for(int i=0;i<degree;i++)
	{
		for(int j=0;j<degree;j++)
		{
			arr[i][j]=0;
		}
	}
	for(int i=0;i<degree;i++)
	{
		cin>>count;
		cin>>number;
		for(int j=0;j<number;j++)
		{
			cin>>num;
			arr[i][num-1]=1;
		}
	}
	for(int i=0;i<degree;i++)
	{
		for(int j=0;j<degree;j++)
		{
			cout<<arr[i][j];
			if(j!=degree-1)
				cout<<" ";
		}
		cout<<endl;
	}
}


Measured memory_bytes: 3124
import heapq
n=int(input())
q=[]
p=list(map(int,input().split()))
ans=1
flag=0
q.append(p[0])
heapq.heapify(q)
for i in range(1,n):
  if n==1:
    ans=1
    break
  if p[0]==1:
    break
  if p[i]<q[0]:
    #print("i",i,q[0])
    ans+=1
  heapq.heappush(q,p[i])
print(ans)

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

int main() {
  int n;
  cin >> n;
  int ans = 1;
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    int x = i;
    int cnt = 0;
    while (x) {
      if (x % 2 != 0) {
        break;
      }
      x /= 2;
      cnt++;
    }
    if (mx < cnt) {
      mx = cnt;
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;

#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;


int main() {

  ll n,q;
  cin >> n;
  vector<ll> s(n);
  REP(i,n) cin >> s.at(i);
  cin >> q;
  vector<ll> t(n);
  REP(i,q) cin >> t.at(i);

  ll count=0;

  REP(i,q){

    ll x = lower_bound(s.begin(),s.end(),t.at(i))-s.begin();
    ll y = upper_bound(s.begin(),s.end(),t.at(i))-s.begin();
    if(y-x>=1){
      count++;
    }
  }

  cout << count << endl;
  
}


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

int main()
{
   int a, b, c;

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

   if(a == b && a != c){
    printf("Yes\n");
   }
   else if(a == c && a != b){
    printf("Yes\n");
   }
   else if(b == c && b != a){
    printf("Yes\n");
   }
   else{
    printf("No\n");
   }

    return 0;
}


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

using namespace std;
using int64 = long long;

int main() {
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    vector<int> scores(n, 0);
    map<char, int> hands;
    hands['r'] = p;
    hands['s'] = r;
    hands['p'] = s;

    long long ans = 0;
    for (int i=0; i<n; i++) {
        if (i < k || t[i] != t[i-k] || scores[i-k] == 0) {
            scores[i] = hands[t[i]];
            ans += scores[i];
            continue;
        }
    }
    

    cout << ans << endl;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<utility>
#include<algorithm>
#include<queue>

using namespace std;

queue<pair<string, int>> tasks;

int main()
{
	cin.tie(0);
	ios::ios_base::sync_with_stdio(false);
	int taskam, q, time = 0;
	cin >> taskam >> q;
	for (int i = 0; i < taskam; ++i) {
		string name;
		int thistask;
		cin >> name >> thistask;
		if (thistask <= q) {
			time += thistask;
			cout << name << " " << time << endl;
			continue;
		}
		time += q;
		tasks.emplace(make_pair(name, thistask-q));
	}
	while (!tasks.empty()) {
		int tmpt = tasks.front().second;
		string tmpname = tasks.front().first;
		tasks.pop();
		int n = tmpt - q;
		if (n > 0) {
			tasks.emplace(make_pair(tmpname, n));
			time += q;
		}
		else {
			time += tmpt;
			cout << tmpname << " " << time << endl;
		}
	}
}

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

int main() {
  int N, K, x;
  cin >> N >> K;

  int s = 0;
  
  int i = 0;
  
  while (i < N){
    cin >> x;
    
    int A = 0;
    int B = 0;
    
    A = x * 2;
    B = (K - x) * 2;      
    
    if (A < B){
      s += A;
    }
    else {
      s += B;
    }
    i++;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
s = input()
k = int(input())
ans = 0
soui = 0
moji = s[0]

for i in range(1,len(s)):
    if s[i] == s[i-1] and soui == 0:
        ans += 1
        soui = 1
    elif soui == 1:
        soui = 0


flag = 0
a = 0
b = 0

while s[0] == s[a] and a != len(s)-1:
    a += 1

while s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1:
    b += 1


if s[0] == s[len(s)-1]:
    flag = 1

for i in range(len(s)):
    if moji != s[i]:
        break
    elif i == len(s)-1:
        flag = 2

if flag == 1:
    print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2))))
elif flag == 2:
    print((k*len(s))//2)
else:
    print(k*ans)


Measured memory_bytes: 9188
S = input()
T = input()
N = len(S)
check = [1]*len(S)
#Tが入る範囲をfor文で探す
#Tが入る範囲から一番最後尾にTを入れる
#余った?にはaを入れる

for i in range(len(S)):
    for j in range(len(T)):
        if (i+j)>=len(S):
            check[i]=0
            break
        if S[i+j]=="?":
            continue
        if S[i+j] != T[j]:
            check[i] = 0
            break
snum=-1
for i in range(N):
    if check[i]==1:
        snum=max(snum,i)

if snum==-1:
    print("UNRESTORABLE")
    exit()
s = []
for i in range(N):
    s.append(S[i])
for i in range(len(T)):
    s[snum+i]=T[i]

for i in range(N):
    if s[i]=="?":
        s[i] = "a"
ans = ""
for i in range(N):
    ans = ans+s[i]

print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<long long>a(n);
  vector<long long>b(n);
  vector<long long>d(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    d[i] = a[i]-b[i];
  }
  sort(d.begin(),d.end());
  long long hiku=0,num1,num2;
  for (int i = 0; i < n; i++) {
    if (d[i] < 0) {
      hiku += d[i];
    }
    else {
      num1 = i;
      break;
    }
  }

  if (hiku == 0) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = n-1; i >= 0; i--) {
    hiku += d[i];
    if (hiku >= 0) {
      num2 = i;
      break;
    }
  }
  if (hiku < 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << n-(num2-num1) << endl;
}  


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#ifdef __linux__
#define getchar getchar_unlocked
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,a,b;
int main()
{
	file();
	read(n),read(a),read(b);
	if((b-a)&1)puts("Borys");
	else puts("Alice");
	return 0;
}


Measured memory_bytes: 256
int main(){
int W, H, x, y, r;
scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
if((x+r)>W || (y+r)>H || (x-r)<0 || (y-r)<0){printf("No\n");}
else{printf("Yes\n");}
return 0;
}

Measured memory_bytes: 584
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long lint;
//typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
const int    dx[]={-1,0,0,1};
const int    dy[]={0,-1,1,0};
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

int N,M;
int P[100010],Y[100010];
vector<int>ran[100010];

signed main(){
  cin>>N>>M;
  for(int i=1;i<=M;i++){
    cin>>P[i]>>Y[i];
    ran[P[i]].push_back(Y[i]);
  }
  for(int i=1;i<=N;i++)sort(ran[i].begin(),ran[i].end());

  for(int i=1;i<=M;i++){
    int temp=(int)(lower_bound(ran[P[i]].begin(),ran[P[i]].end(),Y[i])-ran[P[i]].begin())+1;
    cout<<setw(6)<<setfill('0')<<P[i];
    cout<<setw(6)<<setfill('0')<<temp<<endl;
  }
  return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\01.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;

int gcd(ll x, ll y) {
    if (x < y) swap(x, y);
    if (y == 0) {
        return x;
    }
    return gcd(y, x % y);
}

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


    vector<ll> xs(n);
    rep(i, n) {
        cin >> xs[i];
    }

    sort(xs.begin(), xs.end());
    rep(i, n) {
        xs[i] = abs(xs[i] - x);
    }

    ll ans = xs.back();

    for (ll i = 0; i < n - 1; i++) {
        ll now = gcd(xs[i], xs[i + 1]);
        ans = min(ans, now);
    }
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int i,j,n,nxt,code,MAX,sel;
int num[20],dist[20],wei[20],next[36000][20];
double time[36000][20],speed[36000],ttt,tim;

int main(){
	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d %d %d",&num[i],&dist[i],&wei[i]);
		wei[i]*=20;
	}

	MAX=1<<n;

	for(code=MAX-2;code>=0;code--){
		sel=0;
		for(j=0;j<n;j++){
			if(code >> j & 1)sel+=wei[j];
		}
		speed[code]=2000.0/(sel+70);
	}

	for(code=MAX-2;code>0;code--){
		for(i=0;i<n;i++){
			if( !(code >> i & 1) )continue;
			ttt=99999999;

			for(j=0;j<n;j++){
				if( (code>>j&1) )continue;

				tim=time[code+ (1<<j) ][j]+abs(dist[i]-dist[j])/speed[code];
				if(tim<ttt){ttt=tim;sel=j;}

			}
			time[code][i]=ttt;
			next[code][i]=sel;

		}
	}

	ttt=99999999;
	for(j=0;j<n;j++){
		tim=time[1<<j][j];
		if(tim<ttt){ttt=tim;sel=j;}
	}
	time[0][0]=ttt;
	next[0][0]=sel;

	for(i=0,j=0;i<MAX-1;){
		nxt=next[i][j];
		printf("%s%d",i>0?" ":"",num[nxt]);
		i+=1<<nxt;
		j=nxt;
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 9044
#include<bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(0)
#define ll              long long int
#define ld              long double
#define mk              make_pair
#define pb              push_back
#define f               first
#define s               second
#define fo(i,a,b)       for(i=a;i<b;i++)
#define foe(i,a,b)      for(i=a;i<=b;i++)
#define all(x)          x.begin(),x.end()
#define vi              vector<int>
#define vl              vector <long long int>
#define pii             pair <int,int>
#define pll             pair <long long int, long long int>
#define vpii            vector< pair<int,int> >
#define vpll            vector < pair <long long int,long long int> >
#define MOD             1000000007
using namespace std;
const int inf = INT_MAX;
const ll inf64 = LLONG_MAX;


int main()
{
	boost;
	ll n, m;
	cin >> n >> m;
	ll h[n], i;
	bool good[n];

	fo(i, 0, n){
		cin >> h[i];
		good[i] = true;
	}

	fo(i, 0, m)
	{
		ll a, b;
		cin >> a >> b;
		a--, b--;
		if(h[a] == h[b])
		{
			good[a] = false;
			good[b] = false;
		}
		else if(h[a] < h[b])
		{
			good[a] = false;
		}
		else if(h[b] < h[a])good[b] = false;

		
	}
	ll ans = 0;
	fo(i,0,n)if(good[i])ans++;
	cout << ans;

	return 0;
}

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

using namespace std;

template <long long Mod> struct ModInt { /* {{{ */
  long long v;
  constexpr ModInt(const long long x = 0) {
    v = x % Mod;
    if (v < 0) {
      v += Mod;
    }
  }
  constexpr ModInt operator+(const ModInt rhs) const {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const {
    return ModInt(*this) /= rhs;
  }
  const ModInt &operator+=(const ModInt rhs) {
    v += rhs.v;
    if (v >= Mod) {
      v -= Mod;
    }
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) {
    if (v < rhs.v) {
      v += Mod;
    }
    v -= rhs.v;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) {
    v = v * rhs.v % Mod;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) {
    long long exp = Mod - 2;
    while (exp) {
      if (exp & 1) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }
  friend ostream &operator<<(ostream &s, ModInt<Mod> m) {
    s << m.v;
    return s;
  }
  friend istream &operator>>(istream &s, ModInt<Mod> m) {
    s >> m.v;
    return s;
  }
}; /* }}} */

const int mod = 1e9 + 7;
using modint = ModInt<mod>;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  vector<vector<modint>> dp(N + 5, vector<modint>(K + 5));
  vector<vector<modint>> dps(N + 5, vector<modint>(K + 5));
  dp[0][0] = 1;
  for (int i = 0; i <= K; i++) {
    dps[0][i] = 1;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= K; j++) {
      modint v;
      if (j > A[i]) {
        v = dps[i - 1][j] - dps[i - 1][j - A[i] - 1];
      } else {
        v = dps[i - 1][j];
      }
      dp[i][j] = v;
      if (j == 0) {
        dps[i][j] = v;
      } else {
        dps[i][j] = dps[i][j - 1] + v;
      }
    }
  }
  cout << dp[N][K] << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 166772
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  int max_x = 0;
  int min_x = 1000;
  rep(i, n) {
    cin >> x[i];
    max_x = max(max_x, x[i]);
    min_x = min(min_x, x[i]);
  }
  
  int ans = 1e9;
  for (int i = min_x; i <= max_x; i++) {
    int power = 0;
    rep(j, n) {
      power += (x[j] - i) * (x[j] - i);
    }
    ans = min(ans, power);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#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;
#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
//priority_queue<int,vector<int>, greater<int> > q2;
//tuple
//cout << get<0>( x ) << " " << get<1>( x ) << " " << get<2>( x ) << endl;
//tie(a, b, c) = t;


//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));




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

	int A, B, Q;
	cin >> A >> B >> Q;
	VI T(A), S(B);
	REP(i, A)cin >> T[i];
	REP(i, B)cin >> S[i];
	REP(i, Q) {
		int q;
		cin >> q;
		int ans = LLINF;
		int s1, s2, t1, t2;
		s1 = LB(S, q) - S.begin();
		t1 = LB(T, q) - T.begin();
		s2 = s1 - 1;
		t2 = t1 - 1;

		if (s1 >= 0 && t1 >= 0 && s1 < B&&t1 < A) {
			ans = min(ans, max(S[s1], T[t1]) - q);//どっちも右
			//cout << ans << endl;
		}
		if (s2 >= 0 && t2 >= 0 && s2 < B && t2 < A) {
			ans = min(ans, q - min(S[s2], T[t2]));//どっちも左
			//cout << ans << endl;
		}
		if (s1 >= 0  && s1 < B && t2 >= 0 && t2 < A) {
			ans = min(ans, q - T[t2] + S[s1] - q + min(q - T[t2], S[s1] - q));
			//cout << ans << endl;
		}
		if (s2 >= 0 && s2 < B && t1 >= 0 && t1 < A) {
			ans = min(ans, q - S[s2] + T[t1] - q + min(T[t1] - q, q - S[s2]));
			//cout << ans << endl;
		}

		cout << ans << endl;
		//cout << s1 << " " << t1 << endl;
	}

	return 0;
}



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

using namespace std;

typedef long long ll;

signed main()
{
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w));
    for(auto& x : a)
        for(auto& y : x)
            cin >> y;

    ll ans = 0;

    for(ll i = 0; i < h; ++i){
        for(ll j = 0; j < w; ++j){
            ll cou = (i + 1) * (h - i);
            ll cou2 = (j + 1) * (w - j);
            ans += a[i][j] * cou * cou2;
        }
    }
    cout << ans << endl;
}



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

using namespace std;

int main(){
    int n,i,t,j;
    vector<int> c,s,f;
    cin>>n;
    for(i=0;i<n-1;i++){
        cin>>t;
        c.push_back(t);
        cin>>t;
        s.push_back(t);
        cin>>t;
        f.push_back(t);
    }
    for(i=0;i<n-1;i++){
        int time=0;
        for(j=i;j<n-1;j++){
            if(time < s[j]){
                time=c[j]+s[j];
                // cout<< j<<"<-j  time->"<<time<<endl;
                continue;
            }
            int ftime=s[j];
            while(ftime < time){
                // cout<<j<<"  ftime : "<<ftime<<' '<<f[j]<<endl;
                ftime+=f[j];
            }
            time=ftime+c[j];
            // cout<< j<<"<-j  time->"<<time<<endl;
        }
        cout<<time<<endl;
    }
    cout<<0;
    return 0;
}

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

using namespace std;

int a[10];

bool dfs(int i, int B, int C)
{
    if(i == 10)
        return true;

    if(a[i] > B)
        return dfs(i + 1, a[i], C);
    
    if(a[i] > C)
        return dfs(i + 1, B, a[i]);
    
    return false;


}

int main()
{
    int N;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            cin >> a[j];
        }
        dfs(0, 0, 0);
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
    

    return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int c,d=0;
    for(int i=0;i<b;i++){
        cin>>c;
        d+=c;
    }
    if(d>=a){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    edges = []  # ベルマンフォードするなら頂点よりも辺が主役なので
    repn = [[] for _ in range(N)]
    reverse_repn = [[] for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a, b = a - 1, b - 1
        edges.append((a, b, c))
        repn[a].append(b)
        reverse_repn[b].append(a)
    """
    辺の重みを正負逆転させることで単一始点最短経路問題を解けば良い。
    ベルマンフォードで負閉路を検出したら"inf"を返す。
    ABC137Eを参考にする。
    これも負閉路が1~(N-1)のパス上にあることの確認が必要ですね。。。
    """
    reachable_from_1 = [0] * N
    reachable_from_N = [0] * N
    ok = [0] * N

    def dfs(v):
        if reachable_from_1[v]: return
        reachable_from_1[v] = 1
        for u in repn[v]: dfs(u)

    def reverse_dfs(v):
        if reachable_from_N[v]: return
        reachable_from_N[v] = 1
        for u in reverse_repn[v]: reverse_dfs(u)

    dfs(0)
    reverse_dfs(N - 1)
    for i in range(N):
        if reachable_from_1[i] and reachable_from_N[i]: ok[i] = 1

    # ベルマンフォード
    d = [10**18] * N
    d[0] = 0
    step = 0
    update = True
    while update:
        update = False
        for a, b, c in edges:
            if not ok[a]: continue
            if not ok[b]: continue
            new_cost = d[a] - c
            if new_cost < d[b]:
                update = True
                d[b] = new_cost
        step += 1
        if step > N:
            print("inf")
            return
    print(-d[N - 1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 75148
s = input().split()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])

if c>=b or d<=a:
    print(0)
else:
    if a<=c and b<=d:
        print(b-c)
    elif a<=c and b>d:
        print(d-c)
    elif a>c and b<=d:
        print(b-a)
    else:
        print(d-a)

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    ll r=0,g=0,b=0;
    rep(i,n) {
        if (s[i] == 'R') r++;
        else if (s[i] == 'G') g++;
        else b++;
    }
    ll ans = r*g*b;

    rep(i,n-2){
        for (int j=1; j<(n-i-1)/2+1; j++) {
            if (s[i]!=s[i+j] && s[i]!=s[i+2*j] && s[i+j]!=s[i+2*j]) ans--;
        }
    }

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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
ll go(ll a[],ll b[],ll n,ll m)
{
    for(ll i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        {
            return -1;
        }
    }
    return m;
}
int main()
{
    ft
    ll t,i,j,k,n,m=1,l=-1,r=-1;
    cin>>n;
    ll a[n+2],b[n+2],c[n+2];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
    }
    for(i=0;i<n;i++)
    {
        c[i]=i+1;
    }
    do
    {
        l=max(l,go(c,a,n,m));
        r=max(r,go(c,b,n,m));
        m++;
    }while(next_permutation(c,c+n));
    cout<<abs(l-r)<<"\n";
    return 0;
}

Measured memory_bytes: 3596
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

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

int op(int a, int b){
  return max(a,b);
}

int e(){
  return -1;
}

int target;

bool f(int v){
  return v<target;
}

int main(){
  int N,Q;
  scanf("%d%d",&N,&Q);
  
  vector<int> a(N);
  rep(i,N){
    scanf("%d",&(a[i]));
  }
  
  segtree<int,op,e> st(a);
  
  rep(i,Q){
    int t;
    scanf("%d",&t);
    if(t==1){
      int x,v;
      scanf("%d%d",&x,&v);
      x-=1;
      st.set(x,v);
    }
    else if(t==2){
      int l,r;
      scanf("%d%d",&l,&r);
      l-=1;
      printf("%d\n",st.prod(l,r));
    }
    else if(t==3){
      int p;
      scanf("%d%d",&p,&target);
      p-=1;
      printf("%d\n",st.max_right<f>(p)+1);
    }
  }
  
  return 0;
}

Measured memory_bytes: 6168
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main()
{
	cin >> s;
	REP(i, s.size()-1)
	{
		if (s[i] != s[i + 1]) {
			cnt++;
		}
	}
	cout << cnt << Endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define INF (1e8)
#define N 10005
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> P1;
typedef pair<P,P> P2;

int n, ABC[3], grade[N], Min[3];
vector<int> G[N];

P d[N], d2[2][N];

void dijkstra(){
  
  priority_queue<P1,vector<P1>,greater<P1> > q;
  
  for(int i=0;i<N;i++) d[i]=P(INF,INF);

  d[n]=P(0,Min[0]);
  q.push(P1(P(0,Min[0]),n));
  
  while(!q.empty()){
    
    P1 t=q.top(); q.pop();
    
    int cost1=t.first.first;
    int cost2=t.first.second;
    int node=t.second;

    if(d[node]<P(cost1,cost2)) continue;

    for(int i=0;i<G[node].size();i++){
      
      int nnode=G[node][i];
      int ncost1=cost1+1;
      int ncost2=min(cost2,nnode);
      
      if(nnode>=n) ncost2=min(ncost2,Min[nnode-n]);
      
      if(d[nnode]>P(ncost1,ncost2)){
	d[nnode]=P(ncost1,ncost2);
	q.push(P1(P(ncost1,ncost2),nnode));
      }
    }
    
  }
  
}

P dijkstra2(){
  
  P res=P(INF,INF);

  priority_queue<P2,vector<P2>,greater<P2> > q;

  for(int i=0;i<2;i++)
    for(int j=0;j<N;j++) d2[i][j]=P(INF,INF);
  
  d2[0][n+1]=P(0,Min[1]);
  q.push(P2(P(0,Min[1]),P(0,n+1)));
  
  while(!q.empty()){

    P2 t=q.top(); q.pop();

    int cost1=t.first.first;
    int cost2=t.first.second;
    int idx=t.second.first;
    int node=t.second.second;
    
    if(d2[idx][node]<P(cost1,cost2)) continue;
    if(idx==1&&node==n+2) res=min(res,P(cost1,cost2));
    
    for(int i=0;i<G[node].size();i++){
      
      int nnode=G[node][i];
      int ncost1=cost1+1;
      int ncost2=min(cost2,nnode);
      int nidx2=idx;
      
      if(nnode>=n) ncost2=min(ncost2,Min[nnode-n]);
      
      if(d2[nidx2][nnode]>P(ncost1,ncost2)){
	d2[nidx2][nnode]=P(ncost1,ncost2);
	q.push(P2(P(ncost1,ncost2),P(nidx2,nnode)));
      }
      
    }
    
    if(idx==0){
      
      idx=1;
      cost1=cost1+d[node].first;
      cost2=min(cost2,d[node].second);
      
      if(d2[idx][node]>P(cost1,cost2)){
	d2[idx][node]=P(cost1,cost2);
	q.push(P2(P(cost1,cost2),P(idx,node)));
      }
	
    }
    
  }
  
  return res;
}

int main(){
  
  cin>>n;

  for(int i=0;i<3;i++) cin>>ABC[i];
  
  memset(grade,-1,sizeof(grade));

  for(int i=0;i<3;i++){

    Min[i]=INF;
    
    for(int j=0;j<ABC[i];j++){
      int node;
      cin>>node;
      grade[node-1]=i;
      Min[i]=min(Min[i],node-1);
    }
    
  }
  
  int m;
  cin>>m;
  
  for(int i=0;i<m;i++){
    int x, y;
    cin>>x>>y;
    if(grade[x-1]!=-1) x=n+grade[x-1]+1;
    if(grade[y-1]!=-1) y=n+grade[y-1]+1;
    if(x==y) continue;
    G[x-1].push_back(y-1);
    G[y-1].push_back(x-1);
  }
  
  dijkstra();
  
  P ans=dijkstra2();
  
  cout<<ans.first<<' '<<ans.second+1<<endl;
  
  return 0;
}

Measured memory_bytes: 8288
#!/usr/bin/env python3
a = []
ans = 1
for i in range(3):
    a.append(list(map(int, input().split())))
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = -1
for k in range(3):
    if a[k] == [-1, -1, -1] or (a[0][k] == a[1][k] == a[2][k] == -1):
        ans = 0
if a[0][0] == a[1][1] == a[2][2] == -1:
    ans = 0
elif a[0][2] == a[1][1] == a[2][0] == -1:
    ans = 0
print('YNeos'[ans::2])

Measured memory_bytes: 3064
x, n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = [int(i) for i in input().split()]
flg = True
ans = 0
d = 0
while flg:
    if not x in p:
        ans = x
        flg = False
        break
    elif not x-d in p:
        ans = x-d
        flg = False
        break
    elif not x+d in p:
        ans = x+d
        flg = False
        break
    else:
        d += 1
print(ans)

Measured memory_bytes: 9236
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX = 200010;
ll inv[MAX],fact[MAX],fi[MAX];
constexpr ll mod = 1000000007;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

ll pw(ll a, ll x){
	ll ret = 1;
	while(x){
		while(!(x&1)){
			(a *= a) %= mod;
			x /= 2;
		}
		x--;
		(ret *= a) %= mod;
	}
	return ret;
}

int main(){
	ll i,n,a,b,ans = 0;
	cin >> n >> a >> b;
	inverse();
	ans = pw(2,n) - 1;
	ll k = 1;
	for(i=1;i<=a;i++){
		(k *= (n + 1 - i)*inv[i]%mod) %= mod;
	}
	ans -= k;
	if(ans<0) ans += mod;
	k = 1;
	for(i=1;i<=b;i++){
		(k *= (n + 1 - i)*inv[i]%mod) %= mod;
	}
	ans -= k;
	if(ans<0) ans += mod;
	cout << ans << endl;
}
		

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int main(){
 
  ll N;
  cin>>N;
  ll h[N], cost[N];
  
  for(ll i = 0; i < N; i ++) cin>>h[i];
  for(ll i = 0; i < N; i ++) cost[i] = 0;
  cost[0] = 0;
  cost[1] = abs(h[1]- h[0]);
  for(ll i = 2; i < N; i++){
  	cost[i] = min((cost[i - 1] + abs(h[i] - h[i -1])), (cost[i - 2] + abs(h[i] - h[i -2])));
  }
  cout<<cost[N - 1];
  return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    int N,tmp,cnt = 0;;
    cin >> N;
    tmp = N;

    int n_digit = 0;;
    while(tmp != 0){
        tmp = tmp/10;
        n_digit ++;
    }
    if(n_digit % 2 != 0 ){
        cnt += N - pow(10,n_digit-1) + 1;
        n_digit--;
    }
    while(n_digit != 0 ){
        if(n_digit % 2 == 0){

        }else{
            cnt += pow(10,n_digit) - pow(10,n_digit-1);
        }
        n_digit --;
    }

    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx") 
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define INF 0x3f3f3f3f
#define INFll 0x3f3f3f3f3f3f3f3f
#define y0 _lxybz_
#define y1 _ljmnzyzhhhoscartxdy_
typedef long double ld;
typedef long long ll;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define lo(x) ((x)&(-(x)))
#define trav(a, x) for (auto &a : x)
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
const ld Pi = 4*atan((ld)1);
template<class T> void chmin(T &a,const T&b) { a = min(a, b); }
template<class T> void chmax(T &a,const T&b) { a = max(a, b); }
namespace IO{
template<class T> inline void read(T&ret)
{
	ret=0; int f=1; char c=getchar();
	while(c<48||c>57){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	ret*=f;
}
template<class T> inline void prin(const T&ret)
{
	if(!ret){putchar(48);return;} static T o; o=ret;
	if(o<0){putchar('-');o=-o;}
	static int op[25],tt; tt=0;
	while(o){
		op[++tt]=o%10;
		o/=10;
	}
	for(int i=tt;i;--i)putchar(op[i]+48);
}
template<class T> inline void pri_(const T&ret)
{
	prin(ret);putchar(' ');
}
template<class T> inline void priE(const T&ret)
{
	prin(ret);putchar('\n');
}
}
using namespace IO;

#define N 1000050
#define MO 1000000007
inline int ksm(int p, int k)
{
	static int vv[70];
	vv[0]=p; int s=1;
	for(int i=1; i<=29; ++i)vv[i]=(long long)vv[i-1]*vv[i-1]%MO;
	for(int i=29; i>=0; --i){
		if(k>=1<<i){
			k-=1<<i;
			s=(long long)s*vv[i]%MO;
		}
	}
	return s;
}
int h[N],_h[N],l,r,n,k,Ans,ss,d,op;
inline int C(int a, int b)
{
	return (ll)h[a]*_h[b]%MO*_h[a-b]%MO;
}

inline void _Sol_()
{
	read(n);read(k); //k>1
	h[0]=1;F(i,1,500000)h[i]=(ll)h[i-1]*i%MO;
	F(i,0,500000)_h[i]=ksm(h[i],MO-2);
	l=0; r=min(k,n-1);
	F(i,0,r){
		op=C(n,i);
		ss=i; d=n-i;
		op=(ll)op*C(ss+d-1,d-1)%MO;
		Ans=(Ans+op)%MO;
	}
	priE(Ans);
}

int main()
{
	int T=1; //read(T);
	while(T--)_Sol_();
}

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

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

    int a, b;
    cin >> a >> b;
    int d, r;
    double f;
    d = a / b;
    r = a % b;
    f = 1.0 * a / b;
    printf("%d %d %.8lf\n", d, r, f);

    return 0;
}


Measured memory_bytes: 3224
f=lambda:map(int,input().split())
n,m=f()
l=[0]*n
b=[0]*n
if n>1: l[0]=1
for _ in range(m):
  s,c=f()
  s-=1
  if b[s] and l[s]!=c or n>1 and s==c==0:
    print(-1)
    exit()
  l[s]=c
  b[s]=1
print(*l,sep='')

Measured memory_bytes: 9068
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var N = o.getValue(0);
    var an = o.getArray(1);

    var result = 0;
    for(var i = 0; N > i; i += 2) {
        if (an[i] % 2 === 1) {
            result++;
        }
    }

    return result;
}

Measured memory_bytes: 29580
#!/usr/bin/env python
# coding: utf-8

# In[24]:


N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())


# In[26]:


mylist = [A,B,C,D,E]
x = min(mylist)
ans = -(-N//x)+4
print(ans)


# In[ ]:






Measured memory_bytes: 9092