akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>


int main(int argc, char **argv)
{
  int takahashi = 0;
  char s[5];
  int i;
  scanf("%s%s%s%s",&s[0],&s[1],&s[2],&s[3]);
  for(i = 0 ; i < 4 ; i++){
    if(s[i] == '+'){
      takahashi++;
    }
    else{
      takahashi--;
    }
  }
  printf("%d\n",takahashi);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
int n,m,k;
char a[10][10];
int main() {
    ios::sync_with_stdio(false);cin.tie(0);
  	cin>>n>>m>>k;

  	for(int i=0;i<n;++i){
  		for(int j=0;j<m;++j){
  			cin>>a[i][j];
  		}
  	}

  	int cnt=0;
  	int ans=0;
  	 for(int i=0;i<(1<<n);++i){
  	 	for(int j=0;j<(1<<m);++j){
  	 		cnt=0;
  	 		for(int r=0;r<n;++r){
  	 			for(int c=0;c<m;++c){
  	 				if(!(i&(1<<r)) && !(j&(1<<c)) && a[r][c]=='#') cnt++;
  	 			}
  	 		}

  	 		if(cnt==k) ans++;
  	 	}
  	 }

  	 cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
ll n;
deque<int> fro,bac;
void solve(ll n,int id){
	if(n==1)return; 
	if(n&1){
		solve(n-1,id+1); fro.push_front(id); bac.push_back(id);
	}else{
		solve(n>>1,id+1); fro.push_back(id);  bac.push_back(id);
	}
}

int main(){
	cin>>n; n++;
	solve(n,1);
	cout<<fro.size()*2<<endl;
	while(fro.size()){
		cout<<fro.front()<<" "; fro.pop_front();
	}
	while(bac.size()){
		cout<<bac.front()<<" "; bac.pop_front();
	}
}

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

int main() {
  int64_t a, b, c, x, y;
  std::cin >> a >> b >> c >> x >> y;

  int64_t price = 0;

  if (c * 2 < a + b) {
    const auto n = std::min(x, y);
    price += c * 2 * n;
    x -= n;
    y -= n;
  }
  if (c * 2 < a) {
    price += c * 2 * x;
    y -= x;
    y = std::max(static_cast<int64_t>(0), y);
    x = 0;
  }
  if (c * 2 < b) {
    price += c * 2 * y;
    x -= y;
    x = std::max(static_cast<int64_t>(0), x);
    y = 0;
  }

  price += a * x + b * y;

  std::cout << price << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);

  if(a<b && b<c)
    {
      printf("Yes\n");
    }else
    {
      printf("No\n");
    }

  return 0;
}

Measured memory_bytes: 1008
/*
    2020.6.11
    Ве№И 1379
    LTC
*/
#include <bits/stdc++.h>
#define mem(f, x) memset( f, x, sizeof(f) )
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mk(x, y) make_pair(x, y)
#define fi first
#define se second
#define pk push_back
typedef long long LL;
using namespace std;
const int M = 10;
const int N = 10;
char s[N];

int main( ){
    while( scanf( "%s", s ) != EOF ){
        if( s[0] >= 'A' && s[0] <= 'Z' )
            printf( "A\n" );
        else
            printf( "a\n" );
    }
    return 0;
}


Measured memory_bytes: 3648
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, m; cin >> n >> m;
	vector<vector<int>> e(n);
	rep(i, m)
	{
		int u, v; cin >> u >> v;
		--u, --v;
		e[u].push_back(v);
	}
	int s, t; cin >> s >> t;
	--s, --t;
	vector<vector<int>> dp(n, vector<int>(3, -1));
	queue<pair<int, int>> q;
	dp[s][2] = 0;
	q.push(make_pair(s, 2));
	while (!q.empty())
	{
		int now = q.front().first;
		int step = q.front().second;
		q.pop();
		for (int next : e[now])
		{
			int nextStep = (step + 1) % 3;
			if (dp[next][nextStep] == -1)
			{
				dp[next][nextStep] = dp[now][step];
				if (nextStep == 0)++dp[next][nextStep];
				q.push(make_pair(next, nextStep));
			}
		}
	}
	cout << dp[t][2] << endl;
}


Measured memory_bytes: 11264
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI = 3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM =
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	ll n = s.size();
	if (s[n - 1] == 's')
	{
		s += "es";
	}
	else
	{
		s += "s";
	}
	cout << s << endl;
	return 0;
}


