akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstdio>

using namespace std;

char maze[2001][2001];
int H, W;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ver[2001][2001], hor[2001][2001];

int calc_light(int x, int y);

int main() {
    
    cin >> H >> W;
    
    for (int i = 0; i < H; i++)
        scanf("%s", maze[i]);

    for (int i = 0; i < H; i++) {
        int st = 0, goal = 0;
        while (goal < W) {
            if (maze[i][goal] == '.') goal++;
            else {
                int sum = goal - st;
                for (;st < goal; st++) {
                    hor[i][st] = sum;
                }
                goal++;
                st = goal;
            }
        }
        int sum = goal - st;
                for (;st <= goal; st++) {
                    hor[i][st] = sum;
                }
 
    }
    for (int i = 0; i < W; i++) {
        int st = 0, goal = 0;
        while (goal < H) {
            if (maze[goal][i] == '.') goal++;
            else {
                int sum = goal - st;
                for (;st < goal; st++) {
                    ver[st][i] = sum;
                }
                goal++;
                st = goal;
            }
        }
        int sum = goal - st;
            for (;st < goal; st++) {
                ver[st][i] = sum;
            }
    }
/*
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << ver[i][j] << ' ';
        }
        cout << '\n';
    }
        cout << '\n';

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << hor[i][j] << ' ';
        }
        cout << '\n';
    }
*/


    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (maze[i][j] == '#') continue;
            ans = max(ans, ver[i][j] + hor[i][j] - 1);
        }
    }

    cout << ans << '\n';
}



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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

const int MOD = 1e9 + 7;

void add_self(int& a, int b)
{
	a += b;
	if (a >= MOD)
	{
		a -= MOD;
	}
}

void sub_self(int& a, int b)
{
	a -= b;
	if (a < 0)
	{
		a += MOD;
	}
}

const int MAXN = 1e5 + 5;
vector<int> edges[MAXN];
int in_degree[MAXN]; // the number of edges going to 'b'
int dist[MAXN];
bool visited[MAXN];

void dfs(int a) {
	// assert(!visited[a]);
	visited[a] = true;
	for (int b : edges[a]) {
		dist[b] = max(dist[b], dist[a] + 1);
		in_degree[b]--;
		if (in_degree[b] == 0)
			dfs(b);
	}
}

int main()
{

	FAST_IO;
	int n, m;
	cin >> n >> m;
	while (m--) {
		int a, b;
		cin >> a >> b;
		edges[a].push_back(b);
		++in_degree[b];
	}
	for (int i = 1; i <= n; ++i) {
		if (!visited[i] && in_degree[i] == 0)
			dfs(i);
	}
	int answer = 0;
	for (int i = 1; i <= n; ++i) {
		answer = max(answer, dist[i]);
	}
	cout << answer;
	return 0;
}


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

int main() {
  string S; cin >> S;
  if (S.back() == '2' || S.back() == '4' || S.back() == '5' || S.back() == '7' || S.back() == '9') {
    cout << "hon" << endl;
  }
  else if (S.back() == '0' || S.back() == '1' || S.back() == '6' || S.back() == '8') {
    cout << "pon" << endl;
  }
  else cout << "bon" << endl;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int INF = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for(int i=0; i<m; i++)
    {
        int x;
        cin >> x;
        sum += x;
    }
    cout << max(-1, n-sum);
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=50+10;
int n,a[N],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans+=a[i]*a[j];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
static const int MAX=10000;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n;
vector<pair<int, int> > adj[MAX];
void dijkstra(){
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for(int i=0; i<n; i++){d[i]=INFTY; color[i]=WHITE;}
    d[0]=0;
    PQ.push(make_pair(0, 0));
    color[0]=GRAY;
    while(!PQ.empty()){
        pair<int,int> f=PQ.top(); PQ.pop();
        int u=f.second;
        color[u]=BLACK;
        if(d[u]<f.first*(-1)) continue;
        for(int j=0; j<adj[u].size(); j++){
            int v=adj[u][j].first;
            if(color[v]==BLACK)continue;
            if(d[v]>d[u]+adj[u][j].second){
                d[v]=d[u]+adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                color[v]=GRAY;
            }
        }
    }
    for(int i=0; i<n; i++) cout<<i<<" "<<(d[i]==INFTY ? -1:d[i])<<endl;
}

int main(){
    int k,u,v,c;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>u>>k;
        for(int j=0; j<k; j++){
            cin>>v>>c;
            adj[u].push_back(make_pair(v, c));
        }
    }
    dijkstra();
    return 0;
}

Measured memory_bytes: 8064
#include"bits/stdc++.h"
using namespace std;

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();

