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

#define MAX_N 50
#define MIN 1

using namespace std;

int main(void)
{
  int N,K;
  string S;
  cin >> N >> K;
  cin >> S;
  
  if(MIN <= N && 1<= MAX_N && MIN <= K <= N){
    S[K-1] = tolower(S[K-1]);
    cout << S;
  } else{
    return -1;
  }
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    
    int S = a[0];
    for(int i = 1; i < N; i++) S = S ^ a[i];
    if (S == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;
#define TENS(n) int(1e##n + n)

// Sのi-1文字目までとTのj-1文字目までのLCS
int dp[3001][3001];

void solve()
{
    string s, t;
    cin >> s >> t;

    int S = s.length();
    int T = t.length();

    REP1(i, S)
    {
        REP1(j, T)
        {
            if (s[i - 1] == t[j - 1])
            {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
            }
        }
    }
    int len = dp[S][T];
    string result = "";
    int i = S - 1;
    int j = T - 1;
    while (len)
    {
        if (s[i] == t[j])
        {
            result = s[i] + result;
            i--; j--; len--;
        }
        else if (dp[i+1][j+1]==dp[i+1][j])
            j--;
        else
            i--;
    }

    cout << result << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 35456
N = int(input())
S = input()
m = 10 ** 9 + 7
H = {}
for s in S:
  if not s in H:
    H[s] = 0
  H[s] += 1
#print(H)
ans = 1
for s, k in H.items():
  ans = (ans * (k + 1)) % m
print(ans-1)

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(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 ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"


long long gcd(ll a, ll b)
{
	return b ? gcd(b, a % b) : a;
}

long long lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

long long func(ll x, ll c, ll d)
{
	ll res = x;
	res -= x / c;
	res -= x / d;
	res += x / lcm(c, d);
	return res;
}

bool compare_by_b(pair<long, long> a, pair<long, long> b)
{
	return a.second < b.second;
}

int main()
{
	int n = 0;
	cin >> n;

	vector<pair<long, long>> list(n);
	REP(i, n)
	{
		cin >> list[i].first >> list[i].second;
	}

	sort(list.begin(), list.end(), compare_by_b);
	bool ok = true;
	ll now_time = 0;

	REP(i, n)
	{
		now_time += list[i].first;
		if (now_time > list[i].second)
		{
			ok = false;
		}
	}

	COUT(ok ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>

using namespace std;

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

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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>
istream& operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

int main() {
    int n;
    cin >> n;
    using PL = pair<ll, ll>;
    vector<PL> ranges(n);
    rep(i, n) {
        ll x, l;
        cin >> x >> l;
        ranges.at(i) = PL(x - l, x + l);
    }
    sort(ranges.begin(), ranges.end());

    vector<int> memo(n, -1);
    function<int(int)> solve = [&](int pos) {
        if (n == pos) return 0;
        if (0 <= memo.at(pos)) return memo.at(pos);

        int np = lower_bound(ranges.begin(), ranges.end(), ranges.at(pos).second, 
            [](PL r, int v){ return r.first < v; }
        ) - ranges.begin();
        
        int a = 1 + solve(np);
        int b = solve(pos + 1);
        
        return memo.at(pos) = max(a, b);
    };

    cout << solve(0) << endl;
}

Measured memory_bytes: 8448
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;

int main(){
    int n,k;cin>>n>>k;
    long long ans=k;
    for(int i=1;i<n;i++){
        ans*=(k-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 884
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] primeList = new int[5134];//5134
        int limit = 50001;
        primeList[0] = 2;
        primeList[1] = 3;
        int count = 2;
        for (int i = 5; i < limit; i += 2) {
            boolean wflag = true;
            for (int j = 1; primeList[j] * primeList[j] <= i; j++) {
                if (i % primeList[j] == 0) {
                    wflag = false;
                    break;
                }
            }
            if (wflag) {
                primeList[count++] = i;
            }
        }
        int[] l = new int[limit];
        for (int i = 0; primeList[i]>0; i++) {
            for (int j = i; primeList[j]>0; j++) {
                int s = primeList[i] + primeList[j];
                if (s < limit) {
                    l[s]++;
                }
            }
        }
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            System.out.println(l[n]);
        }

    }
}



Measured memory_bytes: 40004
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

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

#define PI 3.1415926535897932384626433832795


bool min_u(int&m, int v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	vvi f;
	vvi used;
	int n;
	vpii vdir={{0,1},{1,0},{0,-1},{-1,0}};

	solve(int n) : n(n) {
		used.resize(n+2);
		for(auto&m:used) m.assign(n+2,0);
		f.resize(n+2);
		for(auto&m:f) m.assign(n+2,-1);

		for(int y=1;y<=n;y++)
		{
			for(int x=1;x<=n;x++)
			{
				int v=x-1;
				min_u(v, y-1);
				min_u(v, n-x);
				min_u(v, n-y);
				f[y][x]=v;
				used[y][x]=1;
			}
		}
	}
	int armin(int x, int y)
	{
		int v=n;
		for(auto [vx,vy]:vdir)
		{
			int nx=x+vx;
			int ny=y+vy;
			min_u(v, f[ny][nx]);
		}
		return v;
	}
	int remove(int x, int y)
	{
		int ret=f[y][x];

		used[y][x]=0;
		f[y][x]=armin(x, y);

		queue<pii> q;
		q.push(make_pair(x, y));
		while(!q.empty())
		{
			tie(x,y)=q.front();
			q.pop();
			for(auto [vx,vy]:vdir)
			{
				int nx=x+vx;
				int ny=y+vy;
				if(f[ny][nx]<0) continue;
				if(min_u(f[ny][nx], armin(nx, ny)+used[ny][nx]))
				{
					q.push(make_pair(nx,ny));
				}
			}
		}
		return ret;
	}
	int operator()(vpii&p) {
		int ans=0;
		for(auto [x,y]:p)
		{
			ans+=remove(x, y);
		}
		return ans;
	}
};


int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vpii p(n*n);
		for(auto&mp:p)
		{
			int v;
			scanf("%d", &v);
			mp={(v-1)%n+1, (v-1)/n+1};
		}

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


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

int main()
{
  int N;
  int c = 0;
  bool YFlag = false;
  cin >> N;

  for(int i = 1; i <= N; i++)
  {
    int l, r;
    cin >> l >> r;
    c +=  r - l + 1; 
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) moC(res, *, x);
    moC(x, *, x);
    n>>=1;
  }
  return res;
}

ll fa[MAX], rf[MAX];

ll C(ll n, ll k) {
  if(n<k||n<0||k<0) return 0;
  if(k==0) return 1;
  if(n==k) return 1;
  return fa[n]*rf[k]%MOD*rf[n-k]%MOD;
}


int main(void) {
  ll i, j, k;
  ll N, K;
  cin >> N >> K;
  ll a[MAX];
  
  fa[0]=rf[0]=1;
  for(ll i=1; i<MAX; i++) {
    fa[i]=fa[i-1]*i%MOD;
    rf[i]=moP(fa[i], MOD-2);
  }
  
  for(i=1; i<=N; i++) cin >> a[i];
  sort(a+1, a+N+1);
  
  ll ans=0;
  for(i=1; i<=N; i++) {
    moC(ans, +, C(i-1, K-1)*a[i]%MOD);
    moC(ans, -, C(N-i, K-1)*a[i]%MOD);
  }
  
  pt(ans);
}





Measured memory_bytes: 2560
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
A_div = [0] * (10 ** 6 + 1)

for a in A:
    A_div[a] += 1
    if A_div[a] == 1:
        for j in range(2 * a, 10 ** 6 + 1, a):
            A_div[j] += 100

print(A_div.count(1))

Measured memory_bytes: 40072
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String s = in.next();
        final String t = in.next();
        int count = 0;
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == t.charAt(i)) {
                count++;
            }
        }
        System.out.println(count);
    }
}


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

