akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#define lowbit(x) (x&(-x))
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) (a<b?a:b)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e7;
const int maxn = 3e5 + 5;
ll mod = 1e9 + 7;

int n, vis[N + 5];
vector<int> odd, even, g[205];

int check(int n)
{
	if (n <= 2) return 0;
	int m = sqrt(n);
	for (int i = 2; i <= m; i++) if (n%i == 0) return 0;
	return 1;
}

int link[205], used[205];
int dfs(int u)
{
	for (int j = 0; j < g[u].size(); j++)
	{
		int v = g[u][j];
		if (!used[v])
		{
			used[v] = 1;
			if (link[v] == -1 || dfs(link[v]))
			{
				link[v] = u;
				return 1;
			}
		}
	}
	return 0;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x);
		vis[x] = 1;
	}
	for (int i = 1; i <= N + 1; i++)
	{
		if (vis[i] != vis[i - 1])
		{
			if (i & 1) odd.push_back(i);
			else even.push_back(i);
		}
	}

	int osz = odd.size(), esz = even.size();
	for (int i = 0; i < osz; i++)
	{
		for (int j = 0; j < esz; ++j)
		{
			if (check(abs(odd[i] - even[j])))  g[i].push_back(j);
		}
	}

	memset(link, -1, sizeof(link));
	int k = 0;
	for (int i = 0; i < osz; i++)
	{
		memset(used, 0, sizeof(used));
		k += dfs(i);
	}

	printf("%d", k + ((osz - k) / 2 + (esz - k) / 2) * 2 + ((osz-k) % 2) * 3);
}

Measured memory_bytes: 37248
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

const int MAX = 2005;
bool d[3][3][MAX];

