akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <tuple>
#include <utility>
#include <queue>
using namespace std;
using AnsType = long long int;
const AnsType INF = 1LL << 60;

int pow3[10];
int get_digit(int val, int k) {
  val /= pow3[k];
  return val % 3;
}

string tri_to_string(int val, int lim) {
  string res = "";
  for(int i=0; i<lim; i++) {
    res += (char)('0' + get_digit(val, i));
  }
  return res;
}

int modify_digit(int bit, int k, int val) {
  int b = get_digit(bit, k);
  bit -= pow3[k] * b;
  bit += pow3[k] * val;
  return bit;
}

struct Elem {
  int pos, bit;
  AnsType cost;
  Elem() {}
  Elem(int a, int b, AnsType c) : pos(a), bit(b), cost(c) {}
  bool operator<(const Elem &e) const {
    return cost > e.cost;
  }
};

using Graph = vector< vector< pair<int, int> > >;

int main() {
  int N, M, K, P; cin >> N >> M >> K >> P; P--;
  Graph G(N);
  for(int i=0; i<M; i++) {
    int x, y, m; cin >> x >> y >> m;
    x--; y--;
    G[x].emplace_back(y, m);
    G[y].emplace_back(x, m);
  }

  vector< vector<int> > S(N), T(N);
  for(int i=0; i<K; i++) {
    int s, t; cin >> s >> t;
    s--; t--;
    S[s].emplace_back(i);
    T[t].emplace_back(i);
  }

  pow3[0] = 1;
  for(int i=1; i<=K; i++) pow3[i] = pow3[i-1] * 3;
  int fullbit = pow3[K] - 1;
  
  priority_queue<Elem> que;
  vector< vector<AnsType> > dist(N, vector<AnsType>(pow3[K], INF));
  dist[P][0] = 0;
  que.emplace(P, 0, 0);

  while(que.size()) {
    auto cur = que.top(); que.pop();
    int pos = cur.pos, bit = cur.bit;
    AnsType d = cur.cost;
    if(d > dist[pos][bit]) continue;
    // fprintf(stderr, "pos = %d, bit = %s, d = %lld\n", pos + 1, tri_to_string(bit, K).c_str(), d);
    
    {
      int nbit = bit;

      for(auto s : S[pos]) {
        int v = get_digit(nbit, s);
        if(v != 0) continue;
        nbit = modify_digit(nbit, s, v + 1);
      }

      for(auto t : T[pos]) {
        int v = get_digit(nbit, t);
        if(v != 1) continue;
        nbit = modify_digit(nbit, t, v + 1);
      }

      if(dist[pos][nbit] > d) {
        dist[pos][nbit] = d;
        que.emplace(pos, nbit, d);
      }
    }

    for(auto e : G[pos]) {
      int to, c; tie(to, c) = e;

      // fprintf(stderr, "e: to = %d, c = %d\n", to, c);
      int nbit = bit;
      if(dist[to][nbit] > d + c) {
        // fprintf(stderr, "cur = %d, to = %d\n", pos, to);
        dist[to][nbit] = d + c;
        que.emplace(to, nbit, d + c);
      }
    }
  }

  AnsType ans = INF;
  for(int i=0; i<N; i++) {
    ans = min(ans, dist[i][fullbit]);
  }

  if(ans == INF) cout << "Cannot deliver" << endl;
  else cout << ans << endl;
  return 0;
}



Measured memory_bytes: 9764
#include<bits/stdc++.h>
#define STDIO
#define MOD 1000000007
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define INF MOD
using namespace std;
string s;
int main(){
	#ifndef STDIO
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	int acnt=0,bcnt=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A')
			acnt++;
		else
			bcnt++;
	}
	if(acnt==0||bcnt==0)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}


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

  int N,Q;
  string s;
  while(cin >> N >> Q >> s){
    vector<char> t(Q), d(Q);
    REP(i,Q) cin >> t[i] >> d[i];

    int ans = N;
    
    {
      auto check =
	[&](int x){
	  --x;
	  REP(i,Q){
	    if(s[x] == t[i]){
	      if(d[i] == 'R') ++x;
	      else --x;
	    }
	    if(x<0) return true;
	  }
	  return false;
	};
      
      int lb=0, ub=N+1, mid;

      while(abs(lb-ub)>1){
	mid = (lb+ub)/2;

	if(check(mid)){
	  lb = mid;
	}else{
	  ub = mid;
	}
      }
      ans -= lb;
    }

    {
      auto check =
	[&](int x){
	  --x;
	  REP(i,Q){
	    if(s[x] == t[i]){
	      if(d[i] == 'R') ++x;
	      else --x;
	    }
	    if(x>=N) return true;
	  }
	  return false;
	};

      int lb=0, ub=N+1, mid;
      while(abs(lb-ub)>1){
	mid = (lb+ub)/2;

	if(check(mid)){
	  ub = mid;
	}else{
	  lb = mid;
	}
      }
      ans -= (N-lb);
    }
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 976
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int t;
    cin>>t;
    int x=t%10;
    if(x==2 || x==4 || x==5 || x==7 || x==9) cout<<"hon";
    else if(x==0 || x==1 || x==6 || x==8) cout<<"pon";
    else if(x==3) cout<<"bon";

    return 0;
}

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

