akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll a, b, c;
	cin >> a >> b >> c;

	string ans;
	ans = ((a+b-c)*(a+b-c)>4*a*b) ? "Yes" : "No";
	if (c - a - b < 0)
		ans = "No";
	cout << ans << endl;
	return 0;
}

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

int main(){
  // ブルーノが残す一番上のカードを決める O(n)
  // ループ回してO(n^2)で判定できる気がする

  int N, M, ret = 0;
  cin >> N >> M;
  vector< int > Anna(N), Bluno(M);
  for(int i = 0; i < N; i++){
    cin >> Anna[i];
  }
  for(int i = 0; i < M; i++){
    cin >> Bluno[i];
  }
  for(int i = 0; i < M; i++){
    int A = 0, B = i;
    while(A < N && B < M){
      if(Anna[A] == Bluno[B]) B++;
      A++;
    }
    ret = max( ret, B - i);
  }
  cout << ret << endl;
}

Measured memory_bytes: 1232
#include <iostream>

using namespace std;

int main(void){
    string s;
    cin >> s;
    
    int p_num = 0;
    int g_num = 0;
    int win_num = 0;
    int lose_num = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'g' ){
            if(p_num < g_num){
                p_num ++;
                win_num ++;
            } else {
                g_num ++;
            }
        } else {
            if(p_num < g_num){
                p_num ++;
            } else {
                lose_num ++;
                g_num ++;
            }
        }
    }
    cout << win_num - lose_num << endl;
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	// inf := math.MaxInt64
	n, w := scInt2()
	wlist, vlist := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		wlist[i], vlist[i] = scInt2()
	}
	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, w+1)
	}

	for i := 0; i < n; i++ {
		for sumW := 0; sumW <= w; sumW++ {
			if sumW-wlist[i] >= 0 {
				nv := dp[i][sumW-wlist[i]] + vlist[i]
				dp[i+1][sumW] = max(dp[i+1][sumW], nv)
			}
			dp[i+1][sumW] = max(dp[i+1][sumW], dp[i][sumW])
		}
	}
	fmt.Println(dp[n][w])
}

func scStr() string {
	var s string
	fmt.Scan(&s)
	return s
}

func scInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func scInt2() (int, int) {
	var x, y int
	fmt.Scan(&x, &y)
	return x, y
}

func scInt3() (int, int, int) {
	var x, y, z int
	fmt.Scan(&x, &y, &z)
	return x, y, z
}

func scInts(n int) (slice []int) {
	slice = make([]int, n)
	for i := range slice {
		fmt.Scan(&slice[i])
	}
	return slice
}

func hw(h int, w int, init int) [][]int {
	hw := make([][]int, h)
	for i := 0; i < h; i++ {
		hw[i] = make([]int, w)
		for j := 0; j < w; j++ {
			hw[i][j] = init
		}
	}
	return hw
}

func sum(slice []int) (sum int) {
	sum = 0
	for i := range slice {
		sum += slice[i]
	}
	return
}

func uniqueInts(ints []int) (unique []int) {
	m := map[int]bool{}
	for _, v := range ints {
		if !m[v] {
			m[v] = true
			unique = append(unique, v)
		}
	}
	return unique
}