int main(){
  vector<string> s(3); 
  for(int i = 0; i < 3; ++i)cin >> s[i];
  sort(s.begin(), s.end()); 
  int ans = MAX * 3;
  do{
    rep(i, 3)rep(j, 3)rep(k, s[i].size()){
      if(i >= j)continue; 
      bool is_ok = true;
      for(int ni = k; ni < s[i].size(); ++ni){ 
        int nj = ni - k; 
        if(nj >= s[j].size())break;
        if(s[i][ni] == '?' || s[j][nj] == '?')continue;
        if(s[i][ni] != s[j][nj])is_ok = false;
      }
      d[i][j][k] = is_ok;
    }

    auto f = [&](int i, int j, int k){
      if(k >= s[i].size())return true;
      return d[i][j][k];
    };
    rep(x, MAX)rep(y, MAX){
      if(!f(0, 1, x))continue;
      if(!f(1, 2, y))continue;
      if(!f(0, 2, x + y))continue;
      int now = 0;
      now = max({s[0].size(), x + s[1].size(), x + y + s[2].size()});
      ans = min(ans, now);
    }
  }while(next_permutation(s.begin(), s.end())); 

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
K=int(input())

S=[str(_) for _ in range(10)]
ans=S[1:]
S_=[]
for i in range(10):
    for s in S:
        if abs(int(s[0])-i)<=1:
            S_.append(str(i)+s)
            if i!=0:
                ans.append(str(i)+s)
            
for _ in range(9):
#     print(_,'=========')
    S=S_.copy()
    S_=[]
    # print(S)
    S_dict={}

    for i in range(10):
        S_dict[i]=[]

    s_zero=0
    for i in range(10):
        for s in S:
            if abs(int(s[0])-i)<=1:
                S_.append(str(i)+s)
                if i!=0:
                    ans.append(str(i)+s)
                    
    if len(ans)>K+10:
        break
                                
print(ans[K-1])

Measured memory_bytes: 102720
use proconio::input;

const MOD:i64 = 1e9 as i64 + 7;
fn main() {
    input! {
        n:usize,
        k:usize
    };

    let mut res:i64 = 0;
    for i in k..(n+2) {
        let i = i as i64;
        let n = n as i64;
        let minv = (i-1)*i/2;
        let maxv = (n+n-i+1)*i/2;
        let cnt = maxv-minv+1;
        res+=cnt;
        res%=MOD;
    }
    println!("{}",res);
}


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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

bool check(string s) {
  string rs = s;
  reverse(all(rs));
  rep(i, s.size()) {
    if(rs[i] != s[i])
      return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  if(check(s) && check(s.substr(0, n / 2)) && check(s.substr(n / 2 + 1))) {
    cout << "Yes"
         << "\n";
    return 0;
  }
  cout << "No"
       << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
//#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector <int> p(m);
    vector <string> s(m);
    vector <int> used(n + 1), sum(n + 1);
    int ans = 0, res = 0;
    for (int i = 0; i < m; i++) {
        cin >> p[i] >> s[i];
        if (s[i][0] == 'A') used[p[i]] = 1;
        else if (!used[p[i]]) ++sum[p[i]];
    }
    for (auto &i : used) ans += i;
    for (int i = 0; i <= n; i++) {
        res += used[i] * sum[i];
    }
    cout << ans << ' ' << res << '\n';
}


Measured memory_bytes: 6912
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
ans=0
if N%2!=0:
    c=list(Counter(A).items())
    c.sort(reverse=True)
    for a,b in c:
        if a!=0 and b==2:
            ans+=1
        elif a==0 and b==1:
            print(2**ans%(10**9+7))
        else:
            print(0)
            break
else:
    if A.count(0)>0:
        print(0)
    else:
        c=list(Counter(A).items())
        c.sort(reverse=True)
        for a,b in c:
            if a!=1 and b==2:
                ans+=1
            elif a==1 and b==2:
                ans+=1
                print(2**ans%(10**9+7))
            else:
                print(0)
                break


Measured memory_bytes: 16096
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
 
#define LL long long
 
inline int read(){
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
const int INF=9999999;
const int MAXN=300010;
const int MAXM=2010;
const int Mod = 1e9+7;
 
int N; int a[MAXN+1],b[MAXN+1];
int f[MAXM*2+1][MAXM*2+1];
LL ifac[MAXN+1],fac[MAXN+1],inv[MAXN+1];
int A[MAXN+1],B[MAXN+1];
 
inline LL C(LL n,LL m){
    if(n<m) return 0; if(n==m||!m) return 1;
    return fac[n]*ifac[m]%Mod*ifac[n-m]%Mod;
}
 
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    N=read(); fac[0]=1; inv[1]=1; 
	ifac[1]=ifac[0]=1; LL ans=0;
    for(int i=1;i<=(MAXM<<2)+100;i++) 
		fac[i]=fac[i-1]*i%Mod;
    for(int i=2;i<=(MAXM<<2)+100;i++){
        inv[i]=(Mod-(Mod/i))*inv[Mod%i]%Mod;
        ifac[i]=ifac[i-1]*inv[i]%Mod;
    }
    for(int i=1;i<=N;i++){
        A[i]=read(),B[i]=read();
        f[MAXM-A[i]][MAXM-B[i]]++;
        ans=(ans-C(A[i]*2+B[i]*2,A[i]*2)%Mod+Mod)%Mod;
    }
    for(int i=1;i<=MAXM*2;i++){
        for(int j=1;j<=MAXM*2;j++){
            (f[i][j]+=f[i-1][j])%=Mod;
            (f[i][j]+=f[i][j-1])%=Mod;
        }
    }
    for(int i=1;i<=N;i++)
        (ans+=f[A[i]+MAXM][B[i]+MAXM])%=Mod;
	printf("%lld\n",ans*inv[2]%Mod);
    return 0;
}

Measured memory_bytes: 73472
# include<iostream>
# include<cmath>

using namespace std;

int order(int n){
  return (log10(n) / 1) + 1;
}

int main(){
  int n, cnt=0;
  cin >> n;
  for(int i=1; i<=n; ++i){
    if(order(i) % 2 == 1)
      cnt++;
  }

  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

typedef unsigned long long ull;
const int MAX_N = 50;
int N, K;

int x1[MAX_N], y1[MAX_N], d1[MAX_N], x2[MAX_N], y2[MAX_N], d2[MAX_N];

int countKind(int x, int y, int d){
	int ans = 0;
	x++; y++; d++;
	for(int i=0; i<N; i++){
		if(x1[i]<=x && x<=x2[i] && y1[i]<=y && y<=y2[i] && d1[i]<=d && d<=d2[i]) ans ++;
	}
	return ans;
}

using namespace std;

int main(){
	ull v = 0;
	cin >> N >> K;

	vector<int> X(2*N), Y(2*N), D(2*N);

	for(int i=0; i<N; i++){
		cin >> x1[i] >> y1[i] >> d1[i] >> x2[i] >> y2[i] >> d2[i];
		X[i]   = x1[i];
		X[i+N] = x2[i];
		Y[i]   = y1[i];
		Y[i+N] = y2[i];
		D[i]   = d1[i];
		D[i+N] = d2[i];
	}

	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	sort(D.begin(), D.end());

	for(int i=0; i<2*N-1; i++){
	for(int j=0; j<2*N-1; j++){
	for(int k=0; k<2*N-1; k++){
		v += (countKind(X[i], Y[j], D[k]) >= K ? (ull)(X[i+1]-X[i]) * (ull)(Y[j+1]-Y[j]) * (ull)(D[k+1]-D[k]) : 0);
	}}}

	printf("%llu\n", v);
	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  int w,h,n,b=0,c=0;
  int x[1000],y[1000],a[1000];
  int ans;
  cin >> w >> h >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      b = max(b,x[i]);
    }else if (a[i] == 2) {
      w = min(w,x[i]);
    }else if (a[i] == 3) {
      c = max(c,y[i]);
    }else if (a[i] == 4) {
      h = min(h,y[i]);
    }
  }
  if (w <= b || h <= c) {
    cout << "0\n";
  }else{
    ans = abs(w-b) * abs(h-c);
    cout << ans << "\n";
  }
  return 0;
  }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;

int main(){
  string S;
  cin >> S;
  map<char, int> m;
  
  for( int i=0; i<4; i++ ){
    if( m.count( S.at(i) ) ){
      m.at( S.at(i) )++;
    }else{
      m[ S.at(i) ] = 1;
    }
  }
  
  for( auto pair : m ){
    if( pair.second == 2 ){
      continue;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

typedef double ld;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 12;

bool g[MAX][MAX];

int main(){ _

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

	memset(g, 0, sizeof g);

	while(M--){
 		int x,y;
		cin >> x >> y;
		g[x][y] = 1;
		g[y][x] = 1;
	}

	vector<int> V;
	for(int i = 1; i <= N; i++) V.pb(i);

	int ans = 0;

	do{
		if(V[0] != 1) continue;

		bool ok = 1;

		for(int i = 1; i < N; i++){
			ok &= g[V[i]][V[i-1]];
		}
		
		ans += ok;

	} while(next_permutation(all(V)));

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 10, INF = 1e9 + 10, MOD = 1e9 + 7;



int main()
{
    fastInp;

    ll n;
    cin >> n;
    vector<ll> vec((1ll << n));
    for (int i = 0; i < vec.size(); i++) cin >> vec[i];

    map<ll, ll> cnt;
    for (auto cur : vec) cnt[-cur]++;

    multiset<ll> s;
    s.insert(n + 1);

    /*for (auto cur : cnt) {
        cout << abs(cur.first) << " " << cur.second << "\n";
    }*/
    for (auto cur : cnt) {
        ll curS = cur.second;
        //cout << s.size() << "\n";
        if (curS > s.size()) {
            cout << "No\n";
            return 0;
        }
        vector<ll> k;
        for (int i = 0; i < curS; i++) {
            ll v = *(s.rbegin());
            k.push_back(v);
            s.erase((--s.end()));
        }
        for (int i = 0; i < curS; i++) {
            ll v = k[i];
            for (int j = v - 1; j >= 1; j--) {
                s.insert(j);
            }
        }
    }

    cout << "Yes\n";
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int ans=-1,cnt=0,h,last=-1;
    for(int i=0;i<n;i++){
        cin >> h;
        if(last >= h){
            cnt++;
        }
        else{
            ans = max(ans,cnt);
            cnt = 0;
        }
        last = h;
    }
    ans = max(ans,cnt);
    cout << ans << endl;
}


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

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

int 
main() {

  int N; cin >> N;
  vector<int> arrx(N), arry(N), arrh(N);
  rep(i, 0, N){
    cin >> arrx[i] >> arry[i] >> arrh[i];
  }

  int start = 0;
  if(arrh[0] <= 0){
    int i = 0;
    while(arrh[i] == 0){
      i++;
    }
    start = i;
  }

  rep(x, 0, 101){
    rep(y, 0, 101){
      bool flag = true;
      int ansh = arrh[start] + abs(x - arrx[start]) + abs(y - arry[start]);
      rep(l, 0, N){
        if(arrh[l] > 0){
          int comp = arrh[l] + abs(x - arrx[l]) + abs(y - arry[l]);
          if(ansh != comp) flag = false;
        }
        if(arrh[l] == 0){
          int tmp = abs(x - arrx[l]) + abs(y - arry[l]);
          if(ansh> tmp) flag = false;
        }
      }
      if(flag) cout << x << " " << y << " " << ansh << endl;
    }
  }


}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

const int MAX_N = 1e6 + 10;

int nth_prime[MAX_N];
int is_prime[MAX_N];
int min_factor[MAX_N];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; ++i) {
    is_prime[i] = true;
  }

  is_prime[0] = is_prime[1] = false;

  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      nth_prime[p] = i;
      ++p;
      min_factor[i] = i;

      for (int j = 2 * i; j <= n; j += i) {
        if (is_prime[j]) {
          is_prime[j] = false;
          min_factor[j] = i;
        }
      }
    }
  }

  return p;
}

map<int, int> fast_prime_factorize(int n) {
  map<int, int> res;
  while (n > 1 && n % min_factor[n] == 0) {
    ++res[min_factor[n]];
    n /= min_factor[n];
  }
  return res;
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    res[n]++;
  }
  return res;
}

