akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

bool check(const vector<int>& vec) {
    int N = vec.size();
    if (N <= 1) return true;

    vector<int> before(vec.begin(), vec.begin() + N / 2);
    vector<int> after(vec.begin() + N / 2, vec.end());

    int beforeMax = *max_element(before.begin(), before.end());
    int afterMin = *min_element(after.begin(), after.end());

    if (beforeMax - afterMin > 1) return false;

    if (!check(before)) return false;

    if (!check(after)) return false;

    return true;
}


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

    vector<int> H_i;

    for (int i { 0 }; i < N; ++i) {
        int tmp;
        cin >> tmp;
        H_i.push_back(tmp);
    }

    bool enabled { check(H_i) };


    cout << (enabled ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    double pi = acos(-1.);
    double s, l, h;
    s = 1. * a * b * sin(1. * c * pi / 180) / 2;
    l = a + b + sqrt(1. * (a * a + b * b -2* a * b * cos(1. * c * pi / 180)));
    h = 1. * b * sin(1. * c * pi / 180);
    printf("%.6f\n%.6f\n%.6f\n", s, l, h);
}

    


Measured memory_bytes: 3588
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <cmath>
using namespace std;
#define fio ios::sync_with_stdio(0),cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int N,K;
int main() {
	scanf("%d %d", &N, &K);
	printf("%d\n", N%K ? 1 : 0);
}



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

int main() {	
	int t=1;
//	cin >> t;
	while (t--) {
	   int r,c;
	   cin>>r>>c;
	   int m;
	   cin>>m;
	   int a,b;
	   map<int,int>row;
	   map<int,int>col;
	   map<pair<int,int>,int>temp;
	   for(int i=0;i<m;i++)
	   {
	   	  cin>>a>>b;
	   	  a=a-1;
	   	  b=b-1;
	   	  row[a]++;
	   	  col[b]++;
	   	  pair<int,int>p;
	      p.first=a;
	      p.second=b;
	   	  temp[p]=1;
	   	  
	   }
	      pair<int,int>p;
	      p.first=-1;
	      p.second=-1;
	    pair<int,int> mrow=p;
	    pair<int,int>mcol=p;
	    vector<int>vr;
	    vector<int>vc;
	   for(auto i:row)
	   {
	   	   if(i.second>mrow.second)
	   	  {      
	   	        vr.clear();
	   	        vr.push_back(i.first);
	   	  	   mrow.first=i.first;
	   	  	   mrow.second=i.second;
			 }
			 if(i.second==mrow.second)
			 {
			 	 vr.push_back(i.first);
			 }
			 
	   }
	  for(auto i:col)
	  {
	  	if(i.second>mcol.second)
	   	  {      
	   	        vc.clear();
	   	        vc.push_back(i.first);
	   	  	   mcol.first=i.first;
	   	  	   mcol.second=i.second;
			 }
			 if(i.second==mcol.second)
			 {
			 	 vc.push_back(i.first);
			 }
	  }
	  int ans=0;
	  for(int i=0;i<vr.size();i++)
	  {   
	   int flag=0;
	  	 for(int j=0;j<vc.size();j++)
	  	 {
	  	 	 pair<int,int>p;
	  	 	 p.first=vr[i];
	  	 	 p.second=vc[j];
	  	 	 int tem=mrow.second+mcol.second;
	  	 	 if(temp[p]==1)
	  	 	    {  
	  	 	        flag=1;
	  	 	    	 tem--;
				   }	 
			  ans=max(ans,tem);
			  if(flag==0)
			  break;
		   }
		   if(flag==0)
		    break;
	  }
	  
	  cout<<ans<<endl;
}
	    
	} 
	
	

Measured memory_bytes: 54304
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n,k; cin>>n>>k;
  string s; cin>>s;
  vi num;
  int ans=0;
  int cnt=1;
  rep(i,n-1){
    if(s[i]==s[i+1]&&i<n-2) cnt++;
    else{
      if(s[i]==s[i+1]) cnt++;
      if(cnt>1) ans+=(cnt-1);
      num.push_back(cnt);
      cnt=1;
    }
  }
  //for(auto x:num) cout<<x<<endl;
  ans+=(2*k);
  if(ans>(n-1)) cout<<n-1<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 4080
