akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	m := make([]map[rune]int, n)
	chars := make(map[rune]rune)

	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		m[i] = make(map[rune]int)
		for _, c := range s {
			m[i][c]++
			chars[c] = c
		}
	}

	ss := make(map[string]int)
	for _, c := range chars {
		tc := 999
		for i := 0; i < n; i++ {
			t := m[i][c]
			if t < tc {
				tc = t
			}
		}
		if tc > 0 {
			ss[string(c)] = tc
		}
	}

	keys := make([]string, len(ss))
	for k := range ss {
		keys = append(keys, string(k))
	}
	sort.Strings(keys)
	for _, k := range keys {
		fmt.Print(strings.Repeat(k, ss[k]))
	}
	fmt.Println()
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T>
inline bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<vector<int>> dist(n, vector<int>(n, -1));
    for (int i = 0; i < n; i++){
        queue<int> q;
        q.push(i);
        dist[i][i] = 0;
        while (!q.empty()){
            int a = q.front();
            q.pop();
            if (a != n - 1 && dist[i][a + 1] == -1){
                q.push(a + 1);
                dist[i][a + 1] = dist[i][a] + 1;
            }
            if (a != 0 && dist[i][a - 1] == -1){
                q.push(a - 1);
                dist[i][a - 1] = dist[i][a] + 1;
            }
            if (a == x && dist[i][y] == -1){
                q.push(y);
                dist[i][y] = dist[i][a] + 1;
            }
            if (a == y && dist[i][x] == -1){
                q.push(x);
                dist[i][x] = dist[i][a] + 1;
            }
        }
    }
    vector<int> result(n, 0);
    rep(i, n){
        rep(j, n){
            result[dist[i][j]]++;
        }
    }
    repk(i,1, n)
        cout << result[i] / 2 << endl;
    return 0;
}   

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int w,h,n;
int x[101],y[101];
int dp[101][501];

