akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans=-1,a,b,c,d,tmp,tmpp,m,h,w,x[ohara],y[ohara],sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    rep(i,n)cin>>x[i]>>y[i];
    rep(i,n){
        rep(j,n){
            rep(ii,n){
                rep(jj,n){
                    if(i==ii||j==jj)continue;
                    ll tate1,tate2,yoko1,yoko2;
                    yoko1=min(x[j],x[jj]);
                    yoko2=max(x[j],x[jj]);
                    tate1=min(y[i],y[ii]);
                    tate2=max(y[i],y[ii]);
                    cnt=0;
                    rep(z,n){
                        if(yoko1<=x[z]&&x[z]<=yoko2&&tate1<=y[z]&&y[z]<=tate2)cnt++;
                    }
                    if(cnt<k)continue;
                    tmp=(yoko2-yoko1)*(tate2-tate1);
                    if(ans==-1)ans=tmp;
                    else ans=min(ans,tmp);
                }
            }
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 2432
#include<iostream>

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	int apple[200] = { 0 };
	int absol = 101;
	int sum = 0;
	int count = 0;
	for (int i = 0;i < N;i++) {
		apple[i] = L + i;
		if (absol > abs(apple[i])) {
			absol = abs(apple[i]);
			count = i;
		}
		/*cout << apple[i] << endl;*/
		sum += apple[i];
	}
	cout << sum - apple[count] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll A,B;
int main() {
    cin >> A >> B;
    if (!(A >= 1 && A <=9)) {
        cout << "-1" << endl;
    } else if (!(B >= 1 && B <=9)) {
        cout << "-1" << endl;
    } else {
        cout << A*B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a<=k){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());
	let n: usize = iter.read();

	let nums: Vec<u32> = (0..n).into_iter().map(|_| iter.read()).collect();

	let mut match_count = 0;
	for i in 1..n - 1 {
		if nums[i - 1] < nums[i] && nums[i] <= nums[i + 1] {
			match_count += 1;
		} else if nums[i + 1] < nums[i] && nums[i] <= nums[i - 1] {
			match_count += 1;
		}
	}
	println!("{}", match_count);
}


Measured memory_bytes: 4352
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a;
        long num = 0;
        a = sc.nextInt();
        int list[] = new int[a];
        for(int i = 0;i < a; i++){
            list[i] = sc.nextInt();
            num = num + list[i];
        }
        int max = list[0];
        int min = list[0];
        for(int i = 0; i < list.length; i++){
            if(max < list[i]){
                max = list[i];
            }
            if(min > list[i]){
                min = list[i];
            }
        }
        System.out.println(min + " " + max + " " + num);
    }
}


Measured memory_bytes: 42308
import numpy as np

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

arr = np.zeros((H,W), dtype=np.object)

for h in range(H):
  chars = input()
  for w in range(W):
    #print(chars[w])
    arr[h, w] = chars[w]
h_replace = []
for h in range(H):
  if all([a == '.' for a in arr[h]]):
    h_replace.append( h )

w_replace = []
for w in range(W):
  if all([a == '.' for a in arr[:,w]]):
    w_replace.append( w )

arr = np.delete(arr, h_replace, axis=0)
arr = np.delete(arr, w_replace, axis=1)
[ print(''.join(ar)) for ar in arr.tolist() ]

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

