akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int a[1001][1001];
int main(){
    int n, m;
    cin >> n >> m;
    int k;
    cin >> k;
    int cnt = 1;
    for(int i = 1; i <= n; i++){
        string s;
        cin >> s;
        for(int l = 0; l < s.size(); l++){
            if(s[l] == '#'){
                a[i][l + 1] = cnt;
                cnt++;
            }
            else{
                a[i][l + 1] = 0;
            }
        }
    }
    for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(a[i][j] != 0 && a[i][j + 1] == 0){
                a[i][j + 1] = a[i][j];
			}
		}
	}
	for(int i = n; i >= 1; i--) {
		for(int j = m; j >= 1; j--) {
			if(a[i][j] != 0 && a[i][j - 1] == 0){
                a[i][j - 1] = a[i][j];
			}
		}
	}
	for(int i = m; i >= 1; i--){
		for(int j = n; j >= 1; j--){
			if(a[j][i] != 0 && a[j - 1][i] == 0){
                a[j - 1][i] = a[j][i];
			}
		}
	}
	for(int i = 1; i <= m; i++){
		for(int j = 1; j <= n; j++){
			if(a[j][i] != 0 && a[j + 1][i] == 0){
                a[j + 1][i] = a[j][i];
			}
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cout << a[i][j]<< " ";
		}
		cout << "\n";
	}
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  int len;
  cin>>len;
  vector<char> name(len);
  
  for(int i=0;i<len;i++){
    cin>>name.at(i);
  }
  int count = 0;
  int x = len / 2;
  int ans = len % 2;
  if (ans!=0)
  {
    cout<<"No"<<endl;
  }else{
    
    for (int i = 0; i < x;i++){
      if(name.at(i)==name.at(i+x))
        count++;
    }
    if(count==x)
      cout << "Yes" << endl;
    else
    {
      cout << "No" << endl;
    }
  }
  return 0;
}

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

long long gcd(long long a,long long b){
 	if(a == 0 || b == 0){
		return a^b;
	}
 	if(a < b){
     swap(a,b); 
    }
  	long long r = a%b;
  	while(r != 0){
    	a = b;
    	b = r;
    	r = a%b;
    }
  	return b;
}


int main(){
	int n;
  	long long a;
  	cin >>n;
  	long long ans =0;
	for(int i=0;i<n;++i){
      cin >> a; 
      ans = gcd(ans,a);
    }
  	
	cout << ans << endl;
  	
}

Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

bool ok(ll sum, ll K) {
  return sum <= K;
}

int main() {
  ll N, K; cin >> N >> K;
  vector<ll> A(N), F(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int i = 0; i < N; i++) cin >> F[i];
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());
  ll l = -1, r = 1e12;
  while(l+1 < r) {
    ll mid = (l + r) / 2;
    ll sum = 0LL;
    for(int i = 0; i < N; i++) {
      sum += max(0LL, A[i] - mid/F[i]);
    }
    if(ok(sum, K)) r = mid;
    else l = mid;
  }
  cout << r << endl;
  return 0;
}


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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back( make_pair( (a), (b) ) )

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

int main() {
    string s;
    cin >> s;
    string t;
    cin >> t;
    std::vector<int64_t> v;
    if ( s.length() == t.length() ) {
        if ( s == t ) {
            cout << 0 << endl;
        } else {
            int64_t ans = 0;
            rep(i, s.length()) {
                if (s[i] != t[i]) ans++;
            }
            cout << ans << endl;
        }
        return 0;
    }
    rep(i, s.length()-t.length()) {
        // if ( s.at(i) == t.at(i) ) {
            int64_t num = t.length();
            rep(j, t.length()) {
                if ( s[i+j] == t[j] ) {
                    num--;
                }
            }
            v.push_back(num);
        // }
    }
    if (v.empty()) v.push_back(t.length());
    Sort(v);
    cout << v[0] << endl;
    return 0;
}


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