//252908XL

/*
comments:-

*/


Measured memory_bytes: 3640
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    int n;
    cin >> n;
    vector<int> X(n), Y(n);
    for (auto &e : X) {
        cin >> e;
    }
    for (auto &e : Y) {
        cin >> e;
    }
    double ans = 0.0;
    rep(i, n) ans += abs(X[i] - Y[i]);
    cout << ans << "\n";
    ans = 0.0;
    rep(i, n) ans += pow(abs(X[i] - Y[i]), 2);
    cout << sqrt(ans) << "\n";
    ans = 0.0;
    rep(i, n) ans += pow(abs(X[i] - Y[i]), 3);
    cout << pow(ans, 1 / 3.0) << "\n";
    int ans2 = 0;
    rep(i, n) ans2 = max({abs(X[i] - Y[i]), ans2});
    cout << ans2 << "\n";
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i < (int)(n); i++)
typedef long long ll;
#define NP next_permutation
#define MP make_pair

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  char x;
  cin >> x;
  if(x == 'A') cout << 'T' << endl;
  if(x == 'T') cout << 'A' << endl;
  if(x == 'C') cout << 'G' << endl;
  if(x == 'G') cout << 'C' << endl;
}




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

using namespace std;

int main() {
    while (true) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) {
            break;
        }
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (j < x - i - j && x - i - j <= n) {
                    ++ans;
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
long long n,m,k,ans=0,a=0,b,c,d,cnt=0;
string s,alph="abcdefghijklmnopqrstuvwxyz",t[1000],u;
int main(){
  cin >> s >> n;
  map<string,int> mp;
  if(s.size()==n){
    cout << s << endl;
    return 0;
  }
  if(n==1){
    sort(s.begin(),s.end());
    cout << s[0] << endl;
    return 0;
  }
  for(int i=0;i<alph.size();i++){
    for(int j=0;j<s.size();j++){
      if(s[j]==alph[i]){
      	for(int k=1;k<=n;k++){
      		if(mp[s.substr(j,k)]==0){
      			mp[s.substr(j,k)]++;
	      		t[cnt]=s.substr(j,k);
	      		cnt++;
      		}
      	}
      }
    }
	if(cnt>=n){
		sort(t,t+cnt);
	 	cout << t[n-1] << endl;
	   	return 0;
	}
  }  
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define endl enjoy_codeforces
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    int n,m;std::cin>>n>>m;
    long long mod=1'000'000'007;
    auto add=[mod](long long&x, long long y){
        x+=y;
        x%=mod;
        if(x<0)x+=mod;
    };
    long long X=0,Y=0;
    for(int i=0;i<n;i++){
        long long x;std::cin>>x;
        add(X,x*(-n+2*i+1));
    }
    for(int i=0;i<m;i++){
        long long x;std::cin>>x;
        add(Y,x*(-m+2*i+1));
    }
    std::cout<<X*Y%mod<<'\n';
}


Measured memory_bytes: 256
from scipy.sparse import*
def main():
  f=csgraph.floyd_warshall
  n,m,l,*t=map(int,open(0).read().split())
  d=[[0]*(n+1)for _ in range(n+1)]
  for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c
  d=f(f(d,0)<=l)-1
  d[d>n]=-1
  print('\n'.join(str(d[i])for i in zip(*[iter(t[m*3+1:])]*2)))
main()

Measured memory_bytes: 40872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  for (ll i = 1; i <= n;i++){
    if(i*(i+1)/2>=n){
      ll a = i * (i + 1) / 2 - n;
      for (ll j = 1; j <= i; j++){
        if(j==a){
          continue;
        }
        print(j);
      }
      return 0;
    }
  }
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
int A,B,n,g,fa[4007];
char ans[4007];
bool query(int a,int b){
	printf("? %d %d\n",a-1,b-1),fflush(stdout);
	char c;
	scanf(" %c",&c);
	return c=='Y';
}
void solve(std::vector<int>&v){
	if(v.empty())return;
	if(v.size()==1){
		g=v[0];
		ans[g]='1';
		return;
	}
	std::vector<int>v2;
	if(v.size()&1)g=v.back(),v.pop_back();
	for(int i=1;i<v.size();i+=2){
		int a=v[i-1],b=v[i];
		int ab=query(a,b),ba=query(b,a);
		if(ab){
			if(ba){
				fa[a]=b;
				v2.push_back(b);
			}else{
				ans[a]='0';
				v2.push_back(b);
			}
		}else if(ba){
			ans[b]='0';
			v2.push_back(a);
		}
	}
	solve(v2);
}
void dfs(int w){if(!ans[w])dfs(fa[w]),ans[w]=ans[fa[w]];}
int main(){
	scanf("%d%d",&A,&B);
	n=A+B;
	for(int i=1;i<=n;++i)fa[i]=i;
	if(A<=B)puts("Impossible");
	else{
		std::vector<int>v;
		for(int i=0;i<n;++i)v.push_back(i+1);
		solve(v);
		ans[g]='1';
		for(int i=1;i<=n;++i)if(!ans[i]&&fa[i]==i)ans[i]=query(g,i)+'0';
		for(int i=1;i<=n;++i)dfs(i);
		printf("! ");puts(ans+1);
	}
	return 0;
}

Measured memory_bytes: 852
#include <stdio.h>
int main(void){
	int n,k,r,s,p,i=0,sum=0;
	scanf("%d%d%d%d%d",&n,&k,&r,&s,&p);
	char t[n+1];
	int score[n+1];
	scanf("%s",t);
	i=0;
	while(i<n){
		if(i<k){
			if(t[i]=='r'){
				score[i]=p;
			}else if(t[i]=='s'){
				score[i]=r;
			}else if(t[i]=='p'){
				score[i]=s;
			}
		}else{
			if(!(t[i]==t[i-k]&&score[i-k]!=0)){
				if(t[i]=='r'){
					score[i]=p;
				}else if(t[i]=='s'){
					score[i]=r;
				}else if(t[i]=='p'){
					score[i]=s;
				}
			}else{
				score[i]=0;
			}
		}
		i++;
	}
	i=0;
	while(i<n){
		sum+=score[i];
		i++;
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 640
M=8**7
m=M*476+1
f=[1]*M
g=[1]*M
h=[1]*M
i=2
while i<M:f[i]=f[i-1]*i%m;h[i]=-h[m%i]*(m//i)%m;g[i]=g[i-1]*h[i]%m;i+=1
a=0
b=j=1
A,B=map(int,input().split())
if A<B:A,B=B,A
while j<=B:a+=b*f[A+B-j]*g[B-j];b=b*2%m;j+=1
print((a*f[B]*g[A+B]+A)%m)

Measured memory_bytes: 122636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    double t, x;
    cin >> t >> x;
    cout << t / x << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, k;
    ll H;
    cin >> n >> k;
    priority_queue<ll> pq;
    for(int i = 0; i < n; i++) {
        cin >> H;
        pq.push(H);
    }
    while(k-- && !pq.empty()) {
        pq.pop();
    }
    ll ans = 0;
    while(!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 2420
#include <algorithm>
#include <climits>
#include <iostream>
using namespace std;
int main() {
  int n, m = INT_MAX, res = INT_MIN, r;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r;
    if ((r - m) > res) res = r - m;
    if (r < m) m = r;
  };
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  vi x(5);
  rep(i,5){ cin >> x[i];
    if(x[i] == 0){
    cout << i+1 << endl;
    }
  }
}


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

long long s, t;
string a;
bool v[15];

void f(int p) {
	int i;
	if (p == a.size()) {
		t = 0;
		for (i = 0; i < a.size(); i++) {
			if (v[i]) {
				s += t;
				t = 0;
			}
			t = t * 10 + a[i] - '0';
		}
		s += t;
	} else {
		f(p + 1);
		v[p] = 1;
		f(p + 1);
		v[p] = 0;
	}
}

int main()
{
	cin >> a;
	f(1);
	cout << s;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,p=0,q=0,r=0,s=0,n=0,m=0;
    cin>>a>>b>>c>>d;
    p=a*c;
    r=a*d;
    s=b*c;
    q=b*d;
    //cout<<p<<" "<<r<<" "<<s<<" "<<q<<" ";
    n=max(p,r);
    m=max(s,q);
    //cout<<n<<" "<<m<<endl;
    cout<<max(n,m)<<endl;

}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
using namespace std;

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


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll dp[3030][3030];
ll pi[3030][3030];
ll pj[3030][3030];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 3030)REP(j, 3030) dp[i][j] = -1;
    dp[0][0] = 0;

    string s, t;
    cin >> s >> t;
    ll N = s.size();
    ll M = t.size();

    REP(i, N+1){
    	REP(j, M+1){
    		dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    		if(dp[i+1][j] == dp[i][j]){
    			pi[i+1][j] = i;
    			pj[i+1][j] = j;
    		}

    		dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
    		if(dp[i][j+1] == dp[i][j]){
    			pi[i][j+1] = i;
    			pj[i][j+1] = j;
    		}


    		if(i<N && j<M && s[i] == t[j]){
    			dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j+1]);
    			if(dp[i+1][j+1] == dp[i][j]+1){
	    			pi[i+1][j+1] = i;
	    			pj[i+1][j+1] = j;
	    		}
    		}
    	}
    }
    ll ni = N;
    ll nj = M;
    string res = "";
    while(ni!=0 || nj!=0){
    	ll si = pi[ni][nj];
    	ll sj = pj[ni][nj];
    	if(ni-si==1&&nj-sj==1){
    		res += s[si];
    	}
    	ni = si;
    	nj = sj;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;

    /*
    REP(i, N+1){
    	REP(j, M+1){
    		cout << dp[i][j] << " ";
    	}
    	cout << endl;
    }
    cout << dp[N][M] << endl;
    */
    return 0;
}

Measured memory_bytes: 215424
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
#include<iomanip>

using namespace std;

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

	string s, t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string u;
	cin >> u;
	if (u == s) cout << a - 1 << " " << b;
	else cout << a << " " << b - 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    string s;
    cin>>s;
    for(auto iter=s.begin(),last=s.end();iter!=last;++iter){
        cout<<'x';
    }
    cout<<endl;
    return 0;
}

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

