akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main()
{
  int n, l;
  cin >> n >> l;
  vector<string> s;
  string result;

  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    s.push_back(str);
  }

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

  for (int i = 0; i < n; i++) {
    cout << s[i];
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 888
#include <iostream>
using namespace std;
int H, W, A, res;
int C[10][10];
int main(void) {
    cin >> H >> W;
    for (int i = 0; i < 10; ++i)
        for (int j = 0; j < 10; ++j)
            cin >> C[i][j];
    for (int k = 0; k < 10; ++k)
        for (int i = 0; i < 10; ++i)
            for (int j = 0; j < 10; ++j)
                if (C[i][j] > C[i][k] + C[k][j]) C[i][j] = C[i][k] + C[k][j];
    for (int i = 0; i < H; ++i)
        for (int j = 0; j < W; ++j) {
            cin >> A;
            if (A >= 0) res += C[A][1];
        }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
class ST
	def initialize n,iv
		@l = (1<<(n-1).bit_length)-1
		@h = [iv]*(@l+@l+1)
	end

	def max
		return @h[0]
	end

	def [] l,r
		return if r < l
		l,r = @l+l+1,@l+r+1
		lx,rx = @h[l-1],@h[r-1]
		while l <= r
			lx = @h[l-1] if lx < @h[l-1]
			rx = @h[r-1] if rx < @h[r-1]
			l = (l+1)/2
			r = (r-1)/2
		end
		return lx < rx ? rx : lx
	end

	def []= i,v
		j = @l+i+1
		@h[j-1] = v
		@h[j-1] = v while 0 < (j/=2) && @h[j-1] < v
		return v
	end
end

(R,C,K),*RCV = $<.map{|ln| ln.split.map(&:to_i) }

Rs = Array.new(R){ [] }
RCV.each{|s,d,v|
	Rs[s-1] << [d-1,v]
}

r0 = ST.new C,0
while r = Rs.shift
	r.empty? and next or r.sort!

	c0,vs = 0,[0]*4
	until r.empty?
		c,v = r.shift
		r0c = r0[c0,c]
		vs[0] = r0c if vs[0] < r0c
		vs[3] = vs[2]+v if vs[3] < vs[2]+v
		vs[2] = vs[1]+v if vs[2] < vs[1]+v
		vs[1] = vs[0]+v if vs[1] < vs[0]+v
		r0[c] = vs.max
		c0 = c+1
	end
end

p r0.max


Measured memory_bytes: 37188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,t;
    int re=0;
    scanf("%d%d",&x,&t);
    if(t>=x)
    {
        re=0;
    }
    else
    {
        re=x-t;
    }
    printf("%d\n",re);
    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;
    int ans = n % 1000;
    if (ans != 0) ans = 1000-ans;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  bool flag=false;
  if(a==b && a!=c && b!=c) flag=true;
  else if(a!=b && a==c && b!=c) flag=true;
  else if(a!=b && a!=c && b==c) flag=true;
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
// traP is kyopuro circle
// -> true

#include <stdio.h>
#include <algorithm>
using namespace std;

int mp[525][525];

int get(int x,int y,int w,int h){
  int ret = mp[y+h-1][x+w-1];
  if(x>0) ret -= mp[y+h-1][x-1];
  if(y>0) ret -= mp[y-1][x+w-1];
  if(x>0 && y>0) ret += mp[y-1][x-1];
  return ret;
}

int main(){
  while(true){
    int h,w;
    scanf("%d%d",&h,&w);
    if(h==0 && w==0)break;
    for(int i=0;i<h;i++){
      char s[525];
      scanf("%s",&s);
      for(int j=0;j<w;j++){
        mp[i][j] = (s[j]=='*');
      }
    }
    for(int i=0;i<h;i++)for(int j=1;j<w;j++){
      mp[i][j] += mp[i][j-1];
    }
    for(int i=1;i<h;i++)for(int j=0;j<w;j++){
      mp[i][j] += mp[i-1][j];
    }
    int ans = 0;
    for(int x=0;x<w;x++)for(int y=0;y<h;y++){
      // hidari ue : (x,y)
      int hh = h-y;
      for(int ww=1;ww<=w-x;ww++){
        while(hh>0 && get(x,y,ww,hh)!=0)--hh;
        if(hh==0)break;
        int tmp = ww*hh;
        if(tmp>ans)ans=tmp;
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ll t1 = h1 * 60 + m1;
    ll t2 = h2 * 60 + m2;
    cout << (t2 - t1 - k) << endl;
    return 0;
}


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

using namespace std;

const int MOD = 1000000007;

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

  // dp[S] := bicnt(S)番目までの男性と, 女性の部分集合Sでマッチングする場合の数
  vector<int> dp(1 << n, 0);
  vector<int> bitcnt(1 << n, 0);
  // 男性0人と女性0人とマッチングする場合の数は1
  // (マッチングがないという状態が1つある)
  dp[0] = 1;

  for (int bit = 1; bit < (1 << n); bit++) {
    bitcnt[bit] = bitcnt[bit / 2] + (bit & 1);
    for (int lady = 0; lady < n; lady++) {
      // 集合に含まれていないなら無視
      if (!((bit >> lady) & 1)) {
        continue;
      }
      // 差集合はあるbitだけたってるやつを引いてあげればいい
      dp[bit] += dp[bit - (1 << lady)] * a[bitcnt[bit] - 1][lady];
      dp[bit] %= MOD;
    }
  }
  cout << dp[(1 << n) - 1] << endl;
  return 0;
}

Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> arr(100001, 0);

    rep(i, N) {
        int a, b;
        cin >> a >> b;
        arr[a] += b;
    }

    ll cnt = 0;
    ll ans = 1;
    repd(i, 1, 100001) {
        cnt += arr[i];
        if (cnt >= K) {
            ans = i;
            break;
        }
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 2*1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef long long ll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}

int main() {

	int N;
	while(cin >> N,N){
		int a[1024];
		vi idx;
		bool flg = true;
		rep(i,N){
			string str;
			cin >> str;
			if(str == "x") {
				if(idx.size() > 0 && idx[idx.size()-1]+1 == i){
					flg = false;
				}
				idx.pb(i);
				a[i] = INF;
			}
			else{
				a[i] = atoi(str.c_str());
			}
		}
		if(!flg){
			puts("none");
			continue;
		}
		int mn = INF;
		int mx = -INF;
		rep(i,idx.size()) {
			if(idx[i] == 0) {
				mn = min(mn,a[idx[i]+1] - 1);
			}
			else if (idx[i] == N-1) {
				if(N%2 == 1){
					mn = min(mn,a[idx[i]-1] -1);
				}
				else{
					mx = max(mx, a[idx[i]-1] +1);
				}
			}
			else{
				if(idx[i] % 2 == 0 ){
					mn = min(mn,min(a[idx[i]-1],a[idx[i]+1])-1);
				}
				else{
					mx = max(mx, max(a[idx[i]-1],a[idx[i]+1])+1);
				}
			}
		}

		rep(i,N) {
			if(a[i] == INF){
				continue;
			}
			if(i == 0) {
				if(a[i+1] == INF){
					continue;
				}
				if(a[i] > a[i+1]){
					flg = false;
				}
			}
			else if ( i == N -1) {
				if(a[i-1] == INF) {
					continue;
				}
				if(N % 2 == 1){
					if(a[i] > a[i-1]){
						flg = false;
					}
				}
				else{
					if(a[i] < a[i-1]) {
						flg = false;
					}
				}
			}
			else{
				if(a[i+1] == INF && a[i-1] == INF){
					continue;
				}
				if(a[i+1] == INF){
					if(i % 2 == 1){
						if(a[i-1] > a[i]){
							flg = false;
						}
					}
					else{
						if(a[i-1] < a[i]){
							flg = false;
						}
					}
				}
				else if(a[i-1] == INF) {
					if(i % 2 == 1){
						if(a[i+1] > a[i]){
							flg = false;
						}
					}
					else{
						if(a[i+1] < a[i]){
							flg = false;
						}
					}
				}
				else{
					if(i % 2 == 1){
						if(a[i-1] > a[i] || a[i] < a[i+1]){
							flg = false;
						}
					}
					else{
						if(a[i-1] < a[i] || a[i] > a[i+1]) {
							flg = false;
						} 
					}
				}
			}
		}
		if(mn == mx && flg){
			printf("%d\n",mn);
		}
		else if(mn > mx && flg){
			puts("ambiguous");
		}
		else{
			puts("none");
		}

	}

	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
#define in_arr(type, a, n) for(int i = 0; i < n; i++) scanf(type, &((a)[i]));

int main(){
    char c;
    int ret = 0;
    for(int i = 0; i < 3; i++){
        scanf("%c", &c);
        if(c == '1'){
            ++ret;
        }
    }
    printf("%d\n", ret);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<queue>
#include<cstdio>
using namespace std;
int main()
{
    int key;
    char s[1001];
    priority_queue<int>PQ;
    while(1){
            scanf("%s",s);
        if(s[0]=='i'){
            scanf("%d\n",&key);
            PQ.push(key);
        }else if(s[0]=='e'&&s[1]=='x'){
            printf("%d\n",PQ.top());
            PQ.pop();
        }else{
        break;
        }
    }
    return 0;
}


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

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

bool check(char a, char b){
  int a_id = a - 'A';
  int b_id = b - 'A';

  int ax = a_id % 3;
  int ay = a_id / 3;
  int bx = b_id % 3;
  int by = b_id / 3;

  for(int i = 0; i < 4; i++){
    int nx = ax + dx[i];
    int ny = ay + dy[i];
    if(nx == bx && ny == by) return true;
  }
  return false;
}

int main(){
  string s;

  while(cin >> s){
    bool flg = true;

    for(int i = 1; i < s.size(); i++){
      if(!check(s[i], s[i - 1])){
        flg = false;
        break;
      }
    }

    if(flg) cout << s << endl;
  }
}

Measured memory_bytes: 1172
A = []
for _ in range(3):
  A += list(map(int,input().split()))
N = int(input())
B = [int(input()) for _ in range(N)]
C = [0]*9
for i in B:
  if i in A:
    x = A.index(i)
    C[x] = 1
if C[0]*C[1]*C[2] == 1 or C[3]*C[4]*C[5]==1 or C[6]*C[7]*C[8] ==1 or C[0]*C[3]*C[6] ==1 or C[1]*C[4]*C[7]==1 or C[2]*C[5]*C[8] ==1 or C[0]*C[4]*C[8] ==1 or C[2]*C[4]*C[6] ==1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll f(ll x) {
  ll ans;
  if(x%2==0) {
    if((x/2)%2==0) 
      ans = 0 ^ x;
    else 
      ans = 1 ^ x;
  } else {
    if(((x+1)/2)%2==0)
      ans = 0;
    else
      ans = 1;
  }
  return ans;
}

void solve(long long A, long long B){
  ll ans = f(A-1) ^ f(B);
  std::cout << ans << std::endl;
}

int main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    while(1){
        int h,w;cin>>h>>w;
        if(h==0&&w==0)return 0;
        rep(i,h){
            rep(j,w)cout<<"#";
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


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

int main(){
    bool ans=true;
    
    string s;
    int N;

    cin>>N;

    if(N%2==0){
       
        cin>>s;   
        
        for(int i=0;i<N/2;i++){
            if(s[i]!=s[N/2+i]){
                ans=false;
                break;
            }
        }

    }else{
        ans=false;
    }

    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
         cout<<"No"<<endl;   
    }

    return 0;
}

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

typedef long long ll;

int N, K;
ll ans;

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

    int a = N / K;
    int b = (N - K / 2) / K + 1;
    ans += 1LL * a * a * a;
    if(K % 2 == 0 && N >= K / 2) ans += 1LL * b * b * b;
    cout << ans;
}


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

#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;


int dp[101][4][4][4];

int main()
{
    int n;
    cin >> n;
    dp[0][3][3][3] = 1;
    for (int len = 0; len < n+1; len++)
    {
        for (int c1 = 0; c1 < 4; c1++)
        {
            for (int c2 = 0; c2 < 4; c2++)
            {
                for (int c3 = 0; c3 < 4; c3++)
                {
                    if(dp[len][c1][c2][c3] == 0) continue;

                    for (int a = 0; a < 4; a++)
                    {
                        if(a==1 && c1==2 && c2 == 0)continue;
                        if(a==2 && c1==1 && c2 == 0)continue;
                        if(a==1 && c1==0 && c2 == 2)continue;
                        if(a==1 && c2==2 && c3 == 0)continue;
                        if(a==1 && c1==2 && c3 == 0)continue;

                        dp[len+1][a][c1][c2] += dp[len][c1][c2][c3];
                        dp[len + 1][a][c1][c2] %= MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    for (int c1 = 0; c1 < 4; c1++)
    {
        for (int c2 = 0; c2 < 4; c2++)
        {
            for (int c3 = 0; c3 < 4; c3++)
            {
                ans += dp[n][c1][c2][c3];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N =int(input())
l =[int(input()) for i in range(5)]
s=[N]
st=[0 for i in range(5)]
s.extend(st)
ans=0

min_num=min(l)
min_ind=l.index(min_num)

if N%min_num==0:
    times=int(N/min_num)
else:
    times=int(N/min_num)+1

dis=4
ans=times+dis

print(ans)


Measured memory_bytes: 3060
using System;

class Program
{
    static void Main(string[] args)
    {
        var nk = Console.ReadLine().Split();
        var n = int.Parse(nk[0]);
        var k = int.Parse(nk[1]);
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (k <= h[i]) ans++;
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 16096
def main()
  ans = Array.new(N, -1)
  SC.each do |s, c|
    if ans[s-1] == -1
      ans[s-1] = c
    else
      return -1
    end
  end
  
  return -1 if ans[0] == 0 && N > 1
  
  if ans[0] == -1
    if N > 1
      ans[0] = 1 
    else
      ans[0] = 0
    end
  end
  
  N.times do |i|
    if ans[i] == -1
      ans[i] = 0
    end
  end

  return ans.join.to_i
end


N, M = gets.split.map(&:to_i)

SC = M.times.map{gets.split.map(&:to_i)}.uniq
p main


Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<map>
using lint=int64_t;
using namespace std;

#include<vector>
template<typename T>
class UnionFind
{
	public:
	vector<T> parent;
	vector<T> sz;

	UnionFind(T n):parent(n),sz(n)
	{
		for(int i=0;i<n;i++)
			parent[i]=i;
		for(int i=0;i<n;i++)
			sz[i]=1;
	}
	
	void unite(T a,T b)
	{
		a=root(a);
		b=root(b);
		if(a==b)return;
		if(size(a)>size(b))swap(a,b);
		sz[a]+=sz[b];
		sz[b]=0;
		parent[b]=a;
		return;
	}
	
	T root(T n)
	{
		if(parent[n]==n)
			return n;
		else
		{
			T ret=root(parent[n]);
			parent[n]=ret;
			return ret;
		}
	}

	T size(T n)
	{
		return sz[root(n)];
	}
};

int main()
{
	int N,K,L;
	
	cin >> N >> K >> L;
	
	UnionFind<int> uf1(N);
	UnionFind<int> uf2(N);
	for(int i=0;i<K;i++)
	{
		int p,q;
		cin >> p >> q;
		uf1.unite(p-1,q-1);
	}
	for(int i=0;i<L;i++)
	{
		int r,s;
		cin >> r >> s;
		uf2.unite(r-1,s-1);
	}
	
	map<pair<int,int>,int> m;
	for(int i=0;i<N;i++)
		m[make_pair(uf1.root(i),uf2.root(i))]++;
	
	for(int i=0;i<N;i++)
	{
		cout << m[make_pair(uf1.root(i),uf2.root(i))];
		if(i!=N-1)
			cout << " ";
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 15104
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	int h[100010];
	int dp[100010];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		dp[i + 1] = mod;
	}
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < N; i++) {
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1024
//include
//------------------------------------------
#include <bits/stdc++.h>
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> P;
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);
const long long INF = 1000000007;
//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;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    ll ans = 0;
    if(N == 0) ans = 2;
    else if(N == 1) ans = 1;
    else{
        ll L1 = 2, L2 = 1;
        FOR(i,2,N+1){
            ans = L1 + L2;
            L1 = L2;
            L2 = ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
#define inI(x) scanf("%d",&x)
#define inI2(x,y) scanf("%d %d",&x,&y)
#define inI3(x,y,z) scanf("%d %d %d",&x,&y,&z)
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
vector<int>v[100005];
int n,m,num[100005],gr[100005],x,y,k,ans;
bitset<100005>go;
queue<int>q;
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&num[i]);
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%d %d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
    {
        if(!go[i])
        {
            q.push(i);
            while(!q.empty())
            {
                k=q.front();
                go[k]=true;
                gr[k]=i;
                q.pop();
                for(int j=0;j<v[k].size();j++)
                {
                    if(!go[v[k][j]])
                    {
                        q.push(v[k][j]);
                    }
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(gr[i]==gr[num[i]])ans++;
    }
    printf("%d",ans);
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
struct Node{int p,l,r;};
Node T[MAX];
int n,D[MAX],H[MAX];
void Preorder(int u){
  if(u==-1)return;
  cout << " "<<u;
  Preorder(T[u].l);
  Preorder(T[u].r);
}
void Inorder(int u){
  if(u==-1)return;
  Inorder(T[u].l);
  cout << " "<<u;
  Inorder(T[u].r);
}
void Postorder(int u){
  if(u==-1)return;
  Postorder(T[u].l);
  Postorder(T[u].r);
  cout << " " << u;
}


int main(){
  int v,l,r,root = 0;
  cin >> n;
  for(int i=0;i<n;i++)T[i].p=-1;
  for(int i=0;i<n;i++){
    cin >> v >> l >> r;
    T[v].l=l;
    T[v].r=r;
    if(l!=-1)T[l].p=v;
    if(r!=-1)T[r].p=v;
  }
  for(int i=0;i<n;i++)if(T[i].p==-1)root=i;
  cout <<"Preorder"<< endl;
  Preorder(root);
  cout << endl;

  cout <<"Inorder" << endl;
  Inorder(root);
  cout << endl;

  cout << "Postorder" << endl;
  Postorder(root);
  cout << endl;

  return 0;
}

 

Measured memory_bytes: 3084
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

long *memo;
long fib(long n){
	if(n < 2) return 1;
	return memo[n] != -1 ? memo[n] : (memo[n] = fib(n-1) + fib(n-2));
}

int main() {
	memo = new long[64];
	for(int i = 0; i < 64; i++){
		memo[i] = -1;
	}
	
	long n;
	cin >> n;
	cout << fib(n) << endl;
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <map>
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main(){
	int n;
	cin >> n;
	cout << 180*(n-2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

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

    vector<int> time(N);
    for (int i = 0; i < N; i++)
    {
        cin >> time[i];
    }

    int M;
    cin >> M;
    int P[M], X[M];
    for (int i = 0; i < M; i++)
    {
        cin >> P[i] >> X[i];
    }

    int sum;
    int temp;
    bool changed = false;

    for (int i = 0; i < M; i++)
    {
        sum = 0;
        changed = false;
        for (int j = 0; j < N; j++)
        {
            // cout << "time " << time[j] << endl;
            if (j == P[i] - 1)
            {
                temp = time[j];
                // printf("before: time[j] = %d\n", time[j]);
                time[j] = X[i];
                // printf("After: time[j] = %d\n", time[j]);
                changed = true;
            }
            // cout << "time " << time[j] << endl;
            sum += time[j];

            if (changed == true)
            {
                time[j] = temp;
                changed = false;
            }
        }
        printf("%d\n", sum);
    }
    return (0);
}

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

int main() {
  int A,B;
  cin >> A >> B;
  
  if(A + B <= 16 && A <= 8 && B <= 8){
    cout << "Yay!"  << endl;
  }
  
  else{
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
void ran() {
	srand(chrono::steady_clock::now().time_since_epoch().count());
}
long long get_rand() {
	long long a = rand();
	long long b = rand();
	return a * (RAND_MAX + 1ll) + b;
}
void usaco() {
	freopen("problem.in", "r", stdin); 
	freopen("problem.out", "w", stdout);
}
#define endl '\n'
// #define double long double
// #define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;
 
int n, q, block;
const int MXN = 500005;
int arr[MXN];
 
bool sq(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
	if (a.first.first / block == b.first.first / block) {
		return a.first.second < b.first.second;
	}
	return a.first.first < b.first.first;
}
 
int lp = 0;
int rp = 0;
 
int V = 0;
int occ[500005];
 
void add(int x) {
	if ((++occ[x]) == 1) V++;
}
 
void rem(int x) {
	if ((--occ[x]) == 0) V--;
}
 
void movel(int ltarg) {
	while (lp > ltarg) {
		if ((++occ[arr[lp-1]]) == 1) V++;
		lp--;
	}
	while (lp < ltarg) {
		if ((--occ[arr[lp]]) == 0) V--;
		lp++;
	}
}
 
void mover(int rtarg) {
	while (rp > rtarg) {
		if ((--occ[arr[rp]]) == 0) V--;
		rp--;
	}
	while (rp < rtarg) {
		if ((++occ[arr[rp+1]]) == 1) V++;
		rp++;
	}
}
 
int main() {
	
	// ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	scanf("%d %d", &n, &q);
	
	block = 700;
	
	for (int i=0; i<n; i++) {
		scanf("%d", &arr[i]);
	}
	
	pair<pair<int, int>, int> vc[q];
	for (int i=0; i<q; i++) {
		scanf("%d %d", &vc[i].first.first, &vc[i].first.second);
		vc[i].second = i;
		vc[i].first.first--; vc[i].first.second--;
	}
	
	sort(vc, vc+q, sq);
	
	add(arr[0]);
	
	int ans[q];
	
	for (int i=0; i<q; i++) {
		// cout << vc[i].second << endl;
		movel(vc[i].first.first);
		mover(vc[i].first.second);
		ans[vc[i].second] = V;
	}
	
	for (int i=0; i<q; i++) {
		printf("%d\n", ans[i]);
	}
	
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int,int>> a[n];
    REP(i, n) {
        int b;
        cin >> b;
        REP(j, b) {
            int p, q;
            cin >> p >> q;
            a[i].emplace_back(p - 1, q);
        }
    }
    int ans = 0;
    REP(i, 1 << n) {
        bool f = true;
        REP(j, n) {
            if(i & (1 << j)) {
                for(auto c: a[j]) {
                    if(c.second) {
                        if((i & 1 << c.first) == 0) {   // 優先順位は，& より == の方が高い．
                            f = false;
                            break;
                        }
                    } else {
                        if((i & 1 << c.first) != 0) {
                            f = false;
                            break;
                        }                       
                    }
                }
            }
            if(!f) break;
        }
        if(f) {
            int count = 0;  // TODO:count の仕方
            int k = i;
            while(k) {
                if((k & 1) == 1) count++;
                k >>= 1;
            }
            ans = max(count, ans);
        }
    }
    cout << ans << endl;

    return 0;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = A[0]; // さいころ
            int K = A[1]; // 閾値

            double[] Needed = new double[N];
            for(int i = 1; i <= N; i++)
            {
                if (i < K)
                    Needed[i - 1] = 1 / Math.Pow(2, Math.Ceiling(Math.Log(K, 2) - Math.Log(i, 2)));
                else
                    Needed[i - 1] = 1;
            }

            Console.WriteLine(Needed.Sum(x=>x/N));
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
int n,m;
string s;
signed main(){
	cin>>n>>m;
	
	cout<<ll(n*m);
	return 0;
}

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

int main()
{
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  string s;
  cin >> s;
  for (int i = a; i < c; i++)
  {
    if(s.at(i)=='#' && s.at(i+1)=='#'){
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = b; i < d;i++){
    if(s.at(i)=='#' && s.at(i+1)=='#'){
      cout << "No" << endl;
      return 0;
    }
  }
  if(c<d){
    cout << "Yes" << endl;
    return 0;
  }
  for (int i = b-1; i < d;i++){
    if(s.at(i)=='.' && s.at(i+1)=='.' && s.at(i+2)=='.'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res=res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n;
	string s;
	set<string>se;
	cin >> n;
	rep(i, n) {
		cin >> s;
		se.insert(s);
	}
	cout << se.size() << endl;
}

Measured memory_bytes: 19256
function Main(input) {
  input = input.split("\n");	
  var input1 = input[1].split(" ");	
  input1 = input1.map(e=>{
    return parseInt(e,10);
  })
  
  console.log(1/input1.reduce((prev,curr)=>{
    return prev+1/curr
  },0));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
N = int(input())
a = [int(x) for x in input().split()]
for i in range(N):
    v = a[i]
    j = i-1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j-=1
    a[j+1]=v
    print(*a)

Measured memory_bytes: 8088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

// int gcd(int a, int b){
//   if (a%b==0){
//     return(b);
//   }
//   else{
//     return(gcd(b,a%b));
//   }
// }


// ll memo[2020][2020];
// int meke_comb(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int fact(int n){
//   int ans;
//   if(n==1 || n == 0) return 1;
//   ans = n*fact(n-1);
//   return ans;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }




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



Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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


fn main() {
    
    input! {
        d: usize,
        c: [i32; 26],
        s: [[i64; 26]; d],
    }

    let t = (0..d).map(|i| i % 26 + 1);
    for e in t {
        println!("{}", e);
    }
    
}


Measured memory_bytes: 2264
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,d,e,i,j,k,x,y,l=0,lt=0;
cin>>a>>b>>c;
 vector<ll>v;
 v.push_back(a);
v.push_back(b);
v.push_back(c);
sort(v.begin(),v.end());
x=abs(v[2]-v[0]);
y=abs(v[2]-v[1]);
if(x%2==0&&y%2==0)
{
  cout<<(x/2)+(y/2)<<endl;
}
else if(x%2==1&&y%2==1)
{
   v[0]++;
   v[1]++;
  cout<<((v[2]-v[0])/2)+((v[2]-v[1])/2)+1<<endl;
}
else 
{
  if(x%2==0)
  {
   v[0]++;
   v[2]++;
  cout<<((v[2]-v[0])/2)+((v[2]-v[1])/2)+1<<endl;
  }
 else
  
  {
   v[1]++;
   v[2]++;
  cout<<((v[2]-v[0])/2)+((v[2]-v[1])/2)+1<<endl;
  
  }
}

}

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

#define pr pair<int, int>

using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;


//#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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


int a[10010][10010], b[1000];
int dp[10010][3];
 

int main()
{
    int N, X, Y; cin >> N >> X >> Y;
    int sum[N] = {0};
    for(int i = 1; i < N; i++){
        for(int j = i+1; j <= N; j++){
            for(int k = 1; k <= j-i; k++){
                int dist;

                if(j <= X){
                    dist = j-i;
                }
                else if(i <= X && j < Y){
                    dist = min(j-i,X-i+1+(Y-j));
                }
                else if(i <= X){
                    dist = j-i-(Y-X-1);
                }
                else{
                    dist = min(j-i, abs(i - X) + 1 + abs(j - Y));
                }
                if(k == dist){
                    PRINT(i)
                    PRINT(j)
                    PRINT(k)
                    
                    sum[k] ++;
                }

            }
        }
    }
    for(int i = 1; i < N; i++){
        cout << sum[i] << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define equals(a, b) (fabs((a) - (b)) < EPS)

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

const int INF = 1 << 28;
const ll LLINF = 1LL << 60;
const double EPS = 1e-9;

map < int , vector < int > > mp;
int dp[1 << 26];

int main()
{
    int bit = 0;
    string S;
    
    fill_n(dp, 1 << 26, INF);
    dp[0] = 0;
    cin >> S;
    for(int i = 0; i < S.size(); i++) {
        bit ^= (1 << (S[i] - 'a'));
        for(int j = 0; j < 26; j++) {
            dp[bit] = min(dp[bit], dp[bit ^ (1 << j)] + 1);
        }
    }

    cout << dp[bit] + (dp[bit] == 0) << endl;
            
    return (0);
}

Measured memory_bytes: 262912
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

from collections import deque

H, W = map(int, input().split())

start, goal = (1, 1), (H, W)
# 左右上下
directions = [[0,-1],[0,1],[-1,0],[1,0]]
# 四方に一回り大きいフィールドを作る
field = [['*'] * (W+2) for i in range(H+2)]
for i in range(1,H+1):
    row = list(input())[:-1]
    for j in range(1, W+1):
        field[i][j] = row[j-1]

# 移動距離メモ
memo = [[float('inf')] * (W+2) for i in range(H+2)]
memo[start[0]][start[1]] = 0
# 訪問済メモ
visited = [[0] * (W+2) for i in range(H+2)]
# 移動元メモ
prevs = [[None] * (W+2) for i in range(H+2)]

def bfs():
    que = deque()
    # スタート位置
    que.append(start)
    while len(que) != 0:
        cur = que.popleft()
        # 見終わった場所はもうやらない
        if visited[cur[0]][cur[1]] == 1:
            continue
        # 訪問済にする
        visited[cur[0]][cur[1]] = 1
        # 4方向見る
        for direction in directions:
            # 上下左右に1つずつ動かした座標
            nxt = list(map(lambda x,y: x+y, cur, direction))
            # 壁か黒マスはスキップ
            if field[nxt[0]][nxt[1]] == '*' or field[nxt[0]][nxt[1]] == '#':
                continue
            # 現在位置+1の距離を移動先に記録
            if field[nxt[0]][nxt[1]] == '.' and memo[nxt[0]][nxt[1]] > memo[cur[0]][cur[1]] + 1:
                memo[nxt[0]][nxt[1]] = memo[cur[0]][cur[1]] + 1
                # ここで移動元のマスを記録
                prevs[nxt[0]][nxt[1]] = (cur[0], cur[1])
                # キューに次のマスを足す
                que.append(nxt)

# 最短経路を出す
bfs()
# ゴールに辿り着けない場合
if memo[goal[0]][goal[1]] == float('inf'):
    print(-1)
    exit()
# 最短経路で使うマスに目印をつける
field[goal[0]][goal[1]] = '@'
nxt = prevs[goal[0]][goal[1]]
for _ in range(memo[goal[0]][goal[1]]):
    field[nxt[0]][nxt[1]] = '@'
    nxt = prevs[nxt[0]][nxt[1]]
# 残っている白マスが塗り替えられる場所
ans = 0
for i in range(1,H+1):
    for j in range(1, W+1):
        if field[i][j] == '.':
            ans += 1
print(ans)


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

int main(){
    string s;
    cin >> s;
    int k = s.size();
    int ans = 1'000'000;
    for (int i = 0; i < 26; i++){
        bool check = false;
        for (int j = 0; j < k; j++) if (s[j] == 'a' + i) check = true;
        if (!check) continue;
        string t = s;
        int tmp = 0;
        while (1){
            bool flag = true;
            for (int j = 1; j < t.size(); j++) if (t[j - 1] != t[j]) flag = false;
            if (flag){
                ans = min(tmp, ans);
                break;
            }
            tmp++;
            string nt = "";
            for (int j = 0; j < t.size() - 1; j++){
                if (t[j] == 'a' + i || t[j + 1] == 'a' + i) nt.push_back('a' + i);
                else nt.push_back(t[j]);
            }
            t = nt;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    loop {
        let n: usize = sc.read();
        if n == 0 {
            break;
        }
        use std::collections::HashMap;
        let mut counter = HashMap::new();
        let vc: Vec<String> = sc.read_vec(n);
        for (i, s) in vc.iter().cloned().enumerate() {
            *counter.entry(s).or_insert(0) += 1;
            let mut vs = counter.iter().map(|(k, v)| (v, k)).collect::<Vec<_>>();
            vs.sort();
            vs.reverse();
            let first = *vs[0].0;
            let second = if vs.len() > 1 { *vs[1].0 } else { 0 };
            if first > second + (n - 1 - i) {
                println!("{} {}", vs[0].1, i + 1);
                break;
            }
            if i + 1 == n {
                println!("TIE");
            }
        }
    }
}



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

int main() {
  int N, L;
  cin >> N >> L;
  string S[N];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S, S + N);
  for (int i = 0; i < N; i++) {
    cout << S[i];
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> P;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int main(){
	int a, b, ans=0;

	cin >> a >> b;
	if( a > 0 ) ans = 1;
	else if( a <= 0 && b >= 0 ) ans = 0;
	else{
		if( (-a + min(0,b+1))%2 ){
			ans = -1;
		}else{
			ans = 1;
		}
	}

	if( ans == 1 ) cout << "Positive" << endl;
	if( ans == -1 ) cout << "Negative" << endl;
	if( ans == 0 ) cout << "Zero" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int X,A,B;
  scanf("%d %d %d",&X,&A,&B);
  if(B<=A){
    printf("delicious\n");
  }
  if((A<B) && (B<=X+A)){
    printf("safe\n");
  }
  if(B>X+A){
    printf("dangerous\n");
  }
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(){
  char t[1001],w[11],esa[]="END_OF_TEXT";
  int st,i,total=0;
  scanf("%s",&w);
  while(scanf("%s",&t)){
    if(strcmp(t,esa)==0)break;
    st=strlen(t);
    for(i=0;i<st;i++){
      if(t[i]<91 && t[i]>64)t[i]+=32;
    }
    if(strcmp(t,esa)==0)break;
    if(strcmp(t,w)==0)total++;
  }
  printf("%d\n",total);
  return(0);
}

Measured memory_bytes: 548
#include<cstdio>
long long a,b,k;
main(){
    scanf("%lld%lld%lld",&k,&a,&b);
    if(k<=a)return puts("1"),0; //按思路特判
    else if(a<=b)return puts("-1"),0;   //按思路特判
    else printf("%lld\n",((k-a)/(a-b)+bool((k-a)%(a-b)))<<1|1);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

constexpr int INF = 1e9;

int a[100];

int main(void) {
    int i, j, n;
    cin >> n;
    REP (i,n) cin >> a[i];
    int ans = INF;
    REP (i,-100,100) {
        int cost = 0;
        REP (j,n) cost += (a[j]-i)*(a[j]-i);
        ans = min(ans,cost);
    }
    cout << ans << endl;
    return 0;
}


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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  int h, w;
  cin >> h >> w;
  arrst(s,h);
  rep(i,h){
    prt(s[i]);
    prt(s[i]);
  }
}


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

int main() {
  string S;
  cin >> S;

  vector<int> cnt(2);
  for (int i = 0; i < S.size(); ++i) {
    cnt[S[i] == '1']++;
  }

  cout << 2 * min(cnt[0], cnt[1]) << endl;
}


Measured memory_bytes: 512