akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod//i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD


@mt
def slv(N, K):
    ans = 0
    M = 10**9 + 7

    C = Combination(N*2+1, M)
    def H(n, r):
        return C(n+r-1, r)

    K = min(N-1, K)
    for k in range(K+1):
        m = N - k
        t = C(N, k) * H(m, k)
        ans += t
        ans %= M

    return ans


def main():
    N, K = read_int_n()
    print(slv(N, K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 171720
import java.util.Scanner

object Main {
  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val List(v, c) = List.fill(2, N)(sc.nextInt())
    val value = v.zip(c).map{
      case (a, b) => a - b
    }.filter(_ > 0).sum
    println(value)
  }
}

Measured memory_bytes: 25804
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  string w, s;
  int count = 0;
  // https://wikiwiki.jp/kyopro/%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E3%81%AE%E3%83%86%E3%82%AF%E3%83%8B%E3%83%83%E3%82%AF/%E5%85%A5%E5%8A%9B%E3%81%AE%E5%87%A6%E7%90%86%28C%2CC%2B%2B%29
  cin >> w; cin.ignore();
  // http://stlalv.la.coocan.jp/transform.html
  // https://stackoverflow.com/questions/23418390/how-to-convert-a-c-string-to-uppercase
  transform(w.begin(), w.end(), w.begin(), ::tolower);
  while (true){
    // getline(cin, s);
    cin >> s;
    if(s == "END_OF_TEXT"){break;}
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    if(s == w){
      count += 1;
    }
    
    // while (s.find(w) != string::npos){
    //   count += 1;
    //   s.erase(s.find(w), w.length());
    // }
  }
  cout << count << endl;
}


Measured memory_bytes: 3156
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;

#define MAX 100009
#define NIL -1

struct Node { int p, l, r; };
Node T[MAX];
int n, D[MAX];

void setDepth(int u, int p) {
	D[u] = p;
	if (T[u].r != NIL) setDepth(T[u].r, p);
	if (T[u].l != NIL) setDepth(T[u].l, p + 1);
}

void listChild(int u) {
	int c = T[u].l;
	cout << "[";
	while (c != NIL) {
		cout << c;
		c = T[c].r;
		if(c!=NIL) cout << ", ";
	}
	cout << "]";
}

void whatType(int u) {
	if (D[u] == 0) cout << "root";
	else {
		if (T[u].l == NIL) cout << "leaf";
		else cout << "internal node";
	}
}

void print(int u) {
	cout << "node " << u << ": parent = " << T[u].p << ", depth = " << D[u] << ", ";
	whatType(u);
	cout << ", ";
	listChild(u);
	cout << "\n";
}