int main() {
	string s; cin >> s;
	if (s == "Sunny") {
		COUT("Cloudy");
	}
	else if (s == "Cloudy") {
		COUT("Rainy");
	}
	else {
		COUT("Sunny");
	}
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(((s[0]==s[1]&&s[2]==s[3])||(s[0]==s[3]&&s[2]==s[1])||(s[0]==s[2]&&s[1]==s[3]))&&(s[0]!=s[1]||s[1]!=s[2]||s[2]!=s[3]))
    cout<<"Yes";
  else cout<<"No";
}


Measured memory_bytes: 3616
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t

int main() {
	int h, w;
	cin >> h >> w;
	ff(i, 0, h) {
		string a;
		cin >> a;
		cout << a << endl << a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll, ll> P;

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

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

struct Point {
	double x, y;
	int id;
	bool operator <(const Point& p) const {
		return x < p.x || (x == p.x && y < p.y);
	}
};

struct ConvexHullRunner {
	typedef double coord_t;
	typedef double coord2_t;

	coord2_t cross(const Point& O, const Point& A, const Point& B)
	{
		return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
	}

	vector<Point> convex_hull(vector<Point> P)
	{
		size_t n = P.size(), k = 0;
		if (n <= 3) return P;
		vector<Point> H(2 * n);

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

		for (size_t i = 0; i < n; ++i) {
			while (k >= 2 && cross(H[k - 2], H[k - 1], P[i]) <= 0) k--;
			H[k++] = P[i];
		}

		for (size_t i = n - 1, t = k + 1; i > 0; --i) {
			while (k >= t && cross(H[k - 2], H[k - 1], P[i - 1]) <= 0) k--;
			H[k++] = P[i - 1];
		}

		H.resize(k - 1);
		return H;
	}
};

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int even = n % 2 == 0;
	int same = s[0] == s[n - 1];
	if (even ^ same) {
		cout << "Second" << endl;
	}
	else {
		cout << "First" << endl;
	}
	return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>

const int INF = 1<<27;
using namespace std;
typedef pair<int,int> P;
string IntToString(int);
int StringToInt(string);
struct edje{
public:
  int from;
  int to;
  int cost;
  edje(int f,int t,int c){
    from = f;
    to = t;
    cost = c;
  }
};

void bellmanFord(vector<int> &map,vector<edje> &cost){
  for(int i = 0;i < map.size()-1;i++){
    for(int j = 0;j < cost.size();j++){
      map[cost[j].to] = min(map[cost[j].to],map[cost[j].from] + cost[j].cost);
    }
  }
}
void dijkstra(int s,vector<vector<P> >& cost,vector<int>& map){
  map[s] = 0;
  
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,s));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(map[v] < p.first)continue;//
    for(int i = 0;i < cost[v].size();i++){
      if(map[cost[v][i].first] > map[v] + cost[v][i].second){
	map[cost[v][i].first] = map[v] + cost[v][i].second;
	que.push(P(map[cost[v][i].first],cost[v][i].first));
      }
    }

  }
}
int main(){
  while(1){
    int n,m;
    cin >> n >> m;
    if(n == 0 && m == 0)break;
    vector<vector<pair<int,int> > > cost(m);
    vector<vector<pair<int,int> > > time(m);
    for(int i = 0;i < n;i++){
      int a,b,c,t;
      cin >> a >> b >> c >> t;
      cost[a-1].push_back(pair<int,int>(b-1,c));
      cost[b-1].push_back(pair<int,int>(a-1,c));
      time[a-1].push_back(pair<int,int>(b-1,t));
      time[b-1].push_back(pair<int,int>(a-1,t));
    }
    int k;
    cin >> k;
    for(int i = 0;i < k;i++){
      int s,g,q;
      cin >> s >> g >> q;
      vector<vector<pair<int,int> > > tmp;
      if(q == 0) tmp = vector<vector<pair<int,int> > >(cost);
      else if(q == 1) tmp = vector<vector<pair<int,int> > >(time);
      vector<int> map(m,INF);
      //      map[s-1] = 0;
      dijkstra(s-1,tmp,map);
      cout << map[g-1] << endl;
      

    }
  }
  return 0;   
}
string IntToString(int number){
  stringstream ss;
  ss << number;
  return ss.str();
}
int StringToInt(string number){
  stringstream ss;
  ss << number;
  int numInt;
  ss >> numInt;
  return numInt;
  
}

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

int main(){
    int R;
    scanf("%d", &R);
    //円周の長さ＝2*半径*円周率
    float ans = 2 * R * 3.14159265359;
    cout << fixed << setprecision(15);
    cout << ans << endl;
}

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

long long gcd(long long a, long long b) {return b ? gcd(b, a % b) : abs(a);}
long long lcm(long long a, long long b) {return abs(a / gcd(a, b) * b);}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b; cin >> a >> b;
  cout << lcm(a, b) << '\n';
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

#define N_MAX 1000000

using namespace std;
using ll = long long;

