akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front

// #define fisier 1

using namespace std;

typedef long long ll;

const int mod = 1000000007;
const double dancila = 3.14159265359; // PI 
const double eps = 1e-9;

string s, t;
int dp[3002][3002];
int prv[3002][3002];
void solve(int a, int b)
{
	if(a == 0 && b == 0)
		return;
	if(prv[a][b] == 1)
		solve(a-1, b);
	if(prv[a][b] == 2)
		solve(a, b-1);
	if(prv[a][b] == 3)
	{
		solve(a-1, b-1);
		cout << s[a];
	}
}
int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	cin >> s;
	cin >> t;
	int n = s.size(); 
	int m = t.size();
	s = ' ' + s;
	t = ' ' + t;
	for(int i = 0; i <= n; ++i)
		for(int j = 0; j <= m; ++j)
		{
			if(i+1 <= n && dp[i][j] >= dp[i+1][j])
			{
				dp[i+1][j] = dp[i][j];
				prv[i+1][j] = 1;
			}
			if(j+1 <= m && dp[i][j] >= dp[i][j+1])
			{
				dp[i][j+1] = dp[i][j];
				prv[i][j+1] = 2;
			}
			if(i+1 <= n && j+1 <= m && (s[i+1] == t[j+1]) && dp[i][j] >= dp[i+1][j+1])
			{
				dp[i+1][j+1] = dp[i][j] + 1;
				prv[i+1][j+1] = 3;
			}
		}
	solve(n, m);
    return 0;
}


Measured memory_bytes: 70912
#pragma warning(disable:4996)
#define loop(i,start,stop) for(int i = start; i < stop; i++)
#define rloop(j,start,stop) for(int j = start; j >= stop; j--)
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;

int A, B;



bool NOTprime[100005];
bool isOK[100005];
int bucket[320];

void eratos() {
        NOTprime[0] = true;
        NOTprime[1] = true;
        loop(i, 2, 318) {
                if (NOTprime[i]) continue;
                else {
                        for (int j = i + i; j < 100001; j += i) {
                                NOTprime[j] = true;
                        }
                }
        }
}


void calcOK() {
        int first, second;
        loop(i, 0, 100005) {
                if (i % 2 != 1) continue;

                first = i;
                second = (i + 1) / 2;
                if (!NOTprime[first] && !NOTprime[second]) {
                        isOK[i] = true;
                }
        }
}
int bucket_sz;
int num_buckets;
void preprocess() {
        bucket_sz = sqrt(100005);
        num_buckets = 100005 / bucket_sz;
        int start = 0;
        int cur = 0;
        loop(i, 0, num_buckets) {
                int sum = 0;
                loop(j, 0, bucket_sz) {
                        cur = bucket_sz * i + j;
                        if ((cur % 2 == 1) && isOK[cur]) {
                                sum++;
                        }
                }
                bucket[i] = sum;
        }
}


int T;
int main() {
 //      freopen("foo.txt", "r", stdin);
        eratos();
        calcOK();
        preprocess();
        cin >> T;
        int lo, hi; // both inclu

        while (T--) {
                int ans = 0;

                cin >> lo >> hi;
                int iter = lo;
                while (iter < hi && iter % bucket_sz != 0) {
                        if (iter % 2 == 1 && isOK[iter]) {
                                ans++;
                        }
                        iter++;
                }
                while (iter + bucket_sz <= hi) {
                        ans += bucket[iter / bucket_sz];
                        iter += bucket_sz;
                }
                while (iter <= hi) {
                        if (iter % 2 == 1 && isOK[iter]) {
                                ans++;
                        }
                        iter++;
                }
                printf("%d\n", ans);
        }
}

Measured memory_bytes: 896
n = int(input())
a = list(map(int, input().split()))
ans = 1
flag = -1
for i in range(n - 1):
    if flag == -1:
        flag = a[i] < a[i + 1]
        if a[i] == a[i + 1]:
            flag = 2
    elif flag == 1:
        if a[i] > a[i + 1]:
            flag = -1
            ans += 1
    elif flag == 0:
        if a[i] < a[i + 1]:
            flag = -1
            ans += 1
    else:
        if a[i] < a[i + 1]:
            flag = 1
        elif a[i] > a[i + 1]:
            flag = 0
print(ans)

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

