akhauriyash/Code-Regression huggingface dataset:
N = int(input())
x = []
for i in range(N):
  xi, yi = map(int, input().split())
  x.append((xi,yi))
  
sum_dist = 0
for i in range(len(x) - 1):
  for j in range(i+1, len(x), 1):
    sum_dist += ((x[i][0]-x[j][0])**2 + (x[i][1]-x[j][1])**2)**0.5
print(sum_dist*2/N)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const ll INF = 1e18;
const int MOD = 1000000007;

ll dp[20][20];
vector<ll> calc(vector<P>& a) {
   int n = a.size();
   sort(a.begin(), a.end());
   rep(i, 0, n + 1) rep(j, 0, n + 1) dp[i][j] = INF;
   dp[0][0] = 0;
   rep(l, 0, n) {
      rep(r, l + 1, n + 1) {
         {
            ll now = INF;
            rep(k, l, r) {
               ll s = 0;
               rep(i, l, r) {
                  s += abs(a[i].first - a[k].first) * ll(a[i].second);
               }
               chmin(now, s);
            }
            rep(j, 0, n) chmin(dp[r][j + 1], dp[l][j] + now);
         }
         {
            ll now = 0;
            rep(i, l, r) { now += abs(a[i].first) * ll(a[i].second); }
            rep(j, 0, n) chmin(dp[r][j], dp[l][j] + now);
         }
      }
   }
   vector<ll> res(n + 1, INF);
   rep(j, 0, n + 1) res[j] = dp[n][j];
   return res;
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n;
   cin >> n;
   vector<int> x(n), y(n), p(n);
   rep(i, 0, n) cin >> x[i] >> y[i] >> p[i];
   vector<ll> ans(n + 1, INF);
   rep(S, 0, 1 << n) {
      vector<P> ax, ay;
      rep(i, 0, n) {
         if (S >> i & 1) {
            ax.emplace_back(x[i], p[i]);
         } else {
            ay.emplace_back(y[i], p[i]);
         }
      }
      vector<ll> dx = calc(ax);
      vector<ll> dy = calc(ay);
      rep(i, 0, dx.size()) rep(j, 0, dy.size()) {
         ans[i + j] = min(ans[i + j], dx[i] + dy[j]);
      }
   }
   rep(i, 0, n + 1) { cout << ans[i] << endl; }
   return 0;
}

