akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int A, B, C;
int MAX = 1e8;

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> A >> B >> C;
    for (int cnt = 0; cnt < MAX; cnt++) {
        if (A % 2 || B % 2 || C % 2) {
            cout << cnt << endl;
            return 0;
        }
        int a = (B + C) / 2, b = (A + C) / 2, c = (A + B) / 2;
        swap(a, A);
        swap(b, B);
        swap(c, C);
    }
    cout << -1 << endl;


    solve();
    return 0;
}


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

#define LL long long
#define ULL unsigned long long

#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) (((l)+(r))>>1)

const int MOD = (int) 1e9 + 7;
const double eps = (double) 1e-8;
const int maxn = (int) 1e5 + 20;
const double pi = (double) acos(-1.0);

int n;
vector<pair<int, int > > G[maxn];
int c[maxn];

void dfs(int u, int f)
{
    for(auto p : G[u])
    {
        int v = p.first, w = p.second;
        if(v == f) continue;
        c[v] = c[u] ^ w;
        dfs(v, u);
    }
}

void work()
{
    cin >>n;
    for(int i = 1; i < n; i++)
    {
        int x, y, w;
        cin >>x >>y >>w;
        w = w & 1;
        G[x].push_back(make_pair(y, w));
        G[y].push_back(make_pair(x, w));
    }
    dfs(1, 0);
    for(int i = 1; i <= n; i++)
        cout <<c[i] <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r" ,stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416

    int tc = 1;
//    scanf("%d", &tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


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

using namespace std;

class DisjointSet{
  private:
    vector<int> parent, rank;

  public:
    DisjointSet(){};
    DisjointSet(int n){
      parent.resize(n, 0);
      rank.resize(n, 0);
      for(int i=0;i<n;i++){
        this->makeSet(i);
      }
    }

    ~DisjointSet(){};

    void makeSet(int x){
      parent[x] = x;
      rank[x] = 0;
    }

    void unite(int x, int y){
      link(findSet(x), findSet(y));
    }

    void link( int x, int y){
      if( rank[x] > rank[y]){
        parent[y] = x;
      }else{
        parent[x] = y;
        if( rank[x] == rank[y] ){
          rank[y]++;
        }
      }
    }

    int findSet(int x){
      if( x != parent[x] ){
        parent[x] = findSet(parent[x]);
      }
      return parent[x];
    }

    bool same(int x, int y){
      if(findSet(x) == findSet(y)){
          return true;
      }else{
          return false;
      }
    }
};



int main(void){
  int n,q;
  int t, a, b;

  cin >> n >> q;

  DisjointSet ds = DisjointSet(n);

  for(int i=0;i<q;i++){
    cin >> t >> a >> b;
    if(t == 0){
      ds.unite(a,b);    
    }else{
      if(t == 1){
        if(ds.same(a,b)){
          cout << 1 << endl;
        }else{
          cout << 0 << endl;
        }
      }else{
      
      }   
    }
  }
  return 0;
}



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

int main(){
  int a,b;cin>>a>>b;
  string s;cin>>s;
  bool j=1;
  if(s.at(a) != '-')j=0;
  else{
    rep(i,s.size()){
      if(i==a)continue;
      if(s.at(i)<'0' || '9'<s.at(i))j=0;
  	}
  }
  j?cout<<"Yes":cout<<"No";
}

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

int gcd(int x, int y){
	int t = 0;
	t = (x + y) / 2;
	if(x && y != t){
	if(x > y)
		return gcd(x = x - x / y * y,y);
	else if (x < y)
		return gcd(x,y = y - y / x * x);
	}
	else if(x > y)
		return t = x;
	else
		return t = y;
}

int main(){
int n;
int a[1000000];
int j=0;
bool ok=false;
cin>>n;
REP(i,n){
  cin>>a[i];
}
for (int i = 0; i < n; i++)
{
  /* code */
  if(a[i]==1+j){
    j++;
    ok=true;
  }
}
if(ok){
  cout<<n-j<<endl;
}
else
{
  cout<<-1<<endl;
}



}


    

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

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

int main()
{
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    ll n = s.length();

    char prev = 'G';
    ll ans = 0;

    rep(i,n)
    {
    	if(s[i]==prev)
    	{
    		if(prev=='0')
    			s[i] = '1';
    		else
    			s[i] = '0';
    		ans++;
    	}
    	prev = s[i];
    }

    cout << ans << endl;
}


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

int n;
char a[N];

int main()
{
    scanf("%d", &n);
    scanf(" %s", a);
    if (n % 2 == 1)
    {
        printf("No\n");
        return 0;
    }
    for (int i = 0, j = n / 2; i < n / 2; ++i, ++j)
    {
        if (a[i] != a[j])
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    char s[100][11];
    for (i = 0; i < n; i++)
        scanf("%s", s[i]);
    int m;
    scanf("%d", &m);
    char t[100][11];
    for (i = 0; i < m; i++)
        scanf("%s", t[i]);
    int ans = 0;
    int y, j;
    for (i = 0; i < n; i++)
    {
        y = 1;
        for (j = i + 1; j < n; j++)
        {
            if (strcmp(s[i], s[j]) == 0)
                y++;
        }
        for (j = 0; j < m; j++)
        {
            if (strcmp(s[i], t[j]) == 0)
                y--;
        }
        if (ans < y)
            ans = y;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
str_list1 = list(input())
str_list2 = list(input())
str_list2_inv = [i for i in sorted(str_list2)[::-1]]
str1 = ''.join(sorted(str_list1))
str2 = ''.join(str_list2_inv)
if str1 == str2:
    print('No')
elif sorted([str1,str2])[0] == str1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
    string N;
    cin >> N;
 
    int tmp = 0;
    for (int i = 0; i < N.size(); ++i) {
        tmp += N[i] - '0';
    }
 
    if (tmp % 9 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
 
    return 0;
}

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

using namespace std;

int interval[10080];
int s,n,t,p,m,day=0,tii,ald=0,alt=0;
string weekday,tim;

void init(){
    ald=0,alt=0;
    memset(interval, 0, sizeof(interval));
    if(weekday[0]=='A')ald=1;
    if(weekday=="Sun")day=0;
    if(weekday=="Mon")day=1;
    if(weekday=="Tue")day=2;
    if(weekday=="Wed")day=3;
    if(weekday=="Thu")day=4;
    if(weekday=="Fri")day=5;
    if(weekday=="Sat")day=6;
    if(tim=="All")alt=1;
    if(ald==1){
        if(alt==1)for(int i=0;i<10080;i++)interval[i]=1;
        else if(tim=="Day")for(int i=0;i<7;i++)for(int j=i*24*60+6*60;j<i*24*60+18*60;j++)interval[j]=1;
        else for(int i=0;i<7;i++)for(int j=i*24*60+18*60;j<(i*24*60+24*60+6*60);j++)interval[j%10080]=1;
    }
    else{
        if(alt==1)for(int j=day*24*60;j<(day+1)*24*60;j++)interval[j]=1;
        else if(tim=="Day")for(int j=day*24*60+6*60;j<day*24*60+18*60;j++)interval[j]=1;
        else {
            for(int j=day*24*60+18*60;j<(day*24*60+24*60);j++)interval[j%10080]=1;
            for(int j=day*24*60;j<(day*24*60+6*60);j++)interval[j%10080]=1;
        }
    }
}
int main(){
    while(cin>>s>>n>>t>>weekday>>tim>>p>>m){
        if(s==0)
            break;
        init();
        double ans=1;

        for(int i=0;i<10080;i++){
            double cu=1;
            for(int j=0;j<m;j++){
                int now=(j*t+i)%10080;
                int fini=1;
                for(int k=0;k<=s;k++){
                    if(interval[(now+k)%10080]!=1){
                        fini=0;
                        break;
                    }
                }
                if(fini==1){
                    for(int k = 0; k < n; k++)
                        cu *= (double)(p - 1) / p;
                }
            }
            ans=min(ans,cu);
        }
        
        printf("%.10f\n",1-ans);
    }
}

Measured memory_bytes: 1308
n = int(input())
buf = [0 for i in range(100000)]

for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            tp = i*i+j*j+k*k+i*j+j*k+k*i
            buf[tp] += 1

for i in range(n):
    print(buf[i+1])

Measured memory_bytes: 73352
N=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(N-1):
    if i+1==p[i]:
        temp=p[i+1]
        p[i+1]=p[i]
        p[i]=temp
        ans+=1
if p[N-1]==N:
    ans+=1
print(ans)

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

using namespace std;

struct UnionFind {
    vector<int> parent; // parent[root] is the negative of the size.

    explicit UnionFind(int n) : parent(n, -1) {
    };                                       //初期化

    bool unite(int u, int v) {//ノードx,yが属する木を併合
        u = root(u);
        v = root(v);
        if (u == v) return false;
        if (parent[u] > parent[v]) swap(u, v);
        parent[u] += parent[v];
        parent[v] = u;
        return true;
    }

    bool same(int u, int v) {//ノードx,yが同じ木に属するかどうか
        return root(u) == root(v);
    }

    int root(int u) {//ノードuが属する木の根
        return parent[u] < 0 ? u : parent[u] = root(parent[u]);
    }

    int size(int u) {//ノードiを含む木の大きさ
        return -parent[root(u)];
    }
};


int main() {
    unsigned int n, k, l;
    cin >> n >> k >> l;

    auto uf1 = UnionFind(n);
    for (int i = 0; i < k; ++i) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        uf1.unite(p, q);
    }

    auto uf2 = UnionFind(n);
    for (int i = 0; i < l; ++i) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        uf2.unite(p, q);
    }

    map<pair<int, int>, int> mp;
    for (int i = 0; i < n; ++i) {
        mp[make_pair(uf1.root(i), uf2.root(i))]++;
    }

    for (int i = 0; i < n; ++i) {
        cout << mp[make_pair(uf1.root(i), uf2.root(i))];
        (i != n - 1) ? (cout << " ") : (cout << endl);
    }
    return 0;
}

Measured memory_bytes: 13568
#include <stdio.h>

int main (){
  long long int N,A,B,num,count;
  scanf("%lld %lld %lld",&N,&A,&B);
  if(A == 0){
	printf("0");
    return 0;
  }
  num = N%(A+B);
  N = N/(A+B);
  count = N*A;
  if(num > A){
    count += A;
  }else {
    count += num;
  }
  printf("%lld",count);
  return 0;
}

  


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
  string s;
  cin >> s;
  if(s[0]=='a'||s[0]=='i'||s[0]=='e'||s[0]=='u'||s[0]=='o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" <<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	string s;cin>>s;
	int n=s.size();
	rep(i,n){
		if((s[i]=='R' && i%2==1) || (s[i]=='L' && i%2==0)){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1e9+7;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
//llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,m,i,j;cin>>n>>m;
	vector<vector<pair<int,llint>>>go(n);
	for(i=0;i<m;i++){
		int u,v;llint s;cin>>u>>v>>s;s-=2;
		u--;v--;
		go[u].pub(mp(v,s));
		go[v].pub(mp(u,s));
	}
	vector<int>hsi(n,0);
	vector<llint>pra(n);
	llint amax=big,amin=0;
	queue<int>que;que.push(0);
	hsi[0]=1;
	while(que.size()>0){
		int ter=que.front();
		que.pop();
		//cerr<<ter<<endl;
		for(auto it:go[ter]){
			if(hsi[it.fir]==0){
				hsi[it.fir]=-hsi[ter];
				pra[it.fir]=it.sec-pra[ter];
				que.push(it.fir);
			}else if(hsi[it.fir]==hsi[ter]){
				llint aaa=(it.sec-(pra[it.fir]+pra[ter]));
				if(aaa%2){cout<<0<<endl;return 0;}
				if(hsi[ter]==-1){aaa=-aaa;}
				aaa/=2;
				mineq(amax,aaa);maxeq(amin,aaa);
				if(amax<amin){cout<<0<<endl;return 0;}
			}else if(pra[it.fir]+pra[ter]!=it.sec){cout<<0<<endl;return 0;}
		}
	}
	for(i=0;i<n;i++){
		if(hsi[i]==-1){mineq(amax,pra[i]);}
		else{maxeq(amin,-pra[i]);}
	}
	cout<<max(0LL,amax-amin+1)<<endl;
	return 0;
}

Measured memory_bytes: 9216
N,M = [int(i) for i in input().split()]

S = [[] for _ in range(N)]
for i in range(M):
    k,*s = [int(j) for j in input().split()]
    for j in s:
        S[j-1].append(i)

p = [int(i) for i in input().split()]
ans = 0
for i in range(2**N):
    tmp = [0]*M
    for j in range(N):
        if (i >> j) & 1:
            for z in S[j]:
                tmp[z] = tmp[z]^1

    if p == tmp:
        ans += 1
print(ans)


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    string s, t; cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    int len = min(s.length(), t.length());

    REPI(i, len){
        if(s[i] < t[i]){
            cout << "Yes"; return 0;
        }else if(s[i] == t[i])
            continue;
        else{
            cout << "No"; return 0;
        }
    }
    cout << (s.length() < t.length() ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)
const int INF=1e9;
using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
vector<int> h(101);
int solve1(int st,int en,int curr){
  if(st>en) return 0;
  int idx=min_element(h.begin()+st,h.begin()+en+1)-h.begin();
  vector<int> v;
  rep(i,st,en+1) if(h[i]==h[idx]) v.pb(i);
  int ans=solve1(st,v[0]-1,h[idx])+h[idx]-curr;
  rep(i,1,v.size()) ans+= solve1(v[i-1]+1,v[i]-1,h[idx]);
  ans+= solve1(v[v.size()-1]+1,en,h[idx]);
  return ans;
}
void  solve(){
  int n;
  cin>>n;
  rep(i,0,n) cin>>h[i];
  int idx=min_element(h.begin(),h.begin()+n)-h.begin();
  vector<int> v;
  rep(i,0,n) if(h[i]==h[idx]) v.pb(i);
  int ans=solve1(0,v[0]-1,h[idx])+h[idx];
  rep(i,1,v.size()) ans+= solve1(v[i-1]+1,v[i]-1,h[idx]);
  ans+= solve1(v[v.size()-1]+1,n-1,h[idx]);
  cout<<ans<<endl;
}
// int main(){
//
//     optimizeIO();
//     // tc
//     { solve();
//     }
// }


int main(){

  int N, i, j, cnt = 0; cin >> N;
  vector<int> h(N);
  for(i=0; i<N; i++) cin >> h[i];

  while(true){

    j = 0;
    while(h[j] == 0) j++;

    for(i = j; i < N; i++){

      if(h[i] == 0){
        cnt++;
        break;
      }
      h[i]--;
      if(i == N - 1) cnt++;
    }

    bool flag = true;
    for(i = 0; i < N; i++){
      if(h[i] != 0) flag = false;
    }
    if(flag){
      cout << cnt << endl;
      return 0;
    }
  }
  return -1;
}


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

int main() {
  int N; cin >> N;
  
  int answer = 1;
  bool isIncline = false;
  bool isFlat = true;
  vector<int> nums(N);
  
  cin >> nums.at(0);
  
  for (int i = 1; i < N; i++) {
    cin >> nums.at(i);

    if (isFlat) {
      if (nums.at(i) > nums.at(i - 1)) {
        isFlat = false;
        isIncline = true;
      } else if (nums.at(i) < nums.at(i - 1)) {
        isFlat = false;
        isIncline = false;
      }
    } else if (isIncline) {
      if (nums.at(i) < nums.at(i - 1)) {
        answer++;
        isFlat = true;
      }
    } else {
      if (nums.at(i) > nums.at(i - 1)) {
        answer++;
        isFlat = true;
      }
    }
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int n,t,j;
    int r[200000];
    int x;
    int max = 1-1000000000;
    int min ;
    scanf("%d\n",&n);
    for(t=0;t<=n;t++){
        scanf("%d",&r[t]);
        }
    min = r[0];
    for(t=1;t<=n-1;t++){
        x = r[t]-min;
        if(x>max){
            max=x;
        }
        if(r[t]<min){
            min=r[t];
        }
    }
printf("%d\n",max);
return 0;
}

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

int main(){
	int x;
	cin>>x;
	
	bool flag=false;
	while(flag == false){
		//Prime Judgement
		int div=2;
		int cnt=0;	
		do{
			if(x%div==0) cnt++;
			div++;
		} while(div<=x);
		
		if(cnt==1) flag=true;
		else x++;
	}
	cout << x << endl;
}

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

int main(){
    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    if(K <= A){
        cout << K;
        return 0;
    }
    if(K <= A + B){
        cout << A;
        return 0;
    }
    cout << A - (K - A - B);
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  if(a+b>c+d){
    cout << "Left";
  }else if(a+b==c+d){
    cout << "Balanced";
  }else{
    cout << "Right";
  }
}

Measured memory_bytes: 256
S=gets.chop
if S.size==26
  if S=="zyxwvutsrqponmlkjihgfedcba"
    p -1
    exit
  end
  24.downto(0) do |i|
    next if S[i]>S[i+1]
    s=S[0...i]
    s += S[(i+1)...S.size].chars.select{|c|c>S[i]}.min
    puts s
    exit
  end
  exit
end

h={}
S.chars.each{|c|h[c]=true}
"a".upto("z") do |c|
  next if h[c]
  puts S+c
  exit
end


Measured memory_bytes: 1788
N, M = gets.split.map(&:to_i)

G = Array.new(N){ [] }
M.times do 
  u,v = gets.split.map(&:to_i)
  G[u-1] << v-1
  G[v-1] << u-1
end

dp = Array.new(N){ Array.new(1 << N, 0) }
dp[0][1] = 1

(1 ... (1 << N)).each do |state|
  N.times do |u|
    G[u].each do |v|
      if state[v] == 0 # not visited.
        dp[v][state | (1 << v)] += dp[u][state] 
      end
    end
  end
end
puts N.times.map{|u| dp[u][(1 << N) - 1] }.inject(&:+)

Measured memory_bytes: 1788
#input = raw_input
n = int(input())
nums = sorted(map(int, input().split(" ")), reverse=True)

from collections import deque

for i in range(n):
    if i == 0:
        num0 = nums[i]
        out = 0
    elif i == 1:
        num1 = nums[i]
        out = num0
        q = deque([[num0, num1], [num0, num1]])
    else:
        in_e = q.popleft()
        #print(in_e)
        cur = nums[i]
        out += in_e[1]
        for nn in in_e: 
            e = [nn, cur]
            q.append(e)

print(out)

Measured memory_bytes: 35048
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
using namespace std;
 
#define LOCAL  1
#define UPLOAD 2
 
#define ll long long
const long long INF = 1LL << 60;
 
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
#define REP(i,M) for(int i=0;i<M;i++)
 
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  
  ll N = input();
  ll K = input();

  ll ret = ceil(log(N) / log(K));

  output(max((ll)1, ret));
  
  return 0;
}

Measured memory_bytes: 640
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
c=[int(x) for x in input().split()]
z=0
i_old = -100
for i in a:
    z += b[i-1]
    if i == (i_old + 1):
        z += c[i_old-1]
    i_old = i
print(z)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

int main()
{
    int k;
    cin >> k;
    vector<vector<int> > vecini(k, vector<int>(2));
    for(int i = 1; i < k; ++i)
    {
        vecini[i][0] = (10*i) % k;
        vecini[i][1] = (i+1) % k;
    }
    deque<int> q;
    vector<int> cost(k, k);
    vector<bool> viz(k);
    q.push_back(1);
    cost[1] = 1;
    int p, v;
    while(q.empty() == false)
    {
        p = q.front();
        viz[p] = true;
        q.pop_front();
        v = vecini[p][0];
        if(viz[v] == false && cost[p] < cost[v])
        {
            cost[v] = cost[p];
            q.push_front(v);
        }
        v = vecini[p][1];
        if(viz[v] == false && cost[p] + 1 < cost[v])
        {
            cost[v] = cost[p] + 1;
            q.push_back(v);
        }
    }
    cout << cost[0];
    return 0;
}


Measured memory_bytes: 6272
#include <iostream>

using namespace std;

const int MAX = 2e5;
const int MOD = 998244353;

int main() {
  int N, K; cin >> N >> K;
  int L[10], R[10];
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }

  long long dp[MAX]; // imos dp
  for (int i = 0; i < MAX; i++) {
    dp[i] = 0;
  }
  dp[0] = 1;
  dp[1] = MOD - 1;
  long long num = 0;
  for (int i = 0; i < N; i++) {
    num = (num + dp[i]) % MOD;
    if (num == 0) continue;
    for (int j = 0; j < K; j++) {
      if (i + L[j] < N) dp[i + L[j]] = (dp[i + L[j]] + num) % MOD;
      if (i + R[j] + 1 < N) dp[i + R[j] + 1] = (dp[i + R[j] + 1] - num + MOD) % MOD;
    }
  }

  // for debugging
  for (int i = 0; i < N - 1; i++) {
    dp[i + 1] = (dp[i] + dp[i + 1]) % MOD;
  }

  cout << num << endl;
}

Measured memory_bytes: 5164
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10,mod=998244353;
int pw[N],f[N],n;
char str[N]; int S[N];
int sol(int k) {
    int tot=0;
    for(int i=0;i<k;++i) if(S[i]==1) tot=(tot+pw[k-i-1])%mod;
    int flg=1;
    for(int i=k;i<n;++i) if(S[i]!=(S[i-k]^1)) {
        if(S[i]<(S[i-k]^1)) flg=0;
        else flg=1;
        break;
    }
    return (flg+tot)%mod;
}
int main() {
    rd(n);
    scanf("%s",str);
    for(int i=0;i<n;++i) S[i]=str[i]-'0';
    pw[0]=1; for(int i=1;i<=n;++i) pw[i]=pw[i-1]*(ll)2ll%mod;
    for(int i=1;i<=n;++i) if(n%i==0&&((n/i)&1)) f[i]=sol(i);
    for(int i=1;i<=n;++i) if(f[i])
        for(int j=i*2;j<=n;j+=i) if(n%j==0&&((n/j)&1))
            f[j]=(f[j]-f[i])%mod;
    // for(int i=1;i<=n;++i) printf("%d ",f[i]); puts("");
    int ans=0;
    for(int i=1;i<=n;++i) ans=(ans+f[i]*2ll*i)%mod;
    printf("%d",(ans+mod)%mod);
    return 0;
}

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

int judge(string A,string B, int Alen, int Blen){
    int ans=0;
    int i,j;
    int temp=0;
    //かぶったら0にする
    int ansbefore=0;
    for(i=0;i<Alen;++i){
        for(j=0;j<Blen;++j){
            if(A[i]==B[j]){
                if(ansbefore<ans){
                    B[j]='0';
                }
                if(B[j]!='0'){
                    temp=1;
                    //cout<<"i:"<< i<< " j:" << j<< " "<<B[j]<<endl;
                    ans++;
                }
                B[j]='0';
                
            }
        }
        ansbefore=ans;
        temp=0;

    }




    return ans;
}



int main(void){
    // 自分の得意な言語で
    // Let's チャレンジ！！
    int N;
    string s;
    cin>>N>>s;
    string X,Y;

    char c[26];
    int i,j,t;
    int count;
    for(i=0;i<26;i++){
        c[i]='0';
    }
    int max=0;

    for(i=1;i<N;++i){
        X=s[0];
        //j:Xの文字列
        for(j=1;j<i;++j){
            X+=s[j];
        }
        //t-j:Yの文字列
        Y=s[j];
        for(t=j+1;t<N;++t){
            Y+=s[t];
        }
        //文字列形成完了
        //cout << "X:"<< X<< j << " Y:"<< Y<< t-j <<endl;
        count = judge(X,Y,j,t-j);
        //cout << i << ":" <<count<<endl;

        if(count>max){
            max=count;
        }


    }



    cout<< max<<endl;


    return 0;
}


//X と Y のどちらにも含まれている文字

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this


void solve(){
    ll n; cin>>n;

    ll a[n+1];
    FOR(i,1,n) cin>>a[i];

    stack<ll> fi,em;

    ll j = 1;
    bool flag = true;
    while(j<=n){
        ll to_insert = a[j];
        if(fi.size() + em.size()< to_insert - 1){
            flag = false; break;
        }else if(fi.size() < to_insert - 1){
            while(!em.empty()){
                ll x = em.top();
                fi.push(x);
                em.pop();
            }
        }
        while(fi.size() >= to_insert){
            ll x = fi.top();
            fi.pop();
            em.push(x);
        }

        fi.push(to_insert);
        j++;
    }

    if(!flag) cout<<-1<<endl;
    else {
        while(!fi.empty()){
            ll x = fi.top();
            fi.pop();
            em.push(x);    
        }

        while(!em.empty()){
            ll x = em.top();
            cout<<x<<endl;
            em.pop();
        }
    }
}

signed main(){

//  #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    FastRead;    

    ll t;
    t = 1; 
    // cin>>t;
    while(t--) solve();
    
}

Measured memory_bytes: 256
/*
Just a basic DP problem where at every step you have two choices either to choose
i or j, but after choosing that call the recursion for other player and that value 
should after subtraction should be maximum for both.

It should be maximum for both the cases because if we see X-Y then we maximize it by
taking X such that the remaining is minimum for other person
and minimize X-Y by taking maximum Y such that remaining for another is minimum.

Just think it manually and cache using DP.

created by sanyam singhal
*/

#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define w(t) int t;	cin>>t while(t--)
#define triplet pair<int,pair<int,int>>
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
#define loop(i, k, n) for(ll i=k; i<n; i+=1)
#define loop2(i, k, n) for(ll i=k; i>=n; i--)

const ll inf = 1e18;
ll dp[3001][3001];


void take_fileIO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  return;
}

ll bottomUp(vector<ll> &candies, int i, int j, int p) {
  if(i>j){
    return 0;
  }
  else if(dp[i][j]!=-1)
    return dp[i][j];
  else{
    if(p==1){
      ll op1 = candies[i] - bottomUp(candies, i+1, j, 1-p);
      ll op2 = candies[j] - bottomUp(candies, i, j-1, 1-p);
      return dp[i][j] = max(op1, op2);
    }
    else{
      ll op1 = candies[i] - bottomUp(candies, i+1, j, 1-p);
      ll op2 = candies[j] - bottomUp(candies, i, j-1, 1-p);
      return dp[i][j] = max(op1, op2);
    }
  }
}

void solve(){
  memset(dp, -1, sizeof(dp));
  ll n; cin>>n;
  vector<ll>candies(n);
  loop(i, 0, n)
    cin>>candies[i];

  cout<<bottomUp(candies, 0, n-1, 1);
}

int main(){
  fastIO;
  // take_fileIO();
  
  solve();
  return 0;
}

Measured memory_bytes: 71040
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    LL(N);
    STR(S);
    ll ans = 1LL;
    for(ll i = 0LL; i < N-1; i++){
        if(S[i]==S[i+1]){

        } else {
            ans++;
        }
    }
    cout << ans << endl;
   
}

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

int main( ) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n,i,a,b;
    t = 1;
    while(t--) {
     a = 0;
	 cin >> n;
	 int arr[n],brr[n],crr[n - 1];
	 for(i = 0; i < n; i++)
	  cin >> arr[i];
	 for(i = 0; i < n; i++)
	  cin >> brr[i];
	 for(i = 0; i < n - 1; i++)
	  cin >> crr[i];
	 b = arr[0];
	 a = a + brr[b - 1];
	 for(i = 1; i < n; i++) {
	  if(arr[i] == b + 1)
	   a = a + brr[arr[i] - 1] + crr[b - 1];
	  else
	   a = a + brr[arr[i] - 1];
	  b = arr[i];
	 }
	 cout << a << endl;
    }
    return 0;
}



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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll v;
  cin >> v;
  ll ans = 0;
  ans = v / 500 * 1000;
  v %= 500;
  ans += v / 5 * 5;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

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

