akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

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

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

  int H,W; cin >> H >> W;
  vector<string> G(H);
  rep(i, H) cin >> G[i];

  vector<vector<int>> D(H, vector<int>(W, 0));
  queue<pair<int,int>> Q;

  rep(h, H) {
    rep(w, W) {
      if(G[h][w] == '#') {
        Q.push({h,w});
      }
    }
  }

  int ans = 0;

  while(!Q.empty()) {
    auto cur = Q.front(); Q.pop();
    rep(i, 4) {
      int nh = cur.first + dy[i];
      int nw = cur.second + dx[i];
      if(nh >= 0 && nh < H && nw >= 0 && nw < W && G[nh][nw] == '.') {
        if(G[nh][nw] == '#') continue;

        G[nh][nw] = '#';
        D[nh][nw] = D[cur.first][cur.second] + 1;
        chmax(ans, D[nh][nw]);
        Q.push({nh, nw});
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 13456
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Console;

namespace CPLib
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] p = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int ans = 1;
            int now = p[0];
            for (int i = 1; i < n; i++)
            {
                if (p[i] <= now)
                {
                    now = p[i];
                    ans++;
                }
            }
            WriteLine(ans);
        }
    }
}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    char x;
    cin >> x;
    char ans = x+1;
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;
 
 int main(){
     int N, D;
     cin >> N >> D;

     vector<vector<int>> X(N, vector<int>(D));
     for (int i =0;i<N;i++)
     {
         for(int j=0;j<D;j++){
             cin >> X.at(i).at(j);
         }
     }

     double r;
     int count=0;
     for(int i=0;i<N;i++){
         for(int j=i+1;j<N;j++){
             r = 0.0;
             for(int k=0;k<D;k++){
                 r += pow((X.at(i).at(k) - X.at(j).at(k)),2.0);
             }
             r = sqrt(r);
             if((r - floor(r)) == 0.0){
                 count++;
             }
         }
     }

     cout << count << endl;
     
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int cnt=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]!=s[i+1]){
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

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

		int a = scn.nextInt();
		int b = scn.nextInt();
		int ans = 0;

		if(a>= 13) {
			ans = b;
		}else if(a<= 12 && a>=6) {
			ans = b/2;
		}else {
			ans = 0;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int di[10000005];
int main()
{
    int n;
    cin>>n;
    long long sum=0;
     for(int i=1; i<=n; i++) {
        for(int j=1; j*i<=n; j++) {
            di[i*j]++;
            sum+=i*j;
        }
    }
    
    /*for(int i=1; i<=n; i++)
     sum+=1.0*i*di[i];*/
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 42660
#include<bits/stdc++.h>
using namespace std;
int n,m;
int q;
int v[100005],d[100005],c[100005];
vector<int> g[100005];
int colour[100005];
int mindis[100005];
inline void dfs(int x,int dleft,int c)
{
	if(dleft<=mindis[x])
	{
		return;
	}
	mindis[x]=dleft;
	if(colour[x]==0)
	{
		colour[x]=c;
	}
	for(int i=0;i<g[x].size();i++)
	{
		dfs(g[x][i],dleft-1,c);
	}
}
int main()
{
	cin>>n>>m;
	memset(mindis,-1,sizeof(mindis));
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cin>>q;
	for(int i=0;i<q;i++)
	{
		cin>>v[i]>>d[i]>>c[i];
	}
	for(int i=q-1;i>=0;i--)
	{
		dfs(v[i]-1,d[i],c[i]);
	}
	for(int i=0;i<n;i++)
	{
		cout<<colour[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 8440
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cctype>
#include<cmath>
#include<algorithm>
#define LL long long
#define ULL unsigned long long
#define debug(x) cerr << #x << " = " << x << endl
#define MAXN 3000010
using namespace std;
LL read(){
    LL x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return x * f;
}

ULL k;
LL n;
ULL a[200];

int main(){
    k = read();
    if(k == 0){
        puts("2");
        puts("1 1");
        return 0;
    }
    if(k == 1){
        puts("2");
        puts("2 0");
        return 0;
    }
    if(k <= 50){
        cout << k << endl;
        for(int i = (int)k; i; i--){
            printf("%d ", i);
        }
   //     puts("");
        return 0;
    }
    puts("50");
    k -= (LL)50;
    for(int i = 1; i <= 50; i++){
        a[i] = 50 - i + 1 + k / (LL)50;
    }
    
    for(int i = 1; i <= k % (LL)50; i++){
        a[i]++;
    }
    
 //   for(int i=0;i<k%50;i++)a[i]++;
    for(int i = 1; i <= 50; i++) printf("%lld ", a[i]);
 //   puts("");
    return 0;
}
/*#include <iostream>
#include <cstdio>
#define ULL unsigned long long
using namespace std;

ULL now,n,k,flag;

void deal1()
{
    printf("%lld\n",n);
    for(int i=0;i<n;i++)
        if((k-i)%50==0)flag=i;
    ULL tmp=(k-flag)/50;
    for(int i=1;i<=n;i++)
    {
        if(i<=flag)printf("%lld ",tmp+50-i+1);
        else printf("%lld ",tmp+50-i);
    }
}

void deal2()
{
    printf("%lld\n",n);
    for(int i=0;i<n;i++)
        printf("%lld ",n-i);
}

int main()
{
    scanf("%lld",&k);
    if(k==0)
    {
        puts("2");
        puts("1 1");
    }
    else if(k==1)
    {
        puts("2");
        puts("3 0");
    }
    else if(k>50)n=50,deal1();
    else n=k,deal2();
    return 0;
}






*/

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
  
int main(void){
  
  char str[1000];
  char copy[1000];
  char com[8];
  char p[1000];
  int q,a,b;
  register int i,j,s,count;
  
  scanf("%s",str);
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%s %d %d",com,&a,&b);
    if(strcmp(com,"print") == 0){
      for(j = a;j <= b;j++){
        printf("%c",str[j]);
      }
      printf("\n");
    }else if(strcmp(com,"reverse") == 0){
      strcpy(copy,str);
      for(j = a,count = b;j <= b;j++,count--){
        str[count] = copy[j];
      }
    }else if(strcmp(com,"replace") == 0){
        scanf("%s",p);
        for(j = a,s = 0;j <= b;j++,s++){
            str[j] = p[s];
        }
    }
  }
  return 0;
}

Measured memory_bytes: 588
n, l = gets.chomp.split.map(&:to_i)
as = gets.chomp.split.map(&:to_i)

f = false
for i in 1...n
  if l <= as[i] + as[i - 1]
    f = true
    break
  end
end


if f
  puts "Possible"
  for j in 1...i
    puts j
  end
  j = n - 1
  while i < j
    puts j
    j -= 1
  end
  puts i
else
  puts "Impossible"
end


Measured memory_bytes: 12812
import numpy as np
import itertools

n = int(input())
x = np.empty(n)
y = np.empty(n)
for i in range(n):
    x[i], y[i] = map(float, input().split())

grid = np.zeros((n, n))
for i in range(n):
    for j in range(n):
        grid[i][j] = ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5

sum = 0
cnt = 0

for i in itertools.permutations(np.arange(n)):
    cnt += 1
    dist = 0
    for j in range(n - 1):
        dist += grid[i[j]][i[j + 1]]
    sum += dist
print(sum / cnt)


Measured memory_bytes: 12844
#include"bits/stdc++.h"
using namespace std;

#define MAX 100002

int n;

int m;

int deg[MAX];

set<int> s[MAX];

vector<int> pat;

inline void eul(int b){
	while(s[b].size()){
		int node=*s[b].begin();
		s[b].erase(node);
		s[node].erase(b);
		eul(node);
	}
	pat.push_back(b);
}
deque<int> d[MAX];

int im[MAX];

int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		deg[a]++;
		deg[b]++;
		s[a].insert(b);
		s[b].insert(a);
	}
	for(int i=0;i<n;i++){
		if(deg[i]%2){
			puts("No");
			return 0;
		}
	}
	eul(1);
	reverse(pat.begin(),pat.end());
	if(pat.size()<4){
		puts("No");
		return 0;
	}
	int ended=INT_MAX;
	for(int i=pat.size()-1;i>=1;i--){
		int node=pat[i];
		im[i]+=im[i+1];
		if(d[node].size()){
			if(im[d[node][0]]){
				puts("Yes");
				return 0;
			}
			if(ended<=d[node].back()){
				puts("Yes");
				return 0;
			}
			im[i]++;
			ended=min(ended,d[node][0]);
		}
		d[node].push_front(i);
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 126040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
int main()
{
	int N, K;
	cin >>N >>K;
	vector<int> H(N);
	rep(i,N){
		cin >>H.at(i);
	}

	sort(H.begin(), H.end());
	long long sum = 0;
	if(K<N){
		if(K!=0){
			rep(i,K){
			H.erase(H.end()-1);
			}
		}

		for(auto x: H){
			sum += x;
		}
	}
	cout <<sum <<endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// void zz(){
// ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
// }

int32_t main(){
// zz();
int n,k;cin>>n>>k;
vi v(n),vv(n);
for(int i=0;i<n;i++){
   cin>>v[i]>>vv[i];
}
vector<vi>dp(n+1,vi(k+1,0));
for(int i=0;i<=n;i++){
   for(int j=0;j<=k;j++){
    if(i==0 || j==0 )
       dp[i][j]=0;
    else if(v[i-1]<=j)dp[i][j]=max(dp[i-1][j],vv[i-1]+dp[i-1][j-v[i-1]]);
    else dp[i][j]=dp[i-1][j];
   }
}
cout<<dp[n][k]<<endl;

}

Measured memory_bytes: 80256
N = int(input())
A = [int(i) for i in input().split()]
B=[]
C=0
for i in range (N):
    j=0
    while A[i]%2 != 1:
        A[i]=A[i]/2
        j=j+1
    B.append(j)
C=sum(B)
print(C)

Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
set<int>s;
for(int i=0;i<n;i++){
cin>>a[i];
s.insert(a[i]);
}
if(s.size()==n)cout<<"YES";
else cout<<"NO";
return 0;
}

Measured memory_bytes: 10368
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    S = input()
    T = input()

    for i in range(len(S)):
        S = S[-1] + S[:-1]

        if S == T:
            print("Yes")
            sys.exit()
    
    print("No")


main()


Measured memory_bytes: 5056
#include<ios>
int main(){
    int H,W;
    scanf("%d%d",&H,&W);
    for( int i=0;i<W+2;i++) putchar('#');
    putchar(getchar()); //改行
    for( int i=0;i<H;i++){
        putchar('#');
        for(int j=0;j<W;j++){
            putchar(getchar());
        }
        putchar('#');
        putchar(getchar()); //改行
    }
    for( int i=0;i<W+2;i++) putchar('#');
    putchar('\n');
    return 0;
}


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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
    // 入力受け取り, 入次数も管理する
int n;
cin >> n;
int mini=100000000;
for(int i=1;i<n;i++){
int a=i;
int b=n-a;
string as=to_string(a);
string bs=to_string(b);
int sum=0;
for(int j=0;j<(int)(as.length());j++){
sum+=ctoi(as[j]);
}//f j
for(int j=0;j<(int)(bs.length());j++){
sum+=ctoi(bs[j]);
}//f j
mini=min(mini,sum);
}

cout <<mini;






}




Measured memory_bytes: 256
def perm(n, k, p):
  ret = 1
  for i in range(n, n-k, -1):
    ret = (ret * i)%p
  return ret

def comb(n, k, p):
  a = perm(n, k, p)
  b = perm(k, k, p)
  return (a*pow(b, p-2, p))%p

S = int(input())

ans = 0
S -= 3
t = 0
while S >= 0:
    ans += comb(S+t,t, 10**9+7)
    S -= 3
    t += 1

print(ans%(10**9+7))

Measured memory_bytes: 64728
object Main {
  def main(args: Array[String]): Unit = {
    val lines = io.Source.stdin.getLines().toArray
    println(Solver.solve(lines))
  }
}

object Solver {
  def solve(lines: Array[String]) = {
    val N = lines(0).split(' ')(0).toInt
    //println(N)
    val input = lines(1)
    val accmulated = accumulate(input, N)
    //println(accmulated.toList)
    lines.drop(2).map { line =>
      val splited = line.split(' ')
      val start = splited(0).toInt
      val end = splited(1).toInt
      accmulated(end-1) - accmulated(start-1)
    }.mkString("\n")
  }

  def accumulate(input: String, N: Int) = {
    var accumulated = new Array[Int](N)
    accumulated(0) = 0
    (1 to N-1).map {i=>
      val current = if (input.slice(i-1, i+1) == "AC") 1 else 0
      accumulated(i) = accumulated(i-1) + current
    }
    accumulated
  }
}

Measured memory_bytes: 63192
function Main(s){
  s = s.split("\n");
  s[0] = s[0].split(" ").map(a=>+a);
  var n = s[0][0];
  var m = s[0][1];
  var p = s[1].split(" ").map(a=>+a);
  var x = [], y = [];
  for(i = 0; i < m; i++){
    x[i] = s[i+2].split(" ").map(a=>+a);
    y[i] = x[i][1];
    x[i] = x[i][0];
  }
  var g = group(x,y,n);
  var ans = 0;
  for(i = 0; i < n; i++){
    if(g[i+1] === g[p[i]])ans++;
  }
  console.log(ans);
}
function group(a,b,n){
  var p = Array(n+1).fill(0).map(a=>[]);
  var q = Array(n+1);
  var al = a.length;
  for(var i = 0; i < al; i++){
    p[a[i]].push(b[i]);
    p[b[i]].push(a[i]);
  }
  var k = 1;
  for(i = 0; i <= n; i++){
    if(q[i])continue;
    q[i] = k;
    a = p[i];
    while(a.length){
      b = a.pop();
      if(q[b])continue;
      q[b] = k;
      for(var j = 0; j < p[b].length; j++){
        a.push(p[b][j]);
      }
    }
    k++;
  }
  return q;
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

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

int main() {
  int n;
  cin >> n;
  if (n) {
    vector<int> a(n);
    for (int i{}; i < n; ++i) {
      cin >> a[i];
    }
    reverse(a.begin(), a.end());
    cout << a[0];
    for (int i{1}; i < n; ++i) {
      cout << ' ' << a[i];
    }
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3072
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;


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

    string s;

    cin >> s;

    if (s=="SUN"){
        cout << 7;

    }
    else if (s=="MON"){
        cout << 6;

    }else if (s=="TUE"){
         cout << 5;

     }else if (s=="WED"){
          cout << 4;

      }else if (s=="THU"){
           cout << 3;

       }else if (s=="FRI"){
            cout << 2;

        }else if (s=="SAT"){
             cout << 1;

         }

    return 0;
}


Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn is_palindrome(s: &[char]) -> bool {
    (0..s.len() / 2).all(|i| s[i] == s[s.len() - 1 - i])
}

fn main() {
    let S = rl().chars().collect::<Vec<_>>();
    let N = S.len();
    let ok = is_palindrome(&S) && is_palindrome(&S[..N / 2]);
    println!("{}", if ok { "Yes" } else { "No" })
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define INPUTL(i,n) for(ll i=0 ; i<n ; i++)
const int MOD = 1000000007 ; // 1000000009 , 1000000023 ,998244353
const ll INF = (1e18);
const ll infinity = (1e9);
const ld PI = 4*atan((ld)1);


ll power(ll x,ll n,ll MOD)
{
    ll result=1;
    while(n>0){
        if(n&1)result = (result * x)%MOD;
        x=(x*x)%MOD;
        n >>= 1;
    }
    return result%MOD;
}

ll gcd(ll a , ll b){
  if(a==0)return b;
  return gcd(b%a,a);
}
ll n;
vector<ll>ar;
vector<vector<ll>>dp(3*1001,vector<ll>(3*1001));

ll solve(ll i,ll j,ll t){
  if(dp[i][j]!=-1)return dp[i][j];
  if(i==j)return 0;
  if(t)return dp[i][j] = min(solve(i+1,j,0) - ar[i] , solve(i,j-1,0) - ar[j-1]);
  else return dp[i][j] = max(solve(i+1,j,1) + ar[i] , solve(i,j-1,1) + ar[j-1]);
}
int main() {
    #ifdef AVI  
        freopen("input.txt" , "r" , stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    
    cin >> n;
    ar = vector<ll>(n);
    for(auto &x:ar)cin >> x;
    dp = vector<vector<ll>>(n+1,vector<ll>(n+1,-1));
    cout << solve(0,n,0);
}

Measured memory_bytes: 141440
/*input
4 -2 -2 4
3
0 0 2
4 0 1
0 4 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll x[maxn],y[maxn],r[maxn];

priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> q;
double mn[maxn];

double dis(int i,int j){
	return max(0.0,hypot(x[i]-x[j],y[i]-y[j])-r[i]-r[j]);
}

int main()
{
	//IOS;
	ll QQ,QQQ;
	cin>>x[0]>>y[0];
	cin>>QQ>>QQQ;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>x[i]>>y[i]>>r[i];
	n+=2;
	REP(i,n) mn[i]=INF64;
	x[n-1]=QQ,y[n-1]=QQQ;

	mn[0]=0;
	q.push(MP(0,0));

	while(SZ(q)){
		auto cur=q.top();
		q.pop();
		if(cur.F>mn[cur.S]) continue;
		//cout<<cur.S<<' '<<mn[cur.S]<<'\n';
		REP(i,n) if(i!=cur.S){
			if(cur.F+dis(cur.S,i)<mn[i]){
				mn[i]=cur.F+dis(cur.S,i);
				q.push(MP(mn[i],i));
			}
		}
	}
	cout<<fixed<<setprecision(12);
	cout<<mn[n-1];
	return 0;
}


Measured memory_bytes: 12528
loop {
  h, w = gets.chomp.split(' ').map { |i| i.to_i }
  if h == 0 and w == 0 then break
  else
    (1..h).each { |hi|
      (1..w).each { |wi|
        if (hi.odd? and wi.odd?) or (hi.even? and wi.even?)
          print '#'
        else
          print '.'
        end
      }
      print "\n"
    }
    print "\n"
  end
}

Measured memory_bytes: 6108
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long sum = 0;
    long p = 0;
    int ki = 0;
    for(int i = 0; i < n; i++) {
      long a = sc.nextLong();
      sum += a;
      if(a % 2 == 1) ki++;
      if((a == 0) || (i == n - 1)) {
        if(ki % 2 == 1) p++;
        ki = 0;
      }
    }
    System.out.println((sum - p) / 2);
  }
}

Measured memory_bytes: 49572
#include<bits/stdc++.h>
using namespace std;
int n , k;
int arr[200010];
bool valid(int temp)
{
    int count=0;
    for(int i=0;i<n;i++)
    {
        count+=(arr[i]+temp-1)/temp-1;
    }
    if(count<=k)
        return true;
    else
        return false;
}
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int l=0 , r=1000000001;
    while(l+1<r)
    {
        int mid=(l+r)/2;
        if(valid(mid))
            r=mid;
        else
            l=mid;
    }
    cout<<r<<"\n";
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>

double deviation(int n, int s[1000])
{
    int i;
    double sum = 0;
    for (i = 0; i < n; i++)
    {
        sum += s[i];
    }
    double ave = sum / n;
    double square_sum = 0.0;
    for (i = 0; i < n; i++)
    {
        square_sum += (s[i] - ave) * (s[i] - ave);
    }
    return sqrt(square_sum / n);
}

int main(void)
{
    int s[1000];
    int n, i;
    while (1)
    {
        scanf("%d", &n);
        if (n == 0)
        {
            break;
        }
        for (i = 0; i < n; i++)
        {
            scanf("%d", &s[i]);
        }
        printf("%lf\n", deviation(n, s));
    }

    return 0;
}



Measured memory_bytes: 2036
n = int(input())
w = list(map(int,input().split()))
s1 = 0
s2 = 0
head = 0
tail = n-1

while head <= tail:
    if s1 >= s2:
        s2 += w[tail]
        tail -= 1
    else:
        s1 += w[head]
        head += 1
else:
    ans = abs(s1-s2)

print(ans)


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    print(N+N**2+N**3)





if __name__ == "__main__":
    main()

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

int main(){
  string n;
  cin>>n;
  int sum=0;
  for(int i=0;i<n.size();i++){
    sum+=n.at(i)-'0';
    sum%=9;
  }
  if(sum==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int main(void){
    string s;
    cin >> s;
    for(int i=0; i<s.length()-1; i++){
        if(s[i] == s[i+1]){
            cout << i+1  << " " << i+2 << endl;
            return 0; 
        }
    }
    for(int i=0; i<s.length()-2; i++){
        if(s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

enum Kind { POINT, ADD, SUB };

struct Query {
    P cod;
    Kind k;
    int idx;
    bool operator <(const Query &another) { return cod == another.cod ? k < another.k : cod < another.cod; }
};

template<class T>
struct BIT {
    int n;
    T id;
    vector<T> dat;

    //[1, n]
    BIT(int n, T id): n(n), id(id), dat(n + 1, id) {}
    void init(int _n, T _id) { 
        n = _n;
        id = _id;
        dat.assign(_n, _id);
    }
    
    //[1, i]
    T sum(int i) const {
        T s = id;
        while (i > 0) {
            s += dat[i];
            i -= i & -i;
        }
        return s;
    }

    //1-indexed
    void add(int i, T x) {
        while (i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> l(n), r(n);
    rep(i, n) cin >> l[i] >> r[i];
    
    vector<Query> qs;
    rep(i, n) qs.push_back(Query{P(l[i], r[i]), Kind::POINT, -1});
    repr(d, 1, m + 1) {
        for (int i = 1; d * i <= m; i++) {
            int a = d * (i - 1), b = d * i;
            qs.push_back(Query{P(b, m), Kind::ADD, d});
            qs.push_back(Query{P(b, b - 1), Kind::SUB, d});
            qs.push_back(Query{P(a, m), Kind::SUB, d});
            qs.push_back(Query{P(a, b - 1), Kind::ADD, d});
        }
    }
    
    sort(qs.begin(), qs.end());
    
    BIT<int> bit(m + 1, 0);
    vector<int> ans(m + 1);
    for (const Query &q: qs) {
        if (q.k == Kind::POINT) {
            bit.add(q.cod.second, 1);
        }
        else if (q.k == Kind::ADD) {
            ans[q.idx] += bit.sum(q.cod.second);
        }
        else {
            ans[q.idx] -= bit.sum(q.cod.second);
        }
    }
    
    repr(d, 1, m + 1) cout << ans[d] << endl;
}

Measured memory_bytes: 135644
import math
N, C, K = map(int, input().split())
T = [0] * N
for i in range(N):
    T[i] = int(input())

T.sort()

l = []
ans = 0

for i in range(N):
    l.append(T[i])
#    print(l)
    if len(l) != 0:
        for j in range(len(l)):   
            if l[j] + K <= T[i] :
                a = l[j]
                for k in range(min(C, len(l))):
                    if l[0]  <= a + K:
                        l.pop(0)
                ans += 1
                if j >= len(l) - C:
                    break
            else:
                break

#print(l)

check = 0
while check == 0:
    a = l[0]
    for k in range(min(C, len(l))):
        if l[0]  <= a + K:
            l.pop(0)
    ans += 1
    if len(l) == 0:
        check = 1






print(ans)


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

#define ff              first
#define ss              second
// #define int             long long
// #define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             998244353
#define endl            "\n"
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}
// #DEBUG
void __print(int x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// ###################################################################

void fast()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int32_t main()
{
  fast();
  int n;
  cin >> n;
  double p[n];
  vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  dp[0][0] = 1.0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 0; j < n + 1; j++) {
      if (j == 0) {
        dp[i][j] = (1.0 - p[i - 1]) * dp[i - 1][j];
      }
      else {
        dp[i][j] = ((1.0 - p[i - 1]) * dp[i - 1][j]) + (dp[i - 1][j - 1] * p[i - 1]);
      }
    }
  }
  double res = 0.0;
  for (int i = int(n / 2) + 1; i < n + 1; i++) {
    res += dp[n][i];
  }
  cout << setprecision(12) << res << "\n";

}

Measured memory_bytes: 70784
#include<iostream>
#include <vector>
using namespace std;
int main() {
int n;
int sum=0;
cin >> n;
vector< int> a(n);
vector<int> b(n);
vector<int> c(n-1);
for (int i = 0; i < n; ++i) {
	cin >> a[i];

}
for (int i = 0; i < n; i++) {
	cin >> b[i];
	sum = sum + b[i];
}
for (int i = 0; i < n-1 ; i++) {
	cin >> c[i];
}
for (int i = 0; i < n-1; i++) {
	if (a[i] + 1 == a[i + 1]) {
		sum =sum + c[a[i]-1];
	}
}

cout << sum;
system("pause");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int A,B;
  while(input(A,B)) {
    int ans = 0;
    int t = 1;
    for (int i=1;i<100;i++) {
      if (t >= B) break;
      t += A-1;
      ans = i;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [a, b] <- map strToInt . words <$> getLine
    let g1 = [2]

    -- 出力
    putStrLn $ if (a == 2 && b == 2) || (a `elem` [4,6,9,11] && b `elem` [4,6,9,11]) || (a `elem` [1,3,5,7,8,10,12] && b `elem` [1,3,5,7,8,10,12])
                then "Yes" else "No"


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N;
  cin >> N;
  int T[N]={};
  rep(i,N) cin >> T[i];
  rep(i,N-1) T[i+1]=lcm(T[i],T[i+1]);
  cout << T[N-1] << endl;
  return 0;
}


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

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

	vector<int> d(k);
	vector<vector<int>> a(k, vector<int>(n, 0));

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

	int trick = 0;

	for (int i = 0; i < n; i++) {
		int snack = 0;
		for (int j = 0; j < k; j++) {
			for (int l = 0; l < d[j]; l++) {
				if (a[j][l] == i + 1) {
					snack++;
				}
			}
		}
		if (snack == 0) {
			trick++;
		}
	}

	cout << trick << endl;
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
typedef unsigned long long ull;

const ull B1 = 9973;
const ull B2 = 1000000007;

int main(){
    int h, w;
    cin >> h >> w;
    char a[h][w];
    for(int i = 0; i < h; i++)  for(int j = 0; j < w; j++)  cin >> a[i][j];
    int r, c;
    cin >> r >> c;
    char b[r][c];
    for(int i = 0; i < r; i++)  for(int j = 0; j < c; j++)  cin >> b[i][j];
    
    ull d[h][w-c+1], hash[h-r+1][w-c+1];
    ull t1 = 1;
    for(int i = 0; i < c; i++)  t1 *= B1;
    for(int i = 0; i < h; i++){
        ull tmp = 0;
        for(int j = 0; j < c; j++){
            tmp = tmp * B1 + a[i][j];
        }
        for(int j = 0; j+c <= w; j++){
            d[i][j] = tmp;
            if(j+c < w) tmp = tmp*B1 + a[i][j+c] - a[i][j]*t1;
        }
    }
    ull t2 = 1;
    for(int i = 0; i < r; i++)  t2 *= B2;
    for(int j = 0; j < w-c+1; j++){
        ull tmp = 0;
        for(int i = 0; i < r; i++){
            tmp = tmp * B2 + d[i][j];
        }
        for(int i = 0; i+r <= h; i++){
            hash[i][j] = tmp;
            if(i+r < h) tmp = tmp * B2 + d[i+r][j] - d[i][j]*t2;
        }
    }

    ull pat[r];
    for(int i = 0; i < r; i++){
        pat[i] = 0;
        for(int j = 0; j < c; j++){
            pat[i] = pat[i] * B1 + b[i][j];
        }
    }
    ull x = 0;
    for(int i = 0; i < r; i++){
        x = x * B2 + pat[i];
    }

    for(int i = 0; i < h-r+1; i++){
        for(int j = 0; j < w-c+1; j++){
            if(hash[i][j] == x){
                cout << i << " " << j << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 19476
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
import Data.Ord
import Data.Time
import qualified Data.Vector as VC
import qualified Data.Vector.Mutable as VM

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n = replicateM n (map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine)

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n = replicateM n (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n (map BS.unpack . BS.words <$> BS.getLine)

main :: IO ()
main = do
  [h, a] <- readInts
  print $ solve h a

solve h a
  | n == 0 = m
  | otherwise = m + 1
  where
    (m, n) = h `divMod` a

Measured memory_bytes: 380
import sys
input = sys.stdin.readline
N,A,B=map(int,input().split())
if N==1:
    print('YES')
    print(A,B)
    sys.exit()
C=A^B
C=bin(C)[2:]
num=0
for i in range(len(C)):
    if C[i]=='1':
        num+=1
if num%2==0:
    print('NO')
    sys.exit()
def f(a,b,n):
    if n==1:
        return [a,b]
    for i in range(n):
        if a&(1<<i)!=b&(1<<i):
            break
    x=(((1<<i)-1)&a)+((a>>(i+1))<<i)
    y = (((1 << i) - 1) & b) + ((b >> (i + 1)) << i)

    for z in range(1<<(n)):
        if x!=z and y!=z and bin(x^z).count('1')%2==1 and bin(y^z).count('1')%2==1:
            break
    #print(i,a,b,x,y,z)
    L=f(x,z,n-1)
    M=f(z,y,n-1)
    dp=[0]*(2*len(L))
    num=0
    for l in L:
        dp[num]=(((1<<i)-1)&l)+((l>>i)<<(i+1))+(a&(1<<i))
        num+=1
    for l in M:
        dp[num]=(((1<<i)-1)&l)+((l>>i)<<(i+1))+(b&(1<<i))
        num+=1
    #print(L,M,dp,i,a,b,x,y,z)
    return dp

L=f(A,B,N)
print('YES')
print(' '.join(map(str,L)))

Measured memory_bytes: 78040
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

bool f(int n, string &s, int m) {
    set<string> se;
    for (int i = m; i+m <= n; ++i) {
        se.insert(s.substr(i-m, m));
        if (se.count(s.substr(i, m)) > 0) {
            return true;
        }
    }

    return false;
}

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

    int l = 0, r = n/2+1;
    while (r - l > 1) {
        int mid = (l+r) / 2;
        if (f(n, s, mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }

    cout << l << endl;

    return 0;
}


Measured memory_bytes: 4352
object Main {
  def main(args: Array[String]): Unit = {
    val factors = scala.io.StdIn.readLine.split(" ")
    var answer  = factors(1).toInt * Math.pow(100, factors(0).toInt).toInt
    if (factors(1).toInt == 100) answer += Math.pow(100, factors(0).toInt).toInt
    println(answer)
  }
}

Measured memory_bytes: 25524
from collections import Counter
import string
import sys
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)

n = II()
s = sorted([IS() for _ in range(n)])
counter = []
for i in range(len(s)):
    counter.append(C(s[i]))
ans = []
for char in string.ascii_lowercase:
    mini = 50
    for c in counter:
        mini = min(mini, c[char])
    ans.append(char * mini)
print(''.join(ans))

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
int main()
{
	string s;
	cin>>s;
	int i,n=s.size();
	int ans = n;
	for(i=0;i<n-1;++i)
	{
		if(s[i]!=s[i+1])
		{
			ans = min(ans,max(i+1,n-(i+1)));
		}
	}
	cout<<ans;
}


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

typedef long long ll;

int main(void)
{
    struct mount {
        ll h1st; ll h2nd; ll h3rd;
    } m;

    m.h1st = 0; m.h2nd = 0; m.h3rd = 0;

    ll mheight;
    for (int i = 0; i < 10; i++) {
        cin >> mheight;
        if (mheight > m.h1st) {
            m.h3rd = m.h2nd;
            m.h2nd = m.h1st;
            m.h1st = mheight;
        } else if (mheight > m.h2nd) {
            m.h3rd = m.h2nd;
            m.h2nd = mheight;
        } else if (mheight > m.h3rd) {
            m.h3rd = mheight;
        }
    }

    cout << m.h1st << endl;
    cout << m.h2nd << endl;
    cout << m.h3rd << endl;

    return 0;
}

Measured memory_bytes: 1160
MOD = 10 ** 9 + 7
 
N, K = map(int, input().split())
l = list(map(int, input().split()))
pos = []
neg = []
z = 0
 
for v in l:
    if v > 0:
        pos.append(v)
    elif v < 0:
        neg.append(v)
    else:
        z += 1
pos.sort()
neg.sort()
 
if N - z < K:
    print(0)
elif N - z == K:
    if len(neg) % 2 and z:
        print(0)
    else:
        out = 1
        for v in neg + pos:
            out *= v
            out %= 10 ** 9 + 7
        print(out)
elif len(pos) == 0:
    if K % 2:
        if z:
            print(0)
        else:
            neg.reverse()
            out = 1
            for i in range(K):
                out *= neg[i]
                out %= 10 ** 9 + 7
            print(out)
    else:
        out = 1
        for i in range(K):
            out *= neg[i]
            out %= 10 ** 9 + 7
        print(out)
else:
    out = 1
    neg.reverse()
    if K % 2:
        out = pos.pop()
        K -= 1
    while K:
        if len(pos) >= 2:
            nP = pos[-1] * pos[-2]
        else:
            nP = 0
 
        if len(neg) >= 2:
            nN = neg[-1] * neg[-2]
        else:
            nN = 0
 
        if nP > nN:
            pos.pop()
            pos.pop()
            out *= nP
        else:
            neg.pop()
            neg.pop()
            out *= nN
        out %= MOD
        K -= 2
    print(out)


Measured memory_bytes: 108004