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

const int MN = 200010;

int N;
int P[MN], vis[MN];
vector<int> adj[MN];
int tin[MN], par[MN], timer;
vector<int> cycle;

void dfs0(int u) {
    tin[u] = timer++;

    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(tin[v] != -1) {
            if(tin[v] < tin[u]) {
                int t = u;
                while(1) {
                    cycle.push_back(t);
                    if(t == v) break;
                    t = par[t];
                }
            }
            continue;
        }
        par[v] = u;
        dfs0(v);
    }
}

int del[MN], dp[MN];

void dfs1(int u) {
    vector<int> tmp;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(del[v]) continue;
        dfs1(v);
        tmp.push_back(dp[v]);
    }
    sort(tmp.begin(), tmp.end());

    int pos = 0;
    for(int i = 0; i < MN; i++) {
        while(pos < tmp.size() && tmp[pos] < i) pos++;
        if(pos == tmp.size() || tmp[pos] != i) {
            dp[u] = i;
            break;
        }
    }
}

void solve(int x) {
    int pre = x;
    for(int j = 0; j < cycle.size(); j++) {
        int u = cycle[j];

        vector<int> tmp;
        for(int k = 0; k < adj[u].size(); k++) {
            int v = adj[u][k];
            if(del[v]) continue;
            tmp.push_back(dp[v]);
        }
        tmp.push_back(pre);
        sort(tmp.begin(), tmp.end());

        int pos = 0;
        for(int k = 0; k < MN; k++) {
            while(pos < tmp.size() && tmp[pos] < k) pos++;
            if(pos == tmp.size() || tmp[pos] != k) {
                pre = k;
                break;
            }
        }
    }
    if(pre == x) {
        printf("POSSIBLE");
        exit(0);
    }
}

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

    for(int i = 0; i < N; i++) {
        int p; scanf("%d", &p);
        p--;
        adj[p].push_back(i);
        P[i] = p;
    }

    int u = 0;
    while(!vis[u]) {
        vis[u] = 1;
        u = P[u];
    }

    memset(tin, -1, sizeof(tin));
    dfs0(u);

    for(int i = 0; i < cycle.size(); i++) del[ cycle[i] ] = 1;
    for(int i = 0; i < cycle.size(); i++) {
        dfs1(cycle[i]);
    }
    solve(dp[ cycle.back() ]);

    vector<int> tmp;
    for(int i = 0; i < adj[ cycle.back() ].size(); i++) {
        int v = adj[ cycle.back() ][i];
        if(del[v]) continue;
        tmp.push_back(dp[v]);
    }
    tmp.push_back(dp[ cycle.back() ]);
    sort(tmp.begin(), tmp.end());

    int pos = 0;
    for(int i = 0; i < MN; i++) {
        while(pos < tmp.size() && tmp[pos] < i) pos++;
        if(pos == tmp.size() || tmp[pos] != i) {
            solve(i);
            break;
        }
    }
    printf("IMPOSSIBLE");
}


Measured memory_bytes: 28660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))

int main(){
	ll n,ans=0;
	cin >> n;
	vector<ll> p(n);
	FOR(i,0,n)cin >> p[i];
	FOR(i,1,n-1){
		if(p[i]<=p[i+1]&&p[i-1]<=p[i])ans++;
		if(p[i]>=p[i+1]&&p[i-1]>=p[i])ans++;
	}
	cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    int64_t ans = 0;
    map<string, int> M;
    for (int i = 0; i < N; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (M.count(s)){
            ans += M.at(s);
            M.at(s)++;
        }
        else{
            M[s] = 1;
        }
    }
    cout << ans << endl;
}

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

int main() {
	vector<int> a;
	int k,check=0;
	for(int i=0;i<5;i++){
		cin>>k;
		a.push_back(k);
	}
	cin>>k;
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			if(abs(a.at(i)-a.at(j)>k)){
				cout<<":("<<endl;
				return 0;
			}
		}
	}
	cout<<"Yay!"<<endl;
	return 0;
}

Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)

GRID = H.times.map { gets.chomp.chars }
VISITED = Array.new(H) { Array.new(W, false) }

ans = 0

H.times do |y|
  W.times do |x|
    next if VISITED[y][x]

    bc = 0
    wc = 0
    que = [[y, x]]

    until que.empty?
      cy, cx = que.shift

      next if VISITED[cy][cx]
      VISITED[cy][cx] = true

      if GRID[cy][cx] == '#'
        bc += 1
      else
        wc += 1
      end

      [[-1, 0], [0, 1], [1, 0], [0, -1]].each do |dy, dx|
        ny = cy + dy
        nx = cx + dx

        next if ny < 0 || nx < 0 || ny >= H || nx >= W
        next if GRID[cy][cx] == GRID[ny][nx]

        que << [ny, nx]
      end
    end

    ans += bc * wc
  end
