akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int n;
    cin>>n;
    vector<int> A(n),B(n);
    for(int i=0;i<n;i++)cin>>A[i];
    for(int i=0;i<n;i++)B[i]=A[i];
    sort(B.begin(),B.end());
    int M1 = B[n-1],M2 = B[n-2];
    for(int i=0;i<n;i++){
        if(A[i]==M1)cout<<M2<<endl;
        else cout<<M1<<endl;
    }

}

Measured memory_bytes: 3200
#include <iostream>

using namespace std;

int main() {
    string O, E;
    cin >> O >> E;
    int flag = O.length() - E.length();
    for (int i = 0; i < O.length() - 1; ++i) {
        cout << O[i];
        cout << E[i];
    }
    cout << O[O.length() - 1];
    if (!flag) {
        cout << E[O.length() - 1];
    }
    cout << endl;
    return 0;
}

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

int A, B, C;

int main(){
	scanf("%d%d%d", &A, &B, &C);
	int ans = 0;
	for(register int i = 0; i <= 10000000; ++ i){
		if((A & 1) || (B & 1) || (C & 1)) return printf("%d\n", i), 0;
		int ta = B + C >> 1, tb = A + C >> 1, tc = A + B >> 1;
		A = ta;
		B = tb;
		C = tc;
	}
	printf("-1\n");
	return 0;
}

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for (int i = 0; i < ty - sy; i++) {
        cout << 'U';
    }
    for (int i = 0; i < tx - sx; i++) {
        cout << 'R';
    }
    for (int i = 0; i < ty - sy; i++) {
        cout << 'D';
    }
    for (int i = 0; i < tx - sx + 1; i++) {
        cout << 'L';
    }
    for (int i = 0; i < ty - sy + 1; i++) {
        cout << 'U';
    }
    for (int i = 0; i < tx - sx + 1; i++) {
        cout << 'R';
    }
    cout << "DR";
    for (int i = 0; i < ty - sy + 1; i++) {
        cout << 'D';
    }
    for (int i = 0; i < tx -sx + 1; i++) {
        cout << 'L';
    }
    cout << 'U' << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
for ($i=0; $i<5; $i++){
    fscanf(STDIN, "%d", $tmp);
    $array[] = $tmp;
}
fscanf(STDIN, "%d", $K);
if (max($array) - min($array) > $K){
    echo ":(";
}else{
    echo "Yay!";
}

Measured memory_bytes: 3828
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>

namespace IO {
    template <typename _T>
    inline bool read (_T& x) {
        x = 0;
        _T y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return false;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return true;
    }

    template <typename _T>
    inline _T input () {
        _T x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return x;
    }
};
using namespace IO;

namespace modular {
    const int MOD = 1000000007;

    inline int add (int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }

    inline void inc (int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }

    inline int mul (int x, int y) { return 1LL * x * y % MOD; }

    inline int qpow (int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x)) if (y & 1) ans = mul(ans, x);
        return ans;
    }
};

#define reg register
#define MAX_N 200007
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define lep(i, l, r) for(int i = l; i < r; ++i)
#define irep(i, r, l) for(int i = r; i >= l; --i)
#define ilep(i, r, l) for(int i = r; i > l; --i)
typedef long long ll;

int N;
int a[MAX_N];

inline void print (bool k, bool p) { puts(k ^ p ? "First" : "Second"); exit(0); }

void dfs (int p) {
    int cnt[2] = {0, 0};
    rep (i, 1, N) cnt[a[i] & 1]++;
    rep (i, 1, N) if (a[i] == 1) print(cnt[0] & 1, p);
    if (cnt[0] & 1) print(1, p);
    else if (cnt[1] > 1) print(0, p);
    rep (i, 1, N) if (a[i] != 1 && (a[i] & 1)) a[i]--;
    int d = a[1];
    rep (i, 2, N) d = std::__gcd(d, a[i]);
    rep (i, 1, N) a[i] /= d;
    dfs(p ^ 1);
}

int main () {
#ifdef LOCAL
    FIN("in");
#endif
    read(N);
    rep (i, 1, N) read(a[i]);
    dfs(0);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector< vector<int> > abc(n, vector<int>(3));
  for (int i = 0; i < n; ++i) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];

  vector< vector<int> > dp(n + 1, vector<int>(3, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
	if (j == k) continue; // cannot choose the same activity
	dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[i][k]);
      }
    }
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << '\n';
  return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
