akhauriyash/Code-Regression huggingface dataset:
k = int(input())
a,b = [int(i) for i in input().split(' ')]

if a%k == 0 or b%k == 0:
    print('OK')
else:
    a1 = a+1
    for i in range(a1, b):
        if (i%k == 0):
            print('OK')
            break
    else:
        print('NG')

Measured memory_bytes: 9180
# https://atcoder.jp/contests/abc153/tasks/abc153_c
import numpy as np
N, K = map(int, input().split())
H = np.array(list(map(int, input().split())), dtype='int64')
H.sort()
# print('H', H)
if N <= K:
    print(0)
    exit()
if K == 0:
    print(H.sum())
    exit()
subset = H[:-K]
# print(subset)
print(subset.sum())


Measured memory_bytes: 42232
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int con = Integer.parseInt(in.nextLine().split(" ")[1]) - 1;
        String str = in.nextLine();
        in.close();
        char c = (char) (str.charAt(con) + 32);
        String ans = str.substring(0, con) + String.valueOf(c) + str.substring(con + 1);
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
# describe Abc134C do
#   context 'test' do
#     it 'sample' do
#       expect(Abc134C.calc(3, [1,4,3])).to match([4,3,4])
#       expect(Abc134C.calc(2, [5, 5])).to match([5,5])
#     end
#   end
# end

class Abc134C
  def self.input()
    n = STDIN.gets.to_i
    a_array = Enumerator.new do |y|
      loop do
        y << STDIN.gets.to_i
      end
    end.take(n)
    [n, a_array]
  end

  def self.output(result_array)
    puts result_array
  end

  def self.calc(n, a_array)
    a_max, a_max_2 = a_array.to_enum.sort_by{|x| -1 * x }.take(2)
    result_array = a_array.map{|x| x == a_max ? a_max_2: a_max }
    result_array
  end

  def self.main()
    n, a_array = input()
    result_array = calc(n, a_array)
    output(result_array)
  end
end

if __FILE__ == $0
  Abc134C.main
  exit
end

Measured memory_bytes: 9668
from sys import stdin
input = stdin.readline

from collections import deque, defaultdict

def bfs(s):
    Q.append(s)
    color[s] = 1

    while Q:
        u = Q.popleft()

        out.append(u)

        for edge in range(e):
            s, t = list(map(int, lines[edge+1].split()))
            if s == u:
                indeg[t] -= 1
                if indeg[t] == 0 and color ==0:
                    color[t] = 1
                    Q.append(t)


lines = stdin.readlines()

v, e = list(map(int, lines[0].split()))

out = []
outs = defaultdict(list)


color = [0] * v
indeg = [0] * v

for i in range(e):
    s, t = list(map(int, lines[i+1].split()))
    outs[s].append(t)
    indeg[t] += 1

Q = deque(v1 for v1 in range(v) if indeg[v1] == 0)

while Q:
    v1 = Q.popleft()
    out.append(v1)

    for v2 in outs[v1]:
        indeg[v2] -= 1
        if indeg[v2] == 0:
            Q.append(v2)

for i in out:
    print(i)




Measured memory_bytes: 12812
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

template <typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
using Edges = vector<Edge<T>>;
template <typename T>
using AdjList = vector<Edges<T>>;

template <typename T>
class Dijkstra {
    private:
        T INF = numeric_limits<T>::max() / 10;
        int V;           // 頂点数
        AdjList<T> adj;  // adj[始点][動的配列で始点から伸びる枝]
        vector<int> prever;

    public:
        Dijkstra(int n);
        vector<T> cost;
        void AddEdge(int f, int t, int c);
        bool HasPath(int t);                 // tに至るパスはあるか
        vector<int> GetShortestPath(int t);  // tへの最短路
        void Run(int f);
};

template <typename T>
Dijkstra<T>::Dijkstra(int n) :
    V(n + 1), adj(V), prever(vector<int>(V, -1)), cost(V)
{
    fill(cost.begin(), cost.end(), INF);
}

template <typename T>
void Dijkstra<T>::AddEdge(int f, int t, int c) {
    adj[f].push_back(Edge<T>(t, c));
}

template <typename T>
bool Dijkstra<T>::HasPath(int t) {
    return cost[t] != INF;
}

template <typename T>
vector<int> Dijkstra<T>::GetShortestPath(int t) {
    vector<int> path;
    for (; t != -1; t = prever[t]) path.push_back(t);

    reverse(path.begin(), path.end());
    return path;
}

