akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a = list(map(int, input().split()))

# indexをソート
b = [0] * N
for i in range(N):
    b[a[i] - 1] = i

# 初期化　端っこ対策としてひとつ余計に取っている
left = [0] * (N + 1)
right = [0] * (N + 1)
for i in range(N + 1):
    left[i] = i-1
    right[i] = i+1

# 更新
for idx in reversed(b):
    left[right[idx]] = left[idx]
    right[left[idx]] = right[idx]

ans = 0
for i in range(N):
    ans += a[i] * (i - left[i]) * (right[i] - i)

print(ans)

Measured memory_bytes: 40532
def selection_sort(elems: list) -> list:
    swap_num = 0
    for i in range(0, len(elems)):
        mini = i
        for j in range(i + 1, len(elems)):
            if elems[j] < elems[mini]:
                mini = j
        if i != mini:
            elems[i], elems[mini] = elems[mini], elems[i]
            swap_num += 1
    return [elems, swap_num]


if __name__ == "__main__":
    elem_num = int(input())
    elems = list(map(lambda x: int(x), input().split()))
    elems, swap_num = selection_sort(elems)
    print(" ".join([str(elem) for elem in elems]))
    print(f"{swap_num}")



Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
const int inf=2e9;
int n,h[100010],f[100010];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&h[i]);
		f[i]=inf;
	}
	f[1]=0;
	for (int i=1;i<n;i++)
	{
		f[i+1]=min(f[i+1],f[i]+abs(h[i]-h[i+1]));
		f[i+2]=min(f[i+2],f[i]+abs(h[i]-h[i+2]));
	}
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt64(scanner)
	b := getNextInt64(scanner)
	k := getNextInt(scanner)
	for i := 0; i < k; i++ {
		if i%2 == 0 {
			a >>= 1
			b += a
			continue
		}
		b >>= 1
		a += b
	}
	fmt.Fprintln(writer, fmt.Sprintf("%d %d", a, b))
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	int a,b,c,n,i=0,t[100005],x[100005],y[100005],x1=0,y1=0,flag=1;
	scanf("%d",&n);
	while(i<n){
		scanf("%d %d %d",&t[i],&x[i],&y[i]);
		i++;
	}
	i=0;
	for(a=0;a<n;a++){
		if(a==0){
			c=1;
		}else{
			c=t[a-1]+1;
		}
		for(b=c;b<=t[a];b++){
			if(x[a]>x1){
				x1++;
			}else if(x[a]<x1){
				x1--;
			}else if(x[a]==x1 && y[a]>y1){
				y1++;
			}else if(x[a]==x1 && y[a]<y1){
				y1--;
			}else if(x[a]==x1 && y[a]==y1 && (t[a]-b)>=1){
				y1--;
			}else{
				y1--;
			}
	    }
	    if(x1!=x[a] || y1!=y[a]){
	    	flag=0;
	    	break;
		}
	}
	if(flag==1){
		printf("Yes");
	}else{
		printf("No");
	}	
}

Measured memory_bytes: 1280
from collections import deque
import sys

H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
S = [input() for _ in range(H)]

cost = [[0] * W for _ in range(H)]


dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
que = deque([(ch-1, cw-1, 0)])
used = {(ch-1, cw-1)}
warp = [(ch-1, cw-1, 0)]
ddd = []
for i in range(-2,3):
    for j in range(-2,3):
        if (i,j) in dd or i == j == 0:
            continue
        ddd.append((i,j))    

idx = 0
while que:
    while que:
        s, t, cost = que.popleft()
        if s == dh-1 and t == dw-1: 
            print(cost)
            sys.exit()
            break
        for di, dj in dd:
            xi = s + di; yj = t + dj
            if (not 0 <= xi < H) or (not 0 <= yj < W) or S[xi][yj] == '#' or (xi, yj) in used:
                continue
            used.add((xi, yj))
            que.append((xi, yj, cost))
            warp.append((xi,yj, cost)) 
            
    while idx <= len(warp) - 1:
        s, t, cost = warp[idx]
        for di, dj in ddd:
            xi = s + di; yj = t + dj
            if (not 0 <= xi < H) or (not 0 <= yj < W) or S[xi][yj] == '#' or (xi, yj) in used:
                continue
            used.add((xi, yj))
            que.append((xi, yj, cost+1))
            warp.append((xi,yj, cost+1))
        idx += 1
        if que:
            break

