akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_a
//A - Subscribers
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N, A, B; cin>>N>>A>>B;    
    ll ans0 = min(A,B);
    ll ans1 = max(0LL, A+B-N);
    cout<<ans0<<" "<<ans1<<endl;
    return 0;
}

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

int main()
{
 string s;
 cin>>s;
 if(s=="SUN") cout<<"7";
 else if(s=="MON") cout<<"6";
 else if(s=="TUE") cout<<"5";
 else if(s=="WED") cout<<"4";
 else if(s=="THU") cout<<"3";
 else if(s=="FRI") cout<<"2";
 else if(s=="SAT") cout<<"1";
 return 0;
}


Measured memory_bytes: 3512
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader(); 
        int N, L;
        {int[] a = r.ii(); N = a[0]; L = a[1];}
        int[] taste = new int[N];
        for(int i = 0; i < N; i++)
            taste[i] = L+i;
        int min = Math.abs(taste[0]);
        int minI = 0;
        for(int i = 1; i < N; i++){
            if(Math.abs(taste[i]) < min){
                min = Math.abs(taste[i]);
                minI = i;
            }
        }
        int sum = 0;
        for(int t : taste)
            sum += t;
        println(sum-taste[minI]);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, m, i, j, k, x, b, ans;
	cin >> n >> m;
	vector<int> a(m), c(m);
	for (i = 0; i < m; i++) {
		cin >> a[i] >> b;
		c[i] = 0;
		for (j = 0; j < b; j++) {
			cin >> x;
			c[i] += (1 << (x - 1));
		}
	}

	vector<vector<int>> dp(m + 1, vector<int>(1 << n, 1000000000));
	dp[0][0] = 0;
	for (i = 0; i < m; i++) {
		for (j = 0; j < (1 << n); j++) {
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			x = j | c[i];
			dp[i + 1][x] = min(dp[i + 1][x], dp[i][j] + a[i]);
		}
	}

	ans = dp[m][(1 << n) - 1];
	if (ans == 1000000000) ans = -1;
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 16384
n = gets.to_i
arr = gets.chomp.split.map(&:to_i)
arr2 = arr.sort
wrong = 0
arr.zip(arr2){|x, y| wrong += 1 if x != y}
sorted = false
if wrong == 0
    sorted = true
    puts 0
else
    gets.to_i.times{|i|
        x, y = gets.chomp.split.map{|x| x.to_i - 1}
        arr[x], arr[y] = arr[y], arr[x]
        wrong -= 1 if arr2[x] == arr[x]
        wrong += 1 if arr2[x] == arr[y]
        wrong -= 1 if arr2[y] == arr[y]
        wrong += 1 if arr2[y] == arr[x]
        if wrong == 0
            sorted = true
            puts i + 1
            break
        end
    }
end
puts -1 unless sorted



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

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p%i == 0) return false;
	}
	return true;
}

int n;

