akhauriyash/Code-Regression huggingface dataset:
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int ans = 0;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size();++i)
    if(s[i]!=t[i])
        ans++;

    cout << ans;

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3784
import scala.io.{StdIn => in}

object Main extends App {
  val Array(a, b) = in.readLine.split(" ").map(_.toInt)

  val ans = (a, b) match {
    case (a, b) if a > 0 && b > 0 => "Positive"
    case (a, b) if a <= 0 && 0 <= b => "Zero"
    case (a, b) if (a.abs - b.abs + 1) % 2 == 0 => "Positive"
    case (a, b) if (a.abs - b.abs + 1) % 2 == 1 => "Negative"
  }

  println(ans)
}

Measured memory_bytes: 25540
#include<bits/stdc++.h>
#define ll long long
#define lld long double
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 101000;
priority_queue<pair<int,string>,vector<pair<int,string> >,greater<pair<int,string> > > H;
vector<char> C;
int L;
int main(){
	for(int i=0;i<26;i++) C.push_back('a'+i);
	for(int i=0;i<26;i++) C.push_back('A'+i);
	for(int i=0;i<10;i++) C.push_back('0'+i);
	for(int i=0;i<62;i++){
		cout<<"? ";
		pair<int,string> pr;
		for(int j=0;j<128;j++)
			pr.second+=C[i];
		cout<<pr.second<<endl;
		int x;cin>>x;
		pr.first=128-x;
		for(int j=0;j<x;j++) pr.second.pop_back();
		if(pr.first) H.push(pr);
		L+=pr.first;
	}
	while(H.size()>1){
		auto p1=H.top();H.pop();
		auto p2=H.top();H.pop();
		string st;
		int k=0;
		for(int i=0;i<p1.first;i++){
			while(k<p2.first){
				string out=st;
				out+=p2.second[k];
				for(int j=i;j<p1.first;j++)
					out+=p1.second[j];
				cout<<"? "<<out<<endl;
				int x;cin>>x;
				if(L-x!=out.length()) break;
				else st+=p2.second[k++];
			}
			st+=p1.second[i];
		}
		while(k<p2.first) st+=p2.second[k++];
		H.push(make_pair(p1.first+p2.first,st));
	}
	cout<<"! "<<H.top().second<<endl;
	return 0;
}



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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

int main(){
  ll n,l,i,j;
  cin>>n>>l;
  vl a(n);
  cin>>a[0];
  ll pre=a[0];
  bool flag=false;
  ll iti;
  for(i=1;i<n;i++){
    cin>>a[i];
    if(pre+a[i]>=l){
      flag=true;
      iti = i;
    }
    pre=a[i];
  }
  if(!flag){
    cout<<"Impossible"<<endl;
    return 0;
  }
  cout<<"Possible"<<endl;
  for(i=1;i<iti;i++){
    cout<<i<<endl;
  }
  for(i=n-1;i>=iti;i--){
    cout<<i<<endl;
  }
}
  
      


Measured memory_bytes: 1664
package main

import (
    "fmt"
    "os"
    "bufio"
    "sort"
    "strings"
    "strconv"
)

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    line1 := readLine(reader)
    line2 := readLine(reader)
    N, _ := strconv.Atoi(line1)
    arr := strings.Split(line2, " ")
    var nums []int

    for _, v := range arr {
        n, _ := strconv.Atoi(v)
        nums = append(nums, n)
    }

    sort.Sort(sort.IntSlice(nums))

    var retval int = 0
    for i := 0; i < N * 2; i++ {
        if i % 2 == 0 {
            retval += nums[i]
        }
    }

    fmt.Println(retval)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1000000)

    for {
        l, p, e := reader.ReadLine()

        if e != nil {
            panic(e)
        }

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

// スライスの中身削除
func remove(ints [][]int, key int) [][]int {
    result := [][]int{}


    for k, v := range ints {
        if k != key {
            result = append(result, v)
        }
    }

    return result
}

Measured memory_bytes: 768
#include <stdio.h>
int main()
{
    int a,b,x,i;
    long long int c;
    scanf("%d%d",&a,&b);
    if(a<=b)
        x=a;
    else
        x=b;
    for(i=x;i>=1;i--)
    {
        if(a%i==0&&b%i==0)
            break;
    }
    c=a*1.0*b/i;
    printf("%lld",c);
    return 0;
}

Measured memory_bytes: 128
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();
		
		System.out.print(a / b + " " + a % b + " ");
		System.out.printf("%.8f\n", (double)a / b);
		sc.close();
	}

}