#define INF 1e+9
#define MAX_V 2001

struct edge {
    int to;
    int cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int n, x, y;
    cin >> n >> x >> y;

    V = n;
    int E = n;

    for (int i = 0; i < n - 1; i++) {
        G[i].push_back({i + 1, 1});
        G[i + 1].push_back({i, 1});
    }
    G[x - 1].push_back({y - 1, 1});
    G[y - 1].push_back({x - 1, 1});

    vector<int> counter(n, 0);
    for (int i = 0; i < n; i++) {
        dijkstra(i);
        for (int j = i + 1; j < n; j++)
            counter[d[j]]++;
        // for (auto v : d) { cout << v << " "; } cout << endl;
    }

    for (int j = 1; j < n; j++)
        cout << counter[j] << endl;
}

Measured memory_bytes: 384
#define C
typedef long long readtype;

/* Header {{{ */
#ifdef C
#include <stdio.h>
#include <math.h>
#include <string.h>
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)
template<typename type> type abs(type a) { return a < 0 ? -a : a; }
template<typename type> type min(type a, type b) { return a < b ? a : b; }
template<typename type> type beMin(type &a, type b) { return a = (a < b ? a : b); }
template<typename type> type max(type a, type b) { return a > b ? a : b; }
template<typename type> type beMax(type &a, type b) { return a = (a > b ? a : b); }
template<typename type> void swap(type &a, type &b) { type c; c = a; a = b; b = c; }
#endif

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

typedef long long var;

readtype read() {
  readtype a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}
/* }}} */

const int N = 110005;

int cnt, sta[N];
char s[10], res[N];

