akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while(1){
		c -= b;
		if(c <= 0){
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if (a <= 0){
			cout << "No" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>



int main(void){
    int N;
    scanf("%d",&N);
    long long int ans=1;
    int a[N];
    int use[N];
    int kosu=0;
    for(int i=0;i<N;i++)use[i]=0;
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
        if(a[i]==2||a[i]==-2){use[i]=1;ans*=a[i];kosu++;}
    }
    if(ans<0){
        int flag=0;
        for(int i=0;i<N;i++){
            if(a[i]==-1){use[i]=1;ans*=-1;kosu++;flag=1;break;}
        }
            if(flag==0){
                for(int i=N-1;i>=0;i--){if(a[i]==-2){use[i]=0;ans/=-2;kosu--;break;}}
            }
        
    }
    printf("%d\n",kosu);
    for(int i=0;i<N;i++){
        if(use[i]==1)printf("%d\n",i+1);
    }
    return 0;
}


Measured memory_bytes: 2104
package main

import (
	"bufio"
    "fmt"
    "os"
	"unicode/utf8"
	"strconv"
)

/*
func main() {
	var a int;
	fmt.Scan(&a);
	switch a % 10 {
	case 2,4,5,7,9:
		fmt.Println("hon");
	case 3:
		fmt.Println("bon");
	case 0,1,6,8:
		fmt.Println("pon");
	}
}
*/

func main(){
	var k string;
	var s string;

	var sc = bufio.NewScanner(os.Stdin);

	if sc.Scan() {
		k = sc.Text();
	}

	if sc.Scan() {
		s = sc.Text();
	}

	var newK, _ = strconv.Atoi(k);

	if utf8.RuneCountInString(s) <= newK {
		fmt.Println(s);
	} else {
		fmt.Println(string([]rune(s)[:newK]) + "...")
	}
}

Measured memory_bytes: 1756
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
struct Union{
  vector<int> par;
  Union(int a){
  par=vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(int a,int b){
    return (find(a)==find(b));
  }
  int size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    int c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(){
  int h,n,s;
  cin >> h >> n;
  re(i,n){
    cin >> s;
    h=h-s;
  }
  if(h>0)cout << "No";
  else cout << "Yes";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class E
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

		var d = new Dictionary<long, int>();
		foreach (var x in a)
			foreach (var o in Factorize(x).GroupBy(p => p).Select(g => new { p = g.Key, c = g.Count() }))
				if (!d.ContainsKey(o.p) || d[o.p] < o.c) d[o.p] = o.c;

		var lcm = d.Select(p => ((MInt)p.Key).Pow(p.Value)).Aggregate((MInt)1, (x, y) => x * y);
		Console.WriteLine(a.Select(x => lcm / x).Aggregate((x, y) => x + y));
	}

	static long[] Factorize(long n)
	{
		var r = new List<long>();
		while (n % 2 == 0) { r.Add(2); n /= 2; }
		for (long rn = (long)Math.Ceiling(Math.Sqrt(n)), x = 3; x <= rn && n > 1; x += 2)
			while (n % x == 0) { r.Add(x); n /= x; }
		if (n > 1) r.Add(n);
		return r.ToArray();
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator -(MInt x, MInt y) => x.V - y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
	public static MInt operator /(MInt x, MInt y) => x * y.Inv();

	public MInt Pow(int i) => MPow(V, i);
	public MInt Inv() => MPow(V, M - 2);
	public override string ToString() => $"{V}";

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


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


int main() {
  int a, b;
  while (1) {
    cin >> a >> b;
    if (!a && !b) {
      break;
    }
    int d = 0;
    if (a < b) {
      int c = a;
      a = b;
      b = c;
    }
    while (b) {
      int c = a % b;
      a = b;
      b = c;
      ++d;
    }
    cout << a << " " << d << endl;
  }
  return 0;
}

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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  int N;
  string S,T;
  cin>>N>>S>>T;
  vector<int> v;
  int t = 0;
  for(int i = 0; i < N; i++){
    t++;
    if(i == N-1) v.push_back(t);
    else if(S[i]!=S[i+1]) {
      v.push_back(t);
      t=0;
    }
  }
  ll ans = 1LL;
  for(int i = 0; i < (int)v.size();i++){
    if(i==0){
      if(v[i]==1) ans*=3LL;
      if(v[i]==2) ans*=6LL;
    }
    else {
      if(v[i]==1&&v[i-1]==1){
        ans=(ans*2LL)%mod;
      }
      if(v[i]==1&&v[i-1]==2) ans=ans;
      if(v[i]==2&&v[i-1]==1) ans=(ans*2LL)%mod;
      if(v[i]==2&&v[i-1]==2) ans=(ans*3LL)%mod;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n = input()
weights = list(map(int, input().strip().split()))

sum_w = sum(weights)

for t, w in enumerate(weights):
    if sum(weights[:t]) * 2 >= sum_w:
        print(min(sum_w - sum(weights[:t-1]) * 2, sum(weights[:t]) * 2 - sum_w))
        break

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

ll comp(ll a, ll b){
    return max(to_string(a).size(), to_string(b).size());
}

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


    ll n;
    cin >> n;

    ll min_val = INFL;
    for(ll i = 1; i <= sqrt(n); ++ i){
        if(n % i == 0){
            min_val = min(min_val, comp(i, n / i));
        }
    }

    cout << min_val << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	auto count = 0;
	auto m = max(A, max(B, C));
	if (3 * m % 2 != (A + B + C) % 2)
	{
		++m;
	}

	auto diffA = m - A;
	auto diffB = m - B;
	auto diffC = m - C;
	count += diffA / 2;
	count += diffB / 2;
	count += diffC / 2;
	if (diffA % 2 > 0 || diffB % 2 > 0 || diffC % 2 > 0)
	{
		++count;
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
def aa
    # n枚をk人で分配
    n,k = gets.chomp.split(/\s/).map{|x| x.to_i}

    if n < k
        puts 1
        exit
    end

    if n%k == 0
        puts 0
        exit
    end

    kn = Array.new(k,0)
    for i in 1..n
        j = i%k
        kn[j] += 1
    end

    puts kn.max - kn.min
end

aa

Measured memory_bytes: 1916
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
pll haikamax[1<<18][2];
int main(){
	int N;
	scan(N);
	int ANUM=1<<N;
	rep(i,ANUM){
		ll a;
		scan(a);
		if(i!=0){
			priority_queue<pll> haikarank2;
			haikarank2.push(mp(a,(ll)i));
			haikarank2.push(mp(0,-1));
			rep(j,N){
				int haikanum=i&(~(1<<j));
				pll ichii=haikarank2.top();
				haikarank2.pop();
				pll nii=haikarank2.top();
				haikarank2.push(ichii);
				if(i!=haikanum&&haikamax[haikanum][0].second!=ichii.second&&haikamax[haikanum][0].second!=nii.second) haikarank2.push(haikamax[haikanum][0]);
				if(i!=haikanum&&haikamax[haikanum][1].second!=ichii.second&&haikamax[haikanum][1].second!=nii.second) haikarank2.push(haikamax[haikanum][1]);
				/*printf("i:%d j:%d haikanum:%d   ",i,j,haikanum);
				priority_queue<pll> haikaranka=haikarank2;
				rep(k,haikarank2.size()){
					printf("rank[%d]:%lld(%lld) ",k,haikaranka.top().first,haikaranka.top().second);
					haikaranka.pop();
				}
				kaigyo;*/
			}
			haikamax[i][0]=haikarank2.top();
			haikarank2.pop();
			haikamax[i][1]=haikarank2.top();
		}
		else haikamax[i][0]=mp(a,0),haikamax[i][1]=mp(0,-1);
	}
	ll maxnow=0;
	for(int K=1;K<ANUM;K++){
		maxnow=max(maxnow,haikamax[K][0].first+haikamax[K][1].first);
		prin(maxnow);
	}
	return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int dp[N];
int h[N];
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%d",&h[i]),dp[i] = 1e9;
    dp[1]=0;
    for(int i=2;i<=n;i++)
        for(int j=1;j<=k && i-j>0;j++)
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    printf("%d\n",dp[n]);
    return 0;
}


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

void maxHeapify(int*,int);
void buildMaxHeap(int*);

int H;

int main(){
  int *A;
  int i;
  
  //input
  scanf("%d",&H);
  A = malloc(sizeof(int)*(H+1));
  for(i = 1; i < H+1; i++) scanf("%d",&A[i]);

  //process
  buildMaxHeap(A);

  //output
  for(i = 1; i < H+1; i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  
  free(A);
  
  return 0;
}

void maxHeapify(int* A, int i){
  int l, r, largest, temp;
  l = i*2;
  r = i*2+1;
  
  if(l <= H && A[l] > A[i]) largest = l;

  else largest = i;
  
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(A, largest);
  }// 再帰的に呼び出し
}

void buildMaxHeap(int* A){
  int i;
  
  for(i = H/2; i >= 1; i--){
    maxHeapify(A, i);
  }
}



Measured memory_bytes: 3348
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;


bool recur(int it, int p[13], bool f)
{
	while (p[it] == 0 && it < 10)
		it++;

	if (it == 10 && f)
		return true;
	else if (it == 10 && !f)
		return false;


	int a[13];
	int b[13];
	int c[13];
	memcpy(a, p, sizeof(a));
	memcpy(b, p, sizeof(b));
	memcpy(c, p, sizeof(c));

	bool ok = false;
	if (p[it] > 0 && p[it+1] > 0 && p[it+2] > 0)
	{
		--a[it]; --a[it+1]; --a[it+2];
		ok |= recur(it, a, f);
	}
	if (p[it] >= 3)
	{
		b[it] -= 3;
		ok |= recur(it, b, f);
	}
	if (p[it] >= 2 && !f)
	{
		c[it] -= 2;
		ok |= recur(it, c, true);
	}

	return ok;
}

int main()
{
	char buf[128];

	while (fgets(buf, sizeof(buf), stdin))
	{
		buf[13] = '\0';
		int p[13];
		memset(p, 0, sizeof(p));
		for (int i = 0; buf[i] != '\0'; ++i)
			++p[buf[i]-'0'];

		bool any = false;
		vector<int> ans;
		for (int i = 1; i <= 9; ++i)
		{
			int wp[13];
			memcpy(wp, p, sizeof(wp));
			++wp[i];
			bool ok = true;
			for (int j = 1; j <= 9; ++j)
				ok &= wp[j] <= 4;
			if (!ok)
				continue;

			if (recur(1, wp, false))
			{
				ans.push_back(i);
			}
		}
		if (ans.size())
		{
			for (int i = 0; i < ans.size()-1; ++i)
				printf("%d ", ans[i]);
			printf("%d\n", ans[ans.size()-1]);
		}
		else
			printf("0\n");
	}

	return 0;
}

Measured memory_bytes: 0
C1 = input()
C2 = input()

c11 = C1[0]
c12 = C1[1]
c13 = C1[-1]

c21 = C2[0]
c22 = C2[1]
c23 = C2[-1]

if (c11 == c23) and (c13 == c21) and (c12 == c22):
    print("YES")

else:
    print("NO")



Measured memory_bytes: 8924
use proconio::{fastout, input};
use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {n: usize, a: [usize;n]};

    let mut b = BTreeMap::new();

    for i in 0..n {
        b.insert(a[i], i + 1);
    }

    for (k, v) in &b {
        print!("{} ", v);
    }
}


Measured memory_bytes: 6368
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>

typedef long long ll;

const int maxn = 2e5 + 7;
const int maxm = 4e5 + 7;

using namespace std;

int a[maxn];
int to[maxm];
int val[maxm];
int nex[maxm];
int last[maxn], k;
int rt, now, pos;
ll mn;
int sz[maxn];
int son[maxn];
int vis[maxn];
int fa[maxn];
struct edge {
	int x, y;
	ll z;
	inline int operator < (const edge &a) const {
		return z < a.z;
	}
};
vector <edge> e;
int cnt;

inline int read()
{
	int X = 0; char ch = getchar();
	while (ch < '0' || ch > '9') ch = getchar();
	while (ch >= '0' && ch <= '9') X = X * 10 + ch - '0', ch = getchar();
	return X;
}

inline void add_edge(int x, int y, int z)
{
	to[++k] = y; val[k] = z; nex[k] = last[x]; last[x] = k;
}

void getg(int x, int f)
{
	son[x] = 0;
	sz[x] = 1;
	for (int i = last[x]; i; i = nex[i]) {
		int y = to[i];
		if (vis[y] || y == f) continue;
		getg(y, x);
		sz[x] += sz[y];
		if (sz[y] > son[x]) son[x] = sz[y];
	}
	if (now - sz[x] > son[x]) son[x] = now - sz[x];
	if (son[x] < son[rt]) rt = x;
}

void get_min(int x, int f, ll dis)
{
	if (a[x] + dis < mn) mn = a[x] + dis, pos = x;
	for (int i = last[x]; i; i = nex[i])
		if (!vis[to[i]] && to[i] != f) get_min(to[i], x, dis + val[i]);
}

void add(int x, int f, ll dis)
{
	e.push_back((edge){x, pos, a[x] + a[pos] + dis});
	for (int i = last[x]; i; i = nex[i])
		if (!vis[to[i]] && to[i] != f) add(to[i], x, dis + val[i]);
}

void solve(int x)
{
	mn = 1e18;
	get_min(x, 0, 0);
	add(pos, 0, 0);
	vis[x] = 1;
	for (int i = last[x]; i; i = nex[i]) {
		int y = to[i];
		if (vis[y]) continue;
		now = sz[y];
		rt = 0;
		getg(y, x);
		solve(rt);
	}
}

int find(int x)
{
	return fa[x] == x ? x : fa[x] = find(fa[x]);
}

inline ll kruskal()
{
	ll ans = 0;
	sort(e.begin(), e.end());
	for (vector<edge>::iterator it = e.begin(); it != e.end(); it++) {
		int x = find((*it).x), y = find((*it).y);
		if (x != y) fa[x] = y, ans += (*it).z;
	}
	return ans;
}

int main(void)
{
	int n = read();
	for (int i = 1; i <= n; i++) a[i] = read(), fa[i] = i;
	for (int i = 1; i < n; i++) {
		int x = read(), y = read(), z = read();
		add_edge(x, y, z);
		add_edge(y, x, z);
	}
	now = n;
	son[0] = 1e9;
	getg(1, 0);
	solve(rt);
	cout << kruskal() << endl;
	
	return 0;
}

Measured memory_bytes: 86368
<?php
$l=trim(fgets(STDIN));
$c=0;
$n=[];
for($i=0;$i<$l;$i++) $n[]=trim(fgets(STDIN));
echo array_reduce($n
,function($carry,$n){
  if($n<2) return --$carry;
  if($n==2) return $carry;
  if($n%2==0) return --$carry;
  $max=floor(sqrt($n));
  for($i=3;$i<=$max;$i+=2) if($n%$i==0) return --$carry;
  return $carry;
}
,$l);
?>

Measured memory_bytes: 16940
# -*- coding: utf-8 -*-
x,y,z,k = map(int,input().split())
a,b,c = [],[],[]
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []

for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])

ab.sort()

abc = []

for i in range(min(len(ab),k)):
    for j in range(min(z,k)):
        abc.append(ab[-(i+1)] + c[j])

abc.sort()

for i in range(k):
    print(abc[-(i+1)])

Measured memory_bytes: 147900
#include <bits/stdc++.h>
#define endl "\n"
#include <set>


using namespace std;
int main(){
    
ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
int n; cin>>n;
vector<int> a, b, c;
for (int i=0; i<n; i++)
{
	int temp1,temp2, temp3;
	cin>>temp1>>temp2>>temp3;
	a.push_back(temp1); b.push_back(temp2); c.push_back(temp3);
}
int dp[n][4];
dp[n-1][1]=a[n-1];
dp[n-1][2]=b[n-1];
dp[n-1][3]=c[n-1];

for (int i=n-2; i>=0; i--)
{
	dp[i][1]= a[i]+ max( dp[i+1][2], dp[i+1][3]);
	dp[i][2]= b[i] + max( dp[i+1][1], dp[i+1][3]);
	dp[i][3]= c[i] + max( dp[i+1][1], dp[i+1][2]);
}

int ans=max(dp[0][1], dp[0][2]);
ans=max(dp[0][3], ans);
cout<< ans<<endl;

}

Measured memory_bytes: 3308
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, s) memset((v), s, sizeof(v))
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = 50;

int w, h;
int tate[N][N];
int yoko[N][N];
int m[N][N];

int main(void){
    while(cin >> w >> h, w){
        MEMSET(tate, 1);
        MEMSET(yoko, 1);
        MEMSET(m, 0);

        rep(y, h){
            rep(x, w - 1) cin >> tate[y][x + 1];
            if(y != h - 1) rep(x, w) cin >> yoko[y + 1][x];
        }

        queue<pii> q;
        q.push(mp(0, 0));
        m[0][0] = 1;
        while(!q.empty()){
            pii curP = q.front(); q.pop();
            if(curP == mp(w - 1, h - 1)) break;

            if(!tate[curP.Y][curP.X] && !m[curP.Y][curP.X - 1]) q.push(mp(curP.X - 1, curP.Y)), m[curP.Y][curP.X - 1] = m[curP.Y][curP.X] + 1;
            if(!tate[curP.Y][curP.X + 1] && !m[curP.Y][curP.X + 1]) q.push(mp(curP.X + 1, curP.Y)), m[curP.Y][curP.X + 1] = m[curP.Y][curP.X] + 1;
            if(!yoko[curP.Y][curP.X] && !m[curP.Y - 1][curP.X]) q.push(mp(curP.X, curP.Y - 1)), m[curP.Y - 1][curP.X] = m[curP.Y][curP.X] + 1;
            if(!yoko[curP.Y + 1][curP.X] && !m[curP.Y + 1][curP.X]) q.push(mp(curP.X, curP.Y + 1)), m[curP.Y + 1][curP.X] = m[curP.Y][curP.X] + 1;
        }

        cout << m[h - 1][w - 1] << endl;
    }

    return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    sort(a.begin(), a.end());

    auto m = a.back();

    auto it = lower_bound(a.begin(), a.end(), (m + 1) / 2);
    if (*it == m) {
        --it;
    } else if (it != a.begin() && (m - 2 * *(it - 1)) < (2 * *it - m)) {
        --it;
    }

    cout << m << " " << *it << endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll N=in();
	vector<ll> A(N);
	REP(i,N){
		A[i] = in<ll>()-i-1;
	}
	sort(ALL(A));
	ll b = A[N/2];
	ll sum = 0;
	REP(i,N){
		sum += abs(A[i]-b);
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m=MI()
lis=[LI() for i in range(m)]
nums=[]
for i in range(m):
    if lis[i][0]==1:
        nums.append(lis[i][1])
    if lis[i][1]==n:
        nums.append(lis[i][0])
#print(nums)
if len(nums)>len(list(set(nums))):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 104796
N = gets.to_i
dpa = Array.new(N + 1, 0)
dpb = Array.new(N + 1, 0)
dpc = Array.new(N + 1, 0)
N.times do |i|
  a, b, c = gets.split.map(&:to_i)
  dpa[i+1] = dpb[i] + a > dpc[i] + a ? dpb[i] + a : dpc[i] + a
  dpb[i+1] = dpa[i] + b > dpc[i] + b ? dpa[i] + b : dpc[i] + b
  dpc[i+1] = dpa[i] + c > dpb[i] + c ? dpa[i] + c : dpb[i] + c
end
puts [dpa[N], dpb[N], dpc[N]].max

Measured memory_bytes: 4220
n, m = map(int, input().split())
prob = [False] * (n + 1)
exact = [False] * (n + 1)
prob[1] = exact[1] = True
num_in = [1] * (n + 1)
for _ in range(m):
    x, y = map(int, input().split())
    if num_in[x] == 1 and exact[x]:
        exact[y] = True
        exact[x] = False
        prob[x] = False
        prob[y] = True
    elif num_in[x] > 1 and exact[x]:
        exact[x] = False
        prob[y] = True
    elif prob[x]:
        if num_in[x] == 1:
            prob[x] = False
        prob[y] = True
    num_in[y] += 1
    num_in[x] -= 1
print(prob.count(True))

Measured memory_bytes: 11332
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,q1,q2;
double a[86400],L,t;
bool check(double x){
  double p=L;
  r(i,86400){
    p-=a[i]-x;
    if(p>L)p=L;
    if(p<0)return 0;
  }
  double tx=p;
  r(i,86400){
    tx-=a[i]-x;
    if(tx>L)tx=L;
    if(tx<0)return 0;
  }
  return p-tx<1e-5;
}
int main(){
  while(cin>>n>>L,n){
    memset(a,0,sizeof(a));
    r(i,n){
      cin>>q1>>q2>>t;
      for(int i=q1;i<q2;i++)a[i]=t;
    }
    double r=1e11,l=0;
    r(i,77){
      double mid=(r+l)/2.0;
      if(check(mid))r=mid;
      else l=mid+1e-10;
    }
    printf("%.10f\n",l);
  }
}

Measured memory_bytes: 3948
from itertools import combinations
import math
a,b=map(int,input().split())
li=[list(map(int,input().split())) for i in range(a) ]
ln=list(combinations(range(a),2))
ans=[]
l=0
for i in range(len(ln)):
    for j in range(b):
        l+=(li[ln[i][0]][j]-li[ln[i][1]][j])**2
    l3=math.sqrt(l)
    ans.append(l3)
    l=0

answe=0
for i in ans:
    if i.is_integer():
       answe+=1 
print(answe)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  printf ("%" PRIi32 "\n", k == 1 ? 0 : n - k);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
  string s, t;
  cin >> s;
  cin >> t;

  std::reverse(t.begin(), t.end());
  if(s == t){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for (int i=1;i<=n;i++){
            int x=i;
            if (x%3==0){
                System.out.print(" "+i);
                continue;
            }
            else if(x%10==3){
                System.out.print(" "+i);
                continue;
            }
            while ((x/=10)!=0){
                if (x%10==3){
                    System.out.print(" "+i);
                    break;
                }
            }
        }
        System.out.print("\n");
    }
}

Measured memory_bytes: 28472
// https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_10_B
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#define MAXN    100
#define min(a, b) ((a) < (b) ? (a) : (b))

typedef long long LL;

LL dp[MAXN][MAXN];
int rows[MAXN], cols[MAXN];

int main()
{
    int n, i, j, k, diag;

    while(scanf("%d", &n)!=EOF){
        for(i=0; i<n; i++)
            scanf("%d%d", &rows[i], &cols[i]);
        memset(dp, 0, sizeof(dp));
        for(diag=1; diag<n; diag++){
            for(i=0; ; i++){
                j = i + diag;
                if(j==n) break;
                dp[i][j] = LLONG_MAX;
                for(k=i; k<j; k++)
                    dp[i][j] = min(dp[i][j],
                                   dp[i][k] + dp[k+1][j] + rows[i]*cols[k]*cols[j]);
            }
        }
        printf("%lld\n", dp[0][n-1]);
    }
    return 0;
}



Measured memory_bytes: 2088
#include <stdio.h>
#include <stdlib.h>
int main(){
  int *R,j,n,minv,maxv;

  scanf("%d",&n);
  R = (int *)malloc(n * sizeof(int));

  for(j = 0 ; j < n ; j++) scanf("%d",&R[j]);
  
  minv = R[0];
  maxv = R[1] - R[0];
  
  for(j = 1 ; j <= n - 1 ; j++){
    if(maxv < R[j] - minv) maxv = R[j] -minv;   
    if(minv > R[j]) minv = R[j]; }

    printf("%d\n",maxv);

    free(R);
    
    return 0;
}



Measured memory_bytes: 2280
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 1e5 + 8;

vector<int> g[N];


int c[N];
int used[N];
set<pair<int, int>> ans;

void inv(int u, int v) {
	if (ans.count({u, v})) {
		ans.erase({u, v});
		ans.insert({v, u});
	} else if (ans.count({v, u})) {
		ans.erase({v, u});
		ans.insert({u, v});
	} else {
		assert(false);
	}
}

int dfs(int cur) {
	int cv = 0;
	used[cur] = 1;
	for (auto t : g[cur]) {
		if (!used[t]) {
			int v = dfs(t);
			if (v & 1) inv(cur, t);
			cv += v;
		}
	}
	cv += c[cur];
	return cv;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	

	int n, m;
	cin >> n >> m;
	if (m & 1) {
		cout << -1 << endl;
		return 0;
	}
	while (m--) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		c[u] ^= 1;
		ans.insert({u, v});
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0);
	for (auto t : ans) {
		cout << t.first + 1 << ' ' << t.second + 1 << '\n';
	}
}


Measured memory_bytes: 18688
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test(n) cout << "test" << n << endl;
#define fixsp(n) fixed << setprecision(n)
#define defsp(n) defaultfloat << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define iikae auto&
#define vector3D(K, N, M, DP) vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M)));
#define vector4D(K, N, M, O, DP) vector<vector<vector<vector<ll>>>> DP(K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O))));
#define zenbu(a) a.begin(), a.end()
#define rzenbu(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long;using ld = long double;using P = pair<ll,ll>;
template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}
template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};
template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}

/* ここからコード開始 */

int main(){
  kyopro;
  ll N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string S;
  cin >> S;
  ll dame1{}, dame2{};
  rep(i, A-1, max(C, D)){
    if(S[i] == S[i+1] && S[i] == '#'){
      dame1 = 1;
    }
  }
  if(C > D){
    dame2 = 1;
    rep(i, B-1, D){
      if(S[i-1] == S[i] && S[i] == S[i+1] && S[i] == '.'){
      dame2 = 0;
      }
    }
  }
  if(dame1 == 0 && dame2 == 0){
    cout << "Yes" << rt;
  }
  else{
    cout << "No" << rt;
  }
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
const double pie  =3.141592653589793238463;
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define POP(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(),A.end());
#define REV(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n" 
const ll dx[4] = { -1, 1, 0, 0};
const ll dy[4] = {0, 0, -1, 1};
ll XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
ll YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
#define precise(x) cout<<fixed<<setprecision(x)
#define t1(x)                cerr<<#x<<": "<<x<<endl
#define t2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define t4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define t5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define t6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
void SieveOfEratosthenes(ll n) 
{ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // for (ll p=2; p<=n; p++) 
       // if (prime[p]) 
          // cout << p << " "; 
} 

ll power(ll x, ll y) 
{ 
    ll res = 1; 
    while (y > 0) 
    { 
        if (y & 1) 
            res = res * x; 
        y = y >> 1; 
        x = x * x; 
    } 
    return res; 
}
int main()
{
    fastio
    ll t,i,j,k,l,s,m,n,a,x,b,y,z,c,h,d,e,p,o,nl,np,q,r;
    cin>>n;
    map<string,int>mp;
    rep(i,0,n)
    {
        string ss;
        cin>>ss;
        mp[ss]++;
    }

    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;


}

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

int W,H, grid[50][50];

int dfs(int sy, int sx){
	if(grid[sy][sx]==0)return 0;

	stack<pair<int,int>> S;
	S.push( {sy,sx} );

	while(S.size()){
		pair<int,int> u=S.top();	S.pop();
		grid[u.first][u.second]=0;

		for(int dy=-1; dy<=1; dy++){
			for(int dx=-1; dx<=1; dx++){
				int nY=u.first+dy, nX=u.second+dx;
				if(nY<0||nX<0||nY>=H||nX>=W)continue;
				else if(grid[nY][nX]==0)continue;

				S.push( {nY,nX} );
			}
		}
	}
	return 1;
}

int main(){
	while((cin>>W>>H)&&W&&H){
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cin>>grid[i][j];
			}
		}

		int ans=0;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				ans+=dfs(i,j);
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}



Measured memory_bytes: 3184
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i=0, j=0, wordnum, count[1000]={0}, mode, max=0, len=0, longest;
	char word[1000][33] = {0};

	while(scanf("%s", word[i]) != EOF)
		i++;

	wordnum = i;

	i=0;
	while(word[i][0] != '\0'){
		while(word[i][j] != '\0'){
			if(word[i][j] >= 'A' && word[i][j] <='Z'){
				word[i][j] += 'a' - 'A';
			}
			j++;
		}
		j=0;
		i++;
	}

	for(i=0; i<wordnum; i++){
		for(j=0; j<wordnum; j++){
			if(strcmp(word[i], word[j]) == 0){
				count[i]++;
			}
		}
	}

	for(i=0; i<wordnum; i++){
		if(max < count[i]){
			max = count[i];
			mode = i;
		}
	}

	for(i=0; i<wordnum; i++){
		if(strlen(word[i]) > len){
			len = strlen(word[i]);
			longest = i;
		}
	}

	printf("%s %s\n", word[mode], word[longest]);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int count_by_mul(int money, int mul) {
  int count = 0;

  while(money >= mul) {
    int num = mul;
    while (money >= num * mul) {
      num *= mul;
    }

    money -= num;
    count++;
  }
  count += money;

  return count;
}

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

  int mn = N;
  for(int i=0; i<=N; i++) {
    int count = count_by_mul(i, 6) + count_by_mul(N - i, 9);
    if (mn > count) mn = count;
  }

  cout << mn << endl;

  return 0;
}


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