long long gcd(long long a, long long b) {
  if (b == 0) return a;

  return gcd(b, a % b);
}

long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

long long modpow(long long a, long long b) {
  a %= MOD;
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % MOD;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}

long long modinv(long long a) {
  long long b = MOD, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}

ll N;
ll A[10101];
ll B[10101];

int main() {
  cin >> N;
  sieve(1e6 + 1);
  map<int, int> lcmfac;
  rep(i, 0, N) {
    cin >> A[i];
    auto mp = fast_prime_factorize(A[i]);
    for (auto e : mp) {
      chmax(lcmfac[e.first], e.second);
    }
  }

  ll lcmmod = 1;
  for (auto e : lcmfac) {
    lcmmod *= modpow(e.first, e.second);
    lcmmod %= MOD;
  }

  ll ans = 0;
  rep(i, 0, N) {
    ans += lcmmod * modinv(A[i]) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 10880
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)
int N;
vector<vector<int>> jun;
void f(vector<int> j) {
    if (j.size() == N) jun.push_back(j);
    repi(i,1, N+1) {
        vector<int> jj = j;
        rep(k, j.size()) if (i == j[k]) goto END;
        jj.push_back(i);
        f(jj);
    END:
        continue;
    }
}
int main() {
    cin >> N;
    int a,b;
    vector<int> p(N);
    vector<int> q(N);
    rep(i, N) cin >> p[i];
    rep(i, N) cin >> q[i];
    f(vector<int>());
    for (int i = 0;; ++i) {
        rep(j, N) {
            if (p[j] != jun[i][j]) goto ENEND;
        }
        a = i;
        break;
    ENEND:
        continue;
    }
    for (int i = 0;; ++i) {
        rep(j, N) {
            if (q[j] != jun[i][j]) goto EENEND;
        }
        b = i;
        break;
    EENEND:
        continue;
    }
    cout << abs(a - b) << endl;
    return 0;
}



Measured memory_bytes: 3256
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(N)]

    INF = 10**10
    for i in range(N):
        A[i][i] = INF

    ans = 0
    for i in range(N):
        for j in range(i):
            bipas = min(map(sum, zip(A[i], A[j])))

            if A[i][j] > bipas:
                print(-1)
                return 0
            elif A[i][j] < bipas:
                ans += A[i][j]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 6772
