akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<unordered_map>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define pii                 pair<int,int>
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define forr(i, n) for (int i = 0; i < int(n); i++)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 1e7 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
void mansour()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin) ;
    freopen("output.txt" , "w" , stdout) ;
#endif
}
ll mem[100005],n,a[100005],y,mn=LONG_MAX;
ll min_path(int ix)
{
	if(ix>=n)
		return 1e10;
	if(ix==n-1)
		return 0;
	if(mem[ix]!=-1)
		return mem[ix];
	ll r1=1e10,r2=1e10;
	if(ix+1<n)
		r1=abs(a[ix]-a[ix+1])+min_path(ix+1);
	if(ix+2<n)
		r2=abs(a[ix]-a[ix+2])+min_path(ix+2);
	return mem[ix]=min(r1,r2);
}
int main()
{
	mansour();
	//file();
	/*The First*/
	memset(mem,-1,sizeof(mem));
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	cout <<min_path(0)<<"\n";
}

Measured memory_bytes: 4992
n = int(input())
judge = 'Yes'
past_t = past_x = past_y = 0
for i in range(n):
    t, x, y = map(int,input().split())
    if t - past_t < x + y or ((t-past_t)-(x+y)) % 2 != 0:
        judge = 'No'
print(judge)


Measured memory_bytes: 3060
n = int(input())
L = [0] * (n+1)
L[0] = 2
L[1] = 1

def lucas(n):
    if L[n] > 0:
        return L[n]
    L[n] = lucas(n-1) + lucas(n-2)
    return L[n]

print(lucas(n))


Measured memory_bytes: 3060
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

S = str(input())

d = defaultdict(list)
for i,s in enumerate(S):
    d[s].append(i)

for v in d.values():
    for i in range(1,len(v)):
        if v[i]-v[i-1] <= 2:
            print(v[i-1]+1,v[i]+1)
            exit()

print('-1 -1')

Measured memory_bytes: 43632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    string s;
    cin >> s;
    ll ans = 700;
    rep(i, 3) {
        if (s[i] == 'o') ans += 100;
    }

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

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

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

    ll ans=1,lim=1000000000000000000;
    bool flg=true;
    
    rep(i,n){
        ll a;
        cin >> a;
        if(ans!=0&&lim/ans<a){
            flg=false;
        }
        if(a==0){
            flg=true;
            ans=0;
            break;
        }
        ans*=a;
    }
    if(!flg||ans>lim){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}
int a,w,t,r;
signed main(){
    int n;
    cin >> n;
    REP(i,n){
        string s1;
        cin >> s1;
        if(s1=="AC") a++;
        if(s1=="WA") w ++;
        if(s1=="TLE") t ++;
        if(s1=="RE") r++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;


    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll n, h[100100];
ll dp[100100];

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < 100100; i++) dp[i] = inf;

    dp[0] = 0;
    for(int i = 1; i < n; i++){
        dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i>1) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[n-1] << endl;
}


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

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
///#define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 312345;
const double pi = 3.14159265359;
const double eps = 0.00000001;


int32_t main() {

    $
    //freopen("input.txt", "r+", stdin);
    //freopen("output.txt", "w+", stdout);
    
    int a, p;

    cin >> a >> p;

    p += a * 3;

    cout << p/2 << endl;


    
}

Measured memory_bytes: 764
k,n = map(int,input().split())
a = list(map(int,input().split()))
t = [0]*n
t[n-1] = k + a[0] - a[n-1] 
for i in range(n-1):
    t[i] = a[i+1] - a[i]
ans = k - max(t)
print(ans)