int main(){
    int h,w,m;
    cin >> h >> w >> m;
    vi tate_count(h,0);
    vi yoko_count(w,0);
    vector<pair<int,int>> m_save;
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        tate_count[a]++;
        yoko_count[b]++;
        pair<int,int> kani=make_pair(a,b);
        m_save.push_back(kani);
    }
    int maxi_t=0;
    for(int i=0;i<h;i++){
        maxi_t=max(maxi_t,tate_count[i]);
    }
    int maxi_y=0;
    for(int i=0;i<w;i++){
        maxi_y=max(maxi_y,yoko_count[i]);
    }
    int ans=maxi_y+maxi_t;

    map<int,int> tate,yoko;
    ll tc=0,yc=0;
    for(int i=0;i<h;i++){
        if(maxi_t==tate_count[i]){
            tate[i]++;
            tc++;
        }
    }
    for(int i=0;i<w;i++){
        if(maxi_y==yoko_count[i]){
            yoko[i]++;
            yc++;
        }
    }
    ll count=0;
    for(int i=0;i<m;i++){
        if(tate[m_save[i].first]==1&&yoko[m_save[i].second]==1){
            count++;
        }
    }
    if(count>=yc*tc) ans--;

    cout << ans << endl;
}

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


int num_sum(int x){
    int sum = 0, tmp = 0;
    while (1)
    {
        if (x >= 10)
        {
            sum += (x % 10);
            x /= 10;
        }
        else
        {
            tmp += x;
            break;
        }
    }
    return sum + tmp;
}


int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int sum = 0, tmp=0, x=0, count=0;

    for (int i = 1; i <= N;i++){
        if(num_sum(i)>=A && num_sum(i)<=B)
            //cout<<i << " " << num_sum(i)<<endl;
            count += i;
    }
    cout << count << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

int main()
{
    string S;
    cin>>S;
    int long long K,ans=0;
    cin>>K;
    for(int i=0;i<S.size();i++){
        if(S.at(i)=='1'){
            if(i+1==K){
                cout<<1<<endl;
                exit(0);
            }
            continue;
        }
        cout<<S.at(i)<<endl;
        exit(0);
    }
    cout<<1<<endl;
}

Measured memory_bytes: 3600
N = int(input())
word_list = [input() for i in range(N)]

check_list = []
for i in range(N):
    if word_list[i] in word_list[0:i] or word_list[i] in word_list[i + 1:]:
        print('No')
        break
    else:
        for i in range(N - 1):
            if word_list[i][-1] == word_list[i + 1][0]:
                pass
            else:
                print('No')
                break
        else:
            continue #外側のループに対するもので，以降の処理をスキップする
    break
else:
    print('Yes')



Measured memory_bytes: 3060
x,y = map(int,input().split())

a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

def group(n):
    if n in a:
        return a
    elif n in b:
        return b
    else:
        return c
print('Yes') if group(x) == group(y) else print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

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

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

typedef long long ll;

using namespace std;
vector<bool>ok(500000,0),fl(500000,0);
vector<int>memo(500000,-1);
int inf=1e9+7,res=0;

int dfs(int node,int sl,int tl)
{
  if(fl[node]==1&&memo[node]==-1)return inf;
  if(memo[node]>-1)return memo[node];
  fl[node]=1;
  int r=0;
  if(ok[node])r=dfs((node+tl)%sl,sl,tl)+1;
  else r=0;
  return memo[node]=r;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string t,s;
  cin>>s;
  cin>>t;
  int l=t.length(),sl=s.length();
  vector<int>A(l+1);
  A[0] = -1;
  int j = -1;
  for (int i = 0; i < t.size(); i++)
  {
    while (j >= 0 && t[i] != t[j]) j = A[j];
    j++;
    if (j>0&&t[i+1] == t[j]) A[i+1] = A[j];else A[i+1] = j;
  }
  rep(i,l+1)A[i]=i-A[i];
  int m=0,i=0;
  while(m<sl)
  {
    if(t[i]==s[(m+i)%sl])
    {
      i++;
      if(i==l)ok[m]=1;
    }
    else
    {
      m+=A[i];
      if(i>0)i=i-A[i];
    }

  }
//  rep(i,sl)cout<<ok[i]<<endl;

  rep(i,sl){if(res>=inf)break;dfs(i,sl,l);}
  rep(i,sl)chmax(res,memo[i]);
  //rep(i,sl)cout<<memo[i]<<endl
  if(res>=inf)res=-1;
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 13596
#include<stdio.h>
#include<string.h>

int main(){
  char str[100];
  int i,j,k=0;
  
  scanf("%s",str);
  
  if(str[0] != 'A'){
    puts("WA");
    return 0;
  }
  
  if(!(str[1]>=97&&str[1]<=122)){
    puts("WA");
    return 0;
  }
  
  for(i=2;i<strlen(str)-1;i++){
    if(str[i] == 'C'){
      k++;
      continue;
    }
    if(!(str[i]>=97&&str[i]<=122)){
      puts("WA");
      return 0;
    }
  }
  
  for(i=strlen(str)-1;i < strlen(str);i++){
    if(!(str[i]>=97&&str[i]<=122)){
    puts("WA");
    return 0;
  }
  }
  
  if(k == 1){
    puts("AC");
    return 0;
  }
  
  puts("WA");
  return 0;
}
    
    


Measured memory_bytes: 128
/**
 * auther: moririn_cocoa
 */

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second

int main (void) {
  
  int S;
  int W;
  
  cin >> S;
  cin >> W;
  
  if ( S <= W ) {
    
    cout << "unsafe" << endl;
  }
  
  else if ( S > W ) {
    
    cout << "safe" << endl;
  }
  
  return 0;
}




Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a == b) {
			System.out.println(c);
		} else if(b == c) {
			System.out.println(a);
		} else {
			System.out.println(b);
		}
	}
}