Measured memory_bytes: 3596
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        t: usize,
        cts: [[usize; 2];n]
    }

    let mut m = 1001;
    for i in 0..cts.len() {
        if cts[i][1] <= t {
            m = min(m, cts[i][0]);
        }
    }
    if m == 1001 {
        println!("{}", "TLE");
    } else {
        println!("{}", m);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>

using namespace std;
const int N = 25;

int n, ans;
int a[N], b[N], c[N];

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; ++i)
	  scanf("%d", &a[i]);
	for(int i=1; i<=n; ++i)
	  scanf("%d", &b[i]);
	for(int i=1; i<n; ++i)
	  scanf("%d", &c[i]);
	for(int i=1; i<=n; ++i){
	    ans += b[a[i]];
		if(a[i] - a[i-1] == 1){
			ans += c[a[i]-1];
		}
		
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
r,b,g,n = map(int, input().split( ))
ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        if (n-i*r-j*g)>=0 and (n-i*r-j*g)%b==0:
            ans += 1
print(ans)


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

int main(){

    int n,k,x[100];
    int ans=0;

    cin>>n>>k;

    for(int i=0;i<n;i++){
        
        cin>>x[i];
        ans+=min(x[i],k-x[i])*2;

    }

    cout<<ans<<endl;











    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, x = 9;
   cin >> n;
   int ans = n, order = (int)log10(n);
   for (int i = 0; i < order; i++)
   {
      if (i % 2 != 0)
         ans -= x;
      x *= 10;
   }
   if (order % 2 != 0)
      ans -= n - (int)pow(10, order) + 1;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  private static double solve(int n, int k) {
    double sum = 0;
    for (int i = 1; i <= n; i++) {
      int di = i;
      double rate = 1.0 / n;
      while (di < k) {
        di *= 2;
        rate *= 0.5;
      }
      sum += rate;
    }
    return sum;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int k = reader.nextInt();
    out.printf("%.20f\n", solve(n, k));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}



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

int main()
{
    string str;
    string out = "";
    cin >> str;

    for(int i=0; str[i] != '\0'; i++){
        switch (str[i])
        {
        case '0':
            out.push_back(str[i]);
            break;
        case '1':
            out.push_back(str[i]);
            break;
        default:
            if(1 <= out.length()){
                out.pop_back();
                break;
            }
        }
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 3620
n,m = [int(_) for _ in input().split()]
a = {int(input()) for _ in range(m)}
dp = [0 for _ in range(n+1)]
dp[0] = 1
mod = int(1e9+7)
for i in range(1,n+1):
    if i-1 not in a:
        dp[i] += dp[i-1];dp[i] %= mod
    if i >= 2 and i-2 not in a:
        dp[i] += dp[i-2];dp[i] %= mod
print(dp[-1])

Measured memory_bytes: 11884
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    string S; cin >> S;
    int res = S.size();

    REP(i,26){
        int a=0, b=0;
        for(auto& s: S){
            if(s == 'a' + i){
                a = max(a, b);
                b = 0;
            }else ++b;
        }
        res = min(res, max(a, b));
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
  std::string list[1000],tmp;
  int c=0,k=0;
  while(std::cin>>tmp) {
    if( (k=tmp.find(",")) != -1)
      tmp = tmp.substr(0,k);
    if( (k=tmp.find(".")) != -1)
      tmp = tmp.substr(0,k);
    if( (tmp.length() > 2) && (tmp.length() < 7))
      list[c]=tmp,c++;
  }
  for(int i=0; i<c; i++){
    std::cout<<list[i];
    if(i<c-1) std::cout<<" ";
  }
  std::cout<<"\n";
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

li a[10100];
li b[10100];
li n;

inline bool check() {
	cin >> n;
	li sa = 0;
	rep(i, n) {
		cin >> a[i];
		sa += a[i];
	}
	li sb = 0;
	rep(i, n) {
		cin >> b[i];
		sb += b[i];
	}
	if (sa > sb) {
		return false;
	}
	li num = sb - sa;

	li num1 = num;
	rep(i, n) {
		if (a[i] < b[i]) {
			li cnt = (b[i] - a[i] + 1) / 2;
			a[i] += cnt * 2;
			num1 -= cnt;
		}
	}
	if (num1 < 0) {
		return false;
	}
	return true;
}

int main() {
	cout << (check() ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
#define inf 0x7fffffff
/*------------------------------------------------------------*/
int n,m;
int f[310][310][310];
int main(){
	string s;
	cin>>s;
	in(n);
	int l=s.length();
	FOR(i,0,l-1)f[i][i][0]=1;
	FOR(k,1,l)
		FOR(i,0,l-1){
			int j=i+k;
			if(j>=l)break;
			FOR(p,0,n){
				f[i][j][p]=max(f[i+1][j][p],f[i][j-1][p]);
				if(s[i]==s[j])f[i][j][p]=max(f[i][j][p],f[i+1][j-1][p]+2);
				 else if(p)f[i][j][p]=max(f[i][j][p],f[i+1][j-1][p-1]+2);
			}
		}
	int ans=0;
	FOR(i,0,n)ans=max(ans,f[0][l-1][i]);
	out(ans);
}


Measured memory_bytes: 112896
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
vector<int> vec(3);
cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
sort(vec.begin(),vec.end());
cout << vec.at(0) + vec.at(1) << endl;





return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    vector<int> s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    k--;
    cout << s[k] << endl;
    return 0;
}

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

using namespace std;

using bellman_cost = long long;
template<class V, class E>
struct Graph
{
	int sz;
	vector<V> v;
	vector<vector<E>> e;
	vector<E> edges;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	// from, to, cost
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
		edges.emplace_back(pos, args...);
	}
	inline int size() {
		return sz;
	}
};

template<class T>
struct Vertex
{
	T cost;
	bool valid = false; // 到達不能または無限にコストが減るときfalse
	Vertex(T v1) : cost(v1) {}
	Vertex() {}
};
using vertex = Vertex<bellman_cost>;

template<class T>
struct Edge
{
	int from;
	int to;
	T cost;
	Edge(int t, T c) : to(t), cost(c) {}
	Edge(int t, int u, T c) : from(t), to(u), cost(c) {}
	Edge() {}
};
using edge = Edge<bellman_cost>;
using graph = Graph<vertex, edge>;

struct Bellmanford : public graph {
	Bellmanford(int n) : graph(n) {};
	void Bellman_solve(int s, bellman_cost INF_COST) {
		for (auto& vv : v) vv.cost = INF_COST, vv.valid = false;
		v[s].cost = 0, v[s].valid = true;
		for (int i = 0; i + 1 < (int) v.size(); i++) {
			for (auto& x: edges) {
				if (v[x.from].cost == INF_COST) continue;
				v[x.to].cost = min(v[x.to].cost, v[x.from].cost + x.cost);
				v[x.to].valid = true;
			}
		}
		auto valid_check = [&](auto f, int pos) {
			if (!v[pos].valid) return;
			v[pos].valid = false;
			for (auto& y: e[pos]) {
				f(f, y.to);
			}
		};
		for (int i = 0; i < (int) v.size(); i++) {
			for (auto& x: e[i]) {
				if (v[i].cost == INF_COST) continue;
				if (v[x.to].cost > v[i].cost + x.cost) {
					valid_check(valid_check, x.to);
				}
			}
		}
	}
};

/*
template<class V, class E>
void Bellmanford(Graph<V, E>& G, int s, bellman_cost INF_COST)
{
}
*/

void ABC137_E() {
	int N, M, P;
	cin >> N >> M >> P;
	Bellmanford B(N);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		B.add_edge(a-1, b-1, P-c);
	}
	B.Bellman_solve(0, LLONG_MAX);
	if (B.v[N-1].valid) {
		cout << max(0LL, -B.v[N-1].cost) << endl;
	} else {
		cout << -1 << endl;
	}
}

int main() {
	ABC137_E();
}

Measured memory_bytes: 640
import sys  
import numpy as np
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
k = [0] * max(3,(max(a)+1))

for p in a:
    k[p] += 1
ans = 0
for q,r,s in zip(k, k[1:] , k[2:]):
    ans = max(ans, q+r+s)

print(ans)

Measured memory_bytes: 23452
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n;
  cin >> n;
  
  if (n%1110 <= 9){
  cout << "Yes" << endl;
  }
else if ((n%1000)%111 == 0){
cout << "Yes" << endl;
}
  else {
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if((b-a)==(c-b)){
      System.out.println("YES");
    }else{
       System.out.println("NO");
    }
  }
}

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

using namespace std;


int main(void)
{
	int n,t,diff;
	cin >> n;
	vector<int> p(n);
	for(int i=0;i<n;++i){
		cin >> p[i];
	}

	t = 1;
	diff = 0;
	for(int i=0;i<n;++i){
		if(t != p[i]){
			diff++;
		}
		t++;
	}
	if(diff == 2 or diff == 0){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}


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

namespace TYC
{
	const int N = 20;
	
	int *F[N + 1][N + 1], n, k;
	char str[1 << N | 3];
	
	void work()
	{
		scanf("%d%d", &n, &k);
		for (int i = 0; i <= n; i++)
			for (int j = 0; i + j <= n; j++)
			{
				int len = 1 << (i + j) | 3;
				F[i][j] = new int[len];
				memset(F[i][j], 0, sizeof(int[len]));
			}
		for (int i = 0; i <= n; i++)
		{
			scanf("%s", str);
			for (int j = 0; j < 1 << i; j++)
				if (str[j] == '1')
					F[0][i][j] = 1;
		}
		for (int i = 0, v; i <= n; i++)
			for (int j = 1; i + j <= n; j++)
				for (int s = 0; s < 1 << (i + j); s++)
					if ((v = F[i][j][s]))
					{
						int d = (s >> (j - 1)) & 1;
						F[i + 1][j - 1][s] += v;
						F[i][0][s >> j] += v;
						for (int l = j - 1; l > 0; l--)
							if (((s >> (l - 1)) & 1) != d)
							{
								int t = ((s >> j) << l) | (s & ((1 << l) - 1));
								F[i + 1][l - 1][t] += v;
								break;
							}
					}
		for (int i = n; ~i; i--)
			for (int j = 0; j < 1 << i; j++)
				if (F[i][0][j] >= k)
				{
					for (int l = i - 1; ~l; l--)	
						putchar('0' + ((j >> l) & 1));
					return;
				}
	}
}

int main()
{
	TYC::work();
	return 0;
}

Measured memory_bytes: 167552
from itertools import product

D, G = map(int, input().split())
score = []
for i in range(D):
    p, c = map(int, input().split())
    s = (i + 1) * 100
    score.append([s, p, c, s * p + c])

ans = float('inf')
for ptn in product([0, 1], repeat=D):
    total = 0
    cnt = 0
    for i in range(D):
        total += score[i][3] * ptn[i]
        cnt += score[i][1] * ptn[i]

    if 0 in ptn[::-1]:
        i = D - 1 - ptn[::-1].index(0)
        x = score[i]
    else:
        x = score[-1]

    for i in range(x[1]):
        if total >= G:
            break
        total += x[0]
        cnt += 1

    if total < G:
        cnt = float('inf')
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 3064
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    s = input()
    if s.isupper():
        print("A")
    else:
        print("a")
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9492
var
    s1,s2,s3:ansistring;//数据可能很大，所以要用这个
    i:longint;
    b:boolean;
begin
    readln(s1);
    readln(s2);
    if(length(s1)<length(s2))then//判断最长的，好循环
    begin
        s3:=s1;
        s1:=s2;
        s2:=s3;
    end;
    if(length(s1)<>length(s2))then b:=true;//不等于就标记，不然少的那个会爆
    if(b)then
    begin
        for i:=1 to length(s1)-1 do//不等情况下
        begin
            write(s1[i],s2[i]);
        end;
        write(s1[length(s1)]);//要把没输出的补上
    end
    else
    begin
        for i:=1 to length(s1) do//正常情况
        begin
            write(s1[i],s2[i]);
        end;
    end;
end.

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

int h, w;

bool inside(int y, int x) {
  return 0 <= y && y < h && 0 <= x && x < w;
}

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

  vector<vector<char>> a(h, vector<char>(w));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> a[i][j];
    }
  }

  int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a[i][j] == '#') continue;
      char cnt = '0';
      for (int k = 0; k < 8; ++k) {
        int ny = i + dy[k];
        int nx = j + dx[k];
        if (inside(ny, nx) && a[ny][nx] == '#') cnt++;
      }

      a[i][j] = cnt;
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cout << a[i][j];
    }
    puts("");
  }
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class BBiteEating {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), l = s.nextInt(), min = Integer.MAX_VALUE, ans = 0, m = Integer.MAX_VALUE;
            for (int i = 1; i <= n; i++) {
                if (min > Math.abs(l + i - 1)) {
                    min = Math.abs(l + i - 1);
                    m = l + i - 1;
                }
                ans += l + i - 1;
            }
            w.println(ans - m);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

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

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