int main(){
	int s7 = 0,s5 = 0;
	for(int i = 1;i <= 3;i++){
		int x;
		cin >> x;
		if(x == 7) s7++;
		if(x == 5) s5++;
	}
	if(s7 == 1  &&  s5 == 2) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cnt[4],n,x,i;
double dp[301][301][301];
double rec(int a,int b,int c){
	if(b<0||c<0||(n-a-b-c)<0)return 0.0;
	if(a==n)return 0.0;
	if(dp[a][b][c]!=0)return dp[a][b][c];
	return dp[a][b][c]=(rec(a+1,b-1,c)*b/n+rec(a,b+1,c-1)*c/n+rec(a,b,c+1)*(n-a-b-c)/n+1)*n/(n-a);
}
int main(){
	cin>>n;
	for(i=0;i<n;i++)cin>>x,cnt[x]++;
	cout<<fixed<<setprecision(10)<<rec(cnt[0],cnt[1],cnt[2]);
}

Measured memory_bytes: 213248
x = int(input())
n = 10 * x
primes = [True] * n
for i in range(2, n):
    if primes[i]:
        for j in range(i * i, n, i):
            primes[j] = False

for i in range(x, n):
    if primes[i]:
        print(i)
        exit()


Measured memory_bytes: 75712
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;  //このネームスペースを使う

int main(){
  int X;

  cin >> X;

  if(X == 3 || X ==5 || X==7){
    cout << "YES" << endl; 
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[101][101],n,m;
int A[1001],B[1001],C[1001];
main(){
	r(i,101)r(j,101)a[i][j]=(i==j?0:1e8);
	cin>>n>>m;
	r(i,m){
		cin>>A[i]>>B[i]>>C[i];
		A[i]--;B[i]--;
		a[A[i]][B[i]]=a[B[i]][A[i]]=min(C[i],min(a[A[i]][B[i]],a[B[i]][A[i]]));
	}
	r(o,n)r(i,n)r(j,n)a[i][j]=min(a[i][j],a[i][o]+a[o][j]);
	int sum=0;
	r(i,m){
		int X=1;
		r(j,n){
			r(k,n){
				if(a[j][k]==a[j][A[i]]+C[i]+a[B[i]][k])X=0;
			}
		}
		sum+=X;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

// const abcd = "abcdefghijklmnopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
// var dx = [...]int{0, 1, 0, -1, 1, -1, -1, 1}
// var dy = [...]int{1, 0, -1, 0, 1, 1, -1, -1}
// var inf int = 1e13

// var mod = 1000000007
var next = newScanner()

// ---------------------------------------------------------

func main() {
	log.SetFlags(log.Lshortfile)
	K := next.Int()
	A := next.Ints(K)

	if A[len(A)-1] > 2 {
		fmt.Println("-1")
		return
	}

	lo := 2
	hi := 2
	for i := len(A) - 1; i >= 0; i-- {
		x := A[i]
		if hi < x {
			fmt.Println("-1")
			return
		}
		nlo := (lo + x - 1) / x * x
		nhi := hi/x*x + x - 1
		if nlo > nhi {
			fmt.Println("-1")
			return
		}
		lo = nlo
		hi = nhi
	}
	fmt.Println(lo, hi)
}

// ------int method-------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}
func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}
func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) int {
	r := 0
	for i := 0; i < len(a); i++ {
		r += a[i]
	}
	return r
}
func pro(a []int) int {
	r := 1
	for i := 0; i < len(a); i++ {
		r *= a[i]
	}
	return r
}
func fill(a []int, n int) []int {
	for i := 0; i < len(a); i++ {
		a[i] = n
	}
	return a
}
func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---------- buffered scanner -----------------------------------------
func iferr(err error) {
	if err != nil {
		log.Println(err)
	}
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) String() string {
	return s.next()
}
func (s *scanner) Int() int {
	v, e := strconv.Atoi(s.next())
	iferr(e)
	return v
}
func (s *scanner) Ints(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = s.Int()
	}
	return r
}
func (s *scanner) Int64() int64 {
	v, e := strconv.ParseInt(s.next(), 10, 64)
	iferr(e)
	return v
}
func (s *scanner) Uint64() uint64 {
	v, e := strconv.ParseUint(s.next(), 10, 64)
	iferr(e)
	return v
}
func (s *scanner) Float64() float64 {
	v, e := strconv.ParseFloat(s.next(), 64)
	iferr(e)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		iferr(e)
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define whole(x) (x).begin(), (x).end()
#define fr first
#define sc second
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
constexpr int INF = 1<<30;
constexpr long long LINF = 1LL<<60;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

int V, E, r;
vector<P> g[100000];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> V >> E >> r;
  rep(i, E) {
    int s, t, d;
    cin >> s >> t >> d;
    g[s].emplace_back(t, d);
  }
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.emplace(0, r);
  vector<ll> d(V, LINF);
  d[r] = 0;
  while(!pq.empty()) {
    P p = pq.top();
    pq.pop();
    if(p.fr > d[p.sc]) continue;
    for(auto e : g[p.sc]) {
      if(chmin(d[e.fr], p.fr+e.sc)) {
        pq.emplace(d[e.fr], e.fr);
      }
    }
  }
  rep(i, V) {
    if(d[i] == LINF) cout << "INF" << '\n';
    else cout << d[i] << '\n';
  }
  return 0;
}


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

int main(){
    int M1,D1,M2,D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if (M1 != M2) cout << 1 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int Inf = 1e9;
const double EPS = 1e-9;



int main()
{
  int n ;
  string s ;
  cin >> n >> s ;
  vector<int> vec(n+1) ;
  vec.at(0) = 0 ;
  
  REP(i,n){
    if(s.at(i)=='I'){
      vec.at(i+1)=vec.at(i)+1 ;
    }
    else if(s.at(i)=='D'){
      vec.at(i+1)=vec.at(i)-1 ;
    }
  }
  
  sort(ALL(vec)) ;
  
  cout << vec.at(n)<<endl ;

  return 0 ;
}




Measured memory_bytes: 256
import math
ans=0
A=[int(input()) for i in range(5)]
a=10
p=0
for i in range(5):
  if a>(A[i]%10) and A[i]%10!=0:
    p=i
    a=A[i]%10
for i in range(5):
  if i==p:
    ans+=A[i]
  else:
    ans+=10*(math.ceil(A[i]/10))
print(ans)

Measured memory_bytes: 9204
n = int(input())
 
g1 = []
g2 = []
g3 = []
 
cnt = 0
 
for i in range(n):
    s = input()
    cnt += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        g3.append(s)
    elif s[0] == "B":
        g1.append(s)
    elif s[-1] == "A":
        g2.append(s)
        
a = len(g1)
b = len(g2)
c = len(g3)
 
if a == b:
    if a == c:
        cnt += c * 2
    elif a > c:
        cnt += c
        cnt += a
    elif a < c:
        if a == 0:
            cnt += c - 1
        else:
            cnt += a
            cnt += c
elif a > b:
    cnt += b
    cnt += c
elif b > a:
    cnt += a
    cnt += c
 
print(cnt)

Measured memory_bytes: 3700
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string s = Console.ReadLine();
		if(s.Substring(0,1)=="W"){
			Console.WriteLine("0");
		} else {
			int[]A = new int[2*N];
			A[0] = 1;
			string t = "B";
			for(var i=1;i<2*N;i++){
				string t2 = s.Substring(i,1);
				if(s.Substring(i,1)!=t){
					A[i] = A[i-1];
				} else {
					A[i] = -A[i-1];
				}
				t = t2;
			}
			int ct = 0;
			long ans = 1;
			long mod = 1000000007;
			for(var i=0;i<2*N;i++){
				if(A[i]==1){
					ct++;
				} else {
					ans = ans * ct % mod;
					ct--;
				}
			}
			if(ct!=0){
				ans = 0;
			} else {
              	for(var i=2;i<=N;i++){
                 	ans = ans * i % mod;
                }
            }
			Console.WriteLine(ans);
		}
	}
}

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

const int N = 6005, M = N << 1, V = 6000;

int n, djq, f[N][M], ans;

int main()
{
	std::cin >> n >> djq; n *= 3;
	f[0][V] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = -i + V; j <= i + V; j++)
		{
			if (i >= 3) f[i][j] = (1ll * (i - 1) * (i - 2)
				* f[i - 3][j] + f[i][j]) % djq;
			if (i >= 2) f[i][j] = (1ll * (i - 1) * f[i - 2][j + 1] + f[i][j]) % djq;
			f[i][j] = (f[i - 1][j - 1] + f[i][j]) % djq;
		}
	for (int i = V; i <= n + V; i++) ans = (ans + f[n][i]) % djq;
	return std::cout << ans << std::endl, 0;
}

