akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 2e5 + 9, M = 100 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(12);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void READ() {
	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
}

int n, arr[M], x, d, cnt = 1;
int main() {
//	READ();
	OUTPUT();
	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
		d += arr[i];
		if (d <= x)
			cnt++;
	}
	cout << cnt;

	return 0;

}


Measured memory_bytes: 256
w, a, b = map(int, input().split())

if a < b:
    ans = b - (a+w)
    if ans <= 0:
        print(0)
    else:
        print(ans)
else:
    ans = a - (b+w)
    if ans <= 0:
        print(0)
    else:
        print(ans)


Measured memory_bytes: 9100
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-6;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }

// (Integer/Long).bitCount(x)
int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << h; if (sizeof...(t)) cerr << ", "; DBG(t...); }

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}

// Binary Exponentiation
ll pow(ll b, ll e, ll m = 0LL, ll ans = 1LL) { while (e) { if (e & 1LL) { ans *= b; if (m) ans %= m; } b *= b, e >>= 1LL; if (m) b %= m; } return ans; }



void solve(int tcn) {
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2] && s[0] == 'R') {
		cout << 3 << nl;
	}
	else if (s[0] == s[1] && s[0] == 'R' || s[1] == s[2] && s[1] == 'R') {
		cout << 2 << nl;
	}
	else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
		cout << 1 << nl;
	}
	else {
		cout << 0 << nl;
	}
}

