akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int a[3];
  for(int i = 0; i<3 ; i++) cin >> a[i];
  if(a[0] == a[1] + a[2] || a[0] + a[1] ==a[2] || a[0] + a[2] == a[1]) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
n,m = gets.chomp.split.map(&:to_i)

go = Array.new(n+1) { Array.new }
m.times do
  a,b = gets.chomp.split.map(&:to_i)
  go[a].push(b)
  go[b].push(a)
end

que = []
go[1].each do |goo|
  que.push([goo, 1])
end

if que.empty?
  puts 'No'
  exit
end

ans = Array.new(n+1, nil)

while !que.empty?
  ne, ind = que.shift
  next if ne == 1
  next if ans[ne]
  ans[ne] = ind
  go[ne].each do |goo|
    que.push([goo, ne])
  end
end

ans.shift(2)

if ans.all?{|an| an}
  puts 'Yes'
  ans.each do |an|
    p an
  end
else
  puts 'No'
end


Measured memory_bytes: 58756
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,i,a[10101010],hs,hz,hh;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		hz=hz+a[i];
	}
	hs=pow(10,18);
	for(i=1;i<n;i++)
	{
		hh=hh+a[i];
		hz=hz-a[i];
		hs=min(hs,abs(hz-hh));
	}
	cout<<hs<<"\n";
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string s, t; cin >> s >> t;
  ll start = s.size() - t.size();
  ll tsz = t.size();
  for (ll i = start; i >= 0; i--) {
    bool fail = false;
    for (ll j = 0; j < tsz; j++) {
      if (s[i + j] == t[j] || s[i + j] == '?') continue;
      fail = true;
      break;
    }
    if (!fail) {
      for (ll k = 0; k < (ll)s.size(); k++) {
	if (s[k] != '?') {
	  cout << s[k];
	}else if (k < i || i + tsz <= k) {
	  cout << 'a';
	}else {
	  cout << t[k - i];
	}
      }
      cout << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;

  return 0;
}



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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

int dy[]={0,-1,-1,0,1,1};
int dx[]={1,0,-1,-1,0,1};
const int SZ=200;
const int off=100;

int t,n;
bool isEntry[SZ][SZ];
bool isVisited[SZ][SZ];

int bfs(int sy,int sx)
{
    queue<P> que;
    isVisited[sy][sx]=true;
    que.push(P(sy,sx));

    int cnt=1;
    REP(i,t){
	int sz=que.size();
	while(sz--){
	    int y=que.front().first;
	    int x=que.front().second;
	    que.pop();
	    REP(j,6){
		int ny=y+dy[j],nx=x+dx[j];
		if(isEntry[ny][nx] && !isVisited[ny][nx])
		{
		    isVisited[ny][nx]=true;
		    que.push(P(ny,nx));
		    cnt++;
		}
	    }
	}
    }
    return cnt;
}

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

    while(cin>>t>>n,t)
    {
	REP(i,SZ) REP(j,SZ){
	    isEntry[i][j]=true,isVisited[i][j]=false;
	}
	REP(i,n){
	    int x,y; cin>>x>>y;
	    x+=off; y+=off;
	    isEntry[y][x]=false;
	}
	int sx,sy; cin>>sx>>sy;
	sx+=off; sy+=off;
	cout<<bfs(sy,sx)<<endl;
    }
}



Measured memory_bytes: 3268
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    #define COUT(N) cout<<fixed<<setprecision(N)
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    lint N;
    cin >> N;
    lint sum;
    sum = N*(N+1)/2;
    lint N1 = (N/3),N2 = N/5,N3 = N/15;
    lint sum1 = 3*N1*(N1+1)/2,sum2 = 5*N2*(N2+1)/2,sum3 = 15*N3*(N3+1)/2;
    cout << sum-sum1-sum2+sum3;
    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	int arr[n+1][3];
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>arr[i][j];
		}
	}
	int dp[n+1][3];
	dp[1][0]=arr[1][0];
	dp[1][1]=arr[1][1];
	dp[1][2]=arr[1][2];
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			dp[i][j]=arr[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
		}
	}
	cout<< max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
return 0;
}

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