int main() {
	int d, v, c, l, r;
	cin >> n;
	for (int i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

	for (int i = 0; i < n; i++) {
		cin >> v >> d;
		for (int j = 0; j < d; j++) {
			cin >> c;
			if (j == 0)  T[v].l = c;
			else  T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}

	for (int i = 0; i < n; i++) if (T[i].p == NIL) r = i;
	setDepth(r, 0);
	for (int i = 0; i < n; i++) print(i);
}

Measured memory_bytes: 7708
/******************************************
* AUTHOR : Lokesh goel*
* NICK : InsaneNerd *
* INSTITUTION : NIT Kurukshetra *
******************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000000
#define N 100005
#define pii pair<int,int>
#define vp vector<pair<int,int > >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define gsz(x) ((int)(x).size())
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
#define endl "\n"
#define ms(x,v) memset(x,v,sizeof(x))

int main()
{
	fastio;
	string s,t;
	cin>>s>>t;
	int res=0;
	for(int i=0,j=0;i<s.length();i++,j++){
		if(s[i]!=t[i])
			res++;
	}
	cout<<res<<endl;


	return 0;
}

Measured memory_bytes: 3824
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  int h, w;
  cin >> h >> w;
  rep(i, h) {
    string s;
    cin >> s;
    cout << s << endl << s << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n, a[200200];
ll ans;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i];
    sort(a+1, a+1+n, greater<int>());
    ans += a[1];
    int c = n - 2;
    for(int i=2;i<=n;i++){
        if(!c) break;
        c--;
        ans += a[i];
        if(!c) break;
        c--;
        ans += a[i];
        if(!c) break;
    }
    cout << ans;
}

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n,r;
    cin >> n >> r;
    if(n<10){
        cout << (100*(10-n))+r <<endl;
        return 0;
    }else{
        cout << r <<endl;
        return 0;
    }
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int ans = 0;
    for(int i = 0; i < 2; i++){
        int a; cin >> a;
        if(a == 3) ans += 100000;
        if(a == 2) ans += 200000;
        if(a == 1) ans += 300000;
    }
    if(ans == 600000) ans += 400000;
    cout << ans << endl;
    return 0;
}

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

int main(){
    
    int i,j;
    scanf("%d %d",&i,&j);
    i = pow(100,i);
    if(j==100)
    i=101*i;
    else
    i*=j;
    
    printf("%d\n",i);
    
    return 0;
}        

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	string res = "Christmas";

	for (int i = 0; i < 25 - d; i++)
	{
		res += " Eve";
	}

	println(res);
}


Measured memory_bytes: 256
#include <stdio.h>
main()
{
  int i,a[99],b[99];
  char s[99][99];
  for(i=0;i<9;i++)
    {
      scanf("%s%d%d",&s[i],&a[i],&b[i]);     
    }
  for(i=0;i<9;i++)
    {
      printf("%s %d %d\n",s[i],a[i]+b[i],a[i]*200+b[i]*300);     
    }
  exit(0);
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            String[] array = reader.readLine().split(" ");
            int N = Integer.parseInt(array[0]);
            int M = Integer.parseInt(array[1]);

            array = reader.readLine().split(" ");
            PriorityQueue<Long> queue = new PriorityQueue<Long>(new Comparator<Long>() {
                @Override
                public int compare(Long o1, Long o2) {
                    return o2.compareTo(o1);
                }
            });
            for (int i = 0; i < N; i++) {
                queue.add(Long.valueOf(array[i]));
            }

            for (int i = 0; i < M; i++) {
                Long value = queue.poll();
                queue.add(value / 2);
            }

            long sum = 0;
            for (Long value : queue) {
                sum += value;
            }

            System.out.println(sum);
        }
    }

}


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

using namespace std;


bool check(string s)
{

    int n =s.length();
    for (int i=0; i<n; i++)
            if (s[i]!=s[n-i-1]) return false;
    return true;
}



int main()
{


string s;
cin >> s;
int x =s.length();
x/=2;

string a,b;
for (int i=0; i<x; i++)
    a.push_back(s[i]);
for (int i=x+1; i<=2*x; i++)
    b.push_back(s[i]);

//cout << a << " " << b;
if ( check(s) && check(a) && check(b)) cout << "Yes"; else cout << "No";






}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get() {}template<class H, class...T>void get(H&h, T&...t) { cin >> h; get(t...); }
template<class T>void geti(T&a) { for (auto&_ : a)cin >> _; }
template<class T>void getii(T&a) { for (auto&_ : a)geti(_); }
void put(string d) {}template<class H, class...T>void put(string d, H&h, T&...t) { cout << h; if (sizeof...(t))cout << d; put(d, t...); }
template<class T>void puti(T&a, string d = " ") { bool f = 1; for (auto&_ : a)cout << (exchange(f, 0) ? "" : d) << _; cout << endl; }
template<class T>void putii(T&a, string d = " ") { for (auto&_ : a)puti(_, d); }
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

bool isPrime(int num) {
    int N = sqrt(num);
    for (int i = 2; i <= N; i++) {
        if (num%i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    int a;
    int s = 0;
    rep(i,n) {
        cin >> a;
        if (isPrime(a)) {
            s++;
        }
    }
    cout << s << endl;
}



Measured memory_bytes: 3112
// atcoder/abc152/F/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> reverse(pair<P, Q> p) { return make_pair(p.second, p.first); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr lli mod = 1e9 + 7;

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

  int n;
  while (cin >> n) {
    const int inf = 1 << 29;
    const int N = 50 + 5;
    vec<int> g[N];

    int idx[N][N];

    for (int i = 0; i < n - 1; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      g[a].push_back(b);
      g[b].push_back(a);
      idx[a][b] = idx[b][a] = i;
    }

    int m;
    cin >> m;
    vec<pair<int, int>> v(m);
    cin >> v;
    each (i, v) {
      --i.first;
      --i.second;
    }

    static lli b[N][N];
    fill(&b[0][0], &b[N - 1][N - 1] + 1, 0);
    for (int src = 0; src < N; ++src) {
      function<void(int, int)> rec = [&] (int curr, int prev) {
        if (curr != prev) {
          b[src][curr] = b[src][prev] | (1LL << idx[curr][prev]);
        }
        each (next, g[curr]) {
          if (next != prev) rec(next, curr);
        }
        return ;
      };
      rec(src, src);
    }

    lli sum = 0;
    for (int bit = 0; bit < (1 << v.size()); ++bit) {
      lli x = 0;
      for (int i = 0; i < v.size(); ++i) {
        if (bit & (1 << i)) {
          x |= b[v[i].first][v[i].second];
        }
      }
      int y = __builtin_popcountll(bit);
      int z = __builtin_popcountll(x);
      if (y % 2) {
        sum -= (1LL << (n - 1 - z));
      } else {
        sum += (1LL << (n - 1 - z));
      }
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import math
N = int(input())
X = list(map(float, input().split()))
Y = list(map(float, input().split()))
p1 = 0
i = 0
while i < N :
    p1 = p1 + abs(X[i]-Y[i])
    i = i + 1
print(p1)

p2 = 0
i = 0
while i < N :
    p2 = p2 + (X[i]-Y[i])**2
    i = i + 1
print (math.sqrt(p2))

p3 = 0
i = 0
while i < N :
    p3 = p3 + abs((X[i]-Y[i])**3)
    i = i + 1
print(math.pow(p3, (1/3)))

p4 = abs(X[0]-Y[0])
i = 0
while i < N-1 :
    if p4 < abs(X[i+1]-Y[i+1]) :
        p4 = abs(X[i+1]-Y[i+1])
    i = i + 1
print(p4)


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

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
                                                                                                                
int main() {
  ll N;
  cin >> N;

  ll ans = 0;
  for (ll A = 1; A < N; ++A) {
    ll B = 1;
    while (A*B < N) {
      ans ++;
      B++;
    }
  }     
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
int main(){
    int H,W,i,j;
    while(true){
        std::cin >> H >> W;
        if(H==0 && W==0) break;
        for(i = 0; i< H ; i++){
            for(j=0;j<W;j++){
                std::cout << "#";
            }
            std::cout << std::endl;
        }
        std::cout  << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3048
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x=i;
    if(i%3 == 0){
        cout<<" "<<i;
    }
    else if(i%10 == 3){
            cout<<" "<<i;
   }
    else{
        for(x=i;x!=0;x/=10){
            if(x%10==3){
                cout<<" "<<i;
				x = 0;
             }
          }
       }
    }
    cout<<endl;

return 0;
}


Measured memory_bytes: 3096
import math
import bisect
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
result=[]
a=int(input())
for i in range(a-500,a+501):
    if i<0:
        continue
    if is_prime(i):
        result.append(i)
bisect.insort_left(result,a)
n=bisect.bisect_left(result,a)
print(result[n+1])

Measured memory_bytes: 64872
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

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;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define dump(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 shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(4);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    ll n;
    cin >> n;
    ll x[n];
    ll ans= 0;

    rp(i,n-1){
        cin >> x[i];
    }
    ans += x[0];
    rp(i,n-2){
        ans += min(x[i],x[i+1]);
    }
    ans += x[n-2];
    cout << ans;
    cout << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

void sort(char *num){
  int i, j, min;
  for(i = 0;i < 8;i++){
    min = i;
    for(j = i + 1;j < 8;j++)
      min = num[min] < num[j] ? min : j;
    if(min != i){
      num[min] += num[i];
      num[i] = num[min] - num[i];
      num[min] -= num[i];
    }
  }
  return;
}

int main(){
  int i, j, n;
  long long int max, min;
  char num[8];
  scanf("%d", &n);
  while(n--){
    max = min = 0;
    scanf("%s", num);
    sort(num);
    for(i = 0;i < 8;i++){
      max += pow(10, i) * (num[i] - '0');
      min += pow(10, i) * (num[7 - i] - '0');
    }
    printf("%lld\n", max - min);
  }
  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    string s,t;
    cin>>s>>t;
    ll n1 = s.size();
    ll n2 = t.size();
    ll res = INT_MAX;
    for(int i=0;i<n1;i++){
      if(i+n2-1<n1){
        ll cur = 0;
        for(int j=i;j<=i+n2-1;j++){
          if(s[j]!=t[j-i])
            cur++;
        }
        res = min(res,cur);
      }
    }
    cout<<res;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;

	bool graph[N][N];
	memset(graph, false, sizeof(graph));
	rep(i, 0, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a][b] = graph[b][a] = true;
	}

	vector<int> v;
	rep(i, 0, N) v.push_back(i);

	int rsl = 0;
	do {
		bool flag = true;
		rep(i, 0, N - 1) {
			if(i == 0 and v[i] != 0) {
				flag = false;
				break;
			}
			if(graph[v[i]][v[i + 1]]) continue;
			flag = false;
			break;
		}
		if(flag) rsl++;
	} while(next_permutation(v.begin(), v.end()));
	cout << rsl << endl;
}


Measured memory_bytes: 256
s = list(input())
s.reverse()
s = ''.join(map(str, s))
count = 0
word = ['maerd', 'remaerd', 'resare', 'esare']

while count <= len(s)-8:
  counttemp = count
  for i in range(4):
    w = word[i]
    if s[count:count+len(w)] == w:
      count += len(w)
  if counttemp == count:
    break

if s[count:] in word or s[count:] =='':
  print('YES')
else:
  print('NO')

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

int main() {
  int n; cin>>n;
  
  int k=-1;
  for (int i=1; i<=n; i++) {
    if ((i*(i+1))==2*n) {
      k=i;
      break;
    }
  }
  if (k==-1) cout<<"No"<<endl;
  else {
    vector<vector<int>> res(k+1, vector<int>(k, 0));
    int cnt=1;
    for (int i=0; i<k; i++) {
      for (int j=i; j<k; j++) {
        res[i][j]=cnt;
        res[j+1][i]=cnt;
        cnt++;
      }
    }
    cout<<"Yes"<<endl;
    cout<<k+1<<endl;
    for (int i=0; i<=k; i++) {
      cout<<k<<" ";
      for (int j=0; j<k; j++) {
        if (j) cout<<" ";
        cout<<res[i][j];
      }
      cout<<endl;
    }
  }
}


Measured memory_bytes: 2176
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	double n,k,ans=0;
	cin >> n >> k;
	
	for(int i=1;i<=n;i++){
		double t = i, temp=1/n;
		while(t<k){
			t*=2;
			temp/=2;
		}	
		ans += temp;
	}
	printf("%.12f", ans);
}

Measured memory_bytes: 256
h;w;f(y){y=w/3;return h%3?fmin(w%3-1|y<h?fmax(h/2,y)+y+1:h+y,h%2?h:h/2):0;}main(){scanf("%d%d",&h,&w);printf("%.f",fmin(f(h^=w^=h^=w),f()));}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    string S; cin >> S;
    int used_i = -1;
    repr(i, 1, 4) {
        // 同じものがあれば
        if (S[i] == S[0]) {
            used_i = i;
            break;
        }
    }
    if (used_i == -1) {
        cout << "No" << endl;
        return 0;
    }
    int not_used = -1;
    repr(i, 1, 4) {
        // 違うものがあれば
        if (S[i] != S[0]) {
            not_used = i;
            break;
        }
    }
    if (not_used == -1) {
        cout << "No" << endl;
        return 0;
    }
    repr(i, 1, 4) {
        if (i != used_i && i != not_used && S[i] == S[not_used]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define pb push_back
vector<int> G[1000];
int g[1000];
void dfs(int v){
	bool is[1001]={};
	for(int u:G[v]){
		if(g[u]<0) dfs(u);
		is[g[u]]=1;
	}
	rep(i,1001) if(!is[i]){
		g[v]=i;
		break;
	}
}
int v[1000],gr[1001];
int main(){
	int N,M;
	cin>>N>>M;
	rep(i,N) cin>>v[i];
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a].pb(b);
	}
	rep(i,N) g[i]=-1;
	rep(i,N) dfs(i);
	rep(i,N) gr[g[i]]^=v[i];
	bool a=false;
	rep(i,1001) if(gr[i]) a=true;
	if(a) puts("1");
	else puts("2");
}

Measured memory_bytes: 1300
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] s = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			s[i] = Integer.parseInt(sc.next());
			sum += s[i];
		}
		int max = 0;
		if (sum % 10 == 0) {
			Arrays.sort(s);
			int index = 0;
			while (s[index] % 10 == 0) {
				index++;
				if (index == n) {
					System.out.println("0");
					return;
				}
			}
			max = s[index];
		}
		System.out.println(sum - max);
	}
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  map<int, int> cnt;
  for (int i = 0; i < N; i++) {
    if(cnt.count(A.at(i))) cnt[A.at(i)] = cnt.at(A.at(i)) + 1;
    else cnt[A.at(i)] = 1;
  }
  vector<int> cnt2(cnt.size());
  int i = 0;
  for (auto p : cnt) {
    cnt2.at(i) = p.second;
    i++;
  }
  sort(cnt2.begin(), cnt2.end());
  if (cnt.size() <= K) cout << 0 << endl;
  else {
    int sum = 0;
    for (int j = 0; j < cnt.size() - K; j++) {
      sum += cnt2.at(j);
    }
    cout << sum << endl;
  }
}
  
    


Measured memory_bytes: 11136
// id: ALDS1_3_D
// 由于日语系统等原因，网页上的反斜杠\显示成了￥
// 注：本代码用到了C++11的新语法，故在oj系统中编译通不过，要做如下修改
// 删去array，改用vector；两个>之间加空格；vector不能列表初始化，要push_back
// CPU: 00:00sec  Memory: 3268KB
#include <iostream>
#include <string>
#include <stack>
#include <array>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::stack;
using std::string;
using std::vector;
using std::array;

int main()
{
	string s;
	stack<int> pos;
	int total = 0;
	vector<array<int, 2>> areas;

	cin >> s;
	int length = s.size();

	for ( int i = 0; i < length; ++i ) {
		if ( s[i] == '\\' )
			pos.push(i);
		else if ( s[i] == '/' && !pos.empty() ) {
			int lpos = pos.top();
			pos.pop();
			int area = i - lpos;
			total += area;

			array<int, 2> piece{lpos, area};
			
			while ( !areas.empty() && areas.back()[0] > lpos ) {
				piece[1] += areas.back()[1];
				areas.pop_back();
			}
			areas.push_back(piece);
		}
	}

	cout << total << endl;
	
	int k = areas.size();

	cout << k;
	for ( int i = 0; i < k; ++i )
		cout << " " << areas[i][1];
	cout << endl;

	return 0;
}


Measured memory_bytes: 3220
#include <iostream>
using namespace std;
 
 
int main(){
  int N;
  cin >> N;
  
  
  if(N % 10 == 2){
    cout << "hon" << endl;
  }else if ( N % 10 == 4) {
    cout << "hon" << endl;
  } else if ( N % 10 == 5) {
    cout << "hon" << endl;
  } else if ( N % 10 == 7) {
    cout << "hon" << endl;
  } else if ( N % 10 == 9) {
    cout << "hon" << endl;
  } else if ( N % 10 == 1) {
    cout << "pon" << endl;
  }else if ( N % 10 == 0){
    cout << "pon" << endl;
  } else if ( N % 10 == 6) {
    cout << "pon" << endl;
  } else if ( N % 10 == 8) {
    cout << "pon" << endl;
  }else if ( N % 10 == 3) {
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3112
#!/usr/bin/env python
# coding: utf-8

# In[15]:


n = int(input())
a = list(map(int, input().split()))


# In[18]:


a.sort()
ai = max(a)
diff = ai
old = diff
for x in a[:-1]:
    tmp = abs(x-ai/2)
    if tmp <= diff:
        aj = x
        diff = tmp
    if diff == old:
        break
    else:
        old = diff
print(ai,aj)


# In[ ]:






Measured memory_bytes: 20044
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var ABC = lines[0].split(" ").map(i => Number(i));
    ABC.sort((a, b) => b - a)

    console.log(ABC[0] * 10 + ABC[1] + ABC[2])
});

Measured memory_bytes: 11596
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int a, b;
    int c;
    cin >> a >> b;
    c = a + b;

    if( c % 3 == 0 || a %3 == 0 || b % 3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    } 

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int pro=scan.nextInt();
    int sub=scan.nextInt();
    int pronum[]=new int[sub];
    String rate[]=new String[sub];
    int ACans=0, WAans=0;
    int WA[]=new int[pro];
    boolean flag[]=new boolean[pro];
    for(int x=0; x<pro; x++){
      flag[x]=true;
    }
    if(sub>0){
      for(int x=0; x<sub; x++){
        pronum[x]=scan.nextInt();
        rate[x]=scan.next();
        if(flag[pronum[x]-1]){
          if(rate[x].equals("AC")){
            flag[pronum[x]-1]=false;
            ACans++;
            WAans+=WA[pronum[x]-1];
          }else {
            WA[pronum[x]-1]++;
          }
        }
      }
    }
    System.out.println(ACans+" "+WAans);
  }
}

Measured memory_bytes: 71544
#![allow(unused_mut)]

use std::io::{self, BufWriter, Write};
use std::error::Error;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() -> Result<(), Box<dyn Error>> {
    let sout = io::stdout();
    let mut o = BufWriter::new(sout.lock());
  
    input! {
        // input
        a : i32,
        b : i32,
        c : i32,
        k : i32,
    }

    let mut b = b;
    let mut c = c;

    // operate
    for _ in 0 .. k + 1 {
        if b <= a {
            b *= 2;
        } else if c <= b {
            c *= 2;
        } else {
            o.write(b"Yes\n")?;
            return Ok(());
        }
    }

    // let line = format!("\n");
    o.write(b"No\n")?;
    Ok(())
  }


Measured memory_bytes: 2132
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

int64_t mod = 998244353 ;

vector<int> getprime(int n){
    vector<int> p(0) ;
    vector<bool> table(n+1,0) ;
    for (int i = 2; i <= n; i++)
    {
        if (table.at(i) == 0)
        {
            p.push_back(i) ;
            for (size_t j = 2; j < n/i ; j++)
            {
                table.at(i*j) = 1 ;
            }
            
        }
        
    }
    return p ;
}

int main(){
    int n ;
    cin >> n ;
    vector<vector<int> > list(n,vector<int>(0));
    int a,b ;
    vector<int> edge(n-1) ;
    for (int i = 0; i < n-1; i++)
    {
        cin >> a >> b ;
        edge.at(i) = b-1 ;
        list.at(a-1).push_back(b-1) ;
    }
    int ans = 0 ;
    vector<int> color(n) ;
    color.at(0) = 0 ;
    queue<int> wait ;
    int child,parent ;
    wait.push(0) ;
    while (!(wait.empty()))
    {
        parent = wait.front() ;
        wait.pop() ;
        int num = 1 ;
        for (int i = 0; i < list.at(parent).size(); i++)
        {
            child = list.at(parent).at(i) ;
            if (num == color.at(parent))
            {
                num ++ ;
            }
            color.at(child) = num ;
            ans = max (ans,num) ;
            wait.push(child) ;
            num ++ ;
        }
        
    }
    cout << ans << endl ;
    for (int i = 0; i < n-1; i++)
    {
        cout << color.at(edge.at(i)) << endl ;
    }
    
    
    
}

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

int main(){
    cin>>s;
    map<string, int> p;
    p["SUN"] = 7;
    p["MON"] = 6;
    p["TUE"] = 5;
    p["WED"] = 4;
    p["THU"] = 3;
    p["FRI"] = 2;
    p["SAT"] = 1;
    
    cout<<p[s]<<endl;
    
    
}

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

using namespace std;

#define int long long
#define sz(x) (int)x.size()
#define yes cout << "Yes\n"
#define  no cout << "No\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ft first
#define sd second
typedef pair<int, int> pii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<bool> vb;
mt19937_64 rnd(time(0));

void start() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(10);
    // cerr << fixed << setprecision(10);
#ifdef MY
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

signed main() {
    start();
    int n, m;
    cin >> n >> m;
    vector<vb> a(n, vb(m));
    vector<vi> d(n, vi(m));
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < m; ++j)
            a[i][j] = (s[j] == '#');
    }
    for (int i = 0; i < n; ++i) {
        if (a[i][0])
            break;
        d[i][0] = 1;
    }
    for (int i = 0; i < m; ++i) {
        if (a[0][i])
            break;
        d[0][i] = 1;
    }
    for (int i = 1; i < n; ++i) {
        for (int j = 1; j < m; ++j) {
            if (!a[i][j]) {
                if (!a[i - 1][j])
                    d[i][j] += d[i - 1][j];
                if (!a[i][j - 1])
                    d[i][j] += d[i][j - 1];
                d[i][j] %= (int)(1e9 + 7);
            }
        }
    }

    cout << d[n - 1][m - 1];


}


Measured memory_bytes: 11740
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, M; cin >> N >> M;
	if (M == 0) {
		cout << 0 << endl;
		return 0;
	}
	vector<double> L(N), a(N), b(N);
	for (int i = 0; i < N; i++)
		cin >> L[i] >> a[i] >> b[i];
	vector< vector<double> > d(N, vector<double>(N));
	for (int i = 0; i < N; i++)
		for (int j = i + 1; j < N; j++) {
			double dL = L[i] - L[j], da = a[i] - a[j], db = b[i] - b[j];
			d[i][j] = dL * dL + da * da + db * db;
		}
	double maxi = 0;
	for (int S = (1 << M) - 1; S < (1 << N);) {
		double sum = 0;
		for (int i = 0; i < N; i++)
			for (int j = i + 1; j < N; j++)
				if ((S & (1 << i)) && (S & (1 << j)))
					sum += d[i][j];
		maxi = max(maxi, sum);
		int x = S & -S, y = S + x;
		S = ((S & ~y) / x >> 1) | y;
	}
	printf("%.10f\n", maxi);
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool kisuu(ll num) {
	if (num % 2 == 1) return true;
	else return false;
}

int main() {
	ll n, w;
	cin >> n >> w;

	if (n == 1 or w == 1) {
		cout <<1;
	}
	else if (kisuu(n) and kisuu(w)) {
		cout << ((n-1)*w) / 2 + w / 2+1;
	}
	else if (kisuu(n)) {
		cout << ((n - 1)*w) / 2 + w / 2 ;
	}
	else {
		cout << (n*w) / 2;
	}
	return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  long long n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  long long g = __gcd(n, m);
  for (int i = 0, j = 0; i < n && j < m; i += n / g, j += m / g) {
    if (s[i] != t[j]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << n * m / g << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#define ll long long
using namespace std;
int main(){
    int n, arr[100005], modo=1e9+7;
    ll s=1;
    string a;
    cin >> n >> a;
    for(int i=0; i<a.size(); i++){
        arr[a[i]]++;
    }
    for(int i='a'; i<='z'; i++){
        if(arr[i]>0){
            s*=(arr[i]+1);
            s%=modo;
        }
    }
    s--;
    cout << s << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define max 10000000
// cout << "YES\n";
// cout << "NO\n";
int main()
{
    string t, s;
    cin >> s >> t;
    int m, res = 1e5, f = 0;
    for (int i = 0; i < (int)s.size(); i++)
    {
        m = 0;
        for (int j = 0; j < (int)t.size(); j++)
        {
            if (i + j >= (int)s.size())
            {
                f = 1;
                break;
            }
            if (t[j] != s[i + j])
            {
                m++;
            }
        }
        if (f == 1)
        {
            break;
        }
        res = min(res, m);
    }
    cout << res << endl;
    return 0;
}

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


answer=0
result=0

for i in 0..b.length-1
    key=b[i]
    ng1=-1
    ok1=n
    #min
    while (ok1-ng1).abs>1
        
        mid1=(ng1+ok1)/2
        if a[mid1]>=key
        ok1=mid1
        else
        ng1=mid1
            
        end
        
    end
    ab=ng1+1
    
    ng2=-1
    ok2=n
    #max
    while (ok2-ng2).abs>1
        
        mid2=(ng2+ok2)/2
        if c[mid2]>key
            ok2=mid2
        else
            ng2=mid2
            
        end
    end
    
    bc=ok2
    
    result+=(ab*(n-bc))
    
end

p result


Measured memory_bytes: 26552
#include<iostream>
#include<string>

using namespace std;

int main(){
    string s;
    int n;

    cin>>n;
    cin>>s;

    for(int i=0; i<s.size(); i++){
        if(s[i]+n>'Z'){
            cout<<char('A'+s[i]+n-'Z'-1);
        }else{
            cout<<char(s[i]+n);
        }
    }
    cout<<endl;

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

string convert(string s)
{
    while(s.size()<8) s="0"+s;

    string ret="";
    rep(i,s.size())
    {
        if(s[i]=='a') ret+="1010";
        else if(s[i]=='b') ret+="1011";
        else if(s[i]=='c') ret+="1100";
        else if(s[i]=='d') ret+="1101";
        else if(s[i]=='e') ret+="1110";
        else if(s[i]=='f') ret+="1111";
        else
        {
            int num=s[i]-'0';
            int a=8;
            rep(j,4)
            {
                if(num>=a)
                {
                    num-=a;
                    ret+="1";
                }
                else ret+="0";
                a/=2;
            }
        }
    }
    return ret;
}

int main()
{
    ll pw[32];
    pw[0]=1;
    for(int i=1; i<32; ++i) pw[i]=pw[i-1]*2;

    int T;
    cin >>T;
    while(T--)
    {
        vector<string> s(9);
        rep(i,9)
        {
            string tmp;
            cin >>tmp;
            s[i]=convert(tmp);
        }

        string key(32,'u');
        vector<int> carry(32,0);

        for(int i=31; i>=0; --i)
        {
            int a=0;
            rep(j,8) a+=s[j][i]-'0';

            int b=a+carry[i];

            if(b%2==s[8][i]-'0') key[i]='0';
            else
            {
                key[i]='1';
                b=8-a+carry[i];
            }

            if(b%2==1) --b;

            int idx=30;
            while(idx>0)
            {
                if(b>=pw[idx])
                {
                    b-=pw[idx];
                    if(i-idx>=0) ++carry[i-idx];
                }
                --idx;
            }
        }

        ll ans=0;
        rep(i,32)
        {
            if(key[i]=='1') ans+=pw[31-i];
        }
        printf("%llx\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
int main() {
    int s,w;cin >> s >> w;
    cout << (s>w?"safe":"unsafe") << endl;
    return 0;
}

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


int main(){
	int a[100000];
	int i,n,max=0,z1=0,z2=0;

	char mozi[100000];
	


	cin >> mozi;

	size_t size = string(mozi).length();
	n = size;
	

	for (i = 0; i < n; i++) {
		a[i]=(int(mozi[i]-48));
	
    }

	for (i = 0; i < n; i++) {
		if (i % 2 != a[i]) {
			z1++;

		}

		if ((i+1) % 2 != a[i]) {
			z2++;

		}
	}
	if (z1 < z2)cout << z1;
	else cout << z2;


	return 0;
	}



Measured memory_bytes: 896
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
x,y=map(int,input().split())
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
import numpy as np

def main():
    H, W = map(int, input().split())
    S = np.array([list(input()) for _ in range(H)]) == '.'

    L = np.zeros((H, W), dtype=int)
    R = np.zeros((H, W), dtype=int)
    U = np.zeros((H, W), dtype=int)
    D = np.zeros((H, W), dtype=int)

    for w in range(1, W):
        L[:, w] = (L[:, w-1] + 1) * S[:, w-1]
    for w in range(W-2, -1, -1):
        R[:, w] = (R[:, w+1] + 1) * S[:, w+1]
    for h in range(1, H):
        U[h, :] = (U[h-1, :] + 1) * S[h-1, :]
    for h in range(H-2, -1, -1):
        D[h, :] = (D[h+1, :] + 1) * S[h+1, :]

    print(((L+R+U+D)*S).max() + 1)

if __name__ == '__main__':
    main()


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

typedef unsigned long long ll;

struct query {
        int b, c;
};

const int maxn = 100001;
int n, m, a[maxn];
query q[maxn];

bool cmp(query x, query y) {
        return x.c > y.c;
}

void solve(ll sum) {
        ll res = sum;

        int j = 1;
        for (int i = 1; i <= m; i++) {
                ll s = 0, cnt = 0;
                while (j <= n && a[j] < q[i].c && cnt < q[i].b) {
                        s += a[j];
                        j++;
                        cnt++;
                }
                if (cnt > 0)
                        res = res - s + cnt*q[i].c;
        }
        cout << res << '\n';
}

int main() {
        //freopen("D.INP", "r", stdin);
        //freopen("D.OUT", "w", stdout);
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

        ll sum = 0;
        cin >> n >> m;
        for (int i = 1; i <= n; i++) {
                cin >> a[i];
                sum += a[i];
        }
        for (int i = 1; i <= m; i++)
                cin >> q[i].b >> q[i].c;

        sort(a+1, a+1+n);
        sort(q+1, q+1+m, &cmp);

        solve(sum);

        return 0;
}


Measured memory_bytes: 1408
#include <stdio.h> 
#define INF (1<<29)
 
typedef struct{
    int u;
    int k;
    int v[100];
    int c[100];
    int used;
    int cost;
} WGraph;
WGraph G[100];

void getSSSP(int n){
  int i,j;
  int minCost, pos, next_pos, next_cost;
   
  for(i = 0; i < n; i++){
    G[i].used = 0;
    G[i].cost = INF;
  }
  G[0].cost = 0;
 
  while(1){
    minCost = INF;
    for(i = 0; i < n; i++){
      if(G[i].used == 0 && minCost > G[i].cost){
    minCost = G[i].cost;
    pos = i;
      }
    }
    if(minCost == INF) break;
    G[pos].used = 1;
 

    for(i = 0; i < G[pos].k; i++){
      next_pos = G[pos].v[i];
      next_cost = G[pos].c[i] + minCost;
      if(G[next_pos].cost > next_cost) G[next_pos].cost = next_cost;
    }

  }
}

 
main(){
  int i,j,n;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d %d", &G[i].u, &G[i].k);
    for(j = 0; j < G[i].k; j++){
      scanf("%d %d", &G[i].v[j], &G[i].c[j]);
    }
  }
  getSSSP(n);
  for(i = 0; i < n; i++){
    printf("%d %d\n", G[i].u, G[i].cost);
  }
  return 0;
}

Measured memory_bytes: 680
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

int main ()
{
    vector < int > a = {1,4,7,9};
    vector < int > b(4);
    REP(i,4) cin >> b[i];
    sort(b.begin(), b.end());

    REP(i,4) {
        if (a[i] != b[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 764