akhauriyash/Code-Regression huggingface dataset:
#include<cassert>
#include<iostream>
#include<string>

using namespace std;

struct node {
  struct node *prev;
  struct node *next;
  int value;
};

struct node *insert(struct node *front, int v)
{
  node *newfront = new node;
  newfront->prev = nullptr;
  newfront->next = front;
  if (front)
    front->prev = newfront;
  newfront->value = v;
  return newfront;
}

// insert at front, delete first, delete last, delete first element w/ value
int main()
{
  ios_base::sync_with_stdio(false); 

  struct node *first = nullptr;
  struct node *last = nullptr;
  
  int ncmd; cin >> ncmd;
  int n;
  for (int c = 0; c < ncmd; ++c) {
    string cmd;
    cin >> cmd;
    if (cmd=="delete") {
      cin >> n;
      if(!first) continue;
      // cases for first match at beginning,
      // intermediate node, end
      if (first->value == n) {
        goto delFirst;
      } else {  // more than one node
        auto curr = first;
        while (curr != last and curr->value != n) curr = curr->next;
        // two cases: matched, or got to the last node
        assert(curr);
        if (curr == last and curr->value != n) {
          continue;  // no match
        } else if (curr == last) {  // match at last
          goto delLast;
        } else { // match at intermediate, curr->next is not null
          assert(curr != last and curr != first);
          curr->next->prev = curr->prev;
          curr->prev->next = curr->next;
          delete curr;
        }
      }
    } else if (cmd=="insert") {  // easiest: same behavior in all cases
      cin >> n;
      bool need_set_last = false;
      if (!first)
        need_set_last = true;
      first = insert(first, n);
      if (need_set_last)
        last = first;
    } else if (cmd=="deleteFirst") {
delFirst:
      if (first) {
        auto tmp = first;
        if (first->next)
          first->next->prev = nullptr;
        else  // first=last
          last=nullptr; 
        first = first->next;
        delete tmp;
      }
    } else if (cmd=="deleteLast") {
delLast:
      if (last) {
        auto tmp = last;
        if (last->prev)
          last->prev->next = nullptr;
        else // first=last
          first=nullptr;
        last = last->prev;
        delete tmp;
      }
    }
  }

  struct node* curr = first;
  if(curr != nullptr) { cout << first->value; curr = first->next; }
  while(curr != nullptr) {
    cout << " " << curr->value;
    curr = curr->next;
  }
  cout << endl;
}


Measured memory_bytes: 34384
import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    //int n = sc.nextInt();
    int[] intArray = Arrays.stream(sc.nextLine().split(" "))
                           .mapToInt(Integer::parseInt)
                           .toArray();

    Arrays.sort(intArray);
    System.out.println(intArray[0]+" "+intArray[1]+" "+intArray[2]);
  }
}


Measured memory_bytes: 32000
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<vector<int>> calc_next(const string &s) {
    int n = s.size();
    vector<vector<int>> nxt(n + 1, vector<int>(2, n));
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < 2; j++) nxt[i][j] = nxt[i + 1][j];
        nxt[i][s[i] - '0'] = i;
    }
    return nxt;
}

using pii = pair<int, int>;
int main() {
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    auto nxt_s = calc_next(s), nxt_t = calc_next(t);
    vector<vector<int>> dp(n + 2, vector<int>(m + 2, INF));
    using T = pair<char, pii>;
    vector<vector<T>> recon(n + 2, vector<T>(m + 2, {'?', pii(n, m)}));
    dp[n + 1][m + 1] = 0;
    for (int i = n + 1; i >= 0; i--) for (int j = m + 1; j >= 0; j--) {
        if (i == n + 1 && j == m + 1) continue;
        for (int k = 0; k < 2; k++) {
            int ni = nxt_s[min(n, i)][k] + 1;
            int nj = nxt_t[min(m, j)][k] + 1;
            if (chmin(dp[i][j], dp[ni][nj] + 1)) {
                recon[i][j] = {'0' + k, pii(ni, nj)};
            }
        }
    }
    string res = "";
    int idx = 0, jdx = 0;
    while (dp[0][0]--) {
        auto p = recon[idx][jdx];
        res += p.first;
        idx = p.second.first;
        jdx = p.second.second;
    }
    cout << res << endl;
}


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

long long Dp(int n,int h[] , bool vis[] , long long dp[]){
    if(vis[n]){
        return dp[n];
    }else{
        int x,y;
        x = y = __INT_MAX__;
        if(n - 1 >=0){
            x = Dp(n-1,h,vis,dp) + abs(h[n] - h[n-1]);
        }if(n-2 >= 0){
            y = Dp(n-2,h,vis,dp) + abs(h[n] - h[n-2]);
        }

        vis[n] = true;
        dp[n] = min(x,y);

        cout << endl;
        return dp[n];
    }
}