ll INF = 1LL << 60;
int N;
void
bfs(int index, vector<vector<int>>& tree, vector<vector<int>>& ans)
{
  vector<int> dist(N + 1, -1);
  dist[index] = 0;
  queue<int> q;
  for(int value: tree[index]){
    q.push(value);
    //if(index <= value){
      dist[value] = 1;
      ans[index][dist[value]] += 1;
    //}
  }

  while(!q.empty()){
    int value = q.front();
    q.pop();
    for(int next :tree[value]){
      if(dist[next] != -1) continue;
      //if(index >= next) continue;
      dist[next] = dist[value] + 1;
      ans[index][dist[next]] += 1;
      q.push(next);
    }
  }
}


int 
main() {

  int X, Y; cin >> N >> X >> Y;
  vector<vector<int>> tree(N + 1);
  vector<vector<int>> ans (N + 1, vector<int>(N + 1));

  rep(i, 1, N){
    tree[i].push_back(i + 1);
    tree[i + 1].push_back(i);
  }
  if(X != Y && abs(X - Y) != 1){
    tree[X].push_back(Y);
    tree[Y].push_back(X);
  }
  
  repe(i, 1, N){
    bfs(i, tree, ans);
  }

  rep(i, 1, N){
    int out = 0;
    repe(k, 1, N){
      out += ans[k][i];
    }
    cout << out / 2 << endl;
  }
}


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