int main() {
long long m,p=1000000007,n;
string s,t;
bool q;
for(int i=0;i<n;++i){
    cin>>n>>s>>t;
    if(s[i]==t[i]){
        if(i==0){
            m=3;
        }else if(q){
            m=(2*m)%p;
        }
        q=true;
    }
    else{
        if(i==0){
            m=6;
        }else if(q){
            m=(m*2)%p;
        }else{
            m=(m*3)%p;
        }        
        q=false;
        ++i;
    }
}
    cout<<m<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;

//139 E
int main(void) {
	ll n;
	cin >> n;
	vector<queue<ll>> a = vector<queue<ll>>(n, queue<ll>());

	chrono::system_clock::time_point start, end;

	start = chrono::system_clock::now();

	rep(i, 0, n) {
		rep(j, 0, n - 1) {
			ll input;
			cin >> input;
			a[i].push(input-1);
		}
	}
	vector<ll> person = vector<ll>(n);
	rep(i, 0, n) {
		person[i] = a[i].front();
		a[i].pop();
	}
	ll ans = 0;
	bool dontStop = true;
	while (dontStop && ans != -1) {
		ans++;
		bool updated = false;
		rep(i, 0, n) {
			if (person[i] != -1 && i == person[person[i]]) {
				person[person[i]] = -1;
				person[i] = -1;
				updated = true;
			}
		}
		if (updated) {
			dontStop = false;
			rep(i, 0, n) {
				if (person[i] == -1 && a[i].size() > 0) {
					dontStop = true;
					person[i] = a[i].front();
					a[i].pop();
				}
			}
		}
		else {
			ans = -1;
		}
		end = chrono::system_clock::now();

		double time = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
		if (time > 250) {
			ans = n * (n - 1) / 2;
			break;
		}
	}


	cout << ans << endl;
}

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

using i64 = long long;
using P   = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

void solve(long long a, long long b, long long c, long long d) {
    if((a <= 0 && b >= 0) || (c <= 0 && d >= 0))
        cout << max({0LL, a * c, a * d, b * c, b * d}) << endl;
    else
        cout << max({a * c, a * d, b * c, b * d}) << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    long long c;
    scanf("%lld", &c);
    long long d;
    scanf("%lld", &d);
    solve(a, b, c, d);
    return 0;
}


Measured memory_bytes: 3764
#include<iostream>
#include<ctype.h>
#include<string.h>
using namespace std;
int main(void){
  string a,b;
  cin>>a>>b;
  if(a.length()>b.length()) cout<<"GREATER"<<endl;
  else if(a.length()<b.length())  cout<<"LESS"<<endl;
  else if(a==b)  cout<<"EQUAL"<<endl;
  else if(a>b)  cout<<"GREATER"<<endl;
  else cout<<"LESS"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    map<ll, ll> b;
    for (int i = 1; i <= n; i++) {
        if (i > a[i]) b[i - a[i]]++;
    }
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        if (b.count(a[i] + i)) {
            sum += b[a[i] + i];
        }
    }
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 13012
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nomurapc2020
{
    class Program
    {
        static void Main(string[] args)
        {
            a();
        }

        public static void a()
        {
            int[] hmhmk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int h1 = hmhmk[0], m1 = hmhmk[1], h2 = hmhmk[2], m2 = hmhmk[3], k = hmhmk[4];
            int h3 = h2 - h1;
            int m3 = m2 - m1;
            if(m3 < 0)
            {
                h3--;
                m3 += 60; 
            }
            int ans = h3 * 60 + m3 - k;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28288
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        int count0 = 0;
        int count1 = 0;
        
        for(int i=0; i<N; i++){
            if(S.charAt(i) == '0'){
                count0++;
            }else{
                count1++;
            }
        }
        
        if(count0>count1){
            System.out.println(2*count1);
        }else{
            System.out.println(2*count0);
        }
        
   }
}


Measured memory_bytes: 39448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
struct EDGE
{
    int to, cost;
    EDGE(int a, int b){
        to = a;
        cost = b;
    }
    bool operator < (const EDGE& t) const {
        return cost > t.cost;
    }
};
vector<EDGE> v[100]; 
bool f[100];
int search()
{
    int res = 0;
    priority_queue<EDGE> que;
    que.push(EDGE(0, 0));
    while (!que.empty()){
        EDGE e = que.top(); que.pop();
        if (f[e.to]) continue;
        f[e.to] = true;
        res += e.cost;
        rep(i, v[e.to].size()){
            if (!f[v[e.to][i].to]){
                que.push(v[e.to][i]);
            }
        }
    }
    return res;
}

int main()
{
    int n, m;
    while (scanf("%d", &n), n){
        scanf("%d", &m);
        rep(i,m){
            int a, b, c;
            scanf("%d,%d,%d",&a,&b,&c);
            c = c / 100 - 1;
            v[a].pb(EDGE(b, c));
            v[b].pb(EDGE(a, c));
        }
        printf("%d\n", search());
        memset(f, false, sizeof(f));
        rep(i, n) v[i].clear();
    }
    return 0;
}

Measured memory_bytes: 1380
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int size=1,n[2000000];


void up(int now){
  if(n[now]>n[now/2]&&now>1){
    swap(n[now],n[now/2]);
    up(now/2);
  }
}

void down(int now){
  int l;
  if(now*2<=size-1 && n[now]<n[now*2])l=now*2;
  else l=now;
  if(now*2+1<=size-1 && n[now*2+1]>n[l])l=now*2+1;
  if(l!=now){
    swap(n[now],n[l]);
    down(l);
  }
}

int main(){
  //for(int i=0;i<2001;i++)n[i]=-1;///////
  int a;
  string s;
  size=1;
  while(cin>>s&&s!="end"){
    if(s=="insert"){
      cin>>a;
      n[size]=a;
      up(size);
      size++;
    }else if(s=="extract"){
      cout<<n[1];
      cout<< endl;
      n[1]=n[size-1];
      size--;
      down(1);
    }
    //for(int i=1;i<20;i++)cout<<n[i]<<" ";////////
    //cout<<endl;///////
  }
  return 0;
}

Measured memory_bytes: 5296
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;
const int  Inv2 = (MOD+1)/2;

     signed main(){
  int n, k, x, y;
  cin>>n>>k>>x>>y;
  cout<<x*min(k,n)+y*max(0ll,n-k)<<"\n";  
}

        


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;

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

    int n;
    cin >> n;
    vector< pair< string, P > > v;

    for( int i = 0; i < n; ++i ) {
        string s;
        int p;
        cin >> s >> p;
        v.pb( MP( s, MP( -p, i + 1 ) ) );

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

    for( int i = 0; i < n; ++i ) {
        cout << v[i].S.S << endl;

    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1000000009
using P = pair<int,int>;

int main(){
  int n;
  cin >> n;
  if(n % 3 == 0){
    int s = 0;
    rep(i,n){
      int j;
      cin >> j;
      s ^= j;
    }
    if(s == 0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  else{
    bool flag = true;
    rep(i,n){
      int j;
      cin >> j;
      if(j != 0) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import numpy as np
from collections import deque


H, W = [int(str) for str in input().strip().split()]
S = [list(input().strip()) for _ in range(H)]

def calc_max_dist(start_x, start_y):
    dist = [[-1] * W for _ in range(H)]
    que = deque()

    dist[start_x][start_y] = 0
    que.append((start_x, start_y))

    while len(que):
        current_x, current_y = que.popleft()
        for i in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            near_x, near_y = current_x + i[0], current_y + i[1]

            if not (0 <= near_x < H and 0 <= near_y < W):
                continue

            if S[near_x][near_y] == '.' and dist[near_x][near_y] == -1:
                dist[near_x][near_y] = dist[current_x][current_y] + 1
                que.append((near_x, near_y))

    return max([max(_) for _ in dist])


print(max([calc_max_dist(x, y) for x in range(H) for y in range(W) if S[x][y] == '.']))

Measured memory_bytes: 19388
public class Main {

	private static void solve() {
		int k = ni();
		long[] a = nal(k);
		
		long max = 2;
		long min = 2;
		for (int i = k - 1; i >= 0; i --) {
			if (min < a[i]) {
				min = a[i];
			} else {
				min = (min + a[i] - 1) / a[i] * a[i];
			}
			max = max / a[i] * a[i] + (a[i] - 1);
			
			if (max < min) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(min + " " + max);
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			@Override
			public void run() {
				long start = System.currentTimeMillis();
				String debug = args.length > 0 ? args[0] : null;
				if (debug != null) {
					try {
						is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
				}
				reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
				solve();
				out.flush();
				tr((System.currentTimeMillis() - start) + "ms");
			}
		}, "", 64000000).start();
	}

	private static java.io.InputStream is = System.in;
	private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
	private static java.util.StringTokenizer tokenizer = null;
	private static java.io.BufferedReader reader;

	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new java.util.StringTokenizer(reader.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	private static double nd() {
		return Double.parseDouble(next());
	}

	private static long nl() {
		return Long.parseLong(next());
	}

	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private static char[] ns() {
		return next().toCharArray();
	}

	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

	private static int[][] ntable(int n, int m) {
		int[][] table = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[i][j] = ni();
			}
		}
		return table;
	}

	private static int[][] nlist(int n, int m) {
		int[][] table = new int[m][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[j][i] = ni();
			}
		}
		return table;
	}

	private static int ni() {
		return Integer.parseInt(next());
	}

	private static void tr(Object... o) {
		if (is != System.in)
			System.out.println(java.util.Arrays.deepToString(o));
	}
}


Measured memory_bytes: 41404
import sys
from collections import Counter
from collections import deque
import math
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


n=int(input())
l=[int(input()) for i in range(n)]
ans=0
c=0
for i in range(n):
    if l[i]==0:
        ans+=c//2
        c=0
    else:
        c+=l[i]
ans+=c//2
print(ans)

Measured memory_bytes: 7420
# coding: utf-8

def solve(arg: str) -> str:
    NK, H = arg.split('\n')
    n, k = map(int, NK.split())
    ar_H = map(int, H.split())
    return str(sum(k <= int(h) for h in ar_H))


if __name__ == "__main__":
    print(solve('\n'.join([input() for _ in range(2)])))


Measured memory_bytes: 10260
import math
import itertools


N = int(input())

array = [list(map(int, input().split())) for _ in range(N)]

permutation_list = itertools.permutations([x for x in range(N)])

calc = [[0] * N for i in range(N)]
for i in range(N):
    for j in range(N):
        calc[i][j] = math.sqrt((array[i][0] - array[j][0]) ** 2 +
                               (array[i][1] - array[j][1]) ** 2)
        calc[j][i] = calc[i][j]

result = 0
count = 0
for data in permutation_list:
    count += 1
    for i in range(1, len(data)):
        result += calc[data[i - 1]][data[i]]
print(result / count)


Measured memory_bytes: 42092
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

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()
{
    int n;
    cin >> n;
    int mi = 1001001001;
    int ans = 0;
    for(int i = 0; i< n; i++){
        int p;
        cin >> p;
        if(mi > p){
            ans++;
            mi = p;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cstdint>

using namespace std;

int main()
{
	int_least32_t n, m;
	cin >> n >> m;

	vector<int_least32_t> v( n, 0 );
	int_least32_t a, b;
	for(auto i = 0; i < m; ++i) {
		cin >> a >> b;
		++v[a - 1];
		++v[b - 1];
	}

	for(auto& x : v) {
		cout << x << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k ;
    cin >> k;
    cout<< a[k-1] ;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
#define PI acos(-1)
#include <cmath>


using namespace std;

int main(){
	
	
	double R,A;
	cin >> R;
	A=2*R*PI;
	
//	Fahrenheit=Celsius*9/5+32;
//	cout << fixed;
	
	cout << setprecision(20) << A;
	
	return 0;
	
	
	
}

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

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

typedef vector<int> V;
typedef vector<V> VV; 
int main(){
    int N;
    cin>>N;
    vector<int> D(N);
    cin>>D;
    sort(ALL(D));
    VV dp(13,V(13,-1));
    dp[0][0] = 12;
    REP(i,N){
        VV nxt(13,V(13,-1));
        REP(j,13){
            REP(k,13){
                int rj = 24-j;
                int rk = 24-k;
                chmax(nxt[j][D[i]],min({dp[j][k],rj-D[i],D[i]-k}));
                chmax(nxt[D[i]][k],min({dp[j][k],rk-D[i],D[i]-j}));
            }
        }
        swap(dp,nxt);
    }
    int ret=0;
    for(auto &a:dp)for(auto &it:a)chmax(ret,it);
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int r, g, b;
	cin >> r >> g >> b;
	if((100 * r + 10 * g + b) % 4 == 0){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
const int maxN = 1e6 + 7;
typedef long long LL;
const LL O = 1e9 + 7;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

int n;
LL f[maxN];
LL fac[maxN], ifac[maxN], iv[maxN];;

LL C(int x, int y) {
	return 0 <= y && y <= x ? fac[x] * ifac[y] % O * ifac[x-y] % O : 0;
}

int main() {

	n = ri() - 1;
	iv[1] = 1; rep (i, 2, n) iv[i] = iv[O % i] * (O - O / i) % O;
	fac[0] = 1; rep (i, 1, n) fac[i] = fac[i-1] * i % O;
	ifac[0] = 1; rep (i, 1, n) ifac[i] = ifac[i-1] * iv[i] % O;

	rep (i, 1, n) f[i] = C(i-1, n-i);
	rep (i, 1, n) f[i] = (fac[i] * fac[n-i] % O * f[i]) % O;

	LL res = 0;
	rep (i, 1, n) res += (f[i] - f[i-1]) * i % O;
	printf("%lld\n", (res % O + O) % O);

	return 0;
}


Measured memory_bytes: 31488
import java.util.*;

//文字操作

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		ln(sc.nextLine()
				.replaceAll("apple","___tmp")
				.replaceAll("peach","apple")
				.replaceAll("___tmp","peach"));
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
a, b = map(int, input().split())
s = input()
numbers = list('0123456789')

flg = True
for i in range(a):
    if not(s[i] in numbers):
        flg = False
        break
if flg:
    if (s[a] != '-'):
        flg = False
if flg:
    for i in range(b):
        if not(s[a+1+i] in numbers):
            flg = False
            break
print('Yes' if flg else 'No')

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

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll t=1;
	//cin >> t;
	while(t--)
	{
		ll n,wt,ma=0;
		cin>>n>>wt;
		ll w[n+1],v[n+1];
		lp(i,1,n){
			cin>>w[i]>>v[i];
			ma+=v[i];
		}
		ll dp[100000];
		dp[0]=0;
		lp(i,1,100000)
			dp[i]=1000000000007;
		for(ll j=1; j<=n; j++){
			for(ll i=ma; i>=v[j]; i--){
					dp[i]=min(dp[i],w[j]+dp[i-v[j]]);
			}
	}
		ll ans=0;
		for(ll i=0; i<=100000; i++){
			if(dp[i]<=wt){
				ans=max(ans,i);
			}
		}
		cout<<ans<<endl;

	}
	return 0;	
}


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

using namespace std;

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

struct Lab {
    double l, a, b;
};

int main() {
	int n, m;
	vector<Lab> cs;
	cin >> n >> m;
	rep(i, n) {
	    double l, a, b;
	    cin >> l >>  a >> b;
	    cs.push_back({l, a, b});
	}
	
	double ans = -1;
	rep(i, 1<<n) {
	    vector<Lab> elems;
	    rep(j, n) {
	        if(i & (1<<j)) elems.push_back(cs[j]);
	    }
	    if(elems.size() != m) continue;
	    double tmp = 0;
	    rep(i, m-1) REP(j, i+1, m) tmp += pow(elems[i].l - elems[j].l, 2) + pow(elems[i].a - elems[j].a, 2) + pow(elems[i].b - elems[j].b, 2);
	    ans = max(ans, tmp);
	}
	printf("%.8f\n", ans);
}



Measured memory_bytes: 3348
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define endl '\n'
#define pb push_back

// debug 도구

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto& x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}\n";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)

// debug 도구 end

using llong = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VPII = vector<pair<int, int>>;
using VLL = vector<long long>;
using PII = pair<int, int>;

int main() {
    int n;
    cin >> n;
    cout << (n % 2 ? n * 2 : n);
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){

int N,M;
  cin>>N>>M;
int s[M];
int c[M];
  for(int i=0;i<M;i++){
  cin>>s[i]>>c[i];
  }
  
int ans[N];
  for(int i=0;i<N;i++){ans[i]=10;}
  int err=0;
  
 for(int i=0;i<M;i++){
  if(ans[s[i]-1]!=10){if(ans[s[i]-1]!=c[i])err=1;}
  ans[s[i]-1]=c[i];
  }

if(N==1&&M==0)cout<<"0"<<endl;
else{
  if(err==1)cout<<"-1"<<endl;
else{
  if(N==1&&ans[0]==0)cout<<"0"<<endl;
else{
  if(ans[0]==0)err=1;
  if(ans[0]==10)ans[0]=1; 

if(err==1)cout<<"-1"<<endl;
if(err==0){
  for(int i=0;i<N;i++){
    if(ans[i]==10)ans[i]=0;
    cout<<ans[i];}}
           cout<<endl;
}}}
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "YES" << endl;}
void no(){ cout << "NO" << endl;}

//-----------------------------------------

//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  cin >> n;
  cout << (1000 - n % 1000) % 1000 <<endl;



  return 0;
}



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

int seq(string &s,int pos){
	int i = pos;
	while(i < s.size() && s[pos] == s[i]){
		i++;
	}
	return i-pos;
}

int main(){	
	int n;
	while(cin >> n , n){
		string str;
		cin >> str;
		while(n--){
			stringstream newstr;
			for(int i=0;i<str.size();){
				newstr << seq(str,i) << str[i];
				i += seq(str,i);
			}
			str = newstr.str();
		}
		cout << str << endl;
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		char[] c = new char[2];
		c[0] = s.charAt(s.length()-2);
		c[1] = s.charAt(s.length()-1);
		String r = new String(c);
		System.out.println("2018/01/"+r);
	}
}


Measured memory_bytes: 21716
def solve(array, p, t)
  is_solved = false
  return true if (t == 0)
  return false if (t < 0)
  return false if (p >= array.size)
  is_solved ||= solve(array, p+1, t-array[p])
  is_solved ||= solve(array, p+1, t)
end

n1 = gets.chomp.to_i
array1 = gets.chomp.split.map(&:to_i)
n2 = gets.chomp.to_i
array2 = gets.chomp.split.map(&:to_i)

array2.each do |item|
  if solve(array1, 0, item) then
    puts "yes"
  else
    puts "no"
  end
end

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  long long n;
  cin >> n;

  long long ans = 0;
  ans += (n/500) * 1000;
  n %= 500;

  ans += (n/5) * 5;
  cout << ans << '\n';
}

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

int main(){
    int K, N;
    cin>> N>> K;
    int p[1000];
    for (int i = 0; i< N; i++){
        cin >> p[i];
    }
    sort(p, p + N);
    int sum=0;    
    for (int i=0; i< K;i++){
        //cout<<p[i]<<endl;
        sum +=p[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3648
n,k = map(int, raw_input().split(' '))
seen = {}

while(n not in seen):
	seen[n] = abs(n - k)
	if n == k:
		break
	elif n > k:
		if n - k < k:
			n = abs(n-k)
		else:
			n %= k
			n += k
		
	elif n < k:
		n = abs(n - k)
print min(seen.values())

Measured memory_bytes: 27884
#include <stdio.h>

int main(void)
{
  int a[100];
  int i, j, N, minj, num, temp;

  scanf("%d", &N);

  for(i = 0; i < N; i++)
    scanf("%d", &a[i]);

  for(i = 0; i < N-1; i++) {
    minj = i;
    for(j = i; j < N; j++) {
      if(a[j] < a[minj])
        minj = j;
    }
    temp = a[i];
    a[i] = a[minj];
    a[minj] = temp;
    if(i != minj)
      num++;
  }

  for(i = 0; i < N; i++) {
   printf("%d", a[i]);
   if(i != N-1)
     printf(" ");
  }
  printf("\n");
  printf("%d\n", num);

  return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a,0,sizeof(a))
#define make1(a) memset(a,-1,sizeof(a))
#define ALL(v) v.begin(),v.end()
#define pi pair <int,int>
#define pll pair <ll,ll>
#define fast_cin() ios_base::sync_with_stdio(0)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int mod = 1e9+7;



int main()
{
	fast_cin();
	ll n;
	cin >> n;
	for(ll i = 1; i <= 3500; i++)
	{
		for(ll j = 1; j <= 3500; j++)
		{
			ll x = n * i * j;
			ll y = 4 * i * j - n * i - n * j;
			if(y <= 0)
				continue;
			if(x % y == 0)
			{
				cout << i << ' ' << j << ' ' << x / y << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i)-1 = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{	
    string s;
    cin >> s;
    ll ans = 0;

    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R') ans = 3;
    else if(s[0] == 'R' && s[1] == 'R') ans = 2;
    else if(s[1] == 'R' && s[2] == 'R') ans = 2;
    else if(s[0] == 'R') ans = 1;
    else if(s[1] == 'R') ans = 1;
    else if(s[2] == 'R') ans = 1;
    else ans = 0;
    
    cout << ans << endl;
}


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

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

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int x,y;
  int c,i,j;
  while(1){
    scanf("%d%d",&x,&y);
  if(x>=1 && y<=10^9) break;
  }
  if(x<=y){
    c = x;
    x = y;
    y = c;
  }

  while(1){
    c = y % x;
    if(c == 0)break;
    else{
    y = x;
    x = c;
    }
  }
  printf("%d\n",x);
}



Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int H,W;

void saiki(vector< vector<char> >& map,int i,int j,char c){

	map[i][j] = ' ';
	int dx =  j+1;
	int dy =  i+1;
	int mdx = j-1;
	int mdy = i-1;
	if(dy >= 0 && dy < H && map[dy][j] == c) saiki(map,dy,j,c); 
	if(mdy >= 0 && mdy < H && map[mdy][j] == c) saiki(map,mdy,j,c); 
	if(dx >= 0 && dx < W && map[i][dx] == c) saiki(map,i,dx,c);
	if(mdx >= 0 && mdx < W && map[i][mdx] == c) saiki(map,i,mdx,c);

}

int main(){

    bool flag = true;
    char temp;
    vector< vector<char> > map;
    while(flag){
	int count = 0;
	cin >> H >> W;
	if(H==0&&W==0)flag = false;
	else{
	for(int i=0;i<H;i++){
	    map.push_back( vector<char>()  );
	    for(int j=0;j<W;j++){
		cin >> temp;
		map[i].push_back(temp);
	    }
	}

	char c;
	for(int i=0;i<H;i++){
	    for(int j=0;j<W;j++){
		c = map[i][j];
		if(c != ' '){
		    count++;
		    saiki(map,i,j,c);
		}
	    }
	}
	    cout << count << endl;
	    map.clear();
	}
    }
	return 0;
    }

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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < N-2; i++) {
        if (S.substr(i, 3) == "ABC") ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Long __int128_t
#define int long long

Long modpow(Long a, Long n, Long mod) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        Long t = modpow(a, n / 2, mod);
        return t * t % mod;
    }
    return a * modpow(a, n - 1, mod) % mod;
}

template <Long mod, Long p = 257>
struct RollingHash {
    int n;
    vector<Long> table;
    vector<Long> pows;
    RollingHash(const string &s) : n(s.size()), table(n + 1), pows(n + 1) {
        table[0] = 1;
        pows[0] = 1;
        for (int i = 0; i < n; i++) {
            table[i + 1] = (table[i] * p + s[i]) % mod;
            pows[i + 1] = pows[i] * p % mod;
        }
    }

    // [l, r)
    Long hash_substr(int l, int r) {
        Long ret = (table[r] - table[l] * pows[r - l]) % mod;
        if (ret < 0) ret += mod;
        return ret;
    }
};

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    RollingHash<((Long)1 << 62) - 1> rh(s);

    auto has = [&](int k) -> bool {
        map<Long, vector<int>> mp;
        for (int i = 0; i < n - k + 1; i++) {
            mp[rh.hash_substr(i, i + k)].push_back(i);
        }
        for (auto &p : mp) {
            sort(p.second.begin(), p.second.end());
            if (p.second.back() - p.second.front() >= k) return true;
        }
        return false;
    };

    int l = 0, r = n / 2 + 1;
    while (l < r - 1) {
        int m = (l + r) / 2;
        if (has(m)) {
            l = m;
        } else {
            r = m;
        }
    }
    cout << l << endl;
}


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

int main(){
    int n;cin>>n;
    vector<pair<int, int>> students(n);
    int temp;
    for (int i=0;i<n;i++){
        cin >> temp;
        students[i] = make_pair(temp, i+1); 
    }
    sort(students.begin(), students.end());

    for (auto i : students){
        cout << i.second << " ";
    }
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<climits>
#include<random>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;
 
/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
////////////////////////////////
 
#define int long long

const int mod = 1e9 + 7;
const int N = 10001;
int n;
int x;
string s;
int dp[N][10][2][100];
// f is zero means we can do anything .
// f is not zero means we are limited .
int calc(int pos ,int val , int f , int sum){

	if(pos==n){

		return (sum==0);
	}

	int &ans = dp[pos][val][f][sum];

	if(ans!=-1)
		return ans;

	int lim = 9;

	if(f==1)
		lim = s[pos]-'0';
	ans = 0;
	for(int i = 0 ; i <= lim ; ++i){

		if(f==0)
			ans += calc(pos+1 , i , 0 , (sum+i)%x);
		else if(i==lim && f==1)
			ans += calc(pos + 1 , i , 1 , (sum + i)%x);
		else ans += calc(pos+1 , i , 0 , (sum + i)%x);

		ans%=mod;
	}

	return ans;

}

void solve(){

	memset(dp , -1 , sizeof dp);

	cin>>s;

	n = s.size();

	cin>>x;


	int ans = calc(0 , 0 , 1 , 0);

	ans += 5*mod;

	--ans;
	ans%=mod;

	cout<<ans<<endl;
}
 
signed main(){
 
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
        solve();
}


Measured memory_bytes: 157440
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 10000007;
const int inf = 1001001001;



int main(void) {
  string s;
  cin >> s;
  int q;
  cin >> q;
  int cnt = 0;
  string mae = "";
  string usi = "";
  rep(i,q){
    int t;
    cin >> t;
    if(t==1){ 
      cnt++;
      string aa = mae;
      mae = usi;
      usi = aa;
    }
    else{
      int f;
      cin >> f;
      char c;
      cin >> c;
      if(f==1){
        
        mae.push_back(c);
      }
      else{
        usi.push_back(c);
      }
    }
  }
  if(cnt%2==1) reverse(ALL(s));
  reverse(ALL(mae));
  //cout << mae << " " << s << " " << usi << endl;
  s = mae + s + usi;
  cout << s << endl;
      
 
}


Measured memory_bytes: 1348
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    char[][] a = new char[H][W];
    PriorityQueue<Cell> queue = new PriorityQueue<>(Comparator.comparingInt(cell -> cell.depth));
    for (int i = 0; i < H; i++) {
      a[i] = scanner.next().toCharArray();
      for (int j = 0; j < W; j++) {
        if (a[i][j] == '#') {
          queue.add(new Cell(i, j, 0));
        }
      }
    }
    int max = 0;
    while (!queue.isEmpty()) {
      Cell c = queue.poll();
      max = Math.max(max, c.depth);
      for (int[] d : new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}) {
        int x = c.x + d[0];
        int y = c.y + d[1];
        if (x < 0 || x >= H || y < 0 || y >= W) continue;
        if (a[x][y] == '.') {
          a[x][y] = '#';
          queue.add(new Cell(x, y, c.depth + 1));
        }
      }
    }
    System.out.println(max);
  }

  private static class Cell {
    private final int x;
    private final int y;
    private final int depth;

    private Cell(int x, int y, int depth) {
      this.x = x;
      this.y = y;
      this.depth = depth;
    }
  }
}


Measured memory_bytes: 116056
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    double ans = 0;
    double count;
    for(int i = 1;i<=n;i++){//saikoro no me
      count = 0;
      int point = i;
      while(point<k){
        point*=2;
        count++;
      }
      point = 1;
      while(count!=17){
        count++;
        point*=2;
      }
      ans+=point;
    }
    ans/=(double)n;
    ans/=131072;
    System.out.println(ans);
  }
}


Measured memory_bytes: 35844