akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);

  rep(i, 0, 500000 + 1) {
    if (floor(double(i) * 1.08) == N) {
      put(i);
      return 0;
    }
  }

  put(":(");
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int h,w,n;
    cin >> h >> w >> n;
    map <int,int> x,y;
    pair <int,int> ar[n];
    int mx=0,my=0;
    for(int i=0;i<n;i++){
    	int u,v;
    	cin >> u >> v;
    	ar[i]={u,v};
    	x[u]++,y[v]++;
    	mx=max(mx,x[u]),my=max(my,y[v]);
    }
    set <int> a,b;
    for(auto [key,val]:x){
    	if(val==mx)a.insert(key);
    }
    for(auto [key,val]:y){
    	if(val==my)b.insert(key);
    }
    int cnt=0;
    for(int i=0;i<n;i++){
    	auto [u,v]=ar[i];
    	if(a.count(u) and b.count(v))
    		cnt++;
    }
    int ans=mx+my;
    if(cnt>=(int)a.size()*(int)b.size())
    	ans--;
    cout << ans;
}

Measured memory_bytes: 73868
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	const int MAX=100001;
	ll tes[MAX]={};
	ll N,K;
	cin>>N>>K;
	for(int i=0;i<N;i++){
		int a,b;
		cin>>a>>b;
		tes[a]+=b;
	}
	ll count=0;
	for(int i=1;i<=MAX;i++){
		count+=tes[i];
		if(count>=K){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


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

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

    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;

    long long ans, bn;
    bn = min({A, B, C, D, E});
    ans = 4 + N / bn + (N % bn == 0 ? 0 : 1);
    
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main()
{
    int q, h, s, d;
    int n;
    cin >> q >> h >> s >> d;
    cin >> n;
    q *= 4;
    h *= 2;
    s = min(q, min(h, s));
    if (2 * s > d){
        cout << (n / 2) * 1ll * d + (n % 2) * 1ll * s << endl;
    } else {
        cout << s * 1ll * n << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int arr[101];
int main(){

	int x, n;
	cin>>x>>n;
	for(int i=0; i<n; i++){
		int a; cin>>a;
		arr[a]++;
	}
	int i=x;
	int d1=0, d2=0;
	while(1){
		if(arr[i]==0){
			d1 = i; break;
		}
		if(i==101)break;
		i++;
	}
	i=x;
	while(1){
		if(arr[i]==0){
			d2 = i; break;
		}
		if(i==0)break;
		i--;
	}
	int d3 = abs(d1-x);
	int d4 = abs(d2-x);
	if(d3==d4)cout<<min(d1, d2)<<endl;
	else if(d3<=d4)cout<<d1<<endl;
	else cout<<d2<<endl;

return 0;

}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define int long long
using namespace std;

signed main() {
	int n, w;
	cin >> n >> w;
	vector <int> wt(n+1), vl(n+1);
	for (int i=1; i<=n; i++) {
		cin >> wt[i] >> vl[i];
	}
	vector < vector <int> > ans(w+1, vector <int>(n + 1, 0));
	for (int i=0; i<=w; i++) {
		for (int j=1; j<=n; j++) {
			ans[i][j] = ans[i][j - 1];
			if (wt[j] <= i) {
				ans[i][j] = max(ans[i][j], ans[i - wt[j]][j - 1] + vl[j]);
			}
		}
	}
	cout << ans[w][n] << endl;
}


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

 
int main(){
    ll N,K,count=0;
    cin >> N >> K;
    for(ll i=K; i<=N+1; i++){
       ll a=i*(2*N-i+1)/2;
       ll b=i*(i-1)/2;
       count=count+a-b+1;
       count%=1000000007;
    }
        cout << count << endl;
       
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,c[16],x[20001];
  int dp1[256],dp2[256];

  while(cin>>n>>m,n|m){

  for(int i=0;i<m;i++) cin>>c[i];
  for(int i=1;i<n+1;i++) cin>>x[i];
  for(int j=0;j<256;j++) dp1[j]=1145141919;
  for(int j=0;j<256;j++) dp2[j]=1145141919;
  dp1[128]=0;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<256;j++){
      if(dp1[j]!=1145141919){
        for(int k=0;k<m;k++){
          int tmp=j+c[k];
          if(tmp<0) tmp=0;
          if(tmp>255) tmp=255;
          dp2[tmp]=min(dp2[tmp],dp1[j]+(int)pow(x[i+1]-tmp,2));
        }
      }
    }
    for(int j=0;j<256;j++){
      dp1[j]=dp2[j];
      dp2[j]=1145141919;
    }
  }
  for(int i=1;i<256;i++) dp1[i]=min(dp1[i],dp1[i-1]);
  cout<<dp1[255]<<endl;
  }
  
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> xys(n);
    for(auto& e : xys){
        int a;
        cin >> a;
        vector<pair<int, int>> xy(a);
        for(auto& f : xy) cin >> f.first >> f.second, f.first--;
        e = move(xy);
    }

    int ans = 0;
    for(int bit = 0; bit < (1 << n); bit++){
        vector<int> h(n, -1);
        bool discard = false;
        for(int i = 0; i < n; i++){
            if(!((bit >> i) & 1)) continue;
            for(auto& e : xys[i]){
                if(h[e.first] != -1 && h[e.first] != e.second) discard = true;
                if(e.second != (bit >> e.first & 1)) discard = true;
                h[e.first] = e.second;
            }
        }
        if(discard) continue;
        ans = max(ans, (int) bitset<15>(bit).count());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }

constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

constexpr int MAX_N = 100000;

bool vis[MAX_N+10];

int main(){
    int N;
    cin>>N;
    vector<int> p(N);
    rep(i,N){
        cin>>p[i];
    }

    fill(vis,vis+MAX_N+10,false);

    priority_queue<pii,vector<pii>,greater<pii>> que;
    que.push(pii(0,0));
//    vis[0] = true;
    while(!que.empty()){
        pii q = que.top();
        que.pop();

        int u = q.second;
        int cnt = q.first;

//        cout << "pop : u=" << u << " cnt=" << cnt << endl; 

        if(u>=N-1){
            cout << cnt << endl;
            return 0;
        }

        if(vis[u]) continue;
        vis[u] = true;

        if(p[u]==0){
            for(int i=1;i<=6;i++){
                int nxt = u+i;
                if(!vis[nxt]){
                    que.push(pii(cnt+1,nxt));
                }
            }
        }else{
            int nxt = u+p[u];
            if(!vis[nxt]){
                que.push(pii(cnt,nxt));
            }
        }
    }
    cerr << "NO ANSWER" << endl;
}

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

int main(void) {
	int N;
	char s[128];
	char t[128];
	int i;
	if (scanf("%d", &N) != 1) return 1;
	if (scanf("%127s", s) != 1) return 1;
	if (scanf("%127s", t) != 1) return 1;
	for (i = N; i > 0; i--) {
		if (strncmp(s + N - i, t, i) == 0) {
			printf("%d\n", N + N - i);
			return 0;
		}
	}
	printf("%d\n", N + N);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
int n,a,b,c,d;
char str[20];
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) {
		scanf("%s",&str);
		if (str[0]=='A') ++a;
		if (str[0]=='W') ++b;
		if (str[0]=='T') ++c;
		if (str[0]=='R') ++d;
	}
	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a,b,c,d);
	
	return 0;
} 

Measured memory_bytes: 1732
import java.util.*;
import static java.lang.Math.abs;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int[]antena = new int[5];
        for(int i = 0; i < 5; i++){
            antena[i]=  scan.nextInt();
        }

        int k = scan.nextInt();

        int k0 = 0;
        for(int i = 0; i < 5; i++){

            for(int j = i+1; j < 5; j++){
                k0 = antena[i] - antena[j];
                
                if(k < abs(k0)){
                    System.out.println(":(");
                    return;
                }
            }
        }

        System.out.println("Yay!");
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int x,y,z; cin >> x >> y >> z;
    cout << z <<" "<< x <<" "<< y << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    string N;cin>>N;
    int K;cin>>K;
    vector<vector<vector<ll>>> dp(N.size(),vector<vector<ll>>(K+1,vector<ll>(2,0)));
    dp[0][0][0]=1;
    dp[0][1][0]=N[0]-'0'-1;
    dp[0][1][1]=1;
    rep(i,1,N.size()){
        REP(j,K+1){
            dp[i][j][0]+=dp[i-1][j][0];
            if(N[i]!='0'){
                dp[i][j][0]+=dp[i-1][j][1];
                if(j>0){
                    dp[i][j][0]+=(N[i]-'0'-1)*dp[i-1][j-1][1];
                    dp[i][j][1]+=dp[i-1][j-1][1];
                }
            }
            else dp[i][j][1]+=dp[i-1][j][1];
            if(j>0) dp[i][j][0]+=9*dp[i-1][j-1][0];
            // cout<<i<<" "<<j<<" "<<dp[i][j][0]<<" "<<dp[i][j][1]<<endl;
        }
    }
    cout<<dp[N.size()-1][K][0]+dp[N.size()-1][K][1]<<endl;
}

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

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define in(type,a) type a;cin >> a
using ll = long long;