int main() 
{
  string a;
  cin >> a;
  
  for (int i = 0; i < 3; i++)
  {
    if (a.at(i) == '1') cout << 9;
    else cout << 1;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
using namespace std;
 
int main(){
	long int N, M;
	cin >> N >> M;
	vector<int> A(N), B(N);
	for(int i=0;i<N;i++){
		cin >> A[i] >> B[i];
	}
	vector<pair<long int,long int>> buy(N);
	for(int i=0;i<N;i++){
		buy[i].first = A[i];
		buy[i].second = B[i];
	}
	sort(buy.begin(), buy.end());
	long int sum = 0;
	for(int i = 0;i<N;i++){
		if(M <= 0) break;
		long int m = min(buy[i].second,M);
		sum += buy[i].first * m;
		M -= m;
	}
	cout << sum << endl;
}

Measured memory_bytes: 2560
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	int n;
	scanf("%d", &n);
	vector < int > a(n + n);
	for (int i = 0; i < n + n; i++)
		scanf("%d", &a[i]);
	sort(all(a));
	ll ans = 0;
	for (int i = 0; i < n + n; i += 2)
		ans += a[i];
	cout << ans << endl;	

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,f[24][24],k[24],x,kl[24],pas;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a>>b>>x;
    for(i=0; i<a; i++){
        cin>>k[i];
        for(j=1; j<=b; j++){
            cin>>f[i][j];
        }
    }
    pas=1999999999;
    for(i=1; i<(1<<a); i++){
        for(j=1; j<=b; j++) kl[j]=0;
        zx=0;
        for(j=0; j<a; j++){
            if(((1<<j)&i)==0) continue;
            for(jj=1; jj<=b; jj++) kl[jj]+=f[j][jj];
            zx+=k[j];
        }
        for(jj=1; jj<=b; jj++){
            if(kl[jj]<x) break;
        }
        if(jj==b+1){
            if(pas>zx) pas=zx;
        }
    }
    if(pas==1999999999) cout<<-1; else cout<<pas;
    return 0;
}

Measured memory_bytes: 3608
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int countlower(string s){
	int n=s.size();
	int count=0;
	for(int i=0;i<n;i++){
		if(s[i]>='a'&&s[i]<='z'){
			count++;
		}
	}
	return count;
}
char findupper(string s){
	int n=s.size();
	char ans;
	for(int i=1;i<n;i++){
		if(s[i]>='A'&&s[i]<='Z'){
			ans=s[i];
			return ans;
		}
	}
}
int find(string s){
	int n=s.size();
	for(int i=0;i<n;i++){
		if(s[i]=='C'){
			return i;
		}
	}
}
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
    string s;
    cin>>s;
    if(s[0]!='A'){
    	cout<<"WA"<<endl;
    	return 0;
    }
    int c=countlower(s);
    if(c!=s.size()-2){
    	cout<<"WA"<<endl;
    	return 0;
    }
    char ch=findupper(s);
    if(ch!='C'){
    	cout<<"WA"<<endl;
    	return 0;
    }
    int ind=find(s);
    if(ind>=2&&ind<=s.size()-2){
    	cout<<"AC"<<endl;
    }
    else{
    	cout<<"WA"<<endl;
    }
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let s = scan!();

    if s.chars().nth(0) == s.chars().nth(s.len() - 1) {
        if s.len() % 2 == 0 {
            println!("First")
        } else {
            println!("Second")
        }
    } else {
        if s.len() % 2 == 0 {
            println!("Second");
        } else {
            println!("First")
        }
    }
}