#include <iostream>
using namespace std;
int main(){

	int x,y,z;
	cin>>x>>y>>z;

	if(x<y && y<z){cout<<x<<" "<<y<<" "<<z<<endl;}
	else if(y<=x && x<=z){cout<<y<<" "<<x<<" "<<z<<endl;}
	else if(z<=x && x<=y){cout<<z<<" "<<x<<" "<<y<<endl;}
	else if(x<=z && z<=y){cout<<x<<" "<<z<<" "<<y<<endl;}
	else if(y<=z && z<=x){cout<<y<<" "<<z<<" "<<x<<endl;}
	else if(z<=y && y<=x){cout<<z<<" "<<y<<" "<<x<<endl;}
	

	return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> graph(51,vector<int> (51,0));
int n;

void dfs(int s,vector<bool> &visit)
{
	visit[s]=true;
	for (int i=0;i<n+1;i++)
	{
		if (!visit[i] && graph[s][i])
		{
			dfs(i,visit);
		}
	}
	return ;
}

int main()
{
	int m;cin >> n >> m;
	int u,v;
	vector<pair<int,int>> edge(m);
	for (int i=0;i<m;i++)
	{
		cin >> u >>v;
		graph[u][v]++;
		graph[v][u]++;
		edge[i].first=u;
		edge[i].second=v;
	}
	int ans=0;
	for (int i=0;i<m;i++)
	{
		u=edge[i].first;
		v=edge[i].second;
		graph[u][v]--;
		graph[v][u]--;
		vector<bool> visit(n+1,false);
		dfs(1,visit);
		for (int j=1;j<n+1;j++)
		{
			if (!visit[j])
			{
				ans++;
				break;
			}
		}
		graph[u][v]++;
		graph[v][u]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ps = list(map(int, input().split()))
xys = [tuple(map(int, input().split())) for _ in range(m)]

t = {p:p for p in ps}

def trace(x):
    route = [x]
    while t[x] != x:
        x = t[x]
        route.append(x)
    for v in route:
        t[v] = route[-1]
    return route

for x, y in xys:
    u = trace(x)[-1]
    v = trace(y)[-1]
    if u!=v:
        t[u] = v

avs = [
    p
    for i, p in enumerate(ps)
    if trace(i+1)[-1] == trace(p)[-1]
]

print(len(avs))

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

int main(){

int N, M, C;
cin >> N >> M >> C;

vector<int>B(M, 0);
    for(int i = 0; i < M; i++){ 
        cin >> B.at(i);
    }

	vector<vector<int>> A(N, vector<int>(M));
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			cin >> A[i][j];
		}
	}

int ans = 0;

    for(int i = 0; i < N; i++){ 
         int sum = 0;
         for(int j = 0; j < M; j++){ 
              sum += A[i][j] * B[j];
         }
         sum += C;
        if(sum > 0){
            ++ans;
        }
    }

cout << ans << endl; 

}

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

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String s = Integer.toString(N);
        boolean found = false;
        for (char c : s.toCharArray()) {
            if (c == '9') {
                found = true;
                break;
            }
        }
        System.out.println(found ? "Yes" : "No");
    }
}


Measured memory_bytes: 21460
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>

using namespace std;

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

    int i=N/111;

    if(N%111!=0){
        ++i;
    }

    cout<<i*111<<endl;
    return 0;


}

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

