akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.Writer;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author palayutm
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int K = in.nextInt();
            int[] a = in.nextIntArray(n);
            int ans = (int) 1e9;
            for (int i = 0; i + K <= n; i++) {
                int x = a[i], y = a[i + K - 1];
                ans = Math.min(ans, y - x + Math.min(Math.abs(x), Math.abs(y)));
            }
            out.println(ans);
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream out) {
            super(out);
        }

        public OutputWriter(Writer out) {
            super(out);
        }

        public void close() {
            super.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0;
        private int ptrbuf = 0;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int readByte() {
            if (lenbuf == -1) throw new UnknownError();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = stream.read(inbuf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

    }
}



Measured memory_bytes: 22100
import sys
from random import randint
input = sys.stdin.readline
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [i % 26 + 1 for i in range(D)]
last = [0] * 26
def score(day, score):
  for i in range(26): score -= (day - last[i]) * c[i]
  return score
def run(day):
  global last
  last = [0] * 26
  res = 0
  for d in range(day):
    contest = t[d]
    last[contest] = d + 1
    res = score(d + 1, res) + s[d][contest]
  return res


for d in range(1, D + 1):
  mx = -float("inf")
  mxx = randint(1, 27)
  for x in range(26):
    t[d - 1] = x
    res = run(d)
    if mx < res:
      mx = res
      mxx = x
  t[d - 1] = mxx
for d in range(1, D + 1):
  mx = -float("inf")
  mxx = t[d - 1]
  for x in range(26):
    t[d - 1] = x
    res = run(d)
    if mx < res:
      mx = res
      mxx = x
  t[d - 1] = mxx

for x in t: print(x + 1)

Measured memory_bytes: 79388
#include <iostream>
#include<math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)


long long dp[110][100010] = { 0 };

long long w[110];
long long  v[110];

int main() {
	int N,W;
	cin >> N>>W;
	
	
	rep(i, N) {	
			cin >> w[i]>>v[i];
	}
	
	for (int i = 0; i < N; ++i) {
		for (int ww = 0; ww <= W; ++ww) {
			if (ww >= w[i]) dp[i + 1][ww] = max(dp[i][ww - w[i]] + v[i], dp[i][ww]);
			else dp[i + 1][ww] = dp[i][ww];
		}
	}


	cout << dp[N][W] << endl;


return 0;
} 

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int cnt = 0;
  
  for (int X = A; X < B+1; X++){
    int d0,d1,d2,d3,d4;
    d4=X/10000;
    d3=(X-10000*d4)/1000;
    d2=(X-10000*d4-1000*d3)/100;
    d1=(X-10000*d4-1000*d3-100*d2)/10;
    d0=(X-10000*d4-1000*d3-100*d2-10*d1);
    if (d4 == d0 && d3 == d1)
      cnt++;
  }
  
  cout << cnt << endl;
}


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

using namespace std;

const int max_n = (1 << 18) + 5, mod = 998244353;

int mul(int x, int y) {
    return (1LL * x * y) % mod;
}

int power(int a, int b) {
    if (b == 0) {
        return 1 % mod;
    }
    if (b % 2 == 0) {
        return power(mul(a, a), b / 2);
    }
    return mul(a, power(a, b - 1));
}

int inv(int x) {
    return power(x, mod - 2);
}

int n, sum, a[max_n], b[max_n], ans[max_n];

void product(int *a, int *b, int *c) {
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < (1 << n); ++j) {
            c[i ^ j] += mul(a[i], b[j]);
            c[i ^ j] %= mod;
        }
    }
}

int inv2 = inv(2);

template<bool inverse>
void convolve(int n, int *a) {
    if (n == 1) {
        return;
    }
    for (int i = 0; i < n / 2; ++i) {
        int a0 = a[i], a1 = a[i + n / 2];
        a[i] = (a0 + a1) % mod;
        a[i + n / 2] = (a0 + mod - a1) % mod;
        if (inverse) {
            a[i] = mul(a[i], inv2);
            a[i + n / 2] = mul(a[i + n / 2], inv2);
        }
    }
    convolve<inverse>(n / 2, a);
    convolve<inverse>(n / 2, a + n / 2);
}

void fast_product(int n, int *a, int *b, int *c) {
    if (n == 1) {
        c[0] = mul(a[0], b[0]);
        return;
    }
    for (int i = 0; i < n / 2; ++i) {
        int a0 = a[i], a1 = a[i + n / 2];
        a[i] = (a0 + a1) % mod;
        a[i + n / 2] = (a0 + mod - a1) % mod;

        int b0 = b[i], b1 = b[i + n / 2];
        b[i] = (b0 + b1) % mod;
        b[i + n / 2] = (b0 + mod - b1) % mod;
    }
    fast_product(n / 2, a, b, c);
    fast_product(n / 2, a + n / 2, b + n / 2, c + n / 2);
    for (int i = 0; i < n / 2; ++i) {
        int c0 = c[i], c1 = c[i + n / 2];
        c[i] = mul(c0 + c1, inv2);
        c[i + n / 2] = mul(c0 + mod - c1, inv2);
    }
}