template <typename T>
void Dijkstra<T>::Run(int firstNode) {
    // 初期化
    cost.assign(V, INF);
    prever.assign(V, -1);

    using Pi = pair<T, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> pq;

    cost[firstNode] = 0;
    pq.push(Pi(cost[firstNode], firstNode));

    while (!pq.empty()) {
        Pi currentEdge = pq.top();
        pq.pop();
        if (cost[currentEdge.second] < currentEdge.first) continue;

        for (Edge<T> tmp : adj[currentEdge.second]) {
            T sumCost = currentEdge.first + tmp.cost;
            if (cost[tmp.to] > sumCost) {
                cost[tmp.to] = sumCost;
                prever[tmp.to] = currentEdge.second;
                pq.push(Pi(cost[tmp.to], tmp.to));
            }
        }
    }
}

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

    int n;
    cin >> n;

    Dijkstra<LL> dij(n);
    REP(i, n-1){
        int a, b, c;
        cin >> a >> b >> c;
        dij.AddEdge(a-1, b-1, c);
        dij.AddEdge(b-1, a-1, c);
    }

    int q, k;
    cin >> q >> k;
    dij.Run(k-1);
    REP(i, q){
        int x, y;
        cin >> x >> y;
        cout << dij.cost[x-1] + dij.cost[y-1] << endl;
    }
}

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

#define ll long long

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	ll K,n;
	cin >> s;
	cin >> K;
	n = s.size();
	bool all_same = 1;
	for(int i=0;i<n;i++){
		if(s[i]==s[0])continue;
		else{
			all_same = 0;
			break;
		}
	}
	ll ans = 0;
	ll a=0,b=0;
	for(int i=0;i<n;i++){
		int cnt = 1;
		while(s[i]==s[i+1]){
			cnt++;
			i++;
		}
		ans += (cnt/2)*K;
	}
	if(all_same){
		ans = (K*n)/2;
	}else{
		if(s[0]==s[n-1]){
			while(s[a]==s[a+1])a++;
			while(s[n-1-b]==s[n-1-b-1])b++;
			a++;
			b++;
			ans = a/2 + b/2 + (a+b)/2 * (K-1);
			for(int i=a;i<n-b;i++){
				int cnt = 1;
				while(s[i]==s[i+1]){
					cnt++;
					i++;
				}
				ans += (cnt/2) * K ;
			}
		}
	}
	cout << ans << endl;
}

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

#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(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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 (a>b) { a=b; return 1; } return 0; }

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

const int INF = 0x3fffffff;


int main(){
	int N, ans=0;
	string s;

	cin >> s;
	rep(i,s.length()){
		if(i==4) cout << " ";
		cout << s[i];
	}
	cout << endl;


	return 0;
}


Measured memory_bytes: 256
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N=int(input())

if N==1:
    print(0)
else:
    a=factorization(N)

    ans=0

    for j in range(len(a)):
        for k in range(1000000000000000):
            a[j][1]-=k
            ans+=1
            if a[j][1]-(k+1)<0:
                ans-=1
                break
    print(ans)


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

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  int size = 0;
  int np = 0, nd = 0;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}


Measured memory_bytes: 33016
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

#define N 5000000000000000

