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

const int N = 1e5+10;
char ss[N];
int main()
{
    scanf("%s",ss);
    int len=strlen(ss);
    int ans;
    if(ss[0]==ss[len-1]) ans=len-3;
    else ans=len-2;
    if(ans%2==1) printf("First\n");
    else printf("Second\n");
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int x = in.nextInt();
    int ans = 0;
    while (x >= 500) {
      ans += 1000;
      x -= 500;
    }
    while (x >= 5) {
      ans += 5;
      x -= 5;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
#define PP 1000000007
using namespace std;

int main(){
ll N, K, p = 0;cin >> N >> K;
vector<ll> A(N);
map<ll, ll> M;

rep(i, 0, N)cin >> A[i];

M[1] = 1;

rep(i, 2, K + 2){

  if(M[A[p]] == 0){
  
    M[A[p]] = i;

    if(i < K + 1)p = A[p] - 1;

  }

  else{

    ll L = i - M[A[p]], C = (K - M[A[p]] + 1)/L;

    i += L*(C - 1);

    M.clear();
    
    if(i != K + 1)p = A[p] - 1;

  }

}

cout << A[p];

}

Measured memory_bytes: 14772
#pragma region Include/Defines
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <queue>
#include <time.h>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef vector<pii> vpii;
typedef vector <pll> vpll;
typedef long double ld;
#define all(a) std::begin(a), std::end(a)

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

template<typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); }
template<typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); }

#ifdef _DEBUG
#define epr(...) fprintf(stderr,__VA_ARGS__)
#else
#define epr(...) 
#endif
#pragma endregion

const int MAX = 110;
int h, w;
int n, a[MAX * MAX];
int r[MAX][MAX];

void clear() {
}

void read() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
}

