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

int main() {
  uint32_t N = 0, M = 0, K = 0;
  std::cin >> N >> M >> K;
  std::vector<uint64_t> A(N+1, 0), B(M+1, 0);
  for (uint32_t i = 0; i < N; i++){
    uint32_t a = 0;
    std::cin >> a;
    A[i+1] = a + A[i];
  }
  for (uint32_t i = 0; i < M; i++){
    uint32_t b = 0;
    std::cin >> b;
    B[i+1] = b + B[i];
  }

  uint32_t max = 0;
  for (size_t i = 0; i < N+1; i++)
  {
    uint32_t count = i;
    if(A[i] <= K){
      uint32_t remain = K - A[i];
      uint32_t index = std::upper_bound(B.begin(), B.end(), remain) - B.begin();
      count += index - 1;
      if(max < count) max = count;
    }
  }
  
  std::cout << max << std::endl;

  return 0;
}

Measured memory_bytes: 6364
N, M = map(int, input().split())

from fractions import gcd

def make_divisors(n: int):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

divisors = make_divisors(M)

ans = 0
for i in range(len(divisors)):
    d = divisors[i]
    if d*(N-1) >= M:
        continue
    ans = max(ans, gcd(d, M-(d*(N-1))))

print(ans)



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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) { cin >> A.at(i); }
  sort(A.begin(), A.end(), greater<ll>());
  if (A.at(N - 1) == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll const MAX = 1000000000000000000;
  ll ans = 1;

  REP(i, N) {
    if (A.at(i) > MAX / ans) {
      ans = -1;
      break;
    }
    ans *= A.at(i);
  }

  if (ans > MAX) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3980
import sys

H,W = map(int,input().split())
grids = [[s for s in sys.stdin.readline()] for _ in range(H)]

col_cnt = [[0 for _ in range(W)]for _ in range(H)]
for i in range(W):
  tmp_cnt = 0
  prvjj = 0
  for j in range(H):
    if grids[j][i] == '.':
      tmp_cnt += 1
    else:
      col_cnt[j][i] = 0
      for jj in range(prvjj,j):
        col_cnt[jj][i] = tmp_cnt
      prvjj = j+1
      tmp_cnt = 0
  for jj in range(prvjj,H):
    col_cnt[jj][i] = tmp_cnt

ans = -float('inf')
for j in range(H):
  tmp_cnt = 0
  prvii = 0
  for i in range(W):
    if grids[j][i] == '.':
      tmp_cnt += 1
    else:
      for ii in range(prvii,i):
        ans = max(ans,col_cnt[j][ii]+tmp_cnt-1)
      prvii = i+1
      tmp_cnt = 0

  for ii in range(prvii,W):
    ans = max(ans,col_cnt[j][ii]+tmp_cnt-1)

print(ans)

Measured memory_bytes: 220424
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] b = new int[n];//間違え
    boolean[] c = new boolean[n];//正答
    String a = "";
	for (int i = m; i > 0; i--) {
      int d = sc.nextInt() - 1;
      a = sc.next();
      if (a.equals("WA") && !c[d]) {
        b[d]++;
      } else if (a.equals("AC")) {
        if (!c[d]) {
          c[d] = true;
        }
      }
    }
    int e = 0;
    int pena = 0;
    for (int j = 0; j < b.length; j++) {
      if (c[j]) {
        pena = pena + b[j];
      }
    }
    for (boolean f: c) {
      if (f) {
        e++;
      }
    }
    System.out.println(e + " " + pena);
  }
}

Measured memory_bytes: 63800
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
#from math import floor, ceil
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
#inf = 10**17
#mod = 10**9 + 7

n,m=MI()
Q=[]
heapify(Q)
ar=[[] for i in range(m)]
for i in range(n):
    a,b=MI()
    if a<=m:
        ar[a-1].append(b)
#print(ar)
ans=0
for i in range(m):
    for j in ar[i]:
        heappush(Q,j*(-1))
    if Q:
        s=heappop(Q)*(-1)
        ans+=s
print(ans)

Measured memory_bytes: 18788
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)