int main() {
  /*
#ifndef ONLINE_JUDGE
  freopen("source.in", "r", stdin);
  freopen("source.out", "w", stdout);
#endif
  */
  int a = read(), b = read(), n = a + b;
  if (a <= b) {
    puts("Impossible");
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (!cnt) sta[++cnt] = i;
    else {
      printf("? %d %d\n", sta[cnt], i);
      fflush(stdout);
      scanf("%s", s);
      if (s[0] == 'Y') sta[++cnt] = i;
      else cnt--;
    }
  }
  res[sta[cnt]] = '1';
  for (int i = 0; i < n; ++i) {
    if (sta[cnt] == i) continue;
    printf("? %d %d\n", sta[cnt], i);
    fflush(stdout);
    scanf("%s", s);
    res[i] = '0' + (s[0] == 'Y');
  }
  printf("! %s", res);
  fflush(stdout);
  return 0;
}


Measured memory_bytes: 720
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n): #累積和ai,bjを求める
 acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
 acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
 if acum1[i]>k: #ai>Kであれば、どのようにjを選んでもai+bj<=Kとなることはないので探索を終了する
   break
 while acum2[j]>k-acum1[i] and j>0: #各iについて、bj<=K-aiを満たす最大のjを求める
   j-=1
 ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 47544
N,K = map(int,input().split())

ans = [0 for i in range(N)]

for i in range(K):
  d = int(input())
  List=list(map(int,input().split()))
  for j in List:
    ans[j-1] += 1
    
cnt = 0

for i in ans:
  if i == 0:
    cnt += 1
    
print(cnt)

Measured memory_bytes: 9188
from collections import defaultdict
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
X = []
D = defaultdict(int)

for a in A:
    D[a] += 1
for b,c in BC:
    D[c] += b
ans = 0
for e in sorted(D.keys(),reverse=True):
    if D[e] >= N:
        ans += e*N
        break
    else:
        ans += e*D[e]
        N -= D[e]
print(ans)

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

typedef std::pair<int, int> pii;

const int kN = 1e5 + 5;

int n, k, ans = 0, fa[kN], dep[kN];
std::vector<int> ch[kN];
std::priority_queue<pii> que;
bool vis[kN];

void Dfs(int x) {
	dep[x] = dep[fa[x]] + 1;
	for(int i : ch[x]) Dfs(i);
}
void Fill(int x, int d) {
	vis[x] = true;
	if(!d) return;
	for(int i : ch[x]) Fill(i, d - 1);
}

int main() {
	scanf("%d%d%d", &n, &k, fa + 1);
	if(fa[1] != 1) ++ans, fa[1] = 1;
	for(int i = 2; i <= n; ++i) {
		scanf("%d", fa + i);
		ch[fa[i]].push_back(i);
	}
	Dfs(1); Fill(1, k);
	for(int i = 1; i <= n; ++i)
		if(!ch[i].size() && !vis[i]) que.push(std::make_pair(dep[i], i));
	while(!que.empty()) {
		int v = que.top().second; que.pop();
		//printf("F: %d\n", v);
		if(vis[v]) continue;
		for(int i = 1; i < k; ++i) v = fa[v];
		//printf("T: %d\n", v);
		Fill(v, k - 1); ++ans;
		if(fa[v] != 1) que.push(std::make_pair(dep[fa[v]], fa[v]));
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 9728
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

A = lines[0][0]
V = lines[0][1]
B = lines[1][0]
W = lines[1][1]
T = lines[2][0]

if B < A then
  if A - T * V <= B - T * W then
    print "YES"
  else
    print "NO"
  end
elsif A < B then
  if A + T * V >= B + T * W then
    print "YES"
  else
    print "NO"
  end
else
  print "YES"
end

Measured memory_bytes: 14272
#include<iostream>
using namespace std;
int main(){
    int n,x,i;
    cin >> n;
    for(i=1;i<=n;i++){
        x=i;
        if(x%3==0){
            cout << " " << i;
            continue;
        }
        while(x){
            if(x%10==3){
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
#define EPS 0.00000000001

struct Line{
	double x[2],y[2];
};

int main(){
	Line l[2];
	while(true){
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				if(!(cin>>l[i].x[j]>>l[i].y[j])){
					return 0;
				}
			}
		}
		double a,b;
		bool flag=false,ans;
		if(l[0].x[0]==l[0].x[1]){
			swap(l[0],l[1]); flag = true;
		}
		if(l[1].y[0]==l[1].y[1]){
			if(flag){
				ans = false; goto OUT;
			}
			swap(l[0],l[1]);
		}
		a = (l[0].y[1]-l[0].y[0])/(l[0].x[1]-l[0].x[0]);
		b = -(l[1].x[1]-l[1].x[0])/(l[1].y[1]-l[1].y[0]);
		if(abs(a-b)<EPS) ans = true;
		else ans = false;
		OUT:
		if(ans) puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 1184
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;

void main() {
    auto tmp = readln.split.to!(int[]);
    auto A = tmp[0], B = tmp[1];
    iota(1,4).any!(C => A * B * C % 2 == 1).pipe!(b => b ? "Yes" : "No").writeln;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}


int main(int argc,char* argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG=1;}
  dprint("start");

  ll N; cin>>N;
  ll a[N]; CINA(a,N); reverse(a,a+N);
  vector<ll> v;
  v.push_back(a[0]);
  for(int i=1;i<N;++i){
    int m = v.size();
    if(a[i]>=v[m-1]){
      v.push_back(a[i]);
    }else{
      auto x = upper_bound(ALL(v),a[i]);
      while(*x==a[i]){
        ++x;
      }
      *x = a[i];
    }
  }
  if(DEBUG){ for(auto x:v){ cout << x << " ";} cout << "\n"; }
  cout << v.size() << "\n";
}

Measured memory_bytes: 5020
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

typedef int Weight;
struct Edge{
    int from, to;
    Weight weight;
    int rev;     // ネットワークフロー時の逆辺
    Edge(int from, int to, Weight weight) :
        from(from), to(to), weight(weight) { }
    Edge(int from, int to, Weight weight, int rev) :
        from(from), to(to), weight(weight), rev(rev){ }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void addFlowEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, 0, g[a].size() - 1));
}
void addUndirectedEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, c, g[a].size() - 1));
}

