akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdint>
using namespace std;

const int MOD = 1000000007;
int main() {
	int N, a;
	int64_t m;
	bool row;
	string S1, S2;
	cin >> N >> S1 >> S2;
	if (S1[0] == S2[0]) {
		m = 3;
		a = 1;
		row = false;
	} else {
		m = 6;
		a = 2;
		row = true;
	}
	for (int i = a;i < N;i ++) {
		if (S1[i] == S2[i]) {
			if (row) {
				m *= 1;
			} else {
				m *= 2;
			}
			row = false;
		} else {
			i ++;
			if (row) {
				m *= 3;
			} else {
				m *= 2;
			}
			row = true;
		}
		m %= MOD;
	}
	cout << m;
	return 0;
}

/*
ある列が縦に塗られている時
⇒その横の列が横向きなら、x1通り
⇒その横の列が縦向きなら、x2通り
ある列が横に塗られている時
⇒その横の列が横向きなら、x3通り
⇒その横の列が縦向きなら、x2通り[
最初の列の時
⇒横向きならx6通り
⇒縦向きならx3通り
これを左から確認、しかも全て掛け算だから適宜modでおｋ
*/

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

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int sy[4] = { 0,1,0,-1 };

#define atcoder (int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

ll dp[100010] = { 0 };

int main(){
	
	int n;
	cin >> n;
	int cnt = 1;
	int a[110];
	int b;

	rep(i, n)cin >> a[i];
	sort(a, a + n);
	b = a[0];
	rep(i, n) {
		if (b < a[i]) {
			b = a[i];
			cnt++;
		}
	}
	pr(cnt);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize ("02")
#define ll long long
#define oo 1000000007
using namespace std;

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

	ll x, y, a, b, c, ans = 0, k;
	cin >> x >> y >> a >> b >> c;
	vector<ll> r, g, q, an;

	for(int i=0; i<a; i++){cin >> k; r.push_back(k);}
	sort(r.begin(), r.end());

	for(int i=0; i<b; i++){cin >> k; g.push_back(k);}
	sort(g.begin(), g.end());

	for(int i=0; i<c; i++){cin >> k; q.push_back(k);}
	sort(q.begin(), q.end());

	int xy = x + y, xy2 = x + y;
	while(x--){
		an.push_back(r.back());
		//cout << r.back() << " ";
		r.pop_back();
	}
	while(y--){
		an.push_back(g.back());
		//cout << g.back() << " ";
		g.pop_back();
	}
	while(xy-- && c--){
		an.push_back(q.back());
		//cout << q.back() << " ";
		q.pop_back();
	}
	sort(an.begin(), an.end());

	while(xy2--){
		ans += an.back();
		an.pop_back();
	}

	cout << ans;

    return 0;
}


Measured memory_bytes: 8432
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 998244353;
int n, k, a[200002], f[200002];

int check(int x){
	int ans=0;
	for(int i=1; i<=n; i++) ans+=max(0LL, a[i]-x/f[i]);
	return ans;
}

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>n>>k;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=n; i++) cin>>f[i];
	sort(a+1, a+n+1);
	sort(f+1, f+n+1, greater<int>());
	if(check(0)<=k) return cout<<0, 0;
	int l=0, r=0;
	for(int i=1; i<=n; i++) r=max(r, f[i]*a[i]);
	while(r-l>1){
		int mid=(l+r)/2;
		if(check(mid)<=k) r=mid;
		else l=mid;
	}
	//cout<<check(1)<<endl;
	cout<<r;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}



vector<int> yakusuu(int n){
    vector<int> ret ;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            ret.push_back(i) ;
            if(i*i!=n){
                ret.push_back(n/i) ;
            }
        }
    }
    sort(ALL(ret)) ;
    return ret ;
}

bool isgood(int n,vint vec){
  int m = SZ(vec) ;
  REP(i,m){
    if(vec[i]%n!=0){
      return false ;
    }
  }
  return true ;
}

//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x ;
  cin >> n >> x ;
  vint num ;
  num.PB(x) ;
  REP(i,n){
    int a ;
    cin >> a ;
    num.PB(a) ;
  }
  n++ ;
  sort(ALL(num)) ;
  
  int mini = INF ;
  
  vint dis ;
  
  REP(i,n-1){
    mini = min(mini,num[i+1]-num[i]) ;
    dis.PB(num[i+1]-num[i]) ;
  }
  
  vint ret = yakusuu(mini) ;
  
  for(int i=SZ(ret)-1;i>=0;i--){
    if(isgood(ret[i],dis)){
      cout << ret[i] <<endl ;
      return 0 ;
    }
  }
  
    
  
  
  
  return 0 ;
}

Measured memory_bytes: 1528
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>

#define mod 1000000007

using namespace std;
using ll = long long;

void solve() {
    int sum = 0;
    int n;
    cin >> n;
    int l[n], r[n];
    for(int i = 0; i < n; i++){
        cin >> l[i] >> r[i];
        sum += r[i] - l[i] + 1;
    }
    cout << sum << endl;
}

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

