akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100005
#define M 200005
#define LL long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mi d + 1, r
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
inline int sgn(double x){return (x > EPS) - (x < -EPS);}
int n, h, w;
int c[11000];
int a[110][110];
int main(){
    //IN;
    SCC(h, w);
    SC(n);
    FF(i, 1, n){
        SC(c[i]);
    }
    int x = 1, y = 1;
    FF(i, 1, n){
        FF(j, 1, c[i]){
            a[x][y] = i;
            if(x & 1){
                y = y + 1;
                if(y > w){
                    y = w;
                    ++x;
                }
            }else {
                y = y - 1;
                if(y == 0){
                    y = 1;
                    ++x;
                }
            }
        }
    }
    FF(i, 1, h){
        FF(j, 1, w) printf("%d%c", a[i][j], j == w ? '\n' : ' ');
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N;
    cin >> N;
    vector<pair<pair<string,ll>,ll>> P(N);
    REP(i,0,N) {
        string s;
        ll p;
        cin >> s >> p;
        P[i] = make_pair(make_pair(s, -p), i + 1);
    }

    sort(ALL(P));
    REP(i,0,N) _PR(P[i].second);



    return 0;
}

/*



*/

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int m,n,l,a,s,d,t=10000;
    while(~scanf("%d%d%d",&m,&n,&l))
    {
        a=m+n;
        s=n+l;
        d=l+m;
        if(t>a) t=a;
        if(t>s) t=s;
        if(t>d) t=d;

        printf("%d\n",t);
    }
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


int dfs(int n, V<int> &dp, const VV<int> &p) {
    if (dp[n] != -1) {
        return dp[n];
    }
    int ans = 0;
    FOR(i, 0, p[n].size()) {
        chmax(ans, dfs(p[n][i], dp, p) + 1);
    }
    return dp[n] = ans;
}

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

	int N, M;
	cin >> N >> M;
	VV<int> c(N), p(N);
	FOR(i, 0, M) {
	    int a, b;
	    cin >> a >> b;
	    a--; b--;
	    c[a].emplace_back(b);
	    p[b].emplace_back(a);
	}

	V<int> goal;
	FOR(i, 0, N) {
	    if (c[i].size() == 0) {
	        goal.emplace_back(i);
	    }
	}

	int ans = 0;
	V<int> dp(N, -1);
	FOE(g, goal) {
        chmax(ans, dfs(g, dp, p));
    }
    print(ans);

	return 0;
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define print2(a, b) cerr << "(" << a << "," << b << ")" << endl
#define print3(a, b, c) cerr << "(" << a << "," << b << "," << c << ")" << endl


void solve(long long N, long long M, std::vector<long long> A){
    ll sum = 0;
    map<ll, ll> occur;
    occur[0] = 1;
    for (ll i = 0; i < N; i++) {
        sum = (sum + A[i]) % M;
        occur[sum] = occur[sum] + 1;
    }
    ll res = 0;
    //for (const auto& [key, value] : occur) {
    for (auto iter = occur.begin(); iter != occur.end(); iter++) {
        ll value = iter->second;
        res += value * (value-1) / 2;
    }
    cout << res << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,m;
ll a[100010];
ll d[100010];
int main(){
	scanf("%lld%lld",&n,&m);
	a[0]=1;
	rep(i,0,m)scanf("%lld",d+i);
	ll crr=0;
	rep(i,1,n+1){
		if(d[crr]==i){
			crr++;
		}else{
			if(i==1)a[i]=a[i-1];
			if(i!=1)a[i]=(a[i-1]+a[i-2])%MOD;
		}
	}
	printf("%lld ",a[n]);
}

Measured memory_bytes: 1408
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
L = [LIST() for i in range(M)]

num = [1] * N
red = [False] * N
red[0] = True

for a, b in L:
    if num[a-1] == 0:
        # 水がない
        red[a-1] = False
        continue
    else:
        num[b-1] += 1
        num[a-1] -= 1
        red[b-1] = red[b-1] or red[a-1]
        if num[a-1] == 0:
            red[a-1] = False
    
print(sum(red))
# print(sum(num))



Measured memory_bytes: 29588
n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
print(sum(c[:-1]))
e=[[]for _ in[0]*n]
for a,b in zip(t[:-n:2],t[1:-n:2]):e[a-1]+=b-1,;e[b-1]+=a-1,
f=[0]*n
q=[0]
while q:
 v=q.pop();f[v]=c.pop()
 for w in e[v]:q+=[w]*(f[w]<1)
print(*f)

Measured memory_bytes: 6692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
const ll mod = 1e9+7;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int N, K;
    cin >> N >> K;
    ll ans = 0;
    //vector<int> A(M);
    rep(k, N + 1 - K + 1){
        //cout << k << " " << k * N + 1 - k * (k - 1) << endl;
        //ans += k * N + 1 - k * (k - 1);
        //ans += k * (N - k + 1) + 1;
        ll tmp =  ((ll)k * (N - (ll)k + 1)) %mod;
        (tmp += 1) %= mod;
        (ans += mod + tmp) %= mod;
    }
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void){
	int A, B, K;
	scanf("%d %d", &A, &B);
	if ((A+B) % 2 == 0){
		printf("%d\n", (A+B)/2);
	} else{
		printf("IMPOSSIBLE\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
typedef long long ll;
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
long long modpow(long long a,long long n,long long p)
{
    if(n==1)
    {
        return a%p;
    }
    if(n%2==1)
    {
        return a*modpow(a,n-1,p)%p;
    }
    long long t = modpow(a,n/2,p);
    return t*t%p;
}
int main()
{
    /*A
    int n,k;
    cin>>n>>k;
    vector <char> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    a[k-1]=a[k-1]+32;

    rep(i,n)
    {
        cout<<a[i];
    }
    cout<<endl;
    */
    int s;
    cin>>s;
    

    int L = s/100;
    int R = s%100;

    if(L>=1 && L<=12)
    {
        if(R>=1 && R<=12)
        {
            cout<<"AMBIGUOUS"<<endl;
        }
        else
        {
            cout<<"MMYY"<<endl;
        }
    }
    else
    {
        if(R>=1 && R<=12)
        {
            cout<<"YYMM"<<endl;
        }
        else
        {
            cout<<"NA"<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

ll k;
string s;
string ans;

void solve() {
	for (int i = 0; i < s.size(); i++) {
		int x = s[i] - 'a';
		if (x != 0 && 26 - x <= k) {
			k -= 26 - x;
			ans += 'a';
		} else {
			ans += s[i];
		}
		//cout << ans << " " << k << endl;
	}
	k %= 26;
	int y = ans[(int)ans.size() - 1] - 'a';
	y = (y + k) % 26;
	ans[(int)ans.size() - 1] = 'a' + y;
	cout << ans << endl;
}

int main() {
	cin >> s;
	cin >> k;
	solve();
	return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const int INF = 1001001001;

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  string s;
  cin >> s;
  int n = s.length();
  reverse(all(s));
  vector<vector<int> > dp(n+5, vector<int>(2,INF));
  int x = s[0] - '0';
  dp[0][0] = x;
  dp[0][1] = 1+(10-x);
  for (int i = 1; i < n; ++i) {
    x = s[i] - '0';
    chmin(dp[i][0], dp[i-1][0] + x);
    chmin(dp[i][0], dp[i-1][1] + x);
    chmin(dp[i][1], dp[i-1][0] + 1+(10-x));
    chmin(dp[i][1], dp[i-1][1]-1 + 1+(10-(x+1)));
  }
  cout << min(dp[n-1][1], dp[n-1][0]) << endl;
  return 0;
}

Measured memory_bytes: 55964
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<vi> vii;

const int IMAX = ((1 << 30) - 1) * 2 + 1;
const int INF = 100000000;
const double EPS = 1e-10;
//int mod=1000000007




string str = "qwertasdfgzxcvb";



int main(){
	map<char, int> m;
	for (int i = 0; i < str.size(); i++){
		m[str[i]] = 1;
	}
	string s;
	while (cin >> s){
		if (s == "#") break;
		int ans = 0, flag = m[s[0]];
		for (int i = 1; i < s.size(); i++){
			if (flag != m[s[i]]){
				ans++;
				flag = (flag + 1) % 2;
				//cout << i;
			}
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 1192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] o = in.nextString().toCharArray();
			char[] e = in.nextString().toCharArray();

			int len1 = o.length;
			int len2 = e.length;

			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < len1; i++) {

				sb.append(o[i]);
				if (len1 != len2 && i == len1-1) {
					continue;
				}
				sb.append(e[i]);
			}

			out.println(sb.toString());

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
#人の（ほぼ同じなのにうまくいかないので）
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
lines = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    lines[a-1].append(b-1)
    lines[b-1].append(a-1)
ans = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

def dfs(v, parent):
    for u in lines[v]:
        if u != parent:
            ans[u] += ans[v]
            dfs(u, v)

dfs(0, -1)
print (*ans)


Measured memory_bytes: 230960
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32();
            var H = line[0];
            var W = line[1];
            line = consoleReader.SplitInt32();
            var h = line[0];
            var w = line[1];

            return H * W - (h * W + w * (H - h));
        }

        const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader
    {
        public virtual string String() => Console.ReadLine();
        public int Int32() => int.Parse(String());
        public long Int64() => long.Parse(String());
        public ulong UInt64() => ulong.Parse(String());
        public double Double() => double.Parse(String());
        public string[] Split() => String().Split().ToArray();
        public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray();
        public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray();
        public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray();
        public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray();

        public IEnumerable<string> Repeat(int count)
        {
            for (int i = 0; i < count; i++)
                yield return String();
        }
        public IEnumerable<int> RepeatInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int32();
        }
        public IEnumerable<long> RepeatInt64(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int64();
        }
        public IEnumerable<string[]> RepeatSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Split();
        }
        public IEnumerable<int[]> RepeatSplitInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return SplitInt32();
        }
    }
}


Measured memory_bytes: 13268
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())

using namespace std;
using ll = int64_t;

int N, Q;
string S;
vector<int> positions[26];
vector<pair<char, int>> queries;

bool left_out(int p) {
  for (auto q : queries) {
    if (S[p] == q.fi)
      p += q.se;
    if (p < 0)
      return true;
    if (p >= N)
      return false;
  }
  return false;
}

bool right_out(int p) {
for (auto q : queries) {
    if (S[p] == q.fi)
      p += q.se;
    if (p >= N)
      return true;
    if (p < 0)
      return false;
  }
  return false;
}

int left(int x) {
  int l = -1, r = sz(positions[x]);
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (left_out(positions[x][m]))
      l = m;
    else
      r = m;
  }
  return r;
}

int right(int x) {
  int l = -1, r = sz(positions[x]);
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (right_out(positions[x][m]))
      r = m;
    else
      l = m;
  }
  return l;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N >> Q;
  cin >> S;
  for (int i = 0; i < N; i++) {
    int j = S[i] - 'A';
    positions[j].pb(i);
  }
  queries.resize(Q);

  for (int i = 0; i < Q; i++) {
    char c, d;
    cin >> c >> d;
    queries[i] = {c, d == 'L' ? -1 : 1};
  }

  int ans = 0;
  for (int i = 0; i < 26; i++) {
    ans += max<int>(0, right(i) - left(i) + 1);
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3340
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(b/a,c) << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <sstream>
using namespace std;

#define ll long long
#define ld long double
#define pi 3.14159265359;
// %llu %lf

// v:vector  type:型  order:greater(大きい順) or less(小さい順)
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最小値( return ite )
#define _min_element(v) min_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 特定コンテナの中から特定の値をカウントする
#define _count(v,value) count(v.begin(),v.end(),value)

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//                                                              member.emplace(2)とかも同じ
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
template<typename T>
static T _abs(const T x) { return  (x > 0 ? x : -x); }

// 最大公約数
int64_t gcd(int64_t a, int64_t b) { while (b) { int64_t c = b; b = a % b; a = c; } return a; }
// 最小公倍数
int64_t lcm(int64_t a, int64_t b) { if (!a || !b) return 0; return a * b / gcd(a, b); }

// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);

// ■
// UINT32_MAX
// 4294967295 ≒ 4 * 1e9

// ■
// 割り算した結果との比較での丸め対処時 
// ABC 161 B
// https://atcoder.jp/contests/abc161/tasks/abc161_b
// double   border = _sum(v, 0 / (double)(4 * m);
//            ↓
// uint32_t border = (_sum(v, 0) + (4 * m) - 1) / (4 * m);

// ■
// N の数が与えられた場合の組合せ N * (N - 1) / 2



/*
*/
// ABC 153 A
// https://atcoder.jp/contests/abc153/tasks/abc153_a

int main()
{
	int32_t h, a;

	cin >> h >> a;


	printf("%d\n", h / a + ((h % a) ? 1:0));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int n,k,rel=0; cin >> n >> k;
    rep(i, n){
        int a; cin >> a;
        if(a <= k/2) rel += a * 2;
        else rel += (k - a) * 2;
    }
    cout << rel << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

int main(void)
{
    int n, x;
    char m[2];
    vector<bool> s(13, false), h(13, false), c(13, false), d(13, false);
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%s %d", m, &x);
        switch(m[0])
        {
        case 'S':
            s[--x] = true;
            break;
        case 'H':
            h[--x] = true;
            break;
        case 'C':
            c[--x] = true;
            break;
        case 'D':
            d[--x] = true;
            break;
        }
    }
    for(int i=0; i<13; i++)
        if(s[i]==false) printf("S %d\n", i+1);
    for(int i=0; i<13; i++)
        if(h[i]==false) printf("H %d\n", i+1);
    for(int i=0; i<13; i++)
        if(c[i]==false) printf("C %d\n", i+1);
    for(int i=0; i<13; i++)
        if(d[i]==false) printf("D %d\n", i+1);
    
    return 0;
}


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

using ll = long long;
const int INF = 1e9+7;

void solve(){
	int l,r,d,ans=0;cin >> l >> r >> d;
	for(int i = l;i<=r;++i){
		if(i%d==0)
			ans++;
	//	cout << d << ' ' << i << '\n';
	}
	cout << ans << '\n';			
}

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

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr char sp=' ';
constexpr ll mod=1000000007;

int N,X[100],res;

int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>X[i];
	}
	res=1e9;
	for(int i=1;i<=100;i++){
		int c=0;
		for(int j=0;j<N;j++){
			c+=(X[j]-i)*(X[j]-i);
		}
		res=min(res,c);
	}
	cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h){
    rep(j, w){
      int in;
      cin >> in;
      a.at(i).at(j) = in;
    }
  }
  vector<tuple<int, int, int, int>> ans;
  rep(i, h){
    rep(j, w){
      if(a.at(i).at(j) % 2 == 1){
        if(j != w-1){
          ans.push_back(make_tuple(i+1, j+1, i+1, j+2));
          a.at(i).at(j+1)++;
        }else if(i != h-1){
          ans.push_back(make_tuple(i+1, j+1, i+2, j+1));
          a.at(i+1).at(j)++;
        }
      }
    }
  }
  cout << ans.size() << endl;
  for(auto t : ans){
    auto [a, b, c, d] = t;
    cout << a << " " << b << " " << c << " " << d << endl;
  }
  return 0;
}

Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i=0; i<N; i++){
    cin >> P.at(i);
  }
  vector<int> Q(N);
  for(int i=0; i<N; i++){
    cin >> Q.at(i);
  }
  int p = -1;
  int q = -1;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    vec.at(i) = i+1;
  }
  int cnt = 1;
  do{
    if(vec == P){
      p = cnt;
    }
    if(vec == Q){
      q = cnt;
    }
    cnt++;
  }
  while(next_permutation(vec.begin(),vec.end()));
  cout << abs(p-q) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