const int INF = (int)((1ll << 31) - 1ll);
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

template< class Abel > class RMQ {
public:
  RMQ(int _n) {
    init(_n);
  }

  void init(int _n) {
    N = 1;
    while (N < _n) {
      // 頂点数を2のべき乗にする
      N <<= 1;
    }
    d.resize(2 * N - 1);
    for (int i = 0; i < 2 * N - 1; ++i) {
      d[i] = INF;
    }
  }

  void update(int k, Abel a) {
    // kの位置を葉まで移動
    k += N - 1;
    d[k] = a;
    // 頂点まで値を更新する
    while (k > 0) {
      k = (k - 1) / 2;
      d[k] = min(d[k * 2 + 1], d[k * 2 + 2]);
    }
  }

  // 呼び出しは[a, b)の!!!半開区間!!!
  Abel _query(int _a, int _b) {
    return query(_a, _b, 0, 0, N);
  }
  
  
private:
  int N;
  vector< Abel > d;

  // 呼び出しでミスをする可能性があるので、privateにしておく
  Abel query(int a, int b, int k, int l, int r) {
    // [a, b)に対して、[l, r)が範囲として成立していない
    if (!(a < r && l < b)) return INF;
    
    // [a, b)が[l, r)を完全にカバーしている(queryを再帰的に呼び出しても範囲は狭まるだけ)
    if (a <= l && r <= b) return d[k];
    
    // それ以外の時、葉の2つの子の最小値を再帰的に求める
    Abel vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    Abel vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  
};

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

  CIN(N, Q);

  RMQ< int > rmq(N + 1);

  REP(qi, Q) {
    CIN(c, _x, _y);

    if (c == 0) {
      // update
      rmq.update(_x, _y);
    } else {
      // find(半開区間)
      cout << rmq._query(_x, _y + 1) << endl;
    }
  }

  return 0;
}




