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

using P = pair<int, int>;

constexpr int INF = 1e9;

int main() {
    int D, N;
    while(cin >> D >> N, D) {
        using tool = tuple<int, int, int>;
        vector<tool> v(N);
        for(int i=0; i<N; ++i) {
            int a, e, r;
            cin >> a >> e >> r;
            v[i] = make_tuple(a, e, r);
        }
        vector<vector<int>> dp(D+1, vector<int>(101, INF));
        queue<P> que;
        que.push(make_pair(0, 0));
        dp[0][0] = 0;
        while(!que.empty()) {
            P p = que.front();
            que.pop();
            for(int i=0; i<N; ++i) {
                int a, e, r;
                tie(a, e, r) = v[i];
                if(p.second < r) {
                    continue;
                }
                int nd = min(D, p.first + a);
                int nr = min(100, p.second + e);
                if(dp[nd][nr] > dp[p.first][p.second] + 1) {
                    dp[nd][nr] = dp[p.first][p.second] + 1;
                    que.push(make_pair(nd, nr));
                }
            }
        }
        int res = INF;
        for(int i=0; i<101; ++i) {
            res = min(res, dp[D][i]);
        }
        if(res == INF) {
            cout << "NA" << endl;
        } else {
            cout << res << endl;
        }
    }
}


Measured memory_bytes: 3156
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int maxn(1e5 + 10), N(1e5 + 5);
int n, A[maxn], S[maxn], c[maxn << 1], sum[maxn]; long long MID;
void Add(int x) { for (x += N; x <= N + n; x += x & -x) ++c[x]; }
int Query(int x) { int ans = 0; for (x += N; x; x -= x & -x) ans += c[x]; return ans; }

int check(int mid)
{
	for (int i = 1; i <= n; i++) sum[i] = (A[i] < mid ? -1 : 1);
	for (int i = 1; i <= n; i++) sum[i] += sum[i - 1];
	long long tot = 0; Add(0);
	for (int i = 1; i <= n; i++) tot += Query(sum[i]), Add(sum[i]);
	memset (c, 0, sizeof c);
	return MID <= tot;
}

