akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (n > m)
    swap(n, m);
  if (n == 1)
    return 0 * printf("%d\n", (m == 1 ? 1 : m - 2));
  if (n == 2)
    return 0 * puts("0");
  printf("%lld\n", 1LL * (n - 2) * (m - 2));
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
typedef long double ld;

int K;
vector<int> V;
priority_queue<int, vector<int>, greater<int> > Q;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> K;
	for (int i = 1; i <= 9; i++) Q.emplace(i);
	while (K--) {
		int x = Q.top();
		Q.pop();
		V.pb(x);
		for (int i = max(0ll, (x % 10) - 1); i <= min(9ll, (x % 10) + 1); i++)
			Q.emplace(x * 10 + i);
	}
	cout << V.back() << '\n';
}


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

int main() {
  string s;
  cin>>s;
  int a;
  if(s=="SUN")a=7;
  else if(s=="MON")a=6;
  else if(s=="TUE")a=5;
  else if(s=="WED")a=4;
  else if(s=="THU")a=3;
  else if(s=="FRI")a=2;
  else if(s=="SAT")a=1;
  cout<<a<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Scanner;

public class Main {
	public static final Scanner sc = new Scanner(System.in);
	public static final int Max = 1 << 15;
	public static final BitSet isPrime = new BitSet(Max);
	public static final ArrayList<Integer> primes = new ArrayList<Integer>();

	public static void main(String[] args) {
		// init
		isPrime.set(2, Max);
		for (int i = 2; i < Max; i++) {
			if (!isPrime.get(i)) continue;
			// i is prime
			//	if (i <= Max) primes.add(i);
			primes.add(i);
			for (int j = i * i; j < Max; j += i) {
				isPrime.clear(j);
			}
		}

		// main
		while (true) {
			final int in = sc.nextInt();
			if (in == 0) break;

			int ans = 0;
			for (Integer p : primes) {
				if (p > in / 2) break;
				final int re = in - p;
				//	if (primes.contains(remain)) ans++;
				if (isPrime.get(re)) ans++;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 19964
#include<iostream>
#include<stack>
#include<string>
#include<sstream>

using namespace std;

stack<int> Plus(stack<int> st)
{
	int a = st.top();
	st.pop();
	int b = st.top();
	st.pop();
	st.push(b + a);
	return st;
}

stack<int> Minus(stack<int> st)
{
	int a = st.top();
	st.pop();
	int b = st.top();
	st.pop();
	st.push(b - a);
	return st;
}

stack<int> Call(stack<int> st)
{
	int a = st.top();
	st.pop();
	int b = st.top();
	st.pop();
	st.push(b * a);
	return st;
}

stack<int> Judge(stack<int> st,string c)
{ 
	if(c == "+")     st = Plus(st);
	else if(c == "-")st = Minus(st);
	else if(c == "*")st = Call(st);
	return st;
}

int main()
{
	string element;
	stack<int> st;
	while(1){
		cin >> element;
		if(cin.good() == false)break;
		if(element == "+" || element == "-" || element == "*"){
			st = Judge(st,element);
		}
		else{
			stringstream ss;
			ss << element;
			int n;
			ss >> n;
			st.push(n);
		}
	} 
	cout << st.top() << endl;
}

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

using namespace std;

bool sosuu(long long int x){
    for(long long int i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return true;
}

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

    for(int i=2;ans.size()!=N;i++){
        if(sosuu(i)){
            if(i%5==1){
                ans.push_back(i);
            }
        }
    }

    for(int i=0;i<ans.size();i++){
        if(i==0){
            cout << ans[i];
        }else{
            cout << " " << ans[i];
        }
    }

    cout << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n, m;
  cin >> n >> m;

  ll bottom = 1, top = n;
  for (ll i = 0; i < m; ++i) {
    ll l, r;
    cin >> l >> r;

    if (bottom < l) bottom = l;
    if (top > r) top = r;
  }

  ll ans = max(top-bottom+1, ll(0));
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    if N%2:
        print(0)
    else:
        m = N//2
        ans = 0
        t = 5
        while m >= t:
            ans += m//t
            t *= 5
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61980
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
  int n, i;
  long long int la=2, lb=1, m;
  scanf("%d",&n);
  for(i=0;i<n-1;i++){
    m=lb; lb=la+lb; la=m;
  }
  printf("%lld\n",lb);
  return 0;
}


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

const int nax = 1e5 + 5;

vector<int> edges[nax];
int dist[nax];

int dfs(int u) {
	if (dist[u] != -1) return dist[u];
	dist[u] = 0;
	for (auto v : edges[u])
		dist[u] = max(dist[u], 1 + dfs(v));
	return dist[u];
}

int main() {
	memset(dist, -1, sizeof dist);
	int n, m; scanf("%d%d", &n, &m);

	while (m--) {
		int a, b; scanf("%d%d", &a, &b);
		edges[a].push_back(b);
	}

	int ans = 0;
	for (int i = 0; i <= n; i++)
		ans = max(ans, dfs(i));

	cout << ans;
}

Measured memory_bytes: 7424
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;

int modd=1e9+7;

int main(){
  int n,k; cin>>n>>k;
  long long ans[n+1][k+1];
  for(int i=0; i<=n; i++){
    ans[i][0]=1;
    for(int j=1; j<=k; j++) ans[i][j]=0;
  }

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

  int key;
  for(int i=1; i<n; i++){
    key=arr[i]; int j;
    for(j=i-1; j>=0; j--){
        if(arr[j]>arr[j+1]) arr[j+1]=arr[j];
        else { break; }
    }
    arr[j+1]=key;
  }

  int prer=0; int r;
  for(int i=1; i<=n; i++){
    r=arr[i-1];
    for(int j=1; j<=r; j++){ ans[i][j]+=ans[i][j-1]+ans[i-1][j]; ans[i][j]%=modd;  }
    prer=min(r+prer,k);
    for(int j=r+1; j<=prer; j++){ ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-r-1]; ans[i][j]=(ans[i][j]+modd)%modd; }

  }
  cout<<ans[n][k]<<endl;
}


Measured memory_bytes: 79104
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll x,y,a,b,c,A[maxn],B[maxn],C[maxn],ans;
multiset <ll> s;
multiset <ll>::iterator it;

inline bool cmp(ll a,ll b){return a>b;}

int main()
{
	cin>>x>>y>>a>>b>>c;
	for(int i=1;i<=a;i++) A[i]=read();
	for(int i=1;i<=b;i++) B[i]=read();
	for(int i=1;i<=c;i++) C[i]=read();
	sort(A+1,A+a+1,cmp); sort(B+1,B+b+1,cmp); sort(C+1,C+c+1,cmp);
	for(int i=1;i<=x;i++) s.insert(A[i]),ans+=A[i];
	for(int i=1;i<=y;i++) s.insert(B[i]),ans+=B[i];
	for(int i=1;i<=c;i++)
	{
		it=s.begin();
		if(C[i]>*it)
		{
			ans-=*it; ans+=C[i];
			s.erase(it); s.insert(C[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

public class Main {

    public static void main(String[] argv) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        Stack<String> stack = new Stack<String>();
        while (true) {
            String s = in.readLine();
            if (s == null) {
                break;
            }
            if (s.equals("0")) {
                System.out.println(stack.pop());
            } else {
                stack.push(s);
            }
        }
    }
}

Measured memory_bytes: 9360
N = input()
ans = 0
for n in range(1, len(N), 2):
    ans += 9 * 10 ** (n-1)

if len(N) == 1:
    ans = int(N)


elif len(N) % 2 != 0:
    ans += (10 ** (len(N)-1)) * (int(N[0])-1)
    ans += int(N[min(1, len(N)-1):]) + 1


print(ans)


Measured memory_bytes: 3060
n,m = map(int,input().split())
ks = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))

ans = 0
# 2択
for i in range(0,1<<n):
    cnt = [0]*m
    for j in range(n):
        if (i>>j)&1:
            for k in range(m):
                if j + 1 in ks[k][1:]:
                    cnt[k] += 1

    temp = 0
    for i in range(m):
        if cnt[i] % 2 == p[i]:
            temp += 1
    if temp == m:
        ans += 1

print(ans)


Measured memory_bytes: 3064
using System;

namespace ALDS1_1_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int number;
            int counter = 0;

            for (int i = 0; i < n; i++)
            {
                number = int.Parse(Console.ReadLine());
                
                if (Divisor(number))
                    counter++;
            }
            Console.WriteLine(counter);
        }

        public static bool Divisor(int a)
        {
            if (a == 2)
                return true;

            if (a % 2 == 0)
                return false;

            int b = (int)Math.Sqrt(a);
            for (int i = 3; i <= b; i+=2)
            {
                if (a % i == 0)
                    return false;
            }
            return true;
        }
    }
}


Measured memory_bytes: 17936
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int i=0; i<n; i++){
			int y = in.nextInt();
			int m = in.nextInt();
			int d = in.nextInt();
			int res = toNextY(y, m, d) + toMill(y+1);
			System.out.println(res);
		}
	}
	
	public static int toMill(int y){
		int res = 0;
		for(int i=y; i<1000; i++){
			res += (i%3==0) ? 10*20 : (5*20 + 5*19);
		}
		return res;
	}
	
	public static int toNextY(int y, int m, int d){
		int res = 0;
		if(y%3==0){
			res = 20 - d + (10-m)*20;
		}else{
			if(m%2==0){
				res = 19 - d + (10-m)*39/2;
			}else{
				res = 20 - d + 19 + (9-m)*39/2;
			}
		}
		return res+1;
	}
}