int main() {
    setIO();

    int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		//cout << "Case #" << i << ": ";
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 3616
s = input()
n = len(s)

left_edge = int((n - 1) / 2)
right_edge = int((n + 1) / 2)

left = s[:left_edge]
right = s[right_edge:]

def is_kaibun(sentence):
    s_n = len(sentence)
    if s_n % 2 == 0:
        left_edge = right_edge = int(s_n / 2)
    else:
        left_edge = int((s_n - 1) / 2)
        right_edge = int((s_n + 1) / 2)
    left = sentence[:left_edge]
    right = sentence[right_edge:]
    right_rev = right[::-1]
    for l, r in zip(left, right_rev):
        if not l == r:
            return False
    else:
        return True

whole_kaibun = is_kaibun(s)
left_kaibun = is_kaibun(left)
right_kaibun = is_kaibun(right)
if all([whole_kaibun, left_kaibun, right_kaibun]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int arr[20][20];
int main()
{
	int N;
	cin >> N;
	memset(arr, -1, sizeof(arr));
	int i;
	for (i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		while (a--)
		{
			int b, c;
			cin >> b >> c;
			arr[i][b-1] = c;
		}
	}
	int ans = 0;
	for (i = 0; i < (1 << N); i++)
	{
		int j,k; int t = 0;
		for (j = 0; j < N; j++)
		{
			for (k = 0; k < N; k++)
			{
				if (arr[j][k]>=0&&(arr[j][k] != ((i & (1 << k)) / (1 << k)) && ((i & (1 << j)))))
					goto T;
			}
		}
		
		for (j = 0; j < N; j++)
		{
			t += (i & (1 << j)) / (1 << j);
		}
		ans = max(ans, t);
	T:
		int d;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N;//リンゴの数
    int L;//味に関する値
    cin>>N>>L;
    int A[N];
    int SUM=0;
    int x[N];
    for(int i=1;i<=N;i++){
        A[i-1]=L+i-1;
        SUM=SUM+A[i-1];//すべてで作ったアップルパイ
        if(A[i-1]>=0)
            x[i-1]=A[i-1];
        else
            x[i-1]=-A[i-1];
    }
    int min=A[0];
    for(int i=1;i<N;i++){
        if(x[i-1]>x[i]){
            min=A[i];
        }
    }

    cout<<SUM-min<<endl;

    return 0;
}

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

int main() {
  int K, n, cnt;
  cin >> K;
  n = 7 % K;
  bool finish = true;
  cnt = 1;
  if(K%2==0 || K%5==0) {
    cout << -1;
    finish = false;
  }
  while(finish){
    if(n==0){
      cout << cnt;
      break;
    }
    else{
      n = (n*10+7)%K;
      cnt++;
    }
  }
    
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'
#define mp make_pair


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

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


	int a,b,c,k;
	cin>>a>>b>>c>>k;

	int ans = 0;
	if(k<=a)
	{
		ans=k;
	}
	else if(k<=a+b)
	{
		ans=a;
	}
	else 
	{
		ans = a - (k-a-b);
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 3620
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)
print(len(set(a)))

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;

int main()
{
    char S[100010];
    cin >> S;
    int length=strlen(S);
    int counter=0;
    char ans[]="YES";
    while(length>counter){
        if(S[counter]=='d' && S[counter+1]=='r' && S[counter+2]=='e' && S[counter+3]=='a' && S[counter+4]=='m'){
            if(S[counter+5]=='e' && S[counter+6]=='r' && S[counter+7]!='a'){
                counter+=7;
            }else{
                counter+=5;
            }
        }else if(S[counter]=='e' && S[counter+1]=='r' && S[counter+2]=='a' && S[counter+3]=='s' && S[counter+4]=='e'){
            if(S[counter+5]=='r'){
                counter+=6;
            }else{
                counter+=5;
            }
        }else{
            strcpy(ans, "NO");
            break;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

bool is_valid(const vector<int> w, size_t k, int x) {
    size_t q=1;
    int y=0;
    for (size_t i=0; i<w.size(); ++i) {
        if (w[i] > x) return false;

        if (y+w[i] > x) {
            y = w[i];
            if (++q > k)
                return false;
        } else {
            y += w[i];
        }
    }

    return true;
}

int main() {
    size_t n, k;
    scanf("%zu %zu", &n, &k);

    vector<int> w(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &w[i]);

    int lb=0, ub=1<<30;
    while (ub-lb > 1) {
        int mid=(lb+ub)>>1;
        (is_valid(w, k, mid)? ub:lb) = mid;
    }

    printf("%d\n", ub);
    return 0;
}

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


void solve(long long N, std::vector<long long> a){
    map<ll, ll> rec;
    for(ll i=0; i< N; i++){
        if(!rec.count(a[i])) 
            rec[a[i]] = 1;
        else
        {
            rec[a[i]]++;
        }
        
    }
    ll cnt = 0;
    for(auto it = rec.begin(); it != rec.end(); ++it){
        if(it->second > it->first) 
            cnt += it->second - it->first;
        else if(it->second < it->first)
            cnt += it->second;
    }
    cout << cnt << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, T;
int A[int(1e5+5)], M[int(1e5+5)], deg[int(1e5+5)];

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

  for (int i = N - 1; i >= 0; i--){
    M[i] = max(M[i+1], A[i]);
    deg[i] = M[i] - A[i];
  }
  sort(deg, deg + N, greater<int>());

  int ans = 1;
  for (int i = 1; i <= N; i++){
    if (deg[i] == deg[i-1]) ans++;
    else{
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 4824
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int a, n;
	vector<int> v;
	cin >> n;
	if (n >= 2 && n <= 50) {
	while (n--) {
		cin >> a;
		if (a >= 1 && a <= 1000)
			v.push_back(a);
	}
	sort(v.begin(), v.end());
	double sum = v[0];
	for (size_t i{1}; i < v.size(); i++) {
		if (i > 0)
		sum = (sum + v[i]) / 2;
	}
	cout << sum << endl;
	} else return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;


int main(int argc, char* argv[])
{
  std::string str;
  std::cin >> str;

  std::string::iterator it;

  std::string judge = "No";
  for (it = str.begin(); it != str.end(); it++) {
    if (*it == '9') {
      judge = "Yes";
    }
  }

  std::cout << judge << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int n,a,i;
int main(){
	scanf("%d",&n);for(i=1;i<=n;++i)scanf("%d",&a),++mp[a];
	if(mp.size()==1 && mp[0]==n)return puts("Yes"),0;
	if(mp.size()==2 && (--mp.end())->second*3==n*2 && mp[0]==n/3)return puts("Yes"),0;
	i=0;for(auto u:mp)if(i^=u.first,u.second*3!=n)return puts("No"),0;
	puts(i?"No":"Yes");
	return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
int n,ans,a[201];
int main(void)
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++) scanf("%d",&a[i]);
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i+=2) ans+=a[i];
	printf("%d",ans);
}

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

const static double	de_PI	= 3.14159265358979323846;
const static int	de_MOD	= 1000000007;
const static int	de_MAX	= 999999999;
const static int	de_MIN = -999999999;

inline double RoundOff(double a, const int n) {

	for (int i = 0; i < n - 1; i++) { a *= 10; }

	if (a > 0) { a += 0.5; }
	else { a -= 0.5; }

	a = static_cast<int>(a);

	for (int i = 0; i < n - 1; i++) { a /= 10; }

	return a;
}

inline double circumradius(std::complex<double> a, std::complex<double> b, std::complex<double> c) {

	//???
	double eAB = abs(b - a);
	double eBC = abs(c - b);
	double eCA = abs(a - c);

	//?§????(????????????)
	double aCAB = acos((eCA*eCA + eAB*eAB - eBC*eBC) / (2 * eCA*eAB));

	//?????\????????????(??£?????????)
	double R = 0.5*eBC / sin(aCAB);

	return(R);

}

inline std::complex<double> Circumcenter(std::complex<double> a, std::complex<double> b, std::complex<double> c) {

	//???
	double eAB = abs(b - a);
	double eBC = abs(c - b);
	double eCA = abs(a - c);

	//?§????(????????????)
	double aCAB = acos((eCA*eCA + eAB*eAB - eBC*eBC) / (2 * eCA*eAB));
	double aABC = acos((eAB*eAB + eBC*eBC - eCA*eCA) / (2 * eAB*eBC));
	double aBCA = acos((eBC*eBC + eCA*eCA - eAB*eAB) / (2 * eBC*eCA));

	double A = sin(2 * aCAB);
	double B = sin(2 * aABC);
	double C = sin(2 * aBCA);

	//???????????????????????????(?????????????????¢???????????¬???)
	std::complex<double> ans;
	ans.real((A*a.real() + B*b.real() + C*c.real()) / (A + B + C));
	ans.imag((A*a.imag() + B*b.imag() + C*c.imag()) / (A + B + C));

	return(ans);
}

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());

	int n = 0;
	std::cin >> n;
	double x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0;

	std::complex<double> a, b, c, ans;
	double r = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		a.real(x1);	a.imag(y1);
		b.real(x2);	b.imag(y2);
		c.real(x3);	c.imag(y3);
		ans = Circumcenter(a, b, c);
		r = circumradius(a, b, c);
		std::cout << std::fixed << std::setprecision(3) << RoundOff(ans.real(), 4);
		std::cout << " ";
		std::cout << std::fixed << std::setprecision(3) << RoundOff(ans.imag(), 4);
		std::cout << " ";
		std::cout << std::fixed << std::setprecision(3) << RoundOff(r, 4) << std::endl;
	}



}

Measured memory_bytes: 3444
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define nl "\n"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;
#define mt make_tuple
#define vec vector

#define int long long

const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;

typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

void solve() {
	
	int n; cin >> n ;
	cout << (n^1) ; 
}

int32_t main() {

#ifndef ONLINE_JUDGE
    freopen("error.txt", "w", stderr);
#endif

    fast;

	// int t; cin >> t; while(t--)
		solve() ;

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int ans = 2000000000;
  for (int i = 0; i <= n - k; i++) {
    int l = x[i];
    int r = x[i + k - 1];
    ans = min({ans, abs(l) + abs(r - l), abs(r) + abs(r - l)});
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))  // xが範囲内か
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()  // 配列のサイズ
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;  // 確認したいとき
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))  // 切り上げたいとき
#define newline puts("")
#define v(T) vector<T>  // Tはどんな型でもいい
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;  // ******
typedef vector<vi> vvi;
typedef vector<ll> vl;  // ******
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}  // vi a(n); cin>>a;
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}  // cout<<a;  aの中身全部出す
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame1 { puts("-1"); return 0;}
#define dame0 { puts("0"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define out cout << ans << endl;
//mins(ans,now);  ansに最小値が入る
//if(max(ans,now)) ansが小さければ更新して実行。cnt++とか。
//ll sum = suma(a);

int main() {
    string s; cin >> s;
    int cnt = 0;
    int ans = 0;    
    rep(i,sz(s)){
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') cnt++;
        else{
            maxs(ans, cnt);
            cnt = 0;
        }
    }
    maxs(ans,cnt);
    out;
}

/*
g++ a.cpp
./a.out

oj d
oj t

debug:ctrl+shift+B+./problem.exe
problem.in+f5

*/


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

vector<llong> hoge;

template<class Type_k,class Type_p>
Type_p mod_pow(long long n,Type_k k,Type_p p){//n^k(mod p).
	if(k==0) return 1;
	long long res=mod_pow(n*n%p,k/2,p);
	if(k&1) res=res*n%p;
	return res;
}

int main(){
	int n;
	llong k;
	cin>>n>>k;
	
	hoge.resize(k+1);
	hoge[0]=0;
	REP(i,k) hoge[i+1]=mod_pow((llong)i+1,n,MOD);
	//line(hoge);
	
	vector<llong> anss(k+1);
	vector<llong> tmp(k+1);
	for(llong i=k;i>=1;--i){
		//debug(i);
		llong num=k/i;
		//debug(num);
		tmp[i]=hoge[num];
		for(llong j=i+i;j<=k;j+=i){
			//debug(j);
			tmp[i]-=tmp[j];
			while(tmp[i]<0) tmp[i]+=MOD;
		}
		//debug(tmp[i]);
		anss[i]=(tmp[i]*i)%MOD;
	}
	
	//line(anss);
	
	llong ans=0;
	REP(i,k) ans=(ans+anss[i+1])%MOD;
	
	cout<<ans<<endl;
}

Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MN 20005
#define Mod 998244353
int ksm(int a,int x){
	LL ans=1,w=a;
	while(x){
		if(x&1)ans=ans*w%Mod;
		w=w*w%Mod;
		x>>=1;
	}
	return ans;
}
int n,m;
LL f[205][MN],fac[MN],dfac[MN];
int C(int n,int m){
	if(n>m)return 0;
	return fac[m]*dfac[n]%Mod*dfac[m-n]%Mod;
}
int N,r[MN];
LL g[MN],F[MN];
const int G=3,invG=ksm(3,Mod-2);
void NTT(LL f[],int op){
	for(int i=0;i<N;++i)
		if(i<r[i])swap(f[i],f[r[i]]);
	for(register int len=1;len<N;len<<=1){
		int p=len<<1;
		LL tmp=ksm(op?G:invG,(Mod-1)/p);
		for(register int i=0;i<N;i+=p){
			register LL buf=1;
			for(int l=i;l<i+len;++l){
				register LL TMP=buf*f[l+len]%Mod;
				f[l+len]=(f[l]-TMP+Mod)%Mod;
				f[l]=(f[l]+TMP)%Mod;
				buf=buf*tmp%Mod;
			}
		}
	}
	if(!op){
		int invn=ksm(N,Mod-2);
		for(int i=0;i<N;++i)
			f[i]=f[i]*invn%Mod;
	}
}
int main(){
//	freopen("matrix.in","r",stdin);
//	freopen("matrix.out","w",stdout);
	scanf("%d%d",&n,&m);
	f[0][0]=1;
	N=1;
	while(N<=n*2+2)N<<=1;
	fac[0]=1;for(int i=1;i<=N;++i)fac[i]=fac[i-1]*i%Mod;
	dfac[N]=ksm(fac[N],Mod-2);
	for(int i=N-1;i>=0;--i)dfac[i]=dfac[i+1]*(i+1)%Mod;
	for(int i=0;i<N;++i)r[i]=(r[i>>1]>>1)|((i&1)?(N>>1):0);
	for(int i=1;i<=n;++i)g[i]=dfac[i+2];
	NTT(g,1);
	for(int i=1;i<=m;++i){
		for(int j=0;j<=N;++j)
			F[j]=f[i-1][j]*dfac[j]%Mod;
		NTT(F,1);
		for(int j=0;j<=N;++j)
			F[j]=F[j]*g[j]%Mod;
		NTT(F,0);
		for(int j=0;j<=n;++j){
			f[i][j]=f[i-1][j]*(1+j+C(2,j));
			f[i][j]=(f[i][j]+F[j]*fac[j+2])%Mod;
		}
	}
	LL ans=0;
	for(int i=0;i<=n;++i){
		ans=(ans+f[m][i]*C(i,n))%Mod;
	}
	printf("%lld",ans);
	return 0;
}


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

using namespace std;

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

  string s, t;
  cin >> s >> t;

  vector<string> res;
  int ssz = s.size();
  int tsz = t.size();
  int j;
  bool ok = false;
  for (int i = 0; i < ssz; ++i) {
    string tmp(s);
    for (j = 0; j < tsz; ++j) {
      if (i+j >= ssz) break;
      if (s[i+j] == '?' || s[i+j] == t[j]) {
        tmp[i+j] = t[j];
        continue;
      }
      break;
    }
    if (j == tsz) {
      for (auto &c : tmp) {
        if (c == '?') c = 'a';
      }
      res.push_back(tmp);
      ok = true;
    }
  }
  string out;
  if (!ok) out = "UNRESTORABLE";
  else { 
    sort(res.begin(), res.end());
    out = res[0];
  }
  cout << out << endl;

  return 0;
}



Measured memory_bytes: 256
h,w = map(int,input().split())
l = [["."]*(w+2)]
for i in range(h):
    l.append(["."] + [i for i in input()] + ["."])
l.append(["."]*(w+2))
 
def count(i,j):
    if l[i][j] == "#":
        return "#"
    c = 0
    for n in range(i-1,i+2):
        for m in range(j-1,j+2):
            if l[n][m] == "#":
                c += 1
    return str(c)
 
ans = ["".join([count(i,j) for j in range(1,1+w)]) for i in range(1,1+h)]
 
print("\n".join(ans))

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

const int mod = 1000000007;

long long a[60][60];
long long t[60][60];
long long tmp[60][60];
int n;
long long k;

void power(long long b){
	if (b == 1){
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				t[i][j] = a[i][j];
			}
		}
		return ;
	}
	power(b / 2);
	memset(tmp, 0, sizeof(tmp));
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			for (int k = 0; k < n; k++){
				tmp[i][j] = ((t[i][k] * t[k][j] % mod) + tmp[i][j]) % mod;
			}
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			t[i][j] = tmp[i][j];
		}
	}
	if (b & 1){
		memset(tmp, 0, sizeof(tmp));
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				for (int k = 0; k < n; k++){
					tmp[i][j] = ((t[i][k] * a[k][j] % mod) + tmp[i][j]) % mod;
				}
			}
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				t[i][j] = tmp[i][j];
			}
		}
	}
	return ;
}

