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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  
  if ((A+B)>(C+D)){
    cout<<"Left"<<endl;
  }
  
  if ((A+B)==(C+D)){
    cout<<"Balanced"<<endl;
  }
  
  if ((A+B)<(C+D)){
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
import sys
import collections
import itertools


def resolve(in_):
    one = ord(b'1')
    two = ord(b'2')
    # print(f'{one=} {two=}')

    S = in_.readline().strip()
    q = collections.deque(S)
    # print(f'{S=} {q=}')

    reverse_flag = False
    Q = int(in_.readline())
    for query in itertools.islice(in_, Q):
        T = query[0]
        if T == one:
            reverse_flag ^= True 
            # q.reverse()
        elif T == two:
            F = query[2]
            C = query[4]
            if (F == one) ^ reverse_flag:
                q.appendleft(C)
            else:
                q.append(C)

    return bytes(reversed(q)) if reverse_flag else bytes(q)


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer.decode('ascii'))


if __name__ == '__main__':
    main()


Measured memory_bytes: 12064
#!/usr/bin/env python3
import sys
import queue

def create_graph(N, a, b):
    g = {}
    for i in range(N-1):
        if a[i] in g:
            g[a[i]][b[i]] = 0
        else:
            g[a[i]] = {b[i]: 0}
        if b[i] in g:
            g[b[i]][a[i]] = 0
        else:
            g[b[i]] = {a[i]: 0}
    return g


def bfs(g, s):
    Q = queue.Queue()
    Q.put(s)
    while not Q.empty():
        p = Q.get()
        cs = set(range(len(g[p])+2)) - set([v for k, v in g[p].items()])
        for q in g[p].keys():
            # print(f"p:{p} q:{q} g:{g[p][q]}")
            if not g[p][q]:
                c = cs.pop()
                g[p][q] = c
                g[q][p] = c
                Q.put(q)


def solve(N: int, a, b):
    g = create_graph(N, a, b)
    bfs(g, a[0])
    # print(g)
    m = 1
    for i in range(N-1):
        m = max(m, g[a[i]][b[i]])
    print(m)
    for i in range(N-1):
        print(g[a[i]][b[i]])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49264
N, X, Y = map(int, input().split())
ans = [0]*(N-1)
for i in range(N-1):
    for j in range(i+1,N):
        saitan = min(j-i, abs(i-X+1)+1+abs(j-Y+1))
        ans[saitan-1] += 1
for i in range(N-1):
    print(ans[i])


Measured memory_bytes: 3444
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa; cin>>nyaa;


void solve() {
	ll n; cin >> n;
	string str; cin >> str;

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		bool ng = false;
		if (str[i] != '.') {
			ng = true;
		}

		int cou = 0;
		for (int j = i + 1; j < n; j++) {
			if (str[j] == 'B') {
				cou++;
				break;
			}
			else if (str[j] == 'W') {
			}
			else {
				break;
			}
		}

		for (int j = i - 1; j >= 0; j--) {
			if (str[j] == 'B') {
				cou++;
				break;
			}
			else if (str[j] == 'W') {
			}
			else {
				break;
			}
		}
		if (cou == 2)ng = true;

		if (ng)continue;

		ll now = 0;
		ll tmp = 0;
		for (int j = i + 1; j < n; j++) {
			if (str[j] == 'B') {
				tmp++;
			}
			else if (str[j] == 'W') {
				now += tmp;
				break;
			}
			else {
				break;
			}
		}

		tmp = 0;
		for (int j = i - 1; j >= 0; j--) {
			if (str[j] == 'B') {
				tmp++;
			}
			else if (str[j] == 'W') {
				now += tmp;
				break;
			}
			else {
				break;
			}
		}

		ans = max(ans, now);
	}

	cout << ans << endl;
		
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 3224
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function eval(a::Tuple{Int,Int},b::Tuple{Int,Int})
	if a[2]<b[2]
		1
	elseif a[2]==b[2]
		0
	else
		-1
	end
end

function hpush(h::Array{Tuple{Int,Int},1},x::Tuple{Int,Int})
	push!(h,x)
	if length(h) > 1
		l = length(h)
		k = l>>1
		while eval(x,h[k])==1&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpop(h::Array{Tuple{Int,Int},1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if eval(h[2*k],z)>=0
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if eval(z,h[2*k])>=0&&eval(z,h[2*k+1])>=0
					break
				else
					t = eval(h[2*k],h[2*k+1])>=0?2*k:2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end

function main()
    n,m = readline() |> split |> parseMap
    e = [Tuple{Int,Int}[] for i in 1:n]
    for i in 2:n
        push!(e[i],(i-1,0))
    end
    for i in 1:m
        l,r,c = readline() |> split |> parseMap
        push!(e[l],(r,c))
        push!(e[r],(l,c))
    end
    dis = -ones(Int, length(e))
	h = Array{Tuple{Int,Int},1}()
	push!(h,(1,0))
	while !isempty(h)
		v,w = hpop(h)
		dis[v] = dis[v]<0?w:min(dis[v],w)
		for i in 1:length(e[v])
			if dis[e[v][i][1]]<0　|| dis[e[v][i][1]]>w+e[v][i][2]
				dis[e[v][i][1]] = w+e[v][i][2]
				hpush(h,(e[v][i][1],w+e[v][i][2]))
			end
		end
	end
	println(dis[n])   
end

main()

Measured memory_bytes: 172448
#include<iostream>

using namespace std;

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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    int a[n];
    rep (i, n) cin >> a[i];
    string str;
    cin >> str;
    rep (i, str.size()) {
      int aa = a[i % n];
      while (aa) {
	--aa;
	if (str[i] == 'A') str[i] = 'z';
	else if (str[i] == 'a') str[i] = 'Z';
	else --str[i];
      }
    }
    cout << str << endl;
  }
}