void init(int n,bool vis[]){
    for(int i = 0 ; i < n ; i++){
        if(i == 0){
            vis[i] = true;
        }else{
            vis[i] = false;
        }
    }
}

int main(){

    int n;
    cin >> n;
    int h[n];
    bool vis[n];
    long long dp[n];
    dp[0] = 0;
    init(n,vis);
    for(int i = 0 ; i < n ; i++){
        cin >> h[i];
    }

    long long ans = Dp(n-1,h,vis,dp);
    // for(int i = 0 ; i < n ; i++){
    //     cout << dp[i] << " ";
    // }
    cout << ans;
    return 0;
}

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

int main(void){
  char a,b;
  cin>>a>>b;
  if(a=='H'){
    if(b=='H')cout<<'H'<<endl;
    else cout<<'D'<<endl;
  }else{
    if(b=='H')cout<<'D'<<endl;
    else cout<<'H'<<endl;
  }




  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int main(){

	int W,H,N;
	scanf("%d %d %d",&W,&H,&N);

	int max_y[W];
	for(int i = 0; i < W; i++)max_y[i] = 0;

	int x,y;
	for(int i = 0; i < N; i++){
		scanf("%d %d",&x,&y);
		max_y[x] = max(max_y[x],y);
	}

	int ans = W-1;
	int to_right_max_y = 0;
	for(int i = W-2; i >= 0; i--){
		to_right_max_y = max(to_right_max_y,max_y[i+1]);
		ans = min(ans,i+to_right_max_y);
	}

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

	return 0;
}

Measured memory_bytes: 3132
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false



int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include<string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
using namespace std;
int a[110];
int main()
{
     int num=0;
     int sum;
     int x;
     int n,k;
	 cin>>n>>k;
     for(int i=1;i<=k;i++)
     {
     	cin>>sum;
     	for(int j=1;j<=sum;j++)
     	{
     		cin>>x;
     		a[x]++;
		 }
	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(!a[i]) num++;
	 }
	 cout<<num;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

int main() {

    int N, K;
    cin >> N >>K ;

    vector<int> vec(N);
    for (int i = 0; i < N;i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());

    long sum = 0;
    for (int i = 0; i < K;i++) {
        sum = sum+ vec.at(i);
    }
    cout << sum << endl;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

ll pow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1) res = (res * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return res;
}


int main()
{
	int N;
	cin >> N;
	vector<int> A((N + 1) / 2);
	for (int i = 0, Ai; i < N; i++) {
		cin >> Ai;
		if (Ai % 2 != N % 2 && Ai >= 0 && Ai <= N - 1) A[Ai / 2]++;
	}
	bool flag = true;
	for (int i = 0; i < (N + 1) / 2; i++) {
		if (A[i] != 2) {
			if (N % 2 && i == 0 && A[i] == 1) continue;
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << pow(2ll, (ll)N / 2ll) << endl;
	}
	else cout << 0 << endl;
	return 0;
}


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

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

  vector<ll> x(n), y(n);
  rep(i,n){
    cin >> x.at(i) >> y.at(i);
  }

  int ans = 0;

  rep(i,n){
    double di = sqrt(x.at(i)*x.at(i) + y.at(i)*y.at(i));
    if (di <= d) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int h = n/3600;
		int min = n%3600/60;
		int s = n%3600%60;
		
		System.out.println(h+":"+min+":"+s);
	}
}



Measured memory_bytes: 26348
n, m = map(int, input().split())
ac = [False] * n
wa = [0] * n
for _ in range(m):
  prob, s = input().split()
  p = int(prob) - 1
  if not ac[p]:
    if s == 'AC':
      ac[p] = True
    else:
      wa[p] += 1
penalty = 0
for i in range(n):
  if ac[i]:
    penalty += wa[i]
print(sum(ac), penalty)

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

struct UnionFind{
  vector<int> par;
  UnionFind(int N) : par(N){
    for(int i = 0; i < N; i++){
      par[i] = i;
    }
  }
  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y){
    int rx = root(x), ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
};

int main(){
  int N, M; cin >> N >> M;
  vector<int> p(N);
  for(int i = 0; i < N; i++){
    cin >> p[i]; --p[i];
  }
  UnionFind tree(N);
  for(int i = 0; i < M; i++){
    int x, y; cin >> x >> y;
    --x; --y;
    tree.unite(x, y);
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(tree.same(i, p[i])){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K, R, S ,P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    vector<int> A(N+1, 0);
    map<char, int> m;
    m['r'] = P;
    m['s'] = R;
    m['p'] = S;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        A[i] = 0;
        if(i < K) {
            ans += m[T[i]];
            A[i] = 1;
        }
        if(i >= K && i < 2*K) {
            if(T[i]!=T[i-K]) {
                ans+=m[T[i]];
                A[i] = 1;
            }
        }
        if(i >= 2*K) {
            if(T[i]!=T[i-K]) {
                ans+=m[T[i]];
                A[i] = 1;
            }
            if(T[i]==T[i-K] && A[i-K]==0) {
                ans+=m[T[i]];
                A[i] = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

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

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
using str = string;

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

long int M = 1e+9+7;
int inf = 1e+9;

int n,k;
int solve(){
    int ans=0;
    int x;
    rep(i,n){
        cin >> x;
        ans += 2*min(x,k-x);
    }
    return ans;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    while(cin >> n >> k){
        int ans = 0;
        cout << solve() << endl;
        //cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
typedef pair<ll,pair<ll,ll>> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int N;
vector<ll> A(200010);

void solve(){
    int s = 0, t = 0;
    vector<bool> x(30, 0);
    ll res = 0;
    for(;;){
        while(t < N){
            ll dt = A[t];
            vector<bool> dx(30, 0);
            bool can = 1;
            for(int i = 0; i < 30; i++){
                if(dt % 2){
                    dx.at(i) = 1;
                }
                dt /= 2;
                if(x[i] && dx[i]) can = 0;
            }
            
            if(can){
                for(int i = 0; i < 30; i++){
                    if(dx[i]){
                        x[i] = 1;
                    }
                }
                t++;
            }else{
                break;
            }
        }
        res += t - s;
        ll ds = A[s];
        for(int i = 0; i < 30; i++){
            if(ds % 2){
                x[i] = 0;
            }
            ds /= 2;
        }
        s++;
        if(s == N)break;
    }
    cout << res << endl;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    solve();
}


Measured memory_bytes: 1792
n=int(input());a=list(map(int,input().split()));a.sort()
if n%2==1:b=[0]+[(i+1)*2for i in range((n-1)//2)]*2
else:b=[1+i*2for i in range(n//2)]*2
b.sort()
if a!=b:print(0);exit()
else:print((2**(n//2))%(10**9+7))

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using D = long double;
using P = complex<long double>;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const D INF = 1e18;
const D EPS = 1e-10;
const int MOD = 1e9 + 7;

D dot( P p1, P p2 ){
    return p1.real() * p2.real() + p1.imag() * p2.imag();
}

D cross( P p1, P p2 ){
    return p1.real() * p2.imag() - p1.imag() * p2.real();
}

D solve( P p1, P p2, P x ){
    if( dot( p2 - p1, x - p1 ) < EPS ) return abs( x - p1 );
    if( dot( p1 - p2, x - p2 ) < EPS ) return abs( x - p2 );
    return abs( cross( p2 - p1, x - p1 ) ) / abs( p2 - p1 );
}

signed main(){
    int N1; cin >> N1;
    vector<P> low( N1 + 2 );
    low[0] = { 0, 0 };
    low[N1 + 1] = { 1000, 0 };
    REP( i, N1 ){
        D x, y; cin >> x >> y;
        low[i + 1] = { x, y };
    }

    int N2; cin >> N2;
    vector<P> high( N2 + 2 );
    high[0] = { 0, 1000 };
    high[N2 + 1] = { 1000, 1000 };
    REP( i, N2 ){
        D x, y; cin >> x >> y;
        high[i + 1] = { x, y };
    }

    D ans = INF;
    REP( i, N1 + 1 ){
        REP( j, N2 + 2 ){
            chmin( ans, solve( low[i], low[i + 1], high[j] ) );
        }
    }

    REP( i, N2 + 1 ){
        REP( j, N1 + 2 ){
            chmin( ans, solve( high[i], high[i + 1], low[j] ) );
        }
    }

    printf( "%.10Lf\n", ans );
}



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

int main() {
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  int cnt=0,ans=a[0];
  rep(i,n){
    cnt++;
    if(ans==1){
      cout<<cnt<<endl;
      return 0;
    }
    ans=a[ans];
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 3772
#include<stdio.h>
#include<stdlib.h>
int partition(int*,int,int);

int main()
{
  int n,i,q;
  int *a;
  
  scanf("%d",&n);
  a=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  q = partition(a,0,n-1);
  for(i=0;i<n;i++) {
    if(i>0) printf(" ");
    if(i==q) printf("[%d]",a[i]);
    else printf("%d",a[i]);
  }
  printf("\n");
  free(a);
}

int partition(int a[],int p,int r)
{
  int x,i,j,tmp;
  x = a[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(a[j]<=x) {
      i = i+1;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
    }
  }
  tmp = a[i+1];
  a[i+1] = a[r];
  a[r] = tmp;
  return i+1;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n;
    cin>>n;
    string s;
    set<string>st;
    while(cin>>s)
        st.insert(s);
    cout<<st.size()<<endl;
}

Measured memory_bytes: 19116
N, K = map(int, input().split())

c = [[0] * 2001 for _ in range(2000 + 1)]
c[0][0] = 1
for i in range(1, 2000 + 1):
    ci = c[i]
    ci1 = c[i - 1]
    ci[0] = 1
    for j in range(1, i + 1):
        ci[j] = (ci1[j - 1] + ci1[j]) % 1000000007

for i in range(1, K + 1):
    print(c[K - 1][i - 1] * c[N - K + 1][i] % 1000000007)

Measured memory_bytes: 98284
import java.util.*;

object MainKt {
  fun gcd(a:Int,b:Int) :Int = if(b==0) {a} else{
    gcd(b,a%b)
  }
  @JvmStatic fun main(args:Array<String>) {
  val (A,B,C) = readLine()!!.split(" ").map(String::toInt)
  println(if(C % gcd(A,B)==0) {"YES"} else {"NO"})
  }
}

Measured memory_bytes: 37996
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int a[2][600][600],dx[8]={-1,-1,-1,0,1,1,1,0},dy[8]={-1,0,1,-1,1,0,-1,1};
map<int,P> ma[2];
int n,u,v,m,cu,cv,INF=1<<28;
int c[100001];
bool ck(int x,int y) {
  if(x<0 || x>=n || y<0 || y>=n) return false;
  return true;
}
 
bool check(int z, int k) {
  if(!ma[k].count(z)) return false;
  int x=ma[k][z].first,y=ma[k][z].second;
  a[k][x][y]=1;
  for(int i=0; i<4; i++) {
    if(n==1 && i) break;
    int cnt=1,nx=x,ny=y;
    for(int j=0; j<n; j++) {
      nx+=dx[i],ny+=dy[i];
      if(!ck(nx,ny)) break;
      if(a[k][nx][ny]) cnt++;
      else break;
    }
    nx=x,ny=y;
    for(int j=0; j<n; j++) {
      nx+=dx[i+4],ny+=dy[i+4];
      if(!ck(nx,ny)) break;
      if(a[k][nx][ny]) cnt++;
      else break;
    }
    if(cnt==n) {
      if(!k) cu++;
      else cv++;
    }
  }
  if(!k) return (cu>=u);
  else return (cv>=v);
}
 
int main() {
  memset(a,0,sizeof(a));
  ma[0].clear();ma[1].clear();
  cu=0;cv=0;
  cin >> n >> u >> v >> m;
  for(int k=0; k<2; k++) {
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	int x;
	cin >> x;
	ma[k][x]=P(i,j);
      }
    }
  }
  int U=INF,V=INF;
  for(int i=0; i<m; i++) cin >> c[i];
  for(int i=0; i<m; i++) {
    if(check(c[i],0)) U=i;
    if(check(c[i],1)) V=i;
    if(U!=INF || V!=INF) break;
  }
  if(U<V) cout << "USAGI" << endl;
  else if(U>V) cout << "NEKO" << endl;
  else cout << "DRAW" << endl;
  return 0;
}


Measured memory_bytes: 22124
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents =[-1 for i in range(n)]
    # どのグループに属しているかを返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True

    def size(self, x):
        return -self.parents[self.find(x)]

N, M = map(int, input().split())
ut = UnionFind(N)
for i in range(M):
    x, y = list(map(int, input().split()))
    ut.unite(x-1, y-1)
ans = -1
for x in ut.parents:
    if x < 0:
        ans += 1
print(ans)

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

int main() {
   int X[3][3];

   for(int i=0; i<3; i++) {
      for(int j=0; j<3; j++) {
         cin >> X[i][j];
      }
   }

   int n;
   cin >> n;
   for(int b=0; b<n; b++) {
      int y;
      cin >> y;
      for(int i=0; i<3; i++) {
         for(int j=0; j<3; j++) {
            if(X[i][j] == y) X[i][j] = 0;
         }
      }
   }


   for(int i=0; i<3; i++) {
      int row_sum = 0;
      int column_sum = 0;
      for(int j=0; j<3; j++) {
         row_sum += X[i][j];
         column_sum += X[j][i];
      }
      if(row_sum == 0 || column_sum == 0) {
         cout << "Yes" << endl;
         return 0;
      }
   }
   if(X[0][0] + X[1][1] + X[2][2] == 0 || X[0][2] + X[1][1] + X[2][0] == 0) {
      cout << "Yes" << endl;
      return 0;
   }
   cout << "No" << endl;
}

Measured memory_bytes: 3560
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (n, d) = InputLine.to_ia
  counter = 0
  n.times do
    (x, y) = InputLine.to_ia
    counter += 1 if x * x + y * y <= d * d
  end
  puts counter.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 14416
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;
        int s[n];
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += s[i];
        }
        double ave = sum / n;
        sum = 0;
        for (int i = 0; i < n; i++) {
            sum += (s[i] - ave) * (s[i] - ave);
        }
        double dist = sum / n;
        cout << sqrt(dist) << endl;
    }
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n;
ll mod = 1e9+7;
typedef pair<ll,ll> P;
map<P,ll> m;

ll solve(ll S,ll X) {
	if(m.find(P(S,X)) != m.end()) {
		return m[P(S,X)];
	}
	if(S == 0) {
		return m[P(S,X)] = 1;
	}
	if(X == 0) {
		return (m[P(S,X)] = S / 2 + 1) %= mod;
	}
	if(S == 1) {
		return m[P(S,X)] = 2;
	}
	if(X == 1) {
		return (m[P(S,X)] = solve(S,0) + (S - 1) / 2) %= mod;
	}

	return (m[P(S,X)] = solve(S / 2,X / 2) + solve((S - 2) / 2,X / 2) + solve((S - 1) / 2,(X - 1) / 2)) %= mod;
}

int main(){
	cin >> n;
	cout << solve(n,n) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;

inline ll num(const ll P, const ll a)
{
    const ll maxi = P / a;
    const ll mini = (P + a + 1) / (a + 1);
    return maxi - mini + 1;
}

inline ll bin(const ll P)
{
    ll inf = 0;
    ll sup = P + 1;
    while (sup - inf > 1) {
        const ll mid = (inf + sup) / 2;
        if (P >= (__int128_t)mid * (mid - 1)) {
            inf = mid;
        } else {
            sup = mid;
        }
    }
    return inf;
}

int main()
{
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++) {
        ll A, B;
        cin >> A >> B;
        if (A == 1 and B == 1) {
            cout << 0 << endl;
            continue;
        }
        const ll P = A * B - 1;
        if (A < B) {
            swap(A, B);
        }
        const ll u = bin(P);
        const ll v = P / u;
        ll ans = v + u - 1;
        if (P >= A and A >= u and num(P, P / A) == 1) {
            ans--;
        }
        const ll b = P / B;
        if (b > 0 and num(P, B) > 0 and P / b - P / (b + 1) <= 1) { ans--; }
        cout << ans << endl;
    }
    return 0;
}


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

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

#define MAX_V 1000000

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

	int A, B;
	cin >> A >> B;
	if(A * B % 2 == 0) cout << "No" << endl;
	else cout << "Yes" << endl;

}


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

int main(){
		string str,sub1,sub2;
		int m,h;
		while(1){
				cin >> str;
				if(str == "-") break;
				cin >> m;
				for(int i = 0;i < m;i++){
						cin >> h;
						sub1 = str.substr(0,h);
						sub2 = str.substr(h,str.size());
						str = sub2 + sub1;
				}
				cout << str << endl;
		}

		return 0;
}

Measured memory_bytes: 1216
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

Int Ceil(Int a, Int b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return Floor(a, b) + 1;
    }
}

vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

Int digits(Int n) {
    return (Int)to_string(n).size();
}

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

    Int s, c;
    cin >> s >> c;

    Int ans = 0;
    if (c < s * 2) {
        ans = c / 2;
    } else if (c == s * 2) {
        ans = s;
    } else {
        ans += s;
        c -= 2 * s;
        ans += c / 4;
    }

    cout << ans << endl;

    return 0;
}

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

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

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;


int main() {
  int N, M;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  cin >> M;
  vector<string> T(M);
  for (int i = 0; i < M; ++i) {
    cin >> T[i];
  }
  sort(T.begin(), T.end());
  
  int result = 0;
  for (string s : S) {
    int buf = 0;
    for (string b : S) {
      if (s == b) {
        ++buf;
      }
    }
    for (string r : T) {
      if (s == r) {
        --buf;
      }
    }
    result = max(result, buf);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7


def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs


dest = list(map(int, input().split()))

p = (2, 1)
q = (1, 2)
num_p = 0
num_q = 0

while dest[0] and dest[1]:
    if dest[0] >= dest[1]:
        dest[0] -= p[0]
        dest[1] -= p[1]
        num_p += 1
    else:
        dest[0] -= q[0]
        dest[1] -= q[1]
        num_q += 1

modFacts, invs = prepare(num_p + num_q)

if dest == [0, 0]:
    n = num_p + num_q
    r = min(num_p, num_q)
    ans = (modFacts[n] * invs[n - r] * invs[r]) % MOD
else:
    ans = 0

print(ans)


Measured memory_bytes: 49520
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d,f;
d = f =0;
string e;
  cin >> e;
  c = e.size();
  for(int x = 0; x < c;x++){
  	if(e.at(x) -'0' != x%2){
    d++;
    }
  }
  for(int y = 0; y < c;y++){
  	if(e.at(y) - '0' == y%2){
    f++;
    }
  }
  cout << min(d,f) << endl;
}

Measured memory_bytes: 512
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [a, b, c, d] = input[0].map(Number);

  return Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d)
    ? "Yes"
    : "No";
};

console.log(main(read()));


Measured memory_bytes: 29684
#include<iostream>
using namespace std;
signed main(){
  int a,b,c,d=1;
  cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>c;
    b=b-c;
    if(b>=0){
      d++;
    }
  }
  cout<<d<<"\n";
  return(0);
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x; cin >> x;
    ll ok = LLINF, ng = 0;
    ll m = (ok+ng)/2;
    while(abs(ok-ng) > 1){
        ll five = m/2;
        ll six = m-five;
        //cout << six*6 + five*5 << endl;
        if(six*6 + five*5 >= x) ok = m;
        else ng = m;
        m = (ok+ng)/2;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 256
m=int(input())
for i in range(m):
  s=input()
  ptn=set()
  ptn.add(s)
  for j in range(len(s)):
    l=s[:j]
    r=s[j:]
    l_r=l[::-1]
    r_r=r[::-1]
    ptn.add(l+r_r)
    ptn.add(l_r+r)
    ptn.add(l_r+r_r)
    ptn.add(r+l)
    ptn.add(r+l_r)
    ptn.add(r_r+l)
    ptn.add(r_r+l_r)
  print(len(ptn))


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define gcd(a,b)   __gcd(a,b)
#define lcm(a,b)   (a*b)/gcd
#define rep(i,n)   for(int i=0;i<n;i++)
#define Rep(i,n)   for(int i=1;i<=n;i++)
#define REP(i,j,n) for(int i=j;i<=n;i++)
#define fast   ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)


int main()
{ 
	fast;
	ll n,m;
	cin>>n>>m;
	if(n==m){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;

}

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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
    {
        ll n,k;
        cin>>n>>k;

        if(n==0 || k==1)
        {
            cout<<0;
            continue;
        }  

        ll g=n%k;

        g=min(g,k-g);

        cout<<g;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long mod=1e9+7;
#define ll long long
using namespace std;
int lim=0;

/*ll power(ll n)
{
    if(n==0) return 0%mod;
    if(n==1) return 1%mod;
    return ((power(n-1)%mod) + (power(n-2)%mod ))%mod;
}
int main()
{
    ll n;cin>>n;
    cout<<power(n%mod)%mod;
}*/
ll pw(ll x,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1) res=res*x*1ll%mod;
        x=x*x*1ll%mod;
        n/=2;
    }return res;
}
int main()
{
    int n,i,t=0,k,p;
    cin>>n>>k;
    for(i=0;i<n;i++) {cin>>p;if(p>=k) t++;}
    cout<<t<<endl;

}
// C++ program to find sum of two large numbers.
/*#include<bits/stdc++.h>
using namespace std;

// Function for finding sum of larger numbers
string findSum(string str1, string str2)
{
    // Before proceeding further, make sure length
    // of str2 is larger.
    if (str1.length() > str2.length())
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();

    // Reverse both of strings
    reverse(str1.begin(), str1.end());
    reverse(str2.begin(), str2.end());

    int carry = 0;
    for (int i=0; i<n1; i++)
    {
        // Do school mathematics, compute sum of
        // current digits and carry
        int sum = ((str1[i]-'0')+(str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');

        // Calculate carry for next step
        carry = sum/10;
    }

    // Add remaining digits of larger number
    for (int i=n1; i<n2; i++)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)
        str.push_back(carry+'0');

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}

// Driver code
int main()
{
    string str1 ,str2 ;
    cin>>str1>>str2;
    cout << findSum(str1, str2);
    return 0;
}
*/
// CPP program to find (a^b) % MOD where a and
// b may be very large and represented as strings.




Measured memory_bytes: 256
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)
Closed = [False] * (1<<N)
Closed[0] = True
for _ in range(N):
    cnt = 0
    cnt_ = 0
    s_old = -1
    for i, s in enumerate(S):
        if s_old!=s:
            cnt += cnt_
            cnt_ = 0
        c = Closed[i]
        if c:
            cnt_ += 1
        elif cnt > 0:
            Closed[i] = True
            cnt -= 1
        s_old = s
if False in Closed:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 104140
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
const ll mod = 998244353
;
ll modinv(ll a){
  ll b = mod,u = 1,v = 0,t;
  while(b){
    t = a/b;
    a -= t*b;swap(a,b);
    u -= t*v;swap(u,v);
  }
  u %= mod;
  if(u < 0) u += mod;
  return u; 
}
ll modpow(ll x,ll y){
  ll ans = 1;
  while(y){
    if(y&1) ans = ans*x%mod;
    x = x*x%mod;
    y >>= 1;
  }
  return ans;
}
int main(){
  ll N,M,K,i,ans = 0;scanf("%lld%lld%lld",&N,&M,&K);
  ll P[200001];P[0] = P[1] = 1;
  for(i=2;i<=200000;i++) P[i] = P[i-1]*i%mod;
  for(i=0;i<=K;i++){
    ans = (ans+M*modpow(M-1,N-1-i)%mod*P[N-1]%mod*modinv(P[i])%mod*modinv(P[N-1-i])%mod)%mod;
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 5356
#include <iostream>
#include <vector>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a;
 	cin >>a;
 	vector <bool> expo(a+1);
 	expo[1] = 1;
 	for(int b=2;b<=a;b++){
 		int v = b*b;
 		while(v<=a){
 			expo[v] = 1;
 			v *= b;
 		}
 	}
 	for(int i=a;i>=1;i--) if(expo[i]){
 		cout <<i<<endl;
 		return 0;
 	}
 }

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

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

    vector<int> a(n); rep(i,n) cin >> a[i];

    map<int,int> mp; rep(i,n) ++mp[a[i]];

    int ans = 0;

    for(const auto p : mp) {
        int key = p.first;
        int value = p.second;
        if(key == value) continue;
        if(key < value) ans += value - key;
        else ans += value;
    }

    cout << ans << endl;
}


Measured memory_bytes: 5120
#include<iostream>

using namespace std;

int main(){

	int A[5][4][11], n;

	for ( int i = 1; i <= 4; i++ )

		for ( int j = 1; j <= 3; j++ )

			for ( int k = 1; k <= 10; k++ ) A[i][j][k] = 0;


	cin >> n;

	for ( int i = 0; i < n; i++ ){

		int b, f, r, v;

		cin >> b >> f >> r >> v;

		A[b][f][r] += v;

	}

	for ( int f = 1; f <= 4; f++ ){

		if ( f > 1 ) cout << "####################\n";

		for ( int b = 1; b <= 3; b++ ){

			for ( int r = 1; r <= 10; r++ ){

				cout << " " << A[f][b][r];

			}

		cout << endl;

		}

	}

	return 0;

}

Measured memory_bytes: 1164
def dfs(N, AB):
  status = [-1] * N
  for i in range(N):
      if status[i] == 1:
          continue
      stack = [i]
      status[i] = 0
      while stack:
          print("stack:", stack)
          v = stack[-1]
          if AB[v]:
              n = AB[v].pop()
              if status[n] == -1:
                  stack.append(n)
                  status[n] = 0
              elif status[n] == 0:
                  idx = stack.index(n)
                  print("stack:", stack, "n:", n, "idx:", idx)
                  cycle = stack[idx:]
                  
                  return cycle
          else:                  
              status[v] = 1
              stack.pop()
 
  return False

def dfs_2(N, AB):
  for c in range(N):
    stack = [(c, [])]
    while stack:
      # print("stack:", stack)
      curr, visited = stack.pop()
      if curr in visited:
        # print("cycle found:", curr)
        return visited
      else:
        # print("adding in visited:", curr)
        for i in AB[curr]:
          stack.append((i, visited+[curr]))
  return False

 
 
def find_smaller_cycle(cycle, AB):
    i = 0
    while i < len(cycle):
        v = cycle[i]
        if AB[v]:
            n = AB[v].pop()
            if n in cycle:
                r = cycle.index(n)
                if i < r:
                    cycle = cycle[:i+1] + cycle[r:]
                else:
                    cycle = cycle[r:i+1]
                i = cycle.index(v)
        else:
            i += 1
            
    return cycle
 
 
N, M = [int(i) for i in input().split()]
 
AB = [[] for _ in range(N)]
for _ in range(M):
    A, B = [int(i) - 1 for i in input().split()]
    AB[A].append(B)

# print("AB:")
# for i in AB:
#   print(i)
cycle = dfs_2(N, AB)
# print("cycle:", cycle)
if not cycle:
    print(-1)
else:
    cycle = find_smaller_cycle(cycle, AB)
            
    print(len(cycle))
    for v in cycle:
        print(v + 1)

Measured memory_bytes: 3316
lefthand = set("qwertasdfgzxcvb")
while True:
	line = raw_input()
	if line == "#": break
	prehand = line[0] in lefthand
	count = 0
	for c in line:
		if (c in lefthand) != prehand:
			prehand = not prehand
			count += 1
	print count

Measured memory_bytes: 4220
s = input()
n = len(s)

ans = 0

for bit in range(1 << (n - 1)):

    f = s[0]

    for i in range(n - 1):
        if (bit >>i) & 1:
           
            f += "+"
        f += s[i + 1]

    ans += sum(map(int, f.split("+")))

print(ans)

Measured memory_bytes: 68320
#include<bits/stdc++.h>
using namespace std;
string s;
bool f[102];
int main(){
	cin>>s;
	for(register int i=0;i<3;++i){
		f[s[i]]=1;
	}
	for(register int i='a';i<='c';++i)
		if(f[i]==0){
			cout<<"No"<<endl;
			return 0;
		}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n,k,ans = 0;
    cin >> n >> k;
    if(k == 1){//色が一つの時
        if(n > 1){
            cout << 0 << endl;
        }else{
            cout << 1 << endl;
        }
        return 0;
    }

    ans = k;
    for(int i = 1; i < n; i++){
        ans *= (k-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>, int> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int N, a[200005];
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    int L = 0, R = 0, cur = 0;
    ll ans = 0;
    while(R < N){
        while(L < N && ((cur ^ a[L]) == cur + a[L])){
            cur += a[L];
            L++;
        }
        ans += L - R;
        cur -= a[R];
        R++;
    }
    cout << ans;
}

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

int N;
vector<vector<int> > edges;

vector<int> dp;

int dfs(int now, int from, int len)
{
    multiset<int> l;

    for (auto v : edges[now]) if (v != from)
    {
        if (dfs(v, now, len)) return 1;
        l.insert(dp[v]);
    }
    if (!(l.size() % 2)) l.insert(0);

    vector<int> rem;
    while (!l.empty())
    {
        int t = *(--l.end());
        l.erase(--l.end());
        if (l.empty())
        {
            rem.push_back(t);
            break;
        }
        auto itr = l.upper_bound(len - t);
        if (itr == l.begin()) rem.push_back(t);
        else l.erase(--itr);
    }
    if (rem.size() > 1) return 1;

    dp[now] = rem[0] + 1;
    return 0;
}

bool isAble(int b)
{
    dp = vector<int>(N, -1);
    if (dfs(0, -1, b) || dp[0] > b+1 || (edges[0].size() % 2 == 0 && dp[0] > 1)) return false;
    return true;
}

int main()
{
    cin >> N;
    edges.resize(N);
    for (int i=0; i<N-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    int A = 0;
    for (int i=0; i<N; i++) if ((int)edges[i].size() & 1) A++;
    A /= 2;

    cout << A << " ";

    int l = 0, r = N-1;
    while (r - l >1)
    {
        int c = (l + r) / 2;
        if (isAble(c)) r = c;
        else l = c;
    }
    cout << r << endl;
}


Measured memory_bytes: 21120
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);
        var X = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var sortedX = X.OrderBy(x => x).ToArray();

        var D = new (int v, int i)[M - 1];
        for (int i = 0; i < M - 1; i++)
            D[i] = (sortedX[i + 1] - sortedX[i], i);
        var sortedD = D.OrderByDescending(x => x.v);
        
        var sepPos = sortedD.Take(N - 1).Select(x => x.i + 1);
        var startIdx = new[] { 0 }.Concat(sepPos);
        var endIdx = sepPos.Concat(new[] { M }).Select(i => i - 1);

        var l = startIdx.Zip(endIdx, (si, ei) => sortedX[ei] - sortedX[si]);
        var ans = l.Sum();
        
        WriteLine(ans);
    }
}


Measured memory_bytes: 39144
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	return (a+b)%m;}
int sub(int a,int b,int m=mod){	return (a-b+m)%m;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}

int fun(int x)
{
	int low=-1000,high=1000,mid,ans=0;
	while(low<=high)
	{
		int mid=(low+high)/2;
		//cout<<mid<<endl;
		int val=(mid*mid*mid*mid*mid);
		if(val>x)
		{
			high=mid-1;
		}
		else
		{
			low=mid+1;
			ans=mid;
		}
	}
	return ans;
}

int func(int a)
{
	return (a*a*a*a*a);
}

void solve()
{
	int x,i,j;
	cin>>x;
	for(i=-1000;i<=1000;i++)
	{
		for(j=-1000;j<=1000;j++)
		{
			int val1=func(i);
			int val2=func(j);
			if(val1-val2==x)
			{
				cout<<i<<" "<<j<<endl;
				return;
			}
		}
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	while(t--)	solve();
	return 0;
}

Measured memory_bytes: 3652