akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
using namespace std;

#define eps 1e-8
#define mod 1000000007
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;

int n;
vector<int> x, y, p, q;

int root(int node) {
    return node == p[node] ? node : (p[node] = root(p[node]));
}

auto cmp = [](pair<int, pii> a, pair<int, pii> b){return a.first > b.first;};

priority_queue<pair<int, pii>, vector<pair<int, pii>>, decltype(cmp)> pq(cmp);

int main() {
    cin >> n;
    x.resize(n), y.resize(n), p.resize(n), q.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        p[i] = q[i] = i;
    }
    sort(all(q), [](int a, int b){return x[a] < x[b];});
    for (int i = 1; i < n; ++i) {
        pq.push({x[q[i]] - x[q[i - 1]], {q[i], q[i - 1]}});
    }
    sort(all(q), [](int a, int b){return y[a] < y[b];});
    for (int i = 1; i < n; ++i) {
        pq.push({y[q[i]] - y[q[i - 1]], {q[i], q[i - 1]}});
    }
    ll res = 0;
    int cnt = n;
    while (cnt > 1) {
        auto item = pq.top();
        pq.pop();
        int roota = root(item.second.first), rootb = root(item.second.second);
        if (roota == rootb) continue;
        res += item.first;
        --cnt;
        p[roota] = rootb;
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(abs(A-C) <= D){
  	cout << "Yes" << endl;
  }else{
  	if(abs(A-B) <= D && abs(B-C) <= D){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const int MOD=1e8;
const int N=1e5+5;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
ll n,m;
ll fa[N],val[N];
///fa[i] 表示i的根节点
ll Find(ll x)///递归找根结点  并计算权值
{
    if(fa[x]==-1) return x;///fa[x]==-1 表示该节点无父节点
    ll root=Find(fa[x]);
    val[x]+=val[fa[x]];
   // cout<<"x="<<x<<"  root="<<root<<endl;
    return fa[x]=root;
}
int main()
{
    //fre;
    IO;
    while(cin>>n>>m)
    {
        mem(fa,-1);
        rep(i,1,m+1)
        {
            ll u,v,w;
            cin>>u>>v>>w;
            ll tmp1=Find(u);
            ll tmp2=Find(v);
         //   cout<<"tmp1="<<tmp1<<"  tmp2="<<tmp2<<endl;
            if(tmp1!=tmp2)
            {
                val[tmp1]=val[v]-w-val[u];
                fa[tmp1]=tmp2;///u的根节点置为 v的根节点
            }
            else if(val[v]-val[u]!=w)///不满足题意
            {
                cout<<"No\n";
                return 0;
            }
        }
        cout<<"Yes\n";
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
vector<pair<int,int> >v[16];
int main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		int a;cin>>a;
		for(int j=0;j<a;j++){
			int x;char y;cin>>x>>y;
			v[i].push_back({x,y});
		}
	}
	int ans=0;
	int k=(1<<n);
	for(int i=0;i<k;i++){
		int tmp=i;
		string s="";
		int cnt=0;
		while(tmp){
			if(tmp%2){s+='1';cnt++;}
			else s+='0';
			tmp/=2;
		}
		while(s.length()<n)s+='0';
		bool hnhn=false;
		for(int j=0;j<s.length();j++){
			bool t=false;
			if(s[j]=='1'){
				for(auto u:v[j+1]){
					if(s[u.first-1]!=u.second){
						t=true;
						break;
					}
				}
			}
			if(t){hnhn=true;break;}
		}
		if(!hnhn){
			ans=max(ans,cnt);
		}
	}
	cout<<ans;
	return 0;
}

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

#define eb emplace_back
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define ll long long

const int N = 1e6 + 9;
const int INF = 1e9 + 9;

#define int ll

void solve() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    for (int i = 0; i < n; ++ i) {
    	ll m1 = a + c * i - d * (n - 1 - i);
    	ll m2 = a + d * i - c * (n - 1 - i);
    	if (m1 <= b and b <= m2) {
    		cout << "YES\n";
    		return;
    	}
    }
    cout << "NO";
}

main () {
	solve();
	return 0;
}

Measured memory_bytes: 256
n=parse(Int,readline())

an=readline()
an1=split(an)
X=Any[]
for i=1:n+1
    X= push!(X , parse(Int,an1[i]))
end

bn=readline()
bn1=split(bn)
Y=Any[]
for i=1:n
    Y= push!(Y , parse(Int,bn1[i]))
end




k=0

for i=1:n
    if X[i]<Y[i]
        k=k+X[i]
        Y[i]=Y[i]-X[i]
        if X[i+1]<Y[i]
            k=k+X[i+1]
      		X[i+1]=X[i+1]-X[i+1]
        else
            k=k+Y[i]
      		X[i+1]=X[i+1]-Y[i]
        end
    else
        k=k+Y[i]
    end
end
print(k)

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

const long MOD = 1e9 + 7;
const int MAX_N = 1000;

bool isprime(int x) {
  if (x == 2) return true;
  if (x % 2 == 0) return false;
  int i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0) return false;
    i += 2;
  }
  return true;
}