#include<bits/stdc++.h>
using namespace std;
int mx;
struct node
{
	int v,tag;
}t[1000001*4];
void pushdown(int node)
{
	t[node*2].v+=t[node].tag;
	t[node*2+1].v+=t[node].tag;
	t[node*2].tag+=t[node].tag;
	t[node*2+1].tag+=t[node].tag;
	t[node].tag=0;
}
void update(int node,int st,int ed,int l,int r,int ind)
{
	if(st>r||ed<l) return;
	if(st>=l&&ed<=r)
	{
		t[node].v+=ind;
		t[node].tag+=ind;
		return;
	}
	pushdown(node);
	int mid=(st+ed)/2;
	update(node*2,st,mid,l,r,ind);
	update(node*2+1,mid+1,ed,l,r,ind);
	t[node].v=max(t[node*2].v,t[node*2+1].v);
}
int query(int node,int st,int ed,int l,int r)
{
	if(st>r||ed<l) return 0;
	if(st>=l&&ed<=r) return t[node].v;
	pushdown(node);
	int mid=(st+ed)/2;
	return max(query(node*2,st,mid,l,r),
					  query(node*2+1,mid+1,ed,l,r));
}
int a[1000001];
vector<int> v[1000001];
int main()
{
	int n;
	scanf("%d%d",&n,&mx);
	for(int i=1;i<=n;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		v[l].push_back(r);
	}
	for(int i=0;i<=mx+1;i++)
		update(1,0,mx+1,i,i,i);
	int ans=0;
	for(int i=0;i<=mx;i++)
	{
		for(int j=0;j<v[i].size();j++)
			update(1,0,mx+1,1,v[i][j],1);
		ans=max(ans,query(1,0,mx+1,i+1,mx+1)-i-mx-1);
	}
	printf("%d",max(ans,n-mx));
    return 0;
}

Measured memory_bytes: 34560
n = int(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for _ in range(n):
    s = input()
    if s == "AC":
        c0 = c0 + 1
    elif s == "WA":
        c1 = c1 + 1
    elif s == "TLE":
        c2 = c2 + 1
    else:
        c3 = c3 + 1
print("AC x", int(c0))
print("WA x", int(c1))
print("TLE x", int(c2))
print("RE x", int(c3))

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

using ll = long long;
using ull = unsigned long long;

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

    int l, r, d;
    cin >> l >> r >> d;

    int cnt = 0;
    for (int i = l; i <= r; ++i) {
        if (i % d == 0) {
            ++cnt;
        }
    }
    cout << cnt << "\n";

    return 0;
}

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

int main()
{
    int a[100010];
    int b[100010];
    int c[100010];
    int dpa[100010];
    int dpb[100010];
    int dpc[100010];
    int N;
    cin >> N;
    for(int i=0;i<N;i++)
        cin >> a[i] >> b[i] >> c[i];
    dpa[0] = a[0];
    dpb[0] = b[0];
    dpc[0] = c[0];
    for(int i=1;i<N;i++)
    {
        if(dpb[i-1] > dpc[i-1])
            dpa[i] = dpb[i-1] + a[i];
        else
            dpa[i] = dpc[i-1] + a[i];

        if(dpa[i-1] > dpc[i-1])
            dpb[i] = dpa[i-1] + b[i];
        else
            dpb[i] = dpc[i-1] + b[i];

        if(dpa[i-1] > dpb[i-1])
            dpc[i] = dpa[i-1] + c[i];
        else
            dpc[i] = dpb[i-1] + c[i];
    }
    
    cout << max(max(dpa[N-1], dpb[N-1]), dpc[N-1]) << endl;
    return 0;
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static class Solver {
		
		int H, W, N, a[], g[][], COL = 0, PUT = 0;
		
		void solve(FastScanner s, PrintWriter out) {
			H = s.nextInt(); W = s.nextInt();
			a = s.nextIntArray(N = s.nextInt());
			g = new int[H][W];
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++) {
					if((i & 1) == 0) {
						g[i][j] = COL + 1;
					} else {
						g[i][W - j - 1] = COL + 1;
					}
					if(++PUT == a[COL]) {
						PUT = 0; COL++;
					}
				}
			}
			for(int[] gg : g) {
				for(int p : gg)
					out.print(p + " ");
				out.println();
			}
		}
		
	}
	
	public static void main(String[] args) {
		FastScanner s = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		new Solver().solve(s, out);
		
		out.close();
	}
	
	static class FastScanner {
		
		BufferedReader br; StringTokenizer st;
		FastScanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			st = new StringTokenizer("");
		}
		String next() {
			while(!st.hasMoreElements()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch(Exception e) {}
			}
			return st.nextToken();
		}
		
		int nextInt() { return Integer.parseInt(next()); }
		int[] nextIntArray(int N) {
			int[] res = new int[N];
			for(int i = 0; i < N; i++) res[i] = nextInt();
			return res;
		}
		
	}
	
}