int main(void){
	scanf("%d%d%d",&w,&h,&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&x[i],&y[i]);
		x[i]--;
		y[i]--;
	}
	priority_queue<PP,vector<PP>,greater<PP> > que;
	for(int i=0;i<n;i++){
		for(int j=0;j<=500;j++){
			dp[i][j]=50000;
		}
	}
	for(int i=0;i<n;i++){
		int di=x[i]+y[i];
		dp[i][di]=di;
		que.push(PP(di,P(i,di)));
	}
	while(que.size()){
		PP p=que.top();
		que.pop();
		int v=p.second.first;
		int len=p.second.second;
		int cost=p.first;
		if(dp[v][len]<cost)continue;
		for(int i=0;i<n;i++){
			int di=abs(x[i]-x[v])+abs(y[i]-y[v]);
			int nc=max(0,di-1-len);
			if(dp[i][nc]>dp[v][len]+nc){
				dp[i][nc]=dp[v][len]+nc;
				que.push(PP(dp[i][nc],P(i,nc)));
			}
		}
	}
	int ans=50000;
	for(int i=0;i<n;i++){
		int di=abs(w-1-x[i])+abs(h-1-y[i]);
		for(int j=0;j<=500;j++){
			ans=min(ans,dp[i][j]+max(0,di-j));
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
#define int long
void fail() {
    cout << "No";
    exit(0);
}
signed main() {
    int n;
    map<char, int> var;
    cin >> n >> var['A'] >> var['B'] >> var['C'];
    vector<string> str(n);
    vector<char> res(n);
    for (auto& i : str) cin >> i;
    for (int i = 0; i < n; ++i) {
        char c0 = str[i][0], c1 = str[i][1];
        if (!var[c0] && !var[c1]) fail();
        if (!var[c0])
            ++var[c0], --var[c1], res[i] = c0;
        else if (!var[c1])
            ++var[c1], --var[c0], res[i] = c1;
        else {
            if (i + 1 < n && str[i + 1] != str[i]) {
                if (str[i + 1][0] == c0 || str[i + 1][1] == c0)
                    ++var[c0], --var[c1], res[i] = c0;
                else
                    ++var[c1], --var[c0], res[i] = c1;
            } else {
                if (var[c0] < var[c1])
                    ++var[c0], --var[c1], res[i] = c0;
                else
                    ++var[c1], --var[c0], res[i] = c1;
            }
        }
    }
    cout << "Yes" << endl;
    for (auto ch : res) cout << ch << endl;
}

Measured memory_bytes: 6832
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;
int a[5];


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    int timeSum = 0;
    int min = 10;
    for(int i = 0; i < 6;i++){
        if(a[i]%10 != 0){
            if(a[i]%10 < min) min = a[i]%10;
            timeSum += (a[i]/10+1)*10;
        }else{
            timeSum += a[i];
        }
       
        
    }
     cout << timeSum - 10 + min << endl;

    

    return 0;
}

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

int main(int argc, char const *argv[]){
	int cnt = 0;
	string cf2016 = "CODEFESTIVAL2016";
	string s;
	cin >> s;
	for (int i = 0; i < cf2016.size(); ++i)
	{
		if(cf2016.at(i) != s.at(i))	++cnt;
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    vvi p(n);
    REP(i, n) {
      int m; cin >> m;
      p[i].resize(m);
      REP(j, m) {
        cin >> p[i][j];
      }
      sort(ALL(p[i]));
    }
    int k; cin >> k;
    vi l(k);
    REP(i, k) cin >> l[i];
    sort(ALL(l));

    int ans = -1;
    REP(i, n) {
      bool ok = true;
      int ltmp = 0;
      int j = 0;
      while(ltmp < k) {
        if(j >= SZ(p[i]) || l[ltmp] < p[i][j]) {
          ok = false;
          break;
        } else if(l[ltmp] == p[i][j]) {
          ltmp++;
          j++;
        } else {
          j++;
        }
      }
      if(ok && ans == -1) ans = i+1;
      else if(ok) {
        ans = -1;
        break;
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3136
#include <iostream>

using namespace std;

int main () {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  if (S.at(K - 1) == 'A') S.at(K-1) = 'a';
  if (S.at(K - 1) == 'B') S.at(K-1) = 'b';
  if (S.at(K - 1) == 'C') S.at(K-1) = 'c';

  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
using namespace std;

const ll N = 1e6+5;
const ll MOD = 1e9+7;

int main()
{


    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    char c;
    cin >> c;
    if(c == 'A')cout << "T\n";
    if(c == 'T') cout << "A\n";
    if(c=='C') cout << "G\n";
    if(c=='G') cout << "C\n";

    return 0;
}

Measured memory_bytes: 256
import java.io.UnsupportedEncodingException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;


class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String mark = scanner.next();
		int num = mark.length();
		
		SectionDiagram(mark, num, scanner);
		
	}
	//enum宣言
	public static enum Operate{
		back(92),
		slush(47),
		under(95);
		
		private final int mark;
		
		private Operate(final int mark) {
			this.mark = mark;
		}
		
		public int getInt(){
			return this.mark;
		}
	}
	public static Operate getOperate(final int id) {
		Operate[] marks = Operate.values();
		for (Operate type : marks) {
			if (type.getInt() == id) {
				return type;
			}
		}
		return null;
	}
	//治水シミュレーション
	public static void SectionDiagram(String mark, int num, Scanner scanner){
		int count = 0;										//Whileの周回
		byte[] mark_num = new byte[num];					//switch用格納庫
		int sum_puddle = 0;
		
		Deque<Integer> downPos = new ArrayDeque<>();
		Deque<flood> downPosPool = new ArrayDeque<>();
		 
		//文字列変換
		try {
			mark_num = mark.getBytes("US-ASCII");
		} catch (UnsupportedEncodingException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		
		while( num > count ){										//文字数文処理
			switch( getOperate(mark_num[count]) ){					//文字により分岐
			case back:
				downPos.push(count);								//追加
				break;
			case slush:
				//頂上じゃなければ
				if ( !downPos.isEmpty()) {
					int slu = downPos.pop();							//スラッシュ追加
					int puddles = count - slu;
					sum_puddle += puddles;
					while (!downPosPool.isEmpty() && downPosPool.peek().rimit > slu) {
						puddles += downPosPool.pop().trout;
					}
					downPosPool.push(new flood(slu, puddles));
				}
				break;
			case under:
				break;
			}
			count ++;
		}
		//出力処理
        System.out.println(sum_puddle);
		int size = downPosPool.size();
        System.out.print(size);
        for (int i = 0; i < size; i++) {
            System.out.print(" ");
            System.out.print(downPosPool.pollLast().trout);
        }
        System.out.println();
	}
	
	static class flood {
        int rimit;
        int trout;
        flood(int i1, int i2) {
            rimit = i1;
            trout = i2;
        }
    }
}


Measured memory_bytes: 29388
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define se second
#define pi 3.14159265358979
//ll string_inp() {cin.get(); for(int i =0;i<n;i++){ getline(cin,s[i]);}}
ll gcd(ll a, ll b){ if (a == 0) return b;  return gcd(b % a, a);  }
ll power(ll x, ll y, ll mod = 2e18) {ll ans = 1;x %= mod;while(y){if(y&1) ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m,a = t; t = y; y = x - q * y; x = t; } if(x < 0) x += m0;return x;}
int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;}
ll binsearch(std::vector<ll>& nums, ll target) {ll n = nums.size();ll l = 0;ll r = n-1;while(l<=r){ll mid = l+ (r-l)/2;if(nums[mid]==target)return mid;else if(nums[mid]>target)r = mid-1;else l = mid+1;}return -1;}
bool isPowerOfTwo (int x) {return x && (!(x&(x-1))); }

using namespace std;

int main()
{
   fastio
   ll t;
   cin>>t;

ll a[t+5];
for(ll i =0;i<t;i++)
       cin>>a[i];

       ll ans =0;

        if(t==1)
        {
            cout<<0<<endl;

        }
        else {
       for(ll i =1;i<t;i++)
       {
           if(a[i]<a[i-1])
           {


            ans+=a[i-1]-a[i];
            a[i]=a[i-1];
           }

       }
       cout<<ans<<endl;
        }


}




Measured memory_bytes: 5168
n, p = map(int, input().split())

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


# print('(n, p) is ({}, {})'.format(n, p))
list = factorize(p)
# print(list)



ans = 1
for b, e in list:
    # print(b, e)
    tmp = e // n
    # print('b // n is', tmp )
    if tmp !=0:
        for i in range(tmp):
            ans*=b

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int>arr(n), brr(n);
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    for(int i=0; i<n; i++)
    {
        cin >> brr[i];
    }
    reverse(brr.begin(),brr.end());
    int number = -1;
    for(int i=0; i<n; i++)
    {
        if(arr[i] == brr[i])
        {
            number = arr[i];
            break;
        }
    }
    int leftPos = 0;
    for(int i=0; i<n; i++)
    {
        if(arr[i]==number && brr[i]==number)
        {
            leftPos = i;
            break;
        }
    }
    int rightPos = -1;
    for(int i=n-1; i>=0; i--)
    {
        if(arr[i]==number && brr[i]==number)
        {
            rightPos = i;
            break;
        }
    }
    for(int i=0; i<n && number!=-1; i++)
    {
        if(arr[i]!=number && brr[i]!=number && leftPos<=rightPos)
        {
            swap(brr[i],brr[leftPos]);
            leftPos++;
        }
    }
    if(leftPos<=rightPos)
    {
        cout << "No\n";
    } else
    {
        cout <<"Yes\n";
        for(int x : brr)cout << x << " ";
        cout << endl;
    }
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
char c;

void input() { 
  cin >> c;
}

void solve() {
  if (isupper(c)){
    cout << "A" << endl;
  } else {
    cout << "a" << endl;
  }
}

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


Measured memory_bytes: 3584
package main

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

func main() {
	fmt.Printf("%d\n", resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) (int, []map[byte]int) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	n := scanInt(sc)
	// 0-indexed
	selections := []map[byte]int{}
	for i := 0; i < n; i++ {
		selections = append(selections, map[byte]int{
			'a': scanInt(sc),
			'b': scanInt(sc),
			'c': scanInt(sc),
		})
	}

	return n, selections
}

func resolve(n int, selections []map[byte]int) int {
	// 0-indexed
	states := make([]map[byte]int, n)
	// init
	for i := 0; i < n; i++ {
		states[i] = map[byte]int{
			'a': ninf,
			'b': ninf,
			'c': ninf,
		}
	}
	for _, c := range []byte{'a', 'b', 'c'} {
		states[0][c] = selections[0][c]
	}
	// 雋ｰ縺㎤P
	for i := 1; i < n; i++ {
		for _, c := range []byte{'a', 'b', 'c'} {
			bC := states[i-1][c]
			for _, k := range []byte{'a', 'b', 'c'} {
				if c == k {
					continue
				}
				if states[i][k] < bC+selections[i][k] {
					states[i][k] = bC + selections[i][k]
				}
			}
		}
	}
	result := ninf
	for _, k := range []byte{'a', 'b', 'c'} {
		changeToMax(&result, states[n-1][k])
	}
	return result
}

const (
	inf  = math.MaxInt32
	ninf = math.MinInt32
)

func changeToMin(v *int, cand int) (updated bool) {
	if *v > cand {
		*v = cand
		updated = true
	}
	return updated
}

func changeToMax(v *int, cand int) (updated bool) {
	if *v < cand {
		*v = cand
		updated = true
	}
	return updated
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 33280
import java.util.*;


public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] values = new int[n];
        int[] costs = new int[n];
        
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            costs[i] = sc.nextInt();
        }
        
        int sum = 0;
        
        for (int i = 0; i < n; i++) {
            if (values[i] - costs[i] > 0) {
                sum += values[i] - costs[i];
            }
        }
        
        System.out.println(sum);
    }
}

Measured memory_bytes: 23380
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	int rec(int[] b, int left, int right) {
		if (right - left == 2) {
			if (b[left] == -1 && b[left + 1] == -1) {
				return -1;
			}
			if (b[left] == -1 || b[left + 1] == -1) {
				return 0;
			}
			return 1;
		}

		int mid = (left + right) / 2;

		int leftSum = rec(b, left, mid);
		int rightSum = rec(b, mid, right);

		if (leftSum == -1 && rightSum == -1) {
			return -1;
		}
		if (leftSum == -1 || rightSum == -1) {
			return leftSum + rightSum + 1;
		}
		return leftSum + rightSum + 1;
	}

	void run() {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int a[] = new int[m];
		for (int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
		}

		int b[] = new int[n];
		for (int i = 0; i < m; i++) {
			b[a[i]] = -1;
		}
		System.out.println(rec(b, 0, n));
	}
}



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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(b < c || a > d)
        cout << '0' << endl;
    else 
        printf("%d",min(b, d) - max(a, c)) ;
    return 0;
}


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