int main() {
	cin >> n;
	for (int i = 6; i <= 55555; i += 5) {
		if (isprime(i) == true) {
			
			cout << i << " "; n--;
		}
		if (n == 0) break;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
p = input().replace(" ", "")
q = input().replace(" ", "")

array_list = [""]
for i in range(1, n + 1):
    array_list_next = []
    for array in array_list:
        for j in range(1, n + 1):
            if str(j) not in array:
                array_list_next.append(array + str(j))
    array_list = array_list_next

print(abs(array_list.index(p) - array_list.index(q)))


Measured memory_bytes: 14656
h,w=[int(s)for s in input().split(" ")]
map_=[[True if c=='c' else False for c in input()]for i in range(h)]
dis=[['' for i in range(w)]for j in range(h)]
for i in range(h):
    distance=-1
    for j in range(w):
        if map_[i][j]==True:distance=0
        elif distance!=-1:distance+=1
        dis[i][j]=str(distance)
for d in dis:
    print(' '.join(d))

Measured memory_bytes: 8344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int a, b, q;
    cin >> a >> b >> q;
    int s[a], t[b];
    rep(i, 0, a) cin >> s[i];
    rep(i, 0, b) cin >> t[i];
    rep(i, 0, q) {
        int x;
        cin >> x;
        auto itr_mns = lower_bound(s, s + a, x);
        auto itr_mnt = lower_bound(t, t + b, x);
        auto itr_mxs = lower_bound(s, s + a, x);
        auto itr_mxt = lower_bound(t, t + b, x);
        int mns = *itr_mns;
        int mnt = *itr_mnt;
        int mxs = *itr_mxs;
        int mxt = *itr_mxt;
        if (itr_mns == s) {
            mns = -inf;
        } else if (itr_mxs == s + a) {
            itr_mns--;
            mns = *itr_mns;
            mxs = inf;
        } else {
            itr_mns--;
            mns = *itr_mns;
        }
        if (itr_mnt == t) {
            mnt = -inf;
        } else if (itr_mxt == t + b) {
            itr_mnt--;
            mnt = *itr_mnt;
            mxt = inf;
        } else {
            itr_mnt--;
            mnt = *itr_mnt;
        }
        // cout << mns << " " << mxs << "\n";
        // cout << mnt << " " << mxt << "\n";
        int ans = min({abs(x + mxt - 2 * mns), abs(x + mxs - 2 * mnt), abs(2 * mxs - x - mnt), abs(2 * mxt - x - mns),
                       abs(x - min(mns, mnt)), abs(max(mxs, mxt) - x)});
        // cout << abs(x + mxt - 2 * mns) << " " << abs(x + mxs - 2 * mnt) << " " << abs(2 * mxs - x - mnt) << " "
        //  << abs(2 * mxt - x - mns) << " " << abs(x - min(mns, mnt)) << " " << abs(max(mxs, mxt) - x) << "\n";
        cout << ans << "\n";
    }
}

Measured memory_bytes: 5204
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li, li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li, li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = LLONG_MAX;
constexpr li mod = 1000000007;

void Yes(li b) {
	if (b)cout << "Yes";


	else cout << "No";
}
void yes(li b) {
	if (b)cout << "yes";
	else cout << "no";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cout.precision(16);

	li N;
	cin >> N;

	vector<int> A(N);

	Input(A);

	vector<int> primeset;

	for (int i = 2; i <= 1000; i++) {
		bool isp = 1;
		for (int j = 2; j * j <= i; j++) {
			if (!(i % j)){isp = 0; break;}
		}
		if (isp) primeset.eb(i);
	}

	int GCD = A[0];
	set<int> foundp;
	bool ispcop = 1;

	for (auto && a : A) {
		GCD = __gcd(GCD, a);

		if (ispcop) {

			for (auto && p : primeset) {
				if(a<p)break;
				if (!(a % p)) {
					if (foundp.count(p)) {
						ispcop = 0;
						break;
					}
					else {foundp.insert(p);}
				}

				while (!(a % p)) {
					a /= p;
				}

			}


			if (a != 1) {
				if (foundp.count(a)) {
					ispcop = 0;
					break;
				}
				else {foundp.insert(a);}
			}

		}


	}


	if (ispcop) {
		cout << "pairwise coprime";
	}
	else if (GCD == 1) {
		cout << "setwise coprime";
	}
	else {
		cout << "not coprime";
	}



}

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

int ans[100000];
int main() {
  int n;
  cin >> n;
  
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    --a;
    ans[a] = i;
  }
  
  for (int i = 0; i < n; ++i) {
    cout << ans[i] + 1 << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

void output(bool yes) { puts(yes? "YES": "NO"); }

int N;
int A[100111];
LL dp[100111];
int par[100111];
VI G[100111];
VI ord;

int main() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x-- ;y--;
	G[x].push_back(y);
	G[y].push_back(x);
    }

    if (N == 2) {
	output(A[0] == A[1]);
	return 0;
    }

    int r = 0;
    REP (i, N) if (G[i].size() > 1u) { r = i; break; }
    ord.reserve(N); ord.push_back(r);
    par[r] = -1;
    REP (i_, N) {
	int v = ord[i_];
	EACH (e, G[v]) if (*e != par[v]) {
	    par[*e] = v;
	    ord.push_back(*e);
	}
    }

    bool yes = true;

    REP (i_, N) {
	int v = ord[N-1-i_];
	vector<LL> z;
	EACH (e, G[v]) if (*e != par[v]) {
	    z.push_back(dp[*e]);
	}

	if (z.size()) {
	    sort(z.begin(), z.end());
	    LL su = 0;
	    EACH (e, z) su += *e;

	    LL t;

	    if (z.back() > su - z.back()) t = 2 * z.back() - su;
	    else t = 0;

	    LL x = su - A[v];
	    LL y = A[v] - t - x;

	    if (x >= 0 && y >= 0) {
		dp[v] = y + t;
	    } else {
		yes = false;
		break;
	    }
	} else {
	    dp[v] = A[v];
	}
    }

    if (dp[r] != 0) yes = false;
    output(yes);

    return 0;
}



Measured memory_bytes: 7808
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  ll n,ans=1;
  scanf("%lld",&n);
  for(ll i=2;i<=sqrt(n);i++)if(n%i<1)ans=i;
  PRL(ans+n/ans-2);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a[10]={0};
  int d[10];
  bool f[10] = {0};
  rep(i,10){
    d[i] = INF;
  }
  d[1] = 0;
  int h,w;
  cin >> h >> w;
  int c[10][10];
  rep(i,10) rep(j,10)
      cin >> c[i][j];

  rep(i,h) rep(j,w){
    int t;
    cin >> t;
    if(t>=0) a[t]++;
  }