Measured memory_bytes: 384
#include<iostream>
#include<string>

using namespace std;

int main(void){
  string s;  

  while(1){
    getline(cin,s);
    if(s=="END OF INPUT")break;

    int len=s.size();
    for(int i=0,count=0;i<=len;i++){
      if(s[i]==' '||i==len){
	cout << count;
	count=0;
      }
      else count++;
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();

		System.out.println(k % 2 == 0 ? (int)Math.pow(k/2, 2) : k/2 * (k/2 +1));
	}
}

Measured memory_bytes: 35512
#include <bits/stdc++.h>
#define maxn 21
#define maxbm (1<<maxn)
#define mod 1000000007
using namespace std;

int n;
bool ar[maxn][maxn];
int dp[maxn][maxbm];

int f(int curr, int bmask) {
	if(curr == n)
		return 1;
	if(dp[curr][bmask] != -1)
		return dp[curr][bmask];
	dp[curr][bmask] = 0;
	for( int i = 0 ; i < n ; i++ )
		if( ar[curr][i] && (bmask & (1<<i)) == 0 )
			dp[curr][bmask] = ( dp[curr][bmask] + f( curr+1 , (bmask | (1<<i)) ) ) % mod;
	return dp[curr][bmask];
}

int main() {
	scanf("%d",&n);
	for( int i = 0 ; i < n ; i++ )
		for( int j = 0 ; j < n ; j++ )
			cin >> ar[i][j];
	memset(dp, -1, sizeof(dp));
	printf("%d\n",f(0,0));
	return 0;
}


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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

bool prime[100000];

void Prime_Number() {
	memset(prime, true, sizeof(prime));
	prime[0] = false;
	FOR(i, 1, sqrt(100000)) {
		if(prime[i]) {
			for(int j = (i + 1); (i + 1) * j <= 100000; ++j) {
				prime[(i + 1) * j - 1] = false;
			} 
		}
	}
}

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

    int N;
    cin >> N;
    Prime_Number();

    cout << 2 << " ";
    int cnt = 1;
    rep(i, 55555) {
        if(prime[i] && (i + 1) % 10 == 1) {
            cout << i + 1;
            ++cnt;
            if(cnt == N) break;
            else cout << " ";
        }
    }
    cout << endl;
    return 0;
}

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

int main(void){
  vector<int> x(5);
  for(int i = 0;i  <5; i++){
    cin >> x[i];
  }
  cout<<(find(x.begin(), x.end(), 0) - x.begin()) + 1 << endl;
  return 0;
}

Measured memory_bytes: 3556
n,m=map(int,input().split())
broken=[int(input()) for i in range(m)]
mod=10**9+7

is_broken=[True]*(n+1)
for i in range(m):
  is_broken[broken[i]]=False
   
dp=[0]*(n+1)
dp[0]=1
if is_broken[1]:
  dp[1]=dp[0]
  
for i in range(2,n+1):
    if is_broken[i]:
       dp[i]=dp[i-1]+dp[i-2]
       dp[i]%=mod
    else:
      dp[i]=0
      
print(dp[n])   


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

#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define vint vector<int>
#define vchar vector<char>
#define vstr vector<string>
#define pb(n) push_back(n)

