akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 1005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a[maxn];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int cnt = 0;
	for(int i=1;i<=n;i++){
		for(int j=n;j>i;j--){
			if(a[j-1] > a[j]){
				swap(a[j-1],a[j]);
				cnt++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d%c",a[i],i == n ? '\n' : ' ');
	}
	printf("%d\n",cnt);
	return 0;
}



Measured memory_bytes: 3180
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
const int MAX=1000;
const int VMAX=10000;
int n,A[MAX],s,B[MAX],T[VMAX+1];

int solve()
{
	int ans=0;
	bool V[MAX];
	for(int i=0;i<n;i++)
	{
		B[i]=A[i];
		V[i]=false;
	}
	sort(B,B+n);
	for(int i=0;i<n;i++)T[B[i]]=i;
	for(int i=0;i<n;i++)
	{
		if(V[i])continue;
		int cur=i;
		int S=0;
		int m=VMAX;
		int an=0;
		while(1)
		{
			V[cur]=true;
			an++;
			int v=A[cur];
			m=min(m,v);
			S+=v;
			cur=T[v];
			if(V[cur])break;
		}
		ans+=min(S+(an-2)*m,m+S+(an+1)*s);
	}
	return ans;
}
int main()
{
	cin>>n;
	s=VMAX;
	for(int i=0;i<n;i++)
	{
		cin>>A[i];
		s=min(s,A[i]);
	}
	cout<<solve()<<endl;
	return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;


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

    string s; cin >> s;

    rep(i,s.length()) cout << 'x';
    cout << '\n';


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

char str[200];
char goal_str[] = "CODEFESTIVAL2016";
int main() {
    int goal_len = strlen(goal_str);
    while (scanf("%s", str) != EOF) {
        int cnt = 0;
        for (int i = 0; i < goal_len; i++) {
            if (goal_str[i] != str[i]) {
                cnt ++;
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}



Measured memory_bytes: 128
import 'dart:io';

void main() {
  List<String> s = stdin.readLineSync().split('');
  List<String> t = stdin.readLineSync().split('');
  List<bool> check = [];

  for (int i = 0; i < s.length; i++) {
    if (s[i] == t[i]) {
      check.add(true);
    }
  }
    if(check.length == s.length) {
      print('Yes');
    } else {
      print('No');
    }
}


Measured memory_bytes: 13156
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

struct Data
{
    ll k;
    vector<ll> s;
    ll p;
};

void solve()
{
    ll N, M;
    cin >> N >> M;
    vector<Data> data(M);
    vector<ll> P(M);
    for (ll i = 0; i < M; i++)
    {
        ll k;
        cin >> k;
        vector<ll> vec(k);
        for (ll j = 0; j < k; j++)
        {
            cin >> vec[j];
            vec[j]--; // index合わせる
        }
        data[i] = {k, vec, 0};
    }

    for (ll i = 0; i < M; i++)
    {
        cin >> data[i].p;
    }

    ll imax = 1 << N;
    ll mask = 0b0000000001;
    ll allCount = 0;
    for (ll i = 0; i < imax; i++)
    {
        vector<ll> swt(N);
        for (ll j = 0; j < N; j++)
        {
            swt[j] = (i >> j) & mask;
            // cout << swt[j];
        }
        // cout << endl;

        bool isOK = true;
        // 全ての電球についてOKか調べる
        for (auto aData : data)
        {
            ll count = 0;
            for (auto aS : aData.s)
            {
                count += swt[aS];
            }

            if (count % 2 != aData.p)
            {
                isOK = false;
                break;
            }
        }

        if (isOK)
        {
            allCount++;
        }
    }

    cout << allCount << endl;

    return;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
ll a[200005],b[200005],c[200005];
int main()
{
	ll n,cnt=0;
	scanf("%lld",&n);
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(b[a[i]]==0){
			c[cnt++]=a[i];
		}
		b[a[i]]++;
	}
	ll sum=0;
	for(int j=0;j<cnt;j++){
		if(b[c[j]]>=2)
			sum+=(b[c[j]]-1)*b[c[j]]/2;
	}
	for(int i=0;i<n;i++){
		if(b[a[i]]-1>=1){
			printf("%lld\n",sum-b[a[i]]+1); 
		}else{
			printf("%lld\n",sum); 
		}
	}
	return 0;
}

Measured memory_bytes: 7424
def factors(N): #約数を全て求める。ただし、順不同
    from collections import deque
    ret = deque()
    middle = int( N**(1/2))
    for i in range(1, middle):
        if N%i == 0:
            ret.append(i)
            ret.append(N//i)
            
    if N%middle == 0:
        ret.append(middle)
        if middle != N//middle:
            ret.append(N//middle)
    return ret

def main():
    N = int( input())
    ans = 0
    for m in factors(N):
        if m==1:
            continue
        if N//(m-1)*m == N:
            ans += m-1
    print(ans)
    
if __name__ == '__main__':
    main()


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

int main() {

  	int y,x,T,A,B;
  cin >>A >> B >>T;
 	 x=A;
     y=0;
   while(x <T+1){
  	y+=B;
   x+=A;
 }
  cout << y << endl;	
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n;
	int i;
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		
		int ans1,ans2=0;
		for(i=0;i<n;i++)
		{
			int m,a,aa;
			cin >> m >> a >> aa ;
			if(a+aa>ans2)
			{
				ans1=m;
				ans2=a+aa;
			}
		}
		cout << ans1 << " " << ans2 << endl;
	}
}

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

unsigned long long ceil(unsigned long long a, unsigned long long b){
	return (a % b ? a / b + 1 : a / b);
}

int main(){
	unsigned long long  n; cin >> n;
	unsigned long long   a, b; cin >> a >> b;
	unsigned long long  nowt = a, nowa = b;
	for(unsigned long long  i = 1; i < n; ++i){
		cin >> a >> b;
		unsigned long long j = max<unsigned long long>(ceil(nowt, a), ceil(nowa, b));
		nowt = a * j;
		nowa = b * j;
	}
	cout << nowt + nowa << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    string S;
    cin>>S;
    int K;
    cin>>K;
    bool ans=false;
    rep(i,S.size()){
        if(S[i]=='1'&&K!=i+1){
        }
      else{
            cout<<S[i]<<endl;
            ans=true;
            break;
        }
    }
    if(ans==false){
        cout<<1<<endl;
    }
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
int main() {
  cin >> n;
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
import sys
import numpy as np

grid = np.array(sys.stdin.read().split(), dtype=np.int8).reshape(3, 3)

def main():
    grid[:, :] -= grid[0]
    grid[:, :] -= grid[:, 0][:, None]
    print('No' if np.any(grid) else 'Yes')

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 12232
#!/usr/bin/env python3
while True:
    T, P, R = map(int, input().split())
    if T == 0:
        exit()
    ans = [(0, 0, i) for i in range(T)]
    cs = [[0] * P for _ in range(T)]
    ws = [[0] * P for _ in range(T)]
    for _ in range(R):
        tid, pid, time, message = input().split()
        tid = int(tid) - 1
        pid = int(pid) - 1
        time = int(time)
        if message == 'CORRECT':
            s, p, t = ans[tid]
            if cs[tid][pid] > 0:
                continue
            ans[tid] = (s - 1, p + ws[tid][pid] * 1200 + time, tid)
            cs[tid][pid] += 1
        else:
            ws[tid][pid] += 1
    for s, p, t in sorted(ans):
        print(t + 1, -s, p)



Measured memory_bytes: 5648
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define inf LLONG_MAX
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<dob,ll> P;
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll fac[M6],not_prime[M6],ar[M6],a[200],b[200],x[200],pred[200][200];
ll power(ll x,ll n)
{   if(n==0) return 1;
    else if(n%2 == 0) return power((x*x)%M,n/2);
    else return (x*power((x*x)%M,(n-1)/2))%M;
}
void fact(){
    fac[0]=1;
    for(ll i=1;i<M6;i++) fac[i]=(i*fac[i-1])%M;
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<M6;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=MAX;i+=p) not_prime[i]=1;
        }
    }
}
ll modi(ll a, ll m){
    ll m0 = m, t, q; ll x0 = 0, x1 = 1;
    if (m == 1) return 0;
    while (a > 1){  q = a / m; t = m; m = a % m, a = t;t = x0;x0 = x1 - q * x0; x1 = t;}
    if (x1 < 0) x1 += m0;return x1;
}
vector<list< P > > g(M5);
int main(){
    buf; 
    //sieve(); 
    //fact();
    ll i,j,l,n,test,flag,t,ans,s,d,p,k,m; string s1,s2;
    test=1;    
    while(test--){
        cin>>n;
        for(i=1;i<=3500;i++){
            for(j=1;j<=3500;j++){
                if(4*i*j-n*j-n*i>0&&(n*i*j)%(4*i*j-n*j-n*i)==0)
                {cout<<i<<" "<<j<<" "<<(n*i*j)/(4*i*j-n*j-n*i); return 0;}
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>

using namespace std;
int main()
{
	char s[4];
	cin >> s;
	sort(s, s + 4);
	if (s[0] == s[1] && s[2] == s[3]) {
		if (s[0] == s[2]) {
			cout << "No" << endl;
		}
		else { cout << "Yes" << endl; }
	}
	else { cout << "No" << endl; }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

ll N, S;
vector<ll> A;

const int mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    cin >> N >> S;
    A.resize(N);
    rep(i, N) cin >> A[i];

    vector<mint> q(S + 1);
    mint ans = 0;
    rep(i, N) {
        q[0] += 1;
        vector<mint> q2(S + 1);
        rep(j, S + 1) {
            q2[j] += q[j]; // q *= (1 + x^A[i])
            if (j + A[i] <= S) q2[j + A[i]] += q[j];
        }
        q = q2;

        ans += q[S];
    }

    cout << ans << endl;
}

Measured memory_bytes: 3668
k , n = map(int, input().split())
arr = list(map(int, input().split()))

dist = 0

for i in range(len(arr)):
    if i is 0:
        if k - arr[i-1] + arr[i] > dist:
            dist = k - arr[i-1] + arr[i]
    
    if arr[i] - arr[i-1] > dist:
        dist = arr[i] - arr[i-1]

print(k - dist)

Measured memory_bytes: 26060
from fractions import gcd
def lcm(x, y):
  return (x * y) // gcd(x, y)
def num(n1,n2,n3):
  return n1-(n1//n2)-(n1//n3)+(n1//lcm(n2,n3))
A,B,C,D=map(int,input().split())
print(num(B,C,D)-num(A-1,C,D))

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) v.begin(),v.end()
using vint=vector<int>;

int N,L;

vector<int>lis[444444];
int acc[444444];
signed  main(){
  cin>>N>>L;
  vector<int> l(N),r(N);
  for(int i=0;i<N;i++)cin>>l[i]>>r[i];
  
   
  vector<int>vs;
  vs.push_back(0);vs.push_back(L);for(int i=0;i<N;i++)vs.push_back(l[i]),vs.push_back(r[i]);
  sort(vs.begin(),vs.end());vs.erase(unique(vs.begin(),vs.end()),vs.end());
  L=lower_bound(vs.begin(),vs.end(),L)-vs.begin();
  for(int i=0;i<N;i++){
    l[i]=lower_bound(vs.begin(),vs.end(),l[i])-vs.begin();
    r[i]=lower_bound(vs.begin(),vs.end(),r[i])-vs.begin();
  }

  rep(i,N)lis[l[i]].pb(r[i]);

  int cur=0;
  int v=0;
  int ans=0;
  while(v!=L){
    int vv=0;
    while(cur<=v){
      for(auto a:lis[cur])vv=max(vv,a);
      cur++;
    }
    v=vv;
    ans++;
  }
  cout<<ans<<" ";
  rep(i,N)acc[l[i]]++,acc[r[i]]--;
  
  ans=0;
  rep(i,vs.size()-1){
    acc[i+1]+=acc[i];
    ans=max(ans,N-acc[i]+1);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 28332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

unsigned euclidean_gcd(unsigned a, unsigned b)
{
    if (a < b)
        return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    int count = 0;
    ll GCD_cd = euclidean_gcd(c, d);
    ll LCM_cd = c * d / GCD_cd;
    ll to_a_1 = a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / LCM_cd;
    ll to_b = b - b / c - b / d + b / LCM_cd;

    cout << to_b - to_a_1 << endl;
    return 0;
}

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

int main(){

    int n, v;
    cin >> n;

    vector<int> even(1e5+1, 0), odd(1e5+1, 0);
    for(int i = 0; i < n / 2; i++){
        cin >> v;
        even[v]++;
        cin >> v;
        odd[v]++;
    }

    vector<pair<int, int> > even_pair, odd_pair; // pair(count, index)
    for(int i = 1; i <= 1e5; i++){
        even_pair.push_back(make_pair(even[i], i));
        odd_pair.push_back(make_pair(odd[i], i));
    }

    sort(even_pair.rbegin(), even_pair.rend());
    sort(odd_pair.rbegin(), odd_pair.rend());

    if(even_pair[0].second != odd_pair[0].second) cout << n - (even_pair[0].first + odd_pair[0].first) << endl;
    else cout << n - max(even_pair[0].first + odd_pair[1].first, even_pair[1].first + odd_pair[0].first) << endl;

    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N;
bool found(const VVI& post, const string& s){
  int p = 0;
  REP(j,SZ(s)){
	int ix = s[j] - 'a';
	p = post[p][ix] + 1;
	if(p >= N+1) return false;
  }
  return true;
}

void incr(string& s){
  int n = SZ(s);
  if(s == string(n, 'z')){
	s = string(n+1, 'a');
	return;
  }
  for(int i=n-1;i>=0;--i)
	if(s[i] == 'z'){
	  s[i] = 'a';
	}
	else{
	  s[i]++;
	  return;
	}
}

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

  string S;
  cin >> S;
  N = SZ(S);

  VVI post(N+1, VI(26,N));
  for(int i=N-1;i>=0;--i){
	REP(j,26) post[i][j] = post[i+1][j];
	post[i][S[i]-'a'] = i;
  }
  VVI pre(N+1, VI(26,-1));
  REP(i,N){
	if(i) REP(j,26) pre[i][j] = pre[i-1][j];
	pre[i][S[i]-'a'] = i;
  }

  VVI dp(N+1, VI(26,-1));
  for(int c=0;c<26;++c){
	if(pre[N-1][c] == -1){
	  cout << string(1,'a' + c) << endl;
	  return 0;
	}
	dp[1][c] = pre[N-1][c];
  }

  int ans_len = -1, ans_c = -1;
  for(int l=2;l<N;++l){
	REP(c,26){
	  int mn = N;
	  REP(c_,26){
		int ix = dp[l-1][c_];
		if(ix == 0 || pre[ix-1][c] == -1){
		  mn = -1;
		  break;
		}
		mini(mn, pre[ix-1][c]);
	  }
	  if(mn == -1){
		ans_len = l;
		ans_c = c;
		break;
	  }
	  dp[l][c] = mn;
	}
	if(ans_len >= 0) break;
  }

  int p = 0;
  string ans = string(1, 'a' + ans_c);
  for(int l=1;l<ans_len;++l){
	int ix = post[p][ans_c];
	REP(c,26){
	  if(ix >= dp[ans_len-l][c]){
		ans_c = c;
		break;
	  }
	}
	ans += string(1, 'a' + ans_c);
	p = post[ix+1][ans_c];
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 80148
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
 
int main(){
    string A,B;
    cin >> A;
    B = A;
    if(A.at(0) == B.at(2) && A.at(1) == B.at(1) && A.at(2) == B.at(0)){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

using namespace std;

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)

int findOptimalValue(int i, int j, bool chance, vector< vector<pii> > &dp, vector<int> &A)
{
    if(i>j || i >= A.size() || j < 0)
        return 0;
    if(chance)
    {
        if(dp[i][j].x == -1)
            dp[i][j].x = max(A[i] + findOptimalValue(i+1, j, 0, dp, A), A[j] + findOptimalValue(i, j-1, 0, dp, A));
        return dp[i][j].x;
    }
    else
    {
        if(dp[i][j].y == -1)
            dp[i][j].y = min(findOptimalValue(i+1, j, 1, dp, A) - A[i], findOptimalValue(i, j-1, 1, dp, A) - A[j]);
        return dp[i][j].y;
    }
}

void solve()
{
    int n, i, j;
    cin>>n;
    vector<int> A(n);
    for(i = 0; i < n; i++)
        cin>>A[i];
    vector< vector<pii> > dp(n, vector<pii> (n, make_pair(-1,-1)));
    i = 0; j = n-1;
    // for X-Y we select X when boolean is 1
    cout<<findOptimalValue(i, j, 1, dp, A)<<endl;
}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc;
	tc = 1;
    // cin>>tc;
    while(tc--)
        solve();
    return 0;
}


Measured memory_bytes: 141312
from itertools import combinations_with_replacement

n,m,q = map(int,input().split())
abcd = [list(map(int,input().split())) for _ in range(q)]

ans = 0

for l in combinations_with_replacement(range(m), n):
    sum = 0
    for a,b,c,d in abcd:
        if l[b-1] - l[a-1] == c:
            sum += d
        
    ans = max(ans, sum)

print(ans)

Measured memory_bytes: 9176
#include <cstdio>
#include <random>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <chrono>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long


using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;





signed main()
{
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	std::vector<int> v(n);
	for(int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	int res = 0;
	for(int i = 0; i < 60; ++i) {
		int t = 0;
		for(int j = 0; j < n; ++j) {
			if(v[j] >> i & 1) {
				++t;
			}
		}
		res += (1ll << i) % M * t % M * (n - t) % M;
		res %= M;
	}
	cout << res % M << endl;



    
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    ll H[N];
    for(int i = 0; i < N; ++i) cin >> H[i];
    int A[M], B[M];
    for(int i = 0; i < M; ++i) cin >> A[i] >> B[i];

    map<int,ll> m;
    int ans = 0;
    
    //道を整理
    for(int i = 0; i < M; ++i){
        //key add, upd
        if(m.count(A[i]) == 0) m.insert(make_pair(A[i],H[B[i]-1]));
        else m[A[i]] = max(m[A[i]], H[B[i]-1]);
        
        if(m.count(B[i]) == 0) m.insert(make_pair(B[i],H[A[i]-1]));
        else m[B[i]] = max(m[B[i]], H[A[i]-1]);
    }

    //判定
    for(int i = 1; i <= N; ++i){
        if(m.count(i) == 0) ans++;
        else if(H[i-1] > m[i]) ans++;
    //cout << i << ":" << H[i-1] << "," << m[i] << "," << ans << endl;
    }

    cout << ans << endl;
}

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

int main()
{
    int n, m; cin>>n>>m;
    vector<string> a(n+2, string(m+2, ' '));

    for(int i=1; i<=n; ++i) {
        string t; cin>>t;
        for(int j=1; j<=m; ++j) a[i][j]=t[j-1];
    }

    for(int r=1; r<=n; ++r) for(int c=1; c<=m; ++c) if (a[r][c]=='.') {
        int x=0;
        for(int i=-1; i<2; ++i) for(int j=-1; j<2; ++j) if (i|j)
            x+=a[r+i][c+j]=='#';
        a[r][c]='0'+x;
    }

    for(int i=1; i<=n; ++i)
        cout<<a[i].substr(1, m)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();return 0;}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
#define foreach(a,A) for(auto &a:A)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

void solve(){
    ll a, b, c, k; cin >> a >> b >> c >> k;
    ll res = 0;
    if(k <= a){
        res = k;
    } else if(k <= a + b){
        res = a;
    } else {
        res = a - (k - a - b);
    }

    cout << res << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int d[4] = {};
    rep(i, 0, 4) cin >> d[i];
    rep(i, 0, 4){
        rep(j, 0, i){
            int tmp = d[j] * (1LL << (i - j));
            chmin(d[i], tmp);
        }
    }
    int n;
    cin >> n;
    n *= 4;
    int ans = 0;
    repb(i, 3, 0){
        if(n >= (1LL << i)){
            int q = n / (1LL << i);
            n %= (1LL << i);
            ans += d[i] * q;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())

a2=sorted(a)
amax1=a2[n-1]
amax2=a2[n-2]

for i in range(n):
    if a[i]==amax1:
        print(amax2)
    else:
        print(amax1)
        

Measured memory_bytes: 15752
output = []
text = ''
while True:
    input_data = input()
    # 文字列か数値かを判定
    if input_data != '-':
        text = list(input_data)
        num_of_shuffle = int(input())
        for i in range(num_of_shuffle):
            index_num = int(input())
            move_string = text[:index_num]
            text[:index_num] = []
            text.extend(move_string)
        output.append(text)
    else :
        break

for string in output:
    print(''.join(string))


Measured memory_bytes: 5596
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S, T = readline().strip().split()
    print(T + S)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61900
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
using namespace std;
struct node{string s;}b[1000000];
bool cmp(node a, node b)
{
	return a.s < b.s;
}
int main()
{

	
	int n,l;
	cin >> n >> l;
	for(int i = 1;i <= n;++i)
		cin >> b[i].s;
	sort(b + 1,b + 1 + n,cmp);
	for(int i = 1;i <= n;++i)
		cout << b[i].s;
	return 0;
}



Measured memory_bytes: 8064
n = int(input())
red = {}
blue = {}
for i in range(n):
	x, y = map(int, input().split())
	red[x] = y
for i in range(n):
	x, y = map(int, input().split())
	blue[x] = y

sortBlue = sorted(blue.items(), key=lambda x:x[0])
count = 0
for i in range(n):
	pair = {}
	for k, v in red.items():
		if (k < sortBlue[i][0]) and (v < sortBlue[i][1]):
			pair[k] = v
	if pair:
		sortPair = sorted(pair.items(), key=lambda x:-x[1])
		count += 1
		red.pop(sortPair[0][0])
		
print(count)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
int main(){
    int A,B,C;
    scanf("%d %d",&A,&B);
    C=(B-1)/(A-1);
    if((B-1)%(A-1)!=0)
    {
        C++;
    }
    printf("%d",C);
    return 0;
}


Measured memory_bytes: 128
corr=[]#正解した人
n,k,q=input().split()
n=int(n)#n人の人がいる
k=int(k)#もともとのポイント
q=int(q)#正解した数
for i in range(q):
	a=input()
	corr.append(int(a)-1)
ptcp=[]#それぞれのポイント
for i in range(n):
	ptcp.append(k-q)
for i in range(q):
	ptcp[corr[i]]+=1
win=[]
for i in range(n):
	if ptcp[i]<=0:
		win.append("No")
	else:
		win.append("Yes")
for i in win:
	print(i)

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

int main() {
	string s,s1,s2;
	getline(cin,s);
	s2=s1=s;
	while(s1.find("apple")!= std::string::npos){
		s.replace(s1.find("apple"),5,"peach");
		s1.replace(s1.find("apple"),5,"peach");
	}
	while(s2.find("peach")!= std::string::npos){
		s.replace(s2.find("peach"),5,"apple");
		s2.replace(s2.find("peach"),5,"apple");
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,i;
	cin>>n;
	ll x,s1=0,s2=0,m=0;
	for(i=1; i<=n; i++){
		cin>>x;
		s1+=x;
		if(x<m)	s2+=m;
		else	s2+=x;
		m=max(m,x);
	}	
	cout<<s2-s1;
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
string a;
long long vis[1009];
long long n;
long long ans1=0,ans=0;
int main()
{
    cin>>a;
    n=a.size();
    for(int i=0; i<n; i++)
        vis[a[i]]++;
    for(int i='a'; i<='z'; i++)
        if(vis[i]!=0&&vis[i]!=1)
            ans=(long long )ans+((vis[i]*(vis[i]-1))/2);
    ans1=(long long)(n*(n-1))/2;
    ans1=(long long ) ans1+1;
    cout<<(long long)ans1-ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

const ll INF = 1LL << 60;

int main(){
  int n,m;
  cin >> n >> m;
  const int NMAX = 1000;
  const int MMAX = 2000;
  int a[MMAX], b[MMAX];
  ll c[MMAX];
  
  for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i] >> c[i];
    c[i] = -c[i];
  }
  
  ll dist[NMAX];
  
  rep(i,n) dist[i] = INF;
  dist[0] = 0;
  
  rep(loop,n-1){
    rep(i,m){
      if(dist[a[i]-1] == INF) continue;
      if(dist[b[i]-1] > dist[a[i]-1]+c[i]){
        dist[b[i]-1] = dist[a[i]-1]+c[i];
      }
    }
  }
  
  ll ans = dist[n-1];
  bool negative[NMAX];
  rep(i,n) negative[i] = false;
  
  rep(loop,n){
    rep(i,m){
      if(dist[a[i]-1] == INF) continue;
      if(dist[b[i]-1] > dist[a[i]-1] + c[i]){
        dist[b[i]-1] = dist[a[i]-1] + c[i];
        negative[b[i]-1] = true;
      }
      if(negative[a[i]-1] == true){
        negative[b[i]-1] = true;
      }
    }
  }
  
  if(negative[n-1]) cout << "inf" << endl;
  else cout << -ans << endl;
  
  
  return 0;
}

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

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=0;i<k;i++){
        if(i%2==0){
            if(a%2==1)a--;
            b+=a/2;
            a-=a/2;
        }
        else{
            if(b%2==1)b--;
            a+=b/2;
            b-=b/2;
        }
    }
    cout<<a<<" "<<b;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    
    cout << (n - k + 1) << endl;
    return 0;
}


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

int main()
{
    int a,b,c,d;
    while(scanf("%d%d%d%d",&a,&b,&c,&d)==4)
        printf("%d\n",min(a,b)+min(c,d));
    return 0;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    ll ans = 0;
    rep(i, n){
        rep(j, i){
            rep(k, j){
                if(a[i] == a[j] || a[j] == a[k] || a[i] == a[k]) continue;
                if(a[k] + a[j] > a[i]){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
import queue

k = int(input())
q = queue.Queue()

for i in range(1,10):
    q.put(i)

for i in range(1,k):
    l = q.get()
    m = l % 10
    if (m != 0):
        q.put(l * 10 + m - 1)
    q.put(l * 10 + m)
    if (m != 9):
        q.put(l * 10 + m + 1)

print(q.get()) 

Measured memory_bytes: 12480
typedef long long ll;

#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  vector<pair<int, int> > v(n);
  REP(i,n){
    v[i].second = getInt();
    v[i].first = getInt();
  }
  sort(v.begin(), v.end());
  ll sum = 0;
  REP(i,n){
    sum += v[i].second;
    if(sum > v[i].first){
      puts("No");
      return 0;
    }
  }
  puts("Yes");

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)
#define myforInv(i,N) for(i=N;i>=0;i--)
#define myforFLInv(i,f,l) for(i=f;i>l;i--)
#define INF 100000000
using namespace std;
int D,G,p[10],c[10];

int getMinimumNumForTheIndex(int score, int num, int index){
	score -= c[index]+100*(index+1);
	int numOfReducedProblem = 0;
	while(score >= G && numOfReducedProblem < p[index]){
		score -= 100*(index+1);
		numOfReducedProblem++; 
	}
	if(numOfReducedProblem == p[index])return INF;
	return num - numOfReducedProblem;
}

int getMinimumNumForTheIndexList(int score, int num, vector<int> usedIndexList){
	int i,usedIndex,ans=INF;
	myfor(i,usedIndexList.size()){
		usedIndex = usedIndexList[i];
		ans = min(ans, getMinimumNumForTheIndex(score,num,usedIndex));
	}
	return ans;
}

int dfs(int score,int num,int index, vector<int> usedIndexList){
	int i,ans=INF;
	int newScore = score + 100*(index+1)*p[index] + c[index];
	if(index + 1 < D)ans = dfs(score,num,index+1, usedIndexList);
	usedIndexList.push_back(index);
	if(index + 1 < D) ans = min(ans,dfs(newScore,num+p[index],index+1, usedIndexList));
	if(newScore>=G){
		return min(ans,getMinimumNumForTheIndexList(newScore,num+p[index],usedIndexList));
	}
	return ans;
}

int main(){
	int i;
	cin >> D >> G;
	myfor(i,D)cin >> p[i] >> c[i];
	int point,points[10];
	int ans;
	vector<int> v;
	ans = dfs(0,0,0,v);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll const_inf = 1e9+7;
const int const_mod = 13;

int main(int argc, char **argv)
{
	string s; cin >>s;
	reverse(s.begin(), s.end());
	
	int n=s.length();
	ll **dp = new ll*[n+1];
	ll digit=1;
	for(int i=0; i<n+1; i++) dp[i] = new ll[const_mod];
	for(int i=0; i<n+1; i++) for(int j=0; j<const_mod; j++) dp[i][j] = 0;
	//cout << s << "\n";
	for(int i=0; i<n+1; i++){
		if(i==0){
			dp[0][0]=1;
		}else{
			for(int j=0; j<const_mod; j++){
				if(s[i-1]=='?'){
					for(ll k=0; k<10; k++){
						dp[i][(j+k*digit)%const_mod] += dp[i-1][j];
						dp[i][(j+k*digit)%const_mod] %= const_inf;
					}
				}else{
					int k = s[i-1]-'0';
					dp[i][(j+k*digit)%const_mod] += dp[i-1][j];
					dp[i][(j+k*digit)%const_mod] %= const_inf;
				}
			}
			digit*=10;
			digit%=const_mod;
		}
	}
	cout << dp[n][5] << "\n";
	return 0;
}



Measured memory_bytes: 12032
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))

def main():
  s = input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
  print('YES' if len(s) == 0 else 'NO')
if __name__ == '__main__':
  main()

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define MOD 1000000007
#define PI 3.14159265358979

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

using namespace std;

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;

template < typename T >
bool chmin(T &x, const T &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T >
bool chmax(T &x, const T &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
int main() {
	string S;
	cin >> S;
	int N = S.size() + 1;
	vector< int > A(N, 0);
	for (int i = 0; i < N; i++) {
		if (i == 0 & S[0] == '<' || i == N - 1 && S[i - 1] == '>' ||
			0 < i && i < N - 1 && S[i - 1] == '>' && S[i] == '<') {
			A[i] = 0;
			for (int j = i + 1; j < N; j++)
				if (S[j - 1] == '<') {
					if (!chmax(A[j], A[j - 1] + 1))
						break;
				}
			for (int j = i - 1; j >= 0; j--)
				if (S[j] == '>') {
					if (!chmax(A[j], A[j + 1] + 1))
						break;
				}
		}
	}
	ll ans = 0;
	rep(i, N) ans += A[i];
	/*
	rep(i, N - 1) {
		cout << A[i] << S[i];
	}
	cout << A[N - 1] << endl;
	*/
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2820
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

string s;
int n, k;

int ans = 0;

void rec(int pos, int fl, int cnt, int c) {
	if (pos == n) {
		if (cnt == k) ans += c;
	} else {
		int v = s[pos] - '0';
		if (cnt < k) {
			if (fl) {
				rec(pos + 1, fl, cnt + 1, c * 9);
			} else if (v > 0) {
				rec(pos + 1, 1, cnt + 1, c * (v - 1));
				rec(pos + 1, 0, cnt + 1, c);
			}
		}
		rec(pos + 1, fl | (v > 0), cnt, c);
	}
}

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

	cin >> s >> k;
	n = (int)s.size();
	rec(0, 0, 0, 1);
	cout << ans << endl;
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())
x -= 1
y -= 1

ans = [0] * n
for i in range(n):
    for j in range(i + 1, n):
        d = min(abs(i - j),
                abs(i - x) + 1 + abs(y - j),
                abs(i - y) + 1 + abs(x - j))
        ans[d] += 1

for k in range(1, n):
    print(ans[k])


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(a, b);
  FOR(i, 1, 1000) {
    if (b - a == i) {
      int ans = i * (i - 1) / 2 - a;
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}



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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}


// end of Template
int n,m;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    cout<<(n-1)*(m-1)<<newl;
}


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


using namespace std;


#include <functional>

#include <iostream>

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int main() {
  int n,m,x; cin>>n>>m>>x;                                                                                             vector<int> cost(n);                                                                                                 vector<int> a[12];                                                                                                   long mp = 99999999;                                                                                                  rep(i,n){                                                                                                              cin>>cost[i];
    rep(j,m){                                                                                                              int aa;                                                                                                              cin >> aa;                                                                                                           a[i].push_back(aa);
    }
  }
  for(int i=1;i<=n;i++){                                                                                                 foreach_comb(n, i, [&](int *indexes) {                                                                                  long price=0;                                                                                                        map<int,long> mmm;
       rep(j,i){                                                                                                                 price+=cost[indexes[j]];
            rep(k,m){                                                                                                              mmm[k] += a[indexes[j]][k];                                                                                        }
       }                                                                                                                    bool flag = true;
       rep(k,m){                                                                                                                 if(mmm[k] < x){flag=false;}
       }                                                                                                                     if(flag){                                                                                                                mp=min(mp,price);
        }
    });
 }
 if(mp < 99999999) {cout << mp << endl;}
 else{cout << -1 << endl;}

}

Measured memory_bytes: 3560