akhauriyash/Code-Regression huggingface dataset:
#![allow(dead_code, unused_variables)]
use proconio::{fastout, input};
use proconio::marker::Chars;
use std::ops::*;
use std::mem::swap;
use std::fmt;

const MOD:usize = 1000000007;

#[fastout]
fn main() {
    input! {
        h:usize,
        w:usize,
        b : [Chars;h],
    }

    let mut dp :Vec<Vec<Modint>>= vec![vec![0.into();w];h];
    dp[0][0] = 1.into();
    for i in 0..h{
        for j in 0..w{
            if b[i][j] == '#'{
                continue;
            }

            if i == 0 && j == 0{
                continue
            }else if i == 0{
                dp[i][j] = dp[i][j-1];
            }else if j == 0{
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = dp[i][j-1] + dp[i-1][j];
            }
        }
    }
    println!("{}",dp[h-1][w-1]);
}

#[derive(Copy,Clone)]
struct Modint{
    val : usize,
}

impl Modint{
    pub fn new(val : usize) -> Self{
        Modint{
            val : val%MOD,
        }
    }

    fn inv(&self) -> Self{
        let mut x : i32= 1;
        let mut u : i32= 0;
        let mut s : i32= self.val as i32;
        let mut t : i32= MOD as i32;

        while t != 0{
            let k = s/t;
            s -= k * t;
            swap(&mut s,&mut t);
            x -= k * t;
            swap(&mut x, &mut u);
        }
        x %= MOD as i32;
        if x < 0{
            x += MOD as i32;
        }
        
        let x = x as usize;
        Modint{
            val : x,
        }
    }
}

impl Add for Modint{
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        Self {
            val : (self.val + rhs.val) % MOD,
        }
    }
}

impl AddAssign for Modint {
    fn add_assign(&mut self, rhs: Modint) {
        *self = *self + rhs;
    }
}

impl Sub for Modint{
    type Output = Self;

    fn sub(self, other: Self) -> Self {
        Self {
            val :(MOD + self.val - other.val) % MOD,
        }
    }
}

impl SubAssign for Modint {
    fn sub_assign(&mut self, rhs: Modint) {
        *self = *self - rhs;
    }
}

impl Mul for Modint {
    type Output = Modint;

    fn mul(self, rhs: Modint) -> Self {
        Modint{
            val : (self.val * rhs.val) % MOD,
        }
    }
}

impl MulAssign for Modint {
    fn mul_assign(&mut self, rhs: Modint) {
        *self = *self * rhs;
    }
}

impl Div for Modint {
    type Output = Modint;

    fn div(self, rhs: Modint) -> Self {
        Modint{
            val : (self.val * rhs.inv().val) % MOD,
        }
    }
}

impl DivAssign for Modint {
    fn div_assign(&mut self, rhs: Modint) {
        *self = *self / rhs;
    }
}

impl From<i32> for Modint{
    fn from(x : i32) -> Self {
        let mut tmp = x;
        while tmp < 0{
            tmp += MOD as i32;
        }
        let res = Modint::new(tmp as usize);
        res
    }
}

impl From<usize> for Modint{
    fn from(x : usize) -> Self {
        let res = Modint::new(x);
        res
    }
}

impl fmt::Display for Modint{
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.val)
    }
}

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

