akhauriyash/Code-Regression huggingface dataset:
use std::io::{self, Read};

macro_rules! input {
    ($it: expr) => ($it.next().unwrap().parse().unwrap());
    ($it: expr, $T: ty) => ($it.next().unwrap().parse::<$T>().unwrap());
}

fn main() {
    let mut buf = String::new();
    io::stdin().read_to_string(&mut buf).unwrap();

    let mut it = buf.split_whitespace();

    let n: u64 = input!(it);

    let mut prime: Vec<bool> = vec![true; 1000000];
    prime[0] = false;
    prime[1] = false;
    for i in 2..prime.len() {
        if prime[i] {
            let mut j = i + i;
            while j < prime.len() {
                prime[j] = false;
                j += i;
            }
        }
    }

    let mut factors: Vec<u64> = Vec::new();
    let mut rem = n;
    for i in 0..prime.len() {
        if prime[i] {
            let mut count = 0;
            while rem % i as u64 == 0 {
                rem /= i as u64;
                count += 1;
            }
            if count > 0 {
                factors.push(count);
            }
        }
    }
    if rem != 1 {
        factors.push(1);
    }

    let mut ans = 0;
    for mut count in factors {
        let mut i = 0;
        while i + 1 <= count {
            count -= i + 1;
            i += 1;
        }
        ans += i;
    }

    println!("{}", ans);
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int n,a[1001],ans,cnt;
int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; ++i)
		scanf("%d",&a[i]);
	for (int i=1; i<=n; ++i)
	{
		cnt++;
		if (a[i]!=a[i+1])
		{
			ans+=cnt/2;
			cnt=0;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
n=int(input())
d,x=map(int,input().split())

a=[int(input()) for _ in range(n)]
sum_count=0
for i in range(n):
    A=0
    count=0
    
    while(A*a[i]+1<=d):
        count+=1
        A+=1
    sum_count+=count
print(sum_count+x)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll H, W;
  cin >> H >> W;
//  vector<vector<char>> xs(H, vector<char>(W));
  vector<vector<bool>> xs(H, vector<bool>(W));
  for (auto i = 0; i < H; i++) {
    for (auto j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '#') xs[i][j] = true;
      else xs[i][j] = false;
    }
  }
  bool res = true;
  for (auto i = 0; i < H; i++) {
    for (auto j = 0; j < W; j++) if (xs[i][j]) {
      bool valid = false;
      valid |= i > 0 && xs[i-1][j]; // up
      valid |= i + 1 < H && xs[i+1][j]; // down
      valid |= j > 0 && xs[i][j-1]; // left
      valid |= j + 1 < W && xs[i][j+1]; // right
      if (!valid) {
        res = false;
      }
    }
  }


  cout << (res ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <array>
using namespace std;
typedef long long ll;

int main(int argc,char const* argv[])
{
  int n;
  cin >> n;
  vector<int> a(n,0);
  ll now,ans1=0,ans2=0;
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
    }
  now=0;
  for(int i=0;i<n;i++)
    {
      now+=a[i];
      if(i%2==0)
	{
	  if(now<=0)
	    {
	      ans1+=(1-now);
	      now=1;
	    }
	}
      else
	{
	  if(now>=0)
	    {
	      ans1+=abs(now-(-1));
	      now=-1;
	    }
	}
      //cout << ans1 << ' ' << now << endl;
    }
  now=0;
  for(int i=0;i<n;i++)
    {
      now+=a[i];
      if(i%2!=0)
	{
	  if(now<=0)
	    {
	      ans2+=(1-now);
	      now=1;
	    }
	}
      else
	{
	  if(now>=0)
	    {
	      ans2+=abs(now-(-1));
	      now=-1;
	    }
	}
      //cout << ans2 << ' ' << now << endl;
    }
  
  cout << min(ans1,ans2) << endl;
  return 0;
}


Measured memory_bytes: 640
N = int(input())
B = input().split()
Ap = [0 for i in range(N)]
for i in range(N-1):
    B[i] = int(B[i])
for i in range(N):
    if i != 0 and i != N-1:
        Ap[i] = min({B[i-1],B[i]})
    elif i == 0:
        Ap[i] = B[i]
    elif i == N-1:
        Ap[i] = B[N-2]

S = sum(Ap)
print(S)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 100100
#define ll long long
int a[MAX],n;
ll ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i)
    {
        ans+=a[i]/2,a[i]%=2;
        if(a[i]&&a[i+1])++ans,--a[i+1];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 768
n = int(input())
a = list(map(int, input().split()))

d = {}
d[0] = 1000

for i in range(n):
    e = d.copy()
    for stock, money in e.items():
        # sell
        d[0] = max(d[0], money + stock * a[i])
        # buy
        k = money // a[i]
        stock += k
        money -= k * a[i]
        d[stock] = max(d.get(stock, 0), money)

print(d[0])

Measured memory_bytes: 9176
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
--import Debug.Trace

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve [a, b] = foldl' ff 0 $ map (2 ^) [0..40]
    where
        ff acc i
            | odd c1 = acc + i
            | otherwise = acc
            where
                c1 = bc1 - ac1
                ac1 = count i . max 0 $ a - 1
                bc1 = count i b
                
count :: Int -> Int -> Int
count i x
    | odd r = i * (r `div` 2) + m
    | otherwise = i * (r `div` 2)
    where
        (r, m) = (x + 1) `divMod` i
                

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
#include <iostream>
using namespace std;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int ans=0;
    for(int i=0;i<=n;i++){
      string s=to_string(i);
      int sum=0;
      for(int j=0;j<s.length();j++){
          sum+=s[j]-48;
      }
      if(sum>=a&sum<=b){
          ans+=i;
      }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// coded by- mrNOBODY_

#include <bits/stdc++.h>
#define ll long long 
#define ull unsigned long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cin.sync();

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

    int m;
    cin>>m;
    int b;
    int a;
    while(m--)
    {
        cin>>a>>b;
        int sum=0;
        int temp =arr[a-1];
        arr[a-1] = b;
        for(int j=0; j<n; j++)
        {
            sum+= arr[j];
        }
        arr[a-1]= temp;
        cout<<sum<<endl;
    
    }
    return 0;
}

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

int main(void){
    int n, d, ans = 0;
    std::cin >> n >> d;
    int x[n][d];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            std::cin >> x[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int dist = 0;
            for(int k = 0; k < d; k++){
                dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            int rdist = std::sqrt(dist);
            if(rdist * rdist == dist) ans++;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll sz5 = 100000;
ll w1,n;
ll w[100000], v[100000];

ll dp[200][100000];

ll func(ll ind,ll weight){
	
	if(weight>w1) return -1e18;
	if(ind == n) return 0;

	if(dp[ind][weight]!=-1) return dp[ind][weight];

	ll ans = -1e9;

	ans = max(ans,v[ind] + func(ind+1,weight+w[ind]));
	ans = max(ans, func(ind+1, weight));

	dp[ind][weight] = ans;
	return ans;

}

int main(){


#ifndef ONLINE_JUDGE   
freopen("input.txt", "r", stdin); 
// freopen("output.txt", "w", stdout);    
#endif 
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
memset(dp,-1,sizeof(dp));

cin>>n>>w1;

for(int i=0;i<n;i++)
cin>>w[i]>>v[i];
	
cout<<func(0,0);

}





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

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

map<ll, ll> mp;

void prime_fact(int n)
{
    for (int i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            n /= i;
            mp[i]++;
        }
    }
    if (n != 1)
        mp[n]++;
}

int main()
{
    ll mod = 1e9 + 7;
    ll n;
    cin >> n;
    for (ll i = 1; i <= n; i++)
        prime_fact(i);

    ll ans = 1;
    for (auto x : mp)
        (ans *= x.second + 1) %= mod;

    OP(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  for(int i = 0; i<N; i++){
    string S;
    cin >> S;
    
    if(S == "Y"){
      cout << "Four" << endl;
      break;
    }
    else if(i == N-1){
      cout << "Three" << endl;
    }
  }
  
}

Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int main()
{
	int D; cin>>D;
	
	if(D==25) cout<<"Christmas\n";
	
	else if(D==24) cout<<"Christmas Eve\n";
	
	else if(D==23) cout<<"Christmas Eve Eve\n";
	
	else if(D==22) cout<<"Christmas Eve Eve Eve\n";
	
	return 0;	
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int dp[303][303][303] = {0};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;
  string t = s;
  reverse(t.begin(), t.end());

  int n = s.size();

  for (int i = 0; i < n; i++) dp[i][i + 1][0] = 1;

  for (int d = 2; d <= n; d++) {
    for (int i = 0; i < n; i++) {
      int j = d + i;
      if (j > n) continue;
      for (int l = 0; l <= k; l++) {
        dp[i][j][l] = max(dp[i + 1][j][l], dp[i][j - 1][l]);
        if (s[i] == s[j - 1]) {
          dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l] + 2);
        } else {
          if (l > 0)
            dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l - 1] + 2);
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i <= k; i++) ans = max(ans, dp[0][n][i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 108800
#include<stdio.h>
#define MAX 100
#define S 1

int main(){
  int i, n, array[MAX];

  scanf("%d", &n);

  array[0] = S;
  array[1] = S;
  
  for ( i = 2; i <= n; i++ ) {
  	array[i] = array[i-1] + array[i-2];
  }
  printf("%d\n", array[n]);

  return 0;
}


Measured memory_bytes: 2112
#define _CRT_SECURE_NO_WARNINGS
#include <bitset>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>


int main() {
	using uint32 = std::uint_fast32_t;
	using int32 = std::int_fast32_t;
	constexpr uint32 SIZ = 17000;
	std::string s;
	int32 x, y;
	std::cin >> s >> x >> y;
	const uint32 len = s.length();
	std::vector<uint32> a, b;
	uint32 it = 0;
	while (it < len)
		if (s[it] == 'F')
			--x, ++it;
		else
			break;
	for (bool f = 1;it < len;++it)
		if (s[it] == 'T')
			(f ^= 1) ? a.push_back(0) : b.push_back(0);
		else
			f ? ++a.back() : ++b.back();
	std::bitset<SIZ> dpx, dpy;
	x += std::accumulate(a.begin(), a.end(), 0);
	y += std::accumulate(b.begin(), b.end(), 0);
	if (x < 0 || y < 0) {
		puts("No");
		return 0;
	}
	dpx.set(0);
	for (const auto d : a)
		dpx |= dpx << (d << 1);
	dpy.set(0);
	for (const auto d : b)
		dpy |= dpy << (d << 1);
	puts(dpx[x] && dpy[y] ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bits/stdc++.h>
#include<stdio.h>

int main(){
   int N;
   cin >> N;
   string S;
   cin >> S;
   int res=0;
   long long int L=S.length();
   for(int i=0;i<L;++i){
       if(S[i]+N<='Z'){
           S[i]+=N;
       }
       else{
           S[i]='A'+S[i]-'Z'+N-1;
       }
       }
   cout << S;
}

Measured memory_bytes: 256
#####segfunc#####
def segfunc(x, y):
    return min(x, y)
#################

#####ide_ele#####
ide_ele = float('inf')
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

n,k = map(int,input().split())
a = [int(input()) for i in range(n)]
m = max(a)

ind = [[] for i in range(m+1)]
for i,x in enumerate(a):
    ind[x].append(i)
seg_lis = []
for x in ind:
    if x == []:
        seg_lis.append(10**10)
    else:
        try:
            _ = len(x)
            seg_lis.append(x[0])
        except:
            seg_lis.append(x)


numbers = [0]*(m+1)

d = [0]*n

seg = SegTree(seg_lis, segfunc, ide_ele)
for i,x in enumerate(a):
    
    try:
        p = len(ind[x])
        numbers[x] += 1
        seg.update(x, ind[x][numbers[x]])
    except:
        seg.update(x, 10**10)
    
    low = x-k
    high = x+k
    if low < 0:
        low = 0
    if high > m:
        high = m
    q1 = seg.query(x, high+1)
    q2 = seg.query(low, x+1)
    
    if q1 < 10**7:
        d[q1] = max(d[q1], d[i] + 1)
    if q2 < 10**7:
        d[q2] = max(d[q2], d[i] + 1)

print(max(d)+1)

Measured memory_bytes: 197388
import sys

sys.setrecursionlimit(10 ** 5 + 5)

MOD = 10 ** 9 + 7


def dfs(current_node, parent_node, num_colors, graph):
    score = 1
    unavailable_colors = 0 if parent_node == -1 else 1
    for child_node in graph[current_node]:
        if child_node == parent_node:
            continue

        unavailable_colors += 1
        score = score * (num_colors - unavailable_colors) % MOD
        score = score * dfs(child_node, current_node, num_colors, graph) % MOD

    return score % MOD


N, K = list(map(int, input().split()))
G = [set() for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)

print(dfs(0, -1, K, G) * K % MOD)

Measured memory_bytes: 100880
#include <cstdio>
#include <map>
using namespace std;
int main () {
  int N, M;
  scanf("%d %d", &N, &M)+1;
  
  map<int, int> mi;
  
  for (int i = 0; i < N; i++) {
    int K, tmp1;
    scanf("%d", &K)+1;
    for (int ii = 0; ii < K; ii++) {
      scanf("%d", &tmp1)+1;
      mi[tmp1]++;
    }
  }

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    if (mi[i] == N) {
      ans++;
    }
  }
  
  printf("%d", ans);
  
  return 0;
}

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  double L;
  int m = 0;
  cin >> L;
  cout << setprecision(10) << pow(L/3, 3) << endl;
}


Measured memory_bytes: 512
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int M = Integer.parseInt(S[1]);
    
    boolean[] check = new boolean[N];
    int[] sum_wa = new int[N];
    int ac = 0, wa = 0;
    for(int i = 0; i < M; i++){
      String[] T = sc.nextLine().split(" ");
      int A = Integer.parseInt(T[0])-1;
      if(!check[A]){
        if(T[1].equals("WA")){
          sum_wa[A]++;
        }else{
          check[A]= true;
        }
      }
    }
    for(int i = 0; i < N; i++){
      if(check[i]){
        ac++;
        wa += sum_wa[i];
      }
    }
    System.out.println(ac+" "+wa);
  }
}

Measured memory_bytes: 93568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    string S, T;
    cin >> S >> T;
    cout << (int(S[0] == T[0]) + int(S[1] == T[1]) + int(S[2] == T[2])) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;
import java.util.ArrayList;
import java.util.List;
//List<Integer> list = new ArrayList<>();

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.next();
		char[] a = new char[10];
		for (int j = 0; j < 10; j++) {
			a[j] = s.charAt(j);
		}
		int c = Character.getNumericValue(a[6]);
		String t = "TBD";
		if (a[5] == '0') {
			if (c < 5)
				t = "Heisei";
		}
		System.out.println(t);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
        long long n; cin >> n;
        
        int max = 1;
        for (long long i = 2; i * i <= n; ++i)
            if (n % i == 0) max = i;
        
        int m = n / max;
        
        int digit = 0;
        while (m)
        {
            ++digit;
            m /= 10;
        }
        
        cout << digit << endl;
    }

Measured memory_bytes: 256
#include <stdio.h>

    int lday[26] = {-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1, -1,-1, -1}, dp[365], day[26][365] = {}, dayc[26] = {};   //  day     コンテストが実施された日    dayc    dayのインデックス
    int c[26], s[365][26];

int calc(int con, int dd)
{
    int i, ans;
    ans = s[dd][con];
    
    for (i = 0; i < con; i++)
        ans -= c[i] * (dd - lday[i]);
    for (i = con + 1; i < 26; i++)
        ans -= c[i] * (dd - lday[i]);
    return (ans);
}

int main(void){
    int d, D, ans[366], score = 0, tmpscore;
    int i, ii, iii, iv, tmp, tmp2;
    scanf("%d", &D);
    for (i = 0; i < 26; i++)
        scanf("%d", c + i);
    for (ii = 0; ii < D; ii++)
        for (i = 0; i < 26; i++)
            scanf("%d", &s[ii][i]);
            
            
    tmpscore = 0;
    for (d = 0;  d < D; d++)
    {
        tmp = -1000000;
        for (i = 0; i < 26; i++)
        {
            tmp2 = calc(i, d);
            if (tmp2 > tmp)
            {
                tmp = tmp2;
                ans[d] = i;
            }
        }
        tmpscore += tmp;
        day[ans[d]][dayc[ans[d]]++] = d;
        lday[ans[d]] = d;
    }
    
    for (i = 0; i < D; i++)
        printf("%d\n", ans[i] + 1);
}

Measured memory_bytes: 1808
#!python3

from time import perf_counter
limit = 1.92
tick = perf_counter()

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect


def resolve():
    G = 26
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(G)]
    S = [[next(it) for i in range(G)] for i in range(D)]
    L = [[-1] for i in range(G)]
    T = [0] * D

    def update(di, qi):

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]

        a1 = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        a2 = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, (a1, a2)

    U = 7
    def calc(i, j):
        score = S[i][j]
        for k in range(G):
            u = k - L[k][-1]
            score -= C[k] * (u + u + U) * U // 2
        score += C[k] * U * (i-L[j][-1])
        return score

    for di in range(D):
        i, score = 0, calc(di, 0)
        for qi in range(1, G):
            x = calc(di, qi)
            if x > score:
                i, score = qi, x
        T[di] = i
        L[i].append(di)

    def dswap(di, dj):
        qi, qj = T[di], T[dj]
        swap0 = (L[qi], L[qj])

        score, swap1 = update(di, qj)
        T[di] = qj
        L[qi], L[qj] = swap1
        diff, swap2 = update(dj, qi)

        score += diff

        if score > 0:
            T[dj] = qi
            L[qj], L[qi] = swap2
        else:
            score = 0
            T[di], T[dj] = qi, qj
            L[qi], L[qj] = swap0
        return score

    t = 0
    while t < limit:
        if False:
            di, qi = randrange(0, D), randrange(0, G)
            diff, swap = update(di, qi)
            if diff > 0:
                score += diff
                q0, T[di] = T[di], qi
                L[q0], L[qi] = swap
                raise 1
            t = perf_counter() - t
        else:
            di = randrange(0, D-1)
            dj = randrange(di+1, D)
            diff = dswap(di, dj)
            if diff > 0:
                score += diff
        t = perf_counter() - tick

    print(*(i+1 for i in T), sep="\n")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 102160
def main():
    # map(int, input().split())
    # l = list(map(int, input().split()))
    N = int(input())
    S = input()
    flag = False
    for i in range(N):
        s1 = S[:i]
        s2 = S[i:]
        if s1 == s2:
            flag = True
    print('Yes' if flag else 'No')


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
	int a, b, c, d, e, f;
	int min, sum;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
	
	sum = a + b + c + d;
	
	min = a;
	if (b < min){
		min = b;
	}
	if (c < min){
		min = c;
	}
	if (d < min){
		min = d;
	}
	
	sum -= min;
	if (e > f){
		sum += e;
	}
	else {
		sum += f;
	}
	
	printf("%d\n", sum);
	
	return (0);
}



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


