akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vector<string> s(n);
    REP(i,n){
        cin>>s[i];

    }
    
    sort(s.begin(),s.end());

    int kmax = 0, k = 0;
    string mae = "";
    REP(i,n){
        if(mae == s[i]){
            k++;
            kmax = max(kmax,k);
        } else {
            k = 1;
            mae = s[i];
            kmax = max(kmax,k);
        }
    }

    //cout<<kmax<<endl;
    mae = ""; k=0;
    REP(i,n){
        if(mae == s[i]){
            k++;
        } else {
            k = 1;
            mae = s[i];
        }

        if(k==kmax){
            cout<<s[i]<<endl;
        }
    }

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

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

int main(){
    
    int N, M;
    cin >> N;
    int D[N];
    for(int &x:D) cin >> x;
    cin >> M;
    int T[M];
    for(int &x:T) cin >> x;
    
    if(N<M){
        cout << "NO" << endl;
        return 0;
    }
    
    sort(D, D+N);
    sort(T, T+M);
    
    bool ans = true;
    int j = 0;
    
    for(int i=0; i<M; ++i){
        
        while(true){
            
            if(T[i] == D[j]){ j++; break;}
            if(T[i] <  D[j]){
                cout << "NO" << endl;
                return 0;
            }
            j++;
            
        }
        
    }
    
    if(ans) cout << "YES" << endl;
    
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    string ans = "";
    
    for(int i = 0, j = 0; i < s1.size() && j < s2.size(); i++, j++) {
        ans += s1[i];
        ans += s2[j];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#include <climits>
#include <set>

//#define int long long
typedef long long ll;
//#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

#define MOD 1000000007

using namespace std;

typedef vector<int> V;
typedef vector<V> VV;

int N, M;
int a, b, c;

struct edge { ll from, to, cost; };
edge es[2010];
ll d[1010];

/*
bool find_negative_loop() {
    memset(d, 0, sizeof(d));

    ll pre = d[N];

    for (int i=0; i<N; i++) {
        for (int j=0; j<M; j++) {
            edge e = es[j];
            if (d[e.to] > d[e.from] + e.cost) {
                if (i == N - 1 && )

                d[e.to] = d[e.from] + e.cost;

                if (e.to == N)

                if (i == N - 1) return true;
            }
        }
    }
    return false;
}
*/

bool shortest_path(int s)
{
    REP(i,N+1) d[i] = LONG_LONG_MAX / 100;
    d[s] = 0;
    //while (true) {
    REP(i,N) {
        //bool update = false;
        REP(i,M) {
            edge e = es[i];
            if (d[e.from] != LONG_LONG_MAX / 100 && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                //update = true;
            }
        }
        //if (!update) break;
    }

    ll pre = d[N];
    REP(i,M) {
        edge e = es[i];
        if (d[e.from] != LONG_LONG_MAX / 100 && d[e.to] > d[e.from] + e.cost) {
            d[e.to] = d[e.from] + e.cost;
            //update = true;
        }
    }

    if (pre != d[N]) return true;
    else return false;
}

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> N >> M;
    REP(i,M) {
        cin >> a >> b >> c;
        es[i].from = a;
        es[i].to = b;
        es[i].cost = -c;
    }

    /*
    if (find_negative_loop()) {
        cout << "inf" << endl;
    } else {
        shortest_path(1);
        cout << -d[N] << endl;
    }
    */

    if (shortest_path(1)) {
        cout << "inf" << endl;
    } else {
        cout << -d[N] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
#define int ll
signed main() {
	int a, b, c, k; 
	cin >> a >> b >> c >> k;

	int sum = 0;
	if (k > 0) {
		sum += min(a, k);
		k -= min(a, k);
	}

	if (k > 0) {
		k -= min(b, k);
	}

	if (k > 0) {
		sum -= min(c, k);
		k -= min(c, k);
	}

	cout << sum << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int n; cin >> n;
  vector<double> worth(n);
  rep(i, n) cin >> worth[i];
  sort(all(worth));
  double nowworth = (worth[0] + worth[1]) / 2.0;
  rep(i, n - 2){
    nowworth = (nowworth + worth[i + 2]) / 2.0;
  }
  cout << nowworth << endl;
}

Measured memory_bytes: 256
'use strict'
function Main(input) {
  input = input.split('\n')[0].split('');
  const returnObj = input.reduce((a, e) => {
    if (a[e]) {
      ++a[e];
    } else {
      a[e] = 1;
    }
    return a;
  }, {});
  
  let result = 'Yes';
  for (let key in returnObj) {
    if (returnObj[key] % 2 !== 0) {
      result = 'No';
      break;
    }
  }
  console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const int INF = 100001;

vi a;

int main()
{
    int n;
    cin >> n;
    REP(i,n){
        int d;
        cin >> d;
        a.push_back(d);
    }
    sort(ALL(a));

    int ans=0;
    int anc=0;
    REP(i,n){
        if(anc < a[i]){
            ans++;
            anc = a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (int i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(int n, int k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(c-(a-b)<=0){
    cout<<0<<endl;
    return 0;
  }
  cout<<c-(a-b)<<endl;
}

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

template <typename T, typename K> struct P {
	T a;
	K b;
};

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	cout<<fixed<<setprecision(10);
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	int* vec = new int[N];
	ll ans = 0;
	rep( i, 0, K ){
		scanf("%d", vec+i);
		ans += vec[i];
	}
	ll temp = ans;
	rep( i, K, N ){
		scanf("%d", vec+i);
		temp += vec[i]-vec[i-K];
		ans = max( ans, temp);
	}
	printf("%.10lf\n", ( double )(ans + K ) / 2);
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll L, R, ans = 2020;

	cin >> L >> R;

	for (ll i = L; i <= min(L + 2018, R) - 1; i++) {
		for (ll j = i + 1; j <= min(L + 2018, R); j++) {
			ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  ll a=0,b=0;
  cin>>a>>b;
  cout<<a*b;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
using namespace std;
int data[101];
int mod[101];
void ini(void){
  for(int i=0;i<101;i++){
    data[i]=0;
    mod[i]=0;
  }
}



main(){
  int max=0;
  int j;
  j=0;
  int in;
  while(cin >> in){
    for(int i=0;i<101;i++){
      if(in == i){
	data[i]++;//inidata[i];
	break;
      }
    }
    j++;
  }

  //
  for(int i=0;i<101;i++){
    if(max < data[i])max=data[i];
  }

  //
  for(int i=0;i<101;i++){
    if(data[i]==max)cout << i << endl;
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main(){
  long int i, N;
  long int min = 2000000;
  long cnt = 0;
  
  cin >> N;
  
  long int* P = new long int[N];
  
  for(i = 0; i < N; i++){
    cin >> P[i];
  }
  
  for(i = 0; i < N; i++){
    if(P[i] < min){
      min = P[i];
      cnt++;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
	
		int N = keyboard.nextInt();
		int A = keyboard.nextInt();
		int B = keyboard.nextInt();
		
		
		if(N * A > B) {
			System.out.println(B);
		}else{
			System.out.println(N*A);
		}
		keyboard.close();	
	}
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,k;cin>>n>>m>>k;
  
  for(int i=0;i<=m;i++){
    for(int j=0;j<=n;j++){
    if(n*i+j*(m-2*i)==k){
      cout<<"Yes"<<endl;
      return 0;
    }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  k = int(input()) - 1
  li = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ')
  print(li[k])

if __name__=='__main__':
  main()



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

using namespace std;

typedef long long ll;

int main(){
	string s; cin >> s;
	ll res = 0;
	for(int i = 0; i < 1 << (s.length() - 1); i++){
		string t;
		for(int j = 0; j < s.length() - 1; j++){
			t += s[j];
			if((1 << j) & i) t += "+";
		}
		t += *s.rbegin();
		ll p = 0;
		for(int j = 0; j < t.length(); j++){
			if(t[j] == '+'){ res += p; p = 0; }
			else p = 10 * p + t[j] - '0';
		}
		res += p;
	}
	cout << res << endl;
	return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;

    int len = s.length();
    int i;
    for(i=0; i<len; i++){
        if(s.length()%2) {
            s.erase(--s.end());
            continue;
        }
        string tmp1, tmp2;
        for(int j=0; j<s.length()/2; j++){
            tmp1 += s[j];
            tmp2 += s[j+s.length()/2];   
            //cout << tmp1 << " " << tmp2 << endl;
        }
        if(tmp1 == tmp2 && i) break;
        s.erase(--s.end());
        //cout << s << " " << tmp1 << " "  << tmp2 << endl;
    }

    cout << s.length() << endl;

    return 0;
}


Measured memory_bytes: 256
//author:emre yazicioglu

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define fori(a,b,c) for(ll a = b;a < ll(c);a++)
#define ford(a,b,c) for(ll a = b;a >= ll(c);a--)
#define pb push_back

const int N = 2e6 + 7;
ll n,m,k,cnt,cur,ans;
ll dp[N],ar[N];

int main(){

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

	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);

	cin >> n >> k;
	fori(i,1,n + 1){
		cin >> ar[i];
		dp[i] = 1e18;
	}
	
	dp[1] = 0;	
	fori(i,1,n + 1)
		fori(j,i + 1,i + k + 1)
			dp[j] = min(dp[j], dp[i] + abs(ar[i] - ar[j]));

	cout << dp[n];

}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int 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 VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N;
VL A;

int main() {
    cin >> N;
    ll ans = 0, tmp = 0;
    REP(i, N) {
        CINT(a);
        tmp += a;
        if(a == 0 || i == N - 1) {
            ans += tmp / 2;
            tmp = 0;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

ll N;

int main(){
    cin >> N;
    ll m = 0;
    ll ans = 1e15;
    for(ll i=1;i*i <= N;i++){
        if(N % i != 0) continue;
        ll t = i + N/i - 2;
        ans = min(ans,t);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define LL long long
#define N 1200000

const LL mod=1000000007;
LL n,m,ans,a[N],fac[N],ifac[N],f[20][N];

bool cmp(LL x,LL y){return x>y;}

LL inv(LL x){return x==1?1:(mod-mod/x)*inv(mod%x)%mod;}

LL C(LL x,LL y){
	if (x<y) return 0;
	return fac[x]*ifac[y]%mod*ifac[x-y]%mod;
}

int main(){
	scanf("%lld%lld",&n,&m);
	for (LL i=1;i<=m;++i) scanf("%lld",&a[i]);
	sort(a+1,a+m+1,cmp);
	fac[0]=1; for (LL i=1;i<=1<<n;++i) fac[i]=fac[i-1]*i%mod;
	ifac[1<<n]=inv(fac[1<<n]); for (LL i=(1<<n)-1;i>=0;--i) ifac[i]=ifac[i+1]*(i+1)%mod;
	f[0][0]=1;
	for (LL i=1;i<=m;++i)
		for (LL j=0;j<1<<n;++j){
			f[i][j]=f[i-1][j];
			LL tmp=(1<<n)-a[i]+1;
			for (LL k=0;k<n;++k)
				if (j>>k&1) tmp-=1<<k;
			for (LL k=0;k<n;++k)
				if (j>>k&1) f[i][j]=(f[i][j]+f[i-1][j^(1<<k)]*C(tmp+(1<<k)-1,(1<<k)-1)%mod*fac[1<<k])%mod;
		}
	for (LL i=0;i<1<<n;++i){
		LL tmp=0,sum=(1<<n)-1;
		for (LL j=0;j<n;++j){
			tmp+=i>>j&1; sum-=(i>>j&1)*(1<<j);
		}
		f[m][i]=f[m][i]*fac[sum]%mod;
		ans=(ans+(tmp&1?mod-f[m][i]:f[m][i]))%mod;
	}
	printf("%lld\n",(ans<<n)%mod);
	
	return 0;
}
			

Measured memory_bytes: 45312
//   PIGMEISTER™   //

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define PI (ld)3.141592653589793238
#define MAX 100005

int main()
{
    jaldi;
    
    ll x, n;
    cin >> x >> n;
    if (n == 0) {
        cout << x;
        return 0;
    }
    ll p, a[105] = {0};
    sidha (i, 0, n) cin >> p, a[p] = 1;
 
    sidha (i, 0, 100) {
        if (a[x-i] == 0) {
            cout << x-i;
            return 0;
        }
        if (a[x+i] == 0) {
            cout << x+i;
            return 0;
        }
    }

    return 0;
}


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

#define INF 100100100
#define MOD 1000000007

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

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

   ll N,M;
   cin>>N>>M;
   vector<vector<pair<int,int>> > si(N+1);
   ll MAX = -1;
   for(ll i=0;i<M;i++){
      ll P;
      ll Y;
      cin>>P>>Y;
      si[P].push_back(make_pair(Y,i));
   }
   vector<pair<ll,ll> > ans(M);
   for(int i=1;i<N+1;i++)sort(si[i].begin(),si[i].end());
   for(int i=1;i<N+1;i++){
      for(int j=0;j<si[i].size();j++){
         ans[si[i][j].second] = make_pair(i,j+1);
      }
   }
   for(int i=0;i<ans.size();i++)cout<<setfill('0')<<right<<setw(6)<<ans[i].first<<right<<setw(6)<<ans[i].second<<endl;
   return 0;
}


Measured memory_bytes: 8576
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[2][100];
int main() {
	ll n; cin >> n;

	rep(i, 0, n) cin >> a[0][i];
	rep(i, 0, n) cin >> a[1][i];

	ll maxV = 0;
	rep(k, 0, n) {
		ll sum = 0;
		repe(i, 0, k) sum += a[0][i];
		repe(j, k, n - 1) sum += a[1][j];

		maxV = max(sum, maxV);
	}
	cout << maxV << endl;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/tenka1-2018/tasks/tenka1_2018_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (auto &x : A) {
        cin >> x;
    }
    sort(ALL(A));
    int idxS = 0, idxE = N - 1;
    bool flag = false;
    // ソートした後に真ん中で２分割して、小さいグループと大きいグループに対して差分を取る。
    // ただし、端に寄せた2つの値同士は差分を取らないので、中央値付近の2つの値を端に寄せる。
    // Nが奇数なら、中央値との差分が小さいものを端へ寄せる。{1,[2],[3],5,6}
    // Nが偶数なら、中央値付近の2つの値は確定する。{1,[2],[3],5}
    if (N % 2 == 1) {
        if (abs(A[N / 2] - A[N / 2 + 1]) < abs(A[N / 2] - A[N / 2 - 1])) {
            B[0] = A[N / 2];
            B[N - 1] = A[N / 2 + 1];
        } else {
            B[0] = A[N / 2];
            B[N - 1] = A[N / 2 - 1];
            flag = true;
        }
    } else {
        B[0] = A[N / 2];
        B[N - 1] = A[N / 2 - 1];
    }
    FOR(i, 1, N - 1) {
        if (i % 2 != flag) {
            B[i] = A[idxS++];
        } else {
            B[i] = A[idxE--];
        }
    }
    int sum = 0;
    REP(i, N - 1) { sum += abs(B[i] - B[i + 1]); }
    cout << sum << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 4760
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>

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

using namespace std;

int main(void)
{

    int n, m;
    int h[1000000];
    int r[1000000];
    int res = 0;
    
    cin >> n >> m;
    
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    
    int a, b;
    
    for(int i = 0; i < m; i++)
    {
        cin >> a >> b;
        if(h[a-1] > h[b-1])
        {
            r[b-1]++;
        }
        if(h[a-1] < h[b-1])
        {
            r[a-1]++;
        }
        if(h[a-1] == h[b-1])
        {
            r[a-1]++;
            r[b-1]++;
        }
    }
    
    for(int i = 0; i < n; i++)
    {
        if(r[i] == 0) res++;
    }
    
    cout << res;
    
}

Measured memory_bytes: 4416
<?php
$input = trim(fgets(STDIN));

List($a, $b) = explode(" ", $input);

$a = (int)$a;
$b = (int)$b;

if ($a < $b) {
  $s = "<";
} else if ($a > $b) {
  $s = ">";
} else {
  $s = "==";
}

echo "a {$s} b".PHP_EOL;

Measured memory_bytes: 15256
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入


int main(){
    int N;
    cin>>N;
    string S_ori;
    cin>>S_ori;
    int ans=0;
    REP(l,N){
        string S=S_ori.substr(l,S_ori.size());
        //Z-Algorithm
        vector<int> A(S.size(),0);
        A[0] = S.size();
        int i = 1, j = 0;
        while (i < S.size()) {
        while (i+j < S.size() && S[j] == S[i+j]) ++j;
        A[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
        i += k; j -= k;
        }
        REP(i,S.size()){
            if(i>=A[i]) ans=max(ans,A[i]);
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod-2)%mod;}
void comp() {
		ll i,j,k,n,m;
		cin>>n;
		vector<ll>v1;
		map<ll,ll>m1;
		ll sum=0;
		fl(i,n) {
			cin>>j;
			v1.pb(j);
			sum+=j;
			m1[j]++;
		}
		cin>>k;
		fl(i,k) {
			cin>>j>>m;
			sum-=j*m1[j];
			sum+=m*m1[j];
			m1[m]+=m1[j];
			m1[j]=0;
			cout<<sum<<"\n";
		}

}

int main() {
    speedup;
    ll i=0,t;
    t=1;
   // cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    Graph g(n);
    REP(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        add_edge(g, --a, --b, 1, true, 1);
    }

    Array d(n, 0);
    auto dfs = [&](auto &&self, int v, int p) -> void {
        for(auto e : g[v]) {
            if(e.to == p)
                continue;
            d[e.to] = d[v] + 1;
            self(self, e.to, v);
        }
    };

    auto check = [&](int v) -> P {
        d[v] = 0;
        dfs(dfs, v, -1);
        ll ma = 0;
        ll ma_i = 0;
        REP(i, n) {
            if(chmax(ma, d[i]))
                ma_i = i;
        }
        return {ma, ma_i};
    };

    auto leaf = check(0).second;
    auto ma_l = check(leaf).second;
    ll ans = check(ma_l).first + 1;

    if(ans % 3 == 2)
        cout << "Second" << en;
    else
        cout << "First" << en;
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 40508
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
long long f(long long a, long long c)
{
	if (a < 0) return 0;
	return a / c + 1;
}
int main()
{
	long long a, b, x, an;
	scanf("%lld%lld%lld", &a, &b, &x);
	//printf("%d %d\n", f(b, x), f(-1, x));
	an = f(b, x) - f(a - 1, x);
	printf("%lld", an);
	return 0;
}


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

int main() {
	int x[200];
	int i, cos1 = 0, cos2 = 0;
	for (i = 0; i < 101; i++)	x[i] = 0;

	int X, N, M, gate;
	cin >> N >> M >> X;
	for (i = 0; i < M; i++) {
		cin >> gate;
		x[gate] = 1;
	}

	for (i = 0; i <= X; i++)	cos1 += x[i];
	for (i = X; i <= N; i++)	cos2 += x[i];

	if (cos1 < cos2)	cout << cos1;
	else cout << cos2;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  
 if (N == "SUN") {
   cout << 7 << endl;
 }
  else if (N == "MON") {
   cout << 6 << endl;
}
  else if (N == "TUE") {
   cout << 5 << endl;
}
  else if (N == "WED") {
   cout << 4 << endl;
}
  else if (N == "THU") {
   cout << 3 << endl;
}
  else if (N == "FRI") {
   cout << 2 << endl;
}
  else if (N == "SAT") {
   cout << 1 << endl;
}
}

Measured memory_bytes: 256
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

ll n,k;
ll perm[5005];
ll cost[5005];
ll ans=-1e18;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k;
	
	rep(x,1,n+1) cin>>perm[x];
	rep(x,1,n+1){
		cin>>cost[x];
		ans=max(ans,cost[x]);
	}
	
	rep(x,1,n+1){
		ll best=-1e18;
		ll best2=-1e18;
		ll curr=0;
		
		int pos=x;
		int ss=0;
		
		do{
			//cerr<<pos<<endl;
			pos=perm[pos];
			ss++;
		} while (pos!=x);
		
		rep(y,0,ss){
			curr+=cost[pos];
			pos=perm[pos];
			
			if (y<k%ss) best=max(best,curr);
			best2=max(best2,curr);
		}
		
		//cout<<curr<<" "<<best<<" "<<best2<<endl;
		if (curr<0 && best<0) continue;
		ans=max(ans,max(curr,0LL)*(k/ss)+max(best,0LL));
		if (k/ss>=1) ans=max(ans,max(curr,0LL)*(k/ss-1)+best2);
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9+101;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(ll i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}
int N, K;
vector <int> v, rv;
int memo[52][52][52];
int solve(int depth, int r_depth, int cnt) {
    
    if(cnt == K || depth == N || r_depth == N || depth + r_depth == N) {
        return 0;
    }
    if(cnt > K){
        return -INF;
    }
    if(memo[depth][r_depth][cnt] != -INF){
        return memo[depth][r_depth][cnt];
    }
    int ret = -INF;
    ret = solve(depth, r_depth, K);
    if(v[depth] < 0) {
        ret = max(ret,max(solve(depth+1, r_depth, cnt+2), solve(depth+1, r_depth, cnt+1) + v[depth]));
        if(cnt+2<=K)ret = max(ret, solve(depth+1, r_depth, K));
    }
    else{
        ret = max(ret, solve(depth+1, r_depth, cnt+1) + v[depth]);
        ret = max(ret, solve(depth+1, r_depth, K) + v[depth]);
    }
    if(rv[r_depth] < 0) {
        ret = max(ret, max(solve(depth, r_depth+1, cnt+2), solve(depth, r_depth+1, cnt+1) + rv[r_depth]));
        if(cnt+2<=K)ret = max(ret, solve(depth, r_depth+1, K));
    } else{
        ret = max(ret, solve(depth, r_depth+1, cnt+1) + rv[r_depth]);
        ret = max(ret, solve(depth, r_depth+1, K) + rv[r_depth]);
    }
    return memo[depth][r_depth][cnt] = ret;
}

int main() {
    for(int i = 0; i < 52; ++i){
        for(int j = 0; j < 52; ++j) {
            for(int k = 0; k < 52; ++k){
                memo[i][j][k] = -INF;
            }
        }
    }
    cin >> N >> K;
    rep(i,N){ 
        int a;
        cin >> a;
        v.pb(a);
    }
    rep(i,N){
        rv.pb(v[N-i-1]);
    }
    int ans = solve(0, 0, 0);
    cout << ans << endl;
    return 0;
}

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

int n, ans;
double a;
double h[1010],tem[1010];
double t;

int main()
{
	cin >> n >> t >> a;
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	ans = 1;
	for (int i = 2; i <=n; i++) {
		if (abs(t - h[i]*0.006 - a) < abs(t - h[ans]*0.006 - a)) {
			ans = i;
		}
	}

	cout << ans << endl;
	system("pause");
    return 0;
}



Measured memory_bytes: 504
def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(M):
        a, b = map(int, input().split())
        l.append((a,b))
    l.sort(key=lambda x: x[1])
    r = 0
    p = 0
    for i, j in l:
        if p <= i:
            p = j
            r += 1 
    print(r)
main()


Measured memory_bytes: 18224
use std::io::Read;
use std::collections::VecDeque;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut graph: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..m {
        let a: usize = iterator.next().unwrap().parse().unwrap();
        let b: usize = iterator.next().unwrap().parse().unwrap();
        graph[a - 1].push(b - 1);
        graph[b - 1].push(a - 1);
    }

    const INF: usize = std::usize::MAX;

    let mut visited: Vec<bool> = vec![false; n];
    let mut from: Vec<usize> = vec![INF; n];
    visited[0] = true;

    let mut q: VecDeque<usize> = VecDeque::new();
    q.push_back(0);
    while !q.is_empty() {
        let u: usize = q.pop_front().unwrap();
        for &v in graph[u].iter() {
            if !visited[v] {
                visited[v] = true;
                from[v] = u;
                q.push_back(v);
            }
        }
    }

    let mut result = String::from("Yes\n");
    for i in 1..n {
        result.push_str(&format!("{}\n", from[i] + 1));
    }
    return result.trim().to_string();
}


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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++ i)
#define Rep(i, a, b) for (int i = (a), i##end = (b); i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; -- i)

typedef long long LL;

template <class T>
IL bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}

template <class T>
IL bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}

template <class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template <class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template <class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-8, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
#define SZ(x) ((int)(x).size())

const int MAXN = 1000 + 5;

bool col[MAXN][MAXN][2];
int num[2][2];

IL void solve(int n, int p, bool t) {
  int b = 0;
  for (; p % 4 == 0; p >>= 2, ++ b);
  if (p & 1) {
    FOR(i, 0, n) {
      FOR(j, 0, n) {
        col[i][j][t] = ((i >> b) + (j >> b)) & 1;
      }
    }
  } else {
    FOR(i, 0, n) {
      FOR(j, 0, n) {
        col[i][j][t] = (i >> b) & 1;
      }
    }
  }
}

int main() {
  int n, d1, d2;
  scanf("%d%d%d", &n, &d1, &d2);
  solve(n * 2, d1, 0);
  solve(n * 2, d2, 1);
  FOR(i, 0, n * 2) {
    FOR(j, 0, n * 2) {
      ++ num[col[i][j][0]][col[i][j][1]];
    }
  }
  int cur = 0;
  std::pair<bool, bool> f;
  FOR(i, 0, 2) {
    FOR(j, 0, 2) {
      if (chkmax(cur, num[i][j])) {
        f = {i, j};
      }
    }
  }
  int p = 0;
  FOR(i, 0, n * 2) {
    FOR(j, 0, n * 2) {
      if (col[i][j][0] == f.first && col[i][j][1] == f.second) {
        ++ p;
        printf("%d %d\n", i, j);
      }
      if (p == n * n) {
        goto END;
      }
    }
  }
  END: ;
  return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main{
    public static void main(String[] args ){
        Scanner scanner = new Scanner(System.in);
        int H = scanner.nextInt();
        int W = scanner.nextInt();
        while(H != 0 || W != 0){
            for(int i = 1; i <= H; i++){
                for(int j = 1; j <= W; j++){
                    System.out.print("#");
                }
                System.out.print("\n");
            }
            System.out.print("\n");
            H = scanner.nextInt();
            W = scanner.nextInt();
        }
    }
}



Measured memory_bytes: 37740
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<bitset>

using namespace std;

bitset<10000> g[10];

int main()
{
    int r, c;
    while(true)
    {
        int ans = 0;
        cin>>r>>c;
        if(r==0 && c==0) break;
        for(int i = 0; i < r; ++i)
            for(int j = 0; j < c; ++j)
            {
                bool t;
                cin >> t;
                g[i][j] = t;
            }
        for(int i = 0; i < 1<<r; ++i)
        {
            int sum = 0;
            for(int j = 0; j < r; ++j)
                if(i & (1<<j))
                    g[j].flip();
            for(int j = 0; j < c; ++j)
            {
                int p = 0;
                for(int k = 0; k < r; ++k)
                    if(g[k][j])
                        p++;
                sum += max(p, r - p);
            }
            ans = max(ans, sum);
            for(int j = 0; j < r; ++j)
                if(i & (1<<j))
                    g[j].flip();
        }
        cout << ans << endl;        
    }
}


Measured memory_bytes: 3056
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <set>

using namespace std;

const int inf = 1e9;
vector<vector<int>> min_distance;

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);

	int n, m, r;
	cin >> n >> m >> r;
	min_distance.resize(n);
	for (int i = 0; i < n; ++i) {
		min_distance[i].resize(n, inf);
	}

	vector<int> rs(r);

	for (int i = 0; i < r; ++i) {
		cin >> rs[i];
		--rs[i];
	}

	for (int i = 0; i < m; ++i) {
		int l, r, c;
		cin >> l >> r >> c; 
		--l; --r;
		min_distance[l][r] = c;
		min_distance[r][l] = c;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < n; ++k) {
				min_distance[j][k] = min(min_distance[j][k], min_distance[j][i] + min_distance[i][k]);
			}
		}
	}

	long long min_ans = 0;
	for (int i = 1; i < r; ++i) {
		min_ans += min_distance[rs[i]][rs[i - 1]];
	}

	vector<int> cur_r = rs;
	next_permutation(cur_r.begin(), cur_r.end());
	while (cur_r != rs) {
		long long cur_ans = 0;
		for (int i = 1; i < r; ++i) {
			cur_ans += min_distance[cur_r[i]][cur_r[i - 1]];
		}

		min_ans = min(min_ans, cur_ans);
		next_permutation(cur_r.begin(), cur_r.end());
	}

	cout << min_ans << endl;

	return 0;
}

Measured memory_bytes: 384
/***from dust i have come, dust i will be***/

#include<bits/stdc++.h>

typedef long long int ll;
typedef unsigned long long int ull;

#define dbg printf("in\n")
#define nl printf("\n");
#define N 310
#define inf 1e9

#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define sfl(n) scanf("%I64d", &n)
#define sffl(n,m) scanf("%I64d%I64d",&n,&m)

#define pf(n) printf("%d",n)
#define pff(n,m) printf("%d %d",n,m)
#define pffl(n,m) printf("%I64d %I64d",n,m)
#define pfl(n) printf("%I64d",n)
#define pfs(s) printf("%s",s)

#define pb push_back
#define pp pair<int, int>

using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);

    int i, j, k;
    int n, m, t;
    string s;

    cin >> s;

    i = 0, j = s.length() - 1;
    int cnt = 0;

    while(i < j)
    {
        if(s[i] != s[j])
            cnt++;

        i++, j--;
    }

    pf(cnt);

    return 0;
}


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

int main()
{
    long long n;
    cin >> n;
    long long sum = n * (n + 1) / 2;
    for (long long i = 3; i <= n; i += 3){
        sum -= i;
    }
    for (long long i = 5; i <= n; i += 5){
        if (i % 3) sum -= i;
    }
    cout << sum;
    return 0;
}


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

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

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

	int g = 0;
	for (int i = 0;i < n;++i) {
		int u;
		scanf("%d", &u);

		g = gcd(u, g);
	}

	printf("%d", g);

	return 0;
}

Measured memory_bytes: 256
n,c,k=map(int,input().split())
t=[]
for _ in range(n):
  t.append(int(input()))
t.sort()
renow=0
cun=0
for i in range(n):
  if t[i]-t[renow]>k:
    cun+=1
    renow=i
  if i-renow+1>=c:
    cun+=1
    renow=i+1
if renow>=n:
  print(cun)
else:
  print(cun+1)
  


Measured memory_bytes: 13248
#include<bits/stdc++.h>
using namespace std;
char x[10001];
int main()
{
	int a=0;
	gets(x);
	for(int i=0;x[i];i++)
	{
		if(x[i]=='C')
		a=1;
		if(x[i]=='F'&&a==1)
		a=2;
		if(a==2)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import Data.List

func [x] = []
func (x:y:ys) = (y-x):(func (y:ys))    

main :: IO ()
main = do
    [n, m] <- map read . words <$> getLine :: IO [Int]
    x <- map read . words <$> getLine :: IO [Int]
    let s = (maximum x) - (minimum x)
    print $  s - (sum $ drop (m-n) (sort $ func $ sort x))

Measured memory_bytes: 30204
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cstdint>
#include <cmath>
using namespace std;

template <typename Func>
void permutation(int i, int n, int* a, bool* used, Func&& func) {
    if (i == n) {
        func();
        return;
    }
    for (int j = 0; j < n; ++j) {
        if (used[j]) continue;
        a[i] = j + 1;
        used[j] = true;
        permutation(i + 1, n, a, used, std::forward<Func>(func));
        used[j] = false;
    }
}

void solve() {
	int n;
	std::cin >> n;
	std::vector<int> p(n), q(n), a(n);
	bool used[8];
	std::fill_n(used, 8, false);
	for (int i = 0; i < n; ++i) std::cin >> p[i];
	for (int i = 0; i < n; ++i) std::cin >> q[i];
	for (int i = 0; i < n; ++i) a[i] = i + 1;
	int pc = 0, qc = 0, cnt = 0;
	permutation(0, n, a.data(), used, [&] {
		++cnt;
		if (p == a) pc = cnt;
		if (q == a) qc = cnt;
		if (pc && qc) {
			std::cout << std::abs(pc - qc) << std::endl;
			exit(0);
		}
	});
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256