//ダイクストラ法
  while(true){
    int minc = INF;
    int u=-1;
    rep(i,10){
      if(!f[i] && d[i] < minc){
        minc = d[i];
        u = i;
      }
    }
    if(u==-1){
      break;
    }
    f[u] = true;
    rep(j,10){
      d[j] = min(d[j],c[j][u]+minc);
    }
  }
  long long ans;
  rep(i,10){
    ans += a[i] * d[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int ans = 100000000;
  bool ok = false;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> s(tmp);
    int memo = 0;
    vector<int> S(M);
    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        memo += C.at(i);
        for (int j = 0; j < M; j++) {
          S.at(j) += A.at(i).at(j);
        }
      }
    }
    for (int i = 0; i < M; i++) {
      if (S.at(i) < X) {
        break;
      }
      if (i == M - 1) {
        ok = true;
        ans = min(ans, memo);
      }
    }
  }
  if (ok) {
    cout << ans << endl;
  }
  else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, k;
    cin>>n>>k;
    set<int> st;
    rep(i, k){
        int d;
        cin>>d;
        rep(i, d){
            int a;
            cin>>a;
            st.insert(a);
        }
    }
    cout<<n-st.size()<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;

template <typename T, T mod>
class ModuloCombination {
 private:
  std::vector<T> factrial, inverse_factrial;
  T Pow(T x, T y) {
    if (y == 0) return 1;
    if (y % 2 == 0) return Pow(x * x % mod, y / 2);
    return x * Pow(x, y - 1) % mod;
  }

 public:
  ModuloCombination(T n) : factrial(n + 1), inverse_factrial(n + 1) {
    inverse_factrial[0] = factrial[0] = 1;
    for (T i = 1; i <= n; i++) {
      factrial[i] = factrial[i - 1] * i % mod;
      inverse_factrial[i] = Pow(factrial[i], mod - 2);
    }
  }
  T operator()(T n, T k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return factrial[n] * inverse_factrial[k] % mod * inverse_factrial[n - k] % mod;
  }
};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<vector<int>> v(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }

  ModuloCombination<ll, mod> c(k - 1);
  vector<ll> p(n);
  p[0] = 1;
  for (ll i = 1; i <= n - 1; i++) p[i] = p[i - 1] * i % mod;

  function<ll(int i, int j)> dfs = [&](int i, int j) -> ll {
    ll r;
    if (i == j) {
      r = k * (c(k - 1, v[j].size()) * p[v[j].size()] % mod);
    } else {
      r = c(k - 2, v[j].size() - 1) * p[v[j].size() - 1] % mod;
    }
    r %= mod;
    for (auto e : v[j]) {
      if (e == i) continue;
      r *= dfs(j, e);
      r %= mod;
    }
    return r;
  };

  cout << dfs(0, 0) << endl;
}


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

int main()
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);

    for (int i = 0; i < n; i++) {
        int temp;
        std::cin >> temp;
        temp--;

        a[i] = temp;
    }

    int count = 0;
    for (int i = 0; i < n; i++) {
        if (a[a[i]] == i) {
            count++;
        }
    }

    std::cout << count / 2 << std::endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 

const int mod = 1000000007;
const int inf = 1e9;

int main(){
    int a[9];
    rep(i,0,9){cin >> a[i];}
    int n;
    cin >> n;
    int b[n];
    rep(i,0,n){cin >> b[i];}
    rep(i,0,9){
        rep(j,0,n){
            if(a[i]==b[j]){a[i] = 0;}
        }
    }
    bool flag = false;
    if(a[0] == a[1] && a[0] == a[2]){flag = true;}
    if(a[3] == a[4] && a[3] == a[5]){flag = true;}
    if(a[6] == a[7] && a[7] == a[8]){flag = true;}
    if(a[0] == a[3] && a[0] == a[6]){flag = true;}
    if(a[1] == a[4] && a[1] == a[7]){flag = true;}
    if(a[2] == a[5] && a[2] == a[8]){flag = true;}
    if(a[0] == a[4] && a[0] == a[8]){flag = true;}
    if(a[2] == a[4] && a[2] == a[6]){flag = true;}
    if(flag){cout << "Yes";}else{cout << "No";}

}

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

int main() {
    int n;
    int odd = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        if (x & 1)
            odd++;
    }
    puts((n == 1 || odd % 2 == 0) ? "YES" : "NO");
}


Measured memory_bytes: 128
#include<stdio.h>

#define N 8
#define NOT_FREE 1
#define FREE 0

void putQueen(int);
void printBoard(void);

