akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let h1: u32 = sc.cin();
    let m1: u32 = sc.cin();
    let h2: u32 = sc.cin();
    let m2: u32 = sc.cin();
    let k: u32 = sc.cin();

    put!(h2 * 60 + m2 - m1 - h1 * 60 - k);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 2164
#include <cstdio>

void solvex(int x, int y){
	if(x > 9)return ;
	printf("%dx%d=%d\n",y,x,x*y);
	solvex(x+1,y);
}

void solvey(int y){
	if(y > 9)return ;
	solvex(1, y);
	solvey(y+1);
}

int main(){
	solvey(1);
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;


int main() {
  string S; cin >> S;
  LL total = 0;
  LL keta = 1;
  LL cnt[2020]  = {};
  LL ans = 0;
  cnt[0] = 1;
  for (auto it = S.rbegin(); it != S.rend(); ++it) {
    LL v = *it - '0';
    total = (v * keta + total) % 2019;
    keta = (keta * 10) % 2019;

    ans += cnt[total];
    ++cnt[total];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3708
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}
inline int pl(int x,int y){return (x+=y)>=mod?x-mod:x;}
inline int kpow(int a,int b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)s=1ll*s*a%mod;
	return s;
}
int n,h[110],dp[110][110],d[110],m,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&h[i]),d[i]=h[i];
	sort(d+1,d+1+n);
	m=unique(d+1,d+1+n)-d-1;
	for(int i=1;i<=n;++i)h[i]=lower_bound(d+1,d+1+m,h[i])-d;
	for(int i=0;i<=h[1];++i)dp[1][i]=kpow(2,d[h[1]]-d[i])*(1+(i>0))%mod;
	for(int i=0;i<=h[1];++i)add(dp[1][i],mod-dp[1][i+1]);
	for(int i=2;i<=n;++i)
	{
		for(int j=0;j<=h[i-1]&&j<=h[i];++j)dp[i][j]=dp[i-1][j];
		if(h[i-1]>=h[i])
		{
			for(int j=h[i]+1;j<=h[i-1];++j)add(dp[i][h[i]],dp[i-1][j]);
			for(int j=h[i];j<=h[i-1];++j)add(dp[i][h[i]],dp[i-1][j]);
		}
		else
		{
			int res=pl(dp[i][h[i-1]],dp[i-1][h[i-1]]);
			for(int j=h[i-1];j<=h[i];++j)dp[i][j]=1ll*res*kpow(2,d[h[i]]-d[j])%mod;
			for(int j=h[i-1];j<=h[i];++j)add(dp[i][j],mod-dp[i][j+1]);
			res=kpow(2,d[h[i]]-d[h[i-1]]);
			for(int j=0;j<h[i-1];++j)dp[i][j]=1ll*dp[i][j]*res%mod;
		}
	}
//	for(int i=1;i<=n;++i)
//	{
//		for(int j=0;j<=h[i];++j)printf("%d ",dp[i][j]);
//		printf("\n");
//	}
	for(int j=0;j<=h[n];++j)add(ans,dp[n][j]);
	printf("%d",ans);
	return 0;
}


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

struct pno{
    ll p,now;
    bool odd;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n;
    std::cin >> n;
    vector<vector<ll>> edges(n);
    
    for (int i = 0; i < n-1; i++) {
        ll a,b;
        std::cin >> a>>b;
        a--;b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    
    vector<ll> stat(n,-1);
    vector<ll> dis(n,0);

    stat[0]=1;
    std::stack<pno> st;
    st.push({-1,0,true});
    
    vector<ll> p(n);
    p[0]=0;

    while(st.size()){
        auto tmp = st.top();st.pop();
        for (auto e : edges[tmp.now]) {
            if(e==tmp.p)continue;
            if(tmp.odd){
                stat[e]=2;    
            }else{
                stat[e]=1;
            }
            p[e] =tmp.now;
            dis[e]=dis[tmp.now]+1;
            st.push({tmp.now,e,!tmp.odd});
        }
    }
    ll onec=0;
    vector<pair<ll,ll>> chc(n);
    for (int i = 0; i < n; i++) {
        if(stat[i]==1){
            onec++;
        }
        if(i==0){
            chc[i]={edges[i].size(),i};
        }else{
            chc[i]={edges[i].size()-1,i};
        }
    }
    sort(chc.rbegin(),chc.rend());
    ll sec = n-onec;
    vector<ll> ind(3,0);
    if(onec<=n/3){
        ll i3=3;
        ll i1=1;
        for (int i = 0; i < n; i++) {
            if(stat[i]==1){
                std::cout << i3<<" ";
                i3 +=3;
            }else{
                if(i1<=n){
                    std::cout << i1 <<" ";
                    i1++;
                    if(i1%3==0){
                        i1++;
                    }    
                }else{
                    std::cout << i3<<" ";
                    i3+=3;
                }
            }
        }
    }else if(sec<=n/3){
        ll i3=3;
        ll i1=1;
        for (int i = 0; i < n; i++) {
            if(stat[i]==2){
                std::cout << i3 <<" ";
                i3 +=3;
            }else{
                if(i1<=n){
                    std::cout << i1 <<" ";
                    i1++;
                    if(i1%3==0){
                        i1++;
                    }    
                }else{
                    std::cout << i3<<" ";
                    i3+=3;
                }
            }
        }
    }else{
        ll i1=1;
        ll i2=2;
        ll i3=3;
        for (int i = 0; i < n; i++) {
            if(stat[i]==1&&i1<=n){
                std::cout << i1 <<" ";
                i1+=3;
                continue;
            }
            if(stat[i]==2&&i2<=n){
                std::cout << i2 << " ";
                i2+=3;
                continue;
            }
            std::cout << i3<<" ";
            i3+=3;
        }
    }
    std::cout << std::endl;
}


Measured memory_bytes: 24808
#include <iostream>
#include <vector>
using namespace std;
int n;
vector<string> s;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n;
  s.resize(n);
  for(int i = 0; i < n; ++i) {
    cin >> s[i];
    s[i] = s[i] + s[i];
  }
  for(int i = 0; i < n; ++i) s.push_back(s[i]);