int main() {
    in(int, a);
    in(int, b);
    if (a >= 13) {
        cout << b << endl;
    }else if(a <= 5){
        cout << 0 << endl;
    }else{
        cout << b/2 << endl;
    }
    return 0;
}


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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int N;
    cin >> N;
    vi H(N);
    rep(i, N)cin >> H[i];
    int ans = 0;
    for(int j = 0; j < N; j++){
        int mi = infi;

        int i = 0;
        while(H[i] <= 0)i++;
        int k = i;
        for(; k< N && H[k] > 0; k++){
            mi = min(H[k], mi);
        }
        if(mi <0 || mi == infi) continue;
        for(; i<k; i++)H[i]-=mi;
        ans += mi;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

struct Problem {

	void Solve() {

		int N; cin >> N;
		int X, Y; cin >> X >> Y; X--; Y--;
		vector<UL> ans(N);
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int tmp = j - i;
				tmp = min(tmp, abs(j - Y) + abs(i - X) + 1);
				tmp = min(tmp, abs(i - Y) + abs(j - X) + 1);
				ans[tmp] ++;
			}
		}
		for (UL i = 1; i < N; i++) {
			cout << ans[i] << endl;
		}
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,h[100009],m[100009];

int main(){
    cin>>n;
    for(int i =1;i<=n;i++){
        cin>>h[i];
        m[i] = 1e9;
    }
    m[1] = 0;
    for(int i = 1;i<=n;i++)
        for(int j = i+1;j<=i+2;j++)
            if(j<=n)
                m[j] = min(m[j],m[i]+ abs(h[i]-h[j]));
    cout<<m[n]<<endl;

}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    int i,x[5];
    for(i=0;i<5;i++){
        scanf("%d",&x[i]);
    }

    for(i=0;i<5;i++){
        if(x[i]==0) break;
    }
    
    printf("%d\n",i+1);
    return 0;
}