Measured memory_bytes: 4352
var n,i:longint;
    a,x:longint;
    max,maxx,min:longint;
    z:longint;
begin
  read(n);
  min:=maxlongint;
  for i:=1 to n do
  begin
    read(a,x);
    if a>max then
    begin
      max:=a;
      maxx:=x;
    end;
    if x<min then min:=x;
  end;
  z:=0;
  if min<>maxx then
  begin
    writeln(1 div z);
    exit;
  end;
  writeln(max+maxx);
end.


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int l,r,d;
  cin>>l>>r>>d;
  int count=0;
  REP(i,l,r+1){
    if(i%d==0){
      count++;
    }
  }
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string n;
	cin>>n;
	if(n[0]=='7'||n[1]=='7'||n[2]=='7')
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
} 

Measured memory_bytes: 3604
#include <stdio.h>
#include <math.h>
int main(void){  
  /*
  float A;
  float B;
  scanf("%f %f", &A,&B);
  //float c = (B-1)/(A-1);
  int y = (int) ceil((B-1)/(A-1));	
  printf("%d\n", y);
  */
  
  int N;
  scanf("%d", &N);
  int H[N];
  int now_count=0;
  int max_count=0;
  for(int i=0;i<N;i++){
	scanf("%d ",&H[i]);
    if(i==0){
      now_count=0;
      max_count=0;
    }else{
      if(H[i-1]>=H[i]){
        now_count++;
      }else{
        if(max_count < now_count) max_count = now_count;
        now_count=0;
      }        
    }
  }
  if(max_count < now_count) max_count = now_count;
  
  printf("%d", max_count);

  return 0;
}