void write(int *a) {
    for (int i = 0; i < (1 << n); ++i) {
        printf("%d ", a[i]);
    }
    puts("");
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < (1 << n); ++i) {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    sum = inv(sum);
    for (int i = 0; i < (1 << n); ++i) {
        a[i] = mul(a[i], sum);
    }
    a[0] = (a[0] + mod - 1) % mod;
    b[0] = (1 << n) - 1;
    for (int i = 1; i < (1 << n); ++i) {
        b[i] = mod - 1;
    }
    convolve<false>(1 << n, b);
    convolve<false>(1 << n, a);
    for (int i = 0; i < (1 << n); ++i) {
        ans[i] = mul(inv(a[i]), b[i]);
        ans[0] += mod - ans[i];
        ans[0] %= mod;
    }
    convolve<true>(1 << n, ans);
    for (int i = 0; i < (1 << n); ++i) {
        printf("%d\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 5888
#include <iostream>
using namespace std;
int main(void){
    int n, ans = 0, t, a, low, benefit[100000], bmax = 0;
    cin >> n >> t;
    for(int i=0;i<n;i++){
        cin >> a;
        if(i>0)low = min(low, a);
        else low = a;
        benefit[i] = a - low;
        bmax = max(bmax, benefit[i]);
    }
    for(int i=0;i<n;i++){
        if(benefit[i] == bmax)ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int n;
	cin>>n;
	long long int a[n],b[n],tt=0,i,j,k;
	for(j=0;j<=n-1;++j)
	{
		cin>>a[j];	
	}
	for(k=0;k<=n-1;++k)
	{
		cin>>b[k];
	}
	for(i=0;i<=n-1;++i)
	{
		if(a[i]-b[i]>0)
		{
			tt=tt+a[i]-b[i];
		}
	}
	cout<<tt;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
	char str[1000];
	int s,i,n;
	int sum;
	
	while(1){
	scanf("%s",str);
	if(str[0] == '0')
	break;
	sum = 0;
	
	for(n = 0;n < strlen(str);n++)
	
		
	sum += str[n] - '0';
	printf("%d\n",sum);
	}
	
	return 0;
}


Measured memory_bytes: 2108
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    sento = [[0 for i in range(10)] for i in range(10)]

    vs = [1, 10, 100, 1000, 10000, 100000]
    for i in range(1, n+1):
        m = i % 10
        for v in vs:

            if i // v < 10:

                s = i // v
                break
        # print(i, m, s)
        sento[m][s] += 1

    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            # print(i, j, sento[i][j], sento[j][i])
            ans += sento[i][j] * sento[j][i]
    print(ans)
    # print(sento)







if __name__ == '__main__':
    main()

Measured memory_bytes: 40300
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        sum += a;
    }
    if (sum > n) {
        cout << -1 << endl;
    } else {
        cout << n - sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
const int maxn = 1e5 + 5;
int a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    string a; cin >> a;
    char last = -1;
    int ans = 0;
    for (auto g : a){
        ans += (last != g);
        last = g;
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 3760
class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.prev = None
        self.next = None

class DoublyLinkedList(object):
    def __init__(self):
        self.first = Node()
        self.first.prev = self.first
        self.first.next = self.first

    def insert(self, key):
        x = Node(key)
        x.next = self.first.next
        self.first.next.prev = x
        self.first.next = x
        x.prev = self.first

    def search(self, key):
        cur = self.first.next
        while cur != self.first and cur.key != key:
            cur = cur.next

        return cur

    def delete(self, key):
        self.delete_node(self.search(key))

    def delete_node(self, node):
        if node == self.first:
            return
        else:
            node.prev.next = node.next
            node.next.prev = node.prev

    def delete_first(self):
        self.delete_node(self.first.next)

    def delete_last(self):
        self.delete_node(self.first.prev)


if __name__ == "__main__":
    import sys
    input = sys.stdin.readline # faster input

    linklist = DoublyLinkedList()

    n = int(input())

    for _ in range(n):
        inputs = input().rstrip()
        if inputs[0] == 'i':
            linklist.insert(inputs[7:])
        elif inputs[6] == 'F':
            linklist.delete_first()
        elif inputs[6] == 'L':
            linklist.delete_last()
        else:
            linklist.delete(inputs[7:])

    result = []
    cur = linklist.first.next
    while cur != linklist.first:
        result.append(cur.key)
        cur = cur.next

    print(' '.join(result))



Measured memory_bytes: 227800
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
int main() {
  int n; cin >> n;
  int flag = 0;
  for(int i = 0; i <= n; ++i) {
    int res = (int)(1.08 * i);
    //cout << i << "  " << res << endl;
    if(res == n) {
      printf("%d\n", i); 
      flag = 1;break;
    }
  }
  if(!flag) puts(":(");
  return 0;
} 

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

int main()
{
  int r,c;
  cin >> r >> c;
  int a[101][101]={};
  for(int i=0;i<r;i++)
    {
      for(int j=0;j<c;j++)
	{
	  cin >> a[i][j];
	}
    }

  for(int i=0;i<r;i++)
    {
      for(int j=0;j<c;j++)
	{
	  a[i][c]+=a[i][j];
	  a[r][j]+=a[i][j];
	}
    }
 
  for(int j=0;j<c;j++)
    {
      a[r][c]+=a[r][j];
    }

  for(int i=0;i<=r;i++)
    {
      for(int j=0;j<=c;j++)
	{
	  if(j!=c)
	    cout << a[i][j] << " ";
	  else
	    cout << a[i][j];
	}
      cout << endl;
    }

  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n;

int main(){
    cin >> n;
    vector<int> a(n);
    Rep(i,n){
        cin >> a[i];
        a[i]*=n;
    }
    int sum = 0;
    Rep(i,n){
        sum += a[i];
    }
    sum/=n;
    int res=0;
    int mi=INT_MAX;
    Rep(i,n){
        if(mi>abs(a[i]-sum)){
            mi = abs(a[i]-sum);
            res = i;
        }
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <climits>
#include <queue>
#include <algorithm>

using std::queue;
using std::min;

const int MAXX=1e7+5,MAXN=205;
int n,cnt_x,cnt_y;
int x_id[MAXN],y_id[MAXN];
bool up[MAXX];

struct node{int he,iter,dis;}d[MAXN];
struct line{int to,nex,cap;}ed[MAXN*MAXN<<1];

inline bool is_odd_prm(int x){
	if(x==1) return false;
	for(int i=2;i*i<=x;++i){
		if(x%i==0) return false;
	}
	return true;
}

inline void addE(int u,int v,int cap){
	static int cnt=1;
	ed[++cnt]=(line){v,d[u].he,cap};
	d[u].he=cnt;
}

inline int revE(int i){return i^1;}

inline bool BFS(int s,int t,int n){
	for(int i=1;i<=n;++i)
		d[i].dis=-1;
	static queue<int> q;
	d[s].dis=0;
	q.push(s);
	int u;
	while(q.size()){
		u=q.front();
		q.pop();
		for(int i=d[u].he,v;i;i=ed[i].nex){
			if(ed[i].cap==0) continue;
			v=ed[i].to;
			if(d[v].dis==-1){
				d[v].dis=d[u].dis+1;
				q.push(v);
			}
		}
	}
	return d[t].dis!=-1;
}

int aug(int u,int rest,const int t){
	if(u==t) return rest;
	int ret=0;
	for(int &i=d[u].iter,v,cap,flow;i;i=ed[i].nex){
		v=ed[i].to,cap=ed[i].cap;
		if(d[v].dis!=d[u].dis+1 || cap==0)
			continue;
		flow=aug(v,min(cap,rest),t);
		ed[i].cap-=flow,ed[revE(i)].cap+=flow;
		ret+=flow,rest-=flow;
		if(rest==0) return ret;
	}
	if(ret==0) d[u].dis=-1;
	return ret;
}

inline int Dinic(int s,int t,int n){
	int ret=0;
	while(BFS(s,t,n)){
		for(int i=1;i<=n;++i)
			d[i].iter=d[i].he;
		ret+=aug(s,INT_MAX,t);
	}
	return ret;
}

inline void build(){
	for(int i=1;i<=cnt_x;++i){
		for(int j=1,v;j<=cnt_y;++j){
			if(is_odd_prm(abs(x_id[i]-y_id[j]))){
				v=j+cnt_x;
				addE(i,v,INT_MAX),addE(v,i,0);
			}
		}
	}
	for(int i=1,s=cnt_x+cnt_y+1;i<=cnt_x;++i)
		addE(s,i,1),addE(i,s,0);
	for(int i=1,u,t=cnt_x+cnt_y+2;i<=cnt_y;++i){
		u=cnt_x+i;
		addE(u,t,1),addE(t,u,0);
	}
}

int main(){
	scanf("%d",&n);
	int x;
	for(int i=1;i<=n;++i){
		scanf("%d",&x);
		up[x]=true;
	}
	for(int i=1;i<=x+1;++i){
		if(up[i]!=up[i-1])
			i&1 ? x_id[++cnt_x]=i:y_id[++cnt_y]=i;
	}
	build();
	int k=Dinic(cnt_x+cnt_y+1,cnt_x+cnt_y+2,cnt_x+cnt_y+2);
	printf("%d",k+((cnt_x-k)/2+(cnt_y-k)/2)*2+3*((cnt_x-k)%2 && (cnt_y-k)%2));
	return 0;
}

Measured memory_bytes: 8576
ABCK = input().split()
A = int(ABCK[0])
B = int(ABCK[1])
C = int(ABCK[2])
K = int(ABCK[3])
ans = 0

if A >= K:
    ans = K
elif A + B >= K:
    ans = A
else:
    ans = 2*A + B - K

print(ans)


Measured memory_bytes: 9188
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int main() {

	int n,k,count=0;
	cin >>n>> k;
	vector<int>h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (h[i] >= k) {
			count++;
		}
	}
	cout << count << endl;


}

Measured memory_bytes: 640
class String
  def to_ia
    split(/\s/).map {|s| s.to_i}
  end
end
  
class Array
  def binary_search(val)
    left = 0
    right = size
    while left < right
      mid = (left + right) / 2
      if self[mid] == val
        return val
        #return mid
      elsif val < self[mid]
        right = mid
      else
        left = mid + 1
      end
    end
    nil
  end
end

STDIN.readline
subject = STDIN.readline.to_ia
STDIN.readline
search = STDIN.readline.to_ia

ans = 0
search.each do |v|
  ans += 1 unless subject.binary_search(v).nil?
end
puts ans

Measured memory_bytes: 17304
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int k, x;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> k >> x;

  cout << (k * 500 >= x ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 1e5+50;
const int inf = 1e9;

int a[maxn];

int main()
{
    //freopen("in", "r", stdin);
    int n;
    scanf("%d", &n);
    int cnt1 = 0, cnt4 = 0;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
        if (a[i] & 1) cnt1 ++;
        if (a[i] % 4 == 0) cnt4 ++;
    }
    bool ok = true;
    if (n & 1)
    {
        if (cnt4 + 1 < cnt1) ok = false;
    }
    else if (cnt4 < cnt1) ok = false;
    if (ok) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 640
package main

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

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInt() int {
  var x int
  x,_ = strconv.Atoi(NextLine())
  return x
}
func Next2Ints() (int,int) {
  var x,y int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  return x,y
}
func Next3Ints() (int,int,int) {
  var x,y,z int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  z,_ = strconv.Atoi(s[2])
  return x,y,z
}

var tree []Edges
var depth []int64

func main() {
  const infty int64 = 9223372036854775800
  var n int = NextInt()
  tree = make([]Edges,n)
  depth = make([]int64,n)
  for i:=0;i<n-1;i++ {
    var a,b,c int = Next3Ints()
    a,b = a-1,b-1
    tree[a] = append(tree[a],Edge{b,int64(c)})
    tree[b] = append(tree[b],Edge{a,int64(c)})
  }
  var q,k int = Next2Ints()
  k--
  dfs(k,-1,0)
  for i:=0;i<q;i++ {
    var x,y int = Next2Ints()
    x,y = x-1,y-1
    fmt.Println(depth[x]+depth[y])
  }
}

func dfs(v,p int,d int64) {
  depth[v] = d
  for _,e := range tree[v] {
    if e.to == p { continue }
    dfs(e.to,v,d+e.cost)
  }
}

type Edge struct {
  to int
  cost int64
}
type Edges []Edge

Measured memory_bytes: 43648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

ll gcd(ll i, ll j) { return i % j ? gcd(j, i % j) : j; }

int main() {
	
	int n, x;
	cin >> n >> x;
	int ans = 0;
	rep(i, n) {
		int y;
		cin >> y;
		ans = gcd(ans, abs(x - y));
	}
	cout << ans << endl;

}

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

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    ll ans = 0;
    for (auto& p : mp) {
        int s = p.second;
        ans += (ll)s*(s-1) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

	vector <vector<int>> v(10, vector<int>(10,0));
	
	long long int contador=0;
	int n, last, first=0, num;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		num=i;
		
		last=i%10;
		
		while (num>=10)
		{
			num= num/10;
		}
		first= num;
		
		if (first==last)
		{
			contador++;
		}

		
		contador+=2*(v[last][first]);
		v[first][last]++;
		
	
	}
	
	cout<<contador;
	
	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( void )
{
	int k;
	cin >> k;

	vector<ll> base;
	for ( int i = 1; i<= 9; ++i ) {
		base.emplace_back(i);
	}

	while ( true ) {
		if ( (size_t)k <= base.size() ) {
			cout << base[k - 1] << endl;
			return 0;
		}
		k -= base.size();

		vector<ll> next;
		for ( ll& x : base ) {
			for ( int i = -1; i <= 1; ++i ) {
				int d = x % 10 + i;
				if ( d < 0 || d > 9 ) {
					continue;
				}
				ll nx = x * 10 + d;
				next.emplace_back(nx);
			}
		}
		swap(base, next);
	}

	return 0;
}


Measured memory_bytes: 1712
mod = 10**9+7

n, m = gets.to_s.split.map{|t|t.to_i}
a = Array.new(m){ gets.to_s.to_i }

if n == 1
  puts 1
  exit
end

broken = Array.new(n+1){false}
stairs = Array.new(n+1){ 0 }
stairs[0] = stairs[1] = 1

a.each do |k|
  broken[k] = true
end

stairs[1] = 0 if broken[1]

2.upto(n) do |i|
  next if broken[i]
  stairs[i] = stairs[i-1] + stairs[i-2]
  stairs[i] %= mod if stairs[i] >= mod
end

puts stairs[-1]

Measured memory_bytes: 4348
// https://atcoder.jp/contests/abc174/tasks/abc174_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, D;
  cin >> N >> D;

  ll res = 0;

  rep(i, N) {
    ll x, y;
    cin >> x >> y;

    if (x * x + y * y <= D * D) res++;
  }

  cout << res << "\n";
}


Measured memory_bytes: 3644
n=int(input())
s=[1,2,3,4,5,6,7,8,9,10,11,12,13]
h=[1,2,3,4,5,6,7,8,9,10,11,12,13]
c=[1,2,3,4,5,6,7,8,9,10,11,12,13]
d=[1,2,3,4,5,6,7,8,9,10,11,12,13]

for i in range(n):
	x=input().split()
	if x[0]=='S':
		s.remove(int(x[1]))
	elif x[0]=='H':
		h.remove(int(x[1]))
	elif x[0]=='C':
		c.remove(int(x[1]))
	elif x[0]=='D':
		d.remove(int(x[1]))
s=sorted(s)
h=sorted(h)
c=sorted(c)
d=sorted(d)
for i in s:
	print('S',i)
for i in h:
	print('H',i)
for i in c:
	print('C',i)
for i in d:
	print('D',i)



Measured memory_bytes: 5616
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int a = sc.nextInt();
			final int b = sc.nextInt();
			
			if(a % 2 == 0 || b % 2 == 0) {
				System.out.println("No");
			}else {
				System.out.println("Yes");
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

int main()
{
    int n;
    cin>>n;
    int a[n][3], ans[n][3];
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    memset(ans,-1,sizeof(ans));
    for(int i=0;i<3;i++)
        ans[0][i]=a[0][i];
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(k!=j){
                    ans[i][k]=max(ans[i][k],a[i][k]+ans[i-1][j]);
                }
            }
        }
    }
    int ma=-1;
    for(int i=0;i<3;i++)
    {
        if(ma<ans[n-1][i])
        ma=ans[n-1][i];
    }
    cout<<ma<<endl;
    return 0;
}

Measured memory_bytes: 5892
let rec range m n = if m > n then [] else m :: range (m+1) n
let (>>=) xs f = List.map f xs |> List.concat

let solve n y =
  (range 0 n >>= fun a ->
   range 0 (n-a) >>= fun b ->
      if 10000*a + 5000*b + 1000*(n-a-b) = y then [a,b] else [])
  |> function
      | [] -> -1, -1, -1
      | (a, b)::_ -> a, b, n-a-b

let () =
  Scanf.scanf "%d %d\n" @@ fun n y ->
  let a,b,c = solve n y in
  Printf.printf "%d %d %d\n" a b c

Measured memory_bytes: 4992
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define endl "\n"
#define inf 1<<30
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ss stringstream
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define bit_cnt(mask) __builtin_popcount(mask)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1000000007; /// 1e9+7
const int MAX = 100005;     /// 1e5+5
ll bigmod(ll n, ll r)
{
    if(r==0) return 1;
    if(r==1) return n;
    if(r%2==0)
    {
        ll ret = bigmod(n, r/2);
        return ((ret%MOD) * (ret%MOD)) % MOD;
    }
    else return ((n%MOD) * (bigmod(n,r-1)%MOD)) % MOD;
}
ll modinverse(ll a){return bigmod(a,MOD-2)%MOD;}
ll lcm(ll a, ll b) {a=abs(a); b=abs(b); return (a/__gcd(a,b))*b;}
ll gcd(ll a, ll b) {a=abs(a); b=abs(b); if(!b) return a; return __gcd(b,a%b);}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]==5 and a[1]==5 and a[2]==7) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PI;

const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;

int g[2][maxn * 4];
int a[maxn],n,tot = 1;
struct node {
    P e;
    vector<int> c;
} q[maxn * 4];

void updata(int &x,int y) {
    if(a[x] > a[y]) x = y;
}

void add(int f[],int t,int l,int r,int x) {
    if(l == r) {
        f[t] = x;
        return;
    }
    int mid = (l + r) >> 1;
    if(x <= mid) add(f,t << 1,l,mid,x);
    else add(f,t << 1 | 1,mid + 1,r,x);
    updata(f[t],f[t << 1]);
    updata(f[t],f[t << 1 | 1]);
}

int ff(int f[],int t,int l,int r,int ll,int rr) {
    if(ll <= l && r <= rr) return f[t];
    int mid = (l + r) >> 1;
    int k = 0;
    if(ll <= mid) updata(k,ff(f,t << 1,l,mid,ll,rr));
    if(rr > mid) updata(k,ff(f,t << 1 | 1,mid + 1,r,ll,rr));
    return k;
}

void solve(int t,int l,int r) {
    int u,v;
    if(l & 1) u = 1,v = 0;
    else u = 0,v = 1;
    int x = ff(g[u],1,1,n,l,r);
    int y = ff(g[v],1,1,n,x + 1,r);
    q[t].e = P(a[x],a[y]);
    if(l < x) {
        q[t].c.push_back(++tot);
        solve(tot,l,x - 1);
    }
    if(x + 1 < y) {
        q[t].c.push_back(++tot);
        solve(tot,x + 1,y - 1);
    }
    if(y < r) {
        q[t].c.push_back(++tot);
        solve(tot,y + 1,r);
    }
}

priority_queue<PI,vector<PI>,greater<PI> > w;
vector<P> s;

int main() {
    int i;
    scanf("%d",&n);
    a[0] = mod;
    for(i = 1;i <= n; i++) {
        scanf("%d",&a[i]);
        if(i & 1) add(g[1],1,1,n,i);
        else add(g[0],1,1,n,i);
    }
    solve(1,1,n);
    w.push(PI(q[1].e,1));
    while(!w.empty()) {
        PI u = w.top();
        w.pop();
        s.push_back(u.first);
        int x = u.second;
        for(auto v:q[x].c) w.push(PI(q[v].e,v));
    }
    for(auto u:s) printf("%d %d ",u.first,u.second);
    return 0;
}


Measured memory_bytes: 44276
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N,A;cin>>N>>A;
  int64_t ans=N;
  for(int64_t i=1;i<=40;i++){
    double a=1;double b=i+1;
    a/=b;int64_t c=pow(N,a);
    int64_t d=pow(c,i+1);int64_t k=0;
    for(int64_t j=0;j<=i+1;j++){
    if(N<=d){k=c*(i+1)+j;break;}
      d/=c;d*=(c+1);
    }if(k+i*A<ans)ans=k+i*A;
    
  }cout<<ans<<endl;
  return 0;
}

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

using namespace std;

int main()
{
	string S, T;

	cin >> S >> T;

	if (S.size() >= T.size())
	{
		for (int i = 0; i <= S.size() - T.size(); i++)
		{
			if (T[0] == S[i])
			{
				if (T == S.substr(i, T.size()))
				{
					printf("%d\n", i);
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG



int main() {
  ll N, R;
  cin >> N >> R;
  
  if(N>=10){
    cout << R << endl;
  }else{
    cout << R + 100 * (10 - N) << endl;
  }


  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>

using namespace std;
#define ll long long
int K;

ll bfs(){
    queue<ll> q;
    for (int i=1; i<10; i++) q.push(i);
    int m = 0;
    while (!q.empty()){
        ll t = q.front(); q.pop();
        m++;
        if (m == K) return t;
        if (t%10>0) q.push(t*10+t%10-1);
        q.push(t*10+t%10);
        if (t%10<9) q.push(t*10+t%10+1);
    }
}

int main(){
    cin >> K;
    cout << bfs();
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    int sum = 0;
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
        sum += data[i];
    }

    map<int, int> yui;
    rep(i, n) {
        yui[data[i]]++;
    }
    
    Int(q);
    rep(i, q) {
        int2(a, b);
        int p = yui[a];
        sum -= p * a;
        sum += p * b;
        yui[a] = 0;
        yui[b] += p;
        cout << sum << endl;
    }

    return 0;
}


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

int main() {
    int n; cin >> n;
    long long back = 0, front = 0, maxv = 0;
    vector<int> a(n + 1); vector<int> A(n + 1);
    vector<int> b(n); vector<int> B(n);
    for (int i = 0; i < n + 1; i++)
    {
        cin >> a[i];
        A[i] = a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
        B[i] = b[i];
    }

    //後ろから
    for (int i = n - 1; i >= 0; i--)
    {
        if (a[i + 1] <= b[i])
        {
            b[i] -= a[i + 1];
            back += a[i + 1];
            a[i + 1] = 0;
            if (a[i] <= b[i])
            {
                b[i] -= a[i];
                back += a[i];
                a[i] = 0;
            }
            else
            {
                a[i] -= b[i];
                back += b[i];
                b[i] = 0;
            }
        }
        else
        {
            a[i] -= b[i];
            back += b[i];
            b[i] = 0;
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        if (A[i] <= B[i])
        {
            B[i] -= A[i];
            front += A[i];
            A[i] = 0;
            if (A[i + 1] <= B[i])
            {
                B[i] -= A[i + 1];
                front += A[i + 1];
                A[i + 1] = 0;
            }
            else
            {
                A[i + 1] -= B[i];
                front += B[i];
                B[i] = 0;
            }
            
        }
        else
        {
            A[i] -= B[i];
            front += B[i];
            B[i] = 0;
        }
        
        
    }
    maxv = max(front, back);
    cout << maxv << endl;
}

Measured memory_bytes: 1792
import sys
n = int(input())
b = [int(i) for i in input().split()]
if n == 2:
    print(b[0] * 2)
    sys.exit()

total = 0
for i, j in enumerate(b):
    if i == 0:
        total = j
    else:
        total += min(b[i-1], b[i])
print(total + b[-1])

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

using namespace std;

const int maxn = 305;

double dp[maxn][maxn][maxn];

int main()
{
    int n, x;
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x;
        if (x == 1){
            cnt1++;
        } else if (x == 2){
            cnt2++;
        }
        else {
            cnt3++;
        }
    }
    dp[0][0][0] = 0;
    for(int k = 0; k <= n; k++){
        for(int j = 0; j <= n; j++){
            for(int i = 0; i <= n; i++){
                if (i == 0 && j == 0 && k == 0){
                    continue;
                }
                if (i + j + k > n){
                    continue;
                }
                double t1 = 0, t2 = 0, t3 = 0;
                if (i){
                    t1 = i * dp[i - 1][j][k] / (1.0 * (i + j + k));
                }
                if (j){
                    t2 = j * dp[i + 1][j - 1][k] / (1.0 * (i + j + k));
                }
                if (k){
                    t3 = k * dp[i][j + 1][k - 1] / (1.0 * (i + j + k));
                }
                dp[i][j][k] += n / (1.0 * (i + j + k)) + t1 + t2 + t3;
            }
        }
    }
    printf("%.10lf", dp[cnt1][cnt2][cnt3]);

    return 0;
}


Measured memory_bytes: 219392
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

l = inputIL()

if l[0]==l[1]:
  print(l[2])
elif l[0]==l[2]:
  print(l[1])
else:
  print(l[0])


Measured memory_bytes: 63980
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<map>
#include<set>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=110;
ll a[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n);
    int res=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            for(int k=j+1;k<=n;k++)
            {
                if(a[i]==a[j]||a[i]==a[k]||a[j]==a[k]) continue;
                if(a[i]+a[j]>a[k]) res++;
            }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3636
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

l = [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]

K=one_int()

print(l[K-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll x,k,d;
	scanf("%lld %lld %lld",&x,&k,&d);
	if(x<0) x=-x;
	ll c1=x%d;
	ll cnt1=(x-c1)/d;
	ll c2=c1-d;
	ll cnt2=(x-c2)/d;
	if(abs(c1)<abs(c2)){
		if(cnt1>k){
			printf("%lld",x-k*d);
		}
		else{
			ll left=k-cnt1;
			if(left&1) printf("%lld",abs(c2));
			else printf("%lld",abs(c1));
		}
	}
	else{
		if(cnt2>k){
			printf("%lld",abs(x-k*d));
		}
		else{
			ll left=k-cnt2;
			if(left&1) printf("%lld",abs(c1));
			else printf("%lld",abs(c2));
		}
	}
	return 0;
}

Measured memory_bytes: 3828
#include <stdio.h>

int main(void)
{

    int A,B,C,D,tmp;
    
    scanf("%d %d %d %d",&A,&B,&C,&D);
    
    if(A<C){
        if(B<D){
            tmp=B-C;
        } else {
            tmp=D-C;
        }
    } else {
        if(B>D){
            tmp=D-A;
        } else {
            tmp=B-A;
        }
    }
    
    if(tmp > 0){
        printf("%d\n",tmp);
    } else {
        printf("0\n");
    }
    
    return 0;
}

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

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

    long long h[n+1];
    h[0]=0;
    long long ans=0;
    long long cost[n+1];
    cost[0]=0;


    for(int i=1;i<=n;i++)
        cin>>h[i];


     cost[1]=0;
     cost[2]=abs(h[2]-h[1]);


    for(int i=3;i<=n;i++){
         cost[i]=min((abs(h[i]-h[i-1])+cost[i-1]),(abs(h[i]-h[i-2])+cost[i-2]));
    }

    cout<<cost[n]<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;

int n;

char buf[20];
const char *C = "753";

int main(void) {
  cin >> n;
  int res = 0;
  for(int len = 3; len <= 9; ++len) {
    int nPat = 1;
    REP(i, len) {
      nPat *= 3;
    }
    REP(pat, nPat) {
      buf[len] = 0;
      int cur = pat;
      int flag = 0;
      REP(i, len) {
        buf[i] = C[cur%3];
        flag |= 1 << cur%3;
        cur /= 3;
      }
      if(flag != 7) {
        continue;
      }
      int v;
      sscanf(buf, "%d", &v);
      if(v <= n) {
        // cerr << ">" << v << endl;
        ++res;
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.lang.String;
import java.lang.reflect.Array;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;


public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
    int count =0;
        for(int i=0; i<=a; i++)
            for(int j=0; j<=b; j++)
                for (int u=0; u<=c; u++) {
            if(i*500+j*100+u*50==x) {count++;}
                }
    System.out.println(count);

    }

}

Measured memory_bytes: 21844
import math
[a,b,X] = list(map(int,input().split()))
h = (X/a)/a
S = h*a
if S < a*b/2:
    c = 2*S/b
    output = math.degrees(math.atan(b/c))
else:
    c = 2*S/a - b
    output = math.degrees(math.atan((b-c)/a))
print(output)


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

int main(){
	int c[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	int b12=c[0][1]-c[0][0];
	int b23=c[0][2]-c[0][1];
	int a12=c[1][0]-c[0][0];
	int a23=c[2][0]-c[1][0];
	bool flag=true;
	for(int i=1;i<3;i++){
		if(c[i][1]-c[i][0]!=b12 || c[i][2]-c[i][1]!=b23)flag=false;
		if(c[1][i]-c[0][i]!=a12 || c[2][i]-c[1][i]!=a23)flag=false;
	}
	string ans=flag?"Yes":"No";
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h> 
int main(void) 
{ 
int a,b;
    scanf("%d %d\n",&a,&b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 584
import sys, math
from functools import lru_cache
import numpy as np
import heapq
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def lcm(a, b):
    return a*b//math.gcd(a, b)


def main():
    N, A, B = mi()
    print(min(A, B), max(A+B-N, 0))



if __name__ == '__main__':
    main()


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

const int maxn = 200010;
int n, ans, a[maxn], b[maxn], c[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &b[i]);
    }
    for (int k = 0; k <= 28; k++) {
        for (int i = 1; i <= n; i++) {
            c[i] = b[i] & ((1 << (k + 1)) - 1);
        }
        sort(c + 1, c + n + 1);
        long long cnt = 0;
        for (int i = 1; i <= n; i++) {
            int d = a[i] & ((1 << (k + 1)) - 1);
            cnt += lower_bound(c + 1, c + n + 1, (2 << k) - d) - lower_bound(c + 1, c + n + 1, (1 << k) - d);
            cnt += lower_bound(c + 1, c + n + 1, (4 << k) - d) - lower_bound(c + 1, c + n + 1, (3 << k) - d);
        }
        if (cnt & 1) {
            ans |= (1 << k);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2560
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    snack = [0]*n
    for i in range(k):
        d = int(input())
        a = [int(x) for x in input().split()]
        for j in range(d):

            snack[a[j] - 1] += 1
    print(snack.count(0))


if __name__ == '__main__':
    main()

Measured memory_bytes: 27140
#include <bits/stdc++.h>
#define MAX_N 100000
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, m, a[MAX_N+5], fa[MAX_N+5];
int getf(int x) {return fa[x] == x ? x : fa[x] = getf(fa[x]);}
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int i = 1; i <= n; i++) read(a[i]);
	for (int i = 1; i <= m; i++) {
		int u, v; read(u), read(v);
		u = getf(u), v = getf(v);
		if (u ^ v) fa[u] = v;
	}
	int tot = 0;
	for (int i = 1; i <= n; i++)
		tot += getf(i) == getf(a[i]);
	return printf("%d\n", tot), 0;
}


Measured memory_bytes: 1024