main() {
  int N, pos, prime[MAX_N + 1], prime_cnt[MAX_N + 1];
  long ans;
  cin >> N;
  pos = 0;
  REP(i, N + 1) {
    if (i < 2) continue;
    if (isprime(i)) prime[pos++] = i;
  }
  ans = 1;
  REP(i, pos) prime_cnt[i] = 0;
  REP(i, N + 1) {
    int tmp, j;
    if (i == 0) continue;
    tmp = i;
    j = 0;
    while (tmp != 1 && j < pos) {
      if (tmp % prime[j]) {
        j++;
        continue;
      }
      tmp /= prime[j];
      prime_cnt[j]++;
    }
  }
  REP(j, pos) ans = (ans * ++prime_cnt[j]) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int compare_long(const void *a, const void *b){
	long *A = (long*)a;
	long *B = (long*)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;
	return 0;
}
int main(){
	int x,y,z,k;
	scanf("%ld %ld %ld %ld",&x,&y,&z,&k);
	long* a = (long*)malloc(x*sizeof(long));
	long* b = (long*)malloc(y*sizeof(long));
	long* c = (long*)malloc(z*sizeof(long));
	long* ab = (long*)malloc(x*y*sizeof(long));
	long* abc = (long*)malloc(k*z*sizeof(long));
	int i,j;
	for(i=0;i<x;i++)	scanf("%ld",&a[i]);
	for(i=0;i<y;i++)	scanf("%ld",&b[i]);
	for(i=0;i<z;i++)	scanf("%ld",&c[i]);
	for(i=0;i<x;i++){
		for(j=0;j<y;j++){
			ab[i*y+j] = a[i] + b[j];
		} 
	}
	long xy = x*y;
	qsort(ab,xy,sizeof(long),compare_long);
	int sub = (xy <= k)? xy:k;
	for(i=0;i<sub;i++){
		for(j=0;j<z;j++){
			abc[i*z+j] = ab[i] + c[j];
		}
	}
	qsort(abc,k*z,sizeof(long),compare_long);
	for(i=0;i<k;i++)	printf("%ld\n",abc[i]);
	free(a);
	free(b);
	free(c);
	free(ab);
	free(abc);
	return 0;

}


Measured memory_bytes: 54920
def sc(k):
	a = 0
	for c in str(k):
		a += int(c)
	return a

def mx(k):
	n = len(k);
	if k[0] == '1':
		return '9' * (n - 1)
	return chr(ord(k[0]) - 1) + '9' * (n - 1)

n = input()


print(max(sc(n), sc(mx(n))))



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

struct Edge {
    int to;
    int d;
};

const int MAX_PERSONS = 100010;

vector<Edge> graph[MAX_PERSONS];
int positions[MAX_PERSONS];
int visited[MAX_PERSONS];

void dfs(int vertex) {
    visited[vertex] = true;
    for (int j = 0; j < graph[vertex].size(); ++j) {
        int to = graph[vertex][j].to;
        if (!visited[to]) {
            // Update position.
            positions[to] = positions[vertex] + graph[vertex][j].d;
            dfs(to);
        }
    }
}

void solve() {
    int N, M;
    cin >> N;
    cin >> M;
    for (int i = 0; i < MAX_PERSONS; ++i) {
        graph[i].clear();
    }
    memset(visited, 0, sizeof(visited));
    memset(positions, 0, sizeof(positions));
    for (int i = 0; i < M; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        graph[l - 1].push_back({r - 1, d});
        graph[r - 1].push_back({l - 1, -d});
    }

    // Populate positions with DFS.
    positions[0] = 0;
    for (int i = 0; i < N; ++i) {
        dfs(i);
    }

    // Check whether positions satisfy all edges.
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < graph[i].size(); ++j) {
            int person_from = i;
            int person_to = graph[i][j].to;
            int correct_distance = graph[i][j].d;
            if (positions[person_to] - positions[person_from] != correct_distance) {
                cout << "No" << endl;
                return;
            }
        }

    }
    cout << "Yes" << endl;
}

int main() {
    solve();
}


Measured memory_bytes: 12416
from itertools import permutations

def readinput():
    n=int(input())
    P=tuple(map(int,input().split()))
    Q=tuple(map(int,input().split()))
    return n,P,Q

def main(n,P,Q):
    permlist=permutations(range(1,n+1))
    sortedList=sorted(permlist)
    #print(sortedList)
    np=sortedList.index(P)
    nq=sortedList.index(Q)
    return abs(np-nq)

if __name__=='__main__':
    n,P,Q=readinput()
    ans=main(n,P,Q)
    print(ans)