int main(){
	scanf("%d%lld", &n, &k);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			scanf("%lld", &a[i][j]);
		}
	}
	power(k);
	long long ans = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (t[i][j]) ans = (ans + t[i][j]) % mod;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

ll mod = 1e9+7;

ll expo(ll a, ll b){
   ll ans = 1;
   while(b){
       if(b&1){
          ans = (ans*a)%mod;
       }
       a = (a*a)%mod;
       b /= 2;
   }
   return ans;
}

int lev[223456], vis[213456];
vector <int> primes;

void bfs(vector <vector <int> > &vec, int n){
    queue <int> q;
    q.push(n);
    vis[n] = 1;
    lev[n] = 0;
    while(!q.empty()){
          int n1 = q.front();
          q.pop();
          for(int i= 0; i < vec[n1].size(); i++){
              if(!vis[vec[n1][i]]){
                 q.push(vec[n1][i]);
                 vis[vec[n1][i]] = 1;
                 lev[vec[n1][i]] = lev[n1]+1;
              }
          }
    }
}
int ok(vector <ll> &vec){
    for(int i = 0; i < vec.size(); i++){
        if(vec[i] >= vec.size()) return 1;
    }
    return 0;
}

int id[123456], sz[123456];

void init(int n){
     for(int i = 1; i <= n; i++){
         id[i] = i;
         sz[i] = 1;
     }
}