string S;

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

    std::cin >> S;
    int r = 0;
    int b = 0;
    REP(i, S.size()) {
        if(S[i] == '0') {
            r++;
        }
        else {
            b++;
        }
    }
    std::cout << min(r, b) * 2 << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
using namespace std;
using namespace std::chrono;
#define int long long
#define f(a,b,c) for(a=b;a<=c;a++)
#define frev(a,b,c) for(a=b;a>=c;a--)
#define rep(a,b,c) for(a=b;a<c;a++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define endl '\n'
#define ff first
#define ss second
#define ld long double
int M1=1000000007;
int M2=67280421310721;
int M3=998244353;
int INF=1e18;
ld PI=3.141592653589793238;
int power(int a, int b, int mod)
{
    int ans=1;
    int prod=a;
    while(b)
    {
        if(b%2)
            ans=(ans*prod)%mod;
        prod=(prod*prod)%mod;
        b/=2;
    }
    return ans;
}
int inv(int a, int mod)
{
    return power(a, mod-2, mod);
} 
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int fact(int n,int mod){
	int f=1;
	for(int i=1;i<=n;i++) f=(f*i)%mod;
	return f;
}
int ncr(int n,int r,int mod){
	if(mod==1){
	return (fact(n,mod)/fact(r,mod))/fact(n-r,mod);
	}
	return (((fact(n,mod)*inv(fact(r,mod),mod))%mod)*inv(fact(n-r,mod),mod))%mod;
}
void solve(){
    //code starts here
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    ld x1,y1,x2,y2;
    ld an1=h*30+(ld)(30)*m/60;
    ld an2=6*m;
    an1=an1*PI/180;
    an2=an2*PI/180;
    x1=a*cos(an1);
    y1=a*sin(an1);
    x2=b*cos(an2);
    y2=b*sin(an2);
    ld dis=sqrt(pow(x1-x2,2)+pow(y1-y2,2));
    cout<<dis<<endl;   
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<fixed<<setprecision(10);
    auto start = high_resolution_clock::now();
    int i,t=1;
    //cin>>t;
    f(i,1,t) solve();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    //cout << duration.count() << endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
const int dr[]={0,1,0,-1,0};

struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false;
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};
int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int h,w;
	cin >>h >>w;
	vector<string> ba(h, string(w,'.'));
	rep(i, h) cin >>ba[i];
	
	UF ufa(h*w);
	rep(i,h) rep(j,w){
		if(i>0 && ba[i][j] != ba[i-1][j]) ufa.unite(i*w+j, (i-1)*w+j);
		if(j>0 && ba[i][j] != ba[i][j-1]) ufa.unite(i*w+j, i*w+j-1);
	}
	map<int, ll> bkm;
	rep(i, h*w){
		if(ba[i/w][i%w] =='#') bkm[ufa.find(i)]++;
	}
	//for(auto x :bkm) printf("%d:%lld:%d, ",x.first,x.second,ufa.size(x.first)); puts("");
	ll ans =0;
	for(auto x: bkm){
		ans += x.second * (ufa.size(x.first) - x.second);
	}
	cout << ans <<"\n";
	return 0;
}


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

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

int main() {
  string s;
  cin >> s;
  int f = 0;
  REP(i, s.size()-2) {
    if (s[i] == s[i+1] && s[i+1] == s[i+2]) { f = 1; }
  }
  if (f == 0) { printf("No\n"); }
  if (f == 1) { printf("Yes\n"); }
  return 0;
}


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