Measured memory_bytes: 8052
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long A, B;
  cin >> A >> B;
  long ans = A + B;
  ans = max(ans, A - B);
  ans = max(ans, A * B);
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
public class Main {
	
	public void run(java.util.Scanner sc, java.io.PrintStream out) {
		for (;;) {
			final int m = sc.nextInt();
			int n = sc.nextInt();
			if (m == 0 && n == 0) break ;
			final boolean[] d = new boolean[7368792];
			for (int i = m; ; ++i) {
				if (d[i]) continue ;
				if (n == 0) {
					out.println(i);
					break ;
				}
				for (int j = i; j < d.length; j += i)
					d[j] = true;
				n -= 1;
			}
		}
	}

	public static void main(String[] args) {
		(new Main()).run(new java.util.Scanner(System.in), System.out);
	}

}

Measured memory_bytes: 58368
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string n;;
	cin >> n;

	for(int i=0;i<3;i++){
		if(n.at(i)=='1') n.at(i) = '9';
		else if(n.at(i)=='9') n.at(i) = '1';
	}
	cout << n << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	static long count = 0;
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int M = fs.nextInt();
		int[] temp = new int[M + 1];
		for(int i = 1;i <= M;i++) {
			int d = fs.nextInt();
			long c = fs.nextLong();
			temp[i] = myFunc(d, c);
		}

		int ret = temp[1];
		for(int i = 2;i <= M;i++) {
			ret += temp[i];
			count++;
			if(ret >= 10) {
				ret = ret / 10 + ret % 10;
				count++;
			}
		}
		System.out.println(count);

	}

	private static int myFunc(int d, long c) {
		if(c == 1) {
			return d;
		}
		if (c % 2 == 0) {
			int d2 = d * 2;
			int flag = 0;
			if (d >= 5) {
				d2 = d2 / 10 + d2 % 10;
				flag = 1;
			}
			count += c / 2 * (flag + 1);
			return myFunc(d2, c / 2);
		} else {
			int d2 = d + myFunc(d, c - 1);
			count++;
			if (d2 >= 10) {
				d2 = d2 / 10 + d2 % 10;
				count++;
			}
			return d2;
		}
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


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

void func();

int main(){
    func();
}

//B問題までは数学的知識をほとんど要求されない
//数学的考察とともに、素直な全探索を模索する方が早い

void func(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    
    int ans = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(500*i+100*j+50*k == x){
                    ans++;
                    //cout << i << "," << j << "," << k << "\n";
                }
            }
        }
    }
    cout << ans <<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))

//POWER FUNCTION

ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return ((temp)*(temp));
    else
        return (x*(temp)*(temp));
}
int main()
{
    cr7
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    ll x;
    cin >> x;
    ll a = 1;
    while(1){
        for(ll b = a-1; b >= -a; --b){
            if(power(a, 5) - power(b, 5) == x){
                cout << a <<" " << b <<"\n";
                return 0;
            }
        }
        a++;
    }
    return 0;
}

//OUTPUT

/*

*/

Measured memory_bytes: 3640
n = gets.to_i
g = []
n.times do
  s = gets.chomp.chars
  h = Hash.new(0)
  s.each do |x|
    h[x] += 1
  end
  g.push(h)
end
#puts "#{g}"
f = Hash.new(0)
g.each do |x|
  x.each_entry do |k, v|
    f[k] += v
  end
end
f = f.sort_by{|k, v| k}
#puts  "#{f}"
ans = ""
f.each_entry do |k, v|
  c = g.map{|hash| hash[k]}.min
  ans.concat(k * c) if c > 0
#  puts "k=#{k} c=#{c}"
end
puts ans

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

int main() {
  int N, M, i;
  cin >> N;

  map<string, int> m{};

  string card;
  for (i=0; i<N; i++) {
    cin >> card;
    if (0 < m.count(card)) m[card]++;
    else m[card]=1;
  }

  cin >> M;

  for (i=0; i<M; i++) {
    cin >> card;
    if (0 < m.count(card)) m[card]--;
    else m[card]=-1;
  }

  int max = 0;
  for (auto it : m) {
    if (max < it.second) max = it.second;
  }

  cout << max << endl;

  return 0;
}


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