int main()
{
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> wf(n, vector<int>(n, l + 1));
  rep(i, m)
  {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    wf[a][b] = wf[b][a] = c;
  }
  rep(k, n)
    rep(i, n)
      rep(j, n)
        if (wf[i][k] <= l && wf[k][j] <= l)
          wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
  vector<vector<int>> g(n);
  rep(i, n - 1)
    for (int j = i + 1; j < n; j++)
      if (wf[i][j] <= l)
      {
        g[i].push_back(j);
        g[j].push_back(i);
      }
  vector<vector<int>> g2(n, vector<int>(n, -1));
  int query;
  cin >> query;
  rep(i, query)
  {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    queue<pair<int, int>> q;
    q.emplace(s, s);
    while (!q.empty())
    {
      auto p = q.front();
      q.pop();
      int pre = p.first;
      int crt = p.second;
      if (g2[s][crt] != -1)
        continue;
      if (pre != crt)
        g2[s][crt] = g2[s][pre] + 1;
      for (int nxt : g[crt])
        q.emplace(crt, nxt);
    }
    printf("%d\n", g2[s][t]);
  }
  return 0;
}

Measured memory_bytes: 2556
import sys
import bisect


def input():
    return sys.stdin.readline()[:-1]


def main():
    s = input()
    t = input()

    dic = {"q": [], "w": [], "e": [], "r": [], "t": [], "y": [], "u": [], "i": [], "o": [], "p": [], "l": [], "k": [], "j": [
    ], "h": [], "g": [], "f": [], "d": [], "s": [], "a": [], "z": [], "x": [], "c": [], "v": [], "b": [], "n": [], "m": []}
    now = 0
    ans = 0
    # for a in t:
    #     if not a in s:
    #         print(-1)
    #         sys.exit()
    for i in range(len(s)):
        dic[s[i]].append(i+1)
    for t1 in t:
        if len(dic[t1]) < 1:
            print(-1)
            sys.exit()

        old = now
        now = dic[t1][bisect.bisect_right(dic[t1], now) % len(dic[t1])]
        if old >= now:
            ans += 1
        # print(old, now, ans)

    ans = ans*len(s)+now

    # print(dic)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45780
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){

  int n, m, l;
  int a, b, k;
  cin >> a >> b >> k;
  int i = 1,ans;
  ans = gcd(a,b);
  while(k-1){
    ans--;
    if(a%ans==0 && b%ans==0){

      k--;
    }

  }
  cout << ans fin;
    
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
n, u, v = gets.split.map(&:to_i)
edges = []
(n - 1).times { edges << gets.split.map(&:to_i) }
graph = Array.new(n + 1) { Array.new }
# 無向グラフなので両始点のグラフに入れる
edges.each do |f, t|
  graph[f] << [f, t]
  graph[t] << [t, f]
end

takahashi_dist = []
takahashi_dist[u] = 0
takahashi_queue = [[u, u, 0]]
until takahashi_queue.empty?
  from, to, cost = takahashi_queue.shift
  graph[to].each do |f, t|
    # 逆流しないようにする（両方のグラフに入れているので必ず1つ該当する）
    next if t == from
    takahashi_dist[t] = cost + 1
    takahashi_queue << [f, t, cost + 1]
  end
end
takahashi_dist.shift

aoki_dist = []
aoki_dist[v] = 0
aoki_queue = [[v, v, 0]]
until aoki_queue.empty?
  from, to, cost = aoki_queue.shift
  graph[to].each do |f, t|
    # 逆流しないようにする（両方のグラフに入れているので必ず1つ該当する）
    next if t == from
    aoki_dist[t] = cost + 1
    aoki_queue << [f, t, cost + 1]
  end
end
aoki_dist.shift

ans = []
n.times do |i|
  if takahashi_dist[i] < aoki_dist[i]
    ans << aoki_dist[i] - 1
  end
end
puts ans.max


Measured memory_bytes: 31228
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        a: usize, b: usize, c: usize, d: usize, e: usize, f: usize,
    }

    let mut dp = vec![None; f + 1];
    dp[0] = Some(0);
    for i in 0..f + 1 {
        if dp[i].is_none() {
            continue;
        }
        if i + a * 100 <= f {
            dp[i + a * 100] = Some(max(dp[i + a * 100].unwrap_or(0), dp[i].unwrap_or(0)));
        }
        if i + b * 100 <= f {
            dp[i + b * 100] = Some(max(dp[i + b * 100].unwrap_or(0), dp[i].unwrap_or(0)));
        }
        if i + c <= f && (dp[i].unwrap_or(0) + c) * (100 + e) <= (i + c) * e {
            dp[i + c] = Some(max(dp[i + c].unwrap_or(0), dp[i].unwrap_or(0) + c));
        }
        if i + d <= f && (dp[i].unwrap_or(0) + d) * (100 + e) <= (i + d) * e {
            dp[i + d] = Some(max(dp[i + d].unwrap_or(0), dp[i].unwrap_or(0) + d));
        }
    }
    let mut p = -1.0;
    let (mut a, mut b) = (0, 0);
    for i in 1..f + 1 {
        if dp[i].is_none() {
            continue;
        }
        if dp[i].unwrap() as f64 / i as f64 > p {
            a = dp[i].unwrap();
            b = i;
            p = dp[i].unwrap() as f64 / i as f64;
        }
    }
    println!("{} {}", b, a);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            
            
            String[] str = Console.ReadLine().Split(' ');
            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);
            while (H != 0 || W != 0)
            {
                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        if (i == 0 || i == H-1)
                        {
                            Console.Write("#");
                        }
                        else if (j == 0 || j == W-1)
                        {
                            Console.Write("#");
                        }
                        else
                        {
                            Console.Write(".");
                        }

                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
                str = Console.ReadLine().Split(' ');
                H = int.Parse(str[0]);
                W = int.Parse(str[1]);

            }



        }
    }
}