int col[8],dpos[1000]={0},dneg[1000]={0},row[8]={-1},col[8];

int r[8],c[8],k,A[8][8];

int main(){

  int i,j;

  /* for(i=0;i<N;i++){
    for(j=0;j<N;j++){

      col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;

    }
    row[i]=-1;   
  }*/

  scanf("%d",&k);

  for(i=0;i<k;i++){

    scanf("%d%d",&r[i],&c[i]);

    // row[r[i]]=NOT_FREE;
    // col[c[i]]=NOT_FREE;

    A[r[i]][c[i]]=NOT_FREE;
    
    
  }

  putQueen(0);

   return 0;

}

void putQueen(int i){

  int j,m,sirusi=0;

  if(i==N){

    //  printf("wa-i\n");
    printBoard();
    return ;
  }

  // for(m=0;m<k;m++){
  // printf("r[m]:%d,c[m]:%d\n",r[m],c[m]);
  // }
    

  for(j=0;j<N;j++){

    // printf("<count>i:%d,j:%d,[i+j]:%d,[i-j+N-1]:%d,col[j]:%d,dpos[i+j]:%d,dneg[i-j+N-1]:%d\n",i,j,i+j,i-j+N-1,col[j],dpos[i+j],dneg[i-j+N-1]);

    if(col[j]==NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1]==NOT_FREE) continue;

    //printf("wa-i\n")
    
   

    //printf("sirusi %d\n",sirusi);
      
   

      row[i] = j;
      col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
      
      
      //printf("i:%d,j:%d\n",i,j);
      // printf("row:%d,col:%d\n",row[i],col[j]);

      //if(i==4&&j==6) printf("[i+j]:%d,[i-j+N-1]:%d,dpos:%d,dneg:%d\n",i+j,i-j+N-1,dpos[i+j],dneg[i-j+N-1]);
      
      
      putQueen(i+1);
      
      col[j]=dpos[i+j]=dneg[i-j+N-1] = FREE;
    
      
    
  }

    

}

void printBoard(void){

  int i,j;

  // printf("wa-i\n");

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(A[i][j]==NOT_FREE && row[i]!=j) return;
    }
  }
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){

      if(row[i]==j) printf("Q");
      else printf(".");

    }
    printf("\n");
  }

  return ;

}

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

ifstream in ("test.in" );
ofstream out("test.out");

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n;
    cin >> n;
    
    int nr0 = 0, nr1 = 0, nr2 = 0;
    for (int i = 1; i <= n; ++i) {
        int x, nr = 0;
        cin >> x;
        
        while (x % 2 == 0) {
            ++nr;
            x >>= 1;
        }
        
        if (nr == 0) ++nr0; else
        if (nr == 1) ++nr1; else
            ++nr2;
    }
    
    if (nr0 > nr2 + 1)
        cout << "No";
    else
    if (nr0 == nr2 + 1 && nr1 > 0)
        cout << "No";
    else
        cout << "Yes";
    

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), A_original(N);
  for (int i=0; i<N; i++) {
    cin >> A.at(i);
  }
  for (int i=0; i<N; i++) {
    A_original.at(i) = A.at(i);
  }
  sort(A.begin(), A.end());
  int max=A.at(N-1), second=A.at(N-2);
  for (int i=0; i<N; i++) {
    if (max == A_original.at(i)) {
      cout << second << endl;
    }
    else {
      cout << max << endl;
    }
  }
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double X = in.nextDouble();
        int counter = 0;
        long i = 100;
        while(i < X) {
            i +=  (i * 0.01);
            counter++;
        }
        System.out.println(counter);
    }
}


Measured memory_bytes: 37324
# include <iostream>
using namespace std;
string a;
int x;
void work (void)
{
	if (x<1200)
	a="ABC";
else if (x<2800)
    a="ARC";
else a="AGC";
    cout<<a;
}
int main (void)
{
	cin>>x;
	work ();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a;
int b[15],q;
int main()
{
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='0'){q++;b[q]=0;} 
        if(a[i]=='1'){q++;b[q]=1;}
        if(a[i]=='B'&&q>=1)q--;
    }    
    for(int i=1;i<=q;i++)cout<<b[i];
    cout<<endl;
    return 0;
}

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

class check_point{
    public:
    int t,x,y;
};

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

    check_point A[N+1];

    A[0].x = 0;
    A[0].y = 0;
    A[0].t = 0;

    for(int i=1;i<N+1;i++){
        scanf("%d",&A[i].t);
        scanf("%d",&A[i].x);
        scanf("%d",&A[i].y);
    }

    bool flg = true;

    for(int i=0;i<N;i++){
        int min = abs(A[i].x - A[i+1].x) + abs(A[i].y - A[i+1].y);
        int time = A[i+1].t - A[i].t;

        if(min > time || ((time - min)%2 == 1)){
            flg = false;
            break;
        }  
    }

    if(flg){
        printf("%s\n","Yes");
    }else{
        printf("%s\n","No");
    }

    return 0;
}

Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[5]={-1,0,1,0,0};
int dy[5]={0,-1,0,1,0};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    string s;cin>>s;
    if(s=="ABC")cout<<"ARC"<<endl;
    else cout<<"ABC"<<Endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;




