akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 2000000

int size, A[MAX];


void maxHeapify(int);
int extract();
void increaseKey(int,int);
void insert(int);



int main(){
  
  int key;
  char com[20];

  while(1){

    scanf("%s", com);

    if ( com[0] == 'i' ){
      scanf("%d", &key);
      insert(key);
    }
    else if ( strcmp(com, "extract") == 0  ){
      printf("%d\n", extract());
    }
    else break;
  }
  
  return 0;
}



void maxHeapify(int i){
  int l, r;
  int largest;
  int t;
  
  l = 2 * i;
  r = 2 * i + 1;

  if ( l <= size && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= size && A[r] > A[largest] ) largest = r;
  if ( largest != i ){
    
    t = A[i];
    A[i] = A[largest];
    A[largest] = t;
    
    maxHeapify(largest);
  }
}

int extract(){
  
  int maxv;
  
  if ( size < 1 ) return;

  maxv = A[1];
  A[1] = A[size--];
  maxHeapify(1);
  
  return maxv;
}

void increaseKey(int i, int key){
  
  int tmp;
  
  if ( key < A[i] ) return;
  
  A[i] = key;
  
  while ( i > 1 && A[i/2] < A[i] ){
    
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
    
  }
}

void insert(int key){
  
  size++;
  A[size] = -1000000001;
  increaseKey(size, key);
  
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    ll n,m;
    cin >> n >> m;
    ll tmp_n=n;
    ll tmp_m=m;
    if(abs(n-m)>=2) cout << 0 <<endl;
    else{
        ll ans=1;
        while(n>0){
            ans=ans*n%mod;
            n--;
        }
        while(m>0){
            ans=ans*m%mod;
            m--;
        }
        if(tmp_n==tmp_m) cout << 2*ans%mod <<endl;
        else cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int can[51];

int game(int n,int p){
	int x=p;
	while(1){
		for(int i=0;i<n;i++){
			if(p==0){
				p=can[i];
				can[i]=0;
			}else{
				p--;
				can[i]++;
			}
			if(x==can[i])return i;
		}
	}
}


int main(){
	int p,n;
	while(1){
		cin >>n>>p;
		if(n==0&&p==0)break;
		for(int i=0;i<n;i++){
			can[i]=0;
		}
		int ans = game(n,p);
		cout <<ans <<endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N, A, B, x, y;
  cin >> N >> A >> B;
  
  x = N / (A+B);
  y = N% (A+B);
  
  if (y >=A) {
    cout << (x+ 1)* A << endl;
  }
    
  else {
    cout << x* A + y << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {
    int n;
    cin >> n;
    vector<ll> A(n);
    vector<ll> B(n);
    REP(i, 0, n) {
        cin >> A[i] >> B[i];
    }
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        ans += (B[i] - (A[i] + ans) % B[i]) % B[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys

n, m, x = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))
a = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))

cost1 = 0
cost2 = 0

for p in a:
    if p < x:
        cost1 += 1
    else:
        cost2 += 1
print(str(min(cost1, cost2)))


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

int main(void){
	string num;
	
	while(true){
		cin >> num;
		
		if(num[0] =='0') break;
		int sum = 0;
		
		for( int i=0; i < num.size(); i++ ){
			sum += num[i] - '0';
		}
		
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
import sys
input = sys.stdin.readline

n,m,l = map(int,input().split())

# ワーシャルフロイド
def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# m行の入力から距離を値に持つ隣接行列を作成 0-indexed
# directed:無向グラフならFalse、有向グラフならTrue
def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d

d = make_d_matrix(n,m)
d = warshall_floyd(d,n)

inf = 10**3
for i in range(n):
    for j in range(n):
        d[i][j] = 1 if (d[i][j] <= l) else inf

d = warshall_floyd(d,n)

q = int(input())

for _ in range(q):
    s,t = map(int, input().split())
    tmp = d[s-1][t-1]
    if(tmp >= inf):
        print(-1)
    else:
        print(tmp-1)

Measured memory_bytes: 55388
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > X(N);
	rep(i, N) cin >> X[i];
	int ans = LINF;
	rep(P, 110) {
		int tmp = 0;
		rep(i, N) {
			tmp += (X[i] - P) * (X[i] - P);
		}
		chmin(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  multiset<int> P;
  rep(i,N){
    int p;
    cin >> p;
    P.insert(p);
  }
  int T=0;
  rep(i,K){
    if(!P.empty()){
      T += *P.begin();
      P.erase(P.begin());
    }
  }
  cout << T << endl;
}

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {

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

		for(int i=1;i<=n;i++) {
			x =i;
			if(CHECK_NUM(x)) continue;
			if(INCLUDE3(x,i)) continue;
		}
		System.out.println();
		scan.close();
	}

	static boolean CHECK_NUM(int n) {
		if(n%3 == 0) {
			System.out.print(" "+n);
			return true;
		}
		return false;
	}

	/*static boolean INCLUDE3(int n) {
		if(n%10 == 3) {
			System.out.print(" "+n);
			return true;
		}
		return false;
	}*/
	static boolean INCLUDE3(int n,int i) {
		if(n%10 == 3) {
			System.out.print(" "+i);
			return true;
		}
		n/=10;
		if(n!=0) INCLUDE3(n,i);
		return false;
	}
}


Measured memory_bytes: 33256
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        int n,r,ans;
        Scanner reader = new Scanner(System.in);
        n=reader.nextInt();
        r=reader.nextInt();
        if(n>=10){
            ans=r;
        }
        else{
            ans=100*(10-n)+r;
        }
        System.out.println(ans);
    }
}

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

int main(){
  string S;
  cin>>S;
  int count=0;
  int max_lg=0;
  
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T'){
      count++;
       max_lg=max(max_lg,count);
    }
    else{
      max_lg=max(max_lg,count);
      count=0;
    }
  }
  cout<<max_lg<<endl;
}


Measured memory_bytes: 256
import math

n, m =map(int,input().split())
if n <= 1:
  if m <= 1:
    ans = 0
  else:
    ans = math.factorial(m)//(math.factorial(m-2)* math.factorial(2)) 
elif m <= 1:
  ans = math.factorial(n)//(math.factorial(n-2) * math.factorial(2))
else:
  ans = math.factorial(n)//(math.factorial(n-2) * math.factorial(2)) +math.factorial(m)//(math.factorial(m-2)* math.factorial(2)) 
print(ans)


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

int main()
{
  int n;
  cin >> n;
  vector<int> rains;
  for (int i=0;i<n;i++) {
    int t;
    cin >> t;
    rains.push_back(t);
  }
  vector<int> before;
  int b = 0;
  before.push_back(0);
  for (int i=0;i<n;i++) {
    b += rains[i] * ((i%2==0)?1:-1);
    before.push_back(b);
  }
  vector<int> after;
  int a = 0;
  for (int i=n-1;i>=0;i--) {
    a = -a + rains[i];
    after.push_back(a);
  }

  for (int i=0;i<n;i++) {
    if (i!=0) cout << " ";
    cout << ((i%2==0)?-1:1)*before[i] + after[n-i-1];
  }
  cout << endl;
}




Measured memory_bytes: 2552
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;


int main() {

	
	int a, b;
	cin >> a >> b;
	a *= a;
	cout << a - b << endl;
	return 0;
	
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

class unionFind{
private:
    vector<uint> par; //parent
public:
    unionFind(const uint size) :par(size) { for(uint i=0; i<par.size(); ++i){ par[i]=i; } }
    ~unionFind(){}
    
    uint root(const uint rhs){ // returning the root index.
        if(rhs == par[rhs]){ return rhs;
        }       else       { return par[rhs]=root(par[rhs]); }
    }
    
    bool unite(const uint lhs, const uint rhs){
        uint rL = root(lhs);
        uint rR = root(rhs);
        if(par[rL]==par[rR]){ return false; }

        par[rL] = rR;
        return true;
    }
    
    bool same(const uint lhs, const uint rhs){
        return root(lhs)==root(rhs);
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, M; cin >> N >> M;
    vector<int> vP(N); for(int i=0; i<N; ++i){ cin >> vP[i]; --vP[i]; }
    
    class unionFind uf(N);
    for(int i=0; i<M; ++i){
        int x, y; cin >> x >> y; --x; --y;
        uf.unite(x, y);
    }

    int cnt=0;
    for(int i=0; i<N; ++i){
        if(uf.same(i, vP[i])){ ++cnt; }
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 1024
use proconio::input;
use std::cmp;

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }

    let ans = *[a * c, a * d, b * c, b * d].iter().max().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 2128
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





















int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	REP(i, n) {
		cin >> a[i];
		if (i >= k) {
			cout << ((a[i - k] < a[i]) ? "Yes" : "No") << endl;
		}
	}
}

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

using namespace std;

const int nmax = 5005;

int pre[nmax][nmax], suf[nmax][nmax];
int n, k;
int a[nmax];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  pre[0][0] = 1;
  suf[n + 1][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      pre[i][j] = pre[i - 1][j];
      if (j >= a[i])
        pre[i][j] |= pre[i - 1][j - a[i]];
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j <= k; j++) {
      suf[i][j] = suf[i + 1][j];
      if (j >= a[i])
        suf[i][j] |= suf[i + 1][j - a[i]];
    }
  }

  auto has = [&](int x, int l, int r) {
    if (l <= 0) return suf[x][r] >= 1;
    return suf[x][r] - suf[x][l - 1] >= 1;
  };

  int ans = n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      suf[i + 1][j] += suf[i + 1][j - 1];
    }

    if (a[i] > k) {
      ans--;
      continue;
    }

    for (int j = 0; j < k; j++) {
      int left = k - a[i] - j;
      int right = k - j - 1;

      if (pre[i - 1][j] && has(i + 1, left, right)) {
        --ans;
        break;
      }
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 195840
import sys
from random import randint
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


def count_v(last_d, C, S, t, d):
    ret = S[t - 1]
    last_d[t - 1] = d
    for i in range(len(last_d)):
        ret -= C[i] * (d - last_d[i])
    return ret


def count_v_virtual(last_d, C, S, t, d):
    ret = S[t]
    tmp = last_d[t]
    last_d[t] = d
    for i in range(len(last_d)):
        ret -= C[i] * (d - last_d[i])
    last_d[t] = tmp
    return ret


def get_diff_score(T, d, q, C, D, Ss):
    diff = 0
    original_t = T[d - 1]
    last_d_q = 0
    last_d_ori = 0
    for i in range(d):
        if T[i] == q:
            last_d_q = i + 1
        if T[i] == original_t and i < d - 1:
            last_d_ori = i + 1
    # print(d, q, original_t, last_d_q, last_d_ori)
    for i in range(d - 1, D):
        if T[i] == q:
            break
        diff += C[q - 1] * (d - last_d_q)
    # print(diff, C[q - 1])
    T[d - 1] = q
    for i in range(d - 1, D):
        if T[i] == original_t:
            break
        diff -= C[original_t - 1] * (d - last_d_ori)
    # print(C[original_t - 1], diff)
    diff += Ss[d - 1][q - 1] - Ss[d - 1][original_t - 1]
    return diff


def main():
    D = int(input())
    C = inpl()
    Ss = [inpl() for _ in range(D)]
    T = []
    last_d = [-1] * len(C)
    Contest = 26

    v = 0
    for d in range(D):
        tmp_t, tmp_v = -1, -float('inf')
        for i in range(Contest):
            tmp_score = count_v_virtual(last_d, C, Ss[d], i, d)
            if tmp_score > tmp_v:
                tmp_v = tmp_score
                tmp_t = i
        last_d[tmp_t] = d
        v += tmp_v
        T.append(tmp_t + 1)

    Cs = [i + 1 for i, c in enumerate(C)]
    Cs.sort(key=lambda x: C[x - 1])
    c_set = set(Cs[:int(0.1 * len(Cs))])
    c_set_m = Cs[int(0.9 * len(Cs)):]

    for _ in range(30000):
        tmp = [i for i, t in enumerate(T) if t in c_set]
        if len(tmp) < 2:
            break
        i = randint(0, len(tmp) - 1)
        d = randint(0, len(c_set_m) - 1)
        d, q = T[i], c_set_m[d]
        ori_q = T[d - 1]
        diff = get_diff_score(T, d, q, C, D, Ss)
        if diff < -(0.01 * v):
            T[d - 1] = ori_q
        else:
            v += diff

    for _ in range(5000):
        d, q = randint(1, D), randint(1, Contest)
        ori_q = T[d - 1]
        diff = get_diff_score(T, d, q, C, D, Ss)
        if diff < -(0.01 * v):
            T[d - 1] = ori_q
        else:
            v += diff

    for t in T:
        print(t)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 85156
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;

	string ans = "No";
	REP(i, 100) {
		REP(j, 100) {
			if (N == i * 4 + j * 7) {
				ans = "Yes";
				break;
			}
		}
	}

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



Measured memory_bytes: 256
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  CIN(n,k);
  ll ans = 0;
  V v;
  V v2;
  FOR(i,1,n+1){
    if(i%k == 0)
      v2.pb(i);
    if(i%k == 1.0 * k / 2){
      v.pb(i);
    }
  }
  ll hog = v.size();
  hog *= v.size();
  hog *= v.size();
  ans += hog;
  hog = v2.size();
  hog *= v2.size();
  hog *= v2.size();
  COUT(ans + hog);

}

Measured memory_bytes: 2420
N = int(input())
A = list(map(int,input().split()))

ans = 0
while any([a>N-1 for a in A]):
    for i in range(N):
        if A[i] <= N-1: continue
        d = A[i] - (N-1)
        k = -(-d//N)
        A[i] -= k*N
        ans += k
        for j in range(N):
            if j==i: continue
            A[j] += k
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
char s[1000001];
char t;
int	ans;
int a[1000001];
bool check(int x)
{
	int n=strlen(s+1),kum=0;
	for(int i=1;i<=n;i++) a[i]=(s[i]-'0')*9;
	a[1]+=9*x;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>9)
		{
			if(i==n) a[++n]=0;
			a[i+1]+=a[i]/10;
			a[i]%=10;
		}
	}
	for(int i=1;i<=n;i++) kum+=a[i];
	return kum<=x*9;
}
int main()
{
	scanf("%s",s+1); 
	int l=1,r=strlen(s+1);
	reverse(s+1,s+r+1);
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid)==1)
			ans=mid,r=mid-1;
		else
			l=mid+1;
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 4608
import itertools
n = int(input())
R = [i for i in range(1,n+1)]
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

