akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

        if (H == 1 || W == 1) {
            System.out.println(1);
            return;
        }

        System.out.println(H/2*W+(H%2==0 ? 0 : (W+1)/2));
    }
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  string s; cin >> s;
  
  ll ans = 0;

  ll tc = 0, sc = 0;

  rep(i, s.size()) {
    if(s[i] == 'S') sc ++;
    if(sc > 0 && s[i] == 'T') { tc ++; sc --;}
  }
  ans = s.size() - tc * 2;
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string s;
    std::cin >> s;
    int ret = 0;
    for (int i = 0; i < s.size(); i++) {
        int tmp = 0;
        for (int j = i; j < s.size(); j++) {
            if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') tmp++;
            else break;
        }
        ret = std::max(ret, tmp);
    }
    std::cout << ret << std::endl;

    return 0;
}


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

int main(void){

    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);

    if((a <= 9) && (b <= 9)) printf("%d\n", a*b);
    else printf("-1\n");
    
    
    return 0;
}

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

int main()
 {
 	int n,i,d,c=0;
 	cin>>n>>d;
 	if(n%(2*d+1)==0)
 		c=n/(2*d+1);
 	else
 		c=n/(2*d+1)+1;
 	cout<<c<<endl;
 }

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MOD 1000000007
using namespace std;
using lint = long long;