int root(int i){
    while(i != id[i]){
          id[i] = id[id[i]];
          i = id[i];
    }
    return i;
}

void union_find(int p, int q, int &max1){
    int i = root(p);
    int j = root(q);
    max1 = 0;
    if(i == j) return;
    if(sz[i] > sz[j]){
       id[j] = i;
       sz[i] += sz[j];
       max1 = sz[i];
    }
    else{
       id[i] = j;
       sz[j] += sz[i];
       max1 = sz[j];
    }
}
ll arr[12345];

int set1[123];

int main()
{
    int n;
    cin >> n;
    vector <ll> vec(n);
    for(int i = 0; i < n; i++) cin >> vec[i];
    ll k = 0;
    while(ok(vec)){
          sort(vec.begin(), vec.end());
          ll k1 = vec[n-1]/n;
          k += k1;
          vec[n-1] = vec[n-1]%n;
          for(int i = 0; i < n-1; i++) vec[i] += k1;
    }
    cout << k;
}


Measured memory_bytes: 256
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>
 
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
 
typedef unsigned long long UInt64;
typedef long long Int64;
 
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
using namespace std;

typedef pair<int,int> P;

int h,w,n;
string maze[1000];

	int dist[1000][1000];
int bfs(char s,char t)
{
	int sx,sy,tx,ty;
	rep(i,1000) rep(j,1000) dist[i][j]=INF;

	rep(i,h) rep(j,w) 
	{
		if(maze[i][j]==s)
		{
			sx=i;
			sy=j;
		}
		if(maze[i][j]==t)
		{
			tx=i;
			ty=j;
		}

	}

	dist[sx][sy]=0;
	queue<P> que;
	que.push(P(sx,sy));

	while(que.size())
	{
		P p = que.front();
		que.pop();
		if(p.fr==tx&&p.sc==ty)
			return dist[tx][ty];

		rep(i,4)
		{
			int nx=p.fr+dx[i];
			int ny=p.sc+dy[i];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&maze[nx][ny]!='X'&&dist[nx][ny]==INF)
			{
				que.push(P(nx,ny));
				dist[nx][ny] = dist[p.fr][p.sc]+1;
			}
		}
	}

	return -INF;
}