Measured memory_bytes: 23636
#include<cstdio>
int main(void){
        
        int i,j;
        int n;
    //    long long a[300300];
    //    int b[60][300300];

        long long x[65],y[65],z[65];


        for(i=0;i<65;i++){
                x[i]=0;
                y[i]=0;
        }
             
        scanf("%d", &n);
        for(i=0;i<n;i++){
                long long a;
                int b[65];
                scanf("%lld", &a);
                
                for(j=0;j<65;j++){
                     if(a%2==0){
                             x[j]++;
                     } else {
                             y[j]++;
                     }
                     a=a/2;
                }
        }
        
        for(j=0;j<65;j++){
                   z[j]=(x[j]*y[j])%1000000007;
        }
        long long ans=0;
        for(j=64;j>=0;j--){
                ans = (2*ans+ z[j])%1000000007;
        }
        printf("%lld\n", ans);


        return 0;
}


Measured memory_bytes: 128
s = input()

while len(s) >= 5:

    if s[-5:] == 'dream':
        s = s[:-5]
        continue

    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue

    elif s[-5:] == 'erase':
        s = s[:-5]
        continue

    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue

    else:
        break

if len(s) > 0:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=(1<<30);
  ll x[LIMIT2]={0},l,r;
  char s[LIMIT1];
  
  scanf("%lld %lld",&n,&k);
  rep(i,n) scanf("%lld",&x[i]);
  l=0;
  r=k-1;
  while(r<n){
    if(x[l]<0&&x[r]>0){
      j = min(-x[l],x[r])+zt(x[l],x[r]);
    }else{
      j = max(-x[l],x[r]);
    }
    //printf("%lld ",j);
    result = min(result,j);
    l++;
    r++;
  }
  printf("%lld", result);
  
  return 0;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    sort(all(a));
    vector<pair<ll, ll>> b(m);
    rep(i, m)cin >> b[i].second >> b[i].first;
    sort(rall(b));
    ll j = 0;
    rep(i, n){
        if(a[i] < b[j].first){
            a[i] = b[j].first;
            b[j].second--;
        }
        if(b[j].second <= 0)j++;
        if(j >= m)break;
    }
    cout << accumulate(all(a), 0LL) << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  int N;
  cin>>N;
  set<string>k;
  for(int i=0;i<N;i++){
    string s;
    cin>>s;
    k.insert(s);
  }
  cout<<k.size()<<endl;
  return 0;
}

Measured memory_bytes: 19176
n = int(input())
res = []
su = 0
for i in range(1, n+1):
    #print(res, i)
    res.append(i)
    if su + i > n:
        break
    su += i
sa = sum(res) - n
if sa == 0:
    print("\n".join(map(str, res)))
else:
    del res[res.index(sa)]
    print("\n".join(map(str, res)))


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