int main(void)
{
    lint N;
    cin >> N;
    vector<lint> a(N);
    rep(i, N) cin >> a[i];

    lint ans = 1;
    vector<lint> num(N+1, 0);
    num[0] = 3; 
    for(int i = 0; i < N; i++){
        ans = ans * num[a[i]] % MOD;
        num[a[i]]--;
        num[a[i]+1]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	for (int k = 1; k <= B; k++) {
		if (k * A % B == C) {
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define SIZE 1002
int main(){

  int i,j;
  int na,nb,nc,n;
  int a[SIZE],b[SIZE],c[SIZE],d[SIZE];
  int data[SIZE];

  while(1){
  scanf("%d %d %d",&na,&nb,&nc);
  if(na==0 && nb==0 && nc==0)break;
  scanf("%d",&n);

  for(i=1;i<=na+nb+nc;i++)data[i]=2;
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
    if(d[i]==1){
      data[a[i]]=data[b[i]]=data[c[i]]=1;
    }
  }

  for(i=0;i<n;i++){
    if(d[i]==0){
      if(data[a[i]]==1 && data[b[i]]==1)data[c[i]]=0;
      else if(data[a[i]]==1 && data[c[i]]==1)data[b[i]]=0;
      else if(data[b[i]]==1 && data[c[i]]==1)data[a[i]]=0;
    }
  }
  
  for(i=1;i<=na+nb+nc;i++){
    printf("%d\n",data[i]);
  }
  }

  return 0;
}

Measured memory_bytes: 620
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        c: i32,
        k: i32,
        tt: [i32; n],
    };
    let mut t = tt.clone();
    t.sort_by(|a, b| b.cmp(&a));
    let mut dt = std::i32::MAX;
    let mut nc = 0;
    let mut ans = 0;
    for v in t{
        if v >= dt && nc + 1 <= c{
            nc += 1;
            continue;
        }
        dt = v - k;
        ans += 1;
        nc = 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp7
{
	class Program
	{
		static void Main(string[] args)
		{
			var str = Console.ReadLine();
			var q = int.Parse(Console.ReadLine());

			for(int q_i = 0; q_i < q; q_i++)
			{
				var command = Console.ReadLine().Split(' ');
				int a = int.Parse(command[1]);
				int b = int.Parse(command[2]);
				string aa = str.Substring(0, a); //前
				string bb = "";

				if (command[0] == "print")
				{
					if (0 < a && a != b)
					{
						Console.WriteLine(str.Substring(a, b - a + 1));
					}
					else if(a == b)
					{
						Console.WriteLine(str.Substring(b, 1));
					}
					else
					{
						Console.WriteLine(str.Substring(a, b + 1));
					}
				}

				else if(command[0] == "replace")
				{
					string p = command[3]; //置き換える文字列

					//str内の該当する全ての文字が置き換わってしまう
					//str = str.Replace(str.Substring(a, b -a +1), p);/*
					string re = str.Substring(a, b - a + 1); //対象範囲
					re = re.Replace(re, p);
					bb = str.Substring(b + 1, str.Length - b - 1);
					str = aa + re + bb;
				}

				else if(command[0] == "reverse")
				{
					string rs = "";
					
					rs = string.Join("", str.Substring(a, b - a +1).Reverse());
					//int len = str.Length - (a + b);
					//bb = str.Substring(str.Length - len, len); //後
					bb = str.Substring(b + 1, str.Length - b - 1);
					
					//逆順にした部分文字列の前後にくっつける
					str = aa + rs + bb;
				}
			}
		}
	}
}



Measured memory_bytes: 18336
inpl = lambda: list(map(int,input().split()))
N = int(input())
A = inpl()
total = sum(A)
partial = [sum(A[1::2])*2,sum(A[2::2])*2]
A.append(A[0])
A.append(A[1])
ans = [None]*N
for i in range(N):
    ans[i] = total - partial[i%2]
    partial[i%2] += 2*(A[i]-A[i+1])
print(' '.join(map(str,ans)))

Measured memory_bytes: 85988
#include <bits/stdc++.h>
#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 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int a;
	cin >> a;
	int ans = 0;
	if (a / 100 > 12 or a / 100 == 0) ans += 1;
	if (a % 100 > 12 or a % 100 == 0) ans += 2;

	if (ans == 3) cout << "NA" << endl;
	else if (ans == 2) cout << "MMYY" << endl;
	else if (ans == 1) cout << "YYMM" << endl;
	else cout << "AMBIGUOUS" << endl;
}


Measured memory_bytes: 256
l,r = map(int,input().split())
if (r - l) >= 2018:
  print(0)
  exit()
rr = r%2019
lr = l%2019
if lr >= rr:
  print(0)
  exit()
mi = 2018
if (rr - lr) >=673:
  print(0)
  exit()
for i in range(lr,rr):
  for j in range(i+1,rr+1):
    a = (i*j)%2019
    if a < mi:
      mi = a
print(mi)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin>>a>>b;
  cout<<max(a-2*b,0)<<endl;
  

  return 0;

}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String temp;
        String[] buf;
        temp = reader.readLine();
        int N = Integer.parseInt(temp.split(" ")[0]);
        int[] a = new int[N], sorted = new int[N];
        temp = reader.readLine();
        buf = temp.split(" ");
        for(int i=0;i<N;i++){
            int cur = Integer.parseInt(buf[i]);
            a[i] = cur;
            sorted[i] = cur;
        }
        Arrays.sort(sorted);
        int smaller = sorted[N/2-1], bigger = sorted[N/2];
        PrintWriter out = new PrintWriter(System.out);
        int ans = 0;
        for(int i=0;i<N;i++){
            if(a[i]<=smaller) ans = bigger;
            else ans = smaller;
            out.println(ans);
        }
        out.flush();
    }
}

Measured memory_bytes: 53080
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
max = 0 
for i in range(n):
    u = s[i]
    count = 0
    for j in range(n):
        if s[j] == s[i]:
            count = count +1
    for j in range(m):
        if t[j] == s[i]:
            count = count - 1
    if count > max:
        max = count

print(max)
     

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#define lowbit(x) ((x)&(-x))
#define sc scanf
#define debug1(x) cout<<x<<" "
#define debug2(x) cout<<x<<"\n"
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
typedef long long ll;
const ll inf=1e18;
const int N=1e5+10;
ll mod=1e9+7;
using namespace std;
int gcd(int a,int  b){return b==0?a:gcd(b,a%b);}
int arr[N],brr[N];
ll quick_pow(ll a,ll b,ll m)
{
	ll ret=1;
	while(b)
	{
		if(b&1)
		{
			ret*=a;
			ret%=m;
		}
		a*=a;
		a%=m;
		b>>=1;
	}
	return ret;
}
int main()
{
	int k,s;
	while(cin>>k>>s)
	{
		int ans=0;
		for(int i=0;i<=k;i++)
		{
			for(int j=0;j<=k;j++)
			{
				int p=s-i-j;
				if(p<=k&&p>=0)
				ans++;
			}
		}
		cout<<ans<<"\n";
	}	
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    s = S()
    t = S()

    if s==t[:-1]:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 9020
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}