typedef long long ll;

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

    int n; cin >> n;
    vector<ll> a(n);
    map<ll,ll> mp;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a.begin(),a.end());
    ll ans=0,prev=0;
    for(int i=0;i<n;i++){
        if(prev!=a[i]){
            if(mp[a[i]]-a[i]<0) ans += mp[a[i]];
            else ans += mp[a[i]] - a[i];
            prev = a[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  vector<int>b(N);
  for(int i = 0; i < N; i++) {
  cin >> b[i]; 
  }
  set<int>a;
  for(int i = 0; i < N; i++) {
  a.insert(b[i]);
  }
  cout << a.size() << endl;
}




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

int N, K;

int main()
{
    cin >> N >> K;
    vector<int> d(K);
    vector<vector<int>> A(K);

    for (int i = 0; i < K; i++)
    {
        int dx;
        cin >> dx;
        d.at(0) = dx;

        vector<int> a(dx);
        for (int j = 0; j < dx; j++)
        {
            cin >> a.at(j);
        }

        A.at(i) = a;
    }

    int has = 0;

    for (int n = 0; n < N; n++)
    {
        for (int i = 0; i < K; i++)
        {
            bool found = false;
            for (int j = 0; j < A.at(i).size(); j++)
            {
                if (A.at(i).at(j) - 1 == n)
                {
                    has++;
                    found = true;
                    break;
                }
            }

            if (found)
            {
                break;
            }
        }
    }

    cout << N - has << endl;
    return 0;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		if(x < 1200) {
			System.out.println("ABC");
		} else {
			System.out.println("ARC");
		}
		
		scan.close();

	}

}


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

int main() {
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	    cin>>a[i];
	int dp[n]={0};
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
	    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<endl;
}
	
	


Measured memory_bytes: 4388
#include <bits/stdc++.h>
         
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define long long ll
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define rep(i, a, n) for(int i = (a); i < (n); ++i)
#define repr(i, a, n) for(int i = (n); i >= (a); --i)
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
     
int main(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i < 10 ; ++i){
        for(int j = i; j < 10; ++j){
            if(i * j == n){
                cout << "Yes";
                exit(0);
            }
        }
    }
    cout << "No";
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  int a;
  cin >> a;
  int b;
  cin >> b;
  int c;
  cin >> c;
  int d;
  cin >> d;

  a--, b--, c--, d--;

  string S;
  cin >> S;

  auto check = [&](int x, int y) {
    bool f = true;
    rep(i, x, y) {
      if (S[i] == '#' and S[i + 1] == '#') {
        f = false;
      }
    }
    return f;
  };

  if (a < b and b < d and d < c) {
    bool f = false;
    rep(i, b, d + 1) {
      if (S[i - 1] == '.' and S[i] == '.' and S[i + 1] == '.') {
        f = true;
      }
    }
    Yes(check(a, c) and check(b, d) and f);

  } else {
    Yes(check(a, c) and check(b, d));
  }

  return 0;
}