signed main(){
  int A,B,N,M,count=0,count2=0,count3=0;
  str S,T;
  int C='A'-'a';
  cin>>N;
  vstr W(N);
  rep(0,N)cin>>W.at(i);
  rep(0,N-1){
    if(W.at(i).at(W.at(i).size()-1)==W.at(i+1).at(0)){
      count+=1;
    }
    REP(0,N){
      if(W.at(i)==W.at(j))count2+=1;
    }
  }
  if(count==N-1&&count2==N-1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   int ans[13] = {1,1,3,1,2,1,2,1,1,2,1,2,1};
   int x,y;
   cin >> x >> y;
   if(ans[x]==ans[y])
   {
      cout<<"Yes"<<endl;
   }
   else
   {
      cout<<"No"<<endl;
   }
   
   
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair <int,int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int s =0;
  rep(i,n) s += a[i];
  int cnt = 0;
  rep(i, n){
    if(a[i]*(4*m) >= s) cnt++;
  }
  if(cnt >= m){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<usize>();
    let (v0, v1) = {
        let mut v0 = vec![0; n / 2];
        let mut v1 = vec![0; n / 2];
        for i in 0..n {
            if i % 2 == 0 {
                v0[i / 2] = input::<i64>();
            } else {
                v1[i / 2] = input::<i64>();
            }
        }
        v0.sort();
        v1.sort();
        (v0, v1)
    };

    let mut u0 = vec![];
    let mut u1 = vec![];
    let mut c0 = 1;
    let mut c1 = 1;
    for i in 1..n / 2 {
        if v0[i] == v0[i - 1] {
            c0 += 1;
        } else {
            u0.push((c0, v0[i - 1]));
            c0 = 1;
        }
        if v1[i] == v1[i - 1] {
            c1 += 1;
        } else {
            u1.push((c1, v1[i - 1]));
            c1 = 1;
        }
    }
    if c0 > 0 {
        u0.push((c0, v0[n / 2 - 1]));
    }
    if c1 > 0 {
        u1.push((c1, v1[n / 2 - 1]));
    }
    u0.sort();
    u0.reverse();
    u1.sort();
    u1.reverse();

    let ans = if u0[0].1 == u1[0].1 {
        if u0.len() == 1 && u1.len() == 1 {
            n / 2
        } else if u0.len() == 1 {
            n - u0[0].0 - u1[1].0
        } else if u1.len() == 1 {
            n - u0[1].0 - u1[0].0
        } else {
            std::cmp::min(n - u0[1].0 - u1[0].0, n - u0[0].0 - u1[1].0)
        }
    } else {
        n - u0[0].0 - u1[0].0
    };
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = (1<<31), OO = 0x3f3f3f3f;
char str[4],s[4];
int main()
{
  int cnt=0;
  scanf("%s%s",str,s);
  for(int i=0;i<3;++i) cnt+= (str[i]==s[i]);
  printf("%d\n",cnt);
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

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

using namespace std;

int N, M;
vector<int> A, B;

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

	auto next = vector<vector<int>>(N + 1);
	auto cost = vector<int>(N+1,N+1);
	auto ans = vector<int>(N + 1, 0);
	cost[1] = 0;

	for (int i = 0; i < M; i++) {
		int a, b;

		cin >> a;
		cin >> b;

		next[a].push_back(b);
		next[b].push_back(a);
	}


	auto c = [&cost](int l, int r)
	{ 
		return cost[l] > cost[r];
		
	};
	priority_queue<int, vector<int>, decltype(c)> q(c);

	q.push(1);
	cost[1] = 1;

	while (!q.empty()) {
		int n = q.top();
		q.pop();


		vector<int>na = next[n];
		for (int i = 0; i < na.size(); i++) {
			int nn = na[i];

			if (ans[nn] != 0) {
				continue;
			}

			cost[nn] = cost[n] + 1;
			ans[nn] = n;
			q.push(nn);
		}
	}


	cout << "Yes" << endl;
	for (int i = 2; i <= N; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}



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

int main(){
    int n;cin>>n;int L[n];for(int i=0;i<n;i++)cin>>L[i];
    for(int i=0;i<n;i++){if(i==n-1)cout<<L[i]<<endl;else{cout<<L[i]<<' ';}}
    for(int i=1;i<n;i++){
        int v=L[i];int j=i-1;
        while(j>=0 && L[j]>v){
            L[j+1]=L[j];
            j--;
        }
        L[j+1]=v;
        for(int i=0;i<n;i++){
        if(i==n-1)cout<<L[i]<<endl;
        else{cout<<L[i]<<' ';}
    }
    }
    return 0;
}


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

int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    ll ans = 0;
    if (B <= C) {
        ans += 2*B;
        C -= B;
        ans += min(A+1, C);
    }else {
        ans = B+C;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
import itertools
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
rt=[]
for i in range(n):
    for j in range(i+1,n):
        x1=xy[i][0]
        y1=xy[i][1]
        x2=xy[j][0]
        y2=xy[j][1]
        rt.append([(i,j),math.sqrt((x1-x2)**2+(y1-y2)**2)])
l=[i for i in range(n)]
sm=0
cnt=0
for v in list(itertools.permutations(l,n)):
    for i in range(n-1):
        f,t=v[i],v[i+1]
        if f>t:
            f,t=t,f
        for r in rt:
            if r[0]==(f,t):
                sm+=r[1]
    cnt+=1
print(sm/cnt)

Measured memory_bytes: 8052
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	int N, M;
    cin >> N >> M;
    VI A;
    int sum=0;
    rep(i,N){
        int a;
        cin >> a;
        A.PB(a);
        sum += a;

    }

    sort(rall(A));

    string ans ="Yes";
    if(4*M*A[M-1] < sum) ans = "No";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int X, i, total = 0;
	
	scanf("%d", &X);
	
	for (i = 0; i <= X; ++i) {
		total += i;
		if (total >= X) {
			break;
		}
	}
	
	printf("%d", i);
	return 0;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
    int k; cin>>k;
    ll a=7%k;
    rep(i,k+1){
        if(a==0){
            cout<<i+1<<endl;
            return 0;
        }
        a=(a*10+7)%k;
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db long double
#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline int rd()
{
	int x=0;char c=gc();while(!isdigit(c))c=gc();
	while(isdigit(c))x=x*10+c-48,c=gc();return x;
}
const int N=200005,M=20,P=1e9+7;
int n,o[N],st1[N][18],st2[N][18],s[N*4],tg[N*4];
struct st{int x,v;}a[N];
inline bool operator<(const st&a,const st&b){return a.x<b.x;}
struct qr{int l,r;}b[N];
inline bool operator<(const qr&a,const qr&b){return a.r!=b.r?a.r<b.r:a.l>b.l;}
inline int gtl(int v){int x=1;per(i,17,0)if(x+(1<<i)-1<=n&&st1[x][i]<v)x+=1<<i;return x;}
inline int gtr(int v){int x=n;per(i,17,0)if(x-(1<<i)+1>=1&&st2[x][i]>v)x-=1<<i;return x;}
inline void up(int x){s[x]=(s[x<<1]+s[x<<1|1])%P;}
inline void cov(int x){s[x]=0;tg[x]=1;}
inline void dn(int x){if(!tg[x])return;cov(x<<1);cov(x<<1|1);tg[x]=0;}
void upd1(int x,int l,int r,int p,int v)
{
	if(l==r){s[x]=v;return;}int m=l+r>>1;dn(x);
	p<=m?upd1(ls,p,v):upd1(rs,p,v);up(x);
}
void upd2(int x,int l,int r,int tl,int tr)
{
	if(tl<=l&&r<=tr){cov(x);return;}int m=l+r>>1;dn(x);
	if(tl<=m)upd2(ls,tl,tr);if(tr>m)upd2(rs,tl,tr);up(x); 
}
int main()
{
	n=rd();
	rep(i,1,n){a[i].x=rd();o[i]=a[i].v=rd();}
	sort(a+1,a+n+1);sort(o+1,o+n+1);
	rep(i,1,n){a[i].x=i;a[i].v=lower_bound(o+1,o+n+1,a[i].v)-o;}
	rep(i,1,n)st1[i][0]=a[i].v;
	rep(j,1,17)rep(i,1,n-(1<<j)+1)st1[i][j]=max(st1[i][j-1],st1[i+(1<<j-1)][j-1]);
	rep(i,1,n)st2[i][0]=a[i].v;
	rep(j,1,17)rep(i,(1<<j),n)st2[i][j]=min(st2[i][j-1],st2[i-(1<<j-1)][j-1]);
	rep(i,1,n)b[i]=(qr){gtl(a[i].v),gtr(a[i].v)};	
	sort(b+1,b+n+1);rep(i,1,n)o[i]=0;
	rep(i,1,n)o[b[i].r]=max(o[b[i].r],b[i].l);
	rep(i,2,n)o[i]=max(o[i],o[i-1]);
	upd1(1,0,n,0,1);
    rep(i,1,n)
    {
    	upd1(1,0,n,i,s[1]);
    	if(o[i])upd2(1,0,n,0,o[i]-1);
	}
    printf("%d\n",s[1]);
    return 0;
}


Measured memory_bytes: 38528
#include<iostream>
#include<complex>
#include<array>
#include<vector>
#include<cstdio>
using namespace std;

const double EPS = 1e-10;
template<class T>
bool eq(const T& a, const T& b) {return abs(a - b) < EPS;}

typedef  complex<double> point;
// sort/unique用、setではうまく動かないので使うべからず
namespace std {
	bool operator==(const point &a, const point &b){
		return eq(a, b);
	}
	bool operator<(const point& a, const point& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const point& a, const point& b) {
	return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
	return real(conj(a)*b);
}
int ccw(point a, point b, point c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;  // counter clockwise
	if (cross(b, c) < 0)   return -1;  // clockwise
	if (dot(b, c) < 0)     return +2;  // c--a--b on line
	if (norm(b) < norm(c)) return -2;  // a--b--c on line
	return 0;  // a--c--b on line or a----bc
}

struct circle {point p; double r;};
typedef vector<point> polygon;
typedef array<point, 2> line;

point projection(const line& l, const point& p) {
	double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}

point reflection(const line& l, const point& p) {
	return p + 2. * (projection(l, p) - p);
}

int main()
{
  double x0,y0,x1,y1;
  for(;cin>>x0>>y0>>x1>>y1;)
    {
      int n;
      cin>>n;
      for(int i=0;i<n;i++)
	{
	  line l;
	  l[0]=point(x0,y0);
	  l[1]=point(x1,y1);
	  double x,y;
	  cin>>x>>y;
	  point p=point(x,y);
	  point ans=reflection(l,p);
	  printf("%.10lf %.10lf\n",ans.real(),ans.imag());
	  //	  cout<<ans.real()<<" "<<ans.imag()<<endl;
	}
    }
}

Measured memory_bytes: 1256
n=int(input())
s=input()
data=[0]*n
for i in range(n):
    if s[i]=="(":
        data[i]=1
    else:
        data[i]=-1
for i in range(1,n):
    data[i]+=data[i-1]
k=data[-1]
l=min(data)
if l<0:
    l*=-1
    k+=l
    if k>=0:
        print("("*l+s+")"*k)
    else:
        print("("*(l-k)+s)
else:
    if k>=0:
        print(s+")"*k)
    else:
        print("("*(-k)+s)

Measured memory_bytes: 3064
#include<stdio.h>
int main (){


  int H,W,i,j;

  while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0)
      break;
  
  


  for(i=0;i<H;i++){
    for(j=0;j<W;j++){

      if((i+j)%2==0 )
   {

    printf("#");
   }

    else printf(".");
  }
    printf("\n");
  }
  printf("\n");
  }
 return 0;
  }

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

#include <boost/multiprecision/cpp_int.hpp>
using lll = boost::multiprecision::int128_t;

ll d[5000], dsum[5001];
int main() {
  ll k, querylen;
  cin >> k >> querylen;
  repi(k) cin >> d[i];
  repi(querylen) {
    ll n, x, m;
    cin >> n >> x >> m;
    --n;
    x %= m;
    dsum[0] = 0;
    ll plusforoneloop = 0;
    repj(k) {
      if (d[j] % m) ++plusforoneloop;
      dsum[j + 1] = dsum[j] + d[j] % m;
    }
    lll loopnum = n / k, rest = n % k, xb = loopnum * dsum[k] + x;
    lll res = loopnum * plusforoneloop - xb / m;
    xb %= m;
    // cout << "xb:" << xb << " rest:" << rest << endl;
    repj(rest) {
      lll newxb = (xb + d[j]) % m;
      if (newxb > xb) ++res;
      xb = newxb;
    }
    cout << res << endl;
  }
}


Measured memory_bytes: 3692
#include <iostream>
#include <stdio.h>
//#include <string.h>

using namespace std;

struct Matrix{
    int row;
    int col;
    int total;
};

Matrix mts[100][100];
int n;

int main()
{
    scanf("%d",&n);
    for(int i=0; i<n; ++i){
        int r,c;
        scanf("%d %d", &r, &c);
        mts[0][i].row = r;
        mts[0][i].col = c;
        mts[0][i].total = 0;
    }

    for(int i=1; i<n; ++i){
        for(int j=0; j<n-i; ++j){
            int min = 0xfffffff;
            mts[i][j].row = mts[i-1][j].row;
            mts[i][j].col = mts[0][i+j].col;
            for(int k=0; k<i; ++k){
                int tmp = mts[k][j].total + mts[i-k-1][k+j+1].total + mts[k][j].row * mts[i-k-1][k+j+1].row * mts[i-k-1][k+j+1].col;
                min = min < tmp ? min : tmp;
            }
            mts[i][j].total = min;
        }
    }

    cout << mts[n-1][0].total << endl;

    return 0;
}


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

int main()
{
  char s[110],t[110];
  scanf("%s",s);
  scanf("%s",t);
  int mi=10000000,mx=-1;
  for(int i=0; s[i]; i++)
  {
    mi=min(mi,(int)s[i]);
  }
  for(int i=0; t[i]; i++)
  {
    mx=max(mx,(int)t[i]);
  }
  if(mi<mx)
  {
    cout<<"Yes";
  }
  else if(mi==mx)
  {
    int i=0;
    for(; s[i] && t[i] && s[i]==t[i]; i++);
    if(s[i] || t[i]=='\0')
    {
      cout<<"No";
    }
    else
    {
      cout<<"Yes";
    }
  }
  else
  {
    cout<<"No";
  }
  return 0;
}

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

int main(){
  int ans = 0;
  /*入力*/
  int n,d,x;
  cin >> n >> d >> x;
  int a[n];
  for(int i = 0;i < n;i++){
    cin >> a[i];
    ans += (d - 1)/a[i] + 1;
  }
  /**/
  cout << ans + x << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    vector<string> S(N);
    REP(i,N)cin >> S[i];
    sort(all(S));
    string before = S[0];
    int maxa = 0;
    int count = 1;
    REP(i,N-1){
        if(S[i+1] != before){
            maxa = max(maxa,count);
            before = S[i+1];
            count = 0;
        }
        count++;
    }
    maxa = max(maxa,count);
    before = S[0];
    count = 1;
    vector<string> Sa(0);
    REP(i,N-1){
        if(S[i+1] != before){
            if(count == maxa){
                Sa.push_back(S[i]);
            }
            before = S[i+1];
            count = 0;
        }
        count++;
    }
    if(count == maxa){
        Sa.push_back(S[N-1]);
    }
    sort(all(Sa));
    REP(i,Sa.size())cout <<Sa[i]<< "\n";
}

Measured memory_bytes: 14576
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long long N, M;
    cin >> N >> M;
    pair<long long, long long> store[100010];
    int a[100010], b[100010];
    for(long long i = 1;i <= N;i++){
        cin >> a[i] >> b[i];
        store[i] = make_pair(a[i], b[i]);
    }
    sort(store+1, store+N+1);
    
    long long ans = 0;
    for(long long i = 1;i <= N;i++){
        if(M - store[i].second > 0){
            ans += store[i].first * store[i].second;
            M -= store[i].second;
        }
        else {
            ans += store[i].first * M;
            break;
        }
    }
    cout << ans;
}


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

long long dp[51][51][2600];

int main() {
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i);
    }
    
    for (int i = 0; i <= n; i++) dp[i][0][0] = 1;
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n * a; k++) {
                dp[i][j][k] += dp[i - 1][j][k];
                if (0 <= k - x.at(i - 1) && k - x.at(i - 1) <= n * a) dp[i][j][k] += dp[i - 1][j - 1][k - x.at(i - 1)];
            }
        }
    }
    
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += dp[n][i][a * i];
    }
    cout << ans << endl;
}   