int main(){

    vector<int> a;
    vector<int> b;

    string s;
    string t;

    cin >> s >> t;
    for(int i=0; i<s.length(); i++){
        a.push_back(s[i]);
    }
    for(int i=0; i<t.length(); i++){
        b.push_back(t[i]);
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), std::greater<int>());

    int pointer = 0;

    while(pointer < a.size() && pointer < b.size()){
        if(a[pointer] == b[pointer]){
            pointer ++;
        }else if(a[pointer] < b[pointer]){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }

    if(a.size() < b.size()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 1000 + 10;

int n, m;
char g[N][N];
bool vis[N][N];

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


int32_t main(){_

   cin>>n>>m;

   queue<P> q;
   for (int i = 1; i <= n; ++i)
   {
      for (int j = 1; j <= m; ++j)
      {
         cin>>g[i][j];
         if(g[i][j] == '#'){
            q.push({i, j});
         }
      }
   }

   int ans = 0;
   queue<P> tmp;

   while(1){
      if(q.empty()){
         if(tmp.empty())
            break;
         swap(q, tmp);
         ans++;
      }
      auto it = q.front();
      q.pop();
      int X = it.F, Y = it.S;
      if(X < 1 or Y < 1 or X > n or Y > m)continue;
      if(vis[X][Y])continue;
      vis[X][Y] = 1;
      vector<P> v;
      for (int i = 0; i < 4; ++i)
      {
         int nX = it.F + dx[i], nY = it.S + dy[i];
         if(nX < 1 or nY < 1 or nX > n or nY > m)continue;
         if(vis[nX][nY] or g[nX][nY] == '#')continue;
         g[nX][nY] = '#';
         tmp.push({nX, nY});
      }
   }

   cout<<ans;
   return 0;
}

// Common sense: do smth instead of nothing
// Even a single second counts...
// If other's can do it, even I can do it. It wouldn't be that tough. Let me give it a try.
// Mistakes made in past
// -Ques. ask for max-min => think binary_search, DP, greedy
// -not reading question properly / skipping to read & understand all samples properly & wasting time in wrong direction.
// -Using wrong indexing in nested loops something like a[i], when it is supposed to be a[j](WA)
// -value of const int N is not correct (WA/RTE).
// -Did you memset dp to -1 ?
// -check for small edges cases and work on small test cases manually if WA
// -not deallocating memory to pointers can lead to MLE. Use delete :))
// -not reading problem statements of harder problems E,..., thinking it couldn't be solved, but it isn't the case.
// -Avoid using #define int long long as much as possible when it's dp problem and requires high memory say, O(N^2, N=5000) (MLE)
// -Check Bitwise Operator Precedence 
// -Use pragmas to optimize (by constant factor) when necessary..
// -Think before coding & starting to debug. Have patience to look inside code and actually see how it works

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;cin>>n;
    vector<ll>a(n),b(n),c(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)cin>>c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));

    ll ans = 0;

    for(int i = 0;i<n;i++)
    {
		ans+=(ll)(lower_bound(all(a),b[i])-a.begin())*(n-(upper_bound(all(c),b[i])-c.begin()));
    }


    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<long long int> Prime;
    Prime.emplace_back(2);
    for (int i=3;i<=2000000;i+=2) {
        int flag=0;
        double SqrtNum=sqrt(i);
        for (int j=3;j<=SqrtNum;j+=2) {
            if (i%j==0) {
                flag=1;
                break;
            }
        }
        if (flag==0) {
            Prime.emplace_back(i);
        }
    }
    int n,p;
    while (cin>>n>>p) {
        if (n==-1&&p==-1) {
            break;
        }
        std::deque<long long int> sum;
        auto itr=upper_bound(Prime.begin(),Prime.end(),n);
        for (auto itr1=itr;itr1!=itr+100;itr1++) {
            for (auto itr2=itr1;itr2!=itr+100;itr2++) {
                sum.emplace_back(*itr1+*itr2);
            }
        }
        sort(sum.begin(),sum.end());
        cout<<sum[p-1]<<endl;
    }
}


Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int a[2];
int main(){
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]=='a')
a[0]++;
if(s[i]=='b')
a[1]++;
if(s[i]=='c')
a[2]++;
}
if(a[0]==1&&a[1]==1&&a[2]==1)
cout<<"Yes";
else
cout<<"No";
system("pause");
return 0;
}

Measured memory_bytes: 504
#include <iostream>

using namespace std;
void printArray(const int *A, int N){
    for(int i=0; i<N-1; i++){
        cout << A[i] << " ";
    }
    cout << A[N-1] << endl;
}

void selectionSort(int *A, int N){
  int count = 0;
  for(int i=0; i<N; i++){
    int minj = i;
    for(int j=i; j<N; j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }
    if(minj != i){
      swap(A[i], A[minj]);
      count ++;
    }
  }
  printArray(A, N);
  cout << count << endl;
}

int main(){
    int x;
    cin >> x;
    int* A = new int[x];
    for(int i=0; i<x; i++){
        cin >> A[i];
    }
    selectionSort(A, x);
    delete A;
}


Measured memory_bytes: 3092
use proconio::input;

#[macro_export]
macro_rules! make_vec{
    ( $val:expr , $head:expr)=>{
        vec![$val;$head]
    };
    ( $val:expr , $head:expr , $($tail:expr),+ )=>{
        vec![make_vec!($val,$($tail),+);$head]
    };
}