Measured memory_bytes: 592
#include <iostream>

using namespace std;
int main() {
    int citys[50];
    int n ,m , x = 0 , y = 0;
    cin >> n >> m;
    for(int i = 0; i < n; i ++){
        citys[i] = 0;
    }
    for(int i = 0; i < m ; i++){
        cin >> x;
        cin >> y;
        citys[x-1]++;
        citys[y-1]++;
    }
    for (int i = 0; i < n; i++)
        cout << citys[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main(void){
    int m, n;
    int money = 0;
    cin >> n >> m;
    vector<vector<int>> v(m+1);
    priority_queue<int> q;
    for(int i=0; i<n; i++){
        int a, b;
        cin >> a >> b;
        if(a > m) continue;
        v[a].push_back(b);
    }
    for(int i=1; i<=m; i++){
        for(int x : v[i]) q.push(x);
        if(!q.empty()){
            money += q.top();
            q.pop();
        }
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) int(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 100010

template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}

char s[(1<<19)+5];
ll dp[40][20];
int q[20],v[20];
int main(){
    //cout<<setprecision(9)<<fixed;
    srand(time(NULL));
    int T,ca=0,m=0,k,i,j,n,K;
	scanf("%d%s",&n,s);
	ll ans=0;
	rep(i,0,(1<<n)){
		int sz=0,t=0;
		rep(j,0,n)if(i>>j&1)v[sz++]=j;
		else q[t++]=j;
		reverse(v,v+sz);
		reverse(q,q+t);
		dp[n][0]=1;
		rep(j,n,2*n){
			rep(k,0,sz+1)if(dp[j][k]){
				if(k<sz&&s[j]==s[v[k]]){
					dp[j+1][k+1]+=dp[j][k];
				}
				int l=j-n-k;
				if(l<t&&s[j]==s[q[l]]){
					dp[j+1][k]+=dp[j][k];
				}
			}
		}
		ans+=dp[2*n][sz];
		rep(j,n,2*n+1)rep(k,0,sz+1)dp[j][k]=0;
	}
	printf("%lld\n",ans);
}	



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>

using ll = long long;

using namespace std;

#define amax(a, b) a = max(a, b)

using P = pair<int, int>;
#define fi first
#define se second

int main() {
    int h, w, m;
    cin >> h >> w >> m;
    int cnt_x[h], cnt_y[w];
    fill(cnt_x, cnt_x+h, 0);
    fill(cnt_y, cnt_y+w, 0);
    set<P> st;
    int xmax = 0, ymax = 0;
    for (int i=0, hi, wi; i<m; i++) {
        cin >> hi >> wi;
        hi--; wi--;
        st.insert(P{hi, wi});
        cnt_x[hi]++;
        cnt_y[wi]++;
        amax(xmax, cnt_x[hi]);
        amax(ymax, cnt_y[wi]);
    }
    vector<int> xbests, ybests;
    for (int i=0; i<h; i++) {
        if (cnt_x[i] == xmax) {
            xbests.push_back(i);
        }
    }
    for (int i=0; i<w; i++) {
        if (cnt_y[i] == ymax) {
            ybests.push_back(i);
        }
    }
    if ((ll)xbests.size() * ybests.size() > (ll)m) {
        cout << xmax + ymax << '\n';
    } else {
        bool hole = false;
        for (auto &xi:xbests) {
            for (auto &yi:ybests) {
                if (st.count(P{xi, yi}) == 0) hole = true;
            }
        }
        cout << xmax + ymax - (int)(!hole) << '\n';
    }
    return 0;
}

Measured memory_bytes: 23844
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int n;
int main(){
#ifdef __APPLE__
	freopen("main.in","r",stdin);
#endif
	scanf(" %d",&n);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int a,b; scanf(" %d%d",&a,&b);
		if(a > b) swap(a,b);
		ans += b - a + 1;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

int main()
{
	int n; cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) { cin >> p[i]; }

	int ans = 0;
	for (int i = 1; i < n - 1; i++)
	{
		if (max(min(p[i - 1], p[i]), p[i + 1]) == p[i] || min(max(p[i - 1], p[i]), p[i + 1]) == p[i])
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long n,d[200010],l=0,r=0,ans=0,x=0,i,s[200010]={};
  scanf("%lld",&n);
  for(i=0;i<n;i++)scanf("%lld",&d[i]);
  for(i=0;i<n;i++)s[i+1]=s[i]+d[i];
  //for(i=0;i<=n;i++)printf("%lld ",s[i]);printf("\n");
  for(l=0;l<n;l++){
    while((s[r]-s[l])==x&&r<=n)x^=d[r++];//printf("!%lld %lld\n",l,r);
    if(s[r-1]-s[l]==x^d[r-1])ans+=(r-l-1);
    //printf("%lld %lld %lld\n",ans,x^d[r-1],s[r-1]-s[l]);
    x^=d[l];
    //l++;    
    //while((s[r]-s[l])==x&&l<n)x^=d[l++];printf("%lld %lld\n",l,r);
  }
  printf("%lld\n",ans);
  return 0;
}
			


Measured memory_bytes: 3328
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Combination cmb = new Combination(n + 2);
		int[] idxes = new int[n + 1];
		Arrays.fill(idxes, -1);
		int a = 0;
		int b = 0;
		for (int i = 0; i <= n; i++) {
		    int x = sc.nextInt();
		    if (idxes[x] == -1) {
		        idxes[x] = i;
		    } else {
		        a = idxes[x];
		        b = i;
		        break;
		    }
		}
		int c = b - a + 1;
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n + 1; i++) {
		    long total = cmb.getComb(n + 1, i);
		    total -= cmb.getComb(n + 1 - c, i - 1);
		    total += MOD;
		    total %= MOD;
		    sb.append(total).append("\n");
		}
		System.out.print(sb);
   }

}

class Combination {
    static final int MOD = 1000000007;
    long[] fac;
    long[] finv;
    long[] inv;
    
    public Combination (int size) {
        fac = new long [size];
        finv = new long [size];
        inv = new long [size];
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < size; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    
    
    public long getComb(int n, int k) {
        if (n < k || n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
}



Measured memory_bytes: 55324
use std::cmp::{max, min};
use std::collections::{HashMap, HashSet, VecDeque};
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
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")
}

#[allow(dead_code)]
fn main() {
    let h = read::<usize>();
    let w = read::<usize>();
    let mut a = (0..h)
        .map(|_| {
            read::<String>()
                .chars()
                .map(|c| if c == '#' { 0 } else { -1 })
                .collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();

    let mut q = VecDeque::new();
    for i in 0..h {
        for j in 0..w {
            if a[i][j] == 0 {
                q.push_back((i, j, 0));
                a[i][j] = -1;
            }
        }
    }
    let mut s = a;
    while let Some((i, j, c)) = q.pop_front() {
        if s[i][j] >= 0 {
            continue;
        }
        s[i][j] = c;
        if i > 0 {
            q.push_back((i - 1, j, c + 1))
        }
        if j > 0 {
            q.push_back((i, j - 1, c + 1))
        }
        if i < h - 1 {
            q.push_back((i + 1, j, c + 1))
        }
        if j < w - 1 {
            q.push_back((i, j + 1, c + 1))
        }
    }
    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            ans = max(ans, s[i][j]);
        }
    }

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


Measured memory_bytes: 105208
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

template<class T> class Union_Find {
public:
	vector<int> prnt;
	vector<int> rank;
	vector<T> dist;

	Union_Find(int N = 1):prnt(vector<int>(N)),rank(vector<int>(N,0)),dist(vector<int>(N, 0)) {
		for (int i = 0; i < N; ++i) prnt[i] = i;
	}

	int root(int x) {
		if (prnt[x] == x) {
			return x;
		}
		else {
			int r = root(prnt[x]);
			dist[x] += dist[prnt[x]];
			return prnt[x] = r;
		}
	}

	T updated_dist(int x) {
		root(x);
		return dist[x];
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, T w) {
		w += updated_dist(x); w -= updated_dist(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) ++rank[x];
		prnt[y] = x;
		dist[y] = w;
		return true;
	}

	T diff(int x, int y) {
		return updated_dist(y) - updated_dist(x);
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	Union_Find<int> uf(N);
	for (int i = 0; i < M; ++i) {
		int l, r, d;
		cin >> l >> r >> d;
		--l, --r;
		if (uf.same(l, r)) {
			if (d != uf.diff(l, r)) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			uf.merge(l, r, d);
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#define H 250

int main(){

  int n, i;
  int A[H];
  
  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    scanf("%d",&A[i]);
  }

  for(i = 1; i <= n; i++){
    printf("node %d: key = %d, ",i , A[i]);
    if(i != 1) printf("parent key = %d, ",A[i/2]);
    if(2*i < n+1) printf("left key = %d, ",A[2*i]);
    if(2*i < n) printf("right key = %d, ",A[2*i+1]);
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end(), greater<int>());
  cout << vec[0] - vec[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N, Q = map(int, input().split())
E = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
ans = [0]*N
for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

for i in range(N):
    for t in E[i]:
        ans[t] += ans[i]
print(*ans)


Measured memory_bytes: 105660
#include <iostream>
using namespace std;
int a[100], n;
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        for (int k = 0; k < n - 1; k++) cout << a[k] << ' ';
        cout << a[n - 1] << endl;
        int j = i - 1, v = a[i];
        while (j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            a[j] = v;
            j--;
        }
    }
    for (int i = 0; i < n - 1; i++) cout << a[i] << ' ';
    cout << a[n - 1] << endl;
}



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

int main(){
    long long h;
    int n;
    cin >> h >> n;

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

    if (h > sum) cout << "No" << endl;
    else cout << "Yes" << endl;


}

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

int main(){
	int n,m;
	cin>>n>>m;
	vector<int>a(m);
	int sum=0;
	for(int i=0;i<m;i++) {
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n) cout<<"-1"<<endl;
	else
	cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef vector<ll> VI;
typedef vector<pair<ll,ll> > VII;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
//
#define M 1000000007
#define INF (ll)0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define itr iterator
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}

void error_out() { cerr << endl; }
template <typename Head, typename... Tail>
void error_out(Head H, Tail... T) {
  cerr << " " << H;
  error_out(T...);
}
void time_elapsed(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}
#ifndef ONLINE_JUDGE
#define error(...) cerr << "[" << #__VA_ARGS__ << "]:", error_out(__VA_ARGS__)
#define fioe() fileioe()
#define time() time_elapsed()
#else
#define error(...) 1
#define fioe() 1
#define time() 1
#endif


//
int main()
{
	GO
	//fioe();
	ll n,m;
	cin>>n>>m;
	if(n==m){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	time();
	return 0;
}

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


int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int ak,bk;
  ak=a/n;
  bk=b/n;
  if(ak!=bk || a%n==0)
    cout<<"OK"<<endl;
  else
 
      
  cout<<"NG"<<endl;   
  
}


Measured memory_bytes: 3592
#include <iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];// マージソートで使う左半分、右半分の配列
int cnt; // 交換回数

// 分割した要素を統治（マージ）する
void merge(int A[], int n, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL; // 配列末尾に巨大な値を入れておく
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		cnt++; // 交換回数インクリメント
		// 左配列の先頭と右配列の先頭で小さいほうを元配列に追加する
		if (L[i] <= R[j]) { // i: 左配列の先頭を指す, j: 右配列の先頭を指す
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}
}

void mergeSort(int A[], int n, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int main() {
	int A[MAX], n, i; // ソート対象配列Aと要素数と制御変数
	cnt = 0; // 交換回数の初期化

	cin >> n;
	for (i = 0; i < n; i++) cin >> A[i];

	mergeSort(A, n, 0, n);

	for (i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 6992
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 200005
//<<fixed << setprecision(9)

int arr[space],brr[space];
int cnt[space];
vi match[space];
vii v;// cnt, num
queue<pii> have;

int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    int bad=0;
    rep(i,0,n)cin>>arr[i];
    rep(i,0,n)
    {
        cin>>brr[i];
        if(arr[i]==brr[i])
        {
            cnt[arr[i]]++;
            bad++;
        }
    }
    if(bad==0)
    {
        cout<<"Yes\n";
        rep(i,0,n) cout<<brr[i]<<' ';
        return 0;
    }

    rep(i,1,n+1)
    {
        if(cnt[i])
            v.pb({cnt[i],i});
    }
    sort(all(v));
    
    have.push(v.back());
    for(i=sz(v)-2;i>=0;i--)
    {
        have.push(v[i]);
        pii& u =have.front();
        int sub = min(v[i].F,u.F);
        rep(j,0,sub)
            match[v[i].S].pb(u.S);
        u.F-=sub;
        v[i].F-=sub;
        if(u.F==0)
            have.pop();
        if(v[i].F>0)
        {
            pii& u =have.front();
            int sub = min(v[i].F,u.F);
            rep(j,0,sub)
                match[v[i].S].pb(u.S);
            v[i].F-=sub;
            assert(v[i].F==0);
            u.F-=sub;
        }
    }
    pii rem = v.back();

    if(have.front().S==rem.S)
    {
        have.pop();
    }
    while(!have.empty())
    {
        pii u = have.front();
        have.pop();
        rem.F-=u.F;
        rep(i,0,u.F)
            match[rem.S].pb(u.S);
    }

    if(rem.F>0)
    {
        rep(i,0,n)
        {
            if(arr[i]!=brr[i] and rem.S!=brr[i] and rem.S!=arr[i])
            {
                rem.F--;
                match[rem.S].pb(brr[i]);
                brr[i]=rem.S;
                if(rem.F==0)
                    break;
            }
        }
    }

    if(rem.F>0)
        cout<<"No";
    else
    {
        cout<<"Yes\n";
        rep(i,0,n)
        {
            if(arr[i]==brr[i])
            {
                int x = match[brr[i]].back();
                match[brr[i]].pop_back();
                brr[i]=x;
            }
        }
        rep(i,0,n)
            cout<<brr[i]<<" ";
    }

    return 0;
}

Measured memory_bytes: 18020
# coding: utf-8
# ビンゴゲーム
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))

N = int(input())
# 複数行標準入力
S = []
for _ in range(N):
    S.append(int(input()))  # S += [input()] とも書ける

for _S in S:
    for _l1 in range(len(l1)):
        if (_S == l1[_l1]):
            l1[_l1] = 0
    for _l2 in range(len(l2)):
        if (_S == l2[_l2]):
            l2[_l2] = 0
    for _l3 in range(len(l3)):
        if (_S == l3[_l3]):
            l3[_l3] = 0

isBingo = "No"
if (sum(l1) == 0 or sum(l2) == 0 or sum(l3) == 0 or l1[0] + l2[0] + l3[0] == 0 or l1[1] + l2[1] + l3[1] == 0 or l1[2] + l2[2] + l3[2] == 0 or l1[0] + l2[1] + l3[2] == 0 or l1[2] + l2[1] + l3[0] == 0):
    isBingo = "Yes"

print(isBingo)


Measured memory_bytes: 3064
N,Q = map(int,input().split())
S = list(input())

cnt = [0] * N
for i in range(1,N):
    cnt[i] = cnt[i-1]
    if S[i-1] == "A" and S[i] == "C":
        cnt[i] += 1

for _ in range(Q):
    l,r = map(int,input().split())
    print(cnt[r-1] - cnt[l-1])

Measured memory_bytes: 6876
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int x, y;
  cin >> x >> y;


  int ans = INF;
  if(y-x >= 0) chmin(ans, y-x);
  if(-y-x+1 >= 0) chmin(ans, -y-x+1);
  if(y+x+1 >= 0) chmin(ans, y+x+1);
  if(-y+x+2 >= 0) chmin(ans, -y+x+2);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256