int main() {
	int n;
	cin >> n;
	int d[105] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j > i; j--) {
			if (d[j] > d[j - 1]) {
				swap(d[j], d[j - 1]);
			}
		}
	}
	
	int nownum = 0;
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (d[i] != nownum) {
			count++;
		}
		nownum = d[i];
	}
	cout << count << endl;
	return 0;
}

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

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

int main() {
    string s;
    cin >> s;
    int n = s.length();

    cout << s[0] << n-2 << s[n-1] << endl;

    return 0;
}

Measured memory_bytes: 3612
from sys import stdin

n = int(stdin.readline().rstrip())
dic = {}
for _ in range(n):
    ope = stdin.readline().rstrip().split()
    if ope[0] == "insert":
        dic[ope[1]] = True
    elif ope[0] == "find":
        if dic.get(ope[1], False):
            print("yes")
        else:
            print("no")


Measured memory_bytes: 33440
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main(void)
{
    int64_t N;
    cin >> N;

    cout << ((N%1000) ? (1000-N%1000) : 0);
    
    return 0;
}


Measured memory_bytes: 3176
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n,m = map(int,input().split())
ab =[]
cd =[]
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b])
for i in range(m):
    c,d = map(int,input().split())
    cd.append([c,d])

for i in range(n):
    d = 1000000000
    check = 0
    for j in range(m):
        man = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1])
        if man<d:
            d = man
            check = j
    print(check+1)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define Q int tt,qq; cin>>tt ;for(qq=1;qq<=tt;qq++)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main()
{
    int n;
    cin>>n;
    vector<int>a(n),b(n),c(n-1);
    for(int i=0;i<n;i++)    cin>>a[i];
    for(int i=0;i<n;i++)    cin>>b[i];
    for(int i=0;i<n-1;i++)  cin>>c[i];
    for(int i=0;i<n;i++){
        a[i]=a[i]-1;
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=b[a[i]];
        if(a[i+1]-a[i]==1)
            sum+=c[a[i]];
    }
    cout<<sum;

}


