akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

long long N,A,B,maxi=0,add,sum,low,high,mid;

bool check(long long T,long long *h,long long add,long long B,long long N);

int main(){
    cin>>N>>A>>B;
    long long h[N];
    rep(i,N){
        cin>>h[i];
        maxi=max(maxi,h[i]);
    }
    maxi=(maxi/B)+1;
    add=A-B;
    low=0;
    high=maxi;
    while(low<=high){
        mid=(low+high)/2;
        // printf("%llu %llu %llu\n",low,mid,high);
        if(check(mid,h,add,B,N)){
            if(check(mid-1,h,add,B,N)){
                high=mid-1;
            }
            else{
                out(mid);
                return 0;
            }
        }
        else{
            if(check(mid+1,h,add,B,N)){
                out(mid+1);
                return 0;
            }
            else{
                low=mid+1;
            }
        }
    }
    return 0;
}

bool check(long long T,long long *h,long long add,long long B,long long N){
    sum=0;
    long long temp[N];
    rep(j,N){
        temp[j]=h[j];
        temp[j]-=T*B;
        if(temp[j]>0){
            sum+=temp[j]/add;
            if(temp[j]%add!=0)sum+=1;
            }
    }
    if(sum>T){
        return false;
    }else{
        return true;
    }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	char a, b; cin >> a >> b;

	bool res = true; // true : TopCoDeer is honest, otherwise dishonest.
	if (a == 'H'){
		if (b == 'H'){
			res = true;
		}else{ // if (b == 'D')
			res = false;
		} // end if
	}else{ // if (a == 'D')
		if (b == 'H'){
			res = false;
		}else{ // if (b == 'D')
			res = true;
		} // end if
	} // end if

	cout << (res ? 'H' : 'D') << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    
    vector<vector<int>> f(n,vector<int>(10));
    rep(i,n) rep(j,10) cin>>f[i][j];

    vector<vector<int>> p(n,vector<int>(11));
    rep(i,n) rep(j,11) cin>>p[i][j];

    
    int ans = -INF;
    for(int bit=1;bit<(1<<10);bit++){
        vector<int> b(10);
        int t = bit;
        rep(i,10){
            b[i] = t%2;
            t/=2;
        }
        
        
        int tmp = 0;
        rep(i,n){
            int same = 0;
            rep(j,10){
                if(b[j]==f[i][j]&&b[j]==1)same++;
            }
            tmp+=p[i][same];
        }
        if(tmp>ans)ans = tmp;
    }
    cout<<ans<<endl;
}


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

const int MAX = 100005;
const int nil = -1;

struct Node{int parent, left, right;};

Node T[MAX];

// 先行順巡回
void preparse(int u){
    if(u == nil) return;
    printf(" %d",u);
    preparse(T[u].left);
    preparse(T[u].right);
}

// 中間順巡回
void inparse(int u){
    if(u == nil) return;
    inparse(T[u].left);
    printf(" %d",u);
    inparse(T[u].right);
}

// 後行順巡回
void postparse(int u){
    if(u == nil) return;
    postparse(T[u].left);
    postparse(T[u].right);
    printf(" %d",u);
}