int calc(int x) {
    int ret = 0;
    while (x % 100 == 0) {
        x /= 100;
        ++ret;
    }
    return ret;
}
int main() {
    int D, N;
    cin >> D >> N;
    int cnt = 0, val = 0;
    while (cnt < N) {
        ++val;
        if (calc(val) == D)
            ++cnt;
    }
    cout << val << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,m) for(int j=0;j<m;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef vector<pair<ll ,ll> >vepa;
typedef set<char>se;
typedef map<ll,ll> mpp;
const ll N=1e7 ,OO=1e9+5;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,ans,sum,l,r,a,arr[N];
bool f,vis[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
        cin>>l>>r>>n;
        for(int i=1 ; i<=100 ; i++)
          vis[n*i]=1;
        for(int i=l ; i<=r ; i++)
            if(vis[i])
             ans++;
        cout<<ans;
go;
}


Measured memory_bytes: 3628
program main
  implicit none
  integer :: n, i, cnt = 0
  integer(8), allocatable :: a(:)

  read *, n
  allocate (a(n))
  read *, a

  do i = 1, n
    if (a(i) < 0) then
      cnt = cnt + 1
      a(i) = -a(i)
    end if
  end do
  if (mod(cnt, 2) == 0) then
    print '(i0)', sum(a)
  else
    print '(i0)', sum(a) - 2 * minval(a)
  end if
end program

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N; cin >> N;
  vector<int> D(N);
  for (auto& d : D) { cin >> d; }
  int M; cin >> M;
  vector<int> T(M);
  for (auto& t : T) { cin >> t; }

  multiset<int> s{D.begin(), D.end()};
  for (const auto& t : T) {
    auto itr = s.find(t);
    if (itr == s.end()) {
      cout << "NO" << CRLF;
      return;
    } else {
      s.erase(itr);
    }
  }
  cout << "YES" << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 11264
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int Com(int n, int k) {
	int x=1, y=1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

int imos[100005];

signed main() {
	int n, m;
	int ans = 0;
	cin >> n >> m;
	vector<P>p[35];
	rep(i, n) {
		int a, b, c;
		cin >> a >> b >> c;
		c--;
		p[c].push_back({ a,b });
	}
	rep(i, m) sort(p[i].begin(), p[i].end());
	rep(i, m) {
		bool cnt = false;
		rep(j, p[i].size()) {
			if (!cnt) {
				imos[p[i][j].first]++;
				if (j == p[i].size() - 1) imos[p[i][j].second + 1]--;
				else if (p[i][j].second == p[i][j + 1].first) {
					cnt = true;
				}
				else {
					imos[p[i][j].second + 1]--;
				}
			}
			else {
				if (j == p[i].size() - 1) imos[p[i][j].second + 1]--;
				else if (p[i][j].second != p[i][j + 1].first) {
					cnt = false;
					imos[p[i][j].second + 1]--;
				}
			}
		}
	}
	for (int i = 1; i <= 100001; i++) {
		imos[i] += imos[i - 1];
	}
	for (int i = 0; i <= 100001; i++) {
		ans = max(ans, imos[i]);
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
  int N,L;
  cin >> N >> L;
  string S[N], ans;
  for(int i; i<N; i++){
    cin >> S[i];
  }
  
  sort(S,S+N);
  for(int i; i<N; i++){
    ans += S[i];
  }
    
  cout << ans;  
}
    

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for(int i = 0;i < N;i++) {
    cin >> V.at(i);
  }
  for(int j = 0;j < N;j++) {
    cin >> C.at(j);
  }
  vector<int> vec(N);
  for(int k = 0;k < N;k++) {
    vec.at(k) = V.at(k) - C.at(k);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int answer = 0;
  for(int l = 0;l < N;l++) {
     if(vec.at(l) < 0) {
       break;
     }
    answer = answer + vec.at(l);
  }
  cout << answer << endl;
}
  

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub struct WeightedGraph {
    graph: Vec<Vec<(usize, i64)>>,
    v: usize,
}

type WeightedEdge = (usize, usize, i64);
impl WeightedGraph {
    const INF: i64 = 1 << 60;

    pub fn new(edges: &[WeightedEdge], v: usize) -> Self {
        let mut graph = vec![Vec::new(); v];
        for &(u, v, w) in edges {
            graph[u].push((v, w));
            graph[v].push((u, w));
        }
        Self { graph, v }
    }

    pub fn warshall_floyd(&self) -> Vec<Vec<Option<i64>>> {
        let inf = Self::INF;
        let v = self.v;
        let mut cost = vec![vec![inf; v]; v];
        for u in 0..v {
            for &(v, w) in &self.graph[u] {
                cost[u][v] = w;
            }
        }
        for i in 0..v {
            cost[i][i] = 0;
        }
        for k in 0..v {
            for i in 0..v {
                for j in 0..v {
                    cost[i][j] = std::cmp::min(cost[i][j], cost[i][k] + cost[k][j]);
                }
            }
        }
        cost.into_iter()
            .map(|v| self.optionalize(v))
            .collect::<Vec<_>>()
    }

    fn optionalize(&self, v: Vec<i64>) -> Vec<Option<i64>> {
        v.into_iter()
            .map(|x| if x == Self::INF { None } else { Some(x) })
            .collect::<Vec<_>>()
    }
}

fn solve() {
    input! {
        n: usize, m: usize, l: i64,
        edges: [(Usize1, Usize1, i64); m],
        q: usize,
        queries: [(Usize1, Usize1); q]
    };

    let graph = WeightedGraph::new(&edges, n);
    let d = graph.warshall_floyd();
    let edges = (0..n)
        .combinations(2)
        .flat_map(|v| {
            let u = v[0];
            let v = v[1];
            if let Some(c) = d[u][v] {
                if c <= l {
                    return Some((u, v, 1));
                }
            }
            None
        })
        .collect::<Vec<_>>();
    let graph = WeightedGraph::new(&edges, n);
    let d = graph.warshall_floyd();
    for (s, t) in queries {
        let res = if let Some(c) = d[s][t] { c - 1 } else { -1 };
        println!("{}", res);
    }
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 13676
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  string s,t;
  cin >> s >> t;
  ll sum = 0;
  rep(i,s.size()){
    if(s.at(i) == t.at(i)){
      sum ++;
    }
  }
  cout << s.size()-sum << endl;
  return 0;
}

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

using ll = long long;

int main() {
    int N;
    cin >> N;
    rep(i, 9) rep(j, 9)
    if ((i + 1) * (j + 1) == N) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
def main():
    W, H, x, y, r = map(int, input().split())

    x1 = x - r
    x2 = x + r
    y1 = y - r
    y2 = y + r
    if 0 <= x1 <= W and \
            0 <= x2 <= W and \
            0 <= y1 <= H and \
            0 <= y2 <= H:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define dd double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl '\n'
#define MAX 1e18

int n;
int a[401];
int dp[401][401];

int csum(int s,int e){
	int sum=0;
	loop(i,s,e){
		sum+=a[i];
	}
	return sum;
}


int solve(int i,int j){
	if(i>=j){
		return 0;
	}

	if(dp[i][j]!=-1) return dp[i][j];

	int mini=MAX;
	for(int k=i;k<=j-1;k++){
		int temp = solve(i,k)+solve(k+1,j)+csum(i,k)+csum(k+1,j);
		mini=min(mini,temp);
	}

	return dp[i][j]=mini;
}

signed main() {

	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	cin >> n;
	for0(i,n)cin>>a[i];

	memset(dp,-1,sizeof(dp));

	cout<<solve(0,n-1);

	return 0;
}

Measured memory_bytes: 4956
m, d = map(int, input().split())
result = 0
for j in range(m):
    mj = j+1
    for i in range(10, d+1, 1):
        d1 = int(i / 10)
        d10 = i % 10
        if d1 >= 2 and d10 >= 2:
            if d1 * d10 == mj:
                #print(d10,d1,mj)
                result += 1
print(result)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int t = sc.nextInt();
        int s = sc.nextInt();
        double x = ((double)d)/((double)s);

        if(x <= t){
        System.out.println("Yes");
        }else{
        System.out.println("No");
        }
    }
}

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

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

    for (int i = 0; i < S.length(); ++i)
    {
        if (S[i] == T[i])
        {
            continue;
        }

        char c1 = S[i];
        char c2 = T[i];

        for (int j = 0; j < S.length(); ++j)
        {
            bool changed = false;
            if (S[j] == c1)
            {
                S[j] = c2;
                changed = true;
            }
            else if (S[j] == c2)
            {
                S[j] = c1;
                changed = true;
            }

            if (changed && j < i)
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] number = s.Split(' ');
            int a = int.Parse(number[0]);
            int b = int.Parse(number[1]);
            int k = 0;

            if ((a + b) % 2 == 0)
            {
                k = (a + b) / 2;
                Console.WriteLine(k);
            }
            else
            {
                Console.WriteLine("IMPOSSIBLE");
            }

        }
    }
}


