akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

	int n;
	cin >> n;

	vector<int> h(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> h[i];
	}

	for(int i = 1; i <= n; i++) {
		if(h[i] > h[i-1]) h[i]--;
		else if(h[i] < h[i-1]) {
			cout << "No";
			return 0;
		}
	}

	cout << "Yes";

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

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

#define REP(i,n) for(int i = 0; i < n; i++)
#define INF 1e9

#define MAX_N 100000

int n, k;
ll x[MAX_N];
ll y[MAX_N];
char c[MAX_N];

int main(){
  cin >> n >> k;
  REP(i,n)cin >> x[i] >> y[i] >> c[i];

  int cood[2*k][2*k][2];
  REP(i,2*k){
    REP(j,2*k){
      REP(l,2){
        cood[i][j][l] = 0;
      }
    }
  }

  int col;
  REP(i,n){
    if(c[i] == 'B'){
      col = 0;
    }else{
      col = 1;
    }
    cood[x[i]%(2*k)][y[i]%(2*k)][col]++;
  }



  int memo[2*k][2*k][2];  //左下までの和
  REP(l,2){
    REP(i,2*k){
      REP(j,2*k){
        if(i>0 && j>0){
          memo[i][j][l] = memo[i-1][j][l] + memo[i][j-1][l] - memo[i-1][j-1][l] + cood[i][j][l];
        }else if(i > 0){
          memo[i][j][l] = memo[i-1][j][l] + cood[i][j][l];
        }else if(j > 0){
          memo[i][j][l] = memo[i][j-1][l] + cood[i][j][l];
        }else{
          memo[i][j][l] = cood[i][j][l];
        }
      }
    }
  }



  int ret;
  int ans = 0;

  REP(i,k){
    REP(j,k){
      ret = 2 * memo[i][j][0] + 2 * memo[i + k][j + k][0] - 2 * memo[i + k][j][0] - 2 * memo[i][j + k][0] + memo[2 * k-1][j][0] + memo[i][2*k-1][0] + memo[2*k-1][2*k-1][0] - memo[2*k-1][j+k][0] - memo[i + k][2*k-1][0];
      ret += (2 * memo[i][j+k][1] + 2 * memo[i+k][j][1] - 2 * memo[i][j][1] + memo[2*k-1][j+k][1] - memo[2*k-1][j][1] - 2 * memo[i+k][j+k][1] + memo[i+k][2*k-1][1] - memo[i][2*k-1][1]);
      ans = max(ans,ret);
      ans = max(ans, n-ret);
    }
  }

  cout << ans << endl;



  return 0;
}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int r,d,val;
	cin>>r>>d>>val;
	int num=10;
	while(num--){
		val=r*val-d;
		cout<<val<<endl;
	}
	return 0;
}

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

class Node {
public:
	int f_ = -1;
	vector<Node*> link_;
	set<int> block_;
//	void clearf() { f_ = -1; }
	void mark(int i) {
		if (f_ == -1) {
			f_ = i;
			for (auto it = link_.begin(); it < link_.end(); it++) {
				(*it)->mark(i);
			}
		}
		else {
			return;
		}
	}
};

int main() {
	// ネットワーク作成
	int N, M, K;
	cin >> N >> M >> K;
	vector<Node> nodes(N);
//	for (auto it = nodes.begin(); it < nodes.end(); it++) {
//		it->clearf();
//		it->link_.clear();
//		it->block_.clear();
//	}
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		nodes.at(a - 1).link_.push_back(&nodes.at(b - 1));
		nodes.at(b - 1).link_.push_back(&nodes.at(a - 1));
	}
	for (int i = 0; i < K; i++) {
		int a, b;
		cin >> a >> b;
		nodes.at(a - 1).block_.insert(b - 1);
		nodes.at(b - 1).block_.insert(a - 1);
	}

	// 全nodeを分類する。
	for (int i = 0; i < N; i++) {
		if (nodes.at(i).f_ == -1) {
			nodes.at(i).mark(i);
		}
	}

	// クラスタ人数の数え上げ
	std::map<int, int> rscore;
	for (int i = 0; i < N; i++) {
		rscore[nodes.at(i).f_]++; // 存在しないキーを指定した場合は0が挿入される？
	}

	// じぶんのスコアは、クラスタ人数 - 自分の1hop人数 - 自分 - 同じクラスタのブロック数;


	for (int i = 0; i < N; i++) {
		Node* pn = &nodes.at(i);
		int myClsName = pn->f_;
		int myClsN = rscore[myClsName];
		int myHop1 = pn->link_.size();
		int mySameClsBlock = 0;
		for (auto it = pn->block_.begin(); it != pn->block_.end(); it++) {
			if (nodes.at(*it).f_ == myClsName) mySameClsBlock++;
		}
		int myScore = myClsN - myHop1 - 1 - mySameClsBlock;
		cout << myScore << " ";
	}
	cout << endl;
}


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

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

	int x, y;
	cin >> x>> y;
	int a[] = { 1,3,5,7,8,10,12 };
	int b[] = { 4,6,9,11 };
	for (int i = 0; i < 7; i++) {
		if (x == a[i])x = 100;
		if (y == a[i])y = 100;
	}
	for (int i = 0; i < 4; i++) {
		if (x == b[i])x = 200;
		if (y == b[i])y = 200;
	}
	if (x == y) {
		cout << "Yes";
	}
	else cout << "No";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
 
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;
 
 
//debug func
template<typename T>
void vecprint(vector<T> v) {
    for(auto x : v) {
        cerr << x << " ";
    }
    cerr << endl;
}
 
