akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<tuple>
#include<vector>
#include<cstdio>
using namespace std;
#define MAX_N 514514
tuple<int, int, int>A1[MAX_N], A2[MAX_N];
int N, Q, X1, Y1, X2, Y2; vector<int>vec;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &X1, &Y1);
		A1[i] = make_tuple(X1, Y1, i);
		A2[i] = make_tuple(Y1, X1, i);
	}
	sort(A1, A1 + N); sort(A2, A2 + N);
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		scanf("%d%d%d%d", &X1, &X2, &Y1, &Y2);
		int pos1 = lower_bound(A1, A1 + N, make_tuple(X1, Y1, 0)) - A1;
		int pos2 = upper_bound(A1, A1 + N, make_tuple(X2, Y2, MAX_N)) - A1;
		int pos3 = lower_bound(A2, A2 + N, make_tuple(Y1, X1, 0)) - A2;
		int pos4 = upper_bound(A2, A2 + N, make_tuple(Y2, X2, MAX_N)) - A2;
		int size1 = pos2 - pos1;
		int size2 = pos4 - pos3;
		vec.clear();
		if (size1 <= size2) {
			for (int j = pos1; j < pos2; j++) {
				int Y = get<1>(A1[j]);
				if (Y1 <= Y && Y <= Y2) { vec.push_back(get<2>(A1[j])); }
			}
		}
		else {
			for (int j = pos3; j < pos4; j++) {
				int X = get<1>(A2[j]);
				if (X1 <= X && X <= X2) { vec.push_back(get<2>(A2[j])); }
			}
		}
		sort(vec.begin(), vec.end());
		for (int j = 0; j < vec.size(); j++) { printf("%d\n", vec[j]); }
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 14500
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	int n; cin >> n;
	map<string, int> freq;
	for (int i = 1; i <= n; i++) {
		string s; cin >> s;
		freq[s]++;
	}

	cout << freq.size();

	return 0;
}

Measured memory_bytes: 18724
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n) - 1; 0 <= i; --i)
#define rep(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using arr = vector<ll>;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
constexpr int MAX = 2020;