print(-1)



Measured memory_bytes: 190180
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    string s; cin >> s;
    if (s == "ARC") cout << "ABC" << endl;
    else cout << "ARC";
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
int main(){
  ll k,a=0;
  cin>>k;
  for(ll i=1;i<k+1;i++){
    for(ll j=1;j<k+1;j++){
      for(ll l=1;l<k+1;l++){
        a+=gcd(gcd(i,j),l);
      }
    }
  }
  cout << a<< endl;
}
 


Measured memory_bytes: 3620
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				sum += d[i] * d[j];
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912

const long double PI = acos(-1);
const ll DEP = 1LL << 50;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int dist[100010];
const int MAX = 1e9+20;
int main(){
    int N,M; cin >> N >> M;
    int a[100010];
    fill(dist,dist+N,0);
    for(int i = 0; i < M; i++){
        cin >> a[i];
        dist[a[i]] = MAX;
    }
    dist[0] = 1;
    if(dist[1] != MAX){
        dist[1] = 1;
    }
    for(int i = 2; i <= N; i++){
        if(dist[i] == MAX) continue;
        if(dist[i-1] != MAX) dist[i] += dist[i-1];
        if(dist[i-2] != MAX) dist[i] += dist[i-2];
        dist[i] %= MOD;
    }
    cout << dist[N] << endl;
}




Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, h, w ] <- readInts
	[ as, bs ] <- transpose <$> replicateM n readInts
	print $ length $ do
		( a, b ) <- zip as bs
		guard $ h <= a && w <= b
		return ()

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef list<ll> listl;
typedef string str;

#define min(A, B) min(static_cast<ll>(A), static_cast<ll>(B))
#define max(A, B) max(static_cast<ll>(A), static_cast<ll>(B))
#define all(x) (x).begin(), (x).end()
#define mp make_pair

#define _rep(i, m)		for(ll i = 0, i_max = m; i < i_max; i++)
#define _erep(i, m)		for(ll i = 0, i_max = m; i <= i_max; i++)
#define _brep(i, b, m)	for(ll i = b, i_max = m; i < i_max; i++)
#define _ebrep(i, b, m)	for(ll i = b, i_max = m; i <= i_max; i++)
#define _rrep(i, m)		for(ll i = m; i >= 0; i--)
#define _rerep(i, b, e)	for(ll i = b; i >= e; i--)

#define rep(m)			_rep(i, m)
#define erep(m)			_erep(i, m)
#define brep(b, m)		_brep(i, b, m)
#define ebrep(b, m)		_ebrep(i, b, m)
#define rrep(m)			_rrep(i, m)
#define rerep(b, e)		_rerep(i, b, e)

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void in(ll& I)
{
	cin >> I;
}