  int ans = 0;
  for(int i = 0; i < n; ++i) {
    bool ok = true;
    for(int j = 0; j < n; ++j) {
      for(int k = j+1; k < n; ++k) {
        if(s[i+j][k] != s[i+k][j]) {
          ok = false;
          break;
        }
      }
      if(!ok) break;
    }
    if(ok) ++ans;
  }
  cout << ans * n << endl;
  return 0;
}

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

const int N = 1e5 + 7;
const long long MOD = 1e9 + 7;
char s[N];
long long dp[N][11][13];
int bit[N];

int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	bit[0] = 1;
	for (int i = 1; i < N; i++) bit[i] = bit[i - 1] * 10 % 13;
	dp[0][0][0] = 1;
	s[0] = '0';
	for (int i = 1; i <= n; i++) {
		if (s[i] != '?') {
			int now = s[i] - '0';
			for (int pre = 0; pre <= 9; pre++) { 
				if ((s[i - 1] != '?') && (s[i - 1] - '0' != pre)) continue;
				for (int k = 0; k < 13; k++) 
					(dp[i][now][(now * bit[n - i] + k) % 13] += dp[i - 1][pre][k]) %= MOD;
			}
		} else {
			for (int now = 0; now <= 9; now++) 
				for (int pre = 0; pre <= 9; pre++) {
					if ((s[i - 1] != '?') && (s[i - 1] - '0' != pre)) continue;
					for (int k = 0; k < 13; k++) 
						(dp[i][now][(now * bit[n - i] + k) % 13] += dp[i - 1][pre][k]) %= MOD;
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i <= 9; i++) ans = (ans + dp[n][i][5]) % MOD;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 112512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int n, x, sum = 0;
	cin >> n >> x;
	vector<int> m(n);
	for (int i = 0; i < n; i++){
		cin >> m[i];
		sum += m[i];
	}
	sort(m.begin(), m.end());
	int ans = n;
	x -= sum;
	ans += x/m[0];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

string l,r;

ll twop(ll n){
  ll ret=1;
  rep(i,n) ret*=2;
  return ret;
}

void divide(string s, ll &ret) {
  ret+=stoll(s);
  for(ll i=0; i<s.length()-1;++i) {
    l=s.substr(0,i+1);
    r=s.substr(i+1,s.length()-(i+1));
    ret+=stoll(l)*twop(r.length()-1);
    divide(r,ret);
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,r,l;cin>>s; 
  ll ans=0; divide(s,ans);
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define CLR(a) memset(a, 0, sizeof(a))
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b)  for(int i=(a); i<(b); i++)
#define REP(i, a, b)  for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll LL_INf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000009;
const int N = 1e5 +10;

ll n,m;

int main(){
	cin>>n>>m;
	if (n==1) {
		if (m==1) cout<<1<<endl;
		else cout<<m-2<<endl;
	}
	else if (m==1) {
		cout<<n-2<<endl;
	}
	else cout<<(n-2)*(m-2)<<endl;
	//cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
Cac = 0
Cwa = 0
Ctle = 0
Cre = 0
for cnt in range(N):
    Si = input()
    if Si == 'AC':
        Cac = Cac + 1
    elif Si == 'WA':
        Cwa = Cwa + 1
    elif Si == 'TLE':
        Ctle = Ctle + 1
    elif Si == 'RE':
        Cre = Cre + 1

print('AC', 'x', Cac)
print('WA', 'x', Cwa)
print('TLE', 'x', Ctle)
print('RE', 'x', Cre)


Measured memory_bytes: 9176
N = int(input())

link = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    link[u - 1].append((v - 1, w))
    link[v - 1].append((u - 1, w))

d = [0] * N
q = [0]
while q:
    p = q.pop()
    for n, w in link[p]:
        if d[n] == 0:
            d[n] = d[p] + w
            q.append(n)

for i in d:
    print(i % 2)


Measured memory_bytes: 70304
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  ll n,m,l;
  cin>>n>>m>>l;
  
  ll A[n][m];
  ll B[m][l];
  ll C[n][l];
  rep(i,n){
    rep(j,m) cin>>A[i][j];
  }
  rep(i,m){
    rep(j,l) cin>>B[i][j];
  }
  rep(i,n){
    rep(j,l) C[i][j]=0;
  }
  
  rep(i,n){
    rep(j,l){
      rep(k,m) C[i][j]+=A[i][k]*B[k][j];
    }
  }
  
  rep(i,n){
    rep(j,l){
      if(j) cout<<" ";
      cout<<C[i][j];
    }
    cout<<endl;
  }
  
  return 0;
}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

// 素因数分解
vector<pair<Int, Int>> factorization(Int n) {
    vector<pair<Int, Int>> ret;
    for (Int i = 2; i * i <= n; i++) {
        Int cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt > 0) {
            ret.emplace_back(i, cnt);
        }
    }
    if (n > 1) {
        ret.emplace_back(n, 1);
    }
    return ret;
}

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    map<Int, Int> mp;
    for (Int i = 0; i < n; i++) {
        bool check = true;
        vector<pair<Int, Int>> v = factorization(a[i]);
        for (Int j = 0; j < (Int)v.size(); j++) {
            if (mp[v[j].first] > 0) {
                check = false;
                break;
            }
            mp[v[j].first]++;
        }
        if (not check) {
            Int x = a[0];
            for (Int j = 1; j < n; j++) {
                x = gcd(x, a[j]);
            }
            if (x == 1) {
                print("setwise coprime");
            } else {
                print("not coprime");
            }
            return 0;
        }
    }
    print("pairwise coprime");
    return 0;
}


Measured memory_bytes: 11040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

ll dp[3100][3100];

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

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

    ll n = s.size(), m = t.size();

    for(ll i = 1; i <= n; i++) {
        for(ll j = 1; j <= m; j++) {
            if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
        }
    }

    string ans;
    while(n >= 0 && m >= 0) {
        if(dp[n][m] == dp[n][m-1]) m--;
        else if(dp[n][m] == dp[n-1][m]) n--;
        else ans += s[n-1], n--, m--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


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

ans = 0
a = 9999999
for i in range(N):
    ans += B[A[i]-1]
    if A[i] == a + 1:
        ans += C[a-1]
    a = A[i]

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int i,a,b[11]={0},c,i2;
	scanf("%d",&a);
	while(a!=0){
for(i=0;i<11;i++){
b[i]=0;
}
	for(i=0;i<a;i++){
		scanf("%d",&c);
		b[c]++;
	}
	for(i=0;i<10;i++){
		
		if(b[i]==0){
			printf("-\n");
		}
		else{
			for(i2=0;i2<b[i];i2++){
			printf("*");
		}
			printf("\n");
		}
	}
	scanf("%d",&a);
	}
		return 0;
	}

Measured memory_bytes: 572
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    string S;
    cin >> S;
    bool same = false;
    ll N = S.size();
    set<char> se;
    for(int i=0;i<N;i++){
        se.insert(S[i]);
    }
    if(S[0]==S[N-1]) same = true;
    if(se.size()==2){
        cout << "Second" << endl;
        return 0;
    }
    else if(same){
        cout << ((N-2)%2==0 ? "First" : "Second") << endl;
    }
    else{
        cout << ((N-3)%2==0 ? "First" : "Second") << endl;
    }

    return 0;
}

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