template<typename T>
void vecvecprint(vector<vector<T>> v) {
    for(auto x :v) {
        REP(i, x.size()-1) {
            cerr << x[i] << " ";
        }
        cerr << x[x.size()-1] <<endl;
    }
}
 
template<typename T>
void pqprint(priority_queue<T> q) {
    while(!q.empty()) {
        cerr << q.top() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void qprint(queue<T> q) {
    while(!q.empty()) {
        cerr << q.front() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void vecqprint(vector<queue<T>> v) {
    for(int i = 0; i < v.size(); i++) {
        qprint(v[i]);
    }
}
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}
 
int main(void) {
    LL n;
    cin >> n;
    
    LL m = sqrt(n);
    // cerr << n << " " << m << endl;
    int i;
    for(i = m; i > 0; i--) {
        if(n % i == 0) break;
    }
    cout << i + n/i - 2 << endl;
}

Measured memory_bytes: 384
x = int(input())
exp_set = set()
exp_set.add(1)
for i in range(2, 32):
  p = 2
  while True:
    if i**p > 1000:
      break
    exp_set.add(i**p)
    p += 1
ans = 0
for ele in sorted(list(exp_set)):
  if ele > x:
    break
  ans = ele
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=10,INF=1<<29;

const long double eps=1e-12;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        long double mini=INF;
        vector<int> ans(3,INF);
        
        vector<int> A(N);
        for(int i=0;i<N;i++){
            cin>>A[i];
        }
        
        for(int a=0;a<16;a++){
            for(int b=0;b<16;b++){
                for(int c=0;c<16;c++){
                    vector<int> cnt(256);
                    int now=a;
                    
                    for(int i=0;i<N;i++){
                        now=(now*b+c)%256;
                        cnt[(now+A[i])%256]++;
                    }
                    
                    long double sum=0.0;
                    
                    for(int i=0;i<256;i++){
                        if(cnt[i]){
                            sum-=(long double)(cnt[i])/(long double)(N)*((long double)log10((long double)(cnt[i]))/(long double)(N));
                        }
                    }
                    
                    if(sum<mini){
                        mini=sum;
                        ans[0]=a;
                        ans[1]=b;
                        ans[2]=c;
                    }else if(sum-eps<=mini&&mini<=sum+eps){
                        vector<int> p={a,b,c};
                        ans=min(ans,p);
                    }
                }
            }
        }
        
        cout<<ans[0]<<" "<<ans[1]<<" "<<ans[2]<<endl;
    }
}



Measured memory_bytes: 3216
N=int(input())
st=[]
for i in range(N):
    s,t=input().split()
    st.append((s,int(t)))
X=input()

time=0
s=False
for i in range(N):
    if s:
        time+=st[i][1]
    if st[i][0]==X:
        s=True
print(time)

Measured memory_bytes: 61592
def main():
    H, W = (int(i) for i in input().split())
    A = [input() for i in range(H)]
    dhw = ((0, -1), (0, 1), (-1, 0), (1, 0))
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                for dh, dw in dhw:
                    if h+dh < 0 or H <= h+dh or w+dw < 0 or W <= w+dw:
                        continue
                    if A[h+dh][w+dw] == "#":
                        break
                else:
                    return print("No")
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)
vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    long long x;
    cin >> x;
    long long balance = 100;
    for (int i = 0; i < 10000; i++) {
        balance = balance + balance / 100;
        //cout << balance << endl;
        if (balance >= x) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

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

string A, B, C;

int main(){
	cin >>A>>B>>C;
	char f=1;
	f = f * (A[A.length()-1]==B[0]) * (B[B.length()-1]==C[0]);
    if(f){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
    }
    
    return 0;
}


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

char grade(int, int, int);

char grade(int m, int f, int r){
    if(m == -1 || f == -1) return 'F';
    int sum = m + f;
    if(sum < 30) return 'F';
    if(30 <= sum && sum < 50) return (50 <= r)? 'C':'D';
    if(50 <= sum && sum < 65) return 'C';
    if(65 <= sum && sum < 80) return 'B';
    
    return 'A';
}

int main(void){
    int m, f, r;
    while(true){
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r ==-1) break;
        cout << grade(m, f, r) << endl;
    }
}