int n,m,dis[1005][1005];
char s[1005][1005];
queue<int>qx,qy;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='#')
			{
				dis[i][j]=1;
				qx.push(i);
				qy.push(j);
			}
		}
	}
	int ans=1;
	while(!qx.empty())
	{
		int x=qx.front();
		int y=qy.front();
		qx.pop(),qy.pop();
		for(int k=0;k<4;k++)
		{
			int xx=x+dx[k],yy=y+dy[k];
			if(s[xx][yy]=='.')
			{
				s[xx][yy]='#';
				dis[xx][yy]=dis[x][y]+1;
				ans=max(ans,dis[xx][yy]);
				qx.push(xx),qy.push(yy);
			}
		}
	}
	printf("%d\n",ans-1);
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> V(N);
	for (int& i : V) cin >> i;
	vector<int> C(N);
	for (int& i : C) cin >> i;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += max(V[i] - C[i], 0);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

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(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int n=s.size();
	map<char,char> mp1,mp2;
	rep(i,n){
		if(mp1.count(s[i])){
			if(mp1[s[i]]!=t[i]){
				cout<<"No"<<endl;
				return 0;
			}
		}
		mp1[s[i]]=t[i];
		if(mp2.count(t[i])){
			if(mp2[t[i]]!=s[i]){
				cout<<"No"<<endl;
				return 0;
			}
		}
		mp2[t[i]]=s[i];
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 3780
#include<iostream>

using namespace std;

int main() {
	bool inputOver = false;
	char result = 'A';
	while (!inputOver) {
		int m, f, r;
		cin >> m >> f >> r;
		int sum = m + f;
		if (m == -1 && f == -1 && r == -1) {
			inputOver = true;
			break;
		}else{
			if (m==-1||f==-1) {
				result = 'F';
			}
			else if (sum>=80) {
				result = 'A';
			}
			else if (sum>=65&&sum<80)
			{
				result = 'B';
			}
			else if (sum >= 50 && sum<65)
			{
				result = 'C';
			}
			else if (sum >= 30 && sum<50)
			{
				result = 'D';
				if (r >= 50)
					result = 'C';
			}
			else if (sum < 30) {
				result = 'F';
			}

			cout << result << endl;
		
		}
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 3052
//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;
const int MAXM = 13;
const int MOD = 1e9 + 7;

int memo[MAXN][MAXM];

string S;
int n;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

int solve(int pos, int mod) {
	if(pos == n)
		return mod == 5;
	
	if(memo[pos][mod] != -1)
		return memo[pos][mod];
	
	int res = 0;
	if(S[pos] == '?') {
		for(int i = 0; i <= 9; i++)
			res = (res + solve(pos + 1, (mod * 10 + i) % MAXM)) % MOD;
	}
	else res = (res + solve(pos + 1, (mod * 10 + (S[pos] - '0')) % MAXM)) % MOD;
	
	return memo[pos][mod] = res;
}

int main() {
	fast_io();
//	freopen("input/ABC135D.txt", "r", stdin);
	
	cin >> S;
	
	n = S.length();
	memset(memo, -1, sizeof(memo));
	
	cout << solve(0, 0) << '\n';
	
	return 0;
}

Measured memory_bytes: 15032
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
const ll INF=2305843009213693951;//巨大な定数
const int dx[]={0,1,0,-1};//x方向のベクトル
const int dy[]={1,0,-1,0};//y方向のベクトル

int main(){
    //入力
    ll h,w,ch,cw,dh,dw;
    cin>>h>>w>>ch>>cw>>dh>>dw;
    vector<vector<char>> S(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>S[i][j];
        }
    }

    //1-indexedなので0-indexedに直す
    ch--;
    cw--;
    dh--;
    dw--;

    //01-BFS用のdeque
    deque<pll> Q;
    Q.emplace_front(ch,cw);

    //最低何回の魔法でたどり着けるかを記録する
    //巨大な数INFで初期化する
    vector<vector<ll>> T(h,vector<ll>(w,INF));

    //初期地点は0回の魔法でたどり着く
    T[ch][cw]=0;

    //BFSをする
    while(!Q.empty()){
        //現在の座標
        ll nh=Q.front().first;
        ll nw=Q.front().second;
        //queueから削除
        Q.pop_front();
        //移動A
        for(int i=0;i<4;i++){
            //移動先の座標
            ll th=nh+dx[i];
            ll tw=nw+dy[i];
            //範囲外になってないかチェック
            if(th>=h||th<0||tw>=w||tw<0){
                continue;
            }
            //壁かチェック
            if(S[th][tw]=='#'){
                continue;
            }
            //魔法の回数が多い場合更新
            if(T[th][tw]>T[nh][nw]){
                T[th][tw]=T[nh][nw];
                Q.emplace_front(th,tw);
            }
        }
        //移動B
        for(int i=-2;i<=2;i++){
            for(int j=-2;j<=2;j++){
                //移動先の座標
                ll th=nh+i;
                ll tw=nw+j;
                //範囲外になってないかチェック
                if(th>=h||th<0||tw>=w||tw<0){
                    continue;
                }
                //移動先が壁かチェック
                if(S[th][tw]=='#'){
                    continue;
                }
                //INFなら更新
                if(T[th][tw]==INF){
                    T[th][tw]=T[nh][nw]+1;
                    Q.emplace_back(th,tw);
                }
            }
        }
    }

    //ゴールに到達出来ない場合
    if(T[dh][dw]==INF){
        cout<<-1<<endl;
    }

    //到達できる場合
    else{
        cout<<T[dh][dw]<<endl;
    }
}

Measured memory_bytes: 12496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define MOD (ll)1000000007

signed main()
{
    IOS;
    char c;
    cin >> c;
    cout << (char)((int)c+1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V) for (auto v : (V)) cout << v << " "
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int A,B;
  cin >> A>>B;
  if (A<=8 && B<=8)print("Yay!");
  else print(":(");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;

int main(){
   int n,k;
   cin >> n >> k;
   vector<int> A(n);
   rep(i,n)cin >>A[i];
   rep(i,n-k){
      if(A[k+i]>A[i]) {
         cout<<"Yes" <<endl;
      } 
      else cout << "No" <<endl;
   }
}

Measured memory_bytes: 4048
n = int(input())
a = list(map(int, input().split()))
mc = 0
s = 0
m = float('inf')
for i in a:
  if i < 0:
    mc += 1
  s += abs(i)
  m = min(m, abs(i))
if mc % 2 == 0:
  print(s)
else:
  print(s -2 * m)


Measured memory_bytes: 14284
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "job.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,i;
long double x,d,s;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		d=1.0/x;
		s+=d;
	}
	s=1.0/s;
	cout<<fixed<<setprecision(5)<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define  REP(i, n) for(int i=0; i<(n); ++i)
#define  ALL(obj) (obj).begin(), (obj).end()
#define ll long long
#define ul unsigned long

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  --N;
  int B[N];
  FOR(i,0,N) cin >> B[i];
  int total = B[N-1];
  int A = total;
  for(int i=N-2;i>=0;--i)
  {
    total += A > B[i] ? B[i] : A;
    A = B[i];
  }
  total += A;
  cout << total << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++) 
#define FOR(i,ini,n) for(int i=(ini);i<(n);i++)
#define SZ(x) (int)x.size()

using namespace std;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int W,a,b;
	while(cin >> W >> a >> b){
		int l = min(a,b);
		int r = max(a,b);
		int ans  = max(0,r-l-W);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

int main(){
    int N, M, C;
    std::cin >> N >> M >> C;

    int B[M], A[N][M];
    for(int i = 0; i < M; i++){
        std::cin >> B[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M;j++){
            std::cin >> A[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < N; i++){
        int sum = 0;
        for(int j = 0; j < M;j++){
            sum += A[i][j]*B[j];
        }
        if(sum + C > 0)ans++;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
s=list(input())
t=list(input())

checkDict={}
checkDict2={}
flg="Yes"

for i in range(len(s)):

  if(not(s[i] in checkDict.keys())):
    checkDict[s[i]]=t[i]
  else:
    if(checkDict[s[i]]!=t[i]):
      flg="No"

  if(not(t[i] in checkDict2.keys())):
    checkDict2[t[i]]=s[i]
  else:
    if(checkDict2[t[i]]!=s[i]):
      flg="No"
    
  
print(flg)


Measured memory_bytes: 6704
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

# BEGIN CUT HERE
from queue import Queue
def bfs(field, sy, sx, wall, dir):
    h = len(field)
    w = len(field[0])
    dp = [[-1 for _j in range(w)] for _i in range(h)]
    q = Queue()

    dp[sy][sx] = 0
    q.put((sy, sx))
    
    dy = [1, -1, 0, 0, 1, 1, -1, -1]
    dx = [0, 0, 1, -1, 1, -1, 1, -1]
    def isin(x,y): return 0 <= y and y < h and 0 <= x and x < w
    
    while not q.empty():
        y, x = q.get()
        for k in range(dir):
            ny,nx = y+dy[k],x+dx[k]
            if not isin(nx, ny) or field[ny][nx] == wall:
                continue
            elif dp[ny][nx] != -1:
                continue
            dp[ny][nx] = dp[y][x] + 1
            q.put((ny,nx))
        
    return dp
    
# END CUT HERE

def ABC088_D():
    h, w = mi()
    s = [['' for _j in range(w)] for _i in range(h)]
    for i in range(h):
        s[i] = li()
    dp = bfs(s, 0, 0, '#', 4)
    if dp[h - 1][w - 1] < 0:
        print(-1)
    else:
        cnt = 0
        for i in range(h):
            for j in range(w):
                cnt += s[i][j] == '.'
        print(cnt - (dp[h-1][w-1]+1))

if __name__ == '__main__':
    ABC088_D()

Measured memory_bytes: 44776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cassert>
#include <numeric>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

template <typename It>
bool can_sum(It begin, It end, int64_t s) {
    constexpr auto kMax = 10000;
    constexpr auto kOffset = kMax;

    bitset<kMax * 2 + 1> current;

    if (begin == end) {
        return (s == 0);
    }

    if (s + kOffset < 0 || s >= kMax + kOffset) {
        return false;
    }

    current[0 + kOffset] = true;
    for (auto it = begin; it != end; ++it) {
        auto v = *it;
        current = ((current << v) | (current >> v));
    }

    return current[s + kOffset];
}

bool solve(const string& s, int x, int y) {
    // 横移動, 縦移動
    vector<int> xmove(1), ymove;

    bool current_xmove = true;
    for (auto ss : s) {
        if (ss == 'T') {
            current_xmove  = !current_xmove;
            if (current_xmove) {
                xmove.push_back(0);
            } else {
                ymove.push_back(0);
            }
            continue;
        }
        if (current_xmove) {
            ++xmove.back();
        } else {
            ++ymove.back();
        }
    }

    return can_sum(xmove.begin() + 1, xmove.end(), x - xmove[0]) && can_sum(ymove.begin(), ymove.end(), y);
}

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

    int x, y;
    cin >> x >> y;

    cout << (solve(s, x, y) ? "Yes" : "No") << endl;

    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> cnt(1e5 + 1);
    ll sum = 0;
    rep(i, n){
        int a;
        cin >> a;
        sum += a;
        ++cnt[a];
    }
    int q;
    cin >> q;
    rep(i, q){
        int b, c;
        cin >> b >> c;
        sum += (cnt[b] * (c - b));
        cout << sum << endl;
        cnt[c] += cnt[b];
        cnt[b] = 0;
    }
    return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m); 
}
int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int x;
	vi X;

	REP(i,3){
		cin>>x;
		X.pb(x);
	}

	VSORT(X);
	VREV(X);

	print(X[0]*10+X[1]+X[2]);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    int counter=0;
    char s[50];
    cin>>n;
    for(int i=0; i<n ; i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            counter+=1;
        }
    }
    cout<<counter;
    return 0;
}

Measured memory_bytes: 256