Measured memory_bytes: 3624
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

#include <cstdint>

template <std::size_t MOD>
class ModuloInteger
{
public:
    ModuloInteger(const std::size_t init)
        : value(init)
    {
    }

    ModuloInteger operator+(const ModuloInteger& value);
    void operator+=(const ModuloInteger& value);

    ModuloInteger operator-(const ModuloInteger& value);
    void operator-=(const ModuloInteger& value);

    ModuloInteger operator*(const ModuloInteger& value);
    void operator*=(const ModuloInteger& value);

    std::size_t value;
};

template <std::size_t MOD>
ModuloInteger<MOD> ModuloInteger<MOD>::operator+(const ModuloInteger& value)
{
    return (this->value + value.value) % MOD;
}

template <std::size_t MOD>
void ModuloInteger<MOD>::operator+=(const ModuloInteger& value)
{
    this->value = (this->value + value.value) % MOD;
}

template <std::size_t MOD>
ModuloInteger<MOD> ModuloInteger<MOD>::operator-(const ModuloInteger& value)
{
    return (this->value + MOD - value.value) % MOD;
}

template <std::size_t MOD>
void ModuloInteger<MOD>::operator-=(const ModuloInteger& value)
{
    this->value = (this->value - value.value) % MOD;
}

template <std::size_t MOD>
ModuloInteger<MOD> ModuloInteger<MOD>::operator*(const ModuloInteger& value)
{
    return (this->value * value.value) % MOD;
}