#define ll long long
#define MOD 1000000007
#define PI 3.1415


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

    ll v =100;
    ll co=0;
    while(x>v){
        v = v+(v/100);
        co++;
    }
    cout<<co<<endl;

}



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1), b, temp_res(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; i--) {
        int contained = 0, k = 1;
        while (k * i <= n) {
            contained += temp_res[k*i];
            k++;
        }
        if (contained % 2 != a[i]) {
            b.push_back(i);
            temp_res[i] = 1;
        }
    }
    cout << b.size() << endl;
    for (auto x : b) {
        cout << x << " ";
    }
    cout << endl;
}

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

int T[10][10];

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

  int h,w;
  cin >> h >> w;

  rep(i, 10) {
    rep(j, 10) {
      cin >> T[i][j];
    }
  }

  rep(k, 10) {
    rep(i, 10) {
      rep(j, 10) {
        T[i][j] = min(T[i][j], T[i][k] + T[k][j]);
      }
    }
  }

  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      int tmp; cin >> tmp;
      if(tmp == -1 || tmp == 1) continue;
      ans += T[tmp][1];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
{
  type Print = void | string | number | string[] | number[];
  const outs: Print[] = [];
  const _io = (i = 0) => {
    // eslint-disable-next-line @typescript-eslint/no-var-requires
    const str = require("fs").readFileSync("/dev/stdin", "utf8");
    const lines = str.trim().split("\n");
    const s = () => lines[i++] || "";
    const n = () => Number(s());

    const mn = (v: string[]) => v.map(Number);
    const sp = (v: string) => v.split(" ");

    const ss = () => sp(s());
    const nn = () => mn(ss());
    const nls = () => mn(lines.slice(i));
    const nnls = () => lines.slice(i).map((v: string) => mn(sp(v)));

    return { lines, s, n, ss, nn, nls, nnls };
  };
  const main = (): Print => {
    const r = _io();
    const length = r.lines[0];
    const text = r.lines[1];
    // 以下入れ替え
    return checkOnAirConditioner(length, text);
  };

  /**
   * check double of  a string
   *
   * @param length - the string length
   * @param text - the string
   * @returns "Yes" or "No"
   *
   */
  const checkOnAirConditioner = (length: number, text: string): string => {
    // 奇数なら繰り返しできない
    if (length % 2 !== 0) {
      return "No";
    } else {
      const [frontText, backText] = [
        text.substr(0, length / 2),
        text.substr(length / 2, length / 2),
      ];
      if (frontText === backText) {
        return "Yes";
      }
      return "No";
    }
  };

  outs.push(main());

  console.log(
    outs
      .map((line) => (typeof line === "object" ? line.join(" ") : String(line)))
      .join("\n")
  );
}