Measured memory_bytes: 11092
//Created by: Aditya Singh
//Bleed Blue
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define unm unordered_map<int,int>
#define pb emplace_back
#define nt _int128
#define PI 3.1415926535897932384626433
#define inf 1e18

const int N = 100005;

int dp[N][105], ar[N][2], n, m;

int solve(int i, int wt)
{
    if (i == n)
        return 0;
    if (dp[wt][i] != -1)
        return dp[wt][i];
    int x = 0;
    if (wt + ar[i][0] <= m)
        x = ar[i][1] + solve(i + 1, wt + ar[i][0]);
    int y = solve(i + 1, wt);
    return dp[wt][i] = max(x, y);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t;cin>>t;while(t--)
    {
        int i, j, k, ans = 0, cnt = 0, sum = 0;
        cin >> n >> m;
        for (i = 0; i < m + 2; i++)
            for (j = 0; j < n + 2; j++)
                dp[i][j] = -1;
        for (i = 0; i < n; i++)
            cin >> ar[i][0] >> ar[i][1];
        cout << solve(0, 0);
    }
    return 0;
}

Measured memory_bytes: 85512
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<string>
#include<string.h>
#include<stdio.h>
#include <vector>
#include <map>


int main()
{
   long long int a,b,x;
   cin >> a >> b >> x;
   if(a%x == 0)
   {
     cout << (b/x - a/x) +1;

   }
   else
   {
       cout << (b/x - a/x) << endl;
   }



}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s,t;
    int coun=0;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            coun++;
        }
    }
    cout<<coun<<endl;
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n, m; cin >> n >> m;
  vector<int> v(10,-1);
  for(int i = 0; i < m; ++i){
    int x,y; cin >> x >> y;
    if(v[x] != -1 && v[x] != y){
      cout << -1 << endl;
      return 0;
    }
    v[x] = y;
  }
  if(n != 1 && v[1] == 0){
      cout << -1 << endl;
      return 0;
  }
  for(int i = 0; i < n; ++i){
    if(v[i+1] == -1){
      if(n > 1 && i == 0)cout << 1;
      else cout << 0;
    }
    else cout << v[i+1];
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

n,k=get_i
n_bit=n.to_s(2).split("").reverse
ans=1
MOD=10**9+7
n_bit.each do|b|
  if b=="1"
      ans*=k
      ans%=MOD
  end 
  k*=k
  k%=MOD
end
puts ans


Measured memory_bytes: 8904
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

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

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

    lint K = 30;
    vector<vector<lint>> V(K);

    REP(i, K) {
      V[i] = vector<lint>();
    }
    

    REP(i, N) {
      lint a; cin >> a;

      REP(j, K) {
        if (a & (1<<j)) {
          V[j].push_back(a);
          break;
        }
      }
    }

    lint res = 0;

    REP(j, K) {
      vector<lint> v(K, 0);
      sort(V[j].begin(), V[j].end(), greater<lint>());

      map<lint, lint> cnt_list;
      REP(i, V[j].size()) {
        cnt_list[V[j][i]]++;
      }
      
      REP(i, V[j].size()) {
        lint a = V[j][i];
        if (cnt_list[a] == 0) continue;

        lint max_bit = -1;
        lint copy_a = a;
        while(copy_a > 0) {
          max_bit++;
          copy_a = copy_a>>1;
        }

        lint mask = 1<<j;
        
        FOR(bit, j, max_bit+1) {
          if(!(a & 1<<bit)) {
            mask += 1<<bit;
          }
        }


        if(mask == a) {
          if(cnt_list[mask] >= 2) {
            cnt_list[mask]--;
            cnt_list[a]--;
            res += 1;
          }
        }
        else {
          if(cnt_list[mask] > 0) {
            cnt_list[mask]--;
            cnt_list[a]--;
            res += 1;
          }
        }          

      }

    }

    PRINT(res);
    return 0;
}