int main() {
    int a,b,c,x;
    cin >> a >> b>>c>>x;
    int res = 0;
    repe(i,a) {
        repe(j,b) {
            repe(k,c) {
                int total = i*500+j*100+k*50;
                if (total == x) {
                    res++;
                }
            }
        }
    }
    cout << res << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#define MAXN 200006
using namespace std;
int u,v,deep[MAXN],n,m,sum[MAXN],vis[MAXN],ok;
long long a,q,p,ans;
vector<int> road[MAXN];
void DFS(int x,int father)
{
	vis[x]=1;
	sum[x]=1;
	deep[x]=deep[father]+1;
	for(int i=0;i<(int)road[x].size();i++)
	{
		int nex=road[x][i];
		if(nex==father) continue;
		if(vis[nex])
		{
			if((deep[nex]+deep[x])%2==0) ok=0;
			continue;
		}
		DFS(nex,x);
		sum[x]+=sum[nex];
	}
}
int main()
{
	//freopen("squared.in","r",stdin);
	//freopen("squared.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		road[u].push_back(v);
		road[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		ok=1;
		DFS(i,0);
		if(sum[i]==1) a++;
		else 
		{
			if(ok==0) p++;
			else q++;
		}
	}
	ans=a*a+2*a*(n-a)+p*p+p*q*2+2*q*q;
	printf("%lld",ans);
}

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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

const int N_MAX = 200002;

int n;

int BIT[N_MAX];

void update (int pos)
{
    for(int i = pos; i >= 1; i -= i & -i)
        BIT[i]++;
}

int query (int pos)
{
    int ans = 0;
    for(int i = pos; i <= 200000; i += i & -i)
        ans += BIT[i];
    return ans;
}

struct Number
{
    int a, b;
};

bool operator < (const Number &x, const Number &y)
{
    return make_pair(x.a, x.b) < make_pair(y.a, y.b);
}

Number v[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        ll val = 0;
        int k = 0;
        for(int j = 0; j < (int)s.size(); j++)
            if(s[j] != '.')
                val = val * 10 + s[j] - '0';
            else
                k = (int)s.size() - j - 1;
        while(val % 2 == 0)
        {
            val /= 2;
            v[i].a++;
        }
        while(val % 5 == 0)
        {
            val /= 5;
            v[i].b++;
        }
        while(k--)
        {
            v[i].a--;
            v[i].b--;
        }
    }
    sort(v + 1, v + n + 1);
    int pos = n + 1;
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        while(pos > 1 && v[pos - 1].a + v[i].a >= 0)
        {
            pos--;
            update(v[pos].b + 100000);
        }
        ans += query(-v[i].b + 100000);
        if(v[i].a >= 0 && v[i].b >= 0)
            ans--;
    }
    cout << ans / 2 << "\n";
    return 0;
}


Measured memory_bytes: 5192
#include <iostream>
#include <string>
#include <queue>
#include <stdexcept>

using std::cin;
using std::cout;

struct process {
  std::string name;
  unsigned time;
};

void execute(std::queue<process>& l,const unsigned q){
  unsigned time_now = 0;

  while(!l.empty()){
    process buf = l.front();
    l.pop();
    if(buf.time <= q){
      time_now += buf.time;
      cout << buf.name << ' ' << time_now << '\n';
    }
    else{
      buf.time -= q;
      time_now += q;
      l.push(buf);
    }
  }
}

int main(){
  std::queue<process> l;
  unsigned n,q;
  cin >> n >> q;
  for(unsigned i=0;i<n;i++){
    process buf;
    cin >> buf.name >> buf.time;
    l.push(buf);
  }

  execute(l,q);
}

Measured memory_bytes: 4396
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long lint;