int main()
{
	int n, m, d;
	
	while (cin >> n, n) {
		vector<vector<int>> f(n, vector<int>(31, 0));
		vector<vector<long long>> dp(n, vector<long long>(31, 0));
		for (int i = 0; i < n; i++) {
			cin >> m;
			while (m--) {
				cin >> d;
				f[i][d] = 1;
			}
			dp[i][0] = 1L << i;
		}
		int res = -1;
		for (int i = 1; i < 31; i++) {
			for (int j = 0; j < n; j++) {
				if (!f[j][i]) {
					dp[j][i] = dp [j][i - 1];
					continue;
				}
				for (int k = 0; k < n; k++) {
					if (!f[k][i]) continue;
					dp[j][i] |= dp[k][i - 1];
				}
				if (dp[j][i] == (1L << n) - 1) {
					res = i;
					break;
				}
			}
			if (res != -1) break;
		}
		cout << res << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1236
import sys
sys.setrecursionlimit(10**9)
N = int(input())
adjacent_list = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int,input().split())
    u -= 1
    v -= 1
    adjacent_list[u].append([v, w])
    adjacent_list[v].append([u, w])


colors = [-1]*N


def dfs(v, color):
    if colors[v] != -1:
        return
    colors[v] = color
    for adjacent_v in adjacent_list[v]:
        if adjacent_v[1] % 2 == 0:
            dfs(adjacent_v[0], color)
        else:
            dfs(adjacent_v[0], 1-color)

dfs(0,0)

#print(*colors)
for i in range(N):
    print(colors[i])


Measured memory_bytes: 85212
from collections import Counter

N = int(input())
A = list(map(int,input().split()))

def solve():

    if N % 3 != 0:
        return all(a == 0 for a in A)



    counts, vals = zip(*sorted((c,v) for v,c in Counter(A).items()))

    if len(counts) == 1:
        return vals[0] == 0
    elif len(counts) == 2:
        return counts[0]*2 == counts[1] and vals[0] == 0
    elif len(counts) == 3:
        return counts[0] == counts[2] and (vals[0]^vals[1]^vals[2])==0
    else:
        return False

print('Yes' if solve() else 'No')


Measured memory_bytes: 17940
a, b, k = map(int, input().split())
la = [x for x in range(1, a + 1) if a % x == 0]
lb = [x for x in range(1, b + 1) if b % x == 0]
l = set(la) & set(lb)
n = sorted(l, reverse=True)
print(list(n)[k - 1])

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main(){
//int W,H,x,y,r;
    int a,b,c;
    int i=0;
    cin>>a>>b>>c;
int ans=0;
while(ans<c){
i++;
ans+=a;
if(i%7==0)
ans+=b;
}
   cout<<i<<endl;   
  
  
  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define ll long long
ll a[60], b[60], c[60], d[60];
int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
	for (int i = 0; i < M; i++) cin >> c[i] >> d[i];
	ll min = 0;
	int p = 0;
	for (int i = 0; i < N; i++) {
		min = mod;
		for (int j = 0; j < M; j++) {
			if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < min) {
				min = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				p = j;
			}
		}
		cout << p + 1 << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vi vector<ll> 
#define pb push_back
#define For(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007
#define MAX 100005
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	// freopen("output1.txt", "w", stdout);
	#endif
	string s;
	cin>>s;
	if(s[s.length()-1]=='s'){
		s+="es";
		cout<<s;
	}
	else{
		s+="s";
		cout<<s;
	}
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define pb push_back
#define f first
#define s second
#define endl '\n'
vector<vector<pair<int, int>>>vec;
int t[2000005];

int sum(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return sum(v*2, tl, tm, l, min(r, tm))
           + sum(v*2+1, tm+1, tr, max(l, tm+1), r);
}

void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = t[v*2] + t[v*2+1];
    }
}