Measured memory_bytes: 20772
# https://atcoder.jp/contests/abc158/tasks/abc158_c


A, B = gets.split.map(&:to_i)

ai = (A / 0.08).ceil
ax = ((A + 1) / 0.08 - 1).ceil
bi = (B / 0.1).ceil
bx = ((B + 1) / 0.1 - 1).ceil

ans = ([*ai..ax] & [*bi..bx]).sort.first || -1

puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;


lint calc(lint a,lint b){
    if(b == 0)return 1;
    if(b % 2 == 0){
        lint c = calc(a,b/2);
        return (c*c) % MOD;
    }else{
        return (a * calc(a,b-1)) %MOD;
    }
}
int main(){
    int n;
    int a,b;
    cin >> n >> a >> b;
    lint ans = calc(2,n) - 1;
    lint x = 1;
    lint y = 1;
    REP(i,a){
        x = (x * (n - i)) % MOD;
        y = (y * (i+1)) % MOD;
    } 
    lint wal = calc(y,MOD - 2);
    ans = (ans + MOD - (x * wal)%MOD) % MOD;
    x = 1;
    y = 1;
    
    REP(i,b){
        x = (x * (n - i)) % MOD;
        y = (y * (i+1)) % MOD;
    } 
    wal = calc(y,MOD - 2);
    ans = (ans + MOD - (x * wal)%MOD)%MOD;
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true) {
      int n = sc.nextInt();
      if (n == 0) {
        break;
      }
      int[] seq = new int[n];
      for(int i = 0; i < n; i++) {
        seq[i] = sc.nextInt();
      }
      int sumMax = Integer.MIN_VALUE;
      for(int i = 0; i < n; i++) {
        int sumTemp = 0;
        for(int j = i; j < n; j++) {
          sumTemp += seq[j];
          if (sumMax < sumTemp) {
            sumMax = sumTemp;
          }
        }
      }
      System.out.println(sumMax);
    }
  }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 400 + 10;
