akhauriyash/Code-Regression huggingface dataset:
N = int(input())
T, A = map(int, input().split())
Hs = list(map(int, input().split()))

minAH, mini = 10000000, None
for i in range(N):
    AH = abs(A - (T - Hs[i] * 0.006))
    if minAH > AH:
        minAH = AH
        mini = i + 1
print(mini)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}else if(a>b){
		cout<<"a > b"<<endl;
	}else{
		cout<<"a == b"<<endl;
	}
}

Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int me[100000];
void solve(int x,int m,int n,int f){
  if(x>n) return;
  me[f]=m;
  if(n==x){
    for(int i=0;i<f;i++) printf("%d ",me[i]);
    printf("%d\n",me[f]);
    return;
  }
  for(int i=m;i>0;i--) solve(x+i,i,n,f+1);
}

main(){
  while(1){
    cin >> n;
    if(n==0) break;
    for(int i=n;i>0;i--)
      solve(i,i,n,0);
  }
}

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

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

	vector<vector<int>> t(n + 1);
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		cin >> a >> b;
		t[a].push_back(b);
		t[b].push_back(a);
	}

	vector<int> ret(n + 1, -1);
	vector<bool> check(n + 1, false);

	queue<int> q;
	q.push(1);
	check[1] = true;

	while (!q.empty())
	{
		int f = q.front();
		for (auto& j : t[f]) 
		{
			if (check[j]) {
				continue;
			}
			ret[j] = f;
			check[j] = true;
			q.push(j);
		}
		q.pop();
	}

	cout << "Yes" << endl;
	for (int i = 2; i <= n; ++i)
	{
		cout << ret[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 10168
#include<bits/stdc++.h>
#define maxn 500005
using namespace std;
inline int read()
{
	char x = getchar();
	int lin = 0, f = 1;
	while(x < '0' || x > '9')
	{
		if(x == '-') f = -1;
		x = getchar();
	}
    while(x >= '0' && x <= '9')
	{
		lin = lin * 10 + x - '0';
		x = getchar();
	}
	return lin * f;
}
#define PII pair<int,int>
#define fir first
#define sec second
#define ma(a,b) make_pair(a,b)
int n,s[maxn],q[maxn],ans;
int main(){
	n = read();
	for(int i = 1; i <= n; i++)
	{
		s[i] = read();
		q[i] = s[i];
	}
	sort(q + 1,q + 1 + n);
	for(int i = 1; i <= n; i++)
	{
		int ne = lower_bound(q + 1,q + 1 + n,s[i]) - q;
		if(abs(i - ne) & 1) ++ans;
	}
	cout << ans / 2;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<functional>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<unordered_set>
#include<unordered_map>
#define int long long
using namespace std;

int a[26];
signed main(){
	int ans = 1;
	string b; cin >> b;
	for (char c : b) {
		a[c - 'a'] ++;
	}
	int sum = b.length();
	for (int i = 0; i < 26; i++) {
		sum -= a[i];
		ans += a[i] * sum;
	}
	cout << ans << endl;
	getchar();
}


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

int main() {
    int N; cin >> N;
    vector<int> ans(N+1,0);
    for (int i = 1; i * i <= N; ++i) {
        for (int j = 1; i * i + j * j + i * j <= N; ++j) {
            for (int k = 1; i * i + j * j + k * k + i * j + j * k + k * i <= N; ++k) {
                ans[i*i + j*j + k*k + i*j + j*k + k*i]++;
            }
        }
    }
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << endl;
    }
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef vector< int > Array;
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }

int n;
vector< Array > edges;
bool visit[110];

int rec(int v) {
	int res = 1;
	
	visit[v] = 1;
	
	int e_size = size_of(edges[v]);
	for_(i,0,e_size) {
		int u = edges[v][i];
		if (visit[u]) continue;
		maxUpdate(res, rec(u) + 1);
	}
	
	visit[v] = 0;
	
	return res;
}

void solve() {
	minit(visit, 0);
	int ans = 0;
	for_(i,1,101) maxUpdate(ans, rec(i));
	printf("%d\n", ans);
}

int main() {
	while (cin >> n, n) {
		edges.assign(101, Array());
		
		for_(i,0,n) {
			int a, b;
			scanf("%d %d", &a, &b);
			edges[a].push_back(b);
			edges[b].push_back(a);
		}
		
		solve();
	}
	return 0;
}

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

int main()
{
    int n,x,i,j;

    scanf("%d",&n);
    vector<pair<ll,ll>>v;

    for(i=0;i<n;i++)
    {
        scanf("%d",&x);
        v.push_back(make_pair(x,i+1));
    }

    sort(v.begin(),v.end());

    for(i=0;i<v.size();i++)
        cout<<v[i].second<<" ";
    cout<<endl;

    return 0;
}


Measured memory_bytes: 2548
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>
#include <complex>

using namespace std;

#define mod 1000000007

long long int res[3000][3000] = {};

int main()
{
	int n, t;
	cin >> n >> t;
	int a[3000], b[3000];
	vector<pair<int ,int> > ab;
	for(int i = 0; i < n; i++){
		int tmpa, tmpb;
		cin >> tmpa >> tmpb;
		ab.push_back(make_pair(tmpa, tmpb));
	}
	sort(ab.begin(), ab.end());
	for(int i = 0; i < n; i++){
		a[i] = ab[i].first;
		b[i] = ab[i].second;
	}
	res[0][a[0]] = b[0];
	long long int ans = b[0];
	for(int i = 1; i < n; i++){
		res[i][a[i]] = b[i];
		for(int j = 0; j < t; j++){
			res[i][j] = max(res[i - 1][j], res[i][j]);
			ans = max(ans, res[i - 1][j] + b[i]);
			if(j >= a[i]) res[i][j] = max(res[i][j], res[i - 1][j - a[i]] + b[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 70656
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	int a,b,c;
	cin>>a>>b>>c;
	cout << (a<=c&&c<=b?"Yes":"No")<<endl;


	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int a[1000001];
int main()
{
	int s;
	scanf("%d",&s);
	for(int i=0;;i++)
	{
		if(i==0)
			a[i]=s;
		else
		{
			if(a[i-1]%2==0)
				a[i]=a[i-1]/2;
			else
				a[i]=a[i-1]*3+1;
			for(int j=0;j<=i-1;j++)
			{
				if(a[j]==a[i])
				{
					printf("%d",i+1);
					return 0;
				}
			}
		}
	}
	return 0;
}

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

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

    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(n==2)
        cout<<abs(a[0]-a[1])<<"\n";
    else if(k==1)
    {   int c=0;
        for(int i=1;i<n;i++)
        {
            c+=abs(a[i]-a[i-1]);
        }
        cout<<c<<"\n";
    }
    else
    {
        int dp[n]={0};
        dp[0]=0;
        dp[1]=abs(a[0]-a[1]);

        for(int i=2;i<k;i++)
        {   int c=abs(a[i]-a[0]);
            for(int j=1;j<i;j++)
            {
                c=min(c,dp[j]+abs(a[j]-a[i]));
            }
            dp[i]=c;
        }
        for(int i=k;i<n;i++)
        {   int c=dp[i-k]+abs(a[i-k]-a[i]);
            for(int j=i-k+1;j<i;j++)
               c=min(c,dp[j]+abs(a[j]-a[i]));
            dp[i]=c;
        }
        cout<<dp[n-1]<<"\n";
    }

    return 0;
}


Measured memory_bytes: 1024
import sys
import numpy as np

input = sys.stdin.readline

D = int(input())
c = np.array(list(map(int, input().split())), dtype=int)
S = np.array([list(map(int, input().split())) for _ in range(D)], dtype=int)
dissatis = np.zeros(26, dtype=int)

v = 0
for i, s in enumerate(S):
    dissatis += c
    t = np.argmax(s+dissatis)
    dissatis[t] = 0
    print(t+1)


Measured memory_bytes: 27472
a1, b1 =map(int,input().split())
a2, b2 =map(int,input().split())
a3, b3 =map(int,input().split())
data_list=[a1,a2,a3,b1,b2,b3]
count=0
for i in range (4):
    if data_list.count(i)>=2:
        count+=1
if count>=2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int count;
    bool[] c;
    int N;
    List<int>[] G;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        G = new List<int>[N];
        for(int i=0;i<N;i++){
            G[i] = new List<int>();
        }
        for(int i=0;i<M;i++){
            str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0])-1;
            int b = int.Parse(str[1])-1;
            G[a].Add(b);
            G[b].Add(a);
        }
        c = new bool[N];
        count = 0;
        dfs(0,0);
        sb.Append(count+"\n");
    }
    void dfs(int p,int n){
        if(n == N-1){
            count++;
            return;
        }
        c[p] = true;
        for(int i=0;i<G[p].Count;i++){
            int pn = G[p][i];
            if(!c[pn]){
                dfs(pn,n+1);
            }
        }
        c[p] = false;
    }
}

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

int main() {
    long long sum= 0;
    char ch;
    while (cin >> ch ) {
        int num= ch- '0';
        sum+= num;
    }
    if (sum% 9==0) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<complex>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
using namespace std;

int main() {
  int n;
  cin >> n;
  int num;
  vector<int> a;
  int i, j;
  int ans = 1000000;
  int sum = 0;

  for (i = 0; i < n; i++) {
    cin >> num;
    a.push_back(num);
  }

  for (i = -100; i <= 100; i++) {
    sum = 0;
    for (j = 0; j < n; j++) {
      sum += (a[j] - i) * (a[j] - i);
    }
    if (ans > sum) {
      ans = sum;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
// C++ code to count the number of 
// possible triangles using brute 
// force approach 
#include <bits/stdc++.h> 
using namespace std; 

// Function to count all possible 
// triangles with arr[] elements 
int findNumberOfTriangles(int arr[], int n) 
{ 
	// Count of triangles 
	int count = 0; 

	// The three loops select three 
	// different values from array 
	for (int i = 0; i < n; i++) { 
		for (int j = i + 1; j < n; j++) { 

			// The innermost loop checks for 
			// the triangle property 
			for (int k = j + 1; k < n; k++) 

				// Sum of two sides is greater 
				// than the third 
				if ( 
					arr[i] + arr[j] > arr[k] 
					&& arr[i] + arr[k] > arr[j] 
					&& arr[k] + arr[j] > arr[i] && arr[i]!=arr[j] && arr[i]!=arr[k] && arr[j]!=arr[k]) 
					count++; 
		} 
	} 
	return count; 
} 

// Driver code 
int main() 
{ 
    int n;
    cin>>n;
    int a[n],i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<findNumberOfTriangles(a,n);
	return 0; 
} 


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

int main() {
  int n;
  cin >> n;
  
  int min=-1;
  
  for(int i=0;i<n;i++) {
    int a;
    cin >>a;
    
    int counter = 0;
    
    while(a%2==0){
      counter++;
      a /= 2;
    }
    
    if(min==-1 || counter < min) {
      min = counter;
    }
  }
  
  cout << min <<endl;
}


Measured memory_bytes: 256
Imports System.Collections.Generic
Public Class Program
  Shared Sub Main()
    Dim n As Long = Long.Parse(Console.ReadLine())
    Dim s(0 To n - 1)() As Char
    For i As Long = 0 To n - 1
      s(i) = Console.ReadLine().ToCharArray()
      Array.Sort(s(i))
    Next
    Dim dict As Dictionary(Of String, Long) = New Dictionary(Of String, Long)
    Dim output As Long = 0
    For i As Long = 0 To n - 1
      Dim str As String = New String(s(i))
      If Not dict.ContainsKey(str) Then
        dict.Add(str, 1)
      Else
        dict(str) += 1
        output += dict(str) - 1
      End If
    Next
    Console.WriteLine(output.ToString())
  End Sub
End Class

Measured memory_bytes: 37548
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():
    lines = input()
    n = int(lines[0].strip())
    a = list(map(int, lines[1].split()))

    cnt = 0

    for i in range(2, n):
        b = a[i-2:i+1]
        b = sorted(b)
        if a[i-1] == b[1]:
            cnt += 1

    print(cnt)

main()


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

int main() {
    int n,x;cin>>n>>x;
    int s[n+1],d[n],ans;
    
    s[0]=x;
    for(int i=1;i<n+1;++i){
        cin>>s[i];
        d[i-1]=s[i]-s[i-1];
    }
    sort(s,s+n+1);
  for(int i=1;i<n+1;++i){
        d[i-1]=abs(s[i]-s[i-1]);
    }
    sort(d,d+n);
    ans = __gcd(d[0], d[1]);

    for(int i=2;i<n;++i){
    ans = __gcd(ans, d[i]);
    }
    
    cout<<ans<<endl;

	return 0;
}

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

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

using namespace std;
long long a[200005];

int main(){
  int n;
  cin >> n;
  long long tmp=0;
  REP(i, n){
    cin >> a[i];
  }
  for(int i=1; i<n; i++) a[i] += a[i-1];
  sort(a, a+n+1);
  long long res=0;
  REP(i, n){
    tmp=1;
    while(i<n && a[i]==a[i+1]){
      i++;
      tmp++;
    }
    res += tmp * (tmp-1) / 2;
  }
  cout << res << endl;
}

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

using namespace std;

int main(){

  int t;

  cin>>t;
  
  for(int i=0;i<t;i++){

	int n,k;
	int sum=0;

	cin>>n>>k;

	vector<int> x(n);
	vector<int> dis;
	int n_k;

	n_k = n-k;

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

	for(int i=0;i<n-1;++i)
	  dis.push_back(x[i+1]-x[i]);

	sort(dis.begin(),dis.end());
	
	for(int i=0;i<n_k;i++){

	  sum+=dis[i];
	  
	}

	cout<<sum<<endl;
	
  }
  
}



Measured memory_bytes: 4088
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function breakIn(){
		$buf = str_split($this->killNewLine(fgets(STDIN)));
		return $buf;
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->breakIn();
		
		$ans = 0;

		foreach ($s as $w){
			if ( "a" === $w ){
				$ans += 1;
			}elseif ( "b" === $w ){
				$ans += 10;
			}elseif ( "c" === $w ){
				$ans += 100;
			}
		}
		unset($w);

		if ( 111 === $ans ){
			echo "Yes\n";
		}else{
			echo "No\n";
		}
	}
}
?>


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
 
int main(void){
	int N, M;
  	std::cin >> N >> M;
  	std::vector<std::vector<int>> switchSet(M);
  	for(int i = 0; i < M; ++i){
    	int k;
      	std::cin >> k;
      	switchSet[i].resize(k);
      	for(int j = 0; j < k; ++j){
          std::cin >> switchSet[i][j];
          --switchSet[i][j];
        }
    }
  
  	std::vector<int> P(M);
  	for(int i = 0; i < M; ++i) std::cin >> P[i];
  
  	int count = 0;
  	for(int i = 0; i < (1 << N); ++i){
     	bool ok = true;
    	for(int j = 0; j < M; ++j){
        	int c = 0;
          	for(int id : switchSet[j]){
            	if((i >> id) & 1) ++c;
            }
          	c %= 2;
          	if(c != P[j]){
            	ok = false;
            }
        }
      	if(ok) ++count;
    }
  
  	std::cout << count << std::endl;
  	return 0;
}

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


int main() {
    int N;
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        int price = i * 1.08;
        if (price == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}



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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

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

    vector<string>s(n);
    rep(i,n){
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
    }

    sort(s.begin(),s.end());
    s.push_back("");

    ll cnt=1,ans=0;

    rep(i,n){
        if(s[i]==s[i+1]){cnt++;}
        else {
            ans+=(cnt*(cnt-1))/2;
            cnt=1;

        }
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 9604
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int n;
    cin>>n;
    int a,b,c;
    long long int dpa[n],dpb[n],dpc[n];
    cin>>a>>b>>c;
    dpa[0]=a;
    dpb[0]=b;
    dpc[0]=c;
    for(int i=1;i<n;i++){
        cin>>a>>b>>c;
        if(dpa[i-1]<dpb[i-1])
        dpc[i]=c+dpb[i-1];
        else
        dpc[i]=c+dpa[i-1];
        if(dpc[i-1]<dpb[i-1])
        dpa[i]=a+dpb[i-1];
        else
        dpa[i]=a+dpc[i-1];
        if(dpa[i-1]<dpc[i-1])
        dpb[i]=b+dpc[i-1];
        else
        dpb[i]=b+dpa[i-1];
    }
    if(dpa[n-1]>dpb[n-1]&&dpa[n-1]>dpc[n-1])
    cout<<dpa[n-1];
    else if(dpb[n-1]>dpc[n-1])
    cout<<dpb[n-1];
    else
    cout<<dpc[n-1];
    return 0;
}

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

int judge(int n){
  int max=-1, min=1001, sum=0;
  vi s(n);
  rep(i, n){
    cin >> s[i];
    sum+=s[i];
    if(s[i]>max)max=s[i];
    if(s[i]<min)min=s[i];
  }
  return (sum-max-min)/(n-2);
}

int main(){
  int cnt=0;
  vi ans(20);
  rep(i, 20){
    int n;
    cin >> n;
    if(n==0)break;
    ans[i]=judge(n);
    cnt++;
  }

  rep(i, cnt){
    if(ans[i]==-1)break;
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>

int main(void)
{
	int s;
	scanf("%d",&s);
	
	int h = s/3600;
	
	s = s%3600;
	
	int m = s/60;
	
	s = s%60;
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
	
}


Measured memory_bytes: 2056
#include<stdio.h>

int main()
{
    int a,b,c;

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

    if (a!=b && a!=c) printf("%d",a);
    else if (b!=a && b!=c) printf("%d",b);
    else if (c!=a && c!=a) printf("%d",c);

    return 0;
}

Measured memory_bytes: 128
# AOJ 0121 Seven Puzzle 
# Python 2017.6.23 bal4u

def swap(state, x, y):
	s = list(copy.deepcopy(state))
	s[x], s[y] = s[y], s[x]
	return tuple(s)
	
from collections import deque
import copy
MAGIC = 37
move = ((1,4), (0,2,5), (1,3,6), (2,7), (0,5), (1,4,6), (2,5,7), (3,6))

Q = deque()
Q.append(((0,1,2,3,4,5,6,7), 0))
hash = {}
hash[(0,1,2,3,4,5,6,7)] = 0
while Q:
	state, x = Q.popleft()
	step = hash[state]+1
	if step > MAGIC: continue
	for y in move[x]:
		nstate = swap(state, x, y)
		if nstate not in hash: nstep = 100
		else: nstep = hash[nstate]
		if step < nstep:
			Q.append((nstate, y))
			hash[nstate] = step

while 1:
	try: state = tuple(map(int, input().split()))
	except: break
	print(hash[state])


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

using namespace std;

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   string s;
   cin >> s;
   string t = "YAKI";
   if(s.substr(0,4) == t)cout << "Yes";
   else cout << "No";
   return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
p = list(map(int,input().split()))
p_kitaiti = [(1+p[i])/2 for i in range(n)]
ans = sum(p_kitaiti[:k])
number = sum(p_kitaiti[:k])
for i in range(k,n):
    number = number + p_kitaiti[i] - p_kitaiti[i-k]
    ans = max(ans,number)
print(ans)


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

class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var n = input[0];
		var k = input[1];

		var nDigitNum = 0;

		var ans = new List<int>();

		while (n >= k)
		{
			var num = n % k;
			ans.Add(num);
			n /= k;
		}

		ans.Reverse();

		System.Console.WriteLine(ans.Count + 1);

	}
}

Measured memory_bytes: 13396
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1150&lang=jp

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
int main(){
    int coins[4]={10,50,100,500};
    int inp;
    int firsttest = 1;
    while(1){
        cin>>inp;
        if(!inp)
            return 0;
        int have[4];
        int sum = 0;
        rep(i,4){
            cin>>have[i];
            sum+=have[i]*coins[i];
        }
        sum-=inp;
        int minus[4]={0,0,0,0};
        rep(i,4){
            if(sum>=coins[3-i]){
                minus[3-i]=sum/coins[3-i];
                sum%=coins[3-i];
            }
        }
        rep(i,4){
            have[i]=max(0,have[i]-minus[i]);
        }
        if(!firsttest)
            cout<<endl;
        rep(i,4){
            if(have[i])
                cout<<coins[i]<<" "<<have[i]<<endl;
        }
        firsttest = 0;
    }
}

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

using namespace std;
typedef long long ll;

#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define MAX_H 20
#define MAX_W 20

int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, w, h, ans = 0;
string board[MAX_H];

int dfs(int x, int y) {
  if (board[y][x] == '#') {
    return 0;
  } else {
    ans++;
    board[y][x] = '#';
  }

  for (int i = 0; i < 4; i++) {
    int nextx = x + dx[i], nexty = y + dy[i];
    if (nextx >= w || nextx < 0 || nexty >= h || nexty < 0)
      continue;
    dfs(x + dx[i], y + dy[i]);
  }

  return ans;
}

int main(void) {
  vector<int> ret;
  while (true) {
    ans = 0;
    scanf("%d %d", &w, &h);
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < h; i++)
      cin >> board[i];

    int sx = 0, sy = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (board[i][j] == '@') {
          sx = j;
          sy = i;
        }
      }
    }

    dfs(sx, sy);
    ret.push_back(ans);
  }

  for (int i = 0; i < ret.size(); i++) {
    cout << ret[i] << endl;
  }

  return 0;
}

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

using namespace std;

int main(){
    string S, T;
    cin >> S >> T;
    
    vector<string> candidates;
    
    for(int i = 0; i < S.length() - T.length() + 1; ++i){
        bool flag = true;
        for(int j = 0; j < T.length(); ++j){
            if(S[i + j] != '?'&& S[i + j] != T[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            string temp = S;
            temp.replace(i, T.length(), T);
            candidates.push_back(temp);
        }
    }
    
    if(!candidates.size()){
        cout << "UNRESTORABLE\n";
        return 0;
    }
    
    priority_queue<string, vector<string>, greater<string>> que;
    for(int i = 0; i < candidates.size(); ++i){
        for(int j = 0; j < S.length(); ++j){
            if(candidates[i][j] == '?'){
                candidates[i][j] = 'a';
            }
        }
        que.push(candidates[i]);
    }
    
    cout << que.top() << endl;
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<array<int64_t, 3>> XYZ(N);
  for (int i = 0; i < N; i++) {
    cin >> XYZ[i][0] >> XYZ[i][1] >> XYZ[i][2];
  }

  int64_t result = 0;
  for (int i = 0; i < 1 << 3; i++) {
    vector<int64_t> sums;
    for (int k = 0; k < N; k++) {
      int64_t sum = 0;
      for (int j = 0; j < 3; j++) {
        sum += (i & (1 << j)) ? XYZ[k][j] : -XYZ[k][j];
      }
      sums.emplace_back(sum);
    }
    sort(sums.rbegin(), sums.rend());

    int64_t sum = 0;
    for (int k = 0; k < M; k++) sum += sums[k];
    result = max(result, sum);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
s = STDIN.gets.chomp

if s.match(/\A.+keyence\z/)
  puts 'YES'
elsif s.match(/\Ak.+eyence\z/)
  puts 'YES'
elsif s.match(/\Ake.+yence\z/)
  puts 'YES'
elsif s.match(/\Akey.+ence\z/)
  puts 'YES'
elsif s.match(/\Akeye.+nce\z/)
  puts 'YES'
elsif s.match(/\Akeyen.+ce\z/)
  puts 'YES'
elsif s.match(/\Akeyenc.+e\z/)
  puts 'YES'
elsif s.match(/\Akeyence.+\z/)
  puts 'YES'
elsif s == 'keyence'
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 1916
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main() {

ll N,K,a,b;
cin>>N>>K;
vector<pair<ll,ll>> pair(N);
rep(i,N){
  cin>>a>>b;
  pair[i]=make_pair(a,b);
}
sort(all(pair));
ll count=0;
rep(i,N){
  count+=pair[i].second;
  if(count>=K){
    cout<<pair[i].first<<endl;
    break;
  }
}




return 0;
}

Measured memory_bytes: 1792
#!ruby -na
f=->n,m,a,b{s=a/m*n*~-n/2+b/m*n
b%=m
x=b-m*y=(b+n*a%=m)/m
y>0&&s+=f[y,a,m,x%a]+y*=n+x/a
s}
p f[*$F.map(&:to_i)]if$.>1

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

int main() {
  int num;
  int flg = false;
  char str;
  
  cin >> num;

  for (int i = 0; i < num; i++) {
    cin >> str;
     if (str == 'Y'){
      flg = true;
    }
  }
  
  if(flg){cout << "Four" << endl;}
  else {cout << "Three" << endl;}

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
int main(void){
   int x,y,i;
   char s[101];
 
   scanf("%d",&x);
   scanf("%s",s);
   
   y=strlen(s);
  
   if(y<=x){
      printf("%s\n",s);
   }else{
      for(i=0;i<x;i++){
         printf("%c",s[i]);
      }
      
      printf("...\n");
      }
   return 0;
}


Measured memory_bytes: 1644
// https://atcoder.jp/contests/abc084/tasks/abc084_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int m;

  cin >> m;

  cout << (48 - m) << '\n';

  return 0;
}


Measured memory_bytes: 256
n = int(input())
g = []
d = [0] * (n + 1)
for i in range(n + 1):
    g.append([]);
for i in range(n - 1):
    u, v, w = map(int, input().split())
    g[u].append([v, w])
    g[v].append([u, w])
q, k = map(int, input().split())
def bfs(u):
    s = []
    s.append(u)
    while s:
        v = s[-1]
        s.pop()
        for go in g[v]:
            if not d[go[0]] and go[0] != u:
                d[go[0]] = d[v] + go[1]
                s.append(go[0])
bfs(k)
while q > 0:
    u, v = map(int, input().split())
    print(d[u] + d[v])
    q -= 1


Measured memory_bytes: 51408
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
using namespace std;

int INF = 1e9 + 7;

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

vector<vector<int>> c(20, vector<int>(20, 0));

void warshall_floyd() {
	for (int k = 0; k <= 9; k++) {
		for (int i = 0; i <= 9; i++) {
			for (int j = 0; j <= 9; j++) {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
}

int main() {
	int h, w;
	cin >> h >> w;

	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			cin >> c[i][j];
		}
	}

	warshall_floyd();

	int a, sum = 0;
	for (int i = 1; i <= h * w; i++) {
		cin >> a;
		if (a >= 0) {
			sum += c[a][1];
		}
	}
	cout << sum << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n,u,v; 
vll G[100100];

ll ng;
bool reachable[100100];
void dfs(ll v, ll p){
  reachable[v]=true;
  for(auto nv: G[v]){
    if(nv==ng) continue;
    if(nv==p) continue;
    dfs(nv,v);
  }
}

ll dist[100100];
void dfs2(ll v, ll p, ll cnt){
  dist[v]=cnt;
  for(auto nv: G[v]){
    if(nv==p) continue;
    dfs2(nv,v,cnt+1);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>n>>u>>v; u--,v--;
  rep(i,n-1){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<pll> q;
  q.emplace(u,-1);
  q.emplace(v,-1);
  vb visited(n);
  visited[u]=visited[v]=true;
  while(!q.empty()){
    auto p=q.front(); q.pop();
    ll v=p.first, parent=p.second;
    bool flg=false;
    for(auto nv:G[v]){
      if(nv==parent) continue;
      if(visited[nv]){
        ng=nv;
        flg=true;
        break;
      }
      visited[nv]=true;
      q.emplace(nv,v);
    }
    if(flg) break;
  }
  
  dfs(u,-1);
  dfs2(v,-1,0);
  
  ll ans=0;
  rep(i,n){
    if(reachable[i]){
      chmax(ans,dist[i]-1);
    }
  }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 10624
#include <iostream>

int main(){
    int n, k;
    std::cin >> n >> k;

    std::string d = "";
    char buf;
    for(int i = 0; i < k; ++i){
        std::cin >> buf;
        d += buf;
    }

    bool flg = false;
    std::string nStr;
    while(!flg){
        nStr = std::to_string(n);
        for(int i = 0; i < k; ++i){
            if(std::string::npos == nStr.find(d.at(i))){
                flg = true;
            }else{
                flg = false;
                ++n;
                break;
            }                
        }
    }
    std::cout << nStr << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 2;
ll a[N];
int main(){
   int n, m;
   cin >> n >> m;
   priority_queue<int> pq;
   for(int i = 1; i <= n; i++){
      cin >> a[i];
      pq.push(a[i]);
   }
  
   while(m--){
     int x = pq.top();
     pq.pop();
     pq.push(x / 2);
   }
  
   ll ans = 0LL;
   while(!pq.empty()){
      ans += pq.top();
      pq.pop();
   }
  
   cout << ans;
 
   return 0;
}

Measured memory_bytes: 4572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        var A = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var a = new long[N];
        for (int i = 0; i < N; i++)
        {
            a[i] = A[i] - (i + 1);
        }
        Array.Sort(a);

        long ans = 0;
        
        for (int i = 0; i < N; i++)
        {
            ans += Math.Abs(A[i] - (i + 1) - a[N/2]);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28636
n = int(input())
ab = []
for i in range(n-1):
    a, b = map(int,input().split())
    ab.append([a, b])

graph = [[] for _ in range(n+1)]
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (n+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
        
color = [-1] * (n+1)
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if y == parent[x]:
            continue # 子に対応させる
        if c == ng:
            c += 1
        color[y] = c
        c += 1

print(max(color))
for a,b in ab:
    if parent[a] == b:
        print(color[a])
    else:
        print(color[b])

Measured memory_bytes: 107032
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n,x;
  cin>>n>>x;
  vector<int> a(n),b;
  rep(i,n)cin>>a[i];
  int ans=0;
  if(a[0]>x){
    ans+=a[0]-x;
    a[0]=x;
  }
  rep(i,n-1){
    if(a[i]+a[i+1]>x){
      ans+=(a[i]+a[i+1]-x);
      a[i+1]-=(a[i]+a[i+1]-x);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int p[n];
    for (int i = 0; i < n; i++) {
	cin >> p[i];
    }
    int count = 0;
    for (int i = 1; i < n - 1; i++) {
	if (p[i - 1] >= p[i] && p[i] > p[i + 1]) {
	    count++;
	} else if (p[i - 1] < p[i] && p[i] <= p[i + 1]) {
	    count++;
	}
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

main(){
	int n;
	scanf("%d",&n);
	vector<int> a(n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	
	long long ans=0;
	
	for(int i=0;i<n;i++){
		ans+=a[i]/2;a[i]%=2;
		if(a[i]==1 && i+1<n && a[i+1]>=1){a[i]--;a[i+1]--;ans++;}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int N;
ll K;
vector<int> A;
vector<int> order;
vector<int> S;
int s;

void dfs(int v) {
    order[v] = S.size();
    S.push_back(v);

    if (order[A[v]] != -1) {
        s = A[v];
        return;
    }
    dfs(A[v]);
}

int main() {
    cin >> N >> K;
    A.resize(N + 1);
    for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
    order.assign(N + 1, -1);

    dfs(1);
    int p = S.size() - order[s];
    int l = order[s];
    if (K < l) {
        cout << S[K] << endl;
    } else {
        K -= l;
        K %= p;
        cout << S[l + K] << endl;
    }
    return 0;
}

Measured memory_bytes: 11924
def main():
    k = int(input())
    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]
    print(a[k - 1])


if __name__ == '__main__':
    main()


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

int main() {
  
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(),s.end());
  
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  if(s<t)cout << "Yes" << endl;
  else cout << "No" << endl;
  
 
  
  
  
 
  

  
    
 
}


           

Measured memory_bytes: 256
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 2e5 + 10;

int a[N];
multiset<ll> demand;

int main() {
	fast_cin();
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n, greater<int>());
	ll p = 1;
	while (p <= 2 * a[1]) {
		p *= 2;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		while (a[i] < p / 2) {
			p /= 2;
		}
		if (demand.count(a[i])) {
			++ans;
			demand.erase(demand.find(a[i]));
		} else {
			demand.insert(p - a[i]);
		}
	}
	cout << ans << endl;
}

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

int main() {
  string s;
  cin>>s;
  string keyence = "keyence";
  if (s == keyence) {
    cout<<"YES"<<endl;
    return 0;
  }
  int n = s.length();
  for (int i=0; i<n; i++) {
    for (int j=i+1; j<n; j++) {
      string t = s.substr(0, i) + s.substr(j);
      if (t == keyence) {
        cout<<"YES"<<endl;
        return 0;
      }
    }
  }
  cout<<"NO"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
 
namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var pg = new Program();
 
            pg.Execute();
         
        }
 
        private void Execute()
        {
            var input = ReadLinesLongList;
            var ALists = ReadLinesLongList;
            var N = (int)input.ElementAt(0);
            var M = (double)input.ElementAt(1);
            var con = ALists.Sum() * (1 / (4 * M));
 
            if(ALists.OrderByDescending(e => e).Take((int)M).All(e => e >= con)){
                OutputResult("Yes");
            }
            else{
                OutputResult("No");
            }
        }
 
        private void OutputResult<Type>(Type result){
            Console.WriteLine(result);
        }
 
        static long ReadLineLong => long.Parse(Console.ReadLine());
        static string ReadLineString => Console.ReadLine();
        static IEnumerable<long> ReadLinesLongList => Console.ReadLine().Split(' ').Select(i => long.Parse(i));
        static IEnumerable<string> ReadLinesStringList => Console.ReadLine().Split(' ');
 
    }
}


Measured memory_bytes: 28316
import java.util.ArrayList;
import java.util.Scanner;

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

        Scanner inp = new Scanner(System.in);
        total = inp.nextInt();

        int a[] = new int[total];

        for (int k = 0; k < total; k++) {
            a[k] = inp.nextInt();
        }

        int part = partition(a, 0, total-1);

        StringBuilder s = new StringBuilder();
        for (int i = 0; i < total; i++) {
            if (part == i) {
                s.append("[" + a[i] + "]");
            } else {
                s.append(a[i]);
            }

            if (i != total-1) {
                s.append(" ");
            }
        }

        System.out.print(s + "\n");
    }

    public static int partition(int[] a, int p, int r) {
        int x = a[r];
        int i = p-1;
        for (int j = p; j < r; j++) {
            if (a[j] <= x) {
                i = i+1;
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }

        int temp = a[i+1];
        a[i+1] = a[r];
        a[r] = temp;

        return i+1;
    }
}



Measured memory_bytes: 68664
K = input()
N = len(K)
D = int(input())
mod = 10**9+7

dp = [[[0]*D for _ in range(2)] for _ in range(N+1)]
dp[0][1][0] = 0
dp[0][0][0] = 1

for i in range(N):
    a = ord(K[i])-48
    
    for j in range(D):
        for k in range(10):
            dp[i+1][1][(j+k)%D] += dp[i][1][j]
            dp[i+1][1][(j+k)%D] %= mod

    for j in range(D):
        dp[i+1][0][(j+a)%D] += dp[i][0][j]
        dp[i+1][0][(j+a)%D] %= mod

    for j in range(D):
        for k in range(a):
            dp[i+1][1][(j+k)%D] += dp[i][0][j]
            dp[i+1][1][(j+k)%D] %= mod

print((dp[N][1][0] + dp[N][0][0]-1)%mod)

Measured memory_bytes: 64356
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()

    def hoge: String = {
      rep(26) { i =>
        rep(15) { j =>
          if (i * 4 + j * 7 == N) return "Yes"
        }
      }
      "No"
    }

    out.println(hoge)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) { f(i); i += 1 }
  }
  def rep_r(n: Int)(f: Int => Unit): Unit = {
    var i = n - 1
    while(i >= 0) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 26812
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e5+10;
int a[N];
vector<int> vec[N];
bool mark[N];
int dfs(int v,int p){
    mark[v]=1;
    int tot=0,ch=0,maxx=0;
    for(int u:vec[v]){
        if(mark[u])
            continue;
        ch++;
        int t=dfs(u,v);
        tot+=t;
        maxx=max(maxx,t);
    }
    if(ch==0)
        return a[v];
    if(a[v]>tot||a[v]<maxx||a[v]*2<tot){
        cout<<"NO";
        exit(0);
    }
    return 2*a[v]-tot;
}
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<n;i++){
       int a,b;cin>>a>>b;
       vec[a].pb(b);
       vec[b].pb(a);
    }
    if(n==2){
        if(a[1]==a[2])
            cout<<"YES";
        else
            cout<<"NO";
        return 0;
    }
    int v=1;
    for(;v<=n;v++)
        if(vec[v].size()>=2)
            break;
    int ans=dfs(v,-1);
    if(ans==0)
        cout<<"YES";
    else
        cout<<"NO";
}




Measured memory_bytes: 11904
from sys import stdin

def binarysearch(cadena,x):
	low,hi = 0,len(cadena)
	while low+1 != hi:
		mid = low +((hi - low)//2)
		if x < cadena[mid]:
			hi = mid
		else:
			low = mid
	return low

def main():
	N = int(stdin.readline().strip())
	i,number,copy = 0,[-1 for x in range(N)],[-1 for x in range(N)]
	while i < N:
		x = int(stdin.readline().strip())
		number[i] = x
		copy[i] = x
		i+=1
	i,op1 = 0,0
	copy.sort()
	while i < N:
		pos = binarysearch(copy,number[i])
		if (abs(pos-i))%2!= 0:
			op1+=1
		i+=1
	ans = op1//2
	print(ans)
main()

Measured memory_bytes: 8304
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}

int main(){
  int n;
  cin>>n;
  int a=100*n/108;
  if(a*108/100==n)cout<<a<<endl;
  else if((a+1)*108/100==n)cout<<a+1<<endl;
  else cout<<":("<<endl;

  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n,k; cin>>n>>k;
  int ans=0;
  rep(i,n){
    int x; cin>>x;
    if(x>abs(k-x))
    ans+=2*abs(k-x);
    else
    ans+=2*x;
  }
  cout<<ans<<endl;

  return 0;
}


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

int main()
{
    int N;
    std::vector<int> p;

    std::cin >> N;
    for(int i=1; i<=N; i++){
        int pi;
        std::cin >> pi;
        p.push_back(pi);
    }

    std::vector<int> sortedp = p;
    std::sort(sortedp.begin(), sortedp.end());

    int num=0;
    for(int i=0; i<N; i++){
        if(p[i]!=sortedp[i]) num++;
    }

    std::string ans;
    if(num==0 || num==2){
        ans="YES";
    } else {
        ans="NO";
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map(String::toInt)
    var count = 0
    var tempList = aList
    while (true) {
        tempList = tempList.filter { it % 2 == 0 }
        if (tempList.isEmpty()) break
        count += tempList.size
        tempList = tempList.map { it / 2 }
    }
    println(count)
}


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

int main(void){

    int k, x;

    cin >> k >> x;

    for(int i = x - k + 1;i < x + k;i++){
        if(i == x + k - 1) cout << i;
        else cout << i << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256