Measured memory_bytes: 14456
import math

a, b, h, m = map(int, input().split())

omg_s = math.pi / 360
omg_l = math.pi / 30

tht = (60*h + m)*omg_s - m*omg_l

c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(tht))
print(c)

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

signed main(){
  int N;cin >> N;
  string S;cin >> S;
  int r = 0, g = 0, b = 0;
  for(int i = 0;i < S.length();i++){
    if(S[i] == 'R')r++;
    else if(S[i] == 'G')g++;
    else b++;
  }
  int hoge = 0;
  rep(i,N)rep(j,N){
    if(S[i] != S[j])if((i+j)%2 == 0 && S[i] != S[(i+j)/2] && S[j] != S[(i+j)/2]){hoge++;}
  }
  cout << r * g * b - hoge/2;
}



Measured memory_bytes: 3556
local n=io.read("n","l")
local s=io.read()

local t={}
for i=1,n do
    local a=s:sub(i,i)
    if not t[a] then
        t[a]=1
    else
        t[a]=t[a]+1
    end
end

local combination=1
for _,frequency in pairs(t) do
    combination=combination*(frequency+1)%1000000007
end
print(combination-1)

Measured memory_bytes: 1132
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 100005

ll fastpower (ll b , ll p){
    ll k= p%2 ? b : 1 ;
    return p==0 ? 1 : k*(fastpower(b*b,p/2));
}

