akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
    string S;
    while(cin >> S, S != "#") {
        vector<vector<int>> field(9, vector<int>(9));
        int H, W, h = 0, w = 0;
        for(int i = 0; i < S.size(); ++i) {
            char c = S[i];
            if(c == 'b') {
                field[h][w] = 1;
                w++;
            } else if(c == '/') {
                h++;
                H = h + 1;
                W = w;
                w = 0;
            } else {
                w += c - '0';
            }
        }
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        field[a - 1][b - 1] = 0;
        field[c - 1][d - 1] = 1;
        int now = 0;
        for(int i = 0; i < H; ++i) {
            now = 0;
            for(int j = 0; j < W; ++j) {
                if(field[i][j]) {
                    if(now != 0) {
                        cout << now;
                        now = 0;
                    }
                    cout << 'b';
                } else {
                    now++;
                }
            }
            if(now != 0) {
                cout << now;
            }
            if(i != H - 1) {
                cout << '/';
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3048
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let w = read::<String>().to_lowercase();

    let mut count = 0;
    loop {
        let ss = read_vec::<String>();
        if ss[0] == "END_OF_TEXT" {
            break;
        }
        for s in ss {
            if s.to_lowercase() == w {
                count += 1;
            }
        }
    }
    println!("{}", count);
}



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

int A,B,C,D,E;

int main(){
  cin>>A>>B>>C>>D>>E;
  if(A<0){
    cout<<-A*C+D+B*E<<endl;
  }else{
    cout<<(B-A)*E<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int gcd(int a, int b) {
  return b != 0 ? gcd(b, a%b) : a;
}

signed main(void)
{
  int p, q;
  cin >> p >> q;
  int r = gcd(p, q);
  //cout << r << endl;
  p /= r; q /= r;
  set<int> s;
  ll a = 2;
  while(q >= a*a) {
    if(q % a == 0) {
      s.insert(a);
      q /= a;
    } else {
      a++;
    }
  }
  s.insert(q);
  ll ret = 1;
  for(int i: s) ret *= i;
  cout << ret << endl;

  return 0;
}

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

int main(){
  long long A, B; cin >> A >> B;
  long long ans = (A * B + 1) / 2;
  if (A == 1 || B == 1) ans = 1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int A[200001];
	int As[200001];
	scan(N);
	rep(i,N){
		scan(A[i]);
		As[i]=A[i];
	}
	sort(As,As+N);
	int F=As[N-1],S=As[N-2];
	rep(i,N){
		if(A[i]!=F) prin(F);
		else prin(S);
	}
	return 0;
}


Measured memory_bytes: 3200
import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;

void main() {
    int N; readf("%d\n", &N);
    int[] d = new int[100003];
    int[] r = new int[100003];
    foreach (i; 0 .. N) {
        int a, b; readf("%d %d\n", &a, &b);
        d[a]++;
        d[b + 1]--;
    }
    int c = 0;
    foreach (i; 2 .. 100003) {
        c += d[i];
        r[i] = c;
    }
    int ans = 0;
    foreach (i; 2 .. 100003) {
        if (r[i] >= i - 1) {
            ans = i - 1;
        }
    }
    ans.writeln;
}

Measured memory_bytes: 1760
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		long h  = sc.nextLong();
		
		
		
		long sum =0;
		
		
		while (h>1) {
			h=h/2;
			sum++;
		}
		
		
		System.out.println((long)(Math.pow(2, sum+1)-1));
	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 23892
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    def check_yymm(s):
        return 1 <= int(s[2:]) <= 12
    
    def check_mmyy(s):
        return 1 <= int(s[:2]) <= 12
    
    s = input()
    if check_mmyy(s) and check_yymm(s):
        print('AMBIGUOUS')
    elif check_mmyy(s):
        print('MMYY')
    elif check_yymm(s):
        print('YYMM')
    else:
        print('NA')


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
from collections import deque

if __name__ == '__main__':
    k = int(input())
    a = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    for i in range(k - 1):
        x = a.popleft()
        if x % 10 != 0:
            a.append(10 * x + (x % 10) - 1)
        a.append(10 * x + (x % 10))
        if x % 10 != 9:
            a.append(10 * x + (x % 10) + 1)
    print(a.popleft())


Measured memory_bytes: 11908
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    s=SI()
    k=II()
    n=len(s)
    dp=[[[0]*2 for _ in range(k+1)] for _ in range(n+1)]
    dp[0][0][0]=1
    # dp[i][j][f]...i桁目までみたとき、0でない数字がj個で、s以下が確定かどうかがf
    for i,c in enumerate(s):
        for j in range(k+1):
            for f in range(2):
                pre=dp[i][j][f]
                if pre==0:continue
                if f:
                    dp[i+1][j][f]+=pre
                    if j<k:dp[i+1][j+1][f]+=pre*9
                else:
                    c=int(c)
                    if c:
                        dp[i+1][j][1]+=pre
                        if j<k:
                            dp[i+1][j+1][1]+=pre*(c-1)
                            dp[i+1][j+1][0]+=pre
                    else:
                        dp[i+1][j][0]+=pre
    print(sum(dp[n][k]))

main()

Measured memory_bytes: 3064
S = input()+"R"

ans = [0]*len(S)
mass = "R"
cnt = 0

for i,s in enumerate(S):
	if mass != s:
		if s == "L":#RL
			if cnt % 2 == 0:
				ans[i] += cnt//2
				ans[i-1] += cnt//2
			else:
				ans[i] += cnt//2
				ans[i-1] += cnt//2+1
			mass = "L"
		elif s == "R": #LR
			if cnt % 2 == 0:
				ans[i-cnt] += cnt//2
				ans[i-cnt-1] += cnt//2
			else:
				ans[i-cnt] += cnt//2+1
				ans[i-cnt-1] += cnt//2
			mass = "R"
		cnt = 1
	else:
		cnt += 1
print(*ans[:-1])

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

void greatFirst(int& a, int& b)
{
  if(a < b)
  {
    int tmp = a;
    a = b;
    b = tmp;
  }
}

void inputList(vector<ll>* list, ll n, int sortType = 0)
{
  repl(i, n)
  {
    ll tmp;
    cin >> tmp;
    list->push_back(tmp);
  }
  if(sortType == 1)
  {
    sort(list->begin(), list->end());
  }
  else if(sortType == 2)
  {
    sort(list->begin(), list->end(), greater<ll>());
  }
}

int main()
{
  double x;
  cin >> x;
  double v = 100;
  ll ans = 0;
  while(x > v)
  {
    v = floor(v * 1.01);
    ans++;
  }
  
  cout << fixed << ans << endl;
  
  return 0;
}

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

long long a, b, x;

long long func(long long n) {
  if (n == -1) {
    return 0;
  }
  else {
    return n/x + 1;
  }
}

int main() {

  cin >> a >> b >> x;

  long long ans = func(b) - func(a-1);

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
using ll = long long;


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

int main(){
	int n,q;cin >> n >> q;
	string s;cin >> s;
	vector<int> l(q);
	vector<int> r(q);
	for(int i=0;i<q;i++){
		cin >> l.at(i) >> r.at(i);
	}
	vector<int> ruiseki(n,0);
	for(int i=0;i<n;i++){
		ruiseki[i+1] = ruiseki[i];
		if(s[i] == 'A'){
			if(s[i+1] == 'C'){
				ruiseki[i+1]++;
			}
		}
	}
	for(int i=0;i<q;i++){
		int lnum = l[i];
		int rnum = r[i];
		cout << ruiseki[rnum-1] - ruiseki[lnum-1] << endl;
	}
}


Measured memory_bytes: 4164
#include <iostream>
#define rep(i,beg,end) for(int i=(beg);i<(end);i++)
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	if(a%b==0){
		cout<<a/b<<endl;
	}else{
		cout<<a/b+1<<endl;
	} 
	return 0;
}


Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    ll k;
    cin >> k;
    
    rep(i, s.size())
    {
        if (i+1 == k)
        {
            cout << s[i] << endl;
            return 0;
        }
        if (s[i] != '1')
        {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scanner= new Scanner(System.in);
		int a, b ,n;
		
		n = scanner.nextInt();
		a = scanner.nextInt();
		b = scanner.nextInt();
		
		int taxi = b;
		int train = n * a;
		int answer;
		
		if(taxi < train) {
			answer = taxi;
		}else {
			answer = train;
		}
		
		System.out.println(answer);
		
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector <vector <int>> dp(h, vector <int> (w, -1));
    rep (i, h) rep (j, w) {
        char a;
        cin >> a;
        if (a == 'c') dp[i][j] = 0;
    }

    rep (i, h) rep (j, w - 1) if (dp[i][j] >= 0 && dp[i][j + 1] != 0) dp[i][j + 1] = (dp[i][j] + 1);

    rep (i, h) rep (j, w) cout << dp[i][j] << " \n"[j == w - 1];
    return 0;
}


Measured memory_bytes: 3216
s=input()
n=len(s)
from collections import Counter
l=Counter()
for i in "abcdefghijklmnopqrstuvwxyz":
    l[i]=[]
for i in range(n):
    l[s[i]].append(i)
t=input()
m=len(t)
ans=0
p=-1
import bisect
for i in range(m):
    c=t[i]
    ll=l[c]
    if ll==[]:
        print(-1)
        exit()
    if ll[-1]<=p:
        ans+=n
        p=ll[0]
        if i==m-1:
            ans+=p+1
    else:
        p=ll[bisect.bisect_right(ll,p)]
        if i==m-1:
            ans+=p+1
print(ans)


Measured memory_bytes: 7924
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (int i=a; i<b; i++)
// #define endl "\n"
const int mod = 1000000007;

ll power(ll x, ll y) 
{ 
    ll res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = res*x; 
        res%=mod;
        // n must be even now 
        y = y>>1; // y = y/2 
        x = x*x;
        x%=mod;  // Change x to x^2 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);    //Fast I/O
    cin.tie(NULL);
 
    // freopen("input.txt", "r", stdin);    // Read and write from a file
    // freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    string str;
    cin >> str;
    for(int i=0; i<str.size(); i++){
        str[i] = 'A'+(str[i]-'A'+n)%26;
    }

    cout << str << endl;
 
 
    return 0;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
N, M = min(N, M), max(N, M)

if K % M == 0 or K % N == 0:
    print('Yes')
    exit()

for i in range(N + 1):
    k = K - M * i
    n = N - 2 * i
    if n <= 0 or k < 0:
        continue
    if k % n == 0:
        if 0 <= k // n <= M:
            print('Yes')
            exit()
else:
    print('No')

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

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] a = Input.ScanIntArray();
          for(int i=0;i<a[0];i++){
            string N = Input.ScanStr();
            Console.WriteLine(N);
            Console.WriteLine(N);
          }
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define repr(i, n) for(int i=n; )
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    vint(a, n);

    bool flg=false;
    rep(i, n-1) {
        if(a[i] != a[i+1]) flg = true;
    }
    if(!flg) {pr(0); return 0;}

    ll s = INFL;
    int ans = 0;
    FOR(i, -1000, 1000){
        ll t = 0;
        rep(j, n){
            t += (a[j]-i)*(a[j]-i);
        }
        if(s > t){
            s = t;
            ans = i;
        }
    }

    pr(s);
    return 0;}

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

const int MAX_V = 1 << 17;
const int MAX_N = 1 << 18;
const int def = 1 << 25;

typedef pair<int, int> Node;
struct MinSegTree {
	int n;
	Node node[2 * MAX_N - 1];
	int dat[2 * MAX_N - 1];
	int minIdx[2 * MAX_N - 1];

	void init(int n_) {
		n = 1;
		while(n < n_) n *= 2;
		for(int i = 0; i < 2 * n - 1; i++) node[i] = make_pair(def, def);
	}

	Node merge(Node l, Node r) {
		if(l.first <= r.first) return l;
		return r;
	}

	void update(int k, int a) {
		k += n - 1;
		node[k] = make_pair(a, k - (n - 1));
		dat[k] = a;
		minIdx[k] = k - (n - 1);
		while(k > 0) {
			k = (k - 1) / 2;
			node[k] = merge(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}

	Node query(int a, int b) { return query(a, b, 0, 0, n); }

	Node query(int a, int b, int k, int l, int r) {
		if(r <= a || b <= l) return make_pair(def, def);
		if(a <= l && r <= b) return node[k];
		Node vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		Node vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return merge(vl, vr);
	}

	void show() {
		for(int i = 0; i < n; i++) cout << dat[i + n - 1] << " ";
		cout << endl;
	}
};

class LCA {
public:
	MinSegTree st;
	vector<int> G[MAX_V];
	int root;

	int vs[MAX_V * 2 - 1];
	int depth[MAX_V * 2 - 1];
	int id[MAX_V];

	void init(int V, int root = 0) {
		this->root = root;
		int k = 0;
		dfs(root, -1, 0, k);
		st.init(2 * V - 1);
		for(int i = 0; i < 2 * V - 1; i++) {
			st.update(i, depth[i]);
		}
	}

	void addEdge(int u, int v) {
		G[u].push_back(v);
		G[v].push_back(u);
	}

	void dfs(int v, int p, int d, int& k) {
		id[v] = k;
		vs[k] = v;
		depth[k++] = d;
		for(int i = 0; i < G[v].size(); i++) {
			if(G[v][i] != p) {
				dfs(G[v][i], v, d + 1, k);
				vs[k] = v;
				depth[k++] = d;
			}
		}
	}

	int lca(int u, int v) {
		int l = min(id[u], id[v]);
		int r = max(id[u], id[v]);
		return vs[st.query(l, r + 1).second];
	}
};

LCA lca;

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

	int n;
	cin >> n;

	for(int i = 0; i < n; i++) {
		int k;
		cin >> k;
		while(k--) {
			int c;
			cin >> c;
			lca.addEdge(i, c);
		}
	}

	lca.init(n);

	int q;
	cin >> q;
	while(q--) {
		int u, v;
		cin >> u >> v;
		cout << lca.lca(u, v) << endl;
	}
}

Measured memory_bytes: 20592
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>
#include <map>
#include <tuple>
#include <complex>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;
typedef vector<vs> vvs;

typedef vector<pll> vvpl;
typedef vector<vpi> vvpi;

typedef queue<ll> ql;
typedef queue<int> qi;
typedef queue<pll> qpl;
typedef queue<pi> qpi;

template <typename T>
void printv(const vector<T>& v) {
    for (int i = 0; i < v.size(); ++i) {
        printf("[%d] %d\n", i, v[i]);
    }
}

template <typename T>
void printvv(const vector<T>& vv) {
    for (int i = 0; i < vv.size(); ++i) {
        for (int j = 0; j < vv[i].size(); ++j) {
            printf("[%d][%d] %d\n", i, j, vv[i][j]);
        }
    }
}

template <typename T, typename U>
void printp(const pair<T, U>& p) {
    cout << p.first << " " << p.second << endl;
}

template <typename T>
void printvp(const vector<pair<T, T>>& vp) {
    for (int i = 0; i < vp.size(); ++i) {
        printf("[%d] %d, %d\n", vp[i].first, vp[i].second);
    }
}

template <typename T>
void printvvp(const vector<vector<pair<T, T>>>& vvp) {
    for (int i = 0; i < vvp.size(); ++i) {
        for (int j = 0; j < vvp[i].size(); ++j) {
            printf("[%d][%d] %d, %d\n", i, j, vvp[i][j].first, vvp[i][j].second);
        }
    }
}

int main() {
    int N, K; cin >> N >> K;
    vi h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];

    vi dp(N);
    for (int i = 1; i < N; ++i) {
        if (i == 1) dp[i] = abs(h[i] - h[i-1]);
        else {
            auto mini = INT_MAX;
            for (int j = 1; j <= min(i, K); ++j) {
                mini = min(mini, abs(h[i]-h[i-j]) + dp[i-j]);
            }
            dp[i] = mini;
        }
    }
    
    cout << dp[N-1] << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bn begin()
#define en end()
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
#define pi 3.141592653589
using namespace std;

int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie
    int x, y ;
    cin >> x >> y ;
    rep(i, 0, 1000) {
        rep(j, 0, 1000) {
            if(i+j == x) {
                int a = i*2 + j*4 ;
                if(a == y) {
                    cout << "Yes\n" ;
                    return 0 ;
                }
            }
        }
    }
    cout << "No\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
map<c_c, ll> mp;
ll ans;
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        string S = to_string(i);
        mp[{S[0], S.back()}]++;
    }
    for(char a = '0'; a <= '9'; a++) {
        ans += mp[{a, a}] * (mp[{a, a}]);
        cerr << a << " " << ans << endl;
        for(char b = a + 1; b <= '9'; b++) {
            ans += 2 * mp[{a, b}] * mp[{b, a}];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  ll N;
  cin >> N;
  vector<string> S(N);
  for (ll i = 0; i < N; i++) {
    cin >> S[i];
  }

  sort(S.begin(), S.end());  // 昇順

  int mx = 0;
  string last = S[0];
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == last) {
      count++;
      continue;
    }
    mx = max(mx, count);
    last = S[i];
    count = 1;
  }
  mx = max(mx, count);

  last = S[0];
  count = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == last) {
      count++;
      continue;
    }
    if (count == mx) cout << last << endl;
    last = S[i];
    count = 1;
  }
  if (count == mx) cout << last << endl;
}


Measured memory_bytes: 14208
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		int result = 0;
		char pre = s.charAt(0);
		for(int i = 1; i < s.length(); i++){
		    char c = s.charAt(i);
		    if(pre == c){
		        result++;
		        if(c == '0'){
		            c = '1';
		        }else{
		            c = '0';
		        }
		        pre = c;
		    }else{
		        pre = c;
		    }
		}

		
		// 出力
		System.out.println(result);
        
	}
}

