akhauriyash/Code-Regression huggingface dataset:
/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
ll s[N];
int main()
{
	ll n,i;
	sl(n);
	for(i =0 ;i < n;i++)
		sl(s[i]);
	sort(s,s+n);
	ll sum  =0;
	for(i = n-1;i>= 0;i--)
	{
		if(i == n-1)
			sum += s[i]/2;
		else
			sum += s[i];
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	long long N, K;
	cin >> N >> K;

	vector<long long> A(N, 0);
	for (long long i = 0; i < N; i++) {
		cin >> A[i];
	}

	vector<long long> C(N, 0);
	long long pos = A[0];
	vector<long long> path;
	
	path.push_back(0);
	C[0] += 1;

	pos -= 1;
	path.push_back(pos);
	C[pos] += 1;

	while (C[pos] < 2) {
		pos = A[pos];
		pos -= 1;
		path.push_back(pos);
		C[pos] += 1;
	}

	long long ini = path.back();
	path.pop_back();

	auto b = find(path.begin(), path.end(), ini);
	long long idis = distance(path.begin(), b);
	long long rdis = distance(b, path.end());

	if (idis > K) {
		cout << path[K] + 1 << endl;
	}
	else {
		long long val = K - idis;
		val = val % rdis;

		cout << *(b + val) + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 8424
a=input()
b=input()
ans="No"
for i in range(len(a)):
  k=1
  for j in range(len(a)):
    j2=(j+i)%len(a)
    if a[j]!=b[j2]:
      k=0
      break
  if k==1:
    ans="Yes"
    break
    
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  string s=to_string(N);
  int n=s.size();
  int sum=0;
  for(int i=0;i<n;i++){
  sum+=(int)(s.at(i))-48;
  }
  if(N%sum==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		while(true) {
			int L=sc.nextInt();
			if(L==-1) {
				break;
			}
			int sum=0;
			if(L<=10) {
				pl(4280-1150);
			}
			else if(L>10 && L<=20){
				sum=1150+125*(L-10);
				pl(4280-sum);
			}
			else if(L>20 && L<=30) {
				sum=2400+140*(L-20);
				pl(4280-sum);
			}
			else {
				sum+=3800+(L-30)*160;
				pl(4280-sum);
			}
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static int root(int a) {

		int ketasu=0;
		int tmp=a;
		while(tmp>0) {
			ketasu++;
			tmp/=10;
		}
		int constant=(ketasu+1)/2;	//よく使うので定数化
		if(ketasu>=1) {
			int[] suuji=new int[constant];
			tmp=a;
			for(int i=0; i<constant; i++) {
				suuji[constant-1-i]=a%100;
				a/=100;
			}
			int ans=0;
			int kai=0;
			int mae=0;
			if(constant<=1) {
				for(int i=10; i>=0; i--) {
					if(suuji[0]>=i*i) {
						return i;
					}
				}
			}
			else {
				for(int i=0; i<constant; i++) {
					mae+=kai*2;
					for(int j=9; j>=0; j--) {
						if((mae*10+j)*j<=suuji[i]) {
							ans=ans*10+j;
							mae*=10;
							kai=j;
							if(i+1<constant) {
								suuji[i+1]+=(suuji[i]-(mae+j)*j)*100;
							}
							break;
						}
					}
				}
			}
			return ans;
		}
		else {
			return 0;
		}
	}
}


Measured memory_bytes: 24380
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h;
    cin >> h;
    int a;
    cin >> a;

    int turn = 0;
    while (h > 0)
    {
        ++turn;
        h -= a;
    }
    cout << to_string(turn) << endl;
}


Measured memory_bytes: 256
from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

    mat[a].append((i, b))
    mat[b].append((i, a))

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)





Measured memory_bytes: 39396
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    int A,B,C; cin >> A >> B >> C;
    bool ok = false;
    if(A > B && (B < C && C < A)) ok = true;
    if(A < B && (A < C && C < B)) ok = true;
    cout << (ok ? "Yes" : "No" ) << endl;
}

Measured memory_bytes: 3460
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
int main()
{
	int N,M;
	cin>>N>>M;
	char ans[5];
	int s[6],c[6];
	for(int i=1;i<=M;i++)
	 cin>>s[i]>>c[i];
	int cfl=0;
	if(N==1)
	{
		for(int i=0;i<=9;i++)
		 {
		 	sprintf(ans+1,"%d",i);
		 	int flag=1;
		 	for(int j=1;j<=M;j++)
		 	{
		 		if(ans[s[j]]!='0'+c[j])
		 		{
		 			flag=0;
		 			break;
				 }
			 }
			 if(flag==1)
			 {
			 	cout<<i<<endl;
			 	cfl=1;
			 	break;
			 }
		 }
	}
	else
	if (N==2)
	{
		for(int i=10;i<=99;i++)
		 {
		 	sprintf(ans+1,"%d",i);
		 	int flag=1;
		 	for(int j=1;j<=M;j++)
		 	{
		 		if(ans[s[j]]!='0'+c[j])
		 		{
		 			flag=0;
		 			break;
				 }
			 }
			 if(flag==1)
			 {
			 	cout<<i<<endl;
			 	cfl=1;
			 	break;
			 }
		 }
	}
	else if(N==3)
	{
		for(int i=100;i<=999;i++)
		 {
		 	sprintf(ans+1,"%d",i);
		 	int flag=1;
		 	for(int j=1;j<=M;j++)
		 	{
		 		if(ans[s[j]]!='0'+c[j])
		 		{
		 			flag=0;
		 			
		 			break;
				 }
			 }
			 if(flag==1)
			 {
			 	cout<<i<<endl;
			 	cfl=1;
			 	break;
			 }
		 }
	}
	if(cfl==0)
	cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct cap {
    int st, dr;
    long long costJos, costSus;
    int nrEnd;
} a[500100];

int n;

long long dfs(int root, long long costJos) {
    if(root == n) {
        return 0;
    }
    long long totCost = 0;
    a[root].costJos = costJos;
    totCost += dfs(a[root].st, costJos + 1);
    totCost += dfs(a[root].dr, costJos + 1);
    a[root].nrEnd = (int)(a[root].st == n) + (int)(a[root].dr == n);
    a[root].nrEnd += a[a[root].st].nrEnd + a[a[root].dr].nrEnd;

    a[root].costSus = totCost + a[root].nrEnd;
    return a[root].costSus;
};

long long get_score(int root, bool qs) {
    if (root == 0) {
        if (qs) {
            return (long long)-1;
        }
        return (long long)0;
    }


    if (qs) {
        long long st_qs = get_score(a[root].st, true);
        long long st_nqs = get_score(a[root].st, false);
        long long dr_qs = get_score(a[root].dr, true);
        long long dr_nqs = get_score(a[root].dr, false);

        long long ff = st_nqs + dr_nqs;
        long long tf = st_qs + (long long)1 + dr_nqs;
        long long ft = st_nqs + dr_qs + (long long)1;
        long long tt = st_qs + (long long)1 + dr_qs + (long long)1 + a[root].costJos;

        return min(min(tt, ff), min(tf, ft));
    }
    else {
        if (a[root].st == a[root].dr && a[root].st == 0) {
            return (long long)1;
        }

        return (long long)a[root].nrEnd + a[root].costSus;
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        int x, y;
        cin >> x >> y;
        a[i].st = x;
        a[i].dr = y;
    }
    dfs(1, 0);

    cout << get_score(1, true) << '\n';

    return 0;
}


Measured memory_bytes: 42136
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top;
int S[1000];

void push(int x){
  top++;
  S[top]=x;
}

int pop(){
  top--;
  return S[top+1];
}


int main(){
  int a,b;
  int x;
  top=0;
  char s[100];

  while(scanf("%s", s)!= EOF){
    if ( s[0] == '+' ){
      a=pop();
      b=pop();
      push(a+b);
    } else if ( s[0] == '-' ){
      a=pop();
      b=pop();
      push(b-a);
    } else if ( s[0] == '*' ){
      a=pop();
      b=pop();
      push(a*b);
    } else {
      x = atoi(s);
      push(x);
    }
  }

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



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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007ll
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

namespace{
    std::chrono::system_clock::time_point t;
    void tic(){t=TIME;}
    void toc(){fprintf(stderr,"TIME : %lldms\n",MILLISEC(TIME-t));}
}

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}


class UndirectedGraph{
public:
    size_t n;
    vector<vector<int>> vertex_to;
    
    UndirectedGraph(size_t n):n(n),vertex_to(n){}
    
    void connect(int from, int to){
        vertex_to[from].emplace_back(to);
        vertex_to[to].emplace_back(from);
    }
    vector<int>& operator[](int v){
        return vertex_to[v];
    }
    void resize(size_t _n){
        n = _n;
        vertex_to.resize(_n);
    }
    size_t degree(int v){
        return vertex_to[v].size();
    }

};
    
UndirectedGraph g(10);

int width,height;
int m,n;

int dfs(int x,int sum,vector<bool> v){
    if (v[x]) return 0;
    v[x]=true;
    sum|=1<<x;
    
    
    if (sum == (1<<n)-1) return 1;
    
    int r=0;
    for (int to:g.vertex_to[x]){
        r+=dfs(to,sum,v);
    }
    return r;
}

int main(){
    int i,j,k;
    int x,y,a,b;
    
    cin >> n >> m;
    
    for (i=0;i<m;++i){
        scanf("%d%d",&x,&y);
        g.connect(--x,--y);
        
    }
    
    vector<bool> v(n,false);
    cout << dfs(0,0,v) << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>

struct Union_Find {
    std::vector<int> par;
    std::vector<int> rank;
    std::vector<int> sz;
    //初期化
    void init( int n ) {
        par.resize( n );
        rank.resize( n );
        sz.resize(n);
        for ( int i = 0; i < n; ++i ) {
            par[ i ] = i;
            rank[ i ] = 0;
            sz[ i ] = 1;
        }
    }
    
    //木の根を探す
    int find( int s ) {
        if ( par[ s ] == s ) {
            return s;
        }
        return par[ s ] = find( par[ s ] );
    }
    
    //結合
    void unite( int x, int y ) {
        int a = find( x ), b = find( y );
        if ( a == b ) {
            return;
        }
        int size = sz[a] + sz[b];
        sz[a] = sz[b] = size;
        if ( rank[ a ] < rank[ b ] ) {
            par[ a ] = b;
        }
        else {
            par[ a ] = b;
            if ( rank[ a ] == rank[ b ] ) {
                ++rank[ b ];
            }
        }
    }
    
    //二つの数の根が同じかどうか
    bool same( int x, int y ) {
        return find( x ) == find( y );
    }
    
    //サイズを返す
    unsigned int size(int n) {
        return sz[find(n)];
    }
};

using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;
    Union_Find uf;
    uf.init(n);
    vector<pair<int, int>> p(m);
    for(auto&& i : p){
        cin >> i.first >> i.second;
        i.first--;
        i.second--;
    }
    vector<long long> ans(m);
    ans[m - 1] = n * (n - 1) / 2;
    for(long long i = m - 1; i > 0; i--){
        if(uf.same(p[i].first, p[i].second)){
            ans[i - 1] = ans[i];
        }else{
            ans[i - 1] = ans[i] - uf.size(p[i].first) * uf.size(p[i].second);
            uf.unite(p[i].first, p[i].second);
        }
    }
    for(auto&& i : ans){
        cout << i << "\n";
    }
}

Measured memory_bytes: 4096
# DPを用いて解く。
# 少し複雑なので、自分の解説と照らし合わせて読むこと。
MOD = 10**9+7
N = int(input())

# AGCT→0123として扱う

# dpテーブルの作成shape=(101, 3,3,3) #長さが0~100まで扱いたいため
import numpy as np
dp = np.zeros((N+1, 4, 4, 4), dtype="longlong")

dp[0, 3, 3, 3] = 1  # 解説放送流テクニカルな楽な初期化
# 末尾がc3,c2,c1で終わる長さlの文字列の通りの数を計算していく
# print(dp)
for l in range(N):
    for c3 in range(4):
        for c2 in range(4):
            for c1 in range(4):
                # すでに条件を満たしていないのでスキップ(なくても多分平気)
                if dp[l, c3, c2, c1] == 0:
                    continue
                # 最後につける一文字を考える
                for a in range(4):
                    # あかん条件
                    if a == 1 and c1 == 2 and c2 == 0:
                        continue
                    if a == 2 and c1 == 1 and c2 == 0:
                        continue
                    if a == 2 and c1 == 0 and c2 == 1:
                        continue
                    if a == 2 and c1 == 1 and c3 == 0:
                        continue
                    if a == 2 and c2 == 1 and c3 == 0:
                        continue
                    dp[l + 1, c2, c1, a] += dp[l, c3, c2, c1] % MOD
                    dp[l + 1, c2, c1, a] %= MOD

print(dp[N, :, :, :].sum() % MOD)


Measured memory_bytes: 12484
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    int n, m;
    cin >> n >> m;
    rep (i, m) {
        int x;
        cin >> x;
        n -= x;
    }
    if (n < 0) {
        cout << -1 << endl;
    }
    else {
        cout << n << endl;
    }
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 1000005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < SIZE; ++i) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

// 組み合わせ（重複無し）
LL comb(int n, int k) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

// 二項係数
LL Bin(LL n, LL k) {
    if(k < 0 || n < k) {
        return 0;

    }
    LL ret = 1;
    for(LL i = 1; i <= k; ++i) {
        ret *= n--;
        ret /= i;

    }
    return ret;
}

// 重複組み合わせ
LL comb_rep(int x, int y) {
    return comb(x + y - 1, x - 1);

}

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

    int N;
    cin >> N;
    combInit();

    vector<LL> a(N + 1);
    LL t = 4;
    for(int i = 2; i <= N; ++i) {
        a[i] = comb(N, i);
        a[i] *= (t - 2);
        a[i] %= MOD;
        t *= 2;
        t %= MOD;
    }

    LL res = 0;
    LL e = 1;
    for(int i = N; i >= 2; --i) {
        res += a[i] * e;
        res %= MOD;
        e *= 8;
        e %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 34320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
ll modpow(long long a, long long n, long long mod2) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod2;
        a = a * a % mod2;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n,k,ans = INF;
    cin >> n >> k;
    vector<ll> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    for (int i = 0; i+k-1 < n; ++i) {
        ans = min(ans,h[i+k-1] - h[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
x = []
y = []
h = []
for i in range(n):
    x1,y1,h1=[int(i) for i in input().split()]
    x.append(x1) 
    y.append(y1) 
    h.append(h1)

flag = 0
a,b,c = 0,0,0
for i in range(101):
    if flag:
        break
    else:
        for j in range(101):
            if flag:
                break
            else:
                for k in range(n):
                    if h[k] != 0:
                        first = abs(x[k]-i)+abs(y[k]-j)+h[k]
                        break
                ct = 0
                for k in range(n): 
                    tmp = abs(x[k]-i)+abs(y[k]-j)+h[k]
                    if first == tmp or (first < tmp and h[k]==0):
                        ct += 1
                    if ct == n:
                        a,b,c = i,j,first
                        flag = 1

print("{} {} {}".format(a,b,c))

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}

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

int h, w;

vector<string> mat(1005);
vector<vector<int>> dist(1005, vector<int>(1005, INF));

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

  IN(h, w);
  rep(i, h) IN(mat[i]);

  queue<pii> que;

  rep(i, h) rep(j, w) {
    if (mat[i][j] == '#') {
      que.push(make_pair(i, j));
      dist[i][j] = 0;
    }
  }

  i64 res = 0;
  while (!que.empty()) {
    pii now = que.front();
    que.pop();

    for (int i = 0; i < 4; ++i) {
      int ny = now.first + dy[i];
      int nx = now.second + dx[i];
      if (inside(nx, ny, w, h) &&
          dist[ny][nx] > dist[now.first][now.second] + 1 &&
          mat[ny][nx] != '#') {

        int norm = dist[now.first][now.second] + 1;
        mat[ny][nx] = '#';
        chmin(dist[ny][nx], norm);
        chmax(res, dist[ny][nx]);
        que.push(make_pair(ny,nx));
      }
    }
  }

  OUTL(res);

  return 0;
}


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

using namespace std;

int a[100001];
long long ct[100001];
long long cnt[100001];
long long ans[100001];

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<pair<int, int> > v;
    v.push_back({0, -1});
    for (int i = 0; i < n; i++){
        if (a[i] > v.back().first){
            v.push_back({a[i], i});
        }
    }
    for (int i = n - 1; i >= 0; i--){
        int l = 0;
        int r = v.size();
        while (l < r - 1){
            int m = (l + r) / 2;
            if (v[m].first < a[i]){
                l = m;
            }
            else{
                r = m;
            }
        }
        ct[l] += a[i] - v[l].first;
        cnt[l]++;
    }
    for (int i = v.size() - 1; i > 0; i--){
        ct[i - 1] += cnt[i] * (v[i].first - v[i - 1].first);
        cnt[i - 1] += cnt[i];
    }
    for (int i = v.size() - 1; i > 0; i--){
        ans[v[i].second] = ct[i - 1];
    }
    for (int i = 0; i < n; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 4724
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
map<long long,long long> m;vector<long long> v;long long d[100008];long long n;
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	cin>>n;for(long long i=0;i<n;i++)
	{
		long long o;cin>>o; m[o]++;v.push_back(o);
	}
	for(long long i=0;i<v.size();i++) d[i]=v[i];
	sort(d,d+v.size());reverse(d,d+v.size());
	long long rt=0;
	for(long long i=0;i<v.size();i++)
	{
		long long k=d[i];
		if(m[k]>=2 and rt==0) rt=k,m[k]-=2;
		if(m[k]>=2 and rt!=0) 
		{
			cout<<rt*k;return 0;
		}
	}
	cout<<0;
	return 0;
}

Measured memory_bytes: 8052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

string s;

int main() {
	cin >> s;
	ll ans = -1;
	rep(i, (1 << 3)) {
		ll sum = s[0] - '0';
		rep(j, 3) {
			if (i&(1 << j))sum += s[j + 1] - '0';
			else sum -= s[j + 1] - '0';
		}
		if (sum == 7)ans = i;
	}
	cout << s[0];
	rep(j, 3) {
		if (ans&(1 << j)) {
			cout << "+" << s[j + 1];
		}
		else cout << "-" << s[j + 1];
	}
	cout << "=7" << endl;
}

Measured memory_bytes: 256
/*
 *	Argorithms and Data Structures
 *	Lectuire 5 
 *	Koch Curve
 */

#include <stdio.h>

#define Sin60 0.866025
#define Cos60 0.5

typedef struct{
	double x;
	double y;
} Pos;

void TrisectionLine(Pos *s, Pos *t, Pos p1, Pos p2){
	s->x = ( 2.0*(p1.x) + (p2.x) ) / 3.0;
	s->y = ( 2.0*(p1.y) + (p2.y) ) / 3.0;

	t->x = ( (p1.x) + 2.0*(p2.x) ) / 3.0;
	t->y = ( (p1.y) + 2.0*(p2.y) ) / 3.0;
}

void CalcThirdPos(Pos *u, Pos s, Pos t){
	u->x = (t.x - s.x)*Cos60 - (t.y - s.y)*Sin60 + s.x;
	u->y = (t.x - s.x)*Sin60 + (t.y - s.y)*Cos60 + s.y;
}

void PutPos(Pos p){
	printf("%f %f\n", p.x, p.y);
}

void kock(int n, Pos p1, Pos p2){
	Pos s, t, u;
	
	if(n==0) return;

	TrisectionLine(&s, &t, p1, p2);
	CalcThirdPos(&u, s, t);

	kock(n-1, p1, s);	PutPos(s); 
	kock(n-1, s, u);	PutPos(u);
	kock(n-1, u, t);	PutPos(t);
	kock(n-1, t, p2);
}
	
int main(void){
	int n;
	Pos p1, p2;

	p1.x = 0.0;
	p1.y = 0.0;

	p2.x = 100.0;
	p2.y = 0.0;

	scanf("%d", &n);
	PutPos(p1);
	kock(n, p1, p2);
	PutPos(p2);
	return 0;	
}

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

using namespace std;

int main(){
    int a,b,c,o;
    cin>>a>>b>>c>>o;
    int bneed=0;
    int cneed=0;
    bool shouldno=false;
    while (a>=b)
    {
        if(o==0)
        {
            shouldno = true;
            break;
        }
        b = b*2;
        o--;
    }
    while (b>=c)
    {
        if(o==0)
        {
            shouldno = true;
            break;
        }
        c = c*2;
        o--;
    }
    if(shouldno)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    
    

    //system("PAUSE");





}

Measured memory_bytes: 3624
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

main(){
	int n;string s;cin>>n>>s;
	vint v;
	for(int i=0;i<s.size();i++){
		if(i+1!=s.size()&&s[i]==s[i+1]){
			v.pb(2);i++;
		}
		else v.pb(1);
	}
	int ans=3*v[0];
	for(int i=1;i<v.size();i++){
		if(v[i-1]==1&&v[i]==1)ans*=2;
		if(v[i-1]==1&&v[i]==2)ans*=2;
		if(v[i-1]==2&&v[i]==2)ans*=3;
		ans%=MOD;
	}
	dans;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define IOS ios::sync_with_stdio(0);
signed main()
{
	//IOS
	long long int t;
	while(cin>>t)
	{
		long long int l[t];
		long long int max=-1;
		long long int min=-1;
		for(long long int i=0;i<t;i++) 
		{
			cin>>l[i];
			if(max<l[i]) max=l[i];
			if(min==-1||min>l[i]) min=l[i];
		}
		long long int ans=-1;
		for(long long int i=min;i<=max;i++)
		{
			long long int n=0;
			for(long long int j=0;j<t;j++)
			{
				n+=(l[j]-i)*(l[j]-i);
			}
			if(ans==-1||ans>n) ans=n;
		}
		cout<<ans<<"\n";
	}
 } 

Measured memory_bytes: 256
#nは桁数　 (1,0)が含まれてる時と、(2,4),(2,7)みたいな入力の時はだめ
n,m = map(int,input().split())
s = [0]*m
c = [0]*m
d = dict()
ans = 0

for x in range(m):
    s[x],c[x] = map(int,input().split())
    if s[x] not in d:
        d[s[x]] = c[x]
    elif d[s[x]] != c[x]:
        ans = -1
        break

else:
    ans = ""
    for x in range(1,n+1):
        if x in d :
            if x != 1:
                ans += str(d[x])
            elif x == 1 and d[x] != 0:
                ans += str(d[x])
            elif n == 1 and d[x] == 0:
                ans += "0"
            else:
                ans = -1
                break
        else:
            if m != 0:
                if x == 1:
                    ans += str(1)
                else:
                    ans += str(0)
            else:
                if n == 1:
                    ans = str(0)
                else:
                    ans = "1" + ("0"*(n-1))

print(ans)


Measured memory_bytes: 9236
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

int main(void){
    ll a,b;
    cin >> a >> b;
    auto v=prime_factor(gcd(a,b));
    cout << v.size()+1 << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define SUM(x) ((x)*(x+1)/2)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i = 0; i < 26; i++)
        cin >> c[i];
    vector<vector<int>> s(D, vector<int>(26));
    for (int i = 0; i < D; i++)
        for (int j = 0; j < 26; j++)
            cin >> s[i][j];

    vector<int> t(D);
    {
        vector<int> last(26, 0);
        for (int i = 1; i <= D; i++) {
            int mx = -1000000000, ti = 0;
            for (int k = 0; k < 26; k++) {
                int sd = s[i-1][k];
                for (int l = 0; l < 26; l++) {
                    if (l == k)
                        continue;
                    sd -= c[l] * (i - last[l]);
                }
                if (sd > mx) {
                    mx = sd;
                    ti = k;
                }
            }
            last[ti] = i;
            t[i-1] = ti+1;
        }
    }
    
    int score = 0;
    {
        vector<int> last(26, 0);
        for (int i = 1; i <= D; i++) {
            score += s[i-1][t[i-1]-1];
            last[t[i-1]-1] = i;
            for (int j = 0; j < 26; j++)
                score -= c[j] * (i - last[j]);
        }
    }
    int m = 100000;
    mt19937 mt((int)time(0));
    for (int i = 0; i < m; i++) {
        int d = mt() % D + 1, q = mt() % 26 + 1;
        int p = t[d-1];
        t[d-1] = q;
        
        int score2 = 0;
        vector<int> last(26, 0);
        for (int i = 1; i <= D; i++) {
            score2 += s[i-1][t[i-1]-1];
            last[t[i-1]-1] = i;
        for (int j = 0; j < 26; j++)
            score2 -= c[j] * (i - last[j]);
        }
        if (score < score2)
            score = score2;
        else
            t[d-1] = p;
    }
    
    for (int i = 0; i < D; i++)
        cout << t[i] << endl;
    
    //cout << "score:" << score << endl;
    
    return 0;
}


Measured memory_bytes: 3672
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 4 * N + 5;

map<pair<int, int>, bool> vis;
map<pair<int, int>, int> cnt;

int getSum(int x, int y){
    int ret = 0;

    for(int i = x ; i <= x + 2 ; ++i)
        for(int j = y ; j <= y + 2 ; ++j)
            ret += (vis.find(make_pair(i, j)) != vis.end());

    return ret;
}

int n, m;

ll out[10];

bool isOut(int x, int y){
    return (x <= 0 || y <= 0 || x + 2 > n || y + 2 > m);
}

void solve(int x, int y){
    for(int i = 0 ; i < 3 ; ++i)
        for(int j = 0 ; j < 3 ; ++j)
            if(!isOut(x - i, y - j))
                cnt[make_pair(x - i, y - j)] = getSum(x - i, y - j);
}

int main(){
    int h;
    scanf("%d %d %d", &n, &m, &h);
    vector<pair<int, int> > points;
    while(h--){
        int x, y;
        scanf("%d %d", &x, &y);
        vis[make_pair(x, y)] = true;
        points.emplace_back(x, y);
    }

    for(auto p : points)
        solve(p.first, p.second);


    out[0] = (1ll * n - 2) * (1ll * m - 2);

    for(auto p : cnt)
        ++out[p.second], --out[0];


    for(int i = 0 ; i <= 9 ; ++i)
        printf("%lld\n", out[i]);

}

Measured memory_bytes: 63476
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    S = list(input()[:-1])

    ans = 0
    for i in range(1, N):
        A = set(S[:i])
        B = set(S[i:])
        ans = max(ans, len(A&B))
    
    print(ans)


if __name__ == '__main__':
    main()

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

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

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll a, b;
  cin >> a >> b;

  if (a >= 13) {
    cout << b << endl;
  } else if (a >= 6) {
    cout << b / 2 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<math.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define il inline
#define rg register
using namespace std;
il int gi ( ){
	rg int o=0,fl=1;
	char ch=getchar();
	while(!isdigit(ch))fl^=ch=='-',ch=getchar();
	while(isdigit(ch))o=10*o+ch-48,ch=getchar();
	return fl?o:-o;
}
int n,t,x,s,id;
double h,ans=100000000.0;
int main ( ){
	n=gi(),t=gi(),x=gi();
	for(int i=1;i<=n;i++){
		s=gi();
		h=t-(double)s*0.006;
		if(fabs(h-x)<ans)ans=fabs(h-x),id=i;
	}
	printf("%d\n",id);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

vector<int> z_algorithm(const string& s){
    int len = s.length();
    vector<int> table(len);
    table[0] = len;

    int i = 1;  // 今見ている左端
    int j = 0;  // common prefix length
    while(i < len){
        while(i + j < len && s[j] == s[i + j])  ++j;
        table[i] = j;

        if(j == 0){
            ++i;
            continue;
        }

        // 共通接頭辞である場合、どこまで一致するか
        int k = 1;
        while(i + k < len && k + table[k] < j){
            table[i + k] = table[k];
            ++k;
        }
        // 一致した分だけ i と j を処理しておく
        i += k, j -= k;
    }

    return table;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        vector<int> table = z_algorithm(s.substr(i, n - i));
        int sz = table.size();
        int res = 0;
        for(int j = 1; j < sz; ++j){
            if(j >= table[j])   chmax(res, table[j]);
        }
        chmax(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let v: Vec<usize> = sc.next_vec(n);
    let sum = v.iter().sum();
    let mut min = sum;
    for x in v {
        if x % 10 != 0 && min > x {
            min = x;
        }
    }
    println!("{}",sum - if sum % 10 == 0 {min} else {0});
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 4352
// BEGINNING WITH NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
// ATCODER BEGINNERS PROBLEMS
//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.flush();
    int n;
    cin >> n;
    int temp = n;
    int fa = 100;
      int rev=0;
    while(n>0)
    {
      rev += fa*(n%10);
      fa/=10;
      n/=10;
    }
//    cout<<rev<<endl;
    (rev==temp) ? cout<<"Yes" : cout<<"No";
    return 0;
    // Bye Bye 2019
}



Measured memory_bytes: 256
n=int(input())
t=[[0]*10 for _ in range(10)]
for i in range(1,n+1):
    s=str(i)
    t[int(s[0])][int(s[-1])]+=1
ans=0
for i in range(10):
    for j in range(10):
        ans+=t[i][j]*t[j][i]
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {
  public static int min(int a, int b) {
    return a < b ? a : b;
  }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[][] counts = new int[2][100001];
    for (int i = 0; i < n; i++) {
      counts[i % 2][scanner.nextInt()]++;
    }
    int[][] maxCnt = { { 0, 0 }, { 0, 0 } };
    int[] maxValue = { 0, 0 };
    for (int i = 0; i <= 100000; i++) {
      for (int j = 0; j < 2; j++) {
        if (counts[j][i] > maxCnt[j][0]) {
          maxCnt[j][1] = maxCnt[j][0];
          maxCnt[j][0] = counts[j][i];
          maxValue[j] = i;
        } else if (counts[j][i] > maxCnt[j][1]) {
          maxCnt[j][1] = counts[j][i];
        }
      }
    }
    int[] e1 = { maxCnt[0][0], maxValue[0] }, o1 = { maxCnt[1][0], maxValue[1] };
    int e2 = maxCnt[0][1], o2 = maxCnt[1][1];
    if (e1[1] != o1[1]) {
      System.out.println(n - e1[0] - o1[0]);
    } else {
      System.out.println(min(n - e1[0] - o2, n - e2 - o1[0]));
    }
  }
}


Measured memory_bytes: 62948
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int dp[2010][2010][2];

int main(){
    int M,N;
    cin >> M >> N;
    string S,T;
    cin >> S >> T;
    //dp[i][j][k]=Sのi文字目、Tのj文字目まで見て、列車の末尾がkの時に作れる最長の列車の長さ
    dp[0][0][0]=dp[0][0][1]=0;
    int res = 0;
    FOR(i,0,M+1){
        FOR(j,0,N+1){
            int tmp = 0;
            if(i>0)if(S[i-1]=='I')tmp = max(tmp,dp[i-1][j][0]+1);
            if(j>0)if(T[j-1]=='I')tmp = max(tmp,dp[i][j-1][0]+1);
            dp[i][j][1]=tmp;

            tmp = 0;
            if(i>0)if(S[i-1]=='O'&&dp[i-1][j][1]>0)tmp = max(tmp,dp[i-1][j][1]+1);
            if(j>0)if(T[j-1]=='O'&&dp[i][j-1][1]>0)tmp = max(tmp,dp[i][j-1][1]+1);
            dp[i][j][0]=tmp;      

            res = max(res,dp[i][j][1]);      
        }
    }
    cout << res << endl;
    return 0;
}


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

int main(){
    // input
    int N;
    string S;
    cin >> N >> S;

    // count slime
    int ans = 1;
    for(int i=1; i<N; i++ ){
        if( S[i] != S[i-1] ){
            ans++;
        }
    }

    // output
    cout << ans << endl;
} 


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main() {
    //変数の宣言
    char T1[201], T2[201];
    int m, h; //シャッフルの回数, まとめて移動する分
    int i, j, k; //処理用
    
    while(1) {
        scanf("%s\n%d", T1, &m); //トランプの並びとシャッフルの回数の入力
        if (!strcmp(T1, "-")) { //ハイフンが入力されたら終了
            break;
        }
        
        for (i=0; i<m; i++) {//シャッフルの回数だけ
            scanf("%d", &h); //まとめて移動する分　入力
            for (j=h; T1[j] != '\0'; j++) { //移動する分の境からカードの終わりまで
                T2[j-h] = T1[j]; //入れ替える（残された側の再配置
            }
            for (k=0; k<h; k++) { //カードの最初から境まで
                T2[j-h+k] = T1[k]; //（後方に持っていく側
            }
            for (j=0; T1[j] != '\0'; j++) {
                T1[j] = T2[j]; //これらをT1に返す
            }
        }
        //出力
        printf("%s\n", T1);
    }
    
    return 0;
}



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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#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 DEBUG if(0)
#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;
// 階乗
// O(n)
#define SZ 1000010
const int mod=1e9+7;
LL fact[SZ];
struct fact_{
    fact_(){
        fact[0]=1;
        for(int i=1;i<SZ;i++)
            fact[i]=fact[i-1]*i%mod;
    }
}fact_init;

int main(){
    LL N,M;
    cin>>N>>M;
    if(N==M){
        
        cout<<(2*fact[N]%mod)*fact[N]%mod<<endl;
        
    }
    else if(abs(N-M)==1){
        cout<<fact[N]*fact[M]%mod<<endl;

    }
    else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 8064