n = int(input())
C = [list(map(int,input().split())) for i in range(n-1)]
ans = 0
for i in range(n-1):
    for j in range(2):
        C[i][j] -= 1
    C[i].sort()
    ans -= (C[i][0]+1) * (n-C[i][1])

for i in range(n):
    ans += (i+1) * (n-i)
print(ans)

Measured memory_bytes: 103372
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define F first
#define S second 
#define pb(n) push_back(n)
const int N=2e5+6;
const ll M=1e9+7;
ll dp[N],a[N],n;
void  rec(int i)
{
	// printf("i= %d\n",i);
	if(dp[i]!=-1)
	{
		// printf("reached here1\n");
		return ;
	}
	
	if(i>=n-1)
	{
		dp[i]=0;
		// printf("reached here2 %d %d\n",i,n-1);
		return ;
	}
	ll ans1=1e18;
	ll ans2=1e18;
	if(i+1<n)
	{
		rec(i+1);
		ans1=abs(a[i]-a[i+1]) + dp[i+1];
	}
	
	if(i+2<n)
	{
		rec(i+2);
		ans2=abs(a[i]-a[i+2]) + dp[i+2];
	}
	// printf("for i= %d and n= %lld ans 1 = %lld ans2 = %lld\n",i,n,ans1,ans2);	
	dp[i]=min(ans1,ans2);
}
int main()
{
	lscn(n);
	for(int i=0;i<n;i++)
		lscn(a[i]);
	
	memset(dp,-1,sizeof(dp));
	
	rec(0);
	// for(int i=0;i<n;i++)
	// 	printf("%lld ",dp[i]);
	lpri(dp[0]);
}

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