void solve(long long N, long long D, std::vector<std::vector<long long>> X){
  long long count = 0;

  for(int i = 0; i < N; i++) {
    for(int j = (i+1); j < N; j++) {
      long long acc = 0;

      for(int k = 0; k < D; k++) acc += (abs(X[i][k] - X[j][k]) * abs(X[i][k] - X[j][k]));

      for(int k = 0; k <= acc; k++) {
        if((k*k) == acc) {
          count++;
          break;
        }
      }
    }
  }

  cout << count << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long D;
  scanf("%lld",&D);
  std::vector<std::vector<long long>> X(N, std::vector<long long>(D));
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < D ; j++){
      scanf("%lld",&X[i][j]);
    }
  }
    solve(N, D, std::move(X));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int start, end;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'A') {
      start = i;
      break;
    }
  }
  
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'Z') {
      end = i;
    }
  }
  cout << end - start + 1 << endl;
}

Measured memory_bytes: 640
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    if i == 0:
        ans += B[i]
    elif i == N - 1:
        ans += B[i - 1]
    else:
        ans += min(B[i], B[i - 1])
print(ans)



Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <climits>
using namespace std;

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
	while(1) {
		int m;
		cin >> m;
		if(m == 0) break;
		m /= 100;
		int ret = INT_MAX;
		rep(i,m/2+1) {
			rep(j,m/3+1) {
				rep(k,m/5+1) {
					if(i * 2 + j * 3 + k * 5 == m) {
						int sum = 0;
						sum += i * 380 + j * 550 + k * 850;
						sum -= i / 5 * (int) (380 * 5 * 0.2) + j / 4 * (int) (550 * 4 * 0.15)
							+ k / 3 * (int) (850 * 3 * 0.12);
						if(sum < ret) {
							ret = sum;
						}
					}
				}
			}
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main {
	Scanner sc;
	int N;
	int[] A, C, D, skD, sD;
	
	public Main() {
		sc = new Scanner(System.in);
	}
	
	private void calc() {
		N = sc.nextInt();
		C = new int[N+1];
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			C[a]++;
		}
		D = new int[N+1];
		for (int i = 0; i <= N; i++) D[C[i]]++;
		
		sD = new int[N+1];
		skD = new int[N+1];
		
		sD[0] = D[0]; skD[0] = 0;
		for (int i = 1; i <= N; i++) {
			sD[i] = sD[i-1] + D[i];
			skD[i] = skD[i-1] + i*D[i];
		}
		int K = 1;
		int lastK = -1;
		for (int X = N; X > 0; X--) {
			int f = f(X);
			if (f != lastK) {
				for (; K <= f; K++) System.out.println(X);
				lastK = f;
			}
		}
		for (; K <= N; K++) System.out.println(0);
	}
	
	private int f(int X) {
		return (skD[X]+X*(sD[N]-sD[X]))/X;
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 95236
using System;
using System.Linq;
using System.Collections.Generic;
class Program3
{
    static void Main(string[] args)
    {
        // 整数の入力
        double N = double.Parse(Console.ReadLine());

        List<kofukuchiObj> listObjA = new List<kofukuchiObj>();

        for (int i = 0; i < N; i++)
        {
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            listObjA.Add(new kofukuchiObj()
            {
                kofukuchiA = double.Parse(input[0]),
                kofukuchiB = double.Parse(input[1])
            });
        }

        listObjA = listObjA.OrderByDescending(x => (x.kofukuchiA+ x.kofukuchiB)).ToList();

        double cntA = 0;
        double cntB = 0;

        for (int i = 0; i < N; i++)
        {
            if(i % 2 == 0)
            {
                //高橋くんの番     
                cntA += listObjA[i].kofukuchiA;
            }
            else
            {
                //青木さんの番      
                cntB += listObjA[i].kofukuchiB;
            }
        }

        //出力
        Console.WriteLine(cntA - cntB);
    }

    public class kofukuchiObj
    {
        public int index { get; set; }
        public double kofukuchiA { get; set; }
        public double kofukuchiB { get; set; }
    }  
}

Measured memory_bytes: 28860
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
constexpr int64_t INF = 1e6 + 1;

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

  int32_t K;
  cin >> K;
  vector<vector<int>> next_lsb(4, vector<int>(10));
  next_lsb[0] = {0,1,2,3,4,5,6,7,8,9};
  next_lsb[1] = {0,7,4,1,8,5,2,9,6,3};
  next_lsb[2] = {0,3,6,9,2,5,8,1,4,7};
  next_lsb[3] = {0,9,8,7,6,5,4,3,2,1};
  int64_t cur = K;
  int64_t cnt = 0;
  int base_lsb = K % 10;
  if (base_lsb == 1) {
    base_lsb = 0;
  } else if (base_lsb == 3) {
    base_lsb = 1;
  } else if (base_lsb == 7) {
    base_lsb = 2;
  } else if (base_lsb == 9) {
    base_lsb = 3;
  } else {
    cout << -1 << endl;
    return 0;
  }

  while ( cur != 0 && cnt < INF) {
    int lsb = cur % 10;
    int nlsb = lsb <= 7 ? 7 - lsb : 17 - lsb;
    cur += K * next_lsb[base_lsb][nlsb];
    cur /= 10;
    //cout << nlsb << "," << cur << endl;
    cnt++;
  }

  if (cnt >= INF) {
    cout << -1 << endl;
  } else {
    cout << cnt << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3596
def findSumofDigits(n):
    s = 0
    while(n > 0):
        s += n % 10
        n = int(n/10)
    return s

n,a,b = map(int, input().split())
total = 0
for i in range(n+1):
    s = findSumofDigits(i)
    if a<= s <=b:
        total += i
print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#include <iomanip>      // std::setprecision
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define FLL(i,L,R) for (long long int i = L; i < R; i++) //next four are for "for loops"
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)
#define char2Int(c) (c-'0')
#define lastEle(vec) vec[vec.size()-1] 
#define SZ(x) ((int)((x).size()))
#define REMAX(a,b) (a)=max((a),(b)) // set a to the maximum of a and b
#define REMIN(a,b) (a)=min((a),(b));
#define FENWICK(k) (k&-k)
#define FOREACH(i,t) for (auto i=t.begin(); i!=t.end(); i++) // traverse an STL data structure
#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
#define PRESENT(c,x) ((c).find(x) != (c).end()) 
#define CPRESENT(c,x) (find(ALL(c),x) != (c).end()) 
#define LL long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef int elem_t;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
// directions
const int fx[4][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}};
const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
const int rogi[4][2] = { {1,1}, {1,-1}, {-1,1}, {-1,-1} };

int n;
int ile[1000007];

void dane() {
    cin>>n;
    F(i,0,n-1) {
        int a;
        cin>>a;
        ile[a]++;
    }
    F(i,1,n+1) cout<<ile[i]<<endl;
}

int main() {
	IOS
	// int t;
	// cin>>t;
	// F(i,0,t)
	    dane();
    return 0;
}

Measured memory_bytes: 4444
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int N=s.size();
  int a = N-1;
  int z = 1;
  for(int i=0; i<N; i++){
    if(i < a && s[i] == 'A'){
      a = i;
    }
    if(i > z && s[i] == 'Z'){
      z = i;
    }
  }
  cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define inf 0x7fffffff
#define llinf 0x7fffffffffffffffll
using namespace std;
int ge(int x,int y)
{
	int r=x%y;
	if(r==0)
	{
		return y;
	}
	return ge(y,r);
}
int main()
{
	int i,j,k,n,m,x,gcd;
	scanf("%d%d",&n,&m);
	scanf("%d",&x);
	gcd=abs(m-x);
	for(i=1;i<n;i++)
	{
		scanf("%d",&x);
		gcd=ge(gcd,abs(x-m));
	}
	printf("%d",gcd);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
using namespace std;

signed main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    int ans=0;
    rep(i,n){
        if(a[i]==a[i+1]){
            ans++;
            i++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef long long LL;
//-------------------------------------------------------------------LYYY↓
namespace LYYY{
	int read()
	{
		int s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	void write(int x)
	{
		if(x>=10) write(x/10);
		putchar(x%10+48);
	}
}using namespace LYYY;
//-------------------------------------------------------------------bianliang↓
const int mod=998244353;
const int maxn=333333;
char ss[maxn];
int ID[222][222];
//-------------------------------------------------------------------hanshu↓
//-------------------------------------------------------------------main()↓
int main()
{
	ID['R']['G']=ID['G']['R']='B';
	ID['R']['B']=ID['B']['R']='G';
	ID['B']['G']=ID['G']['B']='R';
	int N=read();
	scanf("%s",ss+1);
	LL ans=1;
	for(int i=1;i<=N;++i) ans=ans*i%mod;
	N*=3;
	pii stk1=mp(0,0),stk2=mp(0,0);
	for(int i=1;i<=N;++i)
	{
		if(stk2.second&&stk2.first==ss[i]) ans=ans*(stk2.second--)%mod;
		else if(stk1.second&&stk1.first!=ss[i]) stk2.first=ID[stk1.first][ss[i]],++stk2.second,ans=ans*(stk1.second--)%mod;
		else stk1.first=ss[i],++stk1.second;
	}
	write(ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
int main() {
    int n, h, c=0;
    P p[200000];
    cin>>n>>h;
    for(int i=0;i<n;i++){
        int a, b;
        cin>>a>>b;
        p[i*2]=P(a, 0);
        p[i*2+1]=P(b, 1);
    }
    sort(p, p+n*2, greater<P>());
    for(int i=0;i<n*2;i++){
        int a=p[i].first;
        if(p[i].second==1){
            h-=a;
            c++;
            if(h<=0)break;
        }else{
            c+=(h+a-1)/a;
            break;
        }
    }
    cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 1920