akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, M;
	cin >> N >> M;
	vector< vector< pair<int, int> > > G(N);
	for(int i = 0; i < M; i++) {
		int u, v, d;
		cin >> u >> v >> d;
		G[--u].push_back({--v, d});
		G[v].push_back({u, -d});
	}
	vector<cat> X(N, 0);
	vector<bool> vis(N, false);
	for(int i = 0; i < N; i++) if(!vis[i]) {
		queue<int> q;
		cat mi = 0, mx = 0;
		vis[i] = true;
		q.push(i);
		while(!q.empty()) {
			ALL_THE(G[q.front()], it) if(!vis[it->ff]) {
				vis[it->ff] = true;
				X[it->ff] = X[q.front()]+it->ss;
				mx = max(mx, X[it->ff]);
				mi = min(mi, X[it->ff]);
				q.push(it->ff);
			}
			q.pop();
		}
		if(mx-mi > 1000000000) {
			cout << "No\n";
			return 0;
		}
	}
	for(int i = 0; i < N; i++) ALL_THE(G[i], it)
		if(X[it->ff] != X[i]+it->ss) {
			cout << "No\n";
			return 0;
		}
	cout << "Yes\n";
	return 0;
}

// look at my code
// my code is amazing


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n, k, res = 0;
    cin >> n >> k;
    FOR(i, 1, n)
    {
        int x;
        cin >> x;
        if(x >= k) res++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<P, int> T;
#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))


vector<T> block;
Int w[1080], s[1080], v[1080];
Int n;
Int dp[21600];
int main(){
  cin >> n;
  for(Int i = 0;i < n;i++){
    cin >> w[i] >> s[i] >> v[i];
    block.push_back(T(P(w[i] + s[i], s[i]), i));
  }
  sort(block.begin(), block.end());

  for(Int i = 0;i < n;i++){
    Int ind = block[i].second;
    for(Int i = s[ind];i >= 0;i--){
      dp[i + w[ind]] = max(dp[i+w[ind]], dp[i] + v[ind]);
    }
  }
  Int res = 0;
  for(Int i = 0;i < 21600;i++)res = max(res, dp[i]);
  cout << res << endl;
  return 0;
}

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

//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define FS first
#define SE second

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//Greatest Common Devider
LL gcd(LL a,LL b){
  if(b == 0) return a;
  return gcd(b,a%b);
}
//------------------------------------------
//Least Common Multiple
//Must be used with GCD
LL lcm(LL a,LL b){
  LL g = gcd(a,b);
  return a / g * b;
}
//grobal var
//------------------------------------------


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int N,K;
  cin >> N >>K;
  int up2=1,dn2=1;
  while(true){
   up2*=2;
   if(up2>=K) break;
   dn2=up2;
  }
  int max2=up2;
  long long sum=0;
    int cur2=up2;
    int pre2=up2;
  FOR(i,1,N+1){
    while(true){
      cur2=pre2;
      pre2/=2;
      if(i*pre2<K) break;
    }
    sum += max2/cur2;
    pre2=cur2;
  }
  debug(sum)
  long long mot = max2*N;
  debug(max2)
  cout << std::setprecision(20) << (double)sum / (double)mot << endl;
  return 0;
}


Measured memory_bytes: 256
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 305;

int h, w;
char c[mxn][mxn];

int lc, rc;
int costmemo[mxn][mxn];
bitset<mxn> costvstd[mxn];
int cost(int lp, int rp) {
    auto &ret = costmemo[lp][rp];
    if (costvstd[lp][rp]) return costmemo[lp][rp];
    costvstd[lp][rp] = 1;
    if (min(lp, rp) > 0) return ret = cost(lp-1, rp-1)-(c[h-lp][lc] == c[h-rp][rc]);
    ret = 0;
    for (int i = 0; i < h; i++) {
        ret += i-max(lp, rp) >= 0 and c[i-lp][lc] == c[i-rp][rc];
    }
    return ret;
}