using namespace std;

int main(){	
  	int H,W;
  	cin >> H >> W;

	int h,w;
  	cin >> h >> w;
  
  	cout << (H * W - (h * W + H * w) + h * w) << endl;
  
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=b&&b<=c)cout<<a<<" "<<b<<" "<<c<<endl;
    else if(a<=c&&c<=b)cout<<a<<" "<<c<<" "<<b<<endl;
    else if(b<=a&&a<=c)cout<<b<<" "<<a<<" "<<c<<endl;
    else if(b<=c&&c<=a)cout<<b<<" "<<c<<" "<<a<<endl;
    else if(c<=a&&a<=b)cout<<c<<" "<<a<<" "<<b<<endl;
    else cout<<c<<" "<<b<<" "<<a<<endl;
}


Measured memory_bytes: 3096
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<long long, long long> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i, j, k;
    ll X, K, D;
    cin >> X >> K >> D;
    if(abs(X) / D >= K) {
        cout << abs(X) - K * D << endl;
        return 0;
    } else {
        ll r = abs(X) % D;
        ll k = abs(X) / D;
        if(K % 2 == k % 2) {
            cout << r << endl;
        } else {
            cout << D - r << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3648
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    ll q;
    cin>>n;
    ll brr[n+10];
    ll arr[n+10];
    memset(arr,0,sizeof arr);
    memset(brr,0,sizeof brr);
    FOR1(i,n-1)
    {
        cin>>brr[i];
    }
    sum=brr[1];
    for(ll i=2;i<=n-1;i++) sum+=min(brr[i-1],brr[i]);
    sum+=brr[n-1];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
a = []
for i in range(5):
    a.append(int(input()))
k = int(input())
ans = True
for i in range(5):
    for j in range(5):
        if abs(a[i] - a[j]) > k:
            ans = False
if ans:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////

int main(){
    int N,M;
    SCD2(N,M);
    vector<PII> ab,cd;
    REP(i,N){
        int a,b;
        SCD2(a,b);
        ab.PB(MP(a,b));
    }

    REP(i,M){
        int c,d;
        SCD2(c,d);
        cd.PB(MP(c,d));
    }

    REP(i,N){
        int ans = 2000000000;
        int ansnum;
        REP(j,M){
            int a = ab[i].fst;
            int b = ab[i].snd;
            int c = cd[j].fst;
            int d = cd[j].snd;

            int nans = abs(a-c) + abs(b-d);
            if (nans < ans){
                ansnum = j+1;
                ans = nans;
            }
        }
        PRINTD(ansnum);
    }
    return 0;
}

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

using namespace std;

int main(void)
{
  int n; cin>>n;
  vector<string> s(n);
  string str[]={"AC","WA","TLE","RE"};
  int c[4]={0};
  
  for(int i=0;i<n;i++){
    cin>>s[i];
    if(s[i]==str[0]){c[0]++;}
    if(s[i]==str[1]){c[1]++;}
    if(s[i]==str[2]){c[2]++;}
    if(s[i]==str[3]){c[3]++;}
  }
  
  for(int i=0;i<4;i++){
    cout<<str[i]<<" x "<<c[i]<<endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 6420
#include<stdio.h>

int main(void){
    int prime = 700;
    char topping[5];
    scanf("%s", topping);
    for(int i = 0; i < 3; i++){
        if(topping[i] == 'o'){
            prime += 100;
        }
    }
    printf("%d\n", prime);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;
ll GCD(ll x, ll y) {if (x % y == 0) return y;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x * y / GCD(x, y);}

int main(){
  ll n,m,x,y; cin>>n>>m>>x>>y;
  vector<ll>a(n),b(m);
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>b[i];
  sort(all(a));
  sort(all(b));
  if(min(y,b[0])-max(x,a[n-1])>0) cout<<"No War"<<endl;
  else cout<<"War"<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    vector<int> a(n);
    rep(i, n) {
        cin >> a.at(i);
        if (((i + 1) * a.at(i)) % 2 == 1)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int func(int N){
  if(N<10) return N;
  return func(N/10) + N%10;
}
int main() {
  int N;
  cin >> N;
  
  int S = func(N);
  if(N%S == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[101010];
int main()
{
	int n,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		if(a[a[i]]==i)
			ans++;
	ans/=2;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
table = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8],
         [0, 4, 8], [2, 4, 6]]
check = ->(field, type) {table = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8],
         [0, 4, 8], [2, 4, 6]]
check = ->(field, type) {
  table.each do |pat|
    return true if pat.map {|i| field[i] == type}.all?
  end
  false
}
game = ->(field, left) {
  if check.(field, "o")
      "o"
  elsif check.(field, "x")
      "x"
  else
    nxt = (left.size % 2).zero? ? "x" : "o"
    left.each do |pos|
      table[pos] = nxt
      a = game.(table, left.reject {|i| i == pos})
      return a if a
      table[pos] = "s"
    end
    false
  end
}
         
$<.readlines.map(&:chomp).map(&:chars).each do |field|
  left = field.map {|i| i == "s" ? i : nil}.compact
  result = game.(field, left)
  puts result ? result : "d"
end
  table.each do |pat|
    return true if pat.map {|i| field[i] == type}.all?
  end
  false
}
game = ->(field, left) {
  if check.(field, "o")
      "o"
  elsif check.(field, "x")
      "x"
  else
    nxt = (left.size % 2).zero? ? "x" : "o"
    try = proc {|f|
      left.each do |pos|
        field[pos] = nxt
        a = f.()
        return a if a
        field[pos] = "s"
      end
    }
    try.(->{ check.(field, left.reject {|i| i == pos}) })
    try.(->{ game .(field, left.reject {|i| i == pos}) })
    false
  end
}
         
$<.readlines.map(&:chomp).map(&:chars).each do |field|
  left = field.map {|i| i == "s" ? i : nil}.compact
  result = game.(field, left)
  puts result ? result : "d"
end


Measured memory_bytes: 6892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin >>a[i];
    sort(all(a));

    int x = a[n-1], y = -1;
    int d = x+2;
    rep(i,n-1){
        for(int j:{x/2,(x+1)/2}){
            int p = abs(a[i]-j);
            if(p<d){
                d = p;
                y = a[i];
            }
        }
    }
    cout << x << " " << y << "\n";
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _0206
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                bool count = false;
                int ans = -1;
                int a = int.Parse(Console.ReadLine());
                if (a == 0) { break; }
                int go_to = 0;
                for (int i = 0; i < 12; i++)
                {
                    int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    go_to += s[0] - s[1];
                    if (go_to >= a&&count==false) { count = true; ans = i + 1; }
                    if (i == 11) { if (ans == -1) { Console.WriteLine("NA"); } }

                }
                if (ans >= 0) { Console.WriteLine(ans); }

            }
        }
    }
}

Measured memory_bytes: 9736
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
    scanf("%d%d", &a, &b);
    int x = a + b;
    int y = a - b;
    int z = a * b;
    printf("%d\n", max(max(x ,y), z));

    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        System.out.print("");
        int X = sc.nextInt();
        System.out.println("");

        int[] L = new int[N];
        int i;
        for(i = 0; i < N; i++){
            L[i] = sc.nextInt();
            System.out.print("");
        }
        i = 0;
        int c = 1;
        int sum = 0;

        while(sum <= X && N > 0){
            sum += L[i];
            if(sum <= X) c++;
            i++;
            N --;
        }
        System.out.println(c);
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  ll ans = 0;
  int n = s.size();
  REP(msk,1<<(n-1)){
    ll tmp = 0;
    REP(i,n){
      if(i>0 && (msk>>(i-1))&1){
        ans += tmp;
        tmp = 0;
      }
      tmp *= 10;
      tmp += s[i]-'0';
    }
    ans += tmp;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
program main
	implicit none
    integer(16)::x,b,keta,c
    integer::i
    read(*,*)x
    b=x
    c=0
    keta=0_16
    do while(b>0)
    	c=c+mod(b,10)
    	b=b/10_16
        keta=keta+1
    end do
    !write(*,*) keta
    if(x<=9)then
        write(*,*) x
    else if(x/10**(keta-1) ==1)then
    	write(*,*) max(9*(keta-1),c)
    else if(x+1==10**(keta))then
    	write(*,*) max(9*(keta),c)
    else
    	write(*,*) max(9*(keta-1)+x/10**(keta-1) -1,c)
    end if
    !write(*,*) x/(10_16**(keta-1_16))
    stop
end program main




Measured memory_bytes: 2836
N = int(input())
An = list(map(int, input().split()))
s = 0
if N < 2:
  print(s)
else:
  for i in range(N - 1):
    if An[i] > An[i+1]:
      s += An[i] - An[i+1]
      An[i+1] = An[i]
  print(s)

Measured memory_bytes: 32240
//重み付きUnion-Find木
//参考 https://qiita.com/drken/items/cce6fc5c579051e64fab
// verify https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/1/DSL_1_B

#include<iostream>

using namespace std;

typedef long long ll;

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

#define MAX_N 500000//頂点の最大数

ll par[MAX_N];//親の番号
ll urank[MAX_N];//集合のランク
ll usize[MAX_N];//集合の要素数
ll diff_weight[MAX_N];//親との距離
ll num;//集合の数

void init(ll n) {//初期化
    num = n;
    rep(i,n) {
        par[i] = i;
        urank[i] = 0;
        usize[i] = 1;
        diff_weight[i] = 0;
    }
}

ll find(ll x) {//根の添字を返すと同時に経路圧縮をする
    if(par[x] == x) {
        return x;
    }else {
        ll r = find(par[x]);
        diff_weight[x] += diff_weight[par[x]];//累積和
        return par[x] = r;
    }
}

bool same(ll x,ll y) {
    return find(x) == find(y);
}

ll weight(ll x) {//親との距離を求める
    find(x);
    return diff_weight[x];
}

ll diff(ll x,ll y) {//xからyに行くときのポテンシャルの増加分
    return weight(y) - weight(x);
}

ll get_usize(ll x) {//xが属する集合の要素数を返す。
    return usize[find(x)];
}

bool unite(ll x,ll y,ll w) {//weight(y) = weight(x) + w (diff(x,y) = w) となるようにxの属する集合とyの属する集合をマージ
    if(urank[x] < urank[y]) {swap(x,y);w*=-1;}//x(のroot)の下にy(のroot)をつけるので反転

    w += weight(x);w -= weight(y);
    //x(のroot)の下にy(のroot)をつけるので、w=diff(xのroot,yのroot)となるように

    x = find(x);y = find(y);

    if(x == y) {
        return diff(x,y) == w;
    }

    //x(のroot)の下にy(のroot)をつける。
    if(urank[x] == urank[y]) urank[x]++;
    par[y] = x;

    diff_weight[y] = w;

    return true;
}

ll num_set() {
    return num;
}

ll n,q;
int main() {
    cin >> n >> q;
    init(n);

    rep(i,q) {
        ll c,x,y,z;

        cin >> c;
        if(c) {
            cin >> x >> y;
            if(same(x,y)) cout << diff(x,y) << endl;
            else cout << '?' << endl;
        }else {
            cin >> x >> y >> z;
            unite(x,y,z);
        }
    }
    return 0;
}


Measured memory_bytes: 6252
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0; i < n; i++)
using namespace std;

signed main() {
	int h, w, n;
	cin >> n >> h >> w;
	cout << (n - h + 1) * (n - w + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

void Add(ll &a, ll b){
    a=(a+b)%mod;
    return;
}

void Pro(ll &a, ll b){
    a=(a*b)%mod;
    return;
}

int main(){
    string S,T; cin>>S>>T;
    ll s=S.size(), t=T.size();
    ll ans=t;
    rep(i,s-t+1){
        ll Count=0;
        rep(j,t) if(S[i+j]!=T[j]) Count++;
        ans=min(ans,Count);
    }
    cout<<ans<<endl;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int > pp;
typedef pair<int, pp > p;


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

#define MAX_V 100010
struct edge {int to, line, cost;};
int V;
unordered_map<int, vector<edge> > G[MAX_V];
unordered_map<int,int> emerge[MAX_V];
unordered_map<int, ll>  d[MAX_V];
unordered_set<int> s_line;
unordered_set<int> g_line;

void dijkstra(int sta){
    priority_queue<p,vector<p>, greater<p> > que;
    
    for (auto lin:s_line) {
        d[sta][lin]=0;
        que.push( p(0, pp(sta,lin)) );
    }
    while(!que.empty()){
        p pi = que.top(); que.pop();
        pp v = pi.second;
        int sta = v.first;
        int lin = v.second;
        if(d[sta][lin] < pi.first) continue;
        
        // 別の駅
        REP(i,G[sta][lin].size()){
            edge e = G[sta][lin][i];
            if(d[e.to][e.line] > d[sta][lin] + e.cost){
                d[e.to][e.line] = d[sta][lin] + e.cost;
                que.push( p(d[e.to][e.line], pp(e.to,e.line)) );
            }
        }
        
    }
}

int N, M;
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> M;
    
    REP(i,M) {
        int p,q,c;
        cin >> p >> q >> c;
        p--;
        q--;
        
        if(p == 0 || q == 0) {
            s_line.insert(c);
        }
        if(p == N-1 || q == N-1) {
            g_line.insert(c);
        }
        
        G[p][c].pb({q,c,0});
        G[q][c].pb({p,c,0});
        
        if (emerge[p][c]==0){ G[p][c].pb({p,0,1}); G[p][0].pb({p,c,0}); emerge[p][c]=1; }
        if (emerge[q][c]==0){ G[q][c].pb({q,0,1}); G[q][0].pb({q,c,0}); emerge[q][c]=1; }
        
        d[p][c]=INF;
        d[q][c]=INF;
        d[p][0]=INF;
        d[q][0]=INF;
    }
    
    dijkstra(0);
    
    ll ans = INF;
    for(auto lin:g_line) {
        ans = min(ans,d[N-1][lin]);
    }
    
    if (ans < INF) {
        cout << ans + 1 << endl;
    }
    else {
        cout << -1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 110204
T = int(input())

testcase = [list(map(int,input().split())) for i in range(T)]

from functools import lru_cache

@lru_cache(maxsize=None)
def f(n,a,b,c,d):
    if n == 0:
        return 0
    if n == 1:
        return d
    else:
        return min((n-5*(n//5)) * d + c + f(n//5,a,b,c,d),(n-3*(n//3)) * d + b + f(n//3,a,b,c,d),(n-2*(n//2)) * d + a + f(n//2,a,b,c,d),
                   (5*((n+4)//5)-n) * d + c + f((n+4)//5,a,b,c,d),(3*((n+2)//3)-n) * d + b + f((n+2)//3,a,b,c,d),(2*((n+1)//2)-n) * d + a + f((n+1)//2,a,b,c,d),n*d)

for n,a,b,c,d in testcase:
    print(f(n,a,b,c,d))

Measured memory_bytes: 29616
n = int(input())
p = list(map(int,input().split()))
ans = 0

for i in range(n):
    for j in range(i,n):
        q = []
        for x in p:
            q.append(x)
        q[i],q[j] = q[j],q[i]
        sw = 1
        for k in range(n-1):
            if q[k] > q[k+1]:
                sw = 0
                break
        if sw == 1:
            ans = 1
        q = []
print(["NO","YES"][ans])

Measured memory_bytes: 3064
import java.util.*;

class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        int min = 2018;
        if(r / 2019 - l / 2019 >= 1){
            System.out.println(0);
            return;
        }
        l %= 2019;
        r %= 2019;
        for(int i = l; i <= r; i++){
            for(int j = i + 1; j <= r; j++){
                min = Math.min(min, i * j % 2019);
            }
        }
        System.out.println(min);

    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;int main(){long N,O,u,v;cin>>N;O=N*(N+1)*(N+2)/6;
for(int i=1;i<N;i++){cin>>u>>v;O=O-min(u,v)*(N-max(u,v)+1);}
cout<<O;}


Measured memory_bytes: 3584
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 2e9;



int main() {
	string s; cin >> s; 
	regex re("(dream|dreamer|erase|eraser)*");
	if (regex_match(s, re)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


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

#define endl '\n'

void solve(){
    long long a; cin >> a;
    string s; cin >> s;
    long long ans = a*(long long)(s[0] - '0');
    ans += ( (s[2] - '0')*10LL + (s[3] - '0')*1LL) * a / 100;
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1; //cin >> t;
    while(t--) solve();
}

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

int main() {
  int A = 0, B = 0;
  cin >> A >> B;
  int count = 0;
  int sum = B - A + 1;	//A-B間でとりえる整数の総数

  for( int i = 0; i < sum; ++i ){
    int iA = A + i;
    //1桁ずつ切り出す
    string strA = to_string( iA );
    if( strA[0] == strA[4] && strA[1] == strA[3] ){
      ++count;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,m,anss=0ll;
int size[100005],father[100005],ans[100005];

struct edge
{
	int u,v;
}e[100005];

int find(int x)
{
	if (x!=father[x])  father[x]=find(father[x]);
	return father[x];
}

signed main()
{
	cin>>n>>m;
	for (int i=1;i<=m;i++)  cin>>e[i].u>>e[i].v;
	for (int i=1;i<=n;i++)  father[i]=1ll*i;
	for (int i=1;i<=n;i++)  size[i]=1ll;
	
	ans[m]=(1ll*n*n-1ll*n)/2ll;
	
	for (int i=m;i>=1;i--)
	{
		int x=e[i].u,y=e[i].v;
		if (find(x)==find(y))
		{
			ans[i-1]=ans[i];
			continue;
		}
		else
		{
			ans[i-1]=1ll*ans[i]+1ll*size[find(x)]*size[find(y)];
			size[find(x)]+=1ll*size[find(y)];
			father[find(y)]=find(x);
		}
	}
	for (int i=1;i<=m;i++)  cout<<1ll*n*n-n-1ll*ans[i]<<endl;
	
	return 0;
} 

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


int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i,n){
    ll x;
    cin >> x;
    a[i] = x % 1000000007;
  }
  b[0] = a[0];
  rep(i,n-1){
    
      b[i+1] = (b[i] + a[i+1]) % 1000000007;
    
  }
  
  rep(i,n-1){
    ans = (ans + (a[n-1-i] * b[n-2-i]) % 1000000007) % 1000000007;
  }
  
  cout << ans;
  return 0;
}






Measured memory_bytes: 6348
/*
读题不规范，爆零两行泪。
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
const int N=3000,M=3000;
int n,m;
int dp[2*M+1][N+1][2];
int main(){
	cin>>n>>m;
	for(int i=0;i<=m;i++)dp[0][i][i==0]=1;
	for(int i=1;i<=m;i++)for(int j=0;j<=n;j++){
		if(j==0){
			(dp[2*i-1][j][1]+=dp[2*i-2][j][1])%=mod;
			(dp[2*i-1][j][1]+=(dp[2*i-2][j+1][0]+dp[2*i-2][j+1][1])%mod)%=mod;
			(dp[2*i][j][1]+=dp[2*i-1][j][1])%=mod;
		}
		else{
			if(j<n){
				(dp[2*i-1][j][0]+=dp[2*i-2][j][0])%=mod,(dp[2*i-1][j][1]+=dp[2*i-2][j][1])%=mod;
				(dp[2*i-1][j][0]+=dp[2*i-2][j+1][0])%=mod,(dp[2*i-1][j][1]+=dp[2*i-2][j+1][1])%=mod;
			}
			(dp[2*i][j][0]+=dp[2*i-1][j][0])%=mod,(dp[2*i][j][1]+=dp[2*i-1][j][1])%=mod;
			(dp[2*i][j][0]+=dp[2*i-1][j-1][0])%=mod,(dp[2*i][j][1]+=dp[2*i-1][j-1][1])%=mod;
		}
	}
//	for(int j=n;~j;j--){for(int i=0;i<=2*m;i++)printf("(%2d,%2d) ",dp[i][j][0],dp[i][j][1]);puts("");}
	int ans=0;
	for(int i=0;i<=n;i++)(ans+=dp[2*m][i][1])%=mod;
	cout<<ans;
	return 0;
}

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

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

    ll max = 0;
    ll min = 0;
    ll ans = 0;

    for (ll i = k; i <= n; i++)
    {
        min = (i - 1) * i / 2;
        max = (n + n - i + 1) * i / 2;
        ans += max - min + 1;
    }

    cout << ans % (ll)(pow(10, 9) + 7) + 1;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    seika s;
    cin >> s;
    if (s.size() == 3)
    {
        reverse(s.begin(), s.end());
    }
    cout << s << endl;
}

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


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

using namespace std;

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

int main(){
    string o, e;
    cin >> o >> e;
    int n = o.size() + e.size();
    string ans = "";
    rep(i, n){
        if (i % 2 == 0){
            ans += o[i/2];
        }else{
            ans += e[i/2];
        }
    }   
    cout << ans << endl;
}

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

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))

#define FOR(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define REP(i,n) FOR(i,0,n)

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

using ll = long long;

#define abs(x) ((x) > 0 ? (x) : (-(x)))

int main() {
  int n; cin >> n;
  vector<ll> d(n+1);
  d[0] = (ll)0;
  REP(i,n) cin >> d[i+1];
  REP(i,n) d[i+1] += d[i];
  ll ans = INF;
  FOR(i,1,n) {
    ll x = d[i] - d[0];
    ll y = d[n] - d[i];
    chmin(ans,abs(x-y));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int f;
    for(int i = 0; i < s.size(); i++){
        if(s[i]=='A'){
            f=i;
            break;
        }
    }
    int l;
    for(int i = s.size()-1; i>=0; i--){
        if(s[i]=='Z'){
            l=i;
            break;
        }
    }
    cout<<l-f+1;    
}

Measured memory_bytes: 640
use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! {
        n: usize,
        an: [u64; n],
    }
    let mut prev = 0;
    let mut ans = 0;
    for &a in &an {
        if prev < a {
            prev = a;
        } else {
            ans += prev - a;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,j,n) for(int i=j;i<=n;i++)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3,greater<int>());
    cout<<(a[0]*10+a[1])+a[2];
    
    
}   
    
    
     

     
   





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

int main() {
	int t; //cin>>t;
	t=1;
	while(t--){
	    char c;
	    cin>>c;
	    char cc=(char)(((c-'a')+1)+'a');
	    cout<<cc;
	}
	return 0;
}

Measured memory_bytes: 256