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

template <typename InputIterator>
typename InputIterator::value_type
summation(InputIterator first, InputIterator last) {
  using T = typename InputIterator::value_type;
  T *p = new T();
  const auto sum = std::accumulate(first, last, *p);
  delete p;
  return sum;
}
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
  std::vector<int32_t> a(n);
  std::cin >> a;
  std::sort(a.begin(), a.end());

  std::vector<std::vector<int16_t>> l(n), r(n);

  l[0].push_back(0);
  std::vector<bool> tmp(k, false);
  tmp[0] = true;

  for (int64_t i = 1; i < n; i++) {
    if (a[i - 1] < k) {
      for (const auto j : l[i - 1]) {
        if (k <= a[i - 1] + j) {
          break;
        }
        if (!tmp[a[i - 1] + j]) {
          tmp[a[i - 1] + j] = true;
        }
      }
    }
    l[i].reserve(k);
    for (int64_t j = 0; j < k; j++) {
      if (tmp[j]) {
        l[i].push_back(j);
      }
    }
  }

  r[n - 1].push_back(0);
  std::fill(tmp.begin(), tmp.end(), false);
  tmp[0] = true;

  for (int64_t i = n - 2; 0 <= i; i--) {
    if (a[i + 1] < k) {
      for (const auto j : r[i + 1]) {
        if (k <= a[i + 1] + j) {
          break;
        }
        if (!tmp[a[i + 1] + j]) {
          tmp[a[i + 1] + j] = true;
        }
      }
    }
    r[i].reserve(k);
    for (int64_t j = 0; j < k; j++) {
      if (tmp[j]) {
        r[i].push_back(j);
      }
    }
  }

  int64_t m = 0;
  bool before;

  for (int64_t i = 0; i < n; i++) {
    if (k <= a[i]) {
      break;
    }
    if (0 < i && a[i - 1] == a[i]) {
      if (before) {
        m++;
      }
      continue;
    }

    bool flag = false;
    if (l[i].size() < r[i].size()) {
      for (const auto &j : l[i]) {
        const auto max = k - 1 - j;
        const auto itr = *(--std::upper_bound(r[i].cbegin(),
          r[i].cend(), max));
        if (k <= itr + j + a[i]) {
          flag = true;
          break;
        }
      }
    } else {
      for (const auto &j : r[i]) {
        const auto max = k - 1 - j;
        const auto itr = *(--std::upper_bound(l[i].cbegin(),
          l[i].cend(), max));
        if (k <= itr + j + a[i]) {
          flag = true;
          break;
        }
      }
    }
    if (!flag) {
      m++;
      before = true;
    } else {
      before = false;
    }
  }

  std::cout << m << std::endl;
  return 0;
}


Measured memory_bytes: 89600
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



ll N;
ll table[10][10];