vector<ll> adj[maxn];
ll visited[maxn],dist[maxn],indegree[maxn];


void dfs(ll u){
    visited[u]=true;
    for(auto v:adj[u]){
        if(!visited[v]){
            dist[v]=max(dist[u]+1,dist[v]);
            indegree[v]--;
            if(indegree[v]==0) dfs(v);
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        adj[u].push_back(v);
        indegree[v]++;
    }
    for(int i=1;i<=n;i++){
        if(!visited[i] && indegree[i]==0) dfs(i);
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dist[i]);
    }
    cout<<ans<<"\n";
}

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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9+7;

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}

int dfs(int x, const vector<vi>& edges){
  static vi dp(100000, -1);
  if(dp[x] != -1){
    //cout << "hit:" << x << endl;
    return dp[x];
  }
  //cout << "calc:" << x << endl;

  int ans = 0;
  for (auto i : edges[x]) ans = max(ans, 1 + dfs(i, edges));
  dp[x] = ans;
  return dp[x];
}

void solve(){
  int n, m;
  cin >> n >> m;
  vector<vi> edges(n);

  rep(i, m){
    int x, y;
    cin >> x >> y;
    x--; y--;
    edges[x].emplace_back(y);
  }

  int ans = 0;
  rep(i, n) ans = max(ans, dfs(i, edges));
  cout << ans << endl;
}

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

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
        B[i] = A[i];
    }

    vector<int> ans;
    for(int i=0; i<N-1; i++){
        ans.push_back(1);
        rotate(A.begin(), A.begin()+1, A.end());
        for(int j=0; j<N-1; j++){
            if(A[0] < A.back()){
                ans.push_back(N-1);
                swap(A[0], A.back());
            }
            ans.push_back(1);
            rotate(A.begin(), A.begin()+1, A.end());
        }
    }

    cout << ans.size() << endl;
    for(int a : ans) cout << a << endl;

    // for(int a : ans){
    //     for(int i=a; i<N; i++) swap(B[i], B[i-a]);
    // }
    // for(int i=0; i<N; i++) cerr << B[i] << " ";
    return 0;
}


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

int n, m;
string s, t;
map <string, int> mp;

const int INF = 1000000000;