Measured memory_bytes: 5300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N, P;
string S;

void solve(){

  ll ans = 0;
  
  if(P == 2 || P == 5){
    for(int i = 0; i < N; i++){
      if((S[i] - '0') % P == 0){
        ans += i + 1;
      }
    }
    cout << ans << endl;
    return;
  }


  unordered_map<int, int> rem;
  rem[0] = 1;
  int now = 0, r = 1;

  for(int i = N - 1; i >= 0; i--){
    now += ((S[i] - '0') * r) % P;
    now %= P;
    ans += rem[now]++;
    r = (r * 10) % P;
  }

  cout << ans << endl;
}


int main() {

  cin >> N >> P >> S;
  
  solve();
}

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

int main(void) {
  int a, b;
  cin >> a >> b;
  if (a == 0 || b == 0 || (a < 0 && 0 < b)) {
    cout << "Zero" << endl;
    return 0;
  }
  if (0 < a && 0 < b) {
    cout << "Positive" << endl;
    return 0;
  }

  if (0 < b) {
    b = 0;
  }

  if ((abs(a) - abs(b) + 1) % 2) {
    cout << "Negative" << endl;
  } else {
    cout << "Positive" << endl;
  }
  return 0;
}


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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
  int hats[3] = {0};
  int N;
  cin >> N;
  int tmp;
  vector<int> A;
  for(int i = 0; i < N; ++i) {
    cin >> tmp;
    A.push_back(tmp);
  }

  ll total = 1;
  for(auto a : A) {
    ll minv = 100;
    ll count = 0;
    for(ll i = 0; i < 3; ++i) {
      if(hats[i] == a) {
        count++;
        minv = min(minv, i);
      }
    }
    if(count == 0) {
      total = 0;
      break;
    } else {
      hats[minv]++;
      total = (total * count) % MOD;
    }
  }
  cout << total << endl;
  return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 998244353;
const ll LINF = 1e18;

int N, Q;
vector<ll> sum;
string S;
V idx;

