akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.14159265359;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

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

    map<int, int> cercle;
    irep(i, n) {
        int in;
        cin >> in;
        cercle[in]++;
    }

    string ans = "No";
    if(cercle.size() == 1) {
        if(cercle.find(0) != cercle.end()) {
            ans = "Yes";
        }
    } else if(n%3 == 0 && cercle.size() == 3) {
        int x = 0;
        bool ok = true;
        for(auto c : cercle) {
            x ^= c.first;    
            if(c.second != n/3) {
                ok = false;
            }
        }
        if(ok & !x) { 
            ans = "Yes";
        }
    } else if(n%3 == 0 && cercle.size() == 2) {
        if(cercle[0] == n/3) {
            ans = "Yes";
        }
    } else {
        ans = "No"; 
    }
    cout << ans << endl;
    return 0;
}
/** atcoder **/



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

using namespace std;

int main () {
  int n, limit_t, cost, time;
  vector<pair<int, int>> routes;

  cin >> n >> limit_t;

  for (size_t i = 0; i < n; i++) {
    cin >> cost;
    cin >> time;
    if(time <= limit_t)
      routes.push_back(make_pair(cost, time));
  }

  if(routes.size() == 0)
    cout << "TLE" << endl;
  else {
    sort(routes.begin(), routes.end());

    cout << routes[0].first << endl;
  }

  return 0;
}


Measured memory_bytes: 256
def cmb(n, r, p):
    # ex. 5_C_4 = 5_C_1、rが小さい方を計算したほうが楽
    r = min(r, n - r)

    # n*(n-1)*...*(n-r+1)
    # 組み合わせの公式の分子
    upper = 1
    for i in range(n, n - r, -1):
        upper = (upper * i) % p

    # 1*2*...*r
    # 組み合わせの公式の分母
    lower = 1
    for i in range(1, r + 1):
        lower = (lower * i) % p
    # 剰余の計算において、+-*は良いが、/は普通にやると成り立たない
    # ex. 6/3(mod5)...2になって欲しいが1/3になってしまう
    # 割るのではなく、「逆元」を掛けるとすれば割らなくて済む
    # フェルマーの小定理より、pが素数なら1/lowerの逆元はlower**(p-2)
    # powの第3引数を使うことで繰り返し二乗法になる
    return (upper * pow(lower, p - 2, p)) % p

mod = pow(10, 9) + 7
n, a, b = map(int, input().split())
# 全ての選び方-何も選ばない時-a本の時-b本の時
ans = (pow(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)) % mod
print(ans)


Measured memory_bytes: 9152
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


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

s = [0] * (N+1)
for i in range(N):
    s[i+1] = s[i] + A[i]
# pprint(s)

prev = s[K]
for i in range(K+1, N+1):
    # print(f'i = {i}')
    # print(f's[i] = {s[i]}, s[i-K] = {s[i-K]}')
    score = s[i] - s[i-K]
    # print(f'score = {score}')
    if prev < score:
        print('Yes')
    else:
        print('No')
    prev = score


Measured memory_bytes: 32660
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

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

int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll x = min(A, K);
    ll y = min(B, K - x);
    ll z = min(C, K - x - y);

    cout << x - z << endl;

    return 0;
}


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

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
/*alias*/
#define F first
#define S second
 
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int
 
/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
 
/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}
 
/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;
 
/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right
 
 
//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001
 