int n, m;
int main()
{
  cin >> n >> m;
  vector<pair<ll, ll>> task;
  priority_queue<ll> pq;
  REP(i, n) {
    ll a, b;
    cin >> a >> b;
    task.emplace_back(a, b);
  }
  sort(task.begin(), task.end());

  int j = 0;
  ll ans = 0;
  rep(i, m) {
    while(j < n && task[j].first == i) 
      pq.emplace(task[j++].second);
    if (pq.empty()) continue;
    ans += pq.top();
    pq.pop();
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 3568
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int cnt = 0;
		for(int i = 0; i <= a; i++) {
			for(int j = 0; j <= b; j++) {
				for(int k = 0; k <= c; k++) {
					if(i * 500 + j * 100 + k * 50 == x) {
						cnt++;
					}	
				}
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 22868
function main() {
  var input = getInput();
  var num = parseInt(input);
  console.log(num * num * num);
}

function getInput() {
  if (typeof require == "undefined") {
    return document.getElementById('input').value;
  }
  return require('fs').readFileSync('/dev/stdin').toString();
}

if (typeof require != "undefined") {
  main();
}

Measured memory_bytes: 7384
#include <stdio.h>
int main(void){
    int a,b[100],i;
    scanf("%d",&a);
    for(i=1;i<=a;i++)
    scanf("%d",&b[i]);
    for(i=a;i>=1;i--){
        if(i>1)
        printf("%d ",b[i]);
        else
        printf("%d",b[i]);
    }
    printf("\n");
    return 0;
}



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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// AtCoder Beginner Contest 144

int N, M;
int use_s, use_u;
vector<int> graph[600];

long double calced[600];
long double calc(){
    for(int i = N - 2; i >= 0; i--){
        long double sum = 0;
        int cnt = 0;
        for(int u : graph[i]){
            if(i == use_s && u == use_u)continue;
            sum += calced[u];
            cnt++;
        }
        calced[i] = sum / cnt + 1;
    }
    return calced[0];
}

int main(){

    cin >> N >> M;
    rep(i, M){
        int s, t;
        cin >> s >> t;
        s--; t--;
        graph[s].push_back(t);
    }

    long double ans = calc();
    rep(i, N){
        if(graph[i].size() <= 1)continue;
        else {
            int pos = 0;
            long double ma = 0;
            for(int u : graph[i])if(chmax(ma, calced[u]))pos = u;
            use_s = i; use_u = pos;
            chmin(ans, calc());
        }
    }
    cout << ans << '\n';

}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <random>

#include <fstream>
#include <vector>
#include <algorithm>

#define ll long long int

using namespace std;

int main(void)
{

    
    string s;
    
    cin >> s;
    
    cout << s[0] << s[1] << s[2];
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>

int main(void){
    int i,j,n,m,l,f;
	int c=0;
    scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&m);
		f=0;
		l = (int)(sqrt(m));
		for(j=2;j<=l;j++){
			if(m%j==0){
				f = 1;
				break;
			}
		}
		if(f==0){c++;}
	}
	
	printf("%d\n",c);
	return 0;
}



Measured memory_bytes: 2080
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# 
# a, b = list(map(int, input().split()))
# 

n = int(input())
s = input()

ans = "No"
if s[:n//2] == s[n//2:]:
    ans = "Yes"
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;

typedef long long s64;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 131072;

int n;
int faw[MaxN + 1];
int son[MaxN + 1][2];

struct object
{
	s64 u, v;
	object() {}
	object(const s64 &_u, const s64 &_v)
		: u(_u), v(_v) {}

	friend inline bool operator<(const object &lhs, const object &rhs)
	{
		if (lhs.u != rhs.u)
			return lhs.u < rhs.u;
		return lhs.v > rhs.v;
	}
};
vector<object> all[MaxN + 1];

inline int query(const vector<object> &cur, s64 target)
{
	int l = 0, r = cur.size() - 1;
	while (l <= r)
	{
		int mid = l + r >> 1;
		if (cur[mid].u <= target)
			l = mid + 1;
		else
			r = mid - 1;
	}
	return r;
}

inline bool check(s64 lim)
{
	for (int u = n; u >= 1; --u)
	{
		all[u].clear();

		if (!son[u][0])
			all[u].emplace_back(faw[u], faw[u]);
		else
		{
			int v1 = son[u][0];
			int v2 = son[u][1];
			if (all[v1].size() > all[v2].size())
				swap(v1, v2);

			vector<object> cur;
			for (object it : all[v1])
			{
				int k = query(all[v2], lim - it.u);
				if (k >= 0)
				{
					s64 a = it.v, b = all[v2][k].v;
					cur.emplace_back(a, b);
					cur.emplace_back(b, a);
				}
			}

			if (cur.empty())
				return false;

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

			for (object it : cur)
			{
				s64 a = it.u + faw[u];
				s64 b = it.v + faw[u];
				if (all[u].empty() || b < all[u].back().v)
					all[u].emplace_back(a, b);
			}
		}
	}

	return true;
}

int main()
{
	cin >> n;
	for (int u = 2; u <= n; ++u)
	{
		int v = getint(), w = faw[u] = getint();
		son[v][son[v][0] ? 1 : 0] = u;
	}

	s64 l = 0, r = 0;
	for (int u = 2; u <= n; ++u)
		r += faw[u];

	while (l <= r)
	{
		s64 mid = l + r >> 1;
		if (check(mid))
			r = mid - 1;
		else
			l = mid + 1;
	}

	cout << l << endl;

	return 0;
}

Measured memory_bytes: 31092
def solve():
    S = input()
    ['dream', 'dreamer', 'erase', 'eraser']
    r_S = S[::-1]
    while(len(r_S) > 0):
        if r_S[:7] == 'dreamer'[::-1]:
            r_S = r_S[7:]
        elif r_S[:6] == 'eraser'[::-1]:
            r_S = r_S[6:]
        elif r_S[:5] == 'dream'[::-1] or r_S[:5] == 'erase'[::-1]:
            r_S = r_S[5:]
        else:
            break
    if len(r_S) == 0:
        print('YES')
    else:
        print('NO')

solve()

Measured memory_bytes: 3316
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

s,t=input().split()
a,b=mii()
u=ss()

if u==t:
    print(str(a)+" "+str(b-1))
elif u==s:
    print(str(a-1)+" "+str(b))

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

//int main() {}


int main(){
    int ans = 0;
    int N; cin >> N;
    int A[100002] = {};
    rep(i,N)
    {
        int a; cin >> a;
        A[a] ++;
    }
    vector<int> B(100002);
    for (int i = 1; i < 100001; i++)
    {
        B.at(i) = A[i-1] + A[i] + A[i+1];
    }

    sort(B.rbegin(),B.rend());
    ans = B.at(0);
    
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

// 151-d
int main() {
    int th, ta, ah, aa;
    cin >> th >> ta >> ah >> aa;

    while (true) {
        ah -= ta;
        if (ah <= 0) {
            cout << "Yes" << endl;
            return 0;
        }

        th -= aa;
        if (th <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int N = readInt(r);
        String[] numStrings = r.readLine().split(" ");
        int[] A = new int[N];
        for (int i = 0;i < N;i++) {
            A[i] = Integer.parseInt(numStrings[i]);
        }
//        insertionSort(A, N);
        bubbleSort(A, N);
    }
    
    public static void insertionSort(int[] A, int N) {
        System.out.println(dump(A, N));
        for (int i = 1;i <= (N - 1);i++) {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        }
    }
    
    public static void bubbleSort(int[] A, int N) {
        int swapCount = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void swapInt(int[] A, int j, int k) {
        int v = A[j];
        A[j] = A[k];
        A[k] = v;
    }
    
    public static String dump(int[] A, int N) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0;i < N;i++) {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        return builder.toString();
    }
    
    public static int readInt(BufferedReader r) throws Exception {
        return Integer.parseInt(r.readLine());
    }
}

Measured memory_bytes: 24272
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  cout << min({a,b,c})+min(d,e)-50 << endl;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  set<ll> s;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  cout << s.size() << endl;
}

Measured memory_bytes: 256
n, m, k = gets.chomp.split(' ').map(&:to_i); puts({ true => 'Yes', false => 'No' }[(0..n).to_a.product((0..m).to_a).map { |a| a[0] * a[1] + (n - a[0]) * (m - a[1]) }.include?(k)])

Measured memory_bytes: 61564
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(ll i = 0; i < N; i++){
        cin >> A[i];
    }

    for(ll i = 0; i < N; i++){
        A[i] = A[i] - (i+1);
    }

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

    ll med = 0;
    med = A[N/2];

    ll ans = 0;
    for(int i = 0; i < N; i++){
        ans += abs(A[i]- med);
    }

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


Measured memory_bytes: 1792
import std.stdio, std.conv, std.algorithm, std.array, std.string;

void main() {
	string[] result;
	while (true) {
		auto tmp = readln.split.map!(to!int).array;	
		auto w = tmp[1], h = tmp[0];
		if (w == 0 && h == 0) break;
		struct Point {
			int dx, dy;
			bool flag;
		}
		Point[][] cell = new Point[][](w, h);
		foreach (y; 0..h) {
			auto str = readln;
			foreach (x; 0..w) {
				if (str[x] == '>') {
					cell[x][y] = Point(+1, 0);	
				} else if (str[x] == '<') {
					cell[x][y] = Point(-1, 0);	
				} else if (str[x] == 'v') {
					cell[x][y] = Point(0, +1);	
				} else if (str[x] == '^'){
					cell[x][y] = Point(0, -1);	
				} else {
					cell[x][y] = Point(0, 0);
				}
			}
		}
		uint cx = 0, cy = 0;
		while (true) {
			auto c = cell[cx][cy];
			if (c.flag) {
				result ~= "LOOP";
				break;
			} 
			if (c.dx == 0 && c.dy == 0) {
				result ~= cx.to!string ~ " " ~ cy.to!string;
				break;
			}
			cell[cx][cy].flag = true;
			cx += c.dx;
			cy += c.dy;
		}
	}	
	foreach (r; result) r.writeln;
}

Measured memory_bytes: 2644
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	long long n;
	double ans = 0.0;
	cin >> n;
	vector<long long> v(n);
	for (long long i = 0; i < n; i++)
		cin >> v[i];

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

	ans += (double)(v[0] + v[1]) / 2;

	for (long long i = 2; i < v.size(); i++)
	{
		ans = (double)(ans + v[i]) / 2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
	int N, M;
	int A[1000];
	int Ai, Bj;
	int count[1000];
	
	scanf("%d %d", &N, &M);
	
	for (int i = 0; i < N; i++){
		scanf("%d", &Ai);
		A[i] = Ai;
		count[i] = 0;
	}
	
	for (int j = 0; j < M; j++){
		scanf("%d", &Bj);
		for (int i = 0; i < N; i++){
			if (A[i] <= Bj){
				count[i]++;
				break;
			}
		}
	}
	
	int count_max = 0;
	int max_game = 0;
	
	for (int i = 0; i < N; i++){
		if (count_max < count[i]){
			count_max = count[i];
			max_game = i;
		}
	}
	
	printf("%d\n", max_game + 1);
	
	return (0);
}
	

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int INF = 1001001001;

char mp[1005][1005];
int dist[1005][1005];

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  rep(y, h) rep(x, w) {
    cin >> mp[x][y];
    dist[x][y] = INF;
  }
  deque<PP> q;
  q.emplace_back(make_pair(cw, ch), 0);
  while (!q.empty()) {
    int x = q.front().first.first;
    int y = q.front().first.second;
    int d = q.front().second;
    q.pop_front();
    if (d >= dist[x][y]) continue;
    dist[x][y] = d;
    rep(v, 4) {
      int nx = x + dx[v];
      int ny = y + dy[v];
      if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
      if (mp[nx][ny] == '#') continue;
      q.emplace_front(make_pair(nx, ny), d);
    }
    for (int ex = -2; ex <= 2; ex++) {
      for (int ey = -2; ey <= 2; ey++) {
        int nx = x + ex;
        int ny = y + ey;
        if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
        if (mp[nx][ny] == '#') continue;
        q.emplace_back(make_pair(nx, ny), d + 1);
      }
    }
  }
  int ans = dist[dw][dh];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9848
from operator import itemgetter
n = int(input())
sp = [input().split() for i in range(n)]

for i in range(n):
  sp[i].append(str(i + 1))
  sp[i][1] = int(sp[i][1])

sp.sort(key=itemgetter(1),reverse = True)
sp.sort(key=itemgetter(0))


for i in range(n):
  print(sp[i][2])

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}


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

  ll N ;
  cin >> N;

  map<ll,ll> a;
  rep(i,N){
    ll inp;cin >> inp;
    a[i+1]=inp;
    
  }

  ll ans = 0;
  rep(i,N){
    ll b = a[i+1];
    if(a[b]==(i+1))ans ++;
  }

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


Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int N, c = 0;
    cin >> N;

    int ans = N;
    while(true){
        ans =  N / 2;
        c++;
        N = ans;
        if(N == 1){
            cout << pow(2, c) << endl;
            break;
        }
    }
}



Measured memory_bytes: 3472
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<climits>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
    int f=1,x=0;char s=getchar();   
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int cnt[2][MAXN+5];
int main(){
	int v,n=read();
	for(int i=1;i<=n;i++)
		v=read(),cnt[i%2][v]++;
	int Maxa1=0,Maxa2=0,Maxb1=0,Maxb2=0;
	for(int i=0;i<=MAXN;i++){
		if(cnt[1][Maxa1]<cnt[1][i])
			Maxa2=Maxa1,Maxa1=i;
		else if(cnt[1][Maxa2]<cnt[1][i])
			Maxa2=i;
		if(cnt[0][Maxb1]<cnt[0][i])
			Maxb2=Maxb1,Maxb1=i;
		else if(cnt[0][Maxb2]<cnt[0][i])
			Maxb2=i;
	}
	if(Maxa1!=Maxb1)
		printf("%d\n",n-cnt[1][Maxa1]-cnt[0][Maxb1]);
	else printf("%d\n",n-max(cnt[1][Maxa1]+cnt[0][Maxb2],cnt[1][Maxa2]+cnt[0][Maxb1]));
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, x, y, ans; cin >> a >> b >> c >> x >> y;
    if (a + b > 2 * c) {
        int z = min(x, y);
        cout << min(max(x, y) * 2 * c, z * 2 * c + (x - z) * a + (y - z) * b) << "\n";
    } else {
        cout << a * x + b * y << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll func(int i, int N, int M, int Q, vector<int>& list, vector<int>& a, vector<int>& b, vector<int>& c, vector<int>& d)
{
	if (i >= N)
	{
		auto sum = 0ll;
		for (auto j = 0; j < Q; ++j)
		{
			if (list[b[j]] - list[a[j]] == c[j])
			{
				sum += d[j];
			}
		}
		return sum;
	}

	auto ans = 0ll;
	auto prev = 1;
	if (i > 0)
	{
		prev = list[i - 1];
	}
	for (int k = prev; k <= M; ++k)
	{
		list[i] = k;
		ans = max(ans, func(i + 1, N, M, Q, list, a, b, c, d));
	}

	return ans;
}

int main()
{
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<int> a(Q);
	vector<int> b(Q);
	vector<int> c(Q);
	vector<int> d(Q);
	for (auto i = 0; i < Q; ++i)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		--a[i];
		--b[i];
	}


	vector<int> list(N);
	cout << func(0, N, M, Q, list, a, b, c, d) << endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
template<typename T>
T lcm( T m, T n )
{
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end
bool visited[8]={false};
bool sides[8][8];
int ans=0;

int dfs(int node, int N){
    bool flag= true;
    visited[node]=true;
    for(int i=0; i<N; i++) {
        if (!visited[i] && sides[node][i] && sides[i][node]){
            sides[node][i] = sides[i][node] = false;
            dfs(i,N);
            sides[node][i] = sides[i][node] = true;
        }
    }
    for(int i=0; i<N;i++){
        if(!visited[i]) flag= false;
    }
    if(flag)
        ans++;
    visited[node]= false;

    return 0;
}
int main() {
    long long N,M;
    cin >> N >> M;

    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        sides[a][b] = sides[b][a] = true;
    }

    dfs(0,(int)N);
    cout << ans << endl;
    return 0;
}



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

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    std::cin >> x;
    sum += x - 1;
  }
  std::cout << sum << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int H, W;
	cin >> H >> W;

	vector<vector<bool>> a(H, vector<bool>(W));
	char temp;
	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			cin >> temp;
			if (temp=='#') {
				a[i][j] = true;//黒
			}
			else {
				a[i][j] = false;//白
			}
		}
	}

	//横方向に見る
	bool flag;
	vector<vector<bool>> b;
	for (Int i = 0; i < H; i++) {
		flag = false;//falseなら全部白
		for (Int j = 0; j < W; j++) {
			if (a[i][j]) {
				flag = true;
			}
		}
		if (flag) {//一つでも黒がある場合
			b.push_back(a[i]);
		}
	}

	Int len = b.size();
	//縦方向に見る
	vector<vector<bool>> c(len);
	for (Int j = 0; j < W; j++) {
		flag = false;
		for (Int i = 0; i < len; i++) {
			if (b[i][j]) {
				flag = true;
			}
		}
		if (flag) {
			for (Int i = 0; i < len; i++) {
				c[i].push_back(b[i][j]);
			}
		}
	}

	Int len2 = c[0].size();
	for (Int i = 0; i < len; i++) {
		for (Int j = 0; j < len2; j++) {
			if (c[i][j]) {
				cout << '#';
			}
			else {
				cout << '.';
			}
		}
		cout << "\n";
	}

}


Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    res = min(res, a[x-1] + b[y-1] - c)
print(res)


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

using namespace std;

int main() {
    string s;
    cin >> s;
    int N = s.length();

    // t = s.substr(0, 1)
    // if t + t == s.substr(0, 2)
    int ans = 0;
    for (int len = 2; len < N; len += 2) {
        string t = s.substr(0, len / 2);
        if (s.substr(0, len) == t + t)
            ans = len;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mxn 200005
#define xx first
#define yy second
using namespace std;
int t[mxn];
typedef pair<int, int>pi;
vector<pi>vec;
int main()
{
    int n, q, x, y;
    scanf("%d %d", &n, &q);
    for(int i=1; i<=n; i++)t[i]= INT_MAX;
    for(int i=0; i<q; i++)
    {
        scanf("%d %d", &x, &y);
        if(x==1)t[y]= i;
        else vec.push_back({y, i});
    }
    ll res= 0;
    sort(vec.begin(), vec.end(), greater<pi>());
    for(int i=2; i<n; i++)
    {
        while(!vec.empty() && vec.back().yy>t[i])vec.pop_back();
        if(t[i]==INT_MAX)res+= n-vec.size()-2;
        else if(!vec.empty())res+= (n-vec.back().xx)-vec.size();
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 5900
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)
MOD = 998244353


def main():
    N = int(input())
    D = list(map(int, input().split()))
    C = Counter(D)
    if D[0] != 0:
        print(0)
    elif C[0] > 1:
        print(0)
    else:
        ans = 1
        key = list(C.keys())
        key.sort()
        l = len(key)
        for i in range(1, l):
            if key[i - 1] + 1 != key[i]:
                a = 0
            else:
                a = C[key[i - 1]] ** C[key[i]]
            ans *= a
            ans %= MOD
            if ans == 0:
                break
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19936
/*------------------------------------------------------------------------------------------------|
| %%%%%%%%%%%%%%%%%%%%%%%%%MD.ASANURJAMAL ANOWAR HOSSAIN ANU%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| %%%%%%%%%%%%%%%%%%%%%%%%%COMPUTER SCIENCE AND ENGINEERING%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| %%%%%%%%%%%%%%%%%%%%%%%%%ISLAMIC UNIVERSITY KUSHTIA%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| %%%%%%%%%%%%%%%%%%%%%%%%%BANGLADESH%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|-------------------------------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <list>
#include <map>
#include <fstream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <bitset>
#include <cctype>
#include <vector>
#include <complex>
#include <ctime>
#include <deque>
#include <memory>
#include <utility>

#define S(a) scanf("%d",&a)
#define SL(a) scanf("%ld",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define SL2(a,b) scanf("%ld%ld",&a,&b)
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SL3(a,b,c) scanf("%ld%ld%ld",&a,&b,&c)
#define SLL(a) scanf("%lld",&a)
#define SLL2(a,b) scanf("%lld%lld",&a,&b)
#define SLL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define SS(a) scanf("%s",a)
#define SC(a) scanf("%c",&a)
#define SD(a) scanf("%lf",&a)
#define P(a) printf("%d",a)
#define PL(a) printf("%ld",a)
#define PLL(a) printf("%lld",a)
#define PD(a) printf("%lf",a)
#define PC(a) printf("%c",a)
#define PS(a) printf("%s",a)
#define CS(kk) printf("Case %ld: ",kk++)
#define NL(kk) printf("\n")
#define PI 3.14159265358979323846264338327950
#define eps 1e-9
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)

using namespace std;

long long gcd(long long  a,long long b)
{
while(b>0)
{
a=a%b;
a=a^b;
b=b^a;
a=a^b;
}
return a;
}

long long lcm(long a,long long b)
{
    long long x=(a*b)/gcd(a,b);
    return x;
}
int main()
{
    long long i,ii,l,p,s,n,ll;
    long long a,b,c;
    //cin>>n;
    while(cin>>a>>b)
    {
     l=gcd(a,b);
     ll=lcm(a,b);
     cout<<l<<" "<<ll<<endl;
    }
 return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef vector<pii> vpii;
#define reps(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define all(g) (g).begin(),(g).end()
#define pb push_back
const int mod = 1e9 + 7;
#define INF 1<<25
/*
input case
output case
*/

int n;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int sum = 0;
    reps(i,1,n+1){
        sum += i;
    }
    cout << sum << endl;
}

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


int main(void){
    long  n,now,count = 0;
    
    cin >> n;
    now = 100;
    
    while(1){
        if(now >= n){
            break;
        }
        count ++;
        now = 1.01 * now;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> >a;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		a.push_back(make_pair(y,x));
	}
	sort(a.begin(),a.end());\
	int count=0;
	for(int i=0;i<n;i++){
		count+=a[i].second;
		if(count>a[i].first){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

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

	if(a<=8 && b<=8) cout<< "Yay!" << endl;
	else cout<< ":(" << endl;
 
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int n; cin >> n;
	vector<pair<int,int>> a(n);
	rep(i,n) {
		a[i].second=i+1;
		cin >> a[i].first;
	}
	sort(be(a));
	rep(i,n) cout << a[i].second << endl;
}

Measured memory_bytes: 4008
#include<stdio.h>
#include<stdlib.h>

int main(){
  int a[1000],b[1000];
  char op[1000];
  int i=0,j;
  
  while(1){
    scanf("%d %c%d",&a[i],&op[i],&b[i]);
    if(op[i]=='?'){
      break;
    }
    i++;
  }
  for(j=0;j<i;j++){
    if(op[j]=='+'){
      printf("%d\n",a[j]+b[j]);
    }else if(op[j]=='-'){
      printf("%d\n",a[j]-b[j]);
    }else if(op[j]=='*'){
      printf("%d\n",a[j]*b[j]);
    }else if(op[j]=='/'){
      printf("%d\n",a[j]/b[j]);
    }
  }
  return 0;
  
}


Measured memory_bytes: 2052
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h> 
using namespace std;
int n;
vector <int> g[100004];
typedef long long ll;
ll dp[100004][2];
const ll MOD=1e9+7;
void dfs(int x,int parts){
	dp[x][0]=1,dp[x][1]=1;
	for (int i=0;i<g[x].size();i++) if (g[x][i]!=parts){
		dfs(g[x][i],x);
		dp[x][0]=(dp[x][0]*(dp[g[x][i]][0]+dp[g[x][i]][1]))%MOD;
		dp[x][1]=(dp[x][1]*dp[g[x][i]][0])%MOD;
	}
}
int main(){
	cin>>n;
	for (int i=0;i<n-1;i++){
		int x,y;scanf ("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,-1);
	cout<<(dp[1][0]+dp[1][1])%MOD;
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){


int a,b,c;
cin>>a>>b>>c;
if(a+b+c>=22)cout<<"bust";
else{
    cout<<"win";
}

 return 0;
}
/*
5 7 9

win

*/

Measured memory_bytes: 256
n , m = map(int, input().split())
const = 1000000007
r = [1 for i in range(n+1)]
for i in range(m):
  r[int(input())] = 0
for i in range(2, n+1):
  if r[i] > 0:
    r[i] = (r[i-1] + r[i-2])%const
print(r[n])

Measured memory_bytes: 45040
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    queue<char> q;
    rep(i,s.size()) q.push(s[i]);
    string pre = {q.front()}; q.pop();
    int ans = 1;
    while (!q.empty()) {
        string next = {q.front()}; q.pop();
        if (pre == next) {
            if (q.empty()) break;
            next += q.front();
            q.pop();
        }
        swap(pre,next);
        ans++;
    }
    cout << ans << endl;
}

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

int main()
{
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    double s,W,H;
    W=w,H=h;
    s=W/2.0*H;
    //cout << s << endl;

    printf("%.6f ",s);
    if(w%2==0&&x==w/2&&h%2==0&&y==h/2)
        cout << 1;
    else
        cout << 0;
    return 0;
}




Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M, C = map(int, input().split())
B = [int(x) for x in input().split()]
A = [list(map(int,input().split())) for i in range(N)]

ans = 0

for i in range(N) :
    temp = 0
    for j in range(M) :
        temp += A[i][j] * B[j]
    if temp + C > 0 :
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>

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

int max(int a, int b) {
	if(a > b) return a;
	return b;
}

int main() {
	char s[3];
	scanf("%s", s);
	int array[3] = {0, 0, 0};
	int i = 0;
	for(i = 0; i < 3; i++) {
		if(s[i] == 'a') array[0]++;
		else if(s[i] == 'b') array[1]++;
		else if(s[i] == 'c') array[2]++;
	}

	for(i = 0; i < 3; i++) {
		if(array[i] != 1) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	//char buffer[128];
	//scanf("%s", buffer);
	return 0;
}


Measured memory_bytes: 128
import math
  
n = int(input())
  
  
  
def koch(n,x_0,y_0,x_1,y_1):
    if n == 0:
        return  
    x_m1 = x_0 + (x_1- x_0)/3
    y_m1 = y_0 + (y_1 -y_0)/3
    x_m2 = x_0 + (x_1- x_0)* 2/3
    y_m2 = y_0 + (y_1 -y_0) *2/3
    x_m =  (x_m2 - x_m1) * math.cos(math.pi/3) - (y_m2 - y_m1) * math.sin(math.pi/3) + x_m1
    y_m =  (x_m2 - x_m1) * math.sin(math.pi/3) + (y_m2 - y_m1) * math.cos(math.pi/3) + y_m1
  
    koch(n-1,x_0,y_0,x_m1,y_m1)
    print(x_m1,y_m1)
    koch(n-1,x_m1,y_m1,x_m,y_m)
    print(x_m,y_m)
    koch(n-1,x_m,y_m,x_m2,y_m2)
    print(x_m2,y_m2)
    koch(n-1,x_m2,y_m2,x_1,y_1)
      
print(0,0)
koch(n,0,0,100,0)
print(100,0)


Measured memory_bytes: 5780
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"

int32_t main()
{
	int n;
	cin>>n;
	string s=to_string(n);
	int l=s.size();
	int c=0;
	int i=1;
	while(i<l)
	{
		c+=(pow(10, i-1)*9);
		i+=2;
	}
	if(l%2!=0)
	{
		c+=(n-pow(10, l-1)+1);
	}
	cout<<c<<endl;
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  vector<vector<pair<ll,ll>>> graph(N,vector<pair<ll,ll>>(0));
  rep(i,N-1){
    ll u,v,w; cin>>u>>v>>w; u--; v--;
    graph.at(u).push_back({v,w});
    graph.at(v).push_back({u,w});
  }
  
  vector<int> vec(N,-1);
  queue<ll> que; que.push(0); vec[0]=0;
  while(!que.empty()){
    ll v=que.front(); que.pop();
    for(auto p:graph.at(v)){
      ll nv,w; tie(nv,w)=p;
      if(vec[nv]>-1) continue;
      
      if(w%2==0) vec[nv]=vec[v];
      else vec[nv]=1-vec[v];
      
      que.push(nv);
    }
  }
  
  for(auto v:vec) cout<<v<<endl;
  
  return 0;
}

Measured memory_bytes: 11076
#include <iostream>
#include <vector>

using namespace std;
int main() {
	vector<int> x(5);
	for (int i = 0; i < 5; i++) {
		cin >> x[i];
	}

	for (int i = 0; i < 5; i++) {
		if (x[i] == 0)cout << i + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3432
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    ll r,d,x;
    cin>>r>>d>>x;
    ll ans=x;
    for(int i=0;i<10;i++){
        cout<<r*ans-d<<endl;
        ans=r*ans-d;
    }
    return 0;
}

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

using namespace std;

int main() {
	int n, a, b, c, x;
	while (cin >> n >> a >> b >> c >> x) {
		if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0) {
			break;
		}
		int r[110];
		for (int i = 0; i < n; i++) {
			cin >> r[i];
		}
		int k;
		int count = 0;
		for (k = 0; k < 10010; k++) {
			if (count == n) {
				k--;
				break;
			}
			if (x == r[count]) {
				count++;
			}
			x = (a*x+b)%c;
		}
		if (k <= 10000) {
			cout << k << endl;
		} else {
			cout << -1 << endl;
		}
	}
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define MAX 1000                                      
typedef long long ll;
typedef unsigned long long ull;
extern inline int max( int a, int b ) { return a > b ? a : b ; }
extern inline int min( int a, int b ) { return a > b ? b : a ; }
extern inline ll lmax( ll a, ll b ) { return a > b ? a : b ; }
extern inline ll lmin( ll a, ll b ) { return a > b ? b : a ; }
extern inline ull ulmax( ull a, ull b ) { return a > b ? a : b ; }
extern inline ull ulmin( ull a, ull b ) { return a > b ? b : a ; }

int H, W, cnt=0;
char input[1001][1001];
int dir_x[4] = { -1, 0, 1, 0 };
int dir_y[4] = { 0, 1, 0, -1 };
int Queue[2][2000001];
bool visited[1001][1001];
int rear=0, front=-1;

bool Check( int x, int y ){
	if( x<0 || y<0 || x>=H || y>=W ){
		return false;
	}else{
		return true;
	}
}

void Bfs(){
	
	int tmp = 0;
	rear = 0;
	front = 0;
	memset( Queue, 0, sizeof(Queue) );
	int dx, dy, dix, diy;
	
	for( int i=0; i<H; ++i ){
		for( int j=0; j<W; ++j ){
			if( input[i][j] == '#' && visited[i][j] == false ){
				Queue[0][rear] = i;
				Queue[1][rear] = j;
				visited[i][j] = true;
				rear++;
			}
		}
	}
	
	//printf("rear : %d, front : %d\n", rear, front );
	while( 1 ){
		tmp = rear;
		//printf("rear : %d, front : %d\n", rear, front );
		for( int i=front; i<tmp; ++i ){
			dx = Queue[0][i];
			dy = Queue[1][i];
			for( int j=0; j<4; ++j ){
				dix = dx + dir_x[j];
				diy = dy + dir_y[j];
				if( Check( dix, diy ) && visited[dix][diy] == false && input[dix][diy] == '.' ){
					input[dix][diy] = '#';
					visited[dix][diy] = true;
					Queue[0][rear] = dix;
					Queue[1][rear] = diy;
					rear++;
				}
			}
		}
		front = tmp;
		if( rear == front ){
			break;
		}
		cnt++;
	}
	printf("%d\n", cnt);
}

int main()
{
	memset( input, 0, sizeof(input) );
	memset( Queue, 0, sizeof(Queue) );
	memset( visited, false, sizeof(visited) );
	
	scanf("%d %d", &H, &W);
	for( int i=0; i<H; ++i ){
		fgetc(stdin);
		scanf("%s", input[i]);
	}
	Bfs();
	return 0;
}






Measured memory_bytes: 17792
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, string> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  map<P, int> mp;
  REP(i, n) {
    string s;
    int val;
    cin >> s >> val;
    mp[P(s.size(), s)] += val;
  }
  for (auto a : mp) {
    cout << a.first.second << " " << a.second << endl;
  }
  return 0;
}


Measured memory_bytes: 3208