int main() {
	cin >> n;
	rep (i, n) {
		cin >> s;
		mp[s]++;
	}
	cin >> m;
	rep (i, m) {
		cin >> t;
		mp[t]--;
	}
	int ans  = 0;
	for (auto& i : mp) ans = max(ans, i.second);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,c,x,y = gets.chomp.split(" ").map(&:to_i)

min_sum = Float::INFINITY
max = x > y ? x : y
(0..max).each do |i|
  sum = c * i * 2
  if x - i > 0 then
    sum += a * (x - i)
  end
  if y - i > 0
    sum += b * (y - i)
  end
  min_sum = sum if sum < min_sum
end

puts min_sum



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

typedef long long ll;

#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back

const long double PI = acos(-1);

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll GetDigit(ll num) {return log10(num)+1;}

int main(){
  ll n, k;
  cin >> n >> k;

  ll digit = 0;
  while(n != 0){
    n = n / k;
    digit++;
  }
  cout << digit << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int A, B, H, M;
    double ans;
    cin >> A >> B >> H >> M;
    double Hdeg = 0.5 * H * 60.0 + 0.5 * M;
    double Mdeg = 6.0 * M;
    //cout << Hdeg << Mdeg << endl;
    double Deg = Hdeg - Mdeg;
    if ( Deg >= 180 ) Deg = 360 - Deg;
    //cout << Deg << endl;
    Deg = Deg / 360 * 2 * M_PI;
    ans = B * B + A * A - 2.0 * A * B * cos(Deg);
    ans = sqrt(ans);
    printf("%10.10e\n",ans);
    return 0;
}

Measured memory_bytes: 4132
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    int a, b, h;
    cin >> a >> b >> h;
    o((a + b) * h / 2);
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int dp[2][5001];

int main(){
  int n,in;

  scanf("%d",&n);

  for(int i=0;i<=n/2;i++)
    dp[0][i]=dp[1][i]=2000000000;

  dp[0][0]=0;

  for(int i=1;i<=n;i++){
    scanf("%d",&in);
    for(int j=n/2-1;j>=0;j--){
      dp[1][j+1]=dp[1][j];
    }
    dp[1][0]=2000000000;
    for(int j=0;j<=n/2;j++){
      dp[0][j]=min(dp[1][j]+in,dp[0][j]);
      dp[1][j]=min(dp[0][j]+in,dp[1][j]);
    }
  }

  printf("%d\n",min(dp[0][n/2],dp[1][n/2]));

  return 0;
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n, ans=1, tmp, mi;

	cin>> n;

	cin >> mi;

	for (int i = 1;i < n;i++) {
		cin >> tmp;
		if (tmp < mi) {
			mi = tmp;
			ans++;
		}
	}

	cout<< ans << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <climits>
#include <map>
#include <math.h>
using namespace std;

int main(void)
{
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;

    for (int i = 0; cin >> ch; i++)
    {
        if (ch == '\\')
        {
            S1.push(i);
        }
        else if (ch == '/' && S1.size() > 0)
        {
            int j = S1.top();
            S1.pop();
            sum += i - j;
            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j)
            {
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
    vector<int> ans;
    while (S2.size() > 0)
    {
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++)
    {
        cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;

ll power(ll base,ll n,ll p)
{
    ll r=1;
    while(n)
    {
        if(n%2) r=r*base%p;
        base=base*base%p;
        n/=2;
    }
    return r;
}

int cal(ll x)
{
    int cnt=0;
    for(int i=0;i<=60;i++)
        if((x>>i)&1)
        cnt++;
    return cnt;
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int k=0;
    int cnt=0;
    for(auto &v:s)
    {
        int x=v-'0';
        if(x)
            cnt++;
    }
    ll sum1=0;
    ll sum22=0;
    for(int i=n-1;i>=0;i--)
    {
        int x=s[i]-'0';
        if(x)
        sum1+=power(2,k,cnt+1);
        k++;
    }
    if(cnt-1!=0)
    {
        k=0;
        for(int i=n-1;i>=0;i--)
        {
            int x=s[i]-'0';
            if(x)
            sum22+=power(2,k,cnt-1);
            k++;
        }
    }
    k=0;
    vector<int>ans;
    for(int i=n-1;i>=0;i--)
    {
        int x=s[i]-'0';
        if(x)
        {
            if(cnt==1)
            {
                ans.pb(0);
            }
            else
            {
                ll temp=sum22;
                temp-=power(2,k,cnt-1);
                temp=(temp+cnt-1)%(cnt-1);
                int num=1;
                while(temp)
                {
                    temp%=cal(temp);
                    num++;
                }
                ans.pb(num);
            }
        }
        else
        {
            ll temp=sum1+power(2,k,cnt+1);
            temp%=cnt+1;
            int num=1;
            while(temp)
            {
                temp%=cal(temp);
                num++;
            }
            ans.pb(num);
        }
        k++;
    }
    reverse(ans.begin(),ans.end());
    for(auto &v:ans)
        cout<<v<<'\n';





}


Measured memory_bytes: 4444
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		
		
		String str;
		String x=br.readLine();
		int count=0;
		for(;(str=br.readLine())!=null;){
			String[] stg=str.split(" ");
			for(String i:stg){
				if(i.equalsIgnoreCase(x))count++;
			}
		}System.out.println(count);
		}
		
		}

Measured memory_bytes: 17080
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
using ll=long long;

int main(){
    int N;
    cin >> N;
    ll A[N+10];
    ll ans = 0;
    ll tmp = 0;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(i > 0){
            for(int j = 0; j < i; ++j){
                tmp = abs(A[i] - A[j]);
                if(tmp > ans) ans = tmp;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const ll mo=998244353;
const int inf=1<<30;

ll rui(ll a,ll n){
  ll ans=1;
  while(n>0){
    if(n&1) ans=ans*a%mo;
    a=a*a%mo;
    n/=2;
  }
  return ans;
}

ll dp[3010][3010];

int main(){
  int n,s; cin >> n >> s;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll ans=0;
  dp[0][0]=1;
  rep(i,n)rep(j,s){
    if(j+a[i]<=3009) dp[i+1][j+a[i]]+=dp[i][j];
    dp[i+1][j]+=dp[i][j]*2;
    dp[i+1][j+a[i]]%=mo;
    dp[i+1][j]%=mo;
  }
  rep(i,n+1){
    ans+=dp[i][s]*rui(2,n-i)%mo;
    ans%=mo;
    //cout << ans << endl;
  }
  /*
  rep(i,n+1){
    rep(j,s+1){
      cout << dp[i][j];
    }cout << endl;
  }
  */
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll dp[5005][5005];

void Main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    ll ans = 0;
    rep(i, N) {
        rep(j, N) {
            if (S[i] == S[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }
            if (i + dp[i + 1][j + 1] < j + 1) {
                ans = max(ans, dp[i + 1][j + 1]);
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 195840
#include <stdio.h>
int main(){
  int K;
  int A,B;
  int i;
  scanf("%d",&K);
  scanf("%d %d",&A,&B);
  for(i=A;i<=B;i++){
    if(i%K==0){
      printf("OK\n");
      return 0;
    }
  }
  printf("NG\n");
  return 0;
}

Measured memory_bytes: 1660
#include <stdio.h>
#include <string.h>
#define MAX 2000000

int n,A[MAX+1];
void insert(int);
void increase(int,int);
void max(int);
int extract();

int main(){
    int k;
    char CHAR[10];

    while(1){
        scanf("%s",CHAR);
        if(strcmp(CHAR,"end")==0) break;
        if(strcmp(CHAR,"insert")==0){
            scanf("%d",&k);
            insert(k);
        }
        else{
            printf("%d\n",extract());
        }
    }
    return 0;   
}

void insert(int k){
    n++;
    A[n]=-1;
    increase(n,k);
}
void increase(int n,int k){
    int temp;
     if(k<A[n]) return;
     A[n]=k;
     while(n>1 && A[n/2]<A[n]){
         temp=A[n];
         A[n]=A[n/2];
         A[n/2]=temp;
         n=n/2;
     }
}
void max(int i){
    int l,r,larg,temp;
    l=2*i;
    r=2*i+1;
    if(l<=n && A[l]>A[i]) larg=l;
    else larg=i;
    if(r<=n && A[r]>A[larg]) larg=r;

    if(larg!=i){
       temp=A[i];
       A[i]=A[larg];
       A[larg]=temp;
       max(larg);
    }
}
int extract(){
    int m;
    if(n<1) return 0;
    m=A[1];
    A[1]=A[n];
    n--;
    max(1);
    return m;
}


Measured memory_bytes: 5636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
typedef pair<pl, int> pli;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

struct ROLLING_HASH {
    #define BASE1 1009LL
    #define BASE2 1007LL
    #define MOD1 1000000007LL
    #define MOD2 1000000009LL
    vector<ll> vec;
    vector<pl> acc;
    vector<pl> po;

    ll mod_pow (ll x, ll y, ll m) {
        ll ret = 1;
        while (y) {
            if (y&1) ret = ret * x % m;
            x = x * x % m;
            y /= 2;
        }
        return ret;
    }

    void init(vector<ll> _vec) {
        vec = _vec;
        acc.resize(vec.size());
        po.resize(vec.size());
        pl val = pl(0,0);
        rep(i,vec.size()) {
            if (i == 0) {
                po[0] = pl(1,1);
            } else {
                po[i].first = po[i-1].first*BASE1%MOD1;
                po[i].second = po[i-1].second*BASE2%MOD2;
            }
            val.first = (val.first+vec[i]*po[i].first)%MOD1;
            val.second = (val.second+vec[i]*po[i].second)%MOD2;
            acc[i] = val;
        }
    }

    pl get_hash (int l, int r) {
        pl ret;
        ret.first = (acc[r].first-(l==0?0:acc[l-1].first)+MOD1)%MOD1;
        ret.second = (acc[r].second-(l==0?0:acc[l-1].second)+MOD2)%MOD2;
        ret.first = ret.first * mod_pow(po[l].first, MOD1-2, MOD1) % MOD1;
        ret.second = ret.second * mod_pow(po[l].second, MOD2-2, MOD2) % MOD2;
        return ret;
    }
} rh;

int n;
string s;
vector<ll> v;
bool saw[5000][5000];

int main() {
    cin >> n >> s;
    rep(i,n) v.push_back(s[i]-'a'+1);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (saw[i][j]) continue;
            for (int l = 0; ; l++) {
                if (j+l >= n) break;
                if (i+l >= j) break;
                if (v[i+l] != v[j+l]) break;
                saw[i+l][j+l] = true;
                ans = max(ans,l+1);
            }
        }
    }
    cout << ans << endl;
}

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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans = 0;
  int res = 0;
  rep(i,s.size()){
    if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T') res++;
    else {
      ans = max(ans, res);
      res = 0;
    }
  }
  ans = max(ans, res);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;


int main()
{
	int H, W;
	vector<string> S(52);
	int count;

	cin >> H >> W;

	for (int j = 0; j < W + 2; j++)
		S[0] += ".";
	
	for (int i = 1; i <= H; i++)
	{
		cin >> S[i];
		S[i] = "." + S[i] + ".";
	}

	for (int j = 0; j < W + 2; j++)
		S[H+1] += ".";

	for (int i = 1; i <= H; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			count = 0;
			if (S[i][j] == '#')
			{
				cout << '#';
				continue;
			}
			for (int x = -1; x <= 1; x++)
			{
				for (int y = -1; y <= 1; y++)
				{
					if (S[i + y][j + x] == '#')
						count++;
				}
			}
			cout << count;
		}
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 256
# ABC153-E
if True:
    H,N=map(int,input().split())
    M=tuple(tuple(map(int,input().split()))for i in range(N))
    MAX=max(a for a,b in M)
    DP=[0 for _ in range(H+MAX)]
    for i in range(1,len(DP)):
        DP[i]=min(DP[i-a]+b for a,b in M)
    print(DP[H])

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int lose[5005] = { 0 };
bool match[5005][5005];
int main()
{
	int n;
	cin >> n;
	int m;
	cin >> m;
	int tf = 0;
	int no_1=-1;
	for (int i = 0; i < 5005; i++) {
		for (int j = 0; j < 5005; j++) match[i][j] = false;
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		lose[b]++;
		match[b][a] = true;
	}
	for (int i = 1; i <= n; i++) {
		if (lose[i] == 0) {
			if (no_1 != -1) tf = 1;
			no_1 = i;
		}
	}
	int ans[5005] = { 0 };
	bool used[5005];
	for (int i = 0; i < 5005; i++) used[i] = false;
	for (int i = 1; i <= n; i++) {
		ans[i] = no_1;
		used[no_1] = true;
		for (int j = 1; j <= n; j++) {
			if (match[j][no_1]) lose[j]--;
		}
		no_1 = -1;
		for (int j = 1; j <= n; j++) {
			if (lose[j] == 0 && !used[j]) {
				if (no_1 != -1) tf = 1;
				no_1 = j;
			}
		}
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << endl;
	cout << tf << endl;
    return 0;
}




Measured memory_bytes: 27604
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("Yes");
#define PN printf("No");
#define Py printf("yes");
#define Pn printf("no");
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;
const double PI = acos(-1);

int N, K;

int main() {
	S2(N, K);
	ll ans = (ll)K * pow(K - 1, N - 1);
	PL(ans);
}

Measured memory_bytes: 256
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
#import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s, n, node):
    # 頂点が探索済みかどうかのチェック配列
    check = [False for _ in range(n)]
    check[s] = True
    # 次見る頂点を格納するキュー
    queue = deque([s])
    visited_num = 1

    # 問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color = [-1 for _ in range(n)]
    color[s] = 0

    while visited_num < n:
        # グラフが全連結ではない場合
        if len(queue) == 0:
            # 空配列を返す
            # 現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex = queue.popleft()
        # インデックスがない場合は
        for next_vertex in node[now_vertex]:

            if check[next_vertex] == True:
                continue

            queue.append(next_vertex)
            check[next_vertex] = True

            # 問題固有の計算
            color[next_vertex] = color[now_vertex]+1
            visited_num += 1

    return color


mod = 10**9+7
# n=int(input())
# n,m=list(map(int,input().split()))
# a=list(map(int,input().split()))
def ceil(x, y): return (x+y-1)//y
def input_list(): return list(map(int, input().split()))


n = int(input())
tmp = input()

x = int(tmp, 2)
bit_num = tmp.count("1")
#bit = x % bit_num
p_bit = x % (bit_num+1)
m_bit_flg = False
if bit_num < 2:
    m_bit_flg = True
else:
    m_bit = x % (bit_num-1)

for i in range(n):
    if tmp[i] == "0":
        cal = (p_bit+pow(2, n-i-1, bit_num+1)) % (bit_num+1)
    else:
        if m_bit_flg:
            print(0)
            continue
        cal = (m_bit-pow(2, n-i-1, bit_num-1)) % (bit_num-1)
    ans = 1
    while(cal > 0):
        cal = cal % bin(cal).count("1")
        ans += 1
    # print(cal_bit_num)
    # print(bin(cal))
    print(ans)
    # exit()


Measured memory_bytes: 9904