/*global*/
 
 
//for dfs, I prepare container(tree) at global
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1){
	for(int u: to[v]){
		if(u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}
 
//#define int int64_t
signed main()
{
	int n, q; cin >> n >> q;
	for(int i = 0, i_len = (int)n-1; i < i_len; ++i){
		int a, b;
		cin >> a >> b;
		--a;--b;
		to[a].emplace_back(b);
		to[b].emplace_back(a);		
	}
	ans.resize(n);
	for(int i = 0, i_len = (int)q; i < i_len; ++i){
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(0);
 
	for(int i = 0, i_len = (int)n; i < i_len; ++i){
		cout << ans[i] << "\n";
	}
 
}

Measured memory_bytes: 23552
s = input()
ans = True
for i, v in enumerate(s):
    i += 1
    if i % 2:
        if not v in ['R', 'U', 'D']:
            ans = False
            break
    else:
        if not v in ['L', 'U', 'D']:
            ans = False
            break

if ans:
    print('Yes')
else:
    print('No')
            


Measured memory_bytes: 2940
import itertools
def check(a,b,c):
    for p in itertools.permutations([a,b,c]):
        (x,y,z)=p
        if x*x+y*y==z*z:
            return True
    return False

n=input()
for i in range(n):
    (a,b,c)=map(eval,raw_input().split())
    if check(a,b,c):
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 4384
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()



int main(){
  ll N,m=0;
  cin >> N;
  map<string,ll> A;
  rep(i,N){
    string s;
    cin >> s;
    A[s]++;
    m=max(m,A[s]);
  }
  for(auto [key,value]:A){
    if(m==value){
      cout << key << endl;
    }
  }
}
  

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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXN = 100000;
int num[4];

int main() {
	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		int a;
		cin >> a;
		num[a % 4]++;
	}
	int z = num[1] + num[3] - 1;
	if(num[2] != 0)
		z++;
	if(num[0] >= z)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2632>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int h,w,n;
int get(int i,int j){
    i %= 2*w;
    while(i){
        int T;
        if((i+j)%2 == 0){ T = -min(i,j);
        }else{ T = min(i,w-j-1); }
        j += T; i -= abs(T);
        if(i) i--;
    }
    return j;
}
void solve(){
    cin >> h >> w >> n;
    vector<pii> ab(n); for(auto& in:ab){ cin >> in.first >> in.second; in.first--; in.second--; }
    
    vector<int> amida(w); iota(amida.begin(),amida.end(),0);
    sort(ab.begin(),ab.end());
    for(auto& p:ab){
        int H = p.first, l = p.second, r = p.second+1;
        int getlv = get(H,l), getrv = get(H,r);
        swap(amida[getlv],amida[getrv]);
    }
    
    vector<int> ans(w);
    for(int i = 0; i < w;i++) ans[amida[get(h,i)]] = i + 1;
    for(int i = 0; i < w;i++){
        cout << ans[i] << endl;
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 5976
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5+100)

def dfs(v, pv, c):
    if memo[v][c]!=-1:
        return memo[v][c]
        
    res = 1
    
    for nv in G[v]:
        if nv==pv:
            continue
        
        if c==0:
            res *= dfs(nv, v, 0)+dfs(nv, v, 1)
        else:
            res *= dfs(nv, v, 0)
        
        res %= MOD
    
    memo[v][c] = res
    
    return res

N = int(input())
G = [[] for _ in range(N)]

for _ in range(N-1):
    x, y = map(int, input().split())
    G[x-1].append(y-1)
    G[y-1].append(x-1)

memo = [[-1]*2 for _ in range(N)]
MOD = 10**9+7

print((dfs(0, -1, 0)+dfs(0, -1, 1))%MOD)

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

int main() {
    bool n[3];
    n[0] = true;
    n[1] = n[2] = false;
    char a,b,c;
    while (cin >> a >> c >> b) {
        swap(n[a - 'A'], n[b - 'A']);
    }
    if (n[0]) cout << "A" << endl;
    if (n[1]) cout << "B" << endl;
    if (n[2]) cout << "C" << endl;
    return 0;
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a,mod=1e9+7,dp[114514];
bool f[114514];
int main() {

	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a;
		f[a]=1;
	}
	dp[0]=1;
	if(!f[1])dp[1]=1;
	for(int i=2;i<=n;i++)if(!f[i]){
		dp[i]=dp[i-1]+dp[i-2];
		dp[i]%=mod;
	}
	cout<<dp[n];
	return 0;
}


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

int main(){
	int N;
	cin >> N;
	char last;
	vector<string> W(N);
	for (int i=0; i<N; ++i){
		cin >> W[i];
		// 重複チェック 
		for (int j=0; j<i; ++j){
			if (W[i]== W[j]){
				cout << "No" << endl;
				return 0;
			}
		}
		// しりとりチェック
		if (i != 0 && W[i][0] != last){
			cout << "No" << endl;
			return 0;
		}
		last = W[i][(W[i].size())-1];
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;

import java.util.*;



class Main{

	private static int sum_check(int a){

		int count = 0;

		for(int i = 0;i<=9;i++){
			for(int j = 0;j<=9;j++){
				for(int k = 0;k<=9;k++){
					for(int l = 0;l<=9;l++){
						if((i+j+k+l) == a){count++;}
					}	
				}
			}

		}			

		return count;

	}

	

		public static void main(String args[]) throws IOException{

			Scanner scan = new Scanner(System.in);

			int n,count;

			

			while(scan.hasNext()){

				String str1 = scan.next();

				n = Integer.valueOf(str1).intValue();

				count = sum_check(n);

				System.out.println(count);

			}

		}

}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-9
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9+7;
const double PI = acos(-1);

int n,i,j,k,t;
vector<int> adj[100002];
int dp[100002][2];

int solve(int v, int p, int c){
    int &ans = dp[v][c];
    if(ans == -1){
        ans = 0;
        if(c == 1){
            ans = 1;
            for(int x : adj[v]){
                if(x == p) continue;
                ans = 1LL*ans*solve(x, v, 0) % mod;
            }
        }
        else{
            ans = 1;
            for(int x : adj[v]){
                if(x == p) continue;
                ans = 1LL*ans*(solve(x, v, 0) + solve(x, v, 1))%mod ;
            }
        }
    }
    return ans;
}

int main(){
    memset(dp, -1, sizeof dp);
    scanf("%d", &n);
    for(i=1;i<n;++i){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int ans = (solve(n, n, 0) + solve(n, n, 1)) % mod;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 11264
#[allow(dead_code)]

pub struct Scanner {
    idx: usize, 
    buf: Vec<String>,
}

impl Scanner {
    pub fn new<T: std::io::Read>(inf: &mut T) -> Scanner {
        Self {
            idx:0,
            buf: {
                let mut s = String::new();
                inf.read_to_string(&mut s).expect("I/O error");
                s.split_whitespace().map(|x| x.to_owned()).collect()
            },
        }
    }

    pub fn read<T: std::str::FromStr> (&mut self) -> T 
    where
        <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        if self.empty() {
            panic!("reached the end of input")
        }
        let ret = self.buf[self.idx].parse::<T>().expect("parse error");
        self.idx += 1;
        return ret;
    }

    pub fn empty(&self) -> bool {
        return self.idx >= self.buf.len();
    }
}

fn main() {
    let mut sc = Scanner::new(&mut std::io::stdin());
    let s: Vec<char> = sc.read::<String>().chars().collect();

    let mut ans = 1 << 30;

    let is_unique = |s: &Vec<char>| {
        for i in 1..s.len() {
            if s[i] != s[i - 1] {
                return false;
            }
        }
        return true;
    };

    let x = 'a' as u8;
    let y = 'z' as u8;
    for ch in x..=y {
        let mut cpy = s.clone();
        let mut cnt = 0;

        while !is_unique(&cpy) {
            cnt += 1;
            for i in 1..cpy.len() {
                if cpy[i] == ch as char {
                    cpy[i - 1] = cpy[i];
                }
            }
            cpy.pop();
        }

        ans = std::cmp::min(ans, cnt);
    }

    println!("{}", ans);
}


Measured memory_bytes: 2120
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string nap;
    cin >> nap;
    int n = nap.size();
    int l = -1, p = -1;
    for (int i = 0; i < n - 1; ++i)
    {
        if (nap[i] == nap[i + 1])
        {
            l = i;
            p = i + 1;
        }
    }
    for (int i = 0; i < n - 2; ++i)
    {
        if (nap[i] == nap[i + 2])
        {
            l = i;
            p = i + 2;
        }
    }
    if (l == -1 && p == -1)
        cout << l << " " << p;
    else
        cout << l + 1 << " " << p + 1;
    return 0;
}


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

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

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

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

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

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

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

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

#[cfg(debug_assertions)]
macro_rules! debug {
      ($($a:expr),*) => {
          println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}

fn toi(s:usize, edges: &Vec<Vec<usize>>) -> (usize, usize){
  let mut q = vec![];
  let mut dep = vec![-1; edges.len()];
  q.push(s);
  dep[s] = 0;
  while !q.is_empty() {
    let c = q.pop().unwrap();
    for k in 0..edges[c].len() {
      let e = edges[c][k];
      if dep[e] == -1 {
        q.push(e);
        dep[e] = dep[c] + 1;
      }
    }
  }
  //debug!(dep);
  let mut dis = 0;
  let mut v = 0;
  for i in 0..edges.len() {
    if dis < dep[i] {
      dis = dep[i];
      v = i;
    }
  }
  return (v, dis as usize);
}

fn main() {
  input! {
    n: usize,
    ab: [(usize1, usize1); n-1]
  }
  let mut edges = vec![vec![]; n];
  for (x, y) in ab {
    edges[x].push(y);
    edges[y].push(x);
  }
  //debug!(edges);
  let (v, _) = toi(0, &edges);
  let (_, d) = toi(v, &edges);
  //debug!(d);
  if d % 3 == 1 {
    println!("Second");
  } else {
    println!("First");
  }
}

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

int main() {
	int L, A, B, C, D;
	int finJP, finMath;
	int i = 0;

	cin >> L;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;

	if (A%C > 0) {
		finJP = A / C + 1;
	}
	else {
		finJP = A / C;
	}
	if (B%D > 0) {
		finMath = B / D + 1;
	}
	else {
		finMath = B / D;
	}
	if (finJP < finMath) {
		cout << L - finMath << endl;
	}
	else if (finJP > finMath) {
		cout << L - finJP << endl;
	}
	else {
		cout << L - finMath << endl;
	}

	return 0;
} 


Measured memory_bytes: 3096
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
#define F first
#define S second

const int MOD = 1e9+7; //998244353;
inline int add(int a, int b){ return (a+b)%MOD; }
inline int sub(int a, int b){ return ((a-b)%MOD + MOD)%MOD; }
inline int mul(int a, int b){ return ((ll)a*b)%MOD; }

const int sz = 5e3+5;
int n, pwr[sz/2];
string s;

int getHash(int start, int end){
    int ans = 0;
    for(int i = start; i <= end; ++i){
        ans = add(mul(ans, 26), s[i]-'a');
    }
    return ans;
}

int roll(int hash, int newpos, int len){
    int oldpos = newpos-len;
    return add(mul(sub(hash, mul(pwr[len-1], s[oldpos]-'a')), 26), s[newpos]-'a');
}

bool works(int len){
    int hfrontst = getHash(0, len-1), hbackst = getHash(len-1, 2*len-2);
    for(int gap = 0; gap <= n-len*2; ++gap){
        hbackst = roll(hbackst, 2*len+gap-1, len);
        int hfront = hfrontst;
        int hback = hbackst;
        if(hfront == hback){
            if(s.substr(0, len) == s.substr(len+gap, len)){
                return true;
            }
        }
        for(int i = 2*len+gap; i < n; ++i){
            hfront = roll(hfront, i-len-gap, len);
            hback = roll(hback, i, len);

            if(hfront == hback){
                int frontstart = i-2*len+1-gap, backstart = i-len+1;
                if(s.substr(frontstart, len) == s.substr(backstart, len)){
                    return true;
                }
            }
        }
    }

    return false;
}

void solve(){
    cin >> n >> s;

    pwr[0] = 1;
    for(int i = 1; i <= n/2; ++i) pwr[i] = mul(pwr[i-1], 26);

    int lo = 1;
    int hi = n/2;
    int ans = 0;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        if(works(mid)){
            ans = mid;
            lo = mid+1;
        }
        else hi = mid-1;
    }

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3688
### global variables

$dcache = []

### subroutines

def count_dolls(k, dolls)
  return $dcache[k] if ! $dcache[k].nil?

  dn = dolls.length
  return ($dcache[k] = 0) if (k >= dn)

  h, w = dolls[k]
  max_c = 1

  for i in ((k + 1)...dn)
    hi, wi = dolls[i]
    if hi > h && wi > w
      c = count_dolls(i, dolls) + 1
      max_c = c if max_c < c
    end
  end

  $dcache[k] = max_c
end

### main

while true
  n = gets.strip.to_i
  break if n == 0

  dolls = n.times.map{gets.strip.split(' ').map{|s| s.to_i}}

  m = gets.strip.to_i
  dolls += m.times.map{gets.strip.split(' ').map{|s| s.to_i}}

  dolls.sort!{|a, b| cmp = a[0] <=> b[0]; cmp != 0 ? cmp : a[1] <=> b[1]}
  dn = dolls.length

  $dcache = []

  max_c = 0
  for i in (0...dolls.length)
    c = count_dolls(i, dolls)
    #p "count_dolls(#{i}) = #{c}"

    max_c = c if max_c < c
  end

  puts max_c
end

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

int main(){
	int in[10],out[10];
	int in_num=0;
	int out_num=0;
	int n;
	while(cin >>n){
		if(n == 0){
			in_num--;
			out[out_num] = in[in_num];
			cout << out[out_num]<<endl;
			out_num++;
		}
		else {
			in[in_num] = n;
			in_num++;
		}
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>


using namespace std;

int main() {
    int a,b,c;
    cin >> a;
    cin >> b;
    cin >> c;

    if( (a+b)==c || (a+c)==b || (b+c)==a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> ii;


int main()
{
 int n,m;
 cin >> n >> m;
 ii arr [n];
 for(int i=0;i<n;i++)
 {
    int a,b;
    cin >> a >> b;
    arr[i] = make_pair(a,b);
 }
 sort(arr,arr+n);
 long long ans=0,a=0;
 while(m>0)
 {
     m-=arr[a].second;
     if(m<0) ans+= m*arr[a].first;
     ans+=arr[a].second*arr[a].first;
     
     a++;
 }
 cout << ans;
 return 0;
}

Measured memory_bytes: 1792
A = int(input())
B = int(input())
C = int(input())
X = int(input())

res = 0

for i in range(A+1):
	remain = X - 500 * i
	if i < 0:
		break
	for j in range(B+1):
		rem = X - 500 * i - 100 * j
		if rem < 0:
			break;
		for k in range(C+1):
			r = X - 500 * i - 100 * j - 50 * k
#			print("i:", i, "j:" ,j, "k:", k, "r:", r);
			if r < 0:
				break
			elif r == 0:
				res += 1

print(res)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	int S = 0, T = 0;
	int a, b, c, d;
	int e, f, g, h;

	scanf("%d %d %d %d", &a, &b, &c, &d);
	scanf("%d %d %d %d", &e, &f, &g, &h);

	S = a + b + c + d;
	T = e + f + g + h;

	if (S >= T) {
		printf("%d\n", S);
	}
	else if (S < T) {
		printf("%d\n", T);
	}

	return 0;

	}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
bool pillar[5050][5050];

int main(){
	int a;
	while(cin>>a,a){
		vector<P>v;
		for(int i=0;i<5005;i++)
		for(int j=0;j<5005;j++)pillar[i][j]=false;
		
		for(int i=0;i<a;i++){
			int b,c;
			cin>>b>>c;
			v.push_back(P(b,c));
			pillar[b][c]=true;
			}
			
		int ans=0;	
		
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				if(i==j)continue;
			int dx=v[i].first-v[j].first;
			int dy=v[i].second-v[j].second;
			
			if(dx>=0&&dy>=0){
			if(v[i].first+dy>=0&&v[i].second-dx>=0&&v[i].first+dy<=5002&&v[i].second-dx<=5002){
				if(v[j].first+dy>=0&&v[j].second-dx>=0&&v[j].first+dy<=5002&&v[j].second-dx<=5002){
					if(pillar[v[i].first+dy][v[i].second-dx]){
						if(pillar[v[j].first+dy][v[j].second-dx]){
							/*cout<<v[i].first<<' '<<v[i].second<<endl;
							cout<<v[j].first<<' '<<v[j].second<<endl;
							cout<<v[i].first-dx+dy<<' '<<v[i].second-dx-dy<<endl;
							cout<<v[j].first+dy<<' '<<v[j].second-dx<<endl;*/
							ans=max(ans,((dx*dx)+(dy*dy)));
							}
						}
					}
				}
				
			if(v[i].first-dy>=0&&v[i].second+dx>=0&&v[i].first-dy<=5002&&v[i].second+dx<=5002){
				if(v[j].first-dy>=0&&v[j].second+dx>=0&&v[j].first-dy<=5002&&v[j].second+dx<=5002){
					if(pillar[v[i].first-dy][v[i].second+dx]){
						if(pillar[v[j].first-dy][v[j].second+dx]){
						/*	cout<<v[i].first<<' '<<v[i].second<<endl;
							cout<<v[j].first<<' '<<v[j].second<<endl;
							cout<<v[i].first-dx-dy<<' '<<v[i].second-dx+dy<<endl;
							cout<<v[j].first-dy<<' '<<v[j].second+dx<<endl;*/
							ans=max(ans,((dx*dx)+(dy*dy)));
							}
						}
					}
				}	
			}
			}
		}
				
			cout<<ans<<endl;	
		}
		return 0;
	}

Measured memory_bytes: 27760
def solve():
    MOD = 10**9 + 7

    N = int(input())
    Ss = input().rstrip()

    dp = [1] * N
    for i, S in enumerate(Ss, start=1):
        dp2 = [0] * N
        if S == '<':
            for j in range(N-i):
                dp2[j] = dp2[j-1] + dp[j]
                dp2[j] %= MOD
        else:
            for j in reversed(range(N-i)):
                dp2[j] = dp2[j+1] + dp[j+1]
                dp2[j] %= MOD
        dp = dp2

    print(dp[0])


solve()


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

int main(){
	char game[101];
	cin>>game;
	int m;int n;
	while(game[0]!='0'){
		m=0;n=0;
		for(int i=1;game[i]!='\0';i++){
			if(game[i]=='A'){
				 m++;
			}
			else if(game[i]=='B'){
				n++;
			}
		}
		if(m>n){
			cout<<m+1<<' '<<n<<endl;
		}
		else if(m<n){
			cout<<m<<' '<<n+1<<endl;
		}
		cin>>game;
	}

	return 0;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 50;
typedef long long ll;
int a[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1;i <= n;i++){
        int x;
        cin >> x;
        if(x % 2 && i % 2) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

using namespace std;

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

int MOD = 1e9 + 7;

ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}

int main()
{

	FAST_IO;

	ll n, p;
	string s;
	cin >> n >> p >> s;
	MOD = p;
	if (p == 5 || p == 2) {
        ll ans = 0;
        for(int i = 0; i < n; ++i) {
            if ((s[i] - '0') % p == 0) {
                ans += i+1;
            }
        }
        cout << ans << endl;
        return 0;
    }
	vector<ll> prefix(n + 1);
	ll cnt = 0;
	for (int i = 1; i <= n; ++i) {
		prefix[i] = prefix[i-1] + (s[i - 1] - '0') * modExp(10, n-i);
		prefix[i] %= MOD;
		
	}
	sort(prefix.begin(), prefix.end());
	ll ans = 0;
	for (int i = 0; i <= n;) {
		auto low = lower_bound(prefix.begin(), prefix.end(), prefix[i]);
		auto high = upper_bound(prefix.begin(), prefix.end(), prefix[i]);
		ll k = high - low;
		i += k;
		ans += k * (k - 1) / 2;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 2196
from itertools import product

N,a,b,c = map(int,input().split())

L = list(int(input()) for i in range(N))

products = product(list(range(4)), repeat=N)

ans = float("inf")

for prod in products :
    A = []
    B = []
    C = []
    
    for i in range(len(prod)) :
        if prod[i] == 1 :
            A.append(L[i])
        elif prod[i] == 2 :
            B.append(L[i])
        elif prod[i] == 3 :
            C.append(L[i])
    if len(A) * len(B) * len(C) == 0 :
        continue
    
    cost = 0
    
    for li in [A, B, C] :
        cost += (len(li)-1) * 10
    
    cost += abs(a - sum(A))
    cost += abs(b - sum(B))
    cost += abs(c - sum(C))
    
    ans = min(ans, cost)

print(ans)


Measured memory_bytes: 3064
//C
#include <cassert>
#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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 int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	int N, K;
	cin >> N >> K;
	long long ans = 0;
	for (int i = 0; i < 10000000; i++) {
		if (pow(K, i) > N) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 512
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in a:
    cnt = c
    for j in range(m):
        cnt += i[j] * b[j]
    if cnt > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();
        System.out.print(s1.toUpperCase().charAt(0));
        System.out.print(s2.toUpperCase().charAt(0));
        System.out.print(s3.toUpperCase().charAt(0));
        System.out.println();
    }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;

int main() {
    string s;
    cin>>s;
    if(s=="RRR"){
        cout<<3<<endl;
    } else if(s.find("RR")!=string::npos){
        cout<<2<<endl;
    } else if(s.find("R")!=string::npos){
        cout<<1<<endl;
    } else {
        cout<<0<<endl;
    }
}



Measured memory_bytes: 3624
#include <ctime>
#include <vector>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
int bt6[8] = { 0, 1, 2, 3, 5, 7, 11, 15 };
int n, c, a[109]; bool choose[109], chosen[109], slc[109];
inline long long val(int pos) {
	return chosen[pos] ? 0 : a[pos];
}
long long dfs(int pos, long long sum) {
	if (pos > c) {
		for (int i = 1; i <= n; i++) chosen[i] = false, slc[i] = false;
		for (int i = 1; i <= n; i++) {
			if (choose[i]) {
				for (int j = i; j <= n; j += i) chosen[j] = true;
			}
		}
		// 6m which 2m > c
		long long res = sum;
		for (int i = c / 2 + 1; 6 * i <= n; i++) {
			long long rm = 0;
			for (int j = 0; j < 8; j++) {
				long long cur = 0;
				if (bt6[j] & 1) cur += val(2 * i);
				if (bt6[j] & 2) cur += val(3 * i);
				if (bt6[j] & 4) cur += val(4 * i);
				if (bt6[j] & 8) cur += val(6 * i);
				rm = max(rm, cur);
			}
			res += rm;
			slc[2 * i] = true;
			slc[3 * i] = true;
			slc[4 * i] = true;
			slc[6 * i] = true;
		}
		// 3m which m > c
		for (int i = c + 1; 3 * i <= n; i++) {
			if (!slc[i]) {
				res += max({ 0LL, val(i) + val(3 * i), val(i) + val(2 * i), val(i), val(i) + val(2 * i) + val(3 * i) });
				slc[i] = true;
				slc[2 * i] = true;
				slc[3 * i] = true;
			}
		}
		// 2m which m > c
		for (int i = c + 1; 2 * i <= n; i++) {
			if (!slc[i]) {
				res += max({ 0LL, val(i), val(i) + val(2 * i) });
				slc[i] = true;
				slc[2 * i] = true;
			}
		}
		// normal numbers
		for (int i = c + 1; i <= n; i++) {
			if (!slc[i]) res += max(0LL, val(i));
		}
		return res;
	}
	bool flag = false;
	for (int i = 1; i < pos; i++) {
		if (pos % i == 0 && choose[i]) flag = true;
	}
	choose[pos] = true;
	long long ret = dfs(pos + 1, sum);
	choose[pos] = false;
	if (!flag) {
		ret = max(ret, dfs(pos + 1, sum + a[pos]));
	}
	return ret;
}
long long brute_force() {
	long long ret = 0;
	for (int i = 0; i < 1 << n; i++) {
		long long res = 0;
		for (int j = 1; j <= n; j++) {
			bool flag = false;
			for (int k = 1; k <= j; k++) {
				if (j % k == 0 && (i & (1 << (k - 1)))) flag = true;
			}
			if (!flag) res += a[j];
		}
		ret = max(ret, res);
	}
	return ret;
}
long long rand_gen() {
	long long val = rand() * 1234567891LL + rand() * 234567LL + rand();
	return val;
}
int case_cnt;
void testing(int val_n) {
	for(int rep = 0; rep < 1000; rep++) {
		n = val_n; c = n / 4;
		for (int i = 1; i <= n; i++) a[i] = rand_gen() % 2000000001 - 1000000000;
		long long ret = dfs(1, 0);
		long long correct = brute_force();
		cout << "Case #" << ++case_cnt << endl;
		cout << "a: [";
		for (int i = 1; i <= n; i++) {
			if (i >= 2) cout << ", ";
			cout << a[i];
		}
		cout << "]" << endl;
		cout << "Returns: " << ret << endl;
		cout << "Correct Answer:" << correct << endl;
		if (ret != correct) {
			cout << "!!! WRONG ANSWER !!!" << endl;
			dfs(1, 0);
			assert(false);
		}
	}
}
int main() {
	/*
	srand((unsigned)time(NULL));
	for (int i = 1; i <= 20; i++) {
		testing(i);
	}
	*/
	cin >> n; c = n / 4;
	for (int i = 1; i <= n; i++) cin >> a[i];
	long long ret = dfs(1, 0);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include <set>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

struct load{
  pair<int, int> pos1;
  pair<int, int> pos2;
  int cost2;
  load(){}
};

vector< pair<int, bool> > g[10000];
pair<int, int> pos[10000];
vector<load> loads;

bool operator < (const load &lhs, const load &rhs){
  return lhs.cost2 < rhs.cost2;
}

inline int dbl(int x){ return x * x; }
int dist(int i, int j){
  return dbl(pos[i].first - pos[j].first)
    + dbl(pos[i].second - pos[j].second);
}

load createLoad(int i, int j){
  load ret;
  ret.pos1.first  = i;
  ret.pos1.second = g[i].size();
  g[i].push_back(make_pair(j, true));

  ret.pos2.first  = j;
  ret.pos2.second = g[j].size();
  g[j].push_back(make_pair(i, true));

  ret.cost2 = dist(i, j);
  return ret;
}

int n;
int m;

bool memo[10000];

bool check(int pos, int start){
  if(pos == start) return true;
  memo[pos] = true;
  REP(i, g[pos].size()) if(g[pos][i].second){
    int dst = g[pos][i].first;
    if(!memo[dst] && check(dst, start)) return true;
  }
  return false;
}

int main(){
  double ans = 0.0;

  n = getInt();
  m = getInt();

  loads = vector<load>(m);

  REP(i,n){
    pos[i].first  = getInt();
    pos[i].second = getInt();
  }

  REP(i,m){
    int a = getInt();
    int b = getInt();
    loads[i] = createLoad(a - 1, b - 1);
  }

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

  REP(i,m){
    int a = loads[i].pos1.first;
    int b = loads[i].pos2.first;
    memset(memo, 0, sizeof(memo));
    g[a][loads[i].pos1.second].second = false;
    g[b][loads[i].pos2.second].second = false;
    if(check(b, a)){
      ans += sqrt(loads[i].cost2);
    }else{
      g[a][loads[i].pos1.second].second = true;
      g[b][loads[i].pos2.second].second = true;
    }
  }

  printf("%.5f\n", ans);

  return 0;
}

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

int main(void) {

	int a[100];
	int n,i;
	int flag=0;


	i=0;

	scanf("%d",&n);

	while(i<n){
	scanf("%d",&a[i]);


	if(a[i]%2==0){

		if(a[i]%3!=0 && a[i]%5!=0){
			flag=1;
			printf("DENIED");
			break;
		}

	}
	i++;
	}


	if(flag==0){
		printf("APPROVED");
	}

	return 0;
}



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

double d(double x0, double y0, double x1, double y1) {
  return sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
}

int main() {
  int n;
  cin >> n;
  vector<double> x(n), y(n);
  for(int i = 0; i < n; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  
  double all = 0;
  
  for(int i = 0; i < n - 1; i++) {
    for(int j = i + 1; j < n; j++) {
      all += d(x.at(i), y.at(i), x.at(j), y.at(j));
    }
  }
  
  printf("%.10lf\n", 2 * all / n);
}

Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    a, b = map(int, args[0].split())
    ret = -1
    if a < 10 and b < 10:
        ret = a*b

    return str(ret)


if __name__ == "__main__":
    print(solve(*[input() for _ in range(1)]))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=100005;
const ll inf=(1e15);
int n,k;
ll h[maxn],dp[maxn];
int main()
{
    //ios_base::sync_with_stdio(0),cin.tie(0);
    while(cin>>n>>k)
    {
        dp[1]=0;
        for(int i=1;i<=n;i++) cin>>h[i];
        for(int i=2;i<=n;i++)
        {
            dp[i]=inf;
            for(int j=i-1;j>=1&&i-j<=k;j--) dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
        }
        cout<<dp[n]<<"\n";
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main () {
  vector<int> data(3, 0);
  for (int i= 0; i < 3; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  int result = (data.at(0) * data.at(1))/2;
  cout << result << endl;
  return 0;
}

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

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 10000000;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem1166 : Amazing Mazes **/
bool wall[30][30][4];
int vis[30][30];
int W, H;

int solve()
{
	queue<P> Q;
	Q.push(P(0,0));
	vis[0][0]=1;
	
	while (Q.size()) {
		P p = Q.front(); Q.pop();
		
		rep(i, 4) {
			int nx = p.first+dx[i], ny = p.second+dy[i];
			if_range(nx, ny, W, H) {
				if (vis[nx][ny]==0) {
					if (!wall[p.first][p.second][i]) {
						Q.push(P(nx, ny));
						vis[nx][ny]=vis[p.first][p.second]+1;
					}
				}
			}
		}
	}
	
	return vis[W-1][H-1];
}

int main() {
	while (cin>>W>>H, W||H) {
		fill(wall[0][0], wall[0][0]+4*30*30, false);
		fill(vis[0], vis[0]+30*30, 0);
		
		rep(i, 2*H-1) {
			if (i%2==0) {
				rep(j, W-1) {
					int a; cin>>a;
					if (a) {
						wall[j][i/2][2]=true;
						wall[j+1][i/2][0]=true;
					}
				}
			} else {
				rep(j, W) {
					int a; cin>>a;
					if (a) {
						wall[j][i/2][3]=true;
						wall[j][i/2+1][1]=true;
					}
				}
			}
		}
		cout << solve() << endl;
	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
vector<vector<int>> G;
int dfs(int v,int p=-1){
	int x = 0;
	for(int u:G[v]) if(u!=p) x^=dfs(u,v);
	return x+1;
}
int main(){
	cin>>N;
	G.resize(N);
	rep(i,N-1){
		int x,y;
		cin>>x>>y;
		x--,y--;
		G[x].pb(y);
		G[y].pb(x);
	}
	if(dfs(0)!=1) puts("Alice");
	else puts("Bob");
}


Measured memory_bytes: 10368
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
h=lnii()

ans=0
t_ans=0
for i in range(n-1):
  if h[i]>=h[i+1]:
    t_ans+=1
  else:
    ans=max(ans,t_ans)
    t_ans=0

print(max(ans,t_ans))

Measured memory_bytes: 20648
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

const int N = 1e6+7;
int a[N], mx[N];
 
ll power(ll a, ll b, ll m) {
	ll ans = 1;
	while (b) {
		if (b & 1) ans = (ans*a)%m;
		a = (a*a)%m;
		b >>= 1;
	}
	return ans;
}
 
int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for (int i=1; i<=n; i++)
	{
        cin>>a[i];
        int x = a[i];
        for (int i=2;i*i<=x;i++) 
		{
            if (x%i)    
				continue;
            int cnt = 0;
            while (x%i==0)
			{
        		x/=i; 
				cnt++;
			}  
            mx[i]=max(mx[i],cnt);
        }
        if (x>1)  
			mx[x]=max(mx[x], 1);
    }
    long long lcm = 1;
    for (int i=1; i<N; i++) 
	{
        if (mx[i] == 0) 
			continue;
        lcm =(lcm*power(i,mx[i],MOD))%MOD;
    }
    long long ans = 0;
    for (int i=1; i<=n; i++)
	{
        ans=(ans + lcm*power(a[i],MOD-2,MOD))%MOD;
    }        
    cout<<ans<<endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
ll s=0,i,l;
char n[2000010];
cin>>n;
l=strlen(n);
for(i=0;i<l;i++)
{
	s=s+n[i]-48;
}
 
 
 
if(s%9==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}

Measured memory_bytes: 3784
book = {}
while True:
    try:
        w, n = input().split()
        w = str(w).lower()
        n = int(n)
        if (w not in book.keys()):
            book[w] = [n]
        else:
            book[w] += [n]
    
    except EOFError:
        break
    
W = []
for w, nlist in book.items():
    nlist.sort()
    W.append(w)
W.sort()
for w in W:
    print(w)
    print(*book[w])



Measured memory_bytes: 5612
N,Y = map(int,input().split())
flag = False
ans = ""
for x in range(N + 1):
  if flag:
    break
  for y in range(N + 1):
    if x + y > N or flag:
      break
    if x*10000+y*5000+(N-x-y)*1000 == Y:
      ans = str(x) + " " + str(y) + " " + str(N-x-y)
      flag = True
if flag:
  print(ans)
else:
  print("-1 -1 -1")

Measured memory_bytes: 3064
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int[] d;
	private int[] f;
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}
			adjList.add(tmp);
		}
		in.close();
	}
	
	public int DFS(int v, int t) {
		d[v] = t;
		LinkedList<Integer> nb = adjList.get(v);
		Iterator<Integer> it = nb.iterator();
		while(it.hasNext()) {
			int w = it.next();
			if(d[w] == -1) {
				t ++; 
				t = DFS(w, t);
			}
		}
		f[v] = t + 1;
		return t + 1;
	}
	
	
	
	public void timeStamp() {
		String out = "";
		d = new int[totalVertex];
		f = new int[totalVertex];
		for (int v = 0; v < totalVertex; v++) {
			d[v] = -1;
		}
		int t = 0;
		for(int v = 0; v < totalVertex; v++) {
			if (d[v] == -1) {
				t = DFS(v,t);
				t++;
			}
		}
		for(int v = 0; v < totalVertex; v++) {
			out += (v + 1) + " " + (d[v] + 1) + " " +( f[v] + 1);
			if (totalVertex-1 != v) {
				out += '\n';
			}
		}
		System.out.println(out);
	}
}

public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.timeStamp();
	}
}


Measured memory_bytes: 28872
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int n, m;
    cin >> n >> m;

    Int ans;
    if (n != 1 && m != 1) {
        ans = (n - 2) * (m - 2);
    } else if (n == 1 && m == 1) {
        ans = 1;
    } else {
        ans = max(n, m) - 2;
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
#define endl "\n";
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define POSITIVE_INFINITY 9223372036854775807
#define NEGATIVE_INFINITY -9223372036854775807
#define MOD 1000000007
const int N = 105;
int n, a, b;
int ar[N + 5];

int main()
{
  FASTER;
  cin >> n;
  cin >> a >> b;

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

  for (int i = 0; i < n; i++){
    if (ar[i] <= a)
      x++;
    if (ar[i] >= a + 1 && ar[i] <= b)
      y++;
    if (ar[i] >= b + 1)
      z++;
  }
  cout << (int) min(x, min(y, z)) << endl;
  return 0;
}


Measured memory_bytes: 256
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 c[] = new int[n];
		int sum = 0;
		int counter = 0;

		for(int i = 0; i < m; i++) {
			int p = sc.nextInt()-1;
			String s = sc.next();

			if(c[p] != -1) {
				if(s.equals("WA")) {
					c[p]++;
				}else {
					sum += c[p];
					counter++;
					c[p] = -1;
				}
			}
		}


		System.out.println(counter + " " + sum);
        return;
    }

}



Measured memory_bytes: 64132