int n, a, ans = 0;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (!(i % 2)) {
            if (a % 2) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
char s[111][111];
int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
int main(){
    int n, m;
    while(cin>>n>>m){
        int ans=0;
        for(int i=0; i<n; ++i){
            scanf("%s",s[i]);
        }
        for(int i=0; i<n; ++i){
            for(int j=0; j<m; ++j){
                if(s[i][j]=='#')
                    continue;
                queue<pair<pair<int,int>,int>>q;
                q.push(mk(mk(i,j),0));
                int dis[22][22];
                for(int k=0; k<n; ++k){
                    for(int l=0; l<m; ++l){
                        dis[k][l]=11111;
                    }
                }
                pair<pair<int,int>, int> tmp;
                while(!q.empty()){
                    tmp=q.front();
                    q.pop();
                    if(dis[tmp.fs.fs][tmp.fs.sc]<=tmp.sc){
                        continue;
                    }
                    dis[tmp.fs.fs][tmp.fs.sc]=tmp.sc;
                    for(int k=0; k<4; ++k){
                        int x=tmp.fs.fs+dx[k];
                        int y=tmp.fs.sc+dy[k];
                        if(x<0 || x>=n || y<0 || y>=m)
                            continue;
                        if(s[x][y]=='.')
                            q.push(mk(mk(x,y),tmp.sc+1));
                    }
                }
                for(int k=0; k<n; ++k){
                    for(int l=0; l<m; ++l){
                        if(dis[k][l]<11111){
                            ans=max(ans, dis[k][l]);
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
  return 0;
}




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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  ll A, B;
  cin >> A >> B;
  vector<ll> h(N);
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }

  ll left = -1;
  ll right = 1e9 + 10;

  while(right - left > 1){
    ll mid = left + (right - left) / 2;

    ll base = B * mid;
    ll cnt = 0;
    ll supp = (A-B);
    for(int i = 0; i < N; i++){
      if(base < h[i]){
        cnt += ((h[i] - base) + supp - 1) / supp;
      }
    }

    if(cnt <= mid){
      right = mid;
    }else{
      left = mid;
    }
  }

  cout << right << endl;

  return 0;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int x1, x2, x3 , x4, x5;
	cin >> x1 >> x2 >> x3 >> x4 >> x5;
	if(x1==0)
        cout << 1 << endl;
    else if(x2==0)
        cout << 2 << endl;
    else if(x3==0)
        cout << 3 << endl;
    else if(x4==0)
        cout << 4 << endl;
    else if(x5==0)
        cout << 5 << endl;

	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);

	long long int a,b,ct=0,ans=0;
	cin>>a>>b;
	cout<<min(abs(a%b-b),a%b);
		
	
	return 0;	
}

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

int main(void)
{
  long long N, M, K, A, B = 0, i = 0, j = 0, suma = 0, max = 0, read = 0, readmax = 0;
  long long deskA[200001], deskB[200001];
  scanf("%lld %lld %lld", &N, &M, &K);
  for (i = 0; i < N; i++)
  {
    scanf("%lld", &deskA[i]);
  }
  for (i = 0; i < M; i++)
  {
    scanf("%lld", &deskB[i]);
  }

  for (i = 0; i < N; i++)
  {
    if (suma + deskA[i] <= K)
    {
      suma += deskA[i];
      A++;
    }else
      break;
  }
  max = suma;
  read = A;
  for (j = 0; j < M; j++)
  {
    if (max + deskB[j] <= K)
    {
      max += deskB[j];
      read++;
      B++;
    }
    else
      break;
  }
  readmax = read;
  for (i = 0; i < A; i++)
  {
    max -= deskA[A - i - 1];
    read--;
    for (j = B; j < M; j++)
    {
      if (max + deskB[j] <= K)
      {
        max += deskB[j];
        read++;
        B++;
      }
      else
        break;
    }
    if (readmax < read)
    {
      readmax = read;
    }
  }
  printf("%lld\n", readmax);
  return 0;
}


Measured memory_bytes: 4836
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

vector<P> v;
ll f(int n, ll x){
  if(x<=0) return 0;
  ll p = v[n].first, b = v[n].second;
  if(x==p+b) return p;

  p = v[n-1].first, b = v[n-1].second;
  ll res;
  if(x>=p+b+2){
    res = f(n-1,x-p-b-2) + 1 + p;
  }else{
    res = f(n-1,x-1);
  }
  return res;
}
int main() {
  int n; ll x;
  cin >> n >> x;
  v = vector<P>(n+1);
  v[0] = P(1,0);
  rep(i,n) v[i+1] = P(v[i].first*2+1,v[i].second*2+2);
  cout << f(n,x) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
  char s1, s2, s3;
  scanf("%c%c%c", &s1, &s2, &s3); 
  if(s1==s2&&s2==s3) {
   printf("No");
  }
  else {
   printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	int i,x;
	int a1=0,a2=0,a3=0;
	int b1=0,b2=0,b3=0;

	for(i=0;i<10;i++){
		scanf("%d",&x);
		if(a1 <= x){
			a3 = a2;
			a2 = a1;
			a1 = x;
		}
		else if(a2 <= x){
			a3 = a2;
			a2 = x;
		}
		else if(a3 <= x){
			a3 = x;
		}
	}

	for(i=0;i<10;i++){
		scanf("%d",&x);
		if(b1 <= x){
			b3 = b2;
			b2 = b1;
			b1 = x;
		}
		else if(b2 <= x){
			b3 = b2;
			b2 = x;
		}
		else if(b3 <= x){
			b3 = x;
		}
	}

	printf("%d %d\n",a1+a2+a3,b1+b2+b3);

	return 0;
}

Measured memory_bytes: 0
n=int(input())
a=list(map(int,input().split()))
i,ans=0,0
while i<n-1:
    while i<n-1 and a[i]==a[i+1]: i+=1
    if a[i]<=a[i+1]:
        while i<n-1 and a[i]<=a[i+1]: i+=1
        ans+=1
    elif a[i]>=a[i+1]:
        while i<n-1 and a[i]>=a[i+1]: i+=1
        ans+=1
    i+=1
    if i==n-1: ans+=1
if ans==0: ans=1
print(ans)

Measured memory_bytes: 20316
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

int main(){
    int s; cin >> s;
    int ans = 2;

    if(s == 1 || s == 2) cout <<4 << endl;
    else{
        while(s!=1){
            ans++;
            if(s%2==0) s=s/2;
            else s=s*3+1;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int H, W;
	char c[110][110];
	int i, j;

	scanf("%d %d",&H,&W);

	for (i = 0; i < H; i++) 
		scanf("%s",c[i]);
	
	for (i = 0; i < H; i++) {
		printf("%s\n",c[i]);
		printf("%s\n", c[i]);
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;
using ll=long long;

int main() {
  ll N, M, fin=0, mod=pow(10,9)+7, S=1;
  cin >> N >> M;
  vector<ll> a(M,0);
  set<ll> ss;
  for(ll i=0; i<M; i++) {
    cin >> a[i];
    ss.insert(a[i]);
  }
  for(ll i=0; i<M-1; i++) {
    if (a[i+1]-a[i]==1) {
      fin=1;
      break;
    }
  }
  //cout << fin << endl;
  if (fin==1) {
    cout << 0 << endl;
  }
  else {
    ll s=a.size();
    vector<int> dp(N+1);
    for (int x=0; x<=N; x++) {
      if (ss.count(x)) {dp[x]=0;}
      else if (x<2) {dp[x]=1;}
      else {
        ll d1=dp[x-1]+dp[x-2];
        dp[x]=d1-d1/mod*mod;
      }
    }
    cout << dp[N] << endl;
  }
}


Measured memory_bytes: 8660
#include<stdio.h>
#include<math.h>
long long modexp(long long n)
{
	long long  i=5;
	long long count=0;
	while(i<1000000000000000001)
	{
		count=count+(long long )n/i;
		i=i*5;
	}
	return count;
}


int main()
{
	long long n;

	scanf("%Ld",&n);
	if(n<=2)printf("0\n");
	else if(n%2==1)printf("0\n");
	else
	{
		printf("%Ld\n",modexp(n/2));
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    long h, w;
    cin >> h >> w;
    long ans = 100000000;
    if(h * w % 3 == 0){
        ans = 0;
    }else{
        for(long i = 0; i < h; i++){
            ans = min(ans, (long)max(i * (w % 2), (long)max(abs(w * (h - i) - i * (w / 2)), abs(w * (h - i) - i * ((w + 1) / 2)))));
        }
        for(long i = 0; i < w; i++){
            ans = min(ans, (long)max(i * (h % 2), (long)max(abs(h * (w - i) - i * (h / 2)), abs(h * (w - i) - i * ((h + 1) / 2)))));
        }
        ans = min(ans, (h % 3 + 1) / 2 * w);
        ans = min(ans, (w % 3 + 1) / 2 * h);
    }
    cout << ans;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx")
#include <iostream>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)

int main()
{
    int N;
    cin >> N;
    long long ret = 0;
    FOR(i, 1, N + 1) ret += 1LL * i * (N / i) * (N / i + 1) / 2;
    cout << ret << '\n';
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int f[100005];
int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}
int main(){
	int n,m,u,v;
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		f[i]=i;
	for(int i=1;i<=m;++i){
		cin>>u>>v;
		f[find(u)]=find(v);
	}
	int ans=0;
	for(int i=1;i<=n;++i)
		if(find(i)==i) ++ans;
	cout<<ans-1;
	return 0;
}

Measured memory_bytes: 3984
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int A = in.nextInt();
            int B = in.nextInt();

            System.out.println(Math.min(A, B) + " " + Math.max(0, A + B - N));
        }
    }
}


Measured memory_bytes: 21844
n=int(input())
a=input()
b=input()
c=input()
#print(n,a,b,c)
ans=0
for i in range(n):
  cnt=2
  if a[i]==b[i]:
    cnt-=1
  if b[i]==c[i]:
    cnt-=1
  if a[i]==c[i]:
    cnt-=1
  if cnt==-1:
    cnt=0
  ans=ans+cnt
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#define N 200010
using namespace std;
int n,cnt,tot,X,Y,ans,head[N],fa[N],dep[N],dis[N],Q[N],be[N],ed[N],a[N][2];
bool vis[N],p[N];
struct edge { int to,from,v; }e[N*4];
void insert(int x,int y,int v) 
{
	e[++cnt].to=y,e[cnt].from=head[x],head[x]=cnt,e[cnt].v=v;
	e[++cnt].to=x,e[cnt].from=head[y],head[y]=cnt,e[cnt].v=v;
}
void dfs(int x)
{
	dep[x]=dep[fa[x]]+1,be[x]=++tot;
	for (int i=head[x];i;i=e[i].from) if (e[i].to!=fa[x]) fa[e[i].to]=x,dfs(e[i].to);
	ed[x]=++tot;
}
void bfs()
{
	int l=1,r=1; Q[1]=X,vis[X]=1;
	while (l<=r)
	{
		int x=Q[l++];
		for (int i=head[x];i;i=e[i].from) if (!e[i].v&&!vis[e[i].to])
		{
			dis[e[i].to]=dis[x]+1;
			if (dis[e[i].to]<dep[e[i].to]) vis[e[i].to]=1,Q[++r]=e[i].to;
		}
	}
}
bool pd(int x,int y)
{
	if (be[x]>be[y]) swap(x,y);
	if (be[x]<be[y]&&ed[x]>ed[y]) return dep[y]-dep[x]>2?true:false;
	if (fa[x]==fa[y]) return false;
	return true;
}
int main()
{
	scanf("%d%d%d",&n,&X,&Y);
	for (int i=1;i<n;i++) scanf("%d%d",&a[i][0],&a[i][1]);
	for (int i=1,x,y;i<n;i++) scanf("%d%d",&x,&y),insert(x,y,1);
	dep[0]=-1,dfs(Y);
	for (int i=1;i<n;i++) if (pd(a[i][0],a[i][1])) p[a[i][0]]=p[a[i][1]]=1; else insert(a[i][0],a[i][1],0);
	bfs();
	for (int i=1;i<=n;i++) if (p[i]&&vis[i]) { printf("-1"); return 0; }
	for (int i=1;i<=n;i++) if (vis[i]) ans=max(ans,dep[i]*2);
	printf("%d",ans);
}

Measured memory_bytes: 22656
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    while(1){
        char ban[10][10] = {{0}};
        char field[10][10] = {{0}};
        cin >> field[0];
        if(field[0][0] == '0') break;
        cin >> field[1];
        cin >> field[2];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                ban[i+1][j+1] = field[i][j];
            }
        }
        for(int i = 1; i <= 3; i++){
            for(int j = 1; j <= 3; j++){
                if(i == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[l][j])cnt++;
                    }
                    if(cnt == 3 && ban[i][j] != '+'){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
                if(j == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[i][l])cnt++;
                    }
                    if(cnt == 3 && ban[i][j] != '+'){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
            }
        }
        if(ban[1][1] == ban[2][2] && ban[2][2] == ban[3][3] && ban[1][1] != '+'){
            printf("%c\n",ban[1][1]);
            goto end;
        }
        else if(ban[1][3] == ban[2][2] && ban[2][2] == ban[3][1] && ban[1][3] != '+'){
            printf("%c\n",ban[1][3]);
            goto end;
        }
        printf("NA\n");
        end:;
    }
	return 0;
}

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

using namespace std;
using ll = long long;
using Lll = list<ll>;
using Vll = vector<ll>;

#define rep(a,x,i,f) for(ll a = i; a < f; a+=x )
#define repR(a,x,i,f) for(ll a = i; a > f; a-=x )

ll ms = 1123456789;

ll frog(Vll& s, Vll& ci, int cur,int k)
{
  ll p,min = ms;

  if(cur < 2)
  {
    return ci[cur];
  }

  rep(i,1,1,k+1)
  {
    if(cur - i < 0) break;
    p = abs(s[cur] - s[cur-i]) + (ci[cur-i] != -1 ? ci[cur-i] : frog(s,ci,cur-i,k));
    min = p < min ? p : min;
  }
  
  ci[cur] = min;

  return ci[cur];
}

int main() 
{
  ll n,m,k,p1,p2;
  cin >> n;
  Vll s(n);
  Vll ci(n,-1);

  rep(i,1,0,n)
    cin >> s[i];

  ci[0] = 0;
  ci[1] = abs(s[0] - s[1]);

  rep(i,1,2,n)
  {
    p1 = ci[i-1] + abs(s[i] - s[i-1]);
    p2 = ci[i-2] + abs(s[i] - s[i-2]);
    ci[i] = p1 < p2 ? p1 : p2;
  }

  //m = frog(s,ci,n-1,k);

  cout << ci[n-1] << endl;
}


Measured memory_bytes: 1792
/*
    Author : DemonStar
*/

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int main()
{
    fast;
    int n;
    cin >> n;
    vi v(n);
    cin >> v;
    vi dp(n + 1);
    dp[0] = 0;
    rep(i, 1, n)
    {
        dp[i] = dp[i - 1] + abs(v[i] - v[i - 1]);
        if (i > 1)
            dp[i] = min(dp[i], dp[i - 2] + abs(v[i] - v[i - 2]));
    }
    cout << dp[n - 1] << endl;

#ifdef LOCAL
    cerr
        << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    if (n % 1000 == 0)
        return cout << 0, 0;
    int k;
    if (n > 1000)
        k = n / 1000;
    else
        return cout << 1000 - n, 0;
    k++;
    k = 1000 * k - n;
    cout << k;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
  int n;
  std::cin >> n;
  std::vector<std::pair<int, int> > red(n), blue(n);
  bool pair[101];
  int cnt = 0, max, hoge = 100;

  for(int i = 0; i < n; i++){
    pair[i] = false;
    std::cin >> red[i].first >> red[i].second;
  }
  for(int i = 0; i < n; i++){
    std::cin >> blue[i].first >> blue[i].second;
  }
  std::sort(red.begin(), red.end());
  std::sort(blue.begin(), blue.end());

  for(int i = 0; i < n; i++){
    max = -1;
    for(int j = 0; red[j].first < blue[i].first && j < n; j++){
      if(pair[j] == false && red[j].second < blue[i].second && red[j].second > max){
        max = red[j].second;
        hoge = j;
      }
    }
    pair[hoge] = true;
  }

  for(int i = 0; i < n; i++){
    if(pair[i]) cnt++;
  }
  std::cout << cnt << std::endl;
}

Measured memory_bytes: 504
// 0bd35dc5e428754fa574049b6be8efe0

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MOD = (int) 1e9 + 7;

const int MAXN = 300;

int n, m;

vector<int> lim[4][MAXN + 5];

inline void input()
{
	n = read<int>(), m = read<int>();
	for(int i = 1; i <= m; ++i)
	{
		int l = read<int>(), r = read<int>(), x = read<int>();
		lim[x][r].push_back(l);
	}
}

inline bool chk(int i, int j, int k)
{
	static int pos[4];
	pos[1] = i, pos[2] = j, pos[3] = k;
	sort(pos + 1, pos + 4);

	for(int r = max(i, max(j, k)), t = 1; t <= 3; ++t)
		for(auto l : lim[t][r]) if(!(l > pos[3 - t] && l <= pos[3 - t + 1])) return 0;
	return 1;
}

inline void solve()
{
	static int f[MAXN + 5][MAXN + 5][MAXN + 5];

	f[0][0][0] = 1;
	for(int t = 0; t < n; ++t)
	{
		for(int i = t, j = 0; j <= i; ++j)
			for(int k = 0; k <= i; ++k) if(chk(i, j, k))
			{
				(f[t + 1][j][k] += f[i][j][k]) %= MOD;
				(f[i][t + 1][k] += f[i][j][k]) %= MOD;
				(f[i][j][t + 1] += f[i][j][k]) %= MOD;
			}

		for(int j = t, i = 0; i < j; ++i)
			for(int k = 0; k <= j; ++k) if(chk(i, j, k))
			{
				(f[t + 1][j][k] += f[i][j][k]) %= MOD;
				(f[i][t + 1][k] += f[i][j][k]) %= MOD;
				(f[i][j][t + 1] += f[i][j][k]) %= MOD;
			}

		for(int k = t, i = 0; i < k; ++i)
			for(int j = 0; j < k; ++j) if(chk(i, j, k))
			{
				(f[t + 1][j][k] += f[i][j][k]) %= MOD;
				(f[i][t + 1][k] += f[i][j][k]) %= MOD;
				(f[i][j][t + 1] += f[i][j][k]) %= MOD;
			}
	}
 
	int ans = 0;
	for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) for(int k = 0; k <= n; ++k)
		if(max(i, max(j, k)) == n && chk(i, j, k)) (ans += f[i][j][k]) %= MOD;
	printf("%d\n", (ans + MOD) % MOD);
}

int main()
{
#ifndef ONLINE_JUDGE
//	freopen("E.in", "r", stdin);
//	freopen("E.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 110848
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: ss
 */

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

/* constant */

/* typedef */

/* global variables */

/* subroutines */

bool evenstr(string &s, int n) {
  int hn = n / 2;
  for (int i = 0; i < hn; i++)
    if (s[i] != s[hn + i]) return false;
  return true;
}

/* main */

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

  for (int i = n - 2; i > 0; i -= 2)
    if (evenstr(s, i)) {
      printf("%d\n", i);
      break;
    }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;


void insertionSort(int *A, int N);
void display(int *A, int N);

int main(){
  int A[1000];
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  insertionSort(A, N);
}

void insertionSort(int *A, int N){
  for(int i=1; i< N; i++){
    display(A, N);
    int v, j;
    v = A[i];
    j = i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1] = v;
  }
  display(A, N);
}

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


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
string a,yl="AKIHABARA";
int now,k;
int main()
{
	cin>>a;
	for(int s=0;s<a.size();s++)
	{
		if(a[s]==yl[now])
		{
			now++;
		}
		else
		{
			if(s>0)
			if(a[s]==a[s-1])
			{
				cout<<"NO"<<endl;
				exit(0);
			}
			if(yl[now]=='A')now++,s--;
			else
			{
				cout<<"NO"<<endl;
				exit(0);
			}
		}
	}
	k=a.size();
	for(int s=0;s<a.size();s++)
	{
		if(a[s]=='A')k--;
	}
	if(k==5)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt(), b=sc.nextInt(), c=sc.nextInt(), d=sc.nextInt();

        System.out.println(Math.max(a*b, c*d));
    }
}


Measured memory_bytes: 23892
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  [a, b, c] <- sort . map (read::String -> Int) . words <$> getLine
  let evenNum = foldl (\acc num -> if num `mod` 2 == 0 then acc + 1 else acc) 0 [a, b, c]
  print $ case evenNum of
    1 -> let new_a = if a `mod` 2 == 0 then a else a + 1
             new_b = if b `mod` 2 == 0 then b else b + 1
             new_c = if c `mod` 2 == 0 then c else c + 1
         in ((new_c - new_a) `div` 2) + ((new_c - new_b) `div` 2) + 1
    2 -> let new_a = if a `mod` 2 == 1 then a else a + 1
             new_b = if b `mod` 2 == 1 then b else b + 1
             new_c = if c `mod` 2 == 1 then c else c + 1
         in ((new_c - new_a) `div` 2) + ((new_c - new_b) `div` 2) + 1
    _ -> ((c - a) `div` 2) + ((c - b) `div` 2)

Measured memory_bytes: 508
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;
 
using namespace std;

int main(){
    FAST() ;
    string str1 , str2 ; cin >> str1 >> str2 ;
    for( int i = 0 ; i < str1.length()  ; i++ ){
        cout << str1[i] ;
        if( i < str2.size() )
            cout << str2[i] ;
    }
    cout << endl ;
    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
signed main()
{
    fast;
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
        v[i] = i;
    vector<pii> vp;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        vp.pb({x,y});
    }
    ld avg = 0;
    do
    {
        for(int i=0;i<(int)v.size()-1;i++)
        {
            int x1 = vp[v[i]].first;
            int y1 = vp[v[i]].second;
            int x2 = vp[v[i+1]].first;
            int y2 = vp[v[i+1]].second;
            avg+=((ld)sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
        }
    }while(next_permutation(all(v)));
    int tt = 1;
    for(int i=n;i>=1;i--)
        tt*=i;
    avg = avg/tt;
    cout<<fixed<<setprecision(20)<<avg;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
#define NIL -1
using ll = long long;
const ll MOD = 1000000007;
#define REP(i,n) for (ll i=0; i < (n); ++i)
#define FOR(i,a,b) for (ll i=(a); i < (b); ++i)
using namespace std;

int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n-1);
  REP(i,n) cin >> a[i], a[i]--;
  REP(i,n) cin >> b[i];
  REP(i,n-1) cin >> c[i];

  int sum = 0;
  REP(i,n) {
    sum += b[a[i]];
    if (i > 0 && a[i] == a[i-1] + 1) sum += c[a[i-1]];
  }
  cout << sum << endl;

  return 0;
}


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

using namespace std;

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

	int ans = 0;
	for (int i = 0; i < 1000; ++i) {
		int key[3];
		key[0] = i % 10;
		key[1] = (i / 10) % 10;
		key[2] = (i / 100) % 10;

		int idx = 0;
		for (int j = 0; j < s.size(); ++j) {
			if ((int)(s[j] - '0') == key[idx]) {
				++idx;
			}
			if (idx > 2) {
				++ans;
				break;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

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

    int firstput = 0;
    int lastput = 0;
    int cnt = 0;

    rep(i, n)
    {
        if (s[i] == '(')
        {
            cnt++;
        }
        else
        {
            cnt--;
            if (cnt == -1)
            {
                cnt = 0;
                firstput++;
            }
        }
    }

    lastput = cnt;
    cout << string(firstput, '(') << s << string(lastput, ')') << 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;
using ll=long long;
using P=pair<int,int>;

int main(){
    int n; cin>>n;
    vector<int> b(n-1);
    rep(i,n-1) cin>>b[i];
    vector<int> a(n);
    a[0]=b[0];
    for(int i=1;i<=n-2;i++){
        a[i]=min(b[i],b[i-1]);
    }
    a[n-1]=b[n-2];
    int ans=0;
    rep(i,n) ans+=a[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
import copy

#n = int(input())
n, k = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#b = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

kotae = 0

for i in range(n) :
    if (i == 0) :
        if (n == 1) :
            break
        if (s[i] == "R" and s[i+1] =="R") :
            kotae += 1
    elif (i == n-1) :
        if(s[i] == "L" and s[i-1] == "L") :
            kotae += 1
    else :
        if (s[i] == "L" and s[i - 1] == "L") :
            kotae += 1
        elif (s[i] == "R" and s[i+1] == "R") :
            kotae += 1

j = 0



for i in range(1, n) :
    if (n == 1) :
        break
    if (s[i] != s[i-1]) :
        j += 1

kotae += min(2*k,j)


print(kotae)

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

int main() {
   int n;cin>>n;
   int ar[n];
   
   for(int i=0;i<n;i++)
   {
       cin>>ar[i];
       //cout<<ar[i]<<" ";
   }
   long long int s=0;
   for(int i=1;i<n;i++)
   { // cout<<ar[i]<<" ";
       if(ar[i]<ar[i-1])
       {
           s+=(long long)(ar[i-1]-ar[i]);
            //cout<<(ar[i-1]-ar[i])<<endl;
           ar[i]=ar[i-1];
          
       }
   }
   cout<<s;
}

Measured memory_bytes: 4340
#include<cstdio>
#include<algorithm>
using namespace std;
int h,w,a,b;
bool f[1001][1001];
int main(){
	scanf("%d%d%d%d",&h,&w,&a,&b);
	for(register int i=1;i<=h;i++){
		if(i<=b)for(register int j=1;j<=a;j++)f[i][j]=true;
		else for(register int j=w;j>a;j--)f[i][j]=true;
	}
	for(register int i=1;i<=h;i++){
		for(register int j=1;j<=w;j++)putchar(f[i][j]?'1':'0');
		putchar('\n');
	}
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;

    REP(f, 9+1) REP(s, 9+1) {
        if (f*s == N) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::cmp::min;
fn main() {
    input! {
        a: u64,
        b: u64,
        c: u64,
        d: u64,
        e: u64,
        f: u64,
    }
    let mut ans_sugar = 0;
    let mut ans_water = 0;
    let mut max_density = -0.1f64;
    for ai in 0..f {
        if a * ai * 100 > f {
            break;
        }
        for bi in 0..f {
            let water = (a * ai + b * bi) * 100;
            if water > f {
                break;
            }
            for ci in 0..f {
                if water + ci * c > f {
                    break;
                }
                if ci * c > water / 100 * e {
                    break;
                }
                let di1 = (f - (water + ci * c)) / d;
                let di2 = (water / 100 * e - ci * c) / d;
                let di = min(di1, di2);
                let sugar = ci * c + di * d;
 
                let density = 100.0 * sugar as f64 / (sugar as f64 + water as f64);
 
                // debug!(density, water, sugar);
                if density > max_density {
                    // debug!(density, ci, di);
                    max_density = density;
                    ans_sugar = sugar;
                    ans_water = water;
                }
            }
        }
    }
 
    println!("{} {}", ans_water + ans_sugar, ans_sugar);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  ll n;cin>>n;
  vector<ll> L;
  rep(i,n){
    ll l;cin>>l;
    L.push_back(l);
  }
  ll ans =0;
  ans = n * (n-1) * (n-2) / 6;
  vector<ll> R;
  rep(i,n){
    rep(j,n){
      if(i<=j) continue;
      R.push_back(L[i] + L[j]);
    }
  }
  sort(all(R));
  reverse(all(R));
  sort(all(L));
  reverse(all(L));
  //Rより大きいようなL
  int li=0, ri=0;
  while(li < L.size()){
    while(ri < R.size() && L[li] < R[ri]) ri++;
    ans -= R.size() - ri;
    li++;
  }
  cout<<ans<<endl;

  return 0;
}


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

int main(){
    int h; cin >> h;
    const int size = h+1;
    ll a[size]; roop(i, 1, size) cin >> a[i];

    roop(i, 1, size){
        printf("node %d: key = %ld, ", i, a[i]);
        if(i-1) printf("parent key = %ld, ", a[i/2]);
        int l = 2*i, r = 2*i + 1;
        if(l < size) printf("left key = %ld, ", a[l]);
        if(r < size) printf("right key = %ld, ", a[r]);
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 3232
inpl = lambda: list(map(int,input().split()))

def output(plus,minus):
    print(sum(plus)-sum(minus))
    p = plus[0]
    for z in minus[1:]:
        print(p,z)
        p -= z
    q = minus[0]
    for w in plus[1:]:
        print(q,w)
        q -= w
    print(p,q)

N = int(input())
A = inpl()
plus = list(filter(lambda x: x>0, A))
minus = list(filter(lambda x: x<0, A))
Np = len(plus)
Nm = len(minus)
Nz = N-Np-Nm

if Np == N:
    plus.sort(reverse=True)
    minus = [plus.pop()]
elif Nm == N:
    minus.sort()
    plus = [minus.pop()]
elif Nz == N:
    plus = [0]*(Nz-1)
    minus = [0]
else:
    if Nm == 0:
        minus = [0]*Nz
    else:
        plus.extend([0]*Nz)

output(plus,minus)

Measured memory_bytes: 62476
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){   
   int n;
   cin>>n;
   vector<string> s(n);
   rep(i,n){
      cin>>s[i];
   }
   int flag=0;
   rep(i,n-1){
      if(s[i][s[i].size()-1]!=s[i+1][0]) {
         cout<<"No";
         flag=1;
         break;
      }
      for(int j=i+1;j<n;j++){
         if(s[i]==s[j]){
            cout<<"No";
            flag=1;
            break;
         }
      }
      if(flag==1) break;
   }
   if(flag==0){
      cout<<"Yes";
   }
   


   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define ve vector

int dp[100005];

int main(){
    int n,k;
    cin >> n >> k;
    ve<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    memset(dp,-1,sizeof(dp));
    dp[0] = 0;
    for(int i = 1; i < k+1; i++){
        for(int x: a){
            if(i-x<0)continue;
            if(dp[i-x]==0) dp[i] = 1;
        }
        if(dp[i]==-1) dp[i] = 0;
    }
    if(dp[k])cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}

Measured memory_bytes: 768