Measured memory_bytes: 22228
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;             
int main()
{
    int a[10];
    scanf("%d %d %d",&a[1],&a[2],&a[3]);
    sort(a+1,a+4);
    printf("%d",a[3]*10+a[2]+a[1]);
    return 0;
}

Measured memory_bytes: 256
using System;

public class Vector
{
    public double x { get; set; }
    public double y { get; set; }
}

public class hello
{
    public static void Main()
    {
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var s = Array.ConvertAll(line.Trim().Split(' '), double.Parse);
            var a = new Vector { x = s[0], y = s[1] };
            var b = new Vector { x = s[2], y = s[3] };
            var c = new Vector { x = s[4], y = s[5] };
            var p = new Vector { x = s[6], y = s[7] };
            if (judgeTri(a, b, c, p) == 0) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }
    public static int judgeTri(Vector a, Vector b,Vector c ,Vector p)
    {
        var ab = subVector(b, a);
        var bp = subVector(p, b);
        var bc = subVector(c, b);
        var cp = subVector(p, c);
        var ca = subVector(a, c);
        var ap = subVector(p, a);
        var c1 = ab.x * bp.y - ab.y * bp.x;
        var c2 = bc.x * cp.y - bc.y * cp.x;
        var c3 = ca.x * ap.y - ca.y * ap.x;
        if ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0)) return 0; // inside
        else return 1;  // outside
    }
    public static Vector subVector (Vector a , Vector b)
    {
        var c = new Vector();
        c.x = a.x - b.x;
        c.y = a.y - b.y;
        return c;
    }
}

Measured memory_bytes: 9256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

static class Program
{
    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

    private static int Solve(int N, int W, int[] w, int[] v, int w0)
    {
        int[][] dp1 = new int[N + 1][];
        for (int i = 0; i <= N; ++i) { dp1[i] = new int[300]; }

        for (int i = 0; i < N; ++i)
        {
            int[][] dp2 = new int[N + 1][];
            for (int j = 0; j <= N; ++j) { dp2[j] = new int[300]; }
            for (int j = 0; j <= N; ++j)
            {
                for (int k = 0; k < 300; ++k)
                {
                    int J = j + 1;
                    int K = k + w[i];
                    dp2[j][k] = Math.Max(dp1[j][k], dp2[j][k]);
                    if (J <= N && K < 300) { dp2[J][K] = Math.Max(dp1[j][k] + v[i], dp2[J][K]); }
                }
            }
            dp1 = dp2;
        }
        int max = 0;
        for (int i = 0; i <= N; ++i)
        {
            for (int j = 0; j < 300; ++j)
            {
                if (W >= Math.BigMul(i, w0) + j) { max = Math.Max(dp1[i][j], max); }
            }
        }
        return max;
    }
    static void Main(string[] args)
    {
        int[] args1 = ReadInts();
        int N = args1[0];
        int W = args1[1];
        int[] w = new int[N];
        int[] v = new int[N];
        int w0 = 0;
        for (int i = 0; i < N; ++i)
        {
            int[] args2 = ReadInts();
            if (i == 0) { w0 = args2[0]; }
            w[i] = (i > 0) ? args2[0] - w0 : 0;
            v[i] = args2[1];
        }
        Console.WriteLine(Solve(N, W, w, v, w0));
    }
}


Measured memory_bytes: 16072
#include <cstdio>
#include <cstdlib>
int greater(const void* a,const void* b){
    return *((int*)a)>*((int*)b);
}
int main(){
    int n,k,arr[101];
    scanf(" %d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf(" %d",arr+i);
    }
    qsort(arr,n,sizeof(int),greater);
    for(int i=0;i<n;i++){
        k = k-arr[i];
        if(k==0){
            printf("%d",i+1);
            return 0;
        }else if(k<0){
            printf("%d",i);
            return 0;
        }
    }
    printf("%d",n-1);
    return 0;
}


