akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A,*B;

  int C[VMAX+1];
  int n,i,j;

  scanf("%d",&n);

  A = (unsigned short *)malloc(sizeof(short) * n+1);
  B = (unsigned short *)malloc(sizeof(short) * n+1);
  for(i=0;i<=VMAX;i++) C[i]=0;

  for(i=0;i<n;i++){
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];

  for(j=1;j<=n;j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  return 0;
}



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

int main() {
  int a,b;
  cin >>a >>b;
  vector<int> W={0,13,1,2,3,4,5,6,7,8,9,10,11,12};
  if(W.at(a)>W.at(b)){
    cout <<"Alice" <<endl;
  }
  else if(W.at(a)==W.at(b)){
    cout <<"Draw" <<endl;
  }
  else{
    cout <<"Bob" <<endl;
  }
}

Measured memory_bytes: 256
/* 
 * File:   main.c
 * Author: s1252007
 *
 * Created on June 15, 2018, 10:57 AM
 */

#include <stdio.h>
#include <stdlib.h>

void insertionSort(
    int *A,
    int N
);

/*
 * 
 */
int main(int argc, char** argv) {
    int size;
    int *A;
    
    scanf("%d", &size);
    A = (int *)malloc(sizeof(int) * size);
    if (A == NULL) return EXIT_FAILURE;
    for (int ix = 0; ix < size; ++ix)
    {
        scanf("%d", &A[ix]);
        if (ix > 0) printf(" ");
        printf("%d", A[ix]);
    }
    printf("\n");
    insertionSort(A, size);
    return (EXIT_SUCCESS);
}

void insertionSort(int *A, int N) // N個の要素を含む0-オリジンの配列A
{   
    int v, j;
    for (int i = 1; i <= N-1; ++i)
    {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        
        for (int p = 0; p < N; ++p) 
        {
            if (p > 0) printf(" ");
            printf("%d", A[p]);
        }
        printf("\n");
    }
}




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

using namespace std;

#define endl '\n'

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

  int n, k;
  cin >> n >> k;
  vector<int> stones(n);
  vector<int> dp(n, 1e9);
  for (int i = 0; i < n; i++) {
    cin >> stones[i];
  }
  dp[0] = 0;
  dp[1] = abs(stones[0] - stones[1]);
  for (int i = 2; i < n; i++) {
    for (int j = 1; (i - j) >= 0 && j <= k; j++) {
      dp[i] = min(dp[i], dp[i - j] + abs(stones[i] - stones[i - j]));
    }
  }
  cout << dp[n - 1] << endl;

	return 0;
}


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

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

int main()
{
  int N, M, P;

  cin >> N >> M >> P;
  const ll INF = 1LL << 50;
  const int NMAX = 2500;
  const int MMAX = 5000;
  int a[MMAX];
  int b[MMAX];
  ll c[MMAX];
  for (int i = 0; i < M; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    --(a[i]);
    --(b[i]);
    c[i] = P - c[i];
  }
  ll dist[NMAX];
  dist[0] = 0;
  for (int i = 1; i < N; ++i) {
    dist[i] = INF;
  }
  for (int loop = 0; loop < N - 1; ++loop) {
    for (int i = 0; i < M; ++i) {
      if (dist[a[i]] == INF) continue;
      if (dist[b[i]] > dist[a[i]] + c[i]) {
        dist[b[i]] = dist[a[i]] + c[i];
      }
    }
  }
  ll ans = - dist[N - 1];
  bool negative[NMAX];
  for (int i = 0; i < N; ++i) {
    negative[i] = false;
  }
  for (int loop = 0; loop < N; ++loop) {
    for (int i = 0; i < M; ++i) {
      if (dist[a[i]] == INF) continue;
      if (dist[b[i]] > dist[a[i]] + c[i]) {
        dist[b[i]] = dist[a[i]] + c[i];
        negative[b[i]] = true;
      }
      if (negative[a[i]]) {
        negative[b[i]] = true;
      }
    }
  }

  if (negative[N - 1]) {
    cout << -1;
  } else {
    cout << max(0LL, ans);
  }

  return 0;
}




Measured memory_bytes: 384
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;