end

puts ans


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

int main(){
    vector<int>dishes(5);
    rep(i,5) cin>>dishes.at(i);
    vector<int>notpit;
    rep(i,5){
        if(dishes.at(i)%10!=0){
            notpit.push_back(10-(dishes.at(i)%10));
        }
    }
    sort(notpit.begin(),notpit.end());
    int time=0;
    sort(dishes.begin(),dishes.end());
    rep(i,5) time+=dishes.at(i);
    if(notpit.size()>0) rep(i,notpit.size()-1) time+=notpit.at(i);
    cout<<time<<endl;
}

Measured memory_bytes: 256
N,Q = map(int,input().split())
S = input()
TD = [input().split() for _ in [0]*Q]

def f(n):
    s = S[n]
    for t,d in TD:
        if s==t:
            if d=="L":
                n -= 1
            else:
                n += 1
            if n<0 or N<=n: break
            s = S[n]
    return n

def binary_search(l,r,func):
    if func(l):return l-1
    if not func(r):return r
    while l+1<r:
        i = (l+r)//2
        if func(i):
            r = i
        else:
            l = i
    return l

l = binary_search(0,N-1,lambda n:f(n)>=0)
r = binary_search(0,N-1,lambda n:f(n)>=N)
print(r-l)

Measured memory_bytes: 40912
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

string s;

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

  int n = s.length() - 2;
  string newS = *s.begin() + to_string(n) + *(s.end() - 1);
  cout << newS << endl;

  return 0;
}


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

using namespace std;

#define l(a)std::lower_bound(B,B+n,a-A)

int n,a[2<<18],B[1<<18],s,A,i=1,j,L;

int main(){
	for(;cin>>(n?a[A++]:n););
	for(;i<1<<29;i*=2){
		for(j=0;j<n;j++)B[j]=a[n+j]%(i*2);
		for(std::sort(B,B+n);
		j--;
		s^=(a[j]&i?n-L:L)%2*i)A=a[j]%i,L=l(i*2)-l(i);
		}
	std::cout<<s;
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> a_vec(a);
  vector<int> b_vec(b);
  rep(i, a){
    cin >> a_vec[i];
  }
  rep(i, b){
    cin >> b_vec[i];
  }
  
  int a_min = *min_element(a_vec.begin(), a_vec.end());
  int b_min = *min_element(b_vec.begin(), b_vec.end());
  int ans = a_min + b_min;
  rep(i, m){
    int x, y, c;
    cin >> x >> y >> c;
    x--; y--;
    int value = a_vec[x]+b_vec[y] - c;
    ans = min(ans, value);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int>> day_option_matrix;
vector<vector<int>> computed_maximums;
int max_sum;
int max_happiness_from(int day, int last_taken_index)
{	
	int current_max_sum = 0;
	for (int i = 0; i <= 2; i++)
	{
		if (i != last_taken_index)
		{
			if (computed_maximums[day][i] > -1)
			{
				current_max_sum = max(current_max_sum, computed_maximums[day][i]);
			}
			else
			{
				int current_sum = day_option_matrix[day][i] + max_happiness_from(day + 1, i);
				current_max_sum = max(current_max_sum, current_sum);
				computed_maximums[day][i] = current_sum;
			}
		}
	}

	return current_max_sum;
}
int main()
{
	ios::sync_with_stdio(false);
	int no_days; cin >> no_days;
	day_option_matrix = vector<vector<int>>(no_days);
	computed_maximums = vector<vector<int>>(no_days+1);
	for (int i = 0; i < no_days; i++)
	{
		computed_maximums[i] = vector<int>(3, -1);
		day_option_matrix[i] = vector<int>(3);
		for (size_t j = 0; j < 3; j++)
			cin>>day_option_matrix[i][j];
	}
	computed_maximums[no_days] = vector<int>(3, 0);

	cout << max_happiness_from(0, -1);
	return 0;
}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 200200;
int mul(long long a, long long b){
	return a * b % mod;
}
int p2[maxn];
int main(){
	p2[0] = 1;
	for(int i = 1; i < maxn; i++) p2[i] = mul(2, p2[i - 1]);
	int n; cin >> n;
	string s; cin >> s;
	vector<int> divs;
	for(int d = 1; d <= n; d++){
		if(n % d == 0 && (n / d) % 2 == 1){
			divs.push_back(d);
		}
	}
	int len = divs.size();
	vector<int> how(len);
	int ans = 0;
	for(int i = 0; i < len; i++){
		int d = divs[i];
		int ways = 0;
		for(int j = 0; j < d; j++){
			if(s[j] == '1'){
				ways += p2[d - j - 1];
				if(ways >= mod) ways -= mod;
			}
		}
		bool ok = true;
		for(int j = d; j < n && ok; j++){
			int dist = j / d;
			if(dist % 2){
				if(s[j % d] == '0'){
					if(s[j] == '0'){
						ok = false;
					}
				} else {
					if(s[j] == '1'){
						break;
					}
				}
			} else {
				if(s[j % d] == '0'){
					if(s[j] == '1'){
						break;
					}
				} else {
					if(s[j] == '0'){
						ok = false;
					}
				}
			}
		}
		if(ok){
			ways += 1;
			if(ways >= mod) ways -= mod;
		}
		for(int j = 0; j < i; j++){
			if(d % divs[j] == 0){
				ways += mod - how[j];
				if(ways >= mod) ways -= mod;
			}
		}
		how[i] = ways;
		ans += mul(ways, d);
		if(ans >= mod) ans -= mod;
	}
	cout << mul(ans, 2) << endl;
	return 0;
}


Measured memory_bytes: 1412
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 156 -C
int main(void) {
	int  i, n, x[101];
	long p,t = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &x[i]);
		t += x[i];
	}
	
	p = round((float)t/n);

    t = 0;
    for (i = 0; i < n; i++) 
 		t += pow(x[i] - p, 2);
	printf("%ld",t);
	return 0;
}