int main(){

	scanf("%lld",&N);

	for(int i = 0; i < 10; i++){
		for(int k = 0; k < 10; k++){

			table[i][k] = 0;
		}
	}

	ll head,tail;

	for(ll i = 1; i <= N; i++){

		tail = i%10;
		head = i%10;

		ll tmp = i/10;

		while(tmp > 0){
			head = tmp%10;
			tmp /= 10;
		}

		table[head][tail]++;
	}

	ll ans = 0;

	for(int i = 0; i < 10; i++){
		for(int k = 0; k < 10; k++){

			ans += table[i][k]*table[k][i];
		}
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	string S;
	cin >> S;
	bool ans = S[2] == S[3];
	ans &= S[4] == S[5];
	puts([&] {
		return ans;
	}() ? "Yes": "No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
int n,m,r,c=INF;
int rr[9];
vector<vector<int>> road(201,vector<int>(201,INF));
bool f[9];
void dfs(int cnt,int now,int cost){
  if(cnt==r){
    c=min(cost,c);
    return;
  }
  for(int i=1;i<=r;i++){
    if(!f[i]){
      f[i]=true;
      if(now==0){
        dfs(cnt+1,i,cost);
      }else{
        dfs(cnt+1,i,cost+road[rr[now]][rr[i]]);
      }
      f[i]=false;
    }
  }
}
int main(){
  cin>>n>>m>>r;
  for(int i=1;i<=r;i++){
    cin>>rr[i];
  }
  for(int i=1;i<=m;i++){
    int a,b,c;
    cin>>a>>b>>c;
    road[a][b]=road[b][a]=c;
  }
  for(int k=1;k<=n;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        if(road[i][j]>road[i][k]+road[k][j]){
          road[i][j]=road[i][k]+road[k][j];
        }
      }
    }
  }
  dfs(0,0,0);
  cout<<c;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }

struct UnionFind{

	std::vector<ll> data;
	// dataの各要素について
	// 負の値:その集合のルートであること示す。また、その絶対値は集合の要素数となっている。
	// 正の値:親ノードの番号(dataのインデックス)。root()を呼び出すたびに集合のルートを指すように書きなおされるので木はそんなに深くならない

	//初期化 size:最大要素数
	UnionFind(ll size): data(size, -1) {}
	
	// 集合を併合する
	// すでに同じ集合だった場合は、falseが返る
	void unite(ll x, ll y){
		x=root(x);
		y=root(y);
		if( x != y ){
			// 要素数の大きな方へ合併するためのswap
			if( data[y] < data[x] ) std::swap(x, y);
			// 要素数を加算する
			data[x] += data[y];
			// yの属する集合のルートをxに変更
			data[y] = x;
		}
		//return x!=y;
	}

	// 同じ集合かどうか判定
	bool find(ll x, ll y){
		return root(x) == root(y);
	}

	// 集合の識別番号を返す
	ll root(ll x){
		// 負の値を持つものがその集合のルート
		// 正の値は同じ集合に属するものを指す(辿ればいずれルートへ着く)
		return (data[x] < 0)? x : data[x]=root(data[x]);
	}

	// 集合の要素数を返す
	ll size(ll x){
		return -data[ root(x) ];
	}
};
//UnionFind tree(n);

int main(){
    ll n,m; cin>>n>>m;
    vector<ll> a(m), b(m);
    rep(i,m) cin>>a[i]>>b[i];
    ll res=0;
    rep(i,m){
        UnionFind tree(n);
        rep(j,m){
            if(i==j) continue;
            tree.unite(a[j]-1, b[j]-1);
        }
        if(tree.size(0)!=n) res++;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
import copy

import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

n,k = ips()
a = n//k
b = n//k + 1
a*=k
b*=k
ca = abs(n-a)
cb = abs(n-b)
print(min(ca,cb))

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

void main()
{
    auto a = readln.chomp.to!int;
    auto b = readln.chomp.to!int;
    auto h = readln.chomp.to!int;
    writeln((a + b) * h / 2);
}

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

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	int N, M;
	cin >> N >> M;
	
	vector<int> broken(N + 1);
	int tmp;
	for (int i = 0; i < M; i++) {
		cin >> tmp;
		broken[tmp] = 1;
	}

	vector<int> dp(N + 1);
	dp[0] = 1;

	for (int i = 1; i <= N; i++) {

		if (!broken[i]) {
			dp[i] += dp[i - 1];
			if (i != 1) dp[i] += dp[i - 2];
			dp[i] %= MOD;
		}
	}

	cout << dp[N] << "\n";

	return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		int countn = 0;
		int countw = 0;
		int counts = 0;
		int counte = 0;
		boolean flg1 = false;
		boolean flg2 = false;
		for(int i = 0;i < s.length;i++){
			if(s[i].equals("N")){
				countn++;
			}
			if(s[i].equals("W")){
				countw++;
			}
			if(s[i].equals("S")){
				counts++;
			}
			if(s[i].equals("E")){
				counte++;
			}
		}
		if(countn > 0 && counts > 0){
			flg1 = true;
		} else if(countn == 0 && counts == 0){
			flg1 = true;
		}
		if(countw > 0 && counte > 0){
			flg2 = true;
		} else if(countw == 0 && counte == 0){
			flg2 = true;
		}
		if(flg1 && flg2){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

const int N = 200010;

int n, a[N << 1];

int sma (int i, int j, int k) {
    return a[i] <= k && a[j] <= k;
}

int big (int i, int j, int k) {
    return a[i] > k && a[j] > k;
} 

int check (int k) {
    for (int i = 0; i < n - 1; ++i) {//枚举距离判断
        if (big (n + i, n + i + 1, k) || big (n - i, n - i - 1, k)) return 0;
        if (sma (n + i, n + i + 1, k) || sma (n - i, n - i - 1, k)) return 1;
    }
    return sma (1, 1, k);//没有重合的特判
}

int main(){
	cin >> n;
    for (int i = 1; i <= (n << 1) - 1; ++i) {
        cin >> a[i];
    }
    int l = 1, r = 2 * n - 1, ans;
    while (l < r) {//二分判断
        int mid = (l + r) >> 1;
        if (check (mid)) {
            r = mid;
        } else {
			l = mid + 1;
		}
	}
    cout << r;
    return 0; 
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define PI 2 * acos(0)
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define MAX 300000
#define debug cout << "asfasf" << endl;
#define READ freopen("input.txt", "r", stdin)
#define PRINT freopen("output.txt", "w", stdout);
#define MOD 1e7
#define print(a, b) printf("Case %d: %d\n", a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
/*................OMI.................*/

bool isPrime(ll n)
{
   if (n <= 1)
      return false;
   if (n <= 3)
      return true;

   if (n % 2 == 0 || n % 3 == 0)
      return false;

   for (ll i = 5; i * i <= n; i = i + 2)
      if (n % i == 0)
         return false;

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

ll lcm(ll a, ll b)
{
   ll g = gcd(a, b);
   ll ans = (a * b) / g;
   return ans;
}

///palindrome check!
bool palindrome(string s)
{
   for (ll i = 0; i < s.length() / 2; i++)
   {
      if (s[i] != s[s.length() - i - 1])
         return 0;
   }
   return 1;
}
/// divisors->>
void printDivisors(int n)
{
   for (int i = 1; i <= sqrt(n); i++)
   {
      if (n % i == 0)
      {
         if (n / i == i)
            printf("%d ", i);

         else
            printf("%d %d ", i, n / i);
      }
   }
}
/// string to INT
int convert_number(string s)
{
   int n;
   stringstream(s) >> n;
   return n;

   // int v=atoi(ss.c_str());
   // atoi is better than this function in case of complexity
}

///prime storage>>>

vector<ll> prime;

void primes(ll m)
{

   bool isprime[m];
   for (int i = 0; i <= m; i++)
      isprime[i] = true;

   for (int i = 3; i * i <= m; i++)
   {
      if (isprime[i])
      {

         for (int j = i * i; j <= m; j += i)
            isprime[j] = false;
      }
   }
   prime.push_back(2);
   for (int i = 3; i <= m; i += 2)
      if (isprime[i])
         prime.push_back(i);
}

/************MAIN_FUNCTION***********/

int main(int argc, char *argv[])
{
   FAST;
   ll n;
   cin >> n;

   if (n < 1000)
      cout << (1000 - n) << endl;

   else
   {
      ll m = 1000, i = 1;
      while (m < n)
      
         m+=1000;
        
      

      cout << (m - n) << endl;
   }

   return 0;
}

Measured memory_bytes: 3664
//Littleboy123 Template 1.6
#include <bits/stdc++.h>
using namespace std;

//pragmas
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(n) printf("%d\n", (n))
#define COUTLL(n) printf("%lld\n", (n))
#define CIN(n) scanf("%d", &(n))
#define CINLL(n) scanf("%lld", &(n))
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

void infile(){
	freopen("input.in", "r", stdin);
}

void outfile(){
	freopen("output.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
	if(b == 0)
		return 1;
	if(b == 1)
		return a;
	ll tmp = modex(a, b/2, mod);
	tmp = (tmp * tmp) % mod;
	if(b & 1)
		tmp = (tmp * a) % mod;
	return tmp;
}

//End of template

int n;
int vac[100005][3];
ll memo[100005][3];

ll dp(int pos, int before){
	if(pos == n){
		return 0;
	}
	if(memo[pos][before] != -1)
		return memo[pos][before];
	ll maks = INT_MIN;
	FOR(i, 0, 3){
		if(i+1 != before){
			maks = max(vac[pos][i] + dp(pos+1, i+1), maks);
		}
	}
	return memo[pos][before] = maks;
}

int main(){
	init();

	cin >> n;
	FOR(i, 0, n){
		FOR(j, 0, 3){
			cin >> vac[i][j];
		}
	}
	MEM(memo, -1);
	ll ans = INT_MIN;
	FOR(i, 0, 3){
		ans = max(ans, vac[0][i]+dp(1, i+1));
	}
	cout << ans << nl;
	return 0;	
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

long long INF=LLONG_MAX;

ll n,W,mxV=0;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	cin >> n >> W;
	ll w[n],v[n];
	for(int i=0; i<n; i++){
		cin >> w[i] >> v[i];
		mxV += v[i];
	}
	
	ll dp[mxV+1];
	for(ll i=0; i<=mxV; i++)dp[i]=1e18;
	dp[0] = 0;
	for(int i=0; i<n; i++){
		for(ll j=mxV; j >= v[i]; j--){
			dp[j] = min(dp[j],dp[j-v[i]]+w[i]);
			//cout << i << ' ' << j << ' ' << dp[j] << endl;
		}
	}
	for(ll i=mxV; i>=0; i--){
		if(dp[i]<=W){
			cout << i << endl;
			break;
		}
	}
}	


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

using namespace std;

#define INF ((int)2e18)
#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
#define double long double
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

// bool lesss(double a, double b) { return ((a + EPS) < b); }
bool lesss(double a, double b) { return (a + EPS  < b); }

double sqrtt(double a) {
  double l = 0, r = a;
  for (int i = 0; i < 100000; i++) {
    double mid = (l + r) / 2;
    if (mid * mid == a)
      return mid;
    else if (mid * mid < a) {
      l = mid;
    } else
      r = mid;
  }

  return l;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int a, b, c;

  cin >> a >> b >> c;

  cout << (lesss(a + b + 2 * sqrtt(a * b), c) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    cout << 111 + 999 - n << endl;

    return 0;
}

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

bool p[1000000];

void erato(){
	fill(p, p+1000000, true);
	p[0] = p[1]= false;

	for(int i=0; i*i < 1000000; i++){
		if(!p[i])continue;
		for(int j= i+i; j < 1000000; j+= i){
			p[j] = false;
		}
	}
}

int main(){
	erato();
	int n;
	while(cin >> n, n){
		int ans = 0;
		for(int i=0; i <= n/2; i++){
			if(!p[i]) continue;
			if(p[n-i]) ans++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2136
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define int ll
ll v_color[200005]={0};
vector<P> knode[200005],node[200005];
const ll inf=1e9;
ll ans[200005]={0};
ll dn[200005]={0};
void dfs(ll pos,ll val){
  v_color[pos]=val;
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i].first;
    if(v_color[to]==0){
      ans[node[pos][i].second]=dn[to];
      dfs(to,val%2+1);
    }
  }
}
signed main(){
  ll n,m;
  cin>>n>>m;
  vector<P> vec;
  for(int i=1;i<=n;i++){
    ll val;
    cin>>val;
    dn[i]=val;
    vec.push_back(P(val,i));
  }
  sort(vec.begin(),vec.end());
  for(int i=1;i<=m;i++){
    ll u,v;
    cin>>u>>v;
    knode[u].push_back(P(v,i));
    knode[v].push_back(P(u,i));
  }
  for(int i=1;i<=n;i++){
    P min_v=P(inf,inf);
    for(int j=0;j<knode[i].size();j++){
      ll to=knode[i][j].first;
      min_v=min(min_v,P(dn[to],j));
    }
    node[i].push_back(knode[i][min_v.second]);
    node[knode[i][min_v.second].first].push_back(P(i,knode[i][min_v.second].second));
  }
  for(int i=1;i<=n;i++){
    bool f=false;
    for(int j=0;j<knode[i].size();j++){
      ll to=knode[i][j].first;
      if(dn[to]<=dn[i]) f=true;
    }
    if(!f){
      cout<<-1<<endl;
      return 0;
    }
  }
  for(int i=0;i<n;i++){
    ll pos=vec[i].second;
    if(v_color[pos]==0){
      dfs(pos,1);
    }
  }
  for(int i=1;i<=n;i++) {
    if(v_color[i]==0) cout<<"0";
    else if(v_color[i]==1) cout<<"B";
    else cout<<"W";
  }
  cout<<endl;
  for(int i=1;i<=m;i++){
    cout<<(ans[i]==0?inf:ans[i])<<endl;
  }
}


Measured memory_bytes: 31088
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n,m;cin>>n>>m;
    vin x(m);
    rep(i,m)cin>>x[i];
    if(m<=n){
        cout<<0<<endl;
        return 0;
    }
    sort(all(x));
    vin d(m-1);
    rep(i,m-1)d[i]=x[i+1]-x[i];
    sort(all(d));
    int sum=0;
    rep(i,m-n)sum+=d[i];
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int n,i,j,count;
    count = 0;
    int box[256];
    scanf("%d",&n);
    for (i = 0; i < n; i++){
        scanf("%d",&box[i]);
    }
    for (i = 0; i < n - 2; i++){
        if (box[i] < box[i + 1] && box[i + 1] < box[i + 2] || box[i] > box[i + 1] && box[i + 1] > box[i + 2]){
            count++;
        }
    }
    printf("%d",count);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a,b;
 cin >> a >> b;
 if(a-2*b>0){
     cout << a-2*b << endl;
 }else{
     cout << 0 << endl;
 }
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long sum = 0;
        for (int i = 1; i <= N; i++) {
            if (i % 3 != 0 && i % 5 != 0)
                sum += i;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 35548
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

void solve(){
    int n; cin >> n;
    for(int i=1; i<=9;i++){
        for(int j=1; j<=9; j++){
            if(i*j == n){
                Yes();
                exit(0);
            }
        }
    }
    No();
}

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

Measured memory_bytes: 256
n = int(input())
s = input()
x = list(s)
y = 0
a = 0
while y <= n - 3:
  z = x[y] + x[y + 1] + x[y + 2]
  if z == "ABC":
    a += 1
    y += 1
  else:
    a += 0
    y += 1
print(a)

Measured memory_bytes: 2940
l = input()
a, b, c = map(int, l.split())
if c <= a and c <= b:
    if a <= b:
        print(c, a, b)
    else:
        print(c, b, a)
elif b <= a and b <= c:
    if a <= c:
        print(b, a, c)
    else:
        print(b, c, a)
else:
    if c <= b:
        print(a, c, b)
    else:
        print(l)



Measured memory_bytes: 5596
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;
struct edge {
	int from;
	int to;
	int w;
};
int a;
class Compare {
public:
	//keiroが昇順に並ぶ
	bool operator()(const edge&l, const edge&r) {
		return l.w-a> r.w-a;
	}
};
int main() {
	while (1) {
		int n, m; cin >> n >> m;
		if (!n)break;
		vector<vector<edge>>edges(n);
		for (int i = 0; i < m; ++i) {
			int a, b, w; cin >> a >> b >> w;
			a--;
			b--;
			edges[a].push_back(edge{ a,b,w });
			edges[b].push_back(edge{ b,a,w });
		}
		int ans = 99999999;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < edges[i].size(); ++j) {
				a = edges[i][j].w;
				priority_queue<edge, vector<edge>, Compare>que;
				que.push(edges[i][j]);
				que.push(edge{ edges[i][j].to,edges[i][j].from,edges[i][j].w });
				vector<bool>oks(n);
				int nowans = 0;
				while (!que.empty()) {
					edge atop(que.top());
					que.pop();
					if (!oks[atop.to]) {
						oks[atop.to] = true;
						nowans = max(atop.w - a, nowans);
						
						for (auto k : edges[atop.to]) {
							if (k.w >= a) {
								if (!oks[k.to]) {
									que.push(k);
								}
							}
						}
					}
				}
				if (all_of(oks.begin(), oks.end(), [](const bool a) {return a; })) {
					ans = min(ans,nowans);
				}
			}
		}
		if (ans == 99999999) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3260
n,m=gets.split(" ").map(&:to_i) #最初のｎとｍのVALUE　をとる

a=n.times.map do                #matrixをN回やる
gets.split.map(&:to_i)          #空白段落分けて入力するためMAPとSPLIT
end
b=m.times.map do                #VECTORをm回入力
gets.to_i                       #値入力
end

a.each do |r|                   #rのなかをひとつひとつを繰り返す
    puts r.zip(b).map {|x, y| x * y }.reduce(0, :+)#ZIPはaとbを連動して計算をする
  end
  


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

const int INF = (int)(1000 + 5);

int a, b, c;

int ans = INF;

int main(void){
  scanf("%d %d %d", &a, &b, &c);
  for (int sa = 0; sa < 30; ++sa) {
    for (int sb = 0; sb < 30; ++sb) {
      for (int sc = 0; sc < 30; ++sc) {
        for (int dab = 0; dab < 30; ++dab) {
          for (int dac = 0; dac < 30; ++dac) {
            for (int dcb = 0; dcb < 30; ++dcb) {
              if ((2 * (sa - sb) + (dac - dcb) == (b - a)) &&
                  (2 * (sb - sc) + (dab - dac) == (c - b)) &&
                  (2 * (sa - sc) + (dab - dcb) == (c - a))
              ) {
                int cand = sa + sb + sc + dab + dac + dcb;
                ans = min(ans, cand);
              }
            }
          }
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  vector<int>a(3);
  for(const char c:s){
    a[c-'a']++;
  }
  cout<<(*max_element(a.begin(),a.end())-*min_element(a.begin(),a.end())<2?"YES":"NO")<<endl;
}

Measured memory_bytes: 512
// SeeAlso: https://atcoder.jp/contests/abc138/tasks/abc138_a

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int a;
string s;
int main() {
    cin >> a;
    cin >> s;
    if (a>=3200) {
        print(s);
    } else {
        print("red");
    }
    return 0;
}


Measured memory_bytes: 764
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut st = vec![0; n + 1];
    st[0] = 1;
    for i in 1..n + 1 {
        st[i] = st[i - 1] * i % n;
    }
    let sti: Vec<usize> = st.iter().map(|&x| inv_m(x, n)).collect();
    let mut ans = vec![0; n];
    for i in 0..n {
        if v[i] == 0 {
            continue;
        }
        ans[0] += 1;
        for j in 0..n {
            if (n - j) % 2 == 0 {
                ans[j] += st[n - 1] * sti[j] % n * sti[n - j - 1] % n * pow_m(i, n - j - 1, n) % n;
            } else {
                ans[j] += n - st[n - 1] * sti[j] % n * sti[n - j - 1] % n * pow_m(i, n - j - 1, n) % n;
            }
            ans[j] %= n;
        }
    }
    print!("{}", ans[0]);
    for i in 1..n {
        print!(" {}", ans[i]);
    }
    println!("");
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}

fn inv_m(n: usize, d: usize) -> usize {
    pow_m(n, d - 2, d)
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	for(int i=1; ;i++){
	    int x=sc.nextInt();
	    if(x==0) break;
	    System.out.printf("Case %d: %d\n",i,x);
	}
    }
}



Measured memory_bytes: 62304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k;
int main(){
	cin >> n >> k;
	ll ans = 0;
	if(n == k)
		ans = 0;
	else if(n > k)
		ans = min(n % k, abs(n % k - k));
	else{
		ll q1 = abs(n - k);
		ll q2 = abs(q1 - k);
		ans = min(n, min(q1, q2));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    int n; cin >> n;
    int a[200]; for (int i = 0; i < 2*n; i++) cin >> a[i];
    sort(a, a+2*n);
    int ans = 0;
    for (int j = 2*n-2; j >= 0; j -= 2) ans += a[j];
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;


public class Main	 {
    public static void main(String[] args) throws IOException {
        	Scanner sc = new Scanner(System.in);
        	int n = sc.nextInt();
        	BigInteger f = new BigInteger(Integer.toString(n));
        	long arr[] = new long[n];
        	for(int i=0;i<n;i++) {
        		arr[i] = sc.nextLong();
        	}
        	Arrays.sort(arr);
        	BigInteger[] series = new BigInteger[n];
        	for(int i=0;i<n;i++) {
        		series[i] = new BigInteger(Long.toString(arr[i]));
        	}
        	BigInteger res = new BigInteger("1");
        	boolean flag =false;
        	BigInteger  b2 = new BigInteger("0"); 
        	BigInteger  b3 = new BigInteger("1000000000000000000");
        	for(int i=0;i<n;i++) {
        		res = res.multiply(series[i]);
        		int comparevalue = res.compareTo(b2); 
        		int comparevalue1 = res.compareTo(b3); 
        		if(comparevalue==0) {
        			System.out.println("0");
        			flag=true;
        			break;
        		}
        		else if(comparevalue1==1) {
        			flag=true;
        			System.out.println("-1");
        			break;
        		}
        	}
        	if(flag==false)
        		System.out.println(res);
    }
}


Measured memory_bytes: 68816
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define deb(a) cout << #a << ": " << ENDL
#define all(a) begin(a), end(a)
#define sz(a) (int)(a.size())
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

int main()
{   _
    lli x, k, d; cin >> x >> d >> k;
    x = abs(x);
    lli rem = (x - x % k) / k;
    lli u = x - rem * k;
    lli v = abs(u - k);
    if(d <= rem) {
        x -= k * d;
        cout << x << ENDL;
        return 0;
    }
    d -= rem;
    if(d % 2 == 0) cout << u << ENDL;
    else cout << v << ENDL;
    return 0;
}
/**
1000000000000000
1000000000000000
1000000000000000
1000000000000000
*/


Measured memory_bytes: 3620
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

using Graph = vector<vector<int64_t>>;

constexpr int64_t kInf = (1LL << 40);

int64_t Cost(const Graph &g, const vector<int> &towns, const vector<int> &indexes)
{
    int64_t cost = 0;
    for (size_t i = 0; i + 1 < towns.size(); i += 1) {
        auto a = towns[indexes[i]];
        auto b = towns[indexes[i + 1]];
        cost += g[a][b];
    }
    return cost;
}

int64_t Back(vector<int> &st, vector<bool> &used, int level, const Graph &g, const vector<int> &towns)
{
    if (level >= (int)st.size()) {
        return Cost(g, towns, st);
    }

    auto res = kInf;
    for (size_t i = 0; i < st.size(); i += 1) {
        if (used[i]) {
            continue;
        }

        st[level] = i;
        used[i] = true;

        res = min(res, Back(st, used, level + 1, g, towns));
        used[i] = false;
    }
    return res;
}

int64_t FindBest(const Graph &g, const vector<int> &towns)
{
    vector<int> st(towns.size());
    vector<bool> used(towns.size(), false);

    return Back(st, used, 0, g, towns);
}

int main()
{
    int nodes, edges, towns;
    cin >> nodes >> edges >> towns;

    vector<int> indexes(towns);
    for (auto &ind : indexes) {
        cin >> ind;
        ind -= 1;
    }

    Graph graph(nodes, vector<int64_t >(nodes, kInf));
    for (auto i = 0; i < nodes; i += 1) {
        graph[i][i] = 0;
    }
    for (auto i = 0; i < edges; i += 1) {
        int64_t a, b, cost;
        cin >> a >> b >> cost;
        graph[a - 1][b - 1] = cost;
        graph[b - 1][a - 1] = cost;
    }

    for (auto k = 0; k < nodes; k += 1) {
        for (auto i = 0; i < nodes; i += 1) {
            for (auto j = 0; j < nodes; j += 1) {
                if (k == i || k == j || i == j) {
                    continue;
                }
                if (graph[i][k] < kInf || graph[k][j] < kInf) {
                    graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
                }
            }
        }
    }

    auto res = FindBest(graph, indexes);
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 512
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #n = int(stdin.readline()[:-1])   
    r = stdin.readline()[:-1]
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    #n = int(r)
    #a = r.split()
    a,b,c = r.split()
    #a = list(map(int, r.split()))
    #a,b,c,d = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #res = 0

    if b == '+':
        print(int(a)+int(c))
    else:
        print(int(a)-int(c))

if __name__ == '__main__':
    main()


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

const int INF = 1e9;

int main()
{
    int a,b,k;
    cin >> a >> b >> k;
    for(int i = 0; i < k; i++){
        if(i % 2 == 0){
            if(a % 2 == 1) a--;
            a /= 2;
            b += a;
        }else{
            if(b % 2 == 1) b--;
            b /= 2;
            a += b;
        }
    }
    cout << a << ' ' << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
using namespace std;
typedef long long LL;
LL gi () {
    LL ret=0; char ch=getchar();
    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
    char c=ch=='-'?getchar():ch;
    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();
    return ch=='-'?-ret:ret;
}
const int N = 2000 + 10;
int n,a[N],S;
bitset<N*N> dp;
int main () {
    n = gi();
    for(int i=1;i<=n;i+=1) a[i] = gi(), S += a[i];
    dp[0] = 1;
    for(int i=1;i<=n;i+=1) {
        dp |= (dp<<a[i]);
    }
    for(int i=(S-1)/2+1;i<=S;i+=1)
        if(dp[i]) {
            printf("%d",i); exit(0);
        }
    return 0;
}


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

int main(){
      int a,b;cin >> a >> b;
      string s;cin >> s;
      int n = s.length();
      for(int i = 0;i < n;i++){
            if(i == a && s[i] != '-')return cout << "No", 0;
            else if(i != a && !(s[i] >= '0' && s[i] <= '9'))return cout << "No", 0;
      }
      cout << "Yes";
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class CHAndV {
public:
    int count(vector<string> &v, int i, int j){
        int n=v.size();
        int m=v[0].length(),cnt=0;
        for (int x=0;x<n;x++){
            for (int y=0;y<m;y++){
                if ((!((i&(1<<x))||(j&(1<<y))))&&(v[x][y]=='#'))
                    cnt++;
            }
        }
        return cnt;
    }
	void solve(std::istream& cin, std::ostream& cout) {
        int n,m,k;
        cin>>n>>m>>k;
        vector<string> v;
        string s;
        for (int i=0;i<n;i++){
            cin>>s;
            v.pb(s);
        }
        int ans=0;
        for (int i=0;i<(int)(pow(2,n));i++){
            for (int j=0;j<(int)(pow(2,m));j++){
                if (k==count(v,i,j))
                    ans++;
            }
        }
        cout<<ans;
	}
};


int main() {
	CHAndV solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4088
#include<stdio.h>
#include<stdlib.h>
struct node
{
    int key;
    struct node *next, *prev;
};
struct node *nil; 
void init()
{
    nil=(struct node *)malloc(sizeof(struct node));
    nil->next=nil;
    nil->prev=nil;
} 
struct node *listSearch(int keys)
{
    struct node *cur=nil->next;
    while(cur!=nil && cur->key!=keys)
        cur=cur->next; 
    return cur;
} 
void insert(int keys)
{
    struct node *x=(struct node *)malloc(sizeof(struct node));
    x->key=keys;
    //insert
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
} 
void Delete(struct node *t)
{
    if(t==nil) return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
} 
void deleteFirst()
{
    Delete(nil->next);
} 
void deleteLast()
{
    Delete(nil->prev);
} 
void printList()
{
    struct node *cur=nil->next;
    while(cur->next != nil)
    {
        printf("%d ", cur->key);
        cur=cur->next;
    }
    printf("%d\n", cur->key);
}
int main()
{
    int n, x,i;
    char comm[12];
 
    scanf("%d", &n);
 
    init();
 
    for(i=0; i<n; i++)
    {
        scanf("%s", comm);
        if(comm[0]=='i')
        {
            scanf("%d", &x);
            insert(x);
        }
        if(comm[0]=='d')
        {
            if(comm[6]=='F') deleteFirst();
            else if(comm[6]=='L') deleteLast();
            else
            {
                scanf("%d", &x);
                Delete(listSearch(x));
            }
        }
    }
    printList(); 
    return 0;
}

Measured memory_bytes: 31784
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007; 
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}




std::vector<bool> isPrime;

void Eratosthenes(int n){
    if(n + 1 <= int(isPrime.size())) return;
    isPrime.resize(n+1, true);
    isPrime[0] = isPrime[1] = false;

    for(int i = 2; i * i <= n; ++i){
        if(isPrime[i]){
            for(int j = i; i * j <= n; ++j)
                isPrime[i*j] = false;
        }
    }
}

int main(){
    
    Eratosthenes(10'000'000);
    std::vector<int> a(10'000'001);
    a[13] = 13;
    for(int i(14); i <= 10'000'000; ++i){
        a[i] = a[i-1];
        if(isPrime[i] && isPrime[i-2] && isPrime[i-6] && isPrime[i-8]){
            a[i] = i;
        }
    }
    int n;
    while(1){
        std::cin >> n;
        if(!n) return 0;
        std::cout << a[n] << "\n";
    }
    return 0;
}



Measured memory_bytes: 42972
// Problem : D - Katana Thrower
// Contest : AtCoder - AtCoder Beginner Contest 085
// URL : https://atcoder.jp/contests/abc085/tasks/abc085_d
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N,H;
	cin>>N>>H;
	int mx=-1;
	vi v(N);
	F0R(x,N)
	{
		int a,b;
		cin>>a>>b;
		ckmax(mx,a);
		v[x]=b;
	}
	sort(all(v));
	reverse(all(v));
	if(mx>=H || v[0]>=H)
	{
		cout<<1<<nl;
		return 0;
	}
	ll sum=0;
	F0R(x,N)
	{
		if(v[x]<=mx)
		{
			cout<<(H-sum)/mx+x+((H-sum)%mx!=0?1:0)<<nl;
			return 0;
		}
		sum+=v[x];
		if(sum>=H)
		{
			cout<<x+1<<nl;
			return 0;
		}
	}
	cout<<(H-sum)/mx+(ll)N+((H-sum)%mx!=0?1:0)<<nl;
			
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

int main() {
  int n,m;
  cin >> n >> m;
  std::vector<int> WA(105000,0);
  std::vector<int> AC(105000, 0);

  int wrong = 0, correct = 0;
  rep(i,m) {
    int p;
    string s;
    cin >> p >> s;

    if (AC.at(p) == 1) continue;
    if (s == "WA") WA[p]++;
    else if (s == "AC") {
      AC.at(p) = 1;
      wrong += WA.at(p);
      correct++;
    }
  }
  cout << correct << " " << wrong << endl;
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int MAX=100;
int g[MAX*400+2];

int n,t[MAX+2],v[MAX+2],ans;
int main(void){
	cin >> n;
	t[0]=0;
	for(int i=1;i<=n;i++){
		cin >>t[i];
		t[i]*= 2;//x->2*x座標にする
		t[i]+=t[i-1];//2*x座標と対応させる
	}
	for(int i=0;i<n;i++){
		cin >>v[i];
		v[i]*= 2;//y座標も2倍。傾きが1のまま。
	}
	for(int i=0;i<=t[n];i++){
		g[i]=min(i,t[n]-i);//t[0],t[n]の制限
		for(int j=0;j<n;++j){
			if(i<=t[j]){//i->t[j]->t[j+1]
				g[i]=min(g[i],v[j]+t[j]-i);
			}else if(t[j+1]<=i){//t[j]->t[j+1]->i
				g[i]=min(g[i],v[j]+i-t[j+1]);
			}else{//t[j]->j->t[j+1]
				g[i]=min(g[i],v[j]);
			}
		}
	}
	for(int i=0; i<t[n]; ++i){
		ans += g[i]+g[i+1];//台形の面積
	}
	printf("%.5lf\n",((double)(ans)/8));
	return 0;
}



Measured memory_bytes: 384
/**************************************************
 * Atcoder problems
 * Contest No :083
 * Problem No :B
 * File Name  :program.cs
 * Create date:2020/06/21
 *
 * Copyright 2020 Shunichi Sato,All Rights Reserved.
**************************************************/
//memo terinal command
//compile:mcs program.cs
//excute :mono program.exe
using System;
class Program
{
    static void Main(string[] args)
    {
        // 個数の入力
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);//10000以下の整数
        int A = int.Parse(input[1]);//和の最小値
        int B = int.Parse(input[2]);//和の最大値
        int total = 0;
        // 計算
        for (int i = 1; i <= N; i++){
            int sum = findSumOfDigits(i);
            if (sum >= A && sum <= B){
                total += i;
            }
        }
        //出力
        Console.WriteLine(total);
    }
    static int findSumOfDigits(int n){
        int sum = 0;
        while (n > 0){
            sum += n %10;
            n /= 10;
        }
        return sum;
    }
}


Measured memory_bytes: 17612
MOD = 10 ** 9 + 7
N = int(input())

S_all = pow(10, N, MOD)
S_0 = pow(9, N, MOD)
S_9 = S_0
S_09 = pow(8, N, MOD)

ans = (S_all - (S_0 + S_9 - S_09)) % MOD
print(ans)


Measured memory_bytes: 9156