int main(int argc, char const *argv[]) {
    string S;
    unsigned long long K;
    cin  >> S >> K;
    //cout << pow(2, N) << endl;

    unsigned long long cnt_left = 0;
    for(auto c:S) {
        int n = atoi(&c);
        if(n == 1) {
            cnt_left++;
            if(cnt_left == K) {
                cout << 1 << endl;
                break;
            }
        } else {
            cout << n << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <fstream>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
typedef long long ll;



int main() {

   ll N,A,B;
   cin >> N >> A >> B;

   ll minim = (N-1) * A + B;
   ll maxim = (N-1) * B + A;

   ll ans = maxim - minim + 1;

   cout << max((ll)0,ans) << endl;

   return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> a(N);
	REP(i, N) cin >> a[i];

	set<ll> st;
	st.insert(N);
	st.insert(-1);
	ll res = 0;
	vector<ll> place(N+1);
	REP(i, N) place[a[i]] = i;

	for(int i=1;i<=N;i++){
		auto itr = st.lower_bound(place[i]);
		ll migi = *itr;
		itr--;
		ll hidari = *itr;
		res += i*(migi - place[i])*(place[i] - hidari);
		st.insert(place[i]);
		/*
		dump(i)
		dump(migi)
		dump(hidari)
		dump(place[i])
		cout << endl;
		*/
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int mx = 0;
  for(int i = 0 ; i < n ; i++ ){
    int sum = 0;
    for(int j = 0 ; j < m ; j++ ){
      int a;
      cin >> a;
      sum += a;
    }
    mx = max(mx,sum);
  }
  cout << mx << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

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

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)



void solve() 
{
    int n;
    int k;
    cin>>n>>k;
    vector<ll> marks(n);
	for(int i = 0; i<n; i++)
    {
        cin>>marks[i];
    }
    for(int i= k; i<n; i++)
    {
        if(marks[i]>marks[i-k])
        {
            cout<<"Yes"<<'\n';
        }
        else
        {
            cout<<"No"<<'\n';
        }
        
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

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


Measured memory_bytes: 4780
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto K = readln.chomp.to!long;
    auto rs = new long[](50);
    if (K < 50) {
        foreach (ref r; rs[0..K]) r = 50;
    } else {
        rs[] = 49;
        foreach (ref r; rs) r += K / 50;
        auto m = K % 50;
        foreach (ref r; rs[0..m]) r += 50;
        foreach (ref r; rs) r -= K % 50;
    }
    writeln(50);
    writeln(rs.to!(string[]).join(" "));
}

Measured memory_bytes: 2776
#include <bits/stdc++.h>//stayCalmNeverSettle
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define szof(x) ((int)x.size())
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii; 
int const INF = (int)1e9+1e3;
ll const INFL = (ll)1e18+1e6;

const int N = 2e5+5;

set<int> adj_list[N];
int cnt_node = 0;
void dfs(int s,vector<bool>& visited){
	if(visited[s])
		return;
	visited[s] = true;
	cnt_node++;
	for(auto& u:adj_list[s]){
		dfs(u,visited);
	}
}
void solve(){
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		adj_list[a].insert(b);
		adj_list[b].insert(a);
	}
	vector<bool> visited(n+1,false);
	int ans = 0;
	for(int i=1;i<=n;i++){
		cnt_node = 0;
		if(!visited[i]){
			dfs(i,visited);
			ans = max(ans,cnt_node);
		} 
	}
	cout << ans << endl;
}   

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

Measured memory_bytes: 37964
#include<bits//stdc++.h>
using namespace std;
int main(){
    vector<int> a(10);
    for(int i = 0; i< 10;i++) cin >> a[i];
    sort(a.rbegin(),a.rend());
    cout << a[0] << endl;
    cout << a[1] << endl;
    cout << a[2] << endl;
}


Measured memory_bytes: 3096
from collections import Counter

N = int(input())
S = input()
c = Counter(S)
MOD = 10**9 + 7
# print('c', c)

ans = 1
for v in c.values():
    ans *= v + 1
    ans %= MOD
ans -= 1
ans %= MOD
print(ans)
# 4C4 = 1
# 4C3 = 4
# 4C2 = 6
# 4C1 = 4

# b
#  a
#   a
# ba
# b a


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;

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

const int inf = 1e9 + 1;
const double eps = 1e-9;
const int MAXN = 1e5 + 1;

int n, x, a[101];
int sol;

int main(){

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

    sort(a, a+n);

    for (int i = 0; i < n-1; i++){
        if (x >= a[i]){
            sol++;
            x -= a[i];
        }
    }

    if (x == a[n-1]) sol++;

    cout << sol;

    return 0;

}


Measured memory_bytes: 256
//Christmas

#include <cstdio>

template<long long I, long long A>
struct layers
{
	long long values[I + 1];
	constexpr layers() : values()
	{
		values[0] = 1;
		for (int i = 1; i <= I; ++i)
		{
			values[i] = 2 * values[i - 1] + A;
		}
	}
};

constexpr auto ls = layers<50, 3>();
constexpr auto ps = layers<50, 1>();

long long patties(long long n, long long x)
{
	if (n == 0)
	{
		return 1;
	}
	if (x == 1)
	{
		return 0;
	}
	else if (x <= ls.values[n - 1] + 1)
	{
		return patties(n - 1, x - 1);
	}
	else if (x == ls.values[n - 1] + 2)
	{
		return 1 + ps.values[n - 1];
	}
	else if (x <= 2 * ls.values[n - 1] + 2)
	{
		return 1 + ps.values[n - 1] + patties(n - 1, x - (2 + ls.values[n - 1]));
	}
	else
	{
		return 1 + 2 * ps.values[n - 1];
	}
}

int main()
{
	long long n, x;
	scanf("%lld %lld", &n, &x);
	printf("%lld\n", patties(n, x));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    ll N, M;
    cin >> N >> M;
    ll x[MAX], s[MAX];
    ll i;
    ll ans=0;
    for(i=0; i<M; i++) {
        cin >> x[i];
    }
    sort(x, x+M);
    ans=x[M-1]-x[0];
    for(i=0; i<M-1; i++) {
        s[i]=x[i+1]-x[i];
    }
    sort(s, s+M-1);
    reverse(s, s+M-1);
    
    for(i=0; i<N-1; i++) {
        ans-=s[i];
    }
    
    pt(max(ans, 0));
}



Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97
int mod = 1e9 + 7;

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

    int p[1001] = {};
    for (int i = 2; i <= n; i++) {
        int x = i;
        for (int j = 2; j <= x; j++) {
            while (x % j == 0) {
                x /= j;
                p[j] ++;
            }
        }
    }

    ll ans = 1;
    for (int i = 2; i <= 1000; i++) {
        ans = ans * (p[i] + 1) % mod;
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
import collections
N = int(input())
d = list(map(int, input().split()))
d.sort()
mysum = sum(d)

mytuple = sorted(collections.Counter(d).most_common(), key = lambda k:k[0])

mysum2 = 0 
cnt = 0
for i in mytuple:
  mynum = i[1]
  if mynum + mysum2 < N/2:
  	mysum2 += mynum
  	cnt += 1
  elif mynum + mysum2 == N/2:
    break
  elif  mynum + mysum2 > N/2:
    cnt = -999
    break

if cnt == -999:
  print(0)
else:
  print(mytuple[cnt+1][0] - mytuple[cnt][0])

Measured memory_bytes: 16096
from collections import Counter
N = int(input())
S = []
for n in range(N):
    S.append(input())
c = Counter(S)
K = []
for i,(k,v) in enumerate(c.most_common()):
    if i==0:
        vmax = v
    else:
        if vmax!=v:
            break
    K.append(k)

K = sorted(K)
for k in K:
    print (k)

Measured memory_bytes: 45040
import java.util.*;

public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashMap<String, Integer> map = new HashMap<String, Integer>();
    for (int i = 0; i < n; ++i) {
      String a = sc.next();
      map.put(a, map.getOrDefault(a, 0));
      map.put(a, map.get(a) + 1);
    }
    sc.close();

    for (Map.Entry<String, Integer> e : map.entrySet()) {
      if(e.getValue() > 1) {
        System.out.println("NO");
        System.exit(0);
      }
    }

    System.out.println("YES");
  }
}

Measured memory_bytes: 76068
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long x,k,d,times,left;
    cin>>x>>k>>d;
    x=abs(x);
    times=x/d;
    left=x%d;
    if(times>k)cout<<x-k*d<<endl;
    else
    {
        if( (k-times) &1)
            cout<<d-left<<endl;
        else
            cout<<left<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int h,w;
  cin>>h>>w;
  char grid[h+2][w+2];
  memset(grid,'.',sizeof(grid[0][0])*(h+2)*(w+2));
  for(int i=1;i<=h;i++){
  	string s;
  	cin>>s;
  	for(int j=1;j<=s.length();j++){
  		grid[i][j]=s[j-1];
  	}
  }
  for(int i=1;i<=h;i++){
  	for(int j=1;j<=w;j++){
  		if(grid[i][j]=='.'){
  			int c = 0;
  			grid[i][j+1]=='#'?c++:c=c,grid[i][j-1]=='#'?c++:c=c;
  			grid[i+1][j]=='#'?c++:c=c,grid[i-1][j]=='#'?c++:c=c;
  			grid[i+1][j+1]=='#'?c++:c=c,grid[i-1][j-1]=='#'?c++:c=c;
  			grid[i-1][j+1]=='#'?c++:c=c,grid[i+1][j-1]=='#'?c++:c=c;
  			grid[i][j]=(char)c+48;
  		}
  	}
  }
  for(int i=1;i<=h;i++){
  	for(int j=1;j<=w;j++){
  		cout<<grid[i][j];
  	}
  	cout<<endl;
  }
} 



Measured memory_bytes: 256
from math import *

x = int(input())

lst1 = list(range(2, int(sqrt(1000)) + 1))
lst2 = [1, 1000]

for n in lst1:
   i = 2
   while n ** i < 1000:
      lst2.append(n ** i)
      i += 1

lst2 = list(set(lst2))
lst2.sort()

for i in range(len(lst2)):
   if x < lst2[i]:
      print(lst2[i - 1])
      exit()

print(lst2[-1])

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


int min(int a,int b){
  if(a<b){
    return a;
  }else{
    return b;
  }
}

int main(){
  int a,b,c,x;
  cin>>a>>b>>c;
  cin>>x;
  int a_max=min(x/500,a);
  int rest;
  int count=0;
  for(int i=0;i<=a_max;i++){
    rest=x-500*i;
    for(int j=0;j<=min(rest/100,b);j++){
      if((rest-100*j)/50<=c){
        count+=1;
      }
    }
  }
  cout<<count<<endl;
}
      
      

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map<string, int>mp;
    map<string, int>:: iterator it;
    int n, maxnum = 0;
    string s;
    cin>>n;
    for(int i = 0; i < n; i++)
    {
        cin>>s;
        mp[s]++;
        if(mp[s] > maxnum)
            maxnum = mp[s];
    }
    for(it = mp.begin(); it != mp.end(); it++)
    {
        if(it->second == maxnum)
            cout<<it->first<<endl;
    }
    return 0;
}


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

struct ab
{
  ll a;
  ll b;
};

int main()
{
  ll n, k;
  ll a, b;
  cin >> n >> k;

  vector<ab> v;

  for (ll i = 0; i < n; i++)
  {
    cin >> a >> b;
    ab tmp = {a, b};
    v.push_back(tmp);
  }

  sort(v.begin(), v.end(), [](const ab &tmp1, const ab &tmp2) { return tmp1.a < tmp2.a; });
  ll count = 0;
  ll i = 0;
  while (count < k)
  {
    count += v[i].b;
    i++;
  }

  cout << v[i - 1].a << endl;
}

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

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


Measured memory_bytes: 256
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }
    std::vector<int64_t> B;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        B.push_back(t);
    }
    std::vector<int64_t> C;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        C.push_back(t);
    }

    std::sort(std::begin(A), std::end(A));
    std::sort(std::begin(B), std::end(B));
    std::sort(std::begin(C), std::end(C));

    uint64_t count = 0;
    for (auto b: B) {
        auto anum = std::distance(A.begin(), std::upper_bound(A.begin(), A.end(), b-1));
        auto cnum = std::distance(std::lower_bound(C.begin(), C.end(), b+1), C.end());

        count += anum*cnum;
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 3316
N,K = map(int,input().split())

a = []
for i in range(N):
    a.append(0)
    
for i in range(K):
    b = int(input())
    c = list(map(int,input().split()))
    for j in range(len(c)):
        a[c[j]-1] = 1

cnt = 0

for i in range(len(a)):
    if a[i] == 0:
        cnt += 1
        
print(cnt)

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

int main() {
  string s,t;
  cin>>s>>t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if(s<t)  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (
    acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
    sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


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

# For getting input from input.txt file
#sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
#sys.stdout = open('output.txt', 'w')


def main():
    n, d = invr()
    res = 0
    for _ in range(n):
        p, q = invr()
        dist = sqrt(p**2 + q**2)
        if dist <= d:
            res += 1
    print(res)


# region fastio
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")

# endregion


if __name__ == "__main__":
    main()


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

char a[1005][1005];
int dp[1005][1005] = {};
int h, w;

int main() {
   priority_queue<pair<int, pair<int,int> >, vector<pair<int, pair<int,int> > >, greater<pair<int, pair<int,int> > > > q;
   cin >> h >> w;
   REP(i,h) {
     REP(j,w) {
       dp[i][j] = 5000;
       cin >> a[i][j];
       if(a[i][j] == '#') {
         q.push(make_pair(0, make_pair(i,j)));
         dp[i][j] = 0;
       }
     }
   }

   int result = 0;

   while(!q.empty()) {
     pair<int, pair<int,int> > tmp = q.top();
     q.pop();

     int i = tmp.second.first;
     int j = tmp.second.second;
     int c = tmp.first;

     if (i != 0) {
       if(dp[i-1][j] == 5000) {
         dp[i-1][j] = c+1;
         q.push(make_pair(c+1, make_pair(i-1,j)));
       }
     }
     if (i != h-1) {
       if (dp[i+1][j] == 5000) {
         dp[i+1][j] = c + 1;
         q.push(make_pair(c + 1, make_pair(i+1, j)));
       }
     }

     if (j != 0) {
       if (dp[i][j-1] == 5000) {
         dp[i][j-1] = c + 1;
         q.push(make_pair(c + 1, make_pair(i, j-1)));
       }
     }

    if (j != w-1) {
       if (dp[i][j+1] == 5000) {
         dp[i][j+1] = c + 1;
         q.push(make_pair(c + 1, make_pair(i, j+1)));
       }
     }

     if(q.empty()) {
       result = tmp.first;
     }
   }

  cout << result << endl;
}


Measured memory_bytes: 18796
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap};

struct UnionFind{
    n: usize,
    parent: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind{
    fn new(n: usize ) -> UnionFind{
        let mut parent = vec![0; n];
        for i in 0..n {
            parent[i] = i;
        }
        let size = vec![1; n];
        UnionFind{n, parent, size}
    }

    fn root(&mut self, x: usize) -> usize{
        if x == self.parent[x]{
            self.parent[x]
        }else{
            let res = self.root(self.parent[x]);
            self.parent[x] = res;
            self.parent[x]
        }
    }

    fn unite(&mut self, x: usize, y: usize){
        let a = self.root(x);
        let b = self.root(y);
        if a == b{
            return;
        }
        if self.size[a] <= self.size[b]{
            self.parent[b] = a;
            self.size[a] += self.size[b];
        }else{
            self.parent[a] = b;
            self.size[b] += self.size[a];
        }
    }

    fn is_same(&mut self, x: usize, y: usize) -> bool{
        self.root(x) == self.root(y)
    }

    fn get_size(&mut self, x: usize) -> usize{
        let a = self.root(x);
        self.size[a]
    }
}

fn main() {
    input! {
        n: usize,
        x: usize,
        t: usize,
    }
    let ans = (n + x - 1) / x * t;
    println!("{}", ans);
}


Measured memory_bytes: 2104
#include<iostream>
#include<set>
#include<queue>
using namespace std;
struct edge{int to,color;};
vector<edge> w[100010];
int n,m,d[100010];
set<int> s[100010];
int main()
{
	cin>>n>>m;
	while(m--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		w[a].push_back({b,c});
		w[b].push_back({a,c});
	}
	d[1]=0;
	for(int i=2;i<=n;i++)d[i]=1e6;
	priority_queue<pair<int,int>> q;
	q.push({-d[1],1});
	while(q.size())
	{
		int now=q.top().second,cost=-q.top().first;q.pop();
		if(d[now]<cost) continue;
		for(edge j:w[now])
		{
			int dist=d[now];
			if(!s[now].count(j.color)) dist++;
			if(dist<d[j.to])
			{
				d[j.to]=dist;
				s[j.to].clear();
				s[j.to].insert(j.color);
				q.push({-d[j.to],j.to});
			}
			else if(dist==d[j.to])s[j.to].insert(j.color);
		}
	}
	if(d[n]>4e5)cout<<-1<<endl;
	else cout<<d[n]<<endl;
	return 0;
}


Measured memory_bytes: 21108
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
 
typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
 
const int N = (int)(1e6 + 5);
const int LOG = (int)(20);
 
lli n, l, t, pos[N], off;
ii p[N];
vector<lli> v;
 
int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n >> l >> t;
	for(int i = 1; i <= n; i++) {
		cin >> p[i].fi >> p[i].se;
		p[i].se = p[i].se == 2 ? -1 : 1;
	}
	for(int i = 1; i <= n; i++) {
		lli ps = p[i].fi + p[i].se * t;
		lli pos = ((ps % l) + l) % l;
		v.pb(pos);
		off += (ps > 0 ? ps / l : (ps - l + 1) / l);
	}
	off = ((off % n) + n) % n;
	sort(v.begin(), v.end());
	for(int i = 0; i < v.size(); i++)
		cout << v[(i + off) % n] << endl;
}

Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    vector<int> good(N, 1);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        --A; --B;
        if (H[A] >= H[B]) good[B] = 0;
        if (H[A] <= H[B]) good[A] = 0;
    }
    int ans = accumulate(good.begin(), good.end(), 0);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <stdio.h>
#include <string>
// #include <cstdlib>
#include <stdlib.h>
using namespace std;

long X;
unsigned  long K;
unsigned  long D;

int main(){
    cin >> X >> K >> D;

    if (D > labs(X))
    {
        if(K % 2 == 0){
            cout << labs(X) << endl;
        }
        else{
            if(X >= 0){
                cout << labs(X - D) << endl;
            }
            else{
                cout << labs(X + D) << endl;
            }
        }
    }
    else{
        if (D * K < labs(X))
        {
            if(X >= 0){
                cout << X - (D * K) << endl;
            }
            else{
                cout << labs(X + (D * K)) << endl;
            }
        }
        else{
            if(X >= 0){
                while(X >= 0 && K > 0){
                    X -= D;
                    K--;
                }
                if(K % 2 == 0){
                    cout << labs(X) << endl;
                }
                else{
                    cout << X + D << endl;
                }
            }
            else{
                while (X <= 0 && K > 0){
                    X += D;
                    K--;
                }
                if (K % 2 == 0)
                {
                    cout << labs(X) << endl;
                }
                else
                {
                    cout << labs(X - D) << endl;
                }
            }
        }
    }


}




Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    int n,i;
   cin>>n;
   ll a[n];
   set<ll> s;
   for(i=0;i<n;i++)
    {cin>>a[i];
    s.in(a[i]);
    }
    if(s.size()==n)
        cout<<"YES";
    else
        cout<<"NO";

}


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