Measured memory_bytes: 512
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

H,W = map(int,readline().split())
H += 2; W += 2
grid = '#' * W
for _ in range(H-2):
    grid += '#' + readline().rstrip().decode() + '#'
grid += '#' * W

def bfs(start):
    INF = 10 ** 9
    dist = [INF] * (H*W)
    dist[start] = 0
    q = deque([start])
    while q:
        v = q.popleft()
        dv = dist[v]
        for move in (-1,1,W,-W):
            w = v + move
            if grid[w] == '#':
                continue
            dw = dv + 1
            if dw >= dist[w]:
                continue
            dist[w] = dw
            q.append(w)
    return max(x for x in dist if x < INF)

answer = max(bfs(v) for v in range(H*W) if grid[v] != '#')
print(answer)


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int gcd(int x,int y){
  int temp;
  while(x%y!=0){
    temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

int main(){
  int x,y,ans;
  cin>>x>>y;
   ans=gcd(x,y);
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> s, c;
  rep(i,0,m) {
    int ss, cc;
    cin >> ss >> cc;
    s.push_back(ss);
    c.push_back(cc);
  }

  // s が重複しているかつ c が異なるものが2つ以上
  int _1 = -1;
  int _2 = -1;
  int _3 = -1;
  bool ans = true;
  rep(i,0,m) {
    if (s[i] == 1) {
      if (_1 == -1) {
        _1 = c[i];
      } else if (_1 != c[i]) {
        ans = false;
      }
    }
    if (s[i] == 2) {
      if (_2 == -1) {
        _2 = c[i];
      } else if (_2 != c[i]) {
        ans = false;
      }
    }
    if (s[i] == 3) {
      if (_3 == -1) {
        _3 = c[i];
      } else if (_3 != c[i]) {
        ans = false;
      }
    }
  }

  if (n > 1 && _1 == 0) {
    ans = false;
  }

  if (_1 == -1) {
    _1 = 0;
  }
  if (_2 == -1) {
    _2 = 0;
  }
  if (_3 == -1) {
    _3 = 0;
  }

  if (ans) {
    if (n == 1) {
      cout << _1 << endl;
    } 
    if (n == 2) {
      if ((_1*10 + _2) >= 10) {
        cout << _1*10 + _2 << endl;
      } else {
        cout << _1*10 + _2 + 10 << endl;
      }
    }
    if (n == 3) {
      if ((_1*100 + _2*10 + _3) >= 100) {
        cout << _1*100 + _2*10 + _3 << endl;
      } else {
        cout << _1*100 + _2*10 + _3 + 100 << endl;
      }
    }
  } else {
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int x,y;
    for( ;scanf("%d %d",&x,&y) != EOF; )
    {
         if (x==0 && y==0)
        break;
        if ( x < y)
        printf("%d %d\n",x,y);
        else
        printf("%d %d\n",y,x);
        
    }
    return 0;
}


Measured memory_bytes: 1976
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vl rui(n+1);  // rui[i+1] : a[0]からa[i]までの累積和
    rep(i, n) {
        rui[i+1] = rui[i] + a[i];
    }

    vvl dp(n+1, vl(n+1));  // dp[l][r] : 区間[l,r)のスライムたちを1匹に合成するのに必要なコストの最小値
    exrep(len, 2, n) {  // 区間の長さが1のときはdp[l][r]=0なので区間の長さが2以上のときを考える 
        for(ll l = 0; l + len <= n; l++) {
            ll r = l + len;

            /* 区間[l,r)のスライムたちを1匹に合成する手順は以下。
               まず区間[l,x)と区間[x,r)に分ける。
               次にコストdp[l][x]で[l,x)のスライムたちを1匹のスライムAに合成する。
               同様にコストdp[x][r]で[x,r)のスライムたちも1匹のスライムBに合成する。
               スライムAとスライムBの大きさの合計は区間[l,r)のスライムたちの大きさの合計に等しい。
               よって、最初に位置x (l < x < r) で区間[l,r)を分けたときの最小コストは dp[l][x] + dp[x][r] + (sum_{l <= i < r} a[i]) となる。
               あとは位置xを全て試して、(sum_{l <= i < r} a[i]) = rui[r] - rui[l] と累積和で高速に求めればよい。 */

            ll u = INF;
            exrep(x, l+1, r-1) {  
                chmin(u, dp[l][x] + dp[x][r]);
            }

            dp[l][r] = u + rui[r] - rui[l];
        }
    }
    
    out(dp[0][n]);
    re0;
}

Measured memory_bytes: 1536
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, m, p, a = 0, b = 0;
  scanf("%lld%lld", &n, &m);
  bool flg[n];
  ll cnt[n];
  char s[10];
  for(i = 0; i < n; ++i) flg[i] = true, cnt[i] = 0;
  for(i = 0; i < m; ++i) {
    scanf("%lld%s", &p, s);
    if(flg[--p]) {
      if(s[0] == 'A') ++a, flg[p] = false;
      else ++cnt[p];
    }
  }
  for(i = 0; i < n; ++i) if(!flg[i]) b += cnt[i];
  printf("%lld %lld", a, b);
  return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/python3

import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    while True:
        H, W = read_ints()
        if (H, W) == (0, 0):
            break
        R = [inp() for _ in range(H)]
        S = inp()
        print(solve(H, W, R, S))


def solve(H, W, R, S):
    pos_map = {}
    for y in range(H):
        for x in range(W):
            c = R[y][x]
            if c != '_':
                pos_map[c] = (x, y)

    ans = 0
    cx = 0
    cy = 0
    for c in S:
        x, y = pos_map[c]
        ans += abs(x - cx) + abs(y - cy) + 1
        cx, cy = x, y

    return ans


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 6948
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define pint pair<int, int>
#define mp make_pair

using namespace std;

typedef long long ll;


int n, m;
vector<int> to[5005];
bool visited[5005] = {};
vector<int> ans;

void dfs(int now) {
	if (visited[now]) return;
	visited[now] = true;
	for (auto next : to[now]) {
		if (visited[next]) continue;
		dfs(next);
	}
	cout << now << endl;
	ans.push_back(now);
}

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

	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		to[b].pb(a);
	}

	for (int i = 1; i <= n; i++) {
		dfs(i);
	}

	for(int i=0; i<n-1; i++) {
		int s = ans[i + 1], t = ans[i];
		if (find(to[s].begin(), to[s].end(), t) == to[s].end()) {
			cout << 1 << endl;
			return 0;
		}
	}


	cout << 0 << endl;

	return 0;
}



