akhauriyash/Code-Regression huggingface dataset:
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	int ma=0,co=0;
	rep(i,s.size())if(s[i]=='T')co++,ma=max(ma,co);
	else co--;
	cout<<2*ma<<endl;
}









Measured memory_bytes: 640
H,W,M=map(int, input().split())
hl=[0 for i in range(H+1)]
wl=[0 for i in range(W+1)]
ms=[]
for i in range(M):
    h,w=map(int, input().split())
    hl[h]+=1
    wl[w]+=1
    ms.append([h,w])
a=max(hl)
b=max(wl)
hmax=[]
wmax=[]
s=0
for x in ms:
    if  hl[x[0]]==a and wl[x[1]]==b:
        s+=1
c=hl.count(a)
d=wl.count(b)
if s<c*d:
    print(a+b)
else:
    print(a+b-1)

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> mii;
typedef map<ll,int> mli;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;  ///1e9+7

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=2;ii<=mx;ii++)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n,i,m,s=0;
    cin>>n;
    ll a[n];
    forn(i,n) cin>>a[i],s+=a[i];
    sort(a,a+n);
    s=a[n-1]; i=n-2;
    n-=2;
    while(n>0){
        if(n==1) {s+=a[i]; break;}
        else{n-=2; s+=a[i]*2; i--;}
    }
    cout<<s el;
}

main()
{
        fastio();
//    test _case();
//    while(1) _case();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll;
int main(){
  
  int N ,counter = 0 ;
  cin  >> N ;
  vector<int> A(N);
  vector<int> B(N);
  rep(i,N) cin >> A.at(i) ;
  rep(i,N) B.at(i) = i+1 ;
  rep(i,N) if ( A.at(i) == B.at(i) ) counter++ ;
  //cout << counter << endl;
  if( counter > N - 3   ) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
# 最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# nを素因数分解したリストを返す
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return set(table+[1])

def main():
  a,b=map(int,input().split())
  print(len(prime_decomposition(gcd(a,b))))
  
main()

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int R[n];
    for(int i=0;i<n;i++){
        scanf("%d",&R[i]);
    }
    int max,min;
    max=-1000000000;
    min=R[0];
    for(int j=1;j<n;j++){
        if(R[j]-min>max) max=R[j]-min;
        else;
        
        if(R[j]<min) min=R[j];
        else;
        }
    printf("%d\n",max);
    return 0;
    
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N, M;
	vector<llong> L, R, rui;

	cin >> N >> M;
	L.resize(M);
	R.resize(M);
	rui.resize(N+2, 0);
	for (int i = 0; i < M; i++) {
		cin >> L[i] >> R[i];
		rui[L[i]]++;
		rui[R[i]+1]--;
	}

	llong ans = 0;
	for (int i = 1; i <= N; i++) {
		rui[i] += rui[i-1];
		if (rui[i] == M)
			ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2560
N,M = map(int, input().split())

M1 = M//2
M2 = M-M1

for i in range(M1):
    a=i+1
    b=2*M1+1-i
    print(a,b)
for i in range(M2):
    a=i+1
    b=2*M2-i
    print(2*M1+1 + a,2*M1+1 + b)

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

using namespace std;

const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};

int h, w;
char s[55][55];

int main(){
	scanf("%d%d", &h, &w);
	
	for(int i = 0; i < h; i++)
	scanf("%s", s[i]);
	
	bool ok = 1;
	
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '.') continue;
			int cnt = 0;
			
			for(int k = 0; k < 4; k++){
				int newx = i + dx[k];
				int newy = j + dy[k];
					
				if(newx < 0 || newx > h) continue;
				if(newy < 0 || newy > w) continue;
					
				if(s[newx][newy] == '#') cnt++;
			}
			
			if(cnt == 0) ok = 0;
		}
	}
	
	if(ok)
	printf("Yes\n");
	else
	printf("No\n");
}



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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