int main()
{

    int a,b,c,d,e,f,ans;
    scanf("%d %d %d %d",&a,&b,&c,&d);

    e=((a+d-1)/d);
    f=((c+b-1)/b);

    if(e-f>=0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    

    return 0;
}

Measured memory_bytes: 1576
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    long long int n;
    cin >> n;
    vector<long long int> a;
    vector<long long int> b;
    for(long long int i = 0;i <= n;i++)
    {
        long long int A;
        cin >> A;
        a.push_back(A);
    }
    for(long long int i = 0;i < n;i++)
    {
        long long int B;
        cin >> B;
        b.push_back(B);
    }
    long long int ans = 0;
    for(long long int i = 0;i < n;i++)
    {
        if(a[i] > b[i])
        {
            ans += b[i];
            a[i] -= b[i];
        }
        else
        {
            if(a[i]+a[i+1] <= b[i])
            {
                ans += a[i]+a[i+1];
                a[i]=a[i+1]=0;
            }
            else
            {
                ans += b[i];
                a[i+1] -= b[i]-a[i];
                a[i] = 0;
            }
        }
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  int a[100001] = {};
  rep(i, 0, n) cin >> a[i];
  sort(a, a + n);
  int ok = -1, oo = 0;
  rep(i, 0, n - 1) {
    if(ok >= 0) {
      if((oo + a[i]) * 2 < a[i + 1]) ok = -1;
    }else {
      if((oo + a[i]) * 2 >= a[i + 1]) ok = i;
    }
    oo += a[i];
  }

  cout << n - ok << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <map>

using namespace std;

int main() {
	long long n;
	cin >> n;

	map<long long, int> factors;

	long long i = 2;
	long long maxi = 1e6;
	while (n > 1 && i <= maxi) {
		if (n % i == 0) {
			factors[i]++;
			n /= i;
		} else {
			i++;
		}
	}
	if (n > 1) {
		factors[n]++;
	}

	int ans = 0;
	for (auto p: factors) {
		// printf("%13lld: %3d\n", p.first, p.second);
		int tmp = p.second;
		int j = 1;
		while (tmp >= j) {
			ans++;
			tmp -= j;
			j++;
		}
	}

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


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    
    return 0;
}


Measured memory_bytes: 3636
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)
n=int(input())
for i in range(n):
    if i==0:
        tmp=int(input())   
    else:
        tmp=lcm(tmp,int(input()))
print(tmp)

Measured memory_bytes: 3060
#include<stdio.h>

typedef struct {
	long p,q,r,b;
} mobile;

mobile bar[100];

long kbs(long a, long b){
	if(a<b) return kbs(b,a);
		if(b<=0) return a;
		return kbs(b,a%b);
}

long weight(int i){
	if(i==0) return 1;
	long j,a,b;
	a=bar[i-1].q*weight(bar[i-1].b);
	b=bar[i-1].p*weight(bar[i-1].r);
	j=kbs(a,b);
	j=a/j*b;
	return j/bar[i-1].p+j/bar[i-1].q;
}

int main(){
	int n,i,f,current;
	long heavy,max;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%ld %ld %ld %ld",&bar[i].p,&bar[i].q,&bar[i].r,&bar[i].b);
		}
		f=1;
		current=1;
		while(f){
			f=0;
			for(i=0;i<n;i++){
				if(bar[i].r==current || bar[i].b==current){
					current=i+1;
					f=1;
					break;
				}
			}
		}
		printf("%ld\n",weight(current));
		scanf("%d",&n);
	}
    return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int k =0;
        for(int i=a;i<=b;i++){
            if(c%i==0){
                k++;
            }
        }
        System.out.println(k);
    }
}


Measured memory_bytes: 26292
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main(){
	fast;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i+=2)
		cout<<s[i];
	return 0;
}



Measured memory_bytes: 3752
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;
	