i = 1
for r in itertools.permutations(R,n):
    if r == P:
        p = i
    if r == Q:
        q = i
    i += 1

print(abs(p-q))


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

int n,c,crs[14],ans[52];

bool dfs(int s, int t)
{
	if(s==0) return true;

	for(int i=13; i>=1; i--)
	{
		if(crs[i])
		if((s-i)%i == 0)
		{
			crs[i]--;
			ans[t]=i;
			if(dfs(s-i,t+1))
			{
				return true;
			}
			crs[i]++;
		}
	}
	return false;
}

int main()
{
	while(cin >> n, n)
	{
		int s=0;
		memset(crs,0,sizeof(crs));
		memset(ans,0,sizeof(ans));
		for(int i=0; i<n; i++)
		{
			cin >> c;
			s+=c; crs[c]++;
		}

		if(dfs(s,0))
		{
			for(int i=n-1; i>=0; i--)
			{
				cout << ans[i] << (i==0 ? "\n":" ");
			}
		}
		else
		{
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 868
N, M = list(map(int, input().split()))

def solution():
    answer = 1
    for i in range(1, int(M**0.5)+1):
        if M%i ==0:
            if M//i>=N:
                answer = max(answer , i)
            if i>=N:
                answer = max(answer, M//i)
    return answer

print(solution())

Measured memory_bytes: 3060
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	ans := 3 * n * n

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(void){

  int n;
  while( cin >> n ){
    if( n == 0 )return 0;
    int ans = 0;
    while( n >= 5 ){
      n /= 5;
      ans += n;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#define N 1000000
using namespace std;

int main(){
	int n,k;
	scanf(" %d %d", &n , &k);
	int *a = new int[N];
	for(int i=0;i<n;i++){
		scanf(" %d", &a[i]);
	}
	
	int low=0,high=1e9,mid;
	for(int _=0;_<100;_++){
		if(high-low <= 1) break;
		mid = (low+high)/2;
		int count=0, bef=0;
		bool f = true;
		while(1){
			if(bef == n) break;
			if(count >= k){
				f = false;
				break;
			}
			int bag = mid;
			int p;
			for(p=bef;p<n;p++){
				if(bag >= a[p]) bag-=a[p];
				else break;
			}
			bef = p;
			count++;
		}
		if(f) high = mid;
		else low = mid;
	}
	
	printf("%d\n", high);	
	delete [] a;
	return 0;
}

Measured memory_bytes: 3052
N,A,B = map(int,input().split())
x = 0
count = 0
s = ""
for i in range(1,N+1):
    s = str(i)
    for j in range(len(str(i))):
        x += int(s[j])
    if x >= A and x <= B:
        count += i
    x = 0
print(count)

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string t;
  for (char &c : s) {
    if (c == '0' || c == '1') t.push_back(c);
    else {
      if (t.size() == 0) continue;
      t.pop_back();
    }
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
ant = [int(input()) for _ in range(5)]

minidx = 0
minval = 124
i = 0
for a in ant:
    while 10 < a:
        a %= 10
        if a == 0:
            a = 10
    if a < minval:
        minidx = i
        minval = a
    i += 1

ans = 0
for i in range(5):
    if i == minidx:
        continue
    fact = 10
    while fact - ant[i] < 0:
        fact += 10
    ans += fact

ans += ant[minidx]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string S; cin >> S;
  string S1,S2;
  int N = S.size();
  bool flag1 = true;
  bool flag2 = true;
  REP(i,(N-1)/2){
    if(S[i] != S[(N-2)/2 - i]) 
      flag1 = false;
  }
  FOR(i,(N+2)/2,N){
  	if(S[i] != S[N-1-i])
      flag2 =false;
  }
  if(flag1 && flag2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;

namespace XDYIMCMI0LY {

  const int N = 100 + 5;

  
  int n;
  int m;

  short dp[N][N][N][N];
  short sumh[N][N];
  short suml[N][N];

  inline void ckmax(short &a, short b) {
    if (a < b) {
      a = b;
    }
  }

  inline short getsumh(int h, int l, int r) {
    if (r < l) {
      return 0xcfcf;
    }
    return sumh[h][r] - sumh[h][l - 1];
  }
  inline short getsuml(int h, int l, int r) {
    if (r < l) {
      return 0xcfcf;
    }
    return suml[h][r] - suml[h][l - 1];
  }

  void solve() {
    int posx = 0;
    int posy = 0;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        char t;
        cin >> t;
        if (t == 'E') {
          posx = i;
          posy = j;
        } else {
          int val = t == 'o';
          sumh[i][j] = sumh[i][j - 1] + val;
          suml[j][i] = suml[j][i - 1] + val;
        }
      }
    }
    short ans = 0;
    memset(dp, 0xcfcf, sizeof(dp));
    dp[0][0][0][0] = 0;
    for (int u = 0; u <= posx; ++u) {
      for (int d = 0; d < n - posx; ++d) {
        for (int l = 0; l <= posy; ++l) {
          for (int r = 0; r < m - posy; ++r) {
            if (dp[u][d][l][r] == 0xcfcf) {
              continue;
            }
              
            ans = max(ans, dp[u][d][l][r]);
            // cerr << u << " " << d << " " << l << " " << r << " " << dp[u][d][l][r] << endl;
            if (r - 1 < posy - l - 1) {
              ckmax(dp[u][d][l + 1][r], dp[u][d][l][r] + getsuml(posy - l - 1, max(posx - u, d), min(posx + d, n - u - 1)));
            }
            if (posy + r + 1 < m - l) {
              ckmax(dp[u][d][l][r + 1], dp[u][d][l][r] + getsuml(posy + r + 1, max(posx - u, d), min(posx + d, n - u - 1)));
            }
            if (posx - u - 1 > d - 1) {
              ckmax(dp[u + 1][d][l][r], dp[u][d][l][r] + getsumh(posx - u - 1, max(posy - l, r), min(posy + r, m - l - 1)));
            }
            if (posx + d + 1 < n - u) {
              ckmax(dp[u][d + 1][l][r], dp[u][d][l][r] + getsumh(posx + d + 1, max(posy - l, r), min(posy + r, m - l - 1)));
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}

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


Measured memory_bytes: 237824
use std::io::{stdin, stdout, BufReader, BufRead, StdinLock, Write, BufWriter};

fn main() {
    let (std_in, std_out) = (stdin(), stdout());
    let mut br = BufReader::new(std_in.lock());
    let mut bw = BufWriter::new(std_out.lock());
    
    let s = rs(&mut br);
    let n = s.len();
    let mut res = vec![0; n];

    let mut r = 0;
    for i in 0..n {
        if s[i] == 'R' {
            r += 1;
        } else {
            res[i] += r / 2;
            res [i-1] += (r + 1) / 2;
            r = 0;
        }
    }
    let mut l = 0;
    for i in (0..n).rev() {
        if s[i] == 'L' {
            l += 1;
        } else {
            res[i] += l / 2;
            res [i+1] += (l + 1) / 2;
            l = 0;
        }
    }
    for x in res {
        write!(&mut bw, "{} ", x);
    }
}


//////////////////////////////////////////////////////////////////////////////////
#[allow(dead_code)]
fn rs(br: &mut BufReader<StdinLock>) -> Vec<char> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().chars().collect()
}

#[allow(dead_code)]
fn rn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> T {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn rvs(br: &mut BufReader<StdinLock>) -> Vec<Vec<char>> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.chars().collect()).collect()
}

#[allow(dead_code)]
fn rvn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> Vec<T> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4476
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define debug(a,b) cerr << #a<<" = "<<a<<"       |      "<<#b<<" = "<<b<<'\n'
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const int MX = 1e5+7;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int x,n;cin>>x>>n;
    if(n==0){
		cout<<x<<endl;
		return 0;
	}
    vi32 a(n);
    for(int &X:a)cin>>X;
    sort(all(a));
    if(x==a[0]){
		cout<<a[0]-1<<endl;
		return 0;
	}
	if(x<a[0] || x>a[n-1]){
		cout<<x<<endl;
		return 0;
	}
	vi32 b;
	for(int it:a)b.pb(it);
	b.pb(-100);
	b.pb(105);
	sort(all(b));
	int lb=lower_bound(b.begin(),b.end(),x)-b.begin();
	int mn1=1e9;
	int n1=-1;
	//cerr(lb);
	for(int i=lb;i>0;i--){
		if(b[i]-b[i-1]>1){
			mn1=abs(x-(b[i]-1));
			n1=b[i]-1;
			break;
		}
	}
	int mn2=1e9;
	int n2=-1;
	for(int i=lb;i+1<SZ(b);i++){
		if(b[i+1]-b[i]>1){
			mn2=abs(x-(b[i]+1));
			n2=b[i]+1;
			break;
		}
	}
	//debug(mn1,mn2);
	//debug(n1,n2)<<endl;
	if(mn1<=mn2)cout<<n1<<endl;
	else cout<<n2<<endl;
	return 0;
}


Measured memory_bytes: 3620
n, m = map(int, input().split())  # x = 1, y = 2
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

# print(n, m, h, ab)

bitl = 2 ** n - 1

for a, b in ab:
    a -= 1
    b -= 1
    if h[a] == h[b]:
        bitl &= ~(1 << a)
        bitl &= ~(1 << b)
        continue
    if h[a] < h[b]:
        bitl &= ~(1 << a)
    else:
        bitl &= ~(1 << b)

print(bin(bitl).count("1"))


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

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

int main() { 
    int N, X, T;
    cin >> N >> X >> T;
    if (N % X != 0) {
        cout << T * ((N/X)+1) << endl;
    } else {
        cout << T * (N/X) << endl;
    }

    return 0;
}


Measured memory_bytes: 3592
#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 "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll n, m;
vector<pair<ll, ll>> j;
set<ll> s;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    F0R(i, n)
    {
        ll x, y;
        cin >> x >> y;
        j.pb({y, x});
    }
    sort(j.begin(), j.end(), greater<pair<ll, ll>>());
    // for(auto i : j) cout << i.f << " " << i.s << "\n";
    F0R(i, m) s.insert(i + 1);
    ll res = 0;
    F0R(i, n)
    {
        pair<ll, ll> cur = j[i];
        auto itx = s.lower_bound(cur.s);
        if(itx == s.end()) continue;
        else 
        {
            s.erase(itx);
            res += cur.f;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
const int mx = 1005;
const int inf = 3000;
char a[mx][mx];
int n, m, up[mx][mx], ans = 0;

int main(void){
    
    cin>>n>>m;
    for(int i=1; i<=n; i++) scanf("%s", a[i]+1);
    for(int i=0; i<1003; i++) up[0][i] = up[i][0] = up[n+1][i] = up[i][m+1] = inf;
    for(int i=1; i<=n; i++) for(int j = 1; j <= m; j++)
        up[i][j] = a[i][j] == '#' ? 0 : min(up[i-1][j], up[i][j-1]) + 1;
    for(int i=n; i>0; i--) for(int j = m; j > 0; j--)
        up[i][j] = min(up[i][j], min(up[i+1][j], up[i][j+1]) + 1);
    for(int i=1; i<=n; i++) for(int j = 1; j <= m; j++) ans = max(ans, up[i][j]);
    cout<< ans <<endl;
    
}

Measured memory_bytes: 5120
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
int w,h;
int xs,ys;
int xg,yg;
int n;
int map[101][101];
bool ch;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void dfs(int x,int y,int c){
	if(x==xg && y==yg)ch=true;
	else if(ch==false){
		map[x][y]=-1;
		for(int i=0;i<4;i++){
			int cx=x+dx[i],cy=y+dy[i];
			if(cx>=1 && cx<=w && cy>=1 && cy<=h  && map[cx][cy]==c)dfs(cx,cy,c);
		}
	}
}

int main(void){
	while(1){
		ch=false;
		memset(map,0,sizeof(map));
		cin >> w >> h;
		if(w==0 && h==0)break;
		cin >> xs >> ys;
		cin >> xg >> yg;
		cin >> n;
		for(int i=0;i<n;i++){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			if(d==0){
				for(int i=y;i<y+2;i++){
					for(int j=x;j<x+4;j++){
						map[j][i]=c;
					}
				}
			}
			if(d==1){
				for(int i=y;i<y+4;i++){
					for(int j=x;j<x+2;j++){
						map[j][i]=c;
					}
				}
			}
		}
		if(map[xs][ys]>=1)dfs(xs,ys,map[xs][ys]);
		if(ch)cout << "OK" << endl;
		else cout << "NG" << endl;
	}
    return 0;
}

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

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

struct Data {
  int num;
  Data() : num(0) {}
  Data(int n) : num(n) {}
};

inline Data Merge(Data left, Data right) {
  return Data(left.num + right.num);
}

struct SegmentTree {
  static const int STsize = 1 << 18;
  Data data[STsize]; int n;
  SegmentTree(void) : n(STsize / 2) {}
  void update (int pos, Data value) {
    data[pos] = Merge(data[pos], value);
    while (pos < 2*n-1) {
      int l = pos, r = pos^1;
      pos = pos / 2 + n;
      data[pos] = Merge(data[l], data[r]);
    }
  }
  Data sub(int fr, int to, int node, int la, int ra) {
    if (ra<=fr || to<=la) return Data();
    if (fr<=la && ra<=to) return data[node];
    Data vl = sub(fr, to, (node-n)*2+0, la, (la+ra)/2);
    Data vr = sub(fr, to, (node-n)*2+1, (la+ra)/2, ra);
    return Merge(vl, vr);
  }
  Data query(int fr, int to) { return sub(fr, to, 2*n-2, 0, n); }
};

int main() {
  SegmentTree sgt;
  int n,q;
  cin >> n >> q;
  REP(i,n) {
    sgt.update(i, 0);
  }
  REP(i,q) {
    int c, x, y;
    cin >> c >> x >> y;
    if(c == 0) {
      sgt.update(x, y);
    } else {
      cout << sgt.query(x, y+1).num << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2188
#include <bits/stdc++.h>
using namespace std;
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;
LL N,M;
vector<pair<LL,LL>> key;
LL ans = 0;
void solve(){
	vector<LL> dp(((LL)1)<<N,INF);
	dp[0] = 0;
	for(int bit=0;bit<(1<<N);bit++){
		for(int i=0;i<M;i++){
			int next = bit | ((int)key[i].first);
			dp[next] = min(dp[next],dp[bit]+key[i].second);
		}
	}
	ans = ((dp[(1<<N)-1]==INF)? -1:dp[(1<<N)-1]);
}
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		LL a,b;
		cin >> a >> b;
		LL correspond_treasure = 0;
		for(int k=0;k<b;k++){
			LL key_type;
			cin >> key_type;
			correspond_treasure |= (((LL)1)<<(key_type-1));
		}
		key.emplace_back(correspond_treasure,a);
	}
	solve();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let mut v = Vec::new();
    for _ in 0..5 {
        let tmp = get!(i32);
        v.push(tmp);
    }
    let k = get!(i32);
    if k < (v[v.len() - 1] - v[0]) {
        println!(":(");
    } else {
        println!("Yay!");
    }
}


Measured memory_bytes: 4352
from itertools import permutations

def main():
    n = int(input())
    p = tuple([int(x) for x in input().split()])
    q = tuple([int(x) for x in input().split()])
    L = sorted(list(permutations(list(range(1, n+1)), n)))
    for idx, l in enumerate(L):
        if l == p:
            a = idx
        if l == q:
            b = idx
    ans = abs(a - b)
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 14120
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
 
int A[1000000],n;
 
int main(){
    cin >> n;
    for(int i = 0;i < n;i++)
        scanf("%d",&A[i]);
         
    int q,k,sum = 0;
    cin >> q;
    for(int i = 0;i < q;i++){
        scanf("%d",&k);
        if(*lower_bound(A,A+n,k) == k)
            sum++;
    }
     
    cout << sum << endl;
     
    return 0;
}




Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()
#define elif else if


int low(V<int> a,int b){
  decltype(a)::iterator c=lower_bound(a.begin(),a.end(),b);
  int d=c-a.bgn;
  return d;
}
int upp(V<int> a,int b){
  decltype(a)::iterator c=upper_bound(a.begin(),a.end(),b);
  int d=c-a.bgn;
  return d;
}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int INF=1000000007;
int kaijou(int a){
  int b=1;
  fo(i,a)
    b*=i+1;
  return b;
}

V<P<int,int>> factorize(int n){
  V<P<int,int>> res;
  for(int i=2; i*i<=n; i++){
    if(n%i)
      continue;
    res.emplace_back(i,0);
    while(n%i==0){
      n/=i;
      res.back().second++;
    }
  }
  if(n!=1)
    res.emplace_back(n,1);
  return res;
}

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

signed main(){
  int r;
  cin>>r;
  cout<<3*r*r<<endl;
}

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

const int N = 100054, M = N * 2;

int V, E, Es = 0, R;
int to[M], first[N], next[M], deg[N];
bool used[N];

inline void addedge(int u, int v) {
	to[++Es] = v, next[Es] = first[u], first[u] = Es, ++deg[u];
	to[++Es] = u, next[Es] = first[v], first[v] = Es, ++deg[v];
}

inline bool dfs(int x, int px = 0) {
	int i, y; used[x] = true;
	for (i = first[x]; i; i = next[i]) if ((y = to[i]) != px) {
		if (!used[y] && dfs(y, x)) return true;
		if (y == R) return true;
	}
	return false;
}

int main() {
	int i, u, v, D, cnt;
	scanf("%d%d", &V, &E);
	for (i = 0; i < E; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	for (i = 1; i <= V; ++i) if (deg[i] & 1) return puts("No"), 0;
	D = *std::max_element(deg + 1, deg + (V + 1));
	cnt = std::count(deg + 1, deg + (V + 1), D);
	if (D > 4 || (D == 4 && cnt > 2)) return puts("Yes"), 0;
	if (D < 4 || (D == 4 && cnt < 2)) return puts("No"), 0;
	u = std::find(deg + 1, deg + (V + 1), D) - deg;
	v = std::find(deg + (u + 1), deg + (V + 1), D) - deg;
	used[v] = true, R = u;
	puts(dfs(u) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> pairs(N);
    REP(i, N){
        int a;
        cin >> a;
        pairs.at(i) = make_pair(a, i + 1);
    }
    sort(ALL(pairs));
    REP(i, N) {
        cout <<  pairs.at(i).second << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i,n) for (int 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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int H,W; cin >> H >> W;
    int A,B; cin >> A >> B;
    REP(i,H) {
        REP(j,W) {
            if(i+1 <= B) {
                if(j+1 <= A) cout << '0';
                else cout << '1';
            } else {
                if(j+1 <= A) cout << '1';
                else cout << '0';
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 3624