#[macro_export]
macro_rules! access{
    ($v:expr,$tail:expr)=>{
        $v[$tail]
    };
    ($v:expr,$tail:expr,)=>{
        $v[$tail]
    };
    ($v:expr,$($r:expr),+,$tail:expr)=>{
        access!($v,$($r),+)[$tail]
    };
}
#[macro_export]
macro_rules! make_type_vec{
    ($v:ty,$tail:expr)=>{
        Vec<$v>
    };
    ($v:ty,$tail:expr,)=>{
        Vec<$v>
    };
    ($v:ty,$($r:expr),+,$tail:expr)=>{
        Vec<make_type_vec!($v,$($r),+)>
    };
}
#[macro_export]
macro_rules! access_local{
    ($v:expr,$($r:expr),+)=>{
        v.with()
    };
}
#[macro_export]
macro_rules! memoized{
    (fn $func:tt ($($val:tt [$r:expr]:$typ:ty),*)->$ret:ty{$($t:tt)*} ( $($st:expr),* );)=>{
        {
            use std::cell::RefCell;
            fn $func($($val : $typ),*)->$ret{
                thread_local! {
                    pub static MEMO :RefCell<make_type_vec!(Option<$ret>,$($r),*)>= RefCell::new(make_vec!(None,$($r),*));
                }                
                let __function__=|$($val : $typ),*|->$ret {$($t)*};
                
                if MEMO.with(|v|access!(v.borrow(),$($val),*).is_none()){
                    MEMO.with(|v|access!(v.borrow_mut(),$($val),*)=Some(__function__($($val),*)));
                }
                MEMO.with(|v|access!(v.borrow(),$($val),*).clone()).unwrap()
            }
            $func($($st),*)
        }
    };
    (fn $func:tt ($($val:tt [$r:expr]:$typ:ty),*)[$($cap_val:tt : $cap_typ:ty),*]->$ret:ty{$($t:tt)*} $func2:tt( $($st:expr),* );)=>{
        {
            use std::cell::RefCell;
            assert!(stringify!($func)==stringify!($func2));
            fn $func($($val : $typ),*,$($cap_val:$cap_typ),*)->$ret{
                thread_local! {
                    pub static MEMO :RefCell<make_type_vec!(Option<$ret>,$($r),*)>= RefCell::new(make_vec!(None,$($r),*));
                }                
                let __function__=|$($val : $typ),*,$($cap_val:$cap_typ),*|->$ret {$($t)*};
                
                if MEMO.with(|v|access!(v.borrow(),$($val),*).is_none()){
                    MEMO.with(|v|access!(v.borrow_mut(),$($val),*)=Some(__function__($($val),*,$($cap_val),*)));
                }
                MEMO.with(|v|access!(v.borrow(),$($val),*).clone()).unwrap()
            }
            $func($($st),*)
        }
    };
}

fn main() {
    input!{
        n:usize,
        v:[i64;n],
    }
    let ans=memoized!(
        fn f(now[100001]:usize)[v:&Vec<i64>]->usize{
            if now>=2 {
                (f(now-1,v)+(v[now]-v[now-1]).abs()as usize).min(f(now-2,v)+(v[now]-v[now-2]).abs()as usize)
            }else if now==1{
                f(now-1,v)+(v[now]-v[now-1]).abs()as usize
            }else{
                0
            }
        }
        f(n-1,&v);
    );
    println!("{}",ans);
}

Measured memory_bytes: 18992
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int sum = 0;
		
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < K; i++) {
            int d = sc.nextInt();
			a.add(d);
		}
		Collections.sort(a,Collections.reverseOrder());	
		
		for(int i=0; i<a.size();i++)
		{
			sum += (Math.pow((-1),(i)))*(a.get(i));
		}
		System.out.println(sum);
   
        }
		
	}

Measured memory_bytes: 36080
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(){
  int n,x,y; cin >> n >> x >> y;
  x--; y--;
  ll d[n][n];
  ll ans[n] = {};
  rep(i,n){
    for(int j = i+1; j < n; j++){
      d[i][j] = min(j-i, abs(x-i)+1+abs(y-j));
      ans[d[i][j]-1]++;
      //cout << d[i][j] << " ";
    }
    //cout << "\n";
  }
  rep(i,n-1){
    cout << ans[i] << "\n";
  }
}

Measured memory_bytes: 31104
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;
typedef pair<int,int> pii;

vector<int> ans(100100);

// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b; // aをbで更新
return true;
}
return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b; // aをbで更新
return true;
}
return false;
}

int selectmin(int h, vector<pii> &data, int n){
	int mn = INT_MAX;
  	rep(i,n) {
      	if(h>=data[i].first){
      		chmin(mn, ans[h-data[i].first] + data[i].second);
        }
      	else{
        	chmin(mn, data[i].second);
        }
    }
  	return mn;
}