ll dp[2005][2005];

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  long long Y;
  scanf("%lld", &Y);

  Fill(dp, -1LL);
  dp[0][0] = 0;

  rep(i, 0, N + 1) rep(j, 0, N + 1) {
    ll m = Y - (10000 * i + 5000 * j);
    if (m < 0) continue;
    ll a = m / 1000;
    if (i + j + a == N) {
      cout << i << " " << j << " " << a << endl;
      return 0;
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

vector<vector<int>> disc;

int check(int a, int crtState) {
    int ret = 1;
    int xA = disc[a][0];
    int yA = disc[a][1];
    int rA = disc[a][2];
    for (int i = 0; i < a; i++) {
        if (crtState & (1 << i)) continue;
        int x = disc[i][0];
        int y = disc[i][1];
        int r = disc[i][2];
        int dist = (xA - x)*(xA - x) + (yA - y)*(yA - y);
        int distR = (rA+r)*(rA+r);
        if (dist < distR) ret = 0;
    }
    
    return ret;
}


int solve(int N) {
    disc.clear();
    for (int i = 0; i < N; i++) {
        int x, y, r, c; cin >> x >> y >> r >> c;
        disc.push_back({x, y, r, c});
    }
    
    vector<int> v((1 << N), -1);
    v[0] = 0;
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int crtState = que.front();
        que.pop();
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int bitI = (1 << i);
                int bitJ = (1 << j);
                if ((bitI & crtState) || (bitJ & crtState)) continue;
                int nextState = crtState + bitI + bitJ;
                if (v[nextState] >= 0) continue;
                if (disc[i][3] == disc[j][3] && check(i, crtState) && check(j, crtState)) {
                    v[nextState] = v[crtState] + 1;
                    que.push(nextState);
                }
            }
        }
    }
    
    int ret = 0;
    for (int i = 0; i < (1 << N); i++) {
        ret = max(ret, v[i]);
    }
    return ret*2;
}

int main(void){
    int N;
    vector<int> ans;
    while (1) {
        cin >> N;
        if (!N) break;
        ans.push_back(solve(N));
    }
    for (auto &i : ans) {
        cout << i << endl;
    }
    
}



Measured memory_bytes: 69708
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	ll n;
	cin >> n;
	while (n) {
		if (n % 10 == 7) {
			cout << "Yes" << endl;
			return 0;
		}
		n /= 10;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3652
n = int(input())
li = list(map(int,input().split()))
mini = 1000
a = 0
m = 0
total = sum(li)
for i in range(len(li)):
        a += li[i]
        total -= li[i]
        this = abs(total - a)
        if mini > this:
                mini = this
print(mini)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

long double a, b, x;

void input() {
    cin >> a >> b >> x;
}

long double f(long double a, long double b, long double theta) {
    if(theta > PI / 2.0 - EPS) {
        return 0.0;
    }
    long double ret;
    if(a * tan(theta) <= b) {
        ret = a * a * b - a * a * a * tan(theta) / 2.0;
    } else {
        ret = b * b / tan(theta) * a / 2.0;
    }
    return ret;
}

void solve() {
    input();
    long double ok = PI / 2.0;
    long double ng = 0.0;
    for(int _ = 1; _ <= 27; _++) {
        long double mid = (ok + ng) / 2.0;
        if(f(a, b, mid) < x) ok = mid;
        else ng = mid;
    }
    cout << fixed << setprecision(10) << ok / PI * 180 << endl;
    return;
}

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


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

string S, T, U;
int mem[3005][3005], nxt[3005][3005];

int dp(int a, int b) {
	if (a == -1 || b == -1) return 0;
	if (mem[a][b] != -1) return mem[a][b];
	int ra = dp(a - 1, b), rb = dp(a, b - 1);
	if (ra >= rb) {
		nxt[a][b] = 1;
		mem[a][b] = ra;
	} else {
		nxt[a][b] = 2;
		mem[a][b] = rb;
	}
	if (S[a] == T[b]) {
		ra = dp(a - 1, b - 1) + 1;
		if (ra >= mem[a][b]) {
			nxt[a][b] = 3;
			mem[a][b] = ra;
		}
	}
	return mem[a][b];
}

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	memset(mem, -1, sizeof mem);
	cin >> S >> T;
	dp(S.size() - 1, T.size() - 1);
	for (int a = S.size() - 1, b = T.size() - 1; a != -1 && b != -1; ) {
		if (nxt[a][b] == 3) {
			U.push_back(S[a]);
			a--;
			b--;
		} else if (nxt[a][b] == 1) a--;
		else b--;
	}
	reverse(U.begin(), U.end());
	cout << U << '\n';
}


