akhauriyash/Code-Regression huggingface dataset:
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let v: Vec<char> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.chars().collect()
    };

    let mut w_count = vec![0; n];
    let mut e_count = vec![0; n];

    if v[0] == 'W' {
        w_count[0] = 1;
    }
    for i in 1..n {
        w_count[i] = w_count[i - 1];
        if v[i] == 'W' {
            w_count[i] += 1;
        }
    }

    if v[n - 1] == 'E' {
        e_count[n - 1] = 1;
    }
    for i in (0..(n - 1)).rev() {
        e_count[i] = e_count[i + 1];
        if v[i] == 'E' {
            e_count[i] += 1;
        }
    }

    let mut min = std::usize::MAX;
    for i in 0..n {
        let w = if i == 0 {
            0
        } else {
            w_count[i - 1]
        };
        let e = if i == n - 1 {
            0
        } else {
            e_count[i + 1]
        };
        // let w = match w_count.get(i - 1) {
        //     Some(a) => *a,
        //     None => 0,
        // };
        // let e = match e_count.get(i + 1) {
        //     Some(a) => *a,
        //     None => 0,
        // };
        if w + e < min {
            debugln!("{}: {}", i, w + e);
            min = w + e;
        }
    }

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


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

int main(){
   while(true){
       int n,x,cnt=0; cin>>n>>x;
       if(n==0&&x==0) break;
       for(int i=1;i<n-1;i++){
           for(int j=i+1;i+j<x;j++){
               int z=x-i-j;
               if(j<z&&z<=n) cnt++;
           }
       }
       cout<<cnt<<endl;
   }
}


Measured memory_bytes: 3104
#include <stdio.h>
#include <algorithm>
using namespace std;

int N, B[111];

int main()
{
	scanf ("%d", &N);
	for (int i = 1; i < N; i++) scanf ("%d", &B[i]);

	int A = B[1] + B[N-1];
	for (int i = 2; i < N; i++) A += min(B[i - 1], B[i]);
	printf ("%d\n", A);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<cstring>
#include<set>
using namespace std;
const int inf = 1e9;
const int maxn = 1e5 + 10;

set<string>ss;

int main()
{
	int n;
	cin >> n;
	string s;
	while (n--)
	{
		cin >> s;
		ss.insert(s);
	}
	cout << ss.size();

	return 0;
}

Measured memory_bytes: 19128
k = ['N','E','S','W']
v = [[0,1],[1,0],[0,-1],[-1,0]]
while True:
    n = int(input())
    if not(n): break
    x,y = 10,10
    p = [list(map(int,input().split())) for _ in range(n)]
    for d,r in [input().split() for _ in range(int(input()))]:
        t = v[k.index(d)]
        for _ in range(int(r)):
            x,y =  x+t[0],y+t[1]
            if [x,y] in p: del p[p.index([x,y])]
    print('Yes' if not(p)else 'No')

Measured memory_bytes: 7616
#include <stdio.h>

int dp[45];

int fib(int x) {
  if (dp[x] != -1) {
    return dp[x];
  }
  
  if (x == 0 || x == 1) {
    dp[x] = 1;
    return dp[x];
  } else {
    dp[x] = fib(x - 1) + fib(x - 2);
    return dp[x];
  }
}

int main(void) {
  int i, n;
  for (i = 0; i < 45; i++) {
    dp[i] = -1;
  }
  scanf("%d", &n);

  printf("%d\n", fib(n));

  return 0;
}



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

def main():
    s = input()
    k = int(input())

    n = len(s)
    substrings = set()
    for i in range(n):
        maxlen = min(5, n - i)
        for l in range(1, maxlen + 1):
            ss = s[i:i + l]
            substrings.add(ss)

    li = list(sorted(list(substrings)))
    print(li[k - 1])

main()


Measured memory_bytes: 4680
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef long long LL;

priority_queue<ii> Q;
LL val[2];
int A[2][100010];

int main() {
   int N;
   bool flag = 0;
   scanf("%d", &N);
   for (int i = 0; i < N; i++) {
      scanf("%d %d", &A[0][i], &A[1][i]);
      Q.push(ii(A[0][i] + A[1][i], i));
   }//for
   for (int i = 0; i < N; i++) {
      val[flag] += A[flag][Q.top().second];
      Q.pop();
      flag = !flag;
   }//for
   printf("%lld\n", val[0] - val[1]);
   return 0;
}//main


Measured memory_bytes: 1912
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    /*set<string> st;
    rep(i,n){
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;*/
    map<string,int> mp;
    int ans=0;
    while(n--){
        string s;
        cin>>s;
        mp[s]++;
    }
    for(auto p:mp) ans++;
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 19260
#include<stdio.h>
 
int main(){ 
  long int a, b, v, w, t;
  int c = scanf("%ld %ld %ld %ld %ld", &a, &v, &b, &w, &t);
  
  long int dStart, dv, isCatch;
  dv = v-w;
  dStart = labs(a-b);
//  printf("%ld %ld\n", dStart, dv);
  
  if(dv<=0){
    isCatch=0;
  }
  else if(dv*t>=dStart){
    isCatch=1;
  }
  else{
    isCatch=0;
  }
  
  if(isCatch==1){
    printf("YES");
  }
  else{
    printf("NO");
  }
  return 0;
}

Measured memory_bytes: 1724
N = int(input())
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
if x1+y1 > x2+y2:
    max1 = x1+y1
    min1 = x2+y2
else:
    max1 = x2+y2
    min1 = x1+y1

if x1-y1 > x2-y2:
    max2 = x1-y1
    min2 = x2-y2
else:
    max2 = x2-y2
    min2 = x1-y1

for i in range(N-2):
    x, y = map(int, input().split())
    if x+y > max1:
        max1 = x+y
    elif x+y < min1:
        min1 = x+y
    
    if x-y > max2:
        max2 = x-y
    elif x-y < min2:
        min2 = x-y


ans = print(max((max1-min1),(max2-min2)))

Measured memory_bytes: 9244
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.next_usize();
    let a = sc.next_isize();
    let b = sc.next_isize();

    let diff = (a - b).abs();

    if diff % 2 != 0 {
        println!("{}", "Borys");
    } else {
        println!("{}", "Alice");
    }
}