Measured memory_bytes: 384
import itertools

N,M=map(int,input().split())
route=[list(map(int,input().split())) for _ in range(M)]
candidate=list(itertools.permutations(range(1,N+1)))

ans=0
for c in candidate:
  if c[0]==1:
    for i in range(N-1):
      l=sorted([c[i], c[i+1]])
      if l not in route:
         break
    else:
      ans+=1
print(ans)



Measured memory_bytes: 8052
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

a,b,c = readInts()

if ((c-a-b)**2-4*a*b)>0 and c-a-b>0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9376
n = int(input())
b = list(map(int, input().split()))
a = [0]*n
a[0] = b[0]
if len(b) == 1:
    print(2*sum(b))
else:
    for i in range(1, n-1):
        if b[i] <= b[i - 1]:
            a[i] = b[i]
        else:
            a[i] = b[i - 1]
        a[i + 1] = b[i]
    print(sum(a)) 

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#define lson rt<<1
#define rson rt<<1|1
#define mid ((l+r)>>1)
#define clr(a, b) memset(a, b, sizeof(a))
inline int min(int a, int b){return a<b?a:b;}
const int MAX_N = 300010;
struct SegTree{
	int f, a, lazy;
}node[MAX_N << 2];
char s[MAX_N];
int N, Q, k;

void pushup(int rt){
	node[rt].a = min(node[lson].a, node[rson].a);
	node[rt].f = min(node[lson].f, node[rson].f);
}

void pushdown(int rt){
	if (node[rt].lazy){
		node[lson].lazy += node[rt].lazy;
		node[rson].lazy += node[rt].lazy;
		node[lson].a += node[rt].lazy;
		node[rson].a += node[rt].lazy;
		node[lson].f += node[rt].lazy;
		node[rson].f += node[rt].lazy;
		node[rt].lazy = 0;
	}
}

void build(int l, int r, int rt, int a, int p){
	node[rt].lazy = 0;
	if(l == r){
		node[rt].f = a - l;
		node[rt].a = a;
		return ;
	}
	if (p <= mid) build(l, mid, lson, a, p);
	else build(mid+1, r, rson, a, p);
	pushup(rt);
}

void init(){
	clr(node, 0);
	int sum = 0;
	for (int i = 1;i <= N;++i){
		sum += (s[i] == '(' ? 1 : -1);
		build(1, N, 1, sum, i);
	}
}

void update(int L, int R, int val, int l, int r, int rt){
	if (L <= l && r <= R){
		node[rt].lazy += val;
		node[rt].f += val;
		node[rt].a += val;
		return ;
	}
	pushdown(rt);
	if (L <= mid)	update(L, R, val, l, mid, lson);
	if (R > mid)	update(L, R, val, mid+1, r, rson);
	pushup(rt);
}

int query1(int l, int r, int rt){
	if (l == r)	return l;
	pushdown(rt);
	if (node[lson].f < 0)	return query1(l ,mid, lson);
	return query1(mid+1, r, rson);
}

int query2(int l, int r, int rt){
	if (l == r)	return l+1;
	pushdown(rt);
	if (node[rson].a < 2)	return query2(mid+1, r, rson);
	return query2(l, mid, lson);	
}