Measured memory_bytes: 1676
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int d = sc.nextInt();
        
        int count = 0;
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= d; j++) {
                int d1 = j / 10;
                int d2 = j % 10;
                
                if (d1 >= 2 && d2 >= 2 && d1 * d2 == i) {
                    // System.out.println(i)
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        char a = sc.next().charAt(0);
        char b = sc.next().charAt(0);
      
        if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D')) {
        	System.out.println("H");
        } else {
        	System.out.println("D");
        }
    }
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int w, h;
const int MAX_H = 30;
const int MAX_W = 30;
const int MAX_T = 12;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
char c[MAX_H][MAX_W+1];
int d[MAX_H][MAX_W][MAX_H][MAX_W];
int dp[1<<MAX_T][MAX_T];
int sx, sy;

inline bool check(int hx, int hy){ return 0 <= hx && hx < h && 0 <= hy && hy < w; }

int main()
{
  while(cin >> w >> h, h){
    rep(i, h) rep(j, w) rep(k, h) rep(l, w) d[i][j][k][l] = INF;
    rep(i, h) rep(j, w) cin >> c[i][j];
    rep(i, h) rep(j, w) if(c[i][j] == 'o') sx = i,  sy = j;

    rep(i, h) rep(j, w) d[i][j][i][j] = 0;
    rep(i, h) rep(j, w) rep(k, 4) if(c[i][j] != 'x'){
      int nx = i + dx[k];
      int ny = j + dy[k];
      if(check(nx, ny)){
        if(c[nx][ny] != 'x') d[i][j][nx][ny] = 1;
        if(c[nx][ny] == 'x') d[i][j][nx][ny] = INF;
      }
    }

    rep(k1, h) rep(k2, w) rep(i1, h) rep(i2, w) rep(j1, h) rep(j2, w) minup(d[i1][i2][j1][j2], d[i1][i2][k1][k2] + d[k1][k2][j1][j2]);

    vii vec;
    int n = 0;
    rep(i, h) rep(j, w) if(c[i][j] == '*'){
      n += 1;
      vec.pb(mp(i, j));
    }

    rep(i, 1 << n) rep(j, n) dp[i][j] = INF;
    rep(i, n) dp[1 << i][i] = d[sx][sy][vec[i].first][vec[i].second];

    rep(S, 1 << n) rep(v, n) rep(u, n) minup(dp[S | 1 << u][u], dp[S][v] + d[vec[v].first][vec[v].second][vec[u].first][vec[u].second]);

    int res = INF;
    rep(i, n) minup(res, dp[(1 << n) - 1][i]);
    cout << (res >= INF ? -1 : res) << endl;
  }

  return 0;
}