bool topologicalRecur(const Graph &g, int v, vector<int> &order,
                      vector<int> &color){
    color[v] = 1;
    EACH(i, g[v]){
        if(color[i->to] == 1) return false;
        if(color[i->to] == 2) continue;
        topologicalRecur(g, i->to, order, color);
    }
    order.push_back(v); color[v] = 2;
    return true;
}
bool topologicalSort(const Graph &g, vector<int> &order){
    int n = g.size();
    vector<int> color(n);
    bool res = true;
    for(int i = 0; i < n; ++i) if(color[i] == 0)
        res = res && topologicalRecur(g, i, order, color);
    reverse(ALL(order));
    return res;
}

signed main(){
	int N, M;
	cin >> N >> M;
	Graph g(N + 1), f(N + 1);
	for(int i = 0; i < N - 1 + M; ++i) {
		int A, B;
		cin >> A >> B;
		g[A].push_back(Edge(A, B, 1));
		f[B].push_back(Edge(B, A, 1));
	}
	vector<int> order(N + 1), rev(N + 1);
	topologicalSort(g, order);
	for(int i = 0; i < N; ++i) {
		rev[order[i]] = i;
	}
	vector<int> p(N + 1);
	for(int i = 0; i < N + 1; ++i) {
		if(order[i] == 0) continue;
		int v = order[i];
		if(f[v].size() == 0) {
			p[v] = 0;
			continue;
		}
		int u = f[v][0].to;
		for(auto e: f[v]) {
			if(rev[u] < rev[e.to]) {
				u = e.to;
			}
		}
		p[v] = u;
	}
	for(int i = 1; i <=N; ++i ){
		cout << p[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 22240
s=gets.chop.bytes.map{|e|e-97};k=gets.to_i;i=-1;s.map{x=26-s[i+=1];(s[i]=0;k-=x)if s[i]>0&&k>=x};s[-1]+=k;puts s.map{|e|(e%26+97).chr}*''

Measured memory_bytes: 7660
#include <iostream>
#include <vector>



using namespace std;


int main()
{
    //int s;
    
    vector<int> a(1000010,-1);
    
    cin >> a[0];
    int i=1;
    int r=0;
    
    while(r==0){
        if(a[i-1]%2==0){
            a[i] = a[i-1]/2;
        }else{
            a[i] = 3*a[i-1]+1;
        }
        for(int j=0;j<i;j++){
            if(a[i] == a[j]){
                r=i;
                break;
            }
        }
        i++;
    }
        
    
    cout << r+1 << endl;
    
    
    return 0;
}


Measured memory_bytes: 4096
"""
・なんとか自力AC。大変だった。これ本当に300点か。。
・三角形、角度、三角関数、余弦定理
・2辺の長さが分かっていてもう1辺を知りたいので、角度が分かればいいなーって気持ちになる。
・時刻が与えられるが、短針の微妙な位置とか分からんだろ、ってなる。
・ここで先にD解いたり、Eしばらく考えたりして、E厳し目っぽかったので戻ってきた。
・もう1回、300点でそんな高度な要求がある訳ないという前提の元、考え直してみる。
・ここでやっと、1分毎に動く量を出せば経過時間から割り出せると分かる。
・ちょっとゴニョゴニョして無事角度が出て、さて、2辺と角度が揃ったらどうするんだっけな、とググる。
・余弦定理の公式が出てきて、あぁこんなんあったな、と当てはめる。無事AC。
・こういうのを300点っていう低難度で出せちゃうのは、やっぱり競プロは数学ゲーなんだな、と改めて思わされる所。
"""

import sys
from math import sin, cos, radians, hypot

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

a, b, h, m = MAP()

hm = h*60 + m

heach = hm / 720
meach = m / 60
hdig = heach * 360
mdig = meach * 360

hx = a * cos(radians(hdig))
hy = a * sin(radians(hdig))
mx = b * cos(radians(mdig))
my = b * sin(radians(mdig))

ans = hypot(hx-mx, hy-my)
print(ans)


Measured memory_bytes: 9600
#C
N=int(input())
p=N//100#全部100円の商品を買った場合の買える個数
q=N//105#全部105円
hantei =False
for i in range(q,p+2):#i個の商品を買った上下一円単位は全て埋められる。
  if i*100<=N<=i*105:
    hantei = True
print('1' if hantei else '0')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T> vector<vector<T>> make_vector_2d(int n, int m, T initialValue) {
    auto r = vector<vector<T>>(n);
    for (int i = 0; i < n; i++) r[i] = vector<T>(m,initialValue);
    return r;
}
template <typename T> vector<vector<vector<T>>> make_vector_3d(int n, int m, int l, T initialValue) {
    auto r = vector<vector<vector<T>>>(n);
    for (int i = 0; i < n; i++) {
        r[i] = vector<vector<T>>(m);
        for (int j = 0; j < m; j++) r[i][j] = vector<T>(l, initialValue);
    }
    return r;
}

// ロジック：ある頂点Pを、x以下はAパターン、xより大きく、yより小さい場合はBパターン、y以上はCパターンで分類。
int main() {

    int n, x, y;
    cin >> n >> x >> y;
    int d = y - x;
    vector<int> result(n, 0);

    for (int i = 1; i < n; i++) {
        if (i <= x) { //iがAパターン
            for (int j = i + 1; j <= n; j++) {
                if (j <= x) { //jがAパターン
                    result[j - i]++;
                }
                else if (j < y) { //jがBパターン
                    int dis = std::min(j - i, (x - i) + (1) + (y - j));; //i→X→Y→jと行くパターンの距離と比較し、minをとる。
                    result[dis]++;
                }
                else { //jがCパターン
                    result[j - i - (d - 1)]++;
                }
            }
        }
        else if (i >= y) { //iがCパターン
            for (int j = i + 1; j <= n; j++) { //jもCパターンしかない。
                result[j - i]++;
            }
        }
        else { //iがBパターン
            for (int j = i + 1; j <= n; j++) {
                if (j < y) { //jはBパターン
                    int dis = std::min(j - i, (i - x) + (1) + (y - j)); //i→X→Y→Jと行くパターンの距離と比較し、minをとる。
                    result[dis]++;
                }
                else { //jはCパターン
                    int dis = std::min(j - i, (i - x) + (1) + (j - y)); //i→X→Y→Jと行くパターンの距離と比較し、minをとる。
                    result[dis]++;
                }
            }
        }
    }

    for (int i = 1; i < n; i++) {
        cout << result[i] << endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int N;
    cin >> N;
    int W[N];
    int S = 0, H = 0;
    int min = 1000000;
    for(int i = 0; i < N;i++){
        cin >> W[i];
        S += W[i];
    }
    for(int i = 0;i < N-1;i++){
        S -= W[i];
        H += W[i];
        min = std::min(min, abs(S - H));
    }
    cout << min << endl;
}

Measured memory_bytes: 256
n=int(input())
w=[0 for i in range(101)]
for m in range(2,n+1):
    tmp=m
    for j in range(2,m+1):
        while tmp%j==0:
            w[j]+=1
            tmp//=j
def num(a):
    return len(list(filter(lambda x:x>=a-1,w)))
print(num(75)+num(25)*(num(3)-1) + num(15) * (num(5) - 1)
+ num(5) * (num(5) - 1) * (num(3) - 2) // 2)

Measured memory_bytes: 63540
//
// Created by ?????°?????? on 2016/03/21.
//

#include <iostream>
using namespace std;

int main(){
    int n,x;
    int A[10001] ={0};
    cin >> n;

    for (int i = 0; i < n ; ++i) {
        cin >> x;
        A[x]++;
    }
    bool s = false;
    for (int i = 0; i <= 10000 ; ++i) {
        for (int j = 0; j < A[i] ; ++j) {
            if(s) cout << " ";
            else s = true;
            cout << i;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1208
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, x = rl()
A = rl()
A.sort()
A = np.array(A)
A_cum = A.cumsum()
answer = 0
if A_cum[-1] < x:
    answer = N - 1
for i in range(N):
    if A_cum[i] == x:
        answer = i+1
        break
    elif A_cum[i] > x:
        answer = i
        break
        
print(answer)
# 48

Measured memory_bytes: 12504
"""
幸福な人(HP)でなく不幸な人(UHP)を数える。最終的にHPは HP = N - UHP で求めることができる。
以下のような並びを考える。

    L RR LLLL R L RRR L R LLLL

同じ記号ごとにスペースで区切っている。この中で不幸な人は、両端にいる2人と、スペースで
区切られたグループに付き1人である。このようにして不幸な人の人数を数えることができた。

また、(l, r) の人々を180度回転することによって、回転するグループ両端以外の幸福な人（不幸な人）
の人数は変化しない。両端の幸不幸が変化するのみである。

境界以外を l or r に選んだとしても、幸不幸の数は変化しない。
両端でない facing, unfacing な境界をそれぞれ l, r に選ぶと、
幸福な人を2人増やすことができる。

k が十分に大きい場合、十分な数の操作を行うことによって幸福な人を最大 N - 1 人に
することができる。
"""


n, k = map(int, input().split())
s = input()

hpp = 0
for i in range(n - 1):
    if s[i] == s[i + 1]:
        hpp += 1

# k 回の操作で幸福な人を 2k 人増やすことができる
hpp += 2 * k

# N - 1 人 or k 回で N - 1 人に満たない場合は k 回で幸福にした人の数 + もともと幸福な人。
print(min(n - 1, hpp))



Measured memory_bytes: 3316
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin>>s;
  int a,b,mon;
  a = s[5] - '0';
  b = s[6] - '0';
  mon = 10*a+b;
  if (mon > 4) cout<<"TBD"<<endl;
  else if (mon <= 4) cout<<"Heisei"<<endl;
  return 0;
}

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

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

    rep(i,s.size()){
        cout<<'x';
    }
    cout <<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	string s;
	ll ans=0;
	cin>>n>>s;
	for(int i=0;i<n-2;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')ans++;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
class Problem
  attr_accessor :a, :b, :n, :m, :h, :w, :x, :y

  def initialize
    @x,@y=gets.to_s.split.map{ |v| v.to_i }
  end

  def solve
    0.upto(x) do |kame|
      turu = x - kame
      if y == kame * 4 + turu * 2
        return true
      end
    end
    false
  end

  def show(ans)
    puts ans ? "Yes" : "No"
  end
end

Problem.new.instance_eval do
  show(solve)
end


Measured memory_bytes: 14268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int k; cin>>k;
    int cnta = 0;
    int n = s.size();
    for(int i=0;i<n;i++){
        char c = s[i];
        if(c == 'a') {
            cnta++;
            continue;
        }
        int t = 'z'-c+1;
        if(k>=t){
            k-=t;
            s[i]='a';
            cnta++;
        }
    }
    if(cnta == n || k>0){
        // 残り=kぶんだけ最後を回す
        char c = s[n-1]+(k%26);
        s[n-1] = c;
        cout<<s<<endl;
        return 0;
    }
    cout<<s<<endl;
}

Measured memory_bytes: 592
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N;
int main(void) {
    cin >> N;
    ll a[333][333];
    ll d[333][333];
    ll i, j, k;
    
    for(i=0; i<N; i++)
        for(j=0; j<N; j++) {
            cin >> a[i][j];
            d[i][j]=a[i][j];
        }
    
    for(k=0; k<N; k++) {
        for(i=0; i<N; i++) {
            for(j=0; j<N; j++) {
                if(k==i || k==j || i==j || d[i][k]==INF || d[k][j]==INF) continue;
                if(d[i][k]+d[k][j]==a[i][j]) d[i][j]=INF;
                else if(d[i][k]+d[k][j]<a[i][j]) {
                    pt(-1);
                    return 0;
                }
            }
        }
    }
    
    ll ans=0;
    for(i=0; i<N; i++)
        for(j=0; j<N; j++)
            if(d[i][j]!=INF) ans+=d[i][j];
    
    pt(ans/2);
    
    
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 101001;//ここを問題の制約を見ながらいじる．配列の確保に使う．
//int A[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．

// Main program
void solve(){
  ll N;
  string S[50],X;
  ll T[50];
  cin >> N ;
  ll sum =0;
  
  for(int i=0;i<N;i++){
    cin >> S[i];
    cin >> T[i];
  }
  cin >> X;

  bool flag=false;
  for(int i=0;i<N;i++){
    if(flag){
      sum+=T[i];
    }
    if(X==S[i]){
      flag = true;
    }
  }
  
  cout << sum;
   
  return;

}

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







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

#define FOR(i, n, m) for(int i = n; i < int(m); ++i)
#define REP(i, n) for(int i = 0; i < int(n); ++i)

int main(){
  string S; cin >> S;
  int N = S.size();
  long long cnt = 0, findIdx = 0;
  REP(i, N){
    if(S[i] == 'W'){
      cnt += i - (findIdx++);
    }
  }
  
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

int main() {
	int64_t x;
	cin >> x;

	int64_t n = x / 11;
	n *= 2;
	int64_t m = x % 11;

	if (m) {
		if (m <= 6) {
			n++;
		}
		else {
			n += 2;
		}
	}
	
	cout << n << endl;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, c, ans, tv, s[31][100010], t[31][100010], fl[31];
int main(){
	cin >> n >> c;
	for(int i=0;i<n;i++){
		int st, fi, ch;
		cin >> st >> fi >> ch;
		s[ch][st]++;
		t[ch][fi]++;
	}
	for(int j=1;j<=c;j++){
		for(int i=1;i<100010;i++){
			if(s[j][i]==1&&t[j][i]==1){
				s[j][i]--;
				t[j][i]--;			
			}
		}	
	}
	for(int i=1;i<100010;i++){
		for(int j=1;j<=c;j++){
			if(s[j][i]==1){
				fl[j]++;
				tv++;
			}
		}
		ans = max(ans ,tv);
		for(int j=1;j<=c;j++){
			if(t[j][i]==1){
				fl[j]--;
				tv--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
int main(){
    int a, b, c = 0;
    cin >> a >> b;
    for(int i = 0; i <= 20; i++){
        if( 1 + a * i  - i >= b) {
            c = i; break;
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
# セグメント木　verify
class SegTree():
    def __init__(self,N,function, basement):
        self.n = N
        self.K = (self.n-1).bit_length()
        self.func = function
        self.basement = basement
        self.seg = [basement]*2**(self.K+1)

        for i in range(2**(self.K)-2, -1, -1):
            self.seg[i] = self.func(self.seg[2*i+1], self.seg[2*i+2])

    def update(self, k, value):
        # 0-indexでa[k]の値をvalueに変更
        k += 2**self.K-1
        self.seg[k] = value
        while k:
            k = (k-1)//2
            self.seg[k] = self.func(self.seg[k*2+1], self.seg[k*2+2])

    def query(self, p, q):
        # 0-indexで[p,q)の値を取得する
        if q <= p:
            return self.basement
        num = 2**self.K
        p += num-1
        q += num-2
        res = self.basement
        while q-p > 1:
            if p & 1 == 0:
                res = self.func(res, self.seg[p])
            if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.func(res, self.seg[p])
        else:
            res = self.func(self.func(res, self.seg[p]), self.seg[q])
        return res
N,Q=map(int,input().split())
que=[tuple(map(int,input().split())) for i in range(Q)]
Seg=SegTree(N,min,2**31-1)
for index,u,v in que:
    if index==0:
        Seg.update(u,v)
    else:
        print(Seg.query(u,v+1))


Measured memory_bytes: 23096
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        long H = in.i();
        long W = in.i();

        long a = W / 3;
        long b = (W - a) / 2;
        long c = W - a - b;
        long ans = (c - a) * W;

        a = H / 3;
        b = (H - a) / 2;
        c = H - a - b;
        ans = Math.min(ans, (c - a) * H);

        a = H / 2;
        b = H - a;
        for (int i = 1; i < W; i++) {
            long s1 = a * i;
            long s2 = b * i;
            long s3 = (W - i) * H;
            ans = Math.min(ans, max(s1, s2, s3) - min(s1, s2, s3));
        }

        a = W / 2;
        b = W - a;
        for (int i = 1; i < H; i++) {
            long s1 = a * i;
            long s2 = b * i;
            long s3 = (H - i) * W;
            ans = Math.min(ans, max(s1, s2, s3) - min(s1, s2, s3));
        }

        out.println(ans);
    }

    static long max(long a, long b, long c) {
        return Math.max(a, Math.max(b, c));
    }

    static long min(long a, long b, long c) {
        return Math.min(a, Math.min(b, c));
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


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

int main()
{
    int N;
    cin >> N;

    string S;
    cin >> S;

    unsigned long len = 0;
    for (unsigned long startL1 = 0; startL1 < N; startL1++) {
        for (unsigned long startL2 = startL1 + 1; startL2 < N; startL2++) {
            for (unsigned long end = len; end < startL2 - startL1; end++) {
                string s1 = S.substr(startL1, end + 1);
                string s2 = S.substr(startL2, end + 1);

                if (s1 == s2) {
                    len = max(len, s1.size());
                } else {
                    break;
                }
            }
        }
    }

    cout << len << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	void doIt(){
		Scanner sc = new Scanner(System.in);
		Player[] group = new Player[8];
		Player[] top_two = new Player[6];
		Player[] sub = new Player[6];
		
		for(int i=0; i<3; i++){
			for(int j=0; j<8; j++){
				group[j] = new Player();
				group[j].number = sc.nextInt();
				group[j].time = sc.nextDouble();
			}
			//??????????????????
			Arrays.sort(group);
			//????????¨??????????¨????
			top_two[0+i*2] = group[0]; top_two[1+i*2] = group[1];
			
			//????????¨???????????°?????????
			sub[0+i*2] = group[2];
			sub[1+i*2] = group[3];
		}
		//????????¨???????????????
		for(int i=0; i<6; i++){
			System.out.println(top_two[i].number + " " + top_two[i].time);
		}
		//????????¨???????????°??????????????´?????¨??????
		Arrays.sort(sub);
		for(int i=0; i<2; i++){
			System.out.println(sub[i].number + " " + sub[i].time);
		}
		
	}
	
	public static void main(String[] args){
		new Main().doIt();
	}

	class Player implements Comparable<Player>{
		int number=0;
		double time=0;
		
		@Override
		public int compareTo(Player p) {
			int r=-1;
			if(this.time>p.time) r=1;
			else if(this.time==p.time) r=0;
			return r;
		}
	}
	
}

Measured memory_bytes: 28288
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
l = [a,b,c,d,e]
ans = 'Yay!'
for i in range(len(l)):
    for x in range(i+1,len(l)):
        if abs(l[i] - l[x]) > abs(k):
            ans = ':('
print(ans)

Measured memory_bytes: 3064
n,m,q = map(int,input().split())
abcd = []
for i in range(q):
    abcd.append(list(map(int,input().split())))
ans = 0

def dfs(s):
    if len(s) == n:
        global ans
        count = 0
        for a,b,c,d in abcd:
            a -= 1
            b -= 1
            if s[b] - s[a] == c:
                count += d
        ans = max(ans, count)
        return
    for i in range(s[-1], m+1):
        dfs(s + [i])
for i in range(1,m+1):
    dfs([i])
print(ans)


Measured memory_bytes: 72748
#include <iostream>
#include <stdio.h>

#define MAX_N 100
#define MAX_X 100
#define INF 1'000'000'000

using namespace std;

int X[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> X[i];
  }
  int res = INF;
  for (int i = 1; i <= MAX_X; ++i) {
    int t = 0;
    for (int j = 0; j < N; ++j) {
      t += (i - X[j]) * (i - X[j]);
    }
    res = min(res, t);
  }
  printf("%d\n", res);
}

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

using namespace std;

const int Nmax = 808, inf = Nmax*Nmax;

int i, j, n, m, l, c, k, d[Nmax][Nmax], ans = inf;
char a[Nmax][Nmax];
queue< pair<int,int> > q;

int dist(int x, int y)
{
    int nr = min(min(x-1, n-x), min(y-1, m-y));
    return nr/k + (nr%k > 0);
}

int main()
{
   /// freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n >> m >> k;
    for(i=1; i<=n; ++i) cin >> (a[i]+1);

    for(i=1; i<=n; ++i)
        for(j=1; j<=m; ++j)
            if(a[i][j] == 'S') l = i, c = j;
                else d[i][j] = inf;

    q.push({l, c});
    d[l][c] = 0;

    while(!q.empty())
    {
        l = q.front().first;
        c = q.front().second;
        q.pop();

        if(d[l][c+1] == inf && a[l][c+1] == '.') d[l][c+1] = d[l][c]+1, q.push({l, c+1});
        if(d[l][c-1] == inf && a[l][c-1] == '.') d[l][c-1] = d[l][c]+1, q.push({l, c-1});
        if(d[l+1][c] == inf && a[l+1][c] == '.') d[l+1][c] = d[l][c]+1, q.push({l+1, c});
        if(d[l-1][c] == inf && a[l-1][c] == '.') d[l-1][c] = d[l][c]+1, q.push({l-1, c});
    }

    for(i=1; i<=n; ++i)
        for(j=1; j<=m; ++j)
            if(d[i][j] <= k)
                ans = min(ans, dist(i, j));
    cout << ans + 1 << '\n';

    return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
long long b[100005];
long long a[100005];
long long t[100005];
int cur;
int main(){
	int n,q;
	cin>>n>>q;
	cur=1;
	b[1]=n;
	while(q--){
		long long x;
		cin>>x;
		while(cur&&b[cur]>=x) cur--;
		cur++;
		b[cur]=x;
	}
	t[cur]=1;
	for(int i=cur;i>=1;i--){
		long long k=b[i];
		while(true){
			if(k<=b[1]){
				break;
			}
			int j=lower_bound(b+1,b+1+cur,k)-b-1;
			t[j]+=t[i]*(k/b[j]);
			k%=b[j];
		}
		a[k]+=t[i];
	}
	for(int i=n;i>=1;i--){
		a[i]+=a[i+1];
	}
	for(int i=1;i<=n;i++) cout<<a[i]<<" ";
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 1000000007;
    int n;
    std::cin >> n;

    i64 ret = 1;
    int ss[] { 0, 0, 0 };
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        i64 f = 0;
        for (int &s : ss) if (s == a && !f++) s++;
        ret = ret * f % mod;
    }

    std::cout << ret << std::endl;

    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }

lli calc(lli a,lli b,lli x){
    LOG2((a*x)/b,(x/b)*a);
    return (a*x)/b - (x/b)*a;
}

void func(long long A, long long B, long long N){


    REP(i,0,N){
        
        LOG2(i,calc(A,B,i));
    }
    if(A<=B){
        if(N>=B){
            cout<<A-1<<endl;
        }
        else{
            cout<<calc(A,B,N)<<endl;
        }
    }
    else{//A>B}

        cout<<calc(A,B,min(N,B-1))<<endl;
    }

/*
    if(A<B)cout<<min(A-1,N)
    if(A>B)cout<<min(B-1,N)<<endl;
    */
}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long N;
    scanf("%lld",&N);
    func(A, B, N);
    return 0;
}


Measured memory_bytes: 3800