Measured memory_bytes: 52096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int a,b;
  char c;
  cin >> a >> c >> b;
  if(c == '+') cout << a+b << endl;
  if(c == '-') cout << a-b << endl; 
}

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

int main()
{
   int N,temp;
   char S[10005];
   scanf("%d",&N);
   scanf("%s",S);
   int lens=strlen(S);
   int i;
   for(i=0;i<lens;i++)
   {
       temp=S[i]+N;
       if(temp-(int)'A'>=26)
       {
           temp='A'+(temp-(int)'A')%26;
       }
       printf("%c",temp);
   }
    return 0;
}


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

int main()
{
    int len;
    cin>>len;
    int arr[len],cnt=0,idx=1,i;
    for(i=0;i<len;i++)
        cin>>arr[i];
    for(i=0;i<len;i++)
    {
        if(arr[i]==idx)
            idx++;
        else
        {
            cnt++;
        }
    }
    if(cnt==len)
        cout<<"-1";
    else
        cout<<cnt;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define md(a, b)		((a) % b + b) % b
#define mod(a)			md(a, MOD)
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define forn(i, n)			for(int i = 0; i < n; i++)
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
//int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef long double ld;	
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1); 
int ar[200020];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("qwe.txt", "w", stdout)
	ll mon = 1000;
	ll can = 0;
	int n;
	cin>>n;
	fore(i, 0, n)
	{
		cin>>ar[i];
		if(i > 0)
		{
			if(can == 0)
			{
				if(ar[i] > ar[i-1])
				{
					can = mon / ar[i-1];
					mon %= ar[i-1];
				}
			}
			else
			{
				if(ar[i] < ar[i-1])
				{
					mon += can * ar[i - 1];
					can = 0;
				}
			}
		}
		//cout<<i<<' '<<mon<<' '<<can<<'\n';
	}
	mon += can * ar[n - 1];
	cout<<mon<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2	