int main(){
    int N; cin >> N;

    for(int i=0; i<N; ++i) T[i].parent = nil;

    for(int i=0; i<N; ++i){
        int id, l, r;
        cin >> id >> l >> r;
        T[id].left = l;
        T[id].right = r;
        if(l != nil) T[l].parent = id;
        if(r != nil) T[r].parent = id;
    }

    int root;
    for(int i=0; i<N; ++i) if(T[i].parent == nil) root = i;

    printf("Preorder\n");
    preparse(root);
    printf("\n");

    printf("Inorder\n");
    inparse(root);
    printf("\n");

    printf("Postorder\n");
    postparse(root);
    printf("\n");
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    int x[n];
    rep(i,n){
        cin >> x[i];
    }
    ll ans = LINF;
    for(int i = 1; i <= 100; i++){
        ll t = 0;
        rep(j,n){
            t += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
function gcd(a,b)
  if a<b then
    return gcd(b,a)
  elseif a%b==0 then
    return b
  else
    return gcd(b,a%b)
  end
end
n=io.read():match("%d+")
for i in io.read():gmatch("%d+") do
  if ans==nil then
    ans=i*1
  end
  ans=gcd(ans,i*1)
end
print(string.format("%d",ans))

Measured memory_bytes: 4144
#include<stdio.h>
int a[1000000];
int main(void)
{
    int n,i,j;
    int count=0;

    while (scanf("%d",&n) != EOF){
        for(i = 1; i <= n; i++){
            a[i]=0;
        }
        a[1]=1;
        for(i = 4; i <= n; i+=2){
            a[i]=1;
        }

        for(i = 3; i*i <= n; i++){
            if(a[i]==0){
                for(j = i; j<=n; j+=i){
                    a[i]=0;
                    a[j]=1;
                }
            }
        }

        for(i = 1; i <= n; i++) if(a[i] == 0) count++;
        printf("%d\n",count);
        count=0;
    }
    return 0;
}

Measured memory_bytes: 4308
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    
    int cnt=0;
    
    if(r<=x && x<=W-r){
        cnt++;
    }
    if(r<=y && y<=H-r){
        cnt++;
    }
    if(cnt==2){
        cout <<"Yes" << endl;
    }
    if(cnt!=2){
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
map<char, LL> p1;
map<LL , char> p2;

LL gcd(LL a, LL b)
{
	return b == 0 ? a : gcd(b, a % b);	
} 
string s1, s2;
int main()
{
	LL n, m, L;
	scanf("%lld %lld", &n, &m);
	L = n * m  / gcd(n, m);
	cin >> s1;
	cin >> s2;
	p1.clear();
	p2.clear();
	if(s1[0] != s2[0])
		puts("-1");
	else{
		int flag = 0;
		for(LL i = 1; i < n; i++)
		{
			p1[s1[i]] = 1 + (L / n) * i;
			LL k = 1 + (L / n) * i;
			p2[k] = s1[i];
		}
			
		for(LL i = 1; i < m; i++)
		{
			LL ans = 1 + (L / m) * i;
			if(p2[ans] != 0)
			{
				if(p2[ans] != s2[i])
				{
					flag = 1;
					break;
				}
			}
		}
		if(flag)
			puts("-1");
		else
			printf("%lld\n", L);
	}
	
	return 0;
}

Measured memory_bytes: 10880
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N,M;
    cin >> N >> M;
    lint X[N],Y[M];
    rep(i,N) cin >> X[i];
    rep(i,M) cin >> Y[i];
    lint Xall=0,Yall=0;
    lint Xdis=0,Ydis=0;
    rep(i,N-1) Xdis+=X[i+1]-X[0];
    rep(i,M-1) Ydis+=Y[i+1]-Y[0];
    rep(i,N-1){
        Xall=(Xall+Xdis)%MOD;
        Xdis-=X[i+1]-X[i];
        Xdis-=(N-2-i)*(X[i+1]-X[i]);
    }
    rep(i,M-1){
        Yall=(Yall+Ydis)%MOD;
        Ydis-=Y[i+1]-Y[i];
        Ydis-=(M-2-i)*(Y[i+1]-Y[i]);
    }
    cout << (Xall*Yall)%MOD << endl;
}

Measured memory_bytes: 5180
import math


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]

    X = 0
    if K != 0:
        for digit in range(40, -1, -1):
            if digit > math.log2(K) + 1:
                continue

            zero_n = 0
            one_n = 0
            for a in A:
                if (a >> digit) & 1:
                    one_n += 1
                else:
                    zero_n += 1

            if one_n < zero_n and (X + (1 << digit)) <= K:
                X += (1 << digit)
    else:
        X = 0

    ans = 0
    for a in A:
        ans += X ^ a

    print(ans)


Measured memory_bytes: 14620
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int main(){
	int N;
	cin >> N;
	int ans = N / 3;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9+7;

bool dp[100001][6][6][6], vis[100001][6][6][6];
string s[100001], anst;
ll n;

ll fun(ll a, ll b, ll c, ll idx) {
    if(a<0 or b<0 or c<0)return false;
    if(vis[idx][a][b][c])return dp[idx][a][b][c];
    vis[idx][a][b][c] = true;
    if(idx==n) {
        vis[idx][a][b][c] = true;
        return true;
    }
    bool ans = false;
    if(s[idx]=="AB") {
        if(a<5 and b>0)if(fun(a+1,b-1,c,idx+1)){ans=true;anst.pb('A');}
        if(ans==false and b<5 and a>0)if(fun(a-1,b+1,c,idx+1)){anst.pb('B');ans=true;}
    }
    if(s[idx]=="BC") {
        if(b<5 and c>0)if(fun(a,b+1,c-1,idx+1)){ans=true;anst.pb('B');}
        if(ans==false and c<5 and b>0)if(fun(a,b-1,c+1,idx+1)){anst.pb('C');ans=true;}
    }
    if(s[idx]=="AC") {
        if(a<5 and c>0)if(fun(a+1,b,c-1,idx+1)){ans=true;anst.pb('A');}
        if(ans==false and c<5 and a>0)if(fun(a-1,b,c+1,idx+1)){anst.pb('C');ans=true;}
    }
    dp[idx][a][b][c] = ans;
    return ans;
}

void solve() {
    ll a, b, c, i, j, k, l, ab=0,bc=0,ac=0, aop =0,bop=0,cop=0;
    anst.clear();
    cin>>n>>a>>b>>c;
    fo(i,n+1)fo(j,6)fo(k,6)fo(l,6)vis[i][j][k][l]=false;
    fo(i,n) {
        cin>>s[i];
        if(s[i]=="AB")ab++;
        else if(s[i]=="BC")bc++;
        else ac++;
    }
    a = min(a, 3ll);
    b = min(b, 3ll);
    c = min(c, 3ll);

    if(fun(a,b,c,0)) {
        cout<<"Yes"<<endl;
        reverse(anst.begin(), anst.end());
        for(auto x:anst)cout<<x<<endl; 
    } else {
        cout<<"No"<<endl;
    }
}   

int main()
{
    fastIO;ll t=1;
    // cin>>t;
    while(t--)solve();
}


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

int main() {
  int k,a,b;
  cin >> k >> a >> b;

  for(int i=1; i<1000; i++){
    if(a <= k*i && k*i <= b){
      cout << "OK" <<endl;
      return 0;
    }
  }

  cout << "NG" <<endl;


}


Measured memory_bytes: 3592
#include <stdio.h>

int main() {
	int n, v[25], c, sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &v[i]);
	for (int i = 0; i < n; i++) {
		scanf("%d", &c);
		if (v[i] - c > 0)
			sum += (v[i] - c);
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
a, b, c, d, e, f = list(map(int, input().rstrip().split()))
a *= 100
b *= 100

x, y = a, 0  
conc_best = 0

for i in range(f // a + 1):
    for j in range(((f - a * i) // b) + 1):
        water = i * a + j * b
        if water == 0:
            continue
        rest = f - water
        sug_max = e * water / 100
        for k in range(rest // c + 1):
            for l in range((rest - c * k) // d + 1):
                sugar = c * k + d * l
                conc = sugar / (sugar + water)

                if sugar <= sug_max and conc> conc_best:
                        conc_best = conc
                        x, y = sugar+water , sugar
print(x, y)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
#define N 5000 + 5
#define M 200 + 5
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define dep(i, l, r) for(int i = r; i >= l; --i)
long long ans, S[N], c[N][N];
int n, m, top, a[N], l[N], r[N], st[N], b[M][N]; 
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
void solve(int l, int r, int p, int k){
    if(l > r) return;
    c[l][p] += k, c[p + 1][p] -= k, c[l][r + 1] -= k, c[p + 1][r + 1] += k;
}
int main(){
    n = read(), m = read();
    rep(i, 1, n - 1) a[i] = read(), S[i + 1] = S[i] + a[i];
    rep(i, 1, n) rep(j, 1, m) b[j][i] = read();
    rep(i, 1, m){
        top = 0, memset(l, 0, sizeof(l)), memset(r, 0, sizeof(r));
        dep(j, 1, n){
            while(top && b[i][j] >= b[i][st[top]]) l[st[top]] = j, --top;
            st[++top] = j;
        }
        top = 0;
        rep(j, 1, n){
            while(top && b[i][j] > b[i][st[top]]) r[st[top]] = j, --top;
            st[++top] = j;
        }
        rep(j, 1, n) ++l[j], r[j] = r[j] ? r[j] - 1 : n;
        rep(j, 1, n) solve(l[j], r[j], j, b[i][j]);
    }
    rep(i, 1, n) rep(j, 1, n) c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
    rep(i, 1, n) rep(j, i, n) ans = max(ans, c[i][j] - S[j] + S[i]);
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 203276
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vll L(N);
    REP(i, N) cin >> L[i];

    vector<int> C(1e4, 0);
    REP(i, N) C[L[i]]++;
    FOR(i, 1, C.size()) C[i] += C[i - 1];

    ll ans = 0;
    REP(i, N) FOR(j, i+1, N) {
        ll a = L[i], b = L[j];

        ll l = max(a - b, b - a);
        ll r = a + b - 1;

        if (C[r] - C[l] < 1) continue;

        ans += C[r] - C[l];

        if (l < a && a <= r) ans--;
        if (l < b && b <= r) ans--;
    }

    print(ans / 3);

    
}


Measured memory_bytes: 3720
import java.util.*;

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 = b-a;
    int B = 0;
    for(int i=1; i<=c; i++){
        B += i;
}
    System.out.println(B-b);    
    }
}

Measured memory_bytes: 35532
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>
#define mod 998244353
#define pb push_back
#define ll long long
using namespace std;
int main(){
	int n;
	vector<int> l;
	cin>>n;
	for(int i=0;i<2*n;i++){
		int x;
		cin>>x;
		l.pb(x);
	}
	sort(l.begin(),l.end());
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=l[2*i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self,N):
        self.par =[-1 for i in range(N)]
    def find(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.par[x] > self.par[y]:
            x,y = y,x
        self.par[x] +=self.par[y]
        self.par[y] = x

    def size(self,x):
        return -self.par[self.find(x)]
    def same(self,x,y):
        return self.find(x)==self.find(y)

N,M=map(int,input().split(' '))
q = [list(map(int,input().split(' '))) for i in range(M)]
ans = 0
for i in range(M):
    tmp = q[:i]+q[i+1:]
    uf = UnionFind(N)
    for j,k in tmp:
        uf.unite(j-1,k-1)
    for l in range(N):
        if uf.size(l) != N:
            ans += 1
            break
print(ans)

Measured memory_bytes: 3064
n=int(input())
s=[0]*n
t=[0]*n
for i in range(n):
    a,b=input().split()
    b=int(b)
    s[i]=a
    t[i]=b
x=input()
ans=sum(t)
for i in range(n):
    if s[i]==x:
        print(ans-t[i])
        exit()
    else:
        ans-=t[i]

Measured memory_bytes: 38256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    print(sum([100 * (n - m) + 1900 * m for _ in range(2 ** m)]))


if __name__ == '__main__':
    solve()


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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  string s;
  cin >> s;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      cout << "Bad\n";
      return;
    }
  }
  cout << "Good\n";
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

const int MAX = 2147483647;
const int MAX_N = 100000;

struct RMQ{
    int n;
    vector<int> dat;
    void init(int n_){
        n = 1;
        while(n < n_) n *= 2;
        dat.resize(2 * n - 1, MAX);
        // rep(i, 0, 2 * n - 1) dat[i] = MAX;
    }
    void update(int k, int a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    //min[a, b) query(a, b, 0, 0, r.n)
    int find(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return MAX;
        if(a <= l && r <= b) return dat[k];
        int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
};

signed main(){
    int n, q;
    cin >> n >> q;
    RMQ r;
    r.init(n);
    rep(i, 0, q){
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0){
            r.update(x, y);
        }else{
            cout << r.find(x, y + 1, 0, 0, r.n) << endl;
        }
    }
    // rep(i, 0, 15){
    //     cout << i << ' ' << r.dat[i] << endl;
    // }
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
typedef long long ll;

const int mod = 998244353;
const int N = 3e3+2;
ll a[N], dp[N][N];
int main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0); std::cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int n,i,j,k,s;
    std::cin >> n >> s;
    for(i=1; i<=n; i++) std::cin >> a[i];
    dp[1][0] = 2;
    dp[1][a[1]] = 1;
    for(i=2; i<=n; i++)
    {
        for(j=0; j<=s; j++)
        {
            dp[i][j] = dp[i-1][j]*2;
            dp[i][j] %= mod;
            if(j<a[i]) continue;
            dp[i][j] += dp[i-1][j-a[i]];
            dp[i][j] %= mod;
        }
    }
    std::cout << dp[n][s] << '\n';
    return 0;
}


Measured memory_bytes: 73976
#include <iostream>

using namespace std;

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

    int ta[n];
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        ta[i] = t;
    }

    int m;
    cin >> m;

    int ans[m];
    for (int i = 0; i < m; i++) {
        int p, x;
        cin >> p >> x;
        ans[i] = 0;
        for (int a = 0; a < n; a++) {
            if (a == (p-1)) {
                ans[i] += x;
            } else {
                ans[i] += ta[a];
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
int dp[10][10];
int get_fi(int x)
{
    while (x >= 10)
    {
        x /= 10;
    }
    return x;
}
int main()
{
    int N;
    std::cin >> N;
    for (int i = 1; i <= N; i++)
    {
        int x = get_fi(i);
        int y = i % 10;
        if (x == 0 || y == 0)
            continue;
        dp[x][y]++;
    }
    LL Ans = 0;
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            Ans += dp[i][j] * LL(dp[j][i]);
        }
    }
    std::cout<<Ans<<'\n';
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n;
    char str[100];
    int flag=1;
    int i;

    scanf("%d",&n);
    scanf("%s",str);

    if(n%2){
        printf("%s\n","No");
    }

    if(n%2==0){
        for(i=0;i<n/2;i++){
            if(str[i]!=str[i+n/2]){
                printf("%s\n","No");
                flag=0;
                break;
            }
        }
        if(flag==1){
            printf("%s\n","Yes");
        }
        
    }

    return 0;
}

Measured memory_bytes: 128
//Program.cpp
//Author : Aaryan Srivastava 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define pb push_back
#define popb pop_back
#define ull unsigned long long  
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii,int>
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second 
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 100000 + 5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace std;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#define AaryanS 0 
#endif


map<char,int> m ;
string s ;

int exp(int x, int y){
	x %= mod ;
	int res = 1LL ;
	while(y){
		if(y&1)
			res = (res* x)%mod ;
		x = (x*x)%mod ;
		y /= 2;
	}
	return res%mod ;
}
void solve()
{
	int n ;
	cin >> n ;
	cin >> s ;
	int ans= 1;
	rep(i,n)
		m[s[i]]++ ;
	for(auto &it : m){
		ans *= (it.ss+1) ;
		ans %= mod ;
	}
	ans += mod - 1;
	ans %= mod ;
	cout << ans;

}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case " << t << ":\n" ;
        solve();
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <functional>
typedef long long ll;
using namespace std;

int main() {
    int N;
    cin >> N;
    map<char, ll> mp;
    ll a, b, c;
    cin >> a >> b >> c;

    mp['A'] = a;
    mp['B'] = b;
    mp['C'] = c;

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

    vector<char> ans;


    for(int i = 0; i < N; i++) {
        if(mp[s[i][0]] == 0 && mp[s[i][1]] == 0) {
            cout << "No" << endl;
            return 0;
        }

        else if(mp[s[i][0]] == mp[s[i][1]] && mp[s[i][0]] == 1) {
            if(i == N - 1) {
                ans.push_back(s[i][0]);
            }
            else {
                if(s[i][0] == s[i + 1][0] || s[i][0] == s[i + 1][1]) {
                    ans.push_back(s[i][0]);
                    mp[s[i][0]]++;
                    mp[s[i][1]]--;
                }
                else {
                    ans.push_back(s[i][1]);
                    mp[s[i][1]]++;
                    mp[s[i][0]]--;
                }
            }
        }

        else if(mp[s[i][0]] >= mp[s[i][1]]) {
            ans.push_back(s[i][1]);
            mp[s[i][1]]++;
            mp[s[i][0]]--;
        }

        else {
            ans.push_back(s[i][0]);
            mp[s[i][0]]++;
            mp[s[i][1]]--;
        }
    }


    cout << "Yes" << endl;
    for(auto v: ans) {
        cout << v << endl;
    }

    return 0;


}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  ll n, m; cin >> n >> m;
  vll ab(n);
  rep(i,n) {
    ll a, b; cin >> a >> b;
    ab[i] = mp(a,b);
  }
  sort(all(ab));

  ll ans = 0;
  rep(i,n) {
    ll a = ab[i].ff, b = ab[i].ss;
    if (m == 0) break;
    ll num = min(m, b);
    ans += num * a;
    m -= num;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <math.h>
 
#define gc() getchar_unlocked()
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc();
    while (c >= '0');
    return n;
}
 
int x[102], y[102];
 
int main()
{
    int n, i, t, t2;
    int d, d1, d2;
    long long d3;
     
    n = in();
    for (i = 0; i < n; i++) x[i] = in();
    for (i = 0; i < n; i++) y[i] = in();
    d = 0, d1 = 0, d2 = 0, d3 = 0;
    for (i = 0; i < n; i++) {
        t = x[i] - y[i];
        if (t < 0) t = -t;
        if (t > d) d = t;
        d1 += t;
        t2 = t*t, d2 += t2;
        d3 += t2*t;
    }
    printf("%d\n", d1);
    printf("%.8lf\n", sqrt((double)d2));
    printf("%.8lf\n", pow((double)d3, 1.0/3));
    printf("%d\n", d);
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------


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

	ll n;
	cin>>n;
	ll m=1,cnt=1;
	while(m*2<=n) m*=2,cnt++;
	if(n==m*2-1) cout<<cnt<<endl;
	else cout<<cnt-1<<endl;

	return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai acos(-1)
#define keta(n) cout << fixed << setprecision((n))
#define ll long long
int main()
{
  double x1, x2, y1, y2;
  double l2;
  cin >> x1 >> y1 >> x2 >> y2;
  l2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
  keta(10);
  cout << sqrt(l2);
}



Measured memory_bytes: 3284
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv){
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n; cin >> n;
	ll allsum = 0;
	vll a(n); rep(i,n){ cin >> a[i]; allsum+=a[i]; }
	ll ans = LL_INF;
	ll sum = 0;
	rep(i,n){
		sum += a[i];
		ans = min(ans,abs(2*sum-allsum));
	}
	out(ans);
}




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

int main(){
string aa,bb,g;
int a1=0,b1=0;
cin >>aa >>bb;
cin >>a1 >>b1;
cin >>g;
if(g==aa) a1=a1-1;
    else b1=b1-1;
    cout <<a1 <<" " <<b1 <<endl;
return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())

if k % 2 != 0:
	dev = n // k
	ans = dev ** 3
else:
	dev = n // k 
	if n % k >= k/2:
		ans = dev**3 + (dev + 1)**3
	else:
		ans = 2 * (dev**3)

print(ans)


Measured memory_bytes: 2940
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: 26108
import re
a,b = map(int, input().split(" "))
c = list(input())
flag = 1
for i in range(a):
    if(re.match(r"\d",c[i])):
        pass
    else:
        flag = 0
if(re.match(r"-",c[a])):
    pass
else:
    flag = 0
for i in range(b):
    if(re.match(r"\d",c[a+1+i])):
        pass
    else:
        flag = 0
if(flag):
    print("Yes")
else:
    print("No")

    

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>


int main () {
    std::string s;
    std::cin >> s;
    int cnt = 0;

    std::vector<int> a;
    for (int i = 0; i < s.length(); i++)
    {
        if(s[i] == 'A' || s[i] == 'T' || 
        s[i] == 'C' || s[i] == 'G') {
            cnt++;
        } else {
            if(cnt) {
               cnt = 0;
            }
        }
        a.push_back(cnt);
    }

    std::cout << *std::max_element(a.begin(), a.end()) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll


signed main(void){
    int N,K;
    int A[114514];
    int one=0;
    int left,right;
    cin >> N >> K;
    REP(i,N){
        cin >> A[i];
        if(A[i]==1){
            one=i;
        }
    }
    left=one;
    right=N-one-1;
    if(one==0||one==N-1){
        cout << (N-1-1+K-1)/(K-1) << endl;
    }else{
        cout << (N-1+K-1-1)/(K-1) << endl;
    }
  return 0;
}


Measured memory_bytes: 1024
#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>;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (a > 0 && c > 0) {
    c -= b;
    a -= d;
  }
  string ans = c > 0 ? "No" : "Yes";
  cout << ans << endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
int main(){
	#define ll long long
	ll n;
	cin>>n;
	double time=0.0,sum=0.0;
	for(int i=1;i<=n;i++){
		if(i%2==1)time++;
	}
	sum=time/n*1.000;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    long long X;
    cin >> X;
    long long m=100;
    long long year = 0;
    while (X>m)
    {
        m+=m/100;
        year++;
    }
    cout << year;
    return 0;
}


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

int main() {
  int N, K;
  string S;

  cin >> N >> S >> K;

  char str = S.at(K - 1);
  for (int i = 0; i < N; i++) {
    if (S.at(i) != str) {
      cout << '*';
    } else {
      cout << S.at(i);
    }
  }
  cout << endl;
}

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

int main(){
    string a, b;
    cin >> a >> b;

    int x = a.size() - b.size();
    
    if(x>0){
        cout << "GREATER" << endl;
        return 0;
    }else if(x<0){
        cout << "LESS" << endl;
        return 0;
    }else if(a==b){
        cout << "EQUAL" << endl;
        return 0;
    }
    
    for(int i = 0; i < (int)a.size(); i++){
        if(a[i]==b[i]) continue;
        if(a[i]>b[i]){
            cout << "GREATER" << endl;
            return 0;
        }else if(a[i]<b[i]){
            cout << "LESS" << endl;
            return 0;
        }
    }
    cout << "EQUAL" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int freq[100001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	long long sum = 0;
	for(int i=0,x;i<n;++i)
		cin>>x,freq[x]++,sum+=x*1LL;
	int q;
	cin>>q;
	while(q--)
	{
		int a,b;
		cin>>a>>b;
		sum -= freq[a]*1LL*a;
		sum += freq[a]*1LL*b;
		freq[b] += freq[a];
		freq[a] = 0;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  int A[N+2] = {};
  int64_t ans1 = 0;
  for(int i=1;i<=N;i++){
    cin >> A[i];
    ans1 += abs(A[i] - A[i-1]);
  }
  ans1 += abs(A[N+1]-A[N]);
  for(int i=1;i<=N;i++){
    int64_t ans = ans1;
    ans -= abs(A[i]-A[i-1]) + abs(A[i+1]-A[i]);
    ans += abs(A[i+1] - A[i-1]);
    cout << ans << endl;
  }
}


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

using namespace std;

string s;

int main() {
#if DEBUG
    freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> s;
    int pos = (int)s.size();
    string prev;
    int ans = 0;
    while (pos > 0) {
        bool ok = false;
        for (int i = 1; i <= pos; i++) {
            string can = s.substr(pos - i, i);
            if (can == prev) continue;
            else {
                prev = can;
                pos -= i;
                ok = true;
                break;
            }
        }
        if (ok) ans++;
        else {
            prev += s[pos];
            pos -= 1;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 720
# coding: utf-8
# Your code here!

while True:
   r1 = input()
   if r1 == "0": break
   r2 = input()
   r3 = input()
   
   s1A = r1[1 : len(r1)].count("A")
   s1B = len(r1) - 1 - s1A
   s2A = r2[1 : len(r2)].count("A")
   s2B = len(r2) - 1 - s2A
   s3A = r3[1 : len(r3)].count("A")
   s3B = len(r3) - 1 - s3A
   
   if r2[0] == "A":
      s1A += 1
   else:
      s1B += 1
   
   if r3[0] == "A":
      s2A += 1
   else:
      s2B += 1

   if s3A > s3B:
      s3A += 1
   else:
      s3B += 1
      
   print(s1A, s1B)
   print(s2A, s2B)
   print(s3A, s3B)



Measured memory_bytes: 5560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			int t = 0;
			int it = i;
			for (;it / 10 > 0; it /= 10) {
				t += it % 10;
			}
			t += it;
			if (a <= t && t <= b)
				sum += i;
		}
		System.out.println(sum);
	}
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll N;
  scanf("%lld",&N);
  vector<ll> a(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&a[i]);
  }
  sort(a.rbegin(),a.rend());
  ll alice=0;
  ll bob=0;
  for (int i=0; i<N; i++) {
    if (i%2==0) alice+=a[i];
    else bob+=a[i];
  }
  cout << alice-bob << endl;
}

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


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


int main(){
    string S;
    cin >> S;

    if(S == "Sunny"){
        cout << "Cloudy";
        return 0;
    }

    if(S == "Cloudy"){
        cout << "Rainy";
        return 0;
    }

    if(S == "Rainy"){
        cout << "Sunny";
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int main(){
    int N; cin >> N;
    
    vector<int> ans(4, 0);
    rep(i,N){
        string s; cin >> s;
        if (s == "AC"){
            ans[0]++;
        }
        else if (s == "WA"){
            ans[1]++;
        }
        else if (s == "TLE"){
            ans[2]++;
        }
        else{
            ans[3]++;
        }
    }

    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
//#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"
#define fi first
#define se second

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    ll n;
    cin >> n;
    vi b(n-1), a(n, LLONG_MAX);
    REP(i, 0, n-1)
        cin >> b[i];
    a[0] = b[0];
    a[n-1] = b[n-2];
    REP(i, 1, n-1)
        a[i] = min(b[i-1], b[i]);
    ll s = 0;
    REP(i, 0, n)
        s += a[i];
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=305;
char mp[N][N];int col[N][N],n,m,cnt,K;
int main(){
	scanf("%d%d%d",&n,&m,&K);
	fp(i,1,n)scanf("%s",mp[i]+1);
	fp(i,1,n)fp(j,1,m)if(mp[i][j]=='#'){
		col[i][j]=++cnt;
		for(R int k=j-1;k&&!col[i][k]&&mp[i][k]!='#';--k)col[i][k]=cnt;
		for(R int k=j+1;k<=m&&!col[i][k]&&mp[i][k]!='#';++k)col[i][k]=cnt;
	}
	fp(i,1,n)fp(j,1,m)if(col[i][j]){
		for(R int k=i-1;k&&!col[k][j];--k)col[k][j]=col[i][j];
		for(R int k=i+1;k<=n&&!col[k][j];++k)col[k][j]=col[i][j];
	}
	fp(i,1,n)fp(j,1,m)printf("%d%c",col[i][j]," \n"[j==m]);
	return 0;
}

Measured memory_bytes: 1152
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var line1 = Console.ReadLine()
            .Split(' ')
            .Select(n => int.Parse(n))
            .ToList();
        var N = line1[0];
        var M = line1[1];
        var votes = Console.ReadLine()
            .Split(' ')
            .Select(n => int.Parse(n))
            .ToList();
        var totalVotes = votes.Sum();

        var canSelectable = votes
            .Where(v => v >= (float) totalVotes / (4 * M))
            .Count();

        Console.WriteLine(canSelectable >= M ? "Yes" : "No");
    }
}

Measured memory_bytes: 13396
#include <stdio.h>
int main(void)
{
  int x;
  int a,e,f;
  
  scanf("%d",&x);
  
  a=x/500;
  x-=a*500;  
  e=x/5;
  x-=e*5;
  f=x;
  
  printf("%d",a*1000+e*5);
  
  return 0;
}

Measured memory_bytes: 1700
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe

typify2 (x:y:_) = (x, y)
typify2 _       = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInteger

readIntTuple = typify2 . map readInt . BS.words

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

getIntMatrix = map readIntList . BS.lines <$> BS.getContents

getIntTuple = readIntTuple <$> BS.getLine

getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine

getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

main = do
    nums <- getIntList
    print $ solve (head nums) (nums !! 1) (nums !! 2)

solve a b c
    | n > 0 = n
    | otherwise = 0
  where
    n = c - (a - b)


Measured memory_bytes: 380
#include <iostream>
using namespace std;
int main(void){
    int n, s[1000]={}, p[1000]={}, q[1000]={}, r[1000]={},  P, Q, R, C, flag;
    long int cal[1000]={};
    
    while(1){
        flag=0;
        cin >> n;
        if(n==0) break;
        for(int i=0; i<n; i++){
            cin >> s[i] >> p[i] >> q[i] >> r[i];
            cal[i]=p[i]*4+q[i]*9+r[i]*4;
        }
        cin >> P >> Q >> R >> C;
        
        for(int i=0; i<n; i++){
            if(p[i]<=P && q[i]<=Q && r[i]<=R && cal[i]<=C){
                flag=1;
                cout << s[i] << endl;
            }
        }
        if(flag==0){
            cout << "NA" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3092
#include<stdio.h>
int main()
{
    int n,tmax,c,t,cmin=1000,i,flag=0;
    scanf("%d%d",&n,&tmax);
    for(i=0; i<n; i++)
    {
        scanf("%d%d",&c,&t);
        if(t<=tmax && c<=cmin)
        {
            cmin=c;
            flag=1;
        }
    }
    if(flag==1)
        printf("%d",cmin);
    else
        printf("TLE");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;

int main(){
    string s;
    getline(cin, s);
    ll ans = 0;
    ll cur = 0;
    for(int i = 0; i < s.size(); ++i){
        if(s.at(i) == 'A' || s.at(i) == 'C' ||
           s.at(i) == 'G' || s.at(i) == 'T'){
            cur++;
        }else{
            cur = 0;
        }
        ans = max(ans, cur);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>

using namespace std;

bool x[110],y[110];
int a,b,c,w,h,n,xs=0,ys=0;
int main(){
    scanf("%d %d %d",&w,&h,&n);
    for(int i=0;i<n;i++){
        scanf("%d %d %d",&a,&b,&c);
        if(c==1){
            for(int j=0;j<w;j++)x[j]=x[j] or j<a;
        }
        if(c==2){
            for(int j=0;j<w;j++)x[j]=x[j] or j>=a;
        }
        if(c==3){
            
            for(int j=0;j<h;j++)y[j]=y[j] or j<b;
        }
        if(c==4){
            for(int j=0;j<h;j++)y[j]=y[j] or j>=b;
        }
    }
    
    for(int i=0;i<w;i++)xs+=x[i]==false;
    for(int i=0;i<h;i++)ys+=y[i]==false;
    
    //scanf("%d %d %d",&a,&b,&c);
    
    printf("%d\n",xs*ys);
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N=2e5+5;
int n,a[N];
signed main() {
	#ifdef aome
	in("aome.inp");	
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	fw (i,0,n) cin>>a[i], a[i]-=i;
	sort(a,a+n);
	int val=a[n/2];
	long long ans=0;
	fw (i,0,n) ans+=abs(a[i]-val);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000003
#define HOGE 100000
#define HUGA 100000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n;
int cnt[26];
int num[26];
char cha[100];

void solve(){
    memset(cnt,0,sizeof(cnt));
    rep(i,n) cin >> cha[i];
    rep(i,n){
        int id = cha[i]-'A';
        cnt[id]++;
        rep(j,26) num[j] = cnt[j];
        sort(num,num+26,greater<int>());
        if(num[0] > num[1]+n-i-1){
            rep(j,26){
                if(cnt[j] == num[0]){
                    char out;
                    out = 'A'+j;
                    cout << out << " " << i+1 << endl;
                    return;
                }
            }
        }
    }
    cout << "TIE" << endl;
}

int main(){
    while(cin >> n){
        if(n == 0) break;
        solve();
    }
}

Measured memory_bytes: 3084
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        if ("H".equals(a)) {
            System.out.println(b);
        } else {
            if ("H".equals(b)) {
                System.out.println("D");
            } else {
                System.out.println("H");
            }
        }
    }
}

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

int main(){
    long long n,a,b,count,sho,amari;
    cin >> n >> a >> b;
    count = 0;
    sho = n /(a+b);
    amari = n % (a+b);
    if(a == 0){
        count = 0;
    }else if(amari >= a){
        count = (sho+1)*a;
    }else{
        count = sho * a + amari;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
N = 10**6
n = gets.to_i
a = []
a[N] = p
ans = 0
(2..N).each do |i|
  next if a[i]
  b = i*i
  while b <= N
    a[b] = true
    b += i
  end
  b = 0
  while n%i == 0
    n /= i
    b += 1
  end
  c = 1
  while c <= b
    ans += 1
    b -= c
    c += 1
  end
end

ans += 1 if n > 1
p ans

Measured memory_bytes: 22172