Measured memory_bytes: 279936
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
int n,ans;

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++){
        int t=i,temp=t,count=1;
        int x=1,num=2;
        bool flag=false;
        while(t!=1&&t>1){
            if(num>sqrt(temp)){
                count*=2;
                break;
            }
            if(t%num==0){
                x++;
                t/=num;
                flag=true;
            }else{
                if(flag){
                    count*=x;
                    x=1;
                    flag=false;
                }
                num++;
            }
        }
        if(flag)
        count*=x;
        ans+=count;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};
int main() {
  int h,w;
  cin >> h >> w;
  vector<string> M(h);
  rep(i,h){
    cin >> M[i];
  }
  bool ok = true;
  rep(i,h)rep(j,w){
    if(M[i][j] == '#'){
      bool ok2 = false;
      rep(k,4){
        if(i+dx[k]<0 || i+dx[k]>=h || j+dy[k]<0 || j+dy[k]>=w)continue;
        if(M[i+dx[k]][j+dy[k]] =='#')ok2 = true;
      }
      if(!ok2)ok = false;
    }
  }
  puts(ok?"Yes":"No");
  return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int itemCount = inpt[0];
        int ryokinCount = inpt[1];
        int startPos = inpt[2];

        inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();


        int ans = Math.Min(inpt.Where(a=>a<startPos).Count(), inpt.Where(a=>a>startPos).Count());
        Console.WriteLine(ans);
    }



    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