int main()
{
	cin>>h>>w>>n;

	rep(i,h) cin>>maze[i];

	rep(i,h) rep(j,w) if(maze[i][j]=='S') maze[i][j]='0';
	int ans=0;
	rep(i,n)
		ans+=bfs(i+'0',i+1+'0');

	cout<<ans<<endl;



		return 0;
}

Measured memory_bytes: 6176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

string s;
int n;

bool isEvenStr(int x){
	for(int i = 0; i < x; i++){
		if(s[i] != s[i + x]) return false;
	}

	return true;
}

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


	cin >> s;	
	n = s.size();

	for(int i = n / 2; i >= 1; i--){
		if(n % 2 == 0 && i == n / 2) continue;
		if(isEvenStr(i)){
			cout << i * 2 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC161C()
{
	ll N, K;
	cin >> N >> K;
	ll x = N - (N / K) * K;
	ll y = x - K;

	cout << min(x, abs(y)) << endl;
}

int main()
{
	ABC161C();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
 
int main() {
  int N; cin >> N;
  string result = "No";
  if ( (N/10) % 111 == 0 || (N%1000) % 111 == 0 ) result = "Yes";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

typedef struct P {
	double x, y;
} P;
typedef struct vec {
	double x, y;
	vec() {}
	vec(P p1, P p2) {
		x = p2.x - p1.x;
		y = p2.y - p1.y;
	}
} vec;
inline double cross(vec v1, vec v2) {
	return v1.x*v2.y - v1.y*v2.x;
}

P p[4];
vec v[3];
double a, b;
int ar[3][4] = {
	{0,1,2,3 },{1,2,0,3},{2,0,1,3}
};

int main(){
	bool f;
	while (true) {
		for (int i = 0; i < 4; i++) {
			if (scanf("%lf%lf", &p[i].x, &p[i].y) == EOF) {
				return 0;
			}
		}
		f = true;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				v[j] = vec(p[ar[i][0]], p[ar[i][j + 1]]);
			}
			a = cross(v[0], v[1]);
			b = cross(v[0], v[2]);
			if (a*b < 0) {
				printf("NO\n");
				f = false;
				break;
			}
		}
		if (f) {
			printf("YES\n");
		}
	}

	return 0;
}

Measured memory_bytes: 2556
from math import log,ceil
def solve():
    N,K = map(int, input().split())
    # if N == 1 and K != 1:
    #     print("0")
    #     exit()
        
    # elif N == 1 and K ==  1:
    #     print("1")
    #     exit(0)

    
    ans = 0
    for x in range(1, N+1): # xは初期値
        kaisuu = ceil( log( K / x, 2))
        # tmp = pow(0.5, kaisuu)
        tmp = 1/N
        for i in range(kaisuu):
            tmp *= 0.5
        ans += tmp 
    # ans /= N
    print(ans)
        

    
if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;

int a[105];



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n);

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            for(int x=j+1;x<=n;x++)
            {
                if(a[i]==a[j]||a[j]==a[x])
                    continue;
                int temp=a[i]+a[j];
                if(temp>a[x])
                    cnt++;
            }
        }
    }
    cout<<cnt<<'\n';



}