Measured memory_bytes: 2680
import java.util.*;

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

    int h = sc.nextInt();
    int w = sc.nextInt();

    String s[] = new String[h];
    for (int i = 0; i < h ; i++) {
      s[i] = sc.next();
    }
    
    String t[] = new String[w];
    for (int i = 0; i < h ; i++) {
      String b = "";
      for (int j = 0; j < w; j++) {
        int a = 0;
        if (s[i].substring(j, j+1).equals("#")){
          b += "#";
        } else {
          if (i > 0 && j > 0 && s[i-1].substring(j-1, j).equals("#")) a++;
          if (i > 0 && s[i-1].substring(j, j+1).equals("#")) a++;
          if (i > 0 && j < w-1 && s[i-1].substring(j+1, j+2).equals("#")) a++;
          if (j > 0 && s[i].substring(j-1, j).equals("#")) a++;
          if ( j < w-1 && s[i].substring(j+1, j+2).equals("#")) a++;
          if (i < h-1 && j > 0 && s[i+1].substring(j-1, j).equals("#")) a++;
          if (i < h-1 && s[i+1].substring(j, j+1).equals("#")) a++;
          if (i < h-1 && j < w-1 && s[i+1].substring(j+1, j+2).equals("#")) a++;
          b += String.valueOf(a);
        }
      }
      System.out.println(b);
    }

  }  
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int sumA=0, sumB=0;
  for(int i=0; i<N; i+=2) {
    sumA+=vec.at(i);
  }
  for(int i=1; i<N; i+=2) {
    sumB+=vec.at(i);
  }
  int answer=sumA-sumB;
  cout << answer << endl;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int d;
    int tmp;
    rep(i, k)
    {
        cin >> d;
        rep(j, d)
        {
            cin >> tmp;
            a[tmp - 1]++;
        }
    }
    int cnt = 0;
    rep(i, n)
    {
        if (a[i] == 0)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

class Graph{
private:
 vector< vector<unsigned long> > graph;
public:

 Graph(unsigned long num) : graph(num+1, vector<unsigned long>(num+1, 0)){
  for(unsigned long row_i = 0; row_i < num; ++row_i){
   unsigned long nodeNum = 0; cin >> nodeNum;
   unsigned long nodeMax = 0; cin >> nodeMax;

   for(unsigned long node_i = 0; node_i < nodeMax; ++node_i){
    unsigned long adjectNode = 0; cin >> adjectNode;

    graph[nodeNum][adjectNode] = 1;
   }
  }

 };

 void display(){
  for(unsigned long i = 1, num = graph.size(); i < num; ++i){
   for(unsigned long j = 1; j < num; ++j){
    if(j != 1) cout << " ";
    cout << graph[i][j];
   }
   cout << endl;
  }
 };

protected:
};

int main(){

 unsigned long num = 0; cin >> num;

 Graph g(num);
 g.display();

 return 0;
};

Measured memory_bytes: 1292
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    string S;
    io.read(S);
    S[3] = '8';
    cout << S;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    int K; cin>>K;

    int cnt=0;
    char nxt;
    REP(i,s.size()){
        if(s[i]=='1')
            cnt++;
        else{
            nxt=s[i];
            break;
        }
    }
    if(K<=cnt)
        cout<<'1'<<endl;
    else
        cout<<nxt<<endl;
 
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>
#include <functional>

using namespace std;
using ll = long long;
using ld = double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll, ll>;
const ll INF = 1e17;
const ld eps = 1e-10;
const ll MOD = 1e9 + 7;

const double pi = acos(-1.0);

vector<vector<ll>> es;
vector<bool> visited;
vector<ll> c;


T dfs(ll now, ll root, ll dist) {
	visited[now] = true;
	ll okstone = 0;
	ll ans = dist * c[now];
	ll top = 0;
	ll sum = 0;
	ll restiikanji = 0;
	ll topiikanji = 0;
	ll totalstone = c[now];
	for (auto &&e : es[now]) {
		if (!visited[e]) {
			ll one, ok, step, total;
			tie(one, ok, step, total) = dfs(e, root, dist + 1);
			totalstone += total;
			ans += step;
			okstone += ok;
			if (top < one) {
				sum += top;
				restiikanji = topiikanji;
				top = one;
				topiikanji = ok;
			}
			else {
				restiikanji += ok;
				sum += one;
			}
		}
	}
	ll iikanji;
	if (top <= sum + restiikanji) {
		iikanji = (sum + top) - ((sum + top) % 2);
	}
	else
		iikanji = sum * 2 + restiikanji;
	if (now == root) {
		if (sum + top - iikanji == 0)
			return T(ans, 0, 0, 0);
		else
			return T(INF, 0, 0, 0);
	}
	return T(sum + top - iikanji + totalstone, okstone + iikanji, ans, totalstone);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin >> N;
	string s;
	cin >> s;
	c.resize(N);
	for (int i = 0;i < N;i++)
		c[i] = s[i] == '1';
	es.resize(N);
	for (int i = 0;i < N - 1;i++) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		es[a].push_back(b);
		es[b].push_back(a);
	}
	ll ans = INF;
	for (int i = 0;i < N;i++) {
		visited.assign(N, false);
		ll tmp1, tmp2, tmp3, tmp4;
		tie(tmp1, tmp2, tmp3, tmp4) = dfs(i, i, 0);
		ans = min(ans, tmp1);
	}
	if (ans == INF)
		cout << -1 << endl;
	else
		cout << ans / 2 << endl;
	return 0;
}






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