int memo[mxn][mxn];
bitset<mxn> vstd[mxn];
int dp(int lp, int rp) {
    if (max(lp, rp) >= h) return 0;
    auto &ret = memo[lp][rp];
    if (vstd[lp][rp]) return ret;
    vstd[lp][rp] = 1;
    ret = cost(lp, rp)+min(dp(lp+1, rp), dp(lp, rp+1));
    return ret;
}

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
/*
Critical observation: Every 2 consecutive columns can be solved separately.
*/
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> c[i];
    }

    int ans = 0;
    for (int i = 0; i < w-1; i++) {
        lc = i, rc = i+1;
        memset(vstd, 0, sizeof(vstd)), memset(costvstd, 0, sizeof(costvstd)), ans += dp(0, 0);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
using namespace std;
int main() {
    int N;
    cin >> N;
    int min = 100;
    for(int i = 1; i < N; i++){
        int A = i;
        int B = N - i;
        int ta = A;
        int tb = B;
        int sum = 0;

        for(int j = 0; j < 5; j++){
            sum += ta % 10 + tb % 10;
            ta /= 10;
            tb /= 10;
        }

        if(min > sum) min = sum;

    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  string S;
  int m = 0, l = 0;
  cin >> S;
  for (auto c : S)
  {
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T')
    {
      l++;
      m = max(l, m);
    }
    else
    {
      l = 0;
    }
  }
  cout << m << endl;
}


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct Node {
	int now, step;
};
bool operator >(const Node& n1, const Node& n2) {
	return n1.step > n2.step;
}

int main() {
	int N; cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; ++i) cin >> v[i];

	vector<int> ans(N, 1e9);
	priority_queue<Node, vector<Node>, greater<Node> > Q; Q.push( (Node){0, 0} );
	while ( !Q.empty() ) {
		Node node = Q.top(); Q.pop();
		if (node.now >= N) continue;
		if (node.step >= ans[node.now]) continue;
		ans[node.now] = node.step;

		if (v[node.now]) {
			Q.push( (Node){ node.now + v[node.now], node.step } );
		}
		else {
			for (int i = 1; i <= 6; ++i) {
				Q.push( (Node){ node.now + i, node.step+1 } );
			}
		}
	}
	cout << ans[N-1] << endl;
}

Measured memory_bytes: 1796
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

int64_t X, K, D;

void solve()
{
	std::cin >> X >> K >> D;

	X = std::abs(X);

	int64_t ans;
	if ((double_t)X - (double_t)K * (double_t)D < 0)
	{
		K -= X / D;
		X %= D;
		ans = K % 2 ? std::abs(D - X) : X;
	}
	else ans = X - K * D;

	std::cout << ans << std::endl;
}

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


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define rint register int
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
inline ll rf(){
	int s=0,c=0;ll r=0;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;
}
const int N=1e5+7;
ll inf=1e18+7;
ll t[N*4],lat[N*4];
void pushup(int rt){
	t[rt]=min(t[rt<<1],t[rt<<1|1]);
}
void pushdown(int rt){
	if(lat[rt]){
		t[rt<<1]=min(t[rt<<1],lat[rt]);
		t[rt<<1|1]=min(t[rt<<1|1],lat[rt]);
		lat[rt<<1]=min(lat[rt<<1],lat[rt]);
		lat[rt<<1|1]=min(lat[rt<<1|1],lat[rt]);
	}
}
void built(int l,int r,int rt){
	if(l==r){
		if(l==1){
			t[rt]=0;
			return;
		}
		t[rt]=inf;
		return ;
	}
	int mid=(l+r)/2;
	built(lson);
	built(rson);
	pushup(rt); 
}
void modify(int l,int r,int rt,int L,int R,ll x){
	if(l>=L&&R>=r){
		t[rt]=min(t[rt],x);
		lat[rt]=min(lat[rt],x);
		return ;
	}
	pushdown(rt);
	int mid=(l+r)/2;
	if(L<=mid) modify(lson,L,R,x);
	if(R>mid) modify(rson,L,R,x);
	pushup(rt);
}
ll query(int l,int r,int rt,int L,int R){
	if(l>=L&&R>=r){
		return t[rt];
	}
	pushdown(rt);
	int mid=(l+r)/2;
	ll res=inf;
	if(L<=mid) res=min(res,query(lson,L,R));
	if(R>mid) res=min(res,query(rson,L,R));
	return res; 
}
struct node{
	int l,r,c;
}a[N];
bool cmp(node x,node y){
	return x.l<y.l;
}
int main(){
	for(register int i=1;i<=N*4;i++) lat[i]=inf;
	int n,m;
	n=rf(),m=rf();
	int l,r,c;
	built(1,n,1);
	ll minn;
	for(int i=1;i<=m;i++) a[i].l=rf(),a[i].r=rf(),a[i].c=rf();
	sort(a+1,a+1+m,cmp);
	for(int i=1;i<=m;i++){
		l=a[i].l,r=a[i].r,c=a[i].c;
		minn=query(1,n,1,l,r);
		modify(1,n,1,l,r,minn+c);
	}
	ll ans=query(1,n,1,n,n);
	if(ans>=inf) cout<<"-1";
	else cout<<ans;
	return 0;
}

Measured memory_bytes: 6528
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
char S[20];
int main(){
  int i;
  int res = 0;
  int tmp;
  N = rd(S);
  for(i=(0);i<(N);i++){
    res += (S[i] -= '0');
  }
  for(i=(N)-1;i>=(0);i--){
    if(S[i]){
      int j;
      S[i]--;
      for(j=(i+1);j<(N);j++){
        S[j] = 9;
      }
      tmp = 0;
      for(j=(0);j<(N);j++){
        tmp += S[j];
      }
      chmax(res, tmp);
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int N; char S[20];
// {
//   int res = 0, tmp;
//   rd(S@N);
//   rep(i,N) res += (S[i] -= '0');
//   rrep(i,N) if(S[i]){
//     S[i]--;
//     rep(j,i+1,N) S[j] = 9;
//     tmp = 0;
//     rep(j,N) tmp += S[j];
//     res >?= tmp;
//   }
//   wt(res);
// }


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

int main() {
  vector<int> p(9,0);
  vector<int> a(9);
  int n;
  rep(i,9){
    cin>>a[i];
  }
  cin>>n;
  rep(i,n){
    int b;
    cin>>b;
    rep(j,9){
      if(b==a[j]){
        p[j]=1;
      }
    }
  }
  bool ans=0;
  if(p[0]==1&&p[1]==1&&p[2]==1)ans=1;
  if(p[3]==1&&p[4]==1&&p[5]==1)ans=1;
  if(p[6]==1&&p[7]==1&&p[8]==1)ans=1;
  if(p[0]==1&&p[3]==1&&p[6]==1)ans=1;
  if(p[1]==1&&p[4]==1&&p[7]==1)ans=1;
  if(p[2]==1&&p[5]==1&&p[8]==1)ans=1;
  if(p[0]==1&&p[4]==1&&p[8]==1)ans=1;
  if(p[2]==1&&p[4]==1&&p[6]==1)ans=1;

  

  if(ans){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  ll n,x,t;

  cin >> n >> x >> t;

  ll k;

  k = n / x;

  if(n % x != 0) k++;

  int sum = t * k;

  cout << sum << endl;
}



Measured memory_bytes: 3584
def good_distance():
    N, D = input().split()
    N = int(N)
    D = int(D)
    P = list()
    for a in range(N):
        P.append(list())
        P[a] = input().split()
    for a in range(N):
        for b in range(D):
            P[a][b] = int(P[a][b])
    print()
    result = cal_good_distance(P, D)
    print(result)

def cal_good_distance(x, D):
    count = 0
    count_a = 0
    for a in x:
        if count_a == len(x):
            break
        for b in range(count_a+1, len(x)):
            distance = 0
            for i in range(D):
                distance = distance + (x[count_a][i] - x[b][i])**2
            distance = distance ** (1/2)
            try:
                if isinstance(distance, int) or distance.is_integer():
                    count += 1
            except AttributeError:
                pass
        count_a += 1
    return count

good_distance()

Measured memory_bytes: 9428
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    set<int> s;
    int a;
    for(int i = 0; i < 3; i++){
        cin >> a;
        s.insert(a);
    }
    cout << s.size();
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{
  int n;
  double x[100];
  double y[100];

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<n;i++){
    cin>>y[i];
  }

   double d_first=0.0;
   double d_second=0.0;
   double d_third=0.0;
   double d_last=0.0;
   for(int i=0;i<n;i++){
     d_first+=abs(x[i]-y[i]);
     d_second+=(x[i]-y[i])*(x[i]-y[i]);
     d_third+=abs(x[i]-y[i])*abs(x[i]-y[i])*abs(x[i]-y[i]);
     if(abs(x[i]-y[i])>d_last)
       d_last=abs(x[i]-y[i]);
   }

   
   
   printf("%.6f\n",d_first);
   printf("%.6f\n",sqrt(d_second));
   printf("%.6f\n",pow(d_third,1.0/3.0));
   printf("%.6f\n",d_last);
   
  
  return 0;
}        


Measured memory_bytes: 3412
// Think twice, Code once
// 1SAC
#include<bits/stdc++.h>
using namespace std;

/*============================ DEBUGGING =============================*/

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/*============================= DEFINES ==============================*/

#define eps 1e-9
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define B begin()
#define E end()
#define F first
#define S second
#define tostr(x) to_string(x)
#define SZ(x) ((int)x.size())
#define ins insert
#define rep(i,x,y) for(int i=x;i<y;i++)
#define per(i,x,y) for(int i=x;i>y;i--)
#define repi(i,x,y) for(int i=x;i<=y;i++)
#define peri(i,x,y) for(int i=x;i>=y;i--)
#define inf (ll)LLONG_MAX
#define ds1(i,x) for(auto i=x.begin();i!=x.end();i++)
#define ds2(i,x) for(auto i:x)
#define FIO {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define dig(n) (int)(log10(n)+1)
#define ss(x,k) substr(x,k)  // x is the start pos and k is the length of substr.
#define set(x,k) memset(x,k,sizeof x)
#define Sort(a) sort(a.begin(),a.end())

/*============================== TYPEDEFS ============================*/

typedef long long ll;
typedef long double ld;
typedef long l;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<bool> vb;
typedef queue<int> qi;
typedef vector<pair<int,int> > vpii;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;

/*============================ START FROM HERE =======================*/

int main(){
	FIO
	
	int x,y;cin>>x>>y;
	bool ok1=false,ok2=false;
	int ans=0;
	if(x<=3){
		if(x==1){ans+=300000;ok1=true;}
		else if(x==2)ans+=200000;
		else ans+=100000;
	}
	if(y<=3){
		if(y==1){ans+=300000;ok2=true;}
		else if(y==2)ans+=200000;
		else ans+=100000;
	}
	if(ok1&&ok2)ans+=400000;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long LL;
int main() {
	int a = 0, b = 0,count = 0;
	std::string code;
	std::cin >> a >> b >> code;
	for (int i = 0; i < code.length(); i++) {
		if (code[i] == '-') {
			count++;
		}
	}
	if (a + b + 1 != code.length() || code[a] != '-' || count != 1) {
		std::cout << "No" << std::endl;
	}
	else {
		std::cout << "Yes" << std::endl;
	}
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a, T b) { a = min(a, b); }
template<class T> void umax(T &a, T b) { a = max(a, b); }

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

const int mod = 1e9+7;
const int N = 2e5+5;

void solve(){
	int n,m;
	cin>>n>>m;
	int ans=0,cnt=0;
	map<int,int>solved,wrong;
	rep(i,m){
		int x;
		string y;
		cin>>x>>y;
		if(solved[x])continue;
		if(y=="AC")ans++,cnt+=wrong[x],solved[x]=1;
		else wrong[x]++;
	}
	cout<<ans<<' '<<cnt;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 12936
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		 int K = sc.nextInt();
		 int X = sc.nextInt();
		 
		 Integer a[] = new Integer[2*K-1];
		 
		 for(int i=0; i<2*K-1; i++) {
			 a[i] = X - K + 1 + i;
			 System.out.println(a[i]);
		 }
		 
	}
}


Measured memory_bytes: 23252
#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 c[3][3];
    rep(i,3) {
        rep(j,3) {
            cin >> c[i][j]; 
        }
    }
    bool ok = false;
    rep(i,101) {
        if (c[0][1] == c[2][1] - c[2][0] + c[0][0] && c[0][1] == c[1][1] - c[1][0] + c[0][0]
         && c[0][2] == c[1][2] - c[1][0] + c[0][0] && c[0][2] == c[2][2] - c[2][0] + c[0][0]) {
             ok = true;
             break;
        }
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u) {
    if (u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u) {
    if (u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u) {
    if (u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main() {
    int i, v, l, r, root;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].p = NIL;
    }
    
    for (i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }
    
    
    for (i = 0; i < n; i++) if (T[i].p == NIL) root = i;
    
    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 2708
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

//const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

ijt cums[100010], cumt[100010];
int main() {
	string s, t; cin >> s >> t;
	int q; cin >> q;
	for (int i = 0; i < s.length(); i++)
	{
		cums[i + 1] = cums[i] + ((s[i] == 'A') ? 1 : 2);
	}
	for (int i = 0; i < t.length(); i++)
	{
		cumt[i + 1] = cumt[i] + ((t[i] == 'A') ? 1 : 2);
	}
	for (int i = 0; i < q; i++)
	{
		int a, b, c, d; cin >> a >> b >> c >> d;
		if ((cums[b] - cums[a-1]) % 3 == (cumt[d] - cumt[c-1]) % 3) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2432
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
flag = False
dices = []
for i in range(N):
    a, b = list(MAP())
    if a == b:
        dices.append(True)
    else:
        dices.append(False)

for i in range(N - 2):
    if dices[i] and dices[i + 1] and dices[i + 2]:
        flag = True

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27208
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
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;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;

int par[100000 + 5];    //親
int trank[100000 + 5];  //木の深さ
int num[100000 + 5];
int unum = 0;

//n要素で初期化
void init(int n)
{
    for (int i = 0; i < n; i++) {
        par[i] = i;
        trank[i] = 0;
        num[i] = 1;
    }
}

//木の根を求める
int find(int x)
{
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
        return;
    if (trank[x] < trank[y]) {
        par[x] = y;
        unum -= num[x] * num[y];
        num[y] += num[x];
    } else {
        par[y] = x;
        unum -= num[x] * num[y];
        num[x] += num[y];
        if (trank[x] == trank[y])
            trank[x]++;
    }
}


signed main()
{
    int n, m;
    cin >> n >> m;
    std::vector<pii> a(m);
    std::vector<int> out(m);
    for (int i = 0; i < m; i++) {
        int fst, sec;
        cin >> fst >> sec;
        fst--;
        sec--;
        pii temp(fst, sec);
        a[i] = temp;
    }
    init(n);
    unum = n * (n - 1) / 2;
    for (int i = m - 1; i >= 0; i--) {
        out[i] = unum;
        unite(a[i].first, a[i].second);
    }
    rep(i, m)
    {
        cout << out[i] << endl;
    }
    return 0;
}

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

using namespace std;

int main(int argc, char* argv[]) {
  vector<int> rets;
  vector<int> rets_odd;

  vector<int> options;
  int M = 1000000;
  for (int i = 1;; ++i) {
    int a = i * (i + 1) * (i + 2) / 6;
    if (a > M)
      break;
    options.push_back(a);
  }

  int dp[M + 1];
  for (int i = 0; i < M + 1; ++i)
    dp[i] = 1000000000;
  for (int i = 0; i < options.size(); ++i)
    dp[options[i]] = 1;
  for (int i = 1; i < M; ++i) {
    if (dp[i + 1] == 1)
      continue;
    for (int j = 0; j < options.size(); ++j) {
      if (options[j] > i)
        continue;
      if (dp[i - options[j] + 1] != 1000000000) {
        dp[i + 1] = min(dp[i + 1], dp[i - options[j] + 1] + 1);
      }
    }
  }

  vector<int> options_odd;
  for (int i = 1;; ++i) {
    int a = i * (i + 1) * (i + 2) / 6;
    if (a > M)
      break;
    if (a % 2 == 1)
      options_odd.push_back(a);
  }

  int dp_odd[M + 1];
  for (int i = 0; i < M + 1; ++i)
    dp_odd[i] = 1000000000;
  for (int i = 0; i < options_odd.size(); ++i)
    dp_odd[options_odd[i]] = 1;
  for (int i = 1; i < M; ++i) {
    if (dp_odd[i + 1] == 1)
      continue;
    for (int j = 0; j < options_odd.size(); ++j) {
      if (options_odd[j] > i)
        continue;
      if (dp_odd[i - options_odd[j] + 1] != 1000000000) {
        dp_odd[i + 1] = min(dp_odd[i + 1], dp_odd[i - options_odd[j] + 1] + 1);
      }
    }
  }

  while (true) {
    int n;
    cin >> n;

    if (n == 0)
      break;

    rets.push_back(dp[n]);
    rets_odd.push_back(dp_odd[n]);

  }

  for (int i = 0; i < rets.size(); ++i)
    cout << rets[i] << " " << rets_odd[i] << endl;


  return 0;
}


Measured memory_bytes: 10904
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);

    static void checkArray(int[] a){
        int i ;
        for( i = 0; i < a.length -1; i++){
                System.out.print(a[i] +" ");
        }
        System.out.print(a[i]);
        System.out.println();
    }
    static int[] makeArray(int num){
        int[] arr = new int[num];
        for( int i = 0; i < num; i++){
            arr[i] = sc.nextInt();
        }
        return arr;
    } 
    static int minOf(int[] a, int start) {
        int index = start;
        int min = a[start];
        for(int i = start; i < a.length; i++) {
            if(a[i] < min) {
                min = a[i];
                index = i;
            }
        }
        return index;
    }
    static void swap(int[] a,int i, int j ){
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;    
    }
    
    public static void main(String[] args) {
        int N = sc.nextInt();
        int[] arr = makeArray(N);
        
        int index;
        int count = 0;
        for(int i = 0; i < N; i++) {
            index = minOf(arr,i);
            if(arr[index] != arr[i]) {
                swap(arr,i,index);
                count++;
            }
            
        }
        checkArray(arr);
        System.out.println(count);
    }

}

Measured memory_bytes: 26300
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct BIT{
    int N;
    vector<int>bit;
    BIT(int x) {
        N = x;
        bit.resize(x+1);
    }
    void add(int x,int y) {
        while(x <= N) {
            bit[x] += y;
            x += x&-x;
        }
    }
    int sum(int x) {
        int res = 0;
        while(x) {
            res += bit[x];x-=x&-x;
        }
        return res;
    }
    int sum(int l, int r) {
        return sum(r)-sum(l-1);
    }
};
signed main(){
    int N,Q;
    cin >> N >> Q;
    vector<int>c(N);
    for(int i = 0; i < N; i++) {
        cin >> c[i];
        c[i]--;
    }
    vector<int>cnt(N,-1);
    vector<vector<int>>lr(N);
    for(int i = 0; i < N; i++) {
        int l = cnt[c[i]];
        if(l != -1) {
            // l -> i
            lr[l].push_back(i);
        }
        cnt[c[i]] = i;
    }
    vector<vector<P>>q(N);
    // query
    for(int i = 0; i < Q; i++) {
        int l,r;
        cin >> l >> r;
        l--;r--;
        q[l].push_back({r,i});
    }
    BIT bt(N);
    vector<int>ans(Q);
    for(int i = N-1; i >= 0; i--) {
        for(int y:lr[i]) {
            bt.add(y,1);
        }
        for(P query:q[i]) {
            int r = query.first,l = query.second;
            ans[l] = (r-i+1)-bt.sum(r);
        }
    }
    //出力
    for(int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 71092
#include <iostream>
#include <string>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main(){
  string N;
  cin >> N;
  int sum = 0;
  for(const auto& c : N) {
    sum += c - '0';
  }
  cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3752
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>


using namespace std;
#define PRINT(x) { std::cout << #x << ": " << x << std::endl; }

char S[8001] = {};
int X, Y;
int x0 = 0;
int nx = 0;
int x[8000];
int ny = 0;
int y[8000];
std::map<int, int> mx;
std::map<int, int> my;
int rng[8000];

int index(int i, int v, int sum)
{
    return (2 * sum + 1) * i + sum + v;
}

bool dp(int v0, int n, const int* va, int vf)
{
    if (n == 0)
    {
        return v0 == vf;
    }
    int sum = 0;
    int vmax = 0;
    for (int i = 0; i < n; ++i)
    {
        sum += va[i];
        rng[i] = sum;
        vmax = std::max(vmax, va[i]);
    }
    int vvf = vf - v0;
    if (vvf < -sum || sum < vvf)
    {
        return false;
    }
    sum += vmax;
    int ntbl = (n + 1) * (2 * sum + 1);
    int findex = index(n, vvf, sum);
    if (findex < 0 || ntbl <= findex)
    {
        return false;
    }
    int* tbl = (int*)malloc(sizeof (int) * ntbl);
    memset(tbl, 0, ntbl * sizeof(int));
    tbl[index(0, 0, sum)] = 1;
    for (int i = 0; i < n; ++i)
    {
        for (int j = -rng[i]; j <= rng[i]; ++j)
        {
            tbl[index(i + 1, j, sum)] = tbl[index(i, j - va[i], sum)] ||
                                        tbl[index(i, j + va[i], sum)];
        }
    }
    int ans = tbl[findex];
    free(tbl);
    return ans;
}

int main(int argc, char *argv[])
{
    scanf("%s", S);
    scanf("%d %d", &X, &Y);
    const int ns = strlen(S);
    int is;
    for (is = 0; is < ns; ++is)
    {
        if (S[is] == 'F') x0 += 1;
        else break;
    }
    ++is;
    int state = 1;              // 1(y) -> 0(x) -> 1(y)...
    for (; is < ns; ++is)
    {
        if (S[is] == 'F')
        {
            if (state) ++y[ny];
            else ++x[nx];
        }
        else
        {
            if (state) ++ny;
            else ++nx;
            state = !state;
        }
    }
    if (state) ++ny;
    else ++nx;

    if (dp(x0, nx, x, X) && dp(0, ny, y, Y))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 62464
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC083A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            d = int.Parse(word[3]);
 
			if(a+b == c+d){
              Console.WriteLine("Balanced");
            }
          	else if(a+b < c+d){
              Console.WriteLine("Right");
            }
          	else{
              Console.WriteLine("Left");
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
  int r;
  cin>>r;
  double pi = 2 * acos(0.0); 
  int N=20;
printf("%.*lf\n", N, pi*2*r);
}


Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string s,t;
  cin>>s>>t;
  int range=t.size();
  int start=-1;
  bool allmatch=false;
  if(s.size()<t.size()){
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }
  for(int i=0; i<=s.size()-range; i++){
    string pre=s.substr(i,range);
    bool match=true;
    if(pre==t){
      allmatch=true;
      break;
    }
    for(int j=0; j<range; j++){
      if(s[i+j]!=t[j]&&s[i+j]!='?'){
        match=false;
      }
    }

    if(match){
      start=i;
    }
  }

  if(allmatch){
    for(int i=0; i<s.size(); i++){
      if(s[i]=='?'){
        s[i]='a';
      }
    }
    cout<<s<<endl;
  }else if(start==-1){
    cout<<"UNRESTORABLE"<<endl;
  }else{
    for(int i=start; i<start+range; i++){
      s[i]=t[i-start];
    }
    for(int i=0; i<s.size(); i++){
      if(s[i]=='?'){
        s[i]='a';
      }
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n, l;
	cin >> n >> l;
	vector<int>v;
	repp(i, 1, n+1)v.push_back(l - 1 + i);
	int sum = 0;
	repp(i, 0, n)sum += v[i];
	int sub = 0, minv = 500;
	repp(i, 0, n)if (abs(v[i]) <= minv) { minv = abs(v[i]); sub = v[i]; }
	cout << sum - sub << endl;
}

Measured memory_bytes: 256
def count(keta,kazu):
    if(keta<kazu):
        return 0
    result=1
    wari=1
    for i in range(kazu):
        wari*=i+1
        result*=keta-i
    result//=wari
    #print(result)
    for i in range(kazu):
        result*=9
    return result


def Ans(moji,kazu):
    #print(moji,kazu)
    naga=len(moji)
    if(naga<kazu):
        return 0
    if(kazu==0):
        return 1
    sento=int(moji[0])
    if(naga==1):
        return sento
    #return Ans(moji[1:],kazu)+Ans(moji[1:],kazu-1)+count()
    if(sento==0):
        plus=Ans(moji[1:],kazu)
        return plus
    else:
        plus=Ans(moji[1:],kazu-1)
        #print(count(naga-1,kazu),count(naga-1,kazu-1),plus)
        return count(naga-1,kazu)+count(naga-1,kazu-1)*(sento-1)+plus

n=input()
l=len(n)
k=int(input())


print(Ans(n,k))

#ans=count(l-1,k)
#print(ans)
#batu=0
#for i in range(l):
#    suji=int(n[i])
#    if(suji!=0):
#        batu+=1
#    if(k<batu):
#        break
#    nok=count(l-i-1,k-batu)
#    print(suji,nok)
#    ans+=nok*(suji-1)

#print(ans)

Measured memory_bytes: 3064
n=gets.to_i
as = []
bs = []

n.times do
    a,b = gets.split.map(&:to_i)
    as.push(a)
    bs.push(b)
end

as.sort!
bs.sort!

if n.odd?
    p bs[(n-1)/2] - as[(n-1)/2] + 1
else
    p (bs[n/2-1]-as[n/2-1] + bs[n/2]-as[n/2]) + 1
end

Measured memory_bytes: 20508
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007


const int AGC = 9;
const int GAC = 33;
const int ACG = 6;

bool ok(int i)
{
	return i != AGC && i != GAC && i != ACG;
}

int main()
{
	int n;
	cin >> n;
	// A:00 C:01 G:10 T: 11
	long long int result[101][64] = {};
	for(int i = 0; i < 64; i++){
		if(ok(i)){
			result[3][i] = 1;
		}
	}
	for(int i = 3; i < n; i++){
		for(int j = 0; j < 64; j++){
			int fst = (j >> 4) % 4;
			int snd = (j >> 2) % 4;
			int thd = j % 4;
			for(int k = 0; k < 4; k++){
				int str1 = (fst << 4) + (thd << 2) + k;
				int str2 = (snd << 4) + (thd << 2) + k;
				int str3 = (fst << 4) + (snd << 2) + k;
				if(str1 != AGC && ok(str2) && str3 != AGC){
					result[i + 1][str2] += result[i][j];
					result[i + 1][str2] %= mod;
				}
			}
		}
	}
	long long int ans = 0;
	for(int i = 0; i < 64; i++){
		ans += result[n][i];
		ans %= mod;
	}
	cout << ans << endl;
}



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

int N, M;
string S;
const int MAX = 200000;
vector<int> edges[MAX];
int numA[MAX], numB[MAX];
bool deleted[MAX];

void del(int i){
    if(deleted[i]) return;
    deleted[i] = true;
    for(auto j : edges[i]){
        if(deleted[j]) continue;
        (S[i] == 'A' ? numA[j] : numB[j]) -= 1;
        if(numA[j] == 0 || numB[j] == 0) del(j);
    }
}

int main(){
    int i, j, k;
    cin >> N >> M >> S;
    for(i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
        (S[b] == 'A' ? numA[a] : numB[a]) += 1;
        (S[a] == 'A' ? numA[b] : numB[b]) += 1;
    }

    for(i=0; i<N; i++){
        if(numA[i] == 0 || numB[i] == 0) del(i);
    }
    for(i=0; i<N; i++){
        if(!deleted[i]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 15492
sx,sy,tx,ty = map(int,input().split())
s = ""
s += 'U' * (ty-sy) + 'R' * (tx-sx)
s += 'D' * (ty-sy) + 'L' * (tx-sx)
s += 'L' + 'U' * (ty-sy+1) + 'R' * (tx-sx+1) + 'D'
s += 'R' + 'D' * (ty-sy+1) + 'L' * (tx-sx+1) + 'U'
  
print(s)

Measured memory_bytes: 3060
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;

int ss(int a, int b, int c)
{
  return a * 3600 + b * 60 + c;
}

int N;
int main()
{
loop:
  int a, b, c, d, e, f;
  vector<pair<int, int>> v;

  scanf("%d", &N);
  if(!N)
    return 0;
  for(int i = 0; i < N; i++)
  {
    scanf("%d:%d:%d %d:%d:%d", &a, &b, &c, &d, &e, &f);
    v.push_back(make_pair(ss(a, b, c), ss(d, e, f)));
  }

  int ans = 0, x = 0;
  priority_queue<int, vector<int>, greater<int>> q;
  q.push(1000000000);
  sort(v.begin(), v.end());
  for(int i = 0; i < v.size(); i++)
  {
    while(v[i].first >= q.top())
    {
      q.pop();
      x++;
    }
    if(!x)
      ans++;
    else
      x--;
    q.push(v[i].second);
  }
  printf("%d\n", ans);
  goto loop;
}

Measured memory_bytes: 1172
from collections import deque

n = int(input())
a = deque(list(map(int, input().split())))
b = deque() if n % 2 == 0 else deque([a.popleft()])
for _ in range(n // 2):
    b.append(a.popleft())
    b.appendleft(a.popleft())
print(*b)

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

#define long long long int
using namespace std;


#ifdef JUDGE
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#else
using std::cin;
using std::cout;
#endif

using namespace std;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    long n_r = 0, n_g = 0, n_b = 0;
    for (int i = 0; i < n; i++)
        if (s[i] == 'R') n_r++;
        else if (s[i] == 'G') n_g++;
        else if (s[i] == 'B') n_b++;

    long ans = n_r * n_g * n_b;
    for (int i = 0; i < n - 2; ++i) {
        for (int j = i + 1; j < n - 1; ++j) {
            if (s[i] == s[j]) continue;
            int k = j * 2 - i;
            if (k >= n) continue;
            if ((s[k] != s[j] && s[k] != s[i]))
                --ans;
        }
    }

    cout << ans;
    return 0;


}




Measured memory_bytes: 3660
from collections import deque
S = list(input())
S = deque(S)
rev = False
Q = int(input())
for _ in range(Q):
    T = list(map(str,input().split()))
    if T[0] == '1':
        if rev:
            rev = False
        else:
            rev = True
    if T[0] == '2':
        if T[1] == '1':
            if rev:
                S.append(T[2])
            else:
                S.appendleft(T[2])
        if T[1] == '2':
            if rev:
                S.appendleft(T[2])
            else:
                S.append(T[2])
if rev:
    S = list(reversed(S))
    print("".join(S))
else:
    S = list(S)
    print("".join(S))

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

using namespace std;

int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(k>=e-a) cout <<"Yay!" <<endl;
  else cout<< ":(" << endl;
  return 0;
}

Measured memory_bytes: 256