Measured memory_bytes: 3688
#include<stdio.h>

int main(){

int s=0;
int d=10;
int A=0;
int n;
int a,b;

while(scanf("%d %d %d",&a,&b,&n)!=EOF){
int S=0;s=a%b;
for(int i=0;i<n;i++)
{
s*=10;
A=s/b;s=s%b;
S+=A;
}
printf("%d\n",S);
}
return 0;
}

Measured memory_bytes: 1024
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<ll> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string ans="";
  	rep(i,3){
      string temp;
      cin>>temp;
      ans+=temp[i];
    }
  	cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  //string s;std::cin >> s;
  /*
  ll ans = 0, now = 1;
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='1') ans += now;
    now*=2;
  }
  */
  ll ans;std::cin >> ans;
  string t = to_string(ans);
  for(int i=0;i<t.size();i++){
    if(t[i]=='9'){
      std::cout << "Yes" << '\n';
      return 0;
    }
  }
  std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n;
    cin>>n;
    if(n%(ll)2!=(ll)0){
        cout<<0<<endl;
    }else{
        ll ans=n/(ll)10;
        ll t=5;
        while(t<n/(ll)5){
            t*=(ll)5;
            ans+=n/(t*(ll)2);
        }
        cout<<ans<<endl;
    }
    return(0);
}

Measured memory_bytes: 256
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()

d = {'r': P, 's': R, 'p': S}

list = ['' for i in range(K)]

for i in range(N):
    list[i%K] = list[i%K] + T[i]


score = 0
for i in range(K):
    hand = list[i]
#    print('hand = {}'.format(hand))
    score += d[hand[0]]
#    print(d[hand[0]])
    for j in range(1, len(hand)):
#        print(hand)
        if hand[j] != hand[j-1]:
            score += d[hand[j]]
#            print(d[hand[j]])
        else:
            hand = hand[:(j)] + '#' + hand[(j+1):]

print(score)


Measured memory_bytes: 6132
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;

vl vec;
 