void in(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(listl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(str& s)
{
	cin >> s;
}

void out(ll O)
{
	cout << O;
}

void out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

void rout(bool b, str True, str False)
{
	if (b) cout << True.c_str();
	else cout << False.c_str();
}

int main()
{
	ll K, X;
	cin >> K >> X;

	if (K * 500 >= X)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()
#define ign cin.ignore();

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

using namespace std;
using namespace __gnu_pbds;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main()
{
    IOS
    int n,k;
    cin>>n>>k;
    vi v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    vector<double> vec(n);
    for(int i=0;i<n;i++)
    {
        vec[i]=((double)(v[i]+1))/2;
    }
    double sum=0;
    double maxi=-1;
    for(int i=0;i<k;i++)
    {
        sum=sum+vec[i];
    }
    maxi=sum;
    for(int i=k;i<n;i++)
    {
        sum=sum+vec[i]-vec[i-k];
        maxi=max(maxi,sum);
    }
    cout<<fixed<<setprecision(10)<<maxi;
    return 0;
}


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

int main() {
    double x1, x2, x3, y1, y2, y3;
    int n;
    scanf("%d", &n);
    while (n--) {
        scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
        double a,b,c,d,e,f,x,y,r;
        a=2*(x2-x1);
        b=2*(y2-y1);
        c=x2*x2+y2*y2-x1*x1-y1*y1;
        d=2*(x3-x2);
        e=2*(y3-y2);
        f=x3*x3+y3*y3-x2*x2-y2*y2;
        x=(b*f-e*c)/(b*d-e*a);
        y=(d*c-a*f)/(b*d-e*a);
        r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
        printf("%.3lf %.3lf %.3lf\n", x, y, r);
    }
    return 0;
}

Measured memory_bytes: 2568
def f(S):
    S_not_in_q = []
    S_in_q = []
    tmp = ''
    i = 0
    while i < len(S):
        if S[i] == '"':
            if tmp != '':
                S_not_in_q.append(tmp)
            tmp = ''
            i += 1
            while S[i] != '"':
                tmp += S[i]
                i += 1
            else:
                S_in_q.append(tmp)
                tmp = ''
                i += 1
        else:
            tmp += S[i]
            i += 1
    else:
        if tmp != '':
            S_not_in_q.append(tmp)
    return S_not_in_q, S_in_q
    
while True:
    S1 = input()
    if S1 == '.':
        break
    S2 = input()

    if (S1 == S2):
        print('IDENTICAL')
        continue

    S1_not_in_q, S1_in_q = f(S1)
    S2_not_in_q, S2_in_q = f(S2)

    if (S1_not_in_q != S2_not_in_q):
        print('DIFFERENT')
        continue
    else:
        if len(S1_in_q) != len(S2_in_q):
            print('DIFFERENT')
            continue
        else:
            count = 0
            for i in range(len(S1_in_q)):
                if S1_in_q[i] != S2_in_q[i]:
                    count += 1
            if count < 2:
                print("CLOSE")
                continue
            else:
                print("DIFFERENT")
                continue


Measured memory_bytes: 5592
K, S = gets.split.map(&:to_i)

a, b =
if S <= K
  [0, S]
elsif S <= 2 * K
  [0, K]
else
  [S - 2 * K, K]
end

ans = (a..b).reduce(0) do |x, i|
  t = S - i
  x + (t <= K ? t + 1 : 2 * K - t + 1)
end

puts ans


Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var list = IntList();
            var result = 0;

            for (int i = 0; i < N; i++) {
                if (list[i] == i + 1 && i + 1 < N && list[i + 1] == i + 2) {
                    result++;
                    i++;
                } else if (list[i] == i + 1) {
                    result++;
                }
            }

            Console.WriteLine(result);
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

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

int card[255][14]={{0}};

int main(void){
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        char c;
        int num;
        cin>>c>>num;
        card[(int)c][num]=1;
        
    }
    for(int i=1; i<=13; i++){
        if(card[(int)'S'][i]==0){
            cout<<"S "<<i<<endl;
        }
    }
    for(int i=1; i<=13; i++){
        if(card[(int)'H'][i]==0){
            cout<<"H "<<i<<endl;
        }
    }
    for(int i=1; i<=13; i++){
        if(card[(int)'C'][i]==0){
            cout<<"C "<<i<<endl;
        }
    }
    for(int i=1; i<=13; i++){
        if(card[(int)'D'][i]==0){
            cout<<"D "<<i<<endl;
        }
    }
}



Measured memory_bytes: 3092
#include <ctype.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

//char rbuf[]; int rbufl;
//#define getchar() rbuf[rbufl++]
#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void printint(int32_t x){ if(x<0){x=-x; putchar('-');}else if(x==0){putchar('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar(s[i]); putchar('\n'); }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

int prev[200001];
int rank[200001];
int size[200001];

void init(int n){
	for(int i=1; i<=n; i++){ prev[i]=i; rank[i]=1; size[i]=1; }
}
int root(int x){
	return prev[x]==x?x:(prev[x]=root(prev[x]));
}
void join(int x, int y){
	x=root(x), y=root(y);
	if(x==y) return;
	if(rank[x]<rank[y]){
		prev[x]=y;
		size[y]+=size[x];
	}else if(rank[x]>rank[y]){
		prev[y]=x;
		size[x]+=size[y];
	}else{
		prev[x]=y;
		rank[y]++;
		size[y]+=size[x];
	}
}

int main(void){
	int n=nextint();
	int m=nextint();
	init(n);
	for(int i=0; i<m; i++){
		int a=nextint();
		int b=nextint();
		join(a, b);
	}
	int ans=0;
	for(int i=1; i<=n; i++){
		int now = size[root(i)];
		if(now>ans) ans=now;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int W, H, N;
    cin >> W >> H >> N;
    
    int A = 0;
    int B = W;
    int C = 0;
    int D = H;

    for (int i = 0; i < N; i++){
        int x, y, a;
        cin >> x >> y >> a;

        if (a == 1){
            A = max(A, x);
        }
        else if (a == 2){
            B = min(B, x);
        }
        else if (a == 3){
            C = max(C, y);
        }
        else {
            D = min(D, y);
        }
    }

    if (B - A <= 0 || D - C <= 0){
        cout << 0 << endl;
    }
    else {
        cout << (B - A) * (D - C) << endl;
    }
}

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

using namespace std;

int main(){
    int N, C;
    cin>>N;
    C = N % 10;
    if (C == 2 || C == 4 || C == 5 || C == 7 || C == 9){
        cout<<"hon";
    }
    else if (C == 0 || C == 1 || C == 6 || C == 8){
        cout<<"pon";
    }
    else {
        cout<<"bon";
    }
    return 0;
}


Measured memory_bytes: 3604
import java.util.*;

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

        int n = sc.nextInt();
        String order,str;
        HashSet<String> dic = new HashSet<>();
        
        for(int i = 0;i < n;i++){
            order = sc.next();
            str = sc.next();
            if(order.matches("insert")) dic.add(str);
            else if(order.matches("find")){
                if(dic.contains(str)) System.out.println("yes");
                else    System.out.println("no");
            }
        }
    }
}


Measured memory_bytes: 500920
import sys
m=166666;s=[1]*m;t=[1]*m
for i in range(m):
 if s[i]:
  k=6*i+5
  s[i+k::k]=[0]*len(s[i+k::k])
  t[-2-i+k::k]=[0]*len(t[-2-i+k::k])
 if t[i]:
  k=6*i+7
  s[-2-i+k::k]=[0]*len(s[-2-i+k::k])
  t[i+k::k]=[0]*len(t[i+k::k])
for e in sys.stdin:
 e=int(e)
 print([e-1,sum(s[:(e+1)//6])+sum(t[:(e-1)//6])+2][e>3])


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

int main()
{
    string str;
    cin >> str;
    for (int i = 0; i < str.size(); i++)
    {
        if (str[i] == '1')
        {
            str[i] = '9';
        }
        else
        {
            str[i] = '1';
        }
    }
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops") 
#include<bits/stdc++.h>
 
#define ll 			long long int 
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define dep(i,a,b)	for(int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;
 
#define N  105
ll mod=1e9+7;
ll a[25][25];
 ll dp[25][2100000];
 string s;
 int n;
 int d;
 int rec(int i, int mask,int cnt)
 {
 	if(i==n)
 	{
 		if( cnt==n)
 		return 1;
 	return 0;
 	}
 	ll &res=dp[i][mask];
 	if(res!=-1)
 		return res;
 	res=0;
 	if(n-cnt!=n-i)
 		return 0;
 	rep(j,0,n)
 	{
 		if(a[i][j]&&!(mask&(1<<j)))
 		{
 			res=(res+rec(i+1,int(1<<j|mask),cnt+1))%mod;

 			res=(res+rec(i+1,mask,cnt))%mod;
 		}
 		else
 			res=(res+rec(i+1,mask,cnt))%mod;

 	}
 	return res;
 	
 }
void solve()
{

	memset(dp,-1,sizeof(dp));
	
	
	//int n;
	cin>>n;
	rep(i,0,n)
	{
		rep(j,0,n)
		cin>>a[i][j];
	}
	cout<<rec(0,0,0)%mod;
	

}
	
	
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	#ifndef ONLINE_JUDGE
    	// for getting input from input.txt
    	freopen("input.txt", "r", stdin);
    	// for writing output to output.txt
    	freopen("output.txt", "w", stdout);
	#endif
    	
    
   //cin>>TESTS;
	int p=1;
	while(TESTS--)
	{
		//cout<<"CASE #"<<p<<":"<<" ";
		solve();
		p++;
		
		
	}
	return 0;
}

Measured memory_bytes: 413828
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <cstring>
#include <unordered_set>
#include <unordered_map>

using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const ll INF = 1000010000;
static const ll MOD = 1000000007;
 
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

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

struct graph {
  int L, R;
  vector<vector<int>> adj;
  graph(int L, int R) : L(L), R(R), adj(L+R) { }
  void add_edge(int u, int v) {
    adj[u].push_back(v+L);
    adj[v+L].push_back(u);
  }
  int maximum_matching() {
    vector<int> visited(L), mate(L+R, -1);
    function<bool(int)> augment = [&](int u) { // DFS
      if (visited[u]) return false;
      visited[u] = true;
      for (int w: adj[u]) {
        int v = mate[w];
        if (v < 0 || augment(v)) {
          mate[u] = w;
          mate[w] = u;
          return true;
        }
      }
      return false;
    };
    int match = 0;
    for (int u = 0; u < L; ++u) {
      fill(all(visited), 0);
      if (augment(u)) ++match;
    }
    return match;
  }
};

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(abs(b - a) <= d && abs(c - b) <= d || abs(a - c) <= d) cout<< "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		for (char c : str.toCharArray()) {
			if (Character.isLowerCase(c)) {
				System.out.print(Character.toUpperCase(c));
			} else {
				System.out.print(Character.toLowerCase(c));
			}
		}
		System.out.println();
	}
}

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

int main(){
    int h,a; cin >> h >> a;
    int ans=0;
    for(;;){
        ans++;
        h-=a;
        if(h<=0){
            cout << ans << endl;
            break;
        } 
    }
    return 0;
}


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


int main() {
int  N;
  cin >> N;
  double x;
  if(N%2 == 0){
    cout << fixed << setprecision(10)<< 1.0000000000/2.0000000000 <<endl;
    
}
  else {
    cout << fixed << setprecision(10)<< (N/2 +1.0000000000) / N<<endl;
}
   
}
  


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,cc,n) for(int i=cc;i<(n);++i)
#define dreps(i,cc,n) for(int i=cc;i>(n);--i)
#define llreps(i,cc,n) for(long long i=cc;i<(n);++i)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;


int main()
{
	int n, k, sum = 0;
	cin >> n >> k;
	vector<int> p(n);
	rep(i, n)
	{
		cin >> p[i];
	}
	sort(p.begin(), p.end());
	rep(i, k)
	{
		sum += p[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3620
def main():
    from fractions import gcd
    def lcm(c,d):
        return c//gcd(c,d)*d
    mod=10**9+7
    n=int(input())
    a=[int(i) for i in input().split()]
    l=a[0]
    for i in a:
        l=lcm(l,i)
    ans=0
    for i in a:
        ans+=l//i
    print(ans%mod)
main()


Measured memory_bytes: 6100
#include <iostream>
#include<bits/stdc++.h>
#define ll long long 

#define pb push_back
#define pii pair<int,int>
#define f(i,n) for(int i=0;i<n;i++)

using namespace std;


void solve(){
int n,m;
cin >> n >> m;
cout <<n*m<<endl;
}

int main() {
	
	/*int t;
	cin >> t;
	
	while(t--)*/
	    solve();
	    
	return 0;
}



Measured memory_bytes: 3636
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    int n,k; scanf("%d %d", &n, &k);
    //
    ll res = (ll)0;
    int prev; scanf("%d", &prev);
    if(prev + 0 > k){
        res += prev - min(prev, k-0);
        prev -= prev - min(prev, k-0);
    }
    REP(i,2,n){
        int noww; scanf("%d", &noww);
        if(prev + noww > k){
            res += noww - min(noww, k-prev);
            noww -= noww - min(noww, k-prev);
        }
        if(prev + noww > k){
            res += prev - min(prev, k-noww);
            prev -= prev - min(prev, k-noww);
        }
        prev = noww;
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;

void solve() {
    ll k;
    cin >> k;
    cout << (k/2) * (k-k/2) << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 256
void main() {
	auto ip = readAs!(int[]), N = ip[0], A = ip[1], B = ip[2];
	auto S = rs;
	int a, b;
	foreach(i, c; S) {
		if(c == 'a') {
			a++;
		} else if(c == 'b') b++;

		if(a + min(b, B) <= A + B) {
			debug "%d %d %d %d".writefln(a, b, A, B);
			if(c == 'a') writeln("Yes");
			else if(c == 'b' && b <= B) writeln("Yes");
			else writeln("No");
		} else writeln("No");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 892
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

class IntMutableList {
  private val initialCapacity = 10
  private var innerArray = IntArray(initialCapacity)
  var size = 0
    private set

  fun add(x: Int) {
    if (size == innerArray.size) {
      innerArray = innerArray.copyOf(innerArray.size * 2)
    }
    innerArray[size] = x
    size++
  }

  operator fun get(i: Int): Int {
    if (i < 0 || i >= size) throw IndexOutOfBoundsException()
    return innerArray[i]
  }

  fun toIntArray(): IntArray = innerArray.copyOfRange(0, size)

  fun sort() {
    innerArray.sort(0, size)
  }
}

fun main(args: Array<String>) {
  val (n, k, q) = fastReadInts(3)
  val xs = fastReadInts(n)

  var ans = Int.MAX_VALUE

  // Define here for performance.
  val forbidden = BooleanArray(n)
  for (l in xs) {
    forbidden.fill(false)

    for (i in 0 until n) {
      if (xs[i] < l) {
        forbidden[i] = true
      }
    }

    val mutCandidates = IntMutableList()
    var s = 0
    while (s < n) {
      if (forbidden[s]) {
        s++
      } else {
        var t = s
        while (t + 1 < n && !forbidden[t + 1]) {
          t++
        }
        // xs[s]..xs[t] is a valid range.
        val segmentLength = t - s + 1
        if (segmentLength >= k) {
          val mutSegmentValues = IntMutableList()
          for (i in s..t) {
            mutSegmentValues.add(xs[i])
          }
          mutSegmentValues.sort()
          for (i in 0 until segmentLength - k + 1) {
            mutCandidates.add(mutSegmentValues[i])
          }
        }
        s = t + 1
      }
    }

    if (mutCandidates.size < q) continue

    val candidates = mutCandidates.toIntArray()
    candidates.sort()
    val u = candidates[q - 1]
    ans = Math.min(u - l, ans)
  }
  println(ans)
}


Measured memory_bytes: 72536
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bool prime[55556];

void init_prime() {
  memset(prime, true, sizeof(prime));

  prime[0] = prime[1] = false;
  for (int i = 2; i <= 55555; ++i) {
    if (prime[i]) {
      for (int k = 2*i; k <= 55555; k += i) {
        prime[k] = false;
      }
    }
  }
}

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

  init_prime();


  vector<int> v;
  for (int k = 1; 5*k+1 <= 55555; ++k) {
    if (prime[5*k+1]) v.push_back(5*k+1);
  }

  for (int i = 0; i < n; ++i) {
    printf("%d%c", v[i], i == n-1 ? '\n' : ' ');
  }

  return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    REP(i, s.length()) {
        cout << "x";
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define MAXN 1000000000000000000
using namespace std;
ll a[100010];

ll cheng(ll a,ll b)
{
    ll sum=0;
    while(b)
    {
        if(a>MAXN)
            return -1;
        if(b&1)
        {
            sum+=a;
            if(sum>MAXN)
                return -1;
        }
        a+=a;
        b>>=1;
    }
    return sum;
}

int main(){
	ll n,sum=1;
	scanf("%lld",&n);
	bool is0=false;
	for(ll i=1;i<=n;i++)
    {
        scanf("%lld",a+i);
        if(a[i]==0)
        {
            is0=true;
        }
    }
    if(is0)
    {
        printf("0\n");
        return 0;
    }
	for(ll i=1;i<=n;i++)
    {
        sum=cheng(sum,a[i]);
        if(sum==-1)
            break;
    }
    printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 4644
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()

l = N - sum(A)
if l < 0:
    print(-1)
else:
    print(l)

Measured memory_bytes: 11100
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

def check():
    for i in range(n-m+1):
        for j in range(n-m+1):
            for k in range(m):
                if b[k] != a[j+k][i:i+m]:
                    break
            else:
                return "Yes"

    return "No"

ans = check()

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define pii pair<int,int>
#define MAXNUM 111
pii st[MAXNUM];int num[MAXNUM];
int main()
{
    int n;scanf("%d",&n);
    rep(i,1,n+1)scanf("%d",&num[i]);
    vector<int> x;int flag=1;
    rep(i,1,n+1)
    {
        if(num[i]>i){flag=0;break;}
        x.insert(x.begin()+num[i]-1,num[i]);
    }
    if(!flag)printf("-1\n");
    else {
        for(int k:x)printf("%d\n",k);
    }
}

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

#define rep(i,a,b) for (int i = a;i < b;i++)

using namespace std;

int main() {
	string ans;
	int N;
	cin >> N;
	for (int i = 0;i <= N / 4;i++) {
		for (int j = 0;j <= N / 7;j++) {
			if (N == 4 * i + 7*j) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
using namespace std;
typedef long long ll;
void Read(int &x){
    static char c;
    while(!isdigit(c=getchar()));
    x=(c^48);
    while(isdigit(c=getchar()))
        x=x*10+(c^48);
    return;
}
void Read(ll &x){
    static char c;
    while(!isdigit(c=getchar()));
    x=(c^48);
    while(isdigit(c=getchar()))
        x=x*10+(c^48);
    return;
}
ll a;
int b,c;
int main(){
    Read(a);
    Read(b);
    Read(c);
    printf("%lld\n",a*(b*100+c)/100);
    return 0;
}

Measured memory_bytes: 1600
N = int(input())

a = [int(i) for i in input().split()]

ans = []
sum = 0

for j in range(min(a), max(a)):
    for num in a:
        sum += (num - j) ** 2
    else:
        ans.append(sum)
        sum = 0

if len(ans) == 0:
    print(0)
else:
    print(min(ans))



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  string S;
  cin>>S;
  VI dp(S.size()+1);
  VI ten(200001);
  ten[0]=1;
  rep(i,200000) ten[i+1]=ten[i]*10%2019;
  rep(i,S.size()){
    int tmp=S.size()-1-i;
    dp[i+1]=(dp[i]+(S[tmp]-'0')*ten[i])%2019;
  }
  sort(all(dp));
  int cnt=1;
  ll ans=0;
  rep(i,S.size()){
    if(dp[i+1]==dp[i]) cnt++;
    else{
      ans+=cnt*(cnt-1)/2;
      cnt=1;
    }
  }
  ans+=cnt*(cnt-1)/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 5180
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.next());
        int a=Integer.parseInt(sc.next());
        int b=Integer.parseInt(sc.next());
        ArrayList<Long> v=new ArrayList<Long>();
        for(int i=0;i<n;i++){
            v.add(Long.parseLong(sc.next()));
        }
        sc.close();
        Collections.sort(v,(v1, v2)->{
            if(v1<v2) return 1;
            else if(v1>v2) return -1;
            else return 0;
        });
        long min=v.get(a-1);
        int minCount=0;
        int befA=1;
        double avg=0;
        for(int i=0;i<n;i++){
            if(i<a) avg+=v.get(i);
            if(v.get(i)==min) minCount++;
            if(i==a-1) befA=minCount;
        }
        avg=avg/((double) a);
        long pattern=0;
        long minCj;
        int minCount2;
        int j_max=befA;
        if(min==v.get(0)) j_max+=b-a;
        for(int j=befA;j<=j_max;j++){
            minCount2=minCount;
            minCj=1;
            for(int d=1;d<=j;d++){
                minCj*=minCount2;
                minCount2--;
                minCj/=d;
            }
            pattern+=minCj;
        }
        System.out.println(String.format("%.6f", avg));
        System.out.println(pattern);
    }
}

Measured memory_bytes: 26964
import sys
sys.setrecursionlimit(100000000)
 
moves = [(0, -1), (0, 1), (-1, 0), (1, 0)]
 
 
def search(dataset):
    min_time = 0
    mouse = 1
    gx, gy = get_start(dataset)
    for i in xrange(N):
        gx, gy, min_time_tmp = bfs(dataset, (gx, gy), mouse)
        mouse += 1
        min_time += min_time_tmp
    print min_time
 
 
def bfs(dataset, start, mouse):
    INF = 10000000
    min_time = [[INF for j in xrange(W)] for i in xrange(H)]
    min_time[start[0]][start[1]] = 0
    queue = [start]
 
    while len(queue) != 0:
        dx, dy = queue.pop(0)
        for i, j in moves:
            nx = dx + i
            ny = dy + j
            if 0 <= nx < H and 0 <= ny < W and dataset[nx][ny] != 'X' and min_time[nx][ny] == INF:
                cell = dataset[nx][ny]
            else:
                continue
            if type(cell) is int:
                if mouse == int(cell):
                    min_time[nx][ny] = min_time[dx][dy] + 1
                    return nx, ny, min_time[nx][ny]
            min_time[nx][ny] = min_time[dx][dy] + 1
            queue.append((nx, ny))
 
 
def get_start(dataset):
    for i in xrange(H):
        rows = dataset[i]
        for j in xrange(W):
            cell = rows[j]
            if cell == 'S':
                return i, j
 
 
dataset = []
while True:
    line = raw_input().rstrip().split()
    if len(line) == 3:
        H, W, N = map(int, line)
    else:
        row = []
        for e in line[0]:
            if e.isdigit():
                row.append(int(e))
            else:
                row.append(e)
        dataset.append(row)
    if len(dataset) == H:
        search(dataset)
        break

Measured memory_bytes: 32944
#include<stdio.h>
int main()
{
    int x,a=0,b=0,i=0;
    scanf("%d",&x);
    while(x%500!=0)
    {
        x--;
        i++;
    }
    a=x*2;
    if(i>4)
    {
        while(i%5!=0)
        {
            i--;
        }
        b=i;
    }
    printf("%d",a+b);
}


Measured memory_bytes: 128
l=[input() for _ in range(int(input()))]
s=[]

isno=False
for i in l:
    if i=="A":
        s.append(1)
    else:
        try:
            _=s.pop()
        except:
            print("NO")
            isno=True
            break

if not isno and not s:print("YES")
elif not isno and s:print("NO")



Measured memory_bytes: 5604