akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <climits>

struct Edge{
    long long from;
    long long to;
    long long cost;
};

using namespace std;
using Edges = vector<Edge>;
const long long INF = (1LL << 63) -1 ;
pair<bool, vector<vector<long long> > > bellman_ford(long long begin_idx, long long  N, const Edges& Es){
    //それぞれの頂点へ最短経路距離を保存する配列
    //始点0 ,その他はINF
    //どの頂点がサイクルになっちゃって更新されているのかも1idxで記録
    vector<vector<long long>>  dist_and_updatedflag(N, vector<long long>(2));

    for(int i=0; i<N; ++i){
        dist_and_updatedflag[i][0] = INF;
        dist_and_updatedflag[i][1] = false;
    }

    dist_and_updatedflag[0][0] = 0;

    int cnt = 0;
    while(cnt < N){
        bool end = true;

        for(auto e: Es){
            if(dist_and_updatedflag[e.from][0] != INF && dist_and_updatedflag[e.from][0] + e.cost < dist_and_updatedflag[e.to][0] ){
                dist_and_updatedflag[e.to][0] = dist_and_updatedflag[e.from][0] + e.cost; 
                //一回でも更新したら,終わりではない
                end = false;
                //最後に更新された頂点を記録
                if(cnt == N -1){
                    dist_and_updatedflag[e.to][1] = true;
                }
            }
        }
        //更新がなかったらループ抜ける
        if(end) break;
        cnt++;
    }
    
    return {cnt == N, dist_and_updatedflag};
}

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

    Edges edges(M);
    for(int i=0; i<M; ++i){
        long long a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges[i] = {a, b, -c};
    }

    const auto& dist = bellman_ford(0, N, edges);
    if(dist.first == true){
        if(dist.second[N-1][1] == true){
            cout << "inf" << endl;
        }else{
            cout << -dist.second[N-1][0] << endl;
        }
    } else{
        cout << -dist.second[N-1][0] << endl;
    }   
}

Measured memory_bytes: 3740
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define LL long long
#define ULL unsigned long long 
#define LD long double
#define sqr(x) (x)*(x)  

const int MAXN = 2500000;
const int MAXM = 30;
const int INF = 0x7fffffff;
const int MOD = 1e9+7;
const double eps = 1e-5;
const double pi=acos(-1);

struct rec{double x, y, z;}a[30], b[30];

bool check(int x, int n, int s) {
	int ss = 0;
	int i = 0;
	while (x > 0) {
		i++;
		if (x % 2 == 1) ss++;
		x /= 2;
	}
	if (i > n) return 0;
	if (ss != s) return 0;
	return 1;
}
double cal(int x) {
	int i = 0;
	int nn = 0;
	while (x > 0) {
		++i;
		if (x % 2 == 1) {
			b[++nn] = a[i];
		}
		x /= 2;
	}
	double t = 0;
	for (int i=1; i<=nn-1; ++i) {
		for (int j=i+1; j<=nn; ++j){
			double xx = (b[i].x - b[j].x) * (b[i].x - b[j].x);
			double yy = (b[i].y - b[j].y) * (b[i].y - b[j].y);
			double zz = (b[i].z - b[j].z) * (b[i].z - b[j].z);
			t += xx + yy + zz;
		}
	}
	return t;
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; ++i) {
		scanf("%lf%lf%lf", &a[i].x, &a[i].y, &a[i].z);
	}
	double ans = 0;
	for (int i=1; i<=2097152; ++i) {
		if (check(i, n, m)) {
//			printf("%d\n", i);
			ans = max(ans, cal(i)); 
		}
	}
	printf("%.9lf\n", ans);
}

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

using namespace std;

const int maxn = 200005;

int a[maxn],b[maxn],n;

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    sort(a,a+n);
    int midr=a[n/2],midl=a[n/2-1];

    for (int i=0;i<n;i++)
    {
        if (b[i]<midr) printf("%d\n",midr);
        else printf("%d\n",midl);
    }

    return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
int main(){
	unsigned short row;            	/* 行数格納用変数 */
	int col;            	/* 列数格納用変数 */
	int sheet[101][101];	/* 表格納用配列 */
	int i,j;            	/* ループ変数 */
	
	/* 配列の初期化 */
	for(i = 0;i < 101;i++){
		for(j = 0;j < 101;j++){
			sheet[i][j] = 0;
		}
	}
	
	/* 行数、列数の入力 */
	scanf("%d %d", &row, &col);
	
	/* 表の要素の入力 */
	for(i =0;i < row;i++){
		for(j = 0;j < col;j++){
			/* i行j列の要素の入力 */
			scanf("%d", &sheet[i][j]);
		}
	}
	
	/* 各行の要素の合計の計算 */
	for(i =0;i < row;i++){
		for(j = 0;j < col;j++){
			/* i行j列の要素をi行末端に加算 */
			sheet[i][col] += sheet[i][j];
		}
	}
	
	/* 各列の要素の合計の計算 */
	for(i =0;i < row;i++){
		for(j = 0;j < col;j++){
			/* i行j列の要素をj列末端に加算 */
			sheet[row][j] += sheet[i][j];
		}
	}
	
	/* 全要素の合計の計算 */
	for(i = 0;i < row;i++){
		/* 各行の合計を表の末端に加算 */
		sheet[row][col] += sheet[i][col];
	}
	
	/* 表を出力 */
	for(i =0;i <= row;i++){
		for(j = 0;j < col;j++){
			/* i行j列の要素の出力 */
			printf("%d ", sheet[i][j]);
		}
		/* 末列の出力 */
		printf("%d\n", sheet[i][col]);
	}
	return 0;
}