Measured memory_bytes: 1204
n,y=map(int,input().split())
r=y//1000
b=False
x0=0
for i in range((r//10)+1):
  x1=(r-n-9*i)
  x2=5*n-r+5*i
  if x1>=0 and x2>=0 and x1%4==0 and x2%4==0:
    b=True
    x0=i
    x1=x1//4
    x2=x2//4
    break
if b:
  print(x0,x1,x2)
else:
  print(-1,-1,-1)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(){
  int n, p; cin >> n >> p;
  int a[n];
  int od = 0, ev = 0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i] % 2) od++;
    else ev++;
  }

  ll ans;
  if(p % 2 == 1){
    ans = (1LL << ev) * (1LL << od-1);
  }
  else{
    ans = (1LL << n) - (1LL << ev) * (1LL << od-1);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n, t = gets.chomp.split(" ").map(&:to_i)
array = []
answer = "TLE"

(1..n).each do
  array.push(gets.chomp.split(" ").map(&:to_i))
end

array.keep_if do |item|
  item.last <= t
end

cost_array = []
array.each do |item|
  cost_array.push(item.first)
end

answer = cost_array.min unless array.empty?

puts answer


Measured memory_bytes: 1788
c = [list(map(int, input().split())) for i in range(3)]
a = [0, 0, 0]
count = 0
for i in range(2):
    for j in range(3):
        a[j] = c[i][j] - c[i + 1][j]
    count += 1 if a[0] == a[1] == a[2] else 0
print("Yes" if count == 2 else "No")

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int s; cin>>s;
	int u=s/100,l=s%100;
	string ans;
	if(u==0||u>12){
		if(l==0||l>12)ans="NA"s;
		else ans="YYMM"s;
	}
	else{
		if(l==0||l>12)ans="MMYY"s;
		else ans="AMBIGUOUS"s;
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n,x;cin>>n>>x;
    vi b(n),l(n),u(n);
    rep(i,n)cin>>b[i]>>l[i]>>u[i];
    vp v(n);
    rep(i,n)v[i]=P(l[i]*b[i]+u[i]*(x-b[i]),i);
    sort(all(v));reverse(all(v));
    vi rui(n+1);
    rep(i,n)rui[i+1]=rui[i]+v[i].fi;
    vi id(n);
    rep(i,n)id[v[i].se]=i;
    ll sum=0;
    rep(i,n)sum+=l[i]*b[i];
    ll ok=x*n,ng=-1;
    while(ok-ng>1){
        ll md=(ok+ng)/2;
        bool able=false;
        ll p=md%x;
        rep(i,n){
            ll res=l[i]*min(b[i],p)+u[i]*max(0ll,p-b[i]);
            res+=rui[md/x];
            if(id[i]<md/x)res-=v[id[i]].fi-v[md/x].fi;
            if(res>=sum)able=true;
        }
        if(able)ok=md;
        else ng=md;
    }
    out(ok);
}

Measured memory_bytes: 5760
n=input()
a=[int(i) for i in input().split()]
ac=a[:]


def lcm(x, y):
    x2=x
    y2=y
    while y != 0:
        x, y = y, x%y
    return (x2 * y2) // x

while(len(ac)>1):
    x=ac.pop()
    y=ac.pop()
    ac.append(lcm(x, y))

g=ac[0]-1

ans=0
for i in a:
    ans+=g%i

print(ans)


Measured memory_bytes: 3316
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if (a==5&&b==5&&c==7)
		{printf("YES");
		return 0;}
	if (a==7&&b==5&&c==5)
		{printf("YES");
		return 0;}
	if (a==5&&b==7&&c==5)
		{printf("YES");
		return 0;}
	else
		printf("NO");
	return 0;
}