int main() {
	int i, j, k;
	int H, W;
	char S[102][102];
	cin >> H >> W;
	for (i = 0; i < H; ++i) {
		for (j = 0; j < W; ++j) {
			cin >> S[i][j];
		}
	}
	
	for (i = 0; i < W + 2; ++i) {
		cout << "#";
	}
	cout << endl;

	for (i = 0; i < H; ++i) {
		cout << "#";
		for (j = 0; j < W; ++j) {
			cout << S[i][j];
		}
		cout << "#" << endl;
	}
	//cout << endl;
	for (i = 0; i < W + 2; ++i) {
		cout << "#";
	}
	cout << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m,d = LI()
    k = 2*(n-d) if d != 0 else n
    ans = (m-1)*k/(n*n)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39152
n=int(input())
l=[]
a=[]
b=[]
for i in range(n):
    m=[int(j) for j in input().split()]
    
    for k in m:
        if k%2==0:
            l.append(k)
    
    for p in l:
        if p%3==0 or p%5==0:
            a.append(p)
        else:
            b.append(p)
 
    if len(a)==len(l):
        print("APPROVED")
    else:
        print("DENIED")
    break

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

int main()
{
    string a[3]={"Sunny","Cloudy","Rainy"};
    string s;
    int j;
    cin>>s;
    for(int i=0;i<3;i++){ 
            if(a[i]==s)j=i;
    } 
    cout<<a[(j+1)%3];

    return 0;
}


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

const int N = 1005;

vector <int> g[N];
int x[N], w[N];

int dfs(int u) {
    map <int, int> cnt;
    cnt[x[u]] = 0;
    for (auto & v : g[u]) {
        if (! dfs(v)) return 0;
        map <int, int> tmp;
        for (auto & it : cnt) {
            if (it.first - w[v] >= 0)
                tmp[it.first - w[v]] = it.second + x[v];
            if (it.first - x[v] >= 0)
                tmp[it.first - x[v]] = it.second + w[v];
        }
        cnt = tmp;
    }
    if (cnt.empty()) return 0;
    w[u] = cnt.begin()->second;
    return 1;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 2, p; i <= n; i ++) {
        scanf("%d", &p);
        g[p].emplace_back(i);
    }
    for (int i = 1; i <= n; i ++)
        scanf("%d", x + i);
    puts(dfs(1) ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define ll long long

ll data[4010];
bool out[4010];

int main(){
  int i,j,k,n;
  ll a, b;
  int id;

  while(scanf("%d",&n)){
    if(n == 0) break;
    vector<int> ids;
    bool f = false;

    rep(i,4010) data[i] = 0;
    rep(i,4010) out[i] = false;

    while(n--){
      scanf("%d %lld %lld",&id,&a,&b);

      ids.push_back(id);
      data[id] += a * b;
      if(data[id] >= 1000000LL) out[id] = true;
    }

//    rep(i,ids.size()) cout << "debug " << ids[i] << endl;
    rep(i,ids.size()) if(out[ids[i]]){
      printf("%d\n",ids[i]);
      out[ids[i]] = false;
      f = true;
    }

    if(!f) puts("NA");
  }

  return 0;
}

Measured memory_bytes: 0
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 2e5 + 5;
const int OO = 2e9;

int n,k,a[N],f[N],ans;
vector<int>  v;

void init() {



}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;

    for(int i=0;i<n;++i) {

        cin >> a[i];
        f[a[i]]++;

    }

    for(int i=1;i<N;++i) {

        if(f[i]) v.pb(f[i]);

    }

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

    for(int i=0;i<max(0,int(v.size())-k);++i) {

        ans += v[i];

    }

    cout << ans << '\n';

    return 0;

}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int res = 0;
    vector<int> v;
    for (int i = 0; i < n; i++){
        int k;
        cin >> k;
        v.push_back(k);
    }
    for (int i = 1; i < n - 1; i++){
        if (v[i] > min(v[i+1], v[i-1]) && v[i] < max(v[i+1], v[i-1])){
            res++;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
*A, = map(int, input().split())
dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
for _ in range(M):
    B, C = map(int, input().split())
    if C in dic:
        dic[C] += B
    else:
        dic[C] = B
dic = list(map(lambda x: list(x), sorted(dic.items(), reverse=True)))
i = 0
ans = 0
for _ in range(N):
    ans += dic[i][0]
    dic[i][1] -= 1
    if dic[i][1] == 0:
        i += 1
print(ans)

Measured memory_bytes: 64912
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int a,b;
char ch;
bool bo=true;
int main()
{
	cin>>a>>b;
	for(int i=0;i<a;i++){
		cin>>ch;
		if((int(ch)-48<0) || (int(ch)-48>9))
		bo=false;
	}
	cin>>ch;
	if(ch!='-')
	bo=false;
	for(int i=0;i<a;i++){
		cin>>ch;
		if((int(ch)-48<0) || (int(ch)-48>9))
		bo=false;
	}
	if(bo==true)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl; 
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

ll gcd(ll a, ll b)
{
    ll r = a % b;
    if (r == 0)
        return b;
    return gcd(b, r);
}

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

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

    if (a > b)
        swap(a, b);

    OP(lcm(a, b));

    return 0;
}

Measured memory_bytes: 256
# A - Kenken Race
import re
n,a,b,c,d = map(int,input().split())
s = input()

ts = s[a-1:max(c,d)]
if (re.search(r"##",ts)):
    print("No")
    exit()

# 追い越す場合
if (c > d):
    # 追い越せるポイント[...]が存在
    if (re.search(r"\.\.\.",s[b-1:d])):
        print("Yes")
    else :
        if ((s[b-2] == "#")|(s[b] == "#"))&((s[d-2] == "#")|(s[d] == "#")):
            print("No")
        else :
            print("Yes")
else:
    print("Yes")

Measured memory_bytes: 3700
local mma = math.max
local n, k = io.read("*n", "*n")
local edge = {}
local len = {}
local childcnt = {}
local parent = {}
for i = 1, n do
  edge[i] = {}
  len[i] = -1
  childcnt[i] = 0
  parent[i] = 0
end
len[1] = 0
local ret = io.read("*n") == 1 and 0 or 1
for i = 2, n do
  local a = io.read("*n")
  table.insert(edge[a], i)
  table.insert(edge[i], a)
end
local tasks = {1}
for it = 1, n do
  local src = tasks[it]
  for i = 1, #edge[src] do
    local dst = edge[src][i]
    if len[dst] == -1 then
      len[dst] = len[src] + 1
      table.insert(tasks, dst)
      childcnt[src] = childcnt[src] + 1
      parent[dst] = src
    end
  end
end
local maxlen = {}
tasks = {}
for i = 1, n do
  maxlen[i] = len[i]
  if childcnt[i] == 0 then
    table.insert(tasks, i)
  end
end
for i = 1, n - 1 do
  local c = tasks[i]
  local p = parent[c]
  if k < maxlen[c] then
    if maxlen[c] - len[c] == k - 1 then
      ret = ret + 1
    else
      maxlen[p] = mma(maxlen[p], maxlen[c])
    end
  else
    maxlen[p] = mma(maxlen[p], maxlen[c])
  end
  childcnt[p] = childcnt[p] - 1
  if childcnt[p] == 0 then
    table.insert(tasks, p)
  end
end
print(ret)


Measured memory_bytes: 26888
#include <stdio.h>
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		cin >> a.at(i);
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	int A = 0, B = 0;
	for (int i = 0; i < N; i++)
	{
		if (i % 2 == 0)
			A += a.at(i);
		else
			B += a.at(i);
	}
		cout <<A-B << endl;
}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
G = [[] for _ in range(n)]
q = deque([])
d = [float("inf")]*n
p = [0]*n
for _ in range(m):
    u, v = map(int, input().split())
    G[u-1].append(v-1)
    G[v-1].append(u-1)
d[0] = 0
q.append(0)
while q:
    v = q.popleft()
    for u in G[v]:
        if d[v] + 1 < d[u]:
            d[u] = d[v] + 1
            p[u] = v + 1
            q.append(u)
print("Yes")
for i in range(1, n):
    print(p[i])

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

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if((A == B && C != A)
		|| (B == C && A != B)
		|| (C == A && B != C)){
			cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;

const int MAXN = 3003;
long long dp[MAXN][MAXN];

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

	int n;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	
	for (int i = 0; i < n; ++i) dp[i][i] = a[i];
	for (int d = 1; d < n; d++) {
		for (int i = 0; i + d < n; ++i) {
			dp[i][i+d] = max(a[i] - dp[i+1][i+d], a[i+d] - dp[i][i+d-1]);
		}
	}
	
	//~ for (int i = 0; i < n; i++) {
		//~ for (int j = 0; j < n; j++) cout << dp[i][j] << ' ';
		//~ cout << '\n';
	//~ }
	cout << dp[0][n-1] << endl;
}


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

using namespace std;
using Point = complex< double >;
const double EPS = 1e-10, PI = acos(-1);

bool eq(double a, double b){ return fabs(a-b) < EPS; }

istream &operator>> (istream &is, Point &p) {
  double a, b;
  is >> a >> b;
  p = Point(a, b);
  return is;
}

ostream &operator<< (ostream &os, Point &p) {
  return os << fixed << setprecision(10) << p.real() << " " << p.imag();
}

bool operator<(const Point &a, const Point &b) {
  return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
}

// rotate Φ(rad)
// x = r * cos(θ + Φ)
//   = r * cos(θ) * cos(Φ) - r * sin(θ) * sin(Φ)
//   = x * cos(Φ) - y * sin(Φ) (∵ cos(θ) = x/r, sin(θ) = y/r)  
Point rotate(double phi, const Point &p) {
  double x = p.real(), y = p.imag();
  return Point(x * cos(phi) - y * sin(phi), x * sin(phi) + y * cos(phi));
}

double radian_to_degree(double r) {
  return (r * 180.0 / PI);
}

double degree_to_radian(double d) {
  return (d * PI / 180.0);
}

struct Line{
  Point a, b;

  Line() = default;

  Line(Point a, Point b) : a(a), b(b){}

  Line(double A, double B, double C){
    //ax + by = c
    if(eq(A, 0)){
      a = Point(0, C/B), b = Point(1, C/B);
    }else if(eq(B, 0)){
      a = Point(C/A, 0), b = Point(C/A, 1);
    }else{
      a = Point(0, C/B), b = Point(C/A, 0);
    }
  }

  friend istream &operator>>(istream &is, Line &a) {
    return is >> a.a >> a.b;
  }
  friend ostream &operator<<(ostream &os, Line &a) {
    return os << a.a << " to " << a.b;
  }
};

struct Segment: Line{
  Segment() = default;

  Segment(Point a, Point b) : Line(a, b) {}
};

struct Circle {
  Point p;
  double r;

  Circle() = default;

  Circle(Point p, double r): p(p), r(r){}
};

using Points = vector<Point>;
using Polygon = vector<Point>;
using Segments = vector<Segment>;
using Lines = vector<Line>;
using Circles = vector<Circle>;

double cross(const Point &a, const Point &b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(const Point& a, const Point &b) {
  return a.real() * b.real() + a.imag() * b.imag();
}


// https://mathtrain.jp/projection
Point projection(const Line &l, const Point &p){
  double t = dot(p - l.a, l.a-l.b) / norm(l.a - l.b);
  return l.a + (l.a - l.b) * t;
}

Point projection(const Segment &l, const Point &p){
  double t = dot(p - l.a, l.b-l.a) / norm(l.a - l.b);
  return l.a + (l.b - l.a) * t;
}

Point reflection(const Line &l, const Point &p){
  return p + (projection(l, p) - p) * 2.0;
}

int main(){
  Line l;
  cin >> l;
  int q;
  cin >> q;
  while(q--){
    Point p; cin >> p;
    Point x = reflection(l, p);
    cout << x << endl;
  }
}


Measured memory_bytes: 3360
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    int m = n;
    int ans = 0;
    while (n > 0){
        ans += n % 10;
        n /= 10;
    }
    if (m % ans == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int a[200002],b[200002],c,i,j;
int tong[2][30];
int bj[2][200002];
int main(){
	string s1,s2;
	cin>>s1>>s2;int lon=s1.size();
	for(i=0;i<lon;i++){
		a[i+1]=s1[i]-'a'+1;
		if(tong[0][a[i+1]]==0) tong[0][a[i+1]]=i+1;
		else bj[0][i+1]=tong[0][a[i+1]],tong[0][a[i+1]]=i+1;
		b[i+1]=s2[i]-'a'+1;
		if(tong[1][b[i+1]]==0) tong[1][b[i+1]]=i+1;
		else bj[1][i+1]=tong[1][b[i+1]],
			tong[1][b[i+1]]=i+1;
	}
	for(i=1;i<=lon;i++)
		if(bj[0][i]!=bj[1][i]){
			cout<<"No";return 0;
		}
	cout<<"Yes";
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

long long x(long long a) {
    if (a % 4 == 0) return a;
    if (a % 4 == 1) return 1;
    if (a % 4 == 2) return a + 1;
    return 0;
}
int main() {
    long long a, b;
    cin >> a >> b;
    cout << (x(b) ^ x(a - 1)) << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc141/tasks/abc141_e

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 5*1e3;
const ull B = 100000007;

int N;
char S[N_MAX + 1];

map<ull, int> mp;

void solve() {
  ull t = 1;
  ull h0 = 0;
  int ans = 0;
  FOR(l, 1, N / 2) {
    // printf("l: %d\n", l);
    mp.clear();
    t *= B;
    ull h = h0 = h0 * B + S[l - 1];
    mp[h] = l - 1;
    // printf("  i:%d, h:%llu\n", l - 1, h);
    FOR(i, l, N - 1) {
      h = h * B + S[i] - S[i - l] * t;
      // printf("  i:%d, h:%llu\n", i, h);
      if (mp.count(h) == 0) {
        mp[h] = i;
      } else if (i >= mp[h] + l) {
        ans = l;
        break;
      }
    }
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d", &N);
  scanf("%s", S);
}

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


Measured memory_bytes: 640
n,m = map(int,input().split())
h = list(map(int,input().split()))
h.insert(0,0)

s = [1]*(n+1)
s[0] = -1
for i in range(m):
    a,b = map(int,input().split())
    if h[a] > h[b]:
        s[b] = 0
    elif h[a] == h[b]:
        s[a] = 0
        s[b] = 0
    else:
        s[a] = 0

print(s.count(1))






Measured memory_bytes: 20120
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, M = MAP()

ab = [LIST() for _ in range(M)]
ab.sort(key = lambda x: x[1])

ans = 0
tmp = -INF
for l, r in ab:
    if tmp <= l:
        ans += 1
        tmp = r

print(ans)



Measured memory_bytes: 30028
#include <iostream>
#include <string>

int main(void)
{
	using namespace std;
	int turn, point1 = 0, point2 = 0
	;
	string card1, card2;
	cin >> turn;
	while(turn--)
	{
		cin >> card1 >> card2;
		if(card1 > card2)
			point1 += 3;
		else if(card2 > card1)
			point2 += 3;
		else
		{
			point1 ++;
			point2 ++;
		}
	}
	cout << point1 << " " << point2 << endl;
	return 0;
}


Measured memory_bytes: 3172
#include <stdio.h>

int main(void){
  int n,m,L[100005],R[100005],L1=0,R1=100005;
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d%d",&L[i],&R[i]);
  }
  for(int i=0;i<m;i++){
    if(L[i]>L1) L1=L[i];
    if(R1>R[i]) R1=R[i];
    }
  if(R1-L1<0){
    printf("0\n");
    return 0;
  }
  printf("%d\n",R1-L1+1);

  return 0;
}

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

typedef long long ll;
const int N = 2000006;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	int x = n%1000;
	x = 1000 - x;
	x %= 1000;
	cout<<x;
	
	return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int main(){

  int N1,N2,i,j,key,count=0,left,mid,right;

  scanf("%d", &N1);
  int A[N1];
  for(i=0;i<N1;i++)scanf("%d",&A[i]);
  scanf("%d", &N2);
  int B[N2];
  for(i=0;i<N2;i++)scanf("%d",&B[i]);

  for(i = 0 ; i< N2 ; i++){
    j = 0;
    key = B[i];
    left = 0;
    right = N1;
    while(left < right){
      mid = (left + right) / 2;
      if (A[mid] == key){
	count++;
	break;
      }
      else if(key < A[mid])right = mid;
      else left = mid + 1;
      j++;
    }
  }

  printf("%d\n",count);

  return 0;
}






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

int main() {
  ll x;cin>>x;
  ll m = 100;
  int cnt=0;
  while (m < x) {
    m = (ll)(m * 1.01);
    cnt++;
  }
  cout<<cnt;
}


Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N, K := ReadInt(), ReadInt()
	A := ReadInts(N)
	m := make(map[int]int)
	keys := make([]int, 0)
	for _, a := range A {
		if m[a] == 0 {
			keys = append(keys, a)
		}
		m[a]++
	}
	sort.Slice(keys, func(i, j int) bool {
		return m[keys[i]] < m[keys[j]]
	})
	c := 0
	for len(keys) > K {
		c += m[keys[0]]
		keys = keys[1:]
	}
	fmt.Println(c)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 20092
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    S = input()
    if S == 'AAA' or S == 'BBB':
        print('No')
    else:
        print('Yes')
    return


# B
def B():
    N, A, B = LI()
    ans = N // (A + B) * A + min(N % (A + B), A)
    print(ans)
    return


# C
def C():
    A, B = LI()
    for i in range(1, 1001):
        if i * 8 // 100 == A and i * 10 // 100 == B:
            print(i)
            return
    print(-1)
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 38292
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {

fast();

{
  char a[3][3];
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      cin>>a[i][j];
    }
  }
cout<<a[0][0]<<a[1][1]<<a[2][2]<<endl;
  
  
  

}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,MAXN=5e5+10;
ll Fac[MAXN],InF[MAXN];
inline ll fpow(ll a,ll x){
    ll ans=1;
    for(;x;x>>=1,a=a*a%MOD) if(x&1) ans=ans*a%MOD;
    return ans;
}
inline void pre(){
    Fac[0]=1;
    for(int i=1;i<=5e5;i++)
        Fac[i]=Fac[i-1]*i%MOD;
    InF[int(5e5)]=fpow(Fac[int(5e5)],MOD-2);
    for(int i=5e5-1;i>=0;i--)
        InF[i]=InF[i+1]*(i+1)%MOD;
}
inline ll C(ll n,ll m) { return Fac[n]*InF[m]%MOD*InF[n-m]%MOD; }
inline ll A(ll n,ll m) { return Fac[n]*InF[n-m]%MOD; }
int main(){
    pre();
    ll N,M,Ans=0,Bas=1;
    cin>>N>>M;
    for(int i=0;i<=N;i++){
        Ans+=C(N,i)*A(M,i)%MOD*A(M-i,N-i)%MOD*A(M-i,N-i)%MOD*Bas;
        Ans=(Ans%MOD+MOD)%MOD;
        Bas*=-1;
    }
    cout<<Ans;
    return 0;
}

Measured memory_bytes: 11392
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int cnt=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length()/2;i++){
		if(s.substr(i,1)!=s.substr(s.length()-1-i,1)){
			cnt++;
		}
	}
	cout<<cnt<<endl;


	return 0;
}



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

int main() {
  ll n;
  cin >> n;
  vector <char> v(n);
  ll e = 0;
  rep(i, n) {
    cin >> v.at(i);
    if (v.at(i) == 'E') e++;
  }
  ll res = INF, w = 0;;
  rep(i, n) {
    if (v.at(i) == 'E') {
      e--;
      res = min(res, e+w);
    } else {
      res = min(res, e+w);
      w++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main(){
	int k;
	char s[100];
	int i = 0;
	scanf("%d %s",&k,s);

if(strlen(s) <= k){
	printf("%s",s);}

else{
	while(i < k){
		putchar(s[i]);
		i++;
	}
	printf("...");
	
}
}

Measured memory_bytes: 1732
n, m, q = map(int,input().split())
bord = [[0 for _j in range(n+2)] for _i in range(n+2)]

for _i in range(m):
    left, right = map(int, input().split())
    bord[left][right] += 1

for i in range(1, n+2):
    for j in range(1, n+2):
        bord[i][j] += bord[i][j-1]

result = []
for _i in range(q):
    p, q = map(int, input().split())
    c = 0
    for i in range(p, q+1):
        c += bord[i][q]-bord[i][p-1]
    result.append(c)
print(*result)

Measured memory_bytes: 64984
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MOD=1000000007;

char s[MAXN+1]; int n;

int sum[MAXN+1];
int dp[MAXN+1][2]; // dp[i][j] is number of strings we can make, where we may skip any zerosum prefix iff j=1

int nxtsum[MAXN+1][3];
int nxtsame[MAXN];

void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }
void run() {
	scanf("%s",s); n=strlen(s);

	sum[0]=0; REP(i,n) sum[i+1]=(sum[i]+s[i]-'a'+1)%3;
	for(int i=n;i>=0;--i) { REP(j,3) nxtsum[i][j]=i==n?-1:nxtsum[i+1][j]; nxtsum[i][sum[i]]=i; }
	nxtsame[n-1]=-1; for(int i=n-2;i>=0;--i) nxtsame[i]=s[i]==s[i+1]?i:nxtsame[i+1];

	dp[n][0]=dp[n][1]=1;
	for(int i=n-1;i>=0;--i) REP(j,2) {
		dp[i][j]=0;
		bool nj=j==1||i+1<n&&s[i]==s[i+1]?1:0;
		if(sum[i]==sum[n]&&j==1) inc(dp[i][j],1); // stop
		inc(dp[i][j],dp[i+1][nj]); // take s[i]
		if(nj==0&&nxtsame[i]!=-1&&sum[i+1]==sum[n]) inc(dp[i][j],1); // take s[i] and stop
		int k=(sum[i]+3-(s[i]-'a'+1))%3;
		if(j!=0||nxtsame[i]!=-1) {
			int fr=j==0?nxtsame[i]+2:i;
			if(nxtsum[fr][k]!=-1) inc(dp[i][j],dp[nxtsum[fr][k]][1]); // take other letter
		}
		//printf("%d,%d: %d\n",i,j,dp[i][j]);
	}
	printf("%d\n",dp[0][0]);
}

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


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
int main(void) {
    Int r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC" << endl;
    } else if (r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    return 0;
}



Measured memory_bytes: 3496
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

#define MAX_N 15
#define ll long long

ll ans;
char str[MAX_N];
ll num[MAX_N];
ll n;

// dfs对应三项分别为:dfs深度 加数 被加数
void dfs(ll now, ll pA, ll pB) {
    if (now == n + 1){
        ans += pA + pB;
        return;
    }
    dfs(now + 1, pA + pB, num[now]);            //插入+
    dfs(now + 1, pA     , pB*10 + num[now]);         //不插+
}

void init(){
    n = (ll)strlen(str + 1);
    for(ll i = 1;i <= n;i++){
        num[i] = str[i] - '0';
    }
    ans = 0;
}

int main(){
    scanf("%str", str + 1);
    init();
    dfs(2, 0, num[1]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/*input
1000000
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits>
#include <random>

using namespace std; 

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;

int const MOD = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	ll n;
	cin >> n;
	ll ans=2*(n-1)-1;
	for(ll a=2; a<n; a++) {
		for(ll b=a; ; b++) {
			if(n<=a*b) break;
			if(a!=b) ans+=2;
			else ans++;
		}
	}
	cout << ans;
	return 0;	
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll x,a,b;
    cin>>x>>a>>b;
    x=x-a;
    ll ans=(x/b);
    ans=ans*b;
    ans=x-ans;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var k, s int
var A [][]int

func main() {
	sc.Split(bufio.ScanWords)
	k, s = nextInt(), nextInt()
	ans := 0
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z := s - x - y
			if z >= 0 && z <= k {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#pragma warning (disable:4996)
#include"bits/stdc++.h"
#include<cassert>
#define int long long
#define MRE assert(0);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;
int par[100006], siz[100006];
int a[100006], b[100006], c[100006], d[100006];
int ans[100006];
vector<int>G[100006],B[100006];
void disp(int n) {
	rep(i, n) {
		if (i)cout << ' '; cout << ans[i];
	}cout << endl;
}
void init(int n) {
	rep(i, n) {
		par[i] = i; siz[i] = 1;
	}
}
int find(int x) {
	if (x == par[x])return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y)return;
	if (siz[x] > siz[y])swap(x, y);
	par[x] = y;
	siz[y] += siz[x];
}
signed main() {
	int n, m, k; cin >> n >> m >> k;
	init(n);
	rep(i, m) {
		cin >> a[i] >> b[i]; a[i]--; b[i]--;
		unite(a[i], b[i]);
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	rep(i, k) {
		cin >> c[i] >> d[i];
		c[i]--; d[i]--;
		B[c[i]].push_back(d[i]);
		B[d[i]].push_back(c[i]);
	}

	rep(i, n) {
		int cnt = 0;
		for (int e : B[i]) {
			if (find(i) == find(e))cnt++;
		}
		ans[i] = siz[find(i)] - G[i].size() - cnt - 1;
	}
	disp(n);
}

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

int a[50][6];
int main(){
	vector<int>v[3];
	int n;scanf("%d",&n);
	rep(i,n)rep(j,6){
		int c,d;scanf("%d%d",&c,&d);
		a[i][j]=c*60+d;
		v[j/2].push_back(a[i][j]);
	}
	int Max=0;
	rep(i,v[0].size())rep(j,v[1].size())rep(k,v[2].size()){
		int b[]{v[0][i],v[1][j],v[2][k]};
		int cnt=0;
		rep(t,n){
			bool flag=true;
			rep(l,3){
				if(!(a[t][l*2]<=b[l]&&b[l]<=a[t][l*2+1]))flag=false;
			}
			cnt+=flag;
		}
		Max=max(Max,cnt);
	}
	cout<<Max<<endl;
}

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

ll N,K;
P X[100005];
ll s[100005],e[100005],n[100005];

int main(){

cin>>N>>K; K--;

for(int i=0; i<N; i++) scanf("%ld %ld",&X[i].first,&X[i].second);

sort(X,X+N);

s[0]=0; e[0]=s[0]+X[0].second-1; n[0]=X[0].first;
for(int i=1; i<N; i++){
    s[i]=e[i-1]+1; e[i]=s[i]+X[i].second-1; n[i]=X[i].first;
}

for(int i=0; i<N; i++){
    //cout<<s[i]<<" "<<e[i]<<" "<<n[i]<<endl;
    if(s[i]<=K&&K<=e[i]){
        cout<<n[i]<<endl; return 0;
    }
}

}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  int d[N];
  rep(i, N) {
    cin >> d[i];
  }
  ll sum = 0;
  rep(i, N) REP(j, i + 1, N) {
    sum += d[i] * d[j];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl


int main() {
    string S;
    cin >> S;
    int s = stoi(S);

    int a[4];
    for (int i = 3; i >= 0; i--) {
        a[i] = s % 10;
        s /= 10;
    }

    for (int i = 0; i < (1 << 3); i++) {
        int sum = a[0];
        string ansS;
        ansS += S[0];
        int k = 1;
        for (int j = 2; j >= 0; j--) {
            if (i >> j & 1) {
                sum += a[k];
                ansS += "+";
            }
            else {
                sum -= a[k];
                ansS += "-";
            }
            ansS += S[k];
            k++;
        }
        if (sum == 7) {
            ansS += "=7";
            cout << ansS << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
/*==============================================*\
ID:          shahidul_brur

Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh

 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;
const int LOGN = 20;
int n, h[maxn],k;
ll dp[maxn];
ll cal(int i)
{
    if(i==n) return 0LL;
    ll &ret=dp[i];
    if(ret!=-1) return ret;
    ret = cal(i+1) + abs(h[i]-h[i+1]);
    f2(j,2,k){
        if(i+j<=n) 
            ret = min(ret, cal(i+j) + abs(h[i]-h[i+j]));
    }
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin>>n>>k;
    f1(i,n) cin>>h[i];
    mem(dp, -1);
    cout << cal(1) << "\n";
    return 0;
}


Measured memory_bytes: 6912
import sys

input = sys.stdin.readline

P = 998244353


def make_fac_tables_mod_p(n, p):
    fac = [0] * (n + 1)
    fac_inv = [0] * (n + 1)
    mod_inv = [0] * (n + 1)
    fac[0] = fac[1] = 1
    fac_inv[0] = fac_inv[1] = 1
    mod_inv[1] = 1
    for i in range(2, n + 1):
        fac[i] = (fac[i - 1] * i) % p
        mod_inv[i] = p - mod_inv[p % i] * (p // i) % p
        fac_inv[i] = fac_inv[i - 1] * mod_inv[i] % p
    return fac, fac_inv


def nCk_mod_p(fac, fac_inv, n, k, p):
    return ((fac[n] * fac_inv[n - k]) % p) * fac_inv[k] % p


def main():
    N, M, K = map(int, input().split())

    fac, fac_inv = make_fac_tables_mod_p(N, P)

    ans = M * pow(M - 1, N - 1, mod=P) % P  # k = 0
    for k in range(1, K + 1):
        num = M * pow(M - 1, N - 1 - k, mod=P) % P
        num = num * nCk_mod_p(fac, fac_inv, N - 1, k, P) % P
        ans = (ans + num) % P

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 32632
loop do
  n, k = gets.split.map(&:to_i)
  break if n == 0
  c = []
  k.times { c << gets.to_i }
  c.sort!

  pos = 1
  pos = 2 if c[0] == 0
  r = [[c[pos - 1]]]
  pos.upto(k-1) do |i|
    if c[i] == c[i - 1] + 1
      r.last << c[i]
    else
      r << [c[i]]
    end
  end

  if c.include? 0
    max = 0
    r.each_cons(2) do |a, b|
      max = [max, a.size + b.size + 1].max
    end
    puts max
  else
    puts r.max_by { |e| e.size }.size
  end
end

Measured memory_bytes: 11728
def main():
    n, x = map(int, input().split())
    l_lst = list(map(int, input().split()))
    count = 0
    coordinate_lst = [0]

    for i in range(n):
        coordinate_lst.append(coordinate_lst[i] + l_lst[i])

    for i in range(n+1):
        if coordinate_lst[i] <= x:
            count += 1

    print(count)


if __name__ == '__main__':
    main()

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, 0, n) cin >> p[i];
    sort(p.begin(), p.end());
    int sum = 0;
    rep(i, 0, k) sum += p[i];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3624
// All Heil Fire Lord Zuko

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

#define F first
#define S second
#define PB push_back

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

const int N = 2 * 100 * 1000 + 19;

int n, ind[N], dp[N];

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i ++) {
        int p;
        cin >> p;
        ind[p] = i;
    }
    dp[0] = 0;
    for (int i = 1; i <= n; i ++) {
        if (ind[i] > ind[i - 1])
            dp[i] = dp[i - 1] + 1;
        else
            dp[i] = 1;
    }
    sort(dp, dp + n + 1);
    cout << n - dp[n];
    return 0;
}

/* THINGS TO CHECK */

// Runtime -> 
// Overflow ->
// Time -> N
// Memory ->

/* READ PROBLEM STATEMENT CAREFULLY */


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0))
    cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <limits>

int main() {

    int64_t A, B;
    std::cin >> A >> B;

    for (int64_t i = 0; i < 1100; ++i) {
        if (static_cast<int64_t>(i*0.08) == A && static_cast<int64_t>(i*0.1) == B) {
            std::cout << i << std::endl;
            return 0;
        }
    }

    std::cout << -1 << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l,r;
  cin>>l>>r;
  long long ans=1e9;
  if(r<l+2019)
  {
      for(long long  i=l;i<=r;i++)
      {
          for(long long  j=i+1;j<=r;j++)
          {
            if((i*j)%2019<ans)
                ans=(i*j)%2019;
           // cout<<ans;
          }
      }
  }
  else
  {
      for(long long i=l;i<=l+2019;i++)
      {
          for(long long j=l+1;j<l+2019;j++)
          {
              if((i*j)%2019<ans)
                  ans=(i*j)%2019;
          }
      }
  }
cout<<ans;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    int K;
    cin>>K;
    priority_queue<ll,vector<ll>,greater<ll>> que;
    REP(i,1,10)que.push(i);
    rep(i,K-1){
        ll x=que.top();
        que.pop();
        if(x%10!=0){
            que.push(x*10+(x%10)-1);
        }
        que.push(x*10+(x%10));
        if(x%10!=9){
            que.push(10*x+(x%10)+1);
        }
    }
    cout<<que.top()<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 2420
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
a0 = sum(a[1:])
ans = 0

for i in range(n-1):
    ans += (a0*a[i])%mod
    ans %= mod
    a0 -= a[i+1]
print(ans)


Measured memory_bytes: 31744
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
    
a=sorted(a)
b=sorted(b)
if (n%2==1):
    target=(n+1)//2
    print(b[target-1]-a[target-1]+1)
if (n%2==0):
    target=(n)//2
    left=a[target]+a[target-1]
    right=b[target]+b[target-1]
    ans=right-left+1
    print(ans)

Measured memory_bytes: 27084
_ = input()
Hs = [int(s) for s in input().split()]

m, t = 0, 0
for i in range(len(Hs) - 1):
    if Hs[i] >= Hs[i + 1]:
        t += 1
    else:
        m = max(m, t)
        t = 0
m = max(m, t)

print(m)

Measured memory_bytes: 14252
#include <iostream>

using namespace std;
int main(int argc, char* argv[])
{
	int N,M,i;
	cin>>N>>M;
	int A;
	int ans=0;
	for (i=0;i<M;i++){
		cin>>A;
		ans+=A;
	}
	ans=N-ans;
	if (ans>=0){
		cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3192