typedef long long ll;
typedef long double ld;

const double EPS = 1e-9;
const int INF = (int)1e9 + 41;
const int N = (int)1e6 + 34;

void solve() {
    int n;
    string s;
    map<pair<string, string>, int> m;

    cin >> n >> s;
    for (int msk = 0; msk < (1 << n); msk++) {
        string s1, s2;
        for (int i = 0; i < n; i++) {
            if (msk & (1 << i)) s1.push_back(s[i]);
            else s2.push_back(s[i]);
        }
        m[make_pair(s1, s2)]++;
    }

    ll ans = 0;
    reverse(s.begin(), s.end());
    for (int msk = 0; msk < (1 << n); msk++) {
        string s1, s2;
        for (int i = 0; i < n; i++) {
            if (msk & (1 << i)) s1.push_back(s[i]);
            else s2.push_back(s[i]);
        }
        ans += m[make_pair(s1, s2)];
    }

    cout << ans << "\n";
}

int main() {
#ifdef MADE_BY_SERT
    freopen("a.in", "r", stdin);
    ///freopen("a.out", "w", stdout);
    solve();
    solve();
    solve();
#endif
    //int t; cin >> t; while (t--)
	solve();
    return 0;
}



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

using namespace std;

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

    int N, X;

    cin >> N >> X;

    int count = 1;
    int pos = 0;

    for(int i = 0; i < N; i++)
    {
        int j;
        cin >> j;

        pos += j;

        if(pos <= X)
        {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Debug.Trace
main :: IO ()
main = getLine >> readLine >>= print . solve 

solve :: [Int] -> Int
solve ws = minimum . map (\(x, y) -> abs $ x - y) $ zip xs ys
    where
        xs = scanl (+) 0 ws
        ys = scanr (+) 0 ws

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i){
		cin >> a.at(i);
	}

	for (int i = 1, k = 0; i <= n; ++i){
		k = a.at(k) - 1;
		if(k == 1){
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int debug=1;

int main(){
    int N, M;
    cin >> N >> M;
    // N + N
    // M + M 
    // n C 2
    // m C 2

    int ans;
    ans = N * (N - 1) / 2;
    ans += M * (M - 1) / 2;

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int f(int n){
    int ans=1;
    for(int i=1;i<=n;i++){
        while(ans*2<=i){
            ans*=2;
        }
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    cout << f(n) << endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    double N, K; cin >> N >> K;
    vector<int> x(N); REP(i, N) cin >> x[i];

    int res = 0;

    REP(i, N) {
        if(x[i] <= abs(x[i] - K)) {
            res += x[i];
        } else if(x[i] >= abs(x[i] - K)) {
            res += abs(x[i] - K);
        }
    }

    cout << res * 2 << endl;
}

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

int N, K; //N円の品物、K個の嫌いな数字

bool flag[10] = {false}; //初期値falseの10個の要素を持つflag配列

bool check(int n) //intのnを取るcheck関数
{
    while (n > 0) //nが0以上の間
    {
        if (flag[n % 10] == true) //flag配列のnを10で割った余り番目がtrueなら
        {
            return false;
        }
        else
        {
            n /= 10; //それ以外はnを10で割って代入
        }
    }
    return true;
}

int main()
{
    cin >> N >> K;
    int num = 0, ans; //int型で初期値0のnum、int型のn

    for (int d = 0; d < K; d++) //K回ループ
    {
        cin >> num;       //嫌いな数字をnumに入れて
        flag[num] = true; //flag配列のnum番目をtrueにする
    }

    for (ans = N; ans < 100000; ans++) //Nから100000回繰り返す
    {
        if (check(ans) == true) //もしcheck関数がtrueならbreak
        {
            break;
        }
    }

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


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,sum,i,A[]={1,5,10,50,100,500};
	sum=0;
	for(i=0;i<6;i++){
		scanf("%d",&a);
		sum+=a*A[i];
	}
	if(sum>=1000) printf("1\n");
	else printf("0\n");
	return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll W, H, N;
    cin >> W >> H >> N;
    ll x_l, x_h, y_l, y_h;
    x_l = 0;
    x_h = W;
    y_l = 0;
    y_h = H;

    for (ll i = 0; i < N; i++) {
        ll x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            x_l = max(x_l, x);
        }
        else if (a == 2) {
            x_h = min(x_h, x);
        }
        else if (a == 3) {
            y_l = max(y_l, y);
        }
        else {
            y_h = min(y_h, y);
        }
    }

    cout << max(x_h - x_l, 0LL) * max(y_h - y_l, 0LL) << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split(' ').map(&:to_i)
b = gets.split(' ').map(&:to_i)
c = gets.split(' ').map(&:to_i)

sat = 0
previous = -2
a.each do |i|
  sat += b[i-1]
  sat += c[i-2] if previous == i-1
  previous = i
end
print "#{sat}"


Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}

vector<ll> fact;
vector<ll> inv_fact;

void comb_init(int n) {
	fact.resize(n + 1);
	inv_fact.resize(n + 1);
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD;
	}
}

ll comb(int n, int k) {
	if (n < k) return 0;
	ll ret = fact[n];
	(ret *= inv_fact[k]) %= MOD;
	(ret *= inv_fact[n - k]) %= MOD;
	return ret;
}
int main() {
	int N, M, K;
	cin >> N >> M >> K;
	comb_init(N + M + K);
	ll ans = 0;
	ll now = 1;
	int l = 0, r = 0;
	for (int i = N; i <= N + M + K; i++) {
		ll x = mod_pow(3, N + M + K - i);
		(x *= comb(i - 1, N - 1)) %= MOD;
		(x *= now) %= MOD;
		(ans += x) %= MOD;
		(now *= 2) %= MOD;
		if (i >= N + K) {
			(now += MOD - comb(i - N, l)) %= MOD;
			l++;
		}
		if (i >= N + M) {
			(now += MOD - comb(i - N, r)) %= MOD;
		}
		else {
			r++;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

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

	int n, a, b;
	cin >> n >> a >> b;

	int c = 0;

	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		if (!(t >= a&&t < b))
			c++;
	}

	cout << c << endl;

	return 0;

}

Measured memory_bytes: 256
package main

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

const MAX = 4e6
var Sc *bufio.Scanner
var split string = " "


func main() {
	solve()
}

func solve() {
	initSc()
	_ = inputInt()
	a := inputInts()

  min := func() (cost int) {
    var min int = MAX
    for y:=-100; y <= 100; y++ {
      for _, x := range a {
        cost += (x-y)*(x-y)
      }
      min = map[bool]int{true: cost, false: min}[cost < min]
      cost = 0
    }
    return min
  }()
  fmt.Println(min)
}

func inputInt() (n int) {
	n, _ = strconv.Atoi(Sc.Text())
	exeScan()
	return n
}

func inputInts() (a []int) {
	for _, v := range strings.Split(Sc.Text(), split) {
		t, _ := strconv.Atoi(string(v))
		a = append(a, t)
	}
	exeScan()
	return a
}

func initSc() {
	Sc = bufio.NewScanner(os.Stdin)
	Sc.Scan()
}

func exeScan() {
	Sc.Scan()
}


Measured memory_bytes: 640
a = [int(input()) for _ in range(5)]
d = [[x, 10-x%10 if x%10!=0 else 0] for x in a]
d.sort(key=lambda x: x[1])
sumt=0
for i in range(5):
    sumt+=d[i][0]+d[i][1] if i<4 else d[i][0]
print(sumt)

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

typedef long long ll;
const ll InF = 1e15;

ll solve(ll n) {
  ll ret = 0;
  while(n % 2 == 0) {
    ret++;
    n /= 2;
  }
  return ret;
}

int main() {
    int n;
    cin>>n;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll a;
      cin>>a;
      ans += solve(a);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int c11,c12,c13,c21,c22,c23,c31,c32,c33;
	cin>>c11>>c12>>c13>>c21>>c22>>c23>>c31>>c32>>c33;
	if(c21-c11==c22-c12&&c21-c11==c23-c13){
		if(c21-c31==c22-c32&&c21-c31==c23-c33)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;		
	}
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

int main(){
  cout << fixed << setprecision(15);

  int n; cin >> n;

  ll ans = 0;
  //string ans = "No";

  ans = floor(sqrt(n));
  
  cout << ans * ans << endl;

  return 0;
}

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

int main() {
    int c[3][3];
    int a[3], b[3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

    int max_a0 = 100;
    for (int i = 0; i < 3; i++) {
        max_a0 = min(c[0][i], max_a0);
    }

    bool ok = true;
    for (int i = 0; i <= max_a0; i++) {
        a[0] = i;
        b[0] = c[0][0] - a[0];
        b[1] = c[0][1] - a[0];
        b[2] = c[0][2] - a[0];
        a[1] = c[1][1] - b[1];
        a[2] = c[2][2] - b[2];

        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (c[j][k] != a[j] + b[k]) {
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
        }

        if (ok) break;
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 384