akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stdio.h>
#include <numeric>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
    double l,a,b,c,d;
    cin>>l>>a>>b>>c>>d;
    cout<<l-max(ceil(a/c),ceil(b/d))<<endl;
}


Measured memory_bytes: 3216
#include<stdio.h>
int main()
{
  int to1[3][10]={0},to2[3][10]={0},to3[3][10]={0},to4[3][10]={0};
  int a=0,n,b,f,r,v,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    if(b==1)to1[f-1][r-1]+=v;
    if(b==2)to2[f-1][r-1]+=v;
    if(b==3)to3[f-1][r-1]+=v;
    if(b==4)to4[f-1][r-1]+=v;
  }
  for(a=1;a<=4;a++){
    for(i=0;i<3;i++){
      for(j=0;j<10;j++){
        if(a==1)printf(" %d",to1[i][j]);
        if(a==2)printf(" %d",to2[i][j]);
        if(a==3)printf(" %d",to3[i][j]);
        if(a==4)printf(" %d",to4[i][j]);
      }
      printf("\n");
    }
    if(a!=4)printf("####################\n");
  }
  return 0;
}

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

int main(){
  char s[200001];
  scanf("%s",s);
  int n=0;
  int m=strlen(s)-1;
  while(1){
    if(s[n]=='A') break;
    n++;
  }
  while(1){
    if(s[m]=='Z') break;
    m--;
  }
  printf("%d",m-n+1);
  return 0;
}
    
  


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

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  int sum=0;
  rep(i, N){
    cin >> A[i];
    sum += A[i];
  }
  
  if(sum >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
  

}

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


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

  ll a;cin >> a;
  cout <<(a+a*a+a*a*a) << endl;
  
  
  return 0;
    

}


Measured memory_bytes: 3608
#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 n, m, h[100001], ma[100001];
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> h[i];
        ma[i] = 0;
    }
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        ma[a] = max(ma[a], h[b]);
        ma[b] = max(ma[b], h[a]);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += h[i] > ma[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4364
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;ll a=0,b=0,c=1;
  for(ll i=0;i<n;i++){
    cin>> a;
    b=max(a,b);
    if((b-a)>=2){c=0;break;}
  }
  if(c==0){
    cout<<"No"<<endl;
  }else{
    cout << "Yes"<<endl;
  }
  
}

Measured memory_bytes: 256
module ABC136

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_A

  ! contained <subroutine>s and <function>s are below
  contains
  
  subroutine task_A (volume_Container1_max, volume_Container1_contained, volume_Container2_contained)

    ! arguments for this <subroutine>
    integer(INT8), intent(in) :: volume_Container1_max
    integer(INT8), intent(in) :: volume_Container1_contained
    integer(INT8), intent(in) :: volume_Container2_contained

    ! STEP.01
    ! calculate & output the volume of water remained in the container No.2
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') &!
    volume_Container2_contained - min(volume_Container1_max - volume_Container1_contained, volume_Container2_contained)
    
    ! STEP.END
    return

  end subroutine task_A

end module ABC136

program main

  ! <module>s to import
  use,     intrinsic :: iso_fortran_env
  use, non_intrinsic :: ABC136

  ! variables for this <program>
  integer(INT8) :: A
  integer(INT8) :: B
  integer(INT8) :: C

  read(unit=INPUT_UNIT, fmt=*) A, B, C
  
  call task_A (A, B, C)

end program main

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* 角度でソートし全区間を試す */