Measured memory_bytes: 26532
def solve():
    import sys

    sys.setrecursionlimit(10 ** 7)

    h, w, k = map(int, input().split())
    s = tuple(input() for _ in range(h))

    def build_table(h, w, s):
        """1-indexed, ケーキ個数の二次元累積和"""
        ret = [[0] * (w + 1) for _ in range(h + 1)]
        for r in range(h):
            for c in range(w):
                ret[r + 1][c + 1] = ret[r][c + 1] + ret[r + 1][c] - ret[r][c] + (1 if s[r][c] == '#' else 0)
        return ret

    def rec(ar=0, ac=0, br=h, bc=w, remains=k) -> None:
        # print(ar, ac, br, bc, remains)
        nonlocal curr
        if remains == 1:
            for r in range(ar, br):
                for c in range(ac, bc):
                    ret[r][c] = curr
            curr += 1
            return

        for r in range(ar + 1, br + 1):
            t = tbl[r][bc] - tbl[ar][bc] - tbl[r][ac] + tbl[ar][ac]
            if 0 < t < remains:
                rec(ar, ac, r, bc, t)
                rec(r, ac, br, bc, remains - t)
                return

        for c in range(ac + 1, bc + 1):
            t = tbl[br][c] - tbl[br][ac] - tbl[ar][c] + tbl[ar][ac]
            if 0 < t < remains:
                rec(ar, ac, br, c, t)
                rec(ar, c, br, bc, remains - t)
                return

    tbl = build_table(h, w, s)  # 1-indexed, ケーキ個数の二次元累積和

    ret = [[-1] * w for _ in range(h)]
    curr = 1
    rec()
    return ret


if __name__ == '__main__':
    ret = solve()
    for row in ret:
        print(*row)

# s(0,0),t(h,w)
# [s,t)
# 二次元累積和を利用して、行または列に平行な直線で、recに与えられた長方形を二分する
# 分割後に含まれるケーキ数が減ることを保証するため、片方の分割にすべてのケーキが含まれるものは認めない


Measured memory_bytes: 57180
#include <stdio.h>

int main()
{
    int i, max, min, size;
    double sum=0;
    scanf("%d", &size);
    int arr[size];

    for(i=0; i<size; i++)
    {
        scanf("%d", &arr[i]);
    }

    max = -9999999999;
    min=9999999999;

    for(i=0; i<size; i++)
    {
        if(arr[i] > max)
        {
            max = arr[i];
        }

        if(arr[i] < min)
        {
            min = arr[i];
        }
        sum=sum+arr[i];
    }

    printf("%d %d %.0lf\n",min,max,sum);

    return 0;
}