Measured memory_bytes: 3864
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char
import Data.Bits

modN = 1000000007


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

pow :: Int -> Int -> Int -> Int
pow base 1 modNum = base `mod` modNum
pow base time modNum
    | odd time = let 
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a * base `mod` modNum
    | otherwise = let
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a `mod` modNum

solve :: Integer -> Integer -> Integer
solve n k = let
    ketaCount k = let 
        mini = (0 + k - 1) * k `div` 2
        maxi = (n - k + 1 + n) * k `div` 2
        in
        (maxi - mini + 1) `mod` modN
    in
    (`mod` modN) $ sum $ ketaCount <$> [k..n+1] 



main = do
    (n, k) <- readTuple2
    print $ solve (fromIntegral n)  (fromIntegral k)







Measured memory_bytes: 4912
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}
// }}} End Header

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

    VAR(int, N, M);
    vector<i64> a(N), b(N), c(N);
    vector<int> id(N);

    rep(i, 0, N) {
        read(a[i], b[i], c[i]);
        id[i] = i;
    }

    constexpr int S[] = { 1, -1 };
    i64 ans = 0;
    for (const int x : S) for (const int y : S)  for (const int z : S) {
        sort(all(id), [&](int i, int j) {
            return a[i]*x + b[i]*y + c[i]*z > a[j]*x + b[j]*y + c[j]*z;
        });

        i64 sumA = 0;
        i64 sumB = 0;
        i64 sumC = 0;
        rep(i, 0, M) {
            sumA += a[id[i]];
            sumB += b[id[i]];
            sumC += c[id[i]];
        }
        chmax(ans, abs(sumA) + abs(sumB) + abs(sumC));
    }

    print(ans);

    return 0;
}


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