Measured memory_bytes: 141696
#include <iostream>
using namespace std;
#include<stdio.h> 
int max(int a, int b) { return (a > b)? a : b; } 
  
long long int knapSack(int W, int wt[], int val[], int n) 
{ 
   int i, w; 
   long long int K[n+1][W+1]; 
  
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 
int main() {
	// your code goes here
	int n,w,weight[n],value[n];
	cin>>n>>w;
	for(int i=0;i<n;i++){
		cin>>weight[i]>>value[i];
	}
	cout<<knapSack(w,weight,value,n);
	return 0;
}

Measured memory_bytes: 81152
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
using namespace std;


int main(){
int n;cin>>n;
vi d(n);
rep(i,n)d.at(i)=i+1;
vi p(n);
vi q(n);
rep(i,n)cin>>p.at(i);
rep(j,n)cin>>q.at(j);
int flag=1;
int ap=0;
int aq=0;
do{
rep(i,n){
    if(d.at(i)!=p.at(i))break;
if(i==n-1)ap=flag;
//cout<<ap<<endl;
}

rep(j,n){
    if(d.at(j)!=q.at(j))break;
if(j==n-1)aq=flag;
}
flag++;
}while(next_permutation(all(d)));
int s=abs(ap-aq);
cout<<s<<endl;


}

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

int main(){
  int a, b;
  cin >> a >> b;
  int sum = a+b;
  int gap = a-b;
  int kake = a*b;
  if(sum >= gap && sum >= kake){
    cout << sum << endl;
  }else{
    if(gap >= kake){
      cout << gap << endl;
    }else{
      cout << kake << endl;
    }
  }
  return 0;
}

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

void printArray(int A[], int N) {
    for (int i = 0; i < N-1; i++) cout << A[i] << " ";
    cout << A[N-1] << endl;
}
void insertionSort(int A[], int N) {
    printArray(A, N);
    int v, j;
    for (int i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        printArray(A, N);
    }
}

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


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

using namespace std;

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

    vector<int> h;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        h.push_back(x);
    }

    vector<int> z(0);
    vector<vector<int> > t(n, z);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        vector<int> t1;
        t1 = t[a-1];
        t1.push_back(b);
        t[a-1] = t1;
        vector<int> t2;
        t2 = t[b-1];
        t2.push_back(a);
        t[b-1] = t2;
    }

    int k=0;
    int ans=0;
    for(auto i : t){
        bool highest = true;
        for(auto j : i){
            if(h[k] <= h[j-1]) {
                highest = false;
            }
        }

        if(highest)
            ans++;
        highest = true;
        k++;
    }

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


