akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define Rrep(i,y,x) for(ll i=y;i>x;i--)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define print(x) cout << (x) << endl
#define printvec(x) for(ll i=0;i<x.size();i++) cout << (x.at(i)) <<' ' 
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x.at(i)) << " \n"[i == n-1];}
typedef long long ll;

ll mod=1e9+7;

using namespace std;
ll modpower(ll x, ll y) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else if (y % 2 == 0) {
        ll p = modpower(x, y / 2);
        return p * p % mod;
    } else {
        ll p = modpower (x, y / 2);
        return (p * p) % mod * (x % mod) % mod;
    }
}
int main(){
    ll N,X,Y,Z;
    cin>>N>>X>>Y>>Z;
    ll forbit=(1<<(X+Y+Z -1 )) +(1<<(Y+Z -1 ))+(1<<(Z -1 ));
    ll mask = ((1<<(X+Y+Z)) -1);
    vector<vector<ll>> dp(N+1,vector<ll>(mask+1,0));
    dp.at(0).at(0)=1;
    rep(n,1,N+1){
      rep(i,0,mask+1){
        rep(k,0,10){
          ll t=((i <<(k+1)) | 1<<k) & mask;
            if ((t & forbit) != forbit){
              dp[n][t]+=dp[n-1][i];
              dp[n][t]%=mod;
            }
        }
      }
    }
  ll ans=modpower(10,N);
  rep(i,0,mask+1){
    ans=(ans+ mod - dp[N][i] ) % mod;
  }
  print(ans);

}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;
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() {
    int N;
    cin >> N;
    if (N) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String input = br.readLine();

            String result = "No";
            if (input.contains("a") && input.contains("b") && input.contains("c")) {
                result = "Yes";
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }

    private static int selectFee(int ticketForOnce, int unlimitedRide) {
        int selectedFee = ticketForOnce;
        if (ticketForOnce > unlimitedRide) {
            selectedFee = unlimitedRide;
        }

        return selectedFee;
    }
}

Measured memory_bytes: 22868
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(a);
            var ans = 0;
            var acum = 0L;
            for (var i = 0; i < n - 1; i++) {
                acum += a[i];
                if (a[i + 1] <= acum * 2) {
                    ans++;
                } else {
                   ans = 0; 
                }
            }
            Console.WriteLine(ans+1);
        }
    }
}


Measured memory_bytes: 28252
k = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print k[input()-1]

Measured memory_bytes: 2696
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
    
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    n--;
    int ans=(n)*(n+1)/2;
    cout<<ans<<"\n";



    return 0;
}

Measured memory_bytes: 256
k = int(input())
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(n[k-1])

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