int main()
{
	int n;
	int len;
	char name[32];
	int ans = 0;
	
	scanf("%d", &n);
	scanf("%s", name);
	
	len = strlen(name);
	
	for (int i = 0; i < n; i++){
		static char query[10240];
		int qlen;
		memset(query, -1, sizeof(query));
		scanf("%s", query);
		qlen = strlen(query);
		
		for (int dx = 1; dx <= 34; dx++){
			for (int pos = 0; pos < qlen; pos++){
				bool ok = true;
				int k = 0;
				for (int p = pos; k != len; p += dx){
					if (name[k] != query[p]){
						ok = false;
						break;
					}
					k++;
				}
				if (ok){
					ans++;
					goto next;
				}
			}
		}
		next:;
	}
	
	printf("%d\n", ans);
	
	return (0);
}

Measured memory_bytes: 1044
#include <stdio.h>
#define Bridge ((long long) 1e18)
 
int main(void){
  int n;
  long long a[100000];
  long long x = 1;
  
  scanf("%d", &n);
  
  for(int i = 0; i < n; i++){
    scanf("%lld", &a[i]);
  }
  
  for(int i = 0; i < n; i++){
    if(a[i] == 0){
      printf("0\n");
      return 0;
    }
  }
   
  for(int i = 0; i < n; i++){
    if(a[i] > Bridge / x){
      printf("-1\n");
      return 0;
    }
    
    x *= a[i];
  }
  
  printf("%lld\n", x);
  
  return 0;
}


Measured memory_bytes: 2508
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<ll,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
 
ll gcd(ll n1,ll n2){
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
int arr[MAX];
int f[MAX];
ll b[MAX];
bool visited[MAX];
vi v[MAX];
int ans[MAX];
int maxi=0;
int dp[MAX];
void DFS(int node)
{
	vi vv;
	for(int i=0;i<v[node].size();i++)
	{
		int child=v[node][i];
		DFS(child);
		vv.pb(dp[child]);
	}
	sort(vv.begin(),vv.end());
	int aaa=vv.size();
	for(int i=vv.size()-1;i>=0;i--)
	{
		dp[node]=max(dp[node],aaa-i+vv[i]);
	}
	//cout<<node<<" "<<dp[node]<<endl;
}
int main()
{
	csl;
	int n;
	cin>>n;
	for(int i=2;i<=n;i++)
		cin>>arr[i];
	arr[1]=0;
	//sort(arr+1,arr+n+1);
	for(int i=1;i<=n;i++)
		v[arr[i]].pb(i);
	DFS(1);
	cout<<dp[1]<<endl;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,A[100005],dp[100005];
int main()
{
  cin>>n>>k;
  for(long long i=1;i<=n;i++)
    cin>>A[i];
  dp[1]=0; 
  for(long long i=2;i<=k;i++)
  {
    dp[i]=99999999999;
    for(long long j=i-1;j>=1;j--)
      dp[i]=min(dp[i],abs(A[i]-A[j])+dp[j]);
  }
  //cout<<dp[2];
  for(long long i=k+1;i<=n;i++)
  {
             dp[i]=9999999999;
    for(long long j=i-1;j>=i-k;j--)
    dp[i]=min(abs(A[i]-A[j])+dp[j],dp[i]);
  }
    //for(long long i=1;i<=n;i++)
    //cout<<dp[i]<<" ";
  cout<<dp[n];
  
}

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

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

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

    if(s=="hi" or s=="hihi" or s == "hihihi" or s == "hihihihi" or s == "hihihihihi"){
        puts("Yes");
    }else puts("No");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());

  cout << d.size() << endl;


  
  return 0;
}

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