int main() {
    cin >> N >> Q >> S;
    sum.resize(N + 1);
    REP(i, N - 1) {
        if(S[i + 1] == 'C' && S[i] == 'A') {
            sum[i + 1]++;
        }
        sum[i + 1] += sum[i];
    }
    REP(i, Q) {
        CINT(l, r);
        if(--l == 0)
            cout << sum[--r] << "\n";
        else
            cout << sum[--r] - sum[l] << "\n";
    }
    return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<double> a(n);
    REP(i,0,n) cin>>a[i];
    sort(ALL(a));
    
    double now=a[0];
    REP(i,1,n){
        now = (now+a[i])/2;
    }
    cout << fixed << setprecision(10) << now << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll a ,b ,c; cin >> a >> b >> c;
  if(a >= c){
    a = a - c;
    cout << a << " " << b << endl;
  }
  else{
    cout << 0 << " " << max(a + b - c , (ll)0) << endl;
  }

}


Measured memory_bytes: 256
from queue import Queue
h, w = map(int, input().split())
a = []
for _ in range(h):
    a.append(list(input()))
x = [0, 1]
y = [1, 0]
a[0][0] = 0
q = Queue()
q.put([0, 0])
while (q.qsize() > 0):
    start_y, start_x = q.get()
    for i in range(2):
        xx = start_x + x[i]
        yy = start_y + y[i]
        if (xx >= 0) & (xx < w) & (yy >= 0) & (yy < h):
            if a[yy][xx] == "#":
                a[yy][xx] = a[start_y][start_x] + 1
                q.put([yy, xx])
ans_list = []
for i in range(h):
    ans_list.extend(a[i])
dot_num = ans_list.count(".")
last_num = ans_list[-1]
if last_num != "#":
    if h*w == dot_num + last_num+1:
        ans = "Possible"
    else:
        ans = "Impossible"
else:
    ans = "Impossible"
print(ans)

Measured memory_bytes: 3952
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n, k;
	cin >> n >> k;

	vector<int> v(n), w(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}

	// dp[i][j] i番目以降の品物を価値j以下で選択した際の最大値
	vector<vector<int>> dp(n + 1, vector<int>(k + 1));
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= k; j++) {
			if (j < w[i]) {
				dp[i][j] = dp[i + 1][j];
			} else {
				dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
			}
		}
	}

	cout << dp[0][k] << endl;
	return 0;
}



Measured memory_bytes: 6836
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll cnt1 = 0, cnt2 = 0;
    ll sum1 = 0, sum2 = 0;
    rep(i, N){
        sum1 += A[i];
        if(i % 2 == 0){
            if(sum1 <= 0){
                cnt1 += 1 - sum1;
                sum1 = 1;
            }
        }
        else{
            if(sum1 >= 0){
                cnt1 += sum1 + 1;
                sum1 = -1;
            }
        }
    }
    
    
    rep(i, N){
        sum2 += A[i];
        if(i % 2 == 1){
            if(sum2 <= 0){
                cnt2 += 1 - sum2;
                sum2 = 1;
            }
        }
        else{
            if(sum2 >= 0){
                cnt2 += sum2 + 1;
                sum2 = -1;
            }
        }
    }
    
//    cout << cnt1 << "," << cnt2 <<  endl;
    
    output(min(cnt1, cnt2));
    
    return 0;
}