Measured memory_bytes: 3660
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通り実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), a = scanner.nextInt();
			int[] y = new int[n];
			int maxX = IntStream.range(0, n).map(i -> {
				int x = scanner.nextInt();
				y[i] = x - a;
				return x;
			}).max().getAsInt();
			// 回答の格納する配列
			long[][] dp = new long[n + 1][2 * n * maxX + 1];
			Arrays.fill(dp[0], 0L);
			dp[0][n * maxX] = 1L;
			IntStream.rangeClosed(1, n).forEach(j -> IntStream.range(0, 2 * n * maxX + 1).forEach(t -> {
				if (((t - y[j - 1]) >= 0) && ((t - y[j - 1]) <= 2 * n * maxX)) {
					dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y[j - 1]];
				} else {
					dp[j][t] = dp[j - 1][t];
				}
			}));
			System.out.println(dp[n][n * maxX] - 1);
		}
	}
}


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

using namespace __gnu_pbds;
using namespace std;

template <class T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

#define int long long

int32_t main()
{
    usaco();
    int x;
    cin >> x;
    cout << (x ^ 1);
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define read(x) scanf("%d",&x)
typedef long long ll;
typedef double dl;
using namespace std;

const int N=2e5+7;
const int M=1e9+7;
const int INF=0x3f3f3f3f;

int n,m;

map<int,int> cnt;
int a[N];

void solve(){
	cin>>n;
	fo(i,1,n) cin>>a[i];
	ll ans=0;
	fo(j,1,n){
		ans+=cnt[j-a[j]];
		cnt[a[j]+j]++;
	}
	cout<<ans;
}

int main(){
//	ios::sync_with_stdio(0);
//  cin.tie(0),cout.tie(0);
//	int T;read(T);
//	for(int i=1;i<=T;i++)
		solve();
}


Measured memory_bytes: 21368
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


int main(void){
    ll n; cin >> n;
    vector <ll> as;
    vector <ll> bs;
    ll a;
    ll b;
    vector <vector <pair <ll, ll>>> graph(n, vector<pair <ll, ll>>());
    vector <ll> color(n-1, 0);
    vector <ll> ans;
    REP(i, n-1){
        cin >> a; cin >> b;
        graph[b-1].push_back({a-1, i});
        graph[a-1].push_back({b-1, i});
    }
    ll hasi = -1;
    REP(i, n){
        if (graph[i].size() == 1){
            hasi = i;
            break;
        }
    }
    ll now = hasi;
    queue <ll> q;
    q.push(now);
    while (!q.empty()){
        now = q.front();
        q.pop();
        ll len =  graph[now].size();
        ll prev_color = -1;
        for (auto p: graph[now]){
            ll edge = p.second;
            if (color[edge] > 0){
                prev_color = color[edge];
            }
        }
        ll clr = 1;
        REP(i, len){
            pair<ll,ll> p = graph[now][i];
            ll next = p.first;
            ll edge = p.second;
            if (color[edge] == 0){
                if (clr == prev_color){
                    clr++;
                }
                color[edge] = clr;
                q.push(next);
                clr++;
            }
        }
    }
    ll mx = 0;
    REP(i, n-1){
        mx = max(color[i], mx);
    }
    cout << mx << endl;
    REP(i, n-1){
        cout << color[i] << endl;
    }
    return 0;
}

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)

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

    int x, y;
    while (cin >> x >> y)
    {
        if (x == 0 && y == 0)
        {
            break;
        }

        cout << min(x, y) << " " << max(x, y) << endl;
    }

    return 0;
}