func uniqueStrs(strs []string) (unique []string) {
	m := map[string]bool{}
	for _, v := range strs {
		if !m[v] {
			m[v] = true
			unique = append(unique, v)
		}
	}
	return unique
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func minInts(ints []int) int {
	sort.Ints(ints)
	return ints[0]
}

func maxInts(ints []int) int {
	sort.Ints(ints)
	n := len(ints)
	return ints[n-1]
}

func powi(x, pow int) int {
	return int(math.Pow(float64(x), float64(pow)))
}


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

int main(){
  int n;
  cin>>n;
  while(n>=10){
    n%=10;
  }
  if(n==2||n==4 ||n==5 ||n==7 ||n==9)cout<<"hon"<<endl;
  else if(n==0 ||n==1 ||n==6 ||n==8)cout<<"pon"<<endl;
  else if(n==3)cout<<"bon"<<endl;
}

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

int Dice[100][6];

void shake(int n, char c){
  if(c == 'E'){
    swap(Dice[n][0], Dice[n][3]);
    swap(Dice[n][3], Dice[n][5]);
    swap(Dice[n][5], Dice[n][2]);
  }
  if(c == 'N'){
    swap(Dice[n][0], Dice[n][1]);
    swap(Dice[n][1], Dice[n][5]);
    swap(Dice[n][5], Dice[n][4]);
  }
  if(c == 'S'){
    swap(Dice[n][1], Dice[n][0]);
    swap(Dice[n][0], Dice[n][4]);
    swap(Dice[n][4], Dice[n][5]);
  }
  if(c == 'W'){
    swap(Dice[n][3], Dice[n][0]);
    swap(Dice[n][0], Dice[n][2]);
    swap(Dice[n][2], Dice[n][5]);
  }
}
int main(){
  int i, j, n, judge[100];
  char direction[10] = {"NNNNENNNN"};
  cin >> n;
  for(i = 0; i < 6; i++) cin >> Dice[0][i];
  for(j = 1; j < n; j++){
    for(i = 0; i < 6; i++) cin >> Dice[j][i];
    for(i = 0; i < 10; i++){
      if(Dice[0][1] == Dice[j][1]) break;
      shake(j,direction[i]);
    }
    if(Dice[0][1] != Dice[j][1] && Dice[0][4] != Dice[j][4]) judge[j] = 0;
    else{
      for(i = 0; i < 4; i++){
        if(Dice[0][0] == Dice[j][0] && Dice[0][2] == Dice[j][2] && Dice[0][3] == Dice[j][3] && Dice[0][5] == Dice[j][5]){
          judge[j] = 1;
          break;
        }
        shake(j,'E');
        if(i == 3) judge[j] = 0;
      }
    }
  }
  for(j = 1; j < n; j++){
    if(judge[j] == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main()
{
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  for (auto&& e : p) cin >> e;
  for (auto&& e : q) cin >> e;
  for (auto&& e : r) cin >> e;
  sort(begin(p), end(p), greater<>());
  sort(begin(q), end(q), greater<>());
  priority_queue<int> pq;
  for (int i = 0; i < x; i++)
    pq.push(p[i]);
  for (int i = 0; i < y; i++)
    pq.push(q[i]);
  for (int n : r)
    pq.push(n);
  int64_t ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}


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

int main()
  
{
  string str;
  int strNum = 0;
  cin >> strNum;
  cin >> str;
  
  if(str.size() <= strNum)
  {
    cout << str << endl;
  }
  else cout << str.erase(strNum) << "..." << endl;
  
  return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;
const long long mod=1e9+7;
const long long INF=1LL<<60;

struct edge{long long to,cost;};
typedef pair<long long,long long> P;

vector<edge> G[200010];// 隣接リスト表現
long long d[200010];
long long ds[200010];

void dijkstra(int s,int n){
    priority_queue<P,vector<P>,greater<P> > que;// 距離が小さい順に取り出せるようgreater<P>を指定
    fill(d,d+n,INF);
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;// 更新した頂点の中で距離が最小の頂点v
        if(d[v]<p.first)continue;
        for(auto e:G[v]){// 頂点vから出る辺eを走査
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
void dijkstra2(int s,int n){
    priority_queue<P,vector<P>,greater<P> > que;// 距離が小さい順に取り出せるようgreater<P>を指定
    fill(ds,ds+n,INF);
    ds[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;// 更新した頂点の中で距離が最小の頂点v
        if(ds[v]<p.first)continue;
        for(auto e:G[v]){// 頂点vから出る辺eを走査
            if(ds[e.to]>ds[v]+e.cost){
                ds[e.to]=ds[v]+e.cost;
                que.push(P(ds[e.to],e.to));
            }
        }
    }
}
int main(){
   int n;
   cin>>n;
   vector<long long> a(n),b(n);
   for(int i=0;i<n-1;i++){
       cin>>a[i]>>b[i];
       a[i]--;b[i]--;
       G[a[i]].push_back({b[i],1});
       G[b[i]].push_back({a[i],1});
   }
   
   dijkstra(0,n);dijkstra2(n-1,n);
   int fe=0,sn=0;
   for(int i=0;i<n;i++){
       if(d[i]<=ds[i])fe++;
       else sn++;
   }
   if(fe>sn)cout<<"Fennec"<<endl;
   else cout<<"Snuke"<<endl;
}
 
   

Measured memory_bytes: 14428
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    ll n; cin>>n;
    map<ll,int> mp;
    ll m=n;
    for(ll i=2; i*i<=m; ++i){
        //cout<<"a";
        if(n%i==0){
            //cout<<"b";
            while(n%i==0){
                //cout<<"c";
                n/=i; mp[i]++;
            }
        }
    }
    if(n!=1) mp[n]++;
    int ans=0;
    for(auto & v: mp){
        int a=1;
        while(a*(a+1)<=2*v.second){
            if((a+1)*(a+2)<=2*v.second) a++;
            else break;
        }
        ans+=a;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int a,b,chk1=0,chk2=0;
    string s;
    cin>>a>>b;
    cin>>s;
    if(s.length()==a+b+1 && s[a]=='-'){
        for(int i=0;i<a;i++){
            if(s[i]<48 || s[i]>57){
                chk1=1;
                break;}
        }
       for(int j=a+1;j<s.length();j++){
            if(s[j]<48 || s[j]>57){
                chk2=1;
                break;}
        }

    if(chk1==0 && chk2==0) cout<<"Yes";
    else cout<<"No";
 }
 else cout<<"No";

    return 0;
}


Measured memory_bytes: 3580
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val A = scanner.nextLong()
    val B = scanner.nextLong()
    val S = scanner.next()
    val regex = Regex("[0-9]{$A}-[0-9]{$B}")
    println(if (regex.matches(S)) "Yes" else "No")
}

Measured memory_bytes: 31392
from collections import deque
import bisect

N=int(input())
A=list(map(int,input().split()))
ans=[0]*N
Edge=[[] for _ in range(N)]
loute=[str(0)]*N
for i in range(N-1):
    u,v=map(int,input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)
  
tmp=deque(str(0))
CHN=deque()
LIS=[10**18]*N
label=[False]*N
while tmp:
    T0=int(tmp[-1])
    if label[T0]:
        tmp.pop()
        pos,Val=CHN.pop()
        LIS[pos]=Val
        continue

    pos=bisect.bisect_left(LIS,A[T0])
    CHN.append((pos,LIS[pos]))
    LIS[pos]=A[T0]
    ans[T0]=bisect.bisect_left(LIS,10**18)

    if Edge[T0]:
        for i in Edge[T0]:
            if label[i]==False:
                tmp.append(i)
        label[T0]=True
    else:
        label[T0]=True
    
for i in range(N):
    print(ans[i])

Measured memory_bytes: 78108
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin  >> N >> K;
    int l[N];
    for(int i = 0; i < N; i++){
        cin >> l[i];
    }
    sort(l, l+N, greater<int>());
    int sum = 0;
    for(int i = 0; i < K; i++){
        sum += l[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())
a = [int(x) for x in input().split()]
memo = [0]*(10**5+2)
ans = 1
for i in range(N):
  memo[a[i]] += 1
  memo[a[i]+1] += 1
  memo[a[i]-1] += 1
print(max(memo))


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

int main() {
  int N,D;
  cin >> N >> D;
  cout << (N+(D*2))/((D*2)+1) << endl;
}


Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		sc.close();

		String ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
		int n = s.length() - t.length() + 1;
		for (int i = 0; i < n; i++) {
			if (match(s, t, i)) {
				String str = s.substring(0, i) + t + s.substring(i + t.length(), s.length());
				str = str.replaceAll("\\?", "a");
				if (str.compareTo(ans) < 0) {
					ans = str;
				}
			}
		}
		if ("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz".equals(ans)) {
			System.out.println("UNRESTORABLE");
		} else {
			System.out.println(ans);
		}
	}

	static boolean match(String s, String t, int idx) {
		for (int i = 0; i < t.length(); i++) {
			char ch = s.charAt(idx + i);
			if (ch != '?' && ch != t.charAt(i)) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 22868
from heapq import heappush, heappop
H, W, T, Q = map(int, input().split())
que = []
state = [[0]*(W+1) for i in range(H+1)]
data1 = [[0]*(W+1) for i in range(H+1)]
data2 = [[0]*(W+1) for i in range(H+1)]
def get(data, h, w):
    s = 0
    while h:
        w0 = w
        el = data[h]
        while w0:
            s += el[w0]
            w0 -= w0 & -w0
        h -= h & -h
    return s
def add(data, h, w, x):
    while h <= H:
        w0 = w
        el = data[h]
        while w0 <= W:
            el[w0] += x
            w0 += w0 & -w0
        h += h & -h

for q in range(Q):
    t, c, *ps = map(int, input().split())
    while que and que[0][0] <= t:
        _, h0, w0 = heappop(que)
        add(data1, h0, w0, -1)
        add(data2, h0, w0, 1)
        state[h0][w0] = 2
    if c == 0:
        h0, w0 = ps
        state[h0][w0] = 1
        add(data1, h0, w0, 1)
        heappush(que, (t + T, h0, w0))
    elif c == 1:
        h0, w0 = ps
        if state[h0][w0] == 2:
            add(data2, h0, w0, -1)
            state[h0][w0] = 0
    else:
        h0, w0, h1, w1 = ps
        result1 = get(data1, h1, w1) - get(data1, h1, w0-1) - get(data1, h0-1, w1) + get(data1, h0-1, w0-1)
        result2 = get(data2, h1, w1) - get(data2, h1, w0-1) - get(data2, h0-1, w1) + get(data2, h0-1, w0-1)
        print(result2, result1)

Measured memory_bytes: 119040
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int count(int n) {
    int ans = 0;
    while(n) {
        n /= 10;
        ans++;
    }

    return ans % 2 == 1;
}

int main(void) {
    int N;
    cin>>N;

    int ans = 0;
    for(int i = 1;i <= N;i++) {
        if(count(i))
            ans++;
    }

    cout<<ans<<endl;

    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    
    int l[n];
    for(int i = 0;i < n;i++){
        cin >> l[i];
    }
    
    int ans = 0;
    for(int i = 0;i < n;i++){
        for(int j = i + 1;j < n;j++){
            for(int k = j + 1;k < n;k++){
                if(l[i] == l[j] || l[j] == l[k] || l[i] == l[k]){
                    continue;
                }
                else if(l[i] + l[j] <= l[k] || l[j] + l[k] <= l[i] || l[i] + l[k] <= l[j]){
                    continue;
                }
                ans++;
                //cout << l[i] << ' ' << l[j] << ' ' << l[k] << '\n';
            }
        }
    }
    
    cout << ans;
    return 0;
}


Measured memory_bytes: 3628
/********************************************************************************

        Code by a weak man who named CYJian, and he hopes the code can get more points.

        Algorithm:

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s "in", "r", stdin), freopen(s "out", "w", stdout)

template <typename T> inline void read(T &x) {
    char ch, t = 0;
    x = 0;
    while (!isdigit(ch = ge))
        t |= ch == '-';
    while (isdigit(ch))
        x = x * 10 + (ch ^ 48), ch = ge;
    x = t ? -x : x;
}
inline int read_int() {
    int x;
    return read(x), x;
}
inline ll read_ll() {
    ll x;
    return read(x), x;
}

template <typename T> inline void chkmin(T &a, T b) { a = a < b ? a : b; }
template <typename T> inline void chkmax(T &a, T b) { a = a > b ? a : b; }
//}}}

const int mod = 1e9 + 7;

inline int Mod(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }

int f[5010];
int g[5010];
int P[5010];
int M[5010];
int F[2][5010];

int main() {
#ifdef LOCAL
    FILE("");
#endif

    int n = ri, A = ri, B = ri, res = 1;
    for (int i = 1; i <= n; i++)
        res = Mod(res << 1);
    if (A == 1 || B == 1)
        return printf("%d\n", res), 0;
    if (A > B)
        swap(A, B);
    f[0] = 1, g[0] = 1;
    for (int i = A; i < B; i++) {
        f[i] = Mod(f[i - 1] + g[i - 1]);
        for (int j = A; j <= i; j++)
            Add(g[i], f[i - j]);
    }

    for (int i = 1; i < B; i++)
        for (int j = 1; j <= i; j++)
            P[i] = (P[i] + 1LL * g[i - j] * (i == j ? 1 : j)) % mod;
    for (int i = 1; i < B; i++)
        for (int j = 1; j <= i; j++)
            M[i] = (M[i] + 1LL * g[i - j] * (i == j ? 1 : j - 1)) % mod;

    F[0][0] = F[1][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < B; j++) {
            if (i == j || i == n) {
                F[1][i] = (F[1][i] + 1LL * F[0][i - j] * P[j]) % mod;
                if (i == j)
                    break;
            } else
                F[1][i] = (F[1][i] + 1LL * F[0][i - j] * M[j]) % mod;
        }
        for (int j = 1; j < A; j++) {
            Add(F[0][i], F[1][i - j]);
            if (i == j)
                break;
        }
    }

    cout << Mod(res + mod - Mod(F[0][n] + F[1][n])) << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

const int MAX_N = (int) 1e5 + 1;
// const int MAX_N = 10;

ll A[MAX_N - 1];
ll dp[MAX_N];

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

    int N, M;
    cin >> N >> M;
    // int A[M];
    for (int i = 0; i < M; ++i) {
        cin >> A[i];
    }

    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    int a_idx = 0;
    if (A[0] != 1) {
        dp[1] = 1;
    } else {
        a_idx++;
    }
    const ll X = (ll) 1e9 + 7;
    for (int i = 2; i <= N; ++i) {
        if (a_idx < M && A[a_idx] == i) {
            a_idx++;
        } else {
            dp[i] = dp[i - 1] + dp[i - 2];
            dp[i] %= X;
        }
    }

    cout << dp[N] << '\n';

    return 0;
}


Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	if s == t {
		fmt.Println("Yes")
	} else {
		for i := 0; i < len(s); i++ {
			s = s[1:] + string(s[0])
			if s == t {
				fmt.Println("Yes")
				break
			}
			if i == len(s)-1 {
				fmt.Println("No")
			}
		}
	}
}


Measured memory_bytes: 512
import math

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

A=[]
B=[]

for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

maxA = max(A)
B.sort(reverse=True)


nage = 0
ans = math.ceil((H+maxA)/maxA)#投げなし
for i in range(N):
    nage+=B[i]
    ans = min(ans, (i+1) + math.ceil((max(0,H-nage))/maxA))

print(ans)

Measured memory_bytes: 86832
from itertools import product
n = int(input())

pos = [[int(x) for x in input().split(' ')] for _ in range(n)]

for cx, cy in product(range(101), range(101)):
    H = max(max([abs(p[0]-cx)+abs(p[1]-cy)+p[2] for p in pos if p[2] != 0]), 1)
    if all(max(H-abs(p[0]-cx)-abs(p[1]-cy), 0) == p[2] for p in pos):
        print(cx, cy, H)
        exit()


Measured memory_bytes: 3064
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<ll,ll>

ll memo[100][2];

int main(void)
{
    int n,p;
    cin >> n >> p;
    vector<ll> v(n);
    for(int i = 0;i < n;i++)
    {
        cin >> v[i];
        v[i] %= 2;
    }
    memo[0][0] = 1;
    memo[0][1] = 0;
    for(int i = 0;i < n;i++)
    {
        memo[i+1][0] = memo[i][0];
        memo[i+1][1] = memo[i][1];
        if(v[i])
        {
            memo[i+1][0] += memo[i][1];
            memo[i+1][1] += memo[i][0];
        }
        else
        {
            memo[i+1][0] += memo[i][0];
            memo[i+1][1] += memo[i][1];
        }
    }
    cout << memo[n][p] << endl;
    return 0;
}

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

using namespace std;
#define ll long long
const long long mod=1e9+7;
const int maxn=1e3+7;
int a[maxn],b[maxn];

int dp[maxn][maxn];

int main (){
	int n;cin>>n;
    map<ll,ll>mp;
    ll sum=0;
    for(int i=1;i<=n;i++){
		ll x;cin>>x;
		mp[x]++;
		sum+=x;
    }
    int q;cin>>q;
    while(q--){
		ll a,b;cin>>a>>b;
		sum-=mp[a]*a;
		sum+=mp[a]*b;
		mp[b]+=mp[a];
		mp[a]=0;
		cout<<sum<<endl;
    }
	return 0;
}


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

int main(){
  int64_t n, m;
  cin >> n >> m;
  if(n==1 && m==1){
    cout << 1 << endl;
  }else if(n==1 || m==1){
    cout << max(n, m) - 2 << endl;
  }else{
    cout << (n-2)*(m-2) << endl;
  }
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int d[300];

int main(){
	while(cin>>n){
		rep(i,n){
			cin>>d[i];
		}
		int p = 0;
		unsigned long long int dp[100][22]={0};//dp[i][j]
		dp[0][d[0]] = 1;
		for(int i = 1;i < n-1;i++){
			for(int j = 0;j <=20;j++){
				if(dp[i-1][j]>0){
					if(j+d[i] <=20){
						dp[i][j+d[i]] +=dp[i-1][j];
					}
					if(j-d[i]>=0)
						dp[i][j-d[i]] +=dp[i-1][j];
				}
			}
		}
		int sum = 0;
		for(int i = 0;i <=100000000;i++){
			sum +=1;
		}
		cout <<dp[n-2][d[n-1]]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
// https://atcoder.jp/contests/abc166/tasks/abc166_e

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,avx512f")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>

using uint = unsigned int;
signed main() {
  uint n;
  std::cin >> n;
  std::vector<uint> a;
  a.reserve(n);
  for (uint i = 0; i < n; ++i) { uint t; std::cin >> t; a.emplace_back(t); }

  std::vector<uint> ansv(16);
  uint k = 0;
  for (uint i = 0; i < n; ++i) {
    for (uint j = i + 1; j < n; ++j) {
      ansv[k] += (j - i) == a[j] + a[i];
    }
    ++k;
    if(k > 15){k-=16;}
  }

  long long ans = 0;
  for (const auto& x : ansv) { ans += x; }
  std::cout << ans << std::endl;

  return 0;

}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
string m[111];
ll a,b;
ll vx[4] = {1,0,-1,0};
ll vy[4] = {0,1,0,-1};
bool check(ll x,ll y){
  return x>=0&&x<a&&y>=0&&y<b;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>m[i];
  }
  bool ans = true;
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      bool fl = true;
      for(int k=0;k<4;k++){
	ll x = i+vx[k],y = j+vy[k];
	if(m[i][j] == '#' && check(x,y) && m[x][y] == '#'){fl = false;}
      }
      if(m[i][j] == '#' && fl)ans = false;
    }
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
(defun pow (x n)
    (if (= n 0)
        1
        (* x (pow x (1- n)))))


(let (
		(a (read))
		(b (read))
		(c (read))
		(k (read))
		(maxvalue 0)
		(shit 0))
	(setf maxvalue (max a b c))
	(setf shit (- (+ a b c) maxvalue))
	(setf maxvalue (* maxvalue (pow 2 k)))
	(format t "~D~%" (+ shit maxvalue)))

Measured memory_bytes: 14692
#include <iostream>
#include <cstdio>
using namespace std;
int n, a[5][105], d[5][105];
int main() {
	int i, j;
	cin>>n;
	for(i=1; i<=2; i++) for(j=1; j<=n; j++) cin>>a[i][j];
	for(i=1; i<=2; i++) for(j=1; j<=n; j++) d[i][j] = max(d[i-1][j], d[i][j-1]) + a[i][j];
	cout<<d[2][n];
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n; cin>>n;
	ll sm=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				int a=i, b=j;
				int po=__gcd(a,b);
				int y=__gcd(po,k);
				sm+=y;
			}
		}
	}
	cout<<sm;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a*b>c*d) cout<<a*b;
  if(a*b<c*d) cout<<c*d;
  if(a*b==c*d) cout<<c*d;
  cout<<"\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;

#define A_MAX 500000
#define INVALID -2000000000

int A[A_MAX];

int parent(int i) {
    return i / 2;
}

int left(int i ) {
    return i * 2;
}

int right(int i ) {
    return i * 2 + 1;
}

void max_heapify(int i, int m) {
    int l = left(i);
    int r = right(i);
    int largest;
//    printf("max_heapify(%d, %d)\n", i, m);
    if (l <= m && A[l-1] > A[i-1]) {
        largest = l;
    }
    else {
        largest = i;
    }
    if (r <= m && A[r-1] > A[largest-1]) {
        largest = r;
    }

    if (largest != i) {
        int tmp = A[i-1];
        A[i-1] = A[largest-1];
        A[largest-1] = tmp;
        max_heapify(largest, m);
    }
}

void build_max_heap(int m) {
    for (int i = m/2; i > 0; i--) {
        max_heapify(i, m);
    }
}

int main() {
    int m;

    cin >> m;

    for (int i = 0; i < m; i++) {
        cin >> A[i];
    }

    build_max_heap(m);

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

    return 0;
}



Measured memory_bytes: 5016
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int MOD = 1e+7;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

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

  int H, W;
  cin >> H >> W;
  vector<string> grid(H);
  rep(h, H) cin >> grid[h];

  int res = -1;
  rep(sh, H) {
    rep(sw, W) {
      if(grid[sh][sw] == '#') continue;
      queue<pair<int, int>> que;
      vector<vector<int>> dist(H, vector<int> (W, -1));
      dist[sh][sw] = 0;
      que.push({sh, sw});

      while(!que.empty()) {
        int vh = que.front().fi;
        int vw = que.front().se;
        que.pop();

        rep(dir, 4) {
          int nvh = vh + dy[dir];
          int nvw = vw + dx[dir];

          if(nvh < 0) continue;
          if(nvw < 0) continue;
          if(nvh >= H) continue;
          if(nvw >= W) continue;
          if(dist[nvh][nvw] != -1) continue;
          if(grid[nvh][nvw] == '#') continue;

          dist[nvh][nvw] = dist[vh][vw]+1;
          que.push({nvh, nvw});
        }
      rep(gh, H) rep(gw, W) res = max(res, dist[gh][gw]);
      }
    }
  }
  cout << res << endl;
  return 0;
}

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

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

    auto l = 0;
    auto r = s.size() - 1;
    auto result = 0;

    while (l < r)
    {
        result += s[l] != s[r];

        l++;
        r--;
    }

    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
vector<ll> visited(1e5,0);
vector<pair<ll,ll>> node[(ll)1e5];
vector<ll> ans(1e5,0);
ll maxi = 0;
void dfs(ll num,ll x,ll pos){
  if(visited[num] == 1){
    return;
  }
  visited[num] = 1;
  if(pos != -1){
    ans[pos] = x+1;
  }
  for(auto itr:node[num]){
    if(visited[itr.first] != 1){
      x++;
      x %= maxi;
      dfs(itr.first,x,itr.second);
    }
  }
}
int main(){
  ll n;
  cin >> n;
  rep(i,n-1){
    cin >> tmp1 >> tmp2;
    tmp1--,tmp2--;
    node[tmp1].emplace_back(tmp2,i);
    node[tmp2].emplace_back(tmp1,i);
  }
  vector<ll> sum(n,0);
  rep(i,n-1){
    chmax(maxi,(ll)node[i].size());
  }
  dfs(0,0,-1);
  cout << maxi << endl;
  rep(i,n-1){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 10368
N = int(input())
H = list(map(int,input().split()))

Judge = True
MAX = 0

for i in range(N):
    # print(H[i])
    if i == 0:
        continue
    else:
        if MAX > H[i]:
            Judge = False
            break

        if H[i-1] > H[i]:
            tmp = H[i-1]-1
            MAX = tmp

            if tmp > H[i]:
                Judge = False
                break

        else:
            continue


if Judge:
    print("Yes")
else:
    print("No")

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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	// your code goes here
	string s;
	cin>>s;
	deque <char> q;
	for(int i=0;i<s.length();i++)
	  q.push_front(s.at(i));
	int qq;
	cin>>qq;
	int rev=0;
	for(int i=1;i<=qq;i++)
	 {
	 	int ti;
	 	cin>>ti;
	 	if(ti==1)
	 	 rev++;
	 	else
	 	{
	 	int fi;cin>>fi;char ch;cin>>ch;	
	 	 if((rev & 1)==0)
	 	  {
	 	  	if(fi==1) 
	 	  	  q.push_back(ch);
	 	  	else 
	 	  	  q.push_front(ch);
	 	  }
	 	 else 
	 	 {
	 	    if(fi==2) 
	 	  	  q.push_back(ch);
	 	  	else 
	 	  	  q.push_front(ch);	
	 	 }
	 	} 
	 }
	 if((rev & 1)==0)
	   {
	   	while(!q.empty())
	   	 {cout<<q.back();
	   	 q.pop_back();}
	   }
	 else
	  {
	  	while(!q.empty())
	   	 {cout<<q.front();
	   	 q.pop_front();}
	  }
	return 0;
}

Measured memory_bytes: 976
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
    char a;
    cin >> a;
    if (a >= 'a' && a <='z'){
        cout << 'a';
    }else {
        cout << 'A';
    }
}

Measured memory_bytes: 3632
s = input()
ans = 0
while len(s):
    c = s[0]
    for i in range(len(s)):
        if s[i] != c:
            idx = i
            break
        idx2 = i
    if idx2 == len(s)-1:
        break
    s = s[idx:]
    ans += 1

print(ans)


Measured memory_bytes: 3188
#include<queue>
#include<cstdio>
#include<cstring>

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

using namespace std;

const int INF=1<<29;
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

struct Stat{
	int x,y,d;
	bool operator<(const Stat &S)const{ return d>S.d; }
};

int main(){
	for(int h,w,n;scanf("%d%d%d",&h,&w,&n),h;){
		char cmd[1000001]; scanf("%s",cmd);
		int sx,sy,gx,gy;
		static char B[1000][1001];
		rep(i,h){
			scanf("%s",B[i]);
			rep(j,w){
				if(B[i][j]=='S') sx=j, sy=i;
				if(B[i][j]=='G') gx=j, gy=i;
			}
		}

		int len=strlen(cmd);
		static int dir[1000001];
		dir[0]=1;
		rep(i,len) dir[i+1]=(dir[i]+(cmd[i]=='L'?1:3))%4;

		static int next[1000001][4];
		rep(k,4) next[len][k]=(k==dir[len]?len:INF);
		for(int i=len;i>0;i--) rep(k,4) {
			if(k==dir[i-1]) next[i-1][k]=i-1;
			else            next[i-1][k]=next[i][k];
		}

		static int d[1000][1000][4];
		rep(i,h) rep(j,w) rep(k,4) d[i][j][k]=INF;
		d[sy][sx][1]=0;

		bool ok=false;
		priority_queue<Stat> pq; pq.push((Stat){sx,sy,0});
		while(!pq.empty()){
			Stat S=pq.top(); pq.pop();

			if(d[S.y][S.x][dir[S.d]]<S.d) continue;
			if(S.x==gx && S.y==gy){ ok=true; break; }

			rep(k,4){
				int xx=S.x+dx[k],yy=S.y+dy[k];
				if(0<=yy && yy<h && 0<=xx && xx<w && B[yy][xx]!='#'){
					if(next[S.d][k]<d[yy][xx][k]){
						d[yy][xx][k]=next[S.d][k];
						pq.push((Stat){xx,yy,next[S.d][k]});
					}
				}
			}
		}

		puts(ok?"Yes":"No");
	}

	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#define R register
#define ll long long
#define int long long
using namespace std;

ll base[40];
ll D;
ll ans=0;
ll st[40];

inline void dfs(int now,int len,ll sum)
{
	if(now==len/2+1)
	{
		if(sum!=D) return;
		ll tans=st[1]>=0?(9-st[1]):(9+st[1]);
		for(R int i=2;i<now;i++) tans=tans*(st[i]>=0?(10-st[i]):(10+st[i]));
		ans+=len&1?tans*10:tans;
		return ;
	}
	if(sum+10ll*(base[len-now]-base[now-1])<D) return ;
	if(sum-10ll*(base[len-now]-base[now-1])>D) return ;
	for(R int ss=-9;ss<=9;ss++)
	{
		st[now]=ss;
		dfs(now+1,len,sum+st[now]*(base[len-now]-base[now-1]));
	}
	return ;
}

signed main()
{
	scanf("%lld",&D);
	int tmp=0;ll d=D;
	base[0]=1;
	while(d) tmp++,d/=10;
	for(R int i=1;i<=18;i++) base[i]=base[i-1]*10;
	for(R int i=tmp;i<=18;i++) dfs(1,i,0);
	printf("%lld\n",ans);
	return 0;
}

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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

int N,M;
vi al[100000];
int col[100000];

bool dfs(int i,int c) {
	if (col[i]) return col[i]==c;
	bool s=1;
	col[i]=c;
	for (int j:al[i]) {
		if (!dfs(j,3-c)) s=0;
	}
	return s;
}

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

	ll nt=0,ne=0;
	cin >> N >> M;
	for (int i=0;i<M;i++) {
		int u,v;cin >> u >> v;u--;v--;
		al[u].push_back(v);
		al[v].push_back(u);
	}

	ll ns=0;
	for (int i=0;i<N;i++) if (col[i]==0) {
		if (al[i].size()==0) ns++;
		else {
		nt++;
		ne+=dfs(i,1);
		}
	}

	cout << nt*nt+ne*ne+2*ns*N-ns*ns << endl;

}

Measured memory_bytes: 9984
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d=0,f;
	while(cin>>a>>b>>c)
	{
		for(int i=a;i<=b;i++)
	{
		f=c%i;
		if(f==0)
		d++;
	}
	cout<<d<<endl;
	}
	    

		


	

}

Measured memory_bytes: 3096
#include <iostream>
#include <cmath>

using namespace std;
int i,n,h[100005];
long long dp[100005];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>h[i];
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for(i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1408
fn main() {
  let n: usize = get::val();
  let mut veca: Vec<usize> = get::list(); veca.sort(); veca.reverse();
  let mut vecb: Vec<usize> = get::list(); vecb.sort(); vecb.reverse();
  let mut vecc: Vec<usize> = get::list(); vecc.sort(); vecc.reverse();

  let mut diff1 = vec![];
  let mut diff2 = vec![];
  let mut i = 0;
  let mut j = 0;
  for a in veca {
    while i < n && vecb[i] > a {i+=1}
    diff1.push(i)
  }
  for b in vecb {
    while j < n && vecc[j] > b {j+=1}
    diff2.push(j)
  }

  diff1.reverse();
  let asum = diff2.iter().scan(0,|a,&x|{*a+=x; Some(*a)}).collect::<Vec<_>>();
  let mut ans = 0;
  for &d in &diff1 {
    if d != 0 {ans += asum[d-1]}
  }

  println!("{}", ans)
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().chars().collect()
  }
}


Measured memory_bytes: 13596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 1000000005
#define NIL -1
int main(){
    string s; cin >> s;
    bool flag;
    ll cnt = 0;
    if(s[0] == 'B'){
        cnt++;
        flag = true;
    }
    if(s[0] == 'W'){
        cnt++;
        flag = false;
    }
    for(int i = 1; i < s.size(); i++){
        if(s[i] == 'B' && !flag){
            flag = true;
            cnt++;
        } else if(s[i] == 'W' && flag){
            flag = false;
            cnt++;
        }
    }
    cout << cnt -1 << endl;
}

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

int main(){
    unsigned long M, K;
    cin >> M >> K;
    if(M == 1){
        puts(K ? "-1" : "0 0 1 1");
    }else{
        if(1 << M <= K){
            puts("-1");
        }else{
            cout << K << " ";
            for(unsigned long i = 0; i < 1 << M; ++i){
                if(i ^ K)cout << i << " ";
            }
            cout << K;
            for(unsigned long i = 1UL << M; i;){
                if(--i ^ K)cout << " " << i;
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll cnt = 0;
    REP(i, N) {
        if (A[i] == cnt + 1) cnt++;
    }

    print(cnt == 0 ? -1 : N - cnt);
    
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof a)
#define rep(i, a, b) for(int i(a), i##_END_(b); i <= i##_END_; i++) 
#define drep(i, a, b) for(int i(a), i##_END_(b); i >= i##_END_; i--)
using namespace std;
template<class T> inline bool tomax(T &a, T b) {return a < b ? a = b, 1 : 0;}
template<class T> inline bool tomin(T &a, T b) {return b < a ? a = b, 1 : 0;}
typedef long long ll;
typedef double db;

int main() {
    int l, r;
    ll ans = 1e18;
    scanf("%d%d", &l, &r);
    if(r - l + 1 >= 2019) puts("0");
    else {
        rep(i, l, r)
            rep(j, i + 1, r)
                tomin(ans, (ll) i * j % 2019);
        printf("%lld\n", ans);
    }
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i < 10; i++)
    {
        if (n % i == 0 && n / i < 10)
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b);
#define chmin(a, b) (a)=min(a, b);
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

ll N, M;
ll a[MAX];

ll ok(ll x) {
  ll i;
  ll cnt=0;
  
  for(i=0; i<N; i++)
    cnt+=N-(ll)(lower_bound(a, a+N, x-a[i])-a);
  
  return cnt<M;
}


int main(void) {
  ll i, j, k;
  
  cin >> N >> M;
  
  for(i=0; i<N; i++) cin >> a[i];
  sort(a, a+N);
  
  ll l=0, r=INF;
  while(l+1<r) {
    ll m=(l+r)/2;
    if(ok(m)) r=m;
    else l=m;
  }
  
  ll s[MAX]={};
  for(i=0; i<N; i++) s[i+1]=s[i]+a[i];
  
  ll ans=0;
  ll x=r;
  for(i=0; i<N; i++) {
    ll pos=lower_bound(a, a+N, x-a[i])-a;
    ll cnt=N-pos;
    ans+=a[i]*cnt+(s[N]-s[pos]);
    M-=cnt;
  }
  
  ans+=(x-1)*M;
  pt(ans);
}





Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int sum(int n);

int main()
{
   int n;
   cin>>n;
   int x=sum(n);
   if(n%x==0) cout<<"Yes\n";
   else cout<<"No\n";
}

int sum(int n)
{
    int x=0;
    while(n>0)
    {
        x+=n%10;
        n/=10;
    }
    return x;
}



Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*

	Optimizer

*/
//#pragma GCC optimize("Ofast")

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;

	int s_length = s.size();

	if((s.size() % 2 == 0) ^ (s[0] == s[s_length - 1])) {
		cout  << "Second" << endl;
	}
	else {
		cout  << "First" << endl;
	}

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main(){
  ll H;
  cin >> H;
  ll ans;
  rep(i, 40){
    if(pow(2, i) <= H && H < pow(2, i+1)){
      ans = pow(2, i+1) - 1;
      break;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>
 
// #include <unordered_set>
// #include <unordered_map>
 
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
 
#define pb push_back
#define mp make_pair
 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
 
typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;
 
const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
 
using namespace std;
 
#define N 1000000

int arr[N];
int a[N];
 
// void eratosthenes(){
//     REP(i,N){
//         arr[i]=1;
//     }
//     for(int i=2;i<sqrt(N);i++){
//         if(arr[i]){
//             for(int j=0;i*(j+2)<N;j++){
//                 arr[i*(j+2)]=0;
//             }
//         }
//     }
//     arr[0]=0;
//     arr[1]=0;
// }
 
signed main(){
 	

    int a,b;
    cin>>a>>b;

    int num;

    if(b==100){
        num=a*1000+b;
    }else if(10<=b&&b<=99){
        num=a*100+b;
    }else{
        num=a*10+b;
    }

    // cout<<num<<endl;

    bool flag=false;

    REP(i,1000){
        if(i*i==num){
            flag=true;
            break;
        }
    }

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

Measured memory_bytes: 256
def bubble_sort(ary)
  (ary.length - 1).times do
    for n in 0...ary.length-1
      ary[n],ary[n + 1] = ary[n + 1],ary[n] if ary[n] > ary[n + 1]
    end
  end
end

ary = gets.chomp.split.map(&:to_i)

bubble_sort(ary)
puts "#{ary[0]} #{ary[1]} #{ary[2]}"

Measured memory_bytes: 8596