void Main()
{
	ll h,n;
  	cin >> h >> n;
  	int a, b;
  	vector<pii> data(n);
  	rep(i,n) {
    	cin >> a >> b;
    	data[i] = make_pair(a,b);
  	}

  	ans[0] = 0;
	rep3(i,1,h){
  		ans[i] = selectmin(i, data, n);
  	}
	cout << ans[h] << endl;
 	return;
}


int main()
{
 cin.tie(nullptr);
 ios_base::sync_with_stdio(false);
 cout << fixed << setprecision(15);
 Main();
 return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

bool operator<(tuple<int, int> &l, tuple<int, int> &r)
{
  return (get<0>(l) == get<0>(r)
          ? get<1>(l) < get<1>(r)
          : get<0>(l) < get<0>(r));
}

bool byYX(tuple<int, int> &l, tuple<int, int> &r)
{
  return (get<1>(l) == get<1>(r)
          ? get<0>(l) < get<0>(r)
          : get<1>(l) < get<1>(r));
}

int main(void)
{
  int n;
  cin >> n;
  vector<tuple<int, int>> vab, vcd;
  REP(i,n) {
    int x, y;
    cin >> x >> y;
    vab.push_back(make_tuple(x,y));
  }
  REP(i,n) {
    int x, y;
    cin >> x >> y;
    vcd.push_back(make_tuple(x,y));
  }
  sort(vab.begin(), vab.end(), byYX);
  sort(vcd.begin(), vcd.end(), byYX);
  set<tuple<int,int>> q;
  int j = 0;
  int answer = 0;
  REP(i, n){
    while(j<n && byYX(vab[j], vcd[i])){
      q.insert(vab[j]);
      ++j;
    }
    auto ite = q.upper_bound(vcd[i]);
    if(ite == q.begin()) continue;
    q.erase(--ite);
    ++answer;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <functional>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>

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

    std::cin >> a >> b >> c;

    if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
        std::cout << 0 << std::endl;

        return 0;
    }

    long long  n[3] = {a, b, c};
    
    std::sort(n, n + 3);

    std::cout << n[0] * n[1] << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
    char s[101];
    scanf("%s",s);
    int l=strlen(s);
    for(int i=0;i<l;i++){
        if((i%2==0&&s[i]=='L')||(i%2==1&&s[i]=='R')){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#define Inf 5000000000000000

int main(){
    char s[101];
    int k;
    scanf("%s\n%d",s,&k);
    int a;
    unsigned long long count = 0;
    for(int i = 0; s[i] != '\0'; i++){
        a = s[i] - 48;
        if(a == 1){
            count++;
            if(count == k){
                printf("%d\n",a);

                return 0;
            }
            continue;
        }else{
            for(unsigned long long j = 1; j <= Inf; j++){
                if(count + pow(a,j) >= k){
                    printf("%d\n",a);

                    return 0;
                }
            }
            count += pow(a,Inf);
        }
    }

    return 0;
}

Measured memory_bytes: 256
class Union_Find():
    def __init__(self,N):
        """0,1,...,n-1を要素として初期化する.

        n:要素数
        """
        self.n=N
        self.parents=[-1]*N
        self.rank=[0]*N

    def find(self, x):
        """要素xの属している族を調べる.

        x:要素
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """要素x,yを同一視する.

        x,y:要素
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x]>self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y

            if self.rank[x]==self.rank[y]:
                self.rank[y]+=1

    def size(self, x):
        """要素xの属している要素の数.

        x:要素
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x,yは同一視されているか?

        x,y:要素
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属している族の要素.
        ※族の要素の個数が欲しいときはsizeを使うこと!!

        x:要素
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """族の名前のリスト
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """族の個数
        """
        return len(self.roots())

    def all_group_members(self):
        """全ての族の出力
        """
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

#====================================================================
N,K=map(int,input().split())
P=["*"]+list(map(int,input().split()))
C=["*"]+list(map(int,input().split()))

U=Union_Find(N+1)

for i in range(1,N+1):
    U.union(i,P[i])

Cycle_Point={}
for a in U.roots():
    if a==0:
        continue

    b=P[a]
    S=C[a]
    while a!=b:
        S+=C[b]
        b=P[b]
    Cycle_Point[a]=S

Ans=-float("inf")

for x in range(1,N+1):
    group=U.find(x)
    Round_Point=Cycle_Point[group]
    cycle_size=U.size(x)

    rap,remain=divmod(K,cycle_size)

    if rap==0:
        Temp_Score=0
        Score=C[P[x]]

        p=x
        for _ in range(min(cycle_size,K)):
            p=P[p]
            Temp_Score+=C[p]
            Score=max(Score,Temp_Score)
    elif Round_Point>0:
        p=x
        L=[0]*(cycle_size+1)

        Temp_Score=0
        for k in range(cycle_size):
            p=P[p]
            Temp_Score+=C[p]
            L[k+1]=Temp_Score

        alpha=Round_Point*rap+max(L[:remain+1])
        beta=Round_Point*(rap-1)+max(L)
        Score=max(alpha,beta)

    else:
        Temp_Score=0
        Score=C[P[x]]

        p=x
        for _ in range(min(cycle_size,K)):
            p=P[p]
            Temp_Score+=C[p]
            Score=max(Score,Temp_Score)


    Ans=max(Ans,Score)
    assert 1

print(Ans)

Measured memory_bytes: 72760
program main
	implicit none
	integer x,a,b,aa,bb
	read(*,*)x,a,b
	aa=abs(x-a)
	bb=abs(x-b)
	if(aa>bb)then
		write(*,'(a1)')"B"
	else
		write(*,'(a1)')"A"
	endif
end program main

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int in[100][2];
	char op[100];
	int ans[100], i;
	for (i = 0; i < 100; i++) {
		scanf("%d %s %d", &in[i][1], &op[i], &in[i][2]);
		if (op[i] == '?')break;
	}
	for (int j = 0; j < i; j++) {
		if (op[j] == '+') ans[j] = in[j][1] + in[j][2];
		else if (op[j] == '-') ans[j] = in[j][1] - in[j][2];
		else if (op[j] == '*') ans[j] = in[j][1] * in[j][2];
		else if (op[j] =='/') (int)(ans[j] = in[j][1] / in[j][2]);
		printf("%d\n", ans[j]);
	}

	return 0;
}


Measured memory_bytes: 2616
a = int(input())
b = input()
c = {}
for i in range(a):
    if b[i] not in c:
        c[b[i]] = 1
    else:
        c[b[i]] += 1
d = 1
for k in c.keys():
    d = (d * (c[k] + 1)) % (10 ** 9 + 7)
print(d - 1)


Measured memory_bytes: 3188
import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline

n=int(input())

#初期値が0の辞書
from collections import defaultdict
tree = defaultdict(lambda: set([])) 

color={}
key=[]

for _ in range(n-1):
    a,b=map(int,input().split())
    tree[a-1].add(b-1)
    tree[b-1].add(a-1)
    color[(a-1,b-1)]=0
    key.append((a-1,b-1))

checked=[0]*n
cnt=0

def DEF(parent_color,node_no):
    global color,checked,tree,cnt
    checked[node_no]=1
    cnt=max(cnt,parent_color)
    i=1
    #print("node_no",node_no)
    for item in tree[node_no]:
        if checked[item]==0:
            if i==parent_color:
                i+=1
            
            color[(min(item,node_no),max(item,node_no))]=i
            DEF(i,item)
            i+=1
DEF(0,1)

print(cnt)
for item in key:
    print(color[item])

        








Measured memory_bytes: 96216
#include<bits/stdc++.h>
#include<vector>
#define ll long long
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi=acos(-1); 
const double eps=1e-6;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
const ll mod=1e9+7;
#define maxn 300005
int main()
{
	char n[200005];
	mem(n);
	ll p,len;
	cin>>len>>p;
	cin>>n;
	ll ans=0;
	if(p==2||p==5)
	{
		for(ll i=0;i<len;i++)
		{
			if((n[i]-'0')%p==0)
			ans+=i+1;
		}
		cout<<ans<<endl;
		return 0;
	}
	ll mp[200005];
	mp[0]=1;
	for(int i=1;i<=len;i++)
	{
		mp[i]=(mp[i-1]*10)%p;
		//cout<<mp[i]<<' ';
	}
	ll x[10003];
	mem(x);
	ll tmp=0;
	for(ll i=len-1;i>=0;i--)
	{
		tmp=(tmp+mp[len-i-1]*(n[i]-'0'))%p;
		//cout<<cc<<endl;
		x[tmp]++;
	}
	for(ll i=0;i<p;i++)
	{
		if(i==0)
		ans+=((x[i]*(x[i]+1))/2);
		else
		ans+=((x[i]*(x[i]-1))/2);
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 2048
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int k;
LL h[101010], dp[101010];

int main(){
    INIT;
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        cin >> h[i];
        dp[i] = HINF<LL>();
    }
    dp[1] = 0;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= k;j++){
            if(i - j >= 1)dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << dp[n] << endl;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 2.01e14;
const double eps = 1e-8;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N;
    cin >> N;
    vector<long double> x(N),y(N);
    vector<char> d(N);
    rep(i,0,N) cin >> x[i] >> y[i] >> d[i];

    auto f=[&](long double t){
        long double xmin=inf64,xmax=-inf64,ymin=inf64,ymax=-inf64;
        rep(i,0,N){
            long double xx=x[i],yy=y[i];
            if(d[i]=='R') xx+=t;
            else if(d[i]=='L') xx-=t;
            else if(d[i]=='U') yy+=t;
            else yy-=t;
            chmin(xmin,xx);
            chmax(xmax,xx);
            chmin(ymin,yy);
            chmax(ymax,yy);
        }
        return (xmax-xmin)*(ymax-ymin);
    };

    long double lb=0,ub=inf64;
    rep(i,0,200){
        auto a=(lb+lb+ub)/3;
        auto b=(lb+ub+ub)/3;
        if(f(a)>f(b)){
            lb=a;
        }else{
            ub=b;
        }
    }

    long double ans=min(f(lb),f(0));

    i64 loop=10;
    rep(i,-loop,loop){
        if(max((long double)0,(long double)(i64(lb)+0.5*i)) == 0){
            ++loop;
            continue;
        }
        chmin(ans,f(i64(lb)+0.5*i));
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main(void){
  int m[4][3][10] = {{{0}}};
  int N;
  int b,f,r,v;
  cin >> N;

  for(int i=0;i<N;i++){
    cin >> b >> f >> r >> v;
    m[b-1][f-1][r-1]+=v;
  }

  for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<10;k++){
        cout << ' ' <<m[i][j][k];
      }
      cout << endl;
    }
    if(i!=3){
    cout << "####################" << endl;
  }
  }
  return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    int ans = 0;
    
    if(K == 1)
    {
        ans = 0;
    }
    else
    {
        ans = N - K;
    }
    cout << ans << endl;
    return 0;
}

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

void solve()
{
    string s;
    cin>>s;

    if(s.find('7')!=-1)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    solve();
    return 0;
}


Measured memory_bytes: 3604
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);

            int[] dp = new int[n];
            Arrays.fill(dp, Integer.MAX_VALUE);
            dp[0] = 0;
            for (int i = 1; i < n; i++) {
                if (i - 2 >= 0) dp[i] = Math.min(dp[i], dp[i - 2] + Math.abs(a[i] - a[i - 2]));
                dp[i] = Math.min(dp[i], dp[i - 1] + Math.abs(a[i] - a[i - 1]));
            }

            out.println(dp[n - 1]);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

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

    }
}