using ll = long long int;

const int MAX_N = (int)(1e4 + 5);

int n;
ll a[MAX_N];

int ans;

int numdiv2(ll ai) {
  int cnt = 0;
  while (true) {
    if (ai % 2 == 0) {
      cnt += 1;
      ai /= 2;
    }
    else {
      break;
    }
  }
  return cnt;
}

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

  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(a[i]));
  }

  for (int i = 0; i < n; ++i) {
    ans += numdiv2(a[i]);
  }
  
  printf("%d\n", ans);

  return 0;
}


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

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

    //cout << s.substr(0,n/2) << endl;
    //cout << s.substr((n/2)+1, n-1) << endl;
    string out;
    if (n%2==0){
        if(s.substr(0,n/2)==s.substr((n/2), n-1)){
            out="Yes";
        }
        else{
            out="No";
        }
    }
    else{
        out="No";
    }
    
    cout << out << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;

main(){
    ll int n=in();
    ll int a[3],b[3];
    rep(i,3)cin>>a[i];
    rep(j,3)cin>>b[j];
    ll M=0;
    rep2(i,0,n/a[0]){
        rep2(j,0,n/a[1]){
            ll int nn=n-i*a[0]-j*a[1];
            if(nn<0)continue;
            if(a[2]<b[2])
            M=max(M,i*b[0]+j*b[1]+nn%a[2]+nn/a[2]*b[2]);
            else{
                M=max(M,b[0]*i+b[1]*j+nn);
            }
            
        }
    }
    rep(i,3)swap(a[i],b[i]);
    n=M;
    vector<int> v={0,1,2};
    sort(all(v),[&](int x,int y){
        return b[x]-a[x]>b[y]-a[y];
    });
    if(b[v[0]]<=a[v[0]])
    cout<<M;
    else{
        if(b[v[2]]>a[v[2]]){
                rep2(i,0,n/a[v[0]]){
            rep2(j,0,n/a[v[1]]){
                ll nn=n-i*a[v[0]]-j*a[v[1]];
                if(nn<0)continue;
                if(a[v[2]]<b[v[2]])
                M=max(M,i*b[v[0]]+j*b[v[1]]+nn%a[v[2]]+nn/a[v[2]]*b[v[2]]);
                else{
                    M=max(M,b[v[0]]*i+b[v[1]]*j+nn);
                }
                
            }
            }
            cout<<M;
        }
        else{
            rep2(i,0,n/a[v[0]]){
                ll nn=n-i*a[v[0]];
                if(a[v[1]]<b[v[1]]){
                    M=max(M,i*b[v[0]]+nn%a[v[1]]+nn/a[v[1]]*b[v[1]]);
                }
                else{
                    M=max(M,nn+i*b[v[0]]);
                }
            }
            cout<<M<<endl;
        }
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define long long ll;
int main() {
	int n,W,w,val;
	cin>>n>>W;
	vector<long long> dp(W+1,0);
	for(int i=0;i<n;i++){
		cin>>w>>val;
		for(int j=W;j-w>=0;j--){
			dp[j]=max(val+dp[j-w],dp[j]);
		}
	}
	cout<<dp[W];
	return 0;
}

Measured memory_bytes: 1024
h, w = map(int, input().split())

area = []
d = []

h += 2
w += 2

for i in range(h):
    if i == 0 or i == h-1:
        array = '.' * w
        area.append(array)
    else:
        array = input()
        array = '.' + array + '.'
        area.append(array)


def check(i, j):
    cnt = 0
    for x in range(i-1, i+2):
        for y in range(j-1, j+2):
            if area[x][y] == '#':
                cnt += 1
    return cnt

for i in range(1, h-1):
    for j in range(1, w-1):
        if area[i][j] == '.':
            d.append(check(i, j))
        else:
            d.append('#')
a = 0
for i in d:
    a += 1
    print(i, end='')
    if a == w-2:
        print()
        a = 0

Measured memory_bytes: 3444
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = n-1;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ans = min(ans, i+(n/i)-2);
        }
    }
    cout << ans << endl;
    return 0;
}

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

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(), v.end());
  if (v[n/2 - 1] == v[n/2]) cout << 0 << endl;
  else {
    cout << v[n/2] - v[n/2 - 1] << endl;
  }
}

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


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