Measured memory_bytes: 3076
use std::cmp;
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let cs: Vec<_> = {
        let s: String = parse_line().unwrap();
        s.chars().collect()
    };
    let mut r: usize = 0;
    let mut w: usize = 0;

    for c in cs.iter() {
        if *c == 'R' {
            r += 1
        }
    }
    let mut ans: usize = cmp::max(r, w);

    for c in cs {
        if c == 'R' {
            r -= 1
        } else {
            w += 1
        }
        ans = cmp::min(ans, cmp::max(r, w));
    }

    println!("{}", ans)
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
int n, m, k;
int main() {
    cin >> n >> m >> k;
    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= m; ++j) {
            if(i * m + j * n - 2 * i * j == k) {
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
	return 0;
}


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

int main() {
  int N,cnt=0;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  for(int j=1;;j++){
    int p=0;
    bool a=true;
    for(int i=0;i<N;i++){
      if(vec[i]>=j&&a){
        p++;
        a=false;
      }else if(vec[i]<j&&!a){
        a=true;
      }
    }
    if(p==0){
      cout<<cnt;
      return 0;
    }
    cnt+=p;
  }
  return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    map <int,int> m;
    for(int i=0;i<n;i++){
        cin >> a[i];
        m[a[i]]++;
    }
    int e1=-1,e2=-1;
    for(map<int,int> :: reverse_iterator it=m.rbegin(); it!=m.rend();it++){
        if(it->second >1){
            if(e1==-1){
                e1=it->first;
                if(it->second>3){
                    e2=it->first;
                    break;
                }
            }
            else{
                e2=it->first;
                break;
            }
        }
    }
    if(e1==-1 || e2==-1){
        cout << 0 << endl;
    }
    else{
        cout << 1LL*e1*e2 << endl;
    }
    return 0;
}

Measured memory_bytes: 5376
S = int(input())
f = [0] * (S+1)
f[0] = 1
cumsum = 1
mod = 10**9+7
for i in range(3, S+1):
  f[i] = cumsum - f[i-1] - f[i - 2]
  f[i] %= mod
  cumsum += f[i]
print(f[-1])

Measured memory_bytes: 63600
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define hello std::ios::sync_with_stdio(false);
#define world cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
ll x[N],y[N];ll ans;
int main()
{
	hello world;
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>x[i];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(x[i]>x[j])
				y[i]++;
	m--;
	for(int i=0;i<n;i++)
		for(int j=i;j<n;j++)
			ans+=(x[i]>x[j])*(m+1),ans%=mod;
	for(int i=0;i<n;i++)
	{
		ans+=m*(m+1)/2%mod*y[i]%mod;
		ans%=mod; 
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    char a=s[s.size()-1];
    for(int i=0;i<2;i++){
        cin>>s;
        char b=s[0];
        //cout<<a<<b<<endl;
        if(a!=b){cout<<"NO"<<endl;return 0;}
        a=s[s.size()-1];
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int d,n,result;
  cin>>d>>n;
  if(d==0 && n==100){
    result=101;
  }
  else if(d==1 && n==100){
    result=10100;
  }
  else if(d==2 && n==100){
    result=1010000;
  }
  else result=n*pow(100,d);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 512
#include<cmath>
#include<stack>
#include<cstring>
#include<iostream>
#include<algorithm>
#define SC(x) scanf("%d",&x);
#define pr(x)  cout << x << endl;
#define mem(arr,v) memset(arr,v,sizeof arr);
#define bug(x) cout << "#x = " << x <<endl;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[20];
stack<int> s1,s2;

bool dfs(int pos){
	if(pos == 10 + 1) return true;
	
	int v = a[pos];
	if(s1.empty() || v >= s1.top()){
		s1.push(v);
		if(dfs(pos + 1)) return true;
		s1.pop();
	}
	if(s2.empty() || v >= s2.top()){
		s2.push(v);
		if(dfs(pos + 1)) return true;
		s2.pop();
	}
	return false;
}

int main(){
//	freopen("in.txt","r",stdin);
	int t;
	cin >> t;
	for(int i = 1 ; i <= t ;++i){
		for(int j = 1; j <= 10 ; j++)
			cin >> a[j];
		while(! s1.empty()) s1.pop();
		while(! s2.empty()) s2.pop();
		
		bool ans = dfs(1);
		if(ans)	puts("YES");
		else	puts("NO");
	}
	
}

Measured memory_bytes: 2968
N=int(input())
B=[0]+[int(x) for x in input().split()]+[0]
sum=0

for i in range(N):
    if i==0:
        sum+=B[i+1]
    elif i==N-1:
        sum+=B[i]
    else:
        sum+=min(B[i],B[i+1])

print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define rsort(x) sort(all(x));reverse(all(x))
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  string s;
  cin>>s;
  cout<<"ABC"<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
/*
  分治+DP
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define RG register
#define IL inline
#define inf 1e18
#define LL long long
#define db double
#define N 300005
using namespace std;
IL int gi()
{
    RG int res=0,w=1;
    RG char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-') w=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) res=10*res+ch-48;
    return res*w;
}
int n,a[N],m;LL s[N],L[N],R[N],q[N][2],W[N],V[N]; int h,t; LL x,y;
void pre()
{
    for(int i=1;i<=n;++i) s[i]=s[i-1]+a[i];
    h=t=1;
    for(int i=1;i<=n;++i) {
	L[i]=L[i-1];
	while(h<t&&q[t][1]-q[t-1][1]<=(q[t][0]-q[t-1][0])*i) t--;
	L[i]=max(L[i],q[t][1]-s[i]+1ll*i*(i+1)/2-1ll*i*q[t][0]);
	x=i,y=L[i]+s[i]+1ll*i*(i-1)/2;
	while(h<t&&(q[t][1]-q[t-1][1])*(x-q[t][0])<=(y-q[t][1])*(q[t][0]-q[t-1][0])) t--;
	q[++t][0]=x,q[t][1]=y;
    }
    reverse(a+1,a+n+1);
    for(int i=1;i<=n;++i) s[i]=s[i-1]+a[i];
    h=t=1;
    for(int i=1;i<=n;++i) {
	R[i]=R[i-1];
	while(h<t&&q[t][1]-q[t-1][1]<=(q[t][0]-q[t-1][0])*i) t--;
	R[i]=max(R[i],q[t][1]-s[i]+1ll*i*(i+1)/2-1ll*i*q[t][0]);
	x=i,y=R[i]+s[i]+1ll*i*(i-1)/2;
	while(h<t&&(q[t][1]-q[t-1][1])*(x-q[t][0])<=(y-q[t][1])*(q[t][0]-q[t-1][0])) t--;
	q[++t][0]=x,q[t][1]=y;
    }
    reverse(R+1,R+n+1);
    reverse(a+1,a+n+1);
    for(int i=1;i<=n;++i) W[i]=-inf;
}
void solve(int l,int r) {
    if(l==r) {
	W[l]=max(W[l],L[l-1]+R[l+1]+1-a[l]);
	return;
    }
    int mid=(l+r)>>1;
    if(l<=mid) solve(l,mid); if(mid<r) solve(mid+1,r);
    h=1,t=0;
    s[l-1]=0; for(int i=l;i<=r;++i) s[i]=s[i-1]+a[i];
    for(int i=l-1;i<=mid;++i) {
	x=i,y=L[i]+s[i]+1ll*i*(i-1)/2;
	while(h<t&&(q[t][1]-q[t-1][1])*(x-q[t][0])<=(y-q[t][1])*(q[t][0]-q[t-1][0])) t--;
	q[++t][0]=x,q[t][1]=y;
    }
    for(int i=mid+1;i<=r;++i) {
	while(h<t&&q[t][1]-q[t-1][1]<=(q[t][0]-q[t-1][0])*i) t--;
	V[i]=q[t][1]-s[i]+1ll*i*(i+1)/2-1ll*i*q[t][0]; V[i]+=R[i+1];
    }
    for(int i=r;i>mid;--i) {if(i<r) V[i]=max(V[i+1],V[i]);W[i]=max(W[i],V[i]);}
    reverse(a+l-1,a+r+2); reverse(R+l-1,R+r+2); reverse(L+l-1,L+r+2); h=1,t=0;
    s[l-1]=0; for(int i=l;i<=r;++i) s[i]=s[i-1]+a[i];
    mid=r-mid+l-1;
    for(int i=l-1;i<=mid;++i) {
	x=i,y=R[i]+s[i]+1ll*i*(i-1)/2;
	while(h<t&&(q[t][1]-q[t-1][1])*(x-q[t][0])<=(y-q[t][1])*(q[t][0]-q[t-1][0])) t--;
	q[++t][0]=x,q[t][1]=y;
    }
    for(int i=mid+1;i<=r;++i) {
	while(h<t&&q[t][1]-q[t-1][1]<=(q[t][0]-q[t-1][0])*i) t--;
	V[i]=q[t][1]-s[i]+1ll*i*(i+1)/2-1ll*i*q[t][0]; V[i]+=L[i+1];
    }
    for(int i=r;i>mid;--i) if(i<r) V[i]=max(V[i+1],V[i]);
    reverse(a+l-1,a+r+2); reverse(R+l-1,R+r+2); reverse(V+l-1,V+r+2); reverse(L+l-1,L+r+2);
    mid=r-mid+l-1;
    for(int i=l;i<=mid;++i) W[i]=max(W[i],V[i]);
    return;
}
int main()
{
    n=gi();
    for(int i=1;i<=n;++i) a[i]=gi();
    pre();
    solve(1,n);
    m=gi();
    for(int i=1,pos,v;i<=m;++i) {
	pos=gi(),v=gi();
	printf("%lld\n",max(L[pos-1]+R[pos+1],W[pos]-v+a[pos]));
    }
    return 0;
}

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

using namespace std;

#define ll long long

void solve()
{
    // 入力の処理
    ll N, A, B;
    cin >> N >> A >> B;

    // 0 オリジンに直す
    A--;
    B--;

    // 差が偶数の場合 (差が0は制約上考慮しない)
    if ((B - A) % 2 == 0)
    {
        cout << (B - A) / 2 << endl;
    }
    else
    {
        // 0-Aか B-Nの最大に近い方に寄せる
        // 両方とも同距離ならどっちかでいい
        if (A < ((N - 1) - B))
        {
            cout << A + 1 + (B - (A + 1)) / 2 << endl;
        }
        else
        {
            cout << ((N - 1) - B) + 1 + ((N - 1) - (A + ((N - 1) - B))) / 2 << endl;
        }
    }

    return;
}

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

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

li a, b, c;

int main () {
    fastIO;
    cin >> a >> b >> c;
    cout << (a+b+c - max({a, b, c}));
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String input = br.readLine();
    	String ans = "";
    	for (int i = 0; i < input.length(); i++)
    	{
    		if (Character.isLowerCase(input.charAt(i)))
    			ans += String.valueOf(Character.toUpperCase(input.charAt(i)));
    		else
    			ans += String.valueOf(Character.toLowerCase(input.charAt(i)));
    	}
    	System.out.println(ans);
	}

}

Measured memory_bytes: 29724
function Main(input){
  // 文字列を格納
  let str = input.trim().split('\n')[0];
  let ans = 'ABC';

  if (str == ans) {
    ans = 'ARC';
  } else {
    ans = 'ABC';
  }

  console.log(ans);
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    if(a % k == 0 || b % k == 0 || a/k < b/k) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

const ll M = 1e9+7;
const ll INF = 1e9+7;

ll n, ans;
ll last[220000], cnt[220000];

int main() {
  cin >> n;
  
  for (ll i = 0; i < 210000; i++) last[i] = -1;
  
  for (ll i = 0; i < n; i++) {
    ll c;
    cin >> c;
    if (i == 0) cnt[i] = 1;
    else cnt[i] = cnt[i-1];
    if (last[c] != -1 and last[c] != i-1) {
      cnt[i] += cnt[last[c]];
      cnt[i] %= M;
    }
    last[c] = i;
  }
            
  cout << cnt[n-1] << endl;
  return 0;
}

Measured memory_bytes: 3456
def myfun(c):
	return c[0];

h,w = map(int,input().split())

arr = [];
ans = [];

for i in range(h):

	temp = list(map(int,input().split()))
	arr.append(temp)

count=0;
for i in range(h):
	for j in range(w):

		if arr[i][j]%2==1:
			if j < w-1:
				count+=1
				ans.append( [i+1,j+1,i+1,j+2])
				arr[i][j+1]+=1;
				arr[i][j]-=1;
			elif i < h-1:
				count+=1;
				ans.append( [i+1,j+1,i+2,j+1])
				arr[i][j]-=1;
				arr[i+1][j]+=1;

print(count)
for i in range(count):
	print(*ans[i]);


Measured memory_bytes: 30292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
int main()
{
       ll a,b,c;
       cin>>a>>b>>c;
       ll k;
       cin>>k;
       ll ans = 0;
       ans += min(a,k);
       k -= min(a,k);
       if(!k){
              cout<<ans;
              return 0;
       }
       ans += 0;
       k -= min(b,k);
       if(!k){
              cout<<ans;
              return 0;
       }
       ans -= min(c,k);
       cout<<ans<<endl;

}


Measured memory_bytes: 3616
IDENTIFICATION                    DIVISION.
PROGRAM-ID.                       PROGRAM_ID.

DATA                              DIVISION.
WORKING-STORAGE                   SECTION.
01 LN           PIC X(8).
01 N            PIC 9(3).
01 R            PIC 9(4).
01 ans          PIC Z(3)9.

PROCEDURE                         DIVISION.
    ACCEPT LN.
    UNSTRING LN DELIMITED BY SPACE INTO N R.
    IF 10 <= N
        MOVE R TO ans
    ELSE
        COMPUTE ans = R + 100 * (10 - N)
    END-IF.
    DISPLAY ans.
    STOP RUN.


Measured memory_bytes: 636
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N, p;
  cin >> N;
  int m = N + 100;
  int ret = 0;
  for (int i=0; i<N; i++) {
    cin >> p;
    if (p <= m) {
      ret++;
      m = p;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    int num,n;
    while(~scanf("%d",&n))
    {
        num=0;
        for(int i=0;i<=9;i++)
        {
            for(int j=0;j<=9&&i+j<=n;j++)
            {
                for(int k=0;k<=9&&i+j+k<=n;k++)
                {
                    for(int m=0;m<=9;m++)
                    {
                        if(i+j+k+m==n)
                        {
                            num++;
                            break;
                        }
                    }
                }
            }
        }
        cout<<num<<endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n;cin >> n;
	vector<ll> v(n+1);REP(i, n+1)cin >> v[i];

	if(n != 0 && v[0] != 0){
		cout << -1 << endl;
		return 0;
	}

	ll sum = 0;
	REP(i, n+1)sum += v[i];

	ll ans = 0;
	ll now = 1;
	REP(i, n+1){
	//	cout << "now: " << now << endl;
		ans += now;
		now -= v[i];
		if(i != n && now <= 0){
			cout << -1 << endl;
			return 0;
		}
		sum -= v[i];
		now = min(sum, now * 2);
	}
	//cout << "now: " << now << endl;
	if(now != 0)cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3992
#include <stdio.h>
int main(void){
 
    int W,H,x,y,r;
    int cross_circle_left,cross_circle_right;
    int vertical_circle_up,vertical_circle_down;
    
//    int pi = 3.1415926535;
    
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    //printf("%d %d %d %d %d\n",W,H,x,y,r);
    
    cross_circle_left = x - r;
    cross_circle_right  = x + r;
    vertical_circle_up = y + r;
    vertical_circle_down = y - r;
    
    if( (cross_circle_right <= W) && (cross_circle_left >= 0) ){
        if( (vertical_circle_up <= H) && (vertical_circle_down >= 0) ){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }
    else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans = 0;
        if (A>=13) {
            ans = B;
        }else if(6<=A && A<=12){
            ans = B/2;
        }else{
            ans = 0;
        }
    System.out.println(ans);
    }
}

Measured memory_bytes: 23124
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	N := sc.nextInt()
	An := sc.nextInts()
	target := 1
	for i := 0; i < N; i++ {
		if An[i] == target {
			target++
		}
	}
	if target == 1 {
		fmt.Println(-1)
	} else {
		fmt.Println(N - (target - 1))
	}
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 10240
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

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

    int n,p[25];
    cin>>n;

    reps(i,n){
	cin>>p[i];
    }

    int sum=0;
    for(int i=2;i<n;i++){
	if(min(p[i-1],p[i+1])<p[i] && p[i]<max(p[i-1],p[i+1])){
	    sum++;
	}
    }
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	long long N;
	cin>>N;
	vector<long long> A(N,0);
	vector<long long> B(N,0);
	long long i;
	long long aw=0;
	bool allOK=true;
	for (i=0;i<N;i++){
		cin>>A[i]>>B[i];
		if (A[i]%B[i]!=0){
			allOK=false;
		}
	}
	if (allOK){
		cout<<0<<endl;
		return 0;
	}
	long long x=0;
	for (i=N-1;i>=0;i--){
		if (A[i]<B[i]){
			x=B[i]-A[i];
			A[i]+=x;
			aw+=x;
		}else if (A[i]>B[i]){
			if (A[i]%B[i]!=0){
				x=(A[i]/B[i]+1)*B[i]-A[i];
				A[i]+=x;
				aw+=x;

			}
		}
		if (i>0){
			A[i-1]+=aw;
		}
	}
	cout<<aw<<endl;
	return 0;
}

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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double
#define all(x) x.begin(), x.end()
#define uniq(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

//random_device rd;
//mt19937_64 gen(rd());
//
//template<typename T>
//T rand(T l, T r) {
//    uniform_int_distribution<T> uid(l, r);
//    return uid(gen);
//}

const int maxn = 1e6 + 9;
int cnt[maxn];
int n;
int a[maxn];

bool f(int x, int y)
{
    return !(cnt[x] - cnt[y] - cnt[x - y]);
}

bool solve()
{
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (f(n - 1, i))
            ans ^= a[i];
    }
    return (ans & 1);
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++)
        a[i] = (s[i] - '1');
    for (int i = 2; i <= n; i++)
    {
        cnt[i] = cnt[i - 1];
        int u = i;
        while (u % 2 == 0)
        {
            u /= 2;
            cnt[i]++;
        }
    }
    if (solve())
    {
        cout << 1;
        return 0;
    }
    for (int i = 0; i < n; i++)
    {
        if (a[i] == 1)
        {
            cout << 0;
            return 0;
        }
        a[i] /= 2;
    }
    if (solve())
        cout << 2;
    else
        cout << 0;
}


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

int main ()
{
    string S;
    cin >> S;
    bool palindrome = true;

    if (S.size()%2 != 0)
    {
        int i = 0, j = S.size()-1;
        while (i!=j)
        {
            palindrome = palindrome && (S[i] == S[j]);
            i++;
            j--;
        }

        i = 0; j++;
        while (j != S.size())
        {
            palindrome = palindrome && (S[i] == S[j]);
            i++;
            j++;
        }
    }
    else
    {
        palindrome = false;
    }

    if(palindrome)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 3588
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.size = [1]*size

    def __str__(self):
        from collections import defaultdict
        d = defaultdict(set)
        for i in range(len(self.parent)):
            d[self.find(i)].add(i)
        return str(dict(d))    

    def find(self, x):
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]
    
    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.size[y] += self.size[x]
            self.parent[x] = y
        else:
            self.size[x] += self.size[y]
            self.parent[y] = x
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def sizeofset(self, x):
        return self.size[self.find(x)]

if __name__ == "__main__":
    N,M = map(int,input().split())
    uf = UnionFind(N)
    p = list(map(lambda x:int(x)-1,input().split()))
    for i in range(M):
        x,y = map(lambda x:int(x)-1,input().split())
        uf.unite(x, y)
    ans = 0
    for i in range(N):
        if uf.same(p[i], i):
            ans += 1
    print(ans)

Measured memory_bytes: 18608
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

vector<string> board(4);
vector<vector<int> > memo;

int solve(int y, int x, bitset<16> bs, string& word)
{
    if(memo[y*4+x][bs.to_ulong()] != -1)
        return memo[y*4+x][bs.to_ulong()];

    if(board[y][x] != word[bs.count()])
        return 0;

    bs[y*4+x] = true;
    if(word.size() == bs.count())
        return 1;

    int ret = 0;
    for(int i=0; i<9; ++i){
        int y2 = y + i / 3 - 1;
        int x2 = x + i % 3 - 1;
        if(y2 < 0 || y2 >= 4 || x2 < 0 || x2 >= 4)
            continue;
        if(!bs[y2*4+x2])
            ret += solve(y2, x2, bs, word);
    }

    bs[y*4+x] = false;
    return memo[y*4+x][bs.to_ulong()] = ret;
}

int main()
{
    int n;
    cin >> n;
    vector<string> word(n);
    vector<int> score(n);
    for(int i=0; i<n; ++i)
        cin >> word[i] >> score[i];
    for(int i=0; i<4; ++i)
        cin >> board[i];
    int t;
    cin >> t;

    vector<vector<int> > x(9);
    for(int i=0; i<n; ++i){
        memo.assign(16, vector<int>(1<<16, -1));
        int ret = 0;
        for(int y=0; y<4; ++y){
            for(int x=0; x<4; ++x){
                ret += solve(y, x, 0, word[i]);
            }
        }

        vector<int> v(ret, score[i]);
        x[word[i].size()].insert(x[word[i].size()].end(), v.begin(), v.end());
    }

    for(int i=1; i<=8; ++i)
        sort(x[i].rbegin(), x[i].rend());

    vector<int> dp(t+1, 0);
    for(int i=1; i<=8; ++i){
        for(int j=t; j>=0; --j){
            int sum = 0;
            for(unsigned k=0; k<x[i].size(); ++k){
                sum += x[i][k];
                int j2 = j + i * (k + 1);
                if(j2 > t)
                    break;
                dp[j2] = max(dp[j2], dp[j] + sum);
            }
        }
    }
    cout << dp[t] << endl;

    return 0;
}

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

int main(){
    int b;
    int a;
    cin >> a >> b;
    if(a < b){
        for (int i = 0; i < b;i++)
        {
            cout << a;
        }
    }
    else{
        for (int i = 0; i < a;i++)
        {
            cout << b;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
Y = []
Z = []

if(M <= N):
  print(0)
  
else :  
  for i in range(len(X)-1):
    sub = abs(X[i+1] - X[i])
    Y.append(sub)
  Y.sort()
  Y.reverse()
  xid = 0
  for i in range(N-1):
    Z.append(Y[i])

  ans = sum(Y)-sum(Z)
  if ans < 0:
    ans = 0
  print(ans)

Measured memory_bytes: 13968
#include <stdio.h>

int main()
{
    int i, D, N, M;
    scanf("%d %d", &D, &N);
    
    if(N == 100){
        M = 101; 
    }else{
        M = N;
    }
    
    for(i=0;i<D;i++){
        M *= 100;
    }
    
    printf("%d\n", M);
    
    return 0;
}

Measured memory_bytes: 128
s = input()
c = 'abcdefghijklmnopqrstuvwxyz'

ans = len(s)

if len(set(s)) == 1:
    print("0")
    exit(0)

for j in range(len(c)):
    cnt = 0
    t = ''
    if c[j] in s:
        m = s
        while(1):
            t = ''
            for i in range(len(m)-1):
                if m[i] == c[j]:
                    t = t + c[j]
                elif m[i+1] == c[j]:
                    t = t + c[j]
                else:
                    t = t + m[i]
            m = t
            cnt += 1
            if len(set(t)) == 1:
                break
        ans = min(cnt, ans)

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
typedef long long LL;
using namespace std;
const int maxn=2*1e5+10;
LL a[maxn];
map<LL, LL> ms;
int main()
{
    int n;
    scanf("%d", &n);
    int sum=0;
    for (int i=1; i<=n; i++)
        scanf("%lld", &a[i]);
    LL ans=0, ret=0;
    ms[0]=1;
    for (int i=1; i<=n; i++)
    {
        ret+=a[i];
        if (!ms.count(ret))
        {
            ms[ret]=1;
        }else
        {
            ms[ret]++;
        }
    }
    for (auto it=ms.begin(); it!=ms.end(); it++)
    {
        ans+=(it->second )* (it->second - 1) /2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 14336
# field[x][y], field[h][w]

def debug_field(field)  
  puts field.map {|x| x.join("")}.join("\n")
end

def bfs(h, w, i, j, field)
  items = []
  items << [i, j]
  field[i][j] = '#'
  count = 1
  until items.empty?
    v = items.shift
    [[1, 0], [0, 1],
     [-1, 0], [0, -1]].each do |dx, dy|
      x_new, y_new = [v[0] + dx, v[1] + dy]
      next if x_new >= h or x_new < 0
      next if y_new >= w or y_new < 0
      next if field[x_new][y_new] == '#'
      count += 1
      field[x_new][y_new] = '#'
      items << [x_new, y_new]
    end
  end
  count
end

def solve(height, width, field)
  field.each.with_index do |row, i|
    row.each.with_index do |t, j|
      return puts bfs(height, width, i, j, field) if t == '@'
    end
  end
end

data = $stdin.read.split("\n")
until data.empty?
  width, height = data[0].split(" ").map(&:to_i)
  field = data[1..-1].map(&:chars)
  solve height, width, field
  data = data[(height + 1)..-1]
end

Measured memory_bytes: 22216
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end


n = inp[0]
s = gets.split("")
eh = {"R" => 0 , "G" => 1, "B" => 2}
t = na2(n,3)
n.times do |i|
  3.times do |j|
    t[i][j] = t[i-1][j]
  end
  t[i][eh[s[i]]] += 1
end

ans = 0
n.times do |i|
  (i+1).upto(n-2) do |j|
    next if(s[i] == s[j])
    sa = j - i
    nokori = (3 - eh[s[i]] - eh[s[j]])%3
    ans += t[-1][nokori] - t[j][nokori]
    ans -= 1 if j + sa < n and eh[s[j+sa]]==nokori
  end
end
p ans

Measured memory_bytes: 14424
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

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

    int X; cin >> X;
    LL ok = 1e9+10;
    LL ng = 0;
    while(abs(ok-ng) > 1){
        LL mid = (ok + ng) / 2;
        if((mid+1)*(mid) / 2 >= X){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;


}



Measured memory_bytes: 256