main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int r=0;
	int w=0;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='R'){
			r++;
		}
		else{
			w++;
		}
	}
	int val=0;
	for(int i=0; i<r; i++){
		if(s[i]=='R'){
			val++;
		}
	}
	cout<<r-val;
	return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(ll i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a) memset(a,0,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
vector<int>adj[100005];
int dfs(int u,int vis[],int dist[])
{
    if(vis[u]==1)
        return dist[u];
    vis[u]=1;
    int ans=0;
    rep(i,0,adj[u].size())
    {
        ans=max(ans,dfs(adj[u][i],vis,dist)+1);
    }
    dist[u]=ans;
    return ans;
}
int main()
{
    int n,m;
    cin>>n>>m;
    rep(i,0,m)
    {
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
    }
    int vis[n+1]={0};
    int dist[n+1];
    int res=-1;
    repA(i,1,n)
    {
        if(vis[i]==0)
        res=max(res,dfs(i,vis,dist));
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define aint(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          int;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD = 1000000007;

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

signed main(){
	int n,a[200010],ans = 0,cnt[100010] = {},b[2] = {},bi[2],ci[2],c[2] = {};
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < 2;i++){
		for(int j = 0;j <= 100000;j++) cnt[j] = 0;
		for(int j = i;j < n;j += 2) cnt[a[j]]++;
		for(int j = 0;j <= 100000;j++){
			int ind = j;
			if(b[i] < cnt[j]){
				swap(b[i],cnt[j]);
				swap(bi[i],ind);
			}
			if(c[i] < cnt[j]){
				swap(c[i],cnt[j]);
				swap(ci[i],ind);
			}
		}
	}
	if(bi[0] == bi[1]) cout << n - max(b[0] + c[1],b[1] + c[0]) << endl;
	else cout << n - (b[0] + b[1]) << endl;
	return 0;
}

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

struct s{
  char word[35];
  int c, len;
};

int main(){
  int i = 0, j, f, mc, mlen;
  char in[35];
  struct s w[500];
  while(scanf("%s", in) != EOF){
    f = 0;
    for(j = 0;j <= i;j++){
      if(strcmp(in, w[j].word) == 0){
	w[j].c++;
	f = 1;
	break;
      }
    }

    if(f == 0){
      strcpy(w[++i].word, in);
      w[i].len = strlen(in);
      w[i].c = 1;
    }
  }
  mc = mlen = 0;
  for(j = 0; j <= i;j++){
    mc = w[mc].c > w[j].c ? mc : j;
    mlen = w[mlen].len > w[j].len ? mlen : j;
  }
  printf("%s %s\n", w[mc].word, w[mlen].word);
  return 0;
}

Measured memory_bytes: 572
from collections import Counter
n,m = map(int, input().split())
c = Counter(map(int, input().split()))
r = [0]*m
s = [0]*m
for k, v in c.items():
    i = k%m
    r[i] += v
    s[i] += v//2

ans = r[0]//2
for i in range(1, m):
    j = m-i
    if i > j:
        break
    elif i == j:
        ans += r[i]//2
    else:
        if r[i] < r[j]:
            i,j = j,i
        ans += r[j]
        ans += min((r[i]-r[j])//2, s[i])
print(ans)

Measured memory_bytes: 22628
#include<iostream>
#include<iostream>
#include<string>
using namespace std;
int main() {
	string a, b;
	cin >> a >> b;
	if (a.size()>b.size()) {
		cout << "GREATER\n";
	}
	if (a.size()<b.size()) {
		cout << "LESS\n";
	}
	if (a.size() == b.size()) {
		if (a > b) {
			cout << "GREATER" << endl;
		}
		if (a < b) {
			cout << "LESS" << endl;
		}
		if (a == b) {
			cout << "EQUAL" << endl;
		}
	}
	cin >> a;
}

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

	cin >> n;
	string s,t,ans;
	cin >>s>>t;
	ans="";
	rep(i,n){
		ans+=s.substr(i,1);
		ans+=t.substr(i,1);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}


int main() {
	int s;
	cin >> s;
	if (s == 1) cout << 0 << endl;
	else cout << 1 << endl;
}

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static int h = -1;
	static int v = -1;
	static int goal = -1;
	static int[] route = null;
	static char[][] holizon = null;
	static boolean[][] checkLine = null;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;
		try {
			while (true) {
				int[] param = new int[4];
				for (int i = 0; i < 4; i++) {
					line = br.readLine().trim();
					if (line.equals("0")) {
						System.exit(0);
					}
					param[i] = Integer.parseInt(line);
				}
				v = param[0];
				h = param[3];
				goal = param[2];

				// 途中を保存
				route = new int[h + 1];
				route[0] = param[1];

				holizon = new char[h][v];
				// 追加可能位置の記録
				checkLine = new boolean[h][v - 1];
				for (int i = 0; i < h; i++) {
					holizon[i] = br.readLine().trim().toCharArray();
					route[i + 1] = route[i];
					for (int j = 0; j < v - 1; j++) {
						if (holizon[i][j] == '1') {
							if (j + 1 == route[i] || j + 2 == route[i]) {
								route[i + 1] += j + 1 == route[i] ? 1 : -1;
							}
							checkLine[i][j] = true;
							//縦線が2の時にnull pointer exception発生対策
							if (v > 2) {
								if (j == 0)
									checkLine[i][j + 1] = true;
								else if (j == v - 2)
									checkLine[i][j - 1] = true;
								else {
									checkLine[i][j + 1] = true;
									checkLine[i][j - 1] = true;
								}
							}
						}
					}
				}
				String ans = "0";
				if (route[h] != goal) {
					ans = searchAddLine();
				}
				System.out.println(ans);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	// ライン追加可能場所全てをチェックする
	private static String searchAddLine() {
		String returnData = "1";
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < v - 1; j++) {
				// 結果に影響を与える箇所かどうか
				if ((j + 1 == route[i] || j + 2 == route[i])
						&& checkLine[i][j] == false) {
					if (checkResult(i, j) == true) {
						returnData = Integer.toString(i + 1) + " "
								+ Integer.toString(j + 1);
						return returnData;
					}

				}
			}
		}
		return returnData;
	}

	private static boolean checkResult(int ai, int aj) {
		int tmp = route[ai];
		tmp += aj + 1 == tmp ? 1 : -1;

		for (int i = ai + 1; i < h; i++) {
			for (int j = 0; j < v - 1; j++) {
				if ((j + 1 == tmp || j + 2 == tmp) && holizon[i][j] == '1') {
					tmp += j + 1 == tmp ? 1 : -1;
					break;
				}
			}
		}
		if (tmp == goal)
			return true;
		else
			return false;
	}
}

Measured memory_bytes: 17148
# AOJ 0121

from collections import deque

score = {}
score[tuple(range(8))] = 0
queue = deque()
queue.append(tuple(range(8)))
move = ((1, 4), (0, 2, 5), (1, 3, 6), (2, 7), (0, 5), (1, 4, 6), (2, 5, 7), (3, 6))
while queue:
    puz = queue.popleft()
    pos = puz.index(0)
    for npos in move[pos]:
        npuz = list(puz)
        npuz[pos], npuz[npos] = npuz[npos], 0
        npuz = tuple(npuz)
        if npuz not in score:
            queue.append(npuz)
            score[npuz] = score[puz] + 1

while True:
    try:
        puzzle = tuple(map(int, input().split()))
        print(score[puzzle])
    except EOFError:
        break



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

int main()
{
	string s;
	cin >> s;
	int first = -1, last = -1;
	s += '0';
	for (int i = 0; i < s.length() - 1; ++i){
		if (s[i] == s[i + 1]){
			first = i+1;
			last = i + 2;
			break;
		}
		else if (s[i] == s[i + 2]){
			first = i+1;
			last = i + 3;
			break;
		}
	}
	cout << first <<' '<< last << endl;
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){
    int h,x,i,j;
    
    while(1){
        scanf("%d" "%d",&h,&x);
        if(h==0&&x==0){
            break;
        }else{
            for(i=0;i<h;i++){
                for(j=0;j<x;j++){
                    putchar('#');
                }
                putchar('\n');
            }
        }
        putchar('\n');
    }
}


Measured memory_bytes: 2040
#include <cstdio>
#include <algorithm>
#define LL long long
#define maxn 200010
#define mod 1000000007
using namespace std;
int a[maxn];
LL ans=1,x,y;
int main(){
	int n,k,i,l,r,b=1;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	if(k&1) ans=a[n],b=(a[n]<0?-1:1),n--,k--;
	l=1,r=n;
	while(k){
		x=(LL)a[l]*a[l+1],y=(LL)a[r]*a[r-1];
		if(x*b>y*b)x%=mod,ans=ans*x%mod,l+=2;
		else y%=mod,ans=ans*y%mod,r-=2;
		k-=2;
	}
	ans=(ans%mod+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2460
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L //setprecision(15)

// 約数の列挙O(√n)
vector<ll> divisor(ll n) {
	vector<ll> res;
	for (ll i = 1; i*i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) res.push_back(n / i);
		}
	}
	return res;
}
ll digits(ll n) {
	ll ans = 1;
	while (1) {
		if (n / 10 == 0) break;
		n /= 10; ans++;
	}
	return ans;
}

int main() {
	ll N; cin >> N;
	vector<ll> v = divisor(N);
	sort(v.begin(), v.end());
	ll ans = INF;
	for (auto it = v.begin(); it != v.end(); it++) {
		ll tmp = digits(*it);
		ll tmp2 = digits(N / (*it));
		ans = min(ans, max(tmp, tmp2));
	}
	cout << ans << endl;
}

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

int main(){
	int A,B;
  	string S;
  	cin >> A >> B >> S;
  	if(S.find("-")== A and S.find("-", A+1)==string::npos) {
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e5 + 5;
int n, a[3];
bool ok = true;
char s[N][5];
bool f[N];
int main() {
	scanf("%d%d%d%d", &n, &a[0], &a[1], &a[2]);
	for (int i = 1; i <= n; i++) scanf("%s", s[i]);
	if (a[0] + a[1] + a[2] <= 1 || a[0] + a[1] + a[2] >= 3) {
		for (int i = 1; i <= n; i++) {
			int x = s[i][0] - 'A', y = s[i][1] - 'A';
			if (a[x] == 0 && a[y] == 0) {
				ok = false;
				break;
			}
			if (a[x] > a[y]) a[x]--, a[y]++, f[i] = 1;
			else a[x]++, a[y]--, f[i] = 0;
		}
	} else {
		for (int i = 1; i <= n; i++) {
			int x = s[i][0] - 'A', y = s[i][1] - 'A';
			if (a[x] + a[y] == 0) {
				ok = false;
				break;
			} else if (a[x] != 1 || a[y] != 1) {
				if (a[x] > a[y]) a[x]--, a[y]++, f[i] = 1;
				else a[x]++, a[y]--, f[i] = 0;
			} else {
				int j = i, cnt = 0;
				while (j <= n && strcmp(s[i], s[j]) == 0) cnt++, j++;
				if (j > n || (cnt % 2 == 0)) {
					while (i < j) {
						if (a[x] > a[y]) a[x]--, a[y]++, f[i] = 1;
						else a[x]++, a[y]--, f[i] = 0;
						i++;
					}
					i--;
				}
				else {
					int p = 0;
					for (int k = 0; k < 2; k++)
						for (int l = 0; l < 2; l++)
							if (s[i][k] == s[j][l]) {
								p = s[i][k] - 'A';
								break;
							}
					if (p == x) {
						while (i < j) {
							if (a[x] == a[y] && a[x] == 1) a[x]++, a[y]--, f[i] = 0;
							else a[x]--, a[y]++, f[i] = 1;
							i++;
						}
						i--;
					} else {
						while (i < j) {
							if (a[x] == a[y] && a[x] == 1) a[x]--, a[y]++, f[i] = 1;
							else a[x]++, a[y]--, f[i] = 0;
							i++;
						}
						i--;
					}
				}
			}
		}
	}
	if (!ok) puts("No");
	else {
		puts("Yes");
		for (int i = 1; i <= n; i++) printf("%c\n", s[i][f[i]]);
	}
	return 0;
}

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

int main() {
    int n;
    double sum = 0;
    cin >> n;
    vector<double> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    for (int i = 0; i < n; i++)
    {
        a[i] = 1 / a[i];
    }
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
    }
    cout << (double)1 / sum << endl;
    return 0;
}

Measured memory_bytes: 256