#define rep(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define repn(i, m, n) for (int (i) = (m) ; (i) < (int)(n) ; ++(i))
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define repn_rev(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= (m) ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7

/* ベクトル型 */
struct V {
    double x, y;
    V(double x=0, double y=0): x(x), y(y) {}
    V& operator+=(const V& v){ x += v.x; y+= v.y; return *this;}
    V operator+(const V& v) const{return V(*this) += v;}
    V& operator-=(const V& v){x -= v.x; y-= v.y; return *this;}
    V operator-(const V& v) const{return V(*this) -= v;}
    V& operator*=(double s){x *= s; y*=s; return *this;}
    V operator*(double s) const{return V(*this) *= s;}
    V& operator/=(double s){x /= s; y/=s; return *this;}
    V operator/(double s) const{return V(*this) /= s;}
    /* 内積 */
    double dot(const V& v) const {return x*v.x + y*v.y;}
    /* 外積 */
    double cross(const V& v) const {return x*v.y - v.x*y;}
    /*ノルムの二乗*/
    double norm2() const {return x*x + y*y;}
    /* ノルム */
    double norm() const {return sqrt(norm2());}
    /* 象限判定 */
    int ort() const {
        if(y > 0) return x>0 ? 1:2;
        else return x>0 ? 4:3;
    }
    bool operator<(const V& v) const{
        int o = ort(), vo = v.ort();
        if(o!=vo) return o<vo;
        return cross(v) > 0;
    }
};
istream& operator>>(istream& i, V& v){
    i >> v.x >> v.y;
    return i;
}

int main(){
    int n;
    cin>>n;
    vector<V> v(n);
    rep(i, n) cin>>v[i];
    sort(v.begin(), v.end());
    double ans = 0;
    /* 区間の全通りを試す */
    rep(l, n){
        int r = l;
        V now;
        rep(j, n){
            now += v[r];
            ans = max(ans, now.norm());
            r = (r+1)%n;
        }
    }
    printf("%.12f\n", ans);

    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
int main() {
    lint N;
    cin >> N;
    vector<lint> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));

    vector<lint> GCD_L(N + 1, 0);
    rep(i, N) { GCD_L[i + 1] = __gcd(GCD_L[i], A[i]); }

    // setwise coprimeでない場合
    if (GCD_L[N] != 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    set<lint> used;
    for (int i = 0; i < N; i++) {
        auto a = prime_factorize(A[i]);
        for (auto p : a) {
            lint prime, k;
            tie(prime, k) = p;
            if (used.count(prime) == 1) {
                cout << "setwise coprime" << endl;
                return 0;
            } else {
                used.insert(prime);
            }
        }
    }

    cout << "pairwise coprime" << endl;
    return 0;
}

Measured memory_bytes: 18684
#include <iostream>
#include <stdio.h>
#include <math.h>

#define MAX 101
int sum(0);

void print(int A[], int n) {
    for (int i = 0; i < n; i++) {
        if (i) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", sum);
}

void bubbleSort( int A[], int n ) {
    int i = 1;
    while (1) {
        for (int j = n-1; j >= i; j--) {
            if (A[j] < A[j-1]) {
                std::swap(A[j], A[j-1]);
                sum ++;
            }
        }
        if (i == n) break;
        i++;
    }
    print(A, n);
}

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

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

int main() {
	int n, r[1000], l[1000];
	int s = 0;
	cin >> n;
	for (int i = 0; i != n; i++) {
		cin >> r[i] >> l[i];
		s = s + l[i] - r[i] + 1;
	}
	cout << s << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;

    x = x % p;
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    // cin >> tc;
    while (tc--)
    {
        string s, t;
        cin >> s >> t;
        int n, m;
        cin >> n >> m;
        string g;
        cin >> g;
        if (g == s)
            n--;
        if (g == t)
        {
            m--;
        }
        cout << n << " " << m << endl;
    }

    return 0;
}

Measured memory_bytes: 256
int Z(int *a,int *b){return *b-*a;}
a[999],i;main(n,j){
	for(scanf("%d",&n);i<n;i++)scanf("%d",a+i);
	qsort(a,n,4,Z);
	long long r=1;
	for(i=0;i<n&&(j=a[i]-i/4)>0;i++)r+=j;
	i=!printf("%lld\n",r);
}

Measured memory_bytes: 644
n,a,b = map(int,input().split())
if n%(a+b) <= a and n%(a+b)!=0:
    print(n//(a+b)*a+n%(a+b))
elif n%(a+b)==0:
    print((n//(a+b))*a)
else:
    print(n//(a+b)*a+a)

Measured memory_bytes: 38384
#include <iostream>
#include <cstdint>
#include <bitset>

int main() {
  std::uint_fast64_t n;
  std::cin >> n;

  std::uint_fast64_t result = 0;
  for (std::uint_fast64_t i = 0; i < n; ++i) {
    std::uint_fast64_t a;
    std::cin >> a;
    result += static_cast<std::uint_fast64_t>(std::bitset<32>((a & -a) - 1).count());
  }
  std::cout << result << std::endl;
  return 0;
}

Measured memory_bytes: 256
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}

int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int count{};
    for(int i=0;i<n-2;i++)
    {
        if(arr[i+1]>arr[i] && arr[i+2]>arr[i+1])
            count++;
        if(arr[i+1]<arr[i] && arr[i+2]<arr[i+1])
            count++;
    }
    cout<<count;
	return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;

    cin>>a>>b;
    if(a==1&&b==2)
 cout<<"3"<<endl;
  else if(a==2&&b==3)
    cout<<"1"<<endl;
    else if(a==2&&b==1)
     cout<<"3"<<endl;
       else if(a==3&&b==2)
     cout<<"1"<<endl;
     else cout<<"2"<<endl;

return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <vector>
using namespace std;
map <string,int> mymap;
vector <string> v;
int main ()
{
	int n, i=0, k=1, maxx=-1;
	cin>>n;
	string s[n+1], c[n+1];
	for(i=1; i<=n; i++){
		cin>>s[i];
		mymap[s[i]]+=1;
	}
	for(i=1; i<=n; i++){
		if(maxx<mymap[s[i]]){
			maxx=mymap[s[i]];
		}
	}
	for(i=1; i<=n; i++){
		if(mymap[s[i]]==maxx){
		v.push_back(s[i]);
		mymap[s[i]]=0;
		}	
	}
	sort(v.begin(),v.end());
	for(i=0; i<v.size(); i++){
		cout<<v[i]<<endl;
	}
}

Measured memory_bytes: 30068
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n, m;
    string s;
    cin >> n >> m;
    cin >> s;
    int dp[n+1] = {};
    int prev[n+1] = {};
    for(int i=0;i<=n;++i)
    {
        dp[i] = 1 << 30;
        prev[i] = -1;
    }
    // 0001000
    dp[n] = 0;
    int current = n;
    bool updated = false;
    while(current > 0){
        updated=false;
        for(int j=m;j>0;--j)
        {
            if((current - j) < 0) continue;
            if(s[current-j] == '1') continue;
            if(dp[current-j] > dp[current] + 1)
                dp[current-j] = dp[current] + 1;
                prev[current-j] = j;
                current -= j;
                updated=true;
                break;
        }
        if(!updated) break;
    }

    if(dp[0] == (1<<30))
    {
        cout << "-1" << endl;
    }
    else {
        current = 0;
        while(current != n)
        {
            cout << prev[current];
            current += prev[current];
            if(current != n) {
                cout << " ";
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1488
#include<bits/stdc++.h>
#define U [100005]={}
typedef long long L;using namespace std;map<L,L> path U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;
L D(L a){Z[a]=1;for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){L d=I->first;if(d-P[a]){P[d]=a;E[d]=E[a]+1;C[d]=I->second;D(d);Z[a]+=Z[d];!H[a]|Z[H[a]]<Z[d]?H[a]=d:0;}}}
L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}
L M(L i){return i?B[i]+M(i-(i&-i)):0;}
L S(L i,L x){for(x=G(x)-M(i+1)+M(i++);i<100005;B[i]+=x,i+=i&-i);}
main(){for(cin>>n>>k;p<n-1;p++)cin>>a>>b>>c,path[a][b]=path[b][a]=c;for(D(c=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;a=H[a])O[a]=c++,X[a]=p,S(O[a],H[a]);for(cin>>a;cin>>s>>a>>b;)if(*s&2){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}else A[a]+=b,S(O[a],H[a]),a?S(O[a]-1,a):0;}

Measured memory_bytes: 31984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  
  vector<int> W(N);
  for (int j = 0; j < N; j++)
    W.at(j) = V.at(j);
  
  sort(W.begin(),W.end());
  int count = 0;
  
  for (int k = 0; k < N; k++) {
    if (W.at(k) != V.at(k))
      count++;
  }
  if (count <= 2) 
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
}

Measured memory_bytes: 3604
from sys import stdin
mod = 10**9+7
N,K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
def count_inversion(sequence):
    r = [0]*len(sequence)
    l = [0]*len(sequence)
    for i in range(1,len(sequence),1):
        cnt_r = 0
        cnt_l = 0
        for j in range(i,len(sequence),1):
            if sequence[i-1] > sequence[j]:
                cnt_r += 1
            elif sequence[i-1] < sequence[j]:
                cnt_l += 1
        r[i-1] = cnt_r
        l[i-1] = cnt_l
    return sum(r),sum(l)
r,l = count_inversion(A)
ans = ((K*(K+1))//2)*r
ans += (((K*(K-1))//2))*l
ans = ans%mod
print(ans)


Measured memory_bytes: 41708
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iomanip>
#include <algorithm>

using namespace std;
using ll = long long;

int main(void){
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    for(int i=0;i<X;i++){
        cin >> A[i];
    }
    for(int i=0;i<Y;i++){
        cin >> B[i];
    }
    for(int i=0;i<Z;i++){
        cin >> C[i];
    }

    vector<ll> AB(X*Y);
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            AB[i + j*X] = A[i] + B[j];
        }
    }
    sort(AB.begin(), AB.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());

    vector<ll> tot(K*K);

    for(int i=0;i<min(X*Y, K);i++){
        for(int j=0;j<Z;j++){
            tot[i + j*min(X*Y,K)] = AB[i] + C[j];
        }
    }

    sort(tot.begin(), tot.end(), greater<ll>());

    for(int i=0;i<K;i++){
        cout << tot[i] << endl;
    }

    return 0;
}

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

string FB(int n){
    if(n%3==0&&n%5==0)return "FizzBuzz";
    if(n%3==0)return "Fizz";
    if(n%5==0)return "Buzz";
    stringstream ss;
    ss<<n;
    return ss.str();
}

int m,n;

void solve(){
    vector<int>rem(m);
    for(int i=0;i<m;i++)rem[i]=i+1;

    int c=0;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        if(rem.size()==1)continue;
        if(s!=FB(i)){
            rem.erase(remove(rem.begin(),rem.end(),rem[c]),rem.end());
            c%=rem.size();
        }
        else{
            c=(c+1)%rem.size();
        }
    }

    for(int i=0;i<rem.size();i++){
        cout<<(i?" ":"")<<rem[i];
    }
    cout<<endl;
}

int main(){
    while(cin>>m>>n,m||n)solve();
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
 
#define int long long
#define MOD 1000000007
 
using namespace std;
 
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class T> ostream &operator<<(ostream &os, multiset<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}


void solve() {
    int n;
    cin >> n;
    int a[n][2];
    for(int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1];
    }

    int count = 0;
    for(int i = 0; i < n; i++) {
        if(a[i][0] == a[i][1]) {
            count++;
        }
        else {
            count = 0;
        }
        if(count == 3) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
    
}


int32_t main() {
    int t;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << n * (n - 1) / 2 - n / 2 << '\n';
    fr1(n) for (int j = 1; j < i; j++) if (i + j != n / 2 * 2 + 1) cout << j << ' ' << i << '\n';
}


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

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

    int res = 0;
    for(int i=0; i<4; i++) {
        if(S[i] == '+') res++;
        else res--;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

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

map <int, int> M;

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int a;		cin >> a;
		M[a] = i+1;
	}
	for (int i = 0; i < N; i++) cout << M.find(i+1)->second << " ";
	return 0;
}

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

int n, t, a, x;
int h[1000];

int main() {
  int res = 0;
  int min_diff = 1<<30;
  cin >> n >> t >> a;
  for (int i = 0; i < n; i++) {
    cin >> x;
    int diff = (t * 1000 - x * 6) - a * 1000;
    if (diff < 0) diff = -diff;
    if (diff < min_diff) {
      res = i;
      min_diff = diff;
    }
  }
  cout << res + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N, K = map(int, input().split())
a = list(map(int, input().split()))

dp = [False]*(K+1)

dp[0] = False
for i in range(1, K+1):
    flag = False
    for e in a:
        if e <= i:
            flag = flag or (not dp[i-e])
    dp[i] = flag
if dp[K]:
    print("First")
else:
    print("Second")


Measured memory_bytes: 41964
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, A: "List[int]"):
    A = [0] + A + [0]

    forward = [0]
    curr = 0
    for i in range(N+1):
        forward.append(forward[-1] + abs(curr-A[i+1]))
        curr = A[i+1]

    backward = [0]
    curr = 0
    for i in range(N+1):
        backward.append(backward[-1] + abs(curr-A[N-i]))
        curr = A[N-i]
    backward = backward[::-1]

    buf = []
    for i in range(1, N+1):
        print(forward[i-1] + backward[i+1] + abs(A[i-1] - A[i+1]))

    # print(forward)
    # print(backward)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25404
#dict.rb
dict=Hash.new
n=STDIN.gets.split[0].to_i
n.times {
line=STDIN.gets.split
order=line[0]
arg  =line[1]
if order=="insert" then
  dict[arg]=1
elsif order=="find" 
  if dict[arg]==1
    puts "yes"
  else
    puts "no"
  end
end
}

Measured memory_bytes: 48768
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a, b = inpm()
tmp = a
if(b == 1):
    print(0)
else:
    ans = 1
    while(b > tmp):
        tmp += a - 1
        ans += 1
    print(ans)

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int s;
    std::cin >> s;

    auto func = [](const int& n) -> int {
                    return (n % 2 == 0) ? n / 2 : 3 * n + 1;
                };

    vector<int> a{s};
    set<int>    a_set{s};
    while(true) {
        auto n = func(a.back());
        a.emplace_back(n);
        if(a_set.find(n) == a_set.end()) {
            a_set.insert(n);
        }
        else {
            break;
        }
    }

    std::cout << a.size() << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long MIN(long long a,long long b){return a<b?a:b;}
long long MAX(long long a,long long b){return a<b?b:a;}
int ta[1010],to[1000010],nt[1000010],co[1000010],F[1010];
long long MF(int s,int t,int e,int min){
  if(s==t||min==0)return min;
  long long i,r;
  F[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(F[to[i]])continue;
    r=MF(to[i],t,e,MIN(min,co[i]));
    co[i]-=r;
    co[(i+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
//呼び出す方
//sからtへの最大流を求める　ノード数v辺の数e　aからbへキャパcのフローが流れる
long long maxf(int s,int t,int v,int e,int *a,int *b,int *c){
  long long i,f,r;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    co[ta[a[i]]=i  ]=c[i];
    co[ta[b[i]]=i+e]=0;
  }
  for(f=0;r=MF(s,t,e,1000000000);f+=r){
    for(i=0;i<v;i++)F[i]=0;
  }
  return f;
}
int main(){
  int n,a[100010],b[100010],c[100010],d[100010],r=0,i,j;
  long long s=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  for(i=1;i<=n;i++){
    a[r]=0;
    b[r]=i;
    c[r++]=MAX(0,d[i-1]);
    s+=c[r-1];
    a[r]=i;
    b[r]=n+1;
    c[r++]=MAX(0,-d[i-1]);
    for(j=i-1;j;j--){
      if(i%j==0){
	a[r]=i;
	b[r]=j;
	c[r++]=1e9;
      }
    }
  }//printf("%d\n",s);
  printf("%lld\n",s-maxf(0,n+1,n+2,r,a,b,c));
  return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int N,X;
  cin >> N;
  int ans = 10000000;

  map<int,int>m;
  for (int i = 0; i < N; i++) {
    cin >> X;
    m[X] += 1;
  }

  for (int i = 1; i <= 100; i++) {
    int sum = 0;
    for(auto j = m.begin(); j != m.end(); j++) {
      sum += (i - j->first)*(i - j->first)*j->second;
    }
    ans = min(ans, sum);
  }


  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 3 * 1e5 + 5;
const ll mod = 998244353;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;    
    int n, q;
    cin >> n >> q;
    int occ[n + 1];
    cls(occ, 0);
    w(q){
        int k;
        cin >> k;
        w(k){
            int x;
            cin >> x;
            occ[x] = 1;
        }
    }
    int ans = 0;
    fore(i, 1, n + 1)
        if(!occ[i])
            ans++;
    cout << ans << "\n";
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

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

int main() {
    int H, W;
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int i = 1; i <= H; i++){
            for (int j = 1; j <= W; j++){
                if (i % 2){
                    if (j % 2 == 0) cout << ".";
                    else cout << "#";
                }
                else {
                    if (j % 2 == 0) cout << "#";
                    else cout << ".";
                }
            }
            cout << "\n";
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 3096
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		
		PriorityQueue<Edge> que = new PriorityQueue<>((a, b) -> a.w- b.w);
		for(int i=0; i<n; i++) {
			for(int j=0; j<n; j++) {
				int w = sc.nextInt();
				if(i < j && w != -1) {
					que.add(new Edge(w, i, j));
				}
			}
		}
		
		Node[] V = new Node[n];
		for(int i=0; i<n; i++) {
			V[i] = new Node(i);
		}
		
		int sum = 0;
		while(!que.isEmpty()) {
			Edge edge = que.poll();
			int parent_1 = V[edge.a1].findParent(V);
			int parent_2 = V[edge.a2].findParent(V);
			if(parent_1 != parent_2) {
				V[parent_2].parent = parent_1;
				sum += edge.w;
//				System.out.println(edge.a1 + " " + edge.a2 + " " + edge.w);
			}
		}
		
		System.out.println(sum);
	}
	
	static class Node {
		int id;
		int parent = -1;
		
		Node(int id) {
			this.id = id;
		}
		
		public int findParent(Node[] V) {
			if(parent == -1) {
				return id;
			} else {
				parent = V[parent].findParent(V);
				return parent;
			}
		}
	}
	
	static class Edge {
		int w;
		int a1;
		int a2;
		
		Edge(int w, int a1, int a2) {
			this.w = w;
			this.a1 = a1;
			this.a2 = a2;
		}
	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}

}

Measured memory_bytes: 32068
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

typedef struct {
	vector<int> edge;
	ll a = 0, lc = 0, q = 0;
	bool vi = false;
}node_t;
vector<node_t> node;

void dfs(int p) {
	int N = node.size();
	vector<ll> dp(N + 1, 1e10);
	stack<int> st;
	st.push(p);
	dp[0] = node[p].a, node[p].vi = true;
	stack<pair<int, ll>> re;
	re.push(make_pair(p, 1e10));
	while (!st.empty()) {
		int x = st.top();
		node[x].vi = true;
		st.pop();
		int left = 0, right = N;
		while (left < right) {
			int mid = (left + right) / 2;
			if (node[x].a <= dp[mid]) right = mid;
			else left = mid + 1;
		}
		re.push(make_pair(x, dp[left]));
		dp[left] = node[x].a;
		node[x].lc = left;
		node[x].q = lower_bound(dp.begin(), dp.end(), 1e10) - dp.begin();
		bool con = false;
		for (auto to : node[x].edge) {
			if (node[to].vi)continue;
			con = true;
			st.push(to);	
		}

		if (!con) {
			bool T = true;
			while (!re.empty() && T) {
				int po = re.top().first;
				ll A = re.top().second;
				for (auto to : node[po].edge) {
					if (!node[to].vi) {
						T = false;
						break;
					}
				}
				if (T) {
					dp[node[po].lc] = A;
					re.pop();
				}
			}
		}

	}
}

int main() {
	int N; cin >> N;
	node = vector<node_t>(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> node[i].a;
	}
	for (int i = 0; i < N - 1; i++) {
		int u, v; cin >> u >> v;
		node[u].edge.push_back(v);
		node[v].edge.push_back(u);
	}
	dfs(1);
	for (int i = 1; i <= N; i++) {
		cout << node[i].q << endl;
	}
}



Measured memory_bytes: 24740
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdbool.h>
using namespace std;
typedef long long ll;
ll a[110][110];
ll input[10010];
int main(void) {
	ll h, w, n, count = 0;
	cin >> h >> w >> n;
	for (ll i = 1;i <= n;i++) {
		cin >> input[i];
		count += input[i];
	}
	ll x = 1, y = 1;
	while (count!=0) {
		for (ll i = 1;i <= n;i++) {
			for (ll j = 1;j <= input[i];j++) {
				a[x][y] = i;
				count--;
				if (x % 2 == 0) {
					if (y == 1) {
						x++;
					}
					else y--;
				}
				else {
					if (y == w) {
						x++;
					}
					else y++;
				}
			}
		}
	}
	for (ll i = 1;i <= h;i++) {
		for (ll j = 1;j<=w;j++) {
			if (j == w)cout << a[i][j];
			else cout << a[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 512
def Hantei(S):
    res = False
    dream = list("dream")
    dreamer = list("dreamer")
    erase = list("erase")
    eraser = list("eraser")

    flg = 0
    if S[-1] == dream[-1]:
        flg = 1
    elif S[-1] == dreamer[-1] and S[-2] == dreamer[-2] and S[-3] == dreamer[-3]:
        flg = 2
    elif S[-1] == erase[-1]:
        flg = 3
    elif S[-1] == eraser[-1] and S[-2] == eraser[-2] and S[-3] == eraser[-3]:
        flg = 4

    if flg == 1:
        S.pop()
        if S.pop()==dream[-2] and S.pop()==dream[-3] and S.pop()==dream[-4] and S.pop()==dream[-5]:
            res = True
    if flg == 2:
        S.pop()
        S.pop()
        S.pop()
        if S.pop()==dreamer[-4] and S.pop()==dreamer[-5] and S.pop()==dreamer[-6] and S.pop()==dreamer[-7]:
            res = True
    if flg == 3:
        S.pop()
        if S.pop()==erase[-2] and S.pop()==erase[-3] and S.pop()==erase[-4] and S.pop()==erase[-5]:
            res = True
    if flg == 4:
        S.pop()
        S.pop()
        S.pop()
        if S.pop()==eraser[-4] and S.pop()==eraser[-5] and S.pop()==eraser[-6]:
            res = True
            
    return res

S = list(input())
while True:
    if Hantei(S) == False:
        print("NO")
        break
    if len(S) == 0:
        print("YES")
        break

Measured memory_bytes: 4212
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, a, b) for(int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

int main(){
    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;
#define TENS(n) int(1e##n + n)

char a[1002][1002];
LL dp[1002][1002];
LL mod = 1e9 + 7;

struct pos
{
    int x;
    int y;
};

void solve()
{
    int H;
    cin >> H;
    int W;
    cin >> W;

    REP1(i, H)
    {
        REP1(j, W)
        {
            cin >> a[i][j];
        }
    }
    dp[1][1] = 1;

    REP1(y, H)
    {
        REP1(x, W)
        {
            if (a[y - 1][x] == '.')
            {
                dp[y][x] += (dp[y - 1][x] % mod);
                dp[y][x] %= mod;
            }

            if (a[y][x - 1] == '.')
            {
                dp[y][x] += (dp[y][x - 1] % mod);
                dp[y][x] %= mod;
            }
        }
    }

    // queue<pos> Q;
    // Q.push(pos{1, 1});
    // while (Q.size())
    // {
    //     pos now = Q.front();
    //     Q.pop();

    //     if (a[now.y - 1][now.x] == '.')
    //     {
    //         dp[now.y][now.x] += (dp[now.y - 1][now.x] % mod);
    //         dp[now.y][now.x] %= mod;
    //     }

    //     if (a[now.y][now.x - 1] == '.')
    //     {
    //         dp[now.y][now.x] += (dp[now.y][now.x - 1] % mod);
    //         dp[now.y][now.x] %= mod;
    //     }
    //     if (a[now.y + 1][now.x] == '.')
    //         Q.push(pos{now.y + 1, now.x});
    //     if (a[now.y][now.x + 1] == '.')
    //         Q.push(pos{now.y, now.x + 1});
    // }

    cout << dp[H][W] << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 9088
readHon :: Int -> String
readHon n
 | dig1 == 2 || dig1 == 4 || dig1 == 5 || dig1 == 7 || dig1 == 9  = "hon"
 | dig1 == 0 || dig1 == 1 || dig1 == 6 || dig1 == 8               = "pon"
 | dig1 == 3                                                      = "bon"
 where dig1 = n `mod` 10

main = do
    n <- read <$> getLine
    putStrLn $ readHon n

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 ans = 0;
    for (i64 i = 0; i < 5; i++) {
        i64 x;
        cin >> x;
        if (x == 0) ans = i;
    }
    cout << ans + 1 << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int A, B, T;
    cin >> A >> B >> T;
    ll sum = 0;
    FOR(i, T + 1, 1)
    {
        if (i % A == 0)
            sum += B;
    }
    cout << sum << endl;
    return 0;
}

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

// セグメント木
struct SegmentTree {
private:
    int n;
    vector<ll> node;
	ll ininum; // 初期値。区間sumなら0、区間minならINFなど
	function<ll(ll,ll)> f; // sum,minなどの演算を設定

public:
    SegmentTree(vector<ll> v, ll ininum, function<ll(ll,ll)> f) {
    	this->ininum = ininum;
    	this->f = f;
    	
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = f(node[2*i+1], node[2*i+2]);
    }

    void update(int x, ll val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = f(node[2*x+1], node[2*x+2]);
        }
    }

    ll get(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return ininum;
        if(a <= l && r <= b) return node[k];

        ll vl = get(a, b, 2*k+1, l, (l+r)/2);
        ll vr = get(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};


int main(){
	
	int n;
	cin >> n;
	vector<ll> h(n), a(n);
	rep(i,n){
		cin >> h[i];
		h[i]--;
	}
	rep(i,n) cin >> a[i];
	vector<ll> dp(n);
	SegmentTree seg(dp, 0, [&](ll a, ll b){return max(a,b);});

	rep(i,n){
		dp[h[i]] = a[i] + seg.get(0,h[i]);
		seg.update(h[i], dp[h[i]]);
	}
	
	ll res = 0;
	rep(i,n) res = max( res, dp[i] );
	
	cout << res << endl;
	return 0;
}

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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int k[10], s[10][10];
	for (int i = 0; i < M; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	int p[10];
	for (int i = 0; i < M; i++) {
		cin >> p[i];
	}
	int ans = 0;
	for (int i = 0; i < (1 << N); i++) {
		bool flag = true;
		for (int j = 0; j < M; j++) {
			int c = 0;
			for (int l = 0; l < k[j]; l++) {
				if ((i >> s[j][l]) & 1)c++;
			}
			if (c % 2 != p[j])flag = false;
		}
		if (flag)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define slowanddetermined ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x); cout<<#x<<"="<<x<<endl;
#define debug2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long
using namespace std;


int fun(int n,int x){
    if(x==1) return 0;
    while(n%x==0){
        n/=x;
    }
    n=n%x;
    return n==1;
}

int32_t main()
{
  

    int n;
    cin>>n;
    set<int>st;
    for(int i=2;i*i<=(n-1);i++){
        if((n-1)%i==0){
            st.insert(i);
            st.insert((n-1)/i);
        }
    }
    st.insert(n-1);
   
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            if(fun(n,i))st.insert(i);
            if(fun(n,n/i))st.insert(n/i);
        }
    }
    //c++;
     st.erase(1);
     cout<<st.size();


    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
  
using namespace std;
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
 
//Appropriately Changed
using edge=struct{int to,cost;};
using G=vector<vector<edge>>;
 
//Appropriately Changed
void add_edge(G &graph,int from,int to,int cost){ 
    graph[from].push_back({to,cost});
}
 
auto chu_liu(const G &graph,int root){
    using W=int; const W inf=1<<28;
    const int n=graph.size();

    vector<int> cost(n,inf),pv(n,-1);
    rep(v,n) for(auto &e:graph[v]) if(chmin(cost[e.to],e.cost)) pv[e.to]=v;
 	
    int led=-1,unuse=-1;
    vector<int> comp(n),used(n,-1);
    iota(begin(comp),end(comp),0);

    rep(v,n)if(used[v]== -1 and pv[v]!=-1 and v!=root){
        int cur=used[v]=v;
        for(cur=pv[cur]; cur!=root && used[cur] == -1; cur=pv[cur]) used[cur]=v;
 
        if(used[cur]!=v) continue;
    	led=cur,comp[cur]=cur,v=n; 
    	for(int w=pv[cur]; w != cur; w=pv[w]) comp[w]=cur;
    }
 
    G ngraph(n),ret(n);
    using E=tuple<int,int,int>; map<E,E> dict;

    if(led==-1){
      	rep(v,n) if(v!=root and pv[v]!=-1)add_edge(ret,pv[v],v,cost[v]);
      	return ret;
    }else{
		rep(v,n) for(auto &e:graph[v]){
			int a=comp[v],b=comp[e.to],c=e.cost;
			if(comp[e.to]==led) c-=cost[e.to];
			if(a==b) continue;
			dict[E(a,b,c)]=E(v,e.to,e.cost);
			add_edge(ngraph,a,b,c);
		}
		
		auto ntree=chu_liu(ngraph,comp[root]);

		rep(v,n) for(auto &e:ntree[v]){
			int a,b,c;
			tie(a,b,c)=dict[E(v,e.to,e.cost)];
			if(comp[b]==led) unuse=b;
			add_edge(ret,a,b,c);
		}

		rep(v,n) if(comp[v]==led and v!=unuse) add_edge(ret,pv[v],v,cost[v]);
	}
    return ret;
}

int main(void){
    int v,e,r;
    cin >> v >> e >> r;
    G graph(v);
    rep(i,e){
        int a,b,w;
        cin >> a >> b >> w;
        add_edge(graph,a,b,w);
    }
 
    auto tree=chu_liu(graph,r);
    int ans=0;
    rep(i,v) for(auto &e:tree[i]) ans+=e.cost;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4980
using System;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            
            int n = int.Parse(Console.ReadLine());
            int[] h = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            long[] dp = new long[n];
            dp[0] = 0;
            for (int i = 1; i < n; i++)
            {
                dp[i] = long.MaxValue;
                changeMin(ref dp[i], dp[i - 1] + Math.Abs(h[i] - h[i - 1]));
                if (i > 1) changeMin(ref dp[i], dp[i - 2] + Math.Abs(h[i] - h[i - 2]));
            }

            Console.WriteLine(dp[n - 1]);
        }

        static bool changeMin(ref long a, long b)
        {
            if (a > b)
            {
                a = b;
                return true;
            }
            return false;
        }

    }
}


Measured memory_bytes: 17248
import sys, math
from collections import deque

readline = sys.stdin.readline

S = readline().rstrip()

counts = [0] * len(S)

down = 0
up = 0
state = 0
g = -1

for i, c in enumerate(S):
    if state == 0:
        if c == 'R':
            down += 1
        else:
            g = i - 1
            counts[i - 1] += down // 2 + (down % 2)
            counts[i] += down // 2
            state = 1

    if state == 1:
        if c == 'L':
            if (i - g) % 2 == 0:
                counts[g] += 1
            else:
                counts[g + 1] += 1
        else:
            state = 0
            down = 1

print(' '.join(map(str, counts)))

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

using ll = long long int;

int n;
ll m;

ll ans;

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &m);

  for (ll i = 1; i * i <= m; ++i) {
    if (m % i != 0) continue;

    if (m / i >= n) ans = max(ans, i);
    if (i >= n) ans = max(ans, m / i);
  }

  printf("%lld\n", ans);

  return 0;
}


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

int main(){
	ll mod=1e9+7;

ll n;
cin>>n;
vector<ll> a(n);
ll s=0;
for(int i=0;i<n;i++){
cin>>a[i];
s+=a[i];
}
ll c=0;
for(int i=0;i<n-1;i++){
s-=a[i];
	c+=((s%mod)*(a[i]%mod))%mod;
	c=c%mod;
	
}	
	
cout<<c;

 
}

Measured memory_bytes: 4744