int main(){
  ll A, B, C, res = 0;
  cin >> A >> B >> C;
  if (A + B >= C) {
    res = B + C; //全部食べられる
  }else {
    res = B + (A+B+1);
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#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 pair<int, int> P;
typedef long long ll;

int N, M;
int V[10][10];
int pass[10];
int ans;

void solve(int i, int t) {

    if (t == N) {
        bool ok = true;
        rep(v, N) {
            if (!pass[v]) ok = false;
        }
        if (ok) ans++;
        return;
    }

    rep(v, N) {
        if (V[i][v] && !pass[v]) {
            pass[v] = true;
            solve(v, t+1);
            pass[v] = false;
        }
    }

}

int main() {
    cin >> N >> M;
    rep(i,M) {
        int a, b; cin >> a >> b; --a; --b;
        V[a][b] = 1;
        V[b][a] = 1;
    }
    fill(pass, pass+N, false);
    pass[0] = true;
    solve(0, 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int data[100], out[100], i = 0, k = 0;

int top(){
    return data[i - 1];
}

void pop(){
    i--;
}

int main(){
    int x;
    while(scanf("%d", &data[i]) != EOF){
        if(data[i] != 0){
            i++;
        }else{
            out[k] = top() ;
            k++;
            pop();
        }
    }
    for(x = 0; x < k; x++){
        printf("%d\n",out[x]);
    }
    return 0;
}

Measured memory_bytes: 596
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a = vec![1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
    let k: usize = iterator.next().unwrap().parse().unwrap();

    return a[k - 1].to_string();
}


Measured memory_bytes: 2096
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC093 {
	class ABC093_A {
		static void Main(string[] args) {
			var input = Console.ReadLine();
			if(input.Distinct().Count() == input.Count()) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}
		}
	}
}


Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication92
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b=0;
            if (a == 111)
                b = 3;
            else if (a == 100 || a == 010 || a == 001)
                b = 1;
            else if (a == 000)
                b = 0;
            else if (a == 011 || a == 101 || a == 110)
                b = 2;
            Console.WriteLine(b);
        }
    }
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node* Node;
#define NIL NULL
  
struct node a[500000];
int size=0;
  
Node root = NIL;
   
Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}
   
Node treeSearch(Node u, int k){
  Node i=u;
  while(i!=NIL){
    if(i->key==k)return i;
    else if(i->key<k)i=i->right;
    else i=i->left;     
  }
  return NIL;
}
   
Node treeSuccessor(Node x){
  if(x->right!=NIL)return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
   
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
     
  if(y->left!=NIL)x=y->left;
  else x=y->right;
   
  if(x!=NIL)x->parent=y->parent;
     
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;
   
  if(y!=z)z->key=y->key;
     
  //free(y);
}
   
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
   
  z = &a[size++];
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;   
}
  
  
void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
  
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
  
  
int main(){
  int n,x;
  char str[20];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s", str);
    if(str[0]=='f'){
      scanf("%d",&x);
      Node t=treeSearch(root,x);
      if (t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(str[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }
  
  return 0;
}



Measured memory_bytes: 14216
n = int(input())
u=list(input().split())
b=list(input().split())
v=[int(i) for i in u]
c=[int(j) for j in b]
ans=0
for i in range(len(v)):
  if v[i]>c[i]:
    roy=v[i]-c[i]
    ans+=roy
    
print(ans)

        

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        sc.close();

        if ( a < b ) {
        	if ( b < c ) {
        		System.out.println("Yes");
        	}else {
        		System.out.println("No");
        	}
        }else  {
        	System.out.println("No");
        }

	}

}


Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200005];
bool compare(int a,int b){
    return a>b;
}
int main()
{
	int n,k,x;
	cin>>n>>k;
	memset(a,0,sizeof(a));
	for(int i=0;i<n;i++)
	{
	     cin>>x;
	     a[x]++; 
    }
	int ans=0;
	sort(a,a+n,compare);
	for(int i=k;i<=n;i++)
	{
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	basicIO "io"
	"os"
	"strconv"
)

func main() {
	protagonist(os.Stdin, os.Stdout)
}

func protagonist(r basicIO.Reader, w basicIO.Writer) {
	io := NewIO(r, w)
	A, _ := io.nextInt()
	B, _ := io.nextInt()

	var result int
	if A == B {
		result = A + B
	} else if A < B {
		result = B + B - 1
	} else {
		result = A + A - 1
	}
	io.PutInt(result)
}

type IO struct {
	Scanner *bufio.Scanner
	Writer  basicIO.Writer
}

func NewIO(r basicIO.Reader, w basicIO.Writer) *IO {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &IO{
		Scanner: s,
		Writer:  w,
	}
}

func (io *IO) nextString() string {
	io.Scanner.Scan()
	return io.Scanner.Text()
}

func (io *IO) nextInt() (int, error) {
	io.Scanner.Scan()
	i, err := strconv.Atoi(io.Scanner.Text())
	return i, err
}

func (io *IO) PutInt(v int) {
	fmt.Fprintf(io.Writer, "%d\n", v)
}

func (io *IO) PutString(s string) {
	fmt.Fprintf(io.Writer, "%s\n", s)
}


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

int main(){
    string x;
    cin >> x;
    stack<char> s;
    for(char c : x){
        if(s.empty())
            s.push(c);
        else if(s.top() == 'S' && c == 'T')
            s.pop();
        else
            s.push(c);
    }
    cout << s.size() << endl;
    return 0;
}

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

using namespace std;

int main(){
    int A,B,i=1;
    cin >> A >> B;
    
    if(B==1){
        cout << "0" << endl;
    }else if(B<=A){
        cout << "1" << endl;
    }else{
        while(A+i*(A-1)<B){
            i++;
        }
        cout << 1+i << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vector<string> S(N); cin >> S;
    int ans = 0;
    map<string, int> m;
    REP(i, N){
        Sort(S[i]);
        ans += m[S[i]];
        m[S[i]] += 1;
    }
    Out(ans);

    return 0;
}


Measured memory_bytes: 16640
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las
    

main = do
    (a,b,c) <- readTuple3
    print $ max 0 (c-(a-b))



Measured memory_bytes: 380
import collections

mod = 1000000007

def add(a, b):
    return (a + b) % mod

def sub(a, b):
    return (a + mod - b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))

def solve():
    N=int(input())
    S=list(input())
    c=collections.Counter(S)
    ans=1
    for k in c.keys():
        ans = mul(ans,c[k]+1)
    return sub(ans,1)

print(solve())


Measured memory_bytes: 49904
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      String[] S = br.readLine().split(" ");
      int N = Integer.parseInt(S[0]);
      int M = Integer.parseInt(S[1]);
      int sum = 0;
      S = br.readLine().split(" ");
      for(int i = 0; i < M; i++){
        sum += Integer.parseInt(S[i]);
      }
      int ans = N-sum;
      System.out.println(ans < 0 ? -1 : ans);
    }catch(Exception e){
      System.out.println(e.toString());
    }
  }
}