Measured memory_bytes: 2028
N = int(input())
a = list(map(int, input().split()))

from fractions import gcd
x = a[0]
for i in range(N-1):
    x = (x * a[i+1]) // gcd(x, a[i+1])

# ans = []
# for i in range(x-10, x+10):
#     r = 0
#     for ai in a:
#         r += i % ai
#     ans.append(r)

# print(ans)


r = 0
for ai in a:
    r += (x - 1) % ai
print(r)

Measured memory_bytes: 5176
#include <iostream>

using namespace std;

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

    for (int i = 0; i<input.size(); i++) {
        if (input[i] == '9')
            input[i] = '1';
        else
            input[i] = '9';
    }

    cout << input;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
xs = list(map(int, input().split()))
xs = [0] + xs + [0]
dist = {}

total = 0

for i in range(n+1):
  dist[(i, i+1)] = abs(xs[i+1] - xs[i])
  total += dist[(i, i+1)]

for i in range(n):
  dist[(i, i+2)] = abs(xs[i+2] - xs[i])

for i in range(1, n+1):
  d = total - dist[(i-1, i)] - dist[(i, i+1)] + dist[(i-1, i+1)]
  print(d)


Measured memory_bytes: 83560
l, k = map(int, raw_input().split())

d = [[0, 0] for i in xrange(l + 1)]
d[0][1] = 1
s = 0
for i in xrange(1, l + 1):
    d[i][0] = d[i - 1][1]
    d[i][1] = d[i - 1][0]
    if i >= k:
        d[i][0] += d[i - k][1]
    s += d[i][0]
print s

Measured memory_bytes: 4656
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
char str[maxn];
int main(){
    scanf("%s",str);
    int a = 0, b = 0;
    for (int i=0;str[i];i++) if (str[i] == '0') a++; else b++;
    printf("%d\n",min(a,b)*2);
    return 0;
}


Measured memory_bytes: 384
use proconio::input;

fn f(s: &[char], t: &[char]) -> usize {
    let mut res = 0;
    for i in 0..t.len() {
        if s[i] != t[i] {
            res += 1;
        }
    }
    res
}