Measured memory_bytes: 3800
class Integer
  def to_26_s(base=nil, offset=nil)
    offset ||= 'a'.ord
    base ||= 26
    value = self
    result = []
    while value > 0
      value -= 1
      result << (value%base+offset).chr
      value /= base
    end
    result.reverse.join
  end
end

num = gets.chomp.to_i
puts num.to_26_s

Measured memory_bytes: 14400
N = int(input())
L = list()
As, Bs= list(),list()
for i in range(N):
    A,B = map(int,input().split())
    L.append([A,B])
    As.append(A)
    Bs.append(B)

As.sort()
Bs.sort()
if N % 2 == 0:
    mins = (As[N//2] + As[N//2-1]) / 2.0
    maxs = (Bs[N//2] + Bs[N//2-1]) / 2.0
    print(int((maxs-mins)/0.5)+1)
else:
    mins,maxs = As[N//2], Bs[N//2]

    print(int(maxs-mins)+1)

Measured memory_bytes: 42688
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(100010);
    
    int tmp;
    rep(i,n){
        cin >> tmp;
        a[tmp]++;
    }
    int ans = a[0]+a[1];
    reps(i,1,100010){
        ans = max(ans,a[i-1]+a[i]+a[i+1]);
    }

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

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


void solve(std::string S, std::string T, long long A, long long B, std::string U){
    if (S==U)
        cout << A-1 << " " << B << endl;
    else if(T==U)
        cout << A  << " " << B-1 << endl;
    else 
        cout << A << " " << B << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    std::string U;
    std::cin >> U;
    solve(S, T, A, B, U);
    return 0;
}


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

using namespace std;

typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}

int main()
{
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> a;
    cin >> a >> b;
    if((10 * a + b) % 4){
        cout << "NO" << endl;
    }else
        cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
def getAB(r,books,N):
     if r==0:
         return(books[2*r],books[2*(N+r)])
     elif r==N:
         return(books[2*r-1],books[2*(N+r)-1])
     elif r==N+1:
         return (1,0)
     else:
         return(books[2*r-1]|books[2*r],books[2*(N+r)-1]|books[2*(N+r)])
         
#def getcostandarray(A,B,array,r,books):
#    if array==0:
#        if B:
#            return(3,2)
#        elif A:
#            nextB=getAB(r+1,books,N)[1]
#            if nextB:
#                return (2,1)
#            else:
#                return(2,0)
#        else:
#            return (1,0)
#    elif array==2:
#        if A:
#            return(3,0)
#        elif B:
#            nextB=getAB(r+1,books,N)[1]
#            if nextB:
#                return (2,2)
#            else:
#                return(2,1)
#        else:
#            return (1,2)
#    else:
#        if A==0 and B==0:
#            return (1,1)
#        elif A==1 and B==0:
#            return (2,0)
#        elif B==1 and A==0:
#            return (2,2)
#        else:
#            nextA=getAB(r+1,books,N)[0]
#            if nextA:
#                return (4,0)
#            else:
#                return (4,2)


Q=int(raw_input())
for i in range(Q):
    N=int(raw_input())
    books=[1 if x=='Y' else 0 for x in raw_input()]
    array=0
    Alist=[]
    Blist=[]
    firstB=-1
    lastB=-1
    for i in range(N+1):
        (A,B)=getAB(i,books,N)
        Alist.append(A)
        Blist.append(B)
        if B:
            if firstB==-1:
                firstB=i
            lastB=i
    if firstB!=-1:
        if 1 not in Alist[:firstB+1]:
            Alist[firstB]=1
        if 1 not in Alist[lastB:]:
            Alist[lastB]=1
    totalcost=N+sum(Alist)+sum(Blist)
        #(cost,array)=getcostandarray(A,B,array,i,books)
        #totalcost=totalcost+cost
        #print (A,B),(cost,array)
    #totalcost=totalcost+array
    print totalcost

Measured memory_bytes: 5544
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Miscalculation
 */
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		String exp = br.readLine();
		int ans = parseInt(br.readLine());

		int M, L;
		M = M(exp);
		L = L(exp);
		if (ans == M && ans == L) {
			System.out.println('U');
		} else if (ans == M) {
			System.out.println('M');
		} else if (ans == L) {
			System.out.println('L');
		} else {
			System.out.println('I');
		}
	}

	static int M(String exp) {
		char[] pri = new char[127];
		Arrays.fill(pri, (char) 3);
		pri['*'] = 2;
		pri['+'] = 1;
		pri[0] = 0;
		return calc(exp, pri);
	}

	static int L(String exp) {
		char[] pri = new char[127];
		Arrays.fill(pri, (char) 3);
		pri['*'] = 1;
		pri['+'] = 1;
		pri[0] = 0;
		return calc(exp, pri);
	}

	static int calc(String exp, char[] pri) {
		Deque<Character> stack = new ArrayDeque<>();
		Deque<Character> queue = new ArrayDeque<>();

		stack.push('\0');
		for (char c : exp.toCharArray()) {
			if (pri[c] > pri[stack.peek()]) {
				stack.push(c);
			} else {
				while (pri[c] <= pri[stack.peek()]) {
					queue.offer(stack.pop());
				}
				stack.push(c);
			}
		}
		while (stack.peek() != '\0') queue.offer(stack.pop());

		//
		String rpn = "";
		Deque<Integer> ans = new ArrayDeque<>();

		for (char c : queue) rpn += String.valueOf(c);
		for (char c : rpn.toCharArray()) {
			int a, b;
			switch (c) {
				case '*':
					b = ans.pop();
					a = ans.pop();
					ans.push(a * b);
					break;
				case '+':
					b = ans.pop();
					a = ans.pop();
					ans.push(a + b);
					break;
				default:
					ans.push(c - '0');
					break;
			}
		}
		return ans.peek();
	}
}

Measured memory_bytes: 24484
// LM10: The next Ballon d'Or
import java.util.*;
import java.io.*;
import java.math.*;
import static java.lang.Math.*;
public class Main
{
    static class FastReader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public 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();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
    }
    public static void main(String[] args)throws IOException {
        /*

        */
        PrintWriter pw = new PrintWriter(System.out);
        FastReader fr = new FastReader();
        int t=1;
        for(int ti=0;ti<t;++ti)
        {
            int n=fr.i();
            int [][] arr=new int[n][3];
            for(int ni=0;ni<n;++ni)
            {
                fr.scanIntArr(arr[ni]);
            }
            for(int ni=1;ni<n;++ni)
            {
                arr[ni][0]=max(arr[ni-1][1]+arr[ni][0],arr[ni-1][2]+arr[ni][0]);
                arr[ni][1]=max(arr[ni-1][0]+arr[ni][1],arr[ni-1][2]+arr[ni][1]);
                arr[ni][2]=max(arr[ni-1][1]+arr[ni][2],arr[ni-1][0]+arr[ni][2]);
            }
            int ans=0;
            ans=max(arr[n-1][0],max(arr[n-1][1],arr[n-1][2]));
            pw.println(ans);
        }

        pw.flush();
        pw.close();
    }
}

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

int main(){
    int n,count=0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a.at(i);
    for (int i = 1; i < n-1; i++){
        if ((a.at(i) > a.at(i-1) && a.at(i) < a.at(i+1)) || (a.at(i) < a.at(i-1) && a.at(i) > a.at(i+1))) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    int n, m;
    cin >> n >> m;
    int ans = 0;
    if (n != 1)
    {
        FOR(i, 1, m / n + 1)
        {
            if (m % i == 0)
            {
                ans = i;
            }
        }
    }
    else{
        ans=m;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

vector<int> v;

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

    ll r = 0, g = 0, b = 0;
    foreach(i, s){
        if(i == 'R'){
            r++;
        }else if(i == 'G'){
            g++;
        }else{
            b++;
        }
    }

    ll rgb = r * g * b;
    ll cnt = 0;
    rep(i, n){
        FOR(j, i + 1, n){
            if(s[i] == s[j]){
                continue;
            }
            int k = 2 * j - i;

            if(k >= n || s[k] == s[j] || s[k] == s[i]){
                continue;
            }

            cnt++;
        }
    }

    println(rgb - cnt);
}


Measured memory_bytes: 3600
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
 
import java.util.*;
class Main {
 
    static char[] xx = new char[] {'S','H','C','D'};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            if(n == 0 && x == 0) break;
            int count = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = i + 1; j <= n; j++) {
                    for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == x) {
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        }
 
    }
}


Measured memory_bytes: 26352