typedef long long int ll;

int main(){
    ll n,k,x,y,ans;
    scanf("%lld %lld %lld %lld",&n,&k,&x,&y);
    if(k>n) ans = n*x;
    else ans = (k*x)+(n-k)*y;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii ;


int main(){
    string s;
    cin >> s;
    if(s[s.size()-1] == 's'){
        cout << s << "es";
    }
    else{
        cout << s << "s" ;
    }
}



Measured memory_bytes: 3624
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
int a[110];
int b[110];
int main(){
	for(int i=0;i<3;i++){
		scanf("%d",a+i);
	}
	int ret=0;
	for(int i=0;i<1100;i++){
		if(a[0]%2+a[1]%2+a[2]%2){
			break;
		}
		b[0]=(a[0]+a[1])/2;
		b[1]=(a[2]+a[1])/2;
		b[2]=(a[0]+a[2])/2;
		a[0]=b[0];a[1]=b[1];a[2]=b[2];ret++;
	}
	if(ret>1000)ret=-1;
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2299&lang=jp
using namespace std;

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,-1,0,1 };

vector<int> search(int m, int n, vector<vector<char>>& C,int key) {
	vector<int> dir;
	vector<vector<int>> alp(26);
	for (int i = 0; i < 4;i++) {
		for (int k = 1;k < key;k++) {
			int im = m + k*dx[i];
			int in = n + k*dy[i];
			if (C[im][in] == '#')break;
			if (C[im][in] != '.') {
				alp[C[im][in] - 'A'].push_back(i);
				break;
			}
		}
	}
	for (int i = 0; i < 26;i++) {
		if (alp[i].size() < 2)continue;
		for (int j = 0; j < (int)alp[i].size();j++) {
			dir.push_back(alp[i][j]);
		}
	}
	return dir;
}

void del(int m, int n, vector<vector<char>>& C, int key, int dir) {
	for (int k = 1;k < key;k++) {
		int im = m + k*dx[dir];
		int in = n + k*dy[dir];
		if (C[im][in] == '#')break;
		if (C[im][in] != '.') {
			C[im][in] = '.';
			break;
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int M, N; cin >> M >> N;
	vector<vector<char>> C(M+2, vector<char>(N+2, '#'));
	for (int i = 1; i <= M;i++) for (int j = 1; j <= N;j++) cin >> C[i][j];

	int ans = 0;
	int key = max(N, M);
	while (true) {
		bool f = false;
		for (int i = 1;i <= M;i++) {
			for (int j = 1;j <= N;j++) {
				if (C[i][j] == '.') {
					auto Dir = search(i, j, C, key);
					for (int k = 0; k < (int)Dir.size();k++) {
						if(!f)f = true;
						ans++;
						del(i, j, C, key, Dir[k]);
					}
				}
			}
		}
		if (!f)break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3352