fn main() {
    input! {
        s: String,
        t: String,
    }
    let s: Vec<_> = s.as_str().chars().collect();
    let t: Vec<_> = t.as_str().chars().collect();

    let mut res = s.len();
    for i in 0..=(s.len() - t.len()) {
        let cur = f(&s[i..], &t);
        res = res.min(cur);
    }
    println!("{}", res);
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e18
#define common cout << "Case #" << w+1 << ": "  



unordered_map<int,int> primefactors(int n)  
{
    int f=0;
    unordered_map<int,int>m;
    while (n % 2 == 0)  
    {  
        f+=1;  
        n = n/2;  
    }  
    if(f>0)
    {
        m[2]=f;
        f=0;
    } 
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {   
        while (n % i == 0)  
        {  
            f+=1;  
            n = n/i;  
        } 
        if(f>0)
        {
            m[i]=f;
            f=0;
        }  
    }  
    if (n > 2)  
        m[n]=1; 
    return m;
}

int gcd(int a,int b)
{
    if(b>a)
    {
        int t=b;
        b=a;
        a=t;
    }
    if(a%b==0)
        return b;
    return gcd(b,a%b);
}

int main()
{
    fastio;
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin >> v[i];
    set<int>s;
    int f=1;
    for(int i=n-1;i>-1 and f==1;i--)
    {
        unordered_map<int,int>m=primefactors(v[i]);
        unordered_map<int,int>:: iterator it;
        for(it=m.begin();it!=m.end();it++)
        {
            if(s.find(it->first)!=s.end())  
                f=0;
            s.insert(it->first);
        }
    }
    if(f==1)
        cout << "pairwise coprime" << endl;
    else
    {
        int g=v[0];
        for(int i=1;i<n;i++)
            g=gcd(g,v[i]);
        if(g==1)
            cout << "setwise coprime" << endl;
        else
            cout  << "not coprime" << endl;
    }
}

Measured memory_bytes: 7252
n,k,q = map(int,input().split())
a = [int(input()) for i in range(q)]
d = k - q
count = [d]*n
for j in range(q):
  count[a[j]-1] += 1
for l in range(n):
  if count[l] > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 10600
#  --*-coding:utf-8-*--

def dsMakeSet(ds, x):
    ds[x] = x


def dsFind(ds, x):
    if ds[x] == x:
        return x

    x0 = x
    while ds[x] != x:
        x = ds[x]

    ds[x0] = x
    return x


def dsUnion(ds, x, y):
    xRoot = dsFind(ds, x)
    yRoot = dsFind(ds, y)
    
    if xRoot != yRoot:
        ds[yRoot] = xRoot
        return True

    return False


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

    ds = [i for i in range(N+1)]
    cntOfF = [0]*(N+1)
    blocks = [set() for _ in range(N+1)]

    for _ in range(M):
        a, b = map(int, input().split())
        dsUnion(ds, a, b)
        cntOfF[a] += 1 
        cntOfF[b] += 1 

    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    Q = {}
    for i in range(1, N+1):
        root = dsFind(ds, i)
        if not(root in Q):
            Q[root] = set()

        Q[root].add(i)
    
    X = []
    for i in range(1, N+1):
        root = dsFind(ds, i)
        q = Q[root]
        block = blocks[i]

        x = len(q) - 1 - cntOfF[i] - len(q&block)
        X.append(x)

    print(' '.join(map(str, X)))



main()


Measured memory_bytes: 81448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	string a="abcdefghijklmnopqrstuvwxyz";
	char b;
	cin>>b;
	for(int i=0;i<26;i++)
	{
		if(a[i]==b)
		{
			cout<<a[i+1]<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
S = input()

sum = 0

for i in range(2**(len(S)-1)):
    op_list = ["+"]*(len(S)-1)
    for j in range(len(S)-1):
        if (i>>j)&1:
            op_list[j]=""

    s = ""

    for j in range(len(S)-1):
        s = s + S[j]+op_list[j]

    s = s + S[len(S)-1]

    sum = sum + eval(s)


print(sum)

Measured memory_bytes: 3064
import java.util.Scanner;

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

	int a = sc.nextInt();
	String s = sc.next();

	if (a >= 3200)
	    System.out.println(s);
	else
	    System.out.println("red");
    }
}

Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,n,k;
    cin>>n>>k;
    ll a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    ll dp[n];
    dp[0]=0;
    ll mini=INT_MAX,x,j;
    for(i=1;i<n;i++)
    {
        if(i>=k)
        {
            mini=INT_MAX;
            for(j=1;j<=k;j++)
            {
                x=dp[i-j]+abs(a[i]-a[i-j]);
                if(x<=mini)
                mini=x;
            }
            dp[i]=mini;
        }
        else
        {
            mini=INT_MAX;
            for(j=1;j<=i;j++)
            {
                x=dp[i-j]+abs(a[i]-a[i-j]);
                if(x<=mini)
                mini=x;
            }
            dp[i]=mini;
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List

type MyS = (Int, Int, [(Int, [Int])])

solve :: Int -> Int -> Int -> [(Int,Int)] -> Int
solve bigH bigW bigN xys = minH - 1
  where
  board0 = map f_form $ groupBy f_grp $ sortOn f_sort xys
  f_grp (_,y) (_,y') = y == y'
  f_sort (x,y) = y * (bigH+1) + x
  f_form lst@((_,y):_) = (y, map fst lst)

  minH = minimum (catMaybes (unfoldr f_stUpd initState) ++ [bigH+1])
  initState :: MyS
  initState = (1, 1, board0)
  f_stUpd :: MyS -> Maybe (Maybe Int, MyS)
  f_stUpd (_, _, []) = Nothing
  f_stUpd (x, y, ((by, bxs):rem)) = Just (h, (newX, by, rem))
    where (newX, h) = vacSeat (x + (by - y)) bxs

-- vacSeat 5 [3,4,5,6] ---> (7,Nothing)
-- vacSeat 5 [3,4,5,6,10,12] ---> (7,Just 10)
vacSeat :: Int -> [Int] -> (Int, Maybe Int)
vacSeat t ts =
  head $ filter (\(p,q) -> Just p /= q) $ zip [t..]
  $ map Just (dropWhile (< t) ts) ++ [Nothing]

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bigH,bs_bigW,bs_bigN]:remLines1 = remLines0
      bigH = readBInt bs_bigH
      bigW = readBInt bs_bigW
      bigN = readBInt bs_bigN
      xys = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines1
  in solve bigH bigW bigN xys

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 78076
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=5e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n,k,s;
    cin>>n>>k>>s;
    loop(k,i,0)
        cout<<s<<' ';
    loop(n-k,i,0)
        cout<<s-(s==1?-1:1)<<' ';
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3636
/*
AizuOnline A0505
Title
*/
#include <stdio.h>
// Select Below
#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int m,n;
struct pinf {int place;
             int cnt;
}P[100];
//
int P_comp(const void *x , const void *y)
{
  int n1,n2;
  n1 = ((struct pinf *)x)->cnt;
  n2 = ((struct pinf *)y)->cnt;
  if(n2-n1)
    return(n2-n1);
  n1 = ((struct pinf *)x)->place;
  n2 = ((struct pinf *)y)->place;
  return(n1-n2);
}


main()
{
  int i,j,ans;

  while(EOF != scanf("%d %d",&n,&m) && (n || m))
    {
      for(i=0;i<m;i++)
	{
	P[i].place = i+1;
	P[i].cnt=0;
	}

      for(i=0;i<n;i++)
	for(j=0;j<m;j++)
	  {
	    scanf("%d",&ans);
	    P[j].cnt += ans;
	  }
      qsort(P,m,sizeof(struct pinf),P_comp);
      for(i=0;i<m;i++)
	{
	  printf("%d",P[i].place);
	  if(i<m-1)
	    printf(" ");
	}
      printf("\n");
    }

return(0);
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> v;
typedef pair<int,int>p;
typedef set<int>s;
#define ll long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define FOR(i,a,b) for(int i=a;i>b;--i)
#define FORE(i,a,b) for(int i=a;i>=b;--i)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bg begin()
#define en end()
#define cn continue
/*note

*/
int main()
{
int n,k,sum=0;
cin>>n>>k;
int ar[n];
fr(i,0,n){cin>>ar[i];}
sort(ar,ar+n);
fr(i,0,k){
sum+=ar[i];
}
cout<<sum<<endl;

}



Measured memory_bytes: 3640
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

	using i8 = std::int_least8_t;
	using i32 = std::int_least32_t;
	using i64 = std::int_least64_t;
	using u8 = std::uint_least8_t;
	using u32 = std::uint_least32_t;
	using u64 = std::uint_least64_t;
	using isize = std::ptrdiff_t;
	using usize = std::size_t;

	class rep {
		const usize f, l;

	public:
		class itr {
			friend rep;
			usize i;
			constexpr itr(const usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { ++i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr rep(const usize first, const usize last) noexcept
			: f(first), l(last) {}
		constexpr itr begin() const noexcept { return itr(f); }
		constexpr itr end() const noexcept { return itr(l); }
	};
	class revrep {
		const usize f, l;

	public:
		class itr {
			friend revrep;
			usize i;
			constexpr itr(usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { --i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
		constexpr itr begin() const noexcept { return itr(l); }
		constexpr itr end() const noexcept { return itr(f); }
	};
	template <class T> using vec_alias = std::vector<T>;
	template <class T> auto md_vec(const usize n, const T &value) {
		return std::vector<T>(n, value);
	}
	template <class... Args> auto md_vec(const usize n, Args... args) {
		return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
	}
	template <class T> constexpr T difference(const T &a, const T &b) {
		return a < b ? b - a : a - b;
	}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>
#include<string>

namespace n91 {

	void main_() {
		u32 a, b, c;
		std::cin >> a >> b >> c;
		std::cout << (a == b&&b == c ? "Yes" : "No") << std::endl;
	}

} // namespace n91

int main() {
	n91::main_();
	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d %d %d %d', $cardPlus1Cnt, $cardZeroCnt, $cardMinus1Cnt, $takeCnt);
if ($cardPlus1Cnt > $takeCnt) {
    echo $takeCnt;
} else {
    $minusCnt = $takeCnt - $cardPlus1Cnt - $cardZeroCnt;
    if ($minusCnt < 0) {
        $minusCnt = 0;
    }
    echo $cardPlus1Cnt - $minusCnt;
}

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

int main(){
int N;
  cin >> N;
  vector<int> x(N),y(N),h(N);
  for(int i=0;i<N;i++){
    cin >> x[i] >> y[i] >> h[i];
  }
int max=100;
  for(int posy=0;posy<=max;posy++){
    for(int posx=0;posx<=max;posx++){
    int needh=-1;
      for(int i=0;i<N;i++){
        if(h[i]>0){
          int tmp=h[i]+abs(posy-y[i])+abs(posx-x[i]);
          if(needh==-1){
           needh=tmp;
          }
          else{
            if(needh!=tmp){
            needh=-2;
            break;
            }
          }
        }
      }
     if(needh==-2) continue;
     for(int i=0;i<N;i++){
       if(h[i]==0){
       int dist = abs(posy-y[i])+abs(posx-x[i]);
         if(needh>dist){
           needh=-2;
           break;
         }
       }
     } 
     if(needh==-2)continue;
     cout << posx << " " << posy << " " << needh << endl;
    }
  }


}


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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h,n;
    cin>>h>>n;
    vector <pair<int,int> > a(n);
    for(int i=0;i<n;++i)
    {
        cin>>a[i].first>>a[i].second;
    }
    int dp[h+1];
    dp[0]=0;
    for(int i=1;i<=h;++i)
    {
        int ans=1e18;
        for(int j=0;j<n;++j)
        {
            ans=min(ans,dp[max(0LL,i-a[j].first)]+a[j].second);
        }
        dp[i]=ans;
    }
    /*for(int i=0;i<=h;++i)
    {
        cout<<dp[i]<<" ";
    }*/
    cout<<dp[h];
    return 0;
}


Measured memory_bytes: 384
n=gets().chomp().split(" ")
i=0
a=Array.new(0)
while(i<n[0].to_i)
	a<<gets().chomp()
	i+=1
end
a=a.sort{|a1,a2|
a1<=>a2
}
i=0
while(i<n[0].to_i)
	print(a[i])
	i+=1
end
print("\n")


Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <complex>
#include <iomanip>
#include <algorithm>
using namespace std;

typedef complex<long double> xy;
long eps = 1e-9;
long double dot_product(xy a,xy b) {return (conj(a)*b).real();}
long double cross_product(xy a,xy b) {return (conj(a)*b).imag();}
long double dist_lp(xy a1,xy a2,xy p){
    if(dot_product(a2-a1,p-a1)<eps) return abs(p-a1);
    if(dot_product(a1-a2,p-a2)<eps) return abs(p-a2);
    return abs(cross_product(a2-a1,p-a1))/abs(a2-a1);
}

bool is_online(xy a1,xy a2,xy p){
    return abs(a1-p)+abs(a2-p)<=abs(a1-a2)+eps;    
}

bool is_intersected(xy a1, xy a2, xy b1, xy b2){
    if(is_online(a1,a2,b1) || is_online(a1,a2,b2)) return true;
    if(is_online(b1,b2,a1) || is_online(b1,b2,a2)) return true;
    return (cross_product(a2-a1,b1-a1)*cross_product(a2-a1,b2-a1)<-eps) && 
    (cross_product(b2-b1,a1-b1)*cross_product(b2-b1,a2-b1))<-eps;
}

long double dist_ll(xy a1,xy a2,xy b1,xy b2){
    if(is_intersected(a1,a2,b1,b2)) return 0;
    return min({dist_lp(a1,a2,b1),dist_lp(a1,a2,b2),dist_lp(b1,b2,a1),dist_lp(b1,b2,a2)
    ,abs(a1-b1),abs(a1-b2),abs(a2-b1),abs(a2-b2)});   
}

int N;
long double sx,sy,gx,gy,mi_x,mi_y,ma_x,ma_y;
long double h;


int main(){
    while(cin>>N && N>0){
        long double ans = 1e9;
        cin >> sx >> sy >> gx >> gy;
/*        if(sx>gx){
            swap(sx,sy);
            swap(gx,gy);
        }
*/        xy s = xy(sx,sy),g = xy(gx,gy);
        for(int i=1;i<=N;i++){
            cin >> mi_x >> mi_y >> ma_x >> ma_y >> h;
            if((mi_x<=sx && sx<=ma_x && mi_y<=sy && sy<=ma_y || 
            mi_x<=gx && gx<=ma_x && mi_y<=gy && gy<=ma_y)) ans = 0;
            long double d = min({dist_ll(s,g,xy(mi_x,mi_y),xy(mi_x,ma_y)),
            dist_ll(s,g,xy(mi_x,ma_y),xy(ma_x,ma_y)),
            dist_ll(s,g,xy(ma_x,ma_y),xy(ma_x,mi_y)),
            dist_ll(s,g,xy(ma_x,mi_y),xy(mi_x,mi_y))});
            if(d<=h) ans = min(ans,d);
            else ans = min(ans,(h*h+d*d)/(2.0*h));
        }
        cout << fixed;
        cout << setprecision(10) << ans << endl;
    }
}


Measured memory_bytes: 3272
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    
    if(abs(x-a)>abs(x-b))
    {
        printf("B\n");
    }
    else
    {
        printf("A\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
'use strict';
(function(stdin) {

  var inputs  = stdin.toString().split('\n');
  var cols = inputs[0].split(' ').map(Number);
  var result = (function(numbers, diviser) {

    var isDivisable = (function(diviser) {
      return function(n) {
        return diviser % n === 0;
      };
    })(diviser);

    return numbers.filter(function(v) {
      return isDivisable(v);
    }).length;

  })(range(cols[0], cols[1]), cols[2]);

  console.log(result);

  function range(n, m) {
    var array = [];
    for (var i = n; i < m + 1; i++) {
      array.push(i);
    }
    return array;
  }

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15952
# C問題
N,M = map(int,input().split(" "))
Num = [0]*N
check = [0]*N
flag=0
for i in range(M):
    s,c = map(int,input().split(" "))
    if s==1 and c==0 and N!=1:
        flag=1
        break
    elif check[s-1]==1 and Num[s-1]!=c:
        flag=1
        break
    else:
        Num[s-1] = c
        check[s-1]=1

if flag==1:
    print(-1)
else:
    if N!=1 and Num[0]==0:
        Num[0]=1
    for i in Num:
        print("{}".format(i),end="")
    print("\n",end="")

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

int main() {
  int N, a=0; cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  while(true) {
    bool odd = false;
    for (int i=0; i<N; i++) {
      if (A[i]%2!=0) odd = true;
    }
    if (odd) break;
    for (int i=0; i<N; i++) A[i] /= 2;
    a++;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int mint(int a,int b,int c,int d,int e)
{
    int A=a;int B=b;int C=c;int D=d;int E=e;
    while(A%10!=0)A++;
    while(B%10!=0)B++;
    while(C%10!=0)C++;
    while(D%10!=0)D++;
    while(E%10!=0)E++;
    int sum=A+B+C+D+e;
    if(sum>(a+B+C+D+E))sum=a+B+C+D+E;
    if(sum>(A+b+C+D+E))sum=A+b+C+D+E;
    if(sum>(A+B+c+D+E))sum=A+B+c+D+E;
    if(sum>(A+B+C+d+E))sum=A+B+C+d+E;
    return sum;
}



int main()
{
    int a,b,c,d,e,m;
    cin>>a>>b>>c>>d>>e;
    m=mint(a,b,c,d,e);

    cout<<m;
    return 0;
}


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int k, n;
int main() {
	std::cin >> n >> k;

	std::cout << n - k + 1 << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rrep(i,a,b) for(i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979311599796346854418516159057617187500
#define endl '\n'
const ll N=1e5+5,mod=1000000007;
vector<ll> adj[N];
signed main()
{
    fast;
    ll pro=1,temp,t,m,n,k,i,j,l,r,mid,x,y,z,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,sum=0,flag=1,i1=-1,i2=-1;
	multiset<ll,greater<ll>> ms;
	cin>>n>>m;
	rep(i,1,n)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(i=1;i<=m;i++)
	{
		for(auto e:adj[i])
		{
			ms.insert(e);
		}
		if(ms.size()>0)
		{
			ans+=*(ms.begin());
			ms.erase(ms.begin());
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8320
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
readInt :: BC.ByteString -> Int
readInt = fst . fromJust . BC.readInt
strToInt s = (read :: String -> Int) s

main = do
    n <- readLn :: IO Int
    fs <- map ((map readInt . BC.words)) <$> replicateM n BC.getLine
    ps <- map ((map readInt . BC.words)) <$> replicateM n BC.getLine

    let cd = [0,1]
    let css = [[c0,c1,c2,c3,c4,c5,c6,c7,c8,c9]|c0 <- cd , c1 <- cd , c2 <- cd , c1 <- cd , c3 <- cd , c1 <- cd , c4 <- cd , c5 <- cd , c6 <- cd , c7 <- cd , c8 <- cd , c9 <- cd ,[c0,c1,c2,c3,c4,c5,c6,c7,c8,c9] /= [0,0,0,0,0,0,0,0,0,0] ]
    let ans = [profit fs ps cs n | cs <- css]
    print (maximum ans)
    
profit fs ps cs n  = sum [profita fs ps cs i | i <- [1..n]]
profita fs ps cs i = (ps !! (i-1)) !! n
                     where n = count (fs !! (i-1)) cs 0


count :: [Int] -> [Int] -> Int -> Int
count [] bn n = n
count (a:an) (b:bn) n = if (a==1) && (b==1)
                        then 1 + (count an bn n)
                        else (count an bn n)


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#include "string"
//#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)
const int N = 2e5 + 1;

vector<int>g[N];
int ans[N],a[N];
int n;
vector<int>ve;
stack<int>st;

void dfs(int u,int p){
	int pos = lower_bound(ve.begin(),ve.end(),a[u]) - ve.begin();
	if(pos != ve.size()){
		st.push(ve[pos]);
		ve[pos] = a[u];
	}
	else{
		st.push(-1);
		ve.push_back(a[u]);
	}
	ans[u] = ve.size();
	for(int v:g[u]){
		if(v==p)
			continue;
		dfs(v,u);
	}
	if(st.top() == -1)
		ve.pop_back();
	else{
		pos = lower_bound(ve.begin(),ve.end(),a[u]) - ve.begin();
		ve[pos] = st.top();
	}
	st.pop();
}

int32_t main(){ 
    boost;
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    for(int i=1,u,v;i<n;i++){
    	cin>>u>>v;
    	g[u].push_back(v);
    	g[v].push_back(u);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
    	cout<<ans[i]<<endl;
}


Measured memory_bytes: 28080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int a,b,c,d,sum;

int main(){
	cin>>a;
	d=a%10;
	c=a/10%10;
	b=a/100%10;
	a/=1000;
	sum=(a+b+c+d-7)/2;
	if(sum==b){
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
	}else if(sum==c){
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
	}else if(sum==d){
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
	}else if(sum==b+c){
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
	}else if(sum==b+d){
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
	}else if(sum==c+d){
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
	}else if(sum==b+c+d){
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
	}else{
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long dp[27][200];

int n;
char c;
long long cnt[200];
long long res;
long long M = 1000000007;
int main()
{
    cin>>n;
    for(int i = 0;i<n;i++){
        cin>>c;
        cnt[c]++; 
    }
    //for(int j = 'a';j<='z';j++)cout<<cnt[j]<<" ";
    for(int i = 1;i<=26;i++){
        for(int j = 'a';j<='z';j++){
            if(i == 1){
                dp[i][j] = (dp[i][j-1] + cnt[j])%M;
            }
            else{
                dp[i][j] = (dp[i][j-1] + dp[i-1][j-1]*cnt[j])%M;
            }
            res += dp[i]['z'];
            res %= M;
        }
    }

    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    ll n,a,b;cin>>n>>a>>b;
    ll c=a-b;
    vll h(n);rep(i,n)cin>>h[i];
    ll l=-1;ll r=1e9;ll m,sum;
    while(r-l>1){
        m=(l+r)/2;
        sum=0;
        rep(i,n)sum+=max((ll)0,(h[i]-b*m+c-1)/c);
        if(sum>m)l=m;
        else  r=m;
    }
    cout<<r<<endl;
}

Measured memory_bytes: 4052
from math import sqrt
import itertools

#for i in itertools.permutations(['a', 'b', 'c']):
def distance(dx,dy):
  return sqrt(dx**2 + dy**2)

N=int(input())
xy=[]
for i in range(N):
  x,y=map(int, input().split())
  xy.append((x,y))

ans=0
count=0
for sxy in itertools.permutations(xy):
  #print(sxy)
  for i in range(1,N):
    x2,y2=sxy[i]
    x1,y1=sxy[i-1]
    #print(x1,y1,x2,y2)
    dx=x2-x1
    dy=y2-y1
    ans+=distance(dx,dy)
  count+=1
    
#print(count,ans)
print(ans/count)
    

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

using namespace std;
 
const long long inf = 1e9;
#define ll long long
#define fr(i,a,n) for (int i=a;i<n;i++)
#define rfr(i,n,a) for (int i=n;i>=a;i--)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define endl "\n"
typedef vector<int> VI;
typedef vector<ll> VL;
typedef priority_queue<int> Pqi;
typedef priority_queue<ll> Pql;

ll n, m, k;

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll a,b,c;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	ans += min(a,k);
	k -= a;
	if (k >= 0) {
		k -= b;
	}
	if (k > 0) {
		ans -= min(k,c);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  int e = a+b;
  int f = c+d;
  if (e>f){
    cout << "Left" << endl;
  }
  if(e==f){
    cout << "Balanced" << endl;
}
   if (e<f){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
  return x / gcd(x, y) * y;   // (x * y) / gcd(x, y) だと x*y でオーバフローする可能性あり
}

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

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

  ll ans = lcm(a, b);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{  int n,s;
  cin>>n>>s;
 long int cnt=0;
 for(int i=0;i<=n;i++)
 {  int t1=s-i;
  if(t1>2*n||t1<0)
      continue;
   for(int j=0;j<=n;j++)
    {  int t2=t1-j;
       if(t2>n||t2<0)
           continue;
     cnt++;
    }
 }
 cout<<cnt;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H, W;
		while (true) {
			H = sc.nextInt();
			W = sc.nextInt();
			if (H == 0 && W == 0)
				break;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if ((i == 0 || i == H - 1) || (j == 0 || j == W - 1)) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 35036
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S()

L = [s[1], s[2], s[3] + '==7']
for i in range(8):
    ret = s[0]
    for j in range(3):
        if i & (1 << j):
            ret += '+'
        else:
            ret += '-'
        ret += L[j]
    if eval(ret):
        print(ret.replace('==', '='))
        break

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[0] << c[0] << endl;
  return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define A 26

int main(){
    int n;
    cin >> n;
    vector<short> v(A, 50);

    string S;
    for (int i = 0; i < n; ++i){
        vector<short> tmp(A, 0);
        cin >> S;
        for (auto& c : S){
            tmp[c - 'a'] += 1;
        }

        for (int j = 0; j < A; ++j){
            v[j] = min(tmp[j], v[j]);
        }
    }

    string ans = "";
    for (int i = 0; i < A; ++i){
        for (int j = 0; j < v[i]; ++j){
            ans += (char)(i + 'a');
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
const long long mod=1e9+7;
long long a[100005]={1,1,2,3,5};
bool vis[100005];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    while(m--)
    {
        int ab;
        scanf("%d",&ab);
        a[ab]=0;
        vis[ab]=1;
    }
    for(int i=2;i<=n;i++)
    {
        if(vis[i]==1)continue;
        a[i]=a[i-1]+a[i-2];
        a[i]%=mod;
    }
    printf("%lld",a[n]%mod);
    return 0;
}


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

using namespace std;
typedef long long ll;

vector<int> zalgorithm(string S) {
  int cur = 0;

  vector<int> Z(S.size(), 0);
  for (int i = 1; i < S.size(); ++i) {
    int l = i - cur;
    if (i + Z[l] < cur + Z[cur]) {
      Z[i] = Z[l];
    } else {
      int j = max(0, cur + Z[cur] - i);
      while (i + j < S.size() && S[j] == S[i + j]) j++;
      Z[i] = j;
      cur = i;
    }
  }

  Z[0] = (int)Z.size();
  return Z;
}


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

  int ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    string tmp = s.substr(i);
    vector<int> Z = zalgorithm(tmp);
    for (int j = 1; j < Z.size(); ++j) {
      if (Z[j] < j + 1) {
	ans = max(ans, Z[j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>

using namespace std;

int main(){

        ios::sync_with_stdio(false);
        cin.tie(0);
	
	int n,k;
	
	cin >> n >> k;

	vector<int> p(k);

	for(int i=0;i<k;i++){
		cin >> p[i];
	}

	vector<int> d(k);

	for(int i=0;i<k;i++){
		if(i!=k-1){
			d[i] = p[i+1] - p[i];
		}
		else{
			int a = n - p[i];
			d[i] = a+p[0]; 
		}
	}

	
	int max_d = *max_element(d.begin(),d.end());
	int sum = accumulate(d.begin(),d.end(),0);
	
	cout<<sum-max_d;	
	
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, ans;
  cin >> A>> B >> C;
  priority_queue<int> pq;
  pq.push(A);
  pq.push(B);
  pq.push(C);
  ans = 10*pq.top();
  pq.pop();
  ans += pq.top();
  pq.pop();
  ans += pq.top();
  cout << ans << endl;
}

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

int partition(int* arr, int n) 
{
    const int x = arr[n - 1];   //pivot value
    int i = 0;  //increment if swaped
    int j = 0;  //increment every loop
    for (; j < n; ++j) {   //scan start to end
        if (arr[j] <= x) {
            std::swap(arr[i], arr[j]);
            ++i;
        }
    }
    return i - 1;
}

void print(int const* arr, const int n, int q, int i)
{
    if (i == n - 1 ) {
        std::cout << arr[i] << std::endl;
        return;
    }
    
    if (i == q) {
        std::cout << "[" << arr[i] << "] ";
    }
    else {
        std::cout << arr[i] << " ";
    }

    return print(arr, n, q, i + 1);
}

void print(int const* arr, const int n, int q)
{
    print(arr, n, q, 0);
    return;
}

int main()
{
    int n;
    {
        std::string buf;
        std::getline(std::cin, buf);
        n = std::stoi(buf);
    }

    int arr[100000];
    {
        std::string buf;
        std::getline(std::cin, buf);
        std::stringstream stream;
        stream << buf;
        for (int i = 0; std::getline(stream, buf, ' '); ++i) {
            arr[i] = std::stoi(buf);
        }
    }

    int q = partition(arr, n);
    print(arr, n, q);

    return 0;
}

Measured memory_bytes: 4412
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int g[10][10];
int cnt[10];

int main(){
  const int n = getInt();
  const int m = getInt();

  REP(i,m){
    const int a = getInt() - 1;
    const int b = getInt() - 1;
    g[a][b] = g[b][a] = 1;
    cnt[a]++; cnt[b]++;
  }

  const int lim = 10000;
  double ans = 0.0;

  vector<vector<double> > dp(1 << n, vector<double>(n));
  dp[1][0] = 1.0;

  REP(cc, lim){
    vector<vector<double> > next(1 << n, vector<double>(n));

    REP(i,1<<n) REP(j,n) if(dp[i][j] > 0.0){
      if(i == (1 << n) - 1){
        ans += dp[i][j] * cc;
      }else{
        REP(k,n) if(g[j][k]){
          next[i | (1 << k)][k] += dp[i][j] / cnt[j];
        }
      }
    }

    dp.swap(next);
  }

  printf("%.8f\n", ans);

  return 0;
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<i<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
using namespace std;

const int INF=1e9+7;
const int MOD=998244353;

typedef pair<int,int> PA;
typedef pair<int,PA> PA2;

int comb[201][201];

void comb_prepair(){
    memset(comb,0,sizeof(comb));
    FOR(i,1,201){
        FOR(j,0,i+1){
            if(j==0||j==i) comb[i][j]=1;
            else (comb[i][j]=comb[i-1][j-1]+comb[i-1][j])%=MOD;
        }
    }
}

int gcd(int a,int b){
    a=abs(a); b=abs(b);
    if(a==0||b==0) return a+b;
    else if(a>=b) return gcd(a%b,b);
    else return gcd(a,b%a);
}

int main(){
    int n; cin>>n;
    vector<PA2> v;
    vector<PA> z;
    FOR(i,0,n){
        int x,y; cin>>x>>y;
        z.PB(PA(x,y));
    }
    ll ans=0;
    if(n>=3){
        comb_prepair();
        FOR(i,0,n){
            FOR(j,i+1,n){
                int a=z[i].FI, b=z[i].SE, c=z[j].FI, d=z[j].SE;
                int s=b-d, t=a-c, u=b*c-a*d;
                if(s<0||(s==0&&t<0)){
                    s*=-1; t*=-1; u*=-1;
                }
                int g=gcd(gcd(s,t),u);
                s/=g; t/=g; u/=g;
                v.PB(PA2(s,PA(t,u)));
            }
        }
        //co("test");
        v.PB(PA2(INF,PA(INF,INF)));//番兵
        sort(v.begin(),v.end());
        FOR(i,3,n+1){
            ans+=comb[n][i];
            ans%=MOD;
        }
        PA2 p=v[0];
        int k=1;
        int b[20000]={};
        FOR(i,1,201){
            b[i*(i-1)/2]=i;
        }
        /*
        FOR(i,0,v.size()){
            printf("%d %d %d\n",v[i].FI,v[i].SE.FI,v[i].SE.SE);
        }
        */
        FOR(i,1,v.size()){
            PA2 q=v[i];
            if(p!=q){
                k=b[k];
                //co(k);
                FOR(j,3,k+1){
                    ans+=(MOD-comb[k][j]);
                    ans%=MOD;
                }
                k=1;
                p=q;
            }else{
                k++;
            }
        }
    }
    co(ans);
}


Measured memory_bytes: 960
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;

int main(){
    long long n, m, tmp;
    cin >> n >> m;
    // vector<int> hoge(n);
    priority_queue<long long> que;
    for (int i = 0; i < n; i++){
        cin >> tmp;
        que.push(tmp);
    }
    // sort(hoge.begin(), hoge.end());
    // for (int i = 0; i < n; i++){
    //     cout << hoge[i] << endl;
    // }
    // while (!que.empty()){
    //     cout << que.top() << endl;
    //     que.pop();
    // }
    

    for (int i = 0; i < m; i++){
        // sort(hoge.begin(), hoge.end());
        // vector<int>::iterator iter = max_element(hoge.begin(), hoge.end());
        
        // while (!que.empty()) {
        // }

        // *iter = *iter / 2;
        long long a = que.top();
        que.pop();
        que.push(a/2);

        // hoge[n - 1] = hoge[n - 1] / 2;
    }

    // cout << "done" << endl;
    // while (!que.empty()){
    //     cout << que.top() << endl;
    //     que.pop();
    // }
    // cout << "@" << endl;
    // for (int i = 0; i < n; i++){
    //     cout << hoge[i] << endl;
    // }

    // // long long sum = accumulate(que.begin(), que.end(), 0LL);
    long long sum = 0;
    while (!que.empty()) {
      sum += que.top();
      que.pop();
    }
    // // cout << sum << endl;
    // // long long sum = 0;
    // // for (int i = 0; i < n; i++){
    // //     // cout << hoge[i] << endl;
    // //     sum += hoge[i];
    // // }
    
    cout << sum << endl;
    

    // cout << 19/10 << endl;
}

Measured memory_bytes: 1400
price, num, c = 0, 0, 0

while True:
    try:
        p, n = map(float, input().split(','))
        price += p * n
        num += n
        c += 1
    except:
        print(int(price))
        num /= c
        s = str(num).split('.')
        if int(s[1][0]) > 4:
            print(int(num) + 1)
        else:
            print(int(num))
        break

Measured memory_bytes: 6748
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
A = inpl()
A.sort()
BC = []
for _ in range(M):
    BC.append(inpl())
BC.sort(key=lambda x: -x[1])
 
D = []
for B, C in BC:
    if len(D) >= N:
        break
    d = [int(C)]*B
    D += d
D.sort(reverse=True)

lenD = len(D)
if lenD > N:
    lenD = N

for i in range(lenD):
    if D[i] > A[i]:
        A[i] = D[i]
    else:
        break
ans = sum(A)
print(ans)

Measured memory_bytes: 87960
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  int N, Y;
  scanf("%d %d", &N, &Y);
  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= N - x; y++) {
      int z = N - x - y;
      if (10000 * x + 5000 * y + 1000 * z == Y) {
        printf("%d %d %d\n", x, y, z);
        return 0;
      }
    }
  }
  printf("%d %d %d\n", -1, -1, -1);
  return 0;
}


Measured memory_bytes: 128