Measured memory_bytes: 9492
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  vector<string> S(2);
  in(S[0], S[1]);
  ll ans = 3;
  int s = 1;
  if (S[0][0] != S[1][0]) {
    ans *= 2;
    s *= 2;
  }

  rep(i, s, N) {
    bool f = S[0][i - 1] == S[1][i - 1];
    if (S[0][i] == S[1][i]) {
      if (f) {
        ans *= 2;
      }
    } else {
      if (f) {
        ans *= 2;
      } else {
        ans *= 3;
      } 
      i++;
    }
  }

  print(ans % MOD);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Long a = scan.nextLong();
		Long b = scan.nextLong();
		Long x = scan.nextLong();
		Long count = b / x + 1;
		Long i = (long) 0;
		for(; i < a; i = i + x) {
			count--;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 25556
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  vi X(n),L(n);
  vi lf(n),rg(n),last(n);

  REP(i,n){
    cin>>X[i]>>L[i];
    lf[i]=X[i]-L[i];
    rg[i]=X[i]+L[i];
  }


vector<pair<ll, ll>> p(n);
REP(i,n){
  p[i].first=lf[i];
  p[i].second=rg[i];
}
sort(p.begin(),p.end());//, compare_by_b

ll tmp=10000000000;
for(int i=n-1;i>=0;i--){
  last[i]=min(tmp,p[i].second);
  tmp=last[i];
}

ll start=last[0];
ans++;
for(int i=0;i<n;i++){
  if (start<=p[i].first){
    ans++;
    start=last[i];
  }
}





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

Measured memory_bytes: 5760
N = int(input())
w = list(input())
fin = w[-1]
lst = [w]
for i in range(N-1):
    w = list(input())
    head = w[0]
    if  w[0] != fin or w in lst:
      print("No")
      exit()
    else:
      fin = w[-1]
      lst.append(w)
print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A,B;
  cin>>A>>B;
  if((A+B)%2){
    cout<<"IMPOSSIBLE"<<endl;
  }else{
    cout<<(A+B)/2<<endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pll pair<ll,ll>
#define sll set<ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define vpl vector<pll>
#define gll greater<ll>
#define prq priority_queue
#define mp make_pair
#define pb push_back
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef long double ld;
ll mx=INT_MAX;
ll mn=INT_MIN;
ll mod=1e9+7;
const ll maxs=2e6+6;
ll max2d=1e3+3;


ll v;
vll *g;
ll *p;
ll *lvl;
mll m;
ll *clr;


ll fast(ll base , ll power)
{
    ll res=1;
    while(power)
    {
        if(power&1)
            res=res*base;
        base = base*base;
        power>>=1;
    }
    return res;
}


void addEdge(ll x,ll y)
{
    g[x].pb(y);
    g[y].pb(x);
}


int main()
{
    ll n,m;
    cin>>n>>m;
    
    ll ans = n*(n-1)/2;
    ans += m*(m-1)/2;
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	a := nextInt()
	p := nextInt()

	sum := ((a * 3) + p) / 2
	_, _ = fmt.Fprintf(writer, "%d", sum)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, L = ni()
    val A = na(N)
    val pairs = map(N - 1)(i => i -> (A(i) + A(i + 1)))
    val (mxIx, mxVal) = pairs.maxBy(_._2)
    if (mxVal < L) {
      out.println("Impossible")
    } else {
      out.println("Possible")
      (0 until mxIx) ++ (mxIx + 1 until N - 1).reverse foreach { i =>
        out.println(i + 1)
      }
      out.println(mxIx + 1)
    }
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}


Measured memory_bytes: 51636
n=int(input())
s=input()
t=s.count("R")*s.count("G")*s.count("B")
cnt=0
for i in range(n):
  for j in range(i,n):
    if 2*j-i>=n:
      break
    else:
      if s[i]!=s[j]!=s[2*j-i]!=s[i]:
        cnt+=1
print(t-cnt)

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1;i <= 9;i++) {
        if(N%i == 0 && N/i <= 9){
            ans+=1;
        }
    }
    if(ans > 0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1005

enum Type{
	A,
	B,
	C,
	D,
};

int N;
ll V;
ll input[NUM][4];
Type type_array[4] = {A,B,C,D};
map<ll,ll> AB,CD;

int main(){

	scanf("%d %lld",&N,&V);

	for(int i = 0; i < 4; i++){
		for(int k = 0; k < N; k++){
			scanf("%lld",&input[k][i]);
		}
	}

	//AとBの組合わせ
	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){
			AB[input[i][A]+input[k][B]]++;
		}
	}

	//CとDの組合せ
	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){
			CD[input[i][C]+input[k][D]]++;
		}
	}

	ll ans = 0;
	map<ll,ll>::iterator it = AB.begin();

	ll num_AB,num_CD;

	while (it != AB.end()){
	   num_AB = it->first;
	   num_CD = V-num_AB;
	   ans += AB[num_AB]*CD[num_CD];
	   it++;
	}

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

	return 0;
}



Measured memory_bytes: 190620
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