int main()
{
	int n,x;
	long long a=1,b=1;
	cin >> n;
	while (n--) {
		a *= 3;
		cin >> x;
		if (x%2==0) b *= 2;
	}
	cout << a-b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
int main() {
	
	int N, D;
	cin >> N >> D;
	int PeopleHandle = (2 * D);
	int ans = (N + PeopleHandle) / (PeopleHandle + 1);
	cout << ans << endl;
}


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

int main(){
    int X, Y;
    cin >> X >> Y;
    string ans = "No";

    if(Y%2 == 0){
        if(2*X <= Y && Y <= 4*X){
            ans = "Yes";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
fn main() {
    let mut s = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut i = 1;

    for n in s.split_whitespace() {
        let n = n.parse::<usize>().expect("Parse error");
        if n == 0 {
            break;
        }
        println!("Case {}: {}", i, n);
        i += 1;
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========



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

long long GCD(long long a, long long b) 
{ 
    if(b==0) 
        return a; 
    return GCD(b, a % b);  
      
}

long long LCM(long long a, long long b)
{
    long long gcd=GCD(a,b);
     return (a*b)/gcd;
}

int main()
{
    int i, j, k, n, m, t, x1, y1, x2, y2, s=0, c=0, l;
    cin >> x1 >> y1 >> x2 >> y2 >> k;
    for(i=x1; i<x2; i++)
    {
        s+=60;
    }
    s-=y1;
    s+=y2;
    s=s-k;
    s=max(s, 0);
    cout << s << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void){
  int sec;
  scanf("%d", &sec);
  if(sec == 0){
    printf("0:0:0\n");
  } else {
    int hour = (sec - sec % 3600) / 3600;
    sec = sec - 3600 * hour;
    int min = (sec - sec % 60) / 60;
    sec = sec - 60 * min;
    printf("%d:%d:%d\n", hour, min, sec);
  }
  return 0;
}



Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, K;
string S;

int main() {
	cin >> N >> K >> S;
	
	deque<char> deq;
	REP(i, N) deq.push_back((i % 2 == 1) ^ (S[i] == 'A') ? 'A' : 'B');
	
	REP(i, 2 * N) {
		if (K == 0) break;
		
		char front = deq.front();
		deq.pop_front();
		
		if (front == 'A') deq.push_front('B');
		else deq.push_back(N % 2 == 1 ? 'A' : 'B');
		K--;
	}
	
	string ans = "";	
	REP(i, N) ans += (i % 2 == 1) ^ (deq[i] == 'A') ? 'A' : 'B';
	if (N & 1 && K & 1) ans[0] = ans[0] == 'A' ? 'B' : 'A';
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1164
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    string ans;
    if (N == 0)
    {
        ans = "0";
    }
    ll k = -2;
    while (N != 0)
    {
        if (N % k != 0)
        {
            ans.push_back('1');
            N += k / 2;
        }
        else
        {
            ans.push_back('0');
        }
        k *= -2;
    }
    reverse(ALL(ans));
    OUT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a,b,k;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b>>k;
    if (k<=a){
        cout<<a-k<<' '<<b;
        return 0;
    }
    else {
        k-=a;
        cout<<0<<' ';
        b-=k;
        if (b<0) cout<<0;
        else cout<<b;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	string s, t;
	cin >> s;
	for (int i = 0; i < 4; i++)
	{
		if (s[i]=='2')
		{
			ans++;
		}
	}




	cout << ans << endl;
	//cout <<  << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

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

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 (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll N, L;
    cin >> N >> L;

    ll taste = 0;
    FOR(i, 1, N+1){
        taste += L+i-1;
    }
    // pn(taste);

    ll min_diff = inf;
    ll min_taste = -1;

    // iを食べたとする
    FOR(i, 1, N+1){
        ll new_taste = taste - (L+i-1);
        ll diff = abs(taste - new_taste);

        if(diff < min_diff){
            min_diff = diff;
            min_taste = new_taste;
        }
    }

    p(min_taste);

    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  int A, B;
  cin >> A >> B;




  int ans = 1;
  while(1){
    int tax8 = ans * 0.08;
    int tax10 = ans * 0.1;

    if(tax8 == A && tax10 == B){
      cout << ans << endl;
      return 0;
    }
    if(tax8 > A || tax10 > B){
      cout << "-1" << endl;
      return 0;
    }
    ans++;
  }
  return 0;
}


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

int mdis(int ax, int ay, int bx, int by) {
  int re = abs(ax-bx) + abs(ay-by);
  return re;
}

int main() {
  int N , M;
  cin >> N >> M;
  vector<int> a(N) , b(N) , c(M) , d(M);
  for(int i=0; i<N; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  for(int i=0; i<M; i++) {
    cin >> c.at(i) >> d.at(i);
  }
  vector<vector<long int>> list(N,(vector<long int> (M)));
  for(int i=0; i<N; i++) {
    for(int j=0; j<M; j++) {
      list.at(i).at(j) = mdis(a.at(i), b.at(i), 
                             c.at(j), d.at(j));
    }
  }
  vector<int> sorted(M);
  int min;
  for(int i=0; i<N; i++) {
    for(int j=0; j<M; j++) {
      sorted.at(j) = list.at(i).at(j);
    }
    sort(sorted.begin(),sorted.end());
    min = sorted.at(0);
    for(int j=0; j<M; j++) {
      if(min == list.at(i).at(j)) {
        cout << j+1 << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
str= gets.chomp
l = str.length
l.times do |i|
  next if i == 0 || i == 1
  tmp = str[0..(l-i)]
  next if tmp.length%2 == 1
  h = (l-i)/2
  if tmp[0..h] == tmp[(-h-1)..-1]
    puts tmp.length
        exit 0
  end
end


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    unordered_set<int> S;
    int n, q, ans=0;
    cin >> n;
    for(int i=0;i<n;i++){
        int s;
        cin >> s;
        S.insert(s);
    }
    cin >> q;
    for(int i=0;i<q;i++){
        int t;
        cin >> t;
        if(S.count(t)>0) ans++;
    }

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


Measured memory_bytes: 6896
a,v = map(int, input().split( ))
b,w = map(int, input().split( ))
t = int(input())

dis0 = abs(b - a)
dis = v - w
if w>=v:
  print("NO")
  exit()

if abs(b-a)/(v-w)>t:
  print("NO")
else:
  print("YES")
  

Measured memory_bytes: 9036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
int a,b,k;
cin >> a >> b >> k;
for(int i=0;i<k;i++){
   if(i%2==0){
      if(a%2==1){
         a--;
      }
      b+=a/2;
      a/=2;
   }
   else{
      if(b%2==1){
         b--;
      }
      a+=b/2;
      b/=2;
   }
}
cout << a << " "<<b<<endl;
 }


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n)    FOR(i, 0, n)
#define pb           push_back
#define all(a)       (a).begin(), (a).end()
#define UNIQUE(v)    v.erase(unique(all(v)), v.end());
#define fill(a, x)   memset(a, x, sizeof(a))
#define zero(a)      fill(a, 0)
#define minus(a)     fill(a, -1)
#define dbg(x)       cout << #x "=" << x << endl

int main() {
  ios::sync_with_stdio(false);
  int n;
  int c = 0;
  vi vc_a;
  cin >> n;

  // receiving input
  while (c < n) {
    int tmp;
    cin >> tmp;
    vc_a.pb(tmp);
    c++;
  }

  int k;
  int cc = 0;
  vi vc_q;
  cin >> k;

  while (cc < k) {
    int tmp;
    cin >> tmp;
    vc_q.pb(tmp);
    cc++;
  }

  int count = 0;

  sort(vc_a.begin(), vc_a.end());
  sort(vc_q.begin(), vc_q.end());
  UNIQUE(vc_a);
  UNIQUE(vc_q);

  rep(i, vc_a.size()) {
    rep(j, vc_q.size()) {
      if (vc_q[j] > vc_a[i]) break;
      if (vc_q[j] == vc_a[i]) {
        count++;
        break;
      }
    }
  }

  cout << count << endl;

  return 0;
}



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

bool solve();

int n;
bool s[500], t[500];
bool u[500], v[500];
ll ans[500][500];
ll b = 1;

int main() {
	ll u_orig[500], v_orig[500];
	cin >> n;
	rep(i, n) cin >> s[i];
	rep(i, n) cin >> t[i];
	rep(i, n) cin >> u_orig[i];
	rep(i, n) cin >> v_orig[i];
	rep(d, 64) {
		rep(i, n) {
			u[i] = u_orig[i] & 1; u_orig[i] >>= 1;
			v[i] = v_orig[i] & 1; v_orig[i] >>= 1;
		}
		if (!solve()) {
			cout << -1 << endl;
			return 0;
		}
		b <<= 1;
	}
	rep(i, n) {
		rep(j, n) cout << ans[i][j] << ' ';
		cout << endl;
	}
}

bool resolve_any();
bool resolve_strict_existence();
bool resolve_weak_existence();

bool u_resolved[500];
bool v_resolved[500];
set<int> u_rem[500], v_rem[500];

bool solve() {
	rep(i, n) {
		u_resolved[i] = false;
		v_resolved[i] = false;
	}
	return resolve_any() && resolve_strict_existence() && resolve_weak_existence();
}

bool resolve_any() {
	bool u0 = false, u1 = false, v0 = false, v1 = false;
	rep(i, n) if ( s[i] && !u[i]) {u0 = true; break;}
	rep(i, n) if (!s[i] &&  u[i]) {u1 = true; break;}
	rep(i, n) if ( t[i] && !v[i]) {v0 = true; break;}
	rep(i, n) if (!t[i] &&  v[i]) {v1 = true; break;}
	if (u0 && v1 || u1 && v0) return false;

	bool ures[500] = {}, vres[500] = {};

	rep(i, n) if (s[i] ^ u[i]) {
		u_resolved[i] = ures[i] = true;
		if (u[i]) rep(j, n) ans[i][j] |= b;
		rep(j, n) if (u[i] == v[j]) v_resolved[j] = true;
	}
	rep(j, n) if (t[j] ^ v[j]) {
		v_resolved[j] = vres[j] = true;
		if (v[j]) rep(i, n) ans[i][j] |= b;
		rep(i, n) if (u[i] == v[j]) u_resolved[i] = true;
	}

	rep(i, n) if (!u_resolved[i]) {
		u_rem[i].clear();
		rep(j, n) if (!vres[j]) u_rem[i].insert(j);
		if (u_rem[i].empty()) return false;
	}
	rep(j, n) if (!v_resolved[j]) {
		v_rem[j].clear();
		rep(i, n) if (!ures[i]) v_rem[j].insert(i);
		if (v_rem[j].empty()) return false;
	}
	//rep(i, n) cout << u_resolved[i];
	//cout << "aaa" << (int)t[0] << (int)t[1] << endl;
	return true;
}

bool resolve_v(int);
bool resolve_u(int i) {
	assert(u_resolved[i] == false);
	u_resolved[i] = true;
	int j = *u_rem[i].begin();
	if (u[i]) ans[i][j] |= b;
	if (!v_resolved[j]) {
		if (u[i] == v[j]) v_resolved[j] = true;
		else {
			v_rem[j].erase(i);
			switch(v_rem[j].size()) {
				case 0:
					return false;
				case 1:
					return resolve_v(j);
			}
		}
	}
	return true;
}

bool resolve_v(int j) {
	assert(v_resolved[j] == false);
	v_resolved[j] = true;
	int i = *v_rem[j].begin();
	if (v[j]) ans[i][j] |= b;
	if (!u_resolved[i]) {
		if (u[i] == v[j]) u_resolved[i] = true;
		else {
			u_rem[i].erase(j);
			switch(u_rem[i].size()) {
				case 0:
					return false;
				case 1:
					return resolve_u(i);
			}
		}
	}
	return true;
}

bool resolve_strict_existence() {
	rep(i, n) if (!u_resolved[i] && u_rem[i].size() == 1 && !resolve_u(i)) return false;
	rep(j, n) if (!v_resolved[j] && v_rem[j].size() == 1 && !resolve_v(j)) return false;
	return true;
}

bool resolve_weak_existence() {
	rep(i, n) if (!u_resolved[i]) resolve_u(i);
	rep(j, n) if (!v_resolved[j]) resolve_v(j);
	return true;
}


Measured memory_bytes: 30920
n = int(input())

hats = [0, 0, 0]
count = 1
mod = 1000000007

for a in map(int, input().split()):
  count *= hats.count(a)
  count %= mod
  try:
    hats[hats.index(a)] += 1
  except ValueError:
    count = 0
    break
  
print(count)

Measured memory_bytes: 10644
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<char,int>;

const ll MOD = INF + 7;


int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, n)cin >> a[i];
   sort(ALL(a));
   a.push_back(INF);
   ll res = n;
   rep(i, n){
      int now = a[i];
      for(int j = 1; j * j <= now; j++){
         if(now % j != 0)continue;
         int m = now / j;
         int lbj = lower_bound(ALL(a), j) - a.begin();
         int lbm = lower_bound(ALL(a), m) - a.begin();
         if(a[lbj] == j){
            if(lbj != i || a[lbj + 1] == j){res--;break;}
         }
         else if(a[lbm] == m){
            if(lbm != i || a[lbm + 1] == m){res--;break;}
         }
      }
   }
   cout << res << endl;
}

Measured memory_bytes: 4768
/**
class cfmaster {
 public:
  struct code {
  	see the details down there !
  };
};
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = (int) s.size();
  int m = (int) t.size();
  vector<vector<int>> dp(n, vector<int>(m));
  vector<vector<int>> path(n, vector<int>(m));
  // 0 -> --i
  // 1 -> --j
  // 2 -> --i and --j
  if (s[0] == t[0]) {
  	dp[0][0] = 1;
  	path[0][0] = 2;
	} else {
		dp[0][0] = 0;
		path[0][0] = 0;
	}
	for (int i = 1; i < m; i++) {
		if (s[0] == t[i]) {
			dp[0][i] = 1;
			path[0][i] = 2;
		} else {
			dp[0][i] = dp[0][i - 1];
			path[0][i] = 1;
		}
	}
	for (int i = 1; i < n; i++) {
		if (s[i] == t[0]) {
			dp[i][0] = 1;
			path[i][0] = 2;
		} else {
			dp[i][0] = dp[i - 1][0];
			path[i][0] = 0;
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < m; j++) {
			if (s[i] == t[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
				path[i][j] = 2;
			} else {
				if (dp[i][j - 1] > dp[i - 1][j]) {
					dp[i][j] = dp[i][j - 1];
					path[i][j] = 1;
				} else {
					dp[i][j] = dp[i - 1][j];
					path[i][j] = 0;
				}
			}
		}
	}
	int x = n - 1, y = m - 1;
	string ans;
	while (x >= 0 && y >= 0) {
		if (path[x][y] == 2) {
			ans += s[x];
			--x;
			--y;
		} else {
			if (path[x][y] == 0) {
				--x;
			} else {
				--y;
			}
		}
	} 
	reverse(ans.begin(), ans.end());
	cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD (int)1e9 + 7
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;

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

int ans = INF, n, m, x, cost[12], arr[12][12], level[12];

void solve(int idx, int money) {
	if (idx == n) {
		for (int i = 0; i < m; i++) {
			if (level[i] < x) return;
		}
		ans = min(ans, money);
		return;
	}
	solve(idx + 1, money);
	for (int i = 0; i < m; i++) {
		level[i] += arr[idx][i];
	}
	solve(idx + 1, money + cost[idx]);
	for (int i = 0; i < m; i++) {
		level[i] -= arr[idx][i];
	}
}

int main() {
	fastio;
	cin >> n >> m >> x;
	for (int i = 0; i < n; i++) {
		cin >> cost[i];
		for (int j = 0; j < m; j++) {
			cin >> arr[i][j];
		}
	}
	solve(0, 0);
	if (ans == INF) cout << -1;
	else cout << ans;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.);
int main() {
	int x1, y1, x2, y2;
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	bool flip = 0, change = 0;
	if (x1 == x2) {
		change = 1;
		swap(x1, y1);
		swap(x2, y2);
	}
	if (x1 > x2) {
		swap(x1, x2);
		swap(y1, y2);
	}
	if (y1 > y2) {
		y1 = (int) 1e8 - y1 - 1;
		y2 = (int) 1e8 - y2 - 1;
		flip = 1;
	}
	int n;
	scanf("%d", &n);
	vector<pair<int, int>> a;
	for (int i = 0; i < n; ++ i) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (change) swap(x, y);
		if (flip) y = (int) 1e8 - y - 1;
		if (x >= x1 && x <= x2 && y >= y1 && y <= y2) {
			a.push_back({x, y});
		}
	}
	sort(a.begin(), a.end());
	vector<int> q;
	for (auto p : a) {
		int x = lower_bound(q.begin(), q.end(), p.second) - q.begin();
		if (x == q.size()) q.push_back(p.second);
		q[x] = p.second;
	}
	double ans = (x2 - x1 + y2 - y1) * 100. - q.size() * (20 - 5 * pi);
	if ((int) q.size() == min(x2 - x1 + 1, y2 - y1 + 1)) ans += 5 * pi;
	printf("%.15f\n", ans);
}



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

using namespace std;

int main() {

    int i;
    int weight;

    while(cin >> weight) {
        i = 0;
        do {
            if(weight & 1) {
                cout << pow((double)2, (double)i);
                if(weight != 1) {
                    cout << ' ';
                }
            }
            i++;
        } while(weight >>= 1);
        cout << endl;
    }

}

Measured memory_bytes: 1272
#!/bin/env/perl

use strict;
use warnings;
use utf8;

my @lines;

while (my $line = <STDIN>) {
  chomp $line;
  push @lines, $line;
}

my ($w, $h, $x, $y) = split ' ', $lines[0];

printf "%0.6f %d\n", ($w * $h) /2.0, ($w / 2.0 == $x && $h / 2.0 == $y ? 1 : 0);

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned int;
typedef pair<int,int> P;
typedef priority_queue<int> Pr;
int const MOD = 1000000007;

int dp[2001][2001]; float dpf[2001][2001]={};

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

    int n; string s; cin>>n>>s;
    
    cout<<(n>=3200?s:"red")<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

void solve(){
    int N;
    cin >> N;
    ll ans = 0;
    vvec<pair<ll,ll>> list(N);
    for(int i=0;i<N;i++){
        int k,l,r;
        cin >> k >> l >> r;
        k--;
        ans += min(l,r);
        list[k].emplace_back(l,r);
    }
    priority_queue<ll,vec<ll>,greater<ll>> Q;
    for(int i=0;i<N;i++){
        for(auto& [l,r]:list[i]) if(l-r>=0){
            ans += l-r;
            Q.push(l-r);
        }
        while(Q.size()>i+1){
            ans -= Q.top();
            Q.pop();
        }
    }
    while(!Q.empty()) Q.pop();
    for(int i=N-1;i>=0;i--){
        if(i){
            for(auto& [l,r]:list[i-1]) if(r-l>0){
                ans += r-l;
                Q.push(r-l);
            }
        }
        while(Q.size()>N-i){
            ans -= Q.top();
            Q.pop();
        }
    }
    cout << ans << "\n";
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--){
        solve();
    }
}

Measured memory_bytes: 14092
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm> // sort

using namespace std;

int main(){
    int A,B;

    string res;

    cin >> A >> B;

    if(A == B) res = "Draw";
    else if(A == 1)res = "Alice";
    else if(B == 1)res = "Bob";
    else if(A > B)res = "Alice";
    else res = "Bob";

    cout << res << endl;
}



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

int main(void){
    long int x, y, xx, yy, ans=1;
    cin >> x >> y;
    xx=max(x,y);
    yy=min(x,y);
    x=xx;
    y=yy;
    while(yy>0){
        if(x==y) ans = x;
        y=max(xx,yy)%min(xx,yy);
        x=min(xx,yy);
        xx=x;
        yy=y;
        ans=xx;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
 
 
int main()
{
 	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	//ll tt;	cin>>tt;	while(tt--)
  	{
  		ll n,m;

  	cin>>n>>m;

  	ll sol = n*(n-1) + m*(m-1);

  	cout<<sol/2;

//<<"h";


 
  	}
 	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
    return 0;
  		
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG




int main() {
  ll a;
  cin >> a;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));
  
  cout << a*a*a + a*a + a << endl;

  return 0;
}


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

int main(){
  int a,m[1001],k;
  cin >> a;
  for(int i=0;i<a;i++)cin>>m[i];
  for(int i=0;i<a;i++){
    k=i;
    while(1){
      if(k==0)break;
      else if(m[k]<m[k-1]){
	swap(m[k],m[k-1]);
	k--;
      }else break;
    }
    for(int j=0;j<a;j++){
      cout<<m[j];
      if(j<a-1)cout<<" ";
      else cout << endl;
    }
  }
  return 0;
}

	
  

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

int main(){
  long long N;
  cin>>N;
  long long A[N];
  long long B[N];
  long long sum=0;
  long long div=0;
  for(long long i=0;i<N;i++){
    cin>>A[i];
    B[i]=A[i]-(i+1);
  }
  sort(B,B+N);
  long long T=B[N/2];
  long long ans=0;
  long long minans=10e18;
  for(long long i=T-10;i<=T+10;i++){
    ans=0;
    for(long long j=0;j<N;j++){
      ans+=abs(A[j]-(j+i));
      //cout<<abs(A[j]-(j+i));
    }
    //cout<<i<<" "<<ans<<"#"<<endl;
    minans=min(ans,minans);
  }
  cout<<setprecision(18)<<minans<<endl;
  return 0;
}


Measured memory_bytes: 6748
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,d;
    cin >> n >> d;
    ll cnt = 0;
    double x,y;
    rep(i,n){
        cin >> x >> y;
        if (sqrt(x*x+y*y) <= d+0.0000000000000001) cnt++;
    }
    PRINT(cnt);
}


Measured memory_bytes: 3860
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=200005;
int n,q;
vector<int> a[MAXN];
int cnt[MAXN];
int ans[MAXN];
void dfs(int p,int fa,int add){
	add+=cnt[p];
	ans[p]=add;
	for (int i=0;i<a[p].size();i++){
		int v=a[p][i];
		if (v!=fa)
			dfs(v,p,add);
	}
}

signed main()

{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	for (int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		a[x].push_back(y);
		a[y].push_back(x);
	}

	for (int i=1;i<=q;i++){
		int x,c;
		cin>>x>>c;
		cnt[x]+=c;
	}

	dfs(1,0,0);
	for (int i=1;i<=n;i++)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 27136
mod = int(1e9+7)


def exgcd(a, b, arr):
    if b == 0:
        arr.clear()
        arr.append(1)
        arr.append(0)
        return a
    else:
        d = exgcd(b, a % b, arr)
        x = arr[1]
        y = arr[0] - a//b * arr[1]
        arr[0] = x
        arr[1] = y
        return d


def Inv(a):
    arr = []
    exgcd(a, mod, arr)
    return (arr[0] + mod) % mod


H, W, A, B = map(int, input().split())

fac = [1 for i in range(H + W)]
for i in range(1, len(fac)):
    fac[i] = fac[i-1] * i % mod
inv = [1 for i in range(H+W)]
for i in range(0, len(inv)):
    inv[i] = Inv(fac[i])


def Cnm(n, m):
    return fac[n] * inv[n-m] * inv[m] % mod


ans = Cnm(H+W-2, H-1)
for i in range(1, B+1):
    tmp = Cnm(H-A+i-2, i-1) * Cnm(A+W-i-1, W-i) % mod
    ans = (ans - tmp + mod) % mod
print(ans)


Measured memory_bytes: 19056
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,K,di,count=0,A=0;
 cin >> N >> K;
 vector<int> rist(N+1);
 for (int i = 0; i < N; i++)
  rist.at(i)=0;
 for(int a=0; a< K;a++){
    cin >> di;
    vector<int> data(di);
    for (int i = 0; i < di; i++) {
      cin >> data.at(i);
    }
    for (int i = 0; i < di; i++){
      A=data.at(i);
      rist.at(A-1)=1;
    }
 }
 for(int m=0;m<N;m++){
   if(rist.at(m)==0)
     ++count;
 }
 cout << count << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
template <class YT>
class Array
{
	vector<YT> data;
public:
	Array()
	{
	}
	void add(YT value)
	{
		data.push_back(value);
	}
	void add()
	{
		YT p;
		data.push_back(p);
	}
	YT &operator[](int index)
	{
		if(index>=data.size())
		{
			YT element;
			data.push_back(element);
		}
		return data[index];
	}
	int size()
	{
		return data.size();
	}
	void sort()
	{
		for(int i=0;i<data.size()-1;i++)
			for(int j=i+1;j<data.size();j++)
				if(data[i]>data[j])
				{
					YT p=data[i];
					data[i]=data[j];
					data[j]=p;
				}
	}
};
int main()
{
	int n=10,p=0;
	Array<int> mount;
	for(int i=0;i<n;i++)
	{
		cin>>p;
		mount.add(p);
	}
	mount.sort();
	cout<<mount[mount.size()-1]<<endl;
	cout<<mount[mount.size()-2]<<endl;
	cout<<mount[mount.size()-3]<<endl;
	return 0;
}

Measured memory_bytes: 0
import numpy as np
from collections import defaultdict

h, w, m = map(int, input().split())

rowsum = np.zeros(h, dtype=int)
colsum = np.zeros(w, dtype=int)
targets = defaultdict(int)
for _ in range(m):
    hi, wi = map(int, input().split())
    hi -= 1
    wi -= 1
    rowsum[hi] += 1
    colsum[wi] += 1
    targets[(hi, wi)] = 1

rowmax = np.max(rowsum)
colmax = np.max(colsum)
rowindices = np.where(rowsum == rowmax)[0]
colindices = np.where(colsum == colmax)[0]

for ri in rowindices:
    for ci in colindices:
        if targets[(ri, ci)]:
            continue
        print(rowmax + colmax)
        exit()

print(rowmax + colmax - 1)

Measured memory_bytes: 84596
#include <iostream>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int a[26] = {};
  for (int i = 0; i < S.length(); i++)
    a[S[i] - 'A']++;
  string ans = "No";
  if (0 < a['N' - 'A'] && 0 < a['S' - 'A'] && a['W' - 'A'] == 0 && a['E' - 'A'] == 0)
    ans = "Yes";
  if (0 < a['W' - 'A'] && 0 < a['E' - 'A'] && a['N' - 'A'] == 0 && a['S' - 'A'] == 0)
    ans = "Yes";
  if (0 < a['N' - 'A'] && 0 < a['S' - 'A'] && 0 < a['W' - 'A'] && 0 < a['E' - 'A'])
    ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    T = list(map(int, input().split()))
    A = list(map(int, input().split()))

    pattern = [0] * n
    prev = -f_inf
    for i in range(n):
        if prev < T[i]:
            pattern[i] = 1
            prev = T[i]

    prev = -f_inf
    for i in reversed(range(n)):
        if prev < A[i]:
            if pattern[i] != 0 and T[i] != A[i]:
                print(0)
                exit()
            pattern[i] = 1
            prev = A[i]
        else:
            if pattern[i] != 0 and T[i] > A[i]:
                print(0)
                exit()

    res = 1
    for i in range(n):
        if pattern[i] == 0:
            pattern[i] = min(T[i], A[i])
        res = res * pattern[i] % mod
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 19248
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

//                123456789
const int kMod = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  
  ll sum = 0;
  for (int i = 0; i <= 60; ++i) {
    ll c0 = 0;
    ll c1 = 0;
    for (auto a : A) {
      if (((a>>i)&1LL) == 0) ++c0;
      else ++c1;
    }
    //sum += (1LL<<i) * c0 * c1;
    ll tmp = (1LL<<i) % kMod * c0 % kMod * c1 % kMod;
    sum = (sum + tmp) % kMod;
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD (ll)1000000007

int GCD(int a, int b)
{
    if (!b) return a;
    return GCD(b, a % b);
}

bool prime[1000001]; //<< prime[i] = true : i가 소수이다. false : i는 소수가 아니다.
int a[1000001];
int b[1000001];

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

    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    int gcd = GCD(a[1], a[0]);

    for (int i = 1; i <= n; i++)
    {
        gcd = GCD(gcd, a[i]);
        int temp = a[i];
        int r = sqrt(a[i]);
        for (int j = 2; j <= r + 1; j++)
        {
            if (b[j] > 1 || temp == 1)
                break;
            if (temp % j == 0)
            {
                b[j]++;
                while (temp % j == 0)
                    temp /= j;
            }
        }
        if (temp != 1)
            b[temp]++;
    }
    int mx = 0;
    for (int i = 2; i <= 1000000; i++)
        mx = max(mx, b[i]);

    if (mx > 1 && gcd == 1)
        printf("setwise coprime");
    if (gcd != 1)
        printf("not coprime");
    if (gcd == 1 && mx <= 1)
        printf("pairwise coprime");
	return 0;
}

Measured memory_bytes: 9940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1e9+1;

/*
ナップサック問題
dp[i][j]:品物v[0]~v[i-1]までを使って価値をj以上にするときの重さの最小値
dp[i][j]=
min(dp[i-1][j-v[i-1].second]+v[i-1].first, dp[i-1][j])
ただし、j<v[i-1].secondのときはdp[i-1][j]をそのまま返す
*/

//関数の内側にあるとダメらしい。関数フレームのスタック領域の問題？
const int maxn = 110;
const int maxv = 100005;
ll dp[maxn][maxv];

void solve(){
    int n,w;
    cin >> n >> w;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        v.emplace_back(make_pair(a,b));
    }
    
    rep(i,maxn){
        rep(j, maxv){
            dp[i][j] = INF;
        }
    }

    rep(i,maxv){
        dp[0][i]=INF;
    }
    rep(i,n+1){
        dp[i][0]=0;
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=100000; j++){
            if(j<v[i-1].second) dp[i][j]=dp[i-1][j];
            else{
                dp[i][j]=min(dp[i-1][j], dp[i-1][j-v[i-1].second] + v[i-1].first);
            }
            //if(j<=12) cout << "i:" << i << " j:" << j << " " << dp[i][j] << endl;
        }
    }
    ll ans = 0;
    rep(i,maxv){
        if(dp[n][i] <= w) ans = i;
    }
    cout << ans << endl;
    

}

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


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

int N;
string S, T;

int main() {
  cin >> N;
  cin >> S >> T;
  string ans = "";
  for (int i = 0; i < N; i++) {
    cout << S[i] << T[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
r, g, b, n = gets.split.map(&:to_i)

ans = 0

0.upto(n / r) do |x|
  balls = r * x
  next if balls > n
  if balls == n
    ans += 1
    next
  end

  0.upto(n / g) do |y|
    balls = r * x + g * y
    next if balls > n
    if balls == n
      ans += 1
      next
    end

    rest = n - balls
    ans += 1 if rest % b == 0
  end
end

puts ans


Measured memory_bytes: 1788
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,y=LI()

  for i in range(x+1):
    j=x-i
    z=i*2+j*4

    if z==y:
      return 'Yes'

  return 'No'

# main()
print(main())


Measured memory_bytes: 10792
n, k = map(int, input().split())

l = [0] * (10**5 + 1)

for _ in range(n):
    i, j = map(int, input().split())
    l[i] += j

ind = 0
for i in range(10**5 + 1):
    ind += l[i]
    if ind >= k:
        print(i)
        break

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

int main(){
    double r, s, t;
    cin >> r;
    s = 2 * M_PI * r;
    t = M_PI * r * r;

    cout << fixed << setprecision(6) << t << " " << s << endl;
    
    
    return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int64_t INF = 1LL << 60;
//const int INF = 1 << 29;
//const int MODINF = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
int main(){
    string S;
    cin >> S;
    if(S == "SAT") cout << 1 << endl;
    if(S == "FRI") cout << 2 << endl;
    if(S == "THU") cout << 3 << endl;
    if(S == "WED") cout << 4 << endl;
    if(S == "TUE") cout << 5 << endl;
    if(S == "MON") cout << 6 << endl;
    if(S == "SUN") cout << 7 << endl;
}

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

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (int i=1; i<=n; i++) cin >> a[i];

    vector<bool> used(n+1,false);
    int current = 1;
    while(!used[current]) {
        used[current] = true;
        current = a[current];
        if (current == 2) break;
    }


    int ans = count(used.begin(), used.end(), true);
    if (current != 2) ans = -1;

    cout << ans << endl;
}

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

using namespace std;

void solve() {
  int h, a;
  cin >> h >> a;
  auto num = (h - 1) / a + 1;
  cout << num << endl;
}

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


Measured memory_bytes: 256
import java.util.*;
import java.util.Comparator;
 
public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);       
        int n=sc.nextInt();
        String o="YES";
        int[] a=new int[n];
      BinarySearchTree t=new BinarySearchTree();
        for(int i=0;i<n;i++){
        	a[i]=sc.nextInt();
            if(t.contains(a[i])){
            	o="NO";
                System.out.println(o);
                return;
            }else{
            	t.add(a[i]);
            }
            /*for(int j=0;j<i;j++){
            	if(a[j]==a[i]){
                	o="NO";
                    System.out.println(o);
                    return;
                }
            }*/
        }
      System.out.println(o);
    }
}
class Node {
    int data;
    Node left;
    Node right;
}

class BinarySearchTree {
    private Node root;
  public void add(int data) {
    // ツリーがない場合の特別処理
    if (root == null) {
        root = new Node();
        root.data = data;
        return;
    }

    // 現在ノードをルートノードとする
    Node current = root;
    while (true) {
        // 「追加する値 ＜ 現在ノードの値」なら左の子を対象とする
        if (data < current.data) {
            // 次のノードが存在しない場合はその位置にデータを追加する
            if (current.left == null) {
                current.left = new Node();
                current.left.data = data;
                return;
            }
            // 存在する場合は次のノードを現在ノードとして繰り返す
            current = current.left;
        }
        // 「現在ノードの値 ≦ 追加する値」なら右の子を対象とする
        else if (current.data <= data) {
            if (current.right == null) {
                current.right = new Node();
                current.right.data = data;
                return;
            }
            current = current.right;
        }
    }
}
  public boolean contains(int data) {
    // 現在ノードをルートノードとする
    Node current = root;
    // 次のノードが存在しない場合は探索終了
    while (current != null) {
        // 等しければ探索終了
        if (current.data == data) {
            return true;
        }
        // 「探索値 ＜ 現在ノードの値」なら左の子に進む
         else if (data < current.data) {
            current = current.left;
        }
        // 「現在ノードの値 ＜ 探索値」なら右の子に進む
         else if (current.data < data) {
            current = current.right;
        }
    }
    return false;
  }
}

Measured memory_bytes: 98124