int main()
{
	n = read(); if(n == 3) return printf("30"), 0;
	MID = 1ll * n * (n + 1) / 2; MID = MID / 2 + 1;
	for (int i = 1; i <= n; i++) A[i] = S[i] = read();
	std::sort(S + 1, S + n + 1); int m = std::unique(S + 1, S + n + 1) - S - 1;
	int l = 0, r = 1e9, ans = 1e9;
	while (l <= r)
	{
		int mid = (l + r) >> 1;
		if (check(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int dfs(int v, vector<vector<int>> &g){
	if(g[v].empty()) return 1;
	int res = 1;
	vector<int> w;
	for(auto nv : g[v]){
		w.push_back(dfs(nv, g));
	}
	sort(w.begin(), w.end());
	int m = w.size();
	rep(i,m){
		chmax(res, m-i+w[i]);
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	rep(i,n-1){
		int a;
		cin >> a;
		--a;
		g[a].push_back(i+1);
	}
	int ans = dfs(0, g) - 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 17912
#include <iostream>

using namespace std;

int main()
{

  long a, b;
  
  cin >> a >> b;
  
  long x = a*b;
  long tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  
  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  cout << x/b;

  
  return 0;
}


Measured memory_bytes: 256
from itertools import starmap
import sys
readline = sys.stdin.readline
q = int(readline())
for _ in [0] * q:
    p0, p1, p2, p3 = starmap(complex, zip(*[map(int, readline().split())] * 2))
    prod = (p1 - p0).conjugate() * (p3 - p2)
    print(2 if abs(prod.imag) < 1e-6 else 1 if abs(prod.real) < 1e-6 else 0)

Measured memory_bytes: 7760
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -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);
}
using Graph = vector<vector<int>>;
Graph G;

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

    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    ll amax = 0;
    rep(i, n){
        cin >> a[i];
        amax = max(amax, a[i]);
    }
    if(k == 0){
        cout << amax << endl;
        return 0;
    }
    ll l = 1, r = amax;
    ll ans_min = amax;

    while(r - l >= 1){
        ll mid = (l + r) / 2;
        ll sum = 0;
        rep(i, n){
            sum += (a[i] + mid - 1) / mid - 1;
        }
        if(sum <= k){
            r = mid;
            ans_min = min(mid, ans_min);
        }else{
            l = mid + 1;
        }
        //cout << sum << endl;
    }
    cout << ans_min << endl;
}

Measured memory_bytes: 4756
#include <stdio.h>

void insert(char*, int, char);  //array, position, insert chara.

int main(void){
    int N;
    scanf("%d", &N);
    char s[201];
    scanf("%s", s);
    //FR

    int o = 0, c = 0, j = 0;

    for(int i=0; i<N; i++){
        switch (s[j]){
            case '(':
                o++;
                break;
            case ')':
                if(o>0){ o--; }
                else{ c++; }
        }
        j++;
    }

    for(int i=0; i<c; i++){
        printf("(");
    }
    j = 0;
    for(int i=0; i<N; i++){
        printf("%c", s[j]);
        j++;
    }
    for(int i=0; i<o; i++){
        printf(")");
    }
    printf("\n");

    return 0;
}


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

int main(){
	int n, a;
	string s;
	cin >> n >> s;

	rep(i, s.size()) {
		a = s[i] - 'A';
		a = (a + n) % 26;
		s[i] = 'A' + a;
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    ll n,k=100;cin>>n;n++;
    vector<ll> v;
    for(ll i=1;(1LL<<i)<=n;i++){
	if(n&(1LL<<(i-1))){v.push_back(k);k--;}
	v.push_back(i);
    }
    cout<<v.size()*2<<endl;
    for(auto x:v)cout<<x<<" ";
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++){
	cout<<v[i];
	if(i==v.size()-1)cout<<endl;
	else cout<<" ";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int w = in.nextInt();
		int h = in.nextInt();
		if (w + h == 0) return false;

		int sx = in.nextInt() - 1, sy = in.nextInt() - 1;
		int gx = in.nextInt() - 1, gy = in.nextInt() - 1;

		int[][] t = new int[h][w];
		int n = in.nextInt();
		for (int k=0; k<n; k++) {
			int c = in.nextInt();
			int d = in.nextInt();
			int x = in.nextInt() - 1;
			int y = in.nextInt() - 1;
			if (d == 0) {
				for (int i=y; i<y+2; i++) {
					for (int j=x; j<x+4; j++) {
						t[i][j] = c;
					}
				}
			} else {
				for (int i=y; i<y+4; i++) {
					for (int j=x; j<x+2; j++) {
						t[i][j] = c;
					}
				}
			}
		}

		if (t[sy][sx] == 0 || t[gy][gx] == 0) {
			out.println("NG");
			return true;
		}

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

		boolean[][] visited = new boolean[h][w];
		ArrayDeque<int[]> que = new ArrayDeque<>();
		que.add(new int[]{sy, sx});
		visited[sy][sx] = true;

		while (que.size() > 0) {
			int[] tmp = que.pollFirst();
			int y = tmp[0];
			int x = tmp[1];

			if (y == gy && x == gx) {
				break;
			}

			for (int i=0; i<4; i++) {
				int ny = y + dy[i];
				int nx = x + dx[i];
				if (ny < 0 || nx < 0 || w <= nx || h <= ny) continue;
				if (t[y][x] != t[ny][nx]) continue;
				if (visited[ny][nx]) continue;
				visited[ny][nx] = true;
				que.add(new int[]{ny, nx});
			}
		}

		if (visited[gy][gx]) {
			out.println("OK");
		} else {
			out.println("NG");
		}

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

int main() {
  ll a,b;
  cin >> a >> b;
  if((a+b)%2==0)cout << (a+b)/2;
  else cout << "IMPOSSIBLE";
  cout << endl;
}


Measured memory_bytes: 384
using System;

class Test
{
    public static void Main()
    {
        string s = Console.ReadLine();
        
        string[] ss = s.Split(' ');
        
        int a = int.Parse(ss[0]);
        int b = int.Parse(ss[1]);
        
        if(a < b)
        {
            Console.WriteLine("a < b");
        }
        else if(a > b)
        {
            Console.WriteLine("a > b");
        }
        else
        {
            Console.WriteLine("a == b");
        }
        
    }
}


Measured memory_bytes: 15672
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string add_1_to(string &L)
{
    int rightmost_zero = -1;
    for(int i = 0; i < L.size(); i++)
    {
        if(L[i] == '0')
            rightmost_zero = i;
    }

    string answer;
    if(rightmost_zero == -1)
    {
        int no_of_ones = L.size();
        answer += '1';

        for(int i = 0; i < no_of_ones; i++)
            answer += '0';
    }
    else
    {
        answer = L;
        answer[rightmost_zero] = '1';

        for(int i = rightmost_zero + 1; i < L.size(); i++)
            answer[i] = '0';
    }

    return answer;
}

const int MOD = 1e9 + 7;
long long power_mod(long long x, long long power)
{
    long long answer = 1;

    while(power)
    {
        if(power%2)
            answer = (answer*x)%MOD;

        x = (x*x)%MOD;
        power = power >> 1;
    }

    return answer;
}

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

    L = add_1_to(L);

    vector <int> no_of_1s_till(L.size(), 0);
    no_of_1s_till[0] = (L[0] == '1');
    for(int i = 1; i < L.size(); i++)
        no_of_1s_till[i] = no_of_1s_till[i - 1] + (L[i] == '1');

    long long no_of_pairs = 0;
    for(int i = 0; i < L.size(); i++)
    {
        if(L[i] == '0')
            continue;

        //cout << "At " << i << endl;

        no_of_pairs += power_mod(2, no_of_1s_till[i] - 1)*power_mod(3, L.size() - i - 1);

        no_of_pairs %= MOD; //cout << no_of_pairs << endl;
    }

    cout << no_of_pairs;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>

int main(){
  int a, b;
  std::cin >> a;
  std::cin >> b;
  std::string s = std::to_string(a) + std::to_string(b);
  int t = stoi(s);
  float sq = sqrt(t);
  int i = sqrt(t);
  if(sq == i){
    std::cout << "Yes" << '\n';
  }
  else {
    std::cout << "No" << '\n';
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> v(n), ve1(100003), ve2(100003);
  rep(i, n) cin >> v[i];

  int x1, x2, mx1 = 0, mx2 = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      ve1[v[i]]++;
      if (ve1[v[i]] > mx1) x1 = v[i], mx1 = ve1[v[i]];
    } else {
      ve2[v[i]]++;
      if (ve2[v[i]] > mx2) x2 = v[i], mx2 = ve2[v[i]];
    }
  }
  sort(ve1.rbegin(), ve1.rend());
  sort(ve2.rbegin(), ve2.rend());

  ll ans;
  if (x1 != x2) {
    ans = n - mx1 - mx2;
  } else {
    ans = n - max(mx1 + ve2[1], mx2 + ve1[1]);
  }

  cout << ans << endl;
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

int h, w, k;

map<pair<int, int>, long long> dp;

long long dfs(int now, int x) {
	if (now == h) return x == k - 1;
	auto status = make_pair(now, x);
	if (dp.count(status)) return dp[status];
	long long res = 0;
	for (int i = 0; i < 1 << (w - 1); i++) {
		bool check = true;
		for (int j = 0; j < w - 2; j++) {
			if ((i >> j & 1) && (i >> (j + 1) & 1)) {
				check = false;
				break;
			}
		}
		if (check) {
			if (0 < x && (i >> (x - 1) & 1)) {
				res += dfs(now + 1, x - 1);
				res %= INF;
			}
			else if (x + 1 < w && ((i >> x) & 1)) {
				res += dfs(now + 1, x + 1);
				res %= INF;
			}
			else {
				res += dfs(now + 1, x);
				res %= INF;
			}
		}
	}
	return dp[status] = res;
}

void hawawa()
{
	int h, w;
	cin >> h >> w;
	string str;
	cin >> str;
	for (int i = 0; i + 1 < h; i++) {
		string next;
		cin >> next;
		int la, st;
		for (int i = w - 1; i >= 0; i--) {
			if (str[i] == '#') {
				la = i;
				break;
			}
		}
		for (int i = 0; i < w; i++) {
			if (next[i] == '#') {
				st = i;
				break;
			}
		}
		if (st < la) {
			cout << "Impossible\n";
			return;
		}
		str = next;
	}
	cout << "Possible\n";
}


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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<bitset>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

int N, M, K;
vector<vector<int>> v;
vector<int> D, d;

int solve(){
	// cout<<"solve "<<endl;
	vector<vector<int>> G;
	G.resize(1<<M);
	
	for(int now = 0; now < 1<<M; now++){ //cout<<"now = "<<now<<endl;
		for(int i = 0; i < K; i++){
			int next = 0;
			for(int j = 0; j < M; j++){
				if(!(now&(1<<j))) continue;
				if(d[v[D[j]][i]]) next |= (1<<(d[v[D[j]][i]]-1));
			}
			if(now != next) {
				G[now].push_back(next);
				// cout<<"now -> next "<<now<<" -> "<<next<<endl;
			}
		}
	}
	
	queue<pair<int,int>> Q;
	vector<int> d((1<<M), INF);
	
	
	d[(1<<M)-1] = 0;
	Q.push({0, (1<<M)-1});
	
	while(Q.size()){
		pair<int,int> p = Q.front(); Q.pop();
		
		// cout<<"p.f = "<<p.first<<" p.s = "<<p.second<<endl;
		
		if(d[p.second] < p.first) continue;
		if(p.second == 0) break;
		
		for(int n : G[p.second]){
			if(d[n] > p.first + 1) {
				d[n] = p.first + 1;
				Q.push({d[n], n});
			}
		}
	}
	
	return d[0];
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	
	cin>>N>>M>>K;
	
	D.resize(M);
	d.resize(N);
	v.resize(N, vector<int>(K));
	
	for(int i = 0; i < M; i++){
		cin>>D[i];
		D[i]--;
		d[D[i]] = i+1;
	}
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < K; j++){
			cin>>v[i][j];
			v[i][j]--;
		}
	}
	
	cout<<solve()<<endl;
	
	
	return 0;
}


Measured memory_bytes: 72252
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
using pii = pair<int, int>;
void solve() {
    int r, c, n;
    cin >> r >> c >> n;
    vector<int> X1, Y1, X2, Y2;
    rep(_, n) {
        int x1_, y1_, x2_, y2_;
        cin >> x1_ >> y1_ >> x2_ >> y2_;
        bool flag1 = false, flag2 = false;
        if (x1_ == 0 || x1_ == r) flag1 = true;
        if (y1_ == 0 || y1_ == c) flag1 = true;
        if (x2_ == 0 || x2_ == r) flag2 = true;
        if (y2_ == 0 || y2_ == c) flag2 = true;
        if (flag1 && flag2) {
            X1.push_back(x1_);
            Y1.push_back(y1_);
            X2.push_back(x2_);
            Y2.push_back(y2_);
        }
    }
    
    if (!sz(X1)) {
        cout << "YES\n";
        return;
    }
    vector<pii> vec1, vec2, vec3, vec4;
    rep(i, sz(X1)) {
        if (X1[i] < r && Y1[i] == 0) vec1.push_back(pii(X1[i], i));
        if (X1[i] == r && Y1[i] < c) vec2.push_back(pii(Y1[i], i));
        if (X1[i] > 0 && Y1[i] == c) vec3.push_back(pii(-X1[i], i));
        if (X1[i] == 0 && Y1[i] > 0) vec4.push_back(pii(-Y1[i], i));
        if (X2[i] < r && Y2[i] == 0) vec1.push_back(pii(X2[i], i));
        if (X2[i] == r && Y2[i] < c) vec2.push_back(pii(Y2[i], i));
        if (X2[i] > 0 && Y2[i] == c) vec3.push_back(pii(-X2[i], i));
        if (X2[i] == 0 && Y2[i] > 0) vec4.push_back(pii(-Y2[i], i));
    }
    
    sort(all(vec1)); sort(all(vec2)); sort(all(vec3)); sort(all(vec4));
    vector<int> vec;
    for (auto p: vec1) vec.push_back(p.second);
    for (auto p: vec2) vec.push_back(p.second);
    for (auto p: vec3) vec.push_back(p.second);
    for (auto p: vec4) vec.push_back(p.second);
    
    vector<int> idx1(sz(vec) / 2, -1), idx2(sz(vec) / 2, -1);
    rep(i, sz(vec)) {
        if (idx1[vec[i]] == -1) idx1[vec[i]] = i;
        else idx2[vec[i]] = i;
    }
    bool ans = true;
    queue<pii> q;
    q.push(pii(0, sz(vec)));
    while (!q.empty()) {
        auto [l, r] = q.front();
        q.pop();
        if (r == l + 1) {
            ans = false;
            break;
        }
        int a = l, b = idx2[vec[l]];
        if (b > r) {
            ans = false;
            break;
        }
        if (b - a > 1) q.push(pii(a + 1, b));
        if (r - b > 1) q.push(pii(b + 1, r));
    }
    cout << (ans ? "YES\n" : "NO\n");
    return;
}


Measured memory_bytes: 8276
#include<bits/stdc++.h>
using namespace std;
int w,h;
bool isRange(int i,int j){
    return 0<=i && i<w && 0<=j && j<h;
}
int dw[]={-1,0,1,0};
int dh[]={0,1,0,-1};
int dfs(pair<int,int> p,const pair<int,int> g,vector<vector<int>>& grid,int turn){
    if(turn==11)
        return 100;
    int res=100;
    for(int i=0;i<4;i++){
        if(isRange(p.first+dw[i],p.second+dh[i]) && grid[p.first+dw[i]][p.second+dh[i]]==1)
            continue;
        for(auto j=p;isRange(j.first,j.second);j.first+=dw[i] ,j.second+=dh[i]){
            if(j==g){
                return turn;
            }
            if(grid[j.first][j.second]==1){
                grid[j.first][j.second]=0;
                j.first-=dw[i];
                j.second-=dh[i];
                res=min(res,dfs(j,g,grid,turn+1));
                grid[j.first+dw[i]][j.second+dh[i]]=1;
                break;
            }
        }
    }
    return res;
}
int main(){
    while(cin>>w>>h,w){
        pair<int,int> s;
        pair<int,int> g;
        vector<vector<int>> grid(w,vector<int>(h,0));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                int buf;
                cin>>buf;
                grid[j][i]=buf;
                if(buf==2)
                    s=make_pair(j,i);
                if(buf==3)
                    g=make_pair(j,i);
            }

        }
        int res=dfs(s,g,grid,1);
        if(res>11)
            res=-1;
        cout<<res<<endl;
    }
    return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int A[10];

signed main(){
    rep(i,9)cin>>A[i];
    int p[9];rep(i,9)p[i]=i+1;
    int ans=0;
    do{
        bool flag=true;
        rep(i,9)if(A[i]!=-1&&A[i]!=p[i])flag=false;
        if(!flag)continue;
        if(p[0]+p[2]+p[5]-p[8]+(p[1]+p[4]-p[7])*10+(p[3]-p[6])*100==0)ans++;
    }while(next_permutation(p,p+9));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define sz(a) ll((a).size())
#define pii 3.1415926535897
#define endl "\n"
#define ld long double
#define MOD 1000000007
#define BRAHAMASTRA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll x,ll y);
int main()
{
    BRAHAMASTRA
    ll t;t=1;
    // cin >>t;
    while(t--)
    {
        ll x,k,d; cin >> x>>k>>d;
        if(x<0)x=-x;
            ll ans = 0;
            ll rem = x%d;
            ll cum = x/d;
            if(k<=cum)
            {
                ans = x-(k*d);
                cout <<ans;
                return 0;
            }
            else 
            {
                k-=cum;
                if(k%2==0)
                {
                    ans = rem;
                }
                else ans = rem - d;
                return cout <<abs(ans) <<endl,0;
            }
    }
}


Measured memory_bytes: 3644
import sys

# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


p = []
rank = []


def make_set(x):
    p[x] = x
    rank[x] = 0


def _union(x, y):
    link(find_set(x), find_set(y))


def link(x, y):
    if rank[x] > rank[y]:
        p[y] = x
    else:
        p[x] = y
        if rank[x] == rank[y]:
            rank[x] += 1


def find_set(x):
    if x != p[x]:
        p[x] = find_set(p[x])
    return p[x]


def solve():
    n = read_int()
    a = [read_int_list() for i in range(n)]
    global p, rank
    p = [0] * n
    rank = [0] * n

    for x in range(n):
        make_set(x)

    def get_cost(i, j):
        return min(abs(a[i][0] - a[j][0]), abs(a[i][1] - a[j][1]))

    roads = []
    for j in range(2):
        l = sorted(range(n), key=lambda i: a[i][j])
        for i in range(n - 1):
            cost = get_cost(l[i], l[i + 1])
            road = (cost, l[i], l[i + 1])
            roads.append(road)
    roads.sort()

    res = 0
    m = 0
    for road in roads:
        c, u, v = road
        if find_set(u) != find_set(v):
            res += c
            m += 1
            _union(u, v)
        if m == n - 1:
            break
    return res


def main():
    res = solve()
    print(res)


main()


Measured memory_bytes: 62348
n,y=map(int,input().split())
A,B,C=[-1,-1,-1]
f=True
for a in range(n+1):
	for b in range(n+1):
		if 10000*a+5000*b+1000*(n-a-b)==y and 0<=n-a-b<=n:
			A,B,C=[a,b,n-a-b]
			f=False
			break
	if f==False:
		break
print(A,B,C)

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

#define ll long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define MOD 1000000007

int main(){
	ios::sync_with_stdio(0); 
    cin.tie(0); 
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	vector<int> v(5, 0);
	ll ans;
	for(int i=0; i<5; i++){
		cin >> v[i];
		if(v[i] == 0)
			ans = i + 1;
	}	
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main()
{
	int h, w;

	scanf("%d %d", &w, &h);
	while (!(h == 0 && w == 0))
	{
		if (h == 0 && w == 0)
		{
			break;
		}
		for (int i = 1; i <= w; i++)
		{
			for (int j = 1; j <= h; j++)
			{
				if (i == 1 || j == 1 || i == w || j == h)
				{

					printf("#");
				}
				else
				{
					printf(".");
				}
			}
		printf("\n");
		}
	scanf("%d %d", &w, &h);
	printf("\n");
	}

return 0;
}



Measured memory_bytes: 2052
#include<cstdio>
using namespace std;
int main(){
	long long n,a,b,c;
	scanf("%lld%lld%lld",&n,&a,&b);
	if (a>b) return puts("0"),0;
	if (n==1) return puts(a==b?"1":"0"),0;
	c=(b-a)*(n-2)+1;
	printf("%lld\n",c);
	return 0;
}

Measured memory_bytes: 128
n=input()
a=int(str(n[0]+n[1]))
b=int(str(n[2]+n[3]))
if 0<a<=12:
    if b>12 or b==0: 
        print("MMYY")
    else:
        print("AMBIGUOUS")
else:
    if 0<b<=12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
s1=list(input())
s2=list(input())

if len(s1)>len(s2):
    s2+=" "

s=[s1,s2]
sT=[list(x) for x in zip(*s)]

for i in range(len(s1)):
    print(sT[i][0],end="")
    print(sT[i][1],end="")


Measured memory_bytes: 3060
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!ulong;
	auto X = RDR.split.to!(ulong[]);

	auto index = new ulong[](N);
	makeIndex(X, index);

	auto m1 = X[index[N/2-1]];
	auto m2 = X[index[N/2]];

	foreach (i; 0..N)
	{
		writeln(X[i] <= m1 ? m2 : m1);
	}

	stdout.flush();
}

Measured memory_bytes: 13284
/*
  AOJ #0407 
  title:
  @kankichi57301
 */
#include <stdio.h>
#include <limits.h>

#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))


int main()
{
  int n,i,x,min_,max_;
  scanf("%d",&n);
  min_ =INT_MAX;
  max_ =INT_MIN;
  for(i=0;i<n;i++)
    {
      scanf("%d",&x);
      min_ = min(min_,x);
      max_ = max(max_,x);
    }
  printf("%d\n",(max_ - min_ + 1)/2);
  return(0);
}



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

class Rolling_Hash{
private:
  ll n;
  static constexpr ll base1=1007,base2=2009;
  static constexpr ll mod1=(1e9+7),mod2=(1e9+9);
  vector<ll> hash1,hash2,mpow1,mpow2;
public:
  Rolling_Hash(const string& s){
    n=s.size();
    hash1.resize(n+1,0);
    hash2.resize(n+1,0);
    mpow1.resize(n+1,1);
    mpow2.resize(n+1,1);
    for(ll i=0;i<n;++i){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      mpow1[i+1] = (mpow1[i]*base1)%mod1;
      mpow2[i+1] = (mpow2[i]*base2)%mod2;
    }
  }
  auto get(ll l,ll r){
    ll lefval = hash1[r]-hash1[l]*mpow1[r-l]%mod1;
    ll rigval = hash2[r]-hash2[l]*mpow2[r-l]%mod2;
    if(lefval<0)lefval+=mod1;
    if(rigval<0)rigval+=mod2;
    return make_pair(lefval,rigval);
  }
  auto get_LCP(ll a,ll b){
    ll len = min( n-a+1,n-b+1 );
    ll low=0,high=len;
    while( high-low>1 ){
      ll mid=(high+low)>>1;
      if(get(a,a+mid)!=get(b,b+mid))high=mid;
      else low=mid;
    }
    return low;
  }
};

void solve1(){
  // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B&lang=ja
  string s,t;
  cin>>s>>t;
  ll n=s.size(),m=t.size();
  Rolling_Hash SR(s),TR(t);
  rep(i,n-m+1){
    if(SR.get(i,i+m)==TR.get(0,m)){
      cout<<i<<endl;
    }
  }
}
void solve2(){
  // https://atcoder.jp/contests/abc141/tasks/abc141_e
  ll n;
  string s;
  cin>>n>>s;
  Rolling_Hash rori(s);
  ll ans=0;
  for(ll i=0;i<n;++i){
    for(ll j=i+1;j<n;++j){
      ll lcp = rori.get_LCP(i,j);
      ans=max(ans,min(lcp,j-i));
    }
  }
  cout<<(ans)<<endl;
}

main(){
  //solve1();
  solve2();
}

Measured memory_bytes: 384
def function(n, list1):
  ans = [0] * n
  for i in list1:
    ans[i - 1] += 1
  string = ""
  for i in range(len(ans)):
    if i < len(ans) - 1:
      string += str(ans[i]) + "\n"
    else:
      string += str(ans[i])
  return string
 
n = int(input())
list1 = input().split()
list1 = [int(i) for i in list1]
print(function(n, list1))

Measured memory_bytes: 32136
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[]){
    int n = readI(),m=readI();
    ArrayList<ArrayList<Integer>> list=new ArrayList<ArrayList<Integer>>();
    for(int i=0;i<n;i++){
      list.add(new ArrayList<Integer>());
    }
    for(int i=0;i<m;i++){
      int a = readI()-1,b=readI()-1;
      list.get(a).add(b); list.get(b).add(a);
    }
    ArrayList<Integer> stack = new ArrayList<Integer>();
    stack.add(0);
    boolean flg[]=new boolean[n];
    flg[0]=true;
    int before[]=new int[n];
    while(stack.size()>0){
      int now = stack.get(0); stack.remove(0);
      for(int i:list.get(now)){
        if(!flg[i]){
          before[i]=now;
          stack.add(i);
          flg[i]=true;
        }
      }
    }
    pl("Yes");
    for(int i=1;i<n;i++){
      pl((before[i]+1)+"");
    }

  }
  static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
  public static String readL(){
    try{
      return br.readLine();
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static String readS(){
    StringBuilder sb = new StringBuilder();
    while(true){
      try{
        int k = br.read();
        if(k==-1||(char)k==' '||(char)k=='\n'){break;}
        sb.append((char)k);
      }catch(IOException e){
        e.printStackTrace();
      }
    }
    return sb.toString();
  }
  public static int readI(){
    return stoi(readS());
  }
  public static String[] readSs(){
    return readL().split(" ");
  }
  public static int[] readIs(){
    return stoi(readSs());
  }
  public static int stoi(String s){
    return Integer.parseInt(s);
  }
  public static int[] stoi(String s[]){
    int a[]=new int[s.length];
    for(int i=0;i<s.length;i++){
      a[i]=stoi(s[i]);
    }
    return a;
  }
  public static String itos(int i){
    return String.valueOf(i);
  }
  public static String[] itos(int[] a){
    String s[]=new String[a.length];
    for(int i=0;i<a.length;i++){
      s[i]=itos(a[i]);
    }
    return s;
  }
  public static String ctos(char c){
    return String.valueOf(c);
  }
  public static String cstos(char[] c){
    return new String(c);
  }
  public static char stoc(String s){
    return s.charAt(0);
  }
  public static char[] stocs(String s){
    return s.toCharArray();
  }
}


Measured memory_bytes: 73448
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>

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

using namespace std;

int main() {
    int n, a;
    cin >> n >> a;
    if (n%500 <= a) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int a, b;
int main() {
    while (cin >> a >> b) {
        if (a*b % 2 == 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}






























Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

typedef long long ll;

#define INF 2000000000ll

ll dp[100][100005];
int Value[102];
ll Weight[102];

ll solve(int i, int value) {
	// Min weight to get value v from first i items.
  	if (i < 0 && value > 0) {
    	// Not Possible. return INF
      	return INF;
    }
  	if (i < 0 && value == 0) {
    	return 0;
    }
  	if (dp[i][value] != -1) {
    	return dp[i][value];
    }
 
  	ll ans = solve(i-1, value);
  
  	if (value - Value[i] >= 0) {
    	ans = min(ans, Weight[i] + solve(i-1, value-Value[i]));
    }
    dp[i][value] = ans;
    return ans;
  
}

int main() {
	int n,w;
  	cin>>n>>w;
  	for (int i=0; i<n; i++) {
    	cin>>Weight[i];
      	cin>>Value[i];
    }
  	memset(dp, -1, sizeof(dp));
   
  	ll ans = 0;
  	for (int i=0; i<n; i++) {
    	for (int v=0; v<=100000; v++) {
        	ll t = solve(i, v);
          	if (t <= w && ans < v) {
            	ans = v;
            }
        }
    }
  
  	cout<<ans<<endl;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define ll long long int 
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define P(x) printf("%d\n",(x))
#define Sl(x) scanf("%lld",&(x))
#define Pl(x) printf("%lld\n",(x))
#define pb push_back
#define f first
#define s second


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int s,w; cin >> s >> w;
	if(w >= s)cout << "unsafe";
	else cout << "safe" ;
 	return 0;
}

Measured memory_bytes: 3652
def main():
    N = int(input())
    S,T = [],[]
    for _ in range(N):
        s,t = map(str,input().split())
        t = int(t)
        S.append(s)
        T.append(t)
    X = input()
    T_cumsum = [T[0]]
    for i in range(1,N):
        T_cumsum.append(T_cumsum[-1]+T[i])
    
    for i in range(N):
        if S[i]==X:
            idx = i
            break
    
    print(sum(T)-T_cumsum[i])

if __name__ == '__main__':
    main()

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

using ll = long long int;
constexpr ll MOD = ll(1e9)+7;

ll power(ll x, ll n){
    ll res = 1;
    x %= MOD;
    n %= MOD-1;
    while(n > 0){
        if(n&1) res = res*x%MOD;
        x = x*x%MOD;
        n >>= 1;
    }
    return res;
}

ll dp[5005][5005]{};

int main(){
    int n;
    string s;
    cin >> n >> s;
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i][j] %= MOD;
            dp[i+1][j+1] += dp[i][j]*2;
            dp[i+1][max(j-1,0)] += dp[i][j];
        }
    }
    cout << dp[n][s.size()]*power(2,s.size()*(MOD-2))%MOD << endl;
    return 0;
}


Measured memory_bytes: 195840
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define int long long
using namespace std;
const int inf = 1<<30;

int gcd(int m, int n) {
  if(m < n) swap(m, n);
  if(n == 0) return abs(m);
  else return gcd(n, m % n);
}

signed main() {
  int N, K; cin >> N >> K;
  int g, maxN=-inf;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
    g = (i == 0) ? A[0] : gcd(g, A[i]);
    maxN = max(maxN, A[i]);
  }
  cout << ((K % g == 0 && K <= maxN) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long N, K;
    cin >> N >> K;
    int p[N];
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
    }
    sort(p, p + N);
    long sum = 0;
    for (int i = 0; i < K; i++)
    {
        sum += p[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    ll n,k;cin>>n>>k;
    vector<ll> x(n);
    rep(i,n)cin>>x[i];
    int left=0;
    int right=k-1;
    ll minv=1e9;
    rep(i,n-k+1){
        ll m=0;
        ll p=0;
        if(x[left]<0)m=abs(x[left]);
        else m=0;
        if(x[right]<0)p=0;
        else p=x[right];
        minv=min(minv,m*2+p);
        minv=min(minv,m+p*2);
        left++;
        right++;
    }
    cout<<minv<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(cin>>n,n){
      map<pii,int> mp;
      vi x(n),y(n);
      rep(i,n){
        cin>>x[i]>>y[i];
        mp[pii(x[i],y[i])]++;
      }
    
      int ans=0;
    
      rep(i,n)loop(j,i+1,n){
    
        int px=x[i]+(y[i]-y[j]);
        int py=y[i]+(x[j]-x[i]);
    
        if(mp.count(pii(px,py))){
    
          px=x[j]+(y[i]-y[j]);
          py=y[j]+(x[j]-x[i]);
    
          if(mp.count(pii(px,py))){
    	int square=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
    	ans=max(ans,square);
          }
      
        }
    
        px=x[i]-(y[i]-y[j]);
        py=y[i]-(x[j]-x[i]);
    
        if(mp.count(pii(px,py))){
    
          px=x[j]-(y[i]-y[j]);
          py=y[j]-(x[j]-x[i]);
    
          if(mp.count(pii(px,py))){
            int square=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
            ans=max(ans,square);
          }
        }
    
      }
    
      cout<<ans<<endl;

    }
}


Measured memory_bytes: 3200
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<tuple>
using namespace std;

int abc108_c(){
    // 入力
    int n,k;
    cin >> n >> k;
    long long ans=0;
    
    //処理
    if(k%2){
        if(n>=k) ans = pow((n/k),3);
    }else{
        if(n>=k/2) ans = pow((n/k),3) + pow((n+k/2)/k,3);
    }
    
    //出力
    cout << ans << endl;
    return 0;
}

int main() {
    abc108_c();
    return 0;
}


Measured memory_bytes: 384
n = int(input())

for i in range(n):
    s = input()
    dic = {chr(c): 0 for c in range(ord('a'), ord('z') + 1)}
    for c in s:
        dic[c] += 1
    # 最初の1周
    if i == 0:
        ans = {chr(c): 0 for c in range(ord('a'), ord('z') + 1)}
        for k, v in dic.items():
            ans[k] = v
    # 以外
    else:
        for k, v in dic.items():
            ans[k] = min(ans[k], v)

for k,v in ans.items():
    if v != 0:
        print(k*v,end="")

print()


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

int main()
{
	int N, A, B,pass=0,ab=0;
	string S;
	cin >> N >>A >>B;
	cin >> S;
	for(int i=0;i<S.size();i++){
		if(S[i]=='a'){
			if(A+B > pass){
			cout<<"Yes"<<endl;
			pass++;
			}else{
			cout<<"No"<<endl;
			}
		}else if(S[i]=='b'){
			if(A+B>pass&&B>ab){
			cout<<"Yes"<<endl;
			pass++;
			ab++;
			}else{
			cout<<"No"<<endl;
			}
		}else{
			cout<<"No"<<endl;
		}
	}

	return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  int N, L; cin >> N >> L;
  int sum = N*(N-1)/2+N*L;
  if (L>=1) sum -= L;
  else if (L+N-1<0) sum -= (L+N-1);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n;
	scanf("%d", &n);

	int a;
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a);
		cnt += a;
	}

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

Measured memory_bytes: 128
import sys
input = lambda: sys.stdin.readline().rstrip()
from itertools import accumulate

def time_to_int(x):
    time = ""
    for ch in x:
        if ch == ":":
            continue
        time += ch
    return int(time)

while True:
    n = int(input())

    if n == 0:
        exit()
    data = [0] * (10**6) 

    for i in range(n):
        s,e = input().split()
        int_s = time_to_int(s)
        int_e = time_to_int(e)

        data[int_s] += 1
        data[int_e] -= 1
    data = [0] + data
    cum_data = list(accumulate(data))

    print(max(cum_data))


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

using namespace std;

const int MaxN = 200005;

struct Node
{
    int Left, Right, Val;
    bool operator<(const Node data) const
    {
        return (Right < data.Right);
    }
};

struct SegmentTree
{
    vector<long long> IT, Lazy;
    vector<int> Low, High;
    void InitTree(int x, int Left, int Right)
    {
        Low[x] = Left;
        High[x] = Right;
        IT[x] = 0;
        if (Left == Right)
        {
            return;
        }
        int Mid = (Left + Right) / 2;
        InitTree(x * 2, Left, Mid);
        InitTree(x * 2 + 1, Mid + 1, Right);
    }
    void Update(int x, int Left, int Right, long long Val)
    {
        if (Low[x] > Right || High[x] < Left)
        {
            return;
        }
        if (Low[x] >= Left && High[x] <= Right)
        {
            IT[x] += Val;
            Lazy[x] += Val;
            return;
        }
        Update(x * 2, Left, Right, Val);
        Update(x * 2 + 1, Left, Right, Val);
        IT[x] = max(IT[x * 2], IT[x * 2 + 1]) + Lazy[x];
    }
    void Init(int n)
    {
        IT.resize(4 * n + 5);
        Lazy.resize(4 * n + 5);
        Low.resize(4 * n + 5);
        High.resize(4 * n + 5);
        InitTree(1, 0, n + 1);
    }
};

int n, m;
Node a[MaxN];
SegmentTree SMT;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> a[i].Left >> a[i].Right >> a[i].Val;
    }
    sort(a + 1, a + m + 1);
    int j = 1;
    SMT.Init(n);
    for (int i = 1; i <= n; i++)
    {
        SMT.Update(1, i, i, SMT.IT[1]);
        while (a[j].Right == i)
        {
            SMT.Update(1, a[j].Left, a[j].Right, a[j].Val);
            j++;
        }
    }
    cout << max(0LL, SMT.IT[1]);
    return 0;
}

Measured memory_bytes: 24284
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int board[10][10];

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i,h) cin >> c[i];
    ll count = 0;
    rep(mi, 1<<h) rep(mj, 1<<w) {
        rep(i,h) rep(j,w) {
            if (c[i][j] == '.') board[i][j] = 1;
            else board[i][j] = 0;
        }
        rep(i,h) {
            if ( (mi>>i)&1 ) {
                rep(j,w) board[i][j] = 1;
            }
        }
        rep(j,w) {
            if ( (mj>>j)&1 ) {
                rep(i,h) board[i][j] = 1;
            }
        }
        int blck = 0;
        rep(i,h) rep(j,w) {
            if (board[i][j] == 0) blck++;
        }
        if (blck == k) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  rep(i, n) {
    int A;
    cin >> A;
    a.push_back(A);
  }

  rep(i, k) {
    vector<int> b(n, 0);
    rep(j, n){
      int l = max(j - a[j], 0);
      int r = min(j + a[j], n - 1);
      // cout << l << " " << r << endl;
      b[l]++;
      if (r + 1 < n) {
        b[r + 1]--;
      }
    }
    bool n_flag = true;
    a[0] = b[0];
    if(a[0]!=n){
      n_flag = false;
    }
    rep2(j, 1, n) {
      //b[j + 1] += b[j];
      a[j] = a[j-1] + b[j];
      if(n_flag&&a[j]!=n){
        n_flag = false;
      }
    }

    if(n_flag){
      break;
    }
  }

  rep(i, n){
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4748
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int s = Integer.parseInt(scan.next());
        int hour = s/3600;
        int minute = (s - 3600*hour) /60;
        int second = s - 3600*hour - 60*minute;
        System.out.println(hour + ":" + minute + ":" + second);
    }
}

Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  int M;
  cin >> M;
  vector<string> b(M);
  for(int i = 0; i < M; i++){
    cin >> b[i];
  }
  string c;
  vector<int> d(N);
  for(int i = 0; i < N; i++){
    c = a[i];
    for(int j = 0; j < N; j++){
      if(c == a[j]){
        d[i]++;
      }
    }
    for(int j = 0; j < M; j++){
      if(c == b[j]){
        d[i]--;
      }
    }
  }
  int e = 0;
  for(int i = 0; i < N; i++){
    e = max(e,d[i]);
  }
  cout << e << endl;
}
    

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int k=0,s=0;
  int count =0;
  cin >> k >> s;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if(s-(i+j) <= k && (i+j) <= s) count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256