void solve() {
	int k = 0;
	for (int i = 0; i < h; i++) {
		int dj = i & 1 ? 1 : -1, sj = i & 1 ? 0 : w - 1, ej = i & 1 ? w : -1;
		for (int j = sj; j != ej; j += dj) {
			while (k < n && a[k] == 0) k++;
			r[i][j] = k + 1;
			a[k]--;
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++)
			printf("%d ", r[i][j]);
		printf("\n");
	}
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d%d", &h, &w) == 2) {
		clear();
		read();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>

int main() {
	int n;
	int a;
	int b;
	int na, nb;
	while(1) {
		scanf("%d", &n);
		a = 0;
		b = 0;
		if(n == 0)
		break;
		for(int i = 0; i < n; i++) {
			na = 0;nb = 0;
			scanf("%d %d", &na, &nb);
			if(na > nb) {
				a += na + nb;
			} else if(na < nb) {
				b += na + nb;
			} else {
				a += na;
				b += nb;
			}
		}
		printf("%d %d\n", a, b);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<string>

using namespace std;

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

int main(){
    string s;
    cin >> s;
    rep(i, s.size() - 1){
        for (int j = i + 1; j < s.size(); j++){
            if(s[i] == s[j]){
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 256
import sys
from bisect import bisect

def Longest_Increasing_Subsequence(N,lst):
    #配列の長さがN、配列がlstで与えられる最長増加部分列を返す
    #O(NlogN)
    
    MM=max(lst)+1
    data=[MM]*(N+1)
    #MMは配列の最大値とする
    #infだと計算量が結構大きくなるため
    
    data[0]=0
    for i in range(N):
        b=bisect(data,lst[i])
        data[b]=lst[i]

    ANS=1
    for i in range(1,N+1):
        if data[i]!=MM:
            ANS=i
    
    return ANS

def Longest_Decreasing_Subsequence(N,lst):
    #配列の長さがN、配列がlstで与えられる最長減少部分列を返す
    #O(NlogN)
    
    MM=max(lst)+1
    data=[MM]*(N+1)
    #MMは配列の最大値とする
    
    #配列を逆にして、最長増加部分列を求めればいよい
    lst=lst[::-1]
    
    data[0]=0
    for i in range(N):
        b=bisect(data,lst[i])
        data[b]=lst[i]

    ANS=1
    for i in range(1,N+1):
        if data[i]!=MM:
            ANS=i
    
    return ANS



N,A,B=map(int,input().split())
AAA,BBB=A,B

if A>N or B>N:
    print(-1)
    sys.exit()
if B>N-A+1:
    print(-1)
    sys.exit()

ans=[]
L=1
R=N
flag=[0]*(N+1)
flag[0]=1

if A<B:
    B-=1
    while A>0 and B>0 and len(ans)<N:
        for i in range(max(1,R-A+1),R+1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        R-=A
        A-=1
        for i in range(min(N,L+B-1),L-1,-1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        L+=B
        B-=1
        
    for i in range(min(N,L+B-1),L-1,-1):
        if flag[i]==0:
            flag[i]=1
            ans.append(i)

elif A==B:
    B-=1
    while A>0 and B>0 and len(ans)<N:
        for i in range(max(1,R-A+1),R+1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        R-=A
        A-=1
        for i in range(min(N,L+B-1),L-1,-1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        L+=B
        B-=1
        
    for i in range(max(1,R-A+1),R+1):
        if flag[i]==0:
            flag[i]=1
            ans.append(i)

else:
    A-=1
    while A>0 and B>0 and len(ans)<N:
        for i in range(min(N,L+B-1),L-1,-1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        L+=B
        B-=1
        for i in range(max(1,R-A+1),R+1):
            if flag[i]==0:
                flag[i]=1
                ans.append(i)
        R-=A
        A-=1
    
    for i in range(max(1,R-A+1),R+1):
        if flag[i]==0:
            flag[i]=1
            ans.append(i)

if len(ans)>=N:
    ans=ans[:N]
    if  Longest_Increasing_Subsequence(N,ans)==AAA and Longest_Decreasing_Subsequence(N,ans)==BBB:
        print(*ans)
    else:
        print(-1)
else:
    print(-1)

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

#define ll long long
#define endl "\n"

void solve(){
  ll ans=0;
  ll n;
  cin >> n;
  ans=(1ll*1000*(n/500))+(1ll*5*((n%500)/5));
  cout << ans << endl;
}

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




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

int main() {
	double y;
	while(cin>>y){
	if (y<0) break;
	y=y*16;
	if(y-(int)y !=0 ) cout<<"NA"<<endl;
	else {
		int z=(int) y;
		if(z>8191) cout<<"NA"<<endl;
		else{
			for(int k=11;k>3;k--){
				int q=z>>k;
					q=q&1;
				cout<<q;
				
			}
			cout<<".";
			for(int k=3;k>-1;k--){
				int q=z>>k;
					q=q&1;
				cout<<q;
				
			}
			cout<<endl;
			
			
			
		}
		
		
		
	}
	
	



	}


}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
#define enl << endl
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int a, b;
    cin >> a >> b;
    if(a < 10 && b < 10){
        cout << a*b << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    c = [list(map(int, input().rstrip('\n').split())) for _ in range(3)]
    for i in range(3):
        m = min(c[i])
        for j in range(3):
            c[i][j] -= m
    for i in range(3):
        m = 10 ** 10
        for j in range(3):
            m = min(c[j][i], m)
        for j in range(3):
            c[j][i] -= m
    mt = 0
    for i in range(3):
        for j in range(3):
            mt = max(mt, c[i][j])
    print("Yes" if mt == 0 else "No")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include<functional>
#include <queue>

using namespace std;

struct Shop
{
	int price;
	int stock;
};

istream& operator>> (istream& is, Shop& o) {
	is >> o.price >> o.stock;
	return is;
}

int main()
{
	int shop_length, drink;
	cin >> shop_length >> drink;

	priority_queue < Shop, vector<Shop>, function<bool(const Shop&, const Shop&)>> shops(
		[](const Shop& a, const Shop& b){return a.price > b.price;}
	);

	for (int i = 0; i < shop_length; ++i)
	{
		Shop shop;
		cin >> shop;
		shops.push(shop);
	}
	
	uint64_t sum = 0;
	int remain = drink;



	while(remain > 0)
	{
		auto shop = shops.top();
		shops.pop();

		int bought = min(shop.stock, remain);
		sum += ((uint64_t)shop.price) * bought;

		remain -= bought;
		if (remain <= 0)
			break;
	}

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1400
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){  
	int n;
	cin>>n;
	map<string,int> f;
	rep(i,0,n){
		string s;
		cin>>s;
		sort(all(s));
		f[s]++;
	}  
	int ans=0;
	for(auto i:f){
		ans+=(i.S)*(i.S-1)/2;
	}
	cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}	

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

int main()
{
  ll n;
  cin >> n;
  vector<ll> v(n);
  rep(n) cin >> v[i];
  ll tmp = v[0];
  ll cnt = 0;
  rep(n)
  {
    if(tmp>=v[i])
    {
      tmp = v[i];
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;

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

    int k;
    cin >> k;
    cout << k/2 * ((k+1)/2) << '\n';
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
#define  endl '\n'
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll a[int(1e5) + 5];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == 0) return cout << 0, 0;
    }
    ll ans = 1, mx = ll(1e18);
    for (int i = 0; i < n; i++) {
        if (ans > (mx / a[i]))
            return cout << -1, 0;
        ans *= a[i];
    }
    cout << ans;


}

Measured memory_bytes: 4396
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W, K = MAP()
c = [list(input()) for _ in range(H)]

ans = 0
for y in product([0, 1], repeat=H):
    for x in product([0, 1], repeat=W):
        c_copy = deepcopy(c)
        for i in range(H):
            if y[i]:
                for j in range(W):
                    c_copy[i][j] = "R"
        for i in range(W):
            if x[i]:
                for j in range(H):
                    c_copy[j][i] = "R"
        cnt = 0
        for i in range(H):
            for j in range(W):
                if c_copy[i][j] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1

print(ans)


Measured memory_bytes: 10048
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int ans=0;
		for(int i=0;i<n;i++){
			int x=sc.nextInt();
			if(isPrime(x)) ans++;
		}
		System.out.println(ans);
	}
	static boolean isPrime(int x){
		for(int j=2;j<=Math.sqrt(x);j++){
			if(x%j==0){
				return false;
			}
		}
		return true;
	}

}

Measured memory_bytes: 44092
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7
    #epsilon = 10**-9

    d = int(input())
    c = list(map(int, input().split()))
    last = [0]*26
    s = [list(map(int, input().split())) for _ in range(d)]
    res = []

    def scoring(last, n):
        score = -10**20
        # 開催するコンテスト
        for i in range(26):
            ans = 0
            ans += s[n][i]
            for j in range(26):
                if i == j:
                    continue
                ans -= c[j] * (n+1-last[j])
            if score < ans:
                score = ans
                contest = i

        return contest, last

    for i in range(d):
        contest, last = scoring(last, i)
        last[contest] = i + 1
        res.append(contest+1)

    for i in res:
        print(i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9876
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

bool BinarySearch(int a[], int key, int first, int last)
{
	if (first > last)
	{
		return false;
	}

	int middle = first + (last - first) / 2;

	if (a[middle] == key)
	{
		return true;
	}
	else if (a[middle] < key)
	{
		BinarySearch(a, key, middle + 1, last);
	}
	else
	{
		BinarySearch(a, key, first, middle - 1);
	}
}

int main()
{
	int n, q;
	int S[100000], T[50000];

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &S[i]);
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		scanf("%d", &T[i]);
	}

	int c = 0;
	for (int i = 0; i < q; i++)
	{
		if (BinarySearch(S, T[i], 0, n - 1))
		{
			c++;
		}
	}

	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    using R = double;

    int n, T, A; cin >> n >> T >> A;
    R mind = inf;

    int res = -1;
    rep(i, n){
        int h; cin >> h;
        if(chmin(mind, abs(A - (T - h * 0.006)))){
            res = i + 1;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int main(){

	int N,left,right,maximum;
	scanf("%d",&N);

	int* table = new int[100003];
	for(int i = 0; i <= 100002; i++){
		table[i] = 0;
	}

	for(int i = 0; i < N; i++){
		scanf("%d %d",&left,&right);
		table[left]++;
		table[right+1]--;
	}

	maximum = 0;
	for(int i = 1; i <= N+1; i++){
		table[i] += table[i-1];
		if(table[i]+1 >= i){
			maximum = i;
		}
	}

	printf("%d\n",min(N,max(maximum-1,0)));

	return 0;
}

Measured memory_bytes: 3076
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int V[n+10], C[n+10];
  for(int i = 0; i < n; i++)cin >> V[i];
  for(int i = 0; i < n; i++)cin >> C[i];

  int value = 0;
  for(int i = 0; i < n; i++){
    if( V[i] - C[i] > 0) value +=  V[i] - C[i];
  }
  cout << value <<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v(3);
  for (int i = 0; i < 3; ++i) cin >>v[i];
  if (v[1] == v[2]) cout << v[0] << endl;
  if (v[0] == v[2]) cout << v[1] << endl;
  if (v[0] == v[1]) cout << v[2] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int main()
{
	string s;
	cin >> s;
	if (s[s.size() - 1] == 's') {
		s += "e";
	}
	s += "s";
	printf("%s", s.c_str());

	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n;
  cin>>n;
  string a,b,c;
  cin>>a>>b>>c;
  
  ll ans=0;
  REP(i,n){  
    map<ll,ll> m;
    m[a[i]-'a']+=1;
    m[b[i]-'a']+=1;
    m[c[i]-'a']+=1;
    
    ll h=0;
    REP(j,26)
      h=max(h,m[j]);
    ans+=3-h;
    //cout<<n-h<<endl;
  }
  
  cout<<ans<<endl;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n;
    cin >> n;
    int t[n + 1];
    FOR(i, 1, n) cin >> t[i];
    int m;
    cin >> m;
    FOR(i, 1, m)
    {
        int p, x, pre;
        int ans = 0;
        cin >> p >> x;
        pre = t[p];
        t[p] = x;
        FOR(j, 1, n) ans += t[j];
        cout << ans << '\n';
        t[p] = pre;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		String S = sc.next();
		int count = 0;
		for (int i = 0; i < 10; i++) {
			int first = S.indexOf('0' + i);
			if (first < 0 || first > S.length() - 3) continue;
			for (int j = 0; j < 10; j++) {
				int second = S.indexOf('0' + j, first + 1);
				if (second < 0|| second > S.length() - 2) continue;
				for (int k = 0; k < 10; k++) {
					int third = S.indexOf('0' + k, second + 1);
					if (third < 0) continue;
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 23124
/*
▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
 
*/
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <tuple>
#include <random>
 
using namespace std;


#define ll long long
#define ld double
#define null NULL
#define prev prev228
#define index index228
#define left left228
#define right right228
#define hash hash228
#define y0 y0228
#define firn(i, n) for (int i = 0; i < (int)n; ++i)
#define forn(i, n) for (int i = 1; i <= (int)n; ++i)



template<typename T> inline void uin(T &a, T b) {
    if (b < a) a = b;
}

template<typename T> inline void uax(T &a, T b) {
    if (b > a) a = b;
}


const int n = 100;


char ans[n][n];



bool check(int i, int j, char c) {
    if (ans[i][j] != c && ans[i - 1][j] != c && ans[i + 1][j] != c && ans[i][j - 1] != c && ans[i][j + 1] != c && ans[i - 1][j - 1] != c && ans[i - 1][j + 1] != c && ans[i + 1][j - 1] != c && ans[i + 1][j + 1] != c) {
        return true;
    }
    return false;
}


signed main() {
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    forn(i, n / 2) {
        forn(j, n) {
            ans[i][j] = '.';
        }
    }
    for (int i = n / 2 + 1; i <= n; ++i) {
        forn(j, n) {
            ans[i][j] = '#';
        }
    }
    int fir = 1, sec = 1;
    while (fir < a) {
        bool good = false;
        for (int i = n / 2 + 2; i < n; ++i) {
            for (int j = 2; j < n; ++j) {
                if (check(i, j, '.')) {
                    ans[i][j] = '.';
                    ++fir;
                    good = true;
                    break;
                }
            }
            if (good) break;
        }
        if (fir == a) break;
    }
    while (sec < b) {
        bool good = false;
        for (int i = 2; i < n / 2; ++i) {
            for (int j = 2; j < n; ++j) {
                if (check(i, j, '#')) {
                    ans[i][j] = '#';
                    ++sec;
                    good = true;
                    break;
                }
            }
            if (good) break;
        }
        if (sec == b) break;
    }
    cout << n << " " << n << "\n";
    forn(i, n) {
        forn(j, n) {
            cout << ans[i][j];
        }
        cout << '\n';
    }
    return 0;
}









Measured memory_bytes: 256
# loop {
  r,c = gets.split.map(&:to_i)
  line         = Array.new
  sum_side     = Array.new
  sum_vertical = Array.new
  sum_side_num     = 0
  sum_vertical_num = 0
  sum_final_vertical = 0
  (0..(r - 1)).each{|r|
    line[r] = gets.split.map(&:to_i)
  }

  (0..(r - 1)).each{|r|
    (0..(c - 1)).each{|c|
      print "#{line[r][c]} "
    }
    # 横の列の合計
    puts sum_side[r] = line[r].inject{|sum, n| sum + n}
    sum_side_num += sum_side[r]
  }

  (0..(c - 1)).each{|c|
    (0..(r - 1)).each{|r|
      sum_vertical_num += line[r][c]
    }
    print "#{sum_vertical_num} "
    sum_final_vertical += sum_vertical_num
    sum_vertical_num = 0
  }
  puts sum_side_num 
# }





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

using namespace std;

/*helpfull*/
using vl  = vector<long long>;
using vpl = vector<pair<long long, long long>>;
using vs = vector<string>;
using pl  = pair<long long, long long>;
using ll  = long long int;
using vb  = vector<bool>;


struct hash_pair {
	template <class T1, class T2>
	size_t operator()(const pair<T1, T2>& p) const
	{
		auto hash1 = hash<T1> {}(p.first);
		auto hash2 = hash<T2> {}(p.second);
		return hash1 ^ hash2;
	}
};
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

// shortcut macros
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp              make_pair
#define fi              first
#define se              second
// #define mt              make_tuple
#define pb              push_back
#define all(x)          (x).begin(), (x).end()
#define ini(a, v)       memset(a, v, sizeof(a))
#define rep(i, a, n)    for(ll i=a ; i<n ; ++i)
#define For(i, n)       rep(i, 0, n)
#define sz(x)           (int((x).size()))
#define ump(x,y)        unordered_map<x,y>
#define umpr(x,y,z)     unordered_map<x,y,z>
void printcase(ll &x) {
	cout << "Case #" << x << ": ";
}
void read(vector<ll>&v, ll &n) {
	For(i, n)
	cin >> v[i];
}
void read(ll &x) {
	cin >> x;
}
void read(string &s) {
	cin >> s;
}
void read(int &x) {
	cin >> x;
}
void read(ll a[], ll &n) {
	For(i, n)
	cin >> a[i];
}
void print() {
	cout << endl;
}
void write(vector<ll>&v, ll &n) {
	For(i, n)
	cout << v[i] << " ";
	cout << endl;
}
void write(vector<ll>&v) {
	ll n = v.size();
	For(i, n)
	cout << v[i] << " ";
	cout << endl;
}
void write(ll x) {
	cout << x << endl;
}
void write(string &s) {
	cout << s << endl;
}
void write(int &x) {
	cout << x << endl;
}
void write(ll a[], ll &n) {
	For(i, n)
	cout << a[i] << " ";
	cout << endl;
}

// ll solve() {
// 	ll n, k;
// 	cin >> n >> k;
// 	vl v(n);
// 	read(v, n);
// 	if (k == 0)
// 		return *max_element(all(v));
// 	sort(all(v));
// 	vector<ll > d(n, k / n);

// 	for (int i = 0; i < n; i++) {

// 	}

ll solve(ll k) {
	ll i = 0;
	ll c = 0;
	ll n = 1e8;
	ll prev = -1;
	while (n--) {
		++c;
		i = (i * 10 + 7) % k;
		if (i == prev)
			return -1;
		if (i == 0)
			return c;
		prev = i;
	}
	return -1;
}



// return 1;
// }
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	IOS;
	ll k;
	cin >> k;
	cout << solve(k) << endl;
	return 0;
}




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

#define int long long
using namespace std;

int n;
int num[400][400];
int rui[400][400];

int solve(int l, int r){
	int dp[400];
	dp[n-1] = INT_MIN;
	
	if(l == r){
		for(int i = n-2;i >= 0;i--){
		 	dp[i] = max(num[i+1][l], dp[i+1] + num[i+1][l]);
		 }
	}else{
		for(int i = n-2;i >= 0;i--){
			dp[i] = max(rui[i+1][r+1]-rui[i+1][l], dp[i+1] + num[i+1][r] + num[i+1][l]);
		}
	}
	
	int ans = INT_MIN;
	for(int i = 0;i < n;i++){
		int tmp = rui[i][r+1]-rui[i][l];
		ans = max({ans, tmp, tmp + dp[i]});
	}
	
	return ans;
}

signed main(){
	cin >> n;
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			cin >> num[i][j];
			rui[i][j+1] += rui[i][j] + num[i][j];
		}
	}
	
	int ans = INT_MIN;
	for(int i = 0;i < n;i++){
		for(int j = i;j < n;j++){
			ans = max(ans, solve(i, j));
		}
	}
	
	cout << ans << endl;
	
	return 0;
}
			



Measured memory_bytes: 4964
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] a = new int[n];
		for ( int i=0; i<n; i++ ) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		boolean[] b = new boolean[a[n-1]+1];
		Arrays.fill(b, true);

		for ( int i=0; i<n; i++ ) {
			if ( b[a[i]] ) {
				int f = a[i]*2;
				while ( f<=a[n-1] ) {
					b[f] = false;
					f += a[i];
				}
			}
		}

		int t = 0;
		for ( int i=0; i<n; i++ ) {
			if ( (i>0 && a[i]==a[i-1]) || (i<n-1 && a[i]==a[i+1]) ) continue;
			if ( b[a[i]] ) t++;
		}

		System.out.println(t);
	}
}

Measured memory_bytes: 61440
N, K =  map(int, input().split())
A = list(map(int, input().split()))

p1 = A.index(1) + 1

l = (p1-1) // (K-1)
r = (N-p1) // (K-1)
amari = N - l*(K-1) - r*(K-1)

if N == K:
    ans = 1
elif N <= 2*K-1:
    ans = 2
elif amari == 1:
    ans = l + r
elif amari <= K:
    ans = l + r + 1
else:
    ans = l + r + 2
print(ans)

Measured memory_bytes: 14008
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  if (a < b) {
    return b - a;
  } else {
    return a - b;
  }
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a) {
    a = b;
  }
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b) {
    a = b;
  }
}
template <class F> class fix_point : private F {
public:
  explicit constexpr fix_point(F &&f) : F(std::forward<F>(f)) {}

  template <class... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};
template <class F> constexpr decltype(auto) make_fix(F &&f) {
  return fix_point<F>(std::forward<F>(f));
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const u64 n = scan<u64>();
  const u64 a = scan<u64>() - 1;
  const u64 b = scan<u64>() - 1;
  if (a % 2 == b % 2) {
    std::cout << difference(a, b) / 2 << std::endl;
  } else {
    const u64 x = (a + b + 1) / 2;
    const u64 y = (n - 1 - a + n - 1 - b + 1) / 2;
    std::cout << std::min(x, y) << std::endl;
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
n, *A = map(int, open(0).read().split())
if A[0] != 0:
    if A[0] == 1 and n == 0:
        print(1)
    else:
        print(-1)
else:
    B = list(accumulate(A[::-1]))[::-1]
    C = [1] * (n+1)
    D = [1] * (n+1)

    for i in range(1, n+1):
        C[i] = min(B[i], 2*D[i-1])
        D[i] = C[i] - A[i]
        if D[i] < 0:
            print(-1)
            break
    else:
        print(sum(C))

Measured memory_bytes: 26248
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    long long  N,M; cin>>N>>M;
    vector<vector<long long>> A(N, vector<long long>(2));
    for(size_t i = 0; i < A.size(); i++){
        cin>>A[i][0]>>A[i][1];
    }
    sort(A.begin(),A.end());
    long long money = 0;
    int index = 0;
    int sumNumber = 0;
    while (sumNumber<M){
        if(M - sumNumber - A[index][1] > 0){
            money += A[index][0] * A[index][1];
            sumNumber += A[index][1];
        }
        else{
            money += A[index][0] * (M-sumNumber);
            sumNumber += (M-sumNumber);
        }
        index += 1;
    }
    cout<<money;
}


Measured memory_bytes: 5760
S = input()
T = input()
alp = [chr(ord('a') + i) for i in range(26)]
kanri = [0]*26
flag = True
for i in range(len(S)):
  x = S[i]
  f = ord(x)-97
  if kanri[f] == 0:
    kanri[f] = T[i]
  else:
    if kanri[f] != T[i]:
      flag = False
      break
if flag:
  P = []
  for i in range(26):
    if kanri[i] != 0:
      P.append(kanri[i])
  Q = list(set(P))
  if len(Q) == len(P):
    print('Yes')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
const int maxn=2e5+7;
const ll modn=1e9+7;
const int inf=2e9+7;
const double PI = acos(-1.0);
const double eps=1e-8;
inline int lowbit(int x){return x&-x;}
inline ll lowbit(ll x) {return x&-x;}
inline int CountOneBinary(ll num){int ans=0;while(num){if(num&1) ans+=1;num>>=1;}return ans;}
inline void read(int &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline void read(ll &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline ll qpow(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%modn;x=x*x%modn;y>>=1;}return ans;}
inline double qpow(double x,ll y){double ans=1;while(y){if(y&1) ans=ans*x;x=x*x;y>>=1;}return ans;}
ll n,top,bot;
int main()
{
    while(scanf("%lld",&n)==1)
    {
        top=bot=-1;
        for(int i=0;i<n;i++)
        {
            ll tmp;
            scanf("%lld",&tmp);
            if(top==-1)top=bot=tmp;
            else
            {
                top=max(top,tmp);
                bot=min(bot,tmp);
            }
        }
        printf("%lld\n",top-bot);
    }
    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int h,w;
string s[1001];
int dist[1001][1001];

int mr[] = {-1,1,0,0};
int mc[] = {0,0,1,-1};

int main(){
  cin >> h >> w;
  int sr,sc,gr,gc; cin >> sr >> sc >> gr >> gc;
  sr--;sc--;gr--;gc--;
  for(int i = 0; i < h; ++i)
    cin >> s[i];
  Fill(dist,1001001001);

  queue<tuple<int,int,int>> que1;
  queue<tuple<int,int,int>> que2;
  que1.emplace(sr,sc,0);
  while(!que1.empty() || !que2.empty()){
    if(que1.empty()){
      while(!que2.empty()){
	auto [r,c,d] = que2.front();
	que2.pop();
	if(dist[r][c] <= d)continue;
	que1.emplace(r,c,d);
      }
    } else {
      auto [r,c,d] = que1.front();
      que1.pop();
      if(dist[r][c] <= d)continue;
      dist[r][c] = d;
      for(int i = 0; i < 4; ++i){
	auto [nr,nc,nd] = make_tuple(r+mr[i],c+mc[i],d);
	if(nr < 0 || nc < 0 || nr >= h || nc >= w)continue;
	if(s[nr][nc] == '#')continue;
	que1.emplace(nr,nc,nd);	
      }
      for(int i = -2; i <= 2; ++i){
	for(int j = -2; j <= 2; ++j){
	  auto [nr,nc,nd] = make_tuple(r+i,c+j,d+1);
	  if(nr < 0 || nc < 0 || nr >= h || nc >= w)continue;
	  if(s[nr][nc] == '#')continue;
	  que2.emplace(nr,nc,nd);		  
	}
      }
    }
  }
  cout << (dist[gr][gc] == 1001001001 ? -1 : dist[gr][gc]) << endl;
  return 0;
}


Measured memory_bytes: 10788
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int main(){
    int A,B,ans=0;
    cin >> A >> B;
    ans = A + B;
    if(ans < A - B)ans = A - B;
    if(ans < A * B)ans = A * B;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = 0;
    rep(i,3001) {
        if (i * a > d)
        {
            break;
        }
        rep(j,3001){
            if (i * a + j * b > d)
            {
                break;
            }
            if ((d - i * a - j * b) % c == 0)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    a: [usize1; n],
  }
  let mut popl = vec![0i64; n];
  for &x in &a {
    popl[x] += 1;
  }
  let mut all = 0;
  for i in 0 .. n {
    all += popl[i] * (popl[i] - 1) / 2;
  }
  for i in 0 .. n {
    puts!("{}\n", all - popl[a[i]] + 1);
  }
}


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

int main(){
  long n,m,k;
  double a,nd,md,kd,ld,p;
  cin >> n >> k;
  nd = n;
  kd = k;
  for(double i = 1; i < n+1; i++){
    m = log2(kd/i) +1;
    ld=log2(kd/i) +1;
    md = m;
    if(ld * 10 == md *10)
      md--;
   if(i < k)
     a += pow(0.5,md);
    else
      a += 1;
  }
  p = a / n;
  cout << setprecision(15) << p << endl;

  
}

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

#define rep(i,n) for(i=0;i<(n);i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

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

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
	cin.tie(0);	ios::sync_with_stdio(false);

  int i,j;
  int A,B,M; cin >> A >> B >> M;
  int a[A],b[B];
  int c,x,y;
  int minA=1000000,minB=1000000;
  int ans = 0;
  rep(i,A){cin >> a[i];if(minA>a[i]){minA=a[i];}}
  rep(i,B){cin >> b[i];if(minB>b[i]){minB=b[i];}}
  ans = minA+minB;
  rep(i,M){
      cin >> x >> y >> c;
      int tmp = a[x-1] + b[y-1] - c;
      ans = min(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4408
#include<cstdio>

int n;
int h[101];
int arr[100];

int main(){
	while(1) {
		scanf("%d", &n);

		if( n == 0 ) break;
		
		for( int i = 0; i < n + 1; ++i ) {
			scanf("%d", &h[i]);
		}
		
		int ans = -1;
		for( int i = 0; i < n + 1; ++i ) {
			for( int j = 0; j < n + 1; ++j ) {
				if( i==j ) continue;
				arr[j - (j>i)] = h[j];
			}
			int d = arr[1] - arr[0];
			bool flag = true;
			for( int j = 1; j < n; ++j ) {
				flag &= (arr[j]-arr[j-1])==d;
			}
			if(flag) {
				// 3
				// 1 2 3 5
				// printf("%d\n", h[i]);
				ans = h[i];
			}
		}
		
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1028
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
 
const int MAXN = 1e6 + 10;
int N;
char S[MAXN], T[MAXN];
int q[MAXN], ql, qr;
int ans;
 
int main() {
	register int i, j;
	scanf("%d%s%s", &N, S + 1, T + 1);
	j = N; ql = 1, qr = 0;
	bool ok = 1;
	for(i = 1; i <= N; ++i)
		ok &= S[i] == T[i];
	if(ok)
		return puts("0"), 0;
	for(i = N; i; --i) {
		if(T[i] == T[i - 1]) continue;
		j = min(j, i);
		while(j && T[i] != S[j]) --j;
		if(j == 0) return puts("-1"), 0;
		while(ql <= qr) {
			if(q[ql] - (qr - ql + 1) + 1 > i) ++ql;
			else break;
		}
		q[++qr] = j;
		if(i != j) ans = max(ans, (qr - ql + 1));
	}
	printf("%d\n", ans + 1);
	return 0;
}

Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,mn=200000,ans=0,tmp;
    cin >> n;
    rep(i,n){
        cin >> tmp;
        ans+=(mn>=tmp);
        mn=min(mn,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 380