akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
 
#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 10;

int main(void){
    ll N;
    ll p[MAX_N];
    ll p_max = 0;
    ll answer = 0;
    cin >> N;
    rep(i, N) cin >> p[i];

    rep(i, N){
        p_max = max(p_max, p[i]);
        answer += p[i];
    }

    cout << answer - p_max / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
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;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> H.at(i);
  }
  sort(H.begin(), H.end(), greater<ll>());

  ll ans = 0;
  for (ll i = K; i < N; i++)
  {
    ans += H.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<queue>
#include<algorithm>
#include<stack>
#include<vector>
#include<string>
using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	if (A > B)
		cout << A + A - 1;
	else if (A == B)
		cout << A + B;
	else
		cout << B + B - 1;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static long MOD = (long) 1e9 + 7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] a = new int[3][3];
		boolean[][] ans = new boolean[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				a[i][j] = sc.nextInt();
				ans[i][j] = false;
			}
		}
		int n = sc.nextInt();
		int[] b = arrayInt(sc, n);
		sc.close();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if (a[j][k] == b[i]) {
						ans[j][k] = true;
					}
				}
			}
		}
		if (solve(ans)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	public static boolean solve(boolean[][] a) {
		if (a[0][0] && a[1][1] && a[2][2]) {
			return true;
		}
		if (a[2][0] && a[1][1] && a[0][2]) {
			return true;
		}
		for (int i = 0; i < 3; i++) {
			if (a[i][2] && a[i][1] && a[i][0]) {
				return true;
			}
			if (a[0][i] && a[1][i] && a[2][i]) {
				return true;
			}
		}
		return false;
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static Integer[] arrayInteger(Scanner sc, int n) {
		Integer[] array = new Integer[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 23764
N = int(input())
S = input()
ok, ng = 0, N + 1
while abs(ok - ng) > 1:
    x = (ok + ng) // 2
    check = set()
    for i in range(N - x + 1):
        check.add(S[i: i + x])
        if S[i + x: i + 2 * x] in check:
            ok = x
            break
    else:
        ng = x

print(ok)

Measured memory_bytes: 103428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  ll n, time; cin >> n >> time;
  vector<ll> t(n);
  for(int i=0; i<n; i++)  cin >> t.at(i);

  ll ans = 0;
  for(int i=0; i<n-1; i++){
    ans += min(time, t[i+1]-t[i]);
  }
  cout << ans + time << endl;

}


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

int main(){
	int k;
	int s;
	int res=0;
	cin>>k>>s;
	for(int x=0;x<=k;x++){
		for(int y=0;y<=k;y++){
			int z=s-x-y;
			res+=(0<=z && z<=k);
		}
	}
	cout<<res<<endl;
	return 0;
}


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

int main()
{
	int number[5];
	cin >> number[0] >> number[1] >> number[2] >> number[3] >> number[4];

	for(int i=0;i<5;i++)
	{
		for(int j=4;j>i;j--)
		{
			if(number[j] > number[j-1])
			{
				int temp = number[j];
				number[j] = number[j-1];
				number[j-1] = temp;
			}
		}
	}

	cout << number[0] <<" "<< number[1] <<" "<< number[2] <<" "<< number[3] <<" "<< number[4] << endl;

	return 0;
}

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

using namespace std;

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

// chmax, chmin
template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

class UnionFind {
    std::vector<int> p;

public:
    UnionFind(int n) : p(n, -1) {}

    int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }

    bool same(int x, int y) { return root(x) == root(y); }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (p[y] < p[x]) std::swap(x, y);
        if (p[x] == p[y]) --p[x];
        p[y] = x;
        return true;
    }
};

long long cc[100010];

void solve(long long N, std::vector<long long> A, long long Q,
           std::vector<long long> B, std::vector<long long> C) {
    long long tot = 0;
    for(int i = 0 ; i < N ; i++) {
        cc[A[i]]++;
        tot += A[i];
    }
    for(int i = 0 ; i < Q ; i++) {
        tot -= cc[B[i]] * B[i];
        tot -= cc[C[i]] * C[i];
        cc[C[i]] += cc[B[i]];
        cc[B[i]] = 0;
        tot += cc[B[i]] * B[i];
        tot += cc[C[i]] * C[i];
        cout << tot << endl;
    }
}

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


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

int main() {
	long long x,y,z,k;
	cin >> x >> y >> z >> k;
	long long a[x],b[y],c[z],sum1[x*y],sum2[k*z];
	for(int i=0; i<x; i++) cin >> a[i];
	for(int i=0; i<y; i++) cin >> b[i];
	for(int i=0; i<z; i++) cin >> c[i];

	
  	long long l=0;
	for(int i=0; i<x; i++)
		for(int j=0; j<y; j++,l++)
				sum1[l] = a[i]+b[j];

	sort(sum1,sum1+l,greater<long long>());
  
  	l=0;
  for(int i=0; i<min(k,x*y); i++)
    for(int j=0; j<z; j++,l++)
      sum2[l] = sum1[i] + c[j];
  
  sort(sum2,sum2+l,greater<long long>());

	for(int i=0; i<k; i++) cout << sum2[i] << endl;
}


Measured memory_bytes: 31488
class Node
  attr_accessor :id, :key, :parent, :left, :right

  def initialize(id, n, parent)
    @id = id
    @key = nil
    @parent = parent
    @left  = Node.new(id*2  , n, self) if id*2   <= n
    @right = Node.new(id*2+1, n, self) if id*2+1 <= n
  end
  
  def set_key(id, key)
    n = self
    visited = [n]
    while not visited.empty?
      n = visited.shift
      # begin -------
      if not n.key
        n.key = key
        break
      end
      # end   -------
      visited << n.left if n.left
      visited << n.right if n.right
    end
  end
  
  def out
    n = self
    visited = [n]
    while not visited.empty?
      n = visited.shift
      # begin -------
      print "node #{n.id}: "
      print "key = #{n.key}, "
      print "parent key = #{n.parent.key}, " if n.parent
      print "left key = #{n.left.key}, " if n.left
      print "right key = #{n.right.key}, " if n.right
      puts ''
      # end   -------
      visited << n.left if n.left
      visited << n.right if n.right
    end
  end

end

n = gets.to_i
root = Node.new(1, n, nil)

keys = gets.split.map(&:to_i)
n.times do | i |
  root.set_key(i, keys[i])
end

root.out



Measured memory_bytes: 7008
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main() {
    int x;
    cin >> x;
    int a, b;
    for (int i = 1; i < 300; i++) {
        for (int j = -300; j < 300; j++) {
            if (pow(i, 5) - pow(j, 5) == x) {
                a = i;
                b = j;
                break;
            } 
        }
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 4100
# -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''


# ライブラリのインポート
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
import collections
#import math
global time, Ls, Lf, E,LG,c,n
time = 1

def main():
    global time, Ls, Lf, E, LG,c,n
    c = 0
    n = int(input().strip())
    E = [[] for _ in range(n)]
    LG = collections.deque()
    for line in sys.stdin:
        Ltmp = list(map(int, list(line.strip().split())))
        if not Ltmp[1] == 0: 
            E[Ltmp[0]-1] = Ltmp[2:]
    Ls = [0]*n 
    Lf = [0]*n
    dfs(0)
    for i in range(n):
        print(i+1, Ls[i],Lf[i])
    
def dfs(cur):
    global time, Ls, Lf, E, LG,c,n
    LG.append(cur)
    if Ls[cur] == 0: Ls[cur] = time
    time += 1
    for i in range(len(E[cur])):
        check = E[cur][i] - 1
        if Ls[check] == 0: dfs(check)
    if Lf[cur] == 0:
        Lf[cur] = time
    try:
        x = LG.pop()
        if x == cur: x = LG.pop() 
        dfs(x)
    except:
        time += 1
        for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
    return




    


    
if __name__ == '__main__':
    main()



Measured memory_bytes: 6184
# include <iostream>
# include <string>
# include <algorithm>

int s[4];
std::string str;

int main() {
	std::fill(s, s + 4, 0);
	std::cin >> str;
	for (int i = 0; i < str.size(); ++i) {
		if (str[i] == 'K')
			++s[0];
		else if (str[i] == 'U')
			++s[1];
		else if (str[i] == 'P')
			++s[2];
		else if (str[i] == 'C')
			++s[3];
	}
	int max = 10000;
	for (int i = 0; i < 4; ++i) {
		max = std::min(max, s[i]);
	}
	std::cout << max << std::endl;
	return 0;
}

Measured memory_bytes: 1188
/*
          .  .
          |\_|\
          | a_a\
          | | "]
      ____| '-\___
     /.----.___.-'\
    //        _    \
   //   .-. (~v~) /|
  |'|  /\:  .--  / \
 // |-/  \_/____/\/~|
|/  \ |  []_|_|_] \ |
| \  | \ |___   _\ ]_}
| |  '-' /   '.'  |
| |     /    /|:  |
| |     |   / |:  /\
| |     /  /  |  /  \
| |    |  /  /  |    \
\ |    |/\/  |/|/\    \
 \|\ |\|  |  | / /\/\__\
  \ \| | /   | |__
       / |   |____)
       |_/
*/

#include<bits/stdc++.h>

#define iamabatman ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precision cout.precision(10); cout << fixed;
#define endl '\n'

#define ll long long int
#define ull unsigned long long int
#define ld long double
const int INF = 1<<29;
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pii pair<int,int>
#define vi vector<int>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define debug(x) cerr<<#x<<'='<<(x)<<endl;
using namespace std;

int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void solve()
{
  int n,ans=0;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=n;j++)
    {
      for(int k=1;k<=n;k++)
      {
        ans+=gcd(k,gcd(i,j));
      }
    }
  }
  cout<<ans;

}


int main()
{

  iamabatman
  precision

  int t=1;
  //cin>>t;
  for(int ha=1;ha<=t;ha++)
  {
    //cout<<"Case #"<<ha<<": ";
    solve();
  }
  return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
 
int main() {
 
  int long long t=0,i=0,j=0,N,K;
  int ans=0;
  
  cin >> N >> K;
  
  while (pow(K,ans)<=N)
  {
    ans++;
  }
  
  
  
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 384
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]

ans = 0
for i in range(n):
  ans += sum(a[i])

memo = {}
for i in range(n):
  memo[i] = {}
for k in range(n):
  for i in range(n):
    for j in range(n):
      if k != i and i != j and j != k :
        if a[i][j] > a[i][k]+a[k][j]:
          print(-1)
          exit()
        elif a[i][j] == a[i][k]+a[k][j]:
          if j not in memo[i]:
            ans -= a[i][j]
            memo[i][j] = 1
                  
print(ans//2)

#プリム法
#mincost = [float("inf")]*n
#used = [False]*n
#mincost[0] = 0
#res = 0
#
#while True:
#  v = -1
#  for u in range(n):
#    if (not used[u]) and (v == -1 or mincost[u] < mincost[v]):
#      v = u
#  if v == -1:
#    break
#  used[v] = True
#  res += mincost[v]
#  for u in range(n):
#    mincost[u] = min(mincost[u],a[v][u])


Measured memory_bytes: 49372
#include<iostream> 
#include<stdio.h>
#include<string>
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (n); ++i)	
//setprecision(16)

void outi(int x) { cout << x << endl; }
void outl(ll x) { cout << x << endl; }
void outs(string x) { cout << x << endl; }
ll max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
ll min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}
//---------------------------------------------------------------

int main() {
	string s;
	cin >> s;
	string mae;
	mae.push_back(s[0]);
	mae.push_back(s[1]);
	string usiro;
	usiro.push_back(s[2]);
	usiro.push_back(s[3]);

	int m = stoi(mae);
	int u = stoi(usiro);

	
	if (0 < u && u <= 12) {
		if (0 < m && m <= 12) {
			outs("AMBIGUOUS");
		}
		else
		{
			outs("YYMM");
		}
	}
	else {
		if(0 < m && m <= 12)outs("MMYY");
		else outs("NA");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int M;
  ci(M);
  co(48 - M);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;cin>>n;
  unordered_map<int,int> m;
  while(n--) {
  	int t;cin>>t;
    if(m.find(t)!=m.end()) {
    	cout<<"NO"; exit(0);
    }
    m.insert(make_pair(t,1));
  }
  cout<<"YES";
}

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

int main() {
	long long n,k,c=1000000007,sm=0;
	cin >> n >> k;
	long long a = (n + 2) * (n + 1) / 2;
	for(long long i=k;i<=n+1;i++)
	{
		long long b = (n+1-i) * (n+2-i) /2;
		long long d = i * (i + 1) / 2;
		sm = (sm + a - b - d + 1) % c;
	}
	cout << sm << endl;
	return 0;
}



Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int read()
{
	char c=getchar();
	int res=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') res=(res<<1)+(res<<3)+(c^48),c=getchar();
	return res;
}
int n,A,B;
int a[5005];
long long dp[5005];
int main()
{
	n=read(),A=read(),B=read();
	for(int i=1;i<=n;i++) a[i]=read();
	a[n+1]=0x3f3f3f3f;memset(dp,0x3f,sizeof(dp));dp[0]=0;
	for(int i=1;i<=n+1;i++)
	{
		int sl=0,sr=0;
		for(int j=i-1;j>=0;j--)
		{
			if(a[j]<a[i]) dp[i]=min(dp[i],dp[j]+1ll*sl*A+1ll*sr*B);
			if(a[j]>a[i]) sl++;if(a[j]<a[i]) sr++;
		}
	}
	printf("%lld\n",dp[n+1]);
}

Measured memory_bytes: 3828
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
items = [list(map(int, input().split())) for i in range(M)]
items = sorted(items, key=lambda x: x[1])
last = 0
res = 0
for a, b in items:
    if last <= a:
        res += 1
        last = b
print(res)


Measured memory_bytes: 90072
N, K = map(int, input().split())
S = input()
S += '2'

A = []
if S[0] == '0':
  A.append(0)

cnt = 1
for i in range(1, len(S)):
  if S[i] == S[i-1]:
    cnt += 1
  else:
    A.append(cnt)
    cnt = 1

ans = 0
tot = 0
r = 0

for l in range(len(A)):
  while r < len(A) and r - l < 2 * K + 1:
    tot += A[r]
    r += 1
  if l % 2 == 0:
    ans = max(ans, tot)
  if l == r:
    r += 1
  else:
    tot -= A[l]

print(ans)


Measured memory_bytes: 4084
import sys

a, b, c, d = tuple(input())
op = ('+', '-')

for op1 in op:
    for op2 in op:
        for op3 in op:
            res = a + op1 + b + op2 + c + op3 + d
            if eval(res) == 7:
                print(res + '=7')
                sys.exit(0)



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000001

int h, w;
char origin[500][500], a[500][500], b[500][500];

bool range(int y, int x) {
    return 0 <= y && y < h && 1 <= x && x < w;
}

int main(){
    cin.sync_with_stdio(false);
    cin >> h >> w;

    rep(i, h)rep(j, w) {
        cin >> origin[i][j];
        a[i][j] = b[i][j] = origin[i][j];
    }

    rep(i, h)rep(j, w) {
        if (j != w - 1 && i % 2 == 0 || j == 0) a[i][j] = '#';
        cout << a[i][j] << ((j == w - 1) ? "\n" : "");
    }
    cout << endl;
    rep(i, h)rep(j, w) {
        if (j != 0 && i % 2 == 1 || j == w - 1) b[i][j] = '#';
        cout << b[i][j] << ((j == w - 1) ? "\n" : "");
    }

    return 0;
}

Measured memory_bytes: 1536
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
A = lr()
BC = [lr() for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
D = []
count = 0
for b, c in BC:
    D += [c] * b
    count += b
    if count >= N:
        break

A += D
A.sort(reverse=True)
answer = sum(A[:N])
print(answer)


Measured memory_bytes: 36032
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, m;
    cin >> n >> m;
    vector<P> key;
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        int s = 0;
        rep(j,b) {
            int c;
            cin >> c;
            c--;
            s |= 1<<c;
        }
        key.emplace_back(s,a);
    }

    vector<int> dp(1<<n, INF);
    dp[0] = 0;
    rep(s,1<<n) {
        rep(i,m) {
            int t = s | key[i].first;
            chmin(dp[t], dp[s] + key[i].second);
        }
    }
    int ans = dp.back();
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>

using ll = long long;
using namespace std;
//#define int long long

int main() {
	int a, b;
	string asum, bsum;
	cin >> a >> b;
	for (int i = 0; i < b; i++) {
		asum += to_string(a);
	};
	for (int i = 0; i < a; i++) {
		bsum += to_string(b);
	};
	cout << min(asum, bsum) << endl;

	

	return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]

for s in S:
    for i in range(len(s)):
        if s[i] == ".":
            s[i] = 0

for i in range(len(S)):
    for j in range(len(S[i])):
        if S[i][j] == "#":
            if i != 0:
                if S[i - 1][j] != "#":
                    S[i - 1][j] += 1
                if j != 0 and S[i - 1][j - 1] != "#":
                    S[i - 1][j - 1] += 1
                if j != W - 1 and S[i - 1][j + 1] != "#":
                    S[i - 1][j + 1] += 1
            if j != 0 and S[i][j - 1] != "#":
                S[i][j - 1] += 1
            if j != W - 1 and S[i][j + 1] != "#":
                S[i][j + 1] += 1
            if i != H - 1:
                if S[i + 1][j] != "#":
                    S[i + 1][j] += 1
                if j != 0 and S[i + 1][j - 1] != "#":
                    S[i + 1][j - 1] += 1
                if j != W - 1 and S[i + 1][j + 1] != "#":
                    S[i + 1][j + 1] += 1

for s in S:
    print("".join(map(str,s)))
        

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#define ll long long
using namespace std;
const int MAXN=200005;
int read(){int x;scanf("%d",&x);return x;}
int n,k,a[MAXN],ans;
void readin(){
	n=read(),k=read(),ans=1e9+7;
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	for(int i1=1;i1<=n-k+1;i1++){
		ll j=a[i1+k-1],i=a[i1];
		//ans=min(ans,i*j<0?min(abs(i),abs(j))*2+max(abs(i),abs(j)):max(abs(i),abs(j)));
		int x=(i*j<0)?min(abs(i),abs(j))*2+max(abs(i),abs(j)):max(abs(i),abs(j));
		ans=min(ans,x);
	}
	printf("%d\n",ans);
}
int main(){
	readin();
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll a[4][maxn];
ll len[4];
ll sum[4][maxn];
ll ma[maxn];
ll mb[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
int main() {
	int x,y;
	cin>>x>>y>>len[1]>>len[2]>>len[3];
	for(int l=1;l<=3;l++)
		for(int i=1;i<=len[l];i++)	
			cin>>a[l][i];
	for(int l=1;l<=3;l++)	sort(a[l]+1,a[l]+1+len[l],cmp);
	for(int i=1;i<=3;i++){
		for(int j=1;j<=len[i];j++){
			sum[i][j] = sum[i][j-1]+a[i][j];
		}
	}
	int cnt1 = 1;
	int cnta = 1;
	int cntc = 1;
	while(cnt1<=(x+len[3])&&cnta<=x&&cntc<=len[3]){
		if(a[1][cnta]>=a[3][cntc]){
			ma[cnt1] = ma[cnt1-1]+a[1][cnta];
			cnt1++;
			cnta++;
		}
		else {
			ma[cnt1] = ma[cnt1-1]+a[3][cntc];
			cnt1++;
			cntc++;
		}
	}
	while(cnta<=x){
		ma[cnt1] = ma[cnt1-1]+a[1][cnta];
		cnt1++;
		cnta++; 
	}
	while(cntc<=len[3]){
		ma[cnt1] = ma[cnt1-1]+a[3][cntc];
		cnt1++;
		cntc++; 
	}
	int cnt2 = 1;
	int cntb = 1;
	cntc = 1;
	while(cnt2<=(y+len[3])&&cntb<=y&&cntc<=len[3]){
		if(a[2][cntb]>=a[3][cntc]){
			mb[cnt2] = mb[cnt2-1]+a[2][cntb];
		//	cout<<mb[cnt2]<<"  "<<a[2][cntb]<<endl;
			cnt2++;
			cntb++;
		}
		else {
			mb[cnt2] = mb[cnt2-1]+a[3][cntc];
		//	cout<<mb[cnt2]<<"  "<<a[3][cntc]<<endl;
			cnt2++;
			cntc++;
		}
	}
	while(cntb<=y){
		mb[cnt2] = mb[cnt2-1]+a[2][cntb];
	//	cout<<a[2][cntb]<<endl;
		cnt2++;
		cntb++; 
	}
	while(cntc<=len[3]){
		mb[cnt2] = mb[cnt2-1]+a[3][cntc];
	//	cout<<a[3][cntc]<<endl;
		cnt2++;
		cntc++; 
	}
	int ba = max(1LL,x-len[3]);
	int bb = max(1LL,y-len[3]);
//	for(int i=ba;i<=(len[1]+len[3]);i++) cout<<ma[i]<<" ";
//	cout<<endl;
//	for(int i=1;i<=(len[2]+len[3]);i++) cout<<mb[i]<<" ";
//	cout<<endl;
	ll ans = 0;
	for(int i=ba;i<=x;i++){
		ans = max(ans,sum[1][i]+mb[x+y-i]);
	}
	for(int i=bb;i<=y;i++){
		ans = max(ans,sum[2][i]+ma[x+y-i]);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 14976
n=int(input())
a=1;c={"R":0,"G":0,"B":0}
m=998244353
for i in input():
	s=sorted(c.values())
	c[i]+=1
	if c[i]>s[2]:pass
	elif c[i]>s[1]:a*=s[2]-s[1]
	else:a*=s[1]-s[0]
	a%=m
for j in range(1,n+1):
	a*=j
	a%=m
print(a)

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

int main() {
int sx,sy,tx,ty;
cin >> sx>>sy>>tx>>ty;
string a,A,b,B;
int dx = tx-sx;
int dy = ty-sy;
for(int i=0;i<dx;i++){
    a+="R";
    b+="L";
}
for(int j=0;j<dy;j++){
    a+="U";
    b+="D";
}
A="DR"+a+"UL";
B="UL"+b+"DR";
cout <<a<<b<<A<<B<<endl;  
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <string>//
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
        string s;
        int N;
        cin >> s;
        N=s.size();
        ll ans = 0;
        
        rep(i,1<<(N - 1))
        {
                ll sum = 0;
                ll a = s[0] - '0';
                rep(j,N-1) {
                        if (i & (1 << j))
                        {
                            sum += a;
                            a = 0;
                        }
                        a = a * 10 + (s[j + 1] - '0');
                }
                sum += a;
                ans += sum;
        }
        cout << ans << endl;

        return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N,Q;
    string s;
    cin>>N>>Q>>s;
    char t[Q],d[Q];
    rep(i,Q){
        cin>>t[i]>>d[i];
    }

    int leftng=-1,leftok=N,rightok=-1,rightng=N;    
    while(abs(leftok-leftng)>1){
        int mid=(leftng+leftok)/2;
        int x=mid;
        rep(i,Q){
            if(s[x]==t[i]){
                if(d[i]=='L') x--;
                else x++;
            }
        }
        if(x==-1){
            leftng=mid;
        }else{
            leftok=mid;
        }

    }

    while(abs(rightng-rightok)>1){
        int mid=(rightng+rightok)/2;
        int x=mid;
        rep(i,Q){
            if(s[x]==t[i]){
                if(d[i]=='L') x--;
                else x++;
            }
        }
        if(x==N){
            rightng=mid;
        }else{
            rightok=mid;
        }

    }
    cout << rightok-leftok+1 << endl;



}


Measured memory_bytes: 976
from collections import Counter
n=int(input())
a=input().split()

b=Counter(a[::2])
c=Counter(a[1::2])

bn=0
b1=('0',0)
b2=('0',0)
c1=('0',0)
c2=('0',0)
for i in b.most_common():
  if bn==0:
    b1=i
  if bn==1:
    b2=i
  bn+=1
cn=0  
for i in c.most_common():
  if cn==0:
    c1=i
  if cn==1:
    c2=i
  cn+=1
if b1[0]!=c1[0]:
  print(n-b1[1]-c1[1])
elif b1[1]+c2[1]>c1[1]+b2[1]:
  print(n-b1[1]-c2[1])
else:
  print(n-b2[1]-c1[1])

Measured memory_bytes: 22380
#!/bin/bash

read h1 m1 h2 m2 k
#$(( h1 * 60 + m1 ))
h=$(( h2 - h1 ))
#h=`expr $h2 - $h1`
if [ $m2 -ge $m1 ]; then
#        m=`expr $m2 - $m1`
        m=$(( m2 - m1 ))
else
        h=`expr $h - 1`
        #h=$(( h - 1 ))
        m=`expr $m2 - $m1 + 60`
        #m=$(( m2 - m1 + 60 ))
fi

#expr $h \* 60 + $m - $k
echo $(( h * 60 + m - k ))

Measured memory_bytes: 3808
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int r;
    int rnk[112345];
    int n, m, a[112345], b[112345];

    V g[112345], h[112345];

    int t[112345] = {0};

    cin >> n >> m;

    memset(rnk, -1, sizeof(rnk));

    REP(i, n - 1 + m)
    {
        cin >> a[i] >> b[i];

        t[b[i]]++;

        g[a[i]].push_back(b[i]);
        h[b[i]].push_back(a[i]);
    }

    V v;
    queue<int> q;

    REP(i, n)
    if (t[i + 1] == 0)
    {
        q.push(i + 1);
        v.push_back(i + 1);
    }

    while (q.size())
    {
        int p = q.front();
        q.pop();

        for (int i : g[p])
        {
            t[i]--;
            if (t[i] == 0)
            {
                q.push(i);
                v.push_back(i);
            }
        }
    }

    REP(i, n)
    rnk[v[i]] = i;

    for (int i = 1; i <= n; i++)
    {
        int ma = -1;
        int res = 0;

        for (int j : h[i])
        {
            if (ma < rnk[j])
            {
                ma = rnk[j];
                res = j;
            }
        }

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 16380
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,c=0;        
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    for(int i=1;i<n-1;i++)
    {
        if(v[i-1]>v[i]&&v[i]>v[i+1])
            c++;
        else if(v[i]>v[i-1]&&v[i]<v[i+1])
            c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
      string S;
      cin >> S;
      int ans = false;
      if(S[0] == '9' || S[1] == '9')ans = true;
      if(ans)cout << "Yes";
      else cout << "No";
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

vector<pair<int,int> > v;
int main(){
  string s;
  int k;
  int now = 0;
  cin>>s;
  cin>>k;
  for(int i = 0;i<s.size();i++){
    if(s[i] != 'a'){
      //cout<<"a"<<endl;
      if('z'-s[i]+1<=k-now){
	//	cout<<"b"<<endl;
	now += 'z'-s[i]+1;
	s[i] = 'a';

      }
    }
    // cout<<"s:"<<s<<"\tnow:"<<now<<endl;
  }
  if(k!=now){
    int tmp = (k-now)%26;
    //cout<<"tmp:"<<tmp<<endl;
    if((int)s[s.size()-1]+tmp>'z')
      tmp -= 'z';
    s[s.size()-1] = s[s.size()-1]+tmp;
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 512
import itertools

N, A, B, C = map(int, input().split())
t = [A, B, C]

l = []
for i in range(N):
    l.append(int(input()))

ans = 999999999
count = 0

products = list(itertools.product([0, 1, 2, 3], repeat=N))
# [0, 1, 2, 3]の中からN個（重複可）とってきた時の総当たりの組み合わせ
for p in products:
    scores_g = [[0, 0], [0, 0], [0, 0], [0, 0]]
    for i in range(len(p)):
        scores_g[p[i]][0] += l[i]
        scores_g[p[i]][1] += 1
    for g in range(3):
        if scores_g[g][1] == 0:
            count = 999999999
            continue
        else:
            count += abs(scores_g[g][0] - t[g]) + (scores_g[g][1] - 1) * 10
    if ans > count:
        ans = count
    count = 0

print(ans)

Measured memory_bytes: 10996
#include <stdio.h>

int x[110],ans[110];
int a;
void func(int k, int value, int& sum)
{
	x[k] = value;
	if(k==1)
	{
		sum++;
		if(sum==a) for(int i=1;i<=10;i++) ans[i] = x[i];
		return;
	}
	
	if(value>=1) func(k-1,value-1,sum);
	func(k-1,value,sum);
	if(value<=8) func(k-1,value+1,sum);
	
}
int main()
{
	scanf("%d",&a);
	
	int sum = 0;
	for(int i=1;i<=10;i++)
	{
		for(int j=1;j<=9;j++)
		{
			func(i,j,sum);
		}
	}
	
	int p = 0;
	for(int i=10;i>=1;i--)
	{
		if(ans[i]!=0)
		{
			p = i;
			break;
		}
	}
	for(int i=p;i>=1;i--) printf("%d",ans[i]);
}

Measured memory_bytes: 128
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <sstream>
using namespace std;

#define LL long long
#define LD long double
#define PR pair<int,int>

#define Min(a,b) a=min(a,b)
#define Max(a,b) a=max(a,b)
#define Sz(s) int((s).size())
#define All(s) (s).begin(),(s).end()
#define Fill(s,v) memset(s,v,sizeof(s))
#define pb push_back
#define mp make_pair
#define x first
#define y second

template<typename T> T Abs(T x) { return(x<0 ? -x : x); }
template<typename T> T Sqr(T x) { return(x*x); }

const int INF = (int)1e9;
const LD EPS = 1e-12;
const LD PI = acos(-1.0);

bool s[200010];
int n;


int main() {
	cin >> n;
	char x;
	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> x;
		if (x == '.') {
			s[i] = true;
			count++;
		}
	}
	int ans=count;
	for (int i = 0; i < n; i++) {
		if (s[i]) count--;
		else count++;
		Min(ans,count);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
S = input()

w_count = S.count('W')
e_count = S.count('E')

result = min(w_count, e_count)
left_w = 0
right_e = e_count
for s in S:
    # i番目がリーダーの場合
    result = min(result, left_w + right_e)
    if s == 'W':
        left_w += 1
    else:
        right_e -= 1

print(result)


Measured memory_bytes: 68436
x = int(input())

if x >= 400 and x < 600:
    print(8)
elif x >= 600 and x < 800:
    print(7)
elif x >= 800 and x < 1000:
    print(6)
elif x >= 1000 and x < 1200:
    print(5)
elif x >= 1200 and x < 1400:
    print(4)
elif x >= 1400 and x < 1600:
    print(3)
elif x >= 1600 and x < 1800:
    print(2)
else:
    print(1)

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

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  int days = 0;
  if (A >= B){
    cout << "delicious" << endl;
  }
  else if (X+A >= B){
    cout << "safe" << endl;
  }
  else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100005;
int n,L,Q,x[maxn],f[maxn][18],g[maxn][18];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]);
	scanf("%d",&L);
	for(int i=1;i<=n;i++)
		f[i][0]=upper_bound(x+1,x+n+1,x[i]+L)-x-1;
	for(int j=1;j<=17;j++)
		for(int i=n;i;i--)
			f[i][j]=f[f[i][j-1]][j-1];
	for(int i=1;i<=n;i++)
		g[i][0]=lower_bound(x+1,x+n+1,x[i]-L)-x;
	for(int j=1;j<=17;j++)
		for(int i=1;i<=n;i++)
			g[i][j]=g[g[i][j-1]][j-1];
	int a,b;
	scanf("%d",&Q);
	while(Q--)
	{
		scanf("%d%d",&a,&b);
		int ans=0;
		if(a<b)
		{
			for(int i=17;i>=0;i--)
				if(f[a][i]<b) a=f[a][i],ans+=(1<<i);
		}
		else
		{
			for(int i=17;i>=0;i--)
				if(g[a][i]>b) a=g[a][i],ans+=(1<<i);
		}
		printf("%d\n",ans+1);
	}
	return 0;
}

Measured memory_bytes: 15232
#include <iostream>
using namespace std;
int main(){
  int R;
  cin>>R;
  if(R<1200)
    cout<<"ABC"<<endl;
  else if(R>=1200 && R<2800)
    cout<<"ARC"<<endl;
  else
    cout<<"AGC"<<endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,k;
  cin>>a>>b>>c>>k;
  long long ans=0;
  if(a<=k){
    k-=a;
    ans+=a;
    if(b<=k){
      k-=b;
      if(k>=0){
        ans-=k;
        cout<<ans<<endl;
        return 0;
      }
    }else{
      cout<<ans<<endl;
      return 0;
    }
  }else{
    ans+=k;
    cout<<ans<<endl;
    return 0;
  }
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const ll INF= LLONG_MAX/3;
using pl = pair<ll,ll>;

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

    ll rl=INF, rr=0, bl=INF, br=0;

    vector<pl> p(n);
    multiset<ll> R,B;
    rep(i,n)
    {
        ll x,y;
        scanf(" %lld %lld", &x, &y);
        if(x>y) swap(x,y);

        p[i] = pl(x,y);

        rl=min(rl,x);
        rr=max(rr,x);
        bl=min(bl,y);
        br=max(br,y);

        R.insert(x);
        B.insert(y);
    }

    sort(all(p));
    priority_queue<pl> que;
    rep(i,n) que.push(pl(p[i].se,i));

    ll ans=(rr-rl)*(br-bl);
    while(!que.empty())
    {
        pl val=que.top();
        que.pop();

        int idx=val.se;
        auto ir = R.find(p[idx].fi);
        auto ib = B.find(p[idx].se);

        R.erase(ir);
        R.insert(p[idx].se);

        B.erase(ib);
        B.insert(p[idx].fi);

        rl = *R.begin();
        rr = *R.rbegin();
        bl = *B.begin();
        br = *B.rbegin();
        ans = min(ans,(rr-rl)*(br-bl));
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 28276
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
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 <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int a,b;
    cin >> a >> b;
    int aa = 0, bb = 0;
    string aaa, bbb;
    rep(i,a) {
        aaa += to_string(b);
    }
    rep(i,b) {
        bbb += to_string(a);
    }
    cout << min(aaa,bbb) << "\n";
}


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

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	vector<int> w(1000000);
	vector<int> e(1000000);
	w[0] = 0;
	e[n - 1] = 0;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'W') w[i + 1] = w[i] + 1;
		else w[i + 1] = w[i];
	}
	for (int j = n - 1; j > 0; j--) {
		if (s[j] == 'E') e[j - 1] = e[j] + 1;
		else e[j - 1] = e[j];
	}
	int ans = 1000000;
	for (int k = 0; k < n; k++) {
		if (ans > w[k] + e[k]) ans = w[k] + e[k];
	}
	cout << ans << endl;
}

Measured memory_bytes: 8452
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],flag=1;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(a[i]%2==0)
		{
			if(a[i]%3!=0&&a[i]%5!=0)
			{
				flag=0;
				break;
			}
		}
	}
	if(flag==0) cout<<"DENIED"<<endl;
	else cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var graph [][]int
var used [][]bool
var color []int

func main() {
  var n,m int = Next2Ints()
  graph = make([][]int,n)
  used = make([][]bool,11)
  for i:=0;i<11;i++ { used[i] = make([]bool,n) }
  color = make([]int,n)
  for i:=0;i<m;i++ {
    var a,b int = Next2Ints()
    graph[a-1] = append(graph[a-1],b-1)
    graph[b-1] = append(graph[b-1],a-1)
  }
  var q int = NextInt()
  qs := Queries{}
  for k:=0;k<q;k++ {
    var v,d,c int = Next3Ints()
    qs = append(qs,Query{v-1,d,c})
  }
  for k:=q-1;k>-1;k-- {
    dfs(qs[k].v,qs[k].d,qs[k].c)
  }
  for i:=0;i<n;i++ { fmt.Println(color[i]) }
}

func dfs(v,d,c int) {
  if d < 0 || used[d][v] { return }
  if color[v] == 0 { color[v] = c }
  used[d][v] = true
  dfs(v,d-1,c)
  for _,e := range graph[v] { dfs(e,d-1,c) }
}

type Query struct { v,d,c int }
type Queries []Query

var reader = bufio.NewReaderSize(os.Stdin,1000000)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInt() int {
  x,_ := strconv.Atoi(NextLine())
  return x
}
func Next2Ints() (int,int) {
  s := strings.Split(NextLine()," ")
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}
func Next3Ints() (int,int,int) {
  s := strings.Split(NextLine()," ")
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  z,_ := strconv.Atoi(s[2])
  return x,y,z
}

Measured memory_bytes: 23936
N, M = map(int, input().split())
x = [0] * (N + 1)

for i in range(M):
  l, r = map(int, input().split())
  x[l - 1] += 1
  x[r] -= 1
  
for i in range(1, N + 1):
  x[i] += x[i - 1]
  
#print(x)
print(x.count(M))

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

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

    int n;
    cin >> n;

    vector<int> v(n);

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

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

    cout << v[(n/2)] - v[(n/2)-1] <<endl;

    return 0;
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MAX_INF = 9223372036854775807;
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init, ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T>& v) {
	T ans = -INF;
	rep(i, 0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C & c, std::ostream & os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}


ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll n, m, t, q, s,k,h,w;

void warshall_floyd(ll v_num,vector<vector<long long>> &d) {
	for (long long k = 0; k < v_num; k++) {       // 経由する頂点
		for (long long i = 0; i < v_num; i++) {    // 始点
			for (long long j = 0; j < v_num; j++) {  // 終点
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

ll findIndex(vl& vec, ll num) {
	rep(i, 0, vec.size()) {
		if (vec[i] == num)return i;
	}
	return -1;
}

int main() {
	cin >> n;
	ll nowh = 1, noww = 1;
	rep(i, 0, n) {
		cin >> h >> w;
		ll bai = max(kiriage(nowh, h), kiriage(noww, w));
		nowh = h * bai;
		noww = w * bai;
	}
	printf("%lld\n", nowh + noww);
}

Measured memory_bytes: 256
ss = input()

S1 = []
S2 = []

a = 0
for ind, s in enumerate(ss):
    if '\\' == s:
        S1.append(ind)
    elif s == '/':
        if len(S1) == 0:
            continue
        i = S1.pop()
        a += ind - i
        t = 0
        while len(S2) > 0 and S2[-1][0] > i-1:
            v = S2.pop()
            t += v[1]
        S2.append((i, ind-i+t))

print(a)
if len(S2) == 0:
    print(0)
else:
    print(len(S2), ' '.join(map(lambda x: str(x[1]), S2)))

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

int main() {
    int n;
    cin>>n;
    vector<int> d(n);
    rep(i,n){
        cin>>d[i];
    }
    long ans=0;
    rep(i,n){
        for(int k=i+1;k<n;k++){
            ans=ans+(d[i]*d[k]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612