char f;
string gras,srag,tab[110];
int main()
{
    cin>>a;

    for(int i=1; i<=a; i++)
    {
        cin>>gras;
        tab[i]=gras;
        for(int k=1; k<i; k++)
        { //cout<<tab[k]<<" tu ci się pierdoli";
            if(gras==tab[k] && i!=1)
            {
                cout<<"No";
                return 0;
            }
        }
        if(i!=1 && f==gras[0]) c++;
        b=gras.length()-1;
       // cout<<b<<"   indeks    ";
        f=gras[b];// cout<<f<<"  <== litera    "<<endl;
    }
    if(c==a-1) cout<<"Yes";
    else cout<<"No";
}




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

std::vector<int> prime_factor(const int n) {
    int tmp = n;
    std::vector<int> result;
    for(int i = 2; i * i <= n; ++i) {
        while(!(tmp % i)) {
            tmp /= i;
            result.push_back(i);
        }
    }
    if(tmp != 1) result.push_back(tmp);
    return result;
}

std::vector<bool> Eratosthenes(const int n) {
    std::vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; is_prime[i] && i * i <= n; ++i)
        for(int j = i << 1; j <= n; j += i)
            is_prime[j] = false;
    return is_prime;
}

int power(const int m, const int n) {
    if(!n) return 1;
    if(n & 1) return power(m, n - 1) * m;
    return power(m * m, n >> 1);
}


int mod_power(const long long int m, const long long int n, const int mod) {
    if(!n) return 1;
    if(n & 1) return mod_power(m, n - 1, mod) * m % mod;
    return mod_power(m * m % mod, n >> 1, mod) % mod;
}

int gcd(const int m, const int n) {
    return n ? gcd(n, m % n) : m;
}

int lcm(const long long int m, const long long int n) {
    return m * n / gcd(m, n);
}

int phi(const int n) {
    int answer = n;
    auto list = prime_factor(n);
    for(auto i: std::set<int>(list.begin(), list.end())) answer -= answer / i;
    return answer;
}

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

#include<iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    cout << phi(n) << endl;
}

Measured memory_bytes: 1212
N = int(input())

A = [[int(i) for i in input().split()]for _ in range(N)]
A = sorted(A, key=lambda x:x[1])
total = 0
ret = "Yes"
for i in A:
	total += i[0]
	if total > i[1]:
		ret="No"
		break
print(ret)


Measured memory_bytes: 42716
n = int(input())

adj = [[100001 for j in range(n)] for i in range(n)]

for u in range(n):
    x = list(map(int, input().split()))
    for v, c in zip(x[2::2], x[3::2]):
        adj[u][v] = c

unvisited = [v for v in range(n)]

distance = [9900001] * n


def dijkstra(s):
    distance[s] = 0

    while True:
        mincost = 9900001
        for i in unvisited:
            if distance[i] < mincost:
                mincost = distance[i]
                u = i

        if mincost == 9900001:
            break

        unvisited.remove(u)

        for v in unvisited:
            weight_uv = adj[u][v]
            if weight_uv != 100001:
                t_d = distance[u] + weight_uv
                if t_d < distance[v]:
                    distance[v] = t_d



dijkstra(0)

for v, d in enumerate(distance):
    print(v, d)

Measured memory_bytes: 7848
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] h = new int[n];
        boolean[] ten = new boolean[n];//yoitenboudai ccount i
        int cnt =0; 
        
        for(int i = 0;i<n;i++){
            h[i] = sc.nextInt();
            ten[i] = true;
        }

        for(int i = 0;i<m;i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            if(h[a]<h[b]){
                ten[a] = false;
            }else if(h[a]>h[b]){
                ten[b] = false;
            }else{
                ten[a] = false;
                ten[b] = false;
            }
        }

 /*       for(int i = 0;i<n;i++){
            System.out.println("ten["+i+"]="+ten[i]);

        }
       for(int i = 0;i<n;i++){
           System.out.println("ten2["+i+"]="+ten2[i]);
      }
*/
        for(int i = 0;i<n;i++){
            if(ten[i]){
                cnt++;
                //System.out.println("Yess"+i);
            }

        }

        System.out.println(cnt);
        
    }
}


