akhauriyash/Code-Regression huggingface dataset:
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  bool chkFroot[N] = {false};
  bool chkEroot[N] = {false};
  int a,b;
  for(int i = 0; i < M; i++){
    cin >> a >> b;
    if(a==1) chkFroot[b] = true;
    if(b==N) chkEroot[a] = true;
  }

  bool flag = false;
  for(int i = 2; i < N; i++){
    if(chkFroot[i]&&chkEroot[i]){
      flag = true;
      break;
    }
  }

  if(flag) printf("POSSIBLE\n");
  else printf("IMPOSSIBLE\n");

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);
    int x = 0;
    int y = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (v[i] >= c[i])
        {
            x += v[i];
            y += c[i];
        }
    }
    cout << x - y << endl;
}

Measured memory_bytes: 256
N = int(input())
P = [int(input()) for i in range(N)]
is_earlier = [True] * N
appeared = set()
appeared.add(N+1)
for p in P:
  if p+1 in appeared:
    is_earlier[p-1] = False
  appeared.add(p)

M = 0
now = 1
for i in range(N):
    if is_earlier[i]:
        now += 1
    else:
        M = max(M, now)
        now = 1

print(N - M)

Measured memory_bytes: 24864
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll N, Q, a, b, p, x, cnt[200001] = {};
vector<vector<ll>>path(200001);
bool visited[200001] = {};

void DFS(ll cur, ll counter) {
	cnt[cur] += counter;
	visited[cur] = true;
	for (int i = 0; i < path[cur].size(); i++) {
		if (!visited[path[cur][i]])DFS(path[cur][i], cnt[cur]);
	}
}