Measured memory_bytes: 128
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    s=readline().strip()
    
    res=0
    count0=0
    count1=0
    i=0
    l=len(s)
    while i<l:
        if i==l-1:
            if s[i]=="0":
                count0+=1
            else:
                count1+=1
            i+=1
        elif s[i]==s[i+1]:
            if s[i]=="0":
                count0+=1
            else:
                count1+=1
            i+=1
        else:
            res+=2
            i+=2

    print(res+min(count0,count1)*2)

if __name__=="__main__":
    main()

Measured memory_bytes: 3188
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int N;
int d[50];

int main(){
    cin>>N;
    rep(i,N) cin>>d[i];

    int ans=0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            ans+=d[i]*d[j];
        }
    }

    cout<<ans;
}

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

int main() {
 int n; cin >> n;
 cout << n*n*n << endl;
}


Measured memory_bytes: 256
package main
import (
    "fmt"
    "os"
    "bufio"
    "strconv"
    "reflect"
)
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main(){
    sc.Split(bufio.ScanWords)
    defer out.Flush()   // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	n := nextInt()
	tempt, tempx, tempy := 0, 0, 0
	cnt := 0
	for i:=0; i<n; i++{
		t, x, y := nextInt(), nextInt(), nextInt()
		target := t-tempt
		tempt = t
		targetx, targety := AbsInt(x-tempx), AbsInt(y-tempy)
		tempx, tempy  = x, y
		if target>=(targetx+targety) && (  (target%2==0 && (targetx+targety)%2==0) || (target%2==1 && (targetx+targety)%2==1) ){
			cnt++
		}else{
			break
		}
	}
	if cnt==n{
		fmt.Fprintln(out, "Yes")
	}else{
		fmt.Fprintln(out, "No")
	}
}

func next() string{
    sc.Scan()
    return sc.Text()
}

func nextInt() int{
    a, _ := strconv.Atoi(next())
    return a
}

func nextFloat64() float64{
    a, _ := strconv.ParseFloat(next(), 64)
    return a
}