int main()
{
    int K;
    cin >> K;
    int cnt = 0;
    for(int j = 1; j <= K; j += 2)
    {
        for(int l = 2; l <= K; l+= 2)
        {
            cnt++;
        }
    }

    cout << cnt << endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int dp[31];
	dp[0]=1;
	for(int i = 1; i < 31; ++i)
	{
		dp[i]=dp[i-1];
		if(2<=i) dp[i]+=dp[i-2];
		if(3<=i) dp[i]+=dp[i-3];
	}

	int n;
	while(cin>>n,n) 
	{
		int comb=dp[n];
		int ans=0;
		while(comb>0) 
		{
			comb-=3650;
			ans++;
		}
		cout<<ans<<endl;
	}
  return 0;
}

Measured memory_bytes: 1160
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif

void solve() {
    int n;
    cin >> n;
    ll ans = 1, x;
    bool ok = true, zero = false;
    vl arr(n);
    forn(i, n) cin >> arr[i];
    forn(i, n){
        x = arr[i];
        if(x == 0){
            zero = true;
            break;
        }
        if(x > INF / ans){
            ok = false;
        }else{
            ans *= x;
        }
    }
    if(zero){
        cout << '0';
    }else{
        if(ok){
            cout << ans;
        }else{
            cout << "-1";
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


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

const int MAX = 16;
const int NUM = 9;
double f[MAX][NUM];

int main()
{	
	int n, s, t, b;
	char ts, tt, tb;
	while (cin >> n, n) {
		cin >> ts >> tt >> tb;
		s = ts - 'A';
		t = tt - 'A';
		b = tb - 'A';
		
		fill((double*)f, (double*)(f +  MAX) , 0);
		f[0][s] = 1.0;
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < NUM; j++) {
				if (j >= 3 && (j - 3) != b) f[i + 1][j - 3] += f[i][j] * 0.25;
				else f[i + 1][j] += f[i][j] * 0.25;
				if (j < 6 && (j + 3) != b) f[i + 1][j + 3] += f[i][j] * 0.25;
				else f[i + 1][j] += f[i][j] * 0.25;
				if (j % 3 != 0 && (j - 1) != b) f[i + 1][j - 1] += f[i][j] * 0.25;
				else f[i + 1][j] += f[i][j] * 0.25;
				if (j % 3 != 2 && (j + 1) != b) f[i + 1][j + 1] += f[i][j] * 0.25;
				else f[i + 1][j] += f[i][j] * 0.25;
			}
		}
		printf("%.8lf\n", f[n][t]);
	}
	
	return 0;
}

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

int main() {
    int n, h, maximum = 0, ans = 0;
    cin >> n;
    rep(i, n) {
        cin >> h;
        if(h >= maximum) {
            ans++;
            maximum = h;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
const Release = function () {
    const fs = require('fs');
    const stdin = function (text) {
        if (text) console.log(text);
        return fs.readFileSync('/dev/stdin', 'utf8');
    }
    return stdin;
};


const debug = false;

const stdin = debug ? Debug() : Release();
const input = stdin().split('\n').map(x => parseInt(x));

const X = input[0];
const A = input[1];
const B = input[2];

const c = (X - A) % B;
console.log(c);

Measured memory_bytes: 21064
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 100001
#define INF   1000000000
#define p     1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll A[MAX_N];

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

    ll N, M;
    cin >> N >> M;

    priority_queue<ll> pq;
    
    for (ll i = 0; i < N; i++) {
      cin >> A[i];
      pq.push(A[i]);
    }

  
    for (ll i = 0; i < M; i++) {
      ll a = pq.top();
      pq.pop();
      pq.push(a/2);
    }

    ll ans = 0;
    while (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }

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


Measured memory_bytes: 2040
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<i64> as(N);
  F0R(i, N) {
    cin >> as[i];
  }
  vector<int> ls(N+1), rs(N);
  ls[N] = INT32_MAX;
  F0R(i, K) {
    F0R(j, N) {
      ls[j] = j - as[j];
      rs[j] = j + as[j] + 1;
    }
    sort(rng(ls));
    sort(rng(rs));
    //Print(ls);
    //Print(rs);
    int li = 0, ri = 0;
    int low = N + 1;
    int n = 0;
    F0R(j, N) {
      while (ls[li] <= j) {
        n++;
        li++;
      }
      while (rs[ri] == j) {
        n--;
        ri++;
      }
      chmin(low, as[j] = n);
    }

    if (low >= N) {
      break;
    }
  }

  F0R(i, N) {
    cout << as[i] << ' ';
  }
}
#endif


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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

ll a[100100];
int main() {
  ll n, m;
  cin >> n >> m;
  rep(i, n) cin >> a[i];
  rep(i, n) a[i] /= 2;
  ll alcm = 1;
  rep(i, n) {
    alcm = lcm(alcm, a[i]);
    if (alcm > m) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if ((alcm / a[i]) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << m / alcm - m / (2 * alcm) << endl;
}


Measured memory_bytes: 4420
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    long long N, K;
    cin >> N >> K;

    if (K == 0) {
        cout << N * N << endl;
        return 0;
    }

    long long ans = 0;
    for (long long b = 1; b <= N; b++) {
        long long d = N / b;
        ans += d * max(b - K, 0LL);
        if (N % b > 0) {
            ans += max(0LL, N % b - K + 1);
        }
    }

    cout << ans << endl;

}
















































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n,m;cin >> n >> m;
    vector<int> s(n,0);
    int AC=0,WA=0;
    rep(i,m){
        //cout << "i=" << i << endl;
        int a;string b;
        cin >> a >> b;
        a--;
        if(b=="WA"){
            s[a]++;
        }else{
            if(s[a]>=INF) continue;
            WA += s[a];
            s[a] = INF;
            AC++;
        }
    }
    cout << AC << " " << WA << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int  k, x;
	while(scanf("%d%d", &k, &x)==2)
	{
		bool ans=(k*500>=x);
		printf("%s\n", ans?"Yes":"No");
	}
	return 0;
}


Measured memory_bytes: 128
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n; cin >> n;
    vector<ll> d(n);
    REP(i, n) cin >> d[i];

    ll sum = 0, sum2 = 0;
    REP(i, n) {
        sum += d[i];
        sum2 += d[i] * d[i];
    }
    cout << (sum * sum - sum2) / 2 << endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{   
    int h,n;
    scanf("%d%d",&h,&n);
    int a[n];
    long long ans=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        ans+=a[i];
    }
    if(ans>=h){
    printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 512
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

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

  int h, w;
  cin >> h >> w;

  vector<string> grid(h);
  rep(i,h) cin >> grid[i];

  int res = -1;
  rep(sh,h) {
    rep(sw,w) {
      if (grid[sh][sw] == '#') continue;

      queue<pair<int, int>> que;
      vector<vector<int>> dist(h, vector<int> (w, -1));
      dist[sh][sw] = 0;
      que.push({sh, sw});

      while (!que.empty()) {
        int vh = que.front().fi;
        int vw = que.front().se;
        que.pop();

        rep(dir, 4) {
          int nvh = vh + dy[dir];
          int nvw = vw + dx[dir];

          if (nvh < 0) continue;
          if (nvw < 0) continue;
          if (nvh >= h) continue;
          if (nvw >= w) continue;
          if (dist[nvh][nvw] != -1) continue;
          if (grid[nvh][nvw] == '#') continue;

          dist[nvh][nvw] = dist[vh][vw]+1;
          que.push({nvh, nvw});
        }
      }
      rep(gh,h) rep(gw,w) res = max(res, dist[gh][gw]);
    }
  }

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T = ll> constexpr T TEN(int n) {return (n==0)?1:10*TEN<T>(n-1);}

const int MN = 200200;
int n;
vector<int> g[MN], ga[MN];

int dps[MN], par[MN];
void dfs(int p, int b, int dp = 0) {
    dps[p] = dp;
    par[p] = b;
    for (int d: g[p]) {
        if (d == b) continue;
        dfs(d, p, dp+1);
    }
}

int dist3(int a, int b) {
    if (dps[a] < dps[b]) swap(a, b);
    if (a == b) return false; // dist 0
    if (par[a] == b) return false; // dist 1
    if (par[a] == par[b]) return false; // dist 2(a)
    if (par[a] != -1 && par[par[a]] == b) return false; // dist 2(b)
    return true;
}

int calc(int p, int b, int dp = 0) {
    if (dps[p] <= dp) return 0;
    int ans = 2*(dps[p]-dp); // pass
    for (int d: ga[p]) {
        if (d == b) continue;
        if (dist3(d, p)) {
            return TEN(9); // dist 3 jump
        }
        ans = max(ans, 2+calc(d, p, dp+1));
    }
    return ans;
}

int main() {
    int x, y;
    scanf("%d %d %d", &n, &x, &y); x--; y--;
    for (int i = 0; i < n-1; i++) {
        int a, b;
        scanf("%d %d", &a, &b); a--; b--;
        ga[a].push_back(b);
        ga[b].push_back(a);
    }
    for (int i = 0; i < n-1; i++) {
        int a, b;
        scanf("%d %d", &a, &b); a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(y, -1);
    int ans = calc(x, -1);
    if (ans > TEN(9)/2) ans = -1;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 34072
#include<bits/stdc++.h>
#include <cctype>
#define ll          long long int
#define PB          push_back
#define PII         pair<ll int,ll int>
#define VI          vector<ll int>
#define ALL(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define SZ(x)       (ll int)x.size()
#define hell2        998244353
#define hell9        1000000007
#define FO(i,a,b)    for(i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define BS          binary_search
#define MP          make_pair
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
/*ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
      y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
ll fac[500000]={0};
ll done=1;
ll ncrModP(ll n, ll r, ll p) 
{ 
   if (r==0) 
      return 1; 
     
    fac[0] = 1; 
    if(n>done)
    {for (ll i=done ; i<=n; i++) 
        fac[i] = (fac[i-1]*i)%p;}
        done=max(done,n); 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 

} 
/*ll ncrM(ll n, ll r, ll p) 
{ 
    if (r > n - r) 
        r = n - r; 
    ll C[r + 1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) { 
        for (ll j = min(i, r); j > 0; j--) 
      C[j] = (C[j] + C[j - 1]) % p; 
    } 
    return C[r]; 
}
map<ll,ll>f;
ll done=2;
ll fib(ll k)
{
    ll i;f[0]=1;f[1]=1;f[2]=2;
    if(k<=done)return f[k];
    for(i=done;i<=k;i++)f[i]=(f[i-1]%hell9+f[i-2]%hell9)%hell9;
    done=k;
    return f[k]%hell9;
}*/
int main()
{
//  #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//  #endif
    fio
    ll n,i;
    cin>>n;
    ll a[n],b[n],c[n];ll dp[n][3];
    FO(i,0,n)cin>>a[i]>>b[i]>>c[i];dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0];
    FO(i,1,n)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return 0;
}

Measured memory_bytes: 4992
N = int(input())
a = 4
b = 7
count = 0
for i in range(0, (N // a) + 1):
    for j in range(0, (N // b) + 1):
        if a * i + b * j == N:
            count += 1
        else:
            pass

if count >= 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B;
	while(cin>>A>>B) {
		ll v=atoi((to_string(A)+to_string(B)).c_str());
		ll ans=0;
		RANGE(i, 1, 1000) if(i*i==v) ans=1;
		cout<<YN(ans)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define SUCCESS 1
#define FAILURE 0

int search(int x,int y);

int cannot[2][40];
int a,b,n;

int main()
{
	int i,result;
	while(1)
	{
		scanf("%d %d",&a,&b);
		if(a==0&&b==0)break;
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%d %d",&cannot[0][i],&cannot[1][i]);
		}
		result=search(1,1);

		printf("%d\n",result);
	}
	return 0;
}

int search(int x,int y)
{
	int i,result=0;

	if(x==a&&y==b)return SUCCESS;

	for(i=0;i<n;i++)
	{
		if(x==cannot[0][i]&&y==cannot[1][i])
		{
			return FAILURE;
		}
	}
	if(x<a)
	{
		result+=search(x+1,y);
	}
	if(y<b)
	{
		result+=search(x,y+1);
	}
	return result;
}

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

namespace AtCoder {
    class Program {
        static void Main() {
            int k = int.Parse(Console.ReadLine());
            int sum = 0;
            for(int a = 1; a <= k; a++) {
                for(int b = 1; b <= k; b++) {
                    for(int c = 1; c <= k; c++) {
                        sum += Gcd(a, b, c);
                    }
                }
            }
            Console.WriteLine(sum);
        }
        static int Gcd(int a, int b) {
            if(a < b)
                return Gcd(b, a);
            while(b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
        static int Gcd(int a, int b, int c) {
            return Gcd(Gcd(a, b), c);
        }
    }
}

Measured memory_bytes: 27540
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;

int main() {
	vector<int> h(10);
	for (int i = 0; i < 10; i++) {
		cin >> h[i];
	}
	sort(h.begin(), h.end(),greater<int>());
	for (int i = 0; i < 3; i++) {
		cout << h[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<pair<int, lint>>> edges(n);
    vector<pair<pair<int, int>, lint>> e;
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        lint w;
        cin >> u >> v >> w;
        u--, v--;
        edges[u].emplace_back(v, w);
        edges[v].emplace_back(u, w);
        if (u > v)
            swap(u, v);
        e.push_back({{u, v}, w});
    }
    vector<lint> sz(n, 1);
    {
        int centroid                 = -1;
        lint cent                    = -1;
        lint ret                     = 0;
        function<void(int, int)> dfs = [&](int c, int p) {
            bool ce = true;
            for (auto &v : edges[c]) {
                if (v.first == p)
                    continue;
                dfs(v.first, c);
                sz[c] += sz[v.first];
                ret += v.second * min(sz[v.first], n - sz[v.first]) * 2;
                if (sz[v.first] >= (n + 1) / 2)
                    ce = false;
                if (n % 2 == 0 && sz[v.first] == n / 2) {
                    cent = v.second;
                }
            }
            if (ce && (n - sz[c]) < n / 2) {
                centroid = c;
            }
        };
        dfs(0, -1);
        if (centroid != -1) {
            lint mini = inf;
            for (auto &p : edges[centroid]) {
                mini = min(mini, p.second);
            }
            ret -= mini;
        } else {
            ret -= cent;
        }
        cout << ret << "\n";
    }
    return 0;
}

Measured memory_bytes: 18288
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; string S,T; cin>>N>>S>>T;
  string ans;
  rep(i,0,N){
    ans+=S[i];
    ans+=T[i];
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
s = int(input())
x1, y1 = 0, 0
x2, y2 = 10 ** 9, 1
x3 = 10 ** 9 - ((s-1) % (10 ** 9)+1)
y3 = (s + x3) // (10 ** 9)
print(x1, y1, x2, y2, x3, y3)


Measured memory_bytes: 2940
D,N = map(int,input().split())
res = 0
num = 0
while True:
  res += 1
  x = res
  count = 0
  while x >= 100:
    d = x % 100
    if d != 0: break
    x //= 100
    count += 1
  if count == D:
    num += 1
  if num == N:
    break
print(res)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    ll n,k;
    cin>>n>>k;
    vi a(n);
    REP(i,n){
        cin>>a[i];
        a[i]--;
    }

    vi route;
    int now=0;
    int loopidx = 0;
    vi routeidx(n, -1);

    route.emplace_back(0);
    routeidx[0] = 0;

    ll cnt=0;
    do{
        if(routeidx[a[now]] != -1){
            loopidx = routeidx[a[now]];
            break;
        }
        
        cnt++;
        route.emplace_back(a[now]);
        routeidx[a[now]] = cnt;
        now = a[now];
        //DEBUG(now);
    }while(cnt!=k);

    //DEBUG_VEC(route);

    k = k-loopidx;
    ll loopsz = route.size() - loopidx;
    //DEBUG2(loopidx,loopsz);
    ll ans = route[loopidx + (k % loopsz)];
    ans += 1; //1->0indexにしたため戻す

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

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


int main() {
	
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &i : a){
		cin >> i;
	}
	for(int i=0; i<n; i++){
		if(a.at(i)%2==0){
			if( !(a.at(i)%3==0 || a.at(i)%5==0) ) {
				cout << "DENIED" << endl;
				break;
			}
		}
		if (i==n-1){
			cout << "APPROVED" << endl;
		}
	}
	return 0;
}

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

int main(){
  char s[5];
  int cnt = 0;
  int cnt2 = 0;
  int i,j;

  scanf("%s", s);

  for(i = 0;i < 4;i++){
    for(j = i + 1;j < 4;j++){
      if(s[i] == s[j]) cnt++;
    }
  }

  if(cnt == 2) printf("Yes\n");

  else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100100;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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



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

    int N;cin >> N;
    vector<pair<pair<long long,long long>,long long>> point(N);
    for(int i = 0;i<N;i++){
        cin >> point.at(i).first.first >> point.at(i).first.second >> point.at(i).second;
        swap(point.at(i).first.first,point.at(i).second);
    }
    sort(point.begin(),point.end(),greater<pair<pair<int,int>,long long>>());
    for(int i = 0;i<N;i++) swap(point.at(i).first.first,point.at(i).second);
    
    for(long long x = 0;x<=100;x++){
        for(long long y = 0;y<=100;y++){
            long long vertexH = -1;
            bool ok = true;
            for(int i = 0;i<N;i++){
                long long nh = point.at(i).second;
                long long nx = point.at(i).first.first,ny = point.at(i).first.second;
                //if(nh == 0) break;
                if(vertexH == -1){
                    vertexH = nh+abs(nx-x)+abs(ny-y);
                }
                else{
                    if(nh != max(vertexH-abs(nx-x)-abs(ny-y),(long long)0)){
                        ok = false;
                    }
                }
            }
            if(ok){
                cout << x << " " << y << " " << vertexH << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3676
N=int(input())
x=[]
y=[]
h=[]
for i in range(N):
  a,b,c=map(int,input().split())
  x.append(a)
  y.append(b)
  h.append(c)
field=[[-1 for i in range(101)] for i in range(101)]
for i in range(N):
  for j in range(101):
    for k in range(101):
      if(h[i]!=0):
        if(field[j][k]==-1):
          field[j][k]=h[i]+abs(j-x[i])+abs(k-y[i])
        elif(field[j][k]!=h[i]+abs(j-x[i])+abs(k-y[i])):
          field[j][k]=-2
      else:
        if(field[j][k]>h[i]+abs(j-x[i])+abs(k-y[i])):
          field[j][k]=-2
cx=0
cy=0
H=0
for i in range(101):
  for j in range(101):
    if(field[i][j]>=0):
      cx=i
      cy=j
      H=field[i][j]
print(cx,cy,H)

Measured memory_bytes: 3444
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;

///---program start---///

bool is_red[arr];
int cnt[arr];

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    int n,m;
    cin>>n>>m;
    for (int i=1;i<=n;i++){
        cnt[i]=1;
    }
    is_red[1]=1;

    for (int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        is_red[y]|=is_red[x];
        cnt[x]--;
        cnt[y]++;
        is_red[x]&=(cnt[x]>0);
    }
    int ans=0;
    for (int i=1;i<=n;i++){
        ans+=(is_red[i]?1:0);
    }
    cout<<ans<<"\n";
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

int n;
char s[205];
int dist[205][205];
const int INF = 1e9;

int main() {
	make(n);
	FOR(i,0,n) FOR(j,0,n) dist[i][j] = INF;
	FOR(i,0,n) dist[i][i] = 0;
	FOR(i,0,n) {
		scanf("%s", s);
		FOR(j,0,n) {
			if (s[j] == '1') {
				dist[i][j] = 1;
			}
		}
	}
	FOR(u,0,n) {
		FOR(v1, 0, n) {
			FOR(v2, 0, n) {
				if (dist[v1][v2] > dist[v1][u] + dist[u][v2]) {
					dist[v1][v2] = dist[v1][u] + dist[u][v2];
				}
			}
		}
	}
	int ans = -1;
	bool ok = true;
	FOR(u,0,n) {
		FOR(v1,0,n) FOR(v2,0,n) {
			if (dist[u][v1] == dist[u][v2] && dist[v1][v2] == 1) {
				ok = false;
			}
			ans = max(ans, dist[u][v1]);
		}
	}
	if (!ok) {
		printf("-1\n");
	} else {
		printf("%d\n", ans+1);
	}
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S,h,m,s;
  cin>>S;
  h=m=s=0;
  h=S/3600;
  m=(S%3600)/60;
  s=S%60;
  cout<<h<<":"<<m<<":"<<s<<endl;    
}  


Measured memory_bytes: 3072
s = raw_input()
s_2 = ''
judge = 0
p = raw_input()
for i in range(len(s)):
	s_list = list(s)
	if list(s)[i] == list(p)[0]:
		s_list.extend(s_list[0:i])
		del s_list[0:i]
		s_2 = "".join(s_list)
		if p in s_2:
			judge = 1
if judge :
	print 'Yes'
else :
	print 'No'

Measured memory_bytes: 6420
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

int main() {
    cin >> N;
    cout << 3*N*N << endl;
}

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

int main(){
    int m,n;
    std::string str,tes;
    while(true){
    std::cin >> str >> m;
    if(str=="-")break;
    for(int a=0;a<m;a++){
        std::cin >> n;
        tes=str.substr(0,n);
        str.erase(str.begin(), str.begin()+n);
        str += tes;

    }
    std::cout << str << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3220
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <queue>

#define mod 1000000007
#define MAX_N 10000

using namespace std;

int counter[MAX_N + 1];

int main()
{
    int N, i, x, y, z;

    scanf("%d", &N);
    memset(counter, 0, sizeof counter);
    for(x = 1; x * x <= N; ++x)
        for(y = 1; y * y <= N; ++y)
            for(z = 1; z * z <= N; ++z)
                if(x * x + y * y + z * z + x * y + y * z + z * x <= N)
                    ++counter[x * x + y * y + z * z + x * y + y * z + z * x];
    for(i = 1; i <= N; ++i)
        printf("%d\n", counter[i]);

    return 0;
}


Measured memory_bytes: 1764
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define double long double
#define rep(i,n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define repii(i,a,b) for(ll i=a;i<=b;i++)
#define pb push_back
#define in insert
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
int main()
{
    fastIO;
    int n;
    cin>>n;
    ll a[n];
    rep(i,n)cin>>a[i];
    int ans[n];
    ans[n-1]=1;
    int c=1;
    for(int i=n-2;i>=0;i--)
    {
        if(a[i]>=a[i+1])
            ans[i]=ans[i+1]+1;
        else
            ans[i]=1;
        c=max(c,ans[i]);
    }
    cout<<c-1<<endl;
    return 0;
}


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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

int N;
vector<int> A;

int main()
{
    cin >> N;
    _for(i,0,N){
        int a;
        cin >> a;
        A.push_back(a);
    }
    vector<int> ans;
    for(int i = N; i >= 1;i--){
        int index = i;
        for(int j = (N-1);j >= 0;j--){
            if(A[j] == 0) continue;
            if(index == A[j]){
                ans.push_back(A[j]);
                A[j] = 0;
                break;
            }
            index--;
        }
    }
    reverse(ALL(ans));
    if(ans.size() != N) printf("-1");
    else{
        for(auto a:ans) cout << a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
    int H, W;
    cin >> H >> W;
    
    char C[H][W];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> C[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << C[i][j];
        }
        cout << endl;
        for (int j = 0; j < W; j++) {
            cout << C[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double l;
    cin >> l;
    l /= 3.0;
    l *= l * l;
    cout << fixed << setprecision(10);
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import collections
#import cython
def get_keys(d, val):
    return [k for k, v in d.items() if v == val]
    
def main():
    read = lambda: sys.stdin.readline().rstrip()
    
    N, K  = map(int,read().split())
    A = list(map(int,read().split()))
    
    g = collections.defaultdict(int)
    for i, val in enumerate(A):
        g[i + 1] = val
        
    v = collections.defaultdict(int)
    cnt = 0
    cur = 1
    p = 0
    mp = 0
    while True:
        if v[cur] > 0 or cnt > 2*10**5:
            p = cnt - v[cur]
            mp = v[cur]
            break
        v[cur] = cnt
        cnt += 1
        cur = g[cur]
    
    print(get_keys(v, (K-mp)%p + mp)[0] if K >= mp else get_keys(v, K)[0])


 
if __name__ == "__main__":
    main()

Measured memory_bytes: 60424