int main() {
	cin >> N >> Q;
	for (int i = 1; i < N; i++) {
		cin >> a >> b;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	for (int i = 1; i <= Q; i++) {
		cin >> p >> x;
		cnt[p] += x;
	}
	DFS(1, 0);
	for (int i = 1; i <= N; i++)cout << cnt[i] << endl;
	return 0;
}

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

using namespace std;

#define int long long

 main()
{
    string s;

    cin >> s;

    int rez = 0;

    for(int i = 0; i < s.size(); i++)
    {
        rez += s[i] - '0';
        rez %= 9;
    }

    if(rez == 0)
        cout <<"Yes";
    else
        cout <<"No";

    return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

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

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  int x;
  cin >> x;

  if(x >= 1800) {
    cout << 1 << endl;
  }
  else if(x >= 1600) {
    cout << 2 << endl;
  }
  else if(x >= 1400) {
    cout << 3 << endl;
  }
  else if(x >= 1200) {
    cout << 4 << endl;
  }
  else if(x >= 1000) {
    cout << 5 << endl;
  }
  else if(x >= 800) {
    cout << 6 << endl;
  }
  else if(x >= 600) {
    cout << 7 << endl;
  }
  else {
    cout << 8 << endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

int main()
{
  ll a,b,k;cin>>a>>b>>k;
  if(a>k){
    a=a-k;
  }else if(a+b>k){
    b=a+b-k;
    a=0;
  }else{
    a=0;
    b=0;
  }
  cout<<a<<' '<<b<<endl;
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;

  int A[50], B[50];

  rep(i, 0, M) {
    cin >> A[i] >> B[i];
  }

  int road[50] = {};

  rep(i, 0, M) {
    road[A[i]-1] += 1;
    road[B[i]-1] += 1;
  }

  rep(i, 0, N) {
    cout << road[i] << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>

inline int64_t gcd(int64_t a, int64_t b) {
	return (a % b == 0 ? b : gcd(b, a % b));
}
inline int64_t lcm(int64_t a, int64_t b) {
	return a / gcd(a, b) * b;
}

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

	int64_t ans;
	std::cin >> ans;
	for (int i = 1; i < n; ++i) {
		int64_t t;
		std::cin >> t;
		ans = lcm(ans, t);
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int k,n;
  cin>>k>>n;
  vint h(k);
  rep(i,k){
    cin>>h[i];
  }
  sort(all(h));
  int min=INF;
  int x;
  rep(i,k){
    if(i+n>k){
      break;
    }
    x=h[i+n-1]-h[i];
    chmin(min,x);
  }
  cout<<min<<'\n';
  return(0);
}


Measured memory_bytes: 640
n = STDIN.gets.chomp.to_i

transportation = []

5.times do
  transportation  << STDIN.gets.chomp.to_i
end

min_index = transportation.rindex(transportation.min)

counter = 0

counter = n / transportation[min_index]
unless (n % transportation[min_index]) == 0
  counter += 1
end

puts counter+transportation.length-1


Measured memory_bytes: 1788
<?php 
$num = trim(fgets(STDIN));
$tmp = explode(' ', $num);
if (($tmp[0] < $tmp[1]) && ($tmp[1] < $tmp[2]) && ($tmp[0] < $tmp[2])) {
 echo "Yes".PHP_EOL;
} else {
 echo "No".PHP_EOL;
}

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

using namespace std;

using ll = long long;

static int P = 1000000007;

int main()
{
    int N,M;
    cin >> N >> M;

    vector<bool> sta(N+1,true);
    for(int i=0;i<M;i++)
    {
        int a;
        cin >> a;
        sta.at(a) = false;
    }

    vector<int> V(N+1,0); // 0 ~ N段目

    V.at(0) = 1;
    if(sta.at(1)) V.at(1) = 1;

    for(int i=2;i<=N;i++)
    {
        V.at(i) = (V.at(i-1) + V.at(i-2)) % P; // 2 << 1+0
        if(!sta.at(i))
        {
            V.at(i) = 0;
        }
    }

    cout << V.at(N) << endl;

    return 0;
}

Measured memory_bytes: 640
def main():
    c = int(input()) // 2
    elem = list(map(int, input().split()))
    right, left = sorted(elem)[c - 1:c + 1]
    for val in elem:
        print(median(val, right, left))


def median(val, right, left):
    if right == left:
        return right
    elif val <= right:
        return left
    else:
        return right


if __name__ == '__main__':
    main()


Measured memory_bytes: 26352
from collections import deque
sa = deque(input())
sb = deque(input())
sc = deque(input())

player = "a"
while True:
    if player == "a":
        if len(sa) == 0:
            print("A")
            break
        player = sa.popleft()
    elif player == "b":
        if len(sb) == 0:
            print("B")
            break
        player = sb.popleft()
    else:
        if len(sc) == 0:
            print("C")
            break
        player = sc.popleft()

Measured memory_bytes: 65060
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

int main(){
  string s;
  cin >> s;
  int n=s.size();
  ll k; cin >> k;
  rep(i,n){
    int need='z'-s[i]+1;
    if(s[i]!='a' && need<=k){
      s[i]='a';
      k-=need;
    }
    if(i==n-1&&k>0){
      k%=26;
      s[i]=char(s[i]+k);
    }
  }
  cout<<s<<endl;
}


Measured memory_bytes: 512
var
	A,B,C,D,E:int64;
function gcd(a,b:int64):int64;
begin
	if b=0 then gcd:=a
	else gcd:=gcd(b,a mod b);
end;
begin
	read(A,B,C,D);
	dec(A);
	E:=C div gcd(C,D)*D;
	writeln(B-A-B div C+A div C-B div D+A div D+B div E-A div E);
end.


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int main(){
    string S; cin >> S;
    vector<bool> s;
    rep(i, S.length()){
        if(S[i] == 'W') s.push_back(true);
        else s.push_back(false);
    }
    
    unsigned int cnt = 0;
    auto itr_s = s.begin();
    auto itr_e = itr_s;
    while(itr_e < s.end()){
        if(*itr_s != *itr_e){
            itr_s = itr_e;
            cnt++;
        }
        itr_e++;
    }
    cout << cnt;
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>

using namespace std;

int main(void) {

	int n ,minn=500000,numa=0,numb=0;
	int a[200000]={},b[200000]={};
	string s;

	bool juda=false,judb=false;
	cin>>n>>s;

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

		if(i!=0){
			a[i]=a[i-1];
			b[i]=b[i-1];
		}

		if(s[i]=='.')a[i]++;
		else b[i]++;


	}
/*	for (int i = 0; i < n; i++) {
		//cout<<a[i]<<" "<<b[i]<<"\n";
	}*/
	int tmpa,tmpb;
	minn=a[n-1];

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

		tmpa=b[i]+(a[n-1]-a[i]);
		minn=min(minn,tmpa);

		//printf("i=%d,min=%d\n",i,minn);
	}


	//int ans=min(numa,numb);

	cout<<minn<<"\n";

	return 0;
}


Measured memory_bytes: 2180
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n = 5;
	
	vector<int> a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	vector<int> c(n);

	for (int i = 0; i < n; i++) {
		int v = a[i]-a[i]%10;
		if (a[i] % 10 > 0) {
			v += 10;
		}

		c[i] = v;
	}

	int ans = INF;
	for (int i = 0; i < n; i++) {
		int tmp = 0;
		for (int j = 0; j < n; j++) {
			if (i == j) {
				tmp += a[i];
			}
			else {
				tmp += c[j];
			}
		}

		ans = min(ans, tmp);
	}

	cout << ans << endl;

	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define endl "\n"


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
vll seen;
vvll graph;
vll indeg;
vll ret;


void init(ll n){
  graph.resize(n);
  indeg.resize(n,0);
  seen.resize(n,0);
  ret.resize(0);
}

void bfs(ll s){
  queue<ll> que;
  que.push(s);
  seen[s] = 1;

  while(!que.empty()){
    ll u = que.front(); que.pop();
    ret.push_back(u);
    for(ll i=0;i<graph[u].size();i++){
      ll v = graph[u][i];
      indeg[v]--;
      if(indeg[v] == 0 && seen[v] == 0){
        seen[v] = 1;
        que.push(v);
      }
    }
  }
}

void T_sort(ll n){
  for(ll i=0;i<n;i++){
    for(ll j=0;j<graph[i].size();j++){
      ll v = graph[i][j];
      indeg[v]++;
    }
  }
  for(ll i=0;i<n;i++){
    if(indeg[i] == 0 && seen[i] == 0){
      bfs(i);
    }
  }
}
//-----------------------------------------

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

  ll n;
  cin >> n;
  init(n);
  ll m;
  cin >> m;
  REP(i,m){
    ll s, t;
    cin >> s >> t;
    graph[s].push_back(t);
  }

  T_sort(n);

  cout << !(ret.size() == n) <<endl;

  return 0;
}




Measured memory_bytes: 3248
#include <stdio.h>
int main(void)
{
    int num,val,n,i;
    scanf("%d",&num);
    for(n=1;n<=num;++n){
        printf("Case %d:\n",n);
        scanf("%d",&val);
        for(i=0;i<10;i++){
            val = val*val%100000000;
            val = val/100%10000;
            printf("%d\n",val);
        }
    }
    return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <algorithm>
typedef long long ll;

using namespace std;
 
int main() {
    ll n;
    cin >> n;
    ll sum1 = 0;
    ll sum2 = 0;
    ll count1 = 0;
    ll count2 = 0;
    for (int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        sum1 += ai;
        sum2 += ai;
        if (i % 2) {
            if (sum1 <= 0){
                count1 += 1 - sum1;
                sum1 = 1;
            }
            if (sum2 >= 0){
                count2 += 1 + sum2;
                sum2 = -1;
            }
        }
        else {
            if (sum1 >= 0){
                count1 += 1 + sum1;
                sum1 = -1;
            }
            if (sum2 <= 0){
                count2 += 1 - sum2;
                sum2 = 1;
            }
        }
    }
 
    cout << min(count1, count2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t con = 1000000007LL;
  
  int N;
  cin >> N;
  vector<bitset<60>> A(N);
  for(int i = 0; i < N; i++){
    int64_t Ai;
    cin >> Ai;
    A.at(i) = bitset<60>(Ai);
  }
  
  int64_t sum = 0;
  for(int i = 0; i < 60; i++){
    int num0 = 0;
    int num1 = 0;
    for(int j = 0; j < N; j++){
      if(A.at(j).test(i)){
        num1++;
      }else{
        num0++;
      }
    }
    int64_t sum_temp = ((num0 % con) * (num1 % con)) % con;
    for(int j = 0; j < i; j++){
      sum_temp *= 2;
      sum_temp %= con;
    }
    sum += sum_temp;
    sum %= con;
  }
  cout << sum << endl; 
}

Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			
			final int N = sc.nextInt();
			
			long[] left_height  = new long[N];
			long[] right_height = new long[N];
			for(int i = 0; i < N; i++){
				final long T = sc.nextLong();
				left_height[i] = T;
			}
			for(int i = 0; i < N; i++){
				final long A = sc.nextLong();
				right_height[i] = A;
			}
			
			boolean[] left_changed = new boolean[N];
			left_changed[0] = true;
			for(int i = 1; i < N; i++){
				if(left_height[i] != left_height[i - 1]){
					left_changed[i] = true;
				}
			}
			
			boolean[] right_changed = new boolean[N];
			right_changed[N - 1] = true;
			for(int i = N - 2; i >= 0; i--){
				if(right_height[i + 1] != right_height[i]){
					right_changed[i] = true;
				}
			}
			
			boolean ok = false;
			for(int i = 0; i < N; i++){
				if(left_height[i] > right_height[i]){
					ok = false;
					break;
				}else if(left_height[i] == right_height[i]){
					ok = true;
					break;
				}
			}
			if(!ok){
				System.out.println(0);
				return;
			}
			
			for(int i = 0; i < N; i++){
				if(left_changed[i] && right_changed[i] && left_height[i] != right_height[i]){
					System.out.println(0);
					return;
				}
			}
			
			long answer = 1;
			for(int i = 0; i < N; i++){
				if(left_changed[i] || right_changed[i]){ continue; }
				//System.out.println(i);
				answer *= (Math.min(left_height[i], right_height[i]));
				answer %= (1000000000 + 7);
			}
			
			System.out.println(answer);
		}
	}
}

Measured memory_bytes: 69624
import itertools

n, m, q = list(map(int, input().split()))

a=[]
b=[]
c=[]
d=[]

for i in range(q):
    x = list(map(int, input().split()))
    a.append(x[0])
    b.append(x[1])
    c.append(x[2])
    d.append(x[3])

h = []
A_list = list(itertools.combinations_with_replacement(range(1, m+1), n))


for A in A_list:
    s = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            s += d[i]
    h.append(s)

print(max(h))
 



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

int main() {
  long N;
  cin>>N;
  vector<pair<string, int>> data(N);
  for(int i=0;i<N;i++){
      cin>>data[i].first>>data[i].second;
  }
  string s;
  cin>>s;
  long ans=0;
  int idx;
  for(int i=0;i<N;i++){
    //cout<<data[i].first<<s<<endl;
    if(s==data[i].first) {
      //cout<<data[i].first<<endl;
      idx=i+1;
    }
  }
  if(idx==N){
    cout<<0<<endl;
    return 0;
  }
  else{
    for(int i=idx;i<N;i++){
      ans += data[i].second;
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

void inputData(int n, vector< pair<int, int> > &vp){
    int a[20], b[20];
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    rep(i, n) vp.push_back(make_pair(a[i], b[i]));
    sort(all(vp), greater< pair<int, int> >());
}

int main(){
    int ans = 0;
    int n, m, k;
    vector< pair<int, int> > vp;
    cin >> n >> m >> k;
    inputData(n, vp);

    //rep(i,n) cout << vp[i].first << endl;

    //bit??§??¨??????
    rep(i, (1 << n)){
        //????????????k?????\???????????????????????????????????????
        int c = 0; 
        rep(j, n) if( (i & (1 << j)) == (1 << j) ) c++;
        if(c > k) continue;

        //??¨??????
        int imo = m, sum = 0;
        rep(j, n){
            if( (i & (1 << j)) == (1 << j) ){
                if(vp[j].second <= imo){ //???????????§???????????????????????´???
                    imo -= vp[j].second;
                    sum += vp[j].first * vp[j].second;
                }else{
                    sum += vp[j].first * imo;
                    imo = 0;
                }
            }
        }
        ans = max(ans, sum + imo);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    int n;
    int a[100005];
    cin >> n;
    rep(i, n)
    {
        cin >> a[i];
        a[i]--;
    }
    int cnt = 0;
    bool flag = true;
    while (flag) {
        rep(i, n - 1)
        {
            if (a[i] == i) {
                swap(a[i], a[i + 1]);
                cnt++;
            }
        }
        rrep(i, n)
        {
            if (i == 0)
                break;
            if (a[i] == i) {
                swap(a[i], a[i - 1]);
                cnt++;
            }
        }
        rep(i, n)
        {
            if (a[i] == i) {
                break;
            }
            if (i == n - 1) {
                flag = false;
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 640
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <vector>
# include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include <iostream>
using namespace std;

/*long long F(long long n)
{
    int i;
    for(i=1;i<1e5;i++)
    {
        if(i*i==n)
            {
                printf("%lld",n);
                break;
            }
    }
    if(i==1e5)
    return F(n-1);
}*/

int main ()
{
    int  n,x,y,m;
    scanf("%d",&n);
    m=n;
    x=sqrt(n);
    y=sqrt(m);
    printf("%d",x*y);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int h,w,i,j;
  while(1){
    scanf("%d %d",&h,&w);
    if(h==0 && w==0)break;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        printf("#");
	if(j==w-1)printf("\n");
      }
    }
    printf("\n");
  }
  return 0;
}

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

const int Mod=1e9+7,N=2e5+10;

int w,h,a,b,inv[N],fact[N];

void Init() {
	scanf("%d%d%d%d",&w,&h,&a,&b);
}

int Calc(int n,int m) { return 1ll*fact[n]*inv[n-m]%Mod*inv[m]%Mod; }

void Solve() {
	int n=w+h-2;
	fact[0]=1; for (int i=1;i<=n;++i) fact[i]=1ll*fact[i-1]*i%Mod;
	inv[0]=1; inv[1]=1;  for (int i=2;i<=n;++i) inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for (int i=2;i<=n;++i) inv[i]=1ll*inv[i]*inv[i-1]%Mod;
	int x=w-a,y=b+1,ans=0;
	while (x>=1 && y<=h) {
		ans=(ans+1ll*Calc(x+y-2,y-1)*Calc(w+h-x-y,w-x))%Mod;
		x--; y++;
	}
	printf("%d\n",ans);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
string alph("abcdefghijklmnopqrstuvwxyz");
int fi[2005][2005]={};
signed main(){
    int a,b,c,x;cin>>a>>b>>c>>x;
    int count=0;
    rep(i,0,a+1){
        rep(j,0,b+1){
            rep(k,0,c+1){
                if(i*500+100*j+50*k==x)count++;
            }
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    ll n;
    cin >> n;
    string s = "";
    char d = 'a' + n%26 -1;
    if(n%26==0)d = 'z';
    s = s+d;
    
    
    if(n%26==0)n-=26;
    n/=26;
    while(n > 0){
        char c = 'a' + n % 26 -1;
        if(n%26 == 0)c = 'z';
        s = c + s;
        //n -= n%26;
        if(n%26 == 0)n -= 26;
        n/=26;
        //if(n <= 0)break;
    }
    cout << s << endl;
    return 0;
}

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

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

ll n,m,x,k,d,i,j,index,flag=0,mini,count=0,result,odd,even,sum=0,temp,t;
cin>>n>>x>>t;
//string str;
//cin>>str;
//ll a[200005];
//ll b[200005];
/*for(i=0;i<n;i++)
{
    cin>>a[i];
}
*/
result=(n+(x-1))/x;
result*=t;
cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
go = False

while go == False:
    for i in range(n):
        if a[i] % 2**ans:
            print(ans - 1)
            go = True
            break
    ans += 1

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

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

bool cmp(pint a, pint b) {return a.second < b.second;}
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
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; }

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

    ll ans = n * (n - 1) / 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

void solve(int& N, int& M){
  vector<int> vec(M + 1, 0);
  int d, v;
  for(int i = 0; i < N; i++) {
    cin >> d >> v;
    vec[d] = max(vec[d], v);
  }
  int ans = 0;
  for(int i = 0; i < vec.size(); i++) ans += vec[i];
  cout << ans << endl;
}

int main(){
  int N, M;
  while(cin >> N >> M) {
    if(N == 0 && M == 0) break;
    solve(N, M);
  }
  return 0;
}



Measured memory_bytes: 3104
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	int r,g,b;
	scanf("%d%d%d",&r,&g,&b);
	r=r*100+g*10+b;
	printf("%s\n",r%4==0?"YES":"NO");
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
  string s,t;
  cin>>s>>t;
  cout<<t+s<<endl;

  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = new int[](N+1);

    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        A[s[0]-1] += 1;
        A[s[1]-1] -= 1;
    }

    foreach (i; 0..N) {
        A[i+1] += A[i];
    }

    writeln((N-1).iota.map!(i => A[i] % 2 == 0).all ? "YES" : "NO");
}


Measured memory_bytes: 3708
#include<stdio.h>
#include<string.h>

int main() {
	char inpStr[21];
	scanf("%s", inpStr);
	for (int i = strlen(inpStr) - 1; i >= 0; i--) {
		printf("%c", inpStr[i]);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2036
n = int(input())
h = [list(map(int, input().split())) for _ in range(n)]

dp = [[0, 0, 0] for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(3):
        l = list(range(3))
        l.remove(j)
        x, y = l
        #print(dp)
        dp[i][j] = max(dp[i-1][x], dp[i-1][y]) + h[i-1][j]

print(max(dp[n]))


Measured memory_bytes: 75992
#include<iostream>
using namespace std;
int main()
{
   int n,a=0,w=0,t=0,r=0;
   cin>>n;
   while(n--)
   {
       char s[4];
     cin>>s;
     if(s[0]=='A')
     {
         a++;
     }
     else if(s[0]=='W')
     {
         w++;
     }
     else if(s[0]=='T')
     {
         t++;
     }
     else if(s[0]=='R')
     {
         r++;
     }

       }
       cout<<"AC"<<" "<<"x"<<" "<<a<<endl;
              cout<<"WA"<<" "<<"x"<<" "<<w<<endl;
                     cout<<"TLE"<<" "<<"x"<<" "<<t<<endl;
                            cout<<"RE"<<" "<<"x"<<" "<<r<<endl;
                            return 0;


}


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

int main(){
    int n,a=0;
    cin>>n;
    for(int i=1;i<=9;i++){
        for(int k=1;k<=9;k++){
            if(n==i*k)
            a++;
        }
    }
    if(a==0)
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
	#include<iostream>
	#include<map>
	#include<set>
	#include<vector>
	#include<cstring>
	#include<cassert>
	#include<sstream>
	#include<cmath>
	#include<algorithm>
	#include<queue>
	#include<limits>
	#include<ctime>
	#include<stack>
	#include<bits/stdc++.h>
	#include<string>
	#include<stdlib.h>
	#include<stdio.h>
	
	typedef long long ll;
	using namespace std;
	const ll x=1000000007;
	int mod(ll a){
		return a%x;
	}
	bool hit(int n,int a,int b){
		ll sum=0;
		while(n>0){
			sum+=n%10;
			n/=10;
		}
		if(sum>=a and sum<=b){
			return true;
		}
		else{
			return false;
		}
	}
	int main(){
		ll n,a,b,ans=0;
		cin>>n>>a>>b;
		for(int i=1;i<=n;i++){
			if(hit(i,a,b)){
				ans+=i;
			}
		}
		cout<<ans;
	}

Measured memory_bytes: 3592
/***************************************** 
****       Solution by SlavicG        ****
*****************************************/
 
#include<bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm> 
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;++i)
#define MX 10000000001
#define pow2(a) ((a)*(a))
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define endl "\n"
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 int longestIncreasingSubsequenceLenghtDP(int a[],int n){
    int dp[n],ans=0;
    for(int k = 0;k<n;k++){
        dp[k] = 1;
        for(int i = 0;i<k;i++){
            if(a[i] <= a[k]){
                dp[k] = max(dp[k],dp[i] + 1);
                ans = max(dp[k],ans);
            }
        }
    }
    return ans;
 }
int result[1000] = {0};
int factDP(int n) 
{
   if (n >= 0) {
      result[0] = 1;
      for (int i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
      return result[n];
   }
}
bool checkPrime(int n)
{
    if(n<2) return false;
    for(int x = 2;x*x <=n;x++)
    {
        if(n%x == 0)return false;
    }
    return true;
}
vector<int> primeFactors(int n){
    vector<int> f;
    for(int x = 2;x*x<=n;x++){
        while(n%x==0){
            f.push_back(x);
            n/=x;
        }
    }
    if(n>1)f.push_back(n);
    return f;
}
int binary_Search_Classic(int n, int arr[],int target){
	int l,r,mid;
	l=0;
	r=n-1;
	while(l<=r){
		mid= l+(r-l)/2;
		if(arr[mid] == target){
			return mid;
		}
		if(arr[mid] < target){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return -1;
	
}
int binary_Search_First_Greater(int n, int arr[],int target){
	int l,r,ans,mid;
	l = 0;
	r = n-1;
	ans=-1;
	while(l<=r){
		mid = l + (r-l)/2;
		if(arr[mid] > target){
			ans=mid;
			r=mid-1;
		}else{
			l = mid+1;
		}
	}
	return ans;
}
int countDistinctCharsString(string s) {
    unordered_map<char, int> m; 
    for (int i = 0; i < s.length(); i++) { 
        m[s[i]]++; 
    }
    return m.size(); 
} 
int main()
{
	int  n,m,k;
	cin >> n >> m;
	cin >> k;
	int a[n],b[m];
	vector<ll> A(n+1), B(m+1);
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
	}
	for(int i = 0;i<m;i++)
	{
		cin >> b[i];
	}
	for(int i = 0;i<n;i++)
	{
		A[i+1] = A[i] + a[i];
	}
	B[0]=0;
	for(int i = 0;i<m;i++)
	{
		B[i+1] = b[i] + B[i];
	}
	int ans=0;
	ll rem;
	for(int i = 0;i<=n;i++)
	{
		rem = k-A[i];
		if(rem<0)continue;
		int l = lower_bound(B.begin(),B.end(),rem)-B.begin();
		if(l>m || B[l] > rem)
		{
			l--;
		}
		ans = max(ans,i+l);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
int visited[100001]={0};
int dfs(int i,vector<vector<int>>&v)
{
    visited[i]=1;
    for(int j=0;j<v[i].size();j++)
    {
        if(visited[v[i][j]]==0)
            dfs(v[i][j],v);
    }
    return 0;
}
int main()
{
    long long int n,m,a,b,ct=0;
    cin>>n>>m;
    vector<vector<int>>v(n+1);
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=1;i<=n;i++)
    {
        if(visited[i]==0)
        {
            ct++;
            dfs(i,v);
        }
    }
    cout<<ct-1;

    return 0;
}


Measured memory_bytes: 10000
from collections import deque
h,w = map(int, input().split())
map = [list(input()) for _ in range(h)]
dis = [[float("inf")]*w for _ in range(h)]
dy = [1,0,-1,0]
dx = [0,1,0,-1]
que = deque([])
que.append((0,0))
dis[0][0]=1
count = 0
for i in range(h):
    for j in range(w):
        if map[i][j]=="#":
            count+=1

while que:
    p = que.popleft()
    if p[0]==h-1 and p[1]==w-1:
        break
    for i in range(4):
        ny = p[0] + dy[i]
        nx = p[1] + dx[i]
        if 0<=ny<h and 0<=nx<w and map[ny][nx]!="#" \
           and dis[ny][nx]==float("inf"):
            que.append((ny,nx))
            dis[ny][nx]=dis[p[0]][p[1]]+1

print(h*w-dis[h-1][w-1]-count if dis[h-1][w-1]!=float("inf") else -1)


Measured memory_bytes: 3316
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int N;
	scanf("%d", &N);
	vector<int> vec;
	for(int i=0; i<2*N; ++i) {
		int L;
		scanf("%d", &L);
		vec.push_back(L);
	}
	sort(vec.begin(), vec.end());
	int sum = 0;
	for(int i=0; i<N; ++i) {
		sum += vec[i*2];
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
bool isOK(int index, string key) {
    string res;
    if(index % 2 == 0) {
        if(key == "Female") {
            res = "Male";
        } else {
            res = "Female";
        }
    } else {
        res = key;
    }
    cout << index << endl;

    string pon;
    cin >> pon;
    if(pon == "Vacant") {
        cout << index << endl;
        exit(0);
    }
    if(pon == res) {
        return true;
    } else
        return false;
}
int N;
// 汎用的な二分探索のテンプレ
ll binary_search(string key) {
    ll ng = 0; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll ok = N; // 「index =
               // a.size()-1」が条件を満たさないこともあるので、初期値は
               // a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while(abs(ok - ng) > 1LL) {
        ll mid = (ok + ng) / 2LL;

        if(isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

int main() {
    cin >> N;
    cout << 0 << endl;
    string hoge;
    cin >> hoge;
    if(hoge == "Vacant") {
        cout << 0 << endl;
        return 0;
    }
    binary_search(hoge);
    return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int pow(int x, int y){
  int r = 1;
  for(int i = 0; i < y; i++){
    r *= x;
  }
  return r;
}

bool check(int i, int n){
  if(i > n) return false;
  bool seven = false, five = false, three = false;
  while(i != 0){
    int j = i % 10;
    if(j == 7) seven = true;
    else if(j == 5) five = true;
    else if(j == 3) three = true;
    else return false;
    i /= 10;
  }
  return seven && five && three;
}

int f(int i, int s, int d, int max_d, int n){
  if(d == max_d){
    if(check(s, n)) return 1;
    else return 0;
  }
  int sum = 0;
  int t = s + pow(10, i) * 7;
  sum += f(i + 1, t, d + 1, max_d, n);
  t = s + pow(10, i) * 5;
  sum += f(i + 1, t, d + 1, max_d, n);
  t = s + pow(10, i) * 3;
  sum += f(i + 1, t, d + 1, max_d, n);
  return sum;
}

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

  int n;
  cin >> n;

  int sum = 0;
  for(int i = 0; i < 10; i++){
    sum += f(0, 0, 0, i, n);
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
ts=time.time()
sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
show_flg=True

an=0
k=0
s=input()
d=dict()
d['Sunny']='Cloudy'
d['Cloudy']='Rainy'
d['Rainy']='Sunny'
print(d[s])


Measured memory_bytes: 39276
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  double x, sum=0;
  string u;
  for(int i=0;i<n;i++){
    cin >> x >> u;
    if(u=="BTC") x*=380000.0;
    sum += x;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

int inf = std::numeric_limits<int>().max();

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define ll long long
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> v(n);
	for(int i=0; i<v.size(); i++) {
		cin >> v[i].first >> v[i].second;
		v[i].first = m+1 - v[i].first;
	}
	sort(v.begin(), v.end());

	priority_queue<int> p;

	ll ans = 0;
	int atual = m;
	int i=n-1;
	for(int d = m; d>=1; d--) {
		while (i>=0 and d == v[i].first) {
			p.push(v[i].second);
			//cout << "d " << d << " " << v[i].first << " - " << v[i].second << endl;
			i--;
		}
		if (!p.empty()) {
			ans += p.top();
			p.pop();
		}
	}

	cout << ans << endl;


}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> ans;
  if(N==0) {
    cout << 0 << endl;
    return 0;
  }
  while(abs(N) > 0) {
    if(N==1) {
      ans.push_back(1);
      break;
    }
    int tmp;
    if (N%(-2) == -1) {
      tmp = N/(-2) + 1;
    } else {
      tmp = N/(-2);
    }
    ans.push_back(N-tmp*(-2));
    N = tmp;
  }
  for(int i=ans.size()-1; i>=0; --i) cout << ans[i];
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
 
ll MOD = 1000000007;
ll INF =1<<29;
ll dp[100100];
 
int main() {
     double n ;
     cin >> n;
     double m = ceil(n/2);
     printf("%.10lf\n", m/n);
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
 
int a[201][201],d[201][201];
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int t,r;
string s;
 
int toInt() {
  int x=0;
  while(isdigit(s[t])) {
    x*=10;
    x+=(int)s[t]-48;
    t++;
  }
  return x;
}
 
int multi() {
  int x=toInt();
  while(s.size()>=t && s[t]=='*') {
    t++;
    x*=toInt();
  }
  return x;
}
   
int calc() {
  int ans=multi();
  while(s.size()>t) {
    if(s[t]=='+') {
      t++;
      ans+=multi();
    }
    if(s[t]=='-') {
      t++;
      ans-=multi();
    }
  }
  return ans;
}
 
void di(int i,int j) {
  queue<P> que;
  que.push(P(i,j));
  d[i][j]=r;
  while(!que.empty()) {
    P p=que.front();
    que.pop();
    int nx=p.first,ny=p.second;
    for(int i=0; i<4; i++) {
      int x=nx+dx[i],y=ny+dy[i];
      if(x>=0 && x<=200 && y>=0 && y<=200) {
        if(a[x][y] && !d[x][y]) {
          que.push(P(x,y));
          d[x][y]=r;
        }
      }
    }
  }
}
 
char mozi(int i,int j) {
  di(i,j);
  if(d[i][j+1]==r && d[i][j+2]==r && d[i][j+3]==r && d[i][j+4]==r && d[i+1][j]!=r) return '1';
  if(d[i][j+1]!=r && d[i+1][j]!=r) return '*';
  if(d[i+1][j]!=r) return '4';
  if(d[i][j+1]!=r && d[i+2][j+1]!=r) {
    if(d[i+1][j+1]!=r) return '-';
    else return '+';
  }
  if(d[i+1][j+2]!=r) {
    if(d[i][j+1]==r) return '0';
    else return '7';
  }
  if(d[i+2][j+1]!=r) {
    if(d[i][j+3]==r) return '6';
    else return '5';
  }
  if(d[i][j+1]!=r) {
    if(d[i][j+3]==r) return '2';
    else return '3';
  }
  if(d[i][j+3]==r) return '8';
  else return '9';
}
 
int main() {
  for(int i=0; i<201; i++) {
    for(int j=0; j<201; j++) {
      a[i][j]=0;
      d[i][j]=0;
    }
  }
  t=0;
  r=1;
  int n;
  cin >> n;
  for(int i=0; i<n; i++) {
    int x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if(x1==x2) {
      if(y1>y2) swap(y1,y2);
      for(int i=y1; i<=y2; i++) a[x1][i]=1;
    } else {
      if(x1>x2) swap(x1,x2);
      for(int i=x1; i<=x2; i++) a[i][y1]=1;
    }
  }
  s="";
  for(int i=0; i<201; i++) {
    for(int j=0; j<201; j++) {
      if(a[i][j] && !d[i][j]) {
        s+=mozi(i,j);
        r++;
      }
    }
  }
  cout << calc() << endl;
  return 0;
}


Measured memory_bytes: 3548
#include<stdio.h>
int main(void){
  int a,b,c,d;
  
  scanf("%d%d%d%d",&a,&b,&c,&d);
  
  while(1){ 
   c=c-b;
  if(c<=0){
    printf("Yes");
    return(0);
  }
   a=a-d;
  if(a<=0){
    printf("No");
    return(0);
  }
  }
     
  return(0);
}

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

int N, M;
double L[32];
double a[32];
double b[32];

double diff[32][32];

template<typename T>
T pow(T x, long n) {
  T res = 1;
  T p = x;
  while( n != 0 ) {
    if( n & 0x01 ) res *= p;
    p *= p;
    n >>= 1;
  }
  return res;
}

void calc_diff() {
  for(int i = 0; i < (int)N; ++i) {
    for(int j = 0; j < (int)N; ++j) {
      diff[i][j] = diff[j][i] = pow(L[i] - L[j], 2) + pow(a[i] - a[j], 2) + pow(b[i] - b[j], 2);
    }
  }
}

int main() {

  std::cin >> N >> M;
  for(int i = 0; i < N; ++i) {
    std::cin >> L[i] >> a[i] >> b[i];
  }
  calc_diff();
  double res = -1;
  for(int i = 0; i < (int)(1<<N); ++i) {
    if( __builtin_popcount(i) != M ) continue;
    double temp = 0.0;
    for(int j = 0; j < (int)N; ++j) {
      for(int k = j + 1; k < (int)N; ++k) {
        if( ( i & ( 1 << j ) ) != 0 and ( i & ( 1 << k ) ) != 0 ) temp += diff[j][k];
      }
    }
    res = std::max(res, temp);
  }
  printf("%.20lf\n", res);
  
  return 0;
}

Measured memory_bytes: 3292