ll dist[200007];
bitset<2000007> vis;
vi graph[200007];

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	int n, m; cin >> n >> m;
	FOR(i, m){
		int a, b; cin >> a >> b;
		a--; b--;
		graph[a].PB(b);
		graph[b].PB(a);
	}

	FOR(i, n) dist[i] = MOD;
	dist[0] = 0;
	queue<int> q;
	q.push(0);
	while(!q.empty()){
		int atual = q.front();
		q.pop();
		if(vis[atual]) continue;
		vis[atual]=true;
		for(auto& v : graph[atual]){
			if(!vis[v]){
				dist[v] = min(dist[v], dist[atual]+1);
				q.push(v);
			}
		}
	}

	if((int)vis.count() == n){
		cout << "Yes\n";
		FOR(i, n-1){
			int best = graph[i+1][0];
			for(auto& v : graph[i+1]){
				if(dist[v] < dist[best])
					best = v;
			}
			cout << best+1 << '\n';
		}
	}else
		cout << "No\n";

	return 0;
}

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

using namespace std;

int a,b,c,n;

#define ld long double
#define N 301
ld f[N][N][N];

ld F(int x, int y, int z)
{
    if (x == 0 && y == 0 && z == 0)
        return 0;
    if (f[x][y][z])
        return f[x][y][z];
    f[x][y][z] = 1;
    if (x > 0)
    {
        f[x][y][z] += F(x-1,y,z) * x / n;
    }
    if (y > 0)
    {
        f[x][y][z] += F(x+1,y-1,z) * y / n;
    }
    if (z > 0)
    {
        f[x][y][z] += F(x,y+1,z-1) * z / n;
    }
    f[x][y][z] /= (1.0* (x + y + z) / n);
    return f[x][y][z];
}

int main()
{
    cin >> n;
    for (int i=0; i<n; i++)
    {
        int x; cin >> x;
        if (x == 1)
            a++;
        else if (x == 2)
            b++;
        else
            c++;
    }
    cout << setprecision(12) << fixed << F(a,b,c);
    return 0;
}


