akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n;
    cin >> n;

    int a;
    int prev;
    enum {
        FLAT = 0,
        UP   = 1,
        DOWN = 2
    };
    int status = FLAT;
    cin >> prev;

    int ans = 0;
    rep (i, n - 1)
    {
        cin >> a;
        if (status == FLAT)
        {
            if (a > prev) { status = UP; ++ans; }
            else if (a == prev) status = FLAT;
            else { status = DOWN; ++ans; }
        }
        else
        {
            if (a > prev && status == DOWN) status = FLAT;
            else if (a < prev && status == UP) status = FLAT;
        }
        prev = a;
    }

    if (status == FLAT) ++ans;
    cout << ans << "\n";
    return 0;
}



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


def solve(A: int, B: int):
    if (1 <= A <= 9) and (1 <= B <= 9):
        print(A*B)
    else:
        print(-1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    for (auto& i : a) cin >> i;
    sort(a.rbegin(), a.rend());
    int l = 0, r = 0;
    for (int i : a) {
        if (l < r) l += i;
        else r += i;
    }
    cout << max(0, abs(l - r) - 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  int tmp=n;
  int sum=0;
  while(tmp!=0){
    sum+=tmp%10;
    tmp/=10;
  }
  string ans="No";
  if(n%sum==0)ans="Yes";
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}
int main() {
	string s;
	cin >> s;
	int c = s.size();
	if (c % 2 == 1)
		cout << "No" << endl;
	else {
		sort(s.begin(), s.end());
		for (int i = 0; i < c / 2; i+=2) {
			if (s[i] != s[i + 1]) {
				cout << "No" << endl;
				c = 0;
			}
		}
		if (c != 0)
			cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,m;cin>>n>>m;
	vector<int> a(n,0);
	for(int i = 0; i < m; i++) {
		int x,y;cin>>x>>y;
		a[x- 1]++;
		a[y - 1]++;
	}
	for(int i = 0; i < n; i++) {
		if (a[i] % 2 == 1){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define FOR(i,from,to) for(i=(from);i<(to);i++)

const int NMAX = 100005;

int cluc_dist(int x, int xx) {
	int dx = xx - x;
	if (dx < 0) dx *= -1;
	return dx;
}

int main() {
	int i, j, k, l;
	int N; cin >> N;
	int t = 0, x = 0, y = 0;
	int dt, dx, dy,dist, tt, xx, yy;
	FOR(i, 1, N + 1) {
		cin >> tt >> xx >> yy;
		dt = tt - t;
		dx = cluc_dist(x, xx);
		dy = cluc_dist(y, yy);
		dist = dx + dy;

		if (dt < dist || dt % 2 != dist % 2) {
			cout << "No" << endl;
			return 0;
		}

		t = tt;
		x = xx;
		y = yy;
	}
	cout << "Yes" << endl;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());
 
signed main()
{
    gearup;
    ll k; cin >> k;
    ll num = 7 % k;
    set<ll> s;
    ll cnt = 1;
    for(int i=1;i<=k;i++){
        if(num == 0){
            out(i);
            return 0;
        }
        num = (num * 10 + 7) % k;
    }
    out(-1);
}

Measured memory_bytes: 3628
#include<stdio.h>
#define N 1000000

int A[N],n;

int binarysearch(int key) {

  int left=0,right=n,mid;
  
  while(left < right) {
    mid = (left+right) / 2;
    if(key == A[mid])
      return 1;
    if(key > A[mid] )
      left = mid + 1;
    else if(key < A[mid])
      right = mid;
  }
  return 0;
}

int main(void) {

  int i,p,k,cnt=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  
  scanf("%d",&p);
  for(i=0;i<p;i++) { 
    scanf("%d",&k);
 if(binarysearch(k))
   cnt++;
  }
  printf("%d\n",cnt);
  
  return 0;
}

Measured memory_bytes: 988
N = int(input())
A,B = map(int,input().split())
P = list(map(int,input().split()))

one = []
two = []
three = []

for i in range(N):
    if P[i] <= A:
        one.append(P[i])
    elif P[i] <=B:
        two.append(P[i])
    elif P[i] > B:
        three.append(P[i])

print(min([len(one),len(two),len(three)]))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int L, R;
Int used[100][2][2][2], mem[100][2][2][2];
Int dfs(Int num, Int isZero, Int sameL, Int sameR){
  if(num < 0) return !isZero;
  if(used[num][isZero][sameL][sameR]++) return mem[num][isZero][sameL][sameR];
  Int a = 0, b = 0, c = 0;
  //y=1, x=1
  if(!sameR || (R>>num&1) == 1){
    Int nsameL = sameL && (L>>num&1) != 0;
    Int nsameR = sameR;
    a = dfs(num - 1, 0, nsameL, nsameR);
  }
  //y=1, x=0
  if(!isZero && (!sameL || (L>>num&1) == 0) && (!sameR || (R>>num&1) == 1)){
    Int nsameL = sameL;
    Int nsameR = sameR;
    b = dfs(num - 1, 0, nsameL, nsameR);
  }

  //y=0, x=0
  if((!sameL || (L>>num&1) == 0)){
    Int nsameL = sameL;
    Int nsameR = sameR && (R>>num&1) != 1;
    c = dfs(num - 1, isZero, nsameL, nsameR);
  }
  Int res = (a + b + c)%mod;
  return mem[num][isZero][sameL][sameR] = res;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>L>>R;

  Int ans = dfs(60, 1, 1, 1);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxs 2202002
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;
vector<int> vec[maxs];
int n,m;

bool dfs(int u,int p,int k){
    if(!k && u == n){
        return 1;
    }
    if(!k)
        return 0;
    int id,sz =vec[u].size();
    for(int i=0;i<sz;i++){
        id = vec[u][i];
        if(id == p) continue;
        if(dfs(id,u,k-1)) return 1;
    }
    return 0;
}


int main()
{

    while(~scanf("%d%d",&n,&m)){
        int u,v;
        for(int i=1;i<=m;i++){
            scanf("%d%d",&u,&v);
            vec[u].push_back(v);
            vec[v].push_back(u);
        }
        if(dfs(1,0,2)) puts("POSSIBLE");
        else           puts("IMPOSSIBLE");
    }
    return 0;
}

Measured memory_bytes: 58864
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
ll mx(ll a,ll b){if(a>=b) return a;return b;}
ll mn(ll a,ll b){if(a<b) return a;return b;}
#define pb push_back
#define mp make_pair
#define endl "\n"
#define INF (ll) (3e18)
ll dp[3005][3005];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    vi v;
    ll n,x;cin>>n;
    for(ll i=0;i<n;i++)
        cin>>x,v.pb(x);
    for(ll i=n-1;i>=0;i--)
        for(ll j=i;j<n;j++){
            if(i==j)
                dp[i][j]=v[i];
            else
                dp[i][j]=mx(v[i]-dp[i+1][j],v[j]-dp[i][j-1]);
        }
    cout<<dp[0][n-1]<<endl;
    return 0;
}





Measured memory_bytes: 70144
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<stack>
#include<cstdio>
#include<vector>
#include<algorithm>
#define maxn 23456
//#include <bits/stdc++.h>

using namespace std;

#define ll  long long

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll c;
	cin >> n >> c;
	vector<ll> x(n + 1, 0);
	vector<ll> v(n + 1, 0);
	ll vallsum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> x[i] >> v[i];
		vallsum += v[i];
	}

	ll vrsum = 0, vlsum = 0, ans = 0;
	vector<ll> dpl(n + 1, 0);
	vector<ll> dpr(n + 1, 0);
	for (int i = n - 1; i >= 1; i--) {
		vlsum += v[i + 1];
		dpl[i] = max(dpl[i + 1], vlsum - (c - x[i + 1]) * 2);
	}
	for (int i = 1; i < n; i++){
		vrsum += v[i];
		dpr[i+1] = max(dpr[i], vrsum - x[i] * 2);
	}
	vrsum = 0;
	for (int i = 1; i <= n; i++) {
		vlsum = vallsum - vrsum;
		vrsum += v[i];
		ans = max(ans, vrsum - x[i] + dpl[i]);
		ans = max(ans, vlsum - (c - x[i]) + dpr[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
#import numpy as np
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())

H, W = map(int, input().split())

if H== 1 or W == 1 :
  print (1)
  exit()

if (H*W)%2 == 1 :
  print ((H*W)//2 + 1)
else :
  print ((H*W)//2)






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

using namespace std;

int main()
{
    string s;
    cin>>s;
    string t;
    cin>>t;
     int n= s.size();
     int temp=0;
     for(int i=0;i<n;i++){
    if(s[i]!=t[i]){
        temp=1;
    }
}
   if(temp==1){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }

return 0;
}


Measured memory_bytes: 3564
N = int(input())
ls = []
dp = [[0]*(N+1) for i in range(3)]
for i in range(N):
  a, b, c = map(int, input().split())
  dp[0][i+1] = max(dp[1][i], dp[2][i]) + a
  dp[1][i+1] = max(dp[2][i], dp[0][i]) + b
  dp[2][i+1] = max(dp[0][i], dp[1][i]) + c
print(max(dp[0][N], dp[1][N], dp[2][N]))

Measured memory_bytes: 53016
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S / 3600;
		int m = (S % 3600) / 60;
		int s = S % 60;
		System.out.println(h + ":" + m + ":" + s);
		sc.close();
	}

}


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

int main(){
    ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> q(m);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        q[i]=make_pair(b, a);
    }
    sort(q.begin(),q.end());
    ll e=-1;
    ll cnt=0;
    rep(i,m){
        if(q[i].second>e){
            e=q[i].first-1;
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


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

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

#define MAX_N 100000


int main(){
  int n;
  cin >> n;
  int a[n+2];
  a[0] = 0;
  a[n+1] = 0;
  REP(i,n) cin >> a[i+1];

  int b[n+1], c[n];
  ll sum = 0;
  REP(i,n+1){
    b[i] = abs(a[i+1] - a[i]);
    sum += b[i];
    // cout <<  "b " << b[i] << endl;
  }
  REP(i,n){
    c[i] = abs(a[i+2] - a[i]);
    // cout <<  "c " << c[i] << endl;
  }



  REP(i,n){
    cout << sum + c[i] - b[i] - b[i+1] << endl;
  }

  // cout << sum << endl;

  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int_Max 2147483647
#define ll_Max 9223372036854775807
#define REP(i,f,n) for(int i=f; i<(n); i++)

int main()
{
  int ans = 0;
  int n;
  cin >> n;
  int a[n], a2[n];
  REP(i,0,n){
    cin >> a[i];
    a2[i] = -1;
  }
  int next_p = a[0];
  do{
    ans++;
    a2[next_p - 1] = ans;
    next_p = a[next_p - 1];
    if(a2[next_p - 1] != -1)break;
  }while(a2[1]==-1);


  cout << a2[1] << endl;

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

Measured memory_bytes: 4344
import numpy as np
import itertools
n,m,q = list(map(int, input().split()))
abcd = []
for i in range(q):
    abcd.append(list(map(int, input().split())))
abcd = np.array(abcd)
P = np.array(list(itertools.combinations_with_replacement(range(1,m+1),n)))

max_s = 0
for i in P:
    target = (i[abcd[:,1]-1] - i[abcd[:,0]-1] == abcd[:,2])
    val = np.sum(abcd[target,3])
    if max_s < val : max_s = val

print(max_s)

Measured memory_bytes: 46756
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int ans=INF;
    for(int i=1;i+k-1<=n;i++)
    {
        int j=i+k-1;
        if(a[i]>=0) ans=min(ans,a[j]);
        else if(a[j]<=0) ans=min(ans,-a[i]);
        else ans=min(ans,min(a[j]-2*a[i],-a[i]+2*a[j]));
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 640
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

#普通に考えるのであればnC2 * mC2

# 累積和使えばあるx_iを選んだときの横の長さの和(もう１本のx_iとの距離の合計)は分かる
mod = 10**9 + 7
# H = x[-1] - x[0]
# W = y[-1] - y[0]
# S = H*W % mod
# S *= (n-1)*(m-1)
# if n >= 4:
#     h = x[-2] - x[1]
#     S -= h*W * 2
# if m >= 4:
#     w = y[-2] - y[1]
#     S -= H*w * 2
H = 0
W = 0
for i in range(n//2):
    w = x[n-1-i] - x[i]
    if i == n//2 - 1:
        if n % 2 == 1:
            w *= 2
    else:
        w *= n-2*i-1
    W += w
    W %= mod
for j in range(m // 2):
    h = y[m-1-j] - y[j]
    if j == m//2 - 1:
        if m % 2 == 1:
            h *= 2
    else:
        h *= m-1-2*j
    H += h
    H %= mod
S = H*W

print(S % mod)


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

int n,m;
vector <int> par;     //親
vector <int> ran;    //木の深さ

//n要素で初期化
void inti(int n){
    for(int i=0; i<n; i++){
        par.push_back(i);
        ran.push_back(0);
    }
}

//木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(ran[x] < ran[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if(ran[x] == ran[y]) ran[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x) == find(y);
}

void solve(){
    cin >> n >> m;
    inti(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        unite(a,b);
    }
    
    vector <int> group(n);
    rep(i,n){
        int gr = find(i);
        group[gr]++;
    }

    sort(all(group));
    cout << group[n-1] << endl;
}

int main(){
    solve();
}

Measured memory_bytes: 5852
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }

int main(){
    int N,K; cin >> N >> K;
    vector <int> H(N);
    rep(i,N) cin >> H[i];
    
    vector <int> dp(N+K,INF);
    dp[0]=0;
    for (int i=0; i<N; i++){
        for (int j=1; j<=K; j++){
            chmin(dp[i+j],dp[i]+abs(H[i]-H[i+j]));
        }
    }
   
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>pat[202020];
int deg[202020];
bool flag[202020];
int ans = 0;
int dfs(int node)
{
	flag[node] = true;
	int s = 0, c = 0;
	for (int i = 0; i < pat[node].size(); i++)
	{
		if (!flag[pat[node][i]])
		{
			s += dfs(pat[node][i]);
			c++;
		}
	}
	if (c == 0)return 1;
	if (c == 1 && s == 1)return 1;
	else ans += max(0, s - 1);
	return 0;
}
int main()
{
	int num;
	scanf("%d", &num);
	int maxi = 0;
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		pat[za].push_back(zb);
		pat[zb].push_back(za);
		deg[za]++, deg[zb]++;
		maxi = max(maxi, max(deg[za], deg[zb]));
	}
	if (maxi <= 2)
	{
		printf("1\n");
		return 0;
	}
	int r = -1;
	for (int i = 0; i < num; i++)if (deg[i] >= 3)r = i;
	dfs(r);
	printf("%d\n", ans);
}

Measured memory_bytes: 11136
//
//  main.cpp
//  ABC160A
#include <string>
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    string S;
    cin>>S;
    bool ok=true;
    /*
    for (int i=1; i<6; i++) {
        if (S.at(0)==S.at(i)) ok=false;
    }
    for (int i=2;i<6; i++) {
        if(S.at(1)==S.at(i)) ok=false;
    }
     */
    //if(S.at(2)==S.at(4)) ok=false;
    if(S.at(2)!=S.at(3)) ok=false;
    if(S.at(4)!=S.at(5)) ok=false;
    if (ok) {
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll dp[2005][2005];

int main() {
    ll n;
    cin >> n;
    pair<ll, ll> a[n];
    for (ll i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a, a + n, greater<pair<ll, ll>>());
    ll ans = 0;
    for (ll l = 0; l < n; l++) {
        for (ll r = 0; r < n; r++) {
            if (l + r == n) {
                ans = max(ans, dp[l][r]);
                break;
            }
            dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a[l + r].first * abs(a[l + r].second - l));
            dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a[l + r].first * abs(a[l + r].second - (n - 1 - r)));
        }
    }
    cout << ans << endl;
}

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

int N, M, A[1 << 18], dp[1 << 18], mod = 1000000007;
bool used[1 << 18];

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> A[i]; used[A[i]] = true;
	}
	dp[0] = 1;
	for (int i = 1; i <= N; i++) {
		if (used[i] == true) continue;
		if (i >= 1) dp[i] += dp[i - 1];
		if (i >= 2) dp[i] += dp[i - 2];
		dp[i] %= mod;
	}
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int i,j,k;
    long long A,B,C,D,temp,tempC,tempD,answer;
   
    scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
    A--;
    tempC = C;
    tempD = D;
    long long x,tmp,r;
    x = C * D;
    /* 自然数 a > b を確認・入替 */
    if(C<D){
        tmp = C;
        C = D;
        D = tmp;
    }
    /* ユークリッドの互除法 */
    r = C % D;
    while(r!=0){
        C = D;
        D = r;
        r = C % D;
    }
    /* 最小公倍数を出力 */
    x = x/D;
    C = tempC;
    D = tempD;
    
    answer = (B - B/C - B/D + B/x) - (A - A/C - A/D + A/x);
   
    printf("%lld\n",answer);
    return 0;
}

Measured memory_bytes: 128
/**
 * Created by hiramekun at 20:52 on 2019-09-01.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

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

    cout << (n - 1) * n / 2 << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    char X, Y;
    cin >> X; cin >> Y;
    if(X < Y)
        cout << "<" << endl;
    else if(X > Y)
        cout << ">" << endl;
    else
        cout << "=" << endl;
    return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O #-}

import Data.Char
import Control.Monad
import Data.List

main = do
    n <- readLn :: IO Int
    print$ minimum $ map (mk n) [1..(n-1)]
    where
        mk n a = sum $ map digitToInt $ (show a ++ show (n-a))


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

int main() {
    int n;
    cin >> n;
    long long h[n];
    for (int i=0; i<n; ++i) cin >> h[i];
    sort(h,h+n,greater<int>());
    int y=0;
    long long ans = 0;
    for (int i=0; i<n; ++i) {
        ans += max(0LL,h[i]-y);
        if ((i%4>=2||i==0) && h[i]>=y) ans++;
        if (i%4==1) y++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
const int N=201;
int calc(int x,int k){
	if(x<k)	return 0;
	if(x%k==0)	return x/k;
	int d=x/k,u=d*k,h=(x-u)/(d+1);
	if(x-h*(d+1)==u)	return d;
	return calc(x-(h+1)*(d+1),k);
}
int n,ans;
int main(){
	scanf("%d",&n);
	for(int i=1,x,k;i<=n;i++){
		scanf("%d%d",&x,&k);
		ans^=calc(x,k);
	}
	if(ans)	puts("Takahashi");
	else	puts("Aoki");
	return 0;
}


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

int main() {
  string B;
  cin >> B;
  if(B == "A"){
    cout << "T" << endl;
  }
  if(B == "T"){
cout << "A" << endl;
  }
  if(B == "C"){
    cout << "G" << endl;
  }
  if(B == "G"){
    cout << "C" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main(){
	
	string str;
	cin >> str;
	
	for(int i = 0; i < str.size() - 8; i++){
		cout << str[i];
	}
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

import math
def dig(n):
    for i in range(1,12):
        if n<10**i:
            return i

n = inn()
mn = BIG
en = int(math.sqrt(n))+2
for i in range(1,en):
    if n%i==0:
        mn = min(mn,dig(n//i))
print(mn)


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

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)

using ll = int64_t;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const ll inf = 2e18;

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

	int n, k; cin >> n >> k;
	ll h[n], ans[n]; rep(i, 0, n) cin >> h[i];
	ans[0] = 0;
	rep(i, 1, n) {
		ans[i] = inf;
		rep(j, max(0, i - k), i)
				ckmin(ans[i], ans[j] + abs(h[i] - h[j]));
	}
	cout << ans[n - 1];
}

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

int n,m;
double dmax=0,l[21],a[21],b[21];
vector<int> vec;

double pows(int i,int j)
{
  return pow(l[i]-l[j],2)+pow(a[i]-a[j],2)+pow(b[i]-b[j],2);
}

void pow_max(int cou,vector<int> vec)
{
  if(cou==n){
    if(vec.size()==m){
      double def=0;
      for(int i=0;i<vec.size();i++)
	for(int j=i+1;j<vec.size();j++)
	  def+=pows(vec[i],vec[j]);
      dmax=max(dmax,def);
    }
  } else {
    pow_max(cou+1,vec); vec.push_back(cou);
    pow_max(cou+1,vec); vec.pop_back();
  }
}

int main()
{
  cin>>n>>m;
  for(int i=0;i<n;i++)
    cin>>l[i]>>a[i]>>b[i];
  int cou=0;
  pow_max(cou,vec);    
  printf("%.10f\n", dmax);
}


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

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

    char a, b;
    cin >> a >> b;

    bool ans = (b == 'H');
    if(a == 'D')
        ans = !ans;
    
    cout << (ans ? 'H' : 'D') << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
#define ll long long int
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for(i=l;i<r;i++)
#define bep(i,l,r) for(i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
int main()
{
    io;
    ll s;
    cin>>s;
    if(s<=1000000000)
    cout<<0<<" "<<0<<" "<<1<<" "<<0<<" "<<1<<" "<<s;
    else
    {
        ll t=(ll)sqrt(s);
        ll x1,y1,x2,y2,x3,y3;
        if(t==1000000000)
        {
        x1=t;
        y2=t;
        y1=s-t*t+t;
        }
        else if(s-(t+1)*(t+1)+(t+1)>=0)
        {
        x1=t+1;
        y2=t+1;
        y1= s-(t+1)*(t+1)+(t+1);
        }
        else
        {
        x1=t+1;
        y2=t;
        y1=s-t*t;
        }
        y3=0;
        x2=0;
        x3=1;
       // y1=t1;
        cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef double D;
struct P{int x,y;};
const D INF = 1e15;

inline int dot(P a, P b){return a.x*b.x + a.y*b.y;}
inline int cross(P a, P b){return a.x*b.y - a.y*b.x;}
inline int norm(P a){return a.x*a.x + a.y*a.y;}

inline int ccw(P a, P b, P c){
  b.x -= a.x, b.y -= a.y;
  c.x -= a.x, c.y -= a.y;
  if(cross(b,c)>0)    return +1;   //counter clockwise
  if(cross(b,c)<0)    return -1;   //clockwise
  if(dot(b,c)<0)      return +2;   //c--a--b on line
  if(norm(b)<norm(c)) return -2;   //a--b--c on line
  return 0;                        //on segment
}

inline bool is_cp(P a1, P a2, P b1, P b2){
  if(ccw(a1,a2,b1)*ccw(a1,a2,b2)<=0)
    if(ccw(b1,b2,a1)*ccw(b1,b2,a2)<=0)return true;
  return false;
}

inline D dis(P a, P b){
  return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
}

D dijk(const vector<P> &x, P l1, P l2){
  int n = x.size();
  vector<int> use(n,0);
  vector<D> d(n,INF); d[0] = 0;
  rep(i,n){
    int v = -1;
    rep(u,n){
      if(!use[u] && (v<0 || d[v] > d[u]))v = u;
    }
    if(v==1)return d[1];
    use[v] = 1;

    rep(u,n){
      if(v!=u && !is_cp(x[v],x[u],l1,l2)){
	d[u] = min(d[u], d[v] + dis(x[v],x[u]));
      }
    }
  }
  return INF;
}

int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  
  vector<P> a(n),b(m);
  rep(i,n)scanf("%d%d",&a[i].x,&a[i].y);
  rep(i,m)scanf("%d%d",&b[i].x,&b[i].y);

  D res = min(dijk(a,b[0],b[1]) + dis(b[0],b[1]),
	      dijk(b,a[0],a[1]) + dis(a[0],a[1]));
  if(res>=INF)puts("-1");
  else printf("%.12lf\n",res);
}

Measured memory_bytes: 1240
#include<iostream>

int main(void){
    int a, b ,c;
    std::cin >> a >> b >> c;
    
    int count = 0;
    
    for(int i = a; i <= b; i++){
        if(c % i == 0) count++;
    }
    std::cout << count << std::endl;
    return 0;
}


Measured memory_bytes: 3100
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ');
   let ans = 0;
   for(let i = 1; i<=xs[0]; i++){
      ans = ans + i;
   }
   console.log(ans);




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

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

#define loop(i, x, y) for (i = x; i < y; i++)
#define loopr(i, x, y) for (i = x; i > y; i--)

//use *it instead of it
#define vloop(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define vloopr(it, x) for (auto it = x.end() - 1; it != x.begin() - 1; it--)

#define yes printf("YES\n")
#define no printf("NO\n")
#define pb push_back
#define mp make_pair

#define debug(x) cerr << #x << ":" << x << endl
#define yo cerr << "yo" << endl

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;

#define test(t) \
    ll t;       \
    cin >> t;   \
    while (t--)

//use double
#define precision(x)       \
    cout.setf(ios::fixed); \
    cout << setprecision(10) << x << endl;

// ll gcd(ll x_f, ll y_f)
// {
//     if (x_f == 0)
//         return y_f;
//     return gcd(y_f % x_f, x_f);
// }

// ll power(ll x_f, ll y_f, ll m_f)
// {
//     ll res_f = 1;

//     x_f = x_f% m_f;
//     while (y_f)
//     {
//         if (y_f & 1)
//             res_f = (res_f * x_f) % m_f;
//         y_f = y_f >> 1;
//         x_f = (x_f * x_f) % m_f;
//     }
//     return res_f;
// }

// ll less(ll x_f, ll y_f)
// {
//     return (x_f > y_f) ? y_f : x_f;
// }
// ll more(ll x_f, ll y_f)
// {
//     return (x_f < y_f) ? y_f : x_f;
// }

ll fac(ll x_f)
{
    ll fac_f = 1;
    for (ll i = 1; i <= x_f; i++)
    {
        fac_f *= i;
        fac_f = fac_f % MOD;
    }
    return fac_f;
}

bool composite[1000007] = {false};
void seive(ll x)
{
    composite[0] = true;
    composite[1] = true;
    for (ll i = 2; i <= x; i++)
    {
        if (!composite[i])
        {
            for (ll j = 2 * i; j <= x; j += i)
            {
                composite[j] = true;
            }
        }
    }
}

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

    string s, t;
    cin >> s >> t;
    ll n, m;
    n = s.length();
    m = t.length();
    ll ans = m;
    for (ll i = 0; i <= n - m; i++)
    {
        ll diff = 0;
        for (ll j = 0; j < m; j++)
        {
            if (s[j + i] != t[j])
                diff++;
        }
        ans = min(ans, diff);
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
 int a,b;
 cin >>a >> b;
 int d = max(a+b,a-b);
 int ans = max(d,a*b);
 cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ALL(x) x.begin(),x.end()
const ll MOD=1000000007;
const long double PI=3.14159265358979;

int main(){
  ll N,sum=0;
  cin>>N;
  vector<ll> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
    sum+=a[i];
  }
  sort(ALL(a));
  ll d=0;
  while(sum%10==0){
    if(a[d]%10!=0){
      sum-=a[d];
    }
    d++;
    if(d==N){
      sum=0;
      break;
    }
  }
  cout<<sum;
}

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

constexpr int INF = 1 << 30;

void solve() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> ds(n), cs(m);
    for (auto& d : ds) std::cin >> d;
    for (auto& c : cs) std::cin >> c;

    std::vector<int> ans(n + 1, INF);
    ans[0] = 0;
    for (auto c : cs) {
        for (int i = n - 1; i >= 0; --i) {
            ans[i + 1] = std::min(ans[i + 1], ans[i] + c * ds[i]);
        }
    }

    std::cout << ans[n] << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int N = 200000;
const int oo = 0x3f3f3f3f;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n;
int a[N + 5], p[N + 5];

pii solve(int cur) {
    if(cur == n-1) {
        return p[cur] < p[cur + 1] ? pii(0, cur) : pii(1, cur + 1);
    }

    pii tmp = solve(cur + 1);

    if(!tmp.fst) {
        return p[cur] < p[tmp.snd] ? pii(0, cur) : pii(1, tmp.snd);
    }else {
        int f = tmp.snd;
        if((p[f] < p[cur] && p[cur] < p[cur + 1])
        || (p[cur] < p[cur+1] && p[cur+1] < p[f])
        || (p[cur + 1] < p[f] && p[f] < p[cur])) return tmp;

        return pii(tmp.fst + 1, cur + 1);
    }
}

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif 

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i), p[a[i]] = i;
    
    if(n == 1) return puts("0"), 0;
    printf("%d\n", solve(1).fst);

    return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <stdlib.h>

typedef struct queue{
    int *a;
    int length, size, head;
}queue;

queue *init(){
    queue *que = (queue *)malloc(sizeof(queue));
    que->length = 1;
    que->size = 0;
    que->head = 0;
    que->a = (int *)malloc(sizeof(int));
    return que;
}

int get(queue *que, int i){
    return que->a[(que->head + i) % que->length];
}

void set(queue *que, int i, int x){
    que->a[(que->head + i) % que->length] = x;
}

void resize(queue *que){
    int *b = (int *)malloc(sizeof(int) * (que->size == 0 ? 1 : que->size * 2));
    for(int i=0; i<que->size; ++i) b[i] = que->a[(que->head + i) % que->length];
    free(que->a);
    que->a = b;
    que->length = (que->size == 0 ? 1 : que->size * 2);
    que->head = 0;
}

void insert(queue *que, int i, int x){
    if(que->size == que->length) resize(que);
    if(i + 1 < que->size - i){
        for(int k=0; k<=i; ++k){
            int s = (que->head + k - 1 + que->length) % que->length;
            int t = (s + 1) % que->length;
            que->a[s] = que->a[t];
        }
        set(que, i, x);
        que->head = (que->head - 1 + que->length) % que->length;
    }
    else{
        for(int k=que->size-1; k>=i; --k){
            int s = (que->head + k) % que->length;
            int t = (s + 1) % que->length;
            que->a[t] = que->a[s];
        }
        set(que, i, x);
    }
    ++que->size;
}

void erase(queue *que, int i){
    if(i < que->size - i - 1){
        for(int k=i-1; k>=0; --i){
            int s = (que->head + k + que->length) % que->length;
            int t = (s + 1) % que->length;
            que->a[t] = que->a[s];
        }
        que->head = (que->head + 1) % que->length;
    }
    else{
        for(int k=i+1; k<que->size; ++k){
            int s = (que->head + k - 1 + que->length) % que->length;
            int t = (s + 1) % que->length;
            que->a[s] = que->a[t];
        }
    }
    --que->size;
    if(que->length >= 3 * que->size) resize(que);
}

void push(queue *que, int x){
    insert(que, que->size, x);
}

int front(queue *que){
    return get(que, 0);
}

void pop(queue *que){
    if(que->size == 0) return;
    erase(que, 0);
}

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    queue *que[n];
    for(int i=0; i<n; ++i) que[i] = init();
    while(q--){
        int c, t, x;
        scanf("%d%d", &c, &t);
        if(c == 0){
            scanf("%d", &x);
            push(que[t], x);
        }
        else if(c == 1){
            if(que[t]->size > 0) printf("%d\n", front(que[t]));
        }
        else pop(que[t]);
    }
}


Measured memory_bytes: 2704
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,c,d;cin>>a>>b>>c>>d;
  cout<<min(a,b)*c+max(a-b,(ll)0)*d;
}



Measured memory_bytes: 26980
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>

#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[]){

  string S;
  cin >> S;
  int length = S.length();
  for(int i = 0; i < length-1; i++){
    if(S[i] == 'A'){
      if(S[i+1] == 'C'){
        // success
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n = input_n

hash = {}
hash["AC"] = 0
hash["WA"] = 0
hash["TLE"] = 0
hash["RE"] = 0
n.times do |i|
  s = input_s
  hash[s] += 1
end

puts "AC x #{hash["AC"]}"
puts "WA x #{hash["WA"]}"
puts "TLE x #{hash["TLE"]}"
puts "RE x #{hash["RE"]}"


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

struct DATA
{
	int t, s, d;
	bool operator < (const DATA& a) const {
		return t > a.t;
	}
};

int main()
{
	int n, m;
	while (scanf("%d %d", &n, &m), n + m){
		bool f[20000] = {true};
		priority_queue<DATA> pq;
		
		for (int i = 0; i < m; i++){
			int t, s, d;
			cin >> t >> s >> d;
			s--; d--;
			pq.push({t, s, d});
		}
		
		for (; pq.size(); pq.pop()){
			DATA data = pq.top();
			f[data.d] |= f[data.s];
		}
		
		int res = 0;
		for (int i = 0; i < n; i++){
			res += f[i];
		}
		
		cout << res << endl;
	}
	
	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll r, d, x;
    cin >> r >> d >> x;
    REP(i, 10){
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int maxx = max(a, max(b, c));
	if(((3 * maxx) - a - b - c) % 2 == 1) maxx++;
	cout<<(3 * maxx - a - b - c) / 2<<endl;  
}

Measured memory_bytes: 256
/*author : Yashvardhan
Sunday, April 12, 2020
5:33 PM
*/

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

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))
#define printArr(name,from,to) for(int x = from; x < to; x++) cout << name[x] << " ";


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __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...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int k;
	cin >> k;

	int ans = 0;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k; j++){
			for(int c = 1; c <= k; c++){
				int g1 = __gcd(i,j);
				g1 = __gcd(g1,c);
				ans += g1;
			}
		}
	}

	cout << ans << endl;
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



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

vector<int> v(303030);
int n,k,m,a[3][110];
string s,t;

int main() {
  cin >> n;
  rep(i,2)rep(j,n) cin >> a[i][j];
  int ans=0;
  rep(i,n){
    int cnt=0;
    rep(j,n){
      if(j<=i) cnt+=a[0][j];
      if(j>=i) cnt+=a[1][j];
    }
    ans=max(cnt,ans);
  }
  cout << ans << endl;
}

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

int main() {
int N;
cin >> N;
long int ans = 0;
for (int i = 1; i < N + 1; i++)
{
    if (i % 3 == 0 || i % 5 == 0)
    {}
    else
    {
        ans += i;
    }
    
    
    
}

cout << ans << endl;

}

Measured memory_bytes: 3596