akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
using namespace std;
int intinput() {
	int x;
	cin >> x;
	return x;
}
vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	char a;
	cin >> a;
	if(isupper(a)){
		cout << 'A' << endl;
	}else{
		cout << 'a' << endl;
	}
}

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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 2100;
ll dp[maxn][maxn];
struct node
{
    ll num;
    ll pos;
};
node a[maxn];
bool cmp(const node &a, const node &b)
{
    return a.num > b.num;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    //vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].num;
        a[i].pos = i;
    }
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j + i < n; j++)
        {
            ll now = i + j + 1;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[now].num * abs(a[now].pos - i - 1));
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + a[now].num * abs(a[now].pos - (n - j)));
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n; i++)
    {
        ans = max(dp[i][n - i], ans);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 26632
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    vector<long long> num(1100000, 0);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        auto pf = prime_factorize(A[i]);
        for (auto p : pf) num[p.first] = max(num[p.first], p.second);
    }

    mint LCM = 1;
    for (int v = 2; v < 1100000; ++v) {
        LCM *= modpow(mint(v), num[v]);
    }

    mint res = 0;
    for (auto a : A) {
        res += LCM / a;
    }
    cout << res << endl;
}

Measured memory_bytes: 8960
#include<stdio.h>

int main(){
 
  int n, m;
  int box1[100][100];
  int box2[100];
  int i, j;
  int input;
  int box3[100];
  int sum;
  
  
  scanf("%d %d", &n, &m);
  for(i = 0; i < n; i++)
  {
    for(j = 0; j < m; j++)
    {
     
      scanf("%d", &input);
    
      box1[i][j] = input;
      
    
    }
  
  }
  
  for(i = 0; i < m; i++)
  {
   
    scanf("%d", &input);
   
    box2[i] = input;
  
      
  }

  for(i = 0; i < n; i++)

  {

    sum = 0;
    
    for(j = 0; j < m; j++)
    
    {
      sum += box1[i][j] * box2[j];
    }
    
    box3[i] = sum;

  }

  for(i = 0; i < n; i++)
  
  {
    printf("%d\n", box3[i]);
  }
  
  return 0;
}


Measured memory_bytes: 2112
#include<stdio.h>

void countingsort(int *,int *,int);

int main(){
  int n,i;
  scanf("%d",&n);
  int A[n],B[n];
  for(i=0;i<n;i++){
    scanf("%d",A+i);
  }
  
  countingsort(A,B,n);

  printf("%d",B[0]);

  for(i=1;i<n;i++) printf(" %d",B[i]);
  printf("\n");

  return 0;
}

void countingsort(int *A,int *B,int n){
  int C[10000],i;

  for(i=0;i<10000;i++) C[i]=0;

  for(i=0;i<n;i++) B[i]=0;

  for(i=0;i<n;i++) C[A[i]]++;

  for(i=1;i<10000;i++) C[i]=C[i]+C[i-1];
  
  for(i=n-1;i>=0;i--){
    B[C[A[i]]-1] = A[i];
    C[A[i]]--;
  }
}



Measured memory_bytes: 17396
# include<iostream>
# include<string>
# include<algorithm>
using namespace std;
# define N 300
# define M 1000
# define L 1001

int main(){
    int q;
    cin >> q;
    string iranai; iranai = cin.get(); //改行文字を排除

    string A[N][M];
    int cnt[N];
    for(int i=0; i<(q*2); i++){
        int j=0;
        while((A[i][j] = cin.get()) != "\n"){
            j++;
            cnt[i]++;
        }
    }

    for(int k=0; k<(q*2); k+=2){
        int B[L][L];
        for(int i=0; i<=cnt[k]; i++){
            string str;
            if(i!=0) str = A[k][i-1];
            for(int j=0; j<=cnt[k+1]; j++){
                if(i==0 || j==0) B[i][j] = 0;
                else if(A[k+1][j-1] != str) B[i][j] = max(B[i-1][j], B[i][j-1]);
                else B[i][j] = B[i][j] = B[i-1][j-1] + 1;
            }
        }
        cout << B[cnt[k]][cnt[k+1]] << "\n";
    }
    return 0;
}


Measured memory_bytes: 11288
import numpy as np
if __name__ == "__main__":
    A, B, H, M = map(int, input().split())
    a = 0.5 * (60 * H + M) 
    b = 6 * M 
    #print(a, b)
    a = a * np.pi / 180
    b = b * np.pi / 180
    #print(a, b)
    

    c1 = np.sqrt(A**2 + B**2 - 2 * A * B * np.cos(a-b))
    c2 = np.sqrt(A**2 + B**2 - 2 * A * B * np.cos(b-a))
    print(min(c1, c2))