Measured memory_bytes: 32324
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B =sc.nextInt();
		if (B<=A) {
			System.out.println("delicious");
		} else if (B-A<=X) {
			System.out.println("safe");
		} else {
			System.out.println("dangerous");
		}
	}
}

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

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int c,d;
  c = min(a,b);
  if(n < a+b) d = a+b-n;
  else d = 0;
  cout << c << " " << d << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var str = Console.ReadLine().Split();
            var x = long.Parse(str[0] + str[1]);
            bool f = false;
            for (int i = 0; i <=1000; i++)
            {
                if (i * i == x) { Console.WriteLine("Yes"); f = true;  break; }
            }
            if (!f) Console.WriteLine("No");

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 11092
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, H int
	if _, err := fmt.Scan(&N, &H); err != nil {
		return
	}
	A := make([]int, N)
	B := make([]int, N)

	count := 0

	for i := 0; i < N; i++ {
		if _, err := fmt.Scan(&A[i], &B[i]); err != nil {
			return
		}
	}

	sort.Ints(A)
	sort.Ints(B)
	maximumVal := A[N-1]

	for j := N - 1; j >= 0; j-- {
		if maximumVal > B[j] {
			break
		}
		H -= B[j]
		count++
		if H <= 0 {
			fmt.Println(count)
			return
		}
	}

	if H%maximumVal == 0 {
		fmt.Println(count + H/maximumVal)
	} else {
		fmt.Println(count + H/maximumVal + 1)
	}
}


Measured memory_bytes: 5504
import java.util.Scanner;
public class Main{ 
     
 	public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
        while(true){
            int n=sc.nextInt();
            if(n==0) break;
            int[][] a=new int[n+1][n+1];
            
            for(int i=0;i<n;i++){
                  for(int j=0;j<n;j++){
                      a[i][j]=sc.nextInt();
                
                }
             }
             for(int i=0;i<n;i++){
                  for(int j=0;j<n;j++){
                      a[i][n]+=a[i][j];
                
                 }
             }
             for(int i=0;i<n;i++){
                  for(int j=0;j<n;j++){
                      a[n][i]+=a[j][i];
                
                }
       	    }
            for(int i=0;i<n;i++){
                a[n][n]+=a[n][i];
            }
             for(int i=0;i<=n;i++){
                  for(int j=0;j<=n;j++){
                      System.out.printf("%5d",a[i][j]);
                
           	  }
                 System.out.println();
      	   }
            
        
        }
   
    }
}


Measured memory_bytes: 31944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		var r = p[0];
		var d = p[1];
		var x = p[2];
		
		for(int i = 0; i < 10; i++)
		{
			x = r * x - d;
			Console.WriteLine(x);
		}
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



Measured memory_bytes: 13140