Measured memory_bytes: 3092
#include <stdio.h>

int main(){
  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  
  if(b <= a && c <= a){
    printf("%d", 10 * a + b + c);
  } else if(a <= b && c <= b){
    printf("%d", 10 * b + a + c);
  } else {
    printf("%d", 10 * c + a + b);
  }
}



Measured memory_bytes: 1652
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

e=min(a)+min(b)

for _ in range(M):
    x,y,c=map(int,input().split())
    f=a[x-1]+b[y-1]-c
    e=min(e,f)

print(e)


Measured memory_bytes: 97788
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn main() {
    input! {
        n: usize, ma: usize, mb: usize,
        abcv: [(usize, usize, usize); n]
    };

    let inf = 1_usize << 30;
    let max_g = 10 * n;
    let mut dp = vec![vec![vec![inf; max_g + 1]; max_g + 1]; n + 1];
    dp[0][0][0] = 0;
    for i in 0..n {
        let (a, b, c) = abcv[i];
        for j in 0..max_g + 1 {
            for k in 0..max_g + 1 {
                dp[i + 1][j][k] = dp[i + 1][j][k].min(dp[i][j][k]);
                if j + a > max_g || k + b > max_g {
                    continue;
                }
                dp[i + 1][j + a][k + b] = dp[i + 1][j + a][k + b].min(dp[i][j][k] + c);
            }
        }
    }
    let mut res = inf;
    for i in 1..max_g + 1 {
        for j in 1..max_g + 1 {
            let c = dp[n][i][j];
            if c == inf {
                continue;
            }
            let gcd = i.gcd(&j);
            if i / gcd == ma && j / gcd == mb {
                if c < res {
                    res = c;
                }
            }
        }
    }
    let res = if res == inf { -1 } else { res as isize };
    println!("{}", res);
}


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