template <std::size_t MOD>
void ModuloInteger<MOD>::operator*=(const ModuloInteger& value)
{
    this->value = (this->value * value.value) % MOD;
}

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

    constexpr std::size_t MOD = 1000000007;

    vector<string> table(h);
    for (int i = 0; i < h; i++)
    {
        cin >> table[i];
    }

    vector<vector<ModuloInteger<MOD>>> dp(h, vector<ModuloInteger<MOD>>(w, 0));
    dp[0][0] = 1;

    for (int i = 1; i < w; i++)
    {
        if (table[0][i] == '.')
        {
            dp[0][i] = dp[0][i - 1];
        }
    }

    for (int i = 1; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (table[i][j] == '.')
            {
                dp[i][j] = dp[i - 1][j];
                if (j > 0)
                {
                    dp[i][j] += dp[i][j - 1];
                }
            }
        }
    }
    cout << dp[h - 1][w - 1].value << endl;
}

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

int main(){

    ll N, x;
    cin >> N >> x;

    vector<int> a(N);
    for (ll i=0; i<N; i++){
        cin >> a.at(i);
    }

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

    ll ans = 0;
    for (ll i=0; i<N; i++){
        x -= a.at(i);
        ans++;

        if (x<0) {
            ans--;
            break;
        }
    }
    if (x > 0){
        ans--;
    }

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

Measured memory_bytes: 256
N,W=map(int,input().split())

def solve_knapsack(capacity):
    # basic checks
 
    dp = [0]*(capacity + 1)
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit

    for i in range(0, N):
        weights,profits = map(int,input().split())
        for c in range(capacity, weights-1, -1):
            tmp = profits + dp[c - weights]
            if tmp > dp[c]: dp[c] = tmp
 
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]
  
def main():
 
    res = solve_knapsack(W)
 
    print(res)
if __name__ == "__main__":
	main()

Measured memory_bytes: 9460
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static final BigInteger ZERO = BigInteger.ZERO;
    public static final BigInteger ONE = BigInteger.ONE;
    public static final BigInteger TWO = ONE.add(ONE);

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int [] Ai = new int[N+1];

        for (int i = 0; i < M; i++) {

            Ai[Integer.parseInt(sc.next())] = -1;
        }

        sc.close();

        BigInteger ans = fanc(N,Ai);

        System.out.println(ans.remainder(BigInteger.valueOf(1000000007)));
    }

    public static BigInteger fanc(int N, int[] Ai) {

        BigInteger[] dp = new BigInteger[N+1];

        dp[0] = ONE;
        dp[1] = (Ai[1] == -1) ? ZERO : ONE;

        for (int i = 2; i <= N; i++ )  {

            dp[i-2] = (Ai[i-2] == -1) ? ZERO : dp[i-2];
            dp[i-1] = (Ai[i-1] == -1) ? ZERO : dp[i-1];

            dp[i] = dp[i-2].add(dp[i-1]);
        }

        return dp[N];
    }
}