func nextInts(n int) []int{
    ret := make([]int, n)
    for i:=0; i<n; i++{
        ret[i] = nextInt()
    }
    return ret
}
func nextFloats(n int) []float64{
    ret := make([]float64, n)
    for i:=0; i<n; i++{
        ret[i] = nextFloat64()
    }
    return ret
}
func nextStrings(n int) []string{
    ret := make([]string, n)
    for i:=0; i<n; i++{
        ret[i] = next()
    }
    return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool{
    for _, v := range arr{
        if v==target{
            return true
        }
    }
    return false
}

func PrintOut(src interface{}, joinner string){
    switch reflect.TypeOf(src).Kind(){
        case reflect.Slice:
            s := reflect.ValueOf(src)
            for idx := 0; idx<s.Len(); idx++{
                fmt.Fprintf(out, "%v", s.Index(idx))
                if idx<s.Len()-1{
                    fmt.Fprintf(out, "%s", joinner)
                }else{
                    fmt.Fprintln(out)
                }
            }
        default:
            fmt.Fprintln(out, "fuck")
    }
}

// float64だしmathインポートするのめんどくさいのでintのabs
func AbsInt(n int)int{
	if n>=0{
		return n
	}
	return n*-1
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int l=a+b,r=c+d;
	if(l>r)
		cout<<"Left\n";
	else if(l==r)
		cout<<"Balanced\n";
	else
		cout<<"Right\n";
	return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int x = sc.NextInt();
        int a = sc.NextInt();
        int b = sc.NextInt();

        string answer = "";
        if (b - a <= 0)
        {
            answer = "delicious";
        }
        else if (b - a <= x)
        {
            answer = "safe";
        }
        else
        {
            answer = "dangerous";
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
struct xy{
int x;int y;
};
int main(){
int n,m;cin >> n >> m;
vector<bool>vis(n,0);
queue<xy>q;
vector<vector<int>> adj(n);
vector<int>ans(n);
for(int i = 0;i<m;i++){
    int v,u;cin >> v >> u;
    v--;u--;
    adj[v].push_back(u);
    adj[u].push_back(v);
}
for(int i = 0;i<adj[0].size();i++) q.push({adj[0][i],0});
//vis[0] = 1;
while(!q.empty()){
    xy temp = q.front();q.pop();
    int v = temp.x;int u  = temp.y;
    if(vis[v]) continue;
    vis[v] = 1;
    ans[v] = u;
    for(int i = 0;i<adj[v].size();i++) q.push({adj[v][i],v});
}
cout <<"Yes"<<endl;
for(int i = 1;i<n;i++) cout << ans[i]+1<<endl;
return 0;
}


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

bool isBomb( const vector<string>& v, int i, int j, int h, int w ) {
	return i >= 0 && j >= 0 && i < h && j < w && v[i][j] == '#';
}

int main() {
	int H, W;
	cin >> H >> W;

	vector<string> S;

	for( int i = 0; i < H; ++i ) {
		string s;
		cin >> s;

		S.push_back( s );
	}

	for( int i = 0; i < H; ++i ) {
		for( int j = 0; j < W; ++j ) {
			if( S[i][j] != '.' ) {
				continue;
			}

			char bomb = 0;

			bomb += isBomb( S, i-1, j-1, H, W );
			bomb += isBomb( S, i-1, j,   H, W );
			bomb += isBomb( S, i-1, j+1, H, W );
			bomb += isBomb( S, i,   j-1, H, W );
			bomb += isBomb( S, i,   j+1, H, W );
			bomb += isBomb( S, i+1, j-1, H, W );
			bomb += isBomb( S, i+1, j,   H, W );
			bomb += isBomb( S, i+1, j+1, H, W );

			S[i][j] = '0' + bomb;
		}

		cout << S[i] << endl;
	}
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];

    }
    sort(all(v));

    vector<P> q(m);
    for(int i = 0; i < m; ++i) {
        cin >> q[i].S >> q[i].F;
        
    }
    sort(all(q), greater<P>());

    int pos = 0;
    int qpos = 0;
    bool f = true;
    while(pos < n && qpos < m & f) {
        while(pos < n && q[qpos].S > 0) {
            if(v[pos] >= q[qpos].F) {
                ++pos;
                f = false;
                break;
            }
            v[pos] = q[qpos].F;
            ++pos;
            --q[qpos].S;

        }
        ++qpos;
    }
    
    LL res = 0;
    for(int i = 0; i < n; ++i) {
        res += v[i];

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


Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

int main(){
    int n, k; cin >> n >> k;
    k--;
    string s;
    cin >> s;
    s[k] = s[k] - ('A' - 'a');
    cout << s << endl;
    return 0;

}




Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;

int main(){
    int R,G,B,N,ans=0;
    cin >> R >> G >> B >> N;
    for(int i=0; i<=N; i++){
        for(int j=0; j<=N; j++){
            if(R*i+G*j>N) break;
            if((N-(i*R+j*G))%B==0){
            ans+=1;
            }
        }
    }
    cout << ans << endl;
}

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

//definition
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define MAX 200005

// #define LOCAL
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;

    vector<int> l(2 * n);
    rep(i, 0, 2 * n)
    {
        cin >> l[i];
    }
    sort(all(l));

    int cnt = 0;
    rep(i, 0, n)
    {
        cnt += min(l[2 * i], l[2 * i + 1]);
    }
    cout << cnt << endl;

#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <set>
#include <cmath>
#include <math.h>
#include <sstream> 
 
using namespace std;

int main(){
    long long int n,wa=0;
    cin>>n;
    long long int t=n;
    int keta=0;   
    while(t!=0){
        t/=10;
        keta++;
    }
    
    int k=10;
    t=n;
    for(int i=0;i<keta;i++){
        wa+=t%k;
        t/=10;
    }
    
    if(n%wa==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

int binarySearch(int S[],int n,int T){
  int l=0,m;
  int r=n;
  while(l<r){
    m=(l+r)/2;
    if(S[m]==T)return 1;
    else if(T<S[m])r=m;
    else l=m+1;
  }
  return 0;
}

int main(){
  int i,c=0;
  int n,q,T;
  int *S;

  scanf("%d",&n);
  S = (int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T);
    if(binarySearch(S,n,T)==1)c++;
  }
printf("%d\n",c);

return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    bool ok = false;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int id = 0;
    if(n*k>=1e8){
        for (int i = 0; i < n; i++)
        {
            cout << n << " ";
        }
        cout << endl;
        return 0;
    }

  /*  if( k >= (1LL<<(id+1) )){
        for (int i = 0; i < n; i++)
        {
            cout << n << " ";
        }
        cout << endl;
        return 0;
    }*/

    for (int i = 0; i < k; i++)
    {
        vector<int> rui(n + 2,0);
        for (int i = 0; i < n; i++)
        {
           
            rui[max(i + 1 - a[i], 1LL)]++;
            rui[min(n+1 , a[i] +i+1 +1)]--;
            
            
        }
       // show(rui);
        for (int i = 0; i <=n; i++)
        {
            rui[i + 1] += rui[i];
        }
        
        for (int i = 0; i < n; i++)
        {
            a[i] = rui[i + 1];
        }
        //show(a);
    }
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;

    return 0;
}

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

int main(void){
    int X;
    cin>>X;
    int ans=-1;
    vector<int> expo;
    for(int i=1;i<=31;i++){
        int result=1;
        for(int j=2;j<=10;j++){
            if(result>1000) break;
            expo.push_back(pow(i,j)); 
        }
    }
    for(int i=0;i<expo.size();i++){
        if(expo[i]<=X){
            ans=max(ans,expo[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int X = scan.nextInt();
        int[] L = new int[N];
        for (int i = 0; i < N; i++) L[i] = scan.nextInt();
        int ans = 1, count = 0;
        for (int i = 0; i < N; i++) {
            count += L[i];
            if (count <= X) ++ans;
        }
        System.out.println(ans);
    }
}

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

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

const int mx=1e5+5;

int dp[mx];
vector<int>g[mx];

int path(int u)
{
	if(dp[u]) return dp[u];
	if(g[u].size()==0) return dp[u]=0;
	for(auto it: g[u])
	{
		dp[u]=max(dp[u],1+path(it));
	}
	return dp[u];
}		

void solve()
{
	int n,m;
	cin>>n>>m;
	
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
	}
	
	int ans=0;
	
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,path(i));
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
							                                				
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	
	return 0;
}

Measured memory_bytes: 7424
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
ulong MIDDLE = 100_000;
alias Pair = Tuple!(long, "flag", long, "num");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long h, w;
    scan(h, w);
    long min_dif = INF;
    foreach(i; iota(1, w))
    {
        long split = h * i, rest = h * (w - i);
        long middle1 = h / 2, middle2 = (w - i) / 2;
        long right = (w - i) * middle1, left = (w - i) * (h - middle1);
        long upper = h * middle2, lower = h * (w - i - middle2);
        auto dif1 = only(split, right, left).reduce!(max) - only(split, right, left).reduce!(min); 
        auto dif2 = only(split, upper, lower).reduce!(max) - only(split, upper, lower).reduce!(min);
        min_dif = only(dif1, dif2, min_dif).reduce!(min);
    }
    foreach(i; iota(1, h))
    {
        long split = w * i, rest = w * (h - i);
        long middle1 = w / 2, middle2 = (h - i) / 2;
        long right = (h - i) * middle1, left = (h - i) * (w - middle1);
        long upper = w * middle2, lower = w * (h - i - middle2);
        auto dif1 = only(split, right, left).reduce!(max) - only(split, right, left).reduce!(min); 
        auto dif2 = only(split, upper, lower).reduce!(max) - only(split, upper, lower).reduce!(min);
        min_dif = only(dif1, dif2, min_dif).reduce!(min);
    }
    min_dif.writeln();
}


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

using namespace std;

int main(){
	long long n;
	cin >> n;
	long long min = n;
	//nが何かける何かを求める(このとき二つの数の和を最小になるようにする)。x-1 + y-1が答え
	for(long long i = 1; i < (long long)(sqrt(n)+0.9)+1; i++){
		long long a = i;
		if( n % a != 0) continue;
		long long b = n/a;
		if(a+b-2 < min){
			min = a+b-2;
		}
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 3576
#include <stdio.h>
#include <stdlib.h>
             
int main(void){
int N;
int K;
int min;
scanf("%d",&N);
scanf("%d",&K);
int i = K;
int c = 1;
while(i < N){
i = i+ (K-1);
c = c + 1;
}
printf("%d",c);
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long int dp[1001][101][10];
long int dfs(int s,int p,int d){
  if(!s&&!d)return 1;
  if(s<0||d<0||p<0)return 0;
  if(dp[s][p][d]!=-1)return dp[s][p][d];
  return dp[s][p][d]=dfs(s-p,p-1,d-1)+dfs(s,p-1,d);
}
int main(){
  int d,s;
  memset(dp,-1,sizeof(dp));
  while(cin>>d>>s,d)cout<<dfs(s,100,d)<<endl;
}

Measured memory_bytes: 10924
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


void printv(vector<int> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << " ";
	}
	cout << endl;
}
int main() {
	
	while(1) {
		int n,r; cin >> n >> r;
		if(n + r == 0) {
			break;
		}

		vector<int> H(n,0);
		for (int i = 0; i < n; i++) {
			H[i] = n - i;
		}

		for (int j = 0; j < r; j++) {
			vector<int> a;
			vector<int> b;
			int p,c; cin >> p >> c;
			for (int i = 0; i < p-1; i++) {
				a.push_back(H[i]);
			}
			//cout << "a" << endl;
			//printv(a);
			for (int i = p - 1; i < p - 1 + c; i++) {
				b.push_back(H[i]);
			}
			//cout << "b" << endl;
			//printv(b);
		
			for (int i = 0; i < c; i++) {
				H[i] = b[i];
			}
			//cout << "H1" << endl;
			//printv(H);
			for (int i = 0; i < p - 1; i++) {
				H[c + i] = a[i];
			}
			//cout << "H2" << endl;
			//printv(H);
		}
		cout << H[0] << endl;
	}


	return 0;
}



Measured memory_bytes: 3016
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,m;
  cin >> n;
  m=n;

  vec v;

  ll c=1;
  while(m!=0){
    ll a=(ll) pow(2,c);
    if(abs(m)%a!=0){
      v.push_back(1);
      if(c&1){
        m-=(ll) pow(2,c-1);
      }
      else{
        m+=(ll) pow(2,c-1);
      }
    }
    else{
      v.push_back(0);
    }
    c++;
  }

  if(v.size()==0)v.push_back(0);

  reverse(v.begin(),v.end());

  for(ll i=0;i<v.size();i++)cout << v[i] ;
  cout << endl;

}

Measured memory_bytes: 3972
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
const ll inf = 1e18 + 1;
const ll limit = 1e9;

int main() {
    int n; cin >> n;
    vector<vector<pair<int,int>>> v(n);
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        for (int j = 0; j < a; j++) {
            int x,y; cin >> x >> y; x--;
            v[i].emplace_back(make_pair(x, y));
        }
    }
    int ans = 0;
    for (ll i = 1; i < (1 << n); i++) {
        bool flag = false;
        int res = 0;
        for (int j = 0; j < n; j++) {
            if (i >> j & 1) {
                for (auto p : v[j]) {
                    if (p.second) {
                        if (i >> p.first & p.second) ;
                        else {
                            flag = true;
                            break;
                        }
                    } else {
                        if ((~i) >> p.first & 1) ;
                        else {
                            flag = true;
                            break;
                        }
                    }
                }    
                if (flag) break;
                res++;
            }
        }    
        if (!flag) ans = max(ans,res);
    }
    cout << ans << "\n";
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);

    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

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

    long long Ans = 1;
  
  if(A.at(0) == 0) cout << 0 << endl;
  else{
    
    double D = 0;
    
    for(int i = 0; i < N; i++){
    	D += log10(A.at(i));
    }
    
    if(D<=18){

    for(int i = 0; i < N; i++){
        Ans *= A.at(i);
    }
      
    if(Ans <= 1000000000000000000){

    cout << Ans << endl;
      
    }else cout << -1 << endl;
      
    }else cout << -1 << endl;

  }

}


Measured memory_bytes: 4148
// finish date: 2018/12/15

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N, M;
    cin >> N >> M;
    int ans = 1;
    FOR(i, 1, sqrt(M) + 1) {
        if (M % i == 0) {
            if (i >= N) ans = max(ans, M / i);
            else if (M / i >= N) ans = max(ans, i);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import queue

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]

T = {}
for a, b in ab:
  if a not in T:
    T[a] = [b]
  else:
    T[a].append(b)
  if b not in T:
    T[b] = [a]
  else:
    T[b].append(a)

R = [-1] * (N + 1)
q = queue.Queue()
put = q.put
get = q.get
put(1)
R[1] = 1
while not q.empty(): 
  t = get()
  if t in T:
    for i in T[t]:
      if R[i] == -1:
        R[i] = R[t] + 1
        put(i)

L = [N]
t = N
while t != 1:
  for i in T[t]:
    if R[i] < R[t]:
      L.append(i)
      t = i
      break

k = L[len(L) // 2 - 1]

cnt = 1
put(k)
while not q.empty(): 
  t = get()
  if t in T:
    for i in T[t]:
      if R[i] > R[t]:
        cnt += 1
        put(i)

Ans = ["Fennec", "Snuke"]
print(Ans[cnt >= N - cnt])



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

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

using namespace std;

int main(){
	int n,l; cin>>n>>l;
	string s[100];
	rep(i,n) cin>>s[i];

	sort(s,s+n);

	cout<<accumulate(s,s+n,""s)<<'\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int dp[100][200005];


int main(){
  ll N, K;
  cin >> N >> K;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    a--;
    v.push_back(a);
  }

  rep(i,N) dp[0][i] = v[i];

  REP(i,1,100){
    rep(j,N){
      dp[i][j] = dp[i-1][dp[i-1][j]];
    }
  }

  ll ret = 0;
  for(ll i=61; i>=0; i--){
    if((K>>i)&1){
      ret = dp[i][ret];
    }
  }

  cout << ret+1 << endl;
  
  return 0;
}



Measured memory_bytes: 82192
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1e5+10;
int n,a[maxn];

int main(){
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];

    int cnt = 0;
    LL sum = 0;
    int mx = 1e9+10;
    for (int i=1;i<=n;i++){
        if (a[i] < 0) cnt++, a[i] = -a[i];
        if (a[i] < mx) mx = a[i];
        sum += a[i];
    }
    if (cnt % 2 == 1){
        cout<< sum - mx - mx<<endl;
    }else cout<< sum <<endl;
    return 0;
}


Measured memory_bytes: 640
def a_frog1():
    N = int(input())
    h = list(map(int, input().split()))

    c = [0] * N
    c[1] = abs(h[1] - h[0])
    for i in range(2, N):
        c1 = abs(h[i] - h[i-1]) + c[i-1]
        c2 = abs(h[i] - h[i-2]) + c[i-2]
        c[i] = min(c1, c2)
    print(c[-1])


##########
if __name__ == "__main__":
    a_frog1()


Measured memory_bytes: 13928
import java.io.*; 
import java.util.*; 

public class Main{ 
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}

	static ArrayList<Integer>[] graph;
	static int[] dp;

	static int dfs(int u){
		if(dp[u]!=0)
			return dp[u];

		int vl = 0;
		ArrayList<Integer> curlist = (ArrayList<Integer>) graph[u];
		for(int v: curlist){
			vl = Math.max(vl, dfs(v));
		}

		return dp[u] = vl+1;
	}

	public static void main(String[] args) 
	{ 
        FastReader sc = new FastReader(); 
        //PrintWriter out = new PrintWriter(System.out); 

        int n = sc.nextInt();
        int m = sc.nextInt();
        graph = new ArrayList[n+1];
        dp = new int[n+1];

        for(int i=0;i<=n;i++)
        	graph[i] = new ArrayList<Integer>();

        while(m-->0){
        	int a = sc.nextInt();
        	int b = sc.nextInt();
        	graph[a].add(b);
        }

        for(int i=1;i<=n;i++)
        	dfs(i);

        int ans = 0;
        for(int i=1;i<=n;i++)
        	ans = Math.max(ans, dp[i]);

        System.out.println(ans-1);
        
	}
}


Measured memory_bytes: 59248
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let (N, M, P) = get!(usize, usize, i64);
    let ABC = get!(usize, usize, i64; M);

    let INF = 1000000000000;
    let mut dp = vec!(INF; N + 1);
    let mut used = vec!(false; N + 1);
    dp[1] = 0;
    used[1] = true;
    for k in 0..2*N {
        for i in 0..M {
            let (a, b, c) = ABC[i];
            let w = P - c;
            if used[a] && dp[b] > dp[a] + w {
                dp[b] = dp[a] + w;
                used[b] = true;
                if k >= N - 1 {
                    dp[b] = -INF;
                }
            }
        }
    }
    let mut ans = cmp::max(0, -dp[N]);
    if ans == INF {
        ans = -1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>
#include<queue>
#include<bitset>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>A(N);

	for (int i = 0; i < N; ++i) {
		cin >> A.at(i);
	}

	bool ans = true;

	for (int i = 0; i < N; ++i) {
		if (A.at(i) % 2 == 0) {
			if (!(A.at(i) % 3 == 0 || A.at(i) % 5 == 0)) {
				ans = false;
				break;
			}
		}
	}

	if (ans) {
		cout << "APPROVED" << endl;
	}
	else cout << "DENIED" << endl;

}

Measured memory_bytes: 3636
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007



int main() {
  int W, H, N;
  cin >> W >> H >> N;
  int minx = 0, maxx = W, miny = 0 , maxy = H;
  rep(i, N) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      minx = max(minx, x);
    }
    else if (a == 2) {
      maxx = min(maxx, x);
    }
    else if (a == 3) {
      miny = max(miny, y);
    }
    else {
      maxy = min(maxy, y);
    }
  }

  int lenx = max(0, maxx - minx);
  int leny = max(0, maxy - miny);

  cout << lenx*leny << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 22000;
const int M = 1e6+5;
const int INF = 0x3f3f3f3f;

map <string,int> p; 

int main()
{     
    int n,Max = 0;
    string s;
    scanf("%d",&n);
    for(int i = 0;i < n;++i){
    	cin >> s;
    	p[s]++;
    	Max = max(Max,p[s]);
	}
	
	map <string,int> :: iterator it;
	for(it = p.begin();it != p.end();it++){
		if(it -> second == Max) cout << it -> first << "\n";
	}
    return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;

int main(){
    int n;
    cin>>n;
    set<string> st;
    rep(i,n){
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;
    return 0;
}

Measured memory_bytes: 19216