Measured memory_bytes: 27196
main = do
  [a, b, c, x, y] <- map (read :: String -> Int) <$> words <$> getLine
  let ab = a + b
  let c' = c * 2
  putStrLn $ show $ (min x y) * (min ab c') + if x > y then (min a c') * (x -y) else (min b c') * (y-x)

Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

void solve(){
	
  vector<string> v(12);
  while(cin >> v[0]){
	  for(int i = 1; i < 12; i++) cin >> v[i];
	  bool visited[12][12];
	  for(int i = 0; i < 12; i++){
		for(int j = 0; j < 12; j++){
			 visited[i][j] = false;
		   }  
		}
	   int ret = 0;
	   for(int i = 0; i < 12; i++){
		for(int j = 0; j < 12; j++){
			 if(v[i][j] == '1' && !visited[i][j]){
				 ret++;
				 queue< pair<int, int> > q;
				 q.push(make_pair(i, j));
				 while(!q.empty()){
				  auto p = q.front();
				  q.pop();
				  int nx = p.first, ny = p.second;
				  for(int i = 0; i < 4; i++){
					  int x = nx + dx[i];
					  int y = ny + dy[i];
					  if( x >= 0 && y >= 0 && x < 12 && y < 12){
						  if (v[x][y] == '1' && !visited[x][y]){
							  visited[x][y] = true;
							  q.push(make_pair(x, y));  
							}  
						}  
					}	 
				}
		   }   
		}
	}
  cout << ret << endl;		
 }
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
using namespace std;
signed main(){
    int n,m;
    cin>>n>>m;
    int k[10];
    int s[10][10];
    int p[10];
    int ans=0;
    for(int i=0;i<m;i++){
        cin>>k[i];
        for(int j=0;j<k[i];j++){
            cin>>s[i][j];
        }
    }
    for(int i=0;i<m;i++){
        cin>>p[i];
    }
    int l[10];
    for(int i=0;i<pow(2,n);i++){
        int g=i;
        for(int j=n-1;j>=0;j--){
            l[j]=g/pow(2,j);
            g-=l[j]*pow(2,j);
        }
        bool h=true;
        for(int i=0;i<m;i++){
            int count=0;
            for(int j=0;j<k[i];j++){
                if(l[s[i][j]-1]==1)count++;
            }
            if(count%2!=p[i])h=false;
        }
        if(h==true)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

#define lli long long int

int main() {
	lli n, k, banyak[200010], x, ans = 0;
	scanf("%lld %lld", &n, &k);
	memset(banyak, 0, sizeof banyak);
	for (lli i = 1; i <= n; i++)
		banyak[i % k]++;
	for (lli i = 0; i < k; i++) {
		x = (k - i) % k;
		if ((2 * x) % k == 0)
			ans += (banyak[i] * banyak[x] * banyak[x]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1664
H, W, D = [int(x) for x in input().split()]
A = [0] * (H * W + 1)
for h in range(H):
    inp = [int(x) for x in input().split()]
    for i, a in enumerate(inp):
        A[a] = (i + 1, h + 1)

table = [0] * (H * W + 1)
for i in range(D):
    x = H * W - i - D
    r = 0
    while x > 0:
        table[x] = abs(A[x][0] - A[x+D][0]) + abs(A[x][1] - A[x+D][1]) \
                   + r
        r = table[x]
        x -= D
for q in range(int(input())):
    l, r = [int(x) for x in input().split()]
    print(table[l] - table[r])


Measured memory_bytes: 14648
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

int n, m;
vector<vector<int> > G(100010);
vector<vector<int> > G2(100010);
int vis[100010];
int ty[100010];
long long val[100010];
long long res;
long long x;

int dfs(int u)
{
	int i, v;
	int t2;
	long long v2;
	for(i=0; i<G[u].size(); i++){
		v = G[u][i];
		t2 = 1 - ty[u];
		v2 = G2[u][i] - val[u];
		if(vis[v] == 1){
			if(t2 == ty[v]){
				if(v2 != val[v])
					return 0;
			}
			else{
				if(abs(val[v]-v2) % 2 == 0){
					x = abs(val[v]-v2)/2;
					return 2;
				}
				else
					return 0;
			}
		}
		else{
			ty[v] = t2;
			val[v] = v2;
			vis[v] = 1;
			int r = dfs(v);//
			if(r==0 || r==2)
				return r;
		}
	}
	return 1;
}

int dfs2(int u)
{
	int i, v;
	long long v2;
	for(i=0; i<G[u].size(); i++){
		v = G[u][i];
		if(vis[v] == 1){
			if(G2[u][i] - val[u] != val[v])
				return 0;
		}
		else{
			vis[v] = 1;
			val[v] = G2[u][i] - val[u];
			if(val[v] <= 0)
				return 0;
			if(dfs2(v) == 0)
				return 0;
		}
	}
	return 1;
}

void solve()
{
	int i;
	vis[0] = 1;
	ty[0] = 0;
	val[0] = 0;
	int r = dfs(0);
	if(r == 0)
		printf("0\n");
	else if(r == 2){
		for(i=0; i<n; i++)
			vis[i] = 0;
		val[0] = x;
		vis[0] = 1;
		if(dfs2(0) == 0)
			printf("0\n");
		else
			printf("1\n");
	}
	else{
		long long mn = 1;
		long long mx = 1000000000;
		long long tmp;
		for(i=0; i<n; i++){
			if(ty[i] == 0){
				tmp = -val[i] + 1;
				if(tmp > mn)
					mn = tmp;
			}
			else{
				tmp = val[i] - 1;
				if(tmp < mx)
					mx = tmp;
			}	
		}
		if(mx<mn)
			printf("0\n");
		else
			printf("%lld\n", mx-mn+1);
	}
}

int main()
{
	int i;
	int u, v, s;
	scanf("%d%d", &n, &m);
	for(i=0; i<m; i++){
		scanf("%d%d%d", &u, &v, &s);
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
		G2[u].push_back(s);
		G2[v].push_back(s);
	}
	solve();
	return 0;
}

Measured memory_bytes: 17408
#include <iostream>
#include <algorithm>

using namespace std;

main(){
  int a, b, c, d, e, na, nb, nc, ans;
  while(cin >> a >> b >> c >> d >> e >> na >> nb >> nc && a){
    ans = a * na + b * nb + c * nc;
    if(nc < d){
      if(nb + nc >= d) ans = min(ans, a * na + b * (nb - (d - nc)) + e * d);
      else if(na + nb + nc >= d) ans = min(ans, a * (na - (d - nb - nc)) + e * d);
      else ans = min(ans, e * d);
    }else ans = min(ans, a * na + b * nb + e * nc);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;


struct edge{
    int to;
    ll cost;
    edge(int to, ll cost): to(to), cost(cost){}
};

int n, m;
vector<vector<edge>> G;
vector<bool> used;
map<int, P> memo;

P intersection(P a, P b){
    return make_pair(max(a.first, b.first), min(a.second, b.second));
}

P dfs(int v, P a_s){
    used[v] = true;
    memo[v] = a_s;
    P ret(1, 1000000000);
    for(edge& e : G[v]){
        P b = make_pair(-a_s.first, e.cost - a_s.second);

        if(!used[e.to]) {
            ret = intersection(ret, dfs(e.to, b));
        }else{
            P c = memo[e.to];
            if(c.first != b.first){
                if(abs(b.second - c.second) % abs(c.first - b.first) == 0){
                    ll a = (b.second - c.second) / (c.first - b.first);
                    ret = intersection(ret, P(a, a));
                }else{
                    ret = P(0, -1);
                }
            }else{
                if(c.second - b.second != 0){
                    ret = P(0, -1);
                }
            }
        }

        if(b.first == 0){
            ll a = b.second - e.cost;
            ret = intersection(ret, P(a, a));
        }else if(b.first > 0){
            ret.first = max(ret.first, (1 - b.second + b.first - 1) / b.first);
        }else{
            ret.second = min(ret.second, (b.second - 1) / abs(b.first));
        }
    }
    return ret;
}

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

    G.assign(n, {});
    for(int i=0;i<m;i++){
        int u, v;
        ll s;
        cin >> u >> v >> s;
        u--;
        v--;
        G[u].emplace_back(v, s);
        G[v].emplace_back(u, s);
    }

    used.assign(n, false);
    auto a_range = dfs(0, make_pair(1, 0));
    // cout << a_range.first << " " << a_range.second << endl;
    cout << max(0LL, a_range.second - a_range.first + 1) << endl;

    return 0;
}

Measured memory_bytes: 26496
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 100005;
const int INF = 1e9+7;
int n, a[MX], b[MX];
int main(){
	scanf("%d", &n);
	fill(b,b+n+1,INF);
	rep(i,n) scanf("%d", a+n-1-i);
	rep(i,n) *upper_bound(b,b+n,a[i]) = a[i];
	rep(i,n+1) if(b[i]==INF) return 0*printf("%d\n",i);
}

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

using namespace std;

int main() {

    string* s = new string[7]{ "SAT", "FRI", "THU", "WED", "TUE", "MON",  "SUN" };
    string s1;
    cin >> s1;
    for (int i = 0; i < 7; i++)

        if (s[i] == s1){
            cout << i + 1;  break;


}



    return 0; 
}


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

using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
}

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif



void solve()
{

   string s1,s2;
   cin>>s1>>s2;

   int res=0;

   for(int i=0;i<s1.size();i++){

    if(s1[i]==s2[i]){
        res++;
    }
   }

   cout<<res<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define int long long
using namespace std;

template<class T>
T gcd(T a,T b){
	return b ? gcd(b,a % b) : a;
}

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

signed main(){
    int n,m;
    string s,t;
    cin >> n >> m >> s >> t;
    int g = gcd(n,m),l = lcm(n,m);
    for(int i = 0;i < g;i++){
        if(s[n / g * i] != t[m / g * i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << l << endl;
}

Measured memory_bytes: 512
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 C = sc.nextInt();
		if (A==B&&B==C) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define pair pair<ll,ll>
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 1000000000
#define INF 1000000000000005
#define N 10000
#define NN 1e18
/*
std::cout << std::fixed;
std::cout << std::setprecision(1);
std::cout << VALUE NAME<<endl;
*/
ll tra[100006],tra1[100006];

int main()
{

    fast_cin;

    ll save;
    ld save1;
    cin>>save>>save1;

    ll ans=round(save1*100);

    cout<<(ans*save)/100<<endl;
}



Measured memory_bytes: 3812
#include <atcoder/fenwicktree.hpp>
#include <iostream>

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

using ll = long long;
using namespace std;
using namespace atcoder;

int main(void) {
    int n, q;
    cin >> n >> q;

    fenwick_tree<ll> bit(n);

    rep(i, n) {
        ll val;
        cin >> val;
        bit.add(i, val);
    }

    rep(loop, q) {
        int t;
        cin >> t;
        if (t) {
            ll l, r;
            cin >> l >> r;
            cout << bit.sum(l, r) << endl;
        } else {
            ll p, x;
            cin >> p >> x;
            bit.add(p, x);
        }
    }

    return 0;
}

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

using namespace std;

const int maxn=1e7+10;

int num[maxn];

void init( int n )
{
	for( int i=1;i<=n;i++ )
	{
		num[i]++;
		for( int j=i*2;j<=n;j+=i ) num[j]++;
	}
}


int main()
{
	int n;
	scanf("%d",&n);
	long long ans=0;
	
	init(n);
	for( int i=1;i<=n;i++ )
	{
		ans+=1ll*i*num[i];
	} 
	printf("%lld\n",ans);
}

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

int main(int argc, const char * argv[]) {
    uint32_t K;
    cin >> K;
    string S;
    cin >> S;
    
    if (S.size() <= K) {
        cout << S;
    }else {
        string s = S.substr(0, K);
        cout << s << "...";
    }

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define endl '\n'

int main()
{
    string s,t;
    cin>>s>>t;
    ll s_size=s.size();
    ll t_size=t.size();
    string ans="";
    ll dp[s_size+1][t_size+1];

    for(ll j=0;j<=s_size;j++)
    {
        for(ll k=0;k<=t_size;k++)
        {
            if(j==0 || k==0)
              {

                dp[j][k]=0;
              }
            else if(s[j-1]==t[k-1])
            {
                dp[j][k]=dp[j-1][k-1]+1;

            }
            else dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
        }
    }
  /*  for(ll j=0;j<=s_size;j++)
    {
        for(ll k=0;k<=t_size;k++)
        {
            cout<<dp[j][k]<<" ";
        }
        cout<<endl;
    }*/

    ll j=s_size,k=t_size;
    while(j>0 && k>0)
    {
        if(s[j-1]==t[k-1])
        {
            ans+=s[j-1];
            k--;
            j--;
        }
        else if(dp[j-1][k]>dp[j][k-1])j--;
        else k--;
    }
reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s,t) sort((s).begin(),(s).end(),greater<t>())

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int N; vi A; vi B;
void input()
{
    cin>>N;
    rep(i,N){
        int a; cin>>a; A.emplace_back(a); B.emplace_back(a);
    }
    return;
}

void solve()
{
    SORT(A);
    int max=*(A.end()-1);
    int sec_max=*(A.end()-2);
    rep(i,N){
        if(B[i]==max) cout<<sec_max<<"\n";
        else cout<<max<<"\n";
    }
    return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

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

#define int long long

using namespace std;

int n,m,ans=-999999999999999999;

main(){
	cin>>n>>m;
	int a[n][3],oa[n][3];
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<8;i++){
		int tmp[n]={},ass=0;
		
		for(int j=0;j<n;j++){
			
			for(int k=0;k<3;k++){
				
				if((i>>k)&1)tmp[j]-=a[j][k];
				else tmp[j]+=a[j][k];
			}
			
		}
		sort(tmp,tmp+n);
		reverse(tmp,tmp+n);
		
		for(int j=0;j<m;j++){
			ass+=tmp[j];
		}
		ans=max(ans,ass);
	}
	cout<<ans<<endl;
}

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

const int INF = 1001001001;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    --x; --y;
    vector<int>  ans(n);
    rep(a,n) {
        vector<int> dist(n, INF);
        queue<int> q;
        auto push = [&](int v, int d) {
            if(dist[v]!=INF) return;
            dist[v] = d;
            q.push(v);
        };
        push(a, 0);
        while(!q.empty()) {
            int v = q.front(); q.pop();
            int d = dist[v];
            if(v-1 >= 0) push(v-1, d+1);
            if(v+1 < n) push(v+1, d+1);
            if(v==x) push(y,d+1);
            if(v==y) push(x,d+1);
        }
        rep(i,n) ans[dist[i]]++;
    }
    rep(i,n) ans[i]/=2;
    for(int i = 1; i < n; ++i){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import math
import sys
from itertools import permutations
input = sys.stdin.readline

K=int(input())

cur=1
ans=-1
now=0
for i in range(1000010):
	now += 7*cur
	if now%K==0:
		ans=(i+1)
		break
	cur*=10
	cur=cur%K

print(ans)


Measured memory_bytes: 63804
N = int(input())
a = list(map(int, input().split()))
Alice = 0
Bob = 0
for i in range(N):
  if (i+1)%2 == 1:
    Alice += max(a)
    a.remove(max(a))
  else:
    Bob += max(a)
    a.remove(max(a))
print(Alice - Bob)

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

using namespace std;

int main() {
    long long a,b,c,x,y;
    long long ans = 1e18;
    cin >> a >> b >> c >> x >> y;
    ans = min(ans, min(x,y) * c * 2 + (x - min(x,y)) * a + (y - min(x,y)) * b);
    ans = min(ans,x * a + y * b);
    ans = min(ans, max(x,y) * 2 * c);
    cout << ans;
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	while(true){
		int x, y;
		cin >> x >> y;
		if(x+y==0) break;
		int dp[x][y] = { };
		int n;
		cin >> n;
		REP(i, n){
			int xn, yn;
			cin >> xn >> yn;
			dp[xn-1][yn-1] = -1;
		}
		dp[0][0] = 1;
		REP(i, x){
			REP(j, y){
				if(dp[i][j] != -1){
					if(i != 0 && dp[i-1][j] != -1) dp[i][j] += dp[i-1][j];
					if(j != 0 && dp[i][j-1] != -1) dp[i][j] += dp[i][j-1];
				}
			}
		}
		cout << dp[x-1][y-1] << endl;
	}
	return 0;
} 


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

using namespace std;
int main() {
  long long x, k, d;
  cin >> x >> k >> d;
  if (x < 0) x = -x;

  if (x / d > k && x > 0) {
    cout << x - d * k;
    return 0;

  } else if (x / d > k && x < 0) {
    cout << (x - k * d);
    return 0;
  } else {
    long long a = x % d;
    long long a_minus = a - d;
    long long b = k - x / d;

    if (b % 2 == 0 && x > 0) {
      cout << a;
      return 0;
    } else if (b % 2 == 0 && x < 0) {
      cout << a;
      return 0;
    } else if (b % 2 != 0 && x > 0) {
      cout << -a_minus;
      return 0;
    } else {
      cout << -a_minus;
      return 0;
    }
  }
}


Measured memory_bytes: 3628
N = int(input())
CSF = [0] + [list(map(int, input().split())) for _ in range(N-1)]

def start_from(i,t):
  if i==N:
    return t
  else:
    c,s,f = CSF[i]
    departure = max(s, (t//f + bool(t%f))*f)
    return start_from(i+1, departure + c)
  
for i in range(1,N):
  print(start_from(i, 0))
print(0)
  
                    


Measured memory_bytes: 3700
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 

int digits(int x )
{
	int count = 0;

	while(x!=0)
	{
		x=x/10;
		count+=1;
	}

	return count;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int N;
	cin>>N;

	int answer = 0;

	for(int x=1;x<=N;x++)
	{
		if(digits(x)%2!=0)
			answer+=1;
	}

	cout<<answer<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
char a[1005];
int main()
{
	int ans=inf;
	scanf("%s",a);
	for(int i=0;a[i+2];i++)
	{
		ans=min(ans,abs(753-((a[i]-'0')*100+(a[i+1]-'0')*10+(a[i+2]-'0'))));
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

intmax_t min(intmax_t a, intmax_t b)
{
    return a < b ? a : b;
}

int main(void)
{
    intmax_t H, N, A[(int)1e3], B[(int)1e3];

    scanf("%jd%jd", &H, &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd%jd", &A[i], &B[i]);
    }

    intmax_t dp[(int)1e4 + 1];
    for (size_t i = 0; i < (sizeof(dp) / sizeof(dp[0])); i++) {
        dp[i] = (intmax_t)1e4 * (intmax_t)1e4;
    }
    dp[0] = 0;
    for (size_t i = 0; i < N; i++) {
        for (size_t j = 0; j < H; j++) {
            size_t next = min(j + A[i], H);
            dp[next] = min(dp[next], dp[j] + B[i]);
        }
    }

    printf("%jd\n", dp[H]);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  for (j=1;j<=n;j++)
  {
    key=A[j];
    i=j-1;
    while (i>0&& A[i]>key)
    {
      A[i+1]=A[i];
      i--;
    }
    A[i+1]=key;
    trace(A, n);
  }
  
  
  return 0;
}

Measured memory_bytes: 1864
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    int n; cin >> n;
    int perm[n], x[n], y[n];
    for (int i = 0; i < n; i++) perm[i] = i;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

    double sum = 0;
    do {
        for (int i = 0; i < n - 1; i++) {
            sum += sqrt(pow(x[perm[i+1]] - x[perm[i]], 2) + pow(y[perm[i+1]] - y[perm[i]], 2));
        }
    } while (next_permutation(perm, perm + n));
    for (int i = n; i > 1; i--) sum /= i;
    cout << setprecision(10) << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll depth[100005];
vector<edge> g[100005];

void dfs(int v, int p, ll d) {
  depth[v] = d;
  for (auto e : g[v]) {
    if (e.to == p) continue;
    dfs(e.to, v, d + e.cost);
  }
}

int main() {
  IOS;

  int n; cin >> n;
  REP(i,n-1) {
    int a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  int q,k; cin >> q >> k;
  k--;

  dfs(k, -1, 0);

  REP(i,q) {
    int x,y;
    cin >> x >> y;
    x--; y--;
    cout << depth[x] + depth[y] << endl;
  }

  return 0;
}

Measured memory_bytes: 12800
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
int main(){
   string s;
   cin >> s;
   int x = (int)s.size() - 2;
   if (s[0] == s[(int)s.size()-1]) { 
	   x--;
   }
   if(x & 1){
	   cout << "First";
   }else{
	   cout << "Second";
   }
}








Measured memory_bytes: 512
import java.util.Scanner;

// https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		sc.close();

		int[] array = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

		System.out.println(array[K-1]);
	}
}


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

using namespace std;

int main()
{
	int N;
	cin >> N;
	
	vector<long> A(N);
	vector<long> answer(N);
	
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		
		if (i % 2 == 0)
		{
			answer[0] += A[i];
		}
		else
		{
			answer[0] -= A[i];
		}
	}

	for (int i = 1; i < N; i++)
	{
		// 山[i + 1]に降った雨 = 2 * A[i] - 山[i]に降った雨の漸化式を以下のように変形
		answer[i] = 2 * A[i - 1] - answer[i - 1];
	}
	
	for (int i = 0; i < N; i++)
	{
		cout << answer[i] << " ";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 2944
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<18, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, k;
int s[maxn];
string get() {
	int l = 0, a = 0;
	#pragma GCC ivdep
	for(int i = 0; i < k; i++) {
		if(s[l] == a) s[l] = !a;
		else {
			l = ++l == n ? 0 : l;
			a ^= 1;
			s[l ? l-1 : n-1] = a;
		}
	}
	string res;
	for(int i = 0; i < n; i++) {
		res += char('A' + (s[l++]^a));
		if(l == n) l = 0;
	}
	return res;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> k;
	char t;
	for(int i = 0; i < n; i++) cin >> t, s[i] = t-'A';
	
	cout << get();
}


Measured memory_bytes: 1540
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
 
def find(a, L):
    if L[a] == a: return a
    else: 
        L[a] = find(L[a], L)
        return L[a]
 
def unite(a, b, L, R):
    a = find(a, L)
    b = find(b, L)
    if a == b: return
    if R[a] < R[b]:
        L[a] = b
    else:
        L[b] = a
        if R[a] == R[b]: R[a] += 1
    
  
def solve():
    N, M = map(int, line_input())
    parent = [int(i) for i in range(N)]
    edge = [[] for i in range(N)]
    rank = [0] * N
    for i in range(M):
        x, y, z = map(int, line_input())
        unite(x-1, y-1, parent, rank)
    for i in range(N):
        parent[i] = find(i, parent)
    print(len(set(parent)))
    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 21492
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


long long pow(long long x, long long n) {
    if (n == 0) return 1;
    long long res = pow(x * x, n / 2);
    if (n & 1) res = res * x;
    return res; 
}


void solve() {
    long long H; cin >> H;
    
    int cnt = 0;
    while (H != 1) {
        cnt++;
        H /= 2;
    }

    long long ans = 0;
    for (int i = 0; i <= cnt; i++) {
        ans += pow(2, i);
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 1e5;

int n, k;
int a[MaxN + 5], b[MaxN + 5];
int tot, c[MaxN + 5];

void solve() {
	LL ans = 0;
	for(int i = 1; i <= tot; i++) {
		LL res = 0;
		for(int j = 1; j <= n; j++) {
			if((a[j] | c[i]) == c[i])
				res += (LL)b[j];
		}
		ans = max(ans, res);
	}
	printf("%lld\n", ans);
}

int main()
{
	while(scanf("%d %d", &n, &k) != EOF)
	{
		tot = 0;
		int cnt = 0;
		for(int i = 1; i <= n; i++) 
			scanf("%d %d", &a[i], &b[i]);
		for(int i = 30; i >= 0; i--) {
			int t = 1 << i;
			if(k & t) {
				int tmp = k ^ t;
				tmp = tmp | (t - 1);
				c[++tot] = tmp;
			}
		}
		c[++tot] = k;
		solve();
	}
	return 0;
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }


int n, m;
int a[5010], b[5010][233];
int c[5010], L[5010], R[5010];
ll mp[5010][5010];

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

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

    for (int num = 0; num < m; num++) {
        for (int i = 0; i < n; i++) c[i] = b[i][num];

        V<int> st;
        for (int i = 0; i < n; i++) {
            while (st.size() && c[i] > c[st.back()]) st.pop_back();
            L[i] = (st.size()) ? st.back() + 1 : 0;
            st.push_back(i);
        }

        st.clear();
        for (int i = n - 1; i >= 0; i--) {
            while (st.size() && c[i] >= c[st.back()]) st.pop_back();
            R[i] = (st.size()) ? st.back() - 1 : n - 1;
            st.push_back(i);
        }

        for (int i = 0; i < n; i++) {
            int lw = L[i], up = R[i];
            int d = c[i];
            mp[lw][i] += d;
            mp[lw][up + 1] -= d;
            mp[i + 1][i] -= d;
            mp[i + 1][up + 1] += d;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n; j++) {
            mp[i][j] += mp[i][j - 1];
        }
    }
    for (int j = 0; j < n; j++) {
        for (int i = 1; i < n; i++) {
            mp[i][j] += mp[i - 1][j];
        }
    }

    ll ans = -TEN(18);
    for (int i = 0; i < n; i++) {
        ll dist = 0;
        for (int j = i; j < n; j++) {
            ans = max(ans, mp[i][j] - dist);
            dist += a[j];
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 200960
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  l=0
  r=len(s)-1

  ans=0
  while l<r:
    if s[l]=='x':
      if s[r]=='x':
        l+=1
        r-=1
      else:
        l+=1
        ans+=1
    else:
      if s[r]=='x':
        r-=1
        ans+=1
      else:
        if s[l]==s[r]:
          l+=1
          r-=1
        else:
          return -1

  return ans

# main()
print(main())


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ans = 1001001001001001001;
    for (int i = 0; i < (1 << n); ++i) {
        bitset<15> bs(i);
        ll highest = 0;
        ll cost = 0;
        vector<ll> copy = a;
        for (int j = 0; j < n; ++j) {
            if (bs.test(j) and copy[j] <= highest) {
                cost += highest - copy[j] + 1;
                copy[j] = highest + 1;
            }
            highest = max(highest, copy[j]);
        }
        int see = 0;
        highest = 0;
        for (int j = 0; j < n; ++j) {
            if (highest < copy[j]) {
                see++;
            }
            highest = max(highest, copy[j]);
        }
        if (see < k) continue;
        ans = min(ans, cost);
    }
    cout << ans << endl;
}


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

#define MAX_N 3000006

long long gx[MAX_N], sumx[MAX_N];
long long gxy[MAX_N], sumxy[MAX_N];
long long gxyz[MAX_N];
long long f[1234];
int N;

void Get(int X, int Y, int Z, int p) {
	if (X == 0 || Y == 0 || Z == 0) return;
	memset(gx, 0, sizeof(gx));
	memset(sumx, 0, sizeof(sumx));
	memset(gxy, 0, sizeof(gxy));
	memset(sumxy, 0, sizeof(sumxy));
	memset(gxyz, 0, sizeof(gxyz));
	for (int i = 0; i < MAX_N; i++)
		gx[i] = (i < X);
	sumx[0] = gx[0];
	for (int i = 1; i < MAX_N; i++)
		sumx[i] = sumx[i - 1] + gx[i];
	for (int j = 0; j < MAX_N; j++)
		gxy[j] = sumx[j] - sumx[j - std::min(Y - 1, j)] + gx[j - std::min(Y - 1, j)];
	sumxy[0] = gxy[0];
	for (int j = 1; j < MAX_N; j++)
		sumxy[j] = sumxy[j - 1] + gxy[j];
	for (int k = 0; k < MAX_N; k++)
		gxyz[k] = sumxy[k] - sumxy[k - std::min(Z - 1, k)] + gxy[k - std::min(Z - 1, k)];
	for (int d = 0; d < N; d++)
		for (int t = 0; t * N + d < MAX_N; t++) 
			f[(p + d) % N] = gxyz[t * N + d] + f[(p + d) % N];
}

int X, Y, Z, A, B, C;

int main() {
	scanf("%d%d%d%d%d%d%d", &X, &Y, &Z, &A, &B, &C, &N);
	Get(A, B, C, 3);
	Get(A, B, Z - C, 2);
	Get(A, Y - B, C, 2);
	Get(A, Y - B, Z - C, 1);
	Get(X - A, B, C, 2);
	Get(X - A, B, Z - C, 1);
	Get(X - A, Y - B, C, 1);
	Get(X - A, Y - B, Z - C, 0);
	for (int i = 0; i < N; i++)
		printf("%lld%c", f[i], (i == N - 1) ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 119888
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct list{
  long key;
  struct list *next;
  struct list *back;
};

void insert(long x, struct list *p);
void dele(long x,struct list *p);
void deleteFirst(struct list *p);
void deleteLast(struct list *p);
void show_list(struct list *p);
void free_list(struct list *p);
struct list *HEAD;
int main(void){
  int i,j;
  int n;
  char command[12];
  long x=0;
  struct list *head;

  head=(struct list *) malloc(sizeof(struct list));
  HEAD=head;
  head->next=head;
  head->back=head;
  head->key=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    //printf("head=%d ",head->back->next->key);
    //printf("tail=%d\n",head->back->key);
    scanf("%s",command);
    if(strcmp(command,"insert")==0){
      scanf("%ld",&x);
      insert(x,head);
    }
    else if(strcmp(command,"delete")==0){
      scanf("%ld",&x);
      dele(x,head);
    }
    else if(strcmp(command,"deleteFirst")==0) deleteFirst(head);
    else deleteLast(head);
  }


  show_list(head);
  free_list(head);
  return 0;
}
void show_list(struct list *p){
  p=p->next;
  if(p!=HEAD){
    printf("%d",p->key);
    p=p->next;
  }
  while(p!=HEAD){
    printf(" %d",p->key);
    p=p->next;
  }
  printf("\n");
}
void free_list(struct list *p){
  struct list *p2;
  while(p!=HEAD){
    p2=p->next;
    free(p);
    p=p2;
  }
}
void insert(long x,struct list *p){
  struct list *p2;
  struct list *p3;
  if((p2=(struct list *) malloc(sizeof(struct list))) == NULL){
      printf("malloc error\n");
  }
  p3=p->next;
  p3->back=p2;
  p2->key=x;
  p2->next=p3;
  p2->back=p;
  p->next=p2;
}
void dele(long x,struct list *p){
  struct list *p2;
  while(p->next!=HEAD){
    if(p->next->key==x){
      p2=p->next->next;
      free(p->next);
      p2->back=p;
      p->next=p2;
      break;
    }
    p=p->next;
  }

}
void deleteFirst(struct list *p){
  struct list *p2;
  p2=p->next->next;
  free(p->next);
  p2->back=p;
  p->next=p2;
}
void deleteLast(struct list *p){
  struct list *p0;
  p0=p->back->back;
  free(p->back);
  p->back=p0;
  p0->next=p;
}

Measured memory_bytes: 31788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int H, W;
    int count = 0;
    cin >> H >> W;
    vector<vector<char>> maze(H + 2, vector<char>(W + 2, '#'));
    // データ入力
    rep(1, i, H + 1)
    {
        rep(1, j, W + 1)
        {
            cin >> maze[i][j];
            // 白マスの数を数える
            if (maze[i][j] == '.')
            {
                count++;
            }
        }
    }

    // 四方向探索のための配列
    vector<int> dx(4), dy(4);
    dx = {1, 0, -1, 0};
    dy = {0, 1, 0, -1};

    // bfsのためのデータ構造
    vector<vector<int>> dist(H + 2, vector<int>(W + 2, -1));
    queue<P> que;

    dist[1][1] = 1;
    que.push(P(1, 1));

    // bfsの部分
    while (que.size())
    {
        P v = que.front();
        que.pop();
        if ((v.first == H) && (v.second == W))
        {
            break;
        }
        rep(0, i, 4)
        {
            int nx = v.first + dx[i];
            int ny = v.second + dy[i];
            // 黒マスまたは探索済ならスルー
            if ((maze[nx][ny] == '#') || (dist[nx][ny] != -1))
            {
                continue;
            }
            dist[nx][ny] = dist[v.first][v.second] + 1;
            que.push(P(nx, ny));
        }
    }
    // (H,W)に到達できるなら、(白マスの数) - (通ってきた白マスの数)を出力
    if (dist[H][W] != -1)
    {
        cout << count - dist[H][W] << endl;
    }
    // (H,W)に到達不可能な場合
    else
    {
        cout << dist[H][W] << endl;
    }
}

Measured memory_bytes: 256