int main() {

	char s[128];
	scanf("%s", s);
	if(strlen(s) % 2 != 0) {
		printf("No\n");
		return 0;
	}
	for(int i = 0; i < strlen(s); i += 2) {
		if(s[i] != 'h' || s[i + 1] != 'i') {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cctype>
#include<cstring>
using namespace std;
int main(){
	char a[100];
	int f=1;
	scanf("%s",a);
	if(a[0]!='A'){
			printf("WA\n");
			return 0;
		}
	if(isupper(a[1])){
			printf("WA\n");
			return 0;
		}
	int i;
	for(i=2;i<strlen(a)-1;i++){
		if(isupper(a[i])&&a[i]!='C'){
			printf("WA\n");
			return 0;
		}
		if(a[i]=='C' && f==0){
			printf("WA\n");
			return 0;
		}
		if(a[i]=='C' && f==1){
			f=0;
		}
	}
	if(!islower(a[i])){
		printf("WA\n");
		return 0;
	}
	if(f==0)
		printf("AC\n");
	else
		printf("WA\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int numero;
	cin>>numero;
	int res=numero%10;
	switch(res){
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:cout<<"hon";break;
		case 0:
		case 1:
		case 6:
		case 8:cout<<"pon";break;
		case 3:cout<<"bon";break;
	}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define ll long long
//#define int long long
using namespace std;
void boost()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
void free()
{
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
}
main()
{
	//free();
	boost();
	int a, b;
	cin >> a >> b;
	int cnt = 0;
	for(int i = a; i <= b; i++)
		if(i / 10000 == i % 10 && (i / 1000) % 10 == (i / 10) % 10) cnt++;
	cout << cnt, exit(0);
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<tuple>
#include<functional>

using namespace std;
typedef tuple<int, int, int> T3i;

struct edge {
	int to, cost, dis;
	edge(int a, int b, int c) { to = a, cost = b, dis = c; }
};

int N, M, L;
vector<vector<edge>> E;
int d[100][101];

void djkstra(int start) {
	priority_queue<T3i, vector<T3i>, greater<T3i>> pq;
	d[0][0] = 0;
	pq.push(make_tuple(0, 0, 0));
	while (pq.size()) {
		auto now = pq.top(); pq.pop();
		if (d[get<2>(now)][get<1>(now)] < get<0>(now))continue;

		for (int i = 0; i < E[get<2>(now)].size(); i++) {
			auto next = E[get<2>(now)][i];
			int budget = get<1>(now);

			if (budget + next.dis <= L && d[next.to][budget + next.dis] > get<0>(now)) {
				//予算を使う
				d[next.to][budget + next.dis] = get<0>(now);
				pq.push(make_tuple(get<0>(now), budget + next.dis, next.to));
			}

			if (d[next.to][budget] > get<0>(now) + next.cost) {
				//予算を使わない
				d[next.to][budget] = get<0>(now) + next.cost;
				pq.push(make_tuple(get<0>(now) + next.cost, budget, next.to));
			}

		}
	}
}

int main() {

	while (1) {

		for (int i = 0; i < 100; i++)for (int j = 0; j <= 100; j++)d[i][j] = 999999999;

		cin >> N >> M >> L;
		if (N + M + L == 0)break;
		E.resize(N);

		for (int i = 0; i < M; i++) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			a--, b--;
			E[a].push_back(edge(b, d, c));
			E[b].push_back(edge(a, d, c));
		}

		djkstra(0);

		int ans = 999999999;
		for (int i = 0; i <= L; i++)ans = min(ans, d[N - 1][i]);

		cout << ans << endl;

		E.clear();
	}
	
	return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

// https://onlinejudge.u-aizu.ac.jp/solutions/problem/DSL_2_D/review/3635072/beet/C++14
template<typename E>
struct SegmentTree {
    using H = function<E(E, E)>;
    int n, height;
    H h;
    E ei;
    vector<E> laz;

    SegmentTree(H h, E ei) : h(h), ei(ei) {}

    void init(int n_) {
        n = 1;
        height = 0;
        while (n < n_) n <<= 1, height++;
        laz.assign(2 * n, ei);
    }

    inline void eval(int k) {
        if (laz[k] == ei) return;
        laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]);
        laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
        laz[k] = ei;
    }

    inline void thrust(int k) {
        for (int i = height; i; i--) eval(k >> i);
    }

    void update(int a, int b, E x) {
        thrust(a += n);
        thrust(b += n - 1);
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) laz[l] = h(laz[l], x), l++;
            if (r & 1) --r, laz[r] = h(laz[r], x);
        }
    }

    E get_val(int a) {
        thrust(a += n);
        return laz[a];
    }

    void set_val(int a, E x) {
        thrust(a += n);
        laz[a] = x;
    }
};


int main() {

    int n, q;
    cin >> n >> q;
    auto h = [](int a, int b) { return a + b; };
    SegmentTree<int> st(h, 0);
    st.init(n);

    rep(i, q) {
        int query;
        cin >> query;

        if (query == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            s--;
            st.update(s, t, x);
        } else if (query == 1) {
            int x;
            cin >> x;
            x--;
            cout << st.get_val(x) << endl;
        }

    }

}



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

int main(){
    int s;
    cin >> s;

    vector<int> a;
    a.push_back(s);

    int k = 0;
    int cou = 0;
    int frag = 0;

    while(1){
        if(a[cou] % 2 == 0){
            k = a[cou] / 2;
        }else{
            k = a[cou] * 3 + 1;
        }
        a.push_back(k);
        cou++;
        for(int i = 0; i < cou; i++){
            if(k == a[i]){
                frag = 1;
                break;
            }
        }
        if(frag == 1){
            break;
        }
    }

    cout << cou + 1 << endl;
}

Measured memory_bytes: 256
m=10**9+7
h,w,a,b=map(int,input().split())
d=c=1
for i in range(h-1):
    d=c=c*(w+h-b-2-i)*pow(i+1,m-2,m)%m
for i in range(1,h-a):
    c=c*(b-1+i)*(h-i)*pow(i*(w+h-b-1-i),m-2,m)%m
    d+=c
print(d%m)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
	
	char S[3];
	int count = 0;
	int c = 0;
	scanf("%s", S);
	for (int i = 0; i < 3; i++){
		if (S[i] == 'o'){
			count++;
		}
		

	}
	printf("%d", 700 + count * 100);

	return 0;


}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110

signed main()
{
    string A, B;
    cin >> A >> B;
    int num = atoi((A + B).c_str());
    vector<int> cand;
    for(int i = 1; i <= 1000; ++i) {
        cand.push_back(i * i);
    }
    REP(i, cand.size()) {
        if(num == cand[i]) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-12;
const int MAX=100000+10;
const int EDGE=100000+10;//边的条数
typedef long long ll;
int main()
{
	ll n,x,i,a[MAX],t,ans;
	while(~scanf("%lld%lld",&n,&x))
	{
		mem(a,0);
		t=0;
		for(i=0;i<n;i++)
		{
			scanf("%lld",&a[i]);
		}
		ans=0;
		if(a[0]>x)
		{
			t=a[0]-x;
			ans+=t;
			a[0]-=t;
		}
		for(i=1;i<n;i++)
		{
			if(a[i]+a[i-1]>x)
			{
				t=a[i]+a[i-1]-x;
				ans+=t;
				a[i]-=t;
			}
		}
	//	if(a[n-2]+a[n-1]>x) ans+=a[n-2]+a[n-1]-x;
		printf("%lld\n",ans);
	}
	return 0;
}

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

namespace IO
{
char gc()
{
#ifdef FREAD
	static char buf[1<<21], *P1 = buf, *P2 = buf;
	if(P1 == P2)
	{
		P1 = buf;
		P2 = buf + fread(buf, 1, 1<<21, stdin);
		if(P1 == P2) return EOF;
	}
	return *(P1++);
#else
	return getchar();
#endif
}
template<typename Tp> bool get1(Tp &x)
{
	bool neg = 0;
	char c = gc();
	while( c != EOF && (c < '0' || c > '9') && c != '-' ) c = gc();
	if(c == '-') c = gc(), neg = 1;
	if(c == EOF) return false;
	x = 0;
	for(; c>='0' && c<='9'; c = gc()) x = x*10 + c - '0';
	if(neg) x = -x;
	return true;
}
template<typename Tp> void printendl(Tp x)
{
	if(x<0)putchar('-'),x=-x;
	static short a[40], sz;
	sz = 0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
	puts("");
}
} // namespace IO
using IO::get1;
using IO::printendl;
#define get2(x,y) get1(x) && get1(y)
#define get3(x,y,z) get2(x,y) && get1(z)
#define get4(x,y,z,w) get3(x,y,z) && get1(w)
#define pb push_back
#define mp std::make_pair
#define ff first
#define ss second
typedef long long LL;
typedef unsigned long long uLL;
typedef std::pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll<<61;

const int M = 62;
const int N = 128;
const char S[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

#ifdef EEEEEericKKK
std::string T;
#endif

namespace checker
{

int dp[233][233];
int calc(std::string s, std::string t)
{
	assert(s.size() <= 128);
	assert(t.size() <= 128);
	assert(s.size());
	assert(t.size());
	memset(dp, inf, sizeof(dp));
	dp[0][0] = 0;
	for(int i=0; i<=s.size(); i++) for(int j=0; j<=t.size(); j++)
	{
		dp[i][j+1] = std::min(dp[i][j+1], dp[i][j] + 1);
		dp[i+1][j] = std::min(dp[i+1][j], dp[i][j] + 1);
		dp[i+1][j+1] = std::min(dp[i+1][j+1], dp[i][j] + 1);
		if(i < s.size() && j < t.size() && s[i] == t[j]) dp[i+1][j+1] = std::min(dp[i+1][j+1], dp[i][j]);
	}
	return dp[s.size()][t.size()];
}

} // namespace checker

int tot;
int query(std::string s)
{
	tot++;
#ifdef EEEEEericKKK
	return checker::calc(s, T);
#endif
	printf("? %s\n", s.c_str());
	fflush(stdout);
	int ret;
	get1(ret);
	return ret;
}

int cnt[N], len;
bool isSub(std::string s) { return (query(s) == len - (int)s.size()); }
std::string getnext(std::string s, char c)
{
	int rb = 0, lb = 0, mid;
	while(rb < s.size() && s[rb] != c) rb++;
	rb++;
	while(lb < rb - 1)
	{
		mid = (lb + rb) / 2;
		std::string now;
		for(int i=0; i<mid; i++) now = now + s[i];
		for(int i=0; i<(int)s.size(); i++) if(s[i] == c) now = now + c;
		now = now + c;
		if(isSub(now)) lb = mid;
		else rb = mid;
	}
	std::string ret;
	for(int i=0; i<lb; i++) ret = ret + s[i];
	ret = ret + c;
	for(int i=lb; i<s.size(); i++) ret = ret + s[i];
	return ret;
}

int main()
{
#ifdef EEEEEericKKK
	std::cin >> T;
#endif
	for(int i=0; i<M; i++)
	{
		std::string s = "";
		for(int j=0; j<N; j++) s = s + S[i];
		cnt[i] = N - query(s);
		len += cnt[i];
	}
	
	std::string ans = "";
	for(int i=0; i<M; i++) while(cnt[i]--) ans = getnext(ans, S[i]);
#ifdef EEEEEericKKK
	printf("tot= %d\n", tot);
#endif
	printf("! %s\n", ans.c_str());
	return 0;
}

Measured memory_bytes: 3800
S = list(input())
S.pop(-1)
for i in range(len(S)):
    if len(S) % 2 != 0:
        S.pop(-1)
        continue
    else:
        if S[:len(S)//2] == S[len(S)//2:]:
            print(len(S))
            break
        else:
            S.pop(-1)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

s=int(input())
l = [int(i) for i in input().split()]

count=0
for i in range(len(l)-2):
    if l[i]<l[i+1]<l[i+2]:
        count+=1
    if l[i]>l[i+1]>l[i+2]:
        count+=1

print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int N; cin >> N;
   vector<ll> x(N), y(N);
   vector<LP> ball(N);
   map<LP, bool> mp;
   rep(i, N) {
       cin >> x[i] >> y[i];
       ball[i] = make_pair(x[i], y[i]);
       mp[ball[i]] = true;
   }
   ll ans = N;
   rep(i, N) {
       rep(j, N) {
           if(i == j) continue;
           ll p = x[i] - x[j];
           ll q = y[i] - y[j];
           ll res = 0;
           rep(k, N) {
               res ++;
               if(mp[LP(x[k] - p, y[k] - q)]) res --;
           }
           ans = min(ans, res);
       }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 4096
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005


ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}


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



int main(){
    string s;cin>>s;
    int a[3];memset(a,0,sizeof(a));
    int n=s.size();
    rep(i,0,n-1)a[s[i]-'a']++;
    sort(a,a+3);
    if(n==1)cout<<"YES"<<endl;
    else if(a[2]-a[0]>=2)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

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

R = [w for a, w in zip(a, w) if a == 0]
L = [w for a, w in zip(a, w) if a == 1]

if R and L:
    print(min(R) + min(L))
else:
    print(0)



Measured memory_bytes: 5604
from fractions import gcd
def lcm(a, b):
    return a * b // gcd(a, b)
N, M = map(int, input().split())
B = set(map(lambda x: int(x)//2, input().split()))
power = 1
for b in B:
    power = lcm(power, b)

mn = min(B)
p2 = power // mn

if p2 % 2 == 0:
    print(0)
    exit()
ans1 = M // mn // p2
ans2 = M // mn // (p2 * 2)
print(ans1-ans2)


Measured memory_bytes: 13352
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> h(N + 1);
  h[0] = 0;
  range(i, N) std::cin >> h[i+1];
  std::vector<int> DP(N + 1);
  DP[1] = 0;
  DP[2] = abs(h[2] - h[1]);
  ranges(i, 3, N+1) DP[i] = min(DP[i-1]+abs(h[i]-h[i-1]),DP[i-2]+abs(h[i]-h[i-2]));
  std::cout << DP[N] << '\n';
  return 0;
}

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

int main(){
    //input
    int H,N;
    cin >> H >> N;
    int A[N+1], B[N+1];
    int i,j;
    for(i=1; i<=N; i++){
        cin >> A[i] >> B[i];
    }

    //calc
    int dp[N+1][H+1];
    for(i=0; i<=N; i++){
        dp[i][0] = 0;
    }
    for(j=1; j<=H; j++){
        dp[1][j] = (j/A[1] + (j%A[1]>0))*B[1];
    }
    for(i=2; i<=N; i++){
        for(j=1; j<=H; j++){
            if(j-A[i]<0){
                dp[i][j] = min(dp[i-1][j],B[i]);
            }else{
                dp[i][j] = min(dp[i-1][j],dp[i][j-A[i]]+B[i]);
            }
        }
    }

    //answer
    cout << dp[N][H] << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 42632
#include <stdio.h>

int main(void){
	int i,j,t,a[10];
	for(i=0;i<10;i++)scanf("%d",&a[i]);
	for(i=0;i<9;i++){
		for(j=0;j<9;j++){
			if(a[j]<a[j+1]){
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
	}
	printf("%d\n%d\n%d\n",a[0],a[1],a[2]);

	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        String S;
        String T;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            S = sc.next();
            T = sc.next();

        }
        
        char[] sc = S.toCharArray();
        char[] tc = T.toCharArray();
        char[] result = new char[N*2];
        
        for (int i = 0; i < N; i++) {
            result[2*i] = sc[i];
            result[2*i +1] = tc[i];
        }
        
        
        System.out.println(new String(result));
        

    }


}


Measured memory_bytes: 22356
import itertools
s = input()
ans=0
for i in list(itertools.product([0,1], repeat=len(s)-1)):
    b = 0
    a = int(s[0])
    l = [a]+[0]*(2*(len(s)-1))
    for j in range(len(s)-1):
        if i[j] == 0:
            a += int(s[j+1])
            l[2*j+1] = '+'
            l[2*j+2] = str(s[j+1])
        else:
            a -= int(s[j+1])
            l[2*j+1] = '-'
            l[2*j+2] = str(s[j+1])
    if a == 7:
        l[0] = str(s[0])
        l += '=7'
        l = ''.join(l)
        print(l)
        break

Measured memory_bytes: 9200