int main(){
  int r,d,x,res;
  cin >> r >> d >> x;
  res = r*x - d;
  for (int i = 0; i < 10; i++){
  	cout << res << endl;
    res = res*r - d;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 100001;

long long prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1]; // is_prime[i]がtrueならiは素数
long long like[MAX_N + 1]; // i以下のlike numberの数

// n以下の素数の数を返す
long long sieve(long long n) {
	long long p = 0;
	for (long long i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (long long i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (long long j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return p;
}

void solve(long long Q, vector<long long> l, vector<long long> r){
	sieve(MAX_N);
	like[0] = 0;
	for (long long i = 1; i <= MAX_N; i++) {
		if (is_prime[i] && is_prime[(i+1)/2] && i%2 == 1) {
			like[i] = like[i-1]+1;
		} else {
			like[i] = like[i-1];
		}
	}

	for(int i = 0 ; i <= Q-1 ; i++){
		if (l[i] > 0) {
			printf("%lld\n", like[r[i]]-like[l[i]-1]);
		} else {
			printf("%lld\n", like[r[i]]);
		}
	}

}

int main(){
	long long Q;
	scanf("%lld",&Q);
	vector<long long> r(Q-1+1);
	vector<long long> l(Q-1+1);
	for(int i = 0 ; i <= Q-1 ; i++){
		scanf("%lld",&l[i]);
		scanf("%lld",&r[i]);
	}
	solve(Q, l, r);
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, q; string s;
    cin >> n >> q >> s;
    vector<pair<char, int>> v(q);
    for (int i = 0; i < q; ++i) {
        char a, b;
        cin >> a >> b;
        v[i] = make_pair(a, (b == 'L' ? -1 : 1));
    }
    int ok = -1, ng = n, l, r;
    while(ng-ok > 1){
        int mid = (ok+ng)/2;
        int cur = mid;
        for (int i = 0; i < q; ++i) {
            if(s[cur] == v[i].first) {
                cur += v[i].second;
            }
            if(cur < 0 || cur >= n) break;
        }
        if(cur < 0) ok = mid;
        else ng = mid;
    }
    l = ok, ok = n, ng = -1;
    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        int cur = mid;
        for (int i = 0; i < q; ++i) {
            if(s[cur] == v[i].first) {
                cur += v[i].second;
            }
            if(cur < 0 || cur >= n) break;
        }
        if(cur >= n) ok = mid;
        else ng = mid;
    }
    r = ok;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if(l < i && i < r) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2180
#include"stdio.h"
int main(){
  char s[3];
  scanf("%s",s);
  int a=0;
  if(s[0]=='a'&&s[1]=='b'&&s[2]=='c')
    a=1;
    if(s[0]=='a'&&s[1]=='c'&&s[2]=='b')
      a=1;
  if(s[0]=='b'&&s[1]=='a'&&s[2]=='c')
    a=1;
  if(s[0]=='b'&&s[1]=='c'&&s[2]=='a')
    a=1;
    if(s[0]=='c'&&s[1]=='a'&&s[2]=='b')
      a=1;
       if(s[0]=='c'&&s[1]=='b'&&s[2]=='a')
         a=1;
  if(a)printf("Yes");
  else printf("No");
  
  
    
  
  
  
  
  return 0;
}

Measured memory_bytes: 128
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


#define forn(t, i, n) for (t i = 0; i < (n); ++i)


template <class T = double>
T pi() {
    return acos(T(-1));
}


using namespace std;

// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream& in, ostream& out) {
    double a = next<double>(in);
    double b = next<double>(in);
    double total = next<double>(in) / a;
    double l = 0.0, r = pi() / 2.0;
    forn (int, it, 50) {
        double mid = (l + r) / 2.0;
        double s = sin(mid);
        double c = cos(mid);
        double h = b * c, h1 = a * s;
        double area;
        if (h < h1) {
            area = (b * s + h / s * c) * h / 2.0;
        } else {
            area = (a * c + h1 / c * s) * (h1 / 2.0 + (h - h1));
        }
        if (area < total) {
            r = mid;
        } else {
            l = mid;
        }
    }
    out << setprecision(15) << l / pi() * 180 << endl;
}


int main() {
  solve(cin, cout);
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
#define MOD 1000000007
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> Zeros(61, 0);
  vector<ll> Ones(61, 0);
  rep(i, N) {
    ll A;
    cin >> A;
    rep(j, 61) {
      if ((A & (1LL << j)) != 0) {
        Ones[j]++;
      } else {
        Zeros[j]++;
      }
    }
  }
  ll SUM = 0;
  rep(i, 61) {
    ll XOR_ONE = (Ones[i] * Zeros[i]) % MOD;
    ll SHIFT = (1LL << i) % MOD;
    XOR_ONE = (XOR_ONE * SHIFT) % MOD;
    SUM = (SUM + XOR_ONE) % MOD;
  }
  cout << SUM << endl;
  return 0;
}


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

const string YES = "YES";
const string NO = "NO";

void solve(std::string A, std::string B, std::string C){
    if(A.at(A.length()-1)==B.at(0) && B.at(B.length()-1)==C.at(0)){
        cout << YES << endl;
    }
    else cout << NO << endl;
}

int main(){
    std::string A;
    std::cin >> A;
    std::string B;
    std::cin >> B;
    std::string C;
    std::cin >> C;
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
B = [lst[i][0] for i in range(n)]
node = [[] for i in range(n)]

def Insertion_Sort(lst,B,n):
    for i in range(1,n):
        v = B[i]
        w = lst[i]
        j = i-1
        while j>=0 and B[j]>v:
            B[j+1]=B[j]
            lst[j+1]=lst[j]
            j-=1
        B[j+1]=v
        lst[j+1]=w
        
def find_root():
    A = []
    for i in range(n):
        A.extend(lst[i][1:])
    for i in range(n):
        if not i in A:
            return i

def make_node(arg_parent, arg_sibling, arg_num, arg_depth):
    if arg_num == root:
        type = "root"
    elif lst[arg_num][1] == lst[arg_num][2] == -1:
        type = "leaf"
    else:
        type = "internal node"
    children_lst = lst[arg_num][1:]
    degree = 0
    for i in children_lst:
        if i != -1:
            degree+=1
    height = -1
    node[arg_num] = [arg_parent, arg_sibling, degree, arg_depth, height, type]
    if children_lst[0]!=-1:
        make_node(arg_num, children_lst[1], children_lst[0], arg_depth+1)
    if children_lst[1]!=-1:
        make_node(arg_num, children_lst[0], children_lst[1], arg_depth+1)

def make_height(arg_num, arg_height):
    if arg_height > node[arg_num][4]:
        node[arg_num][4] = arg_height
        if node[arg_num][0] != -1:
            make_height(node[arg_num][0], arg_height+1)

def make_height_0_list():
    A = []
    for i in range(n):
        if node[i][2] == 0:
            A.append(i)
    return A

Insertion_Sort(lst, B, n)
root = find_root()
make_node(-1, -1, root, 0)
height_0_list = make_height_0_list()
for i in height_0_list:
    make_height(i, 0)

for i in range(n):
    parent, sibling, degree, depth, height, type = node[i]
    print(f"node {i}: parent = {parent}, sibling = {sibling}, degree = {degree}, depth = {depth}, height = {height}, {type}")


Measured memory_bytes: 5636
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N;
int H[21];

signed main(){
	cin>>N;
	int ans=0;
	REP(i,N){
		cin>>H[i];
	}
	for(int i=0;i<N;i++){
		int Max=0;
		for(int j=0;j<i;j++){
			Max=max(Max,H[j]);
		}
		if(Max<=H[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;
vll a;
vll b;
lli ans = 0;

void output(){
    cout << a[0];
    for(lli i = 1;i < n;i++){
        cout << " " << a[i];
    }
    cout << endl;
}

int main(){
    cin >> n;
    a = vll(n);
    for(lli i = 0;i < n;i++) cin >> a[i];
    for(lli i = n-1;i >= 0;i--){
        for(lli j = n-1;j > 0;j--){
            if(a[j] < a[j-1]) swap(a[j],a[j-1]),ans++;
        }
    }
    output();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
	string a;
    cin>>a;
    if (a.size()==3){
	
    int x=0;
    if (a[0]=='R'||a[1]=='R'||a[2]=='R')
    {
    	x=1;
	}
    if (a[0]=='R'&&a[1]=='R')
    {
    	x=2;
	}
    if (a[1]=='R'&&a[2]=='R')
    {
    	x=2;
	}
	if(a[0]=='R'&&a[1]=='R'&&a[2]=='R')
	{
		x=3;
	}
	
	cout<<x;
}
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int s = a; //????°????
		int b = a; //?????§???
		long num = a; //????¨????
		for (int i=1; i<n; i++) {
			a = sc.nextInt();
			num += a;
			if(s>a){
				s = a;
			}else if(b<a){
				b = a;
			}
		}
		System.out.println(s + " " + b + " " + num);
	}
}

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

int main()
{
  int n;
  cin>>n;
  int dp[5][4][11]={0};
  for (int i = 0; i < n; ++i)
  {
    int b,f,r,v;
    cin>>b>>f>>r>>v;
    dp[b][f][r]+=v;
  }
  for (int i = 1; i < 5; ++i)
  {
    for (int j = 1; j < 4; ++j)
    {
      for (int k = 1; k < 11; ++k)
      {
        cout<<" "<<dp[i][j][k];
      }
      cout<<endl;
    }
    if(i!=4) cout<<"####################"<<endl;
  }
}


Measured memory_bytes: 3092
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		double x1 = stdIn.nextDouble();
		double y1 = stdIn.nextDouble();
		double x2 = stdIn.nextDouble();
		double y2 = stdIn.nextDouble();
		System.out.printf("%.5f",Math.pow(Math.pow(x1-x2,2)+Math.pow(y1-y2,2),(double)1/2));
		System.out.println();
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  
  for(int i = 0;i<N;i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  int ans = 0;
  for(int i = 0;i<N;i++){
    if(i%2 == 0) ans += A[i];
    if(i%2 != 0) ans -= A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
t = input()
cnt = 0
mcnt = 0
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j] == t[j]:
            cnt += 1
    if cnt >= mcnt:
        mcnt = cnt
    cnt = 0
ans = len(t) - mcnt
print(ans)

Measured memory_bytes: 9048
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
S1 = [A[0]]*N
S2 = [A[-1]]*N
for i in range(1, N):
    S1[i] = S1[i-1]+A[i]
    S2[i] = S2[i-1]+A[N-i-1]
ans = S1[-1]
for i in range(1, N-2):
    s1 = S1[i]
    b = bisect_left(S1, s1/2)
    if abs(S1[b]-s1/2)>abs(s1/2-S1[b-1]):
        b-=1
    P, Q = S1[b], s1-S1[b]
    s2 = S2[N-i-2]
    c = bisect_left(S2, s2/2)
    if abs(S2[c]-s2/2)>abs(s2/2-S2[c-1]):
        c-=1
    R, S = S2[c], s2-S2[c]
    res = max(P, Q, R, S)-min(P, Q, R, S)
    ans = min(ans, res)
print(ans)

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

int digits[25];
long long S(long long k){
    long long res = 0;
    while(k){
        res += k%10;
        k /= 10;
    }
    return res;
}

long long Pow10[20];

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

    long long temp = 1;
    printf("%lld\n", temp);
    Pow10[0] = 1;
    for(int i = 1; i < 19; i ++){
        Pow10[i] = 10*Pow10[i-1];
    }
    K --;
    while(K){
        long long next1 = temp;
        double bestVal = 1e308;
        for(int i = 0; i < 18; i ++){
            long long nextTemp = temp+Pow10[i];
            double val1 = (double)nextTemp/S(nextTemp);
            if(bestVal > val1){
                bestVal = val1;
                next1 = nextTemp;
            }
        }

        K --;
        printf("%lld\n", next1);
        temp = next1;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_Q = 100000;
int Q;
ll A[MAX_Q], B[MAX_Q];

int main(){
  cin >> Q;
  REP(i, Q) cin >> A[i] >> B[i];
  REP(i, Q) {
    ll a = A[i], b = B[i];
    if (a > b) swap(a, b);
    if(a == b || a == b - 1) {
      cout << (a - 1) * 2 << endl;
    } else {
      ll c = ll(sqrt(a * b));
      if (c * (c + 1) < a * b) {
        cout << c * 2 - 1 << endl;
      } else if(c * c < a * b) {
        cout << (c - 1) * 2 << endl;
      } else {
        cout << (c - 1) * 2 - 1 << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Go Home
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int n;
  for (n = 1; n * (n + 1) < x * 2; n++);
  printf("%d\n", n);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
// O(log N)　keyのある場所を返す。なかったら-1を返す
int search(int key, vector<int> a){
  int right = a.size();
  int left = 0;
  while(right >= left){
    int middle = left + (right - left) / 2;
    if(a[middle] == key) return middle; //keyが入ってる場所を返す
    else if(a[middle] > key) right = middle - 1;
    else if(a[middle] < key) left = middle + 1;
  }
  //なければ-1を返す
  return -1;
}
// O(N^2) babble sort
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a * n , b) << endl;
  return 0;
}

Measured memory_bytes: 256
def count_division(f, t, d)
  return 1 + ((t - f - d + (1+(f-1)%d)) / d)
end

a, b, c, d = gets.chomp.split.map(&:to_i)

all_num = b - a + 1
c_num = count_division(a, b, c)
d_num = count_division(a, b, d)
cd_num = count_division(a, b, c.lcm(d))

puts(all_num - c_num - d_num + cd_num)

Measured memory_bytes: 1788
A, B, M = (int(x) for x in input().split())
a_s = [int(x) for x in input().split()]
b_s = [int(x) for x in input().split()]

minimum_price_with_discount = 0

for i in range(M):
    x, y, c = (int(x) for x in input().split())
    price_with_discount = a_s[x-1] + b_s[y-1] - c
    if i == 0:
        minimum_price_with_discount = price_with_discount
    else:
        if minimum_price_with_discount > price_with_discount:
            minimum_price_with_discount = price_with_discount
        else:
            continue

a_s.sort(), b_s.sort()
minimum_price_without_discount = a_s[0] + b_s[0]

if minimum_price_with_discount > minimum_price_without_discount:
    print(minimum_price_without_discount)
else:
    print(minimum_price_with_discount)

Measured memory_bytes: 18488
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <bitset>
#include <queue>


#define Z class
#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
using pll = pair<long long, long long>;

template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;

int main() {
    int D, N; cin >> D >> N;
    //コーナーケースの処理
    if (N == 100) N++;
    
    cout << N;
    rep (i, D) cout << "00";
    cout << endl;
}



Measured memory_bytes: 256
/*==============================================*\
Codeforces ID:    mdshihab                        
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    FI(); /// skip this line for compile
    int a,b;
    cin >> a >> b;
    if(b%a) cout << b-a << endl;
    else cout << a+b << endl;
    return 0;
}



Measured memory_bytes: 3636
def main(n):
  def c(i,j):
    ret=0
    for k in range(1,n+1):
      if str(k)[0]==str(i) and str(k)[-1]==str(j):
        ret+=1
    return ret
  ans=0
  for a in range(1,10):
    for b in range(a,10):
      d=c(a,b)*c(b,a)
      ans+=d
      if a!=b:
        ans+=d
  print(ans)
if __name__=='__main__':
  n=int(input())
  main(n)

Measured memory_bytes: 40556
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
#======================================================#
def main():
    n = II()
    s = IS()
    cnt_b = 0
    cnt_w = s.count('.')
    cnt = cnt_w
    for i in range(n):
        if s[i] == '#':
            cnt_b += 1
        else:
            cnt_w -= 1
        cnt = min(cnt, cnt_b+cnt_w)
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3500
#include <cstdio>
#include <iostream>
#include <string>

int main()
{
    int N, K;
    std::string S;
    scanf("%d", &N);
    std::cin >> S;
    scanf("%d", &K);

    auto a = S[K - 1];

    for (int i = 0; i < N; i++) {
        if (S[i] != a) {
            S[i] = '*';
        }
    }
    std::cout << S << "\n";


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <int>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(int i=0;i<n;i++)
#define loopj(n)	for(int j=0;j<n;j++)
ll mod=1e9+7;
const int N = 3e6+7, M = 2 * N;
string arr[1009];
int freq[30];
bool prime[N];
int prims[N];
int sz=0;
void SieveOfEratosthenes(ll n)
{
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            prims[sz++]=p;
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

}
int main()
{
      //freopen ("output.txt","w",stdout);
        //ios_base::sync_with_stdio(0), cin.tie(0),cout.tie(0);
    ll k,w,n;
    cin >> k >>w;
    cout << (k+w)%24 <<endl;
}


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

#define llint long long int

using namespace std;

int main(){
    llint N;

    cin >> N;

    map<int, int> mp;

    for(int p = 2; p <= sqrt(N) + 1; p ++){
        if(N % p == 0){
            N /= p;

            if(mp.find(p) == mp.end()){
                mp[p] = 1;
            }else{
                mp[p] ++;
            }
            p --;
        }
    }
    if(N > 1){
        if(mp.find(N) == mp.end()){
            mp[N] = 1;
        }else{
            mp[N] ++;
        }
    }
    int ans = 0;

    for(auto x : mp){
        for(int i = 1; i <= 100; i ++){
            if(i * (i + 1) / 2 > x.second){
                ans += i - 1;

                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;

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

vi pr;

int fun(int n){
	int ret=0;
	for(int i=1;i*i<=n;++i){
		if(n%i==0){
			int ano=n/i;
			ret+=1+(ano!=i);
		}
	}
	return ret;
}

void solve(){
	int n; cin>>n;
	int fre[1000006]={0};
	for(int i=1;i<=1000000;++i) for(int j=1;j<=1000000;++j) {
		int pro=i*j;
		if(pro>1000000) break;
		fre[pro]++;
	}
	int cnt=0;
	f(c,1,n){
		int r=n-c;
		cnt+=fre[r];
	}
	cout<<cnt<<"\n";
}


int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
  	int t=1;   //cin>>t;
  	while(t--) solve();
 	return 0;
}

Measured memory_bytes: 11460
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-2):
  if max(p[i], p[i+1], p[i+2]) != p[i+1] and min(p[i], p[i+1], p[i+2]) != p[i+1]:
    ans = ans + 1
print(ans)

Measured memory_bytes: 9136
'use strict';
(function(stdin) {

    //define function
    //declare variable

    var inputs = stdin.toString().trim().split('\n');
    var x = inputs;
    var set = x*x*x;
    //main

    //display
    //console.log(inputs[0]);
    //console.log(x);
console.log(parseInt(set));

}(require('fs').readFileSync('/dev/stdin', 'utf8')))

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

vector<ll>par(2e5+10);
void init(ll n) {
  for(ll i=0;i<n;i++) {
    par[i]=i;
  }
}

ll root(ll x) {
  if(par[x]==x) {
    return x;
  }
  else {
    return par[x]=root(par[x]);
  }
}

bool same(ll x, ll y) {
  return root(x)==root(y);
}

void unite(ll x, ll y) {
  if(same(x,y)) return;
  par[root(x)]=root(y);
}

int main() {
  ll n,q;
  cin >> n >> q;
  init(n);
  for(ll i=0;i<q;i++) {
    ll c,x,y;
    cin >> c >> x >> y;
    if(c) {
      cout << same(x,y) << endl;
    }
    else {
      unite(x,y);
    }
  }
}


Measured memory_bytes: 4260
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,w;
	cin>>n>>w;
	int val[n+5],wt[n+5];
	for(int i=1;i<=n;i++)
		val[i]=wt[i]=0;
	for(int i=1;i<=n;i++)
		cin>>wt[i]>>val[i];
	long long int dp[n+1][w+1];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
			else if(wt[i]<=j)
				dp[i][j]=max(val[i]+dp[i-1][j-wt[i]],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][w]<<endl;

}


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

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		LinkedList<String> output = new LinkedList<String>();
		double[] p = new double[6];//0a 1b 2c 3d 4e 5f
		double a, b, c, d, e, f;
		while (in.hasNext()) {
			for (int i = 0; i < p.length; i++) {
				p[i] = in.nextDouble();
			}
			a = p[0];
			b = p[1];
			c = p[2];
			d = p[3];
			e = p[4];
			f = p[5];
			double y = (c * d - a * f) / (b * d - a * e);
			double x = (c * e - b * f) / (a * e - b * d);
			BigDecimal X = new BigDecimal(x);
			BigDecimal Y = new BigDecimal(y);
			X = X.setScale(3, BigDecimal.ROUND_HALF_UP);
			Y = Y.setScale(3, BigDecimal.ROUND_HALF_UP);
			output.add(String.format("%.3f %.3f", X, Y));
		}
		in.close();
		for (int i = 0; i < output.size(); i++) {
			System.out.println(output.get(i));
		}
	}
}

Measured memory_bytes: 28692
inputs1 = list(map(int, (input().split())))
a = list(map(int, (input().split())))

k = inputs1[0]
n = inputs1[1]

b = [0 for i in range(n)]

for i in range(n-1):
    b[i] = a[i + 1] - a[i]

b[n-1] = k - a[n-1] + a[0]

m = max(b)

print(k-m)


Measured memory_bytes: 25840
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;

int inf = 2e9, mod = 1e9+7;

int inv(int b, int e = mod - 2){
    if(e == 0) return 1;
    if(e == 1) return b;
    int cur = inv(b,e/2);
    return cur * cur % mod * (e%2?b:1) % mod;
}
vi fact(2e5 + 1), ifact(2e5 + 1);
int choose(int n, int k){
    return fact[n] * ifact[k] % mod * ifact[n-k] % mod;
}
int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n,m,a,b,sum = 0; cin >> n >> m >> a >> b;
    fact[0] = ifact[0] = 1;
    for(int i = 1; i <= 2e5;i++) fact[i] = fact[i-1] * i % mod, ifact[i] = ifact[i-1] * inv(i) % mod;
    for(int i = 0;i<n-a;i++){
        sum = (sum + choose(i + b - 1,i) * choose(n-i-1 + m-b-1,m-b-1) % mod) % mod;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
    int d,n;
    ll ans=0;
    cin>>d>>n;
    if(d==0){
        ans=0;
        for(int i=0;i<n;i++){
            ans++;
            if(ans%100==0){
                ans++;
            }
        }
        cout<<ans<<endl;return 0;
    }
    if(d==1){
        ans=0;
        for(int i=0;i<n;i++){
            ans+=100;
            if((ans/100)%100==0){
                ans+=100;
            }
        }
        cout<<ans<<endl;return 0;
    }
    if(d==2){
        ans=0;
        for(int i=0;i<n;i++){
            ans+=10000;
            if((ans/10000)%100==0){
                ans+=10000;
            }
        }
        cout<<ans<<endl;return 0;
    }
    return 0;
}



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

namespace EightQueen
{
    internal class Program
    {
        private const int n = 8;
        private static List<int> row, col, dpos, dneg;
        private static bool[,] x;
        
        static void Start()
        {
            row = new List<int>();
            col = new List<int>();
            dpos = new List<int>();
            dneg = new List<int>();
            x = new bool[n, n];
            for (var i = 0; i < n; i++)
            {
                row.Add(-1);
                col.Add(-1);
            }

            for (var i = 0; i < 2 * n - 1; i++)
            {
                dpos.Add(-1);
                dneg.Add(-1);
            }
            
            
        }

        static void PrintBoard()
        {
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < n; j++)
                {
                    if (x[i,j])
                    {
                        if (row[i] != j) return;
                    }
                }
            }

            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < n; j++)
                {
                    Console.Write((row[i] == j) ? "Q" : ".");
                }
                Console.WriteLine();
            }
        }

        static void PutQueen(int i)
        {
            if (i == n)
            {
                PrintBoard();
                return;
            }

            for (var j = 0; j < n; j++)
            {
                if(col[j] == 1 || dpos[i + j] == 1 || dneg[i - j + n - 1] == 1) continue;

                row[i] = j;
                col[j] = dpos[i + j] = dneg[i - j + n - 1] = 1;
                
                PutQueen(i + 1);

                row[i] = col[j] = dpos[i + j] = dneg[i - j + n - 1] = -1;
            }
        }
        public static void Main(string[] args)
        {
            Start();

            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < n; j++)
                {
                    x[i,j] = false;
                }
            }

            var k = int.Parse(Console.ReadLine());
            for (var i = 0; i < k; i++)
            {
                var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                x[input[0],input[1]] = true;
            }
            
            PutQueen(0);

        }
    }
}


Measured memory_bytes: 18308
package main

import "fmt"

func main() {
	var c1, c2 string
	fmt.Scan(&c1, &c2)
	if c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
# そのまま入力文字列の入力
N = input()

# 空白区切りの数値をリスト化
h_list = list(map(int, input().split()))

r = 0
prev_height = -1
tmp_reslt = 0
for current_height in h_list:
    if prev_height == -1:
        prev_height = current_height
        continue

    if prev_height >= current_height:
        tmp_reslt += 1
    else:
        r = max(r, tmp_reslt)
        tmp_reslt = 0
    prev_height = current_height

r = max(r, tmp_reslt)

print(r)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;
typedef pair<long long, long long> pll;
// scanf("%d %d %d %d", &w, &b, &d, &s); %lld
// printf("%d\n", points);
// const double PI = acos(-1);
const int MAX = 1e7+1;
ll divi[MAX];

void ini(){
	for(int i = 1; i<=MAX; i++){
		for(int j = i; j<=MAX; j+=i){
			divi[j]++;
		}
	}
}

int main() 
{
	fastIO;
	int n; cin >> n;
	ll ans = 0;
	ini();
	
	for(int i = 1; i<=n; i++)
		ans += (i * divi[i]);
		
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 81760
#include<iostream>
using namespace std;
typedef unsigned long long int ull;

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

  ull r = 0;

  if(n-1 > 0)
  {
    r = k;
    for(int i = 1; i<n; i++)
    r *= (k-1);
  }else
  r = k;
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int A, B; cin >> A >> B;
    for (int i = min(A, B); i <= max(A, B); ++i) {
        if (abs(A - i) == abs(B - i)) {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("%s\n", "IMPOSSIBLE");
}


Measured memory_bytes: 256
from collections import defaultdict
MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for num in A:
    d[num] += 1
d[0] += 1

if all(d[i] == 2 for i in range((N + 1) % 2, N, 2)):
    print(2 ** (N // 2) % MOD)
else:
    print(0)

Measured memory_bytes: 14820
#include <stdio.h>

int main(void)
{
	int H, W, i, j;
	
	while(1)
	{
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0) break;
		for(i = 0; i < H; i++)
		{
			for(j = 0; j < W; j++)
			{
				if((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
					printf("#");
				else
				    printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}
const ll MOD = 1e9+7;
long long Comb(int n, int i){long long ans = 1; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){
      ans *=(n+1-j);
      ans /= j;
      ans %= MOD;} }return ans;}

bool include(int a[], int val, int n){
    int left = 0, right = n;
    int middle = (left + right)/2;
    while(left < right){
        if(a[middle] == val) return true;
        else if(a[middle] > val) {
            right = middle;
        } else {
            left = middle + 1;
        }
        middle = (left + right) / 2;
        if(a[middle] == 2) return true;
    }
    return false;
}

void solve(void){
    int n, m;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    cin >> m;
    int b[m];
    for(int i = 0; i < m; ++i) cin >> b[i];
    for(int val :b){
        if(!include(a, val, n)) {
            cout << 0 << endl;
            return;
        }
    }
    cout << 1 << endl;
}

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



Measured memory_bytes: 4632
def dot(ndarray,array)
    answer = []
    ndarray.each do |part_of_ndarray|
        mult = 0
        array.each_with_index do |number,index|
            mult += part_of_ndarray[index] * number
        end
        answer.push(mult)
    end
    return answer
end

input_info = gets.split.map(&:to_i)
ndmatrix = []
input_info[0].times do
    ndmatrix.push(gets.split.map(&:to_i))
end
matrix = []
input_info[1].times do
    matrix.push(gets.to_i)
end
puts(dot(ndmatrix,matrix))


Measured memory_bytes: 6980
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n,k,s=1,sosuu[100010]={2};
  for(int i=3;i<=999999;i+=2){
    k=0;
    for(int j=3;j<=sqrt(i);j+=2){
      if(i%j==0){
	k=1;
	break;
      }
    }
    if(k==0){
      sosuu[s]=i;
      s++;
    }
  }
  while(cin>>n){
    int a=0;
    for(a=0;sosuu[a]<=n;a++){
      if(sosuu[a]==999983){
	a++;
	break;
      }
    }
    cout<<a<<endl;   
  }
  return 0;
}

Measured memory_bytes: 3356
N, A, B, C = list(map(int, input().split()))
l = []
for i in range(N):
    l.append(int(input()))

def cost(z, ABC):
    if len(z) == 0:
        return float('inf')
    else:
        return abs(ABC - sum(z)) + (len(z) - 1) * 10

def retmin(l, a, b, c, d):
    if len(l) == d:
        return cost(a, A) + cost(b, B) + cost(c, C)
    else:
        new_a = a + [l[d]]
        new_b = b + [l[d]]
        new_c = c + [l[d]]
        
        return min(retmin(l, new_a, b, c, d + 1),
                   retmin(l, a, new_b, c, d + 1),
                   retmin(l, a, b, new_c, d + 1),
                   retmin(l, a, b, c, d + 1))
    
print(retmin(l, [], [], [], 0))

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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		long wa = 0;
		for(int i = 1; i <= n; i++)
		{
			wa += i;
		}
		Console.WriteLine(wa);
	}
	
	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 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, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:
using pii = pair<int,int>;
vector<pii> ary;

//Appropriately Changed
using edge = struct {int to, cost;};
using G = vector<vector<edge>>;

//Appropriately Changed
void add_edge(G &graph, int from, int to, int cost) {
	graph[from].push_back({to, cost});
	graph[to].push_back({from, cost});
}

auto bfs(const G &graph,int s,int inf){
    const int n=graph.size();
    vector<int> dist(n,inf);
 
    deque<int> q;
    dist[s]=0,q.push_back(s);
    
    while(!q.empty()){
        int v=q.front(); q.pop_front();
        for(auto &e:graph[v]){
            int nc=dist[v]+e.cost,nv=e.to;
            if(chmin(dist[nv],nc)) {
            	if (e.cost)
            		q.push_back(nv);
            	else
            		q.push_front(nv);
            }
        }
    }
    return dist;
}


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

	rep(v,1,n+1) ary.push_back(pii(0,v));
	vector<int> p(m),q(m),c(m);

	rep(i,m){
		cin >> p[i] >> q[i] >> c[i];
		ary.push_back(pii(c[i],p[i]));
		ary.push_back(pii(c[i],q[i]));
	}

	uniq(ary);
	const int t = ary.size();

	G graph(t);

	rep(i,m){
		const int a = getidx(ary,pii(c[i],p[i]));
		const int b = getidx(ary,pii(c[i],q[i]));
		add_edge(graph,a,b,0);		
	}

	rep(i,n,t){
		const int v = ary[i].second - 1;
		add_edge(graph,i,v,1);
	}

	const int inf = 1 << 21;

	auto dist = bfs(graph,0,inf);

	if(dist[n-1] == inf){
		puts("-1");
	} else {
		cout << dist[n-1] / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 39788
def common(x,y):
    n = len(x)
    m = len(y)
    c1 = [0for i in range(m+1)]
    for i in range(n):
        e1 = x[i]
        c2 = c1[:]
        for j in range(m):
            if (e1 == y[j]):
                c1[j+1] = c2[j] + 1
            elif (c1[j+1] < c1[j]):
                c1[j+1] = c1[j]
    return(c1[-1])


t = int(input())
for w in range(t):
    fseq = str(input()) ##Xk
    sseq = str(input()) ##Yl
    print(common(fseq,sseq))
    


Measured memory_bytes: 5636