Measured memory_bytes: 34252
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def kari():
    a = list(map(int, input().split()))
    b = map(int, input().split())


def start_process(num, data):
    kouyakusuu1, kouyakusuu2, kouyakusuu3 = gcd(data[0], data[1]), max(data[0], data[1]), min(data[0], data[1])
    # print(kouyakusuu2, kouyakusuu3)

    for i in range(2, num):
        if i == 2:
            a = gcd(data[i], kouyakusuu2)
            b = gcd(data[i], kouyakusuu3)
            kari1 = max(a, b)
            kari2 = kouyakusuu1

            kari3 = gcd(data[i], kouyakusuu1)
        else:
            kari1 = gcd(data[i], kouyakusuu2)
            kari2 = kouyakusuu1

            kari3 = gcd(data[i], kouyakusuu1)



        kouyakusuu1 = kari3
        kouyakusuu2 = max(kari1, kari2)



    print(max(kouyakusuu1, kouyakusuu2))

# def start_process(num, data):
#     for i in range(num)

def main():
    num = int(input())
    data = list(map(int, input().split()))
    start_process(num, data)



if __name__ == '__main__':
    main()


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

#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 repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

vector<vector<int>> tree(200000,vector<int>());
unordered_map<int,int> add;
vector<ll> ans(200000,0);
vector<bool> visited(200000,false);

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

  int n = s.size();
  int sum = 0;
  rep(i,n){
    sum += s[i]-'0';
  }

  ll num = stoll(s);

  if(num%sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 6528
using System;

namespace C___City_Savers
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var Ai = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var Bi = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            long result = 0;
            for (int i = 0; i < N; i++)
            {
                if (Ai[i] >= Bi[i])
                {
                    result += Bi[i];
                }
                else
                {
                    result += Ai[i];
                    long overkill = Bi[i] - Ai[i];
                    if (Ai[i + 1] >= overkill)
                    {
                        result += overkill;
                        Ai[i + 1] -= overkill;
                    }
                    else
                    {
                        result += Ai[i + 1];
                        Ai[i + 1] = 0;
                    }
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 33740
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main(void){
    
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    int ans = 1;
    char preC = S.at(0);
    for(int i=1; i<N; i++){
        if(preC != S.at(i)){
            ans++;
        }
        preC = S.at(i);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using pii = std::pair<int, int>;
using namespace std;

int main() {
  int N;
  cin >> N;
  vec<ll> A(N), B(N), C(N);
  REP(i, N) { cin >> A[i]; }
  REP(i, N) { cin >> B[i]; }
  REP(i, N) { cin >> C[i]; }
  sort(ALL(A));
  sort(ALL(C));

  ll answer = 0;
  REP(i, N) {
    const auto ai = upper_bound(ALL(A), B[i] - 1);
    const auto al = distance(A.begin(), ai);
    const auto ci = lower_bound(ALL(C), B[i] + 1);
    const auto cl = distance(ci, C.end());
    answer += (al * cl);
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
#include <stack>
#include <cmath>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (LL i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<LL> VI;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF*INF;
const int MAX = 400040	;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = 1000LL * 1000 * 1000 + 7;

int n;
VI g[MAX/4];
LL dpT[MAX/4][2];
LL dp(int v, int p, int type)
{
	if(dpT[v][type]!=-1LL)
		return dpT[v][type];
	LL ans=1;
	FOR(i,0,SZ(g[v]))
	{
		int to=g[v][i];
		if(to!=p)
		{
			LL tmp = 0;
			if(type)//if white
				tmp=(tmp+dp(to,v,0))%mod;//black
			tmp=(tmp+dp(to,v,1))%mod;//white
			ans=(ans*tmp)%mod;
		}
	}
	return dpT[v][type]=ans;
}



int main()
{
	//freopen("input.tXXt", "r", stdin);
	ios_base::sync_with_stdio(0);
	FILL(dpT,-1);
	cin >> n;
	FOR(i,0,n-1)
	{
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].PB(b);
		g[b].PB(a);
	}
	cout<<(dp(0,-1,1)+dp(0,-1,0))%mod;
	return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

typedef vector<int> V;
typedef vector<V> VV;
int main(){
    int N,M;
    deque<int> res;
    cin>>N>>M;
    V A(M),B(M);
    VV g(N+1);
    REP(i,M){
        cin>>A[i]>>B[i];
        g[A[i]].pb(i);
        g[B[i]].pb(i);
    }
    V used(N+1,0);
    used[A[0]]=used[B[0]]=1;
    REC(void,int) f1=[&](int v){
        res.push_front(v);
        for(auto &it:g[v]){
            int u=v^A[it]^B[it];
            if(used[u]==0){
                used[u]=1;
                f1(u);return;
            }
        }
    };
    REC(void,int) f2=[&](int v){
        res.push_back(v);
        for(auto &it:g[v]){
            int u=v^A[it]^B[it];
            if(used[u]==0){
                used[u]=1;
                f2(u);return;
            }
        }
    };
    f1(A[0]);
    f2(B[0]);
    cout<<res.size()<<endl;
    for(auto &it:res)cout<<it<<" ";
    cout<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;

const ll INF = 1000000000000000LL;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    ll maxv = -INF;
    int maxi = -1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (maxv < a[i]) {
            maxi = i;
            maxv = a[i];
        }
    }
    if (maxv < 0) {
        cout << maxv << endl;
        cout << n - 1 << endl;
        for (int i = 0; i < n - 1 - maxi; i++) {
            cout << n - i << endl;
        }
        for (int i = 0; i < maxi; i++) {
            cout << 1 << endl;
        }
        return 0;
    }

    vector<int> b[2];
    ll sum[2] = {};
    int l[2] = {-1, -1}, r[2] = {-1, -1};
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] >= 0) {
            sum[i % 2] += a[i];
            if (r[i % 2] == -1) r[i % 2] = i;
            l[i % 2] = i;
        } else {
            b[i % 2].push_back(i);
        }
    }

    int idx = (sum[0] >= sum[1] ? 0 : 1);
    cout << sum[idx] << endl;
    vector<int> ope;
    
    for (int i = 0; i < (int)a.size() - 1 - r[idx]; i++) {
        ope.push_back(n);
        n--;
    }

    for (int i = 0; i < l[idx]; i++) {
        ope.push_back(1);
        n--;
    }

    for (int i : b[idx]) {
        if (i >= l[idx] && i <= r[idx]) {
            ope.push_back(i - l[idx] + 1);
            n -= 2;
        }
    }

    while (n > 1) {
        ope.push_back(2);
        n -= 2;
    }

    cout << ope.size() << endl;
    for (int i : ope) {
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main(){
    var N int

    fmt.Scan(&N)

    P := make([]int, N)

    for i:=0; i<N; i++{
        fmt.Scan(&P[i])
    }

    min := P[0]
    var count int

    for i:=0; i<N; i++ {
        if min>=P[i]{
            min = P[i]
            count++
        }
    }
    fmt.Println(count)
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
     
using namespace std;
     
int main(){
	long long N,M;
	long long ans=0,num=0;
	cin >> N >> M;
	vector<pair<long,long>> P(N);
	for(int i=0;i<N;i++){
		cin >> P.at(i).first >> P.at(i).second;
	}
	
	sort(P.begin(),P.end());

	for(int i=0;i<N;i++){
		int k=0;
		while(k<P.at(i).second){
			if(num<M){
				ans += P.at(i).first;
				num++;
				k++;
			}
			else if(num==M) break;
		}
		if(num==M)break;
	}
	

	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
const int MAXN =  2 * 1e5 + 5;

LL n, a[MAXN], ans;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf ("%lld", &a[i]);
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] < a[i - 1]) {
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	printf ("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n, m;
  cin>>n>>m;
  int a[m];
  int s = 0;
  REP(i, m) cin>>a[i];
  REP(i, m) s += a[i];
  int ans = n - s;
  if(ans < 0) ans = -1;
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 3680
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] a = new int[2][n];
        for(int i = 0 ; i < 2 ; i++ ){
            for(int j = 0 ; j < n ; j++ ){
                a[i][j] = sc.nextInt();
            }
        }
        sc.close();
        int s = 0;
        int k = 0;
        for(int i = 0 ; i < n ; i++ ){
            k = 0;
            for(int j = 0 ; j <= i ; j++ ){
                k += a[0][j];
            }
            for(int j = i ; j < n ; j++ ){
                k += a[1][j];
            }
            s = Math.max(s , k);
        }
        System.out.println(s);
    }
}

Measured memory_bytes: 36244
import queue

N = int(input())

e = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    e[a].append(b)
    e[b].append(a)

even_v = []
odd_v = []

is_reached = [False] * (N+1)
q = queue.Queue()
# [start vertex, total distance]
q.put([1, 0])

# BFS
while not q.empty():
    v, d = q.get()
    if is_reached[v]:
        continue
    is_reached[v] = True
    
    if d%2 == 0:
        even_v.append(v)
    else:
        odd_v.append(v)

    for tv in e[v]:
        q.put([tv, d+1])

r1 = list(range(1, N+1, 3))
r2 = list(range(2, N+1, 3))
r3 = list(range(3, N+1, 3))

ans = [0] * N
if len(even_v) <= len(r3):
    for v in even_v:
        ans[v-1] = r3.pop()
elif len(odd_v) <= len(r3):
    for v in odd_v:
        ans[v-1] = r3.pop()
else:
    for v in even_v:
        if not r1:
            break
        ans[v-1] = r1.pop()
    for v in odd_v:
        if not r2:
            break
        ans[v-1] = r2.pop()
rv = []
rv.extend(r1)
rv.extend(r2)
rv.extend(r3)
for i, p in enumerate(ans):
    if p == 0:
        ans[i] = rv.pop()

print(' '.join(list(map(str, ans))))


Measured memory_bytes: 127360
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut seq = vec![0 as i64; n];
    for i in 0..n {
        seq[i] = read();
    }
    seq.sort();
    let mut best = seq[0];
    let mut best_dist = seq[n - 1] * 2;
    for i in 0..n - 1 {
        let dist = (seq[n - 1] - seq[i] * 2).abs();
        if dist < best_dist {
            best = seq[i];
            best_dist = dist;
        }
    }
    println!("{} {}", seq[n - 1], best);
}


Measured memory_bytes: 4352