const ll mod = 1e9 + 7;
int n, c;
int a[maxn], b[maxn];
ll p[maxn][maxn], u[maxn][maxn], f[maxn][maxn];
int main()
{
	scanf("%d%d", &n, &c);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	for(int j = 0; j < maxn; ++j) 
	{
		p[j][0] = 1;
		for(int k = 1; k <= c; ++k)
			p[j][k] = p[j][k - 1] * j % mod;
	}
	for(int k = 0; k <= c; ++k)
		for(int j = 1; j < maxn; ++j)
			p[j][k] = (p[j][k] + p[j - 1][k]) % mod;
	for(int i = 1; i <= n; ++i)
		for(int k = 0; k <= c; ++k)
			u[i][k] = (p[b[i]][k] - p[a[i] - 1][k] + mod) % mod;
	f[0][0] = 1;
	for(int i = 1; i <= n; ++i)
		for(int j = 0; j <= c; ++j)
			for(int k = 0; k <= j; ++k)
				f[i][j] = (f[i][j] + f[i - 1][j - k] * u[i][k] % mod) % mod; 
	printf("%lld\n", f[n][c]);
	return 0;
}

Measured memory_bytes: 7704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i, n+1) cin >> a[i];
    vector<int> b(n);
    rep(i, n) cin >> b[i];
    ll count = 0;
    rep(i, n) {
        if (a[i] >= b[i]) {
            count += b[i];
        }
        else {
            count += a[i];
            b[i] -= a[i];
            count += min(b[i], a[i + 1]);
            a[i + 1] -= min(a[i + 1], b[i]);
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 4028
#include <stdio.h>

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int N, d[64], sum, ssum;

int main() {

	scanf("%d", &N);
	rep(i, N) scanf("%d", &d[i]);
	rep(i, N) {
		sum += d[i];
		ssum += d[i] * d[i];
	}

	printf("%d\n", (sum* sum - ssum) / 2);

	return 0;
}


Measured memory_bytes: 128
S = input()

def iskai(s):
  result=False
  if s == s[::-1]:
    result=True
  return(result)

ans = 'No'
hf = len(S)//2 + 1

if iskai(S) and iskai(S[:hf-1]) and iskai(S[hf:]):
  ans = 'Yes'
  
print(ans)

Measured memory_bytes: 8980
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cmath>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define rrep(i, n) for (int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for (int i=(int)(n);i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}
template<typename T>bool chmin(T&a,T b){return a>b?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return a<b?(a=b,1):0;}
int read(){int a;scanf("%lld",&a);return a;}

const long double pi = acos(-1);
constexpr int inf = 3*TEN(18) + 10;

const int mod = TEN(9)+7;

int N, M;
pii rng[100010];
vector<pii> in[100010], out[100010];
int d[100010];

signed main()
{
	cin >> N >> M;
	rep(i, M) {
		int l, r, c; cin >> l >> r >> c;
		--l, --r;
		rng[i] = pii(l, r);
		in[l].emplace_back(c, i);
		out[r].emplace_back(c, i);
	}

	rep(i, N) d[i] = inf;
	d[0] = 0;

	set<pii> V;

	rep(i, N) {
		if (V.size())
			chmin(d[i], V.begin()->first);

		for (pii p : out[i]) {
			int id = p.scd;
			int v = d[rng[id].first] + p.fst;
			V.erase(pii(v, id));
		}

		for (pii p : in[i]) {
			int c = p.fst, id = p.scd;
			int v = d[rng[id].first] + c;
			V.insert(pii(v, id));
		}
	}

	if (d[N - 1] == inf) {
		puts("-1");
	} else {
		printf("%lld\n", d[N - 1]);
	}
}




Measured memory_bytes: 19552
n = input()

if len(n) == 1:
  print(n)
  exit()

if all(x == "9" for x in n[1:]):
  ans = n
else:
  ok = False
  ans = ""
  for i, c in enumerate(n):
    x = int(c)
    if x == 9:
      ans += "9"
    else:
      if ok:
        ans += "9"
      else:
        if i == len(n)-1:
          ans = ans[:-1]
          ans += str(int(n[i-1])-1)
          ans += "9"
        else:
          ans += str(x-1)
      ok = True
t = 0
for c in ans:
  x = int(c)
  t += x

print(t)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

ll mobius[100010];

void initmobius()
{
    for(ll i=1;i<100010;i++)
    {
        mobius[i]=1;
    }
    for(ll i=2;i<100010;i++)
    {
        if(mobius[i]==1)
        {
            for(ll j=i;j<100010;j+=i)
            {
                mobius[j]*=(-i);
            }
            for(ll j=(i*i);j<100010;j+=(i*i))
            {
                mobius[j]=0;
            }
        }
    }
    for(ll i=2;i<100010;i++)
    {
        if(mobius[i]>0)
        {
            mobius[i]=1;
        }
        else if(mobius[i]<0)
        {
            mobius[i]=-1;
        }
    }
    return;
}

ll modexpo(ll base,ll power)
{
    ll result=1;
    while(power)
    {
        if(power&1)
        {
            result=(result*base)%MOD;
        }
        base=(base*base)%MOD;
        power>>=1;
    }
    return result;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    initmobius();
    ll n,k,store;
    cin>>n>>k;
    ll divby[k+1];
    for(ll i=1;i<=k;i++)
    {   
        store=k/i;
        divby[i]=modexpo(store,n);
    }
    for(ll i=1;i<=k;i++)
    {
        for(ll j=2;(j*i)<=k;j++)
        {
            divby[i]+=(mobius[j]*divby[j*i]);
            if(divby[i]>=MOD)
            {
                divby[i]-=MOD;
            }
            else if(divby[i]<0)
            {
                divby[i]+=MOD;
            }
        }
    }
    ll ans=0;
    for(ll i=1;i<=k;i++)
    {
        store=divby[i]*i;
        if(store>=MOD)
        {
            store%=MOD;
        }
        ans+=store;
        if(ans>=MOD)
        {
            ans-=MOD;
        }
    }
    cout<<ans;
    return 0;
}

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



int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    
    int all = 0;
    rep(i,n) {
        //all = all ^ a[i];
        all ^= a[i];
    }
    
    rep(i,n) {
        int ans = all ^ a[i];
        if(i == n-1)
            cout << ans << endl;
        else
            cout << ans << " ";
    }

    
    return 0;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MAX = 100005;
int main() {
    int n; cin >> n;
    vector<int> a(MAX);
    rep(i, n) {
        int x; cin >> x;
        a[x]++;
    }
    int mx = 0;
    rep(i, MAX-1) {
        mx = max(mx, a[i]+a[i+1]+a[i+2]);
    }
    cout << mx;
}


Measured memory_bytes: 640
import java.util.*;

class Main {
    public static int maxx(int a, int b, int c)
{
    return Math.max(Math.max(a,b),c);
}
    public static void main(String args[] ) throws Exception {
        Scanner ob=new Scanner(System.in);
        int n=ob.nextInt();
        int INF = (int)1e9+7;
        int a[]=new int[n];
        int dp[][]=new int[n][3];
        int a1,b,c;
        for(int i=0;i<n;i++)
        {
            a1=ob.nextInt();b=ob.nextInt();c=ob.nextInt();
            if(i==0)
            {
                dp[i][0]=a1;dp[i][1]=b;dp[i][2]=c;
            }
            else
            {
                dp[i][0]=Math.max(dp[i-1][1]+a1,dp[i-1][2]+a1);
                dp[i][1]=Math.max(dp[i-1][0]+b,dp[i-1][2]+b);
                dp[i][2]=Math.max(dp[i-1][1]+c,dp[i-1][0]+c);
            }
        }
        
       
        System.out.println(maxx(dp[n-1][0],dp[n-1][1],dp[n-1][2]));
        
        //System.out.println(Arrays.toString(a));
        //System.out.println(Arrays.toString(dp));
        
        
        
        //System.out.println(Arrays.toString(dp));
        //System.out.println("Hello World!");
    }
}


Measured memory_bytes: 97096
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF = 1000000100;

int main(){
    int x[5];
    for(int i=0;i<5;i++){
        cin >> x[i];
    }
    for(int i=0;i<5;i++){
        if(x[i]==0){
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3160
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
#include <bitset>

using namespace std;

int main(){
    int N, a[100];
    cin >> N;
    for(int i = 0; i < N; i++) cin >> a[i];

    sort(a, a+N);
    reverse(a, a+N);

    int A = 0, B = 0;

    for(int i = 0; i < N; i++){
        if(i % 2 == 0) A += a[i];
        else B += a[i];
    }

    cout << A - B << endl;


    return 0;
}

Measured memory_bytes: 256
s = [int(i) for i in input()]
    
if s[0] == 0 or s[-1] == 1 :
    print(-1)
    
else :
    s.pop()
    if s != s[::-1] :
        print(-1)
        
    else :
        org = 1
        for i in range((len(s) + 1) // 2) :
            if s[i] == 1 :
                for j in range(org + 1, i + 3) :
                    print(org, j)
                org = i + 2
        for i in range(org + 1, len(s) + 2) :
            print(org, i)

Measured memory_bytes: 51420
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int n,m;
    cin >> n >> m;
    int sum = 0;
    for(int i = 0;i<m;i++){
        int a = 0;
        cin >> a;
        sum += a;
    }
    if(sum > n){
        cout << "-1" << endl;
    }else{
        cout << n - sum <<endl;
    }    

    return 0;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007 , __ = _<<1 , inf = 0x3f3f3f3f;

int n,nn,val[__];

inline int able(int lim)
{
	int adis=inf,bdis=inf;
	for(int i=1;i<nn;i++)
	{
		if(val[i]<lim && val[i+1]<lim)adis=min(adis,min(abs(n-i),abs(n-i-1)));
		if(val[i]>=lim && val[i+1]>=lim)bdis=min(bdis,min(abs(n-i),abs(n-i-1)));
	}

	if(adis==inf && bdis==inf)return val[1]>=lim;
	return bdis<adis;
}

int main()
{
	n=ty(),nn=n+n-1;
	for(int i=1;i<=nn;i++)val[i]=ty();
	
	int l=1,r=nn;
	while(r>l)
	{
		int mid=(l+r+1)>>1;
		if(able(mid))l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
 
//qsort
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}
 
int main(void) {
 
  // 入力
  int n,a,b;
  scanf("%d",&n);
  scanf("%d",&a);
  scanf("%d",&b);
  
  int min=a*n;
  if(min>b)min=b;
  printf("%d",min);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,x,l,ans,t;
  ans=0;
  t=-10000000000;
  cin>>n;
  vector<pair<long, long>> vec(n);
  for(long i=0; i<n; i++){
    cin>>x>>l;
    vec.at(i).first=x+l;
    vec.at(i).second=x-l;
  }
  sort(vec.begin(), vec.end());
  for(long i=0; i<n; i++){
    if(vec.at(i).second>=t){
      t=vec.at(i).first;
      ans=ans+1;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int vis[25][25];
char s[25][25];
int x[4] = {0, 1, 0, -1};
int y[4] = {1, 0, -1, 0};
struct node { int x, y; } q[25 * 25];
int h, w;

int Solve(int a, int b, int c, int d) {
  if (s[a][b] == '#' || s[c][d] == '#') return 0;
  memset(vis, 0, sizeof(vis));
  vis[a][b] = 1;
  int head = 1, tail = 0;
  q[++tail] = (node){a, b};
  while (head <= tail) {
    node t = q[head++];
    for (RI i = 0; i < 4; ++i) {
      if (t.x + x[i] >= 1 && t.x + x[i] <= h && t.y + y[i] >= 1 && t.y + y[i] <= w)
        if (!vis[t.x + x[i]][t.y + y[i]] && s[t.x + x[i]][t.y + y[i]] != '#')
          vis[t.x + x[i]][t.y + y[i]] = vis[t.x][t.y] + 1, q[++tail] = (node){t.x + x[i], t.y + y[i]};
    }
  }
    return vis[c][d] - 1;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  cin >> h >> w;
  for (RI i = 1; i <= h; ++i)
    cin >> (s[i] + 1);
  int ans = 0;
  for (RI i = 1; i <= h; ++i)
    for (RI j = 1; j <= w; ++j)
      for (RI k = 1; k <= h; ++k)
        for (RI l = 1; l <= w; ++l)
          ans = max(ans, Solve(i, j, k, l));
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

//int tx[] = {0,1,0,-1};
//int ty[] = {-1,a0,1,0};

const int tx[] = {0,1,1,0};
const int ty[] = {0,0,1,1};

static const double EPS = 1e-8;

ll mypow(ll x,int power){
	ll res = 1;
	while(power>0){
		if(power & 1) res *= x;
		x *= x;
		power >>= 1;
	}
	return res;
}

void init_format(vector<vector<string> >& bit_format){
	bit_format.resize(4);

	bit_format[0].push_back("0xxxxxxx");

	bit_format[1].push_back("110yyyyx");
	bit_format[1].push_back("10xxxxxx");

	bit_format[2].push_back("1110yyyy");
	bit_format[2].push_back("10yxxxxx");
	bit_format[2].push_back("10xxxxxx");

	bit_format[3].push_back("11110yyy");
	bit_format[3].push_back("10yyxxxx");
	bit_format[3].push_back("10xxxxxx");
	bit_format[3].push_back("10xxxxxx");
}

ll CountPatterns(int start,int last,const vector<vector<string> >& bit_format,const vector<string>& bits,int len){
	bool isok = true;

	int x_num = 0;
	int y_num = 0;
	int y1_num = 0;
	int y0_num = 0;

	for(int i=start,k=0;i<bits.size() && i <= last && k< bit_format[len-1].size();i++,k++){

		for(int j=0;j<bits[i].size() && j< bit_format[len-1][k].size();j++){

			if(bits[i][j]=='x'){
				if(bit_format[len-1][k][j] == 'x'){
					x_num++;
				}

				else if(bit_format[len-1][k][j] == 'y'){
					y_num++;
				}
			}

			else if(bits[i][j]=='1'){
				if(bit_format[len-1][k][j] =='0'){
					isok = false;
				}

				else if(bit_format[len-1][k][j] == 'y'){
					y1_num++;
				}
				else{
					continue;
				}
			}
			else if(bits[i][j] == '0'){
				if(bit_format[len-1][k][j] =='1'){
					isok = false;
				}
				else if(bit_format[len-1][k][j] == 'y'){
					y0_num++;
				}
			}
		}
	}

	if(y_num==0 && y1_num==0 && y0_num > 0) isok = false;

	ll x_patterns = mypow(2,x_num);
	ll y_patterns = 1;

	if(y1_num > 0){
		y_patterns = mypow(2,y_num);
	}
	else{
		y_patterns = mypow(2,y_num)-1;
	}

	if(y_patterns == 0) y_patterns = 1;
	if(!isok) return 0;

	x_patterns %= 1000000;
	y_patterns %= 1000000;

	return x_patterns*y_patterns % 1000000LL;
}

ll dp[1001];

int main(){
	vector<vector<string> > bit_format;
	init_format(bit_format);

	int N;
	while(cin >> N){
		if(N==0) break;

		string line;
		vector<string> bits;
		for(int i=0;i<N;i++){
			string line;
			cin >> line;
			bits.push_back(line);
		}

		
		memset(dp,0,sizeof(dp));
		for(int start=0;start<N ;start++){
			for(int len = 4; len >=1; len--){
				if(start-len+1 < 0) continue;
				ll patterns = CountPatterns(start-len+1,start,bit_format,bits,len);	
				dp[start] += patterns * (start-len >=0 ? dp[start-len] : 1);
				dp[start] %= 1000000LL;
			}
		}
		printf("%ld\n",dp[N-1]%1000000LL);
	}
}

Measured memory_bytes: 1284
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
typedef long long LL;
long long n,c,x[100005],v[100005],sz[100005],nz[100005],sj[100005],nj[100005],ans=0;
int main()
{
	cin>>n>>c;
	for(LL i=1;i<=n;i++)
	{
		cin>>x[i]>>v[i];
	}
	for(LL i=1;i<=n;i++)
	{
		sj[i]=sj[i-1]+v[i];
		sz[i]=max(sz[i-1],sj[i]-x[i]);
	}
	for(LL i=n;i>=1;i--)
	{
		nj[i]=nj[i+1]+v[i];
		nz[i]=max(nz[i+1],nj[i]-(c-x[i]));
		
	}
	for(LL i=1;i<=n;i++)
	{
		ans=max(ans,sz[i]);
		ans=max(ans,sj[i]+nz[i+1]-2*x[i]);
	}
	for(LL i=n;i>=1;i--)
	{
		ans=max(ans,nz[i]);
		ans=max(ans,nj[i]+sz[i-1]-2*(c-x[i]));
	}
	cout<<ans;
	return 0;
	
} 


Measured memory_bytes: 4992
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline T GCD_L(T a,T b){
  T r;
  while(a){
    r=b;
    b=a;
    a=r%a;
  }
  return b;
}
template<class T> inline T LCM_L(T a,T b){
  return a/GCD_L(a,b)*b;
}
int N;
long long T[100];
int main(){
  long long res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(T[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY;
    long long Q5VJL1cS;
    if(N==0){
      Q5VJL1cS = 1;
    }
    else{
      Q5VJL1cS = T[0];
      for(KL2GvlyY=(1);KL2GvlyY<(N);KL2GvlyY++){
        Q5VJL1cS = LCM_L(Q5VJL1cS, T[KL2GvlyY]);
      }
    }
    res =Q5VJL1cS;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// int N; ll T[100];
// {
//   ll res;
//   rd(N,T(N));
//   res = lcm(T(N));
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4+5;

int n,a,b,cnt;
int x[10],y[10],t[10];
 
inline bool check1(){
	for(int i = 0;i < n;++i){
		if(x[i] != t[i]) return 0;
	}
	a = cnt;
	return 1;
}

inline bool check2(){
	for(int i = 0;i < n;++i){
		if(y[i] != t[i]) return 0;
	}
	b = cnt;
	return 1;
}
 
int main()
{
    scanf("%d",&n);
    for(int i = 0;i < n;++i) scanf("%d",&x[i]),t[i] = i+1;
    for(int i = 0;i < n;++i) scanf("%d",&y[i]);
    
    cnt = 1;
    bool f1 = 0,f2 = 0;
    do{
    	if(!f1) check1();
    	if(!f2) check2();
    	if(f1 && f2) break;
    	cnt++;
	}while(next_permutation(t,t+n));
	
	printf("%d\n",abs(a-b));
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

LL q, h, s, d;
LL n;
LL cnt[5];
int o[5];

bool cmp(int a, int b) {
    return cnt[a] < cnt[b];
}

int main()
{
#ifdef ANONYM
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    clock_t rtime = clock();
#endif

    cin >> q >> h >> s >> d >> n;
    cnt[1] = q*8LL; cnt[2] = h*4LL; cnt[3] = s*2LL; cnt[4] = d;
    REP(i, 1, 5) o[i] = i;
    sort(o+1, o+5, cmp);
    if(o[1] <= 3) {
        cout << n*cnt[o[1]]/2LL << endl;
    } else {
        if(n%2LL) {
            cout << (n-1LL)/2LL*cnt[4] + min(q*4LL, min(h*2LL, s)) << endl;
        } else {
            cout << n/2LL * cnt[4] << endl;
        }
    }


#ifdef ANONYM
    debug("time: %d\n", (int)(clock() - rtime));
#endif
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
 
#define for0(i,n) for(ll i = 0;i < (n);i++)
#define for1(i,n) for(ll i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define fastio cin.tie(NULL);cout.tie(NULL);ios::sync_with_stdio(false)
#define F first
#define S second
#define EPS 1e-12
#define all(x) (x).begin(),(x).end()
#define INF ll(2e18)
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}cout<<endl;
#define deb1(a) cout<<(a)<<endl;
#define deb2(a,b) cout<<(a)<<" "<<(b)<<endl;
#define deb3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;
 
using namespace std;
 
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ii> vii;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<ll,ll> > vll;
typedef long double LD;
 
const ll mod =  998244353;

/* 
ll nop = 100;
vi primes(nop,1);
 
void sieve(){
    primes[1] = primes[0] = 0;
    for(ll i = 2;i * i <= nop;i++){
        if(primes[i]){
            for(ll j = i*i; j <= nop;j+=i){
                primes[j] = 0;
            }
        }
    }
}

ll phi(ll n) {
    ll tot = n;
    for(ll i = 2;i*i <= n;i++) {
        if(n%i == 0) {
            tot -= tot/i;
        }
        while(n%i == 0) {
            n /= i;
        }
    }
    if(n > 1) {
        tot -= tot/n;
    }
    return tot;
}
*/
 
ll gcd(ll a,ll b){    //a larger, b smaller
    if(b>a) swap(b,a);
    if(b==0) return a;
    return gcd(b,a%b);
}
/*
void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}
 
ll lcm(ll a,ll b){
    return (a*b)/gcd(a,b);
}
 */
ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}
 
ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans*num)%mod;
        }
        num = (num*num)%mod;
        e>>=1;
    }
    return ans%mod;
}
 
ll modinv(ll a){
    return mexp(a,mod-2);
}

void solve() {
    char ch;
    cin>>ch;
    if(islower(ch)) {
        cout<<char('a')<<endl;
    }
    else {
        deb1(char('A'));
    }
}

int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    for1(T,t) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3612
function main()
	lines=readlines()
	N,M=map(x->parse(Int,x),split(shift!(lines)))
	A=[((a,b)=map(x->parse(Int,x),split(s));(b,a)) for s=lines]
	sort!(A)
	c=p=0
	for (b,a)=A
		if p<a
			c+=1
			p=b-1
		end
	end
	println(c)
end
main()


Measured memory_bytes: 153828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    vector<ll> a(n,0);
    rep(i,k){
        ll d;cin>>d;
        rep(j,d){
            ll A;cin>>A;
            a[A-1]++;
        }
    }
    ll ans = 0;
    for(ll A:a){
        if(A==0)ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int w,h;
vector<vector<int> >  b;
int sx,sy,gx,gy;
int ans;

void test(int x,int y,int n){
  int bx,by;
  int xx=x,yy=y;
  if(++n>=ans) return;

  while(b[y][x+1]==0){
    x++;
    if(x==gx&&y==gy){
      ans=n;
      return;
    }
  }
  if((x!=xx)&&(x+1!=w-1)){
    bx=x+1; by=y;
    b[by][bx]=0;
    test(x,y,n);
    b[by][bx]=1;
  }
  x=xx;y=yy;

  while(b[y][x-1]==0){
    x--;
    if(x==gx&&y==gy){
      ans=n;
      return;
    }
  }
  if(x!=xx&&x-1!=0){
    bx=x-1; by=y;
    b[by][bx]=0;
    test(x,y,n);
    b[by][bx]=1;
  }
  x=xx;y=yy;

  while(b[y+1][x]==0){
    y++;
    if(x==gx&&y==gy){
      ans=n;
      return;
    }
  }
  if(y!=yy&&y+1!=h-1){
    bx=x; by=y+1;
    b[by][bx]=0;
    test(x,y,n);
    b[by][bx]=1;
  }
  x=xx;y=yy;

  while(b[y-1][x]==0){
    y--;
    if(x==gx&&y==gy){
      ans=n;
      return;
    }
  }
  if(y!=yy&&y-1!=0){
    bx=x; by=y-1;
    b[by][bx]=0;
    test(x,y,n);
    b[by][bx]=1;
  }
  x=xx;y=yy;
}

int main(){
  while(cin>>w>>h,w+h){
    w+=2;h+=2;
    ans=11;
    b=vector<vector<int> >(h+2,vector<int>(w+2,1));
    for(int i=1;i<h-1;i++){
      for(int j=1;j<w-1;j++){
        cin >> b[i][j];
        if(b[i][j]==2){
          b[i][j]=0;
          sx=j;sy=i;
        }else if(b[i][j]==3){
          b[i][j]=0;
          gx=j;gy=i;
        }
      }
    }
    test(sx,sy,0);
    if(ans==11) cout << -1 << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
A=[]
for x in T:
    if x == 's':
        A.append('r')
    if x == 'p':
        A.append('s')
    if x == 'r':
        A.append('p')
 
for i in range(K,N):
    if A[i-K] == A[i]:
        A[i] = 'x'
 
ans = 0
for x in A:
    if x == 's':
        ans += S
    if x == 'p':
        ans += P
    if x == 'r':
        ans += R
print(ans)

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 100+10;
const int maxk = 100000+10;
int memo[maxk],A[maxn],N,K;

int dp(int k){
	int &res = memo[k];
	if(res != -1)return res;
	set<int> S;
	forn(i,0,N){
		if(A[i] > k)continue;
		S.insert(dp(k-A[i]));
	}
	int cnt = 0;
	while(1){
		if(!S.count(cnt)){
			res = cnt;
			return res;
		}
		cnt++;
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	forn(i,0,maxk)memo[i] = -1;
	cin >> N >> K;
	forn(i,0,N)cin >> A[i];
	int res = dp(K);
	if(res)cout << "First\n";
	else cout << "Second\n";
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s,t; cin>>s>>t;
	int j=0,n=s.size();
	string ans="No"s;
	while(n){
		bool yes=true;
		for(int i=0,k=j;i<t.size();++i,++k){
			if(s.at(k)!=t.at(i))yes=false;
		}
		if(yes){ans="Yes"s;break;}
		s+=s.at(j);
		++j,--n;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
#define MOD 100000
using namespace std;
int main(void){

    int n,m;
    cin>>n>>m;

    int a[100020],b[100020] = {};
    b[0] = 0;
    for(int i = 0;i < n-1;i++){
        cin>>a[i];
        b[i+1] = a[i] + b[i];
    }
    int now = 0,ans = 0;
    for(int j = 0;j < m;j++){
        int x;
        cin>>x;
        ans += abs(b[now + x] - b[now]);
        ans %= MOD;
        now += x;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1948
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 998244353
using namespace std;


int main(){
    int N, M;
    cin >> N >> M;
    vector<int> path[600];
    
    int a[600*599/2], b[600*599/2];
    
    for(int i=0; i<M; i++){
        int s,t;
        cin >>s >> t;
        s--; t--;
        
        a[i]=s;
        b[i]=t;
        path[s].push_back(t);
    }
    
    
    
    double ans=0;
    
    
    double maxE[600]={};
    maxE[N-1]=-1;
    
    double compE[600];
    compE[N-1]=0;
    for(int i=N-2; i>=0; i--){
        double num=path[i].size();
        compE[i]=0;
        for(int dst : path[i]){
            compE[i] += (compE[dst]+1)/num;
            
            maxE[i] = max(maxE[i], compE[dst]);
        }
    }
    ans = compE[0];
    
    
    for(int i=0; i<N-1; i++){
        double E[600]={};
        int ok=1;
        E[N-1]=0;
        for(int j=N-2; j>=0; j--){
            double num=path[j].size();
            if(i==j){
                num--;
            }
            if(num==0){
                ok=0;
                break;
            }
            
            
            E[j]=0;
            
            int flag=0;
            for(int dst : path[j]){
                if(i==j && compE[dst]==maxE[j] && flag==0){
                    flag=1;
                    continue;
                }
                
                E[j] += (E[dst]+1)/num;
            }
            if(E[j]==0){
                ok=0;
                break;
            }
        }
    
        if(ok){
            ans = min(ans, E[0]);
        }
    }
    
    

    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}


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

#define N 2000001
#define I 10000

int n;

void CountingSort(int *A, int *B) {
	int i, j;
	int C[I+1];

	for (i = 0; i <= I; i++) C[i] = 0;

	for (j = 1; j <= n; j++) {
		C[A[j]]++;
	}
	for (i = 1; i <= I; i++) {
		C[i] = C[i] + C[i-1];
	}
	for (j = n; j >= 1; j--) {
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
}

int main () {
	int i;
	int *A, *B;

	scanf("%d", &n);

	A = (int *)malloc(sizeof(int) * n + 1);
	B = (int *)malloc(sizeof(int) * n + 1);

	for (i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
	}

	CountingSort(A, B);

	for (i = 1; i < n; i++) {
		printf("%d ", B[i]);
	}
	printf("%d\n", B[i]);

	return 0;
}

Measured memory_bytes: 16268
S = input()

base = ['A', 'T', 'G', 'C']

ans = ''
a = ''
for i in range(len(S)):
    if S[i] in base:
        a += S[i]
        if len(a) > len(ans):
            ans = a
    else:
        a = ''
print(len(ans))


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

using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

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

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(long long int i=0;i<n;i++)
#define rep(i,k,n) for (lli i = k; i <= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

typedef pair <lli,lli> pll;
 
// CODE BEGINS :

void solve()
{
    lli n, k; cin>>n>>k;

    if(k>n) k=n;

    lli arr[n];
    forz(i,n) cin>>arr[i];

    lli dp[n+1];
    forz(i,n+1) dp[i]=1e17;

    dp[1]=0;
    for(lli i=2; i<=k; i++)
    {
        for(lli j=1; j<i; j++)
        {
            dp[i] = fmin(dp[i], dp[j] + abs(arr[i-1] - arr[j-1]));
        }
    }

    for(lli i=k+1; i<=n; i++)
    {
        lli key = 1e17;

        lli cnt=1;
        for(lli j=i-1; cnt<=k; j--)
        {
            cnt++;

            key = fmin(key, dp[j] + abs(arr[i-1] - arr[j-1]));
        }

        dp[i] = key;
    }

    // forz(i,n) cout<<dp[i+1]<<" "; cout<<endl;

    cout<<dp[n]<<endl;
}

int main()
{
    kira; 

    lli t=1; //cin>>t;

    while(t--)
    {
        solve();
    }
    
    return 0;
}




















Measured memory_bytes: 1792
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
cnt_a = Counter(a)
q = int(input())
s = [sum(a)] + [0] * q
for i in range(q):
    b, c = map(int, input().split())
    bn = cnt_a[b]
    s[i + 1] = s[i] + (c - b)*bn
    cnt_a[b] = 0
    cnt_a[c] += bn
    print(s[i + 1])

Measured memory_bytes: 27784