Measured memory_bytes: 99940
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderBeginnerContest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // 064-A

            var line = Console.ReadLine().Split(' ');
            var r = int.Parse(line[0]);
            var g = int.Parse(line[1]);
            var b = int.Parse(line[2]);

            var x = r * 100 + g * 10 + b;

            if(x%4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
 
    ll L, R; cin >> L >> R;
    if ((L-1) / 2019 != R / 2019) {
        cout << 0 << endl; return 0;
    }
    L = L % 2019; R = R % 2019;
    int ans = 2018;
    FOR(i, L, R+1) {
        FOR(j, i+1, R+1) {
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;
 
    return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

vector <int> V;
int n,x,y,z,k;
int dp[100010][3];

int main()
{
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> x >> y >> z;
        dp[i][0]=x+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=y+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=z+max(dp[i-1][0],dp[i-1][1]);
    }
    cout << max(max(dp[n][0],dp[n][1]),dp[n][2]);
}


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

int main() {
    //
    int num, k;
    long long waru = 1000000007;

    cin >> num >> k;

    vector<long long> vec(num);
    vector<long long> kekka(num + 1, 1);

    for (int i = 0; i < num; i++) cin >> vec.at(i);

    kekka.at(0) = vec.at(0);
    for (int i = 1; i < num; i++) {
        if (i < k) {
            kekka.at(i) = (kekka.at(i - 1) + vec.at(i));
            continue;
        } else {
            kekka.at(i) = (kekka.at(i - 1) + vec.at(i) - vec.at(i - k));
            if (kekka.at(i) > kekka.at(i - 1))
                cout << "Yes" << endl;
            else
                cout << "No" << endl;
        }
    }
    //
}


Measured memory_bytes: 6412
N, Y= map(int, input().split())
s=-1
g=-1
ic=-1

fl=False
for i in range(N+1):
    for j in range(N+1-i):
        k=N-i-j
#        print(i,j,k)
        if (1000*i+5000*j+10000*k)==Y:
            fl=True
            s=i
            g=j
            ic=k
            break
        if fl:
            break
    if fl:
        break
print(ic,g,s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dep(i,a,b) for(int i=a; i>=b; i--)
#define sq(a) (a)*(a)
#define ms(a,v)	memset(a,v,sizeof a)
using namespace std;
const long long INF = 1e18 , MAXN =1e5, MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<string, string> mss;
/*
1 2 3 4 5 6 7 8 9 10 11 12 21 22 23
10*x+(x%10)-1 if (x%10!=0)
10*x+(x%10)
10*x+(x%10)+1 if (x%10!=9)
*/
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k;  cin>>k;
  vector<ll>arr={1,2,3,4,5,6,7,8,9};
  if (k<=9) cout<<arr[k-1];
  else{
    k-=9;
    int i=0;
    while (k>0){
      if (arr[i]%10!=0){
        k--;
        arr.pb(10*arr[i]+(arr[i]%10)-1);
        if (k==0){
         cout<<arr.back()<<"\n";
        break;
      }
      }
      k--;
      arr.pb(10*arr[i]+(arr[i]%10));
      if (k==0) {
        cout<<arr.back()<<"\n";
        break;
      }
      if (arr[i]%10!=9){
        k--;
        arr.pb(10*arr[i]+(arr[i]%10)+1);
        if (k==0){
          cout<<arr.back();
          break;
        }
      }
      i++;
    }
  }
    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 5010

#define CHECK

ll N;
string S;

int LCSuff[MAX_N+1][MAX_N+1]; 

int LCSubStr(const char *X, const char *Y, int m, int n) 
{ 
    // Create a table to store lengths of longest 
    // common suffixes of substrings.   Note that 
    // LCSuff[i][j] contains length of longest 
    // common suffix of X[0..i-1] and Y[0..j-1].  

    int result = 0;  // To store length of the  
    // longest common substring 

    /* Following steps build LCSuff[m+1][n+1] in 
       bottom up fashion. */
    for (int i=0; i<=m; i++) 
    { 
        for (int j=0; j<=n; j++) 
        { 

            // The first row and first column  
            // entries have no logical meaning,  
            // they are used only for simplicity  
            // of program 
            if (i == 0 || j == 0) 
                LCSuff[i][j] = 0; 

            else if (X[i-1] == Y[j-1]) 
            { 
                LCSuff[i][j] = LCSuff[i-1][j-1] + 1; 
                result = max(result, LCSuff[i][j]); 
            } 
            else LCSuff[i][j] = 0; 
        } 
    } 
    return result; 
} 

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

    cin >> N >> S;

    const char* S_c = S.c_str();

    ll ans = 0;
    ll lb = 1, ub = N - 1;

#ifdef CHECK
    while(ub - lb > 100) {
#else
    while(ub - lb > 2) {
#endif
        ll t1 = (2 * lb + ub) / 3;
        ll t2 = (lb + 2 * ub) / 3;

        ll cand1 = LCSubStr(S_c, S_c + t1, t1, N - t1);
        ll cand2 = LCSubStr(S_c, S_c + t2, t2, N - t2);
        ans = max({ans, cand1, cand2});

        //DBG("t1: %lld t2: %lld cand1: %lld cand2: %lld\n", t1, t2, cand1, cand2);

        if(cand1 <= cand2) {
            lb = t1 - 1;
        }
        else {
            ub = t2 + 1;
        }
    }

    for(int i = lb; i <= ub; ++i) {
        ll cand = LCSubStr(S_c, S_c + i, i, N - i);
        ans = max(ans, cand);
    }
#ifdef CHECK
    for(int i = 0; i < (int)(min((int)150, N)); ++i) {
        ll cand = LCSubStr(S_c, S_c + i, i, N - i);
        ans = max(ans, cand);
    }
    for(int i = (int)(max((int)0, N - 150)); i < N; ++i) {
        ll cand = LCSubStr(S_c, S_c + i, i, N - i);
        ans = max(ans, cand);
    }
#endif

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

    return 0;
}


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

int main(){
    int M,K; cin >> M >> K;
    int N=pow(2,M);
    if(M==1&&K==0){
        cout << "0 0 1 1" << endl;
        return 0;
    }
    if(N<=K){
        cout << -1 << endl;
        return 0;
    }
    if(M==1&&K==1){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<N;i++){
        if(i!=K) cout << i << " ";
    }
    cout << K << " ";
    for(int i=N-1;i>=0;i--){
        if(i!=K) cout << i << " ";
    }
    cout << K << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
  
  int k,n,i,max;
  scanf("%d %d",&k,&n);
  
  int a[n+1],b[n+1];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  b[0] = a[0] + (k - a[n-1]);
  for(i=1;i<n;i++){
    b[i] = a[i] - a[i-1];
    //printf("%d",
  }
  max = b[0];
  for(i=0;i<n;i++){
    if(max < b[i]) max = b[i];
  }
  
  printf("%d",k-max);
  
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

template<class F>
i64 bisect(i64 l, i64 r, F f) { // (l, r]
  if (r - l <= 1) return r;
  i64 m = l + (r - l) / 2;
  return f(m) ? bisect(l, m, f) : bisect(m, r, f);
}
template<class F>
i64 bisect_left(i64 l, i64 r, F f) {
  return bisect(l, r, [=](i64 x) { return !f(x); }) - 1;
}
i64 n, m, v, p;
vector<i64> a;
int main() {
    cin >> n >> m >> v >> p;
    read_n(a, n);
    sort(begin(a), end(a), greater<i64>());

    i64 ans = 1 + bisect_left(0, n, [&](i64 x) {
        if (x < p) return true;
        // cerr << x << ':' << a[x] + m << ' ' << a[p - 1] << endl;
        if (a[x] + m < a[p - 1]) return false;
        i64 s = a[x] + m;
        i64 u = v - (p - 1) - (n - x);
        if (u <= 0) return true;
        i64 sum = 0;
        for (int i = p - 1; i < x; ++i) {
            sum += min(m, s - a[i]);
        }
        return sum >= u * m;
    });   

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <climits>
#include <utility>
#include <numeric>
typedef long long ll;
using namespace std;

int gcd(int a,int b){
  if(b==0)return a;
  else return gcd(b,a%b);
}

struct Factorizer{
  int n;
  vector<int> minFactor;
  vector<bool> cnt;

  Factorizer(int max){
    int i, j;
    n = max;
    minFactor.resize(n);
    cnt.resize(n,0);
    iota(minFactor.begin(),minFactor.end(),0);
    for(i=2;i*i<n;i++){
      if(minFactor[i]<i) continue;
      for(j=i*i;j<n;j+=i){
        if(minFactor[j]==j) minFactor[j] = i;
      }
    }
  }

  bool check(int x){
    while(x>1){
      if(cnt[minFactor[x]]) return 1;
      else cnt[minFactor[x]] = 1;

      int t = minFactor[x];
      while(x%t==0){
        x /= t;
      }
    }
    return 0;
  }
};

int main(int argc, char *argv[]) {
  int n, i, s;
  cin >> n;

  Factorizer f(1000001);
  vector<int> a(n);

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

  for(i=0;i<n;i++){
    if(f.check(a[i])){
      break;
    }
  }
  if(i==n){
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int c = gcd(a[0],a[1]);
  for(i=2;i<n;i++){
    c = gcd(c,a[i]);
    if(c==1) break;
  }
  if(c==1){
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

  return 0;
}


Measured memory_bytes: 11024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) ll t;cin>>t; while(t--)
int main()
{
  ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

ll i,n,s=0, flag=0;cin>>n;
   if(n==0) cout<<"1";
   else cout<<"0";
}
  

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 100100;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
using P = pair<int, int>;
const string YES = "Yes";
const string NO = "No";
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse! Oh~MyGod」

void solve(long long N, long long M, std::vector<long long> a,std::vector<long long> b, std::vector<long long> c){
  vecllvec d(110,vecll(110,INF));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i==j){
        d[i][j]=0;
      }
    }
  }
  for(int i=0;i<M;i++){
    d[a[i]][b[i]]=min(c[i],d[a[i]][b[i]]);
    d[b[i]][a[i]]=min(c[i],d[b[i]][a[i]]);
  }
  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  int ans=M;
  for(int i=0;i<M;i++){
    bool che=false;
    for(int j=0;j<N;j++){
      if(d[j][a[i]]+c[i]==d[j][b[i]]) che=true;
    }
    if(che) ans--;
  }
  cout<<ans<<endl;
  return;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> a(M);
  std::vector<long long> b(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &a[i]);
    a[i]--;
    scanf("%lld", &b[i]);
    b[i]--;
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(a), std::move(b), std::move(c));
  return 0;
}


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

//Compiler version g++ 6.3.0

int main()
{
    long long int a, b, c;
    cin>>a>>b;
    if((a+b)%2==0)
    {
      c=(a+b)/2;
      cout<<c;
    }
    
    else
    {
      cout<<"IMPOSSIBLE";
    }
}

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

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

    vector<long long> vec(N);
    for (int i = 0; i < N; ++i) {
        cin >> vec[i];
    }

    for (int i = 0; i < N; ++i) {
        if (vec[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    long long ans = 1;
    for (int i = 0; i < N; ++i) {
        if (ans <= powl(10, 18) / vec[i]) {
            ans *= vec[i];
            continue;
        }
        cout << -1 << endl;
        return 0;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
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...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    string s;cin >> s;
    int n = s.size();
    for(int i = 0;i < n;){
        if(s.substr(i,5) == "dream"){
            if(s.substr(i+5,6) == "eraser"){
                i += 11;
            }
            else if(s.substr(i+5,5) == "erase"){
                i += 10;
            }
            else if(s.substr(i,7) == "dreamer"){
                i += 7;
            }
            else {
                i+= 5;
            }
        }
        else if(s.substr(i,5) == "erase"){
            if(s.substr(i,6) == "eraser"){
                i += 6;
            }
            else {
                i += 5;
            }
        }
        else {
            cout << "NO" << endl;
            return 0;
        }


    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3772
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++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 ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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 w,a,b; cin >> w >> a >> b;
    int move;
    if(a<b){
        if(a+w<b) move = b-(a+w);
        else move = 0;
    }else{
        if(b+w<a) move = a- (b+w);
        else move =0;
    }
    cout << move ;
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n,r;cin >>n>>r;
    n=(n>10)?10:n;
    ll ans=r+100*(10-n);
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
    vector<vector<int>> t(10, vector<int>(10));
    for (auto &ti: t) for (auto &tij: ti) cin >> tij;
    auto calc = [&](vector<int> &a) {
        int ret = 0;
        rep(i, 4) ret = t[ret][a[i]];
        return ret;
    };
    auto is_zero = [&](vector<int> &a) { return t[calc(a)][a.back()] == 0; };
    auto can_detect = [&](vector<int> &a) {
        // altering one single digit
        vector<int> b = a;
        rep(i, 5) rep(err, 10) if (a[i] != err) {
            b[i] = err;
            if (is_zero(b)) return false;
            b[i] = a[i];
        }
        // transposing two adjacent digits
        rep(i, 4) if (a[i] != a[i + 1]) {
            swap(b[i], b[i + 1]);
            if (is_zero(b)) return false;
            swap(b[i], b[i + 1]);
        }
        return true;
    };
    int cnt = 0;
    rep(a, 10) rep(b, 10) rep(c, 10) rep(d, 10) {
        vector<int> v{a, b, c, d};
        v.emplace_back(calc(v));
        cnt += !can_detect(v);
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<functional>
#include<list>
#include<bitset>
#include<numeric>
#include<utility>
#define INF (int)1e9
#define MOD 1000000007
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> p;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	char b = s[0];
	char c = s[1];
	if (c == b) {
		cout << 1 << " " << 2;
		return 0;
	}
	char a;
	for (int i = 2; i < s.size(); i++) {
		a = b;
		b = c;
		c = s[i];
		if (a == b||a==c||b==c) {
			cout << i - 1 << " " << i + 1;
			return 0;
		}
	}
	cout << -1 << " " << -1;
	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
int lcm(int a, int b){
  return a / gcd(a,b) * b;
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};
// 区間加算にも対応した BIT
template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int N;
ll D,A;
vector<ll> X,H;

bool comp(int i, int j){
  return X[i] < X[j];
}

int main(){
  cin >> N >> D >> A;
  X.resize(N); H.resize(N);
  rep(i,N) cin >> X[i] >> H[i];
  
  vector<int> ids(N);
  rep(i,N) ids[i] = i;
  sort(ids.begin(),ids.end(),comp); //Xを昇順で並べ替えた場合の位置を記録
  
  vector<ll> nX(N),nH(N);
  rep(i,N) nX[i] = X[ids[i]], nH[i] = H[ids[i]];//X,HをXの昇順で並べ換える
  X = nX, H = nH;
  
  BIT<ll> bit(N+10); //BITの初期化
  rep(i,N) bit.add(i+1,i+2, H[i]); //BITに加算。
  ll res = 0;
  
  rep(i,N){
    ll cur = bit.sum(i+1, i+2); //iの数字を取得
    if(cur <= 0) continue; //もしi番目のHPが0以下だったら次に行く
    
    ll need = (cur + A - 1)/A; //切り上げで攻撃回数計算
    
    ll right = X[i] + D * 2; //X[i]からD*2の距離にある位置を取得
    int id = upper_bound(X.begin(), X.end(), right) - X.begin(); //idを取得
    
    bit.add(i+1,id+1,-need * A); //その位置まで数字を減算する
    res += need; //回数を足しこむ
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  vector<int> bars;
  for(int i=0;i<12;i++){
    int temp;
    cin >> temp;
    bars.push_back(temp);
  }
  sort(bars.begin(),bars.end());
  bool isyes = true;
  for(int i=0;i<3;i++){
    if(bars[0+4*i]!=bars[1+4*i] || bars[0+4*i]!=bars[2+4*i] || bars[0+4*i]!=bars[3+4*i]){
      isyes = false;
    }
  }
  if(isyes)cout << "yes" << endl;
  else cout << "no" << endl;
  return 0;
}


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

const int MAX = 3e5;
int msp[MAX + 1] = { 0 };

int main(){
	int n, c;
	fill(msp, msp + MAX + 1, 0);
	for(int i = 1;i <= MAX;i += 7){
		msp[i] = 1;
	}
	msp[1] = 0;
	for(int i = 6;i <= MAX;i += 7){
		msp[i] = 1;
	}
	for(int i = 1;i <= sqrt(MAX);++i){
		if(msp[i]){
			for(int j = i + i;j <= MAX;j += i){
				msp[j] = 0;
			}
		}
	}
	while(cin >> n, n != 1){
		c = 0;
		cout << n << ": ";
		for(int i = 2;i <= n;++i){
			if(msp[i] && n % i == 0){
				if(c) cout << " ";
				cout << i;
				++c;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2332
#include<bits/stdc++.h>
#define fi first
#define se second
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e7+10;
const int N=1e7;
int x,y;
ll f[maxn],inv[maxn];
ll ksm(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1) ret=ret*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return ret;
}
ll C(ll n,ll m){
	if(m>n) return 0;
	return f[n]*inv[n-m]%mod*inv[m]%mod;
}
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	f[0]=1;
	for(int i=1;i<=N;i++) f[i]=f[i-1]*i%mod;
	inv[N]=ksm(f[N],mod-2);
	for(ll i=N-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	while(cin>>x>>y){
		if(x<y) swap(x,y);
		if((x+y)%3){
			cout<<0<<endl;
			continue;
		}
		cout<<C((x+y)/3,(x+y)/3*2-y)<<endl;
	}
	return 0;
}
/*C((x+y)/3,)
0 3 6 9
(x+y)/3*2-x+1 
0 2 4 6*/
//4*(x+y)3

Measured memory_bytes: 156544
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
ll a[1000005],cnt[1000005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,n,t,l,r;
    cin>>n;
    ll g=0;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
        g=__gcd(g,a[i]);
        cnt[a[i]]++;
    }
    if(g>1)
    {
        cout<<"not coprime"<<'\n';
        return 0;
    }
    bool monu=1;
    ll val;
    for(i=2; i<1000000; i++)
    {
        val=0;
        for(j=i; j<1000000; j+=i)
        {
            val+=cnt[j];
        }
        if(val>1)
            monu=0;
    }
    if(monu)
        cout<<"pairwise coprime"<<'\n';
    else
        cout <<"setwise coprime"<<'\n';
}






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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B, C;
    cin >> A >> B >> C;

    ll ans;
    if (A%2 == 0 || B%2 == 0 || C%2 == 0) {
        ans = 0;
    } else {
        if (A < B) {
            if (B < C) {
                ans = A*B;
            } else {
                ans = A*C;
            }
        } else {
            if (A < C) {
                ans = A*B;
            } else {
                ans = B*C;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
  int n,m,i,j,k,l;
  char s[100][11],t[100][11];
  vector <int> v;
  cin>>n;
  for(i=0;i<n;i++)
    cin>>s[i];
  cin>>m;
  for(i=0;i<m;i++)
    cin>>t[i];
  v.push_back(0);
  
  if(s[0]==t[0])
    cout<<"a";
  
  for(i=0;i<n;i++){
    j=0;
    for(l=0;l<n;l++){
      if(strcmp(s[i],s[l])==0)
        j++;
    }
    for(k=0;k<m;k++){
      if(strcmp(s[i],t[k])==0)
        j--;
    }
    v.push_back(j);
  }
  sort(v.begin(),v.end(),greater<int> ());
  
  cout<<v[0]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 

const double EPS=0.00001;
const long double PI = acos(-1.0);
 
int dp[1<<26];
const int INF = 1e9;
 
int main() {
    string S;
    cin >> S;
    REP(i,(1<<26)) dp[i] = INF;
    dp[0] = 0;
    int stat = 0;
    REP(i,SZ(S)){
        stat ^= 1 << (S[i]-'a');
        REP(j,26) {
            int tmp = (stat^(1<<j));//今見ている文字がいない状態
            dp[stat] = min(dp[stat], dp[tmp]+1);
        }
    }
    cout<<max(dp[stat],1)<< endl;
    return 0;
}

Measured memory_bytes: 262788
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fl first
#define fr second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;

const int N = 100 + 5;

char s[N];
int n, k;
LL f[N][5][2];

LL DP(int now, int cnt, int ok)
{
    if (now == n + 1) return cnt == k;
    if (cnt > k) return 0;
    if (f[now][cnt][ok]) return f[now][cnt][ok];
    LL res = 0;
    for (int i = 0; i <= 9; i++)
    {
        if (ok && i > s[now] - '0') break;
        res += DP(now + 1, cnt + (i != 0), ok && (i == s[now] - '0'));
    }
    //cout << now << " " << cnt << " " << ok << " " << res << endl;
    return f[now][cnt][ok] = res;
}

int main()
{
    scanf("%s%d", s + 1, &k);
    n = strlen(s + 1);
    printf("%lld\n", DP(1, 0, 1));
    return 0;
}

Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

L = [list(map(int, input().split())) for _ in range(M)]

# 割引券を使わない
m = min(a) + min(b)
ans = []
ans.append(m)
for i in range(M):
    x = L[i][0]
    y = L[i][1]
    c = L[i][2]
    p = a[x - 1]
    k = b[y - 1]
    ans.append(p + k - c)

print(min(ans))

Measured memory_bytes: 42412
import sys
input = sys.stdin.readline


h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]

diff = [[0]*(w) for i in range(h)]
for i in range(h):
    for j in range(w):
        diff[i][j] = abs(a[i][j] - b[i][j])

dp = [0] * (h*w)
dp[0] |= 1 << (13000 + diff[0][0])
dp[0] |= 1 << (13000 - diff[0][0])

for k in range(h*w):
    i = k // w
    j = k % w
    if i+1 < h:
        tmp1 = diff[i+1][j]
        dp[k + w] |= dp[k] << tmp1
        dp[k + w] |= dp[k] >> tmp1       
    if j+1 < w:
        tmp2 = diff[i][j+1]
        dp[k + 1] |= dp[k] << tmp2
        dp[k + 1] |= dp[k] >> tmp2


ans = 10**9
for i in range(81):
    if dp[w*h - 1] >> 13000 + i & 1:
        ans = min(ans, i)
for i in range(81):
    if dp[w*h - 1] >> 13000 - i & 1:
        ans = min(ans, i) 
print(ans)

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


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

    ll ans = 0;

    ans += min(n, m / 2);
    m -= ans * 2;
    ans += m / 4;
    cout << ans << endl;
}

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

int main(){
  int n,i,kotae=0,hantei=0,soko=0;
  cin>>n;
  int a[n+2];
  a[0]=0;
  a[n+1]=0;
  for(i=1;i<=n;i++){
    cin>>a[i];
    if(a[i]>a[i-1]){
      if(hantei==0){
        soko=a[i-1];
      }
      hantei=1;
    }else if(a[i]<a[i-1]){
      if(hantei==1){
        kotae+=a[i-1]-soko;
      }
      hantei=0;
    }
  }
  if(hantei==1){
    kotae+=a[n]-soko;
  }
  cout<<kotae;
}

Measured memory_bytes: 256
N=int(input())
dp=[1000000000000000 for i in range(N)]
h=[int(x) for x in input().split()]
dp[0]=0
for i in range(N-1):
    dp[i+1] = dp[i+1] if dp[i+1]<dp[i]+abs(h[i+1]-h[i]) else dp[i]+abs(h[i+1]-h[i])
    if i<N-2:
        dp[i+2] = dp[i+2] if dp[i+2]<dp[i]+abs(h[i+2]-h[i]) else dp[i]+abs(h[i+2]-h[i])
print(dp[-1])

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

int main(){
  int m, f, r;
  cin >> m >> f >> r;
  while(true){
    if(m == -1 && f == -1 && r == -1)
      break;
    else if(m == -1 || f == -1)
      cout << "F" << endl;
    else if(m + f >= 80)
      cout << "A" << endl;
    else if(m + f >= 65)
      cout << "B" << endl;
    else if(m + f >= 50)
      cout << "C" << endl;
    else if(m + f >= 30){
      if(r >= 50){
        cout << "C" << endl;
      } else{
        cout << "D" << endl;
      }
    }
    else
      cout << "F" << endl;
    
    cin >> m >> f >> r;
  }
  return 0;
}


Measured memory_bytes: 3084
#include <iostream>
using namespace std;
int main(void){
	char a;
	cin >> a;
	if(a == 'a' || a == 'e'||  a == 'i' ||  a == 'o' ||  a == 'u'){
		cout << "vowel" << endl;
		return 0;
	}
	else{
		cout << "consonant" << endl;
	}
}

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

int main(){
  int a, b, c, d = 0;

  cin>>a>>b;

  c = b - a;

  for(int i = 1; i <= c-1; i++){
    d += i;
  }

  cout<<d-a<<endl;

  

  
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int n;
  string s;
  string t="abcdefghijklmnopqrstuvwxyz";
  int aa=0;
  char c[100010];
  long long int ans=1;
  cin>>n>>s;
  for(int i=0;i<t.size();i++){
    for(int j=0;j<n;j++){
      if(t[i]==s[j]){
        aa++;
      }
    }
    ans*=aa+1;
    ans=ans%1000000007;
    aa=0;
  }
  cout<<ans-1<<endl;
}

Measured memory_bytes: 512
N,M = map(int,input().split())
dev = 10**9+7

dec = abs(N-M)

if dec > 1:
    ans = 0
else:
    idx = max(N,M)
    dp = [1 for _ in range(idx+1)]
    dp[0] = 1
    for i in range(idx):
        dp[i+1] = dp[i]*(i+1)
        dp[i+1] %= dev

    if dec == 1:
        ans = dp[idx]*dp[idx-1]
        ans %= dev
    else:
        ans = 2*dp[idx]*dp[idx]
        ans %= dev

print(int(ans))

Measured memory_bytes: 7064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll MOD = 1e9 + 7;

ll solveZero(const vector<ll>& xsum) {
  ll res = 1;
  for (int i = 0; i < xsum.size() - 1; i++) {
    if (xsum[i] == 0) {
      res = res * 2 % MOD;
    }
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (ll& x : A) cin >> x;
    vector<ll> xsum(N);
    xsum[0] = A[0];
    for (int i = 1; i < N; i++) xsum[i] = xsum[i - 1] ^ A[i];
    vector<ll> dp(N, 0ll);
    map<ll, ll> preVal;
    map<ll, ll> sumDp;
    map<ll, int> preZero;
    int zero = 0;
    for (int i = 0; i < N; i++) {
      ll X = xsum[i];
      if (X == 0) {
        ++zero;
        continue;
      }
      ll ways = 1;
      ll Z = zero - preZero[X];
      if (preVal.count(X)) {
        ways += preVal[X] - 1 + MOD;
        ways %= MOD;
        ways += sumDp[X] * Z % MOD;
        ways %= MOD;
      }
      dp[i] = ways;
      preVal[X] = dp[i];
      preZero[X] = zero;
      sumDp[X] = (sumDp[X] + dp[i]) % MOD;
    }
    ll res = 0;
    if (xsum.back() != 0) {
      res = dp.back();
    } else {
      for (int i = 0; i < N; i++) {
        if (xsum[i] != 0) {
          res += dp[i];
          res %= MOD;
        }
      }
      res += solveZero(xsum);
      res %= MOD;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 65792
// https://atcoder.jp/contests/agc027/tasks/agc027_a
"use strict";
function Main(input) {
  input = input.trim().split("\n");
  let [N, X] = input[0].trim().split(" ").map(Number);
  const a = input[1]
    .trim()
    .split(" ")
    .map(Number)
    .sort((a, b) => a - b);

  let count = 0;
  for (let i = 0; i < N; i++) {
    if (i === N - 1) {
      if (a[i] === X) {
        count++;
      }
    } else if (X >= a[i]) {
      X -= a[i];
      count++;
    } else {
      break;
    }
  }

  console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()


typedef long long ll;


const ll mod = 998244353;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    string S;
    cin >> S;
    ll ans = 0;
    int N = S.size();
    for (int bit = 0; bit < (1 << N); ++bit) {
        ll tmp = 0;
        rep(i, N) {
            if (bit & (1 << i)) {
                ans += tmp;
                tmp = 0;
            } else {
                tmp = tmp*10 + (int)(S[i] - '0');
            }
        }
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
   int n,sum=0;cin>>n;
   vector<int> v(n);
   rep(i,0,n){
      cin>>v[i];
      sum+=v[i];
   }

   sort(all(v));


   if(sum-v.back()>v.back())cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

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

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for(int i=0; i<M; i++) cin >> B[i];
    int A[M][N];
    for(int i=0; i<N; i++) {
        for(int j=0; j<M; j++) {
            cin >> A[j][i];
        }
    }

    int count = 0;
    for(int i=0; i<N; i++) {
        int total = C;
        for(int j=0; j<M; j++) {
            total += (A[j][i] * B[j]);
        }
        if(total > 0) {
            count++;
        }
    }
    cout << count << endl;
}



Measured memory_bytes: 3608