int main(){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x = x2 - x1;
    int y = y2 - y1;

    cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x << endl;

}



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

/* I'm too stupid to solve this problem */

using namespace std;
#define PI 3.14159265359
#define eps 1e-7
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
const int INF = 1<<29;
typedef unsigned long long ull;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int n;

int main(){
	ios_base::sync_with_stdio(false); //Fast I/O
	cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);	

    cin >> n;
    vector<ll> A(n);
    FOR(i,0,n)
        cin >> A[i];

    int b1=0,b2=0,b3=0;
    bool ans=false;

    for(auto x: A){
        if(x%4==0)
            b2++;
        else if(x%2==0)
            b1++;
        else
            b3++;
    }
    if(b2>=b3)
        ans=true;

    ans|=(b1==0 && b3==b2+1);

    if(ans)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


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

int main() {
	int n, k, a[100000], i, S[100000], m=0;
	while (cin >> n >> k, n, k) {
		for (i = 0; i < n; i++) {
			cin >> a[i];
		}
		S[0] = 0;
		for (i = 0; i < k; i++) {
			S[0] += a[i];
		}
		for (i = 1; i < n - k + 1; i++) {
			S[i] = S[i - 1] - a[i - 1] + a[i + k - 1];
			m = max(m, S[i]);
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 1748
import math
n=int(input())
ans=[0]*(10**5)
for x in range(1,int(math.sqrt(n))+1):
  for y in range(1,int(math.sqrt(n))+1):
    for z in range(1,int(math.sqrt(n))+1):
      ans[((x+y)**2+(y+z)**2+(z+x)**2)//2-1]+=1

for i in range(n):
  print(ans[i])

Measured memory_bytes: 75248
import os, sys, re, math

N = int(input())
AB = []
for i in range(N):
    AB.append([int(n) for n in input().split()])

AB = sorted(AB, key=lambda k:k[1])

result = 'Yes'
t = 0
for ab in AB:
    t += ab[0]
    if t > ab[1]:
        result = 'No'
        break

print(result)


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define INF 1000000000000000000LL
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 45
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef pair<i64, i64> pi ;
typedef tree< pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 1000005

i64 dp[maxn] , dCnt[maxn] , mCnt[maxn] ;
char s[maxn] ;
vector <i64> ans ;
int main()
{
    int i , j , k , l , m, n , q ;

    scanf("%d",&n) ;
    scanf("%s",s+1) ;
    scanf("%d",&q) ;

    for(i=1 ; i<=q ; i++)
    {
        scanf("%d",&k) ;

        i64 res = 0LL ;
        for(j=1 ; j<=n ;  j++)
        {
            dCnt[j] = dCnt[j-1] ;
            mCnt[j] = mCnt[j-1] ;
            dp[j] = dp[j-1] ;
            if(  s[j]=='D' ) dCnt[j] += 1 ;
            if( s[j]=='M' )
            {
                mCnt[j] += 1 ;
                dp[j] += dCnt[j] ;
            }
            if( s[j]=='C' )
            {
                res += dp[j] ;
                if( j>=k )
                {
                    res = res - dp[j-k] - dCnt[j-k]*( mCnt[j]-mCnt[j-k] ) ;
                }
            }
        }
        ans.pb(res) ;
    }
    for(i=0 ; i<ans.size(); i++)
    {
        printf("%lld\n",ans[i]) ;
    }

    return 0 ;
}



Measured memory_bytes: 24704
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String s = in.next();
		int q = in.nextInt();
		boolean rev = false;
		char[] pr = new char[q];
		int ppr = 0;
		char[] po = new char[q];
		int ppo = 0;
		for (int i = 0; i < q; i++) {
			int t = in.nextInt();
			if (t == 1)
				rev ^= true;
			else {
				int f = in.nextInt();
				String c = in.next();
				if ((f == 1 && rev) || (f != 1 && !rev))
					po[ppo++] = c.charAt(0);
				else
					pr[ppr++] = c.charAt(0);
			}
		}
		if (rev) {
			System.out.print(reverse(po, ppo));
			System.out.print(reverse(s.toCharArray(), s.length()));
			System.out.println(String.valueOf(pr, 0, ppr));
		} else {
			System.out.print(reverse(pr, ppr));
			System.out.print(s);
			System.out.println(String.valueOf(po, 0, ppo));
		}
	}

	private static String reverse(char[] c, int cp) {
		char[] cr = new char[cp];
		for (int i = 0; i < cp; i++)
			cr[i] = c[cp - i - 1];

		return String.valueOf(cr);
	}
}

Measured memory_bytes: 147416
n = int(input())
strings = []
for i in range(n):
    s = input()
    s10 = []
    for j in range(10):
        s10.append(s[j])
        s10.sort()
    s = ''
    for j in range(10):
        s += s10[j]
    strings.append(s)

set_strings = dict()

for i in range(n):
    if not strings[i] in set_strings.keys():
        set_strings[strings[i]] = 1
    else:
        set_strings[strings[i]] += 1

count = 0
for num in set_strings.values():
    count += num * (num - 1) / 2
print(int(count))



Measured memory_bytes: 19460
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+')
      cnt++;
    else
      cnt--;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 110
#define INF 1e9
 
struct Edge{
    int to,f;
    Edge(int to,int f) : to(to),f(f) {}
};
 
struct State{
    int v,d,e;
    State(int v,int d,int e) : v(v),d(d),e(e) {}
};
 
int d[MAX][MAX][1<<4];
 
int main(){
    int N,M,E,S,T,R,a,b,c;
    vector<Edge> G[MAX];
    cin >> N >> M >> E >> S >> T >> R;
    for(int i = 0 ; i < M ; i++){
        cin >> a >> b;
        G[a].push_back(Edge(b,-1));
        G[b].push_back(Edge(a,-1));
    }
    int bit = 0;
    vector<int> event(N,-1);
    for(int i = 0 ; i < E ; i++){
        cin >> a >> b >> c;
        G[a].push_back(Edge(b,i));
        G[b].push_back(Edge(a,i));
        event[c] = i;
        if(c == S) bit |= 1<<i;
    }
    fill(d[0][0],d[0][0]+MAX*MAX*(1<<4),INF);
    d[S][0][bit] = 0;
    bool ok = false;
    queue<State> Q; Q.push(State(S,0,bit));
    while(!Q.empty()){
        State s = Q.front(); Q.pop();
        int v = s.v,day = s.d,ev = s.e;
        if(v == T){
            ok = true;
            cout << d[v][day][ev] << endl;
            break;
        }
        int ncost = d[v][day][ev] + 1;
        if(ncost < d[S][0][ev]){
            d[S][0][ev] = ncost;
            Q.push(State(S,0,ev));
        }
        for(int i = 0 ; i < (int)G[v].size() ; i++){
            Edge e = G[v][i];
            if(day + 1 > R) continue;
            int nev = ev | (event[e.to] >= 0 ? 1<<event[e.to] : 0);
            if(e.f == -1 || (ev >> e.f & 1)){
                if(ncost < d[e.to][day+1][nev]){
                    d[e.to][day+1][nev] = ncost;
                    Q.push(State(e.to,day+1,nev));
                }
            }
        }
    }
    if(!ok) cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3920
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
ll calc(ll x1, ll y1, ll x2, ll y2){
	return abs(x1-x2)+abs(y1-y2);
}
int main() {
	ll n, m;
	cin >> n >> m;
	vector<P> x(n);
	vector<P> y(m);
	rep(i,n){
		ll a, b; cin >> a >> b;
		x[i].first = a;
		x[i].second = b;
	}
	rep(i,m){
		ll c, d; cin >> c >> d;
		y[i].first = c;
		y[i].second = d;
	}
	for(auto k : x){
		ll min = INF, ans;
		rep(i,m){
			ll dist = calc(k.first, k.second, y[i].first, y[i].second);
			if(dist < min){
				min = dist;
				ans = i+1;
			}
			//cout << ans << " ";
		}
		//cout << endl;
		cout << ans << endl;
	}
 	return 0;
}

Measured memory_bytes: 3640
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

//    public static int[] primes(int n) {
//        List<Integer> candidates =
//                IntStream.rangeClosed(2, n).boxed().collect(Collectors.toList());
//
//        int prime = 2;
//        double upper = Math.sqrt(n);
//        while (prime < upper) {
//            int currentPrime = prime;
//            candidates = candidates.stream().filter(c -> c % currentPrime != 0).
//                    collect(Collectors.toList());
//            prime = candidates.stream().filter(c -> c > currentPrime).findFirst().get();
//        }
//
//        return candidates.stream().mapToInt(Integer::valueOf).toArray();
//    }

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

        int N = sc.nextInt();

//        if (Arrays.stream(primes(N)).filter(n -> n >= 1 && n <= 9).count() >= 2) System.out.println("Yes");
//        else System.out.println("No");
        
        for (int a = 1; a <= 9; a++) {
            for (int b = 1; b <= 9; b++) {
                if (N == a * b) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}


signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    while (b<=a)
    {
        b*=2;
        k--;
    }
    
    while (c<=b)
    {
        k--;
        c*=2;
    }
    if(k<0)
        cout<<"No";
    else
        cout<<"Yes";

}

Measured memory_bytes: 3608
w = int(input())
lots = [i for i in range(w)]
n = int(input())

for i in range(n):
    a, b = map(int, input().split(","))
    lots[a - 1], lots[b - 1] = lots[b - 1], lots[a - 1]

for i in range(w):
    print(lots[i] + 1)

Measured memory_bytes: 5600
#include <stdio.h>

int main(void)
{
  int N,i,kari,j,ans=0,num,real=0;
  int k[100];
  
  scanf("%d",&N);
  
  if(N==1)
  printf("1");
  
  else
  {
  
  for(i=0;i<=N;i++)
  { 
    kari = i;
   
    while(kari % 2 == 0 && kari != 0)
   {
     num++;
     kari = kari / 2;
   }
   
    k[i] = num;
      num = 0;
  }
  
 
  
  for(i=0;i<=N;i++)
  {
    if(k[i]>ans)
    {  ans = k[i];
      real = i;   }
  }
  
  printf("\n%d", real);
 }
  
	return 0;
}

Measured memory_bytes: 128
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec() -> Vec<i32> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect()
}

fn read_int_tuple() -> (i32, i32) {
    let v = read_vec();
    (v[0], v[1])
}

fn main() {
    let (K, X) = read_int_tuple();
    let mut ans = Vec::new();
    for i in X-K+1..X+K {
        ans.push(format!("{}", i));
    }
    println!("{}", ans.join(" "));
}


Measured memory_bytes: 4352
from itertools import combinations
n, k = map(int, input().split())
if k > ((n-1)*(n-2))//2:
    print(-1)
    exit()

edges = []
for i in range(2, n+1):  # 1を中心としたスター型グラフ
    edges.append((1, i))
dist_2 = ((n-1)*(n-2))//2
list_2 = list(combinations(range(2, n+1), 2))
#print(list_2)
for i in range(dist_2-k):
    edges.append(list_2[i])


def ans(lis):
    print(len(lis))
    for x, y in lis:
        print(x, y)
ans(edges)


Measured memory_bytes: 68804