Measured memory_bytes: 664296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  if (A > B) {
    if (B == 1) cout << "Bob" << endl;
    else cout << "Alice" << endl;
  }
  else if (A < B) {
    if (A == 1) cout << "Alice" << endl;
    else cout << "Bob" << endl;
  }
  else cout << "Draw" << endl;
}

Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    S = [list(input().split()) for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "snuke":
                x = chr(ord('A') + j)
                print(x + str(i+1))
                return


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
S = input()
T = input()

def turn(S,T,i):
    return S[i:] + S[:i]


def isOk(S,T):
    for i in range(len(S)):
        if turn(S,T,i) == T:
            print("Yes")
            return
    print("No")

isOk(S,T)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
using std::swap;
#define rep(i,n) for(int i=0;i<n;i++)

vector <pair<pair<string, int>,int>> v;
int main()
{
	int N;
	cin >> N;
	v.resize(N);
	rep(i, N) {
		string a;
		int b;
		cin >> a >> b;
		v[i].first = make_pair(a,b*(-1));
		v[i].second = i+1;
	}
	sort(v.begin(), v.end());
	rep(i, N)cout << v[i].second << "\n";
	return 0;
}


Measured memory_bytes: 256
n=int(input())
arr=[input() for _ in range(n)]
dic={}
check='abcdefghijklmnopqrstuvwxyz'
for s in arr:
  count=[0]*26
  for i in range(10):
    for j in range(26):
      if s[i]==check[j]:
        count[j]+=1
        break
  count=tuple(count)
  if count not in dic:
    dic[count]=1
  else:
    dic[count]+=1
ans=0
for val in dic.values():
  ans+=val*(val-1)//2
print(ans)

Measured memory_bytes: 120580
n, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
for i in range(n + 1):
    if sum(A[:i]) > x:
        print(i - 1)
        exit()
    elif sum(A[:i]) == x:
        print(i)
        exit()
print(n - 1)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
vector<vector<int>> v(100010);
vector<vector<int>> inv(100010);
int a[100010];

bool used[100010];
int ans = 0;
int n,k;


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
        if(a[i]>=0){
            v[i].push_back(a[i]);
            inv[a[i]].push_back(i);
        }
    }
    queue<int> q;
    for(int i=0;i<n;i++){
        if(a[i]==-1){
            ans++;
            used[i] = true;
            continue;
        }
        if(inv[i].size()==0){
            q.push(i);
        }
    }
    int d[n] = {};
    while(q.size()){
        int t = q.front(); q.pop();
        if(!used[t]) ans++;
        used[t] = true;
        for(auto i:v[t]){
            if(!used[i] && d[t]+1<k){
                if(d[i]==0){
                    d[i] = d[t]+1;
                    q.push(i);
                }
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 14700
#include <stdio.h>
#include <math.h>
int main(void){
  int n,k,sum=1,i;
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    sum=fmin(sum*2,sum+k);
  }
  printf("%d",sum);
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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

int main(){
	ll N,M; cin>>N>>M;
	priority_queue<ll> que;
	rep(i,N){
		ll x; cin>>x;
		que.push(x);
	}
	rep(i,M){
		ll t=que.top(); que.pop();
		que.push(t/2);
	}
	ll ans=0;
	while(!que.empty()){
		ll tmp=que.top(); que.pop();
		ans+=tmp;
	}
	cout<<ans;
}

Measured memory_bytes: 1400
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        if (S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35628
from collections import deque

def resolve():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))

    q = deque()
    diffs = set()

    for i in range(n):
        if bb[i] != aa[i]:
            diffs.add(i)

        bef_i = i-1 if i > 0 else n-1
        aft_i = i+1 if i < n-1 else 0
        if bb[i] > aa[i] and bb[i] > bb[bef_i] + bb[aft_i]:
            q.append(i)

    count = 0

    while len(q) > 0:
        i = q.popleft()

        bef_i = i-1 if i > 0 else n-1
        bef2_i = bef_i-1 if bef_i > 0 else n-1
        aft_i = i+1 if i < n-1 else 0
        aft2_i = aft_i+1 if aft_i < n-1 else 0

        count += (bb[i] - aa[i]) // (bb[bef_i] + bb[aft_i])
        bb[i] = (bb[i] - aa[i]) % (bb[bef_i] + bb[aft_i]) + aa[i]

        if bb[i] == aa[i]:
            diffs.remove(i)

        if bb[bef_i] > aa[bef_i] and bb[bef_i] > bb[bef2_i] + bb[i]:
            q.append(bef_i)

        if bb[aft_i] > aa[aft_i] and bb[aft_i] > bb[aft2_i] + bb[i]:
            q.append(aft_i)

    if len(diffs) > 0:
        print(-1)
        return

    print(count)
resolve()

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

int main() {
    string s;
    cin >> s;
    if (s.compare("ABC") == 0) {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>

using namespace std;

const int maxn=1e5+5;

typedef long long LL;

int n,k,s[maxn];

int res(LL p)
{
	int i=0;
	for(int j=0;j<k;j++){
		LL temp=0;
		while(temp+s[i]<=p){
			temp+=s[i];
			i++;
			if(i==n){
				return n;
			}
		}
	}
	return i;
}

LL solve()
{
	LL left=0,right=100000*10000,mid;
	while(left<right){
		mid=left+((right-left)>>1);
		int v=res(mid);
		if(v>=n){
			right=mid;
		}else{
			left=mid+1;
		}
	}
	return right;
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&s[i]);
	}
	LL ans=solve();
	cout<<ans<<endl;
	return 0;
}
/*
5 3
8 
1 
7
3
9
*/


Measured memory_bytes: 3524
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int A,B;
    cin >> A >> B;
    if(A*B%2==0){
        cout << "No";
    }else{
        cout << "Yes";
    }
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;
signed main(){
    int n;
    cin >> n;
    vector<vector<int>> a(2,vector<int>(n));
    REP(i,2){
        REP(j,n){
            int d;
            cin >> d;
            a[i][j] = d;
        }
    }
    int ans = 0;
    REP(i,n){
        int e=0;
        REP(j,i+1){
            e += a[0][j];
        }
        FOR(j,i,n){
            e += a[1][j];
        }
        ans = max(ans,e);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		//String t = sc.next();
		//String g = sc.next();
		long n = sc.nextLong();
		long m = sc.nextLong();
		long k = sc.nextLong();
		//long l = sc.nextLong();
		//String buff="Christmas";
		long count=0;
		long[] array=new long[3];

		/*for(long i=n;i<25;i++) {
			buff+=" Eve";
		}*/
		Arrays.sort(array);
		/*if(n==3||n==5||n==7) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}*/
		System.out.println(n*m/2);
		//System.out.println(Math.abs(array[2]-array[1])+Math.abs(array[1]-array[0]));
	}
}




Measured memory_bytes: 21716
<?php
function dfs($s, $mx){
    global $N;
    if(strlen($s) == $N){
        printf("%s\n", $s);
    } else {
        for($c = ord('a'); $c <= ord($mx); $c++) {
            dfs($s . chr($c), (($c === ord($mx)) ? chr(ord($mx) + 1) : chr(ord($mx))));
        }
    }
}
fscanf(STDIN, "%d", $N);
dfs('', 'a');


Measured memory_bytes: 5880
#include<iostream>
#include<cstring>

using namespace std;

typedef long long ll;

ll pow(int b, int p){
	ll ret = 1;
	while(p > 0){
		ret = 1LL * ret * b;
		--p;
	}
	return ret;
}

int fr[3];

int clac(int n, int len, ll cur){
	if(len == 0){
		if(cur <= n && fr[0] > 0 && fr[1] > 0 && fr[2] > 0) return 1;
		else return 0;
	}
	int ret = 0;
	++fr[0];
	ret += clac(n, len - 1, cur + 3 * pow(10, len - 1));
	--fr[0];

	++fr[1];
	ret += clac(n, len - 1, cur + 5 * pow(10, len - 1));
	--fr[1];

	++fr[2];
	ret += clac(n, len - 1, cur + 7 * pow(10, len - 1));
	--fr[2];

	return ret;
}


int main(){
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);

	std::ios_base::sync_with_stdio(false), cin.tie(0);

	int n, temp, len = 0, ans = 0;
	cin >> n;
	temp = n;
	while(temp > 0){
		temp /= 10;
		++len;
		ans += clac(n, len, 0);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> P(1000000),Y(1000000);
  vector<int> yd[100001];
  for(int i=0; i<M; i++){
    cin >> P[i] >> Y[i];
    yd[P[i]].push_back(Y[i]);
  }
  for(int i=0; i<N; i++){
    sort(yd[i+1].begin(),yd[i+1].end());
  }
  for(int i=0; i<M; i++){
    cout << setfill('0') << right << setw(6) << P[i];
    cout << setfill('0') << right << setw(6) << lower_bound(yd[P[i]].begin(),yd[P[i]].end(),Y[i])-(yd[P[i]].begin())+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 14848
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
int main()
{
	int n,m,q,k;
	cin>>n>>m;
	if(m>=n) cout<<"unsafe";
	else cout<<"safe";
}


Measured memory_bytes: 3136
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>

int N;

int Ns[210000];

int main()
{
	scanf("%d",&N);
	int wi;
	for(wi=1;wi<=N;++wi)	
	{
		scanf("%d",Ns+wi);
		Ns[wi]-=wi;
	}
	std::sort(Ns+1,Ns+1+N);
	long long Ans=0;
	for(wi=1;wi<(N+1)/2;++wi)
		Ans+=Ns[(N+1)/2]-Ns[wi];
	for(wi=(N+1)/2;wi<=N;++wi)
		Ans+=Ns[wi]-Ns[(N+1)/2];
	std::cout<<Ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a;
  string b;
  cin>>a>>b;
  if(a>=3200)cout<<b;
  else cout<<"red";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<string>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())
#define INF 1e5
int main(){
	ll n;
	cin>>n;
	cout<<n*(n-1)/2<<endl;
}
	

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

struct Card {
	char suit;
	int number;
	int order;
};

int partition(vector<Card>& A, int p, int r)
{
	int x = A[r].number;
	int i = p - 1;

	for (int j = p; j < r; ++j)
		if (A[j].number <= x)
			i++, swap(A[i], A[j]);
	swap(A[i + 1], A[r]);

	return i + 1;
}

void quick_sort(vector<Card>& A, int p, int r)
{
	if (p < r)
	{
		int q = partition(A, p, r);
		quick_sort(A, p, q - 1);
		quick_sort(A, q + 1, r);
	}
}

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

	int n;
	cin >> n;

	vector<Card> A(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> A[i].suit >> A[i].number;
		A[i].order = i;
	}

	quick_sort(A, 0, n - 1);

	bool stable = true;
	for (int i = 0; i < n; ++i)
		if (A[i].number == A[i + 1].number && A[i].order > A[i + 1].order)
			stable = false;

	cout << (stable ? "Stable" : "Not stable") << endl;

	for (int i = 0; i < n; ++i)
		cout << A[i].suit << " " << A[i].number << endl;

	return 0;
}

Measured memory_bytes: 2324
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int main()
{
    int n,w;
    while(cin >> n >> w) {
        if(n == 0 && w == 0) break;

        int cnt[1005];
        memset(cnt,0,sizeof(cnt));
        
        int seg = 0;
        rep(i,n) {
            int x;
            cin >> x;
            cnt[x/w]++;

            seg = max(seg,x/w);
        }

        int vmax = 0;
        rep(i,1005) {
            vmax = max(vmax,cnt[i]);
        }

        double ans = 0;
        rep(i,seg+1) {
            ans += (seg - i) /(double)seg * (cnt[i] / (double)vmax);
        }

        cout << fixed;
        cout.precision(10);
        cout << ans + 0.01 << endl;

    }

    return 0;
}

Measured memory_bytes: 1236
def b_or_w(b_1, b_2, b_3):
    b, w = 'bbb', 'www'
    board = [b_1, b_2, b_3]
    for i in range(3):
        col = b_1[i] + b_2[i] + b_3[i]
        board.append(col)
    board.append(b_1[0] + b_2[1] + b_3[2])
    board.append(b_1[2] + b_2[1] + b_3[0])
    for bod in board:
        if bod == b:
            return 'b'
        elif bod == w:
            return 'w'
    else:
        return 'NA'

while True:
    b_1 = input()
    if b_1 == '0': break
    b_2, b_3 = input(), input()
    print(b_or_w(b_1, b_2, b_3))



Measured memory_bytes: 5556
def resolve():
    S = str(input())
    S_size = len(S)
    S_reverse = S[::-1]
    count = (S_size - 1) / 2
    next_s = S[0:int(count)]
    extt2_s = S[int((S_size + 3) / 2)::S_size]

    if S == S_reverse and next_s == next_s[::-1] and extt2_s == extt2_s[::-1]:
        print("Yes")
    else:
        print("No")
resolve()

Measured memory_bytes: 38384
# Picture Frame

h,w = map(int,input().split())
a = []
for i in range(h):
    a.append(input())

print('#' * (len(a[0])+2))
for i in range(len(a)):
    print( '#'+ a[i] +'#' )
print('#' * (len(a[0])+2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s[2]==s[3] && s[4]==s[5]){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }
  return 0;
}


Measured memory_bytes: 256