Measured memory_bytes: 1024
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<ll> memo(3, 0);
	ll MOD = 1e9 + 7;
	ll res = 1;
	rep(i, n)
	{
		int a; cin >> a;
		ll cnt = 0;
		rep(i, 3)
		{
			if (memo[i] == a)++cnt;
		}
		res *= cnt;
		res %= MOD;
		rep(i, 3)
		{
			if (memo[i] == a)
			{
				++memo[i];
				break;
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000007
#define maxn 1000000009
signed main()
{
    string S;
    cin >> S;
    bool ans = true;
    for (int i = 1; i < S.length(); i++)
    {
        if (S[i] == S[i - 1])
        {
            ans = false;
        }
    }
    cout << (ans ? "Good" : "Bad") << endl;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		BigDecimal a = new BigDecimal(sc.next());
		BigDecimal b = new BigDecimal(sc.next());
		System.out.println(a.multiply(b).setScale(0, RoundingMode.DOWN));
	}
}


Measured memory_bytes: 35624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		String s = sc.next();
		int[] count = new int[26];
		
		for(char c : s.toCharArray()) {
			count[c-97]++;
		}
		
		for(int c : count) {
			if(c % 2 != 0) {
				out.println("No");
				return;
			}
		}
		
		out.println("Yes");
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21332
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(void) {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double theta_a, theta_b;
  
  theta_a = M_PI / 6.0 * (h+m/60.0);
  theta_b = M_PI / 30.0 * m;
  
  double x;
  
  x = sqrt(a*a + b*b - 2.0 * a * b * cos(abs(theta_a - theta_b)));
  
  cout << fixed << setprecision(20) << x << endl;
  
  return 0;
}

Measured memory_bytes: 4228
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	vector<int> a(5);
	rep(i, 5) cin >> a[i];

	int time = 0;

	int mi = 10;

	rep(i, 5) {
		if (a[i] % 10 == 0) {
			time += a[i];
		}
		else {
			time += a[i] + 10 - (a[i] % 10);
			mi = min(mi, a[i] % 10);
		}
	}

	time -= 10 - mi;

	cout << time << endl;

	return 0;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return;
}

int main()
{
	int S = 0, W = 0;
	scanf("%d %d", &S, &W);

	if (W >= S) {
		printf("unsafe\n");
	} else {
		printf("safe\n");

	}

	return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   string s;
   getline(cin, s);
   rep(i, s.size()) {
      if (s[i] >= 'a' && s[i] <= 'z')
         s[i] = s[i] - 'a' + 'A';
      else if (s[i] >= 'A' && s[i] <= 'Z')
         s[i] = s[i] - 'A' + 'a';
   }
   cout << s << endl;
   return 0;
}


Measured memory_bytes: 3212
#include<cstdio>

#define MAX_N 100

int n, u, k, v;
int adj[MAX_N][MAX_N];

int main(void){
	scanf("%d", &n);

	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			adj[i][j] = 0;
		}
	}

	for(int i = 0; i < n; i++){
		scanf("%d", &u);
		u -= 1;
		scanf("%d", &k);
		for(int j = 0; j < k; j++){
			scanf("%d", &v);
			v -= 1;
			adj[u][v] = 1;
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			printf("%d", adj[i][j]);
			if(j != n - 1){
				printf(" ");
			}
			else if(j == n - 1){
				printf("\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 2688
n,m = map(int,input().split())
a = []
if m == 0:
    a = set()
else:
    for i in range(m):
        a.append(int(input()))
a = set(a)
dp = [0]*(n+1)
dp[0] = 1
if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1
MOD = 10 ** 9 + 7

for i in range(2,n+1):
    if i in a:
        continue
    dp[i] = (dp[i-2] + dp[i-1]) % MOD
print(dp[n])

Measured memory_bytes: 13212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}

int main(){
  ll ans = 1e18;
  int N,M,X;
  cin >> N >> M >> X;
  vector<ll> cost(N);
  vector<vector<ll>> skill(N,vector<ll> (M));
  rep(i,N){
    cin >> cost[i];
    rep(j,M){
      cin >> skill[i][j];
    }
  }

  for(int i=0; i<=(1<<N); i++){
    vector<bool> use;
    int now = i;
    rep(x,N){
      use.pb(now&1);
      now >>= 1;
    }
    vector<ll> ski(M,0);
    ll preans = 0;
    rep(j,N){
      if(use[j]){
        preans += cost[j];
        rep(k,M){
          ski[k] += skill[j][k];
        }
      }
    }
    bool ok = true;
    rep(k,M){
      if(ski[k]<X) ok = false;
    }
    if(ok) chmin(ans,preans);
  }

  if(ans == 1e18){
    cout << -1 << endl;
  }
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3568
x = raw_input()
x = x.split(" ")
w = int(x[0])
h = int(x[1])
x1 = int(x[2])
y = int(x[3])
r = int(x[4])

if x1 + r > w or x1 - r < 0 or y + r > h or y - r < 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 4644
/* ALDS1_2_A */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      String[] str = br.readLine().split(" ");

      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }

      BubbleSort bs = new BubbleSort();
      bs.bubbleSort(array, n);

      for(int i = 0; i < n ; i++){
        sb.append(array[i]).append(" ");
      }
      sb.deleteCharAt(sb.length() - 1);
      sb.append("\n");
      sb.append(bs.getCount());

      System.out.println(sb);
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

class BubbleSort
{
  private static int changeCount;

  public void bubbleSort(int[] A, int N)
  {
    changeCount = 0;
    boolean flag = true;
    int i = 0;

    while(flag){
      flag = false;
      for(int j = N-1; j > i; j--){
        if(A[j] < A[j-1]){
          int tmp = A[j];
          A[j] = A[j-1];
          A[j-1] = tmp;
          flag = true;
          changeCount++;
        }
      }
      i++;
    }
  }

  public int getCount()
  {
    return changeCount;
  }
}

Measured memory_bytes: 24448
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string S, T;
  cin >> S >> T;
  const int64_t L = static_cast<int64_t>(S.length());
  int64_t result = 0;
  for (int64_t i = 0; i < L; ++i) {
    if (S.c_str()[i] != T.c_str()[i]) {
      ++result;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3780
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int na=scan.nextInt();  
String nb=scan.next();
String nc=scan.next();
  
String[] mb=nb.split("");
String[] mc=nc.split("");
  
String[] md=new String[2*na];
for(int i=0;i<na;i++){
    md[2*i]=mb[i];
    md[2*i+1]=mc[i];
}

  String nd=String.join("",md);
  System.out.println(nd);

}
}


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

using namespace std;

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

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

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

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

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int k,a,b;
    cin>>k>>a>>b;
    FOR(i,a,b+1){
        if(i%k==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3688
#include <iostream>
int main () {
    int N, M;
    std::cin>>N>>M;
    size_t count = 0;
    if ( N == 1 && M == 1 ) count = 1;
    else if ( N == 1 ) count = static_cast<size_t>(M - 2);
    else if ( M == 1 ) count = static_cast<size_t>(N - 2);
    else  count = static_cast<size_t>(M-2) * static_cast<size_t>(N-2);
    std::cout<<count<<std::endl;
    return 0;

}


Measured memory_bytes: 256
def insertionsort(a, n, g):
    cnt = 0
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j = j - g
            cnt += 1
        a[j + g] = v
    return cnt


def shellsort(a, n):
    g = []
    gap = 1
    while gap <= n:
        g.append(gap)
        gap = 3 * gap + 1
    g = g[::-1]
    m = len(g)
    print(m)
    print(*g)
    cnt = 0
    for i in range(m):
        cnt += insertionsort(a, n, g[i])
    print(cnt)

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
shellsort(a, n)
print("\n".join(map(str, a)))

Measured memory_bytes: 189956
s=list(input())
t=input()
k=[]
for i in range(len(s)-len(t)+1):
  m=i
  for j in t:
    if s[m]==j or s[m]=='?':
      m+=1
    else:break
  else:
    l=s[:i]+list(t)+s[i+len(t):]
    for i in l:
      if i=='?':
        l[l.index(i)]='a'
    k.append(''.join(l))
if len(k)==0:
  k.append('UNRESTORABLE')
print(min(k))

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

int main() {
  int H,N;
  cin >> H >> N;
  int sum=0;
  for(int i =0; i<N; i++) {
    int A[N]; cin >> A[i];
    sum += A[i];
  }
  if(H>sum) cout << "No" << endl;
  if(H<=sum) cout << "Yes" << endl;
}

Measured memory_bytes: 3980
h, w = map(int, input().split())
G = [list(input()) for _ in range(h)]

remove_h = []
for i in range(h):
    if set(G[i]) == {"."}:
        remove_h.append(i)

remove_w = []
for j in range(w):
    if set([g[j] for g in G]) == {"."}:
        remove_w.append(j)

for i in range(h):
    if i not in remove_h:
        S = ""
        for j in range(w):
            if j not in remove_w:
                S += G[i][j]
        print(S)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

typedef tuple<int, int, int> T;

int main(){
    int N, Q; cin >> N >> Q;
    vector<T> xst(N);
    set<pair<int, int>> se;
    vector<int> ans(Q, -1);

    for(int i=0; i<N; ++i){
        int s, t, x; cin >> s >> t >> x;
        s -= x; t -= x;
        xst[i] = make_tuple(x, s, t);
    }
    sort(xst.begin(), xst.end());

    for(int i=0; i<Q; ++i){
        int d; cin >> d;
        se.insert(make_pair(d, i));
    }

    for(int i=0; i<N; ++i){
        int x, s, t;
        tie(x, s, t) = xst[i];
        auto itr = se.lower_bound(make_pair(s, -1));

        while(itr != se.end()){
            if(itr->first >= t) break;
            ans[itr->second] = x;
            se.erase(itr++);
        }
    }

    for(auto e:ans) cout << e << endl;

    return 0;
}


Measured memory_bytes: 14336
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<int> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	int n ; cin >> n ;
	string s ; cin >> s ;
	int ans = 0 ;
	for(int i=0;i<n;i++){
		vll cnt(n,0) ;
		cnt.at(i) = n-i ;
		int p=i+1,j=0 ;
		while(p<n){
			while(p+j<n&&s.at(p+j)==s.at(i+j)) j++ ;
			cnt.at(p) = j ;
			if(j==0){
				p++ ;
				continue ;
			}
			int k = 1 ;
			while(k<j&&k+cnt.at(i+k)<j){
				cnt.at(p+k) = cnt.at(i+k) ;
				k++ ;
			}
			p += k ;
			j -= k ;
		}
		for(int j=i;j<n;j++){
			ans = max(ans,min(cnt.at(j),j-i)) ;
//			cout << cnt.at(j) << (j==n-1?'\n':' ') ;
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
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; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    map<string,int> m;
    int n; cin >> n;
    rep(i,n) {
        string s; cin >> s;
        m[s]++;
    }
    int ma = 0;
    for (auto val : m) {
        ma = max(ma,val.second);
    }
    for (auto val : m) {
        if(val.second==ma) {
            cout << val.first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 23808
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli K;
	cin >> K;

	cout << (K / 2) * ((K + 1) / 2) << endl;



	return 0;
}

Measured memory_bytes: 256
//Fence
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
#define ll long long
//#define d double
//#define int long long
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
#define M 100000000
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int m=s.length(),n=t.length();
    long dp[m+1][n+1];
    for(int i=0;i<=m;i++)
        for(int j=0;j<=n;j++)
    {
        if(i==0||j==0)dp[i][j]=0;
        else if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
        else
        {
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int index=dp[m][n];
    string ans="";
    int i=m,j=n;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1]){
            ans.push_back(s[i-1]);
            i--;j--;}
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
                i--;
            else j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}


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

int main() {
    ll T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

    ll d1 = T1 * (A1 - B1);
    ll d2 = T2 * (A2 - B2);

    auto sign = [](ll a) { return a / abs(a); };

    ll d = d1, prev, next;
    ll ans = 0;
    ll D = d1 + d2;

    if (D == 0) {
        cout << "infinity" << endl;
        return 0;
    }
    if (sign(D) != sign(d1)) {
        d1 = abs(d1);
        D = abs(D);
        ans = ((d1) / D) * 2 + 1;
        if ((d1 % D) == 0) ans -= 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    map<string, int> mp;
    
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        mp[s]++;
    }
    int m; cin >> m;
    for (int i = 0; i < m; i++) {
        string s; cin >> s;
        mp[s]--;
    }
    
    int ans = 0;
    for (const auto &iter : mp) {
        ans = max(ans, iter.second);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256