10 7 5
1 2 3 4 6 8 9


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13396
#include <iostream>
using namespace std;
int main(void){
    int n;
    while (cin >> n && n) {
        int count = 0;
        int end = (n + 1) / 2;
        for (int start = 1; start < end; ++start) {
            int sum = start;
            for (int i = start + 1; i <= end; ++i) {
                count += (sum += i) == n;
                if (sum >= n) break;
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 1160
///Coder ---->>>> Kael (Joan Marcos Rivera)
///Team ACM : CyberSpace ____ IPVCE FEDERICO ENGELS
///KingOfString
///Copyright

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;

typedef long long ll;
typedef pair < string , int > par;

#define pb push_back
#define s second
#define mp make_pair
#define f first
#define maxn 100010
#define eps 1e-9
#define mod 50010
#define less(n) order_of_key(n)
#define en_pos(n) find_by_order(n) /// --- >> iterador --- >> empieza en 0

const int oo=1e9+10;

int h[maxn],dp[maxn];
int main() {

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

    int n;

    cin >> n;

    for(int i=1;i<=n;i++){
        cin >> h[i];
        dp[i]=oo;
    }

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

    cout << dp[n];
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[394][394];
int l[393];
int r[393];
int p[393];
int ans[393];
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d%d%d",l+i,r+i,p+i);
	}
	for(int i=0;i<394;i++)
		for(int j=0;j<394;j++)
			dp[i][j]=-99999999;
	dp[0][0]=0;
	for(int i=1;i<=a;i++){
		for(int j=0;j<394;j++){
			dp[i][j]=max(dp[i][j],dp[i-1][j]);
			for(int k=l[i-1];k<=r[i-1];k++){
				if(j-k>=0){
					dp[i][j]=max(dp[i][j],dp[i-1][j-k]+p[i-1]);
					dp[i][j]=max(dp[i][j],dp[i][j-k]+p[i-1]);
				}
			}
		}
	}
	int b;
	bool ok=true;
	scanf("%d",&b);
	for(int i=0;i<b;i++){
		int c;
		scanf("%d",&c);
		ans[i]=dp[a][c];
		if(ans[i]<0)ok=false;
	}
	if(ok){
		for(int i=0;i<b;i++)printf("%d\n",ans[i]);
	}else printf("-1\n");
	
}

Measured memory_bytes: 1636
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int ns,nl,cnt;
int vec[12][12];
bool used[12][12];
vector<int> dis;
const int INF = 1<<30;
 
void permutation(int s,int cost,vector<int> P){
  bool fin = true;
   
  for(int i=1;i<=ns;i++){
    if(!used[s][i] && vec[s][i] != INF && i!=s){
      fin = false;
      P.push_back(i);
      used[s][i] = used[i][s] = true;
      permutation(i,cost+vec[s][i],P);
      used[s][i] = used[i][s] = false;
      P.pop_back();
    }
  }
   
  if(fin){
    if(cnt <= cost){
      if(cnt == cost){
    bool AorB = false;//true -> dis, false -> P
    for(int i=0;i<min(dis.size(),P.size());i++){
      if(dis[i] > P[i]){
        AorB = false;
        break;
      }
      else if(dis[i] < P[i]){
        AorB = true;
        break;
      }
    }
    if(!AorB){
      dis.clear();
      copy(P.begin(),P.end(),back_inserter(dis));
    }
      }
      else if(cnt < cost){
    dis.clear();
    copy(P.begin(),P.end(),back_inserter(dis));
      }  
      cnt = cost;
    }
  }
 
}
 
int main(){
  int s1,s2,d;
  
  while(true){
    cin >> ns >> nl;
    if(ns+nl == 0)break;
    dis.clear();
    dis.push_back(9999999);
    for(int j=0;j<12;j++)for(int i=0;i<12;i++){
    vec[i][j]=INF;   
    used[j][i] = false;
      }
    cnt = 0;
 
    for(int i=0;i<nl;i++){
      cin >> s1 >> s2 >> d;
      vec[s1][s2] = vec[s2][s1] = d;
    }
 
    vector<int> pos;
    for(int i=1;i<=ns;i++){
      pos.push_back(i);
       
      permutation(i,0,pos);
      for(int k=0;k<12;k++)for(int j=0;j<12;j++)used[k][j] = false;
      pos.pop_back();
    }
    cout << cnt << endl;
    for(int i=0;i<dis.size();i++){
      cout << dis[i];
      if(i == dis.size()-1)cout<< endl;
      else cout << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <map>
#include <queue>
using namespace std;

struct bug{
	string name;
	int tim;
};

int main()
{
	string worm;
	while(cin >> worm){
		if(worm == "0"){
			break;
		}
		map<string,int> memo;
		bug w;
		w.name = worm;
		w.tim = 0;
		queue<bug> que;
		que.push(w);
		bool fl = false;
		while(que.size()){
			bug tmp = que.front();
			que.pop();
			//êF»è
			bool flag = true;
			for(int i=0;i<tmp.name.size();i++){
				if(tmp.name[0] != tmp.name[i]){
					flag = false;
					break;
				}
			}
			if(flag){
				fl = true;
				cout << tmp.tim << endl;
				break;
			}
			//êxo½©»è
			if(memo.find(tmp.name) != memo.end())
				continue;
			else
				memo[tmp.name] = tmp.tim;

			//ÇÁ
			for(int i=0;i<tmp.name.size();i++){
				if(tmp.name[i] != tmp.name[i+1]){
					bug t = tmp;
					if((tmp.name[i] == 'r' && tmp.name[i+1] == 'g') || (tmp.name[i] == 'g' && tmp.name[i+1] == 'r') ){
						t.name[i] = 'b'; t.name[i+1] = 'b';
					}else if((tmp.name[i] == 'g' && tmp.name[i+1] == 'b') || (tmp.name[i] == 'b' && tmp.name[i+1] == 'g') ){
						t.name[i] = 'r'; t.name[i+1] = 'r';
					}else if((tmp.name[i] == 'b' && tmp.name[i+1] == 'r') || (tmp.name[i] == 'r' && tmp.name[i+1] == 'b') ){
						t.name[i] = 'g'; t.name[i+1] = 'g';
					}
					t.tim++;
					que.push(t);
				}
			}
		}
		if(!fl)
			cout << "NA" << endl;
	}
	return 0;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  cout<<(a*b)/2<<endl;
}



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

int main(){
    string s;
    cin>>s;
    int a=0,b=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='0')a++;
        else b++;
    }
    //this question was so tricky ,i loved it 
    //even thought it seems that we have to use some other data structure the logic and formation is so easy
    cout<<min(a,b)*2;
}


Measured memory_bytes: 512
use std::io;


fn main() {
    let (n, d) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let mut x = Vec::new();
    for _ in 0..n {
        x.push(read::<isize>());
    }

    let mut cnt = 0;
    for i in 0..n { for j in (i + 1)..n {
        let mut norm = 0;
        for k in 0..d {
            norm += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }

        let mut f = false;
        for k in 0..norm + 1 {
            if k * k == norm { f = true; }
        }

        if f { cnt += 1; }
    }}

    println!("{}", cnt);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
n, t = map(int, input().split())
food = []
for i in range(n):
    food.append(list(map(int, input().split())))

food.sort()

#dp[i][j]: i番目までの料理をいくつか食べて、時間jまでに注文した美味しさの合計のmax
dp = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(n):
    for j in range(t+1):
        a, b = food[i]
        if j == t:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

        elif j + a >= t:
            dp[i+1][t] = max(dp[i][j] + b, dp[i+1][t])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

        else:
            dp[i+1][j+a] = max(dp[i][j] + b, dp[i+1][j+a])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

print(dp[n][t])


Measured memory_bytes: 124248
#include <stdio.h>

int main(void)
 {
   
  int a;
  int b;
  for (a = 1; a<= 9;a++){
  
  for (b = 1; b<= 9;b++){
   
  printf("%dx%1d=",a,b);
 	 
   printf("%d\n"  ,a *b);	
	}}
  return 0;
 }

Measured memory_bytes: 524
def main():
    N, K = map(int, input().split())
    A = map(int, input().split())
    u = [1] + [0] * K
    v = [1] + [0] * K
    s = 1
    for a in A:
        u, v = v, u
        s += a
        c = 0
        for i, t in enumerate(u[:a + 1]):
            c += t
            v[i] = c
        for i, t, tt in zip(range(a + 1, K + 1), u[a + 1:s], u):
            c += t - tt
            v[i] = c
    print(v[K] % (10 ** 9 + 7))

main()


Measured memory_bytes: 38504
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;

const int mod = 1000000007;
static const int N = 100001;
vector< vector<int> > M(N);
vector<int> visited(N, 0);

void bfs(int s, vector<int>& D);
void dfs(int st, int d, vector<int>& D);

int n;

int main() {
    int T, A;
    cin >> n >> T >> A;
    T--; A--;

    int a, b;
    for (int i = 0; i < n-1; i++) {
        cin >> a >> b;
        a--; b--;
        M[a].push_back(b);
        M[b].push_back(a);
    }

    vector<int> T_dis(N, -1);
    vector<int> A_dis(N, -1);
    //bfs(T, T_dis);
    //bfs(A, A_dis);

    dfs(T, 0, T_dis);
    for (int i = 0; i < N; i++) visited[i] = 0;
    dfs(A, 0, A_dis);

    /*
    for (int i = 0; i < n; i++) {
        cout << T_dis[i] << " | " << A_dis[i] << '\n';
    }
    */

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (T_dis[i] < A_dis[i]) {
            ans = max(ans, T_dis[i] + max(0, A_dis[i] - T_dis[i] - 1));
        }
    }
    cout << ans << '\n';

}

void bfs(int s, vector<int>& D) {
    queue<int> q;
    D[s] = 0;
    q.push(s);
    int u;
    while ( !q.empty() ) {
        u = q.front(); q.pop();
        for (int i = 0; i < M[u].size(); i++) {
            int cur_node = M[u][i];
            if (D[cur_node] != -1) continue;
            D[cur_node] = D[u] + 1;
            q.push(cur_node);
        }
    }
}

void dfs(int st, int d, vector<int>& D){
    D[st] = d;
    visited[st] = 1;
    for(auto i : M[st]){
        if(!visited[i]){
            dfs(i, d + 1, D);
        }
    }
}


Measured memory_bytes: 10752
#include <cstdio>
#include <algorithm>
using namespace std;

int can[2][101];
int dp[2][101];

int main(){
	int N;
	scanf("%d", &N);
	for(int i=0; i<2; ++i){
		for(int j=0; j<N; ++j)
			scanf("%d", &can[i][j]);
	}
	for(int j=N-1; j>=0; --j){
		dp[1][j] = can[1][j] + dp[1][j+1];
		dp[0][j] = can[0][j] + max(dp[0][j+1], dp[1][j]);
	}
	printf("%d\n", dp[0][0]);
}


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

int n, m, a, s = 0;
const int MAXN = 1e4 + 10;

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

    cin >> n >> m;
    for(int i = 0; i < m; ++i) {
        cin >> a;
        s += a;
    }

    if(s > n) cout << -1 << "\n";
    else cout << n - s << "\n";

    return 0;
}


Measured memory_bytes: 3492
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<list>
#include<iomanip>
#include<cstring>
#include<queue>
#define h 200010
#define lli long long int
#define pb push_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
using namespace std;
vector<lli>par(h);
lli func(lli a) 
{
	if(par[a]==a) return a;
	else return par[a]=func(par[a]);
} 
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli n, e, i, x, y, u, v, ans=0,l=0,cnt;
	set<lli>c;
	cin>>n>>e;
	for(i=0;i<=n;i++) 
	par[i]=i;
	for(i=0;i<e;i++) 
	{
		cin>>x>>y;
		u=func(x);
		v=func(y);
		if(u!=v) par[u]=v;
	} 
	for(i=1;i<=n;i++) 
	u=func(i);
	sort(par.begin()+1,par.begin()+n+1);
	cnt=1;
	for(i=1;i<=n;i++) 
	{
		c.insert(par[i]);
		if(l==c.size()) cnt+=1;
		else {l+=1;ans=max(ans,cnt);cnt=1;} 
	} 
	ans=max(ans,cnt);
	cout<<ans<<endl;
  return 0;
} 



Measured memory_bytes: 14116
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;


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



int main() {
    int n;
    //3*5*7
    //3*3*3*5
    //3*5*11
    //3*5*13
    //
    cin >> n;
    int ans = 0;
    if (n < 105) {
        ans = 0;
    }
    else if (n < 135) {
        ans = 1;
    }
    else if (n < 165) {
        ans = 2;
    }
    else if (n < 189) {
        ans = 3;
    }
    else if (n < 195) {
        ans = 4;
    }
    else {
        ans = 5;
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S; cin >> S;
    rep(i,S.size()) {
        if (i % 2 == 0) {
            if (S.at(i) == 'L') {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if (S.at(i) == 'R') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
def pow(a, n, MOD=1):
    """
    繰り返し二乗法 (半分の数の 2 乗) / 自乗
    Compute nth power of a -- O(logn)
    """
    if n == 0:
        return 1
    x = pow(a, n//2, MOD)
    x = (x%MOD * x%MOD) % MOD
    if n%2 == 1:
        x = (x%MOD * a%MOD) % MOD
    return x


MOD = 1_000_000_007
m, n = map(int, input().split())
print(pow(m, n, MOD))


Measured memory_bytes: 5612
#include <cstdio>

int tor[300001];
int tol[300001];

int main()
{
  int n;
  char s[300001];
  scanf("%d%s", &n, s);
  for (int i = 0; s[i]; ++i)
  {
    tor[i + 1] = tor[i] + (s[i] == 'W' ? 1 : 0);
  }
  for (int i = n - 1; i > 0; --i)
  {
    tol[i - 1] = tol[i] + (s[i] == 'E' ? 1 : 0);
  }
  int ans = 1e8;
  for (int i = 0; i < n; ++i)
  {
    if (ans > tor[i] + tol[i]) ans = tor[i] + tol[i];
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 2816
#include<stdio.h>
int main(void){
	int a[3];
    for(int i=0;i<3;i++){
    	scanf("%d",&a[i]);
    }
    if(a[0]+a[1]+a[2]>=22){
    	printf("bust\n");
    }else{
    	printf("win\n");
    }
    return(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
const int MOD=1e9+7;
using pii=std::pair<int,int>;
using namespace std;

int x;

int check(int a, int b)
{
    int ap5 = 1, bp5 = 1;
    for(int i = 0; i < 5; i++)
    {
        ap5 *= a;
        bp5 *= b;
    }
    return ap5 - bp5 == x;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> x;
    for(int a = 0; a < 4000; a++)
        for(int b = -4000; b < a; b++)
            if(check(a, b))
            {
                cout << a << " " << b << "\n";
                return 0;
            }
    assert(false);
    return 0;
}

Measured memory_bytes: 3608
N, A, B = map(int,input().split())
S = input()
count1 = 0
count2 = 0
for s in S:
  if s == "a" and count1 < A+B:
    count1 += 1
    print("Yes")
  elif s =="b" and count1 < A+B and count2 < B:
    count1 += 1
    count2 += 1
    print("Yes")
  else:
    print("No")
    

Measured memory_bytes: 4016
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let n: usize;
    input!(n);

    let mut ans = 0;

    for i in 1..n/2+1 {
        if n - i != i {
            ans += 1;
        }
    }
    p(ans);
}


Measured memory_bytes: 4352
/*
 *
 *   Author     : Amit Kumar
 *   Date 	: June 22, 2019
 * 
 */

#include <bits/stdc++.h>

//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define _ub upper_bound
#define _lb lower_bound
#define bint long long int
#define _in(x) scanf("%lld",&x)
#define _f first
#define _s second
#define _all(x) x.begin(),x.end()
#define _pb push_back
#define _eb emplace_back
#define _mp make_pair
#define _iv(v) for(auto &i:v){cin>>i;}
#define _ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define _ovn(v) for(auto i:v){cout<<i<<endl;}
#define _euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define _eovn(v) for(auto i:v){cerr<<i<<endl;}
#define _os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define _osn(s) for(auto itr:s){cout<<itr<<endl;}
#define _eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define _eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define _rep(x) for(auto i=0 ; i<(x); ++i)
#define _repe(x) for(auto i=0; i<=(x); ++i)
#define _irep(a,b) for(auto i=(a); i<(b); ++i)
#define _irepe(a,b) for(auto i=(a); i<=(b); ++i)
#define _crep(a,b,c) for(auto i=(a); i<(b); i+=(c))
#define _crepe(a,b,c) for(auto i=(a); i<=(b); i+=(c))
#define _min(x,y) ((y) ^ (((x) ^ (y)) & (-((x) < (y)))))
#define _max(x,y) ((x) ^ (((x) ^ (y)) & (-((x) < (y)))))
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 
    

    bint w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<.5 * w * h<<" "<<(2*x==w and 2*y==h)<<endl;



    return ;
}




int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(9);
    cout<<fixed;
//    cout<<boolalpha;
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[200000], b[200000], bit[262145];
void add(int i, int x) {
	while (i <= n) bit[i] += x, i += i & -i;
}
int sum(int i) {
	int ret = 0;
	while(i > 0) ret += bit[i], i -= i & -i;
	return ret;
}
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]), b[i] = a[i];
	sort(b, b + n);
	long long ret = 0;
	for(int i = 0; i < n; i++) {
		int ptr = lower_bound(b, b + n, a[i]) - b; add(ptr + 1, 1);
 		ret += i - sum(ptr + 1);
	}
	printf("%lld\n", ret + n);
	return 0;
}

Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
ll r[2019];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  ll p=1,ans=0,t=0;
  r[0]++;
  for(int i=s.size()-1;i>=0;i--){
    t = (t + p*(s[i]-'0')) % 2019;
    ans+=r[t]++;
    p = (p*10)%2019;
  }
  cout << ans << endl;
}


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

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

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

int dp[10001][101];

void solve()
{
    int K, T;
    cin >> K >> T;

    int sum = 0;
    int a_max = 0;
    REP0 (i, T)
    {
        int a;
        cin >> a;
        sum += a;
        a_max = max(a, a_max);
    }

    if (T == 1)
    {
        cout << sum - 1 << endl;
        return;
    }

    cout << max(0, a_max - (sum - a_max) - 1) << endl;
}

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


Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    dai=max(p[i-1],p[i],p[i+1])
    syo=min(p[i-1],p[i],p[i+1])
    if p[i]!=dai:
        if p[i]!=syo:
            ans=ans+1
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000
struct Card{
  char suit;
  int value;
};
struct Card L[MAX / 2 + 2],R[MAX / 2 + 2];

void merge(struct Card A[],int n,int left,int mid,int right){
  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0;i < n1;i++){
      L[i] = A[left + i];
  }
  for(i=0;i < n2;i++){
      R[i] = A[mid + i];
  }
  L[n1].value = R[n2].value = SENTINEL;

  i = j = 0;
  for(k = left;k < right;k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}
void mergeSort(struct Card A[],int n,int left,int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}
int partition(struct Card A[],int n,int p,int r){
  int i,j;
  struct Card t,x;
  x=A[r];
  i = p-1;
  for(j = p;j < r;j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t= A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;
  return i+1;
}
void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p < r){
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}


int main(){
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable = 1;
  scanf("%d",&n);
  for(i=  0;i < n;i++){
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }
  mergeSort(A,n,0,n);
  quickSort(B,n,0,n - 1);
  for(i = 0;i < n;i++){
    if(A[i].suit != B[i].suit){
        stable=0;
    }
  }
  if(stable == 1){
      printf("Stable\n");
  }
  else printf("Not stable\n");
  for(i = 0;i < n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }
  return 0;
}


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

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

int n,m;
vector<vector<pair<int,int>>> graph;
vector<bool> checked;
vector<ll> x;

void dfs(int s,ll p){
    
    if(checked[s]){
        if(p!=x[s]){
            cout<<"No"<<endl;
            exit(0);
        }else{
            return;
        }
    }
    x[s]=p;
    checked[s]=true;
    for(int i=0;i<graph[s].size();i++){
        dfs(graph[s][i].first,(ll)graph[s][i].second+x[s]);
    }
    
    return;
}


int main(){
    
    cin>>n>>m;
    graph.resize(n);
    checked.resize(n);
    x.resize(n);
    //for(int i=0;i<n;i++) x[i]=0;
    
    //for(int i=0;i<n;i++) checked[i]=false;
    
    
    for(int i=0;i<m;i++){
        int l,r,d;
        cin>>l>>r>>d;
        l--;
        r--;
        
        graph[l].push_back(make_pair(r,d));
        graph[r].push_back(make_pair(l,-d));
    }
    for(int i=0;i<n;i++){
        if(checked[i]) continue;
        dfs(i,0);
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		string s;
		cin >> s;
		int n = s.length();
		for(int i=0; i < n; i++){
			if(i < n-1 && s[i] == s[i+1]){
				cout << i + 1 << " " << i + 2 << endl;
				return;
			}
			if(i < n-2 && s[i] == s[i+2]){
				cout << i + 1 << " " << i + 3 << endl;
				return;
			}
		}
		cout << "-1 -1\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}

	void doIt() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		if ((a * b) % 2 == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");

		}
	}
}

Measured memory_bytes: 21844
///////////////////////////////////////////////////////////////////////////
// /*Dis = size of the program || TLE. */
/*
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
*/
// #pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops") /* D = Too many loops */

#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define MOD 1000000007
#define pi acos(-1.0)
#define MAX 10000001
//////////////////////////////////////////////////////////////////////////
/* Custom function starts here */

/* Custom function ends here: */
//////////////////////////////////////////////////////////////////////////////

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  /* MAIN Code STARTS here: */

    string str;
    cin >> str;
    int even{}, odd{};

    map<int, int> map;
    for(int i = 0; i<str.size(); i++){
        if(map.count(str[i]) == 0 ){
            map.insert(make_pair(str[i], 1));
        }
        else{
            map[str[i]]++;
        }
    }

    auto itr = map.begin();
    auto itr2 = map.end();

    for(; itr != itr2; itr++){
        if(itr -> second %2 == 0){
        even = 1;
        }
        else{
            even = 0;
            break;
        }
    }

    if(even == 1){
        cout << "Yes" << endl;
    }
    else if(even == 0){
        cout << "No" << endl;
    }
  /* MAIN Code ENDS here: */
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> vec(n);
    vector<int> vec2(n);

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

    sort(vec.begin(), vec.end());
    int firstmax = vec[n-1];
    int secondmax = vec[n-2];

    for (int i = 0; i < n; i++)
    {
        if (vec2[i] == firstmax)
        {
            cout << secondmax << endl;
        }
        else
        {
            cout << firstmax << endl;
        }
    }
}


Measured memory_bytes: 3200