int main(){
	while (~scanf("%d %d", &N, &Q)){
		scanf("%s", s+1);
		init();
		while (Q--){
			scanf("%d", &k);
			bool flag = (s[k] == '(');
			s[k] = flag ? ')' : '(';
			update(k, N, flag ? -2 : 2, 1, N, 1);
			k = (flag ? query1(1, N, 1) : query2(1, N, 1));
			flag = (s[k] == '(');
			s[k] = flag ? ')' : '(';
			update(k, N, flag ? -2 : 2, 1, N, 1);
			printf("%d\n", k);
		}
	}
	return 0;
}

Measured memory_bytes: 15396
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0226

"""
import sys
from sys import stdin
input = stdin.readline


def solve(r, a):
    hit = 0
    blow = 0

    for i in range(4):
        if r[i] == a[i]:
            hit += 1
        else:
            if a[i] in r:
                blow += 1
    return hit, blow


def main(args):
    while True:
        r, a = input().split()
        if r == '0' and a == '0':
            break
        hit, blow = solve(r, a)
        print(hit, blow)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8172
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, a, b = input_int_list()
    S = input()
    passed = 0
    oversea = 0
    for s in S:
        if s == "a" and passed < a + b:
            passed += 1
            print("Yes")
        elif s == "b" and passed < a + b and oversea < b:
            oversea += 1
            passed += 1
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 70564
/**
 * 	author: MahfuzAhmed
 * 	created: 08.08.2019 
**/

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define forn(var,from,to) for(int var=(from);var<(to);var++)
#define forx(var,from,to) for(int var=(from);var<=(to);var++)
#define fory(var,from,to) for(int var=(from);var>=(to);var--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vvi vector<vi>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(p) p.begin(),p.end()
typedef long long ll;
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int MAX_N = 1e6+5;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
       
    #ifdef _DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
    int n; cin >> n;
    int arr[n];
    
    forn(i, 0, n) cin >> arr[i];
    
    int cnt = 0;
    
    forn(i, 1, n-1){
        if((arr[i] > arr[i-1] && arr[i] < arr[i+1]) ||
            (arr[i] < arr[i-1] && arr[i] > arr[i+1]))
            cnt++;
    }
    
    cout << cnt << "\n";
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000; ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

//二分累乗法
ll binarypow(ll a, ll n, ll mod) {
  ll res = 1;
  while(n > 0) {
    if(n & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
    n >>= 1;
  }
  return res;
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x); // 再帰的に解く
    y -= a / b * x;
    return d;
}

ll modinv(ll a, ll m) {
  ll x, y;
  extGCD(a, m, x, y);
  return (x % m + m) % m;
}

ll gyaku[200100];

ll combination(ll n, ll r) {
  if(r==1)return n;
  else return n * combination(n-1, r-1) % mod * gyaku[r] % mod;
}

int main() {
    ll n, a, b; cin >> n >> a >> b;
    ll ans = binarypow(2, n, mod);
    rep(i, 200100) gyaku[i] = modinv(i, mod);
    ans -= 1;
    ans %= mod;
    ans -= combination(n, a);
    ans %= mod;
    ans -= combination(n, b);
    ans %= mod;
    if(ans < 0) ans += mod;
    cout << ans << endl;
}

Measured memory_bytes: 8064
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>
#include <array>

using namespace std;

vector<int> buf;


int main(int argc, char* argv[]){
    int N, K, C;
    string s;
    cin >> N >> K >> C;
    cin >> s;

    buf.resize(K, -1);

    int num = K;
    int cur = N - 1;

    while(cur >= 0){
        if(s[cur] == 'x'){
            --cur;
            continue;
        }

        buf[--num] = cur;
        if(num == 0){
            break;
        }

        cur -= C + 1;
    }

    cur = 0;
    num = 0;

    while(cur < N){
        if(s[cur] == 'x'){
            ++cur;
            continue;
        }

        if(buf[num++] == cur){
            cout << cur + 1 << endl;
        }

        if(num == K){
            break;
        }

        cur += C + 1;
    }

}


Measured memory_bytes: 2564
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
	Q[tail]=x;
	tail=(tail+1)%LEN;
}

P dequeue(){
	P x=Q[head];
	head=(head+1)%LEN;
	return x;
}

int min(int a,int b){return a<b?a:b;}

int main(){
	int elaps=0,c;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);
	
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=1;tail=n+1;
	
	while(head!=tail){
		u=dequeue();
		c=min(q,u.t);
		u.t-=c;
		elaps+=c;
		if(u.t>0)enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	
	return 0;
}

Measured memory_bytes: 10756
import math
n = int(input())

ans = 0
if n < 105:
    print(0)
else:
    for i in range(105, n +1):
        if i % 2 == 0:
            continue
        div = []
        for j in range(1, int(math.sqrt(i**2) + 1)):
            if i % j == 0:
                div.append(j)
                if j != i // j:
                    div.append(i //j)
        if len(div) // 2 == 8:
            ans += 1
    print(ans)

Measured memory_bytes: 3060
#include<cstdio>

class dice{
private:
	int a,b,c,d,e,f;
public:
	void setnumber(void);
	void E(void);
	void W(void);
	void S(void);
	void N(void);
	void printa(void);
};

void dice::setnumber(void){
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
}

void dice::E(void){
int a1=a,c1=c,d1=d,f1=f;
a=d1;
c=a1;
d=f1;
f=c1;
}

void dice::W(void){
int a1=a,c1=c,d1=d,f1=f;
a=c1;
c=f1;
d=a1;
f=d1;
}

void dice::S(void){
int a1=a,b1=b,e1=e,f1=f;
a=e1;
b=a1;
e=f1;
f=b1;
}

void dice::N(void){
int a1=a,b1=b,e1=e,f1=f;
a=b1;
b=f1;
e=a1;
f=e1;
}

void dice::printa(void){
printf("%d\n",a);
}

int main(void){
dice koro;
char ch[101];
int i=0;
koro.setnumber();
scanf("%s",ch);
while(ch[i]!='\0'){

	if(ch[i]=='E'){
		koro.E();
	}else if(ch[i]=='W'){
		koro.W();
	}else if(ch[i]=='S'){
		koro.S();
	}else if(ch[i]=='N'){
		koro.N();
	}
	i++;
}

koro.printa();

return 0;
}

		

Measured memory_bytes: 2732
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

int N;
int A[2][104];
int DP[2][104];
int solve() {
   FOR(j, 1, N)
      DP[0][j] = DP[0][j-1] + A[0][j];
   FOR(j, 1, N) {
      DP[1][j] = max(DP[0][j] + A[1][j], DP[1][j-1] + A[1][j]);
   }
   return DP[1][N];
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);

   cin >> N;
   REP(i, 2) {
      FOR(j, 1, N)
         cin >> A[i][j];
   }
   int res = solve();
   cout << res << endl;

   return 0;
}


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


void MyFunc(unsigned int h, unsigned int w, unsigned int n)
{
  unsigned int count = 0;
  unsigned int countOfPaint = 0;
  
  if (h > w)
  {
    for (int i = 0; i < h; i++)
    {
      count += h;
      countOfPaint++;
      if (count >= n) break;
    }
  }
  else
  {
    for (int i = 0; i < h; i++)
    {
      count += w;
      countOfPaint++;
      if (count >= n) break;
    }
  }
  cout << countOfPaint << endl;
}


int main(void)
{
  unsigned int H, W, N;

  cin >> H >> W >> N;
  function<void(unsigned int, unsigned int, unsigned int)> func = MyFunc;
  func(H, W, N);

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <functional>
#include <bitset>

using namespace std;

int main()
{
	long W, H, x, y;
	cin >> W >> H >> x >> y;

	//vector<unsigned int> vec_i(N);
	//for (int ic = 0; ic < N; ic++) {
	//	int buf;
	//	cin >> buf;
	//	vec_i[ic] = buf;
	//}

	double squareDiv2 = W * H  * 0.5;


	std::cout << squareDiv2;


	if (x == W * 0.5 && y == H * 0.5) {
		std::cout << " " << 1;
	}
	else {
		std::cout << " " << 0;
	}

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,M=map(int,input().split())
A=[0]*N
B=[0]*N
C=[0]*M
D=[0]*M
for i in range(N):
    a,b=map(int,input().split())
    A[i]=a
    B[i]=b
for i in range(M):
    c,d=map(int,input().split())
    C[i]=c
    D[i]=d

for i in range(N):
    ans=0
    lgt=float('inf')
    for j in range(M):
        l=abs(A[i]-C[j])+abs(B[i]-D[j])
        if l<lgt:
            lgt=l
            ans=j
    print(ans+1)

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

int main() {
   ll n;
   cin>>n;
   
   ll arr[n];
   map<ll,ll> m;
   ll sum = 0;
   for(int i = 0;i<n;i++){
   cin>>arr[i];
   m[arr[i]]++;
   sum += arr[i];
   }
   
   ll queries;
   cin>>queries;
   while(queries--)
   {
       ll b,c;
       cin>>b>>c;
       if(m.find(b)==m.end())
       {
           cout<<sum<<"\n";
       }
       else
       {
           // now we have to check that the element exist in the map or not..
           sum = sum - m[b]*b + m[b]*c;
           ll temp = m[b];
           m.erase(b);
           m[c] = m[c] + temp;
           cout<<sum<<"\n";
           
       }
       
   }
  
    
	return 0;
}

Measured memory_bytes: 8300
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = INF;
vl flag, color, D; vll path;
//***********//
int main() {
	string S;
	cin >> S;
	for (i = 0; i < 3; i++) {
		if (S[i] == '1') S[i] = '9';
		else S[i] = '1';
	}
	cout << S;
}

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

vector<ii> adj[3000];
vector<ll> rev[3005];
ll vis[3005], cnt[3005], in_queue[3005];
ll mark[3005];
ll n, m, k;

ii hascycle(){
    if(!mark[1]) return {0, 0};
    queue<ll> q; q.push(1);
    vector<ll> dist(3005, 1e14);
    in_queue[1] = 1;
    dist[1] = 0;
    while(!q.empty()){
        ll u = q.front(); q.pop();
        in_queue[u] = 0;
        cnt[u]++;
        if(cnt[u] >= n) return {1,-1};
        for(ii par : adj[u]){
            ll v = par.first, w = par.second;
            if(mark[v] and dist[v] > dist[u] + w){
                dist[v] = dist[u] + w;
                if(!in_queue[v]){
                    in_queue[v] = 1;
                    q.push(v);
                }
            }
        }
    }
    return {0, dist[n]};
}

void dfs(int u){
    mark[u] = 1;
    for(int v : rev[u])
        if(!mark[v])
            dfs(v);
}

int main(){
    
    cin >> n >> m >> k;
    ll maxiedge = 0;
    for(ll i = 0; i < m; i++){
        ll u, v, w; cin >> u >> v >> w;
        maxiedge = max(maxiedge, w);
        adj[u].push_back({v, k-w});
        rev[v].push_back(u);
    }
    dfs(n);
    
    ii res = hascycle();
    if(res.first == 1) cout << -1 << endl;
    else{
        cout << max(-res.second, 0LL) << endl; // ?????
    }
    
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i, k) for (auto &i : k)
#define all(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main()
{
	ll n;
	cin >> n;
	ll tmp=sqrt(n);
	for(int i=tmp+1;i>0;i--){
		if(n%i==0){
			cout << i+(n/i)-2 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define len(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

ll N;
void solve(){
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N){
    ll x, y;
    cin >> x >> y;
    A[i] = x - y;
    B[i] = x + y;
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  ll ans = max(A[N-1] - A[0], B[N-1] - B[0]);
  cout << ans << endl;
}

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


Measured memory_bytes: 6332
using System;
using System.Collections.Generic;
using System.Linq;

class Program{

  static int n;
  static int sum = 0;
  static string ans;

  static int Main() {

    string nyu =  Console.ReadLine();
    n = int.Parse(nyu);

    char[] s = nyu.ToCharArray();

    for (int i = 0; i < s.Length; i++) {
      sum += (int)char.GetNumericValue(s[i]);
    }

    if (n % sum == 0) {
      ans = "Yes";
    } else {
      ans = "No";
    }

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


Measured memory_bytes: 13268
object Main extends App {
  import scala.io.StdIn._
  solve
  def solve: Unit = {
    val a = readLine.trim.toInt
    val b = readLine.trim.toInt
    val c = readLine.trim.toInt
    val d = readLine.trim.toInt
    val e = readLine.trim.toInt
    val kaitoujikan = if (a < 0) -a * c + d else 0
    println(
      kaitoujikan + (if (a < 0) b else b - a) * e
    )
  }
  implicit class ScopeFunc[T](private val value: T) {
    def let[A](func:T ⇒ A): A = func(value)
    def also(func:T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}




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

using namespace std ;

#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define ll long long int 

#define fr first
#define se second

#define all(v) v.begin(),v.end() 
#define rall(v) v.rbegin(),v.rend()
#define sz(v) v.size() 

#define pb push_back
#define mp make_pair 

#define PI 3.141592653589793238



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


//bool valid(int x, int y){return x > 0 && x < n && y > 0 && y < m;}

int n;
vector<int>v;

int main(){
  cin >> n;
  v.resize(n);
  for(int i = 0 ; i < n ; i++)
    cin >> v[i];
  sort(all(v));
  int c = accumulate(all(v),0);
  c -= 2*(v[n-1]);
  puts(c > 0 ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
from collections import deque

H,W = map(int, input().split())
s = ["#"*(W+2)]+["#"+input()+"#" for i in range(H)]+["#"*(W+2)]

def bfs(sh,sw):
  if s[sh][sw] == "#":
    return 0
  queue = deque([(sh,sw)]) #スタート地点をdequeに入れる
  dist = [[-1] * (W+1) for i in range(H+1)] #距離をメモするリストを作成
  dist[sh][sw] = 0 #スタート地点の距離を0にする
  while queue:
    h,w = queue.popleft() #queueの左から位置情報を取り出す
    d = dist[h][w] #現在のマスの数字を保持(移動距離)
    # print("dist", dist)
    for i in [h-1,h+1]: #x軸に前後する
      if s[i][w] == "." and dist[i][w] == -1: #行ける、かつ未踏破のマス
        dist[i][w] = d + 1 #移動距離をメモ
        queue.append((i,w)) #移動先のマスをqueueに格納
    for j in [w-1,w+1]: #y軸を行ったり来たり
      if s[h][j] == "." and dist[h][j] == -1:
        dist[h][j] = d + 1
        queue.append((h,j))
          
  max_dist = 0
  for i in dist:
    max_dist = max(max_dist,max(i)) #移動距離が多いマスを抽出
  return max_dist
      

ans = 0          
for i in range(1,H+1):
  for j in range(1,W+1):
    now = bfs(i,j)
    ans = max(ans, now)
print(ans)


Measured memory_bytes: 46428
import java.util.Scanner;

class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String args[]){
        int n;
        int p[]=new int[20];
        n=sc.nextInt();
        int max=-99999999,max_i=0;
        for(int i=0;i<n;i++){
            p[i]=sc.nextInt();
            if(p[i]>max){
                max=p[i];
                max_i=i;
            }
        }
        int ans=0;
        for(int i=0;i<n;i++){
            if(i==max_i)continue;
            ans+=p[i];
        }
        System.out.println(ans+max/2);
        
    }
}

Measured memory_bytes: 23764
N = int(input())
H = list(map(int, input().split()))
fl = True

for i in range(0, len(H)-1):
    if H[i] > H[i+1] + 1:
        fl = False
        break

    if H[i-1] == H[i]:
        if H[i] > H[i+1]:
            fl = False
            break

    if H[i-1] < H[i]:
        if H[i] == H[i+1] + 1 or H[i] == H[i+1]:
            H[i] = H[i] - 1

if fl == True:
    print('Yes')
elif fl == False:
    print('No')


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

int main(){
	long long a,b;
	cin>>a>>b;
	if(a<=0&&b>=0)cout<<"Zero"<<endl;
	else if(a>0&&b>0)cout<<"Positive"<<endl;
	else if(a<0&&b<0){
		if((b-a)%2==0)cout<<"Negative"<<endl;
		else cout<<"Positive"<<endl;
	}
}

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

int main()
{
    ll N;
    cin >> N;
    vector<ll>A(N);
    rep(i, N)cin >> A[i];
    rep(i, N - 1)A[i + 1] += A[i];

    ll res = 1ll << 60;
    rep(i, N - 1) {
        ll l = A[i];
        ll r = A.back() - l;
        res = min(res, abs(l - r));
    }
    cout << res << endl;
    return 0;
}


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

int main(){
  /*
  int n, i, j;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  */
 int a, b;
 cin >> a >> b;
 string s = "";
 if(a>b){
   rep(i, a){
      s += to_string(b);
   }
 }
  else{
   rep(i, b){
      s += to_string(a);
   }
 }
 cout << s << endl;

}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define MAX 1010
string s1, s2;
int dp[MAX][MAX];
int main(void) {
    cin >> s1;
    cin >> s2;
    int size1 = s1.size(), size2 = s2.size();
    for (int i = 0; i <= size1; i++) dp[i][0] = i;
    for (int i = 0; i <= size2; i++) dp[0][i] = i;
    for (int i = 1; i <= size1; i++) {
        for (int j = 1; j <= size2; j++) {
            int cost;
            if (s1.substr(i-1, 1) == s2.substr(j-1, 1)) cost = 0;
            else cost = 1;
            dp[i][j] = min(min(dp[i-1][j-1] + cost, dp[i-1][j] + 1), dp[i][j-1] + 1);
        }
    }
    cout << dp[size1][size2] << endl;
    return 0;
}

Measured memory_bytes: 5140
#include <stdio.h>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, m, a, b, now;
  scanf("%lld%lld", &n, &m);
  bool flg[n], t;
  vector<ll> vec[n];
  deque<ll> ans;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld", &a, &b);
    vec[--a].push_back(--b);
    vec[b].push_back(a);
  }
  ans.push_front(0);
  for(i = 0; i < n; ++i) flg[i] = true;
  flg[0] = false;
  while(1) {
    now = ans.front();
    t = false;
    for(i = 0; i < vec[now].size(); ++i) if(flg[vec[now][i]]) {
      ans.push_front(vec[now][i]);
      flg[vec[now][i]] = false;
      t = true;
      break;
    }
    if(t) continue;
    now = ans.back();
    for(i = 0; i < vec[now].size(); ++i) if(flg[vec[now][i]]) {
      ans.push_back(vec[now][i]);
      flg[vec[now][i]] = false;
      t = true;
      break;
    }
    if(t) continue;
    else break;
  }
  printf("%lld\n", ans.size());
  while(ans.size()) printf("%lld ", ans.front() + 1), ans.pop_front();
  return 0;
}

Measured memory_bytes: 7168
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{ 
int a,b,c;
  cin>>a>>b>>c;
  if(a==5&&b==5&&c==7)  cout<<"YES"<<endl;
  else if(a==5&&b==7&&c==5)  cout<<"YES"<<endl;
  else if(a==7&&b==5&&c==5)  cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0; 
  }

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

int main() {
	int N;
	cin >> N;
	vector<int> w(N);
	for(int i = 0; i < N; ++i) {
		cin >> w[i];
	}
	int a = 0;
	int b = 0;
	for(int i = 0; i < N; ++i) {
		b += w[i];
	}
	int sum = b;
	int dis = b;
	for(int i = 0; i < N; ++i) {
		a += w[i];
		b = b - w[i];
		if(abs(b - a) <= dis) {
			dis = abs(b - a);
		} else {
			cout << dis << endl;
			break;
		}
	}
	if(dis == sum) {
		cout << dis << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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; }
//#define int long long

//とりあえず、与えられた条件でできることを考えてみる！！

void solve() {
	int n, m; ll l;
    cin >> n >> m >> l;
    ll d[330][330];
    rep(i, n) {
        rep(j, n) {
            d[i][j] = INF;
        }
    }
    rep(i, m) {
        int a, b; ll c; cin >> a >> b >> c;
        --a; --b;
        d[a][b] = c;
        d[b][a] = c;
    }
    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    //とりあえず、できることは各点間の最短距離を求める
    //最短距離がわかれば、L以下の長さのパスを結ぶことができる

    ll p[330][330];
    
    rep(i, n) {
        rep(j, n) {
            if(d[i][j] <= l) p[i][j] = 1;
            else p[i][j] = INF;
        }
    }
    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                p[i][j] = min(p[i][j], p[i][k] + p[k][j]);
            }
        }
    }
    int q; cin >> q;
    while(q--) {
        int s, t; cin >> s >> t;
        --s; --t;
        if(p[s][t] == INF) cout << -1 << endl;
        else cout << p[s][t] - 1 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 2176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class MainClass
{
    static void Main()
    {
        var NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = NK[0], K = NK[1];
        var x = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var p = x.Where(_ => _ >= 0).ToArray();
        var m = x.Where(_ => _ < 0).OrderByDescending(_=>_).ToArray();
        long min = long.MaxValue / 4;
        if (m.Length >= K)
            min = Math.Min(min, -m[K - 1]);
        if (p.Length >= K)
            min = Math.Min(min, p[K - 1]);
        for (int i = 0; i < p.Length; i++)
        {
            int c = i + 1;
            if (m.Length >= K - c&& K-c>0)
                min = Math.Min(min, p[i] * 2 - m[K - 1 - c]);
        }
        for (int i = 0; i < m.Length; i++)
        {
            int c = i + 1;
            if (p.Length >= K - c&& K-c>0)
                min = Math.Min(min, -m[i] * 2 + p[K - 1 - c]);
        }
        Console.WriteLine(min);
    }
}

Measured memory_bytes: 27488
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL N, M;

LL modpow(LL a, LL n) {
	LL ret = 1;
	while (n)ret = ret*((n % 2) ? a : 1) % MOD,a=a*a%MOD, n >>= 1;
	return ret;
}

LL comb(int P, int Q) {
	if (P < 0 || Q<0 || Q>P)return 0;
	LL p = 1, q = 1;
	Q = min(Q, P - Q);
	for (int i = 1; i <= Q; i++)p = p*P%MOD, q = q*i%MOD, P--;
	return p*modpow(q, MOD - 2) % MOD;
}

LL hcomb(int P, int Q) { return (P == 0 && Q == 0) ? 1 : comb(P + Q - 1, Q); }

map<LL, LL> enumprimenum(LL n) {
	map<LL, LL> ret;
	for (LL i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	//素数なら1度も割られずにでてくるのでnのまま。
	if (n != 1)ret[n] = 1;
	return ret;
}

int main() {
	
	cin >> N>>M;

	auto f = enumprimenum(M);
	LL ans = 1;
	for (auto m : f) {
		ans = ans*hcomb(N,m.second) % MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
void main() {
	auto N = readAs!ulong;
	
	if(N < 357) {
		writeln(0);
		return;
	}
	gen(N).lowerBound(N + 1).length.writeln;
	
}

auto gen(ulong n) {
	auto t = n.to!string.length;
	
	dchar[][] arr = ["3", "5", "7"].to!(dchar[][]);
	foreach(i; 1..t) {
		auto tmp = arr.dup;
		foreach(p; ['3', '5', '7']) {
			foreach(k; tmp) {
				arr ~= p ~ k;
			}
		}
	}
	return arr.filter!(i => i.dup.sort().uniq.array.length == 3).array.sort().uniq.array.to!(ulong[]).sort();
}

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

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 34684