Measured memory_bytes: 2100
n, a, b = [int(x) for x in input().split()]
c = b - a
if c % 2 == 0:
    print(c // 2)
    exit()
d = n - a
e = b - 1
f = ((n - b) + 1) + ((n - ((n - b) + 1 + a)) // 2)
g = a + ((b - a) // 2)
print(min([d, e, f, g]))


Measured memory_bytes: 38384
package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    
    var odds []int
    for i := 0; i < n; i++ {
        var num int 
        fmt.Scan(&num)

        if num%2 == 1 {
            odds = append(odds, num)
        }   
    }
    if len(odds)%2 == 0 {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }   
}   


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

bool JudgePrime(int n)
{
	double a = sqrt(n);

	if (n == 1)
	{
		return false;
	}
	if (n == 2)
	{
		return true;
	}
	else
	{
		for (int i = 2; i <= a; i++)
		{
			if (n % i == 0)
			{
				return false; 
			}
		}
		return true;
	}
}

int main()
{
	int n;
	int count = 0;
	int A[10000];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
	}

	for (int i = 0; i < n; i++)
	{
		if (JudgePrime(A[i]) == true)
		{
			count += 1;
		}
	}

	cout << count << "\n";

	return 0;
}


Measured memory_bytes: 3108
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j;
            cin>>n;
            string s;
            cin>>s;
            n=s.length();
            int flag=0,ct=0,ct2=0,ct3;
            for(i=0;i<n;++i)
            {
                if(s[i]=='W')
                {
                    ++ct;
                }
                else
                {
                    ++ct2;
                }
            }
            ct3=ct;
            for(i=0;i<n;++i)
            {
                if(s[i]=='W')
                {
                    ct2=ct2-i;
                    break;
                }
            }
            for(i=n-1,j=0;i>=0;--i,++j)
            {
                if(s[i]=='R')
                {
                    ct=ct-j;
                    break;
                }
            }
            int ans=min(ct,ct2),ans2=0;
            for(i=n-ct3;i<n;++i)
            {
                if(s[i]=='R')
                    ++ans2;
            }
            ans=min(ans,ans2);
            ans2=0;

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


Measured memory_bytes: 3772
def main():
    n = int(input())
    s = list(map(int, list(input())))
    idx = [[] for _ in range(10)]
    for i, v in enumerate(s):
        idx[v].append(i)
    ans = 0
    for i in range(1000):
        c = 0
        p = -1
        chk = True
        while c < 3 and chk:
            chk = False
            for j in idx[i // 100]:
                if j > p:
                    c += 1
                    p = j
                    chk = True
                    i = i % 100 * 10
                    break
        if c == 3:
            ans += 1
    print(ans)

main()

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

using ll=long long;

int main(){

ll j=0, N, K;
cin >> N >> K;

if(N<K){
cout << 1 << endl;
goto xyz;
}

while(1){
++j;
N/=K;
if(N<K){cout << j+1 << endl; break;}
}

xyz:;

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1e9+7;



void solve(){

    string s;
    cin >> s;
    int ans = 0;
    int ret = 0;
    if (s[0] == 'R') {
        ans++;
        ret = 1;   
    }
    for(int i = 1; i < 3; i++){
        if (s[i] =='R'){
            ans++;
            ret = max(ans,ret);
        }
        else{
            ans = 0;
        }
    }
    cout << ret;
}


int main() {
    int T;
    //cin >> T;
    T = 1;
    while (T--) {
        solve();
        cout << endl;
    }
}














Measured memory_bytes: 3632
args = {}
l = ["a", "b", "c", "d", "e", "k"]
for i in range(len(l)):
    args[l[i]] = int(input())
for i in range(len(l) - 1):
    j = 5-i
    for m in range(len(l) - 2):
        n = j - (m+1)
        if n <= 0:
            continue
        if args[l[j-1]] - args[l[n-1]] > args["k"]:
            print(':(')
            exit()
print("Yay!")


Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int ans[N+1];
  for(int i=1;i<=N;++i){
    ans[i] = 0;
    for(int x=1;x<=i;++x){
      if(x*x+1+1+x+1+x>i) break;
      for(int y=1;y<=x;++y){
        if(x*x+y*y+1+x*y+y+x>i) break;
        for(int z=1;z<=y;++z){
          if(x*x+y*y+z*z+x*y+y*z+z*x==i){
            if(x==y && y==z) ans[i]++;
            if((x!=y && y==z) || (x==y && y!=z)) ans[i] += 3;
            if(x!=y && y!=z) ans[i] += 6;
          }
          else if(x*x+y*y+z*z+x*y+y*z+z*x>i) break;
        }
      }
    }
  }
  for(int i=1;i<=N;++i){
    cout<<ans[i]<<endl;
  }
}



Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

#define ll long long

int main()
{
    int N;
    std::cin >> N;

    int count = N / 2;
    if(N % 2 != 0) count++;

    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 3536
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = Integer.parseInt(sc.next());
            b[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        List<ArrayList<Integer>> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            list.get(a[i] - 1).add(b[i] - 1);
            list.get(b[i] - 1).add(a[i] - 1);
        }

        // 出力
        for (ArrayList<Integer> set : list) {
            System.out.println(set.size());
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define b begin
#define e end
using namespace std;
int main()
{
    char s[200001],t[200001];
    scanf("%s %s",s,t);
    ll r=strlen(s);
    ll i,c=0;
    for(i=0;i<r;i++){
        if(s[i]!=t[i])
        c++;
    }
    cout<<c;
}

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

int main() {
	int i,j,k,n,m,l;
	cin >> n >> m >> l;
	long long a[n][m],b[m][l],c[n][l];
	for(i=0;i<n;i++){
		for(k=0;k<l;k++){
			c[i][k] =0;
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	for(j=0;j<m;j++){
		for(k=0;k<l;k++){
			cin >> b[j][k];
		}
	}
	for(i=0;i<n;i++){
		for(k=0;k<l;k++){
			for(j=0;j<m;j++){
				c[i][k] += a[i][j]*b[j][k];
			}
			cout << c[i][k];
			if(k != l-1)
		            cout << " ";
		}
	cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
map<ll,ll>mp;
signed main(){
	ll a,b,c,ans=0;
	cin>>a>>b>>c;
	mp[a]++;
	mp[b]++;
	mp[c]++;
	for(auto x:mp){
		if(x.second)ans++;
	}
	cout<<ans<<endl;
}


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

using namespace std;

int main(int qtd, char* nome[])
{
    int n;
    cin >> n;
    int a[n], sum = 0;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int s[2] = {0}, t = sum / 2, ti = 1, dist = INT_MAX;
    sum = 0;
    for (int i = 0; i < n; i++){
        sum += a[i];
        if (abs(sum - t) < dist){
            dist = abs(sum - t);
            ti = i;
        }
    }

    for(int i = 0; i < n; i++){
        if (i > ti)
            s[0] += a[i];
        else
            s[1] += a[i];
    }

    cout << abs(s[0] - s[1]) << endl;

    return 0;
}

Measured memory_bytes: 256
nq = input().split()
n, q = int(nq[0]), int(nq[1])
s = list(input())
r_li = []
l_li = []
t_li = []
for i in range(q):
    rl = input().split()
    l_li.append(int(rl[0]))
    r_li.append(int(rl[1]))
count = 0
i = 0
while True:
    if i == n:
        break
    else:
        if s[i] == "A":
            if i == n - 1:
                i += 1
                t_li.append(count)
            else:
                if s[i + 1] == "C":
                    t_li.append(count)
                    count += 1
                    t_li.append(count)
                    i += 2
                else:
                    t_li.append(count)
                    i += 1
        else:
            i += 1
            t_li.append(count)
for i in range(q):
    print(t_li[r_li[i] - 1] - t_li[l_li[i] - 1])


Measured memory_bytes: 14884
#include <bits/stdc++.h>
using namespace std;
int read();
void print(int x) {
    if (x == 0) return printf("invalid string"), void();
    if (x == 1) return;
    print(x >> 1), putchar(x & 1 ^ '0');
}
int n, K;
char s[1100005];
int f[50000007], hi[2500005], lim = 1 << 21;
int nx[2500005][2];
void init() {
    for (int i = 2; i < lim; ++i) hi[i] = hi[i >> 1] + 1;
    for (int i = 2; i < lim; ++i) {
        nx[i >> 1][0] ? nx[i][0] = nx[i >> 1][0] << 1 | (i & 1) : 0;
        nx[i >> 1][1] ? nx[i][1] = nx[i >> 1][1] << 1 | (i & 1) : 0;
        !nx[i][i & 1] ? nx[i][i & 1] = 1 : 0;
    }
}
int id(int S, int T) { return (S << hi[T] | (T ^ (1 << hi[T]))) * 21 + hi[S]; }
int main() {
    n = read(), K = read(), init();
    for (int i = 0; i <= n; ++i) {
        scanf("%s", s);
        for (int j = 0, en = 1 << i; j < 1 << i; ++j)
            if (s[j] == '1') f[id(1, j | en)] = 1;
    }

    for (int T = (1 << n + 1) - 1; T > 1; --T) {
        int a = nx[T][0], b = nx[T][1];
        for (int S = (1 << n - hi[T] + 1) - 1; S; --S) {
            a ? f[id(S << 1, a)] += f[id(S, T)] : 0;
            b ? f[id(S << 1 | 1, b)] += f[id(S, T)] : 0;
            f[id(S, 1)] += f[id(S, T)];
        }
    }

    int res = 0;
    for (int S = (1 << n + 1) - 1; S; --S) {
        if (hi[S] < hi[res]) break;
        f[id(S, 1)] >= K ? res = S : 0;
    }
    print(res), puts("");
    return 0;
}
int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    return x * f;
}

Measured memory_bytes: 205568
#include <stdio.h>
#include <string.h>
#define MAX 1000000
#define L 12

char H[MAX][L];

int Getchar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

long long getkey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(Getchar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return key % MAX;
}

int h2(int key){
  return key % MAX;
}

int find(char str[]){
  long long key, i, h;

  key = getkey(str);
  for(i = 0;; i++){
    h = (h1(key) + i * h2(key))% MAX;
    if(strcmp(H[h],str) == 0){
      return 1;
    }else if(strlen(H[h]) == 0){
      return 0;
    }
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;

  key = getkey(str);
  for(i = 0; ; i++){
    h = (h1(key) + i * h2(key)) % MAX;
    if(strcmp(H[h],str) == 0){
      return 1;
    }else if(strlen(H[h]) == 0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < MAX; i++ ) H[i][0] = '\0';//ヌル文字ふへへ
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
	
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }
  
  return 0;
}





Measured memory_bytes: 13460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    char a, b;
    cin >> a >> b;
    if(a == b) cout << "=" << endl;
    else if(a < b) cout << "<" << endl;
    else cout << ">" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int main()
{
	char c;
	int num;
	int stack[200];
	int sp;


	sp = 0;
	while((c = getchar()) != '\n'){
		if(isdigit(c)){
			ungetc(c, stdin);
			scanf("%d", &num);
			stack[sp++] = num;
		}else{
			switch(c){
				case '+':
					stack[sp - 2] = stack[sp - 2] + stack[sp - 1];
					sp--;
				break;
				case '-':
					stack[sp - 2] = stack[sp - 2] - stack[sp - 1];
					sp--;
				break;
				case '*':
					stack[sp - 2] = stack[sp - 2] * stack[sp - 1];
					sp--;
				break;
			}
		}
	}

	printf("%d\n", stack[0]);

	return 0;
}


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

int main(void)
{
    while (true) {
        int m, f, r;
        cin >> m >> f >> r;
        if (m + f + r == -3) break;
        else if (m == -1 || f == -1) cout << 'F' << endl;
        else if (m + f >= 80) cout << 'A' << endl;
        else if (m + f >= 65) cout << 'B' << endl;
        else if (m + f >= 50) cout << 'C' << endl;
        else if (m + f >= 30 ) cout << ((r < 50)? 'D' : 'C') << endl;
        else cout << 'F' << endl;;
    }
    return 0;
}


Measured memory_bytes: 3092
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int N = saori.saori_hayami();
		int W = saori.saori_hayami();
		int[] w = new int[N];
		int[] v = new int[N];
		int value = 0;
		for(int i = 0; i < N;i++){
			w[i] = saori.saori_hayami();
			v[i] = saori.saori_hayami();
			value = v[i] + value;
		}
		long[][] dp = new long[w.length+1][value+1];
		for (int i = 0; i < w.length+1; i++) {
			for (int j = 0; j < value+1; j++) {
				dp[i][j] = Integer.MAX_VALUE;
			}
		}
		dp[0][0] = 0;
		for(int i = 0; i < w.length;i++){
			for(int j = 0; j <= value;j++){
				dp[i+1][j] = Math.min(dp[i+1][j], dp[i][j]);
				if(j - v[i] >= 0){
					dp[i+1][j] = Math.min(dp[i+1][j], dp[i][j-v[i]] + w[i]);
				}
			}
		}
		int ans = 0;
		for (int i = 0; i <= value; i++) {
			if (dp[N][i] <= W) {
				ans = i;
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 128980
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 15, s = 0, t = 5e5 + 5;
struct lpl{int to, dis;}lin;
int N, M, cnt, y[maxn], dis[maxn];
vector<lpl> point[maxn];
set<int> d[maxn];
map<lpl, int> mp;
priority_queue<lpl> q;

inline bool operator < (lpl A, lpl B){return (A.dis == B.dis) ? (A.to > B.to) : (A.dis > B.dis);}

inline void connect(int a, int b, int c){
	lin.dis = c; lin.to = b; point[a].push_back(lin);
}

inline void putit(){
	scanf("%d%d", &N, &M); int A, B, p, q, m;
	for(int i = 1; i <= M; ++i){
		scanf("%d%d%d", &p, &q, &m); lin.to = m;
		d[p].insert(m); d[q].insert(m);
		lin.dis = p; A = mp[lin]; if(!A) {mp[lin] = ++cnt; A = cnt;} 
		lin.dis = q; B = mp[lin]; if(!B) {mp[lin] = ++cnt; B = cnt;} 
		connect(A, B, 0); connect(B, A, 0);
	}
}

inline void prepare(){
	set<int>::iterator iter; int now;
	for(int i = 1; i <= N; ++i){
		y[i] = ++cnt; 
		for(iter = d[i].begin(); iter != d[i].end(); ++iter){
			now = mp[(lpl){*iter, i}];
			connect(y[i], now, 0); connect(now, y[i], 1);
		}
	}
	connect(s, y[1], 1); connect(y[N], t, 0);
}

inline void dijkstra(){
	memset(dis, 0x3f, sizeof(dis)); lpl qwe, asd;
	lin.to = s; lin.dis = 0; q.push(lin);
	while(!q.empty()){
		lin = q.top(); q.pop();
		if(lin.to == t){cout << lin.dis - 1; return;}
		for(int i = point[lin.to].size() - 1; i >= 0; --i){
			qwe = point[lin.to][i];
			if(dis[qwe.to] > lin.dis + qwe.dis){
				dis[qwe.to] = lin.dis + qwe.dis;
				asd.to = qwe.to; asd.dis = dis[qwe.to];
				q.push(asd);
			}
		}
	}
	printf("-1");
}
//
//inline void check(){
//	set<int>::iterator iter;
//	for(int i = 1; i <= N; ++i){
//		printf("dian = %d\n gongsi:  ", i);
//		for(iter = d[i].begin(); iter != d[i].end(); ++iter) printf("%d ", *iter);
//		printf("\n");
//	}
//}

int main()
{
	//freopen("lpl.in", "r", stdin);
	putit();
	prepare();
	dijkstra();
	return 0;
}

Measured memory_bytes: 101660
n = int(input())
s = input().split(" ")
S = list(map(int, s))
q = int(input())
t = input().split(" ")
T = list(map(int, t))
C = 0

def binarySearch(A, key):
    left = 0
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

for i in range(q):
    if binarySearch(S,T[i]):
        C += 1

print(C)

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

int main() {
  string S;
  cin >> S;
  
  int counter;
  counter = 0;
  
  if(S.at(0)=='R'){
    ++counter;
    if(S.at(1)=='R'){
      ++counter;
      if(S.at(2)=='R'){
   		 ++counter;
    	 cout << counter <<endl;
      }
      else if(S.at(2)!='R')cout << counter <<endl;
    }
    else if(S.at(1)!='R')cout << counter <<endl;
  }
  else if(S.at(0)!='R'){
    if(S.at(1)=='R'){
      ++counter;
      if(S.at(2)=='R'){
   		 ++counter;
    	 cout << counter <<endl;
      }
      else if(S.at(2)!='R')cout << counter <<endl;
    }
    else if(S.at(1)!='R'){
      if(S.at(2)=='R'){
   		 ++counter;
    	 cout << counter <<endl;
      }
      else if(S.at(2)!='R')cout << counter <<endl;
    }
  }
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long X){

    REP(k,1,10000000){
        if((360*k)%X==0){
            LOG3(360*k,X,k);
            cout<<(360*k)/X<<endl;
            return;
        }
    }


}

int main(){
    // cout << fixed << setprecision(5);

    long long X;
    scanf("%lld",&X);
    func(X);
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
using namespace std;
#include <string>
int main(){
	int ans=0;
	string str,s1,s2;
	cin >> str;
	for(int i=2;i<str.length();i+=2){
		s1 = str.substr(0, i/2);
		s2 = str.substr(i/2,i/2);
		if(s1 ==s2) ans = i;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(System.in);
    try {
      int[][] c = new int[3][3];
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          c[i][j] = scanner.nextInt();
        }
      }
      
      for (int i = 0; i < 2; i++) {
        if (!check_h(c,i)) {
          System.out.println("No");
          return;
        }
      }
      
      for (int j = 0; j < 2; j++) {
        if (!check_v(c,j)) {
          System.out.println("No");
          return;
        }
      }
      
      System.out.println("Yes");
    }
    finally {
      scanner.close();
    }
  }

  private static boolean check_v(int[][] c, int j) {
    for (int i = 0; i < 2; i++) {
      if (c[i][j+1] - c[i][j] != c[i+1][j+1] - c[i+1][j]) return false;
    }
    return true;
  }

  private static boolean check_h(int[][] c, int i) {
    for (int j = 0; j < 2; j++) {
      if (c[i+1][j] - c[i][j] != c[i+1][j+1] - c[i][j+1]) return false;
    }
    return true;
  }
}

Measured memory_bytes: 23252
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int x;

    cin >> x;

    if (x == 3 || x == 5 || x == 7)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 998244353;

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

    ll n;
    cin >> n;
    vector<long double> x(n);
    vector<string> u(n);
    REP(i, n) cin >> x[i] >> u[i];

    long double ret = 0;
    REP(i, n) {
        if(u[i] == "JPY") ret += x[i];
        else ret += x[i] * 380000;
    }
    cout << fixed << setprecision(15) << ret << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
ans=0
while True:
    l,m=-1,-1
    for i in range(n):
        if h[i]!=0:
            l=i
            break
    if l==-1:
        break
    if l==n-1:
        ans+=h[l]
        break
    r=l
    for i in range(l,n):
        if h[i]==0:
            break
        else:
            r=i
            if m==-1:
                m=h[i]
            else:
                m=min(m,h[i])

    for i in range(l,r+1):
        h[i]-=m
    ans+=m
print(ans)


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  char x;
  cin >> x;
  cout << (char)(x + 1) << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;

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

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

    printf("%d\n", h * w - a * w - b * h + a * b);

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
import math
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

a,b = inpl()
print(a*b)

Measured memory_bytes: 10068
#include<stdio.h>

int main(void) {
	int x[4];
	int y[4];
	int v[2];
	int a, b;
	int i;
	for (i = 0; i < 2; i++) {
		scanf("%d%d", &x[i], &y[i]);
	}
	v[0] = x[1] - x[0];
	v[1] = y[1] - y[0];
	a = -v[1];
	b = v[0];
	x[2] = x[1] + a;
	y[2] = y[1] + b;
	a = -v[0];
	b = -v[1];
	x[3] = x[2] + a;
	y[3] = y[2] + b;

	printf("%d %d %d %d\n", x[2], y[2], x[3], y[3]);
	return 0;
}

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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define TC int tc; cin >> tc; while(tc--)

using namespace std;

const int INF = 1e9 + 7;

int h, w, sx, sy, dh, dw;
vector<vector<char>> g;

bool legal(int i, int j){
	if(i < 0 || j < 0 || i >= h || j >= w || g[i][j] == '#') return false;
	return true;
}

int main(void)
{
	FAST;
	cin >> h >> w >> sx >> sy >> dh >> dw;
	sx--; sy--; dh--; dw--;
	g = vector<vector<char>>(h, vector<char>(w));
	vector<vector<int>> dist(h, vector<int>(w, INF));

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> g[i][j];
		}
	}

	deque<int> x, y;
	x.push_front(sx);
	y.push_front(sy);
	dist[sx][sy] = 0;

	int dx[4] = {0, 1, -1, 0};
	int dy[4] = {1, 0, 0, -1};

	while(!x.empty() && !y.empty()){

		int curx = x.front(), cury = y.front();
		x.pop_front(); y.pop_front();

		for(int i = 0; i < 4; i++){
			int nx = curx + dx[i], ny = cury + dy[i];
			if(!legal(nx, ny)) continue;
			if(dist[nx][ny] > dist[curx][cury]){
				dist[nx][ny] = dist[curx][cury];
				x.push_front(nx);
				y.push_front(ny);
			}
		}

		for(int nx = curx-2; nx <= curx+2; nx++){
			for(int ny = cury - 2; ny <= cury + 2; ny++){
				if(!legal(nx, ny)) continue;
				if(dist[nx][ny] > dist[curx][cury] + 1){
					dist[nx][ny] = dist[curx][cury] + 1;
					x.push_back(nx);
					y.push_back(ny);
				}
			}
		}
	}

	if(dist[dh][dw] == INF) cout << -1 << '\n';
	else cout << dist[dh][dw] << '\n';


	return 0;
}


Measured memory_bytes: 8644
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    string si;
    cin >> si;
    int q;
    cin >> q;

    deque<char> s;
    for (auto &c: si) s.push_back(c);

    bool rev = false;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            rev = !rev;
        } else {
            int f;
            char c;
            cin >> f >> c;

            if (rev) f = f == 1 ? 2 : 1;

            if (f == 1) s.push_front(c);
            else s.push_back(c);
        }
    }

    if (rev) {
        for (auto it = s.rbegin(); it != s.rend(); ++it) {
            cout << *it;
        }
        cout << endl;
    } else {
        for (auto c: s) cout << c;
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 896
package main

import (
	f "fmt"
)

func main() {
	var n, x, t int
	f.Scan(&n, &x, &t)

	m := n % x
	if m == 0 {
		ans := n / x * t
		f.Println(ans)
	} else {
		ans := (n/x + 1) * t
		f.Println(ans)
	}
}


Measured memory_bytes: 1772
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"
 
using namespace std;
const long long MOD = (long long)1e9 + 7;

int r;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> r;
    int ans = r*r;
    ans = ans*3;
    cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素



signed main(){
  int N,W;
  cin>>N>>W;
  ll w[N],V[N];
  for(int i=0;i<N;i++)cin>>w[i]>>V[i];
  ll dp[N][W+1];
  for(int i=0;i<=W;i++){
    if(i<w[0]){

      dp[0][i]=0;
    }else{
      dp[0][i]=V[0];
    }
  }
  for(int i=0;i<N-1;i++){
    for(int j=0;j<=W;j++){
      if(j>=w[i+1]){
        dp[i+1][j]=max(dp[i][j],dp[i][j-w[i+1]]+V[i+1]);
      }else{

        dp[i+1][j]=dp[i][j];
      }
    }
  }
  cout<<dp[N-1][W]<<endl;
}

Measured memory_bytes: 78336
n=int(input())
ans=[100000000000000,1,1]
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        if abs(n//i-i)<ans[0]:
            ans=[abs(n//i-i),i,n//i]
print(ans[1]-1+ans[2]-1)

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

int main()
{
	int n,p;
	int i;
	scanf("%d",&n);
	int a[105];	
	int sum=0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		sum+=a[i];
	}
	int ok=0;	
		if(sum%10!=0)
		{
			printf("%d",sum);
		}
		else
		{
			for(int i=0;i<n;i++)
			{
				if(a[i]%10!=0)
				{
					p=a[i];
					ok=1;
					break;				
				}						
			}
			if(ok==1)
			{	
				printf("%d",sum-p);
			}
			else
			{
				printf("0\n");
			}		
		}	
	return 0;
}

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

string G[1001];
int n, m;
ll dp[1001][1001];

ll dfs(int x, int y) {
	if(x == n-1 and y == m-1)
		return 1;
	if(x < 0 or x >= n or y < 0 or y >= m or G[x][y] == '#')
		return 0;

	ll &ret = dp[x][y];
	if(ret != -1)
		return ret;

	ret = (dfs(x+1, y) + dfs(x, y+1))%MOD;
	return ret;
}

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

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

	memset(dp, -1, sizeof dp);
	cout << dfs(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 9216
n, m = map(int, input().split())
A = list(map(int, input().split()))
import numpy as np
A = np.array(A)
A = A/ np.sum(A)
thre = 1/(4*m)
count = 0
for i in A:
  if i >= thre:
    count += 1
if count >= m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 21920
fn main() {

//    let s = String::from("101");
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();

//    println!("{}",s);
    let mut ans = 0;
    if &s[0..1] == "1" {
        ans = ans + 1;
    }
    if &s[1..2] == "1" {
        ans = ans + 1;
    }
    if &s[2..3] == "1" {
        ans = ans + 1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(){
  int n,x,sum=0;
  scanf("%d",&n);
  x=n;
  while(x!=0){
    sum+=x%10;
    x/=10;
  }
  if(n%sum==0)
    puts("Yes");
  else
    puts("No");
  return 0;
}


Measured memory_bytes: 128
n = str(input())

if len(n) != 1:
    n = n[-1:]

if n == "2" or n == "4" or n == "5" or n == "7" or n == "9":
    print("hon")
elif n == "0" or n == "1" or n == "6" or n == "8":
    print("pon")
else:
    print("bon")    
    

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

using namespace std;
#define ll unsigned long long


int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string A;
	string B;
	cin>>A;
	cin>>B;
	int n = A.length();
	int m = B.length();
	int dp[n + 1][m + 1];
	for (int i=0; i<=n; i++){
		for (int j=0; j<=m; j++){
			dp[i][j] = 0;
		}
	}
	for (int i=0; i<=n; i++){
		for (int j=0; j<=m; j++){
			if(i == 0 || j == 0)
				dp[i][j] = 0;
			else{
				if(A[i - 1] == B[j - 1])
					dp[i][j] = dp[i - 1][j - 1] + 1;
				else
					dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	int ans = dp[n][m];
	map<int,int> check;
	vector<char> res;
	for (int i=n; i>=1; i--){
		for (int j=m; j>=1; j--){
			if(A[i - 1] == B[j - 1] && dp[i][j] == ans &&check[i - 1] == 0){
				res.push_back(A[i - 1]);
				check[i - 1] ++;
				ans--;
			}
			if(ans == 0)	break;	
		}
	}
	for (int i=res.size()-1; i>=0; i--){
		cout<<res[i];
	}
}

Measured memory_bytes: 38900