Measured memory_bytes: 128
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a,cnt=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    if(!(a%2)) {
      cnt++;
    }
  }
  cout << (cnt==n?"second":"first") << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for {
		n, x := nextInt(), nextInt()
		if n == 0 && x == 0 {
			break
		}
		ans := 0
		for i := 1; i < n; i++ {
			for j := i + 1; j < n; j++ {
				k := x - i - j
				if k > j && k <= n {
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}



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

int N;

bool check_Sort(vector<int> &X, vector<int> &Y){
    
    bool ans = true;
    
    for(int i = 0; i < N; i++){
        if(X.at(i) != Y.at(i)){
            ans = false;
            break;
        }
    }
    return ans;
}


int main(void){
    
    cin >> N;
    vector<int> p(N);
    vector<int> sort_P(N);
    
    for(int i = 0; i < N; i++){
        cin >> p.at(i);
        sort_P.at(i) = p.at(i);
    }
    
    sort(sort_P.begin(), sort_P.end());
    
    if( check_Sort(p, sort_P) ){
        cout << "YES" << endl;
        return 0;
    }
    
    
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            swap(p.at(i), p.at(j));
            
            if( check_Sort(p, sort_P) ){
                cout << "YES" << endl;
                return 0;
            }
            swap(p.at(j), p.at(i));
        }
    }
    
    cout << "NO" << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    for(int i = 0; i < 3; i++){
        if(S.at(i) == '1')
        S.at(i) = '9';
        else if(S.at(i) == '9')
        S.at(i) = '1';
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

struct Node{
	int key;
	Node *right,*left,*parent;
};

Node *root,*NIL;

void insert(int k){
	Node *y=NIL;
	Node *x=root;
	Node *z;
	
	z=(Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y=x;
		if(z->key < x->key){
			x=x->left;
		} else {
			x=x->right;
		}
	}
	
	z->parent = y;
	if(y==NIL){
		root = z;
	}  else {
		if(z->key<y->key){
			y->left=z;
		} else{
			y->right=z;
		}
	}
}

void inorder(Node *u){
	if(u==NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

void preorder(Node *u){
	if(u==NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}



int main() {
	
	int n,i,x;
	string com;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		cin>>com;
		if(com=="insert"){
			scanf("%d",&x);
			insert(x);
		}else if(com=="print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 26560
def solve(A):
    A = sorted(A)
    ma = min(A)
    for i in range(3):
        A[i] -= ma
    if A == [0, 0, 0]:
        return 0
    elif A == [0, 0, 1]:
        return 1
    elif A == [0, 1, 1]:
        return 2

A = list(map(int,input().split()))
A = sorted(A)
ca = (A[2] - A[0]) // 2
A[0] += 2 * ca
cb = (A[2] - A[1]) // 2
A[1] += 2 * cb
ans = ca + cb + solve(A)
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
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;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(ll,N);
  AIN(ll,D,N);
  SORT(D);
  ll ans = D[N/2] - D[N/2 -1];
  OUT(ans);
}

Measured memory_bytes: 1152
import sys
input = sys.stdin.readline
f = lambda:map(int,input().split())
d,g = f()
g//=100
ll = []
for i in range(d):
  p,c = f()
  ll.append([i+1,p,c//100])
ll = ll[::-1]
import itertools as it
ans = 10**9
for t in it.product(range(2),repeat=d):
  cnt = 0
  tot = 0
  flg = 1
  lg = [1,0]
  for i,b in enumerate(t):
    u,p,c = ll[i]
    if b:
      cnt += p
      tot += u*p+c
    elif flg:
      lg = [u,p]
      flg = 0
  if g <= tot+lg[0]*lg[1]:
    ans=min(ans,cnt+max(g-tot,0)//lg[0])
print(max(ans,1))

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

using namespace std;

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;

const int inf = 1e9;
const ll inf64 = 1e18;

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int R, G, B, N;

    cin >> R >> G >> B >> N;

    int res = 0;

    for (int r = 0; r <= N; r += R) {
        for (int g = 0; r + g <= N; g += G) {
            int b = N - r - g;
            if (b % B == 0) {
                res++;
            }
        }
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
c=["."+input()+"." for i in range(h)]
s=["."*(w+2)]
s.extend(c)
b=["."*(w+2)]
s.extend(b)
sc=[[0for _ in range(w+2)] for i in range(h+2)]
# print(sc)

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="#":
            if sc[i-1][j-1]!="#":
                sc[i-1][j-1]+=1
            if sc[i][j-1]!="#":
                sc[i][j-1]+=1
            if sc[i+1][j-1]!="#":
                sc[i+1][j-1]+=1
            if sc[i-1][j]!="#":
                sc[i-1][j]+=1
            if sc[i+1][j]!="#":
                sc[i+1][j]+=1
            if sc[i-1][j+1]!="#":
                sc[i-1][j+1]+=1
            if sc[i][j+1]!="#":
                sc[i][j+1]+=1
            if sc[i+1][j+1]!="#":
                sc[i+1][j+1]+=1
            sc[i][j]="#"
for i in range(1,h+1):
    ne="".join([str(_) for _ in sc[i]])
    ne=ne[1:w+1]
    print(ne)

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

int main() {
	int n;
	cin >> n;
	map<string, int> ma;
	for(int i = 0; i < n; i++) {
		string s;
		cin >> s;
		ma[s] += 1;
	}
	cout << (int)ma.size() << endl;
}

Measured memory_bytes: 19168
N = gets.to_i
as = gets.split.map(&:to_i)

kinds = {}

as.each do |a|
  if a <= 399
    kinds["399"] = kinds["399"].to_i + 1
  elsif a <= 799
    kinds["799"] = kinds["799"].to_i + 1
  elsif a <= 1199
    kinds["1199"] = kinds["1199"].to_i + 1
  elsif a <= 1599
    kinds["1599"] = kinds["1599"].to_i + 1
  elsif a <= 1999
    kinds["1999"] = kinds["1999"].to_i + 1
  elsif a <= 2399
    kinds["2399"] = kinds["2399"].to_i + 1
  elsif a <= 2799
    kinds["2799"] = kinds["2799"].to_i + 1
  elsif a <= 3199
    kinds["3199"] = kinds["3199"].to_i + 1
  else
    kinds["X"] = kinds["X"].to_i + 1
  end
end

if kinds.reject { |k, v| k == "X" }.count == 0
  min = 1
  max = kinds["X"]
elsif kinds.select { |k, v| k == "X" }.count > 0
  min = kinds.count - 1
  max = min + kinds["X"]
else
  min = kinds.count
  max = min
end

puts "#{min} #{max}"

Measured memory_bytes: 1788
N = list(map(int, input().split()))
array = list(map(int, input().split()))
array.remove(array[0])
dainyu = []
for i in range(0, N[0]-1):
    data = list(map(int, input().split()))
    dainyu = []
    for loop in range(1, data[0]+1):
        if (array.count(data[loop]) != 0) :
            dainyu.append(data[loop])
    array = dainyu
print(len(array))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main(){
    
    int h , w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h){
        cin >> s[i];
    }

    int ans = 0;

    rep(si, h)rep(sj, w){
        if(s[si][sj] == '#') continue;
        vvi dist(h, vi(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x){
            dist[i][j] = x;
            q.push(P(i, j));
        };

        update(si, sj, 0);

        while(!q.empty()){
            int i = q.front().fi;
            int j = q.front().se;
            q.pop();
            rep(dir, 4){
                int ni = i + di[dir];
                int nj = j + dj[dir];
                if(ni<0||ni>=h||nj<0||nj>=w) continue;
                if(s[ni][nj]=='#') continue;
                if(dist[ni][nj] != INF) continue;
                update(ni, nj, dist[i][j]+1);
            }
        }

        rep(i, h)rep(j, w){
            if(dist[i][j]==INF) continue;
            if(s[i][j]=='#') continue;
            ans = max(ans, dist[i][j]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include <limits>

using namespace std;

int main() {
	unsigned long long a;
	unsigned long long N;
	unsigned long long count = numeric_limits<unsigned long long>::max();

	cin >> N;

	for (unsigned long i = 1; i < sqrt(N)  * 2; i++) {
		if (N % i == 0) {
			a = (unsigned long long)(i + N / i - 2);
			if (count > a) {
				count = a;
			}

		}
	}

	cout << count;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <utility>

#define FOR(i,a,b) for(int i = (a); i < (b); ++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 ALL(a) begin(a), end(a)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	REP(i, s.size() - 8)cout << s[i];
	cout << "\n";
	return 0;
}


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

//for test in *.in; do echo $test; ./a.out < $test ; done
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define pb push_back
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define MOD 1000000007
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main(){
	int a,b,c;
	cin >> a >> b >> c;
	if((a==b and a!=c) or (a==c and a!=b) or (c==b and a!=c)){
		cout << "Yes\n";
	}else
		cout << "No\n";
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size() - 1 ; i++){
        if(s[i] != s[i + 1])
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
/*
Educational DP Contest - B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
 
int main()  
{ 
    FAST_INP;
    int n, k;
    cin >> n >> k;
    vector<int> h(n), dp(n,1e9+5);
    for(int i=0;i<n;i++) cin >> h[i];
  	dp[0]=0;
  	for(int i=0;i<n;i++) {
    	for(int j=i+1;j<=i+k;j++){
    		if(j<n){
    			dp[j] = min(dp[j],dp[i]+abs(h[j]-h[i]));
			}
		}
    }
  	cout << dp[n-1] << "\n";
    return 0;
} 


Measured memory_bytes: 3936
import Data.List
import Control.Monad

next :: (Int, Int) -> (Int, Int) -> (Int, Int)
next (t, a) (t', a') = (t' * r, a' * r)
  where t'' = (t + t' - 1) `div` t'
        a'' = (a + a' - 1) `div` a'
        r = max t'' a''

readLine :: String -> (Int, Int)
readLine line = (x, y)
  where [x, y] = fmap read $ words line

main :: IO ()
main = do
  n <- read <$> getLine
  ratios <- fmap readLine <$> replicateM n getLine
  print $ uncurry (+) $ foldl' next (1, 1) ratios


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<pair<int, int > > v(n);
    for(int i=0; i<n; i++){
        cin>>v[i].first>>v[i].second;
    }
    int cnt = 0;
    int fcnt = 0;
    for(int i=0; i<n; i++){
        if(v[i].first==v[i].second){
            cnt++;
        }
        else{
            cnt = 0;
        }
        fcnt = max(fcnt, cnt);
    }
    fcnt = max(fcnt, cnt);
    if(fcnt>=3){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
int main(void){
  double left,right;
  int lefta = 0,righta = 0;
  int leftb = 0,rightb = 0;
  int leftc = 0,rightc = 0;
  int leftd = 0,rightd = 0;
  while(scanf("%lf %lf",&left,&right) != EOF){
    if(left >= 1.1){
      lefta++;
    }
    else if(left < 1.1 && left >= 0.6){
      leftb++;
    }
    else if(left < 0.6 && left >= 0.2){
      leftc++;
    }
    else{
      leftd++;
    }
    if(right >= 1.1){
      righta++;
    }
    else if(right < 1.1 && right >= 0.6){
      rightb++;
    }
    else if(right < 0.6 && right >= 0.2){
      rightc++;
    }
    else{
      rightd++;
    }
  }
    printf("%d %d\n%d %d\n%d %d\n%d %d\n",lefta,righta,leftb,rightb,leftc,rightc,leftd,rightd);
  return 0;
}

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

int cost(int n ,int h[] , int k)
{ int DP[n+1];
	DP[1] = 0; DP[2] = abs(h[2]-h[1]);
	for (int i = 3; i <= n; i++) 
	{
	int min1= DP[i-1]+ abs(h[i]-h[i-1]);
	for(int j=2;j<=k;j++)
	{    if((i-j) > 0)
			{
					if( min1 > ( DP[i-j]+ abs(h[i]-h[i-j]) ) )
					min1 = DP[i-j]+ abs(h[i]-h[i-j]);
			}
	
	}
	DP[i]=min1;
	}
	 return DP[n];
}

int main() {
	
int n,k;
cin>>n>>k;
int h[n+1];
for(int i=1;i<n+1;i++)
cin>>h[i];
cout<<cost(n,h,k);
	// your code goes here
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>

using namespace std;
 
/********** TEMPLATE STARTS HERE ***********/
   
#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define test int t; cin >> t; while(t--)
#define skip continue
#define stop break
#define sz(v) (int)v.size()
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define gcd __gcd 
#define FO(i, a) for(auto & i : a)
#define debug(a) cout << #a << ": " << a << endl
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << endl
#define SET(a, b) memset(a, b, sizeof(a));
#define refresh fflush(stdout);
#define digits(n) (int)(log10(n) + 1)
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pii> vii;
typedef vector <pll> vll;
   
const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;
   
template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
  
/*********** TEMPLATE ENDS HERE *************/

vector <pair <pii, pii> > ans;

int v[507][507];

main()
{
	IOS
	
	int n, m;
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			cin >> v[i][j];
		}
		
	for(int i = n; i >= 1; i--)
		for(int j = m; j >= 1; j--)
			if(v[i][j] & 1)
			{
				if(i == 1 && j == 1)
					break;
				
				v[i][j]--;
				
				if(i != 1)
				{
					v[i - 1][j]++;
					ans.pb({{i, j}, {i - 1, j}});
				}
				else
				{
					v[i][j - 1]++;
					ans.pb({{i, j}, {i, j - 1}});
				}
			}
			
	cout << sz(ans) << endl;
	
	for(auto i : ans)
		cout << i.F.F << ' ' << i.F.S << ' ' << i.S.F << ' ' << i.S.S << endl;
}

Measured memory_bytes: 5232
#!/usr/bin/perl

use strict;
use warnings;

my ($a, $b);
{
    my $in = <STDIN>;
    ($a, $b) = split(" ", $in);
}
my ($n, $s);
if ($a<$b)
{
    $n = $b;
    $s = $a;
}
else
{
    $n = $a;
    $s = $b;
}
my $ans = "";
for (my $i=0; $i<$n; $i++)
{
    $ans .= $s;
}

print "$ans\n";

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long d[101][4][4][4];
long long mod = 1000000007;
int main() { // 012   021  102       01?2        0?12
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < 4; i++) {
		for (int k = 0; k < 4; k++) {
			for (int j = 0; j < 4; j++) {
				d[3][i][k][j] = 1;
			}
		}
	}
	d[3][0][1][2] = 0; d[3][0][2][1] = 0; d[3][1][0][2] = 0;

	for (int l = 3; l < n; l++) { // 길이가 n까지
		for (int k = 0; k < 4; k++) { // 첫번째 문자
			for (int j = 0; j < 4; j++) { // 두번째 문자
				for (int r = 0; r < 4; r++) { // 세번째 문자
					if (d[l][k][j][r] == 0)continue;
					for (int o = 0; o < 4; o++) { //네번째 문자
						if (j == 0 && r == 1 && o == 2)continue;
						if (j == 0 && r == 2 && o == 1)continue;
						if (j == 1 && r == 0 && o == 2)continue;
						if (k == 0 && j == 1 && o == 2)continue;
						if (k == 0 && r == 1 && o == 2)continue;
						d[l + 1][j][r][o] += d[l][k][j][r];
						d[l + 1][j][r][o] %= mod;
					}		
				}
			}
		}
	}

	long long ans = 0;
	for (int l = 0; l < 4; l++) {
		for (int k = 0; k < 4; k++) {
			for (int j = 0; j < 4; j++) {
				ans += d[n][l][k][j];
				ans %= mod;
			}
		}
	}
	cout << ans << '\n';


}

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

using namespace std;

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

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

    map<int, bool> p;
    for (int i = 0; i < n; i++) {
        if (!p.count(a[i]))
            p[a[i]] = true;
        else
            p.erase(a[i]);
    }

    cout << p.size() << endl;

    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt int Q[100005]={0}
#define mp make_pair
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<int>()) 
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(int i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(int i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=mpowe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}

string s;
ll tree[400000+5];
ll a[100000+5];
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a;
    if(a==0)
        return b; 
    return gcd(b, a % b);  
      
}
void build(ll node,ll start,ll end)
{
    if(start==end)
    {
        tree[node]=a[start];
        
    }
    else
    {
        ll mid = (start+end)/2;
        build(2*node+1,start,mid);
        build(2*node+2,mid+1,end);
        tree[node]=gcd(tree[2*node+1],tree[2*node+2]);
    }
}
void update(ll tree[],ll node,ll start,ll end,ll idx)
{
    if(start==end)
    {
        tree[node] = max(0LL,tree[node]-1);
    }
    else
    {
        ll mid = (start+end)/2;
        if(start<=idx && mid>=idx)
        {
            update(tree,2*node+1,start,mid,idx);
        }
        else
        {
            update(tree,2*node+2,mid+1,end,idx);
        }
        tree[node] = tree[2*node+1]+tree[2*node+2];
    }
}
ll query(ll node,ll start,ll end,ll l,ll r)
{
    if(r<start || l>end)
    {
        return 0;
    }
    if(l<=start && r>=end)
    {
        return tree[node];
    }
    ll mid = (start+end)/2;
    ll p1 = query(2*node+1,start,mid,l,r);
    ll p2 = query(2*node+2,mid+1,end,l,r);
   return gcd(p1,p2);
}

int main()
{                       
    fastio();
 
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
 
public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = Integer.parseInt(scanner.nextLine());
 
        Dice[] dices = new Dice[num];
        boolean flag = true;
 
        loop: for (int i = 0; i < num; i++) {
            dices[i] = new Dice(scanner.nextLine());
            for (int j = 0; j < i; j++) {
                if (dices[i].equals(dices[j])) {
                    flag = false;
                    break loop;
                }
            }
        }
        System.out.println(flag ? "Yes" : "No");
    }
}
 
class Dice {
    int[] a = new int[6];
 
    Dice(String s) {
        String[] b = s.split(" ");
        for (int i = 0; i < 6; i++) {
            a[i] = Integer.parseInt(b[i]);
        }
    }
 
    public void roll(char c) {
        int temp;
        switch (c) {
        case 'E':
            temp = a[0];
            a[0] = a[3];
            a[3] = a[5];
            a[5] = a[2];
            a[2] = temp;
            break;
        case 'N':
            temp = a[0];
            a[0] = a[1];
            a[1] = a[5];
            a[5] = a[4];
            a[4] = temp;
            break;
        case 'W':
            temp = a[0];
            a[0] = a[2];
            a[2] = a[5];
            a[5] = a[3];
            a[3] = temp;
            break;
        default:
            temp = a[0];
            a[0] = a[4];
            a[4] = a[5];
            a[5] = a[1];
            a[1] = temp;
            break;
        }
    }
 
    public boolean equals(Dice d) {
        char[] c = { 'E', 'E', 'E', 'N', 'W', 'W', 'W', 'S' };
        boolean flag = false;
        loop: for (int i = 0; i < 24; i++) {
            /*System.out.println(Arrays.toString(a) + "========"
                    + Arrays.toString(d.a));*/
            if (Arrays.equals(a, d.a)) {
                flag = true;
                break loop;
            }
            d.roll(c[i % 8]);
        }
        return flag;
    }
}



Measured memory_bytes: 27968
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
  long long i,d,n,m;
  cin >> n >> m >> d;
  double x;
  if (d!=0){
    x=2*(n-d)*(m-1);
  } else {
    x=(n-d)*(m-1);
  }
  x/=(n*n);
  cout << std::fixed;
  cout << std::setprecision(7) << x <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <stack>
using namespace std;
 
int main() {
    int M, D;
    cin >> M >> D;
    int cnt = 0;

    for (int i = 1; i <= M; ++i) {
        for (int j = 1; j <= D; ++j) {
            int d10 = j / 10;
            int d1 = j - d10 * 10;
            if (i == d1 * d10) {
                if (d1 >= 2 && d10 >= 2) cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

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

bool compare(int a,int b){
  return a<b;//ascending
} 

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);


    int d,t,s;
    cin>>d>>t>>s;
  double k=(double)d/s;
    if((k)<=t){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }


  return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
long long ans = INT64_MAX;
long long dif(long long a, long long b, long long c) {
    return max(a, max(b, c))-min(a, min(b, c));
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long H, W;
    cin >> H >> W;
    long long A, B, C;
    for (int i = 0; i < 2; i++, swap(H, W)) {
        if (H%3 == 0) ans = 0;
        else {
            ans = min(ans, W);
            A = (H/3+H%3-1)*W;
            B = (H/3*2+1)*(W/2+W%2);
            C = (H/3*2+1)*(W/2);
            ans = min(ans, dif(A, B, C));
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

#define MAX 1010
typedef unsigned long long ull;

int N,M,P,Q;
char field[MAX][MAX],pattern[MAX][MAX];
ull hash[MAX][MAX],tmp[MAX][MAX];

void compute_hash(char a[MAX][MAX],int n,int m){
    const ull B1 = 63533;
    const ull B2 = 100007;
   
    ull t1 = 1;
    for(int j = 0 ; j < Q ; j++) t1 *= B1;
   
    for(int i = 0 ; i < n ; i++){
        ull e = 0;
        for(int j = 0 ; j < Q ; j++) e = e * B1 + a[i][j];
        for(int j = 0 ; j + Q <= m ; j++){
            tmp[i][j] = e;
            if(j + Q < m) e = e * B1 - t1 * a[i][j] + a[i][j+Q]; 
        }
    }
   
    ull t2 = 1;
    for(int i = 0 ; i < P ; i++) t2 *= B2;
   
    for(int j = 0 ; j + Q <= m ; j++){
        ull e = 0;
        for(int i = 0 ; i < P ; i++) e = e * B2 + tmp[i][j];
     
        for(int i = 0 ; i + P <= n ; i++){
            hash[i][j] = e;
            if(i + P < n) e = e * B2 - t2 * tmp[i][j] + tmp[i+P][j];
        }
    }
}
 
void solve(){
    compute_hash(pattern, P, Q);
    ull res = hash[0][0];
    compute_hash(field, N, M);
    for(int i = 0 ; i <= N ; i++){
        for(int j = 0 ; j <= M ; j++){
            if(res == hash[i][j]){
                cout << i << " " << j << endl;
            }
        }
    }
}

int main(){
    cin >> N >> M;
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < M ; j++){
            cin >> field[i][j];
        }
    }
    cin >> P >> Q;
    for(int i = 0 ; i < P ; i++){
        for(int j = 0 ; j < Q ; j++){
            cin >> pattern[i][j];
        }
    }
    if(N < P && M < Q) return 0;
    solve();
    return 0;
}

Measured memory_bytes: 18584
import itertools

n, m, q = map(int, input().split())

As = list(itertools.combinations_with_replacement(range(1,m+1), n))

ans = [0] * len(As)
for _ in range(q):
  a, b, c, d = map(int, input().split())
  for i, A in enumerate(As):
    if A[b-1] - A[a-1] == c:
      ans[i] += d

print(max(ans))

Measured memory_bytes: 25252
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=5e3+10;
ll dp[N][N];
int P[N],D[N];
const ll INF=1e18;
int main()
{
	int n,A,B;scanf("%d%d%d",&n,&A,&B);
	for(int i=0;i<n;i++)scanf("%d",&D[i]);
	int tar=0;
	for(int i=0;i<n;i++){
		tar++;int cnt=0;
		for(int j=0;j<n;j++){
			if(D[j]==tar){
				P[tar]=n-tar-cnt;
				break;
			}else if(D[j]>tar)cnt++;
		}
	}fill(&dp[0][0],&dp[N-1][N],INF);
	for(int i=0;i<=n;i++)dp[0][i]=0;
	for(int i=1;i<=n;i++){
		ll M=INF;
		for(int j=0;j<=n;j++){
			M=min(M,dp[i-1][j]);
			//n-j,P[i]
			if(P[i]+1==n-j)dp[i][j+1]=min(dp[i][j+1],M);
			else if(P[i]+1<n-j)dp[i][j+1]=min(dp[i][j+1],M+B);
			else dp[i][j]=min(dp[i][j],M+A);
		}
	}cout<<dp[n][n]<<'\n';
}


Measured memory_bytes: 196480
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int[] c = new int[n];
    int[] v = new int[n];
    for (int i = 0; i < n; i++) {
      v[i] = s.nextInt();
    }
    for (int i = 0; i < n; i++) {
      c[i] = s.nextInt();
    }
    int maxV = 0;
    for (int i = 0; i < n; i++) {
      maxV += Math.max(0, v[i] - c[i]);
    }
    System.out.println(maxV);
  }
}


Measured memory_bytes: 23252
//
//AtCoder Beginner Contest 067
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<ll> a(n);
    ll sum = 0;
    REP(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    ll x = 0;
    ll y = sum;
    ll ans = 10e10;
    REP(i, n-1){
        x+=a[i];
        y-=a[i];
        ans = min(ans, abs(x - y));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4744
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        long A;
        long B;
        long K;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextLong();
            B = sc.nextLong();
            K = sc.nextLong();
        }
        long A2 = 0;
        long B2 =0;
        if(A < K) {
            A2 = 0;
        }else {
            A2 = A - K;
        }
        long K2 = K - (A-A2);
        if(B < K2) {
            B2 = 0;
        }else {
            B2 = B - K2;
        }


        System.out.println(A2 +" "+B2);
    }
}


Measured memory_bytes: 23764
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		List<Integer> list = new ArrayList<>();

		int a = sc.nextInt();
		int b = sc.nextInt();
		int bigger = Math.max(a,b);
		int lesser = Math.min(a,b);

		if(bigger>lesser){
			System.out.println(bigger*2-1);
		} else if(bigger ==lesser){
			System.out.println(bigger+lesser);
		}
	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N],sum,t;



int main()
{
	fast;
	cin>>n;
	m=n;
	n*=3;
	fs(ar,n);
	sort(ar+1,ar+n+1,greater<int>());
	for(int i=1;i<=n;i++)
	{
		if(i%2==0)
			sum+=ar[i];
		if(i==m*2)
			break;
	}
	cout<<sum<<endl;

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

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

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i= n-1;i>=0;i--){
		if (i!=0){
			cout << a[i] << " ";
		}else{
			cout << a[i] << endl;
		}
		
	}
	return 0;

}


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

int main() {
  int a, b;

  cin >> a >> b;

  if (a == b){
    cout << "a == b" << endl;
  } else if (a > b) {
    cout << "a > b" << endl;
  } else if ( a < b){
    cout << "a < b" << endl;
  }
}



Measured memory_bytes: 3104
x1, x2, x3, x4, x5 = map(int, input().split())
if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
else:
    print(5)

Measured memory_bytes: 9172
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a!=b && b!=c && a!=c)
    {
        printf("3\n");
    }
    else if(a==b && b!=c && a!=c)
    {
        printf("2\n");
    }
    else if(a!=b && b==c && a!=c)
    {
        printf("2\n");
    }
    else if(a!=b && b!=c && a==c)
    {
        printf("2\n");
    }
    else
    {
        printf("1\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
typedef tuple<int,int,int> T;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

queue<int> uft_q1;
int uft_parent[200005];
int uft_num[200005];
int edge_num[200005];

int uft_check_parent(int uft_x){
	if(uft_parent[uft_x]!=-1)return uft_check_parent(uft_parent[uft_x]);
	int uft_a;
	while(!uft_q1.empty()){
		uft_a=uft_q1.front(),uft_q1.pop();
		uft_parent[uft_a]=uft_x;
	}
	return uft_x;
}

bool uft_connect(int uft_x,int uft_y){
	uft_x=uft_check_parent(uft_x),uft_y=uft_check_parent(uft_y);
	if(uft_x==uft_y){
		if(edge_num[uft_x]<uft_num[uft_x]){
			edge_num[uft_x]++;
			return true;
		}else return false;
	}
	if(edge_num[uft_x]+edge_num[uft_y]+1>uft_num[uft_x]+uft_num[uft_y])return false;
	if(uft_num[uft_x]>uft_num[uft_y])swap(uft_x,uft_y);
	uft_parent[uft_x]=uft_y;
	uft_num[uft_y]+=uft_num[uft_x];
	edge_num[uft_y]+=edge_num[uft_x]+1;
	return true;
}

priority_queue<T> q1;

int main(){
	int n,p,q;
	int i,j,k;
	int a,b,c;
	LL s=0;
	cin>>n>>p>>q;
	memset(uft_parent,-1,sizeof(uft_parent));
	for(i=0;i<p+q;i++)uft_num[i]=1;
	for(i=0;i<n;i++){
		cin>>a>>b>>c;
		a--,b--;
		q1.push(make_tuple(c,a,b));
	}
	while(!q1.empty()){
		tie(c,a,b)=q1.top(),q1.pop();
		if(uft_connect(a,p+b)){
			s+=c;
			//cout<<c<<endl;
		}
	}
	cout<<s<<endl;

}

Measured memory_bytes: 3448