Measured memory_bytes: 426240
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll mod=1000000007;
ll combi(ll N_, ll C_) {
    const int NUM_=400001;
    static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
    if (fact[0]==0) {
        inv[1]=fact[0]=factr[0]=1;
        for (int i=2;i<=NUM_;++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
        for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mod, factr[i]=factr[i-1]*inv[i]%mod;
    }
    if(C_<0 || C_>N_) return 0;
    return factr[C_]*fact[N_]%mod*factr[N_-C_]%mod;
}
ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:combi(P_+Q_-1,Q_);}
int main(){
    int n,m;
    cin >> n >> m;
    map<int,int>mp;
    vector<int>a;
    int k = sqrt(m)+1;
    for(int i = 2; i<=k;i++){
        int temp = 0;
        while(m%i==0){
            m/=i;
            temp++;
        }
        if(temp){
            a.push_back(temp);
        }
    }
    if(m>1)a.push_back(1);
    ll ans = 1;
    for(int x:a){
        ans *= hcomb(n,x);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9600
#include<stdio.h>

#define MAX 10

void calculation(int array[][MAX + 1], int i, int j);

main()
{
	int i = 0, j = 0;
	int n = 0;
	while(scanf("%d", &n), (n != 0))
	{
		int array[MAX + 1][MAX + 1];
		for(i = 0; i < n + 1; i++)
		{
			for(j = 0; j < n + 1; j++)
			{
				if((i < n) && (j < n))
				{
					array[i][j] = 0;
					scanf("%d", &array[i][j]);
				}
				else
				{
					array[i][j] = 0;
				}
			}
		}
		calculation(array, i, j);
	}
	return 0;
}
void calculation(int array[][MAX+ 1], int max_i, int max_j)
{
	//printf("max_i = %d max_j = %d\n", max_i, max_j);
	short i = 0, j = 0;
	for(i = 0; i < max_i; i++)
	{
		for(j = 0; j < max_j - 1; j++)
		{
			array[i][max_j - 1] += array[i][j];
		}
	}
	for(i = 0; i < max_i - 1; i++)
	{
		for(j = 0; j < max_j; j++)
		{
			array[max_i - 1][j] += array[i][j];
		}
	}
	
	for(i = 0; i < max_i; i++)
	{
		for(j = 0; j < max_j; j++)
		{
			printf("%5d", array[i][j]);
		}
		puts("");
	}
	return;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
#define endl              "\n"
#define pb              push_back
#define fir               first
#define sec               second
#define all(v)            ((v).begin()), ((v).end())
#define sz(v)            ((int)((v).size()))
#define ll              long long
#define ld              long double
#define lp(i, n)        for(int i = 0 ; (int)i<n ; i++)
#define loop(i, x, n)       for(int i=x ; (int)i<=n ; i++)
#define isPowerOfTwo(s) (!(s & (s-1)))
typedef vector<int> vi;
typedef deque<int> de;
void origi() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
int dig(int n) {
    int re = 0;
    while (n > 0)
        n /= 10, re++;
    return re;
}
void tiranga() {
    int n;
    cin >> n;
    int arr[] = { 0,9,0,909,0,90909 };
    if (!(dig(n) % 2))
        cout << arr[dig(n) - 1];
    else {
        int digits = dig(n);
        if (digits == 1)
            cout << n;
        else {
            int res = arr[digits - 2];
            int temp = 1;
            lp(i, digits - 1)
                temp *= 10;
            res += n - temp;
            cout << ++res;
        }
    }
}
int main() {
#ifndef ONLINE_JUDGE.
    //freopen("input.txt", "r", stdin);
#else
#endif
    
    origi();
    tiranga();
    //cout << sumOfDig(123654);
   // genLarge(10, 10);
   // genSmall(10);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	cout << "ABC" << n << "\n";
	return 0;
}

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

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int64 n;
    cin >> n;

    int64 five = 10;
    int64 ans = 0;

    if (n % 2) {
        cout << 0 << endl;
        return 0;
    }

    while (five <= n) {
        ans += n / five;
        five *= 5;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9+1;
//後ろから考える
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> dp(k+1,0);

  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      if (i - a[j] >= 0) dp[i] |= !(dp[i - a[j]]);
    }
  }

  cout << (dp[k] ? "First" : "Second") << endl; 
  return 0;
} 

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

long long n;
long long r[110], c[110];
vector<vector<long long>> dp(110, vector<long long>(110, -1));
long long rec(long long l, long long m){
    if(dp[l][m] != -1) return dp[l][m];
    if(l + 1 == m) return dp[l][m] = r[l] * c[l] * c[m];
    else if(l == m) return dp[l][m] = 0;
    else{
        long long ans = 1e9;
        for (long long i = l; i < m; i++)
        {
            long long len = rec(l, i) + r[l] * c[i] * c[m] + rec(i + 1, m);
            ans = min(ans , len);
        }
        return dp[l][m] = ans;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> r[i] >> c[i];
    }

    int ans = rec(0, n-1);
    cout << ans << endl;
}


Measured memory_bytes: 3248
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <iterator>
#include <map>

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

using namespace std;

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

struct Field
{
	vector<vector<char> >  f;
	int cnt;
};

bool check(vector<vector<char> > v,int y,int x)
{
   	char ret = v[0][0];
	rep(i,y)
	{
		rep(j,x)
		{
			if(ret != v[i][j]) return false;
		}
	}

	return true;
}

void change(vector<vector<char> > &v,int y,int x,char color)
{
	bool used[10][10];
	rep(i,10) rep(j,10) used[i][j] = false;

	queue<pair<pair<int,int>,char> > que;
	que.push(make_pair(make_pair(0,0),v[0][0]));
	used[0][0] = true;
	v[0][0] = color;

	while(que.size())
	{
		int nowy = que.front().first.first;
		int nowx = que.front().first.second;
	   	char nowc = que.front().second;

		que.pop();

		rep(i,4)
		{
			int ny = nowy + dy[i];
			int nx = nowx + dx[i];

			if(0 <= ny && ny < y && 0 <= nx && nx < x && !used[ny][nx])
			{
			    char nc = v[ny][nx];
				if(nc == nowc)
				{
					used[ny][nx] = true;
					v[ny][nx] = color;
					que.push(make_pair(make_pair(ny,nx),nc));
				}
			}
		}
	
	}


}

int main()
{
	int x,y;
	while(cin >> x >> y)
	{
		if(x == 0 && y == 0) break;

		vector<vector<char> > f;
		f.resize(y);

		rep(i,y)
		{
			rep(j,x)
			{
			    char s;
				cin >> s;
				f[i].push_back(s);
			}
		}
		
		Field field;
		field.f.resize(y);
		rep(i,y) copy(f[i].begin(),f[i].end(),back_inserter(field.f[i]));
		field.cnt = 0;

		queue<Field> que;
		que.push(field);
		int ans = 0;

		map<vector<vector<char> >,int> ma;

		while(que.size())
		{
			Field field = que.front();
			que.pop();

			if(check(field.f,y,x))
			{
				ans = field.cnt;
				break;
			}

			if(ma[field.f] == 0)
			{
				ma[field.f]++;

				Field next;
				next.f.resize(y);

				rep(i,y) copy(field.f[i].begin(),field.f[i].end(),back_inserter(next.f[i]));
				next.cnt = field.cnt + 1;

				change(next.f,y,x,'R');
				que.push(next);
			
				rep(i,y) next.f[i].clear();
				rep(i,y) copy(field.f[i].begin(),field.f[i].end(),back_inserter(next.f[i]));
				next.cnt = field.cnt + 1;

				change(next.f,y,x,'G');
				que.push(next);

				rep(i,y) next.f[i].clear();
				rep(i,y) copy(field.f[i].begin(),field.f[i].end(),back_inserter(next.f[i]));
				next.cnt = field.cnt + 1;
			
				change(next.f,y,x,'B');
				que.push(next);
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 6744
import { stringify } from "querystring";

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});

// 解答
function main(inputs:Array<string>) : void {

    // 入力した文章
    let sentence: string = inputs[0];
    let isPalindrome: boolean = false;
    let charNum: number = sentence.length;
    
    if (palindromeCheck(sentence)
       && palindromeCheck(sentence.substring(0, (charNum - 1) / 2))
       && palindromeCheck(sentence.substring(Math.round((charNum + 3) / 2) - 1, charNum))) {

        isPalindrome = true;
    }

    if (isPalindrome) {

        console.log('Yes');
    } else {

        console.log('No');
    }
}

function palindromeCheck(sentence: string) : boolean {

    const reversed = sentence.split('')
                             .reverse()
                             .join('');

    if (sentence == reversed) {

        return true;
    }
    
    return false;
}


Measured memory_bytes: 7500
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		for (;;) {
			l = sc.next() + "=";
			if(l.equals(".=")) break;
			int cnt = 0;
			arg = new int[3];
			for (int p = 0; p < 3; p++) for (int q = 0; q < 3; q++) for (int r = 0; r < 3; r++) {
				this.p = 0;
				arg[0] = p;
				arg[1] = q;
				arg[2] = r;
//				debug(p, q, r, exp());
				if (exp() == 2) cnt++;
			}
			System.out.println(cnt);
		}
	}

	String l;
	int p;
	int[] arg;

	char next() {
		return l.charAt(p++);
	}

	int exp() {
		char c = next();
		if (c == '-') return not(exp());
		if (c == '(') {
			int a = exp();
			c = next();
			int b = exp();
			p++;
//			debug(a, b, c);
			if (c == '+') return add(a, b);
			return mult(a, b);
		}
		p--;
		return val();
	}

	int not(int x) {
		return 2 - x;
	}

	int mult(int x, int y) {
		return min(x, y);
	}

	int add(int x, int y) {
		return max(x, y);
	}

	int val() {
		char c = next();
		switch (c) {
		case 'P': return arg[0];
		case 'Q': return arg[1];
		case 'R': return arg[2];
		default:  return c - '0';
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 22540
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramC
    {
        static void Main()
        {
            int n = NextInt, k = NextInt, q = NextInt;
            var array = Enumerable.Repeat(0, n).ToArray();
            for (int i = 0; i < q; i++)
            {
                array[NextInt - 1]++;
            }

            System.Console.WriteLine(string.Join("\n", array.Select(x => (q - k < x) ? "Yes" : "No")));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 20828
import Foundation

var input_num = [String]()
var count:Int = 0

for i in 0..<2 {
  input_num.append(readLine()!)
}

let nk = input_num[0].componentsSeparatedByString(" ")
let n = Int(nk[0])!
let k = Int(nk[1])!

let hList = input_num[1].componentsSeparatedByString(" ")
for i in 0..<hList.count {
  if Int(hList[i]) >= k {
    count += 1
  }
}

print(count)

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

void printv(vector<ll> v){
        for(ll elem : v) cout << elem << " ";
        cout << endl;
}

int main(void){
        ll n, k;
        cin >> n >> k;
        vector<ll> a(n+1);
        for(int i = 1; i <= n; i++) cin >> a[i];
        vector<ll> v;
        vector<bool> b(n+1, false);
        ll i = 1;
        while(!b[i]){
                v.push_back(i);
                b[i] = true;
                i = a[i];
        }
        //cout << "a = "; printv(a);
        //cout << "v = "; printv(v);
        if(k < (ll)v.size()){
                cout << v[k] << endl;
        } else {
                ll j;
                //printf("a[v.back()] = %lld\n", a[v.back()]);
                ll m = (ll)v.size();
                for(j = 0; j < m; j++){
                        //printf("j = %lld v[j] = %lld\n", j, v[j]);
                        if(v[j] == a[v.back()]){
                                if(j != 0){
                                        v.erase(v.begin(), v.begin()+j);
                                }
                                break;
                        } else {
                                //v.erase(v.begin());
                                //cout << "v = "; printv(v);
                        }
                }
                k -= j;
                //cout << "v = "; printv(v);
                cout << v[k%v.size()] << endl;
        }
        return 0;
}


Measured memory_bytes: 6940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, ans = inf;
	cin >> n;
	string s;
	cin >> s;
	int ws = 0, bs = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '#') bs++;
		else ws++;
	}
	int w = 0, b = 0;
	ans = min(ans, bs);
	rep(i, n) {
		if (s[i] == '#') b++;
		else w++;
		ans = min(ans, b + (ws - w));
	}
	ans = min(ans, min(ws, bs));
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640