Measured memory_bytes: 59408
#include<bits/stdc++.h>
using namespace std;
int arr[1004];
int main()
{
	int n,k,pi,sum=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>pi;arr[i]=pi;
	}
	sort(arr,arr+n);
	for(int i=0;i<k;i++)
		sum+=arr[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 3584
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
using namespace std;

int main(){
	int N; cin >> N;
	int D[2][110];
	for (int i = 0;i < N; i++) cin >> D[0][i] >> D[1][i];
	for (int i = 0; i < N - 2; i++)
	{
		if ((D[0][i] == D[1][i]) && (D[0][i + 1] == D[1][i + 1]) &&
		(D[0][i + 2] == D[1][i + 2]))
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	cout << max(max(2 * a - 1, 2 * b - 1), a + b) << '\n';
	return 0;
}

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

#define pds pair<double,string>

using namespace std;

int main(){
	int n,a,b,c,d,e,f,s,m,p;
	while(cin>>n,n){
		vector<pds> v;
		for(int i=n;i--;){
			string l;
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			a+=b+c+(d+e)*m,f*=s*m;
			v.push_back(make_pair(-1.0*(f-p)/a,l));
		}
		sort(v.begin(),v.end());
		for(auto i:v)cout<<i.second<<endl;
		cout<<"#"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>

int main(){
    int n,k,x,y,sum=0;
    scanf("%d%d%d%d",&n,&k,&x,&y);
    for (int i=0; i<n; i++) {
        if (i<k) {
            sum+=x;
        }else{
            sum+=y;
        }
    }
    printf("%d\n",sum);
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        vector<Int> A(2 * N);
        for (int i = 0; i < 2 * N; ++i) {
            cin >> A[i];
        }
        sort(all(A));
        Int ans = 0;
        for (int i = 0; i < 2 * N; i += 2) {
            ans += A[i];
        }
        cout << ans << endl;
    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define RFOR(i,k,n) for (int (i)=(n)-1; (i)>=(k); --(i))
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
using namespace std;
//static const int INF = 1e9;
//static const double PI = acos(-1.0);
//static const double EPS = 1e-10;
//static const int dx[8] = { 1, 1, 0,-1,-1,-1, 0, 1};
//static const int dy[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;

int main() {
  int N, ans = 0;
  cin >> N;
  VI l(N), r(N);
  REP(i, N) { cin >> l[i] >> r[i]; }
  REP(i, N) { ans += r[i] - l[i] + 1; }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  long a[n+1],x[n+1];
  for(int i = 1;i <= n;i++){
    cin >> a[i];
    x[i] = 0;
  }
  for(int i = 1;i <= n;i++){
    if(i % 2 == 0){
      x[1] -= a[i];
    }
    else{
      x[1] += a[i];
    }
  }
  x[1] /= 2;
  for(int i = 2;i <= n;i++){
    x[i] = a[i-1] - x[i-1];
  }
  for(int i = 1;i <= n;i++){
    cout << x[i]*2 << endl;
  }
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define f(i,a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ld float
#define fd(i,a, b) for (ll i = a; i >= b; i--)
#define mx 1e17
/*  #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
     typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/


ll modpow(ll a,ll b){
 ll res=1;
 while(b>0)
{
    if(b&1)res=(res*a)%mod;
    b=b>>1;
    a=(a*a)%mod;

}
return res;
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
ll n,k;
cin>>n>>k;
ll aa[n];
f(i,0,n)cin>>aa[i];
sort(aa,aa+n);
ll ans=0;
for(int i=n-1-k;i>=0;i--)ans+=aa[i];
cout<<ans;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
// vector<int> fac; //precompute fac array
// fac.resize(n+1);
// fac[0] = 1; 
// for (int i=1; i<=n; i++)   fac[i] = m(m(fac[i-1])*m(i));
// int modInverse(int n){ 
// return p(n, MOD-2); 
// }  
// int nCr(int n, int r){   
//     if(r == 0)  return 1; 
//     return m(m(m(fac[n])*m(modInverse(fac[r])))*m(modInverse(fac[n-r]))); 
// } 
signed main(){
    fast();
    int n;
    cin >> n;
    int a = m(m(m(p(10, n))+p(8, n))-m((m(m(2)*m(p((int)9, n))))));
    cout << a << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

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

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


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

bool dic[1300000000] = {false};

int main() {
    int n, i, j, k;
    unsigned long long idx;
    char command[13];
    char element[13];
    char cur;
    cin >> n;
    for (i=0; i<n; i++) {
        cin >> command >> element;
        j = 0;
        while (element[j] != '\0') {
            j++;
        }
        j--;
        idx = 0;
        for (k=j; k>=0; k--) {
            if (element[j-k] == 'A') idx += 1 * int(pow(4.0, k));
            else if (element[j-k] == 'C') idx += 2 * int(pow(4.0, k));
            else if (element[j-k] == 'G') idx += 3 * int(pow(4.0, k));
            else idx += 4 * int(pow(4.0, k));
        }
        if (command[0] == 'i') {
            dic[idx] = true;
            // cout << idx << endl;
        }
        else {
            if (dic[idx]) cout << "yes\n";
            else cout << "no\n";
            // cout << idx << endl;
        }
    }
}


Measured memory_bytes: 4436
/*
 * I won't be broken
 * I won't be tortured
 * I won't be beaten down
 * I have the answer
 * I can take the pressure
 * I will turn it all around
 * Lift me up above this
 * The flames and the ashes
 * Lift me up and help me to fly away
*/
#include <bits/stdc++.h>
using namespace std;
int n,t[100005],x[100005],y[1000005];
int main(){
        scanf("%d",&n);
        t[0]=y[0]=x[0]=0;
        for(int i = 1; i<=n; i++)
                scanf("%d %d %d",t+i,x+i,y+i);
        for(int i = n; i>=1; i--){
                if(x[i]==x[i-1]&&y[i]==y[i-1]&&(t[i]-t[i-1])%2&&(t[i]!=t[i-1])){
                        printf("No\n");
                        return 0;
                }
                else if((t[i]-t[i-1])<abs(x[i]-x[i-1])+abs(y[i]-y[i-1])||(t[i]-t[i-1])%2!=(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2){
                        printf("No\n");
                        return 0;
                }


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


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    string S,T;
    cin >> S >> T;
    int N = S.size();
    for(int i=0;i<N;i++){
        string s = S;
        for(int j=0;j<N;j++){
            if(j-i>=0){
                s[j-i] = S[j];
            }
            else{
                int num = abs(j-i);
                s[N-num]=S[j];
            }
        }
        if(s==T){
            cout << "Yes" << endl;
            break;
        }
        else if(i==N-1){
            cout << "No" <<endl;
        }
    }
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>

#define LL long long
#define VI vector<int>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

template <class T> int find_index(T x, const std::vector<T> &v) {
    auto it = std::find(v.begin(), v.end(), x);
    if (it != v.end()) { return (int)std::distance(v.begin(), it); }
    return -1;
}

template <class T> void print(T x) {
    std::cout << x << std::endl;
}

using namespace std;



int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    int l = 0, r = 0;
    int center = S.size() / 2;
    if (S.size() % 2 == 0) {
        l = center - 1;
        r = center;
    }
    else {
        l = center;
        r = center;
    }
    while (0 <= l && r < S.size() && S[l] == S[center] && S[l] == S[r]) {
        l--;
        r++;
    }
    print(S.size() - (l + 1));

    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <deque> 

using namespace std;


int n, q;
char s[100010];
int lAcCount[100010];	//从左往右的AC出现次数,也即F[i] 

int main()
{
	scanf("%d%d\n", &n, &q);
	scanf("%s", s);
	//s要移进一格，方便计算
	for (int i = n ; i >= 1 ; i--) 
		s[i] = s[i - 1];
	s[0] = ' ';
	
	//首先计算从左往右的AC出现的次数，从1开始计算，所有先赋予初值 
	lAcCount[0] = 0;
	for (int i = 1 ; i <= n ; i++)
	{
		//动态转移方程
		//F[i] = max(F[i-1], F[i-2])，如果(s[i-1],s[i]不等于AC
		//     =  max(F[i-1], F[i-2]+1)，如果(s[i-1],s[i]等于AC
		lAcCount[i] = lAcCount[i - 1];
		if (s[i - 1] == 'A' && s[i] == 'C')
		{
			if ((lAcCount[i - 2] + 1) > lAcCount[i])
				lAcCount[i] = lAcCount[i - 2] + 1;
		}
		else
		{
			if (lAcCount[i - 2] > lAcCount[i])	//这点应当是不可能的 
				lAcCount[i] = lAcCount[i - 2];
		}
	}
	
	//然后，处理查询
	int l, r;
	int ans;
	for (int ii = 0 ; ii < q ; ii++) 
	{
		scanf("%d%d", &l, &r);
		
//		ans = lAcCount[r] - lAcCount[l - 1];
		ans = lAcCount[r] - lAcCount[l];	//这里不应当有-1？ 
		printf("%d\n", ans);
	}
	
	return 0;
}


Measured memory_bytes: 1280
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

def func(B, X):
  res = 0
  for i in range(M):
    res += B[i] * X[i]
  return res
    
  
count = 0
for i in range(N):
  if func(B, A[i]) + C > 0:
    count += 1

print(count)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int m1,d1,m2,d2;
   cin >> m1 >>d1 >> m2 >> d2;
   if(m1!=m2){
      cout << "1\n";
   }else{
      cout << "0\n";
   }
   return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
  char s[200], t[200];
  scanf("%s%s", s, t);

  int n = strlen(s); int k = 0;

  for(int i = 0; i < n; i++){
    k = 0;
    for(int j = 0; j < n; j++){
      if(j + i < n && t[i + j] == s[j]){
	k++;
      }
      else if(j + i >= n && t[i + j - n] == s[j]){
	k++;
      }
    }
    if(k == n){
      printf("Yes\n");
      break;
    }
    else if(i == n - 1){
      printf("No\n");
    }
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

map<pair<string,string>,int64_t> mp;
int main(){
    int n; cin>>n;
    string s; cin>>s;
    string s1=s.substr(0,n);
    string s2=s.substr(n); reverse(all(s2));
    for(int mask=0;mask<(1<<n);mask++){
        string r,b;
        for(int i=0;i<n;i++){
            if(mask>>i&1){
                r+=s1[i];
            }else{
                b+=s1[i];
            }
        }
        mp[{r,b}]++;
    }
    int64_t ans=0;
    for(int mask=0;mask<(1<<n);mask++){
        string r,b;
        for(int i=0;i<n;i++){
            if(mask>>i&1){
                b+=s2[i];
            }else{
                r+=s2[i];
            }
        }
        ans+=mp[{r,b}];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 91904
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>

#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)

using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
char S[1111];

int main() {
	scanf("%s", S);
	bool n=false,w=false,s=false,e=false;
	int l = strlen(S);
	int px=0, py=0;
	REP(i, l) {
		if(S[i]=='N') {
			n=true;
			py--;
		} else if(S[i]=='W') {
			w=true;
			px--;
		} else if(S[i]=='E') {
			e = true;
			px++;
		} else {
			s = true;
			py++;
		}
	}
	bool good = true;
	if(px>0&&!w) good = false;
	if(px<0&&!e) good = false;
	if(py<0&&!s) good = false;
	if(py>0&&!n) good = false;
	if(good) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;
const ll base = 5;
const ll MOD2 = 2111211121;
const ll base2 = 3;

set<pair<ll, ll>> X[100010], fin;
ll roll[100010], roll2[100010];
vector<ll> DS;
ll L;

void dfs(ll rh, ll bn, ll rh2, ll bn2, ll dep) {
	rh %= MOD;
	rh2 %= MOD2;

	if (fin.count({ rh,rh2 }))return;

	if (X[dep].count({ rh,rh2 }) == 0) {
		DS.push_back(L - dep);
		return;
	}
	bn *= base;bn %= MOD;
	bn2 *= base2;bn2 %= MOD2;

	rh += bn;
	rh2 += bn2;
	dfs(rh, bn, rh2, bn2, dep + 1);

	rh += bn;
	rh2 += bn2;
	dfs(rh, bn, rh2, bn2, dep + 1);
}

int main() {
	ll N;
	cin >> N >> L;
	vector<string> S(N);
	for (int i = 0;i < N;i++) {
		cin >> S[i];
	}
	ll b, s, b2;
	for (int i = 0;i < N;i++) {
		b = b2 = 1;
		s = S[i].size();
		roll[i] = roll2[i] = 0;
		for (int j = 0;j < s;j++) {
			if (S[i][j] == '1') {
				roll[i] += b * 2;
				roll2[i] += b2 * 2;
			}
			else {
				roll[i] += b;
				roll2[i] += b2;
			}
			roll[i] %= MOD;
			roll2[i] %= MOD2;
			X[j].insert({ roll[i],roll2[i] });
			if (j == s - 1)fin.insert({ roll[i],roll2[i] });
			else {
				b *= base;
				b2 *= base2;
				b %= MOD;
				b2 %= MOD2;
			}
		}
	}
	dfs(1, 1, 1, 1, 0);
	dfs(2, 1, 2, 1, 0);

	ll xora = 0;
	for (ll i : DS) {
		//cout << i << endl;
		xora = (xora ^ i ^ (i - 1));
	}
	if (xora) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Bob" << endl;
	}
}

Measured memory_bytes: 21884
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Ti4 tuple<int, int, int, int>
#define Tlll tuple<ll, ll, ll>
#define PI 3.141592653589793

int main() {
    int m, n1, n2; 
    
    while (cin >> m >> n1 >> n2) {
        if (m == 0) return 0;
        int p[m], mx = 0, mx_idx = -1;
        for (int i = 0; i < m; i++) cin >> p[i];
        for (int i = n1; i <= n2; i++) {
            if (mx <= p[i - 1] - p[i]) {
                mx = p[i - 1] - p[i];
                mx_idx = i;
            }
        }
        cout << mx_idx << endl;
    }
}



Measured memory_bytes: 3076
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x);
		y = y >> 1;
		x = (x * x);
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n, 0);
	vector<ll> b(n, 0);
	vector<ll> c(n - 1, 0);
	f(i, 0, n)
		cin >> a[i];
	f(i, 0, n)
		cin >> b[i];
	f(i, 0, n-1)
		cin >> c[i];
	ll sum = 0;
	f(i, 0, n)
	{
		sum += b[a[i] - 1];
		if (i > 0 && a[i - 1] + 1 == a[i])
		{
			sum += c[a[i] - 2];
		}
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;

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 debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
int run_test(){
      int n, x, y;
      cin >> n >> x >> y;
      int k = min(x, y);
      int t = max(x, y);
      int dist[n + 1][n + 1];
      for(int i=1; i<=n; i++){
            for(int j = i + 1; j <= n; j++){
                  dist[i][j] = min(j - i, abs(t-j) + abs(x - i) + 1);
            }
      }
      int ans[n + 1];
      fill(ans, 0);
      for(int i=1; i<=n; i++){
            for(int j = i + 1; j<=n ;j++){
                  ans[dist[i][j]]++;
            }
      } 
      for(int i=1; i<n; i++){
            cout << ans[i] << "\n";
      }
      return 0;
}

int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 17388
#include <cstdio>

int n, a[200002];
int sum, bit;
long long res;

int main() {
    scanf("%d", &n);
    int l = 0;
    for (int r = 0; r < n; r++) {
        scanf("%d", &a[r]);
        
        while (l < r && sum+a[r] != (sum^a[r])) {
            sum -= a[l];
            bit ^= a[l];
            l++;
        }
        res += (r-l+1);
        sum += a[r];
        bit ^= a[r];
    }

    printf("%lld", res);

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;

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

int main() {
    cout<<setprecision(16);
    ll a,l;
    while(true) {
        cin >> a >> l;
    if(a==0&&l==0)break;
    map<ll,ll> m;
    m[a]=0;
    ll ii=0;
    ll pre=a;
    while(true){
        ii++;
        vector<ll> v1(l);
        rep(g,l)v1[g]=0;
        ll ka=pre, j=0;
        while(ka>=1){
            v1[j]=ka%10ll;
            ka/=10ll;
            j++;
        }

        sort(v1.rbegin(),v1.rend());
        vector<ll> v2(l);
        rep(g,l){v2[g]=v1[g];}

        //v2=v1;
        sort(v2.begin(),v2.end());
        reverse(v1.begin(),v1.end());
        reverse(v2.begin(),v2.end());

        ll sv1=0,sv2=0;
        rep(i,l){
            sv1+=v1[i]*(ll)(pow(10,i));
            sv2+=v2[i]*(ll)(pow(10,i));
        }
        ll sv;
        sv=sv1-sv2;

        if(m[sv]!=0||sv==a){
            cout<<(sv==a?0:m[sv])<<" "<<sv<<" "<<ii-(sv==a?0:m[sv])<<endl;
            break;
        }else{
            m[sv]=ii;
            //cout<<" "<<ii<<" "<<sv1<<" "<<sv2<<" "<<sv<<endl;
            pre=sv;
        }

    }
    }



    


    return 0;
}



Measured memory_bytes: 3344
#include <algorithm>
#include <tuple>
#include <utility>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  vector<int> C(N);
  for(int i = 0; i < N; ++i)
    cin >> C[i], --C[i];
  const int b = 2048;
  vector<vector<tuple<int,int,int>>> query(b);
  for(int i = 0; i < Q; ++i){
    int l, r;
    cin >> l >> r;
    --l;
    query[l/b].emplace_back(r,l,i);
  }
  for(auto& q : query)
    sort(q.begin(), q.end());
  vector<int> ans(Q);
  for(const auto& q : query){
    if(q.empty()) continue;
    vector<int> cnt(N);
    int m = 0;
    int ll = get<1>(q[0]), rr = ll;
    for(auto [r, l, i] : q){
      while(rr < r){
        ++cnt[C[rr]];
        if(cnt[C[rr]] == 1)
          ++m;
        ++rr;
      }
      while(ll < l){
        --cnt[C[ll]];
        if(!cnt[C[ll]])
          --m;
        ++ll;
      }
      while(ll > l){
        --ll;
        ++cnt[C[ll]];
        if(cnt[C[ll]] == 1)
          ++m;
      }
      ans[i] = m;
    }
  }
  for(auto e : ans)
    cout << e << '\n';
}


Measured memory_bytes: 17236
s = input()
s = s.replace('BC', 'X')
s = s[::-1]

ans = 0
cnt_x = 0
# count the num of X
for i, c in enumerate(s):
    if c == 'X':
        cnt_x += 1
    
    elif c == 'A':
        ans += cnt_x

    elif c in {'B', 'C'}:
        cnt_x = 0

print(ans)


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

int main(){
  int minv = 10;
  int sum = 0;
  int a;
  for (int i=0; i<5; i++){
	cin >> a;
	sum += (a / 10 + 1) * 10;
	if (a % 10 == 0)
	  sum -= 10;
	else if (a % 10 < minv)
	  minv = a % 10;
  }
  cout << sum - 10 + minv << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a,vector<vector<ll>> b,int n){
	int i,j,k,t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k]*b[k][j] % M)%M;
			c[i].push_back(t);
		}
	}
	return c;
}
int main() {
	int a, b;
	cin >> a >> b;
	cout << (a - 1)*(b - 1) << endl;
}

Measured memory_bytes: 4992
import math
N = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]

p_unused = list(range(1,N+1))
q_unused = list(range(1,N+1))

di_p = 0
di_q = 0
for i in range(N):
    p_num = p_unused.index(P[i])
    p_unused.remove(P[i])
    di_p += p_num * math.factorial(N-i-1)

    q_num = q_unused.index(Q[i])
    q_unused.remove(Q[i])
    di_q += q_num * math.factorial(N-i-1)

print(abs(di_p-di_q))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main(){
    double a , b;
    double x;
    
    cin >> x;
    double pi = 3.1415926535897932384626643383279;
    a = pi * x * x;
    b = 2 * pi * x;
    cout << fixed << setprecision(6) << a << " " << fixed << setprecision(6) << b << endl;
}


Measured memory_bytes: 3272
import sys,bisect,heapq
def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(input())

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a*b*GCD(a,b)

def main():
    s = S()
    l = 0
    r = len(s)-1
    ans = 0

    while l < r:
        if s[l] == s[r]:
            l += 1
            r -= 1
        elif s[l] == "x":
            ans += 1
            l += 1
        elif s[r] == "x":
            ans += 1
            r -= 1
        else:
            ans = -1
            break
    return(ans)


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 39664
n, y = gets.chomp.split.map(&:to_i)

([y / 10000, n].min).step(0, -1) do |i|
  ([(y - 10000 * i) / 5000, n - i].min).step(0, -1) do |j|
    rest = y - 10000 * i - 5000 * j
    break if rest % 1000 != 0
    if rest / 1000 == n - i - j
      puts "#{i} #{j} #{rest / 1000}"
      exit
    end
  end
end
puts "-1 -1 -1"

Measured memory_bytes: 1788
/*
[abc131] E - Friendships
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int N, K;

void add_edge(int u, int v) { cout << u + 1 << " " << v + 1 << endl; }

void solve() {
    int m = (N - 1) * (N - 2) / 2 - K;
    if (m < 0) {
        cout << -1 << endl;
        return;
    }

    int M = N - 1 + m;
    cout << M << endl;

    for (int i = 1; i < N; i++) {
        add_edge(0, i);
    }

    int cnt = 0;
    for (int i = 1; i < N; i++) {
        for (int j = i + 1; j < N && cnt < m; j++, cnt++) {
            add_edge(i, j);
        }
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a>b)
		printf("a > b\n");
	if(a==b)
		printf("a == b\n");
	if(a<b)
		printf("a < b\n");
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int x=0; char ch=getchar();
    while(ch < '0' || ch > '9')   ch = getchar();
    while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48) , ch = getchar();
    return x;
}
const int N = 1e6 + 5,P = 998244353;
int n,m,now,a[N],b[N],c[N],vi[N];
long long f(int T)
{
    int k = m / T,sum = 0,ans = 0;
    for(int i = 1;i <= k;i ++)   sum = (sum + 1LL * i * a[i * T]) % P;
    for(int i = 1;i <= k;i ++)
	{
        sum = (sum - 1LL * i * a[i * T] % P + P) % P;
        ans = (ans + 1LL * sum * i % P * a[i * T] % P) % P;
    }
    return ans;
}
int main()
{
    n = read(); b[1] = 1;
    for(int i = 1,x;i <= n;i ++) ++a[x = read()],m = max(m,x);
    for(int i = 2;i <= m;i ++)
	{
        if(!vi[i])  c[++ now] = i,b[i] = -1;
        for(int j = 1;j <= now && c[j] * i <= m;j ++)
		{
            vi[c[j] * i] = 1;
            if(i % c[j] == 0)   break;
            else    b[i * c[j]] = -b[i];
        }
    }
    for(int i = 1;i <= m;i++)   c[i] = (P + b[i] * i) % P;
    for(int i = m;i;i --) for(int j = i * 2;j <= m;j += i)    c[j] = (c[j] + c[i]) % P;
    long long ans = 0;
    for(int i = 1;i <= m;i ++)   ans =( ans + 1LL * a[i] * (a[i] - 1) / 2 % P * i) % P;
    for(int i = 1;i <= m;i ++)   ans = (ans + i * f(i) % P * c[i]) % P;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 15872
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for i in range(m)]

hlst=[[0,i] for i in range(h)]    
wlst=[[0,i] for i in range(w)]
dic={}
for i in range(m):
    hh,ww=hw[i]
    hlst[hh-1][0]-=1
    wlst[ww-1][0]-=1
    dic[(hh-1,ww-1)]=1

hlst.sort()
wlst.sort()
hkouho=[]
wkouho=[]
mi=0
for i in range(h):
    if mi<hlst[i][0]:
        break
    hkouho.append(hlst[i][1])
    mi=hlst[i][0]
mi=0
for i in range(w):
    if mi<wlst[i][0]:
        break
    wkouho.append(wlst[i][1])
    mi=wlst[i][0]
# print(hkouho)
# print(wkouho)
# print(hlst)
for i in range(len(hkouho)):
    for j in range(len(wkouho)):
        if not (hkouho[i],wkouho[j]) in dic:
            print(-hlst[0][0]-wlst[0][0])
            exit()
print(-hlst[0][0]-wlst[0][0]-1)
# print(hkouho[0],wkouho[0])

Measured memory_bytes: 217212
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
#define MAX 200000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)

int main(){
    int n,W;
    cin>>n>>W;
    vector<int> w(n);
    vector<int> v(n);
    rep(i,n) cin>>w[i]>>v[i];
    vector<vector<int>>dp(n,vector<int> (MAX,INF));
    //dp[i][j]　iまでの品物で価値がj以上組み合わせで重さが最小のもの
    rep(i,v[0]+1) dp[0][i]=w[0];
    rep(i,n-1){
        rep(j,MAX){
            if(j>v[i+1]) dp[i+1][j]=min(dp[i][j],dp[i][j-v[i+1]]+w[i+1]);
            else dp[i+1][j]=min(dp[i][j],w[i+1]);
        }
       
    }
    rep(i,MAX) if(dp[n-1][i]>W){ cout<<i-1<<endl;break;}
    
    return 0;
}

Measured memory_bytes: 79488
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = []
for i in range(n):
    A.append(ii())

amax = max(A)
anmax = sorted(A)[-2]
cntmax = A.count(amax)

if cntmax > 1:
    for j in A:
        print(amax)
else:
    for k in A:
        if k == amax:
            print(anmax)
        else:
            print(amax)

Measured memory_bytes: 13416
#include<iostream>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>

using namespace std;

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

    vector<int> grid(n+1);
    vector<int> block(m);

    for(int i = 0; i < m; i++){
        cin >> block.at(i);
    }

    for(int i = 0; i < m; i++){
        for(int j = 0; j < n+1; j++){
            if(block.at(i) == j){
                grid.at(j) = 1;

            }
        }
    }

    int countLeft = 0;
    int countRight = 0;

    for(int i = 0; i <= x-1; i++){
        if(grid.at(i) == 1){
            countLeft++;
        }
    }
    for(int i = x+1; i <= n; i++){
        if(grid.at(i) == 1){
            countRight++;
        }
    }

    int ans = min(countLeft, countRight);
    cout << ans << endl;

}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
INF = 1 << 60


def main():
    N, W, *WV = map(int, read().split())
    weight = WV[::2]
    value = WV[1::2]

    V = sum(value)
    dp = [[INF] * (V + 1) for _ in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        for v in range(V + 1):
            if v - value[i] >= 0:
                dp[i + 1][v] = dp[i][v - value[i]] + weight[i]
            else:
                dp[i + 1][v] = weight[i]
            if dp[i + 1][v] > dp[i][v]:
                dp[i + 1][v] = dp[i][v]

    ans = 0
    for v in range(V + 1):
        if dp[N][v] <= W:
            ans = v
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 119280
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;

public class Main {
	//2-100
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		if (n<30) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
		
		
		
	}
	

}

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

int main() {
	
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k <= a)
    {
        cout << k;
    }
    else
    {
        if(a+b >= k)
        {
            cout << a;
        }
        else
        {
            ll sum = 0;
            sum = (-1)*(k-(a+b));
            k =k - (k-(a+b));
            k -= (k-a);
            sum += k;
            cout << sum;
        }
    }
    
	return 0; 
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
int main(){
  string S;
  cin >> S;
  if(S=="SUN") cout << 7 ;
  if(S=="MON") cout << 6 ;
  if(S=="TUE") cout << 5 ;
  if(S=="WED") cout << 4 ;
  if(S=="THU") cout << 3 ;
  if(S=="FRI") cout << 2 ;
  if(S=="SAT") cout << 1 ;
}


Measured memory_bytes: 256