Measured memory_bytes: 29484
#include <iostream>
#include<bits/stdc++.h>
#include <vector>

using namespace std;

int main()
{
   long long int n,a,b;
   cin >> n>>a>>b;
   long long int s,m,d;
   
     m = n/(a+b);
   
     d = n%(a+b);
   
   if(d>a){
   	s = m*a + a;
   }
   else{
   	s = m*a + d;
   }
   cout << s;
}





Measured memory_bytes: 256
import java.util.Scanner;

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

        int x = stdIn.nextInt();
        int y = stdIn.nextInt();
        int z = stdIn.nextInt();

        System.out.println(z + " " + x + " " + y);
    }
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define RLOOP(i, N) for (int i =(int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
//cout<<"Yes"<<endl;
//cout<<"No"<<endl;
int main(){
  int h1,m1,h2,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  if(h2<h1){
    h2+=24;
  }else if(h2==h1){
    if(m2<m1){
      h2+=24;
    }
  }
  int tmp1=h1*60+m1;
  int tmp2=h2*60+m2;
  tmp2-=k;
  cout<<tmp2-tmp1<<endl;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precise cout.precision(8); cout << fixed;
#define seed srand(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
using namespace std;

int main() {


    zoom;    
    int L, R, d; cin >> L >> R >> d;
    int ans = (R / d) - ((L - 1) / d);
    cout << ans;
    return 0;
}

Measured memory_bytes: 3668
/********************************************
 *Author*        :👻ZZZZone
 *Created Time*  : 六 10/14 20:19:11 2017
 * Ended  Time*  : 六 10/14 20:32:18 2017
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

int n, k;
LL ans;

struct point{
	int x, y;
}a[55];

int xx[55];

bool cmp(point a, point b){
	return a.y < b.y;
}

void solve(int l, int r){
	vector<point> tmp;
	for(int i = 1; i <= n; i++)
		if(a[i].x >= l && a[i].x <= r) tmp.push_back(a[i]);
	sort(tmp.begin(), tmp.end(), cmp);
	if(tmp.size() < k) return;
	for(int i = 0; i <= tmp.size() - k; i++){
		LL are = (LL)(r - l) * (LL)(tmp[i+k-1].y - tmp[i].y);
		ans = min(ans, are);
	}
}


int main()
{
	while(~scanf("%d %d", &n, &k)){
		ans = (1LL << 62);
		for(int i = 1; i <= n; i++){
			scanf("%d %d", &a[i].x, &a[i].y);
			xx[i] = a[i].x;
		}
		sort(xx + 1, xx + 1 + n);
		for(int i = 1; i <= n; i++)
			for(int j = i; j <= n; j++)
				solve(xx[i], xx[j]);
		printf("%lld\n", ans);
	}
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll A[200010];
int main()
{
	int N; cin >> N;
	ll sum1 = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum1 += A[i];
	}
	ll diff = INF, sum2 = 0, ans = INF;
	for (int i = 0; i < N; i++) {
		sum1 -= A[i];
		sum2 += A[i];
		diff = abs(sum1 - sum2);
		ans = min(ans, diff);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
H,W = map(int,input().split())

A=[]
for i in range(H):
    A.append(list(map(int,input().split())))

ans=[]

for i in range(H):
    for j in range(W):
        if i%2==0:
            n=j
        else:
            n=W-1-j
        if A[i][n]%2==1:
            A[i][n]-=1
            if i<H-1 and ((i%2==0 and n==W-1) or (i%2==1 and n==0)):
                A[i+1][n]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+2,n+1))
            if (i%2==0 and n!=W-1) or (i%2==1 and n!=0):
                A[i][n+(-1)**(i%2)]+=1
                ans.append('{} {} {} {}'.format(i+1,n+1,i+1,n+1+(-1)**(i%2)))

print(len(ans))
for s in ans:
    print(s)


Measured memory_bytes: 69340
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,C,a;
    int cs = 0;
    cin >> N >> C;
    for(int i=0;i<C;i++){
        cin >> a;
        cs =cs+a;
    }
    if(cs%(N+1)==0){
        cout << cs/(N+1) << endl;
    }else{
        cout << cs/(N+1)+1 << endl;
    }
}


Measured memory_bytes: 3132
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int i,a,b;
	cin>>i;
	a=i/10;
	b=i-a*10;
	if(i>=10&&i<=99)
	{
		if(a==9||b==9)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

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

inline void init() {
#ifdef __LOCAL__
  freopen("in", "r", stdin);
#endif
}

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

int len(int x) {
  int ret = 0;
  while (x) {
    x /= 10;
    ret++;
  }
  return ret;
}

int main() {
  init();

  int a, b;
  cin >> a >> b;
  a *= pow(10, len(b));
  a += b;
  int root = sqrt(a);
  if (root * root == a) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  
  return 0;
}


Measured memory_bytes: 256
<?php
define('MOD', 10 ** 9 + 7);
list($n) = ints();
echo modFac($n);

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modDiv(modFac($n), modFac($n - $r));
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}


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

int n, k;
int t[100002];

int main(){

  while(cin >> n >> k, n || k){
    int sum = 0;

    for(int i = 0; i < n; i++){
      cin >> t[i];
      if(i < k) sum += t[i];
    }

    int ans = sum;

    for(int i = 0; i < n - k; i++){
      sum -= t[i];
      sum += t[i + k];
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1548
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int m = n/2;

    int v[n];
    rep(i, n) {
        cin >> v[i];
    }

    int o[m], e[m];     //v[n]の奇数番目(1-index)の項がo[m],偶数番目(1-index)の項がe[m]
    rep(i, m) {
        o[i] = v[2*i];
        e[i] = v[2*i+1];
    }
    sort(o, o+m);
    sort(e, e+m);

    int to = o[0];
    int ko = 0;
    vector<int> co(m);
    rep(i, m) {
        if(to < o[i]) {
            to = o[i];
            ko++;
            co[ko]++;
        } 
        else {
            co[ko]++;
        }
    }

    int te = e[0];
    int ke = 0;
    vector<int> ce(m);
    rep(i, m) {
        if(te < e[i]) {
            te = e[i];
            ke++;
            ce[ke]++;
        } 
        else {
            ce[ke]++;
        }
    }

    sort(co.begin(), co.end());
    reverse(co.begin(), co.end());
    sort(ce.begin(), ce.end());
    reverse(ce.begin(), ce.end());

    int modeO = o[0];  //modeOにはoの最頻値(oにco[0]個ある数)が入る
    int bo = 0;
    rep(i, m) {
        if(modeO < o[i]) {
            if(bo == co[0]) {
                break;
            }
            modeO = o[i];
            bo = 0;
        }
        bo++;
    }

    int modeE = e[0];  //modeEにはeの最頻値(eにce[0]個ある数)が入る
    int be = 0;
    rep(i, m) {
        if(modeE < e[i]) {
            if(be == ce[0]) {
                break;
            }
            modeE = e[i];
            be = 0;
        }
        be++;
    }

    int ans;
    if(modeO != modeE) {  //最頻値が異なる数の場合
        ans = n - (co[0] + ce[0]);
    }
    else {  //最頻値が同じ数の場合
        int u = co[0] + ce[1];
        int v = co[1] + ce[0];
        ans = n - max(u, v);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n = int(input())
  t,a = map(int,input().split())
  H = list(map(int,input().split()))
  mi_ = float('inf')
  for i in range(n):
    temp = t - H[i] * 0.006
    if mi_ > abs(a-temp):
      mi_ = abs(a-temp)
      idx = i+1
  print(idx)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

typedef long long ll;

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

  int n;
  cin >> n;

  vector<int> x(n);
  rep(i, n) {
    cin >> x[i];
  }

  int minX = *min_element(x.begin(), x.end());
  int maxX = *max_element(x.begin(), x.end());

  int ans = 1e9;
  for (int p = minX; p <= maxX; p++) {
    int tmp = 0;
    rep(i, n) {
      tmp += (x[i]-p)*(x[i]-p);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import copy

n = int(input())
A = []

for i in range(n):
    x, y = input().split()
    z = {'mark': x, 'num': int(y)}
    A.append(z)

B = copy.deepcopy(A)

def partition(p, r):
    i = p
    for j in range(p, r):
        if A[j]['num'] <= A[r]['num']:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[i], A[r] = A[r], A[i]
    return i

def quicksort(p, r):
    if p < r:
        q = partition(p, r)
        quicksort(p, q-1)
        quicksort(q+1, r)

quicksort(0, n-1)

def checkstable():
    for i in range(n-1):
        if A[i]['num'] == A[i+1]['num']:
            if B.index(A[i]) > B.index(A[i+1]):
                return 'Not stable'
                break
    return 'Stable'

print(checkstable())
for i in A:
    print(i['mark'], i['num'])


Measured memory_bytes: 69200
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
#define ll long long
using namespace std;
int n,m,a[100100];
ll c[2][100100],s,t,ans;
void add(int id,int le,int ri,ll val){
	for(;ri;ri-=lowbit(ri)) c[id][ri]+=val;
	le--;if(le==0) return;
	for(;le;le-=lowbit(le)) c[id][le]-=val;
}
ll get(int id,int x){
	ll tot=0;
	for(;x<=m;x+=lowbit(x)) tot+=c[id][x];
	return tot;
}
ll gans(int x){
	ll ans=0;
	ans+=get(0,x);
	ans+=(ll)(x)*get(1,x);
	return ans;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<n;i++){
		s=a[i];t=a[i+1];
		if(s<t){
			add(0,1,s,t-s);
			add(0,s+1,t,t+1);
			add(1,s+1,t,-1);
			add(0,t+1,m,t-s);
		}
		else{
			add(0,1,t,t+1);
			add(1,1,t,-1);
			add(0,t+1,s,t+m-s);
			add(0,s+1,m,t+m+1);
			add(1,s+1,m,-1);
		}
	}
	ans=1e18;
	for(int i=1;i<=m;i++) ans=min(ans,gans(i));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5516
#include <iostream>
#include <cstring>
using namespace std;
int n,a,b,x,y,ans;
int main()
{
	cin>>n>>x>>y;
	for (int i=1;i<=n;++i)
	{
		cin>>a>>b;
		if (a>=x&&b>=y) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

int main(){
  string S;
  cin >> S;
  int Ans = 0;
  for(int i = 0; i < 4; i++){
    if(S[i] == '+') ++Ans;
    else --Ans;
  }

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


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct KMP{
    vi a;
    KMP() = default;
    KMP(const string& s) : a(s.size() + 1, -1) {
        int j = -1;
        REP(i, s.size()) {
            while(j >= 0 && s[i] != s[j]) j = a[j];
            a[i + 1] = ++j;
        }
    }

    inline int operator[](int i) { return a[i]; }
};

vll memo;
vi E;

ll dfs (int p) {
    if (memo[p] > -1) return memo[p];

    if (E[p] == -1) {
        return memo[p] = 0;
    } else {
        memo[p] = inf; // to detect loop
        return memo[p] = dfs(E[p]) + 1;
    }
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string s, t;
    cin >> s >> t;

    string ss = s;
    while(ss.size() < s.size() + t.size()) {
        ss += s;
    }

    KMP kmp(t);

    E.resize(s.size(), -1);

    int i = 0, j = 0;
    while(i < s.size()) {
        while(j < t.size() && ss[i + j] == t[j]) ++j;

        if (j == t.size()) E[i] = (i + t.size()) % s.size();

        i += j - kmp[j];
        if (j > 0) j = kmp[j];
    }

    ll ans = 0;
    memo.resize(s.size(), -1);
    REP(i, s.size()) {
        if (memo[i] > -1) continue;
        ans = max(ans, dfs(i));
    }

    if (ans >= inf) {
        print(-1);
    } else {
        print(ans);
    }

}


Measured memory_bytes: 21528
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int l, n, x[200010], a[200010];
int cum[200010], rcum[200010];
int ans;

signed main() {
	cin >> l >> n;
	for (int i = 1; i <= n; i++)cin >> x[i], a[i] = x[i] - x[i - 1];
	a[n + 1] = l - x[n];
	for (int i = 1; i <= n + 1; i++)cum[i] = cum[i - 1] + a[i];
	for (int i = n + 1; i >= 1; i--)rcum[i] = rcum[i + 1] + a[i];
	int cnt = 0;
	ans = rcum[2];
	for (int i = 2; i <= (n + 1) / 2; i++) {
		cnt += a[i - 1] + cum[i - 2] * 2;
		cnt -= 2 * (cum[2 * (i - 1) - 1] - cum[i - 1]);;
		cnt += 2 * rcum[2 * i - 1];
		ans = max(ans, cnt);
		ans = max(ans, cnt + cum[i - 1] - rcum[i + 1] + 2*rcum[i * 2]);
	}
	cnt = 0;
	ans = max(ans, cum[n]);
	for (int i = n; i >= (n + 3) / 2; i--) {
		cnt += a[i + 1] + rcum[i + 2] * 2;
		int p = n + 2 - i;
		cnt -= 2 * (rcum[n + 2 - (2 * (p - 1) - 1)] - rcum[i + 1]);
		cnt += 2 * cum[n + 2 - 2 * p + 1];
		ans = max(ans, cnt);
		ans = max(ans, cnt + rcum[i + 1] - cum[i - 1] +2* cum[n + 2 - 2 * p]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;

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

const int unk = 1010101010;

bool check(vector<int> v, int cand){
	replace(ALL(v), unk, cand);
	int n = v.size() - 2;
	for(int i = 1; i <= n; ++i){
		if(i % 2){
			if(v[i] >= v[i - 1] || v[i] >= v[i + 1]){
				return false;
			}
		}
		else{
			if(v[i] <= v[i - 1] || v[i] <= v[i + 1]){
				return false;
			}
		}
	}
	return true;
}

int main(){
	int n;
	string str;
	while(cin >> n, n){
		vector<int> v(n + 2, unk);
		v[0] = INT_MAX;
		v.back() = (n % 2 ? INT_MAX : INT_MIN);

		vector<int> cand;
		for(int i = 1; i <= n; ++i){
			cin >> str;
			if(str[0] != 'x'){
				v[i] = strtol(str.c_str(), 0, 10);
				for(int j = 1; j <= 2; ++j){
					cand.push_back(v[i] + j);
					cand.push_back(v[i] - j);
				}
			}
		}
		sort(ALL(cand));
		cand.erase(unique(ALL(cand)), cand.end());

		vector<int> ans;
		for(int i = 0; i < cand.size(); ++i){
			if(check(v, cand[i])){
				ans.push_back(cand[i]);
				if(ans.size() > 1){ break; }
			}
		}
		
		if(ans.empty()){
			puts("none");
		}
		else if(ans.size() == 1){
			printf("%d\n", ans[0]);
		}
		else{
			puts("ambiguous");
		}
	}
}

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

int main() {
  ll a, b, x; cin >> a >> b >> x;
  ll ans;
  ans = b/x - a/x + (a%x == 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M; cin >> N >> M;
    bitset<100000> B;
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--, b--;
        B.flip(a);
        B.flip(b);
    }
    cout << (B.none() ? "YES" : "NO") << endl;
    return 0;
}


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

int main() {
	string s, p; 
	cin>>p;
	int pLen = p.length();
	int count = 0;
	
	while(cin>>s)
	{
	   if(s == "END_OF_TEXT") break;
	   if(s.length()<p.length()) continue;
	   for(int i=0; i<s.length(); i++)
	   {
			if((int)s[i]>64 && (int)s[i]<92)
			{
				s[i] = s[i]-'A' + 'a';
			}
	   }

	   if(s==p)
	   {
	   		count++;
	   }
	}

	cout<<count<<"\n";
	
	return 0;
}


Measured memory_bytes: 3120
package main

import "fmt"

func main() {
	// Code for A - Fighting over Candies
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	if a+b == c || b+c == a || c+a == b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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


int main()
 {
ll n,k,i,sum=0;
cin>>n>>k;
ll a[n];
for(i=0;i<n;i++)
cin>>a[i];
 
 sort(a,a+n);
 for(i=0;i<k;i++)
 {
     sum=sum+a[i];
 }
 cout<<sum<<endl;
   return 0;
 }

Measured memory_bytes: 3644
import Data.List
import Debug.Trace

main = do
  [n,z,w] <- map read . words <$> getLine :: IO [Int]
  as <- map read . words <$> getLine :: IO [Int]
  print $ solve z w as

solve :: Int -> Int -> [Int] -> Int
solve z w (a:[]) =　abs(a-w)
solve z w as =
  result
  where
    look (a1:a2:[]) = (a1,a2)
    look (a:as) = look as
    (an_, an) = look as
    result = maximum [abs(an-w),abs(an-an_)]


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


int main() {
  int n,m;
  cin >> n >> m;
  
  vector<string> a(n),b(m);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  for(int i=0; i<m; i++){
    cin >> b[i];
  }
  
  bool c = true;
  
  for(int i=0; i<n-m+1; i++){
    for(int j=0; j<n-m+1; j++){
      
      c = true;
      
      if(a[i].substr(j,m)==b[0]){
        for(int k=0; k<m; k++){
          if(a[i+k].substr(j,m)!=b[k]) c = false;
        }
        if(c){
          cout << "Yes" << endl;
          return 0;
        }
      

      }
    }
  }
  cout << "No" << endl; 
        
}

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

int n,sum,maks;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i = 1;i <= n;i++){
		int bil;
		cin>>bil;
		sum = sum + bil;
		if(bil > maks){
			maks = bil;
		}
	}
	cout<<sum - maks / 2<<endl;
}


Measured memory_bytes: 256