pub struct Scanner {
    buf: std::collections::VecDeque<String>,
}

impl Scanner {
    pub fn new() -> Self {
        Self {
            buf: std::collections::VecDeque::new(),
        }
    }

    fn scan_line(&mut self) {
        let mut flag = 0;
        while self.buf.is_empty() {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let mut iter = s.split_whitespace().peekable();
            if iter.peek().is_none() {
                if flag >= 5 {
                    panic!("There is no input!");
                }
                flag += 1;
                continue;
            }

            for si in iter {
                self.buf.push_back(si.to_string());
            }
        }
    }

    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        self.scan_line();
        self.buf
            .pop_front()
            .unwrap()
            .parse()
            .unwrap_or_else(|_| panic!("Couldn't parse!"))
    }

    pub fn next_usize(&mut self) -> usize {
        self.next()
    }

    pub fn next_isize(&mut self) -> isize {
        self.next()
    }

    pub fn next_chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }

    pub fn next_string(&mut self) -> String {
        self.next()
    }

    pub fn next_char(&mut self) -> char {
        self.next()
    }

    pub fn next_float(&mut self) -> f64 {
        self.next()
    }
}


Measured memory_bytes: 2080
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    long long sum=0;
    long long max1,x;
    scanf("%lld",&x);
    max1=x;
    int i;
    for(i=1;i<n;i++)
    {
        scanf("%lld",&x);
        if(x<max1)
        {
            sum=sum+max1-x;
        }
        else
            max1=x;
    }
    printf("%lld\n",sum);
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  set<char> sc;
  REP(i, s.length()) sc.insert(s[i]);
  if (sc.size() == 26) {
    cout << "None" << endl;
  } else {
    for (char c = 'a'; c <= 'z'; ++c) {
      if (sc.find(c) == sc.end()) {
        cout << c << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 512
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

def dfs(x,y):
    c[x][y]='0'
    for dx in range(-1,2):
        for dy in range(-1,2):
            nx=dx+x
            ny=dy+y
            if c[nx][ny]=='1':dfs(nx,ny)

while 1:
    c=[]
    w,h=map(int,input().split())
    if w==h==0:exit()
    w+=2
    c=[list('@'*w)]
    for i in range(h):
        c+=[list('@'+input().replace(' ','').replace('\n','')+'@')]
    c+=[list('@'*w)]
    h+=2
    cnt=0

    for i in range(1,h):
        for j in range(1,w):
            if c[i][j]=='1':
                dfs(i,j)
                cnt+=1
    print(cnt)


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

using namespace std;

int main(){
int a,b,c;
cin >> a;
cin >> b;
cin >> c;
if(a!=b && b!=c && a!=c){
  cout << "No";
}
else if (a==b && b==c){
  cout <<"No";
}
else {
  cout <<"Yes";
}
return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
D - Knight
https://atcoder.jp/contests/abc145/tasks/abc145_d

"""
import sys


def modinv(a, m):
    b, u, v = m, 1, 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    return u if u >= 0 else u + m


def solve(X, Y):
    MOD = 10**9 + 7
    if (X + Y) % 3:
        return 0
    n = (X - 2 * Y) / -3.0
    m = (Y - 2 * X) / -3.0
    if not n.is_integer() or not m.is_integer() or n < 0 or m < 0:
        return 0
    n, m = int(n), int(m)
    x1 = 1
    for i in range(2, n + m + 1):
        x1 = (x1 * i) % MOD
    x2 = 1
    for i in range(2, n+1):
        x2 = (x2 * i) % MOD
    for i in range(2, m+1):
        x2 = (x2 * i) % MOD
    ans = (x1 * modinv(x2, MOD)) % MOD
    return ans


def main(args):
    X, Y = map(int, input().split())
    ans = solve(X, Y)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

int main() {
  int N; cin >> N;
  int ans =0;
  for (int i =1; i<=N; i+=2) {
    int count8 =0;  
    for (int j =1; j<=N; j+=2) {
      if (i % j == 0) count8++;
    }
    if (count8 == 8) ans++;
  }
  cout << ans << endl; 
}


Measured memory_bytes: 3600
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;
const ll INF = 1e18;

ll x[N];

int main(){
	fastio;
	int n, k; cin>>n>>k;
	For(i,0,n) cin>>x[i];
	ll ans = INF;
	For(i,0,n){
		if(i+k>n) break;
		ll cur=0;
		ll left = x[i]<0 ? -x[i]:0;
		ll right = x[i+k-1]>0 ? x[i+k-1]:0;
		cur = min(left*2+right,right*2+left);
		ans = min(cur,ans);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4388
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var ABCD = Sarray()[0];
            var A = ABCD / 1000;
            var B = ABCD % 1000 / 100;
            var C = ABCD % 100 / 10;
            var D = ABCD % 10;
            var pt = new long[] { +1, -1 };
            var pts = new string[] { "+", "-" };
            for (var i = 0; i < 2; ++i)
                for (var j = 0; j < 2; ++j)
                    for (var k = 0; k < 2; ++k)
                    {
                        if (7 == A + pt[i] * B + pt[j] * C + pt[k] * D)
                        {
                            WriteLine($"{A}{pts[i]}{B}{pts[j]}{C}{pts[k]}{D}=7");
                            return;
                        }
                    }
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28212
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int w,n,a,b;
    char c;
    cin >> w >> n;
    vector<int> v;
    for(int i = 0 ; i < w ; i++){
	v.push_back(i+1);
    }
    for(int i = 0 ; i < n ; i++){
	cin >> a >> c >> b;
	a--; b--;
	swap(v[a],v[b]);
    }
    for(int i = 0 ; i < w ; i++){
	cout << v[i] << endl;
    }
    return 0;
}

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

#define fi first
#define se second
#define inf 0x3f3f3f3f
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define MOD 1000000007
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
void dfs(string s,char c){
	if(s.size()==n){
		cout << s << '\n';
		return ;
	}
	for(char i='a';i<=c;i++){
		if(i==c){
			char x = i+1;
			dfs(s+i,x);
		}else
			dfs(s+i,c);
	}
}


int32_t main(){
	cin >> n;
	string aux = "";
	char x='a';
	dfs(aux,x);	
	
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}







Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<queue>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int maxm = 2007, maxn = 1007;
int cnt = 1;
int head[maxn], visited[maxn], dfn[maxn], visited1[maxn];
int b[maxn];
struct edge
{
	int u, v, next;
}e[maxm];
void addedge(int u, int v)
{
	e[cnt].u = u;
	e[cnt].v = v;
	e[cnt].next = head[u];
	head[u] = cnt;
	cnt++;
}
vector<int> v;
int ans = 1e9 + 7;
void dfs(int x, int num)
{
	visited[x] = 1;
	dfn[x] = num;
	for (int i = head[x]; i > 0; i = e[i].next)
	{
		int y = e[i].v;
		if (visited1[y] == 1)
		{
			if (dfn[x] - dfn[y] + 1 < ans)
			{
				ans = dfn[x] - dfn[y] + 1;
				int sz = v.size();
				for (int i = 1; i <= ans; i++)
				{
					b[i] = v[sz - i];
				}
			}
		}
		if (visited[y] == 0)
		{
			visited1[y] = 1;
			v.push_back(y);
			dfs(y, num + 1);
		}
	}
	v.pop_back();
	visited1[x] = 0;
}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		addedge(x, y);
	}
	for (int i = 1; i <= n; i++)
	{
		if (visited[i] == 0)
		{
			v.clear();
			v.push_back(i);
			visited1[i] = 1;
			dfs(i, 1);
		}
	}
	if (ans == 1e9 + 7)
		printf("-1\n");
	else
	{
		printf("%d\n", ans);
		for (int i = ans; i >= 1; i--)
		{
			printf("%d\n", b[i]);
		}
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int K=sc.nextInt();

		if(A > K) {
			System.out.println(K);
		}else if(A + B >= K) {
			System.out.println(A);
		}else {
			System.out.println(A - (K - A - B));
		}

		sc.close();

	}
}


Measured memory_bytes: 35560
package main

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

func main() {
	s := IOInitialize()
	N := Int(s)
	l2 := []int{}
	for i := 0; i <= 31; i++ {
		l2 = append(l2, pow(-2, i))
	}
	posSumLis := []int{}
	negaSumLis := []int{}
	posSum := 0
	negaSum := 0
	for i, num := range l2 {
		if i == 0 {
			posSum += num
			posSumLis = append(posSumLis, posSum)
			continue
		}
		if i%2 == 0 {
			posSum += num
			posSumLis = append(posSumLis, posSum)
		} else {
			negaSum += num
			negaSumLis = append(negaSumLis, negaSum)
		}
	}
	if N == 0 {
		fmt.Println("0")
		return
	}
	indexes := getIndexes(N, l2, posSumLis, negaSumLis)
	maxIndex := indexes[0]
	res := ""
	for i := 0; i <= maxIndex; i++ {
		if isInSlice(indexes, i) {
			res = "1" + res
		} else {
			res = "0" + res
		}
	}
	fmt.Println(res)
}

func isInSlice(slice []int, num int) bool {
	for _, _num := range slice {
		if num == _num {
			return true
		}
	}
	return false
}

func serachIndex(N int, posSumLis []int, negaSumLis []int) int {
	var index int
	if N > 0 {
		for i, num := range posSumLis {
			if N == 1 {
				index = 0
				break
			}
			if num >= N && posSumLis[i-1] < N {
				index = i * 2
				break
			}
		}
	} else {
		for i, num := range negaSumLis {
			if N == -1 || N == -2 {
				index = 1
				break
			}
			if num <= N && posSumLis[i-1] > N {
				index = i*2 + 1
				break
			}
		}
	}
	return index
}

func getIndexes(N int, l2 []int, posSumLis []int, negaSumLis []int) []int {
	indexes := []int{}
	index := serachIndex(N, posSumLis, negaSumLis)
	indexes = append(indexes, index)
	if l2[index] == N {
		return indexes
	}
	_indexes := getIndexes(N-l2[index], l2, posSumLis, negaSumLis)
	indexes = append(indexes, _indexes...)
	return indexes
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("scan error")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("text to int error")
	}
	return value
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() 
{
	int a,b;
  	cin >> a >> b;
  
	if(a>=13){
		cout << b << endl;
	}
	else if(a>=6){
		cout << b/2 << endl;
	}
	else{
		cout << '0' << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def to_hash_key(a)
  a.ord - 'a'.ord
end

s = gets.chomp
t = gets.chomp

hash = Array.new(27) { [] }
0.upto(s.size - 1) do |i|
  hash[to_hash_key(s[i])].push(i + 1)
end

0.upto(25) do |i|
  next if hash[i].empty?
  hash[i] << hash[i][0] + s.size
end

ans = 0
current = 0
t.chars.each do |c|
  index = to_hash_key(c)
  if hash[index].empty?
    puts "-1"
    exit
  end
  next_current = hash[index].bsearch { |x| x > current }
  ans += next_current - current
  current = next_current % s.size
end

puts ans


Measured memory_bytes: 10748
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N+1),B(N+1,0);
    for (int i = 2; i <= N; i++)
    {
        cin >> A[i];
        B[A[i]]++;
    }
    for (int i = 1; i <= N; i++)
    {
        cout << B[i] << endl;
    }
    
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[2][110];
    for(int i = 0; i < n; ++i) cin >> a[0][i];
    for(int i = 0; i < n; ++i) cin >> a[1][i];
    
    int max = 0;
    for(int i = 0; i < n; ++i) {
        int res = 0;
        
        for(int j = 0; j <= i; ++j) res += a[0][j];
        for(int j = i; j < n; ++j) res += a[1][j];
        
        if(max < res) max = res;
    }
    
    cout << max << endl;
}


Measured memory_bytes: 256
def main():
	n, *a = map(int, open(0).read().split())
	cur = 1
	ans = a[0] - 1
	a[0] = 1
	for x in a:
		if x <= cur:
			pass
		elif x == cur + 1:
			cur = x
		else:
			ans += 0 - -(x - cur - 1) // (cur + 1)
	print(ans)

if __name__=="__main__":
	main()

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

const int N=1e5+20;

int n,a[N];

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);

	sort(a,a+n);
	int mid=a[n-1]/2;
	int i=lower_bound(a,a+n,mid)-a;
	printf("%d ",a[n-1]);
	if(i==n-1) printf("%d",a[i-1]);
	else if(i==0) printf("%d",a[0]);
	else if(a[i]-mid<=mid-a[i-1]) printf("%d",a[i]);
	else printf("%d",a[i-1]);
}

Measured memory_bytes: 640
#include <iostream>

int main(){
	int a,b,c;
	std::cin >> a;
	std::cin >> b;
	std::cin >> c;
	if (a > b){
		std::swap(a,b);
	}
	if (b > c){
		std::swap(b,c);
	}
	if (a > b){
		std::swap(a,b);
	}
	std::cout << a <<" "<< b <<" "<< c <<std::endl;
}

Measured memory_bytes: 3088
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
string S = "";

int main() {
	scanf("%lld", &N);
	cin >> S;
	ll ans = 0;
	fi(i, 1, S.size() - 1, 1) {
		char curr = S[i];
		map<char, ll> mp, inds;
		mp.clear();
		inds.clear();
		fi(j, 0, i, 1) {
			mp[S[j]]++;
			inds[S[j]] = j;
		}
		
		fi(k, i + 1, S.size(), 1) {
			char nex = S[k];
			if(S[k] != S[i]) {
				// cout << 2 * i - k << " " << k << "hey\n";
				if(2* i - k >= 0 && S[i - k + i] != curr && S[2 * i - k] != nex) {
					ans += i - mp[nex] - mp[curr] - 1;
				}
				else {
					ans += i - mp[nex] - mp[curr];
				}
			}
		}
		// cout << i << " " << ans <<  "this\n";
	}
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 3788
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int n, m;

int main() {
    fastio();

    cin >> n >> m;

    int i = 1, j = n - 1;

    int c = 0;
    bool flag = false;
    while (c < m) {
        if (n % 2 == 0 && j - i <= n / 2 && !flag) {
            j--;
            flag = true;
        }

        cout << i << " " << j << "\n";
        i++, j--;

        c++;
    }

    return 0;
}

Measured memory_bytes: 3648
import java.lang.*;
import java.util.*;
import java.io.*;

public class Main
{
	public static void main (String[] arg)throws IOException
	{
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String line;
		StringTokenizer token1;
		int a[]=new int[3];
		int sum1=0, sum2=0;
		while ((line = input.readLine()) != null && !line.isEmpty()) {
			token1 = new StringTokenizer(line,",");
			for(int i=0;i<3;i++){
				a[i]=Integer.parseInt(token1.nextToken());
			}
			//Arrays.sort(a);
			if(a[1]*a[1]+a[0]*a[0]==a[2]*a[2]){
				sum1++;
			}
			if(a[1]==a[0]){
				sum2++;
			}
		}
		System.out.println(sum1);
		System.out.println(sum2);
	}
}	

Measured memory_bytes: 16864
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
using namespace std;
typedef long long LL;
typedef double ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int INF=1<<30;
const int SIZE=30;
const int BITSIZE=1<<20;
const int TIMES=40;
int N,M,K;
int S;
bool isNo[11];
bool able(int x){
	string s=to_string(x);
	REP(i,s.size())
		if(isNo[s[i]-'0']) return false;
	return true;
}
int main(){
	cin >> N >> K;
	int x;
	REP(i,K){
		cin >> x;
		isNo[x]=true;
	}
	FOR(i,N,INF){
		if(able(i)){
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint a(N);
  rep(i, N) cin >> a[i];
  map<int, int> mp;
  rep(i, N) mp[a[i]]++;
  int ans = 0;
  for(auto&& p : mp) {
    if(p.first < p.second) ans += p.second-p.first;
    else if(p.first > p.second) ans += p.second;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7040
import java.util.*;
public class Main{
  public static void main(String[] args){
    int[] a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    System.out.println(a[n-1]);
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int n;
    long long ans,c,r,m,a,h;
    string s;
    c=r=m=a=h=0;
    scanf("%d",&n);
    for (int i=0;i<n;i++)
        {
            cin>>s;
            if (s[0]=='C') c++;
            if (s[0]=='R') r++;
            if (s[0]=='M') m++;
            if (s[0]=='A') a++;
            if (s[0]=='H') h++;
        }
    ans=c*r*m+c*r*a+c*r*h+c*m*a+c*m*h+c*a*h+r*m*a+r*m*h+r*a*h+m*a*h;
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 256
package main
  
import (
    "fmt"
    "sort"
)

func main() {
    var n int
    fmt.Scan(&n)
    as := make([]int, n)
    ss := make([]int, n)
    for i := range as {
        fmt.Scan(&as[i])
        ss[i] = as[i]
    }
    sort.Sort(sort.Reverse(sort.IntSlice(ss)))
    for i := range as {
        if as[i] == ss[0] {
            fmt.Println(ss[1])
        } else {
            fmt.Println(ss[0])
        }
    }
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  int k, x;
  cin >> k >> x;

  int a, b;
  a = x-(k-1);
  b = x+(k-1);

  FOR(i,a,b+1) cout << i << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],l,r;
vector<int> v;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		v.push_back(a[i]);
	}
	v.push_back(-1);
	sort(v.begin(),v.end());
	l=v[n/2];
	r=v[n/2+1];
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=r)
		{
			printf("%d\n",l);
		}else if(a[i]<=l)
		{
			printf("%d\n",r);
		}
	}
}

Measured memory_bytes: 4944
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,d,count=0;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin >> x[i][j];
        }
    }
    
    int sum=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int temp = 0;
            for(int k=0;k<d;k++){
                int pow_value = abs(x[i][k] - x[j][k]);
                temp += pow_value*pow_value;
            }
            bool flag = false;
            for(int k=0;k<=temp;k++){
                if(k*k==temp) flag = true;
            }
            if(flag) sum++;
        }
    }
        
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
Vec(P,lli,51,1);
Vec(Q,lli,51,1);
lli dfs(lli N,lli K){
  lli prs=0;
  if(!N)prs++;
  else if(K<2)prs+=0;
  else if(K<P[N-1]+2)prs+=dfs(N-1,K-1);
  else if(K==P[N-1]+2)prs+=1+Q[N-1];
  else if(K<P[N-1]*2+3)prs+=1+Q[N-1]+dfs(N-1,K-2-P[N-1]);
  else prs+=Q[N];
  return prs;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> N >> K;
  rep(i,1,51)P[i]=P[i-1]*2+3;
  rep(i,1,51)Q[i]=Q[i-1]*2+1;
  Out(dfs(N,K));
}

Measured memory_bytes: 3568
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	double odd = (N / 2) + (N % 2), even = (N / 2);
	cout << fixed << setprecision(10);
	cout << odd / (double)N << endl;
}

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

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

    int count = 0;

    if(N < K){
        cout << 1 << endl;
        return 0;
    }

    while(N >= K){
        N = N / K;
        count++;
    }

    cout << count+1 <<endl;

}

Measured memory_bytes: 256
using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0 || i.ToString().Contains("3"))
                {
                    Console.Write(" " + i);
                    continue;
                }
                else
                {
                    continue;
                }
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 15912
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<utility>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cassert>
#define pb push_back
#define st first
#define nd second
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long lo;
const int mod=1000000007,N=500005;
lo a,b,c,d,e,g=1,h[N];
pair<lo,lo>arr[N];
void solve(){
	cin >> a;
	for(lo i=1;i<=a;i++){
		cin >> arr[i].nd >> arr[i].st;
	}
	sort(arr+1,arr+a+1);
	lo x=0;
	for(lo i=1;i<=a;i++){
		x+=arr[i].nd;
		if(x>arr[i].st){
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

int main(){
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	// cin >> g;
	while(g--)solve();
}

Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int bs(vector<ll>& a,ll x){
  ll l=-1,r=a.size(),m;
  while(l+1<r){
    m=(l+r)/2;
    if(a[m]>x) r=m;
    else l=m;
  }
  return r;
}

int main(){
  ll n,ans=0,d[100010],e[100010]={};
  cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  fr(i,n) cin>>a[i];
  fr(i,n) cin>>b[i];
  fr(i,n) cin>>c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  fr(i,n) d[i]=n-bs(c,b[i]);
  ifr(i,n) e[i]=e[i+1]+d[i];
  fr(i,n) ans+=e[bs(b,a[i])];
  cout<<ans<<endl;
}

Measured memory_bytes: 4096
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using G = vector<vector<int>>;
const long long INF = 1LL<<60;

int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    string t;
    //swapしても末尾に追加していくのは変わらない
    rep(qi,q){
        int ty;
        cin >> ty;
        if(ty == 1){
            swap(s,t);//O(1)

        }else{
            int f;char c;
            cin >> f >> c;
            if(f == 1){
                t+=c;
            }else{
                s+=c;
            }
        }
    }
    reverse(t.begin(),t.end());
    t+=s;
    cout << t << endl;
}

Measured memory_bytes: 1128
#include<stdio.h>

int main(void){
    int x;

    scanf("%d", &x);

    while(1)
	{
		int div=0;
		for(int j=1;j<=x;j++)
		{
			if(x%j==0) div++;
		}

		if(div==2){
            printf("%d ",x);
            break;
        }

        x++;
	}

}

Measured memory_bytes: 256
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    ll x, start = 100, cnt = 0;
    cin >> x;
    for (;;) {
        if (start >= x) {
            cout << cnt << endl;
            return 0;
        }
        start = start + start / 100;
        cnt++;
    }

    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(){
	int a, b, c, ans = 0;
	scanf("%d %d %d", &a, &b, &c);
	for(int i=1;; i++){
		ans += c;
		if(b*i >= a){
			printf("%d\n", ans);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2140
#include <stdio.h>
#include<stdlib.h>
#define Max 100
int top = 0,S[Max];
int main(){
  int x;
  char c[Max];

  while(scanf("%s",c) != EOF){
    if(c[0] == '+') {
      S[top-2] = S[top-1] + S[top-2];
      top--;
    }
    else if(c[0] == '-') {
      S[top-2] = S[top-2] - S[top-1];
      top--;
    }
    else if(c[0] == '*') {
      S[top-2] = S[top-1] * S[top-2];
      top--;
    }
    else{
      S[top] = atoi(c);
      top++;
    }    
  }
  printf("%d\n",S[top-1]);
    return 0;
  }

Measured memory_bytes: 548
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main(void)
{
	int a, b, d, r;

	double f;

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

	d = a / b;

	r = a % b;

	f = (double)a / b;

	printf("%d %d %f", d, r,f);

	return 0;
}


Measured memory_bytes: 2700
#include <stdio.h>

//FILE *in = freopen("input.txt", "r", stdin);
//FILE *out = freopen("output.txt", "w", stdout);

int p, q;

void process() {
	int cnt = 0;
	int x, y, z;
	for(int n = -150; n < 150; n++) {
		for(int m = -150; m < 150; m++) {
			x = m*p - n*q;
			y = m*q + n*p;
			z = m*m + n*n;
			if(z == 0) continue;
			if(x % z == 0 && y % z == 0) ++cnt;
		}
	}
	if(cnt > 8) {
		printf("C\n");
	}
	else {
		printf("P\n");
	}
}

void output() {
}

int main() {
	int N;
	scanf("%d", &N);
	for(int i = 0; i < N; i++) {
		scanf("%d%d", &p, &q);
		process();
		output();
	}
	return 0;
}

Measured memory_bytes: 996
#include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

int main() {
    int N;
    cin >> N;
    vector<int> dp(N);
    vector<int> h(N);
    Rep(i, N) {
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = dp[0] + abs(h[1] - h[0]);
    for (int i = 2; i < N; i++) {
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if (x - r >= 0 && x + r <= H && y - r >= 0 && y + r <= H)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



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

int cnt(int x) {
    int c = 0;
    for (int i = 1; i <= x; i++) {
        if (x % i == 0) {
            c++;
        }
    }
    return c;
}

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

    int c = 0;
    for (int i = 1; i <= n; i+=2) {
        if (cnt(i) == 8) {
            c++;
        }
    }

    cout << c << endl;
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll  long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define f(i,n)   for(int i=0;i<n;i++)
#define INF 1e9+5
#define LINF 1e18L+5;
#define pb push_back
#define mk make_pair
using namespace std;
/************************BELIAL**********DEVIL*********BELIAL***********DEVIL*************************/
int main()
{
    

    int n;
    cin>>n;

    vector<int> arr(n);
    vector<int> dp(n,INF);


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

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

           }


    	}


       cout<<dp[n-1];


}

Measured memory_bytes: 1024
#include <stdio.h>
#include <queue>
#include <bitset>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
#define PB push_back
int t=0,k;
struct node{
    int num;
    int val[4];
    void in(){
        num=++t;
        for(int i=0;i<k;i++)scanf("%d",&val[i]);
        return ;
    }
    node per(vector<int>& p){
        node ans;
        ans.num=num;
        for(int i=0;i<k;i++)ans.val[i]=val[p[i]];
        return ans;
    }
};
struct cmp{
    bool operator()(const node a,const node b){
        for(int i=0;i<k;i++)if(a.val[i]!=b.val[i])return a.val[i]<b.val[i];
        return true;
    }
};
const int N=5e4+10;
int main(){
    int n,tot=1,d,l,r,deg[N],now=1,last,cnt=0,temp;
    map<vector<int>,int>m;
    map<int,vector<int>>b;
    node a[N],nxt;
    vector<int> p,graph[N],tp;
    bitset<N>used;
    priority_queue<node,vector<node>,cmp>pq[24];
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)a[i].in();
    for(int i=0;i<k;i++)p.PB(i);
    for(int i=k;i>0;i--)tot*=i;
    for(int i=0;i<tot;i++){
        m.insert({p,i});
        b.insert({i,p});
        next_permutation(p.begin(),p.end());
    }
    used.reset();
    scanf("%d",&d);
    while(d--){
        scanf("%d%d",&l,&r);
        graph[l].PB(r);
        deg[r]++;
    }
    for(int i=1;i<=n;i++)if(deg[i]==0)for(int j=0;j<tot;j++)pq[j].push(a[i].per(b[j]));
    tp.clear();
    for(int i=0;i<k;i++){
        scanf("%d",&temp);
        temp--;
        tp.PB(temp);
    }
    now=m[tp];
    scanf("%d",&r);
    while(r--){
        last=now;
        scanf("%d",&l);
        tp.clear();
        for(int i=0;i<k;i++){
            scanf("%d",&temp);
            temp--;
            tp.PB(temp);
        }
        now=m[tp];
        while(cnt<l){
            nxt=pq[last].top();
            pq[last].pop();
            if(used[nxt.num])continue;
            used[nxt.num]=true;
            printf("%d\n",nxt.num);
            for(int i:graph[nxt.num]){
                deg[i]--;
                if(deg[i]==0)for(int j=0;j<tot;j++)pq[j].push(a[i].per(b[j]));
            }
            cnt++;
        }
    }
    while(cnt<n){
        nxt=pq[now].top();
        pq[now].pop();
        if(used[nxt.num])continue;
        used[nxt.num]=true;
        printf("%d\n",nxt.num);
        for(int i:graph[nxt.num]){
            deg[i]--;
            if(deg[i]==0)for(int j=0;j<tot;j++)pq[j].push(a[i].per(b[j]));
        }
        cnt++;
    }
}


Measured memory_bytes: 29604
i,j= list(map(int, input().split()))
ans1=-1
ans2=-1
ans3=-1
for k in range(i+1):
    for m in range(i-k+1):
        n=i-k-m
        if j==(k*10000)+(m*5000)+(n*1000):
            ans1=k
            ans2=m
            ans3=n
print(ans1,ans2,ans3)

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    string S; cin >> S;
    if (S.length() % 2 > 0) {
        cout << "No" << endl;
        return 0;
    }

    REP(i, S.length()) {
        if (i % 2 == 0) {
            if (S[i] == 'h') continue;
            cout << "No" << endl;
            return 0;
        } else {
            if (S[i] == 'i') continue;
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int n,m,p;
    while(cin>>n>>m>>p,n){
        double t=0,h=0;
        rep(i,n){
            int s; cin>>s;
            if(i+1==m)h=s;
            t+=s;
        }
        cout<<floor(h?t*(100-p)/h:0)<<endl;
    }
}

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

int main(){
  int N,ans = 30;
  cin >> N;
  for(int i = 0; i < N; i++){
  	int a,b = 0;
    cin >> a;
    while(a % 2 == 0){
    	b++;
        a = a / 2; 
    }
    ans = min(b,ans);
  }
  cout << ans << endl;
}  

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

int main() {
  int n;
  cin >> n;
  
  int a, b;
  int ans = 0;
  for(int i=0; i<n; i++) {
    cin >> a >> b;
    ans += b-a+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628