akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}




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

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

    cout << ((S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) ? "Yes":"No") << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 
const int N=2e3+10;
vi adj[N];
int dist[N];
int ans[N];
// bool vis[N];

int solve(){
	int n,x,y;cin>>n>>x>>y;
	adj[x].pb(y);
	adj[y].pb(x);
	for(int i=0;i<n-1;i++){
		int x=i+1;
		int y=i+2;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	for(int i=1;i<=n;i++){
		bool vis[N];
		memset(vis,0,sizeof(vis));
		vis[i]=1;
		dist[i]=0;
		queue<int> q;
		q.push(i);
		while(!q.empty()){
			auto f=q.front();
			q.pop();
			for(auto i:adj[f]){
				if(vis[i]) continue;
				dist[i]=dist[f]+1;
				ans[dist[i]]++;
				q.push(i);
				vis[i]=1;
			}
		}
	}
	for(int i=1;i<n;i++) cout<<ans[i]/2<<endl;




    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	string s; cin >> s;
	cout << s.size() / 2 - count_if(all(s), [](char c) { return c == 'p';  }) << endl;
	system("pause");
}

Measured memory_bytes: 760
from collections import deque


def main():
    N, M, Q = map(int, input().split())
    q = []
    for i in range(Q):
        a, b, c, d = map(int, input().split())
        q.append([a - 1, b - 1, c, d])

    seqs = deque([])
    ids = deque([N - 1] * M)
    for i in range(M):
        seqs.append([1] * (N - 1) + [i + 1])

    ans = 0
    while seqs:
        seq, idx = seqs.popleft(), ids.popleft()
        # calc score
        score = 0
        for a, b, c, d in q:
            if seq[b] - seq[a] == c:
                score += d
        ans = max(ans, score)
        # push new sequence
        if idx == 0:
            continue
        for i in range(1, seq[idx] + 1):
            seqs.append(seq[:idx - 1] + [i] + seq[idx:])
            ids.append(idx - 1)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

using R = pair<ll, string>;
R convert(const string& s) {
    ll cnt = 0;
    rep(i, s.size()) {
        if (s[i] != '.') {
            cnt = i;
            break;
        }
    }
    return R(cnt, s.substr(cnt));
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    while (cin >> n) {
        vector<string> lines(n); cin >> lines;
        vector<R> v;
        rep(i, n) {
            v.pb(convert(lines[i]));
        }
        rep(i, n) {
            rep(j, v[i].first-1) {
                bool f = false;
                rep(k, i+1, n) {
                    if (v[k].first == j+1) {
                        f = true;
                        break;
                    }
                    if (v[k].first < j+1) break;
                }
                if (f) cout << "|";
                else cout << " ";
            }
            if (v[i].first > 0) cout << "+";
            cout << v[i].second << endl;
        }
    }
}

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

using namespace std;

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

bool bs(int diff, int x) {
    for (ll mid = 1000; mid >= -1000; --mid) {
        if (x == pow(mid + diff, 5) - pow(mid, 5)) {
            cout << mid + diff << ' ' << mid << '\n';
            return true;
        }
    }
    return false;
}

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

    int x;
    cin >> x;
    for (int ctr1 = 1; ctr1 * ctr1 <= x; ++ctr1) {
        if (x % ctr1 == 0) {
            if (bs(ctr1, x))
                return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 4044
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
    ll t1, t2;
    ll a1, a2;
    ll b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    if(t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2){
        cout << "infinity" << endl;
        return 0;
    }

    //おそい方を1に
    if(t1 * a1 + t2 * a2 > t1 * b1 + t2 * b2){
        ll tmp = a1;
        a1 = b1;
        b1 = tmp;
        tmp = a2;
        a2 = b2;
        b2 = tmp;
    }

    ll ans = 0;

    ll x = t1 * a1 - t1 * b1;
    ll y = (t1 * b1 + t2 * b2) - (t1 * a1 + t2 * a2);

    //cout << x << endl;
    //cout << y << endl;

    if(x <= 0) ans = 0;
    else{
        ans = x / y * 2;
        if(x % y != 0) ans++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 104;
ll a,c,b,d,ans=0;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b>>c>>d;
	FOR(i,0,a+1){
		FOR(j,0,b+1){
			FOR(k,0,c+1){
				if((i*500+j*100+k*50)==d)ans++;
			}
		}
	}
	pri(ans);
	return 0;
}


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

def isprime(n):
    if n==1:
        return False
    else:
        for i in range(2,int(n**0.5)+1):
            if n%i==0:
                return False
        return True
        
while True:
    if isprime(x):
        print(x)
        exit()
    else:
        x+=1

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

void solve(long **G, int n, int u, long *d, int t) {
  int i;
  char *flag;
  flag = (char*)malloc(sizeof(char) * n);
  for (i = 0; i < n; i++) {
    if(G[u][i] != -1 && (d[i] == -1 || d[i] > t+G[u][i])) {
      flag[i] = 1;
      d[i] = t+G[u][i];
    }
    else flag[i] = 0;
  }
  for (i = 0; i < n; i++) {
    if(flag[i] == 1) {
      solve(G,n,i,d,t+G[u][i]);
    }
  }
  free(flag);
}

int main()
{
  int n;
  int i,j,u,k,v;
  long **G,c;
  long *d;
  scanf("%d",&n);
  G = (long**)malloc(sizeof(long*) * n);
  for (i = 0; i < n; i++) {
    G[i] = (long*)malloc(sizeof(long) * n);
    for(j = 0; j < n; j++) G[i][j] = -1;
  }
  for (i = 0; i < n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 0; j < k; j++) {
      scanf("%d %ld", &v, &c);
      G[u][v] = c;
    }
  }
  d = (long*)malloc(sizeof(long) * n);
  d[0] = 0;
  for (i = 1; i < n; i++) {
    d[i] = -1;
  }
  solve(G,n,0,d,0);
  for (i = 0; i < n; i++) {
    printf("%d %ld\n", i, d[i]);
  }
  return 0;
}

Measured memory_bytes: 676
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 20;
const double eps = 1e-9;
using namespace std;
string str;
ll dp[MAXN][MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n >> str;
    ll ans = 0;
    for (int i = 0; i < (1 << n); i++)
    {
        memset(dp, 0, sizeof dp);
        string t1, t2;
        for (int j = 0; j < n; j++)
            if ((i >> j) & 1)
                t1 = str[j] + t1;
            else
                t2 = str[j] + t2;
        int l1 = t1.length(), l2 = t2.length();
        for (int j = 0; j <= l1; j++)
            for (int k = 0; k <= l2; k++)
            {
                if (j == 0 && k == 0)
                    dp[j][k] = 1;
                else if (j == 0 && t2[k - 1] == str[n + k - 1])
                    dp[j][k] = dp[j][k - 1];
                else if (k == 0 && t1[j - 1] == str[n + j - 1])
                    dp[j][k] = dp[j][k - 1];
                else if (t1[j - 1] == str[n + j + k - 1] && t2[k - 1] != str[n + j + k - 1])
                    dp[j][k] = dp[j - 1][k];
                else if (t1[j - 1] != str[n + j + k - 1] && t2[k - 1] == str[n + j + k - 1])
                    dp[j][k] = dp[j][k - 1];
                else if (t1[j - 1] == str[n + j + k - 1] && t2[k - 1] == str[n + j + k - 1])
                    dp[j][k] = dp[j - 1][k] + dp[j][k - 1];
            }
        ans += dp[l1][l2];
    }
    cout << 2ll * ans << "\n";
    return 0;
}


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

using namespace std;

int N;
int K;
bool num[10];

int main() {
  cin >> N >> K;
  int Min;
  for(int i = 0; i < K; i++){
    int a;
    cin >> a;
    num[a] = true;
  }

  for(int i = N; ; i++) {
    int tmp = i;
    bool is = true;
    while(tmp > 0) {
      if(num[tmp%10]) {
	is = false; break;
      }
      tmp /= 10;
    }
    if(is) {
      cout << i <<endl; return 0;
    }
  }
}
      
   
      

  
  


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

int main(void){

    int n;
    int ar[1000];

    cin >> n;

    n = n*2;

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

    sort(ar, ar + n);

    int sum=0;

    for(int i=0;i<n;i++){
        if(i%2 == 0){
            sum += ar[i];
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int n, q, s, t, x, u, a[1 << 18], i;
bool f;
iP b[1 << 18];

void update(int k, int l, int r) {
	if (!(t < l || r < s)) {
		if (s <= l&&r <= t) {
			a[k] = x;
			b[k] = mkp(x, i);
		}
		else {
			if (b[k].second > b[k * 2].second) {
				b[k * 2] = b[k];
				a[k * 2] = b[k].first;
			}
			if (b[k].second > b[k * 2 + 1].second) {
				b[k * 2 + 1] = b[k];
				a[k * 2 + 1] = b[k].first;
			}
			update(k * 2, l, (l + r) / 2);
			update(k * 2 + 1, (l + r) / 2 + 1, r);
			a[k] = min(a[k * 2], a[k * 2 + 1]);
		}
	}
}
int find(int k, int l, int r) {
	if (t < l || r < s)return intmax;
	else if (s <= l&&r <= t)return a[k];
	else {
		if (b[k].second > b[k * 2].second) {
			b[k * 2] = b[k];
			a[k * 2] = b[k].first;
		}
		if (b[k].second > b[k * 2 + 1].second) {
			b[k * 2 + 1] = b[k];
			a[k * 2 + 1] = b[k].first;
		}
		return min(find(k * 2, l, (l + r) / 2), find(k * 2 + 1, (l + r) / 2 + 1, r));
	}
}
int main(){
	cin >> n >> q;
	for (i = 1; true; ++i) {
		if (1 << i >= n) {
			u = 1 << i;
			break;
		}
	}
	fill(a, a + u * 2, intmax);
	fill(b, b + u * 2, mkp(intmax, -1));
	for (i = 0; i != q; ++i) {
		cin >> f >> s >> t;
		if (f)
			cout << find(1, 0, u - 1) << endl;
		else {
			cin >> x;
			update(1, 0, u - 1);
		}
	}
	return 0;
}



Measured memory_bytes: 6164
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;

int main(){
   ll n; cin >> n;
   print(n * (n - 1) / 2);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <iomanip>

double solve(size_t n, const std::vector<int>& v) {
    int a = 0;
    int b = 0;
    int c = 0;
    static double dp[301][301][301];

    for (size_t i = 0; i < n; i++) {
        switch (v[i]) {
            case 1: a++; break;
            case 2: b++; break;
            case 3: c++; break;
        }
    }

    for (int i = 0; i <= c; i++) {
        for (int j = 0; j <= b + c - i; j++) {
            for (int k = 0; k <= n - i - j; k++) {
                if (i == 0 && j == 0 && k == 0) {
                    continue;
                }

                double e = 0;

                if (k > 0) {
                    e += k * dp[i][j][k - 1];
                }

                if (j > 0) {
                    e += j * dp[i][j - 1][k + 1];
                }

                if (i > 0) {
                    e += i * dp[i - 1][j + 1][k];
                }

                dp[i][j][k] = (e + n) / (i + j + k);
            }
        }
    }

    return dp[c][b][a];
}

int main() {
    size_t n;
    std::vector<int> v;

    std::cin >> n;

    v.resize(n);
    for (size_t i = 0; i < n; i++) {
        std::cin >> v[i];
    }

    std::cout << std::setprecision(12) << solve(n, v) << std::endl;
}


Measured memory_bytes: 207104
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;

const double PI=3.14159265358979323846;

int main()
{
    int R;
    cin >> R;
    cout << fixed << setprecision(4) << 2.0 * R * PI << endl;
    return 0;
}


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

int n, k;
string s, t;

string solve();

int main() {
  cin >> n >> k >> s;
  t = s;
  reverse(t.begin(), t.end());
  t = s + t;
  cout << solve() << endl;
  return 0;
}

string solve() {
  string res = s;
  if (k == 1) {
    for (int i = 0; i <= n; ++i) res = min(res, t.substr(i, n));
    return res;
  }
  for (int i = 0; i < n; ++i) {
    int id = i + n, cnt = 0;
    while (id > i && t[i + n] == t[id]) --id, ++cnt;
    for (int j = 1; j < k && cnt < n; ++j) cnt = min(n, cnt * 2);
    string now(cnt, t[i + n]);
    while (now.size() < n) now += t[id--];
    res = min(res, now);
  }
  return res;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n);
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
const int INF = 1000000000;
const int MAX = 101;

int main() {
	int N,M;
	SCD2(N,M);
	
	static int d[MAX][MAX];
	static int adj[MAX][MAX];
	stack<pair<int,int> >S;
	set<pair<int,int> >adjE;
	
	REP(i,MAX){
		REP(j,MAX){
			if (i!=j){
				d[i][j] = INF;
				adj[i][j] = INF;
			}else{
				d[i][j] = 0;
				adj[i][j] = 0;
			}
		}
	}
	
	REP(i,M){
		int a,b,c;
		SCD3(a,b,c);
		
		d[a][b] = c;
		d[b][a] = c;
		adj[a][b] = c;
		adj[b][a] = c;
		S.push(MP(min(a,b),max(a,b)));
		
	}
	
	REP(k,N){
		REP(i,N){
			REP(j,N){
				d[i+1][j+1] = min(d[i+1][j+1] , d[i+1][k+1] + d[k+1][j+1]);
			}
		}
	}
	
	while(!S.empty()){
		pair<int,int> ab = S.top();
		S.pop();
		int a = ab.first;
		int b = ab.second;
		
		FORq(s,1,N-1){
			FORq(t,s+1,N){
				if (d[s][t] == d[s][a] + adj[a][b] + d[b][t]){
					adjE.insert(ab);
				}
			}
		}
		
	}
	
	PRINTD(M - adjE.size());
}










Measured memory_bytes: 384
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
	char a[101];
	cin >> a;
	int flag = 0;
	int N = strlen(a);
	for (int i = 0; i < N; i++)
	{
		if (flag == 0 && a[i] == 'C')
		{
			flag++;
		}
		else if (flag == 1 && a[i] == 'F')
		{
			flag++;
			break;
		}
	}
	if (flag == 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include"iostream"
#include"string"
using namespace std;

int main() {
	string s;
	string ans;
	cin >> s;
	
	int numC = 0;
	for (int i = 2; i < s.size() - 1; i++)
	{
		if (s.at(i) == 'C')
		{
			numC++;
		}
	}


	int numCap = 0;
	for (int i = 0; i < s.size() ; i++)
	{
		if ('A'<=s.at(i) && s.at(i)<='Z')
		{
			numCap++;
		}
	}


	if (s.at(0) != 'A'||numC!=1||numCap!=2)
	{
		ans = "WA";
	}
	else 
	{
		ans = "AC";
	}
	cout << ans << endl;
}

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

string tostr(int n)
{
	string ret="";
	for(int i=0;i<3;i++)
	{
		char cur=(n%10)+'0';
		ret=cur+ret;
		n/=10;
	}
	return ret;
}

int main()
{
	int N;
	string S;

	cin >> N;
	cin >> S;

	int ans=0;
	for(int i=0;i<1000;i++)
	{
		string s=tostr(i);
		int c=0;
		int index=0;
		bool ok[3]={};
		for(;index<N;index++)
		{
			if(S[index]==s[c])
			{
				ok[c]=true;
				break;
			}
		}
		index++;
		c++;
		for(;index<N;index++)
		{
			if(S[index]==s[c])
			{
				ok[c]=true;
				break;
			}
		}
		index++;
		c++;
		for(;index<N;index++)
		{
			if(S[index]==s[c])
			{
				ok[c]=true;
				break;
			}
		}
		if(ok[0] && ok[1] && ok[2])
			ans++;
	}

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



Measured memory_bytes: 256
def build_line(width, i, h):
    s = ''
    if i == 0 or i == h-1:
        while len(s) < width:
                s += '#'
    else:
        s += '#'
        while len(s) < width - 1:
            s += '.'
        s += '#'
    return s

while True:
    h,w = [int(i) for i in input().split()]
    if not (h and w):
        break
    for i in range(h):
        print(build_line(w, i, h))
    print()



Measured memory_bytes: 5624
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;


int main() {


	int n;
	char s[10000];
	cin >> n;

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

	int ans = 0;

	for (int dis = 1; dis < n; dis++) {
		int x = 0;

		int now = 0;

		rep(i, n - dis) {
			if (s[i] == s[i + dis]) { now++; if (x < now) { x = now; } }
			else { now = 0; }

			

		}

		x = min(x, dis);

		if (x > ans) { ans = x; }
	}

	cout << ans;


	system("PAUSE");

}

Measured memory_bytes: 504
# A - Libra

# 天秤の左の皿におもりA,Bを、右の皿におもりB,Dを載せた場合、
# 天秤がどちらに傾くかを出力する


A,B,C,D = map(int,input().split())

left_dish = A + B
right_dish = C + D

if left_dish > right_dish:
    print('Left')
elif left_dish < right_dish:
    print('Right')
elif left_dish == right_dish:
    print('Balanced')


Measured memory_bytes: 9056
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <queue>
#include <algorithm>
using namespace std;

#define rep(i,n)for(int i=0; i<(int)(n); i++)
#define bitrep(tmp, N)for (int tmp=0; tmp < (1<<N);tmp++)
#define all(v) v.begin(), end.bigin()

int INF = 10e9;
using P = pair<int,int>;


int main(){
  string S_d, T;
  cin >> S_d >> T;
  int s_size = (int) S_d.size(), t_size = (int) T.size();
  vector<string> ans;
  string S;
  rep(i, s_size) S+="?";
  bool able = false;
  //for1
  rep(i, s_size-t_size+1){
    able = false;
    for(int j=0; j<t_size; j++){
      if(S_d[i+j]==T[j]||S_d[i+j]=='?'){
        if(j==t_size-1){
          able=true;
          S.replace(i, t_size, T);
        }
      }else break;
    }
    if (able){
      for (int k=0; k<s_size; k++){
        if(S[k]=='?'){
          if(S_d[k]=='?') S[k]='a';
          else S[k]=S_d[k];  
        }
      }
      ans.push_back(S);
      rep(i,s_size) S[i] = '?';
    }
  }
  if (!ans.empty()){
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;  
  }else cout<< "UNRESTORABLE" << endl;
  


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}

int main() {
  int k,n;cin>>k>>n;
  int first,end;
  int a,b;
  int ans=0;
  cin>>first;
  b=first;
  rep(i,n-1){
    a=b;
    cin>>b;
    ans=max(ans,b-a);
    if(i==n-2){
      end=b;
    }
  }
  ans=max(ans,k-(end-first));
  cout<<k-ans<<endl;
}


Measured memory_bytes: 256
<?php
  list($A, $V) = explode(" ", trim(fgets(STDIN)));
  list($B, $W) = explode(" ", trim(fgets(STDIN)));
  list($T) = explode(" ", trim(fgets(STDIN)));


  $sa = abs($A-$B);

  $sokudo = $V-$W;

  if($T * $sokudo >= $sa){
    echo 'YES';
  }else{
    echo 'NO';
  }

Measured memory_bytes: 16148
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        var A = new int[26];
        var B = new int[26];
        var S = cin.next;
        for (int i = 0; i < N; i++)
        {
            B[S[i] - 'a']++;
        }
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            A[S[i] - 'a']++;
            B[S[i] - 'a']--;
            int sum = 0;
            for (int j = 0; j < 26; j++)
            {
                if (A[j] * B[j] > 0) sum++;
            }
            chmax(ref ans, sum);
        }
        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

using i64 = int64_t;

constexpr i64 INF = 1000000000000000001;

int main(){
    i64 n, k;
    cin >> n >> k;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());

    i64 valid = INF, invalid = -INF;
    while(abs(valid-invalid) > 1){
        i64 mid = min(valid, invalid) + (abs(valid - invalid)) / 2;
        i64 cnt = 0;
        for(int i=0;i<n;++i){
            if(v[i] == 0){
                if(mid >= 0)
                    cnt += n-i-1;
            }else if(v[i] > 0){
                auto itr = partition_point(v.begin()+i+1, v.end(), [&](i64 x){return v[i]*x <= mid;});
                cnt += itr - (v.begin()+i+1);
            }else{
                auto itr = partition_point(v.begin()+i+1, v.end(), [&](i64 x){return v[i]*x > mid;});
                cnt += v.end() - itr;
            }
        }
        //cerr << mid << " " << cnt << endl;
        if(cnt >= k)valid = mid;
        else invalid = mid;
    }

    cout << valid << endl;

    return 0;
}

Measured memory_bytes: 2420
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		Set<Integer> a = new HashSet<Integer>();
		
		for (int i = 0; i < n; i++) {
			int x = scan.nextInt();
			if (!a.contains(x)) {
				a.add(x);				
			} else {
				System.out.println("NO");
				return;
			}
		}
		
		System.out.println("YES");

	}

}

Measured memory_bytes: 99676
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#include<string>

using namespace std;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int x;
int main() {
    cin >> x;
    while(true) {
        if(IsPrime(x)) {
            break;
        } else {
            x++;
        }
    }
    cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
int main(){
  int n, ac=0, wa=0, tle=0, re=0;
  cin>>n;
  string s; 
  for(int i=1;i<=n;i++) {
    cin>>s;
    if(s=="AC")ac+=1;
    if(s=="WA")wa+=1;
    if(s=="TLE")tle+=1;
    if(s=="RE")re+=1;
    }
  cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<re<<endl;
  }


Measured memory_bytes: 3628
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
if 0 in a:
    print(0)
    quit()
for i in range(1,n):
    ans*=a[i]
    if ans > 10**18:
        break
print(ans if ans<=10**18 else "-1")


Measured memory_bytes: 21788
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double A = sc.nextDouble();
        double B = sc.nextDouble();
        double H = sc.nextDouble();
        double M = sc.nextDouble();
        sc.close();

        // 一分ごとの分針の角度の増減値を求める
        double perMinRad = 360.0000 / 60.0000;

        // 一時間ごとの時針の角度の増減値を求める
        double perHourRad = 360.0000 / (12.0000 * 60.0000);

        // 分針の角度
        double minRad = perMinRad * M;

        // 時針の角度
        double hourRad = (H * 60 * perHourRad) + (M * perHourRad);

        double rad = hourRad - minRad;

        if (rad > 180) {
            rad = 360.0000 - rad;
        }

        if (rad == 180.0) {
            System.out.println(A + B);
        } else {
            rad = Math.toRadians(rad);
            double cosRad = Math.cos(rad);
            double res = Math.sqrt(Math.pow(A, 2) + Math.pow(B, 2) - (2 * A * B * cosRad));
            System.out.println(res);
        }
    }
}


Measured memory_bytes: 37372
N = int(input())
ABC = []
for i in range(N):
    ABC.append(list(map(int,input().split())))
dp = [[0,0,0] for i in range(N)]
for i in range(N):
    if i == 0:
        dp[i][0] = ABC[i][0]
        dp[i][1] = ABC[i][1]
        dp[i][2] = ABC[i][2]
    else:
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+ABC[i][0]
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+ABC[i][1]
        dp[i][2] = max(dp[i-1][0],dp[i-1][1])+ABC[i][2]
print(max(dp[N-1]))

Measured memory_bytes: 81880
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
ostream& operator<<(ostream &os, const vector<ll> &st){
  for(int i=0;i<(int)st.size();++i){
    if(i==(int)st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
ostream& operator<<(ostream &os, const vector<vector<ll>> &st){
  for(int i=0;i<(int)st.size();++i){
    os << st[i] << endl;
  }
  return os;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll l,a,b,m;
  cin >> l >> a >> b >> m;
  vl cd(19);
  cd[0] = -1;
  vl d(19,0);
  ll d0 = 10;
  REP(i,18){
    d[i+1] = d0;
    ll tmp = (d0-a-1)/b;
    if(d0-a-1<0) cd[i+1] = -1;
    else cd[i+1] = min(tmp,l-1);
    d0 *= 10;
  }
  //cout << cd << endl;
  RREP(i,18){
    cd[i+1] -= cd[i];
  }
  //cout << cd << endl;
  a %= m;
  b %= m;
  ll x = 0;
  ll s = a;
  FOR(p,1,19){
    /*
    rは二乗する行列
    1乗時は以下の通り

    10^p 0 0
    1    1 0
    0    1 1

    d[p]は10^pを持っておく配列
    */
    vvl r(3,vl(3));
    r[0][0] = d[p]%m;
    r[0][1] = r[0][2] = 0;
    r[1][0] = r[1][1] = 1;
    r[1][2] = r[2][0] = 0;
    r[2][1] = r[2][2] = 1;

    //resはr^cd[p]を最終的に持つ行列
    //最初は単位行列にしておく。
    vvl res(3,vl(3,0));
    res[0][0] = res[1][1] = res[2][2] = 1;
    //行列累乗を繰り返し二乗法する
    for(;cd[p]>0;cd[p]>>=1){
      //その累乗が必要なら、resにrを右積する
      if(cd[p]&1){
        vvl tmp(3,vl(3,0));
        REP(i,3)REP(j,3)REP(k,3){
          tmp[i][j] += res[i][k]*r[k][j];
          tmp[i][j] %= m;
        }
        res = tmp;
      }
      //rを二乗する
      vvl t(3,vl(3,0));
      REP(i,3)REP(j,3)REP(k,3){
        t[i][j] += r[i][k]*r[k][j];
        t[i][j] %= m;
      }
      r = t;
    }
    //横ベクトルv={x,s,b}にresを右積して、横ベクトルtに遷移させる
    vl v(3);
    v[0] = x;
    v[1] = s;
    v[2] = b;
    vl t(3,0);
    REP(i,3)REP(j,3){
      t[i] += v[j]*res[j][i];
      t[i] %= m;
    }
    x = t[0];
    s = t[1];
    //cout << x << " " << s << endl;
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<cmath>
#define MAX 2000050
#define ll long long int
using namespace std;

string str;
int main(){
  cin>>str;
  int n = str.size();
  for(int i=0;i<n-1;i++){
    if(str[i]==str[i+1]){
      cout<<i+1<<" "<<i+2<<endl;
      return 0;
    }
  }
  for(int i=0;i<n-2;i++){
    if(str[i]==str[i+2]){
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
    }
  }
  cout<<-1<<" "<<-1<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int C=4e4;
const int N=2e5;
int p[N],a[N],b[N];
int main(){
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&p[i]);
	for (int i=1;i<=n;i++)
	{
		a[i]=C*i;
		b[i]=(n+1-i)*C;
	}
	for (int i=1;i<=n;i++)
		a[p[i]]+=i;
	for (int i=1;i<=n;i++)
	printf("%d ",a[i]);
	printf("\n");
	for (int i=1;i<=n;i++)
	printf("%d ",b[i]);
}
		

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

int main(){
    int a=0,b=0;
    cin >> a >> b;
    if(a!=1 && b!=1) cout << 1 << endl;
    else if(a!=2 && b!=2) cout << 2 << endl;
    else if(a!=3 && b!=3) cout << 3 << endl;
    return 0;
}

Measured memory_bytes: 256
/******************
*  Author: BD747  *
******************/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
using namespace std;

int x;

int main(){

	cin>>x;
	if(x==5 || x==3 || x==7){
		cout<<"YES";
	}else{
		cout<<"NO";
	}

	return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	priority_queue<long long> q;

    for (int i = 0; i < n; i++) {
    	int x; cin >> x;
    	q.push(x);
    }
     
    while (m--) {
    	long long value = q.top();
    	q.pop();
    	value /= 2;
    	q.push(value);
    }
    long long ans = 0;
    while(!q.empty()) {
        ans += q.top();
        q.pop();
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
3
011
101
110

1-2 2-3はできるけど1-3がむすべなくてだめとか

6
010110
101001
010100
101000
100000
010000

1 245
2 136
3 24
4 13
5 1
6 2

{5} {13} {42} {6}
{5} {1} {24} {36}
136 2 45

36 2 1 54
1のよこ 245
2のよこ 136

辺さえ存在すればよい？
無駄があってもいいってことかな
N=200
200^200はむり
BFSで、最大深さが回答かなあ
最長距離をとりたい
WFとか

3点つながったら作れない
200^3で判定可能

1-2-3-4
1-----4
もだめ

BFSかな
200回のMaxとか

NGパターンわからん
同じ深さにあったらNGかな

たかだかN^3なのになぜTLE
30で無限ループしてる
30
010000000000000000000000000000
101000000000000000000000000000
010100000000000000000000000000
001010000000000000000000000000
000101000000000000000000000000
000010100000000000000000000000
000001010000000000000000000000
000000101000000000000000000000
000000010100000000000000000000
000000001010000000000000000000
000000000101000000000000000000
000000000010100000000000000000
000000000001010000000000000000
000000000000101000000000000000
000000000000010100000000000000
000000000000001010000000000000
000000000000000101000000000000
000000000000000010100000000000
000000000000000001010000000000
000000000000000000101000000000
000000000000000000010100000000
000000000000000000001010000000
000000000000000000000101000000
000000000000000000000010100000
000000000000000000000001010000
000000000000000000000000101000
000000000000000000000000010100
000000000000000000000000001010
000000000000000000000000000101
000000000000000000000000000010

あああ、重複push_backしてた
減ったけどTLEだな
queueに入りすぎてるっぽい
なんでそんなに入るんだ？
ああ、seen入れるタイミング間違えてる
*/
vector<vector<ll>> G(210,vector<ll>(0,0));
ll N,oo=9,ans=-oo;
queue<pair<ll,ll>> Q;//次の行先と深さ

ll bfs(){
  vector<ll> seen(210,-1);
  ll tmp=0;
  //最初
  auto m=Q.front();
  seen[m.first]=0;
  while(!Q.empty()){
    auto now=Q.front(); Q.pop();
    ll v=now.first;
    ll d=now.second;
    tmp=max(tmp,d);
    for(auto next_v:G[v]){
      if(seen[next_v]==d) return -1;
      if(seen[next_v]>-1) continue;
      seen[next_v]=d+1;
      Q.emplace(next_v,d+1);
    }
  }
  return tmp;
}
int main(){
  cin>>N;
  for(ll i=1; i<=N; i++){
    string s; cin>>s;
    for(ll j=1; j<=N; j++){
      if(s[j-1]=='0') continue;
      G[i].push_back(j);
    }
  }
  for(ll i=1; i<=N; i++){
    Q.emplace(i,0);
    ans=max(ans,bfs());
    if(ans==-1){
      cout<<-1<<endl;
      return 0;
    }
  }
  ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 3904
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    int cnt = 0;
    while (h > 0)
    {
        h -= a;
        cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define watch(x); cout<<#x<<"="<<x<<endl;
#define watch2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long


std::vector<pair<int,int>> arr;
int dp[2003][2003];
int n;
int solve(int pos,int left,int right){
	if(pos>=n)return 0;
	if(left>right) return INT_MIN;
	int &ans=dp[left][right];
	if(ans!=-1)return ans;

	int maxi1,maxi2;
	maxi1=solve(pos+1,left+1,right)+abs(arr[pos].second-left)*arr[pos].first;
	maxi2=solve(pos+1,left,right-1)+abs(arr[pos].second-right)*arr[pos].first;
	return ans=max(maxi1,maxi2);
}



int32_t main() 
{ 
    fast
    cin>>n;
    arr.resize(n);
    for(int i=0;i<n;i++){
    	cin>>arr[i].first;
    	arr[i].second=i;
    }
    sort(arr.rbegin(),arr.rend());
    memset(dp,-1,sizeof dp);

    int answer=solve(0,0,n-1);
    cout<<answer;




    return 0; 
} 


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

const int maxn = 100005;

int n, m, a, b;
bool good, found_shit;
bool path[maxn];
vector < int > g[maxn];
deque < int > ans;

signed main () {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d %d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	path[1] = 1;
	ans.push_back(1);
	while (!good) {
		found_shit = 0;
		for (int v: g[ans.front()]) {
			if (!path[v]) {
				found_shit = 1;
				path[v] = 1;
				ans.push_front(v);
				break;
			}
		}
		if (found_shit)
			continue;
		for (int v: g[ans.back()]) {
			if (!path[v]) {
				found_shit = 1;
				path[v] = 1;
				ans.push_back(v);
				break;
			}
		}
		if (found_shit)
			continue;
		good = 1;
	}
	printf("%d\n", int(ans.size()));
	for (int i = 0; i < int(ans.size()); ++i)
		printf("%d ", ans[i]);
	printf("\n");
}


Measured memory_bytes: 9672
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x%y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;

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

	int first, end;

	first =S.find_first_of('A');
	end = S.find_last_of('Z');

	cout << end - first + 1 << endl;



}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define maxn 1010
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize(2)
#define ll long long
#define makefa(n) for(int i=1;i<=(n);i++)f[i]=i;
#define hh puts("");
#define eps 1e-10
#define db double
int n;
int dif=0;
char s[maxn];
void dfs(int i){
    if(i==n+1){
        cout<<s+1<<endl;
        return;}
    for (int j = 0; j <=dif ; ++j) {
        s[i]='a'+j;
        int tmp=dif;
        if(j==dif)dif++;
        dfs(i+1);
        dif=tmp;
    }
}
int main(){
    cin>>n;
    dfs(1);
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    int N;
    cin >> N;
    vector<int> C(N);
    rep(i, N)
    {
        cin >> C[i];
    }
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());
    int A = 0, B = 0;
    rep(i, N)
    {
        // cout << C[i] << endl;
        if (i % 2 == 0)
            A += C[i];
        else
            B += C[i];
    }
    cout << A - B << endl;
    return 0;
}

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

int main() {
  long long n, d, ans = 0;
  cin >> n >> d;
  vector<long long> x(n);
  vector<long long> y(n);
  for (long long i = 0; i < n; i++)
  {
    cin >> x[i] >> y[i];
  }

  for (long long i = 0; i < n; i++)
  {
    if (x[i]*x[i]+y[i]*y[i] <= d*d)
    {
      ans++;
    }
    
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 6428
def main():
    A, B, C, X, Y = map(int, input().split())
    prices = sorted([(X, A, C), (Y, B, C)], key=lambda x: x[0])
    min_price = 1e10
    for i in range(prices[0][0]+1):
        tmp_price = prices[0][1] * i + 2 * prices[0][2] * (prices[0][0]-i)
        rest = prices[1][0] - (prices[0][0]-i)
        tmp_price += min(rest * prices[1][1], 2 * rest * prices[1][2])
        min_price = min(min_price, tmp_price)

    print(min_price)


if __name__ == '__main__':
    main()


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

int main() {
	int a[3];
	for(int i=0; i<3; ++i) cin >> a[i];
	sort(a, a+3);
	int ans=0;
	if((a[0]%2)^(a[1]%2)){
	    ++ans;
	    ++a[2];
	    ++a[0];
	}
	cout << ans + (a[1]-a[0])/2 + (a[2]-a[1]) << endl;
	return 0;
}


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

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

  set<string> s;
  vector<vector<int>> cnt(N,vector<int>(10));
  for(int i = 0; i < N; ++i){
    if(i > 0) cnt[i] = cnt[i-1];
    ++cnt[i][S[i]-'0'];
  }
  for(int i = 1; i < N-1; ++i){
    vector<int> pre = cnt[i-1];
    vector<int> nex = cnt.back();
    for(int j = 0; j < 10; ++j)
      nex[j] -= cnt[i][j];
    for(int j = 0; j < 10; ++j){
      if(!pre[j]) continue;
      for(int k = 0; k < 10; ++k){
        if(!nex[k]) continue;
        string t(3,'0');
        t[0] = '0'+j;
        t[2] = '0'+k;
        t[1] = S[i];
        s.insert(t);
      }
    }
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 2432
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int N,M;




int main(int argc, char const *argv[])
{
    cin>>N>>M;
    
    std::vector<int> X(M);
    for(size_t i=0;i<X.size();i++){
        cin>>X[i];
    }
    if(M==1){
        cout<<0<<endl;
        return 0;
    }
    sort(X.begin(),X.end());
    std::vector<int> X_diff(M-1);
    for(size_t i=0;i<X_diff.size();i++){
        X_diff[i]=X[i+1]-X[i];
    }
    sort(X_diff.begin(),X_diff.end());
    int sum=0;
    if(X_diff.size()+1>N){
for(size_t i=0;i<X_diff.size()-N+1;i++){
    
sum+=X_diff[i];
}
cout<<sum<<endl;
}else{
    cout<<0<<endl;
}
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int a[212345];
int main(){
  int n;
  cin>>n;
  rep(i,n)cin>>a[i];

  map<ll,int> cnt;
  ll sum=0;
  ll ans=0;
  rep(i,n){
    sum+=a[i];
    if(sum==0)ans++;
    ans+=cnt[sum];
    cnt[sum]++;
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 13568
#include<stdio.h>
const int MAX_V=10000;
int prime[MAX_V+1];
int main(){
  int i,k,n,p,q,v;
  for(i=2;i<=MAX_V;i++){
    prime[i]=1;
  }
  for(i=2;i*i<=MAX_V;i++){
    if(prime[i]){
      for(k=2*i;k<=MAX_V;k+=i){
        prime[k]=0;
      }
    }
  }
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(v=n-2;v>=2;v--){
      int isprime=prime[v]*prime[v+2];
      if(isprime){
        printf("%d %d\n",v,v+2);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 2624