void prians(bool answer) {
  if(answer)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

string s, data[4] = {"maerd", "remaerd", "esare", "resare"};

bool ch();

int main() {
  cin >> s;
  prians(ch());
  return 0;
}

bool ch() {
  reverse(s.begin(), s.end());
  for(int i = 0; i < s.size(); ++i) {
    bool cannot = 1;
    for(int j = 0; j < 4; ++j)
      if(i + data[j].size() <= s.size()) {
        bool cons = 1;
        for(int k = 0; k < data[j].size(); ++k) {
          if(s[i + k] != data[j][k]) break;
          if(k == data[j].size() - 1) cons = 0;
        }
        if(!cons) {
          cannot = 0;
          i += data[j].size() - 1;
          break;
        }
      }
    if(cannot) return 0;
  }
  return 1;
}

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

int main () {
  string S;
  cin >> S;
  int N = S.size();
  vector<int>count(N,0);
  int R = 0;
  int L = 0;
  
  for (int i = 0; i < N-1; i++) {
    if (S.at(i) == 'R'){
      R++;
    }
    else {
      L++;
    }
    if (i == N-2){
      if (S.at(i+1) == 'R'){
        R++;
      }
      else {
        L++;
      }
    }
    if (S.at(i) == 'L' && S.at(i+1) == 'R'){
      if ((R+L) % 2 == 0){
        count.at(i-L) = (R+L)/2;
        count.at(i-L+1) = (R+L)/2;
      }
      else if (R % 2 == 0){
        count.at(i-L) = (R+L)/2;
        count.at(i-L+1) = R+L - (R+L)/2;
      }
      else {
        count.at(i-L+1) = (R+L)/2;
        count.at(i-L) = R+L - (R+L)/2;
      }
      R = 0;
      L = 0;
    }
    else if (i == N-2){
      if ((R+L) % 2 == 0){
        count.at(i-L+1) = (R+L)/2;
        count.at(i-L+2) = (R+L)/2;
      }
      else if (R % 2 == 0){
        count.at(i-L+1) = (R+L)/2;
        count.at(i-L+2) = R+L - (R+L)/2;
      }
      else {
        count.at(i-L+2) = (R+L)/2;
        count.at(i-L+1) = R+L - (R+L)/2;
      }
    }
  }
  
  for (int i = 0; i < N; i++) {
    cout << count.at(i);
    if (i == N-1){
      cout << endl;
    }
    else {
      cout << ' ';
    }
  }
}
        
        
    

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;




int main(void) {
  ll N;
  cin >> N;
  ll h[111]={};
  ll i, j;
  
  for(i=1; i<=N; i++) {
    cin >> h[i];
  }
  
  ll ans=0;
  for(ll t=100; t>0; t--) {
    
    ll f=0;
    for(i=1; i<=N; i++) {
      if(h[i]==t) {
        h[i]--;
        if(!f) ans++;
        f=1;
      }else {
        f=0;
      }
      
    }
    
  }
  
  pt(ans);
  
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rsort(x) sort(x.rbegin(), x.rend())
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define fio(x) ios::sync_with_stdio(x), cin.tie(x), cout.tie(x);
#define znit(x) memset(x, 0, sizeof(x))
#define mnit(x) memset(x, -1, sizeof(x))
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> piii;
typedef pair<pair<int, int>, int> ppi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db EPS = 1e-7;

const ll mod = 1e9 + 7;
const ll mod2 = 1e9 + 9;
ll mypow(ll x, ll y, ll p){ll ret = 1;while(y){if(y & 1) ret = (ret * x) % p;x = (x * x) % p; y /= 2;}return ret;}
ll inv(ll x, ll p){return mypow(x, p - 2, p);}
ll gcd(ll x, ll y){return y ? gcd(y, x % y) : x;}

const int MAX = 1e5 + 3;
char S[MAX];
int N;
string t;

int main(){
    scanf("%s", S + 1);
    N = strlen(S + 1);
    if(S[N] == '1' || S[1] == '0' || S[N - 1] == '0'){
        puts("-1");
        return 0;
    }
    for(int i = 1; i <= N - 1; i++){
        t.push_back(S[i]);
    }
    string x = t;
    reverse(x.begin(), x.end());
    if(x == t){
        int node = 3;
        int bef = 1, cur = 2;
        printf("%d %d\n", bef, cur);
        for(int i = 2; i <= N - 1; i++){
            if(S[i] == '1') bef = cur, cur = node;
            else bef = node;
            printf("%d %d\n", bef, cur);
            node++;
        }
    }
    else{
        puts("-1");
    }
	return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define INF LONG_LONG_MAX
#define int long long
#define ar array
#define db double
#define pi 3.14159265358979323846
#define pow pw
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,d;
    cin>>n>>d;
    int ans=0;
    for (int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        db dis=sqrt(a*a+b*b);
        if (dis<=d) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int s[m], c[m];
    rep(i, m) scanf("%d%d", &s[i], &c[i]), --s[i];
    rep(i, 1000)if(to_string(i).size() == n){
        string t = to_string(i);
        bool flag = true;
        rep(j, m)if(t[s[j]]-'0' != c[j]){
            flag = false;
            break;
        }
        if(flag){
            printf("%d\n", i);
            return 0;
        }
    }
    puts("-1");
}


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

using namespace std;

#define lli  long long int
#define pb   push_back

lli counter(lli div, lli n){
    lli counter=0;
    for(lli i=1; 1; i++){
        if(div*i <= n)counter = counter+(div*i);
        else break;
        //cout << counter << endl;
    }
    return counter;
}

int main(){
    lli n, sum=0;
    cin >> n;
    for(lli i=1; i<=n; i++){
        sum = sum + counter(i, n);
    }
    cout << sum;
}

Measured memory_bytes: 3608
input()
l=[[int(c)] for c in raw_input().split()]
for i,a in enumerate(sorted(l)):
    a[0]=i+1
s=0
r=len(l)
b=[0]*(1+r)
for n, in reversed(l):
    i=n
    while i>0:
        s+=b[i]
        i&=i-1
    while n<=r:
        b[n]+=1
        n+=n&-n
print s

Measured memory_bytes: 42280
integer(8)A,B;
read*,A,B;A=A-1;
if(mod(B,2)==0)then
    if(mod(B,4)/=0)then
        B=B+1;
    endif
else
    if(mod(B-1,4)==0)then
        B=1
    else
        B=0
    endif
endif
if(mod(A,2)==0)then
    if(mod(A,4)/=0)then
        A=A+1;
    endif
else
    if(mod(A-1,4)==0)then
        A=1
    else
        A=0
    endif
endif
A = xor(A,B);
write(*,'(i0)')A
end

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	vector<char>al(26);
	al = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
	
	string S;
	cin >> S;
	int Z = S.size();
	vector<int>A(26);
	rep(i, Z) {
		rep(j, 26) {
			if (S[i] == al[j]) {
				A[j]++;
			}
		}
	}
	rep(i, 26) {
		if (A[i] >= 2) {
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
  
	int n;
	cin >> n;
	pair<int, int> a[n];
	for(int i = 0; i < n; i++)cin >> a[i].first >> a[i].second;
	sort(a, a + n);
	for(int i = 0; i < n; i++){
		cout << a[i].first << ' ' << a[i].second << '\n';
	}
    return 0;
}



Measured memory_bytes: 3940
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in(),K=in();
	auto A=vecin(N);

	vector<ll> PS(N,0),NS(N,0);
	REP(i,N){
		REP(j,N){
			if(A[i]>A[j]){
				if(i>j){
					PS[i]++;
				}
				else NS[i]++;
			}
		}
	}

	ll S=0;
	ll PST = K,NST = K;
	if(K%2){
		NST *= (K+1LL)/2LL;
		NST %= atcoder_mod;
		PST *= (K-1LL)/2LL;
		PST %= atcoder_mod;
	}
	else{
		NST /= 2LL;
		NST *= K+1LL;
		NST %= atcoder_mod;
		PST /= 2LL;
		PST *= K-1LL;
		PST %= atcoder_mod;
	}

	REP(i,N){
		S += (NS[i]*NST)%atcoder_mod;
		S %= atcoder_mod;
		S += (PS[i]*PST)%atcoder_mod;
		S %= atcoder_mod;
	}

	out(S);
	return 0;
}


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

int main(void)
{
    int K;
    int A;
    int B;
    int temp;
    scanf("%d", &K);
    scanf("%d", &A);
    scanf("%d", &B);
    temp = A;
    while (1)
    {
        if (temp % K == 0)
        {
            printf("OK");
            return 0;
        }
        ++temp;
        if (temp > B)
        {
            printf("NG");
            return 0;
        }
    }
}

Measured memory_bytes: 1732
#include<stdio.h>
int main(void){
    int high, width;
    while (1)
    {
        scanf("%d %d", &high, &width);
        if (high == 0 && width == 0)
        {
            break;
        }
        int i, j;
        for (i = 0; i < high;i++){
            for (j = 0; j < width;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
/*
    @uthor: Varun Mishra
    "varun21999" ->  Codechef, Codeforce, Hackerrank, Hackerearth;
*/
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
//#define int     long long int
#define ull     unsigned int
#define ld      long double
#define pb      push_back
#define pa      pair<int,int>
#define ppa     pair<pair<int,int>,int>
#define pap     pair<int,pair<int,int>>
#define v1d     vector<int>
#define v2d     vector<vector<int> >
#define vpa     vector<pair<int,int>>
#define M       1000000007
#define MN      LLONG_MIN
#define MX      LLONG_MAX
#define ff      first
#define ss      second
#define endl    "\n"
#define v1s     vector<string>
#define all(v)  v.begin(),v.end()
#define S(v)    sort(v.begin(),v.end())
#define RS(v)          sort(v.rbegin(),v.rend())
#define R(v)           reverse(v.begin(),v.end())
#define mxpq(T)        priority_queue <T>
#define mnpq(T)        priority_queue<T,vector<T>,greater<T>>
#define T              int tc;cin>>tc;while(tc--)
#define p2d(v)         for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)         for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)         for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define forIloop(i,n)  for(auto i=0;i<n;i++);
#define forDloop(i,n)  for(auto i=n-1;i>=0;i--);
#define qqq 400005
const int MOD = 1e9 + 7;
// int popcount(int num){
//     num = num - ((num >> 1) & 0x55555555);
//     num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
//     return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
// }
// int powerOfTwo(int n){
//     return 1 << n;
// }

// int arr[1000001];
// bool temet = false;




void codeforce(){
    int x,n; cin>>x>>n;
    vector<int>arr(n);
    for(auto &i:arr){
        cin>>i;
    }
    if(n == 0){
        cout << x << endl;
        return;
    }
    int num=0;
    bool flag = false;
    while(!flag){
        if(find(arr.begin(), arr.end(), x-num) == arr.end()){
            cout << x-num << endl;
            flag = true;
        }
        else if(find(arr.begin(), arr.end(), x+num) == arr.end()){
            cout << x+num << endl;
            flag = true;
        }
        num++;
    }
}



int32_t main(){

    cout<<fixed<<setprecision(16);
    cin.sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    /*#ifndef _DEBUG
     freopen("input.txt",  "r",  stdin);
     freopen("output.txt", "w", stdout);
    #endif*/
    //auto start = high_resolution_clock::now();

    // Lucario();
    //codeforceContest();
    //hackerEarth();
    //codeChef();
    codeforce();

   /* auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    cout << "Time: "<<duration.count()<<endl;*/
    return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
        String ans = "NG";
        for(int i = a; i <= b; i++) {
            if(i % k == 0) ans = "OK";
        }

        System.out.println(ans);
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
typedef pair<int,int> P;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    const int MAX = 1e5+10;
    UnionFind uf(MAX*2);

    int x,y;
    REP(i,N){
    	cin >> x >> y;
    	uf.unite(x,y+MAX);
    }

    map<int, lint> mx, my;
    FOR(i,0,MAX) mx[uf.root(i)]++;
    FOR(i,MAX,MAX*2) my[uf.root(i)]++;
    lint res = 0;
    REP(i,MAX*2) res += mx[i] * my[i];
    cout << res - N << endl;

    return 0;
}


Measured memory_bytes: 27904
n, k = [ int(v) for v in input().split() ]
cost_list = [ int(v) for v in input().split() ]
min_cost_list = [None for i in range(n)]
min_cost_list[0] = 0
for i in range(1,n):
    candidate_list = []
    for j in range(max(i-k,0),i):
        candidate_list.append(abs(cost_list[i]-cost_list[j])+min_cost_list[j])

    min_cost_list[i] = min(candidate_list)



print(min_cost_list[-1])

Measured memory_bytes: 56672
import java.util.Scanner;

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

    int[] a = new int[3];
    a[0] = scanner.nextInt();
    a[1] = scanner.nextInt();
    a[2] = scanner.nextInt();
    if (a[0] == a[1] && a[1] == a[2]) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


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

int main() {
    ll x, a, b;
    cin >> x >> a >> b;

    if (a >= b)
        cout << "delicious" << endl;
    else if (x >= b - a)
        cout << "safe" << endl;
    else
        cout << "dangerous" << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    int n, r, p, c;
    while (true) {
        cin >> n >> r;
        if (n == 0 && r == 0){
            break;
        }
        int before[n];
        
        int after[n];
        for (int i = 1; i <= n; i++) {
            before[n-i] = i;
        }
        for (int i = 0; i < r; i++) {
            cin >> p >> c;
            for (int j = p-1; j < p+c-1; j++) {
                after[j-(p-1)] = before[j];
            }

            
            for (int j = 0; j < p-1; j++) {
                after[c+j] = before[j];
            }
            for (int j = p+c-1; j<n; j++) {
                after[j] = before[j];
            }
            
            for (int j = 0; j < n; j++) {
                before[j] = after[j];
            }
        }
        cout << after[0] << endl;

        
    }
    
    return 0;
}

Measured memory_bytes: 1160
N = int(input())
s = input()
t = input()
kaburi = 0
if s == t:
  print(N)
else:
  for i in range(N):
    if s[-(i+1):] == t[0:i+1]:
      kaburi = len(s[-(i+1):])
  print(2*N-kaburi)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(void){
    int a[11],fir,i,n;
    cin>>n;
    while (n--) {
        int sec=0;
        for (i=0; i<10; i++) {
            cin>>a[i];
        }
        fir=a[0];
        for (i=1; i<10; i++) {
            if(fir<a[i])fir=a[i];
            else if(sec<a[i])sec=a[i];
            else break;
        }
        if(i==10)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1152
/*
Hey there stalker....

█▀▀▄░░░░░░░░░░░▄▀▀█
░█░░░▀▄░▄▄▄▄▄░▄▀░░░█
░░▀▄░░░▀░░░░░▀░░░▄▀
░░░░▌░▄▄░░░▄▄░▐▀▀
░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█
░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█
▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█
█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀
░▀▄░░▀░░▀▀▀░░▀░░░▄█▀
░░░█░░░░░░░░░░░▄▀▄░▀▄
░░░█░░░░░░░░░▄▀█░░█░░█
░░░█░░░░░░░░░░░█▄█░░▄▀
░░░█░░░░░░░░░░░████▀
░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀

Like what you see?
*/
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pii         pair<ll ,ll>
#define vi          vector<ll>
#define present(container, element) (container.find(element) != container.end()) /* For set n maps */
#define cpresent(container, element) (find(all(container),element) != container.end()) /* For vectors */
#define all(a)      (a).begin(),(a).end()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define F           first
#define S           second
#define I           insert
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define trav(a, x) 	for(auto& a : x)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lcase(a) (char)tolower(a)
#define ll long long int
#define lld long double
#define endl "\n"
#define PI 3.14159265358979323844
#define MOD 1000000007
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
const int N = 1e5 + 5;
/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

int32_t main()
{
   IOS

    int TESTS=1;
    //cin >> TESTS;
    while (TESTS--)
    {
    	ll n,k;
    	cin>> n >> k;

    	vector<double> s(n);
    	for(int i=0;i<n;i++)
		{
			cin>> s[i];
			s[i]=(s[i]+1)/2;                  // expected value of dice
		}

		vector<double> v1(n+1);
		for(int i=0;i<n;i++)
		{
			v1[i+1]=v1[i]+s[i];
		}
		double ans=0;
		for(int i=k;i<=n;i++)
		{
			ans=max(ans,v1[i]-v1[i-k]);
		}
		cout<< fixed<< setprecision(10)<< ans << endl;




    }
    return 0;
}


Measured memory_bytes: 6416
#include<bits/stdc++.h>
using namespace std;
struct yu
{
	int a[100001];
}a,b,c,p,q,ip,iq,id,aa,bb,cc;
int n,k,f,g;
yu getinv(yu a)
{
	yu b;
	for (int i=1;i<=n;i++)b.a[a.a[i]]=i;
	return b;
}
yu cheng(yu a,yu b)
{
	yu c;
	for (int i=1;i<=n;i++)c.a[i]=a.a[b.a[i]];
	return c;
} 
yu mi(yu a,int y)
{
	yu c=id;
	while (y)
	{
		if (y%2==1)c=cheng(c,a);
		a=cheng(a,a);
		y/=2;
	}
	return c;
}
int main()
{
	scanf("%d %d",&n,&k);
	for (int i=1;i<=n;i++)scanf("%d",&p.a[i]);
	for (int i=1;i<=n;i++)scanf("%d",&q.a[i]);
	for (int i=1;i<=n;i++)id.a[i]=i;
	ip=getinv(p);
	iq=getinv(q);
	f=(k-1)/6;
	g=k-f*6;
	cc=cheng(cheng(cheng(q,ip),iq),p);
	aa=mi(cc,f);
	if (g==1)bb=p;
	if (g==2)bb=q;
	if (g==3)bb=cheng(q,ip);
	if (g==4)bb=ip,aa=cheng(aa,q);
	if (g==5)bb=iq,aa=cheng(cheng(aa,q),ip);
	if (g==6)bb=cheng(iq,p),aa=cheng(cheng(aa,q),ip);
	p=cheng(cheng(aa,bb),getinv(aa));
	for (int i=1;i<=n;i++)printf("%d ",p.a[i]);
} 





Measured memory_bytes: 11896
#include<stdio.h>
#define  N 2000000
#define INF -2100000000

int h,a[N+1];

void maxHeapify(int i){
  int l,r,largest,temp;
  l=2*i;
  r=2*i+1;

  if(l<=h&&a[l]>a[i]) largest=l;
  else largest=i;
  if(r<=h&&a[r]>a[largest]) largest=r;

  if(largest!=i){
    temp=a[i];
    a[i]=a[largest];
    a[largest]=temp;
    maxHeapify(largest);
  }
}

int extract(){
  int max;
  if(h<1) return INF;
  max=a[1];
  a[1]=a[h--];
  maxHeapify(1);
  return max;
}

void heapincreasekey(int i,int key){
  int temp;
  
  if(key<a[i]) return;
  a[i]=key;
  
  while(i>1&&a[i/2]<a[i]){
    temp=a[i];
    a[i]=a[i/2];
    a[i/2]=temp;
    i=i/2;
  }
}

void insert(int key){
  h++;
  a[h]=INF;
  heapincreasekey(h,key);
}

int main(){
  int key;
  char c[10];

  while(1){
    scanf("%s",c);
    if(c[0]=='e'&&c[1]=='n') break;
    if(c[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else{
      printf("%d\n",extract());
    }
  }
  
  return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i,n) cin >> A[i];
  bool flag = true;
  rep(i,n){
    if(A[i] % 2 == 0){
      if(A[i] % 3 != 0 && A[i] % 5 != 0){
        flag = false;
      }
    }
  }
  if(flag) puts("APPROVED");
  else puts("DENIED");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> a(M), c(M, 0);
	for(int i=0; i<M; ++i){
	    int b;
	    cin >> a[i] >> b;
	    for(int j=0; j<b; ++j){
	        int p;
	        cin >> p;
	        c[i]=(c[i])|(1<<(p-1));
	    }
	}
	int w=(1<<N);
	vector<vector<int>> dp(M+1, vector<int>(w, -1));
	dp[0][0]=0;
	for(int i=0; i<M; ++i){
	    for(int j=0; j<w; ++j){
	        if(dp[i][j]>=0){
	            if(dp[i+1][j]<0) dp[i+1][j]=dp[i][j];
	            else dp[i+1][j]=min(dp[i+1][j], dp[i][j]);
	            if(dp[i+1][j|(c[i])]<0) dp[i+1][j|(c[i])]=dp[i][j]+a[i];
	            else dp[i+1][j|(c[i])]=min(dp[i+1][j|(c[i])], dp[i][j]+a[i]);
	        }
	    }
	}
	cout << dp[M][w-1] << endl;
	return 0;
}


Measured memory_bytes: 16384
h,w,m = map(int,input().split())
b = []
x = [0 for _ in range(w)]
y = [0 for _ in range(h)]
for i in range(m):
  bh,bw = map(int,input().split())
  bh -= 1
  bw -= 1
  b.append((bh,bw))
  x[bw] += 1
  y[bh] += 1
#print(b,x,y)

mxx = max(x)
mxy = max(y)

cmxb = 0
for by,bx in b:
  if y[by]+x[bx] == mxx+mxy:
    cmxb += 1
cmxx = 0
for xi in x:
  if xi == mxx:
    cmxx += 1
cmxy = 0
for yi in y:
  if yi == mxy:
    cmxy += 1
#print(cmxb,cmxx,cmxy)

if cmxb == cmxx*cmxy:
  print(mxx+mxy-1)
else:
  print(mxx+mxy)

Measured memory_bytes: 111548
#include<stdio.h>
#include<math.h>

int main() {

	int e; //??\??????
	int x,y,z; //???????????¨?????°
	int m; //?????????
	int A[10000]; //??????????´???¨??????
	int a=0;  //??????????´???¨?????°
	int i; //??????????????¨?????°
	//int count;

	for(;;) {

	scanf("%d",&e);

	if(e==0)
		break;

	m=1000001; //(????????????)


	for(z=pow(e,1.0/3.0)+1;z>=0;z--) {

		for(y=sqrt(e-z*z*z);y>=0;y--) {
			for(x=e-y*y-z*z*z;x>=0;x--) {
				if((x+y*y+z*z*z)==e) { //x,y,z??????????????????????????????x+y+z???m???????°????????????°
					if(x+y+z<m) {     //m?????´??°
						m=x+y+z;
						//printf("%d %d %d %d\n",m,x,y,z);
						break; //??????y,z?????????????????¶????????????x????????¨???????????§????????§??±???
					}
					if(x+y+z>m)
						break;
				}
			}
		}
	}

	A[a]=m; //?????????????´?
	a++;
	}

	for(i=0;i<a;i++)
		printf("%d\n",A[i]); //??????

	return 0;
}

Measured memory_bytes: 696
#include <bits/stdc++.h>
using namespace std;
int main()
{
   cin.tie(0);
   ios::sync_with_stdio(false);
   int h, w;
   cin >> h >> w;
   vector<string> vc;
   for (int i = 0; i < h; i++)
   {
      string s;
      cin >> s;
      vc.push_back(s);
   }
   for (int i = 0; i < h; i++)
   {
      for (int j = 0; j < w; j++)
      {
         if (vc[i][j] == '.')
         {
            int cnt = 0;
            string s = "";
            for (int k = -1; k <= 1; k++)
            {
               for (int f = -1; f <= 1; f++)
               {
                  if (i + k >= 0 && i + k < h && j + f >= 0 && j + f < w)
                  {
                     if (vc[i + k][j + f] == '#')
                     {
                        if (k == 0 && f == 0)
                        {
                        }
                        else
                        {
                           cnt++;
                        }
                     }
                  }
               }
            }
            vc[i][j] = cnt + '0';
         }
      }
   }
   for (int i = 0; i < h; i++)
   {
      cout << vc[i] << endl;
   }
}

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

using namespace std;

long n, m, k, res;
long a[200005];

int main()
{
	long x;

	cin >> n >> k;

	for (long i = 0; i < n; ++i)
	{
		cin >> x;
		a[x] += 1;
	}

	sort(a + 1, a + n + 1);

	for (long i = 1; i <= n - k; ++i)
		res += a[i];

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '(L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

int main(){
 
    int n,a;
    cin>>n;
    cin>>a;

    cout<<(n*n-a)<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[5];
int main(){
    cin>>a;
    sort(a,a+3);
    if(a[0]=='a'&&a[1]=='b'&&a[2]=='c'){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;
typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
int main()
{IOS
ll mod=1e9+7;
int t;
cin>>t;
int a[t];
for(int i=0;i<t;++i) cin>>a[i];
ll dp[t];

dp[0]=0;
dp[1]=abs(a[1]-a[0]);
for(int i=2;i<t;++i)
{ dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1]);
    //cout<<dp[i]<<" ";
}
cout<<dp[t-1];
}

Measured memory_bytes: 1408