Measured memory_bytes: 25848
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

//INSERT ABOVE HERE
signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  using M = Mint<int>;
  M ans=M(2).pow(n)-M(1);
  ans-=M::comb(n,a);
  ans-=M::comb(n,b);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    input!{
      n: usize,
      aa: [u64; n],
    }
    let mut ans = gcd(aa[0], aa[1]);
    for &a in &aa {
        ans = gcd(ans, a);
    }
    println!("{}", ans);
}


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

int main(){
  ll N,M;cin>>N>>M;
  if(N==1&&M==1) cout << 1 << endl;
  else if(N==1||M==1){
    cout << N*M-2 << endl;
  }
  else if(N==2||M==2){
    cout << 0 << endl;
  }
  else cout << (N-2)*(M-2) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <map>
using namespace std;
typedef map<string, int> MyMap;

MyMap hash;

void print_map(char* msg, int begin, int end) {
	char t_msg[1001] = {'\0'};
	string t_str;
	int cnt = 0;
	
	for (int i = begin; i < end; i++) {
		t_msg[cnt] = msg[i];
		cnt++;
	}
	t_msg[end] = '\0';
	
	t_str = string(t_msg);
	// Key isnt exist.
	if ((int)hash.count(t_str) == 0) {
		hash.insert(MyMap::value_type(t_str, 1));
	}
	// Key is exist. (return number is 1.)
	else {
		hash[t_str]++;
	}
}

int main(int argc, char *argv[]) {
	char msg[1001];
	fgets(msg, 1001, stdin);
	// Load
	int cnt = 0;
	for (int i = 0; i < 1001; i++) {
		if (msg[i] == '\n') {
			print_map(msg, cnt, i);
			break;
		}
		if (msg[i] == ' ') {
			print_map(msg, cnt, i);
			cnt = i+1;
		}
	}
	// Map print
	MyMap::iterator itr = hash.begin();
	MyMap::iterator max_sz_itr;
	MyMap::iterator max_fq_itr;
	int max_str_size = 0;
	int max_freq = 0;
	while (itr != hash.end()) {
		// max size
		if ((*itr).second > max_str_size) {
			max_str_size = (*itr).second;
			max_sz_itr = itr;
		}
		// max freq
		int t_freq = static_cast<int>((*itr).first.size());
		if (t_freq > max_freq) {
			max_freq = t_freq;
			max_fq_itr = itr;
		}
		itr++;
	}
	// print
	printf("%s %s\n",
	(*max_sz_itr).first.c_str(), (*max_fq_itr).first.c_str());
	return 0;
}

Measured memory_bytes: 0
n, y = map(int, input().split())

def main():
    if (5000*n) == y:
        print('{} {} {}'.format(0, n, 0))
        return
    if (10000*n) == y:
        print('{} {} {}'.format(n, 0, 0))
        return
    if (1000*n) == y:
        print('{} {} {}'.format(0, 0, n))
        return
    for i in range(n):
        for j in range(n-i):
            k = n - (i+j)
            if (10000*i + 5000*j + 1000*k) == y:
                print('{} {} {}'.format(i, j, k))
                return
    print('-1 -1 -1')

main()


Measured memory_bytes: 38768
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int cnt[26];
int main() {
	string w;
	cin >> w;
	for (int i = 0; i < w.size(); i++) {
		cnt[w[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (cnt[i] % 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		long n = long.Parse(input[0]);
		long x = long.Parse(input[1]);
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long answer = long.MaxValue;
    long[] minTimes = new long[n];
    long timeMemo = 0;

    for(int i = 0; i < n; i++)
    {
      minTimes[i] = long.MaxValue;
    }

    for(int magicCount = 0; magicCount < n; magicCount++)
    {
      timeMemo = 0;

      for(int i = 0; i < n; i++)
      {
        if(i-magicCount >= 0)
          minTimes[i] = Math.Min(minTimes[i], nums[i-magicCount]);
        else
          minTimes[i] = Math.Min(minTimes[i], nums[i-magicCount+n]);
        timeMemo += minTimes[i];
      }
      timeMemo += x*magicCount;
      answer = Math.Min(answer, timeMemo);
    }
    
		Console.WriteLine(answer);
	}
}

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

int main(){

  long long int n,a[10010],b[10010],ans;

  while(cin >> n, n){

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

    sort(a,a+n);

    ans = 0;

    for(int i=0;i<n-1;i++){
      ans += a[i];
      b[i] = ans;
    }

    ans = 0;

    for(int i=0;i<n-1;i++) ans += b[i];

    cout << ans << endl;

  }
}

Measured memory_bytes: 1324
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int a, b;
    cin >> a >> b;
    int ans = max(0, a-2*b);
    cout << ans << endl;

    return 0;
}


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

int main(){
  int n,t=1,count=0;
  cin >> n;
  int a[n];
  r(i,n)cin >> a[i];
  while(count<100001){
    t=a[t-1];
    count++;
    if(t==2)break;
  }
  if(count==100001)cout <<-1<<endl;
  else cout << count << endl;
}

Measured memory_bytes: 640
N = int(input())
S_P = { i+1: input().split() for i in range(N)}
for i in range(N):
    S_P[i+1][1] = int(S_P[i+1][1])
S_P = sorted(S_P.items(), key=lambda x:x[1][1], reverse=True)
S_P = sorted(S_P, key = lambda x:x[1][0])
for i in range(N):
    print(S_P[i][0])
print()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int a,b; cin >>a >>b;
  if(a>12) cout <<b;
  else if(a>5) cout <<b/2;
  else cout <<0;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3576
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=998244353;
const int inf=1<<30;

const int MAX=200001; //nCrのnのMAX+1
ll fac[MAX],finv[MAX],inv[MAX];

void cominit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for (int i=2;i<MAX;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;
	}
}
ll com(int n,int k){ //1≦k≦n≦10^7
	if (n<k) return 0;
	if (n<0||k<0) return 0;
	return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
//Add cominit(); in main function.

ll rui(ll a,ll n){
	ll ans=1;
	while(n>0){
		if(n&1) ans=ans*a%mod;
		a=a*a%mod;
		n/=2;
	}
	return ans;
}

int main(){
	cominit();
	ll n,m,k; cin >> n >> m >> k;
	ll ans=0;
	rep(i,k+1){
		ans+=com(n-1,i)*m%mod*rui(m-1,n-1-i)%mod;
		ans%=mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8328
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll x;
    cin >> x;
    map<ll, int> xmap;
    for (ll i = -8600; i <= 8600; i++) {
        ll w = i * i * i * i * i;
        if (w - x < w) {
            ll t = w - x;
            if (xmap.find(t) != xmap.end()) {
                cout << i << ' ' << xmap[t] << endl;
                return 0;
            }
        }
        xmap[i * i * i * i * i] = i;
    }
}


Measured memory_bytes: 4184
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
//password:+BdCHpO8dQvpo5fnV3/u
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
int w,h,n;
int grid[5050][5050];
int main() {
  cin>>w>>h>>n;
  for(int i=1;i<=n;i++)
  {
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1)
    {
      for(int i=1;i<=x;i++)
      {
        for(int j=1;j<=h;j++)
        {
          grid[i][j]=1;
        }
      }
    }
    if(a==2)
    {
      for(int i=x+1;i<=w;i++)
      {
        for(int j=1;j<=h;j++)
        {
          grid[i][j]=1;
        }
      }
    }
    if(a==3)
    {
      for(int i=1;i<=w;i++)
      {
        for(int j=1;j<=y;j++)
        {
          grid[i][j]=1;
        }
      }
    }
    if(a==4)
    {
      for(int i=1;i<=w;i++)
      {
        for(int j=y+1;j<=h;j++)
        {
          grid[i][j]=1;
        }
      }
    }
  }
  int ans=0;
  for(int i=1;i<=w;i++)
  {
    for(int j=1;j<=h;j++)
    {
      if(grid[i][j]==0) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
fun main(arg: Array<String>) {
    val k = readLine()!!.toInt()
    if (k == 1) {
        println(1)
        return
    }
    val po: Array<Int?> = Array(k) { null }
    po[1] = 1
    var searchSet = setOf(1)
    while (searchSet.isNotEmpty()) {
        val newSet: MutableSet<Int> = mutableSetOf()
        searchSet.forEach {
            val next1 = (it * 10) % k
            val next2 = (it + 1) % k
            if (po[next1] == null || po[it]!! < po[next1]!!) {
                po[next1] = po[it]
                newSet.add(next1)
            }
            if (po[next2] == null || po[it]!! + 1 < po[next2]!!) {
                po[next2] = po[it]!! + 1
                newSet.add(next2)
            }
        }
        searchSet = newSet
    }
    println(po[0])
}


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

typedef long double LD;
typedef long long ll;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define mod             1000000007
#define INF             2147483647
#define Endl            "\n"
#define FasterIO        ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0) ;
#define precision(a)    cout << fixed << setprecision(a)
#define bug(a,b)        cout<<a<<"\t"<<b<<"\n";
#define Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";
#define reset(a,b)      memset(a,b,sizeof(a));
#define srt(a)      sort(a.begin(),a.end());

const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int sz=1e5+9;

int strtoint(string str){
    stringstream ss(str);
    int x = 0;
    ss >> x ;
    return x ;
}
string intostr(int x){
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
void rem(string &s, const string &c) {
	auto pos = s.find(c);
	if (pos == string::npos) {
		cout << -1 << endl;
		exit(0);
	}
	s.erase(0, pos + 1);
}
void println (int n){
    cout<<n<<"\n";
}
void printvec(vector <int> &a){
    for (int i=0;i<a.size();i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printgraph(vector <int> g[],int e){
    for (int i=0;i<e;i++){
        cout<<i<<" --> ";
        for (int j=0;j<g[i].size();j++){
            cout<<g[i][j]<<" ";
        }
        cout<<"\n";
    }
}

void printmap (map <int,int> &mymap){
    for (auto itr = mymap.begin(); itr != mymap.end(); ++itr) {
        cout << '\t' << itr->first
             << '\t' << itr->second << '\n';
    }
    cout << "\n";
}

int n,x,arr[sz],dp[sz];


int rec (int i){
    if (i==n) return 0;
    if (dp[i]!=-1) return dp[i];
    int left = abs(arr[i]-arr[i+1])+rec(i+1);
    int right = INF;
    if (i+2<=n){
        right = abs(arr[i]-arr[i+2])+rec (i+2);
    }
    return dp[i]= min(left,right);
}


void solve(){

    cin>>n;
    reset (dp,-1);
    for (int i=1;i<=n;i++)cin>>arr[i];


    cout << rec (1) << Endl;

    //printvec(v);
}


int main(){
    //FasterIO;

    solve();
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
typedef long long llint;
llint bingo[3][3];
llint n;
llint row[3][3];
llint col[3][3];
llint naname[2][3];

void solve(){
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> row[i][j];
    }
  }
  cin >> n;
  llint b[n];
  for(int i=0;i<n;i++)cin >> b[i];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      col[j][i] = row[i][j];
    }
  }
  for(int j=0;j<3;j++){
    naname[0][j]=row[j][j];
    naname[1][2-j]=row[j][2-j];
  }
  bool f=false;
  for(int k=0;k<n;k++){
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(b[k]==row[i][j])row[i][j]=0;
        if(b[k]==col[i][j])col[i][j]=0;
        if(b[k]==naname[i][j])naname[i][j]=0;
      }
    }
  }
  for(int i=0;i<3;i++){
    if(row[i][0]==row[i][1] && row[i][1]==row[i][2]){
      f=true;
      break;
    }
    if(col[i][0]==col[i][1] && col[i][1]==col[i][2]){
      f=true;
      break;
    }
  }
  for(int i=0;i<2;i++){
    if(naname[i][0]==naname[i][1] && naname[i][1]==naname[i][2])f=true;
  }

  if(f){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  cout << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

int main(){
        int k;
        scanf("%d", &k);

        std::priority_queue<P, std::vector<P>, std::greater<P>> que;
        for(int i=0; i<10; i++) que.push(P(10, i));
        while(k){
                ll a, dig;
                std::tie(dig, a) = que.top();
                que.pop();

                ll tmp = a, td = dig/10;
                while(td>=10){
                        tmp /= 10;
                        td /= 10;
                }
                if(tmp!=0) k--;

                if(k<1){
                        printf("%ld\n", a);
                        break;
                }

                if(tmp>0) que.push(P(dig*10, (tmp-1)*dig+a));
                que.push(P(dig*10, tmp*dig+a));
                if(tmp<9) que.push(P(dig*10, (tmp+1)*dig+a));
        }
        return 0;
}

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

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a[0]>='a'&&a[0]<='z'){
    a[0]+='A'-'a';
  }
  if(b[0]>='a'&&b[0]<='z'){
    b[0]+='A'-'a';
  }
  if(c[0]>='a'&&c[0]<='z'){
    c[0]+='A'-'a';
  }
  cout<<a[0]<<b[0]<<c[0]<<endl;
}

Measured memory_bytes: 256
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int ab[26]={0},dep[26]={0};
string s;
struct node{
	int key;
	vector<char>ch; 
	friend bool operator<(const node &a,const node &b){return a.key>b.key;}
};
priority_queue<node>pq;
void build(){
	
	for(int i=0;i<26;i++){
		if(ab[i]!=0){
			node t; 
			t.ch.push_back(i);
			t.key=ab[i];
			pq.push(t);
//			printf("i %d key %d\n",i,t.key);
		} 
	}
	if (pq.size()==1){
		node a=pq.top(); 
		dep[a.ch[0]]++;return;
	} 
	while(pq.size()>1){
		node a=pq.top();pq.pop();
		node b=pq.top();pq.pop();
		for(int i=0;i<b.ch.size();i++) a.ch.push_back(b.ch[i]);
		for(int i=0;i<a.ch.size();i++) dep[a.ch[i]]++; 
		a.key+=b.key;
		pq.push(a);
	}
//	node ans=pq.top();
//	for(int i=0;i<ans.ch.size();i++) printf("%d ",ans.ch[i]);
//	printf("\n%d\n",ans.key); 
}
main(){
	cin>>s;
	for(int i=0;i<s.size();i++) ab[s[i]%'a']++;
//	for(int i=0;i<26;i++) printf("%d ",ab[i]);printf("\n");
	build(); int sum=0;
//	for(int i=0;i<26;i++) printf("%d ",dep[i]);printf("\n");
	for(int i=0;i<26;i++) sum+=dep[i]*ab[i];
	printf("%d\n",sum);
}	
//aaabccdeeeee


Measured memory_bytes: 3472