int main()
{
    ll m,d,cnt=0;
    cin>>m>>d;
    for (int i = 10; i <= d; ++i)
    {
        if( (i%10>=2) && (i/10)%10>=2)
        {
            if((i%10) * ((i/10)%10)<=m)
                cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 300005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,a[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<3*n;i++) scanf("%d",&a[i]);
    sort(a,a+3*n);
    ll ans=0;
    for(int i=3*n-2;i>=n;i-=2) ans+=a[i];
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 1408
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))
MOD = 10**9 + 7

n, k = MAP()
have = set([])
for i in range(k):
    d = INT()
    a = LIST()
    have = set(list(have) + a)
print(n - len(have))

Measured memory_bytes: 72808
def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True
  
s = input()

s_1 = s[:(int)((len(s)-1)/2)]
s_2 = s[(int)((len(s)+3)/2)-1:len(s)]

if is_kaibun(s) and is_kaibun(s_1) and is_kaibun(s_2):
  print('Yes')
else:
  print('No')

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

int main()
{
	int n,p;
    cin>>n;
    int t=1;
    map<int,int> f;
        for(int i=1;i<=100;i++)
    {
        for(int j=1;j<=100;j++)
        {
            for(int k=1;k<=100;k++)
            {
                        p=i*i+j*j+k*k+i*j+i*k+j*k;
        {
            f[p]++;
        }    
            }
        }

    }

    for(int i=1;i<=n;i++)
        cout<<f[i]<<endl;
	return 0;
}

Measured memory_bytes: 5404
n = int(input())
a = []
b = []
ab = []
for i in range(n):
    ai,bi = map(int,input().split())
    a.append(ai)
    b.append(bi)
    ab.append((ai,bi))
a.sort()
b.sort()
x1 = a[(n-1)//2]
x2 = a[(n-1)//2+1]
y1 = b[n-1-(n-1)//2]
y2 = b[n-2-(n-1)//2]
if n % 2 == 1:
    print(y1-x1+1)
else:
    print(y2+y1-x2-x1+1)

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

int main()
{
    string s;
    cin >> s;
    int q;
    cin >> q;
    string prefix = "";
    string suffix = "";
    bool flag = false;
    for (int i = 0; i < q; i++)
    {
        int t;
        cin >> t;
        if (t == 1) flag = !flag;
        if (t == 2)
        {
            int f; char c;
            cin >> f >> c;
            f--;
            if (flag) f = !f;
            if (f == 0) prefix += c;
            else suffix += c;
        }
    }
    if (flag)
    {
        for (int i = 0; i < suffix.size(); i++) cout << suffix[suffix.size() - 1 - i];
        for (int i = 0; i < s.size(); i++) cout << s[s.size() - 1 - i];
        cout << prefix << endl;
    }
    else 
    {
        for (int i = 0; i < prefix.size(); i++) cout << prefix[prefix.size() - 1 - i];
        cout << s << suffix << endl;
    }
}


Measured memory_bytes: 1088
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,d[MN+5],q[MN+5],top,head[MN+5],cnt=0;
int main()
{
	n=read();memset(d,40,sizeof(d));
	d[q[top=1]=1]=1;
	for(int i=1;i<=top;++i)
	{
		int x=q[i];
		if(d[x]+1<d[(x+1)%n]) d[q[++top]=(x+1)%n]=d[x]+1;
		if(d[x]<d[x*10%n]) d[q[i]=x*10%n]=d[x],--i;
	}
	printf("%d\n",d[0]);
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
int main() {
  int a,b,c,i;
  std::cin>>i;
  for(int j=0;j<i; j++) {
    std::cin>>a>>b>>c;
    a*=a,b*=b;c*=c;
    if((a==b+c)||(b==a+c)||(c==a+b)){
      std::cout<<"YES\n";
    }else{
      std::cout<<"NO\n";
    }
  }
}

Measured memory_bytes: 0
/*GRATITUDE*/
//Arise Awake and Stop Not Till the Goal is reached. You are the greatest of all. Hare Krishna
//Break through all barriers..
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define ff              first
#define ss              second
#define uint            unsigned long long
#define int             long long
#define double           long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define vpii            vector<pii>
#define umpii           unordered_map<int,int>
#define ustii           unordered_set<int>   
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             10000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define endl            "\n"
#define all(x)             x.begin(), x.end()
#define all_r(x)           x.rbegin(), x.rend()
#define sortall(x)         sort(all(x))
#define sortall_r(x)       sort(all_r(x))  
#define tr(it, a)          for(auto it = a.begin(); it != a.end(); it++)
#define PI                 acos(-1)
#define w(t)              int t; cin>>t; while(t--)
#define for_f(a,b,c)      for(int i=a;i<=b;i=i+c)
#define for_r(a,b,c)      for(int i=a;i>=b;i=i-c) 
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define trace1(x) cout << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
void ash_god()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    freopen("o.txt", "w", stdout);
#endif
}
/*************************************************************************************************/
//Write your functions here..............................


/***************************************************************************************************/
void solve() {
/*Write your code here*/
string s,t; cin>>s>>t;
int res=0;
for_f(0,s.length()-1,1){
    if(s[i]!=t[i]) res++;
}
cout<<res<<endl;
}
int32_t main()
{
ash_god();
bool tc=0;
if(tc)  {
    w(t) solve();
}
else solve();

return 0;
} 



Measured memory_bytes: 3776
import numpy as np


n, m = map(int, input().split())
a = []
for i in range(n):
    a.append(list(input()[:]))
b = []
for i in range(m):
    b.append(list(input()[:]))
a = np.array(a)
b = np.array(b)
for i in range(n-m+1):
    for j in range(n-m+1):
        if (a[i:i+m, j:j+m] == b).all():
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")



Measured memory_bytes: 12512
/* ***********************************************
Author        :yang12138
Created Time  :2017年06月03日 星期六 20时49分50秒
File Name     :C.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=1e6+10;

ll a[N],b[N];
int n;

int Hash(ll x){
	return lower_bound(b+1,b+n+1,x)-b;
}

ll bit[N];
void add(int i,int x){
	while(i<=n){
		bit[i]+=x;
		i+=i&-i;
	}
}

ll sum(int i){
	ll ans=0;
	while(i){
		ans+=bit[i];
		i-=i&-i;
	}
	return ans;
}

void solve(){
	ll k;
	scanf("%d%lld",&n,&k);
	
	for(int i=1;i<=n;i++){
		scanf("%lld",a+i);
		a[i]+=a[i-1]-k;
		b[i]=a[i];
	}

	sort(b+1,b+n+1);

	ll ans=0;
	for(int i=1;i<=n;i++){
		int id=Hash(a[i]);
		ans+=sum(id);
		add(id,1);
		if(a[i]>=0) ans++;
	}

	printf("%lld\n",ans);

}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef long long ll;
typedef pair<int,int> P;
ll mod=1e6+3;
void add(ll &x,ll y){
	x+=y;
	x%=mod;
}
int N,M;
vector<P> es;
set<int> st;
set<int>::iterator it;
int nxt[110000];
ll dp[110000][4];
bool comp(const P& l,const P& r){
	return l.sc-l.fs<r.sc-r.fs;
}
void init(){
	es.clear();
	st.clear();
	rep(i,110000){
		nxt[i]=0;
		rep(j,4) dp[i][j]=0;
	}
}
int main(){
	while(true){
		cin>>N>>M;
		if(N==0) break;
		init();
		if(N%2){
			puts("0");
			continue;
		}
		if(M==0){
			if(N==2) puts("1");
			else puts("2");
			continue;
		}
		int p,q,r,s;
		rep(i,M){
			int a,b;
			cin>>a>>b;
			a--,b--;
			if(a>b) swap(a,b);
			if(b-a>N/2) swap(a,b),b+=N;
			es.pb(P(a,b));
		}
		sort(all(es),comp);
		{
			p=es[M-1].fs,q=es[M-1].sc,r=q,s=p+N;
			if(r>=N) r-=N,s-=N;
			es.pb(P(r,s));
		}
		rep(i,M+1){
			P e=es[i];
			int a=e.fs,b=e.sc;
			int y=a,x=-1,nx=b;
			ll val[4]={},nval[4]={};
			val[1]=val[2]=1;
			while(true){
				it=st.lower_bound(y);
				if(it==st.end()||*it>=b) break;
				x=*it;
				nx=nxt[x];
				if((x-y)%2){
					swap(val[0],val[1]);
					swap(val[2],val[3]);
				}
				for(int o=0;o<=2;o+=2){
					add(nval[0+o],val[0+o]*dp[x][2]);
					add(nval[1+o],val[0+o]*dp[x][3]);
					add(nval[0+o],val[1+o]*dp[x][0]);
					add(nval[1+o],val[1+o]*dp[x][1]);
				}
				rep(j,4) val[j]=nval[j],nval[j]=0;
				st.erase(x);
				st.erase(x+N);
				y=nx;
			}
			if((b-y)%2){
				swap(val[0],val[1]);
				swap(val[2],val[3]);
			}
			st.insert(a);
			st.insert(a+N);
			nxt[a]=b,nxt[a+N]=b+N;
			rep(j,4) dp[a][j]=val[j];
			if(i!=M) add(dp[a][3],dp[a][0]);
			rep(j,4) dp[a+N][j]=dp[a][j];
		}
		ll ans=dp[p][0]*dp[r][3]+dp[p][1]*dp[r][1]+dp[p][2]*dp[r][2]+dp[p][3]*dp[r][0];
/*		show(p);
		show(q);
		show(r);
		show(s);
		rep(i,4) show(dp[p][i]);
		rep(i,4) show(dp[r][i]);*/
		cout<<ans%mod<<endl;
	}
}

Measured memory_bytes: 6764
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars
    }
    let n = s.len();
    let mut res = 0;
    let mut b: usize = 0;
    while b < (1usize << n-1) {
        let mut sum = 0;
        for i in 0..n {
            let d = s[i].to_digit(10).unwrap() as usize;
            if (b >> i) & 1 != 0 {
                res += sum * 10 + d;
                sum = 0;
            } else {
                sum = sum * 10 + d;
            }
        }
        res += sum;
        b += 1;
    }
    println!("{}", res);
}


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

int main(){
    int N;
    cin >> N;
    int n = N;
    int i = 0;
    while(n > 1000){
        n -= 1000;
        i++;
    }
    int ans = (i+1)*1000 - N;
    cout << ans << endl;
}

Measured memory_bytes: 3620