akhauriyash/Code-Regression huggingface dataset:
h,w,k=map(int,input().split())
a=[list(input())for i in range(h)]
b=[[1]*w for i in range(h)]
c=0
for i in range(h):
    if c:
        break
    for j in range(w):
        if a[i][j]=="S":
            c=1
            p=[i,j]
            b[i][j]=0
def f(x,y):
    return min(x,w-y-1,y,h-x-1)
an=f(p[0],p[1])
q=[p]
c=0
while q and c!=k:
    c+=1
    d=[]
    x=[0,0,1,-1]
    y=[1,-1,0,0]
    for i,j in q:
        for s,t in zip(x,y):
            if 0<i+s<h-1 and 0<j+t<w-1:
                if b[i+s][j+t]:
                    if a[i+s][j+t]==".":
                        an=min(an,f(i+s,j+t))
                        b[i+s][j+t]=0
                        d.append([i+s,j+t])
            else:
                if a[i+s][j+t]==".":
                     print(1)
                     exit()
    q=d[::]
print(2+(an-1)//k)

Measured memory_bytes: 14032
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<cstdlib>
#include <memory>
using namespace std;

typedef struct Node {
    int key;
    Node *parent, *left, *right;
} Node;

Node *root, *NIL;

void insert(int k) {
    Node *x = root;
    Node *y = NIL;
    Node *z = new Node;

    z = (Node *)malloc(sizeof(Node));
    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z -> parent = y;
    if (y == NIL) root = z;
    else {
        if ( z->key < y->key ) y->left = z;
        else y->right = z;
    }
}

void inorder(Node *u) {
    if ( u == NIL ) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if ( u == NIL ) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ) {
        cin >> com;
        if ( com == "insert" ) {
            scanf("%d", &x);
            insert(x);
        } else if ( com == "print" ) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


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

int main() {
	int q[10001], w[10001];
	
	int x = 1;
	while (1) {
		int n;
		int a = 0;
		int b = 0;
		cin >> n;
		if (n == 0) {
			break;
		}

		for (int i = 1; i <= n; ++i) {
			int c, d;
			cin >> c >> d;
			if (c == d) {
				a = a + c;
				b = b + d;
			}
			else if (c > d) {
				a = a + c + d;
			}
			else {
				b = b + c + d;
			}
		}
		q[x] = a;
		w[x] = b;
		x = x + 1;
	}
	for (int j = 1; j <= x-1; ++j) {
		cout << q[j]<<" "<< w[j] << endl;
	}
}

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


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

	set<string> top5;
	for(int i=0;i<s.size();i++) {
		for(int j=1;i + j <= s.size() && j <= K;j++) {
			top5.insert(s.substr(i, j));
			while(top5.size() > K) {
				top5.erase(--top5.end());
			}
		}
	}

	cout << *(--top5.end()) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> v(n);
    REP(i,n) cin >> v[i];

    ll ans = 0;
    REP(i,n-1) FOR(j,i+1,n) ans += v[i] * v[j];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

double p[2999];
double dp[3000][3000];

int main() {
    int n, i, j;
    double ans = 0;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%lf", &p[i]);
    
    dp[0][0] = 1;
    
    for (i = 0; i < n; i++) {
        for (j = 0; j <= i; j++) {
            dp[j + 1][i - j] += dp[j][i - j] * p[i];
            dp[j][i - j + 1] += dp[j][i - j] * (1 - p[i]);
        }
    }
    
    for (i = 0; i <= n; i++) {
        if (i > n - i) ans += dp[i][n - i];
    }
    
    printf("%.12lf\n", ans);
    
    return 0;
}


Measured memory_bytes: 69888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 3;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
ll prime[100002];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll countdigit(ll n);

void solve(){
    string s; cin >> s;
    ll ans=0,c=0;
    rep(i,0,s.size()){
        if(s[i]=='R'){
            c++;
            ans=max(ans,c);
        }
        else {
           // cout<<c<<" ";
            ans=max(ans,c);
            c=0;
        }
    }
    if(s[2]=='R')ans=max(ans,c);
    cout<<ans<<endl;
}
int main()
{
    ll t=1;
    //cin >> t;
    while(t--) {
        solve();
     
    }

}


//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
long long INF;
int main(){
	long long h,w;
	cin>>h>>w;
	INF = w*h;
	long long r[4];
	for(int i=0; i<4; i++) r[i] = INF;
	
	if(h%3) r[0] = w;
	else r[0] = 0;
	if(w%3) r[1] = h;
	else r[1] = 0;
	
	for(int i=1; i<h; i++){
		long long div1 = i*w;
		long long div2 = (h-i)*w;
		long long arr[3];
		if(w%2){
			arr[0] = i*(w/2+1);
			arr[1] = i*(w/2);
		}
		else{
			arr[0] = i*(w/2);
			arr[1] = i*(w/2);
		}
		arr[2] = div2;
		r[2] = min(r[2],*max_element(arr,arr+3)-*min_element(arr,arr+3));
		if(w%2){
			arr[0] = (h-i)*(w/2+1);
			arr[1] = (h-i)*(w/2);
		}
		else{
			arr[0] = (h-i)*(w/2);
			arr[1] = arr[0];
		}
		arr[2] = div1;
		r[2] = min(r[2],*max_element(arr,arr+3)-*min_element(arr,arr+3));
	}
	for(int i=1; i<w; i++){
		long long div1 = i*h;
		long long div2 = (w-i)*h;
		long long arr[3];
		if(h%2){
			arr[0] = (h/2+1)*i;
			arr[1] = (h/2)*i;
		}
		else{
			arr[0] = (h/2)*i;
			arr[1] = arr[0];
		}
		arr[2] = div2;
		r[3] = min(r[3],*max_element(arr,arr+3)-*min_element(arr,arr+3));
		
		if(h%2){
			arr[0] = (h/2+1)*(w-i);
			arr[1] = (h/2)*(w-i);
		}
		else{
			arr[0] = (h/2)*(w-i);
			arr[1] = arr[0];
		}
		arr[2] = div1;
		r[3] = min(r[3],*max_element(arr,arr+3)-*min_element(arr,arr+3));
	}
	cout<<*min_element(r,r+4);
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <complex>
#include <cmath>

using namespace std;

int main()
{
  while (true)
  {
    double n;
    cin >> n;
    if (n == 0)
      return 0;

    double s[int(n)];
    double avg = 0;
    for (int i = 0; i < n; ++i)
    {
      cin >> s[i];
      avg += s[i];
    }
    avg /= n;

    double dispersion = 0;
    for (int i = 0; i < n; ++i)
      dispersion += pow(avg - s[i], 2);
    dispersion /= n;

    cout << fixed << setprecision(10) << abs(sqrt(dispersion)) << endl;
  }
}

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

using namespace std;

void swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}


int lFunc(string str){
	
	int num=str.at(0)-'0';

	for(int i=1;i<str.size();i+=2){
		if(str.at(i)=='+'){
			num+=(str.at(i+1)-'0');
		}
		else{
			num*=(str.at(i+1)-'0');
		}
	}

	return  num;
}

int uFunc(string str){
	
	int *dataNum;
	int *dataCal;
	int length = str.size()/2;

	dataNum = new int[str.size()/2+1];
	dataCal = new int[str.size()/2];

	for(int i=0;i<str.size();i++){
		if(i%2==0){
			dataNum[i/2]=str.at(i)-'0';
		}
		else{
			if(str.at(i)=='+'){
				dataCal[i/2]=1;
			}
			else{
				dataCal[i/2]=2;
			}
		}
	}
	/*
	for(int k=0;k<length+1;k++){
		cout<<dataNum[k]<<" ";
	}
	cout<<endl;

	for(int k=0;k<length;k++){
		cout<<dataCal[k]<<" ";
	}
	cout<<endl;
	*/

	while(1){
		int flag=0;

		for(int i=0;i<length;i++){
			if(dataCal[i]==2){
				dataNum[i]*=dataNum[i+1];
				flag=1;

				for(int now=i;now<length-1;now++){
					swap(&dataNum[now+1],&dataNum[now+2]);
					swap(&dataCal[now],&dataCal[now+1]);
				}
				length--;
			}
			/*
			for(int k=0;k<length+1;k++){
				cout<<dataNum[k]<<" ";
			}
			cout<<endl;

			for(int k=0;k<length;k++){
				cout<<dataCal[k]<<" ";
			}
			cout<<endl;
			*/
		}
		if(flag==0)break;
	}

	int num=dataNum[0];
	for(int i=1;i<=length;i++){
		num+=dataNum[i];
	}
//	cout<<"U="<<num<<endl;

	return num;
}

int main(){

	string str;

	cin>>str;

	int input;
	cin>>input;

	if(input==lFunc(str) && input==uFunc(str)){
		cout<<"U"<<endl;
	}
	else if(input == lFunc(str)){
		cout<<"L"<<endl;
	}
	else if(input == uFunc(str)){
		cout<<"M"<<endl;
	}
	else{
		cout<<"I"<<endl;
	}

	return 0;
}

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

const int T = 60;
const int INF = 1e9;
const int dx[6] = {1, 1, 0, -1, -1, 0};
const int dy[6] = {0, 1, 1, 0, -1, -1};

int main() {
  int t, n;
  while (cin >> t >> n, t) {
    vector<vector<int>> g(2 * T + 1, vector<int>(2 * T + 1, INF));
    REP(i, n) {
      int x, y;
      cin >> x >> y;
      g[T + x][T + y] = -1;
    }
    int sx, sy;
    cin >> sx >> sy;
    int ans = 0;
    queue<P> q({{T + sx, T + sy}});
    g[T + sx][T + sy] = 0;
    while (!q.empty()) {
      int x = q.front().first;
      int y = q.front().second;
      q.pop();
      if (g[x][y] > t) continue;
      ans++;
      REP(i, 6) {
        int tx = x + dx[i];
        int ty = y + dy[i];
        if (g[tx][ty] == -1) continue;
        if (g[tx][ty] <= g[x][y] + 1) continue;
        g[tx][ty] = g[x][y] + 1;
        q.push({tx, ty});
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3184
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    int k;
    cin >> k;

    queue< vector<int> > numbers;
    for(int i = 1; i <= 9; i++){
        vector<int> v(1);
        v[0] = i;
        numbers.push( v );
    }

    int sum = 0;
    vector<int> ans;
    while (true)
    {

        vector<int> v = numbers.front();
        numbers.pop();
        sum ++;
        if(sum == k){
            ans = v;
            break;
        }        

        for(int i = -1; i <= 1; i++){
            int n = v.back() + i;
            if(n >= 0 && n <= 9){
                vector<int> tmp = v;
                tmp.push_back(n);
                numbers.push( tmp );
            }
        }

    }
    
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] ;
    }
    cout << endl;

    return 0;
}

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

int main() {
  int N,M,max;
  cin>>N;
  vector<string> s(N);
  for(int i=0;i<N;i++){
    cin>>s.at(i);
  }
  cin>>M;
  vector<string> t(M);
  for(int i=0;i<M;i++){
    cin>>t.at(i);
  }
  max=0;
  for(int i=0;i<N;i++){
    int gain=0;
    string word=s.at(i);
    for(int j=0;j<N;j++){
      if (s.at(j)==word){gain++;}
    }
    for(int j=0;j<M;j++){
      if (t.at(j)==word){gain--;}
    }
    if(gain>max){max=gain;}
  }
  cout<<max<<endl;

}

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


void solve(long long H, long long N, std::vector<long long> A, std::vector<long long> B){
    vector<ll> dp(H + 1, numeric_limits<ll>::max());
    dp.at(0) = 0;
    REP(i, N){
        for(ll d = 0; d < H; ++d){
            if(dp.at(d) == numeric_limits<ll>::max()){ continue; }
            const ll d2 = min(H, d + A.at(i));
            dp.at(d2) = min(dp.at(d2), dp.at(d) + B.at(i));
        }
    }
    cout << dp.at(H) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(H, N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
int main()
{
	char c[101];
	gets(c);
	int len=strlen(c),i;
	bool isc=0,isf=0;
	for(i=0;i<len;i++)
	{
		if(c[i]=='C')isc=1;
		else if(c[i]=='F'&&isc)isf=1;
	}
	if(isf)printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

using namespace std;

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

struct Edge { int from, to, cost; };
bool comp(const Edge& e1, const Edge& e2) {
	return e1.cost < e2.cost;
}

struct UnionFind {
	vector<int> par, rank;
	
	UnionFind() {}
	UnionFind(int n) {
		init(n);
	}
	
	int init(int n) {
		par.resize(n);
		rank.resize(n, 0);
		REP(i, n) par[i] = i;
	}
	
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	while (true) {
		int n, m;
		cin >> n;
		if (n == 0) break;
		cin >> m;
		
		UnionFind uf(n);
		vector<Edge> v(m);
		
		REP(i, m) {
			int a, b, c;
			scanf("%d,%d,%d", &a, &b, &c);
			v[i].from = a;
			v[i].to = b;
			v[i].cost = c;
		}
		sort(v.begin(), v.end(), comp);
		
		int ans = 0;
		REP(i, m) {
			Edge e = v[i];
			if (! uf.same(e.from, e.to)) {
				uf.unite(e.from, e.to);
				ans += e.cost / 100 - 1;
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1320
n, *a = map(int, open(0).read().split())

a = [0] + a + [0]
s = 0
for i in range(n + 1):
    s += abs(a[i + 1] - a[i])
for i in range(1, n + 1):
    b = abs(a[i] - a[i-1])
    c = abs(a[i+1]-a[i])
    d = abs(a[i+1]-a[i-1])
    print(s - b - c + d)


Measured memory_bytes: 20392
N, K = STDIN.gets.chomp.split(' ').map(&:to_i)                          
S = STDIN.gets.chomp.split("").map(&:to_i)

renzoku = Array.new(0)

if S[0] == 0 then
  renzoku.push(0) # 1から始まる配列にしたいので,0から始まった場合は
                  # 無理やり先頭に0をpushする
end

now = S[0]
count = 0
S.each { |c|
  if (c == now) then
    count += 1
  else
    now = 1 - now # 0, 1を反転させる
    renzoku.push(count)
    count = 1
  end
}

renzoku.push(count) # 最後は尻切れトンボになるので,push

if (now == 0) then
  renzoku.push(0) # 1で終わる配列にしたいので,0で終わった場合は
                  # 無理やり最後に0をpushする
end

ruisekiWa = Array.new(0)
ruisekiWa.push(0) # 累積和は0からスタート
sum = 0
renzoku.each { |v|
  sum += v
  ruisekiWa.push(sum)
}
  
haba = K * 2 + 1

result = Array.new(0)

left = 0 # 1のあるところからスタート
right = 0

while left < ruisekiWa.length do
  if left + haba < ruisekiWa.length then
    right = left + haba
  else
    right = ruisekiWa.length - 1
  end
  result.push(ruisekiWa[right] - ruisekiWa[left])
  left += 2
end

puts result.max  

Measured memory_bytes: 9724
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;

int W, H;
int c[1000][1000];

void dfs(int x, int y) {
  int moveX[3] = {0,-1,1};
  int moveY[3] = {0,-1,1};
  c[x][y] = 0;
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
      int nx=x+moveX[i], ny=y+moveY[j];
      if(nx<0||ny<0) continue;
      if(c[nx][ny] == 1) dfs(nx,ny);
    }
  }
}

signed main() {
  cin>>W>>H;
  while (W+H!=0) {
    // i = y, j = x
    for(int i=0;i<1000;i++)for(int j=0;j<1000;j++)c[i][j]=0;
    for(int i=0;i<H;i++){
      for(int j= 0;j<W;j++){
        cin>>c[i][j];
      }
    }
    
    int ans = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (c[i][j] == 1) {
          dfs(i, j);
          ans++;
        }
      }
    }
    cout << ans << endl;
    cin >> W >> H;
  }
}



Measured memory_bytes: 11256
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      #ifndef ONLINE_JUDGE
      freopen("inputf.in",  "r",   stdin);
      freopen("outputf.in", "w",  stdout);
      #endif
      FastIO
      lld k;
      string s;
      cin >> k >> s;
      if (s.length() <= k){
      	cout << s;
      }
      else{
      	for(lld i = 0; i < k; i += 1){
      		cout << s[i];
      	}
      	cout << "...";
      }
      return 0;
}

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

const int MIN = 1;
const int MAX = 10000;

bool isIN(int v)
{
    if ((MIN <= v) && (v <= MAX))
    {
        return true;
    }
    return false;
}

bool isOrder(int a, int b)
{
    if (a <= b)
    {
        return true;
    }
    return false;
}

int main()
{
    int a,b,c;
    while (cin >> a >> b >> c)
    {
        if (!isIN(a) || !isIN(b) || !isIN(c))
        {
            continue;
        }
        if (!isOrder(a, b))
        {
            continue;
        }
        int cnt = 0;
        for (int i = a; i <= b; i++)
        {
            if ((c % i) == 0)
            {
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return (0);
}

Measured memory_bytes: 3080
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

#define SIZE (10*10*10*10*10)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

char S[SIZE];

int main()
{
  int cnt = 1;
  int i;
  int result = 0;
  int odd0 = 0;
  int odd1 = 0;
  int even0 = 0;
  int even1 = 0;
  int a_e0  = 0;
  int a_e1  = 0;
  int a_o0  = 0;
  int a_o1  = 0;

  i=0;
  while (cnt == 1) {
    cnt = scanf("%c", &S[i]);
    if (cnt != 1) break;
    if ((S[i] != '0') && (S[i] != '1')) break;
    if ((i & 1) == 0) {
      if (S[i] == '0') {
        even0++;
      } else {
        even1++;
      }
    } else {
      if (S[i] == '0') {
        odd0++;
      } else {
        odd1++;
      }
    }
    i++;
  }

  a_e0 = even1 + odd0;
  a_e1 = even0 + odd1;
  a_o0 = even0 + odd1;
  a_o1 = even1 + odd0;

  result = MIN(a_e0,   a_e1);
  result = MIN(result, a_o0);
  result = MIN(result, a_o1);

  printf("%d", result);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
signed main() {
    int n;
    cin >> n;
    int a[n+1];
    bool positive = true;
    bool negative = true;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if(a[i] < 0) positive = false;
        if(a[i] > 0) negative = false;
    }
    int m = n - 1;
    if (!positive && !negative) {
        cout << m * 2 << endl;
        int Max = -(1 << 30);
        int maxi = -1;
        for (int i = 1; i <= n; i++) {
            if (Max < abs(a[i])) {
                Max = abs(a[i]);
                maxi = i;
                if(a[i] >= 0) {
                    positive = true;
                    negative = false;
                } else {
                    positive = false;
                    negative = true;
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            if(i == maxi) continue;
            a[i] += Max;
            cout << maxi << " " << i << endl;
        }
        if (positive) goto pos;
        else goto neg;
    }
    if (positive) {
        cout << m << endl;
        pos:
        for (int i = 1; i <= n - 1; i++) {
            cout << i << " " << i + 1 << endl;
        }
    } else if(negative) {
        cout << m << endl;
        neg:
        for (int i = n; i > 1; i--) {
            cout << i << " " << i - 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int N;
 cin >> N;
 vector<tuple<string,int,int>>p(N);
 for (int i = 0; i < N; i++)
 {
    string a;
    int b;
    cin >> a >> b;
    p.at(i)=make_tuple(a,b*-1,i+1);
 }
 sort(p.begin(),p.end());
  for (int i = 0; i < N; i++)
 {
    string a;
    int b,c;
    tie(a,b,c)=p.at(i);
    cout << c << endl;
 }

}

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

using namespace std;

int main()
{
    int a,b;
    int flag=-1;
    cin>>a>>b;
    if(a>=1&&a<=9&&b<=9&&b>=1)
        cout<<a*b<<endl;
    else
        cout<<flag<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int su[n+1] = {0};
	for(int i=0;i<k;i++){
		int d;
		cin>>d;
		for(int j = 0; j < d; j++){
		    int a;
			cin>>a;
			su[a]++;
		}
	}
	int count=0;
	for(int i = 1; i <= n; i++){
		if(!su[i]){
			count++;
		}
	}
	cout<<count;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
  int x, y, w, h, r;
  cin >> w >> h >> x >> y >> r;
  if (x-r >= 0 && y-r >= 0 && x+r <= w && y+r <= h) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3108
<?php

$input = trim(fgets(STDIN),"\r\n");
while (1) {

	$lines = explode(' ', $input);

	$height = intval($lines[0]);
	$width = intval($lines[1]);

	for ($i=0; $i < $height; $i++) { 
		for ($j=0; $j < $width; $j++) { 
			print('#');
		}
		print("\n");
	}
	print("\n");

	$input = trim(fgets(STDIN),"\r\n");
	if((string)$input === '0 0')
		break;
}

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

#define mp(x, y) make_pair((x), (y))

typedef long long ll;

int n;
ll a[100005];
vector<pair<ll,int> > s;
int id;
ll ans[100005];
multiset<ll> q;
int open;

int main()
{
	scanf("%d", &n);
	for(int i=0; i<n; i++) scanf("%lld", &a[i]);
	for(int i=0; i<n; i++) s.push_back(mp(-a[i], i));
	sort(s.begin(), s.end());
	id=n-1;
	for(int i=0; i<n; ) {
		ll curval=-s[i].first;
		int curid=s[i].second;
		ll nextval=0;
		int j=i+1;
		while(j<n && s[j].second>s[i].second) j++;
		if(j<n) {
			nextval=-s[j].first;
		}
		i=j;
		ans[curid]+=open*(curval-nextval);
		while(q.size()) {
			if(-(*q.begin())>=nextval) {
				ans[curid]+=(-(*q.begin()))-nextval;
				open++;
				q.erase(q.begin());
			} else {
				break;
			}
		}
		while(id>=curid) {
			if(a[id]>=nextval) {
				ans[curid]+=a[id]-nextval;
				open++;
			} else {
				q.insert(-a[id]);
			}
			id--;
		}
	}
	for(int i=0; i<n; i++) printf("%lld\n", ans[i]);

	return 0;
}

Measured memory_bytes: 7408
N = int(input())
str_cnt = {}
for i in range(N):
  st = input()
  if st in str_cnt:
    str_cnt[st] += 1
  else:
    str_cnt[st] = 1

max_cnt = max(str_cnt.values())
res_list = []

for item in str_cnt.items():
  if item[1] == max_cnt:
    res_list.append(item[0])

res_list.sort()

for res in res_list:
  print(res)

Measured memory_bytes: 91224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<pii,int>;


int main(){
    ll x;
    cin >> x;
    ll a = 100;
    bool ok = true;
    ll i = 0;
    while(ok){
        i++;
        a *= 1.01;
        if(x <= a) ok = false;
    }
    cout << i << endl;
}

Measured memory_bytes: 3608
import itertools
import math


def dist(a, b):
    return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)


N = int(input())
C = [tuple(map(int, input().split())) for _ in range(N)]

s = 0
for cmb in itertools.combinations(C, 2):
    s += 2 * dist(cmb[0], cmb[1]) / N

print(s)


Measured memory_bytes: 38896
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}
ll lcm(ll a, ll b) {
  ll tmp=gcd(a,b);
  return (a/tmp)*(b/tmp)*tmp;
}

int main(){
  ll N;
  cin >> N;
  vector<ll> a(N), k(N);
  ll f=0;
  rep(i,N){
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  ll g = a[1];
  for(ll i=2;i<N;i++){
    g = gcd(g,a[i]);
  }
  vector<vector<ll> > dp(N+2,vector<ll>(2,0));
  dp[0][0] = a[0];
  dp[0][1] = a[1];
  for(ll i=0;i<N-1;i++){
    dp[i+1][0] = gcd(dp[i][0],a[i+1]);
    dp[i+1][1] = max(dp[i][0], gcd(dp[i][1],a[i+1]));
  }
  cout << max(dp[N-1][1],g) << endl;
}


Measured memory_bytes: 7296
N, K = map(int, input().split())
# 復元プール
a = list(map(int, input().split()))
dp = [False for _ in range(K+1)]
# dp[i]石が残りi個のとき、先手が勝てるか
for i in range(1, K+1):
    for j in range(N):
        if i - a[j] >= 0:
            dp[i] = dp[i] or (not dp[i - a[j]])
if dp[K]:
    print("First")
else:
    print("Second")

Measured memory_bytes: 73996
//Code By CXY07
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int MAXN = 100010;
const int INF = 2e9;
const int mod = 1e9 + 7;

int n,ans,tmpans = 1; 
int a[MAXN],s[MAXN],cnt = 0;

/*inline int ksm(int x,int b) {
	int res = 1;
	while(b) {
		if(b & 1) res *= x;
		x *= x;
		b >>= 1;
	}
	return res;
}*/

signed main () {
	//cout << 3141 % 628 << endl;
	cin >> n;
	for(register int i = 2,res;i * i <= n; ++i) { 
		res = n;
		if(res % i) continue;
		while(res % i == 0) res /= i;
		if(res != n && res % i == 1) ans++;
	}
	n--;
	for(register int i = 2;i * i <= n; ++i) {
		if(n % i) continue;
		a[++cnt] = i;
		while(n % i == 0) s[cnt]++,n /= i;
		tmpans *= (s[cnt] + 1);
	}
	if(n != 1) {
		a[++cnt] = n,s[cnt] = 1;
		tmpans *= (s[cnt] + 1);
	}
	ans += tmpans;
	cout << ans << endl;
	return 0;
}

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

string S;

int main(){
    cin>>S;
    int n=S.length();
    for(int i=0;i<n;i++){
        if(i%2==0){
            if(S[i]=='L'){
                cout<<"No"<<endl;
                return 0;
            }
        }else if(i%2==1){
            if(S[i]=='R'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    char a[h + 2][w + 2];
    for (int i = 0; i < h + 2; ++i) {
        for (int j = 0; j < w + 2; ++j) {
            a[i][j] = '#';
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i + 1][j + 1];
        }
    }

    for (int i = 0; i < h + 2; ++i) {
        for (int j = 0; j < w + 2; ++j) {
            cout << a[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 310;

typedef long long ll;
const int mod = 998244353;
inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int sub(int a,int b){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/* math */
int g[N][N][N],f[N][N][N],n;
// j zeros to add, k ones to add;
char s[N];

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);reverse(s+1,s+n+1);
	s[n+1]='2';
	f[0][0][0]=g[0][0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=i;j++){
			for(int k=0;j+k<=i;k++){
//				f[i][j][k]=add(f[i][j][k], g[i][j][k]);
				if(g[i][j][k]){
					int _d=i-j-k+1;
					int dir=s[_d]-'0';
					g[i+1][j][k]=add(g[i][j][k],g[i+1][j][k]);
					if(dir)g[i+1][j+1][k]=add(g[i+1][j+1][k],g[i][j][k]);
					else g[i+1][j][k+1]=add(g[i+1][j][k+1],g[i][j][k]);
				}
				/*-------*/
			}
		}
	}

	f[n][0][0]=1;
	for(int i=n-1;i;i--){
		for(int j=0;j<=i;j++){
			for(int k=0;j+k<=i;k++){
				int dir=s[i-j-k+1]-'0';
				int dir2=s[i-j-k+2]-'0';
//				assert(dir>=0&&dir<=1&&dir2>=0&&dir2<=1);
//				cerr << dir << " " << dir2 << endl;
				int nt[3];
				nt[0]=j,nt[1]=k,nt[2]=0;
				nt[0]++;
				if(nt[dir]){
					nt[dir]--;
					if(nt[dir2]&&(dir2==0||dir==0))nt[dir2]--;
				}
				f[i][j][k]|=f[i+1][nt[0]][nt[1]];
//				cerr << nt[0] << " " << nt[1] << ",";
				nt[0]=j,nt[1]=k;
				nt[1]++;
				if(nt[dir]){
					nt[dir]--;
					if(nt[dir2]&&(dir2==1||dir==1))nt[dir2]--;
				}
				f[i][j][k]|=f[i+1][nt[0]][nt[1]];
//				cerr << nt[0] << " " << nt[1] << endl;
//				cerr << i << " " << j << " " << k << "|" << f[i][j][k] << endl;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++)for(int k=0;k+j<=i;k++){
			if(f[i][j][k]){
//				cerr << i << " " << j << " " << k << " " << g[i][j][k] << endl;
				ans=add(ans, g[i][j][k]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 115040
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

bool is_prime(const unsigned n){
    switch(n){
        case 0: 
        case 1: return false;
        case 2: 
        case 3: return true;
    } 

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    

    if(n%6 != 1 && n%6 != 5) return false;
    
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false;
        if(n%(i+2) == 0) return false;
    }

    return true;
}

long long Count(int n){
    int cnt=0;
    while(n){
        cnt++;
        n/=10;
    }
    return cnt;
}

int main(){
    long long n,nn;
    long long mini=INF;
    cin>>n;
    if(is_prime(n)){
      cout<<Count(n)<<endl;
      return 0;
    }
    nn=n;
    for(long long i=1;i<=n;i++){
      //cout<<i<<endl;
        if(nn%i==0){
            long long maxi=max(i,nn/i);
            mini=min(mini,Count(maxi));
        }
	 n=nn/i;
    }
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 256
import re

S = list(input())

for i in range(2**3):
    bits = [(i>>j)&1 for j in range(3)]
    bits.append("")

    expr = ""
    for b, s in zip(bits, S):
        expr += s
        if b == 0:
            expr += "+"
        elif b == 1:
            expr += "-"
    expr_sum = eval(expr)
    if expr_sum == 7:
        print(expr + "=7")
        break

Measured memory_bytes: 38384
package main

import (
	"fmt"
	"log"
	"sort"
)

func main() {

	const num = 5 //
	var time[num] int //
	var sum int
	var wait []int //array or slice

	//
	for i := 0; i < num; i++{
		_, err := fmt.Scan(&time[i])
		if err != nil {
			log.Fatal(err)
		}
	}

	//
	for i := 0; i < num; i++ {
		wait = append(wait, 0)

		if time[i] % 10 != 0{
			wait[i] = 10 - (time[i] % 10)
		}
	}

	//
	sort.Ints(wait)

	for i := 0; i < num; i++{

		//
		if i == num - 1{
			wait[i] = 0
		}

		sum = sum + time[i] + wait[i]
	}

	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  ll Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  ll one = min(min(4 * Q, 2 * H), S);
  ll two = min(2 * one, D);
  cout << (N / 2) * two + (N % 2) * one << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int a, b, c;
  
  cin >> a >> b >> c;
  
  if(a >= b){
    if(a >= c){
      cout << 10*a+b+c << endl;
    }
    else{
      cout << 10*c+a+b << endl;
    }
  }else{
      if(b >= c){
	cout << 10*b + a + c << endl;
      }else{
	  cout << 10*c + a + b << endl;				  
	}
    }
      return 0;
}
	  


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

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;

int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    int a, b, c; cin>>a>>b>>c;
    map<int, bool> mp;
    mp[a], mp[b], mp[c];
    cout<<mp.size();
	return 0;

}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i =0; i < N; i++) cin >> A[i];

    vector<int> S(N+1, 0);
    for (int i = 0; i < N; i++) {
        S[i+1] = S[i] + A[i];
    }
    int sum = S[N];

    int ret = 0;
    for (int i= 0; i <= N-2; i++) {
        int tmp = sum - S[i+1] + MOD;
        tmp %= MOD;
        ret += (tmp * A[i]) % MOD;
        ret %= MOD;
    }

    cout << ret << endl;
    return 0;
}

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

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,k){
        vector<int> b(n+1);
        fill(All(b),0);
        rep(j,n){
            b[max(0,j-a[j])]++;
            b[min(n,j+1+a[j])]--;
        }  
        fill(All(a),0);
        a[0] = b[0];
        for(int j = 1;j<n;j++) a[j]=a[j-1]+b[j];
        bool fl = true;
        rep(j,n){
            if(a[j]!=n) {
                fl = false;
                break;
            }
        }
        if(fl) break;
        //Debug_Output_ALL(a);
    }
    rep(i,n) cout << a[i] << " ";
    cout << endl;
}

Measured memory_bytes: 4836
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

int main(){
    int N,T;
    cin >> N >> T;
    int c[N], t[N];

    REP(i,N){
        cin >> c[i] >> t[i];
    }

    int ans=INF;
    bool flag=false;

    REP(i,N){
        if(t[i]<=T){
            if(c[i]<ans){
                ans = c[i];
                flag = true;
            }
        }
    }
    if(flag){
        cout << ans << endl;
    }else{
        cout << "TLE" << endl;
    }

    return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll n;
vector<ll> a(3000);
vector<vector<ll>> dp(3010,vector<ll>(3010,1e14));

ll solve(ll l, ll r, ll times)
{
    if(times == n) return 0;
    if(dp.at(l).at(r) != 1e14) return dp.at(l).at(r);
    ll res;
    if(times%2 == 0){
        res = max(solve(l+1,r, times+1) + a.at(l), solve(l,r-1, times+1) + a.at(r));
    }else{
        res = min(solve(l+1,r, times+1) - a.at(l), solve(l,r-1, times+1) - a.at(r));
    }
    return dp.at(l).at(r) =  res;
}

int main()
{
    ll i,j,k;
    
    cin >> n;
    
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    ll ans = solve(0, n-1, 0);
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N+1);
  vector<bool> pushedButton(N+1, false);
  
  for (int i = 1; i < N+1; i++) cin >> a.at(i);
  
  int index = 1, total = 0;
  while (true) {
    total++;

    if (a.at(index) == 2) {
      cout << total << endl;
      break;
    }

    if (pushedButton.at(index) == true) {
      cout << -1 << endl;
      break;
    }

    pushedButton.at(index) = true;
    index = a.at(index);
  }
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	std::string s;

	std::cin >> s;

	if (s.length() < 2 || s.length() % 2 == 1) {
		std::cout << "No" << std::endl;
		return 0;
	}
	
	for (size_t i = 0; i < s.length(); i+=2)
	{
		if (s[i] != 'h' || s[i + 1] != 'i') {
			std::cout << "No" << std::endl;
			return 0;
		}
	}
	
	std::cout << "Yes" << std::endl;

	return 0;
}


Measured memory_bytes: 256
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) a.begin(), a.end()
#define ifnot(a) if (not(a))
#define int long long
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) cerr << #x << " = " << (x) << " " << endl;
#else
const bool test = false;
#define dump(x) 
#define dumpl(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}
 
class Solver {
public:
  int N, Y;

  void solve() {
    cin >> N >> Y;
    int y = Y / 1000;
    rep(i, N + 1) rep(j, N + 1) {
      int k = N - i - j;
      if (k < 0) continue;
      if (i * 10 + j * 5 + k == y) {
        cout << i << " "<< j << " " << k << endl;
        return;
      }
    }
    cout << "-1 -1 -1" << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


Measured memory_bytes: 256
s = input()
n = len(s)
sss = "No"

if s[0:n//2] == s[n//2+1:n][::-1]:
    r = n//2
    le = r//2
    if s[0:le] == s[r-le:r][::-1]:
        if s[r+1:r+1+le] == s[n-le:n][::-1]:
            sss = "Yes"
            
print(sss)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define REP(i,x) for(int i=0,i##_len=(x);i<i##_len;++i)
#define rep(i,a,b) for(int i=(a),i##_len(b);i<i##_len;++i)
#define All(x) begin(x),end(x)
#define rAll(x) rbegin(x),rend(x)
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    ll l=1,r=1;
    REP(i,N){
        ll t,a;
        cin>>t>>a;
        ll mul=max((l+t-1)/t,(r+a-1)/a);
        l=mul*t;
        r=mul*a;
    }
    cout<<l+r<<endl;
}


Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>

struct P {
    float x, y;
    P operator-(const P& p) {
        return P{x - p.x, y - p.y};
    }
};

float dot(const P& p1, const P& p2) {
    return p1.x * p2.x + p1.y * p2.y;
}

float cross(const P& p1, const P& p2) {
    return p1.x * p2.y - p1.y * p2.x;
}

float abs(const P& p) {
    return std::sqrt(p.x * p.x + p.y * p.y);
}

float distance_ls_p(P a, P b, P c) {
  if ( dot(c-b, a-b) < 1e-6 ) return abs(b-a);
  if ( dot(a-c, b-c) < 1e-6 ) return abs(c-a);
  return std::abs(cross(b-c, a-b)) / abs(b-c);
}

int main()
{
    struct UFO {
        float x, y;
        float v;
        float r;
        float sita;
        float d;
    };
    
    while (true) {
        int count = 0;
        int R, N;
        std::cin >> R >> N;
        
        if (R == 0 && N == 0) {
            break;
        }
        
        std::vector<UFO> ufos(N);
        
        for (int i = 0; i < N; i++) {
            std::cin >> ufos[i].x >> ufos[i].y >> ufos[i].r >> ufos[i].v;
            ufos[i].sita = std::atan2(ufos[i].y, ufos[i].x);
            ufos[i].d = std::sqrt(ufos[i].x * ufos[i].x + ufos[i].y * ufos[i].y);
        }
        
        while (!ufos.empty()) {
            for (std::size_t i = 0; i < ufos.size(); i++) {
                ufos[i].d = std::max(ufos[i].d - ufos[i].v, 0.0f);
                ufos[i].x = std::cos(ufos[i].sita) * ufos[i].d;
                ufos[i].y = std::sin(ufos[i].sita) * ufos[i].d;
            }
            
            count += std::count_if(ufos.begin(), ufos.end(), [R](auto& elem){
                return elem.d <= R;
            });
            
            {
                auto rm_it = std::remove_if(ufos.begin(), ufos.end(), [R](auto& elem){
                    return elem.d <= R;
                });
                ufos.erase(rm_it, ufos.end());
            }
            
            std::sort(ufos.begin(), ufos.end(), [](auto& lhs, auto& rhs){
                return lhs.d < rhs.d;
            });
            
            if (ufos.empty()) {
                break;
            }
            
            float a = ufos[0].y / ufos[0].x;
            {
                float shot_angle = std::atan2(ufos[0].y, ufos[0].x);
                auto rm_it = std::remove_if(ufos.begin(), ufos.end(), [shot_angle, R, a, &ufos](auto& elem){
                    return distance_ls_p(P{elem.x, elem.y}, 
                                         P{R * std::cos(shot_angle), R * std::sin(shot_angle)},
                                         P{1e6f * std::cos(shot_angle), 1e6f * std::sin(shot_angle)}) < elem.r;
                });
                ufos.erase(rm_it, ufos.end());
            }
        }
        printf("%d\n", count);
    }
}



Measured memory_bytes: 3360
N, M, C = map(int, input().split())
B = [int(b) for b in input().split()]
Count = 0
for _ in range(N):
    A = [int(a) for a in input().split()]
    Total = C
    for i in range(M):
        Total += A[i] * B[i]
    if Total > 0: Count += 1
print(Count)


Measured memory_bytes: 3060