int main () {
  
  string S;
  cin >> S;
  
  int a = 0, b = 0;
  
  for (int i = 0; i < S.length(); i++){
    if (S[i] == '0') {
      a++;
    } else if (S[i] == '1') {
      b++;
    }
  }
  
  cout << min(a, b) * 2 << endl;
  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = inf + 7;
const int N = (int)2e5 + 5;

bool isPal(string s){
	for(int i=0;i<sz(s)/2;i++){
		if(s[i]!=s[sz(s)-1-i]){
			return 0;
		}
	}
	return 1;
}

void solve(){
		string s;
		cin>>s;
		if(!isPal(s)){
			cout<<"No";
			return;
		}
		string t="",l="";
		rep(i,sz(s)/2){
			t+=s[i];
		}
		for(int i=sz(s)/2+1;i<sz(s);i++){
				l+=s[i];
		}
		if(isPal(l) &&  isPal(t))cout<<"Yes";
		else cout<<"No";

}


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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;

const ll mod = 1000000007;
const ll INF = 1000000000000;

ll dp[200010], n, num[200010], kai[200010];
string s;

int main()
{
	cin >> n >> s;
	kai[0] = 1;
	for (int i = 1; i <= 200005; i++)
	{
		kai[i] = kai[i - 1] * i % mod;
	}

	if (s[0] == 'W')
	{
		cout << 0 << endl;
		return 0;
	}

	num[0] = 1;
	dp[0] = 1;
	for (int i = 1; i < 2 * n; i++)
	{
		if (s[i] == 'W')
		{
			if (num[i - 1] % 2 == 0)
			{
				num[i] = num[i - 1] - 1;
				(dp[i] = dp[i - 1] * num[i - 1] % mod) %= mod;
			}
			else
			{
				num[i] = num[i - 1] + 1;
				dp[i] = dp[i - 1];
			}
		}
		else
		{
			if (num[i - 1] % 2 == 0)
			{
				num[i] = num[i - 1] + 1;
				dp[i] = dp[i - 1];
			}
			else
			{
				num[i] = num[i - 1] - 1;
				(dp[i] = dp[i - 1] * num[i - 1] % mod) %= mod;
			}
		}
	}

	if (num[2 * n - 1] == 0)
	{
		cout << dp[2 * n - 1] * kai[n] % mod << endl;
	}
	else
	{
		cout << 0 << endl;
	}

	int www;
	cin >> www;
}


Measured memory_bytes: 5252
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#define ll long long
using namespace std;

int main(){

  int K;
  cin >> K;
  int a[1000001];

  a[1] = 7 % K;

  for (int i=2; i<=K; i++)
    a[i] = (a[i-1] * 10 + 7) % K;

  for (int i=1; i<=K; i++)
    if(a[i] == 0){
      cout << i << endl;
      return 0;
    }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 7020
import numpy as np
import heapq as hq

n,m = map(int,input().split())
a = [-i for i in map(int,input().split())]
hq.heapify(a)

for i in range(m):
    max = hq.heappop(a)
    hq.heappush(a, int(max/2))

ans = sum(a) * -1
print(ans)


Measured memory_bytes: 23120
import java.io.*;
import java.util.*;

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	public void run() {
		while (true) {
			int n = in.nextInt();
			if (n == 0) break;
			
			int res = 0;
			
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1, sum = i; j <= n; j++) {
					sum += j;
					if (sum == n) res++;
				}
			}
			
			System.out.println(res);
		}
		out.close();
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

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

using namespace std;
using namespace __gnu_pbds;

#define ll long long

typedef tree< pair<int,int>, null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

Order_Set X;

const int mxn = 1e7+100;
const int Mod = 1e9+7;

int arr[mxn], qs[mxn];
int bitOn[55];
map<int,int>Mp, cnt, op;
vector< pair<int, pair<int,int> > >Pi, Ans;
vector<int>G[mxn];
set<int>seet[mxn];

int main()
{
     ios::sync_with_stdio(false);

     int n;
     cin>>n;
     string str1, str2;
     cin>>str1>>str2;
     string Ans = "";
     for(int i=0 ; i<n ; i++) Ans+=str1[i], Ans+=str2[i];
     cout<<Ans<<endl;

     return 0;
}




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

int main() {
  
  int n;
  cin >> n;
  
  double x, a = 0;
  string u;
  REP(i,n) {
    cin >> x >> u;
    if (u == "JPY") a += x;
    else a += x * 380000;
  }
  
  cout << a << endl;

}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
long long int* segTree;

long long int max_query(long long int qs, long long int qe, long long int si, long long int ei, long long int index)
{
   if(ei < qs || si > qe) return 0;

   if(si >= qs && ei <= qe)
   {
      return segTree[index];
   }

   long long int mid = (si + ei) >> 1;

   long long int a = max_query(qs, qe, si, mid, (index<<1)+1 );
   long long int b = max_query(qs, qe, mid + 1, ei, (index<<1)+2 );
   return max(a, b);
}

void max_self(long long int& a, long long int b)
{
  a = max(a, b);
}

void update(long long int bui, long long int si, long long int ei, long long int index, long long int val)
{
   if(ei < bui || si > bui) return ;

   if(si == ei)
   {
      max_self(segTree[index], val);
      return;
   }

   long long int mid = (si + ei) >> 1;

   update(bui, si, mid, (index<<1)+1, val );
   update(bui, mid + 1, ei, (index<<1)+2, val );
   segTree[index] = max(segTree[(index<<1)+1], segTree[(index<<1)+2]);
}


int main()
{
  long long int n;
  cin >> n;
  long long int arr[n], val[n];
  for (long long int i = 0; i < n; ++i)
  {
    cin >> arr[i];
    arr[i] -= 1;
  }
  for (long long int i = 0; i < n; ++i)
  {
    cin >> val[i];
  }

  segTree = new long long int[4*n + 1];

  for (long long int i = 0; i < 4*n + 1; ++i)
  {
     segTree[i] = 0;
  }

  long long int ans = 0;

  for (long long int i = 0; i < n; ++i)
  {
     long long int maxm = 0;
     if(arr[i] - 1 >= 0)
     {
      maxm = max_query(0, arr[i] - 1, 0, n-1, 0);
      //if(i == 1) cout << arr[i] << endl;
    }

   //if(i == 1) cout << maxm << endl;
     
     ans = max(ans , maxm + val[i]);
     
     //cout << arr[i] + 1 << " " << maxm + val[i] << endl;
     update(arr[i], 0, n-1, 0, maxm + val[i]);


  }

  cout << ans;


  return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
const int N = 1e9;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
typedef long long ll;
int n;
int a[maxn], pre_max[maxn];
std::map<int, int> map;
inline ll get(int v) {
	int & x = map[v];
	auto it = map.upper_bound(v);
	ll ans = 0;
	for(auto i = it;i != map.end();++i) {
		ans += i -> second * ll(i -> first - v);
		x += i -> second;
	}
	map.erase(it, map.end());
	return ans;
}
ll cnt[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 1, n) {
		cin >> a[i];
		if(a[i] > a[pre_max[i - 1]]) {
			pre_max[i] = i;
		} else {
			pre_max[i] = pre_max[i - 1];
		}
	}
	for(int i = n + 1;i >= 1;) {
		int nxt = pre_max[i - 1];
		for(int j = nxt;j < i;++j) map[a[j]] += 1;
		cnt[i] += get(a[nxt]); i = nxt;
	}
	rep(i, 1, n) {
		cout << cnt[i] << '\n';
	}
}


Measured memory_bytes: 5888